@pibit.ai/cure-design-system 0.6.35 → 0.6.37

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.
Files changed (30) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +453 -425
  4. package/dist/patterns/condition-builder/add-action-button.d.ts +17 -0
  5. package/dist/patterns/condition-builder/add-action-button.d.ts.map +1 -0
  6. package/dist/patterns/condition-builder/add-action-button.js +26 -0
  7. package/dist/patterns/condition-builder/condition-builder.d.ts +4 -0
  8. package/dist/patterns/condition-builder/condition-builder.d.ts.map +1 -0
  9. package/dist/patterns/condition-builder/condition-builder.js +134 -0
  10. package/dist/patterns/condition-builder/condition-group.d.ts +4 -0
  11. package/dist/patterns/condition-builder/condition-group.d.ts.map +1 -0
  12. package/dist/patterns/condition-builder/condition-group.js +476 -0
  13. package/dist/patterns/condition-builder/condition-reorder-handle.d.ts +17 -0
  14. package/dist/patterns/condition-builder/condition-reorder-handle.d.ts.map +1 -0
  15. package/dist/patterns/condition-builder/condition-reorder-handle.js +66 -0
  16. package/dist/patterns/condition-builder/condition-row.d.ts +4 -0
  17. package/dist/patterns/condition-builder/condition-row.d.ts.map +1 -0
  18. package/dist/patterns/condition-builder/condition-row.js +238 -0
  19. package/dist/patterns/condition-builder/index.d.ts +43 -0
  20. package/dist/patterns/condition-builder/index.d.ts.map +1 -0
  21. package/dist/patterns/condition-builder/types.d.ts +342 -0
  22. package/dist/patterns/condition-builder/types.d.ts.map +1 -0
  23. package/dist/patterns/condition-builder/types.js +16 -0
  24. package/dist/patterns/condition-builder/utils.d.ts +73 -0
  25. package/dist/patterns/condition-builder/utils.d.ts.map +1 -0
  26. package/dist/patterns/condition-builder/utils.js +180 -0
  27. package/dist/patterns/condition-builder/utils.test.d.ts +2 -0
  28. package/dist/patterns/condition-builder/utils.test.d.ts.map +1 -0
  29. package/dist/styles/components.css +1 -1
  30. package/package.json +1 -1
@@ -0,0 +1,342 @@
1
+ import { ReactNode } from 'react';
2
+ /**
3
+ * Logical operator for combining conditions within a group
4
+ */
5
+ export type LogicalOperator = "AND" | "OR";
6
+ /**
7
+ * NodePath represents the path to a node in the condition tree.
8
+ * Each number is an index at that level.
9
+ * Example: [0, 2, 1] means: conditions[0].conditions[2].conditions[1]
10
+ */
11
+ export type NodePath = number[];
12
+ /**
13
+ * Minimal field shape so that domain types (e.g. FieldReference) without index
14
+ * signatures are assignable. Avoids [key: string]: unknown on sub-objects.
15
+ */
16
+ export interface BaseLeafConditionField {
17
+ type?: string;
18
+ path?: string;
19
+ data_type?: string;
20
+ }
21
+ /**
22
+ * Minimal value shape for condition RHS so that domain types are assignable.
23
+ * - value: string | number | [string, string] (between) etc.
24
+ * - unit: for relative date operators (after, before, etc.) e.g. "days" | "weeks" | "months" | "years"
25
+ */
26
+ export interface BaseLeafConditionValue {
27
+ type?: string;
28
+ value?: unknown;
29
+ unit?: string;
30
+ data_type?: string;
31
+ }
32
+ /**
33
+ * Base interface for a leaf condition (a single check)
34
+ * Consumers can extend this with additional fields as needed.
35
+ * No index signature on the interface so that strict types (e.g. LeafCondition
36
+ * with FieldReference) satisfy the constraint.
37
+ */
38
+ export interface BaseLeafCondition {
39
+ /** Field reference with path */
40
+ field?: BaseLeafConditionField;
41
+ /** Operator/check type (e.g., "equals", "exists", "empty") */
42
+ check?: string;
43
+ /** Value to compare against (optional for unary operators) */
44
+ value?: BaseLeafConditionValue;
45
+ }
46
+ /**
47
+ * Base interface for a group condition (contains nested conditions)
48
+ */
49
+ export interface BaseGroupCondition<TCondition = BaseCondition> {
50
+ /** Logical operator for combining child conditions */
51
+ operator: LogicalOperator;
52
+ /** Child conditions */
53
+ conditions: TCondition[];
54
+ }
55
+ /**
56
+ * Union type for either leaf or group condition
57
+ */
58
+ export type BaseCondition = BaseLeafCondition | BaseGroupCondition<BaseCondition>;
59
+ /**
60
+ * Type guard to check if condition is a group
61
+ */
62
+ export declare function isBaseGroupCondition<T extends object>(condition: T): condition is T & BaseGroupCondition<unknown>;
63
+ /**
64
+ * Type guard to check if condition is a leaf
65
+ */
66
+ export declare function isBaseLeafCondition<T extends object>(condition: T): condition is T & BaseLeafCondition;
67
+ /**
68
+ * Props passed to the custom leaf row renderer
69
+ */
70
+ export interface LeafRowRenderProps<TLeaf> {
71
+ /** The leaf condition data */
72
+ condition: TLeaf;
73
+ /** Path to this condition in the tree */
74
+ nodePath: NodePath;
75
+ /** Whether this is the first condition in its parent */
76
+ isFirst: boolean;
77
+ /** Callback when condition is updated */
78
+ onUpdate: (updates: Partial<TLeaf>) => void;
79
+ /** Callback when condition is deleted */
80
+ onDelete: () => void;
81
+ /** Whether this condition has validation errors */
82
+ isInvalid: boolean;
83
+ /** First validation error message for this row (optional) */
84
+ errorMessage?: string;
85
+ /** Component size */
86
+ size: "sm" | "md" | "lg";
87
+ /** Pointer down handler for drag handle - attach to your drag handle element */
88
+ onDragHandlePointerDown?: (e: React.PointerEvent) => void;
89
+ /** Callback when condition is duplicated via the drag-handle context menu */
90
+ onDuplicate?: () => void;
91
+ /** When true, hide/disable the row delete control */
92
+ isDeleteDisabled?: boolean;
93
+ /**
94
+ * `hideOperatorColumn` mode only: true when this row is the innermost hovered
95
+ * node, so exactly one drag handle is visible at a time. Undefined otherwise.
96
+ */
97
+ isDragHandleVisible?: boolean;
98
+ }
99
+ /** Context passed to `extraAddActions`. */
100
+ export interface ExtraAddActionsContext {
101
+ nodePath: NodePath;
102
+ level: number;
103
+ canAddNestedGroup: boolean;
104
+ }
105
+ /** Context passed to `renderCustomNode`. */
106
+ export interface CustomNodeRenderContext {
107
+ nodePath: NodePath;
108
+ index: number;
109
+ isFirst: boolean;
110
+ onDragHandlePointerDown?: (e: React.PointerEvent) => void;
111
+ onDuplicate?: () => void;
112
+ onDelete: () => void;
113
+ }
114
+ /** Context passed to `isDeleteDisabled`. */
115
+ export interface DeleteDisabledContext {
116
+ nodePath: NodePath;
117
+ siblingCount: number;
118
+ }
119
+ /**
120
+ * Configuration for the ConditionBuilder
121
+ *
122
+ * @template TCondition - The union type of all conditions (e.g. LeafCondition | GroupCondition)
123
+ * @template TLeaf - The leaf condition type; must extend TCondition and BaseLeafCondition
124
+ * @template TGroup - The group condition type; must extend TCondition and BaseGroupCondition
125
+ */
126
+ export interface ConditionBuilderConfig<TCondition, TLeaf extends TCondition & BaseLeafCondition, TGroup extends TCondition & BaseGroupCondition<TCondition>> {
127
+ /** Type guard to check if a condition is a leaf */
128
+ isLeafCondition: (condition: TCondition) => condition is TLeaf;
129
+ /** Type guard to check if a condition is a group */
130
+ isGroupCondition: (condition: TCondition) => condition is TGroup;
131
+ /** Factory function to create an empty leaf condition */
132
+ createEmptyLeaf: () => TLeaf;
133
+ /** Factory function to create an empty group with one leaf */
134
+ createEmptyGroup: (operator: LogicalOperator) => TGroup;
135
+ /** Get the operator from a group condition */
136
+ getGroupOperator: (group: TGroup) => LogicalOperator;
137
+ /** Get the conditions array from a group condition */
138
+ getGroupConditions: (group: TGroup) => TCondition[];
139
+ }
140
+ /**
141
+ * Props for the main ConditionBuilder component
142
+ */
143
+ export interface ConditionBuilderProps<TCondition, TLeaf extends TCondition & BaseLeafCondition, TGroup extends TCondition & BaseGroupCondition<TCondition>> {
144
+ /** The conditions array to render */
145
+ conditions: TCondition[];
146
+ /** Root logical operator (AND/OR) */
147
+ rootOperator: LogicalOperator;
148
+ /** Configuration with type guards and factories */
149
+ config: ConditionBuilderConfig<TCondition, TLeaf, TGroup>;
150
+ /** Callback when a condition is added */
151
+ onAddCondition: (parentPath: NodePath) => void;
152
+ /** Callback when a condition is updated */
153
+ onUpdateCondition: (path: NodePath, updates: Partial<TLeaf>) => void;
154
+ /** Callback when a condition is deleted */
155
+ onDeleteCondition: (path: NodePath) => void;
156
+ /** Callback when a group is added */
157
+ onAddGroup: (parentPath: NodePath) => void;
158
+ /** Callback when group operator is updated */
159
+ onUpdateGroupOperator: (path: NodePath, operator: LogicalOperator) => void;
160
+ /** Callback when a group is deleted */
161
+ onDeleteGroup: (path: NodePath) => void;
162
+ /** Callback when a leaf or group is duplicated (clone inserted after the node) */
163
+ onDuplicateCondition?: (path: NodePath) => void;
164
+ /** Callback when conditions are reordered (parent path + new order for that level) */
165
+ onReorder: (parentPath: NodePath, newOrder: TCondition[]) => void;
166
+ /** Callback when root operator is updated */
167
+ onUpdateRootOperator: (operator: LogicalOperator) => void;
168
+ /** Custom renderer for leaf conditions (optional) */
169
+ renderLeafRow?: (props: LeafRowRenderProps<TLeaf>) => ReactNode;
170
+ /** When true, leaf rows omit the generic Where/And/Or column (custom renderLeafRow owns it). */
171
+ hideOperatorColumn?: boolean;
172
+ /** Set of invalid condition paths (serialized as strings) */
173
+ invalidPaths?: Set<string>;
174
+ /** Optional: get first error message for a path (for inline hint) */
175
+ getErrorMessage?: (pathString: string) => string | undefined;
176
+ /** Maximum nesting depth (default: 3) */
177
+ maxDepth?: number;
178
+ /** Component size (default: "sm") */
179
+ size?: "sm" | "md" | "lg";
180
+ /** Label for empty state (e.g., "conditions" or "prerequisites") */
181
+ emptyStateLabel?: string;
182
+ /** Text for "Add Filter" button */
183
+ addFilterLabel?: string;
184
+ /** Text for "Add Filter Group" button */
185
+ addFilterGroupLabel?: string;
186
+ /** Optional className for the add-condition and add-group action buttons. */
187
+ addActionClassName?: string;
188
+ /** Optional className used by add actions inside nested groups. */
189
+ nestedAddActionClassName?: string;
190
+ /** Hides add and clear controls while retaining the configured condition tree. */
191
+ hideAddActions?: boolean;
192
+ /** Resolve operator options by field data type (e.g. from rules meta API). Used by default ConditionRow when no renderLeafRow. */
193
+ getOperatorOptions?: (dataType: string | undefined) => {
194
+ id: string;
195
+ label: string;
196
+ }[];
197
+ /** Optional className for the outer wrapper (default: "py-2") */
198
+ className?: string;
199
+ /** Optional className merged onto Reorder.Group for row spacing */
200
+ reorderGroupClassName?: string;
201
+ /**
202
+ * Extra add-action buttons (e.g. Add Document Condition). Omitted → identical default UI.
203
+ * Also rendered in the empty state. Consumer gates visibility via `canAddNestedGroup`.
204
+ */
205
+ extraAddActions?: (ctx: ExtraAddActionsContext) => ReactNode;
206
+ /**
207
+ * Custom node renderer. If it returns a node, that is used instead of leaf/group.
208
+ * Return null to fall through to the default leaf/group path.
209
+ */
210
+ renderCustomNode?: (condition: TCondition, ctx: CustomNodeRenderContext) => ReactNode | null;
211
+ /**
212
+ * When true for a node, hide/disable its delete control and skip it during Clear Group
213
+ * so the last remaining sibling is not removed.
214
+ */
215
+ isDeleteDisabled?: (ctx: DeleteDisabledContext) => boolean;
216
+ /**
217
+ * Show Clear Group on the builder root (level 0). Default false — the rule
218
+ * engine only shows Clear Group on nested group cards.
219
+ */
220
+ showRootClearGroup?: boolean;
221
+ /**
222
+ * Custom Clear Group handler for the builder root. Inner groups still use
223
+ * the default delete-all-children loop. Omitted → default loop at root too.
224
+ */
225
+ onRootClearGroup?: () => void;
226
+ }
227
+ /**
228
+ * Props for the ConditionGroup component
229
+ */
230
+ export interface ConditionGroupProps<TCondition, TLeaf extends TCondition & BaseLeafCondition, TGroup extends TCondition & BaseGroupCondition<TCondition>> {
231
+ /** The group condition data (or virtual root group) */
232
+ group: TGroup;
233
+ /** Path to this group in the tree */
234
+ nodePath: NodePath;
235
+ /** Current nesting level (0 = root) */
236
+ level: number;
237
+ /** Maximum nesting depth allowed */
238
+ maxDepth: number;
239
+ /** Whether this is the first item in its parent */
240
+ isFirst: boolean;
241
+ /** Parent's logical operator (for display between siblings) */
242
+ parentOperator?: LogicalOperator;
243
+ /** Configuration with type guards and factories */
244
+ config: ConditionBuilderConfig<TCondition, TLeaf, TGroup>;
245
+ /** Callback when a condition is added */
246
+ onAddCondition: (parentPath: NodePath) => void;
247
+ /** Callback when a condition is updated */
248
+ onUpdateCondition: (path: NodePath, updates: Partial<TLeaf>) => void;
249
+ /** Callback when a condition is deleted */
250
+ onDeleteCondition: (path: NodePath) => void;
251
+ /** Callback when a group is added */
252
+ onAddGroup: (parentPath: NodePath) => void;
253
+ /** Callback when group operator is updated */
254
+ onUpdateGroupOperator: (path: NodePath, operator: LogicalOperator) => void;
255
+ /** Callback when a group is deleted */
256
+ onDeleteGroup: (path: NodePath) => void;
257
+ /** Callback when a leaf or group is duplicated (clone inserted after the node) */
258
+ onDuplicateCondition?: (path: NodePath) => void;
259
+ /** Callback when conditions are reordered (parent path + new order for that level) */
260
+ onReorder: (parentPath: NodePath, newOrder: TCondition[]) => void;
261
+ /** Custom renderer for leaf conditions (optional) */
262
+ renderLeafRow?: (props: LeafRowRenderProps<TLeaf>) => ReactNode;
263
+ /** When true, leaf rows omit the generic Where/And/Or column (custom renderLeafRow owns it). */
264
+ hideOperatorColumn?: boolean;
265
+ /** Set of invalid condition paths */
266
+ invalidPaths: Set<string>;
267
+ /** Optional: get first error message for a path */
268
+ getErrorMessage?: (pathString: string) => string | undefined;
269
+ /** Component size */
270
+ size: "sm" | "md" | "lg";
271
+ /** Resolve operator options by field data type (e.g. from rules meta API). Passed to default ConditionRow. */
272
+ getOperatorOptions?: (dataType: string | undefined) => {
273
+ id: string;
274
+ label: string;
275
+ }[];
276
+ /** Text for "Add Filter" button */
277
+ addFilterLabel: string;
278
+ /** Text for "Add Filter Group" button */
279
+ addFilterGroupLabel: string;
280
+ /** Optional className for the add-condition and add-group action buttons. */
281
+ addActionClassName?: string;
282
+ /** Optional className used by add actions inside nested groups. */
283
+ nestedAddActionClassName?: string;
284
+ /** Hides add and clear controls while retaining the configured condition tree. */
285
+ hideAddActions?: boolean;
286
+ /** Optional className merged onto Reorder.Group for row spacing */
287
+ reorderGroupClassName?: string;
288
+ /** Extra add-action buttons. Omitted → identical default UI. */
289
+ extraAddActions?: (ctx: ExtraAddActionsContext) => ReactNode;
290
+ /** Custom node renderer. Return null to fall through to leaf/group. */
291
+ renderCustomNode?: (condition: TCondition, ctx: CustomNodeRenderContext) => ReactNode | null;
292
+ /** When true for a node, hide/disable delete and skip it during Clear Group. */
293
+ isDeleteDisabled?: (ctx: DeleteDisabledContext) => boolean;
294
+ /** Show Clear Group at this builder's root (level 0). Default false. */
295
+ showRootClearGroup?: boolean;
296
+ /** Custom Clear Group handler for the builder root. */
297
+ onRootClearGroup?: () => void;
298
+ }
299
+ /**
300
+ * Props for the default ConditionRow component
301
+ */
302
+ export interface ConditionRowProps<TLeaf> {
303
+ /** The leaf condition data */
304
+ condition: TLeaf;
305
+ /** Path to this condition in the tree */
306
+ nodePath: NodePath;
307
+ /** Whether this is the first condition in its parent */
308
+ isFirst: boolean;
309
+ /** Callback when condition is updated */
310
+ onUpdate: (updates: Partial<TLeaf>) => void;
311
+ /** Callback when condition is deleted */
312
+ onDelete: () => void;
313
+ /** Whether this condition has validation errors */
314
+ isInvalid?: boolean;
315
+ /** Set of invalid field types for this condition */
316
+ invalidFields?: Set<"field" | "check" | "value">;
317
+ /** First validation error message (optional) */
318
+ errorMessage?: string;
319
+ /** Component size */
320
+ size?: "sm" | "md" | "lg";
321
+ /** Resolve operator options by field data type (e.g. from rules meta API). When provided, used instead of placeholder list. */
322
+ getOperatorOptions?: (dataType: string | undefined) => {
323
+ id: string;
324
+ label: string;
325
+ }[];
326
+ /** Pointer down handler for drag handle - attach to your drag handle element */
327
+ onDragHandlePointerDown?: (e: React.PointerEvent) => void;
328
+ /** Callback when condition is duplicated (inserts a clone after this row) */
329
+ onDuplicate?: () => void;
330
+ /** When true, hide/disable the row delete control */
331
+ isDeleteDisabled?: boolean;
332
+ }
333
+ /**
334
+ * Validation error for a specific path
335
+ */
336
+ export interface ConditionValidationError {
337
+ path: NodePath;
338
+ pathString: string;
339
+ message: string;
340
+ field: "field" | "check" | "value" | "group";
341
+ }
342
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/patterns/condition-builder/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,K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OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC;IACjD,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB;IACrB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,+HAA+H;IAC/H,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,KAAK;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACvF,gFAAgF;IAChF,uBAAuB,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,YAAY,KAAK,IAAI,CAAC;IAC1D,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAMD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACrC,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;CAChD"}
@@ -0,0 +1,16 @@
1
+ function e(n) {
2
+ if (n === null || typeof n != "object")
3
+ return !1;
4
+ const o = n;
5
+ return "conditions" in o && Array.isArray(o.conditions) && "operator" in o && typeof o.operator == "string";
6
+ }
7
+ function i(n) {
8
+ if (n === null || typeof n != "object")
9
+ return !1;
10
+ const o = n, r = "field" in o || "check" in o, t = !("conditions" in o && Array.isArray(o.conditions));
11
+ return r && t;
12
+ }
13
+ export {
14
+ e as isBaseGroupCondition,
15
+ i as isBaseLeafCondition
16
+ };
@@ -0,0 +1,73 @@
1
+ import { NodePath, LogicalOperator, BaseLeafCondition, BaseGroupCondition, ConditionValidationError } from './types';
2
+ /**
3
+ * Serialize a path to a string for use as a key/Set member
4
+ */
5
+ export declare const pathToString: (path: NodePath) => string;
6
+ /**
7
+ * Parse a path string back to a NodePath
8
+ */
9
+ export declare const stringToPath: (pathString: string) => NodePath;
10
+ /**
11
+ * Get a condition at a specific path in the tree.
12
+ * Returns undefined if path is invalid.
13
+ */
14
+ export declare function getConditionAtPath<TCondition>(conditions: TCondition[], path: NodePath, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): TCondition | undefined;
15
+ /**
16
+ * Get the parent group at a specific path.
17
+ * Returns the conditions array and the parent path.
18
+ */
19
+ export declare function getParentAtPath<TCondition>(conditions: TCondition[], path: NodePath, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): {
20
+ parent: TCondition[];
21
+ parentPath: NodePath;
22
+ } | undefined;
23
+ /**
24
+ * Set (replace) a condition at a specific path.
25
+ * Returns a new conditions array with the update applied.
26
+ */
27
+ export declare function setConditionAtPath<TCondition>(conditions: TCondition[], path: NodePath, newCondition: TCondition, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): TCondition[];
28
+ /**
29
+ * Insert a condition at a specific path and index within that level.
30
+ * Path points to the parent group (or root if empty).
31
+ */
32
+ export declare function insertConditionAtPath<TCondition>(conditions: TCondition[], path: NodePath, index: number, newCondition: TCondition, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): TCondition[];
33
+ /**
34
+ * Remove a condition at a specific path.
35
+ * Returns a new conditions array with the removal applied.
36
+ */
37
+ export declare function removeConditionAtPath<TCondition>(conditions: TCondition[], path: NodePath, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): TCondition[];
38
+ /**
39
+ * Move a condition within the same level (reorder).
40
+ * fromIndex and toIndex are positions within the parent at parentPath.
41
+ */
42
+ export declare function moveConditionAtPath<TCondition>(conditions: TCondition[], parentPath: NodePath, fromIndex: number, toIndex: number, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): TCondition[];
43
+ /**
44
+ * Set the group operator at a specific path.
45
+ * The path must point to a GroupCondition.
46
+ */
47
+ export declare function setGroupOperatorAtPath<TCondition>(conditions: TCondition[], path: NodePath, operator: LogicalOperator, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): TCondition[];
48
+ /**
49
+ * Update a leaf condition at a specific path with partial updates.
50
+ */
51
+ export declare function updateLeafConditionAtPath<TCondition, TLeaf extends BaseLeafCondition>(conditions: TCondition[], path: NodePath, updates: Partial<TLeaf>, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>, isLeaf: (c: TCondition) => c is TCondition & TLeaf): TCondition[];
52
+ /**
53
+ * Deep-clone a condition (leaf or group) at `path` and insert the copy immediately after it.
54
+ */
55
+ export declare function duplicateConditionAtPath<TCondition>(conditions: TCondition[], path: NodePath, isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): TCondition[];
56
+ /**
57
+ * Count leaf conditions in the tree (recursive).
58
+ */
59
+ export declare function countLeafConditions<TCondition>(conditions: TCondition[], isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>, isLeaf: (c: TCondition) => boolean): number;
60
+ /**
61
+ * Count groups in the tree (recursive).
62
+ */
63
+ export declare function countGroups<TCondition>(conditions: TCondition[], isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>): number;
64
+ /**
65
+ * Validate the condition tree and return errors.
66
+ * Basic validation: field required, check required for leaves; non-empty for groups.
67
+ */
68
+ export declare function validateConditionTree<TCondition>(conditions: TCondition[], isGroup: (c: TCondition) => c is TCondition & BaseGroupCondition<TCondition>, isLeaf: (c: TCondition) => c is TCondition & BaseLeafCondition, basePath?: NodePath): ConditionValidationError[];
69
+ /**
70
+ * Get a set of invalid paths from validation errors
71
+ */
72
+ export declare const getInvalidPaths: (errors: ConditionValidationError[]) => Set<string>;
73
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/patterns/condition-builder/utils.ts"],"names":[],"mappings":"AAAA;;;;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)
7
+ return;
8
+ const n = e[r];
9
+ if (l.length === 0)
10
+ return n;
11
+ if (t(n))
12
+ return g(n.conditions, l, t);
13
+ }
14
+ function b(e, u, t) {
15
+ if (u.length === 0)
16
+ return { parent: e, parentPath: [] };
17
+ if (u.length === 1)
18
+ return { parent: e, parentPath: [] };
19
+ const r = u.slice(0, -1), l = g(e, r, t);
20
+ if (l && t(l))
21
+ return { parent: l.conditions, parentPath: r };
22
+ }
23
+ function c(e, u, t, r) {
24
+ if (u.length === 0)
25
+ return e;
26
+ const [l, ...n] = u;
27
+ return l < 0 || l >= e.length ? e : e.map((h, f) => f !== l ? h : n.length === 0 ? t : r(h) ? {
28
+ ...h,
29
+ conditions: c(h.conditions, n, t, r)
30
+ } : h);
31
+ }
32
+ function v(e, u, t, r, l) {
33
+ if (u.length === 0) {
34
+ const f = [...e];
35
+ return f.splice(t, 0, r), f;
36
+ }
37
+ const [n, ...h] = u;
38
+ return n < 0 || n >= e.length ? e : e.map((f, s) => s !== n ? f : h.length === 0 ? l(f) ? {
39
+ ...f,
40
+ conditions: [...f.conditions, r]
41
+ } : f : l(f) ? {
42
+ ...f,
43
+ conditions: v(f.conditions, h, t, r, l)
44
+ } : f);
45
+ }
46
+ function m(e, u, t) {
47
+ if (u.length === 0)
48
+ return e;
49
+ const [r, ...l] = u;
50
+ return r < 0 || r >= e.length ? e : l.length === 0 ? e.filter((n, h) => h !== r) : e.map((n, h) => h !== r ? n : t(n) ? {
51
+ ...n,
52
+ conditions: m(n.conditions, l, t)
53
+ } : n);
54
+ }
55
+ function C(e, u, t, r, l) {
56
+ if (t === r)
57
+ return e;
58
+ if (u.length === 0) {
59
+ const f = [...e], [s] = f.splice(t, 1);
60
+ return f.splice(r, 0, s), f;
61
+ }
62
+ const [n, ...h] = u;
63
+ return n < 0 || n >= e.length ? e : e.map((f, s) => {
64
+ if (s !== n) return f;
65
+ if (h.length === 0) {
66
+ if (l(f)) {
67
+ const a = [...f.conditions], [i] = a.splice(t, 1);
68
+ return a.splice(r, 0, i), {
69
+ ...f,
70
+ conditions: a
71
+ };
72
+ }
73
+ return f;
74
+ }
75
+ return l(f) ? {
76
+ ...f,
77
+ conditions: C(f.conditions, h, t, r, l)
78
+ } : f;
79
+ });
80
+ }
81
+ function p(e, u, t, r) {
82
+ if (u.length === 0)
83
+ return e;
84
+ const [l, ...n] = u;
85
+ return l < 0 || l >= e.length ? e : e.map((h, f) => f !== l ? h : n.length === 0 ? r(h) ? {
86
+ ...h,
87
+ operator: t
88
+ } : h : r(h) ? {
89
+ ...h,
90
+ conditions: p(h.conditions, n, t, r)
91
+ } : h);
92
+ }
93
+ function k(e, u, t, r, l) {
94
+ const n = g(e, u, r);
95
+ if (!n || !l(n))
96
+ return e;
97
+ const h = {
98
+ ...n,
99
+ ...t,
100
+ field: t.field ? { ...n.field, ...t.field } : n.field,
101
+ value: t.value ? { ...n.value, ...t.value } : n.value
102
+ };
103
+ return c(e, u, h, r);
104
+ }
105
+ function q(e, u, t) {
106
+ if (u.length === 0)
107
+ return e;
108
+ const r = g(e, u, t);
109
+ if (!r)
110
+ return e;
111
+ const l = structuredClone(r), n = u[u.length - 1], h = u.slice(0, -1);
112
+ if (h.length === 0) {
113
+ const a = [...e];
114
+ return a.splice(n + 1, 0, l), a;
115
+ }
116
+ const f = g(e, h, t);
117
+ if (!f || !t(f))
118
+ return e;
119
+ const s = [...f.conditions];
120
+ return s.splice(n + 1, 0, l), c(e, h, { ...f, conditions: s }, t);
121
+ }
122
+ function A(e, u, t) {
123
+ let r = 0;
124
+ for (const l of e)
125
+ t(l) ? r += 1 : u(l) && (r += A(l.conditions, u, t));
126
+ return r;
127
+ }
128
+ function x(e, u) {
129
+ let t = 0;
130
+ for (const r of e)
131
+ u(r) && (t += 1 + x(r.conditions, u));
132
+ return t;
133
+ }
134
+ function S(e, u, t, r = []) {
135
+ const l = [];
136
+ return e.forEach((n, h) => {
137
+ var a;
138
+ const f = [...r, h], s = P(f);
139
+ if (t(n))
140
+ (a = n.field) != null && a.path || l.push({
141
+ path: f,
142
+ pathString: s,
143
+ message: "Field is required",
144
+ field: "field"
145
+ }), n.check || l.push({
146
+ path: f,
147
+ pathString: s,
148
+ message: "Operator is required",
149
+ field: "check"
150
+ });
151
+ else if (u(n)) {
152
+ n.conditions.length === 0 && l.push({
153
+ path: f,
154
+ pathString: s,
155
+ message: "Group cannot be empty",
156
+ field: "group"
157
+ });
158
+ const i = S(n.conditions, u, t, f);
159
+ l.push(...i);
160
+ }
161
+ }), l;
162
+ }
163
+ const w = (e) => new Set(e.map((u) => u.pathString));
164
+ export {
165
+ x as countGroups,
166
+ A as countLeafConditions,
167
+ q as duplicateConditionAtPath,
168
+ g as getConditionAtPath,
169
+ w as getInvalidPaths,
170
+ b as getParentAtPath,
171
+ v as insertConditionAtPath,
172
+ C as moveConditionAtPath,
173
+ P as pathToString,
174
+ m as removeConditionAtPath,
175
+ c as setConditionAtPath,
176
+ p as setGroupOperatorAtPath,
177
+ T as stringToPath,
178
+ k as updateLeafConditionAtPath,
179
+ S as validateConditionTree
180
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../../src/patterns/condition-builder/utils.test.ts"],"names":[],"mappings":""}