/** * Serializable predicate over the widget being edited, for example to show a data slot only when * another option is set. * * A condition is plain data, so it can live in a plugin manifest and be evaluated by any editor * host. The variants are: * * - `{ path, equals }` — the value at `path` equals `equals` (deep equality). * - `{ path, in }` — the value at `path` equals one of the values in `in` (deep equality). * - `{ slot, minItems }` — the data slot named `slot` has at least `minItems` items (a finite number). * - `{ all }` — every nested condition is true (true for an empty list). * - `{ any }` — at least one nested condition is true (false for an empty list). * - `{ not }` — the nested condition is false. * * `path` is a dot path into `{ chartType, dataOptions, styleOptions }` of the widget being edited, * for example `'styleOptions.legend.enabled'`. A path that does not exist reads as `undefined`. * * @group Plugin System * @example * ```ts * import type { DataPanelInput } from '@sisense/sdk-ui'; * import type { Condition } from '@sisense/sdk-ui/sisense-internal'; * * // A plugin's "goal" slot: shown only when the plugin's own `showGoal` style option is on * // and its "value" slot has an item * const visibleWhen: Condition = { * all: [ * { path: 'styleOptions.showGoal', equals: true }, * { slot: 'value', minItems: 1 }, * ], * }; * * const goal: DataPanelInput = { name: 'goal', type: 'measure', visibleWhen }; * ``` * @sisenseInternal */ export type Condition = { readonly path: string; readonly equals: unknown; } | { readonly path: string; readonly in: readonly unknown[]; } | { readonly slot: string; readonly minItems: number; } | { readonly all: readonly Condition[]; } | { readonly any: readonly Condition[]; } | { readonly not: Condition; }; /** * The state of the widget being edited that a {@link Condition} is evaluated against. * * @sisenseInternal */ export interface ConditionContext { /** Type of the widget being edited, read by paths starting with `chartType`. */ readonly chartType?: string; /** Data options of the widget, read by paths starting with `dataOptions`. */ readonly dataOptions?: unknown; /** Style options of the widget, read by paths starting with `styleOptions`. */ readonly styleOptions?: unknown; /** * Number of items in each data slot, keyed by slot name, read by `{ slot, minItems }`. * A slot that is not listed has no items. */ readonly slotItemCounts?: Readonly>; } /** * Checks whether a value is a well-formed {@link Condition}, nested conditions included. * * Manifests can come from untyped code or from a newer SDK version, so hosts check a condition * before relying on it. * * @param value - The value to check. * @returns Whether every node of the value is a recognized condition variant. * @sisenseInternal */ export declare const isValidCondition: (value: unknown) => value is Condition; /** * Evaluates a {@link Condition} against the widget being edited. * * Pure: the result depends only on the arguments. `equals` and `in` compare with deep equality. * A missing path reads as `undefined`; a slot missing from `slotItemCounts` has no items. * * @param condition - The condition to evaluate. * @param context - The state of the widget being edited. * @returns Whether the condition holds, or `undefined` when any part of it is not a recognized * condition (malformed, or written for a newer SDK version). Callers decide what that means; * for slot visibility see {@link isDataPanelInputVisible}. * @sisenseInternal */ export declare const evaluateCondition: (condition: Condition, context: ConditionContext) => boolean | undefined; /** * Anything with an optional visibility condition, such as a data panel input. * * @sisenseInternal */ export interface WithVisibleWhen { /** When the owner is shown. Omit to always show it. */ readonly visibleWhen?: Condition; } /** * Whether a data panel input is shown for the widget being edited. * * An input without `visibleWhen` is always shown. An input whose `visibleWhen` is not a recognized * condition is also shown: a host never hides a slot, which may hold saved data, because of a rule * it cannot read. Plugin registration warns about such conditions. * * @param input - The input, or anything with an optional `visibleWhen`. * @param context - The state of the widget being edited. * @returns Whether the input is shown. * @sisenseInternal */ export declare const isDataPanelInputVisible: (input: WithVisibleWhen, context: ConditionContext) => boolean;