@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,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.ts`, which translates labels through the
9
+ * `@molecule/app-vue` i18n composable 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,0 +1 @@
1
+ {"version":3,"file":"operators.js","sourceRoot":"","sources":["../src/operators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,wEAAwE;AACxE,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,UA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IAC3C,OAAO,KAAK,CAAC,SAAS,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAgB,EAAE,IAAY;IACzD,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAA;AACvD,CAAC"}
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Rule-builder types — schema, operators, and recursive rule trees.
3
+ *
4
+ * The rule tree is a discriminated union: a `RuleGroup` contains an
5
+ * `op` (`AND` or `OR`) plus a list of children (themselves groups or
6
+ * leaves), and a `RuleLeaf` is a `{ field, op, value }` triple.
7
+ *
8
+ * The schema declares the available `fields`, each typed (text, number,
9
+ * date, select) so the builder can render the right value editor and
10
+ * filter the operator dropdown to operators that make sense for that
11
+ * type.
12
+ *
13
+ * @module
14
+ */
15
+ /**
16
+ * Logical join operator at a group level.
17
+ */
18
+ export type RuleGroupOp = 'AND' | 'OR';
19
+ /**
20
+ * Built-in field types supported by the default operator catalog and
21
+ * value editors. Consumers can supply custom operator lists per field
22
+ * if these don't fit.
23
+ */
24
+ export type RuleFieldType = 'text' | 'number' | 'date' | 'select' | 'boolean';
25
+ /**
26
+ * Operator descriptor — `id` is what's stored on the leaf, `label` is
27
+ * what's shown in the operator dropdown.
28
+ *
29
+ * `arity` controls how many value inputs are rendered:
30
+ * - `'unary'` — no value input (e.g. `is empty`, `exists`)
31
+ * - `'binary'` — one value input (default)
32
+ * - `'between'` — two value inputs (rendered as `from`/`to`)
33
+ */
34
+ export interface RuleOperator {
35
+ /** Operator id stored on the leaf. */
36
+ id: string;
37
+ /** Translated, human-readable label. */
38
+ label: string;
39
+ /** Number of value inputs to render. Default `'binary'`. */
40
+ arity?: 'unary' | 'binary' | 'between';
41
+ }
42
+ /**
43
+ * Field descriptor in the schema — the rule builder uses it to render
44
+ * the field dropdown, infer the value editor, and (when no explicit
45
+ * `operators` list is given) pick a default operator catalog by `type`.
46
+ */
47
+ export interface RuleField {
48
+ /** Stable field identifier stored on the leaf. */
49
+ name: string;
50
+ /** Translated, human-readable label shown in the field dropdown. */
51
+ label: string;
52
+ /** Built-in type used to pick the value editor + default operators. */
53
+ type: RuleFieldType;
54
+ /**
55
+ * Operators valid for this field. Optional — when omitted, the
56
+ * builder uses the default catalog for `type` from `defaultOperators`.
57
+ */
58
+ operators?: RuleOperator[];
59
+ /**
60
+ * For `type: 'select'` — the option list rendered as a `<Select>`.
61
+ * Ignored for other types.
62
+ */
63
+ options?: Array<{
64
+ value: string;
65
+ label: string;
66
+ }>;
67
+ /** Optional placeholder for text/number/date inputs. */
68
+ placeholder?: string;
69
+ }
70
+ /**
71
+ * Schema given to `<RuleBuilder>`. Currently only `fields` — kept as an
72
+ * object so future schema-level config (max depth, group limit, etc.)
73
+ * can be added without breaking the API.
74
+ */
75
+ export interface RuleSchema {
76
+ /** Available fields, in the order they appear in the field dropdown. */
77
+ fields: RuleField[];
78
+ }
79
+ /**
80
+ * Leaf rule — a single `field op value` predicate.
81
+ *
82
+ * `value` is opaque to the builder for `text` / `number` / `select` /
83
+ * `boolean` (it stores whatever the input produced — string for text /
84
+ * select / date, number for number, boolean for boolean). For `between`
85
+ * arity operators it's stored as a `[from, to]` two-element tuple.
86
+ */
87
+ export interface RuleLeaf {
88
+ /** Discriminator. */
89
+ kind: 'leaf';
90
+ /** Stable id (uuid-ish) — used for element identity + delete identity. */
91
+ id: string;
92
+ /** Field name from the schema. Empty string when unset. */
93
+ field: string;
94
+ /** Operator id from the field's operator catalog. Empty when unset. */
95
+ op: string;
96
+ /**
97
+ * Current value. `undefined` when unset. Encoding depends on the
98
+ * operator's `arity`:
99
+ * - `'unary'` — value is ignored.
100
+ * - `'binary'` — string | number | boolean.
101
+ * - `'between'` — `[from, to]` tuple.
102
+ */
103
+ value?: RuleLeafValue;
104
+ }
105
+ /** Possible leaf value encodings. See `RuleLeaf.value`. */
106
+ export type RuleLeafValue = string | number | boolean | [string, string] | [number, number];
107
+ /**
108
+ * Group rule — a logical conjunction (AND) or disjunction (OR) of
109
+ * children. Children may themselves be groups, allowing arbitrary
110
+ * nesting like `(A AND (B OR C) AND D)`.
111
+ */
112
+ export interface RuleGroup {
113
+ /** Discriminator. */
114
+ kind: 'group';
115
+ /** Stable id. */
116
+ id: string;
117
+ /** Logical operator joining the children. */
118
+ op: RuleGroupOp;
119
+ /** Child rules — groups or leaves, in display order. */
120
+ children: Rule[];
121
+ }
122
+ /** Either a group or a leaf. */
123
+ export type Rule = RuleGroup | RuleLeaf;
124
+ /** Public component props. */
125
+ export interface RuleBuilderProps {
126
+ /** Field catalog the user picks from. */
127
+ schema: RuleSchema;
128
+ /** Current rule tree (controlled). */
129
+ rules: Rule;
130
+ /**
131
+ * Called whenever the user mutates the tree — receives the full new
132
+ * root rule. Output is a deterministic JSON-serializable structure.
133
+ */
134
+ onChange: (next: Rule) => void;
135
+ /** Optional extra root-level class. */
136
+ className?: string;
137
+ }
138
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,IAAI,CAAA;AAEtC;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE7E;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,EAAE,EAAE,MAAM,CAAA;IACV,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAA;IACb,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;CACvC;AAED;;;;GAIG;AACH,MAA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MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,MAAM,EAAE,UAAU,CAAA;IAClB,sCAAsC;IACtC,KAAK,EAAE,IAAI,CAAA;IACX;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAC9B,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Rule-builder types — schema, operators, and recursive rule trees.
3
+ *
4
+ * The rule tree is a discriminated union: a `RuleGroup` contains an
5
+ * `op` (`AND` or `OR`) plus a list of children (themselves groups or
6
+ * leaves), and a `RuleLeaf` is a `{ field, op, value }` triple.
7
+ *
8
+ * The schema declares the available `fields`, each typed (text, number,
9
+ * date, select) so the builder can render the right value editor and
10
+ * filter the operator dropdown to operators that make sense for that
11
+ * type.
12
+ *
13
+ * @module
14
+ */
15
+ export {};
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Pure rule-tree utilities — id generation + immutable update helpers.
3
+ *
4
+ * Kept free of any UI framework so they're trivial to unit-test and to
5
+ * reuse from non-UI consumers (e.g. server-side validation, CLI tooling).
6
+ *
7
+ * @module
8
+ */
9
+ import type { Rule, RuleGroup, RuleGroupOp, RuleLeaf } from './types.js';
10
+ /**
11
+ * Generate a short non-cryptographic id. Sufficient for rendered element
12
+ * identity and in-memory rule identity within a single editing session.
13
+ *
14
+ * @returns A short random id.
15
+ */
16
+ export declare function makeId(): string;
17
+ /**
18
+ * Build a fresh empty leaf — used when the user clicks "Add condition".
19
+ *
20
+ * @returns A new leaf with all fields blank and a fresh id.
21
+ */
22
+ export declare function emptyLeaf(): RuleLeaf;
23
+ /**
24
+ * Build a fresh empty group — used when the user clicks "Add group".
25
+ *
26
+ * @param op - Initial group operator, defaults to `'AND'`.
27
+ * @returns A new group with one empty leaf already inside.
28
+ */
29
+ export declare function emptyGroup(op?: RuleGroupOp): RuleGroup;
30
+ /**
31
+ * Replace `target` (matched by id) anywhere in the tree with `replacement`.
32
+ *
33
+ * @param tree - Root of the rule tree.
34
+ * @param targetId - Id of the rule to replace.
35
+ * @param replacement - Replacement rule (same id is not required).
36
+ * @returns New tree with the replacement applied.
37
+ */
38
+ export declare function replaceById(tree: Rule, targetId: string, replacement: Rule): Rule;
39
+ /**
40
+ * Remove the rule with id `targetId` from the tree. The root itself
41
+ * cannot be removed — when `targetId` matches the root, the tree is
42
+ * returned unchanged.
43
+ *
44
+ * @param tree - Root of the rule tree.
45
+ * @param targetId - Id of the rule to remove.
46
+ * @returns New tree with the rule removed (or the original tree if no match).
47
+ */
48
+ export declare function removeById(tree: Rule, targetId: string): Rule;
49
+ /**
50
+ * Append `child` to the children of the group identified by `groupId`.
51
+ * If the id doesn't match any group, returns the tree unchanged.
52
+ *
53
+ * @param tree - Root of the rule tree.
54
+ * @param groupId - Id of the group to append to.
55
+ * @param child - Rule to append.
56
+ * @returns New tree with the child appended.
57
+ */
58
+ export declare function appendToGroup(tree: Rule, groupId: string, child: Rule): Rule;
59
+ /**
60
+ * Toggle a group's `op` between `'AND'` and `'OR'`.
61
+ *
62
+ * @param tree - Root of the rule tree.
63
+ * @param groupId - Id of the group to toggle.
64
+ * @returns New tree with the group's op flipped (or the original tree if no match).
65
+ */
66
+ export declare function toggleGroupOp(tree: Rule, groupId: string): Rule;
67
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAExE;;;;;GAKG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAE/B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,QAAQ,CAEpC;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,GAAE,WAAmB,GAAG,SAAS,CAE7D;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,GAAG,IAAI,CAOjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAM7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,CAS5E;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAS/D"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Pure rule-tree utilities — id generation + immutable update helpers.
3
+ *
4
+ * Kept free of any UI framework so they're trivial to unit-test and to
5
+ * reuse from non-UI consumers (e.g. server-side validation, CLI tooling).
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Generate a short non-cryptographic id. Sufficient for rendered element
11
+ * identity and in-memory rule identity within a single editing session.
12
+ *
13
+ * @returns A short random id.
14
+ */
15
+ export function makeId() {
16
+ return Math.random().toString(36).slice(2, 10);
17
+ }
18
+ /**
19
+ * Build a fresh empty leaf — used when the user clicks "Add condition".
20
+ *
21
+ * @returns A new leaf with all fields blank and a fresh id.
22
+ */
23
+ export function emptyLeaf() {
24
+ return { kind: 'leaf', id: makeId(), field: '', op: '' };
25
+ }
26
+ /**
27
+ * Build a fresh empty group — used when the user clicks "Add group".
28
+ *
29
+ * @param op - Initial group operator, defaults to `'AND'`.
30
+ * @returns A new group with one empty leaf already inside.
31
+ */
32
+ export function emptyGroup(op = 'AND') {
33
+ return { kind: 'group', id: makeId(), op, children: [emptyLeaf()] };
34
+ }
35
+ /**
36
+ * Replace `target` (matched by id) anywhere in the tree with `replacement`.
37
+ *
38
+ * @param tree - Root of the rule tree.
39
+ * @param targetId - Id of the rule to replace.
40
+ * @param replacement - Replacement rule (same id is not required).
41
+ * @returns New tree with the replacement applied.
42
+ */
43
+ export function replaceById(tree, targetId, replacement) {
44
+ if (tree.id === targetId)
45
+ return replacement;
46
+ if (tree.kind === 'leaf')
47
+ return tree;
48
+ return {
49
+ ...tree,
50
+ children: tree.children.map((c) => replaceById(c, targetId, replacement)),
51
+ };
52
+ }
53
+ /**
54
+ * Remove the rule with id `targetId` from the tree. The root itself
55
+ * cannot be removed — when `targetId` matches the root, the tree is
56
+ * returned unchanged.
57
+ *
58
+ * @param tree - Root of the rule tree.
59
+ * @param targetId - Id of the rule to remove.
60
+ * @returns New tree with the rule removed (or the original tree if no match).
61
+ */
62
+ export function removeById(tree, targetId) {
63
+ if (tree.kind === 'leaf')
64
+ return tree;
65
+ return {
66
+ ...tree,
67
+ children: tree.children.filter((c) => c.id !== targetId).map((c) => removeById(c, targetId)),
68
+ };
69
+ }
70
+ /**
71
+ * Append `child` to the children of the group identified by `groupId`.
72
+ * If the id doesn't match any group, returns the tree unchanged.
73
+ *
74
+ * @param tree - Root of the rule tree.
75
+ * @param groupId - Id of the group to append to.
76
+ * @param child - Rule to append.
77
+ * @returns New tree with the child appended.
78
+ */
79
+ export function appendToGroup(tree, groupId, child) {
80
+ if (tree.kind === 'leaf')
81
+ return tree;
82
+ if (tree.id === groupId) {
83
+ return { ...tree, children: [...tree.children, child] };
84
+ }
85
+ return {
86
+ ...tree,
87
+ children: tree.children.map((c) => appendToGroup(c, groupId, child)),
88
+ };
89
+ }
90
+ /**
91
+ * Toggle a group's `op` between `'AND'` and `'OR'`.
92
+ *
93
+ * @param tree - Root of the rule tree.
94
+ * @param groupId - Id of the group to toggle.
95
+ * @returns New tree with the group's op flipped (or the original tree if no match).
96
+ */
97
+ export function toggleGroupOp(tree, groupId) {
98
+ if (tree.kind === 'leaf')
99
+ return tree;
100
+ if (tree.id === groupId) {
101
+ return { ...tree, op: tree.op === 'AND' ? 'OR' : 'AND' };
102
+ }
103
+ return {
104
+ ...tree,
105
+ children: tree.children.map((c) => toggleGroupOp(c, groupId)),
106
+ };
107
+ }
108
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAA;AAC1D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAkB,KAAK;IAChD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,CAAA;AACrE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,QAAgB,EAAE,WAAiB;IACzE,IAAI,IAAI,CAAC,EAAE,KAAK,QAAQ;QAAE,OAAO,WAAW,CAAA;IAC5C,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,IAAI,CAAA;IACrC,OAAO;QACL,GAAG,IAAI;QACP,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EA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,EAAE,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAA;IAC1D,CAAC;IACD,OAAO;QACL,GAAG,IAAI;QACP,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;KAC9D,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@molecule/app-rule-builder-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Visual condition / rule builder — nested AND / OR groups of field-operator-value leaves, used for feature-flag targeting, automation triggers, segmentation, and IoT scenarios",
5
+ "homepage": "https://www.molecule.dev/packages/app-rule-builder-vue",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "vue-tsc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "rule",
28
+ "builder",
29
+ "predicate",
30
+ "condition",
31
+ "feature-flag",
32
+ "automation",
33
+ "vue"
34
+ ],
35
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
36
+ "license": "Apache-2.0",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/molecule-dev/molecule.git",
40
+ "directory": "packages/app/features/rule-builder-vue"
41
+ },
42
+ "engines": {
43
+ "node": ">=20"
44
+ },
45
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "peerDependencies": {
50
+ "@molecule/app-ui": "^1.0.1",
51
+ "@molecule/app-ui-vue": "^1.1.0",
52
+ "@molecule/app-vue": "^3.5.0",
53
+ "vue": "^3.4.0"
54
+ },
55
+ "devDependencies": {
56
+ "@molecule/app-framework-conformance": "0.0.0",
57
+ "@molecule/app-i18n": "1.2.2",
58
+ "@molecule/app-icons": "1.0.4",
59
+ "@molecule/app-ui": "1.5.0",
60
+ "@molecule/app-ui-vue": "1.2.1",
61
+ "@molecule/app-vue": "3.9.0",
62
+ "@types/node": "26.6.5",
63
+ "jsdom": "30.1.3",
64
+ "typescript": "6.0.3",
65
+ "vite": "8.3.5",
66
+ "vitest": "4.1.12",
67
+ "vue": "3.5.44",
68
+ "vue-tsc": "3.3.13"
69
+ }
70
+ }