@molecule/app-rule-builder-vue 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,55 @@
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 { type PropType, type VNode } from 'vue';
13
+ import type { Rule, RuleSchema } from './types.js';
14
+ /**
15
+ * Visual rule / predicate builder. The rendered tree is a recursive
16
+ * `RuleGroup` of `RuleLeaf` predicates joined by `AND` or `OR`. The
17
+ * component is fully controlled — every interaction emits a new root
18
+ * rule via `onChange`.
19
+ *
20
+ * Vue counterpart of `@molecule/app-rule-builder-react`'s `RuleBuilder` —
21
+ * the same props (React names) and the same DOM for the same input.
22
+ *
23
+ * @param props - Component props (see {@link RuleBuilderProps}).
24
+ * @returns The rendered rule builder.
25
+ */
26
+ export declare const RuleBuilder: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
27
+ schema: {
28
+ type: PropType<RuleSchema>;
29
+ required: true;
30
+ };
31
+ rules: {
32
+ type: PropType<Rule>;
33
+ required: true;
34
+ };
35
+ onChange: {
36
+ type: PropType<(next: Rule) => void>;
37
+ required: true;
38
+ };
39
+ className: StringConstructor;
40
+ }>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
41
+ schema: {
42
+ type: PropType<RuleSchema>;
43
+ required: true;
44
+ };
45
+ rules: {
46
+ type: PropType<Rule>;
47
+ required: true;
48
+ };
49
+ onChange: {
50
+ type: PropType<(next: Rule) => void>;
51
+ required: true;
52
+ };
53
+ className: StringConstructor;
54
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
55
+ //# sourceMappingURL=RuleBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuleBuilder.d.ts","sourceRoot":"","sources":["../src/RuleBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAsB,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAmB,MAAM,KAAK,CAAA;AAOpF,OAAO,KAAK,EAAE,IAAI,EAAiD,UAAU,EAAE,MAAM,YAAY,CAAA;AAkBjG;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW;;cAIF,QAAQ,CAAC,UAAU,CAAC;;;;cAIpB,QAAQ,CAAC,IAAI,CAAC;;;;cAIZ,QAAQ,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;;;;UAqVvC,KAAK;;cA7VE,QAAQ,CAAC,UAAU,CAAC;;;;cAIpB,QAAQ,CAAC,IAAI,CAAC;;;;cAIZ,QAAQ,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;;;;iGAsWpD,CAAA"}
@@ -0,0 +1,300 @@
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 { defineComponent, h } from 'vue';
13
+ import { getClassMap } from '@molecule/app-ui';
14
+ import { Button, Input, Select } from '@molecule/app-ui-vue';
15
+ import { useTranslation } from '@molecule/app-vue';
16
+ import { operatorById, operatorsFor } from './operators.js';
17
+ import { appendToGroup, emptyGroup, emptyLeaf, removeById, replaceById, toggleGroupOp, } from './utilities.js';
18
+ /**
19
+ * Reads the string a native input event carries.
20
+ *
21
+ * @param event - The native input event.
22
+ * @returns The input's current value.
23
+ */
24
+ const inputValue = (event) => event.target.value;
25
+ /**
26
+ * Visual rule / predicate builder. The rendered tree is a recursive
27
+ * `RuleGroup` of `RuleLeaf` predicates joined by `AND` or `OR`. The
28
+ * component is fully controlled — every interaction emits a new root
29
+ * rule via `onChange`.
30
+ *
31
+ * Vue counterpart of `@molecule/app-rule-builder-react`'s `RuleBuilder` —
32
+ * the same props (React names) and the same DOM for the same input.
33
+ *
34
+ * @param props - Component props (see {@link RuleBuilderProps}).
35
+ * @returns The rendered rule builder.
36
+ */
37
+ export const RuleBuilder = defineComponent({
38
+ name: 'RuleBuilder',
39
+ props: {
40
+ schema: {
41
+ type: Object,
42
+ required: true,
43
+ },
44
+ rules: {
45
+ type: Object,
46
+ required: true,
47
+ },
48
+ onChange: {
49
+ type: Function,
50
+ required: true,
51
+ },
52
+ className: String,
53
+ },
54
+ setup(props) {
55
+ const cm = getClassMap();
56
+ const { t } = useTranslation();
57
+ /**
58
+ * The root group React renders: the given tree itself when it is a
59
+ * group, otherwise an implicit AND group wrapping the bare leaf.
60
+ *
61
+ * @returns The root group.
62
+ */
63
+ const rootGroup = () => props.rules.kind === 'group'
64
+ ? props.rules
65
+ : { kind: 'group', id: 'root', op: 'AND', children: [props.rules] };
66
+ /**
67
+ * Render one group: the `AND` / `OR` toggle row, the children, and the
68
+ * "Add condition" / "Add group" buttons.
69
+ *
70
+ * @param group - The group to render.
71
+ * @param isRoot - Whether this is the root (which has no remove button).
72
+ * @param onReplace - Receives the group's replacement.
73
+ * @param onRemove - Removes this group from its parent.
74
+ * @returns The rendered group.
75
+ */
76
+ const renderGroup = (group, isRoot, onReplace, onRemove) => {
77
+ const toggle = () => {
78
+ onReplace(toggleGroupOp(group, group.id));
79
+ };
80
+ const addCondition = () => {
81
+ onReplace(appendToGroup(group, group.id, emptyLeaf()));
82
+ };
83
+ const addGroup = () => {
84
+ onReplace(appendToGroup(group, group.id, emptyGroup()));
85
+ };
86
+ const removeChild = (childId) => {
87
+ onReplace(removeById(group, childId));
88
+ };
89
+ const replaceChild = (childId, next) => {
90
+ onReplace(replaceById(group, childId, next));
91
+ };
92
+ const opLabel = group.op === 'AND'
93
+ ? t('ruleBuilder.op.and', {}, { defaultValue: 'AND' })
94
+ : t('ruleBuilder.op.or', {}, { defaultValue: 'OR' });
95
+ const children = group.children.map((child) => child.kind === 'group'
96
+ ? renderGroup(child, false, (next) => replaceChild(child.id, next), () => removeChild(child.id))
97
+ : renderLeaf(child, (next) => replaceChild(child.id, next), () => removeChild(child.id)));
98
+ const header = [
99
+ h(Button, {
100
+ variant: 'outline',
101
+ size: 'sm',
102
+ onClick: toggle,
103
+ 'aria-label': t('ruleBuilder.aria.toggleOp', {}, { defaultValue: 'Toggle AND / OR' }),
104
+ 'data-mol-id': `rule-builder-group-${group.id}-toggle`,
105
+ }, [opLabel]),
106
+ h('span', { class: cm.cn(cm.textSize('xs'), cm.textMuted) }, [
107
+ group.op === 'AND'
108
+ ? t('ruleBuilder.help.allMustMatch', {}, { defaultValue: 'All conditions must match' })
109
+ : t('ruleBuilder.help.anyMustMatch', {}, { defaultValue: 'Any condition may match' }),
110
+ ]),
111
+ ];
112
+ if (!isRoot)
113
+ header.push(h(Button, {
114
+ variant: 'ghost',
115
+ size: 'sm',
116
+ onClick: onRemove,
117
+ 'aria-label': t('ruleBuilder.aria.removeGroup', {}, { defaultValue: 'Remove group' }),
118
+ 'data-mol-id': `rule-builder-group-${group.id}-remove`,
119
+ }, [t('ruleBuilder.action.removeGroup', {}, { defaultValue: 'Remove group' })]));
120
+ return h('div', {
121
+ class: cm.cn(cm.flex({ direction: 'col', gap: 'xs' }), cm.borderAll, cm.surface),
122
+ style: cm.sp({ p: 3 }),
123
+ 'data-mol-id': `rule-builder-group-${group.id}`,
124
+ 'data-group-op': group.op,
125
+ }, [
126
+ h('div', { class: cm.flex({ align: 'center', gap: 'xs' }) }, header),
127
+ h('div', { class: cm.flex({ direction: 'col', gap: 'xs' }), style: cm.sp({ p: 2 }) }, children),
128
+ h('div', { class: cm.flex({ align: 'center', gap: 'xs' }) }, [
129
+ h(Button, {
130
+ variant: 'outline',
131
+ size: 'sm',
132
+ onClick: addCondition,
133
+ 'data-mol-id': `rule-builder-group-${group.id}-add-condition`,
134
+ }, [t('ruleBuilder.action.addCondition', {}, { defaultValue: '+ Add condition' })]),
135
+ h(Button, {
136
+ variant: 'ghost',
137
+ size: 'sm',
138
+ onClick: addGroup,
139
+ 'data-mol-id': `rule-builder-group-${group.id}-add-group`,
140
+ }, [t('ruleBuilder.action.addGroup', {}, { defaultValue: '+ Add group' })]),
141
+ ]),
142
+ ]);
143
+ };
144
+ /**
145
+ * Render the value-side input(s) for a leaf, picking between
146
+ * text / number / date / select / boolean editors based on the field's
147
+ * `type` and the operator's `arity`.
148
+ *
149
+ * @param field - The leaf's field descriptor.
150
+ * @param arity - The operator's arity (`binary` or `between`).
151
+ * @param value - The leaf's current value.
152
+ * @param onChange - Receives the next value.
153
+ * @returns The rendered value editor.
154
+ */
155
+ const renderValueEditor = (field, arity, value, onChange) => {
156
+ if (arity === 'between') {
157
+ const tuple = Array.isArray(value) && value.length === 2
158
+ ? value
159
+ : field.type === 'number'
160
+ ? [0, 0]
161
+ : ['', ''];
162
+ const inputType = field.type === 'date' ? 'date' : field.type === 'number' ? 'number' : 'text';
163
+ const setFrom = (v) => {
164
+ const next = (field.type === 'number'
165
+ ? [Number(v), tuple[1]]
166
+ : [v, tuple[1]]);
167
+ onChange(next);
168
+ };
169
+ const setTo = (v) => {
170
+ const next = (field.type === 'number'
171
+ ? [tuple[0], Number(v)]
172
+ : [tuple[0], v]);
173
+ onChange(next);
174
+ };
175
+ return h('span', { class: cm.flex({ align: 'center', gap: 'xs' }) }, [
176
+ h(Input, {
177
+ type: inputType,
178
+ value: String(tuple[0] ?? ''),
179
+ onChange: (event) => setFrom(inputValue(event)),
180
+ 'aria-label': t('ruleBuilder.aria.valueFrom', {}, { defaultValue: 'From' }),
181
+ }),
182
+ h('span', {}, [t('ruleBuilder.between.separator', {}, { defaultValue: '–' })]),
183
+ h(Input, {
184
+ type: inputType,
185
+ value: String(tuple[1] ?? ''),
186
+ onChange: (event) => setTo(inputValue(event)),
187
+ 'aria-label': t('ruleBuilder.aria.valueTo', {}, { defaultValue: 'To' }),
188
+ }),
189
+ ]);
190
+ }
191
+ if (field.type === 'select') {
192
+ const options = field.options ?? [];
193
+ return h(Select, {
194
+ value: typeof value === 'string' ? value : '',
195
+ onValueChange: (v) => onChange(v),
196
+ options,
197
+ 'aria-label': t('ruleBuilder.aria.value', {}, { defaultValue: 'Value' }),
198
+ });
199
+ }
200
+ if (field.type === 'boolean') {
201
+ const opts = [
202
+ { value: 'true', label: t('ruleBuilder.boolean.true', {}, { defaultValue: 'true' }) },
203
+ { value: 'false', label: t('ruleBuilder.boolean.false', {}, { defaultValue: 'false' }) },
204
+ ];
205
+ return h(Select, {
206
+ value: value === true ? 'true' : value === false ? 'false' : '',
207
+ onValueChange: (v) => onChange(v === 'true'),
208
+ options: opts,
209
+ 'aria-label': t('ruleBuilder.aria.value', {}, { defaultValue: 'Value' }),
210
+ });
211
+ }
212
+ const inputType = field.type === 'date' ? 'date' : field.type === 'number' ? 'number' : 'text';
213
+ return h(Input, {
214
+ type: inputType,
215
+ value: value === undefined ? '' : String(value),
216
+ onChange: (event) => {
217
+ const raw = inputValue(event);
218
+ onChange(field.type === 'number' ? Number(raw) : raw);
219
+ },
220
+ placeholder: field.placeholder,
221
+ 'aria-label': t('ruleBuilder.aria.value', {}, { defaultValue: 'Value' }),
222
+ });
223
+ };
224
+ /**
225
+ * Render a single field → operator → value row.
226
+ *
227
+ * @param leaf - The leaf to render.
228
+ * @param onReplace - Receives the leaf's replacement.
229
+ * @param onRemove - Removes this leaf from its group.
230
+ * @returns The rendered leaf.
231
+ */
232
+ const renderLeaf = (leaf, onReplace, onRemove) => {
233
+ const field = props.schema.fields.find((f) => f.name === leaf.field);
234
+ const ops = field ? operatorsFor(field) : [];
235
+ const op = field ? operatorById(field, leaf.op) : undefined;
236
+ const arity = op?.arity ?? 'binary';
237
+ const setField = (name) => {
238
+ const f = props.schema.fields.find((x) => x.name === name);
239
+ const firstOp = f ? operatorsFor(f)[0] : undefined;
240
+ onReplace({
241
+ ...leaf,
242
+ field: name,
243
+ op: firstOp?.id ?? '',
244
+ value: undefined,
245
+ });
246
+ };
247
+ const setOp = (opId) => {
248
+ onReplace({ ...leaf, op: opId, value: undefined });
249
+ };
250
+ const setValue = (value) => {
251
+ onReplace({ ...leaf, value });
252
+ };
253
+ const fieldOptions = [
254
+ {
255
+ value: '',
256
+ label: t('ruleBuilder.field.placeholder', {}, { defaultValue: 'Select field…' }),
257
+ },
258
+ ...props.schema.fields.map((f) => ({ value: f.name, label: f.label })),
259
+ ];
260
+ const operatorOptions = ops.map((o) => ({ value: o.id, label: o.label }));
261
+ const row = [
262
+ h(Select, {
263
+ value: leaf.field,
264
+ onValueChange: setField,
265
+ options: fieldOptions,
266
+ 'aria-label': t('ruleBuilder.aria.field', {}, { defaultValue: 'Field' }),
267
+ }),
268
+ ];
269
+ if (field)
270
+ row.push(h(Select, {
271
+ value: leaf.op,
272
+ onValueChange: setOp,
273
+ options: operatorOptions,
274
+ 'aria-label': t('ruleBuilder.aria.operator', {}, { defaultValue: 'Operator' }),
275
+ }));
276
+ if (field && op && arity !== 'unary')
277
+ row.push(renderValueEditor(field, arity, leaf.value, setValue));
278
+ row.push(h(Button, {
279
+ variant: 'ghost',
280
+ size: 'sm',
281
+ onClick: onRemove,
282
+ 'aria-label': t('ruleBuilder.aria.removeCondition', {}, {
283
+ defaultValue: 'Remove condition',
284
+ }),
285
+ 'data-mol-id': `rule-builder-leaf-${leaf.id}-remove`,
286
+ }, [t('ruleBuilder.action.removeCondition', {}, { defaultValue: 'Remove' })]));
287
+ return h('div', {
288
+ class: cm.flex({ align: 'center', gap: 'xs', wrap: 'wrap' }),
289
+ 'data-mol-id': `rule-builder-leaf-${leaf.id}`,
290
+ }, row);
291
+ };
292
+ return () => h('div', {
293
+ class: cm.cn(cm.flex({ direction: 'col', gap: 'sm' }), props.className),
294
+ 'data-mol-id': 'rule-builder',
295
+ }, [
296
+ renderGroup(rootGroup(), true, (next) => props.onChange(next), () => props.onChange(emptyGroup())),
297
+ ]);
298
+ },
299
+ });
300
+ //# sourceMappingURL=RuleBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RuleBuilder.js","sourceRoot":"","sources":["../src/RuleBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAA8C,MAAM,KAAK,CAAA;AAEpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE3D,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,aAAa,GACd,MAAM,gBAAgB,CAAA;AAEvB;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,KAAY,EAAU,EAAE,CAAE,KAAK,CAAC,MAA2B,CAAC,KAAK,CAAA;AAErF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC;IACzC,IAAI,EAAE,aAAa;IACnB,KAAK,EAAE;QACL,MAAM,EAAE;YACN,IAAI,EAAE,MAA8B;YACpC,QAAQ,EAAE,IAAI;SACf;QACD,KAAK,EAAE;YACL,IAAI,EAAE,MAAwB;YAC9B,QAAQ,EAAE,IAAI;SACf;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,QAA0C;YAChD,QAAQ,EAAE,IAAI;SACf;QACD,SAAS,EAAE,MAAM;KAClB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AAC;YACvE,aAAa,EAAE,cAAc;SAC9B,EACD;YACE,WAAW,CACT,SAAS,EAAE,EACX,IAAI,EACJ,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC9B,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CACnC;SACF,CACF,CAAA;IACL,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Visual condition / rule builder for Vue.
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
+ * ```ts
21
+ * import { createApp, defineComponent, h, ref } from 'vue'
22
+ *
23
+ * import {
24
+ * RuleBuilder,
25
+ * emptyGroup,
26
+ * type Rule,
27
+ * type RuleSchema,
28
+ * } from '@molecule/app-rule-builder-vue'
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
+ * const rules = ref<Rule>(emptyGroup('AND'))
39
+ *
40
+ * const App = defineComponent({
41
+ * setup() {
42
+ * return () =>
43
+ * h(RuleBuilder, {
44
+ * schema,
45
+ * rules: rules.value,
46
+ * onChange: (next: Rule) => {
47
+ * rules.value = next
48
+ * },
49
+ * })
50
+ * },
51
+ * })
52
+ *
53
+ * createApp(App).mount('#app')
54
+ * ```
55
+ *
56
+ * @remarks
57
+ * - `<RuleBuilder>` throws unless rendered inside a Vue app that provides an
58
+ * i18n provider (bonded `@molecule/app-i18n`, as `moleculePlugin` wires) with
59
+ * a bonded ClassMap (`setClassMap()`).
60
+ * - Output is a plain JSON-serializable `Rule` tree — this package only
61
+ * renders and edits it. Evaluation (matching rows/users against the tree)
62
+ * is the app's job, typically server-side.
63
+ * - Fully controlled: keep the tree in a `ref` and pass it back via `rules`;
64
+ * start with `emptyGroup('AND')`.
65
+ * - Translations: registered companion bond `@molecule/app-locales-rule-builder`.
66
+ *
67
+ * @module
68
+ */
69
+ export * from './operators.js';
70
+ export * from './RuleBuilder.js';
71
+ export * from './types.js';
72
+ export * from './utilities.js';
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Visual condition / rule builder for Vue.
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
+ * ```ts
21
+ * import { createApp, defineComponent, h, ref } from 'vue'
22
+ *
23
+ * import {
24
+ * RuleBuilder,
25
+ * emptyGroup,
26
+ * type Rule,
27
+ * type RuleSchema,
28
+ * } from '@molecule/app-rule-builder-vue'
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
+ * const rules = ref<Rule>(emptyGroup('AND'))
39
+ *
40
+ * const App = defineComponent({
41
+ * setup() {
42
+ * return () =>
43
+ * h(RuleBuilder, {
44
+ * schema,
45
+ * rules: rules.value,
46
+ * onChange: (next: Rule) => {
47
+ * rules.value = next
48
+ * },
49
+ * })
50
+ * },
51
+ * })
52
+ *
53
+ * createApp(App).mount('#app')
54
+ * ```
55
+ *
56
+ * @remarks
57
+ * - `<RuleBuilder>` throws unless rendered inside a Vue app that provides an
58
+ * i18n provider (bonded `@molecule/app-i18n`, as `moleculePlugin` wires) with
59
+ * a bonded ClassMap (`setClassMap()`).
60
+ * - Output is a plain JSON-serializable `Rule` tree — this package only
61
+ * renders and edits it. Evaluation (matching rows/users against the tree)
62
+ * is the app's job, typically server-side.
63
+ * - Fully controlled: keep the tree in a `ref` and pass it back via `rules`;
64
+ * start with `emptyGroup('AND')`.
65
+ * - Translations: registered companion bond `@molecule/app-locales-rule-builder`.
66
+ *
67
+ * @module
68
+ */
69
+ export * from './operators.js';
70
+ export * from './RuleBuilder.js';
71
+ export * from './types.js';
72
+ export * from './utilities.js';
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,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.ts`, which translates labels through the
9
+ * `@molecule/app-vue` i18n composable 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"}