@uipath/apollo-wind 2.93.0 → 2.94.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.
Files changed (124) 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/conditions-editor/condition-row.cjs +458 -0
  27. package/dist/components/ui/conditions-editor/condition-row.d.ts +23 -0
  28. package/dist/components/ui/conditions-editor/condition-row.js +421 -0
  29. package/dist/components/ui/conditions-editor/conditions-editor.cjs +363 -0
  30. package/dist/components/ui/conditions-editor/conditions-editor.d.ts +67 -0
  31. package/dist/components/ui/conditions-editor/conditions-editor.js +329 -0
  32. package/dist/components/ui/conditions-editor/context.cjs +45 -0
  33. package/dist/components/ui/conditions-editor/context.d.ts +54 -0
  34. package/dist/components/ui/conditions-editor/context.js +8 -0
  35. package/dist/components/ui/conditions-editor/index.cjs +55 -0
  36. package/dist/components/ui/conditions-editor/index.d.ts +6 -0
  37. package/dist/components/ui/conditions-editor/index.js +6 -0
  38. package/dist/components/ui/conditions-editor/model.cjs +126 -0
  39. package/dist/components/ui/conditions-editor/model.d.ts +39 -0
  40. package/dist/components/ui/conditions-editor/model.js +71 -0
  41. package/dist/components/ui/conditions-editor/status.cjs +198 -0
  42. package/dist/components/ui/conditions-editor/status.d.ts +44 -0
  43. package/dist/components/ui/conditions-editor/status.js +131 -0
  44. package/dist/components/ui/conditions-editor/strings.cjs +86 -0
  45. package/dist/components/ui/conditions-editor/strings.d.ts +62 -0
  46. package/dist/components/ui/conditions-editor/strings.js +52 -0
  47. package/dist/components/ui/conditions-editor/vocabulary.cjs +163 -0
  48. package/dist/components/ui/conditions-editor/vocabulary.d.ts +51 -0
  49. package/dist/components/ui/conditions-editor/vocabulary.js +129 -0
  50. package/dist/components/ui/field-actions/index.cjs +9 -2
  51. package/dist/components/ui/field-actions/index.d.ts +1 -0
  52. package/dist/components/ui/field-actions/index.js +2 -1
  53. package/dist/components/ui/field-actions/insert-variable-action.cjs +3 -1
  54. package/dist/components/ui/field-actions/insert-variable-action.d.ts +4 -1
  55. package/dist/components/ui/field-actions/insert-variable-action.js +3 -1
  56. package/dist/components/ui/field-actions/rules-action.cjs +244 -0
  57. package/dist/components/ui/field-actions/rules-action.d.ts +42 -0
  58. package/dist/components/ui/field-actions/rules-action.js +207 -0
  59. package/dist/components/ui/index.cjs +273 -234
  60. package/dist/components/ui/index.d.ts +3 -0
  61. package/dist/components/ui/index.js +3 -0
  62. package/dist/components/ui/quick-form-field/components/field-header.cjs +137 -167
  63. package/dist/components/ui/quick-form-field/components/field-header.d.ts +1 -1
  64. package/dist/components/ui/quick-form-field/components/field-header.js +138 -168
  65. package/dist/components/ui/quick-form-field/components/header-actions.cjs +187 -0
  66. package/dist/components/ui/quick-form-field/components/header-actions.d.ts +59 -0
  67. package/dist/components/ui/quick-form-field/components/header-actions.js +138 -0
  68. package/dist/components/ui/quick-form-field/components/header-context.cjs +59 -0
  69. package/dist/components/ui/quick-form-field/components/header-context.d.ts +33 -0
  70. package/dist/components/ui/quick-form-field/components/header-context.js +16 -0
  71. package/dist/components/ui/quick-form-field/index.cjs +18 -4
  72. package/dist/components/ui/quick-form-field/index.d.ts +2 -0
  73. package/dist/components/ui/quick-form-field/index.js +3 -1
  74. package/dist/components/ui/quick-form-field/quick-form-field.cjs +1 -1
  75. package/dist/components/ui/quick-form-field/quick-form-field.d.ts +6 -6
  76. package/dist/components/ui/quick-form-field/quick-form-field.js +1 -1
  77. package/dist/components/ui/quick-form-field/types.d.ts +42 -11
  78. package/dist/components/ui/row-groups/add-row-button.cjs +54 -0
  79. package/dist/components/ui/row-groups/add-row-button.d.ts +10 -0
  80. package/dist/components/ui/row-groups/add-row-button.js +20 -0
  81. package/dist/components/ui/row-groups/after-press.cjs +73 -0
  82. package/dist/components/ui/row-groups/after-press.d.ts +7 -0
  83. package/dist/components/ui/row-groups/after-press.js +36 -0
  84. package/dist/components/ui/row-groups/collapsible-row-group.cjs +83 -0
  85. package/dist/components/ui/row-groups/collapsible-row-group.d.ts +13 -0
  86. package/dist/components/ui/row-groups/collapsible-row-group.js +49 -0
  87. package/dist/components/ui/row-groups/empty-rows.cjs +42 -0
  88. package/dist/components/ui/row-groups/empty-rows.d.ts +7 -0
  89. package/dist/components/ui/row-groups/empty-rows.js +8 -0
  90. package/dist/components/ui/row-groups/group-mode-toggle.cjs +80 -0
  91. package/dist/components/ui/row-groups/group-mode-toggle.d.ts +26 -0
  92. package/dist/components/ui/row-groups/group-mode-toggle.js +40 -0
  93. package/dist/components/ui/row-groups/index.cjs +62 -0
  94. package/dist/components/ui/row-groups/index.d.ts +6 -0
  95. package/dist/components/ui/row-groups/index.js +7 -0
  96. package/dist/components/ui/row-groups/row-delete-button.cjs +54 -0
  97. package/dist/components/ui/row-groups/row-delete-button.d.ts +18 -0
  98. package/dist/components/ui/row-groups/row-delete-button.js +20 -0
  99. package/dist/components/ui/row-groups/use-row-focus.cjs +82 -0
  100. package/dist/components/ui/row-groups/use-row-focus.d.ts +17 -0
  101. package/dist/components/ui/row-groups/use-row-focus.js +48 -0
  102. package/dist/components/ui/rules-editor/context.cjs +45 -0
  103. package/dist/components/ui/rules-editor/context.d.ts +52 -0
  104. package/dist/components/ui/rules-editor/context.js +8 -0
  105. package/dist/components/ui/rules-editor/index.cjs +56 -0
  106. package/dist/components/ui/rules-editor/index.d.ts +4 -0
  107. package/dist/components/ui/rules-editor/index.js +4 -0
  108. package/dist/components/ui/rules-editor/model.cjs +205 -0
  109. package/dist/components/ui/rules-editor/model.d.ts +128 -0
  110. package/dist/components/ui/rules-editor/model.js +144 -0
  111. package/dist/components/ui/rules-editor/rule-card.cjs +470 -0
  112. package/dist/components/ui/rules-editor/rule-card.d.ts +14 -0
  113. package/dist/components/ui/rules-editor/rule-card.js +436 -0
  114. package/dist/components/ui/rules-editor/rules-editor.cjs +160 -0
  115. package/dist/components/ui/rules-editor/rules-editor.d.ts +66 -0
  116. package/dist/components/ui/rules-editor/rules-editor.js +126 -0
  117. package/dist/components/ui/rules-editor/strings.cjs +68 -0
  118. package/dist/components/ui/rules-editor/strings.d.ts +56 -0
  119. package/dist/components/ui/rules-editor/strings.js +34 -0
  120. package/dist/index.cjs +129 -8
  121. package/dist/index.d.ts +17 -4
  122. package/dist/index.js +10 -3
  123. package/dist/styles.css +97 -24
  124. package/package.json +2 -2
@@ -0,0 +1,436 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Braces, Form, SquareFunction } from "lucide-react";
3
+ import { memo, useCallback, useEffect, useId, useRef, useState } from "react";
4
+ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "../alert-dialog.js";
5
+ import { Button, buttonVariants } from "../button.js";
6
+ import { ConditionsEditor, createCondition, createConditionGroup } from "../conditions-editor/index.js";
7
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from "../dropdown-menu.js";
8
+ import { ValueModeMenuItem } from "../field-addons/field-menu.js";
9
+ import { FormField, FormFieldDescription, FormFieldError, FormFieldLabel } from "../form-field.js";
10
+ import { RowDeleteButton } from "../row-groups/index.js";
11
+ import { afterPress } from "../row-groups/after-press.js";
12
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
13
+ import { Textarea } from "../textarea.js";
14
+ import { useRulesEditor } from "./context.js";
15
+ import { isBlank, isUnconditionalRule, missingFields, unknownFields, unknownValueFields, withMode } from "./model.js";
16
+ function switched(rule, dialect, vocabulary) {
17
+ if ('conditions' === rule.mode) {
18
+ const expression = dialect?.toExpression?.(rule.conditions, vocabulary) ?? (isBlank(rule) ? '' : void 0);
19
+ return void 0 === expression ? void 0 : withMode(rule, {
20
+ mode: 'expression',
21
+ expression
22
+ });
23
+ }
24
+ if ('preserved' === rule.mode) return;
25
+ if (isBlank(rule)) return withMode(rule, {
26
+ mode: 'conditions',
27
+ conditions: oneCondition()
28
+ });
29
+ const conditions = dialect?.fromExpression?.(rule.expression, vocabulary);
30
+ return conditions && withMode(rule, {
31
+ mode: 'conditions',
32
+ conditions
33
+ });
34
+ }
35
+ const oneCondition = ()=>createConditionGroup('all', [
36
+ createCondition()
37
+ ]);
38
+ const FOCUSABLE = 'button:not(:disabled), input:not(:disabled), textarea:not(:disabled)';
39
+ function BuiltInExpressionEditor({ id, value, onChange, onBlur, labelledBy, invalid, errorId, disabled, placeholder }) {
40
+ return /*#__PURE__*/ jsx(Textarea, {
41
+ id: id,
42
+ value: value,
43
+ onChange: (event)=>onChange(event.target.value),
44
+ onBlur: onBlur,
45
+ placeholder: placeholder,
46
+ disabled: disabled,
47
+ minRows: 2,
48
+ maxRows: 8,
49
+ spellCheck: false,
50
+ autoCapitalize: "off",
51
+ autoCorrect: "off",
52
+ className: "font-mono text-xs",
53
+ "aria-labelledby": labelledBy,
54
+ "aria-invalid": invalid || void 0,
55
+ "aria-describedby": errorId,
56
+ "aria-errormessage": errorId
57
+ });
58
+ }
59
+ const rule_card_RuleCard = /*#__PURE__*/ memo(function({ rule, index, position, onDelete }) {
60
+ const editor = useRulesEditor();
61
+ const { strings: text, disabled, updateRule } = editor;
62
+ const [touched, setTouched] = useState(()=>editor.defaultTouched?.includes(rule.id) ?? false);
63
+ const [confirm, setConfirm] = useState({
64
+ open: false,
65
+ target: 'expression'
66
+ });
67
+ const baseId = useId();
68
+ const ids = {
69
+ name: `${baseId}-name`,
70
+ outcome: `${baseId}-outcome`,
71
+ expression: `${baseId}-expression`,
72
+ expressionLabel: `${baseId}-expression-label`,
73
+ outcomeError: `${baseId}-outcome-error`,
74
+ repair: `${baseId}-repair`,
75
+ expressionError: `${baseId}-expression-error`,
76
+ preserved: `${baseId}-preserved`,
77
+ preservedLabel: `${baseId}-preserved-label`,
78
+ preservedNote: `${baseId}-preserved-note`,
79
+ preservedError: `${baseId}-preserved-error`
80
+ };
81
+ const ruleName = text.ruleName(index);
82
+ const conditionsName = text.ruleConditions(ruleName);
83
+ const modeRef = useRef(null);
84
+ const bodyRef = useRef(null);
85
+ const restoreFocus = ()=>{
86
+ if (modeRef.current?.isConnected) modeRef.current.focus();
87
+ else bodyRef.current?.querySelector(FOCUSABLE)?.focus();
88
+ };
89
+ const apply = (next)=>{
90
+ setTouched(false);
91
+ updateRule(next);
92
+ };
93
+ const switchMode = (mode)=>{
94
+ if (mode === rule.mode) return;
95
+ const next = switched(rule, editor.dialect, editor.vocabulary);
96
+ if (next) apply(next);
97
+ else setConfirm({
98
+ open: true,
99
+ target: mode
100
+ });
101
+ };
102
+ const confirmSwitch = ()=>{
103
+ if (disabled) return;
104
+ apply('expression' === confirm.target ? withMode(rule, {
105
+ mode: 'expression',
106
+ expression: ''
107
+ }) : withMode(rule, {
108
+ mode: 'conditions',
109
+ conditions: oneCondition()
110
+ }));
111
+ };
112
+ const problem = 'expression' === rule.mode && '' !== rule.expression.trim() ? editor.dialect?.checkExpression?.(rule, editor.vocabulary) : void 0;
113
+ const missing = 'expression' === rule.mode && '' !== rule.expression.trim() ? unknownFields(rule.expression, editor.vocabulary.fields, editor.dialect) : [];
114
+ const [openedText] = useState(()=>'expression' === rule.mode ? rule.expression : void 0);
115
+ const unchanged = 'expression' === rule.mode && rule.expression === openedText;
116
+ const repair = editor.dialect?.repair?.(rule);
117
+ const repaired = useRef(false);
118
+ const repairRule = ()=>{
119
+ if (!repair) return;
120
+ repaired.current = true;
121
+ updateRule(repair.rule);
122
+ };
123
+ useEffect(()=>{
124
+ if (!repaired.current || repair) return;
125
+ repaired.current = false;
126
+ restoreFocus();
127
+ });
128
+ const { vocabulary, dialect } = editor;
129
+ const valueWarning = useCallback((c)=>{
130
+ const missing = unknownValueFields(c, vocabulary, dialect);
131
+ return missing.length > 0 ? text.errorExpressionUnknownFields(missing) : void 0;
132
+ }, [
133
+ vocabulary,
134
+ dialect,
135
+ text
136
+ ]);
137
+ const outcomeKnown = editor.outcomes.some((option)=>option.value === rule.outcome);
138
+ const outcomeError = outcomeKnown ? void 0 : text.errorOutcome;
139
+ const showModeToggle = editor.allowExpressions || 'conditions' !== rule.mode;
140
+ const modes = {
141
+ conditions: {
142
+ icon: Form,
143
+ title: text.modeConditions,
144
+ description: text.modeConditionsDescription
145
+ },
146
+ expression: {
147
+ icon: SquareFunction,
148
+ title: text.modeExpression,
149
+ description: text.modeExpressionDescription
150
+ },
151
+ preserved: {
152
+ icon: Braces,
153
+ title: text.modePreserved,
154
+ description: text.preservedNote
155
+ }
156
+ };
157
+ const ModeIcon = modes[rule.mode].icon;
158
+ let body;
159
+ if ('conditions' === rule.mode) body = /*#__PURE__*/ jsx(ConditionsEditor, {
160
+ label: conditionsName,
161
+ value: rule.conditions,
162
+ onChange: (conditions)=>updateRule({
163
+ ...rule,
164
+ conditions
165
+ }),
166
+ fields: editor.vocabulary.fields,
167
+ operators: editor.vocabulary.operators,
168
+ valueModes: editor.vocabulary.valueModes,
169
+ variables: editor.variables,
170
+ renderValue: editor.renderValue,
171
+ maxDepth: 0,
172
+ showMatchMode: editor.showMatchMode,
173
+ container: "plain",
174
+ forceErrors: editor.forceErrors,
175
+ defaultTouched: editor.defaultTouched,
176
+ disabled: disabled,
177
+ strings: editor.conditionsStrings,
178
+ valueModeStrings: editor.valueModeStrings,
179
+ multiSelectStrings: editor.multiSelectStrings,
180
+ valueWarning: valueWarning
181
+ });
182
+ else if ('preserved' === rule.mode) {
183
+ const missingKeys = missingFields(rule.fieldKeys ?? [], editor.vocabulary.fields);
184
+ const describedBy = [
185
+ ...missingKeys.length > 0 ? [
186
+ ids.preservedError
187
+ ] : [],
188
+ ...repair ? [] : [
189
+ ids.preservedNote
190
+ ]
191
+ ].join(' ');
192
+ body = /*#__PURE__*/ jsxs(FormField, {
193
+ children: [
194
+ /*#__PURE__*/ jsx(FormFieldLabel, {
195
+ id: ids.preservedLabel,
196
+ htmlFor: ids.preserved,
197
+ children: text.modePreserved
198
+ }),
199
+ /*#__PURE__*/ jsx(Textarea, {
200
+ id: ids.preserved,
201
+ value: rule.preservedSource,
202
+ readOnly: true,
203
+ minRows: 2,
204
+ maxRows: 8,
205
+ spellCheck: false,
206
+ className: "font-mono text-xs",
207
+ "aria-labelledby": `${ids.name} ${ids.preservedLabel}`,
208
+ "aria-describedby": describedBy || void 0
209
+ }),
210
+ missingKeys.length > 0 && /*#__PURE__*/ jsx(FormFieldError, {
211
+ id: ids.preservedError,
212
+ children: text.errorExpressionUnknownFields(missingKeys)
213
+ }),
214
+ !repair && /*#__PURE__*/ jsx(FormFieldDescription, {
215
+ id: ids.preservedNote,
216
+ children: text.preservedNote
217
+ })
218
+ ]
219
+ });
220
+ } else {
221
+ const shown = editor.forceErrors || touched;
222
+ const error = shown && '' === rule.expression.trim() ? text.errorExpression : 'invalid' === problem && (shown || unchanged) ? text.errorExpressionInvalid : missing.length > 0 && (shown || unchanged) ? text.errorExpressionUnknownFields(missing) : void 0;
223
+ const props = {
224
+ rule,
225
+ id: ids.expression,
226
+ value: rule.expression,
227
+ onChange: (expression)=>updateRule({
228
+ ...rule,
229
+ expression
230
+ }),
231
+ onBlur: ()=>afterPress(()=>setTouched(true)),
232
+ labelledBy: `${ids.name} ${ids.expressionLabel}`,
233
+ invalid: Boolean(error),
234
+ errorId: error ? ids.expressionError : void 0,
235
+ disabled,
236
+ placeholder: text.expressionPlaceholder || void 0
237
+ };
238
+ const custom = editor.renderExpressionEditor?.(props);
239
+ body = /*#__PURE__*/ jsxs(FormField, {
240
+ children: [
241
+ /*#__PURE__*/ jsx(FormFieldLabel, {
242
+ id: ids.expressionLabel,
243
+ htmlFor: ids.expression,
244
+ children: text.expressionLabel
245
+ }),
246
+ void 0 === custom ? /*#__PURE__*/ jsx(BuiltInExpressionEditor, {
247
+ ...props
248
+ }) : custom,
249
+ error && /*#__PURE__*/ jsx(FormFieldError, {
250
+ id: ids.expressionError,
251
+ children: error
252
+ })
253
+ ]
254
+ });
255
+ }
256
+ return /*#__PURE__*/ jsxs("fieldset", {
257
+ "data-row": "",
258
+ "aria-label": ruleName,
259
+ className: "m-0 flex min-w-0 flex-col gap-3 rounded-lg border border-solid border-border bg-card p-3",
260
+ children: [
261
+ /*#__PURE__*/ jsx("span", {
262
+ id: ids.name,
263
+ className: "sr-only",
264
+ children: ruleName
265
+ }),
266
+ /*#__PURE__*/ jsxs("div", {
267
+ className: "flex flex-col",
268
+ children: [
269
+ /*#__PURE__*/ jsxs("div", {
270
+ className: "flex flex-wrap items-center gap-2",
271
+ children: [
272
+ /*#__PURE__*/ jsxs("div", {
273
+ className: "flex items-center gap-2",
274
+ children: [
275
+ /*#__PURE__*/ jsx("span", {
276
+ id: ids.outcome,
277
+ className: "sr-only",
278
+ children: text.outcomeLabel
279
+ }),
280
+ /*#__PURE__*/ jsxs(Select, {
281
+ value: outcomeKnown ? rule.outcome : '',
282
+ disabled: disabled,
283
+ onValueChange: (outcome)=>updateRule({
284
+ ...rule,
285
+ outcome
286
+ }),
287
+ children: [
288
+ /*#__PURE__*/ jsx(SelectTrigger, {
289
+ "data-row-first": "",
290
+ className: "w-auto shrink-0",
291
+ "aria-labelledby": `${ids.name} ${ids.outcome}`,
292
+ "aria-invalid": outcomeError ? true : void 0,
293
+ "aria-describedby": outcomeError ? ids.outcomeError : void 0,
294
+ "aria-errormessage": outcomeError ? ids.outcomeError : void 0,
295
+ children: /*#__PURE__*/ jsx(SelectValue, {
296
+ placeholder: text.outcomePlaceholder
297
+ })
298
+ }),
299
+ /*#__PURE__*/ jsx(SelectContent, {
300
+ children: editor.outcomes.map((option)=>/*#__PURE__*/ jsx(SelectItem, {
301
+ value: option.value,
302
+ children: option.label
303
+ }, option.value))
304
+ })
305
+ ]
306
+ }),
307
+ /*#__PURE__*/ jsx("span", {
308
+ className: "flex h-9 shrink-0 items-center text-xs text-muted-foreground future:h-10",
309
+ children: isUnconditionalRule(rule) ? text.always : text.when
310
+ })
311
+ ]
312
+ }),
313
+ /*#__PURE__*/ jsxs("div", {
314
+ className: "ml-auto flex h-9 items-center gap-2 future:h-10",
315
+ children: [
316
+ showModeToggle && /*#__PURE__*/ jsxs(DropdownMenu, {
317
+ children: [
318
+ /*#__PURE__*/ jsx(DropdownMenuTrigger, {
319
+ asChild: true,
320
+ children: /*#__PURE__*/ jsx(Button, {
321
+ ref: modeRef,
322
+ type: "button",
323
+ variant: "ghost",
324
+ size: "xs",
325
+ icon: true,
326
+ disabled: disabled,
327
+ "aria-label": text.ruleMode(ruleName, modes[rule.mode].title),
328
+ title: text.ruleMode(ruleName, modes[rule.mode].title),
329
+ className: "px-1.5 text-muted-foreground hover:text-foreground",
330
+ children: /*#__PURE__*/ jsx(ModeIcon, {})
331
+ })
332
+ }),
333
+ /*#__PURE__*/ jsx(DropdownMenuContent, {
334
+ align: "end",
335
+ className: "w-56",
336
+ onCloseAutoFocus: (event)=>{
337
+ if (modeRef.current?.isConnected) return;
338
+ event.preventDefault();
339
+ restoreFocus();
340
+ },
341
+ children: [
342
+ 'conditions',
343
+ 'expression'
344
+ ].map((mode)=>/*#__PURE__*/ jsx(ValueModeMenuItem, {
345
+ icon: modes[mode].icon,
346
+ label: modes[mode].title,
347
+ description: modes[mode].description,
348
+ active: rule.mode === mode,
349
+ onClick: ()=>switchMode(mode)
350
+ }, mode))
351
+ })
352
+ ]
353
+ }),
354
+ /*#__PURE__*/ jsx(RowDeleteButton, {
355
+ label: text.removeRule(index),
356
+ disabled: disabled,
357
+ onClick: ()=>onDelete(rule.id, position)
358
+ })
359
+ ]
360
+ })
361
+ ]
362
+ }),
363
+ outcomeError && /*#__PURE__*/ jsx(FormFieldError, {
364
+ id: ids.outcomeError,
365
+ children: outcomeError
366
+ })
367
+ ]
368
+ }),
369
+ /*#__PURE__*/ jsx("div", {
370
+ ref: bodyRef,
371
+ className: "flex min-w-0 flex-col gap-3",
372
+ children: body
373
+ }),
374
+ repair && /*#__PURE__*/ jsxs("div", {
375
+ className: "flex flex-wrap items-center gap-x-2",
376
+ children: [
377
+ /*#__PURE__*/ jsx(FormFieldError, {
378
+ id: ids.repair,
379
+ children: text.ruleNeedsRepair(repair.reason)
380
+ }),
381
+ /*#__PURE__*/ jsx(Button, {
382
+ type: "button",
383
+ variant: "link",
384
+ size: "xs",
385
+ className: "h-auto px-0",
386
+ disabled: disabled,
387
+ "aria-describedby": ids.repair,
388
+ onClick: repairRule,
389
+ children: text.repairAction
390
+ })
391
+ ]
392
+ }),
393
+ /*#__PURE__*/ jsx(AlertDialog, {
394
+ open: confirm.open,
395
+ onOpenChange: (open)=>setConfirm((current)=>({
396
+ ...current,
397
+ open
398
+ })),
399
+ children: /*#__PURE__*/ jsxs(AlertDialogContent, {
400
+ onCloseAutoFocus: (event)=>{
401
+ event.preventDefault();
402
+ restoreFocus();
403
+ },
404
+ children: [
405
+ /*#__PURE__*/ jsxs(AlertDialogHeader, {
406
+ children: [
407
+ /*#__PURE__*/ jsx(AlertDialogTitle, {
408
+ children: 'expression' === confirm.target ? text.switchToExpressionTitle : text.switchToConditionsTitle
409
+ }),
410
+ /*#__PURE__*/ jsx(AlertDialogDescription, {
411
+ children: 'preserved' === rule.mode ? text.switchFromPreservedDescription : 'expression' === confirm.target ? text.switchToExpressionDescription : text.switchToConditionsDescription
412
+ })
413
+ ]
414
+ }),
415
+ /*#__PURE__*/ jsxs(AlertDialogFooter, {
416
+ children: [
417
+ /*#__PURE__*/ jsx(AlertDialogCancel, {
418
+ children: text.cancel
419
+ }),
420
+ /*#__PURE__*/ jsx(AlertDialogAction, {
421
+ className: buttonVariants({
422
+ variant: 'destructive'
423
+ }),
424
+ disabled: disabled,
425
+ onClick: confirmSwitch,
426
+ children: text.switchConfirm
427
+ })
428
+ ]
429
+ })
430
+ ]
431
+ })
432
+ })
433
+ ]
434
+ });
435
+ });
436
+ export { rule_card_RuleCard as RuleCard };
@@ -0,0 +1,160 @@
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
+ RulesEditor: ()=>RulesEditor
28
+ });
29
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
30
+ const external_react_namespaceObject = require("react");
31
+ const index_cjs_namespaceObject = require("../conditions-editor/index.cjs");
32
+ const status_cjs_namespaceObject = require("../conditions-editor/status.cjs");
33
+ const external_row_groups_index_cjs_namespaceObject = require("../row-groups/index.cjs");
34
+ const after_press_cjs_namespaceObject = require("../row-groups/after-press.cjs");
35
+ const external_lib_index_cjs_namespaceObject = require("../../../lib/index.cjs");
36
+ const external_context_cjs_namespaceObject = require("./context.cjs");
37
+ const external_model_cjs_namespaceObject = require("./model.cjs");
38
+ const external_rule_card_cjs_namespaceObject = require("./rule-card.cjs");
39
+ const external_strings_cjs_namespaceObject = require("./strings.cjs");
40
+ function RulesEditor({ value, onChange, label, outcomes, defaultOutcome, fields, operators = index_cjs_namespaceObject.DEFAULT_CONDITION_OPERATORS, valueModes, variables, renderValue, showMatchMode = true, allowExpressions = true, dialect, renderExpressionEditor, forceErrors = false, defaultTouched, disabled = false, className, strings, conditionsStrings, valueModeStrings, multiSelectStrings }) {
41
+ (0, after_press_cjs_namespaceObject.usePressTracking)();
42
+ const focus = (0, external_row_groups_index_cjs_namespaceObject.useRowFocus)();
43
+ const latest = external_react_namespaceObject.useRef({
44
+ value,
45
+ onChange
46
+ });
47
+ latest.current = {
48
+ value,
49
+ onChange
50
+ };
51
+ const updateRule = external_react_namespaceObject.useCallback((rule)=>latest.current.onChange(latest.current.value.map((current)=>current.id === rule.id ? rule : current)), []);
52
+ const { afterDelete } = focus;
53
+ const deleteRule = external_react_namespaceObject.useCallback((id, position)=>{
54
+ afterDelete(position);
55
+ latest.current.onChange(latest.current.value.filter((rule)=>rule.id !== id));
56
+ }, [
57
+ afterDelete
58
+ ]);
59
+ const text = external_react_namespaceObject.useMemo(()=>({
60
+ ...external_strings_cjs_namespaceObject.DEFAULT_RULES_EDITOR_STRINGS,
61
+ ...strings
62
+ }), [
63
+ strings
64
+ ]);
65
+ const ruleConditionsStrings = external_react_namespaceObject.useMemo(()=>({
66
+ ...conditionsStrings,
67
+ empty: ''
68
+ }), [
69
+ conditionsStrings
70
+ ]);
71
+ const modes = valueModes ?? (0, status_cjs_namespaceObject.defaultValueModes)(variables);
72
+ const vocabulary = external_react_namespaceObject.useMemo(()=>({
73
+ fields,
74
+ operators,
75
+ valueModes: modes
76
+ }), [
77
+ fields,
78
+ operators,
79
+ modes
80
+ ]);
81
+ const editor = external_react_namespaceObject.useMemo(()=>({
82
+ outcomes,
83
+ vocabulary,
84
+ variables,
85
+ renderValue,
86
+ showMatchMode,
87
+ allowExpressions,
88
+ dialect,
89
+ renderExpressionEditor,
90
+ forceErrors,
91
+ defaultTouched,
92
+ disabled,
93
+ strings: text,
94
+ conditionsStrings: ruleConditionsStrings,
95
+ valueModeStrings,
96
+ multiSelectStrings,
97
+ updateRule
98
+ }), [
99
+ outcomes,
100
+ vocabulary,
101
+ variables,
102
+ renderValue,
103
+ showMatchMode,
104
+ allowExpressions,
105
+ dialect,
106
+ renderExpressionEditor,
107
+ forceErrors,
108
+ defaultTouched,
109
+ disabled,
110
+ text,
111
+ ruleConditionsStrings,
112
+ valueModeStrings,
113
+ multiSelectStrings,
114
+ updateRule
115
+ ]);
116
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_cjs_namespaceObject.RulesEditorContext.Provider, {
117
+ value: editor,
118
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("fieldset", {
119
+ "aria-label": label,
120
+ className: (0, external_lib_index_cjs_namespaceObject.cn)('m-0 flex min-w-0 flex-col gap-2 border-0 p-0', className),
121
+ children: [
122
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
123
+ ref: focus.listRef,
124
+ className: "flex flex-col gap-2",
125
+ children: 0 === value.length ? text.empty && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_row_groups_index_cjs_namespaceObject.EmptyRows, {
126
+ children: text.empty
127
+ }) : value.map((rule, position)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rule_card_cjs_namespaceObject.RuleCard, {
128
+ rule: rule,
129
+ index: position + 1,
130
+ position: position,
131
+ onDelete: deleteRule
132
+ }, rule.id))
133
+ }),
134
+ /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
135
+ children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_row_groups_index_cjs_namespaceObject.AddRowButton, {
136
+ ref: focus.addRef,
137
+ disabled: disabled,
138
+ onClick: ()=>{
139
+ focus.afterAdd();
140
+ onChange([
141
+ ...value,
142
+ (0, external_model_cjs_namespaceObject.createRule)({
143
+ outcome: defaultOutcome ?? outcomes[0]?.value ?? ''
144
+ })
145
+ ]);
146
+ },
147
+ children: text.addRule
148
+ })
149
+ })
150
+ ]
151
+ })
152
+ });
153
+ }
154
+ exports.RulesEditor = __webpack_exports__.RulesEditor;
155
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
156
+ "RulesEditor"
157
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
158
+ Object.defineProperty(exports, '__esModule', {
159
+ value: true
160
+ });
@@ -0,0 +1,66 @@
1
+ import { type ConditionField, type ConditionOperators, type ConditionsEditorStrings, type ConditionValueMode, type RenderConditionValue } from '../conditions-editor';
2
+ import type { ValueModeStrings } from '../field-addons';
3
+ import type { MultiSelectStrings } from '../multi-select';
4
+ import type { VariablePickerItem } from '../variable-picker';
5
+ import { type RenderRuleExpressionEditor } from './context';
6
+ import { type Rule, type RuleOutcome, type RulesDialect } from './model';
7
+ import { type RulesEditorStrings } from './strings';
8
+ export interface RulesEditorProps {
9
+ value: readonly Rule[];
10
+ onChange: (next: Rule[]) => void;
11
+ /** Names the list for assistive technology, e.g. "Field behavior". */
12
+ label: string;
13
+ /** What a rule can do, in the order the outcome select lists them. */
14
+ outcomes: readonly RuleOutcome[];
15
+ /** A new rule's outcome. Defaults to the first of `outcomes`. */
16
+ defaultOutcome?: string;
17
+ /** What a condition can compare. */
18
+ fields: readonly ConditionField[];
19
+ /** The operators per field type. Defaults to the English set. */
20
+ operators?: ConditionOperators;
21
+ /** The value modes each condition's value offers. See `ConditionsEditor`. */
22
+ valueModes?: readonly ConditionValueMode[];
23
+ /** What a condition's Variable mode picks from. */
24
+ variables?: VariablePickerItem[];
25
+ /** Replaces a condition value's control. See `RenderConditionValue`. */
26
+ renderValue?: RenderConditionValue;
27
+ /** Whether a rule's All / Any switch can show. See `ConditionsEditor`. */
28
+ showMatchMode?: boolean;
29
+ /**
30
+ * Offer each rule a switch to one written expression. A rule that already is one always shows
31
+ * the switch, so it can go back to conditions.
32
+ */
33
+ allowExpressions?: boolean;
34
+ /** Carries a rule across when it switches between conditions and an expression. */
35
+ dialect?: RulesDialect;
36
+ /** Replaces the built-in expression editor. See `RenderRuleExpressionEditor`. */
37
+ renderExpressionEditor?: RenderRuleExpressionEditor;
38
+ /** Show every incomplete condition's and blank expression's message, as after a submit. */
39
+ forceErrors?: boolean;
40
+ /**
41
+ * Ids of rules and conditions to treat as already left, so their messages show, e.g. when
42
+ * restoring a draft. Read when each rule mounts.
43
+ */
44
+ defaultTouched?: readonly string[];
45
+ disabled?: boolean;
46
+ className?: string;
47
+ /** Overrides for any subset of the English strings. */
48
+ strings?: Partial<RulesEditorStrings>;
49
+ /**
50
+ * Overrides for the conditions' strings. Their `empty` is not shown: a rule with no conditions
51
+ * says it applies always, in its header.
52
+ */
53
+ conditionsStrings?: Partial<ConditionsEditorStrings>;
54
+ /** Overrides for the value-mode menu, indicator, and variable control. */
55
+ valueModeStrings?: Partial<ValueModeStrings>;
56
+ /** Overrides for the options control of an operator that takes several. */
57
+ multiSelectStrings?: Partial<MultiSelectStrings>;
58
+ }
59
+ /**
60
+ * Edits a list of rules. Each rule has an outcome, and either conditions or one written
61
+ * expression that decide when it applies. Controlled: it holds no rules of its own.
62
+ *
63
+ * Pass the vocabulary, strings, and render functions with a stable identity, such as module
64
+ * constants or memoised values: a new object on each render re-renders every rule.
65
+ */
66
+ export declare function RulesEditor({ value, onChange, label, outcomes, defaultOutcome, fields, operators, valueModes, variables, renderValue, showMatchMode, allowExpressions, dialect, renderExpressionEditor, forceErrors, defaultTouched, disabled, className, strings, conditionsStrings, valueModeStrings, multiSelectStrings, }: RulesEditorProps): import("react/jsx-runtime").JSX.Element;