@uipath/apollo-wind 2.93.0 → 2.94.1

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 (132) hide show
  1. package/dist/components/forms/field-renderer.cjs +1 -1
  2. package/dist/components/forms/field-renderer.js +1 -1
  3. package/dist/components/forms/field-rules-strings.cjs +40 -0
  4. package/dist/components/forms/field-rules-strings.d.ts +17 -0
  5. package/dist/components/forms/field-rules-strings.js +6 -0
  6. package/dist/components/forms/field-rules.cjs +526 -0
  7. package/dist/components/forms/field-rules.d.ts +97 -0
  8. package/dist/components/forms/field-rules.js +468 -0
  9. package/dist/components/forms/form-designer.cjs +208 -592
  10. package/dist/components/forms/form-designer.js +210 -594
  11. package/dist/components/forms/form-schema.d.ts +5 -0
  12. package/dist/components/forms/index.cjs +43 -3
  13. package/dist/components/forms/index.d.ts +4 -0
  14. package/dist/components/forms/index.js +5 -1
  15. package/dist/components/forms/metadata-form.cjs +1 -1
  16. package/dist/components/forms/metadata-form.js +1 -1
  17. package/dist/components/forms/rules-engine-dialect.cjs +644 -0
  18. package/dist/components/forms/rules-engine-dialect.d.ts +90 -0
  19. package/dist/components/forms/rules-engine-dialect.js +537 -0
  20. package/dist/components/forms/rules-engine.cjs +99 -10
  21. package/dist/components/forms/rules-engine.d.ts +5 -0
  22. package/dist/components/forms/rules-engine.js +99 -10
  23. package/dist/components/forms/use-field-rules.cjs +122 -0
  24. package/dist/components/forms/use-field-rules.d.ts +31 -0
  25. package/dist/components/forms/use-field-rules.js +88 -0
  26. package/dist/components/ui/command.cjs +1 -1
  27. package/dist/components/ui/command.js +1 -1
  28. package/dist/components/ui/conditions-editor/condition-row.cjs +458 -0
  29. package/dist/components/ui/conditions-editor/condition-row.d.ts +23 -0
  30. package/dist/components/ui/conditions-editor/condition-row.js +421 -0
  31. package/dist/components/ui/conditions-editor/conditions-editor.cjs +363 -0
  32. package/dist/components/ui/conditions-editor/conditions-editor.d.ts +67 -0
  33. package/dist/components/ui/conditions-editor/conditions-editor.js +329 -0
  34. package/dist/components/ui/conditions-editor/context.cjs +45 -0
  35. package/dist/components/ui/conditions-editor/context.d.ts +54 -0
  36. package/dist/components/ui/conditions-editor/context.js +8 -0
  37. package/dist/components/ui/conditions-editor/index.cjs +55 -0
  38. package/dist/components/ui/conditions-editor/index.d.ts +6 -0
  39. package/dist/components/ui/conditions-editor/index.js +6 -0
  40. package/dist/components/ui/conditions-editor/model.cjs +126 -0
  41. package/dist/components/ui/conditions-editor/model.d.ts +39 -0
  42. package/dist/components/ui/conditions-editor/model.js +71 -0
  43. package/dist/components/ui/conditions-editor/status.cjs +198 -0
  44. package/dist/components/ui/conditions-editor/status.d.ts +44 -0
  45. package/dist/components/ui/conditions-editor/status.js +131 -0
  46. package/dist/components/ui/conditions-editor/strings.cjs +86 -0
  47. package/dist/components/ui/conditions-editor/strings.d.ts +62 -0
  48. package/dist/components/ui/conditions-editor/strings.js +52 -0
  49. package/dist/components/ui/conditions-editor/vocabulary.cjs +163 -0
  50. package/dist/components/ui/conditions-editor/vocabulary.d.ts +51 -0
  51. package/dist/components/ui/conditions-editor/vocabulary.js +129 -0
  52. package/dist/components/ui/context-menu.cjs +1 -1
  53. package/dist/components/ui/context-menu.js +1 -1
  54. package/dist/components/ui/dropdown-menu.cjs +1 -1
  55. package/dist/components/ui/dropdown-menu.js +1 -1
  56. package/dist/components/ui/field-actions/index.cjs +9 -2
  57. package/dist/components/ui/field-actions/index.d.ts +1 -0
  58. package/dist/components/ui/field-actions/index.js +2 -1
  59. package/dist/components/ui/field-actions/insert-variable-action.cjs +3 -1
  60. package/dist/components/ui/field-actions/insert-variable-action.d.ts +4 -1
  61. package/dist/components/ui/field-actions/insert-variable-action.js +3 -1
  62. package/dist/components/ui/field-actions/rules-action.cjs +244 -0
  63. package/dist/components/ui/field-actions/rules-action.d.ts +42 -0
  64. package/dist/components/ui/field-actions/rules-action.js +207 -0
  65. package/dist/components/ui/index.cjs +285 -246
  66. package/dist/components/ui/index.d.ts +3 -0
  67. package/dist/components/ui/index.js +3 -0
  68. package/dist/components/ui/quick-form-field/components/field-header.cjs +137 -167
  69. package/dist/components/ui/quick-form-field/components/field-header.d.ts +1 -1
  70. package/dist/components/ui/quick-form-field/components/field-header.js +138 -168
  71. package/dist/components/ui/quick-form-field/components/header-actions.cjs +187 -0
  72. package/dist/components/ui/quick-form-field/components/header-actions.d.ts +59 -0
  73. package/dist/components/ui/quick-form-field/components/header-actions.js +138 -0
  74. package/dist/components/ui/quick-form-field/components/header-context.cjs +59 -0
  75. package/dist/components/ui/quick-form-field/components/header-context.d.ts +33 -0
  76. package/dist/components/ui/quick-form-field/components/header-context.js +16 -0
  77. package/dist/components/ui/quick-form-field/index.cjs +18 -4
  78. package/dist/components/ui/quick-form-field/index.d.ts +2 -0
  79. package/dist/components/ui/quick-form-field/index.js +3 -1
  80. package/dist/components/ui/quick-form-field/quick-form-field.cjs +1 -1
  81. package/dist/components/ui/quick-form-field/quick-form-field.d.ts +6 -6
  82. package/dist/components/ui/quick-form-field/quick-form-field.js +1 -1
  83. package/dist/components/ui/quick-form-field/types.d.ts +42 -11
  84. package/dist/components/ui/row-groups/add-row-button.cjs +54 -0
  85. package/dist/components/ui/row-groups/add-row-button.d.ts +10 -0
  86. package/dist/components/ui/row-groups/add-row-button.js +20 -0
  87. package/dist/components/ui/row-groups/after-press.cjs +73 -0
  88. package/dist/components/ui/row-groups/after-press.d.ts +7 -0
  89. package/dist/components/ui/row-groups/after-press.js +36 -0
  90. package/dist/components/ui/row-groups/collapsible-row-group.cjs +83 -0
  91. package/dist/components/ui/row-groups/collapsible-row-group.d.ts +13 -0
  92. package/dist/components/ui/row-groups/collapsible-row-group.js +49 -0
  93. package/dist/components/ui/row-groups/empty-rows.cjs +42 -0
  94. package/dist/components/ui/row-groups/empty-rows.d.ts +7 -0
  95. package/dist/components/ui/row-groups/empty-rows.js +8 -0
  96. package/dist/components/ui/row-groups/group-mode-toggle.cjs +80 -0
  97. package/dist/components/ui/row-groups/group-mode-toggle.d.ts +26 -0
  98. package/dist/components/ui/row-groups/group-mode-toggle.js +40 -0
  99. package/dist/components/ui/row-groups/index.cjs +62 -0
  100. package/dist/components/ui/row-groups/index.d.ts +6 -0
  101. package/dist/components/ui/row-groups/index.js +7 -0
  102. package/dist/components/ui/row-groups/row-delete-button.cjs +54 -0
  103. package/dist/components/ui/row-groups/row-delete-button.d.ts +18 -0
  104. package/dist/components/ui/row-groups/row-delete-button.js +20 -0
  105. package/dist/components/ui/row-groups/use-row-focus.cjs +82 -0
  106. package/dist/components/ui/row-groups/use-row-focus.d.ts +17 -0
  107. package/dist/components/ui/row-groups/use-row-focus.js +48 -0
  108. package/dist/components/ui/rules-editor/context.cjs +45 -0
  109. package/dist/components/ui/rules-editor/context.d.ts +52 -0
  110. package/dist/components/ui/rules-editor/context.js +8 -0
  111. package/dist/components/ui/rules-editor/index.cjs +56 -0
  112. package/dist/components/ui/rules-editor/index.d.ts +4 -0
  113. package/dist/components/ui/rules-editor/index.js +4 -0
  114. package/dist/components/ui/rules-editor/model.cjs +205 -0
  115. package/dist/components/ui/rules-editor/model.d.ts +128 -0
  116. package/dist/components/ui/rules-editor/model.js +144 -0
  117. package/dist/components/ui/rules-editor/rule-card.cjs +470 -0
  118. package/dist/components/ui/rules-editor/rule-card.d.ts +14 -0
  119. package/dist/components/ui/rules-editor/rule-card.js +436 -0
  120. package/dist/components/ui/rules-editor/rules-editor.cjs +160 -0
  121. package/dist/components/ui/rules-editor/rules-editor.d.ts +66 -0
  122. package/dist/components/ui/rules-editor/rules-editor.js +126 -0
  123. package/dist/components/ui/rules-editor/strings.cjs +68 -0
  124. package/dist/components/ui/rules-editor/strings.d.ts +56 -0
  125. package/dist/components/ui/rules-editor/strings.js +34 -0
  126. package/dist/components/ui/select.cjs +1 -1
  127. package/dist/components/ui/select.js +1 -1
  128. package/dist/index.cjs +129 -8
  129. package/dist/index.d.ts +17 -4
  130. package/dist/index.js +10 -3
  131. package/dist/styles.css +97 -24
  132. package/package.json +2 -2
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ RulesAction: ()=>RulesAction,
28
+ DEFAULT_RULES_ACTION_STRINGS: ()=>DEFAULT_RULES_ACTION_STRINGS
29
+ });
30
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
31
+ const external_lucide_react_namespaceObject = require("lucide-react");
32
+ const external_react_namespaceObject = require("react");
33
+ const external_button_cjs_namespaceObject = require("../button.cjs");
34
+ const index_cjs_namespaceObject = require("../conditions-editor/index.cjs");
35
+ const external_label_cjs_namespaceObject = require("../label.cjs");
36
+ const external_popover_cjs_namespaceObject = require("../popover.cjs");
37
+ const header_context_cjs_namespaceObject = require("../quick-form-field/components/header-context.cjs");
38
+ const external_rules_editor_index_cjs_namespaceObject = require("../rules-editor/index.cjs");
39
+ const external_switch_cjs_namespaceObject = require("../switch.cjs");
40
+ const external_tooltip_cjs_namespaceObject = require("../tooltip.cjs");
41
+ const external_lib_index_cjs_namespaceObject = require("../../../lib/index.cjs");
42
+ const external_collapse_cjs_namespaceObject = require("./collapse.cjs");
43
+ const DEFAULT_RULES_ACTION_STRINGS = {
44
+ trigger: (count, issues)=>0 === count ? 'Field rules' : 0 === issues ? `Field rules (${count})` : `Field rules (${count}), ${issues} ${1 === issues ? 'needs' : 'need'} attention`,
45
+ title: 'Field rules',
46
+ required: 'Required field',
47
+ makeConditional: 'Make conditional'
48
+ };
49
+ function RulesAction({ requiredOutcome, disabled, strings, editorStrings, value, onChange, defaultTouched, ...editor }) {
50
+ const header = (0, header_context_cjs_namespaceObject.useQuickFormFieldHeader)();
51
+ const inert = !!disabled || !!header?.disabled;
52
+ const text = {
53
+ ...DEFAULT_RULES_ACTION_STRINGS,
54
+ ...strings
55
+ };
56
+ const [open, setOpen] = (0, external_react_namespaceObject.useState)(false);
57
+ const titleId = (0, external_react_namespaceObject.useId)();
58
+ const requiredId = (0, external_react_namespaceObject.useId)();
59
+ const rulesList = (0, external_react_namespaceObject.useRef)(null);
60
+ const focusRule = (0, external_react_namespaceObject.useRef)(null);
61
+ const count = value.length;
62
+ const { outcomes, fields, operators, valueModes, variables, dialect } = editor;
63
+ const issues = (0, external_react_namespaceObject.useMemo)(()=>(0, external_rules_editor_index_cjs_namespaceObject.findRuleIssues)(value, {
64
+ outcomes,
65
+ fields,
66
+ operators,
67
+ valueModes,
68
+ variables
69
+ }, dialect), [
70
+ value,
71
+ outcomes,
72
+ fields,
73
+ operators,
74
+ valueModes,
75
+ variables,
76
+ dialect
77
+ ]);
78
+ const flagged = new Set(issues.map((issue)=>issue.ruleId)).size;
79
+ const [openedIssues, setOpenedIssues] = (0, external_react_namespaceObject.useState)([]);
80
+ const changeOpen = (next)=>{
81
+ if (next) setOpenedIssues((0, external_rules_editor_index_cjs_namespaceObject.issueIds)(issues));
82
+ setOpen(next);
83
+ };
84
+ const touched = (0, external_react_namespaceObject.useMemo)(()=>[
85
+ ...defaultTouched ?? [],
86
+ ...openedIssues
87
+ ], [
88
+ defaultTouched,
89
+ openedIssues
90
+ ]);
91
+ const triggerLabel = text.trigger(count, flagged);
92
+ const requiredIndex = void 0 === requiredOutcome ? -1 : value.findIndex((rule)=>rule.outcome === requiredOutcome && (0, external_rules_editor_index_cjs_namespaceObject.isUnconditionalRule)(rule));
93
+ const requiredRule = requiredIndex < 0 ? void 0 : value[requiredIndex];
94
+ const rules = requiredRule ? value.filter((rule)=>rule !== requiredRule) : value;
95
+ const showSwitch = void 0 !== requiredOutcome && (!!requiredRule || !rules.some((rule)=>rule.outcome === requiredOutcome));
96
+ const changeRules = (next)=>{
97
+ if (!requiredRule) return onChange(next);
98
+ const before = new Set(value.slice(0, requiredIndex).map((rule)=>rule.id));
99
+ const after = next.reduce((at, rule, position)=>before.has(rule.id) ? position + 1 : at, 0);
100
+ onChange([
101
+ ...next.slice(0, after),
102
+ requiredRule,
103
+ ...next.slice(after)
104
+ ]);
105
+ };
106
+ const setRequired = (on)=>{
107
+ if (!requiredOutcome) return;
108
+ onChange(on ? [
109
+ (0, external_rules_editor_index_cjs_namespaceObject.createRule)({
110
+ outcome: requiredOutcome,
111
+ conditions: (0, index_cjs_namespaceObject.createConditionGroup)()
112
+ }),
113
+ ...value
114
+ ] : [
115
+ ...rules
116
+ ]);
117
+ };
118
+ const makeConditional = ()=>{
119
+ onChange(value.map((rule)=>rule === requiredRule && 'conditions' === rule.mode ? {
120
+ ...rule,
121
+ conditions: {
122
+ ...rule.conditions,
123
+ children: [
124
+ (0, index_cjs_namespaceObject.createCondition)()
125
+ ]
126
+ }
127
+ } : rule));
128
+ focusRule.current = {
129
+ position: requiredIndex,
130
+ rules: rules.length + 1
131
+ };
132
+ };
133
+ (0, external_react_namespaceObject.useEffect)(()=>{
134
+ const next = focusRule.current;
135
+ const cards = rulesList.current?.querySelectorAll(':scope > fieldset > div > [data-row]');
136
+ if (!next || !cards || cards.length !== next.rules) return;
137
+ focusRule.current = null;
138
+ cards[next.position]?.querySelector(':scope [data-row] [data-row-first]')?.focus();
139
+ });
140
+ const rulesStrings = (0, external_react_namespaceObject.useMemo)(()=>showSwitch ? {
141
+ ...editorStrings,
142
+ empty: ''
143
+ } : editorStrings, [
144
+ showSwitch,
145
+ editorStrings
146
+ ]);
147
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_popover_cjs_namespaceObject.Popover, {
148
+ open: open,
149
+ onOpenChange: changeOpen,
150
+ children: [
151
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_tooltip_cjs_namespaceObject.Tooltip, {
152
+ children: [
153
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_tooltip_cjs_namespaceObject.TooltipTrigger, {
154
+ asChild: true,
155
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_popover_cjs_namespaceObject.PopoverTrigger, {
156
+ asChild: true,
157
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_button_cjs_namespaceObject.Button, {
158
+ type: "button",
159
+ variant: "ghost",
160
+ size: "3xs",
161
+ icon: true,
162
+ "aria-label": triggerLabel,
163
+ className: (0, external_lib_index_cjs_namespaceObject.cn)('relative', external_collapse_cjs_namespaceObject.FIELD_ACTION_CLASS, (open || count > 0) && 'text-brand', flagged > 0 && 'text-destructive'),
164
+ children: [
165
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_lucide_react_namespaceObject.Network, {}),
166
+ count > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
167
+ "aria-hidden": true,
168
+ className: (0, external_lib_index_cjs_namespaceObject.cn)('absolute -right-1 -top-1 flex h-3.5 min-w-3.5 items-center justify-center rounded-full px-0.5 text-[9px] font-medium leading-none', flagged > 0 ? 'bg-destructive text-destructive-foreground' : 'bg-brand/15 text-brand'),
169
+ children: count
170
+ })
171
+ ]
172
+ })
173
+ })
174
+ }),
175
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_tooltip_cjs_namespaceObject.TooltipContent, {
176
+ children: triggerLabel
177
+ })
178
+ ]
179
+ }),
180
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_popover_cjs_namespaceObject.PopoverContent, {
181
+ align: "end",
182
+ sideOffset: 6,
183
+ collisionPadding: 8,
184
+ "aria-labelledby": titleId,
185
+ className: "flex max-h-[var(--radix-popover-content-available-height)] w-[min(29rem,calc(100vw-2rem))] flex-col gap-2.5 overflow-y-auto p-3",
186
+ children: [
187
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
188
+ id: titleId,
189
+ className: "text-xs font-semibold text-foreground",
190
+ children: text.title
191
+ }),
192
+ showSwitch && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
193
+ className: "flex h-10 items-center gap-2.5 rounded-lg border border-solid border-border bg-card px-3",
194
+ children: [
195
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_switch_cjs_namespaceObject.Switch, {
196
+ id: requiredId,
197
+ size: "sm",
198
+ checked: !!requiredRule,
199
+ onCheckedChange: setRequired,
200
+ disabled: inert
201
+ }),
202
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_label_cjs_namespaceObject.Label, {
203
+ htmlFor: requiredId,
204
+ className: "flex-1 text-xs font-normal text-foreground",
205
+ children: text.required
206
+ }),
207
+ requiredRule && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_button_cjs_namespaceObject.Button, {
208
+ type: "button",
209
+ variant: "ghost",
210
+ size: "3xs",
211
+ onClick: makeConditional,
212
+ disabled: inert,
213
+ className: "text-xs text-muted-foreground hover:text-foreground",
214
+ children: text.makeConditional
215
+ })
216
+ ]
217
+ }),
218
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
219
+ ref: rulesList,
220
+ className: "contents",
221
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rules_editor_index_cjs_namespaceObject.RulesEditor, {
222
+ ...editor,
223
+ value: rules,
224
+ onChange: changeRules,
225
+ label: text.title,
226
+ disabled: inert,
227
+ strings: rulesStrings,
228
+ defaultTouched: touched
229
+ })
230
+ })
231
+ ]
232
+ })
233
+ ]
234
+ });
235
+ }
236
+ exports.DEFAULT_RULES_ACTION_STRINGS = __webpack_exports__.DEFAULT_RULES_ACTION_STRINGS;
237
+ exports.RulesAction = __webpack_exports__.RulesAction;
238
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
239
+ "DEFAULT_RULES_ACTION_STRINGS",
240
+ "RulesAction"
241
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
242
+ Object.defineProperty(exports, '__esModule', {
243
+ value: true
244
+ });
@@ -0,0 +1,42 @@
1
+ import { type RulesEditorProps, type RulesEditorStrings } from '../rules-editor';
2
+ export interface RulesActionStrings {
3
+ /**
4
+ * The trigger's accessible name and tooltip, given how many rules are set and how many of them
5
+ * need attention: unfinished, on a field the form no longer has, or not runnable.
6
+ */
7
+ trigger: (count: number, issues: number) => string;
8
+ /** The popover's heading, which also names the rules list. */
9
+ title: string;
10
+ /** The Required switch's label. */
11
+ required: string;
12
+ /** Turns the Required switch's rule into one with conditions. */
13
+ makeConditional: string;
14
+ }
15
+ export declare const DEFAULT_RULES_ACTION_STRINGS: RulesActionStrings;
16
+ export interface RulesActionProps extends Omit<RulesEditorProps, 'label' | 'disabled' | 'className' | 'strings'> {
17
+ /**
18
+ * The outcome that requires the field. Its rule with no conditions, which always applies, shows
19
+ * as a Required switch above the other rules. Omit where requiring the field is no choice.
20
+ */
21
+ requiredOutcome?: string;
22
+ /**
23
+ * Disables every control in the popover, which still opens so the rules can be read. Disabled
24
+ * while an enclosing QuickFormField is, too.
25
+ */
26
+ disabled?: boolean;
27
+ /** Overrides for any subset of the action's English strings. */
28
+ strings?: Partial<RulesActionStrings>;
29
+ /** Overrides for the rules editor's strings. */
30
+ editorStrings?: Partial<RulesEditorStrings>;
31
+ }
32
+ /**
33
+ * The field-rules header action: a RulesEditor in a popover, with an optional Required switch,
34
+ * behind a trigger that counts the rules and turns red while any needs attention, whose messages
35
+ * then show as the popover opens. The switch is a rule like the others, shown apart: on, it is a
36
+ * `requiredOutcome` rule with no conditions, and Make conditional gives it one. Inside a
37
+ * QuickFormField's `headerActions` it follows the field's `disabled`; disabled, the popover still
38
+ * opens, read-only. Requires an ancestor `TooltipProvider`.
39
+ *
40
+ * Pair it with `useFieldRules` to store the rules as RulesEngine `FieldRule`s.
41
+ */
42
+ export declare function RulesAction({ requiredOutcome, disabled, strings, editorStrings, value, onChange, defaultTouched, ...editor }: RulesActionProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,207 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Network } from "lucide-react";
3
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
4
+ import { Button } from "../button.js";
5
+ import { createCondition, createConditionGroup } from "../conditions-editor/index.js";
6
+ import { Label } from "../label.js";
7
+ import { Popover, PopoverContent, PopoverTrigger } from "../popover.js";
8
+ import { useQuickFormFieldHeader } from "../quick-form-field/components/header-context.js";
9
+ import { RulesEditor, createRule, findRuleIssues, isUnconditionalRule, issueIds } from "../rules-editor/index.js";
10
+ import { Switch } from "../switch.js";
11
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip.js";
12
+ import { cn } from "../../../lib/index.js";
13
+ import { FIELD_ACTION_CLASS } from "./collapse.js";
14
+ const DEFAULT_RULES_ACTION_STRINGS = {
15
+ trigger: (count, issues)=>0 === count ? 'Field rules' : 0 === issues ? `Field rules (${count})` : `Field rules (${count}), ${issues} ${1 === issues ? 'needs' : 'need'} attention`,
16
+ title: 'Field rules',
17
+ required: 'Required field',
18
+ makeConditional: 'Make conditional'
19
+ };
20
+ function RulesAction({ requiredOutcome, disabled, strings, editorStrings, value, onChange, defaultTouched, ...editor }) {
21
+ const header = useQuickFormFieldHeader();
22
+ const inert = !!disabled || !!header?.disabled;
23
+ const text = {
24
+ ...DEFAULT_RULES_ACTION_STRINGS,
25
+ ...strings
26
+ };
27
+ const [open, setOpen] = useState(false);
28
+ const titleId = useId();
29
+ const requiredId = useId();
30
+ const rulesList = useRef(null);
31
+ const focusRule = useRef(null);
32
+ const count = value.length;
33
+ const { outcomes, fields, operators, valueModes, variables, dialect } = editor;
34
+ const issues = useMemo(()=>findRuleIssues(value, {
35
+ outcomes,
36
+ fields,
37
+ operators,
38
+ valueModes,
39
+ variables
40
+ }, dialect), [
41
+ value,
42
+ outcomes,
43
+ fields,
44
+ operators,
45
+ valueModes,
46
+ variables,
47
+ dialect
48
+ ]);
49
+ const flagged = new Set(issues.map((issue)=>issue.ruleId)).size;
50
+ const [openedIssues, setOpenedIssues] = useState([]);
51
+ const changeOpen = (next)=>{
52
+ if (next) setOpenedIssues(issueIds(issues));
53
+ setOpen(next);
54
+ };
55
+ const touched = useMemo(()=>[
56
+ ...defaultTouched ?? [],
57
+ ...openedIssues
58
+ ], [
59
+ defaultTouched,
60
+ openedIssues
61
+ ]);
62
+ const triggerLabel = text.trigger(count, flagged);
63
+ const requiredIndex = void 0 === requiredOutcome ? -1 : value.findIndex((rule)=>rule.outcome === requiredOutcome && isUnconditionalRule(rule));
64
+ const requiredRule = requiredIndex < 0 ? void 0 : value[requiredIndex];
65
+ const rules = requiredRule ? value.filter((rule)=>rule !== requiredRule) : value;
66
+ const showSwitch = void 0 !== requiredOutcome && (!!requiredRule || !rules.some((rule)=>rule.outcome === requiredOutcome));
67
+ const changeRules = (next)=>{
68
+ if (!requiredRule) return onChange(next);
69
+ const before = new Set(value.slice(0, requiredIndex).map((rule)=>rule.id));
70
+ const after = next.reduce((at, rule, position)=>before.has(rule.id) ? position + 1 : at, 0);
71
+ onChange([
72
+ ...next.slice(0, after),
73
+ requiredRule,
74
+ ...next.slice(after)
75
+ ]);
76
+ };
77
+ const setRequired = (on)=>{
78
+ if (!requiredOutcome) return;
79
+ onChange(on ? [
80
+ createRule({
81
+ outcome: requiredOutcome,
82
+ conditions: createConditionGroup()
83
+ }),
84
+ ...value
85
+ ] : [
86
+ ...rules
87
+ ]);
88
+ };
89
+ const makeConditional = ()=>{
90
+ onChange(value.map((rule)=>rule === requiredRule && 'conditions' === rule.mode ? {
91
+ ...rule,
92
+ conditions: {
93
+ ...rule.conditions,
94
+ children: [
95
+ createCondition()
96
+ ]
97
+ }
98
+ } : rule));
99
+ focusRule.current = {
100
+ position: requiredIndex,
101
+ rules: rules.length + 1
102
+ };
103
+ };
104
+ useEffect(()=>{
105
+ const next = focusRule.current;
106
+ const cards = rulesList.current?.querySelectorAll(':scope > fieldset > div > [data-row]');
107
+ if (!next || !cards || cards.length !== next.rules) return;
108
+ focusRule.current = null;
109
+ cards[next.position]?.querySelector(':scope [data-row] [data-row-first]')?.focus();
110
+ });
111
+ const rulesStrings = useMemo(()=>showSwitch ? {
112
+ ...editorStrings,
113
+ empty: ''
114
+ } : editorStrings, [
115
+ showSwitch,
116
+ editorStrings
117
+ ]);
118
+ return /*#__PURE__*/ jsxs(Popover, {
119
+ open: open,
120
+ onOpenChange: changeOpen,
121
+ children: [
122
+ /*#__PURE__*/ jsxs(Tooltip, {
123
+ children: [
124
+ /*#__PURE__*/ jsx(TooltipTrigger, {
125
+ asChild: true,
126
+ children: /*#__PURE__*/ jsx(PopoverTrigger, {
127
+ asChild: true,
128
+ children: /*#__PURE__*/ jsxs(Button, {
129
+ type: "button",
130
+ variant: "ghost",
131
+ size: "3xs",
132
+ icon: true,
133
+ "aria-label": triggerLabel,
134
+ className: cn('relative', FIELD_ACTION_CLASS, (open || count > 0) && 'text-brand', flagged > 0 && 'text-destructive'),
135
+ children: [
136
+ /*#__PURE__*/ jsx(Network, {}),
137
+ count > 0 && /*#__PURE__*/ jsx("span", {
138
+ "aria-hidden": true,
139
+ className: cn('absolute -right-1 -top-1 flex h-3.5 min-w-3.5 items-center justify-center rounded-full px-0.5 text-[9px] font-medium leading-none', flagged > 0 ? 'bg-destructive text-destructive-foreground' : 'bg-brand/15 text-brand'),
140
+ children: count
141
+ })
142
+ ]
143
+ })
144
+ })
145
+ }),
146
+ /*#__PURE__*/ jsx(TooltipContent, {
147
+ children: triggerLabel
148
+ })
149
+ ]
150
+ }),
151
+ /*#__PURE__*/ jsxs(PopoverContent, {
152
+ align: "end",
153
+ sideOffset: 6,
154
+ collisionPadding: 8,
155
+ "aria-labelledby": titleId,
156
+ className: "flex max-h-[var(--radix-popover-content-available-height)] w-[min(29rem,calc(100vw-2rem))] flex-col gap-2.5 overflow-y-auto p-3",
157
+ children: [
158
+ /*#__PURE__*/ jsx("div", {
159
+ id: titleId,
160
+ className: "text-xs font-semibold text-foreground",
161
+ children: text.title
162
+ }),
163
+ showSwitch && /*#__PURE__*/ jsxs("div", {
164
+ className: "flex h-10 items-center gap-2.5 rounded-lg border border-solid border-border bg-card px-3",
165
+ children: [
166
+ /*#__PURE__*/ jsx(Switch, {
167
+ id: requiredId,
168
+ size: "sm",
169
+ checked: !!requiredRule,
170
+ onCheckedChange: setRequired,
171
+ disabled: inert
172
+ }),
173
+ /*#__PURE__*/ jsx(Label, {
174
+ htmlFor: requiredId,
175
+ className: "flex-1 text-xs font-normal text-foreground",
176
+ children: text.required
177
+ }),
178
+ requiredRule && /*#__PURE__*/ jsx(Button, {
179
+ type: "button",
180
+ variant: "ghost",
181
+ size: "3xs",
182
+ onClick: makeConditional,
183
+ disabled: inert,
184
+ className: "text-xs text-muted-foreground hover:text-foreground",
185
+ children: text.makeConditional
186
+ })
187
+ ]
188
+ }),
189
+ /*#__PURE__*/ jsx("div", {
190
+ ref: rulesList,
191
+ className: "contents",
192
+ children: /*#__PURE__*/ jsx(RulesEditor, {
193
+ ...editor,
194
+ value: rules,
195
+ onChange: changeRules,
196
+ label: text.title,
197
+ disabled: inert,
198
+ strings: rulesStrings,
199
+ defaultTouched: touched
200
+ })
201
+ })
202
+ ]
203
+ })
204
+ ]
205
+ });
206
+ }
207
+ export { DEFAULT_RULES_ACTION_STRINGS, RulesAction };