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

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,17 @@
1
+ /**
2
+ * Drag handle that optionally opens a Duplicate menu on right-click.
3
+ * Left-button pointer down starts drag immediately (same as before).
4
+ */
5
+ /** Workflow builder handle look; pass via `className` (hideOperatorColumn mode only). */
6
+ export declare const WORKFLOW_REORDER_HANDLE_CLASS = "size-7 rounded-lg p-0 text-fg-quaternary transition-none hover:bg-transparent hover:text-fg-quaternary";
7
+ export interface ConditionReorderHandleProps {
8
+ /** Pointer-down / drag-start handler from the reorder list */
9
+ onDragHandlePointerDown?: (e: React.PointerEvent) => void;
10
+ /** When provided, right-click opens a menu with Duplicate */
11
+ onDuplicate?: () => void;
12
+ size?: "sm" | "md" | "lg";
13
+ className?: string;
14
+ }
15
+ export declare function ConditionReorderHandle({ onDragHandlePointerDown, onDuplicate, size, className, }: ConditionReorderHandleProps): import("react/jsx-runtime").JSX.Element;
16
+ export default ConditionReorderHandle;
17
+ //# sourceMappingURL=condition-reorder-handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-reorder-handle.d.ts","sourceRoot":"","sources":["../../../src/patterns/condition-builder/condition-reorder-handle.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,yFAAyF;AACzF,eAAO,MAAM,6BAA6B,2GACkE,CAAC;AAE7G,MAAM,WAAW,2BAA2B;IACxC,8DAA8D;IAC9D,uBAAuB,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,YAAY,KAAK,IAAI,CAAC;IAC1D,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,sBAAsB,CAAC,EACnC,uBAAuB,EACvB,WAAW,EACX,IAAW,EACX,SAAS,GACZ,EAAE,2BAA2B,2CAyD7B;AAED,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { jsx as r, jsxs as p } from "react/jsx-runtime";
2
+ import { useState as d, useRef as h } from "react";
3
+ import { Button as x } from "react-aria-components";
4
+ import { Copy01 as b } from "@untitledui/icons";
5
+ import { cx as R } from "../../utils/cn.js";
6
+ import { ReorderDots8x14 as l } from "../../primitives/custom-icon/icons/reorder-dots-8x14.js";
7
+ import { Dropdown as o } from "../../primitives/dropdown/dropdown.js";
8
+ const u = {
9
+ sm: "size-4",
10
+ md: "size-5",
11
+ lg: "size-6"
12
+ }, S = "size-7 rounded-lg p-0 text-fg-quaternary transition-none hover:bg-transparent hover:text-fg-quaternary";
13
+ function _({
14
+ onDragHandlePointerDown: t,
15
+ onDuplicate: a,
16
+ size: i = "sm",
17
+ className: m
18
+ }) {
19
+ const [f, n] = d(!1), s = h(!1), c = R(
20
+ "flex cursor-grab items-center justify-center rounded-md p-1 text-quaternary transition-colors hover:bg-secondary_hover hover:text-secondary active:cursor-grabbing select-none touch-none",
21
+ m
22
+ );
23
+ return a ? /* @__PURE__ */ p(
24
+ o.Root,
25
+ {
26
+ isOpen: f,
27
+ onOpenChange: (e) => {
28
+ if (e) {
29
+ if (!s.current) return;
30
+ s.current = !1;
31
+ }
32
+ n(e);
33
+ },
34
+ children: [
35
+ /* @__PURE__ */ r(
36
+ x,
37
+ {
38
+ "aria-label": "Drag to reorder. Right-click for more actions",
39
+ className: c,
40
+ onPointerDown: (e) => {
41
+ e.button === 0 && (n(!1), t == null || t(e));
42
+ },
43
+ onContextMenu: (e) => {
44
+ e.preventDefault(), e.stopPropagation(), s.current = !0, n(!0);
45
+ },
46
+ children: /* @__PURE__ */ r(l, { color: "currentColor", className: u[i] })
47
+ }
48
+ ),
49
+ /* @__PURE__ */ r(o.Popover, { className: "w-min", placement: "bottom end", children: /* @__PURE__ */ r(
50
+ o.Menu,
51
+ {
52
+ onAction: (e) => {
53
+ e === "duplicate" && a();
54
+ },
55
+ children: /* @__PURE__ */ r(o.Item, { id: "duplicate", icon: b, label: "Duplicate" })
56
+ }
57
+ ) })
58
+ ]
59
+ }
60
+ ) : /* @__PURE__ */ r("div", { className: c, onPointerDown: t, "aria-label": "Drag to reorder", children: /* @__PURE__ */ r(l, { color: "currentColor", className: u[i] }) });
61
+ }
62
+ export {
63
+ _ as ConditionReorderHandle,
64
+ S as WORKFLOW_REORDER_HANDLE_CLASS,
65
+ _ as default
66
+ };
@@ -0,0 +1,4 @@
1
+ import { ConditionRowProps, BaseLeafCondition } from './types';
2
+ export declare function ConditionRow<TLeaf extends BaseLeafCondition>({ condition, nodePath: _nodePath, isFirst: _isFirst, onUpdate, onDelete, isInvalid, invalidFields, errorMessage, size, getOperatorOptions, onDragHandlePointerDown, onDuplicate, isDeleteDisabled, }: ConditionRowProps<TLeaf>): import("react/jsx-runtime").JSX.Element;
3
+ export default ConditionRow;
4
+ //# sourceMappingURL=condition-row.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-row.d.ts","sourceRoot":"","sources":["../../../src/patterns/condition-builder/condition-row.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AA4BpE,wBAAgB,YAAY,CAAC,KAAK,SAAS,iBAAiB,EAAE,EAC1D,SAAS,EACT,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,QAAQ,EACjB,QAAQ,EACR,QAAQ,EACR,SAAiB,EACjB,aAAyB,EACzB,YAAY,EACZ,IAAW,EACX,kBAAkB,EAClB,uBAAuB,EACvB,WAAW,EACX,gBAAwB,GAC3B,EAAE,iBAAiB,CAAC,KAAK,CAAC,2CAoP1B;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,238 @@
1
+ import { jsxs as h, jsx as t, Fragment as I } from "react/jsx-runtime";
2
+ import { useMemo as g } from "react";
3
+ import { Trash02 as U } from "@untitledui/icons";
4
+ import { cx as p } from "../../utils/cn.js";
5
+ import { ConditionReorderHandle as X } from "./condition-reorder-handle.js";
6
+ import { Input as f } from "../../primitives/input/input.js";
7
+ import { Select as x } from "../../primitives/select/select.js";
8
+ import { ButtonUtility as Z } from "../../primitives/button/button-utility.js";
9
+ const Y = /* @__PURE__ */ new Set(["exists", "notExists", "empty", "notEmpty"]), j = "between", L = /* @__PURE__ */ new Set(["after", "before", "onOrBefore", "onOrAfter"]), $ = [
10
+ { id: "days", label: "days" },
11
+ { id: "weeks", label: "weeks" },
12
+ { id: "months", label: "months" },
13
+ { id: "years", label: "years" }
14
+ ];
15
+ function he({
16
+ condition: a,
17
+ nodePath: z,
18
+ isFirst: ee,
19
+ onUpdate: i,
20
+ onDelete: D,
21
+ isInvalid: w = !1,
22
+ invalidFields: u = /* @__PURE__ */ new Set(),
23
+ errorMessage: N,
24
+ size: s = "sm",
25
+ getOperatorOptions: o,
26
+ onDragHandlePointerDown: F,
27
+ onDuplicate: H,
28
+ isDeleteDisabled: W = !1
29
+ }) {
30
+ var A, R, E, T, B, P, K, O, V;
31
+ const m = a.check || "", C = (A = a.field) == null ? void 0 : A.data_type, q = g(() => {
32
+ const e = (o == null ? void 0 : o(C)) ?? [];
33
+ return [{ id: "", label: "Select operator" }, ...e];
34
+ }, [o, C]), d = g(() => Y.has(m), [m]), S = g(() => m === j, [m]), _ = g(() => L.has(m), [m]), G = (e) => {
35
+ i({
36
+ field: {
37
+ ...a.field,
38
+ path: e
39
+ }
40
+ });
41
+ }, J = (e) => {
42
+ var c, v;
43
+ if (!e) return;
44
+ const l = { check: e }, n = ((c = a.field) == null ? void 0 : c.data_type) || "string";
45
+ if (Y.has(e))
46
+ l.value = void 0;
47
+ else if (e === j) {
48
+ const r = (v = a.value) == null ? void 0 : v.value, y = Array.isArray(r) ? r : [r ?? "", r ?? ""];
49
+ l.value = {
50
+ type: "static",
51
+ value: [String(y[0] ?? ""), String(y[1] ?? "")],
52
+ data_type: n
53
+ };
54
+ } else if (L.has(e)) {
55
+ const r = a.value, y = typeof (r == null ? void 0 : r.value) == "number" ? r.value : parseInt(String((r == null ? void 0 : r.value) ?? 0), 10), Q = (r == null ? void 0 : r.unit) === "days" || (r == null ? void 0 : r.unit) === "weeks" || (r == null ? void 0 : r.unit) === "months" || (r == null ? void 0 : r.unit) === "years" ? r.unit : "days";
56
+ l.value = {
57
+ type: "static",
58
+ value: Number.isNaN(y) ? 0 : y,
59
+ unit: Q,
60
+ data_type: "date"
61
+ };
62
+ } else a.value || (l.value = {
63
+ type: "static",
64
+ value: "",
65
+ data_type: n
66
+ });
67
+ i(l);
68
+ }, M = (e) => {
69
+ var l;
70
+ i({
71
+ value: {
72
+ ...a.value,
73
+ type: "static",
74
+ value: e,
75
+ data_type: ((l = a.field) == null ? void 0 : l.data_type) || "string"
76
+ }
77
+ });
78
+ }, b = (e, l) => {
79
+ var c, v;
80
+ const n = Array.isArray((c = a.value) == null ? void 0 : c.value) ? [...a.value.value] : ["", ""];
81
+ n[e] = l, i({
82
+ value: {
83
+ ...a.value,
84
+ type: "static",
85
+ value: n,
86
+ data_type: ((v = a.field) == null ? void 0 : v.data_type) || "string"
87
+ }
88
+ });
89
+ }, k = (e, l) => {
90
+ i({
91
+ value: {
92
+ ...a.value,
93
+ type: "static",
94
+ value: e,
95
+ unit: l,
96
+ data_type: "date"
97
+ }
98
+ });
99
+ };
100
+ return /* @__PURE__ */ h("div", { className: "flex flex-col gap-1 w-full min-w-0", children: [
101
+ /* @__PURE__ */ h("div", { className: "flex items-center gap-2 group min-w-0", children: [
102
+ /* @__PURE__ */ h("div", { className: "flex min-w-0 flex-1 shrink items-center gap-2 overflow-hidden", children: [
103
+ /* @__PURE__ */ t(
104
+ f,
105
+ {
106
+ size: s,
107
+ wrapperClassName: p(
108
+ "min-w-0 max-w-[220px] flex-1 shrink",
109
+ (w || u.has("field")) && "!ring-2 !ring-error"
110
+ ),
111
+ placeholder: "Field path (e.g., ACORD.effective_date)",
112
+ value: ((R = a.field) == null ? void 0 : R.path) || "",
113
+ onChange: (e) => G(e)
114
+ }
115
+ ),
116
+ /* @__PURE__ */ t(
117
+ x,
118
+ {
119
+ size: s,
120
+ className: p(
121
+ "min-w-0 max-w-[180px] flex-1 shrink",
122
+ (w || u.has("check")) && "[&>button]:ring-2 [&>button]:ring-error"
123
+ ),
124
+ placeholder: "Select operator",
125
+ selectedKey: a.check || "",
126
+ onSelectionChange: (e) => J(e),
127
+ items: q,
128
+ children: (e) => /* @__PURE__ */ t(x.Item, { id: e.id, children: e.label })
129
+ }
130
+ ),
131
+ !d && S && /* @__PURE__ */ h(I, { children: [
132
+ /* @__PURE__ */ t(
133
+ f,
134
+ {
135
+ size: s,
136
+ wrapperClassName: p(
137
+ "min-w-0 max-w-[160px] flex-1 shrink",
138
+ u.has("value") && "!ring-2 !ring-error"
139
+ ),
140
+ placeholder: "From",
141
+ value: Array.isArray((E = a.value) == null ? void 0 : E.value) ? String(a.value.value[0] ?? "") : "",
142
+ onChange: (e) => b(0, e)
143
+ }
144
+ ),
145
+ /* @__PURE__ */ t("span", { className: "text-sm text-tertiary shrink-0", children: "to" }),
146
+ /* @__PURE__ */ t(
147
+ f,
148
+ {
149
+ size: s,
150
+ wrapperClassName: p(
151
+ "min-w-0 max-w-[160px] flex-1 shrink",
152
+ u.has("value") && "!ring-2 !ring-error"
153
+ ),
154
+ placeholder: "To",
155
+ value: Array.isArray((T = a.value) == null ? void 0 : T.value) ? String(a.value.value[1] ?? "") : "",
156
+ onChange: (e) => b(1, e)
157
+ }
158
+ )
159
+ ] }),
160
+ !d && _ && /* @__PURE__ */ h(I, { children: [
161
+ /* @__PURE__ */ t(
162
+ f,
163
+ {
164
+ size: s,
165
+ wrapperClassName: p(
166
+ "min-w-0 max-w-[72px] shrink-0",
167
+ u.has("value") && "!ring-2 !ring-error"
168
+ ),
169
+ inputType: "number",
170
+ placeholder: "0",
171
+ value: typeof ((B = a.value) == null ? void 0 : B.value) == "number" ? String(a.value.value) : String(((P = a.value) == null ? void 0 : P.value) ?? ""),
172
+ onChange: (e) => {
173
+ var n;
174
+ const l = parseInt(String(e), 10);
175
+ k(Number.isNaN(l) ? 0 : l, ((n = a.value) == null ? void 0 : n.unit) ?? "days");
176
+ }
177
+ }
178
+ ),
179
+ /* @__PURE__ */ t(
180
+ x,
181
+ {
182
+ size: s,
183
+ className: "min-w-0 max-w-[100px] shrink",
184
+ selectedKey: ((K = a.value) == null ? void 0 : K.unit) ?? "days",
185
+ onSelectionChange: (e) => {
186
+ var l;
187
+ return k(
188
+ typeof ((l = a.value) == null ? void 0 : l.value) == "number" ? a.value.value : 0,
189
+ e || "days"
190
+ );
191
+ },
192
+ items: $,
193
+ children: (e) => /* @__PURE__ */ t(x.Item, { id: e.id, children: e.label })
194
+ }
195
+ )
196
+ ] }),
197
+ !d && !S && !_ && /* @__PURE__ */ t(
198
+ f,
199
+ {
200
+ size: s,
201
+ wrapperClassName: p(
202
+ "min-w-0 max-w-[220px] flex-1 shrink",
203
+ u.has("value") && "!ring-2 !ring-error"
204
+ ),
205
+ placeholder: "Value",
206
+ value: typeof ((O = a.value) == null ? void 0 : O.value) == "string" ? a.value.value : String(((V = a.value) == null ? void 0 : V.value) ?? ""),
207
+ onChange: (e) => M(e)
208
+ }
209
+ )
210
+ ] }),
211
+ /* @__PURE__ */ h("div", { className: "flex shrink-0 items-center gap-1", children: [
212
+ !W && /* @__PURE__ */ t(
213
+ Z,
214
+ {
215
+ "aria-label": "Remove condition",
216
+ icon: () => /* @__PURE__ */ t(U, { size: 18 }),
217
+ color: "tertiary",
218
+ size: "xs",
219
+ onClick: D
220
+ }
221
+ ),
222
+ /* @__PURE__ */ t(
223
+ X,
224
+ {
225
+ size: s,
226
+ onDragHandlePointerDown: F,
227
+ onDuplicate: H
228
+ }
229
+ )
230
+ ] })
231
+ ] }),
232
+ N && /* @__PURE__ */ t("p", { className: "text-sm text-error pl-1", role: "alert", children: N })
233
+ ] });
234
+ }
235
+ export {
236
+ he as ConditionRow,
237
+ he as default
238
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Condition Builder - Generic Reusable Component
3
+ *
4
+ * A flexible, recursive condition builder that can be used in any context.
5
+ * Pass your own types, type guards, and factory functions via the config prop.
6
+ *
7
+ * Example usage:
8
+ * ```tsx
9
+ * import { ConditionBuilder, type ConditionBuilderConfig } from '@/components/application/condition-builder';
10
+ *
11
+ * // Define your condition types
12
+ * interface MyLeafCondition { field: string; operator: string; value: string; }
13
+ * interface MyGroupCondition { operator: 'AND' | 'OR'; conditions: MyCondition[]; }
14
+ * type MyCondition = MyLeafCondition | MyGroupCondition;
15
+ *
16
+ * // Create config
17
+ * const config: ConditionBuilderConfig<MyLeafCondition, MyGroupCondition, MyCondition> = {
18
+ * isLeafCondition: (c): c is MyLeafCondition => 'field' in c,
19
+ * isGroupCondition: (c): c is MyGroupCondition => 'conditions' in c,
20
+ * createEmptyLeaf: () => ({ field: '', operator: '', value: '' }),
21
+ * createEmptyGroup: (op) => ({ operator: op, conditions: [] }),
22
+ * getGroupOperator: (g) => g.operator,
23
+ * getGroupConditions: (g) => g.conditions,
24
+ * };
25
+ *
26
+ * // Use the component
27
+ * <ConditionBuilder
28
+ * conditions={myConditions}
29
+ * rootOperator="AND"
30
+ * config={config}
31
+ * onAddCondition={...}
32
+ * // ... other callbacks
33
+ * />
34
+ * ```
35
+ */
36
+ export { ConditionBuilder } from './condition-builder';
37
+ export { ConditionGroup } from './condition-group';
38
+ export { ConditionRow } from './condition-row';
39
+ export { ConditionReorderHandle, WORKFLOW_REORDER_HANDLE_CLASS } from './condition-reorder-handle';
40
+ export type { LogicalOperator, NodePath, BaseLeafCondition, BaseGroupCondition, BaseCondition, ExtraAddActionsContext, CustomNodeRenderContext, DeleteDisabledContext, LeafRowRenderProps, ConditionBuilderConfig, ConditionBuilderProps, ConditionGroupProps, ConditionRowProps, ConditionValidationError, } from './types';
41
+ export { isBaseGroupCondition, isBaseLeafCondition } from './types';
42
+ export { pathToString, stringToPath, getConditionAtPath, getParentAtPath, setConditionAtPath, insertConditionAtPath, removeConditionAtPath, moveConditionAtPath, setGroupOperatorAtPath, updateLeafConditionAtPath, duplicateConditionAtPath, countLeafConditions, countGroups, validateConditionTree, getInvalidPaths, } from './utils';
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/patterns/condition-builder/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAGnG,YAAY,EAER,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EAErB,kBAAkB,EAElB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EAEjB,wBAAwB,GAC3B,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGpE,OAAO,EAEH,YAAY,EACZ,YAAY,EAEZ,kBAAkB,EAClB,eAAe,EAEf,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,EAExB,mBAAmB,EACnB,WAAW,EAEX,qBAAqB,EACrB,eAAe,GAClB,MAAM,SAAS,CAAC"}