@molecule/app-rule-builder-angular 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,66 @@
1
+ /**
2
+ * Visual condition / rule builder for Angular.
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 { Component } from '@angular/core'
22
+ * import { emptyGroup, RuleBuilder, type Rule, type RuleSchema } from '@molecule/app-rule-builder-angular'
23
+ *
24
+ * const schema: RuleSchema = {
25
+ * fields: [
26
+ * { name: 'country', label: 'Country', type: 'select', options: [{ value: 'US', label: 'United States' }] },
27
+ * { name: 'plan', label: 'Plan', type: 'text' },
28
+ * { name: 'spend', label: 'Spend', type: 'number' },
29
+ * ],
30
+ * }
31
+ *
32
+ * @Component({
33
+ * selector: 'app-rules',
34
+ * standalone: true,
35
+ * imports: [RuleBuilder],
36
+ * template: `<div mol-rule-builder [schema]="schema" [rules]="rules" [onChange]="changed"></div>`,
37
+ * })
38
+ * export class Rules {
39
+ * readonly schema = schema
40
+ * rules: Rule = emptyGroup('AND')
41
+ *
42
+ * changed = (next: Rule): void => {
43
+ * this.rules = next
44
+ * }
45
+ * }
46
+ * ```
47
+ *
48
+ * @remarks
49
+ * - `<RuleBuilder>` needs an i18n provider (`provideMolecule({ i18n })` or the
50
+ * bonded `@molecule/app-i18n` provider) and a bonded ClassMap
51
+ * (`setClassMap()`); rendering throws otherwise.
52
+ * - Output is a plain JSON-serializable `Rule` tree — this package only
53
+ * renders and edits it. Evaluation (matching rows/users against the tree)
54
+ * is the app's job, typically server-side.
55
+ * - Fully controlled: keep the tree in a component field and pass it back via
56
+ * `rules`; start with `emptyGroup('AND')`. `onChange` receives the full new
57
+ * root rule as an input, an ordinary function.
58
+ * - Translations: registered companion bond `@molecule/app-locales-rule-builder`.
59
+ *
60
+ * @module
61
+ */
62
+ export * from './operators.js';
63
+ export * from './rule-builder.component.js';
64
+ export * from './types.js';
65
+ export * from './utilities.js';
66
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Visual condition / rule builder for Angular.
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 { Component } from '@angular/core'
22
+ * import { emptyGroup, RuleBuilder, type Rule, type RuleSchema } from '@molecule/app-rule-builder-angular'
23
+ *
24
+ * const schema: RuleSchema = {
25
+ * fields: [
26
+ * { name: 'country', label: 'Country', type: 'select', options: [{ value: 'US', label: 'United States' }] },
27
+ * { name: 'plan', label: 'Plan', type: 'text' },
28
+ * { name: 'spend', label: 'Spend', type: 'number' },
29
+ * ],
30
+ * }
31
+ *
32
+ * @Component({
33
+ * selector: 'app-rules',
34
+ * standalone: true,
35
+ * imports: [RuleBuilder],
36
+ * template: `<div mol-rule-builder [schema]="schema" [rules]="rules" [onChange]="changed"></div>`,
37
+ * })
38
+ * export class Rules {
39
+ * readonly schema = schema
40
+ * rules: Rule = emptyGroup('AND')
41
+ *
42
+ * changed = (next: Rule): void => {
43
+ * this.rules = next
44
+ * }
45
+ * }
46
+ * ```
47
+ *
48
+ * @remarks
49
+ * - `<RuleBuilder>` needs an i18n provider (`provideMolecule({ i18n })` or the
50
+ * bonded `@molecule/app-i18n` provider) and a bonded ClassMap
51
+ * (`setClassMap()`); rendering throws otherwise.
52
+ * - Output is a plain JSON-serializable `Rule` tree — this package only
53
+ * renders and edits it. Evaluation (matching rows/users against the tree)
54
+ * is the app's job, typically server-side.
55
+ * - Fully controlled: keep the tree in a component field and pass it back via
56
+ * `rules`; start with `emptyGroup('AND')`. `onChange` receives the full new
57
+ * root rule as an input, an ordinary function.
58
+ * - Translations: registered companion bond `@molecule/app-locales-rule-builder`.
59
+ *
60
+ * @module
61
+ */
62
+ export * from './operators.js';
63
+ export * from './rule-builder.component.js';
64
+ export * from './types.js';
65
+ export * from './utilities.js';
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,6BAA6B,CAAA;AAC3C,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
+ * `rule-builder.component.ts`, which translates labels through
9
+ * `@molecule/app-angular`'s i18n function 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
+ * `rule-builder.component.ts`, which translates labels through
9
+ * `@molecule/app-angular`'s i18n function 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,UAAU;IACpB,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,WAAW,EAAE,IAAI;IACjB,kBAAkB,EAAE,KAAK;IACzB,QAAQ,EAAE,IAAI;IACd,eAAe,EAAE,KAAK;IACtB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,UAAU,EAAE,YAAY;IACxB,EAAE,EAAE,IAAI;IACR,KAAK,EAAE,OAAO;CACN,CAAA;AAEV;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA0C;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