@molecule/app-rule-builder-solid 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,248 @@
1
+ /**
2
+ * `<RuleBuilder>` — visual condition / rule builder.
3
+ *
4
+ * Renders a recursive AND / OR group tree with field → operator → value
5
+ * leaves. Used by feature-flag-manager (target-audience rules),
6
+ * ai-workflow-automator (trigger conditions), email-marketing
7
+ * (segment definitions), iot-device-manager (automation rules), and
8
+ * smart-home-dashboard (scene triggers).
9
+ *
10
+ * @module
11
+ */
12
+ import { For, Show } from 'solid-js';
13
+ import { useTranslation } from '@molecule/app-solid';
14
+ import { getClassMap } from '@molecule/app-ui';
15
+ import { Button, Input, Select } from '@molecule/app-ui-solid';
16
+ import { operatorById, operatorsFor } from './operators.js';
17
+ import { appendToGroup, emptyGroup, emptyLeaf, removeById, replaceById, toggleGroupOp, } from './utilities.js';
18
+ /**
19
+ * Converts a React-style style object (camelCase keys) into the kebab-case
20
+ * object Solid's style runtime applies through `setProperty`, so the rendered
21
+ * inline style matches React's byte for byte.
22
+ *
23
+ * @param style - The ClassMap spacing record (`cm.sp(...)`).
24
+ * @returns The kebab-case style record.
25
+ */
26
+ const styleProps = (style) => Object.fromEntries(Object.entries(style).map(([key, value]) => [
27
+ key.startsWith('--') ? key : key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`),
28
+ value,
29
+ ]));
30
+ /**
31
+ * Reads the string a native input event carries.
32
+ *
33
+ * @param event - The native input event.
34
+ * @returns The input's current value.
35
+ */
36
+ const inputValue = (event) => event.target.value;
37
+ /**
38
+ * Render one group: the `AND` / `OR` toggle row, the children, and the
39
+ * "Add condition" / "Add group" buttons.
40
+ *
41
+ * @param props - Group renderer props.
42
+ * @returns The rendered group.
43
+ */
44
+ const Group = (props) => {
45
+ const cm = getClassMap();
46
+ const { t } = useTranslation();
47
+ const toggle = () => {
48
+ props.onReplace(toggleGroupOp(props.group, props.group.id));
49
+ };
50
+ const addCondition = () => {
51
+ props.onReplace(appendToGroup(props.group, props.group.id, emptyLeaf()));
52
+ };
53
+ const addGroup = () => {
54
+ props.onReplace(appendToGroup(props.group, props.group.id, emptyGroup()));
55
+ };
56
+ const removeChild = (childId) => {
57
+ props.onReplace(removeById(props.group, childId));
58
+ };
59
+ const replaceChild = (childId, next) => {
60
+ props.onReplace(replaceById(props.group, childId, next));
61
+ };
62
+ const opLabel = () => props.group.op === 'AND'
63
+ ? t('ruleBuilder.op.and', {}, { defaultValue: 'AND' })
64
+ : t('ruleBuilder.op.or', {}, { defaultValue: 'OR' });
65
+ return (<div class={cm.cn(cm.flex({ direction: 'col', gap: 'xs' }), cm.borderAll, cm.surface)} style={styleProps(cm.sp({ p: 3 }))} data-mol-id={`rule-builder-group-${props.group.id}`} data-group-op={props.group.op}>
66
+ <div class={cm.flex({ align: 'center', gap: 'xs' })}>
67
+ <Button variant="outline" size="sm" onClick={toggle} aria-label={t('ruleBuilder.aria.toggleOp', {}, { defaultValue: 'Toggle AND / OR' })} data-mol-id={`rule-builder-group-${props.group.id}-toggle`}>
68
+ {opLabel()}
69
+ </Button>
70
+ <span class={cm.cn(cm.textSize('xs'), cm.textMuted)}>
71
+ {props.group.op === 'AND'
72
+ ? t('ruleBuilder.help.allMustMatch', {}, { defaultValue: 'All conditions must match' })
73
+ : t('ruleBuilder.help.anyMustMatch', {}, { defaultValue: 'Any condition may match' })}
74
+ </span>
75
+ <Show when={!props.isRoot}>
76
+ <Button variant="ghost" size="sm" onClick={props.onRemove} aria-label={t('ruleBuilder.aria.removeGroup', {}, { defaultValue: 'Remove group' })} data-mol-id={`rule-builder-group-${props.group.id}-remove`}>
77
+ {t('ruleBuilder.action.removeGroup', {}, { defaultValue: 'Remove group' })}
78
+ </Button>
79
+ </Show>
80
+ </div>
81
+
82
+ <div class={cm.flex({ direction: 'col', gap: 'xs' })} style={styleProps(cm.sp({ p: 2 }))}>
83
+ <For each={props.group.children}>
84
+ {(child) => (<Show when={child.kind === 'group'} fallback={<Leaf leaf={child} schema={props.schema} onReplace={(next) => replaceChild(child.id, next)} onRemove={() => removeChild(child.id)}/>}>
85
+ <Group group={child} schema={props.schema} onReplace={(next) => replaceChild(child.id, next)} onRemove={() => removeChild(child.id)}/>
86
+ </Show>)}
87
+ </For>
88
+ </div>
89
+
90
+ <div class={cm.flex({ align: 'center', gap: 'xs' })}>
91
+ <Button variant="outline" size="sm" onClick={addCondition} data-mol-id={`rule-builder-group-${props.group.id}-add-condition`}>
92
+ {t('ruleBuilder.action.addCondition', {}, { defaultValue: '+ Add condition' })}
93
+ </Button>
94
+ <Button variant="ghost" size="sm" onClick={addGroup} data-mol-id={`rule-builder-group-${props.group.id}-add-group`}>
95
+ {t('ruleBuilder.action.addGroup', {}, { defaultValue: '+ Add group' })}
96
+ </Button>
97
+ </div>
98
+ </div>);
99
+ };
100
+ /**
101
+ * Render the value-side input(s) for a leaf, picking between
102
+ * text / number / date / select / boolean editors based on the field's
103
+ * `type` and the operator's `arity`.
104
+ *
105
+ * @param props - Value-editor props.
106
+ * @returns The rendered value editor.
107
+ */
108
+ const ValueEditor = (props) => {
109
+ const cm = getClassMap();
110
+ const { t } = useTranslation();
111
+ /** The `[from, to]` tuple, falling back to empty values. */
112
+ const tuple = () => {
113
+ const value = props.value;
114
+ if (Array.isArray(value) && value.length === 2)
115
+ return value;
116
+ return props.field.type === 'number' ? [0, 0] : ['', ''];
117
+ };
118
+ /**
119
+ * The input type the field renders.
120
+ *
121
+ * @returns The native input type.
122
+ */
123
+ const inputType = () => props.field.type === 'date' ? 'date' : props.field.type === 'number' ? 'number' : 'text';
124
+ const setFrom = (v) => {
125
+ const current = tuple();
126
+ props.onChange((props.field.type === 'number'
127
+ ? [Number(v), current[1]]
128
+ : [v, current[1]]));
129
+ };
130
+ const setTo = (v) => {
131
+ const current = tuple();
132
+ props.onChange((props.field.type === 'number'
133
+ ? [current[0], Number(v)]
134
+ : [current[0], v]));
135
+ };
136
+ return (<>
137
+ <Show when={props.arity === 'between'}>
138
+ <span class={cm.flex({ align: 'center', gap: 'xs' })}>
139
+ <Input type={inputType()} value={String(tuple()[0] ?? '')} onChange={(event) => setFrom(inputValue(event))} aria-label={t('ruleBuilder.aria.valueFrom', {}, { defaultValue: 'From' })}/>
140
+ <span>{t('ruleBuilder.between.separator', {}, { defaultValue: '–' })}</span>
141
+ <Input type={inputType()} value={String(tuple()[1] ?? '')} onChange={(event) => setTo(inputValue(event))} aria-label={t('ruleBuilder.aria.valueTo', {}, { defaultValue: 'To' })}/>
142
+ </span>
143
+ </Show>
144
+ <Show when={props.arity !== 'between' && props.field.type === 'select'}>
145
+ <Select value={typeof props.value === 'string' ? props.value : ''} onValueChange={(v) => props.onChange(v)} options={props.field.options ?? []} aria-label={t('ruleBuilder.aria.value', {}, { defaultValue: 'Value' })}/>
146
+ </Show>
147
+ <Show when={props.arity !== 'between' && props.field.type === 'boolean'}>
148
+ <Select value={props.value === true ? 'true' : props.value === false ? 'false' : ''} onValueChange={(v) => props.onChange(v === 'true')} options={[
149
+ { value: 'true', label: t('ruleBuilder.boolean.true', {}, { defaultValue: 'true' }) },
150
+ {
151
+ value: 'false',
152
+ label: t('ruleBuilder.boolean.false', {}, { defaultValue: 'false' }),
153
+ },
154
+ ]} aria-label={t('ruleBuilder.aria.value', {}, { defaultValue: 'Value' })}/>
155
+ </Show>
156
+ <Show when={props.arity !== 'between' &&
157
+ props.field.type !== 'select' &&
158
+ props.field.type !== 'boolean'}>
159
+ <Input type={inputType()} value={props.value === undefined ? '' : String(props.value)} onChange={(event) => {
160
+ const raw = inputValue(event);
161
+ props.onChange(props.field.type === 'number' ? Number(raw) : raw);
162
+ }} placeholder={props.field.placeholder} aria-label={t('ruleBuilder.aria.value', {}, { defaultValue: 'Value' })}/>
163
+ </Show>
164
+ </>);
165
+ };
166
+ /**
167
+ * Render a single field → operator → value row.
168
+ *
169
+ * @param props - Leaf renderer props.
170
+ * @returns The rendered leaf.
171
+ */
172
+ const Leaf = (props) => {
173
+ const cm = getClassMap();
174
+ const { t } = useTranslation();
175
+ const field = () => props.schema.fields.find((f) => f.name === props.leaf.field);
176
+ const ops = () => {
177
+ const f = field();
178
+ return f ? operatorsFor(f) : [];
179
+ };
180
+ const op = () => {
181
+ const f = field();
182
+ return f ? operatorById(f, props.leaf.op) : undefined;
183
+ };
184
+ const arity = () => op()?.arity ?? 'binary';
185
+ const setField = (name) => {
186
+ const f = props.schema.fields.find((x) => x.name === name);
187
+ const firstOp = f ? operatorsFor(f)[0] : undefined;
188
+ props.onReplace({
189
+ ...props.leaf,
190
+ field: name,
191
+ op: firstOp?.id ?? '',
192
+ value: undefined,
193
+ });
194
+ };
195
+ const setOp = (opId) => {
196
+ props.onReplace({ ...props.leaf, op: opId, value: undefined });
197
+ };
198
+ const setValue = (value) => {
199
+ props.onReplace({ ...props.leaf, value });
200
+ };
201
+ const fieldOptions = () => [
202
+ { value: '', label: t('ruleBuilder.field.placeholder', {}, { defaultValue: 'Select field…' }) },
203
+ ...props.schema.fields.map((f) => ({ value: f.name, label: f.label })),
204
+ ];
205
+ return (<div class={cm.flex({ align: 'center', gap: 'xs', wrap: 'wrap' })} data-mol-id={`rule-builder-leaf-${props.leaf.id}`}>
206
+ <Select value={props.leaf.field} onValueChange={setField} options={fieldOptions()} aria-label={t('ruleBuilder.aria.field', {}, { defaultValue: 'Field' })}/>
207
+ <Show when={field()}>
208
+ <Select value={props.leaf.op} onValueChange={setOp} options={ops().map((o) => ({ value: o.id, label: o.label }))} aria-label={t('ruleBuilder.aria.operator', {}, { defaultValue: 'Operator' })}/>
209
+ </Show>
210
+ <Show when={field() && op() && arity() !== 'unary'}>
211
+ <ValueEditor field={field()} arity={arity()} value={props.leaf.value} onChange={setValue}/>
212
+ </Show>
213
+ <Button variant="ghost" size="sm" onClick={props.onRemove} aria-label={t('ruleBuilder.aria.removeCondition', {}, {
214
+ defaultValue: 'Remove condition',
215
+ })} data-mol-id={`rule-builder-leaf-${props.leaf.id}-remove`}>
216
+ {t('ruleBuilder.action.removeCondition', {}, { defaultValue: 'Remove' })}
217
+ </Button>
218
+ </div>);
219
+ };
220
+ /**
221
+ * Visual rule / predicate builder. The rendered tree is a recursive
222
+ * `RuleGroup` of `RuleLeaf` predicates joined by `AND` or `OR`. The
223
+ * component is fully controlled — every interaction emits a new root
224
+ * rule via `onChange`.
225
+ *
226
+ * This is the Solid counterpart of `@molecule/app-rule-builder-react`'s
227
+ * `RuleBuilder`: the same props (React names), the same ClassMap tokens, and
228
+ * the same DOM for the same input.
229
+ *
230
+ * @param props - Component props (see {@link RuleBuilderProps}).
231
+ * @returns The rendered rule builder.
232
+ */
233
+ export const RuleBuilder = (props) => {
234
+ const cm = getClassMap();
235
+ /**
236
+ * The root group React renders: the given tree itself when it is a
237
+ * group, otherwise an implicit AND group wrapping the bare leaf.
238
+ *
239
+ * @returns The root group.
240
+ */
241
+ const rootGroup = () => props.rules.kind === 'group'
242
+ ? props.rules
243
+ : { kind: 'group', id: 'root', op: 'AND', children: [props.rules] };
244
+ return (<div class={cm.cn(cm.flex({ direction: 'col', gap: 'sm' }), props.className)} data-mol-id="rule-builder">
245
+ <Group group={rootGroup()} schema={props.schema} isRoot onReplace={(next) => props.onChange(next)} onRemove={() => props.onChange(emptyGroup())}/>
246
+ </div>);
247
+ };
248
+ //# sourceMappingURL=RuleBuilder.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuleBuilder.jsx","sourceRoot":"","sources":["../src/RuleBuilder.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,EAAE,YAA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AE,GAAG,CAAC,CACP,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,WAAW,GAAgC,CAAC,KAAK,EAAE,EAAE;IAChE,MAAM,EAAE,GAAG,WAAW,EAAE,CAAA;IAExB;;;;;OAKG;IACH,MAAM,SAAS,GAAG,GAAc,EAAE,CAChC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO;QAC1B,CAAC,CAAC,KAAK,CAAC,KAAK;QACb,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAA;IAEvE,OAAO,CACL,CAAC,GAAG,CACF,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CACxE,WAAW,CAAC,cAAc,CAE1B;MAAA,CAAC,KAAK,CACJ,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC,CACnB,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CACrB,MAAM,CACN,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAC1C,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAEjD;IAAA,EAAE,GAAG,CAAC,CACP,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Visual condition / rule builder for Solid.
3
+ *
4
+ * Exports:
5
+ * - `<RuleBuilder>` — controlled tree editor for AND / OR groups of
6
+ * field-operator-value leaves.
7
+ * - `RuleSchema`, `RuleField`, `RuleOperator`, `Rule`, `RuleGroup`,
8
+ * `RuleLeaf`, `RuleLeafValue`, `RuleGroupOp`, `RuleFieldType` types.
9
+ * - `defaultOperators`, `operatorsFor`, `operatorById`, `OP` operator
10
+ * catalog helpers.
11
+ * - `emptyGroup`, `emptyLeaf`, `replaceById`, `removeById`,
12
+ * `appendToGroup`, `toggleGroupOp`, `makeId` pure tree utilities.
13
+ *
14
+ * Used by feature-flag-manager (audience targeting),
15
+ * ai-workflow-automator (trigger conditions), email-marketing
16
+ * (segments), iot-device-manager + smart-home-dashboard (scenes /
17
+ * automations).
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { createSignal } from 'solid-js'
22
+ *
23
+ * import {
24
+ * RuleBuilder,
25
+ * emptyGroup,
26
+ * type Rule,
27
+ * type RuleSchema,
28
+ * } from '@molecule/app-rule-builder-solid'
29
+ *
30
+ * const schema: RuleSchema = {
31
+ * fields: [
32
+ * { name: 'country', label: 'Country', type: 'select', options: [{ value: 'US', label: 'United States' }] },
33
+ * { name: 'plan', label: 'Plan', type: 'text' },
34
+ * { name: 'spend', label: 'Spend', type: 'number' },
35
+ * ],
36
+ * }
37
+ *
38
+ * function Demo() {
39
+ * const [rules, setRules] = createSignal<Rule>(emptyGroup('AND'))
40
+ * return <RuleBuilder schema={schema} rules={rules()} onChange={setRules} />
41
+ * }
42
+ * ```
43
+ *
44
+ * @remarks
45
+ * - `<RuleBuilder>` throws unless rendered inside a Solid app whose
46
+ * `MoleculeProvider` supplies an i18n provider (bonded `@molecule/app-i18n`
47
+ * is the fallback) with a bonded ClassMap (`setClassMap()`).
48
+ * - Output is a plain JSON-serializable `Rule` tree — this package only
49
+ * renders and edits it. Evaluation (matching rows/users against the tree)
50
+ * is the app's job, typically server-side.
51
+ * - Fully controlled: keep the tree in a signal and pass it back via `rules`;
52
+ * start with `emptyGroup('AND')`.
53
+ * - Translations: registered companion bond `@molecule/app-locales-rule-builder`.
54
+ *
55
+ * @module
56
+ */
57
+ export * from './operators.js';
58
+ export * from './RuleBuilder.jsx';
59
+ export * from './types.js';
60
+ export * from './utilities.js';
61
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Visual condition / rule builder for Solid.
3
+ *
4
+ * Exports:
5
+ * - `<RuleBuilder>` — controlled tree editor for AND / OR groups of
6
+ * field-operator-value leaves.
7
+ * - `RuleSchema`, `RuleField`, `RuleOperator`, `Rule`, `RuleGroup`,
8
+ * `RuleLeaf`, `RuleLeafValue`, `RuleGroupOp`, `RuleFieldType` types.
9
+ * - `defaultOperators`, `operatorsFor`, `operatorById`, `OP` operator
10
+ * catalog helpers.
11
+ * - `emptyGroup`, `emptyLeaf`, `replaceById`, `removeById`,
12
+ * `appendToGroup`, `toggleGroupOp`, `makeId` pure tree utilities.
13
+ *
14
+ * Used by feature-flag-manager (audience targeting),
15
+ * ai-workflow-automator (trigger conditions), email-marketing
16
+ * (segments), iot-device-manager + smart-home-dashboard (scenes /
17
+ * automations).
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { createSignal } from 'solid-js'
22
+ *
23
+ * import {
24
+ * RuleBuilder,
25
+ * emptyGroup,
26
+ * type Rule,
27
+ * type RuleSchema,
28
+ * } from '@molecule/app-rule-builder-solid'
29
+ *
30
+ * const schema: RuleSchema = {
31
+ * fields: [
32
+ * { name: 'country', label: 'Country', type: 'select', options: [{ value: 'US', label: 'United States' }] },
33
+ * { name: 'plan', label: 'Plan', type: 'text' },
34
+ * { name: 'spend', label: 'Spend', type: 'number' },
35
+ * ],
36
+ * }
37
+ *
38
+ * function Demo() {
39
+ * const [rules, setRules] = createSignal<Rule>(emptyGroup('AND'))
40
+ * return <RuleBuilder schema={schema} rules={rules()} onChange={setRules} />
41
+ * }
42
+ * ```
43
+ *
44
+ * @remarks
45
+ * - `<RuleBuilder>` throws unless rendered inside a Solid app whose
46
+ * `MoleculeProvider` supplies an i18n provider (bonded `@molecule/app-i18n`
47
+ * is the fallback) with a bonded ClassMap (`setClassMap()`).
48
+ * - Output is a plain JSON-serializable `Rule` tree — this package only
49
+ * renders and edits it. Evaluation (matching rows/users against the tree)
50
+ * is the app's job, typically server-side.
51
+ * - Fully controlled: keep the tree in a signal and pass it back via `rules`;
52
+ * start with `emptyGroup('AND')`.
53
+ * - Translations: registered companion bond `@molecule/app-locales-rule-builder`.
54
+ *
55
+ * @module
56
+ */
57
+ export * from './operators.js';
58
+ export * from './RuleBuilder.jsx';
59
+ export * from './types.js';
60
+ export * from './utilities.js';
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Default operator catalogs per field type, plus a small helper that
3
+ * picks the catalog for a given field (preferring the field's own
4
+ * `operators` override when provided).
5
+ *
6
+ * All operator labels here use English fallbacks via `t(key, ..., {
7
+ * defaultValue })` at the call site — this module is consumed by
8
+ * `RuleBuilder.tsx`, which translates labels through the
9
+ * `@molecule/app-solid` i18n primitives before passing them to the
10
+ * dropdown.
11
+ *
12
+ * @module
13
+ */
14
+ import type { RuleField, RuleFieldType, RuleOperator } from './types.js';
15
+ /** Operator id constants — exported so consumers can inspect leaves. */
16
+ export declare const OP: {
17
+ readonly Equals: "eq";
18
+ readonly NotEquals: "neq";
19
+ readonly Contains: "contains";
20
+ readonly NotContains: "notContains";
21
+ readonly StartsWith: "startsWith";
22
+ readonly EndsWith: "endsWith";
23
+ readonly GreaterThan: "gt";
24
+ readonly GreaterThanOrEqual: "gte";
25
+ readonly LessThan: "lt";
26
+ readonly LessThanOrEqual: "lte";
27
+ readonly Between: "between";
28
+ readonly Before: "before";
29
+ readonly After: "after";
30
+ readonly IsTrue: "isTrue";
31
+ readonly IsFalse: "isFalse";
32
+ readonly IsEmpty: "isEmpty";
33
+ readonly IsNotEmpty: "isNotEmpty";
34
+ readonly In: "in";
35
+ readonly NotIn: "notIn";
36
+ };
37
+ /**
38
+ * Untranslated operator descriptors per field type.
39
+ *
40
+ * `RuleBuilder` translates each `label` at render time; the strings
41
+ * here are English fallbacks only, never shown directly.
42
+ */
43
+ export declare const defaultOperators: Record<RuleFieldType, RuleOperator[]>;
44
+ /**
45
+ * Resolve the operator catalog for `field`. Returns the field's own
46
+ * `operators` override when provided, otherwise the built-in catalog
47
+ * for the field's `type`.
48
+ *
49
+ * @param field - Field descriptor from the schema.
50
+ * @returns Operator catalog applicable to this field.
51
+ */
52
+ export declare function operatorsFor(field: RuleField): RuleOperator[];
53
+ /**
54
+ * Look up a single operator descriptor by id within `field`'s catalog.
55
+ *
56
+ * @param field - Field descriptor.
57
+ * @param opId - Operator id to look up.
58
+ * @returns The operator descriptor, or `undefined` if `opId` isn't in the catalog.
59
+ */
60
+ export declare function operatorById(field: RuleField, opId: string): RuleOperator | undefined;
61
+ //# sourceMappingURL=operators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../src/operators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAExE,wEAAwE;AACxE,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;CAoBL,CAAA;AAEV;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,aAAa,EAAE,YAAY,EAAE,CAkClE,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY,EAAE,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAErF"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Default operator catalogs per field type, plus a small helper that
3
+ * picks the catalog for a given field (preferring the field's own
4
+ * `operators` override when provided).
5
+ *
6
+ * All operator labels here use English fallbacks via `t(key, ..., {
7
+ * defaultValue })` at the call site — this module is consumed by
8
+ * `RuleBuilder.tsx`, which translates labels through the
9
+ * `@molecule/app-solid` i18n primitives before passing them to the
10
+ * dropdown.
11
+ *
12
+ * @module
13
+ */
14
+ /** Operator id constants — exported so consumers can inspect leaves. */
15
+ export const OP = {
16
+ Equals: 'eq',
17
+ NotEquals: 'neq',
18
+ Contains: 'contains',
19
+ NotContains: 'notContains',
20
+ StartsWith: 'startsWith',
21
+ EndsWith: 'endsWith',
22
+ GreaterThan: 'gt',
23
+ GreaterThanOrEqual: 'gte',
24
+ LessThan: 'lt',
25
+ LessThanOrEqual: 'lte',
26
+ Between: 'between',
27
+ Before: 'before',
28
+ After: 'after',
29
+ IsTrue: 'isTrue',
30
+ IsFalse: 'isFalse',
31
+ IsEmpty: 'isEmpty',
32
+ IsNotEmpty: 'isNotEmpty',
33
+ In: 'in',
34
+ NotIn: 'notIn',
35
+ };
36
+ /**
37
+ * Untranslated operator descriptors per field type.
38
+ *
39
+ * `RuleBuilder` translates each `label` at render time; the strings
40
+ * here are English fallbacks only, never shown directly.
41
+ */
42
+ export const defaultOperators = {
43
+ text: [
44
+ { id: OP.Equals, label: 'equals' },
45
+ { id: OP.NotEquals, label: 'does not equal' },
46
+ { id: OP.Contains, label: 'contains' },
47
+ { id: OP.NotContains, label: 'does not contain' },
48
+ { id: OP.StartsWith, label: 'starts with' },
49
+ { id: OP.EndsWith, label: 'ends with' },
50
+ { id: OP.IsEmpty, label: 'is empty', arity: 'unary' },
51
+ { id: OP.IsNotEmpty, label: 'is not empty', arity: 'unary' },
52
+ ],
53
+ number: [
54
+ { id: OP.Equals, label: '=' },
55
+ { id: OP.NotEquals, label: '≠' },
56
+ { id: OP.GreaterThan, label: '>' },
57
+ { id: OP.GreaterThanOrEqual, label: '≥' },
58
+ { id: OP.LessThan, label: '<' },
59
+ { id: OP.LessThanOrEqual, label: '≤' },
60
+ { id: OP.Between, label: 'between', arity: 'between' },
61
+ ],
62
+ date: [
63
+ { id: OP.Equals, label: 'on' },
64
+ { id: OP.Before, label: 'before' },
65
+ { id: OP.After, label: 'after' },
66
+ { id: OP.Between, label: 'between', arity: 'between' },
67
+ ],
68
+ select: [
69
+ { id: OP.Equals, label: 'is' },
70
+ { id: OP.NotEquals, label: 'is not' },
71
+ ],
72
+ boolean: [
73
+ { id: OP.IsTrue, label: 'is true', arity: 'unary' },
74
+ { id: OP.IsFalse, label: 'is false', arity: 'unary' },
75
+ ],
76
+ };
77
+ /**
78
+ * Resolve the operator catalog for `field`. Returns the field's own
79
+ * `operators` override when provided, otherwise the built-in catalog
80
+ * for the field's `type`.
81
+ *
82
+ * @param field - Field descriptor from the schema.
83
+ * @returns Operator catalog applicable to this field.
84
+ */
85
+ export function operatorsFor(field) {
86
+ return field.operators ?? defaultOperators[field.type] ?? [];
87
+ }
88
+ /**
89
+ * Look up a single operator descriptor by id within `field`'s catalog.
90
+ *
91
+ * @param field - Field descriptor.
92
+ * @param opId - Operator id to look up.
93
+ * @returns The operator descriptor, or `undefined` if `opId` isn't in the catalog.
94
+ */
95
+ export function operatorById(field, opId) {
96
+ return operatorsFor(field).find((o) => o.id === opId);
97
+ }
98
+ //# sourceMappingURL=operators.js.map
@@ -0,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