@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
@@ -37,10 +37,55 @@ __webpack_require__.d(__webpack_exports__, {
37
37
  RulesEngine: ()=>RulesEngine,
38
38
  ExpressionBuilder: ()=>ExpressionBuilder
39
39
  });
40
+ const external_date_fns_namespaceObject = require("date-fns");
40
41
  const external_jsep_namespaceObject = require("jsep");
41
42
  var external_jsep_default = /*#__PURE__*/ __webpack_require__.n(external_jsep_namespaceObject);
42
43
  const index_cjs_namespaceObject = require("../../lib/index.cjs");
44
+ const date_value_cjs_namespaceObject = require("../../lib/date-value.cjs");
43
45
  const external_opaque_value_cjs_namespaceObject = require("./opaque-value.cjs");
46
+ const COMPARISON_OPERATORS = new Set([
47
+ '==',
48
+ '===',
49
+ '!=',
50
+ '!==',
51
+ '<',
52
+ '>',
53
+ '<=',
54
+ '>='
55
+ ]);
56
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
57
+ function isValidDate(value) {
58
+ return value instanceof Date && (0, external_date_fns_namespaceObject.isValid)(value);
59
+ }
60
+ function normalizeDateValues(left, right) {
61
+ if (!isValidDate(left) && !isValidDate(right)) return [
62
+ left,
63
+ right
64
+ ];
65
+ return [
66
+ normalizeDateValue(left, right),
67
+ normalizeDateValue(right, left)
68
+ ];
69
+ }
70
+ function normalizeDateValue(value, other) {
71
+ if (isValidDate(value)) return 'string' == typeof other && DATE_ONLY.test(other) ? (0, external_date_fns_namespaceObject.format)(value, 'yyyy-MM-dd') : value.getTime();
72
+ if ('string' == typeof value && !DATE_ONLY.test(value) && isValidDate(other)) return (0, date_value_cjs_namespaceObject.toDateValue)(value)?.getTime() ?? value;
73
+ return value;
74
+ }
75
+ function includesValue(list, value) {
76
+ if (!isValidDate(value)) return list.includes(value);
77
+ return list.some((item)=>{
78
+ const [a, b] = normalizeDateValues(value, item);
79
+ return a === b;
80
+ });
81
+ }
82
+ function isEmptyValue(value) {
83
+ if (null == value || '' === value) return true;
84
+ if (Array.isArray(value)) return 0 === value.length;
85
+ if ('object' != typeof value || (0, external_opaque_value_cjs_namespaceObject.isValueModeOpaque)(value)) return false;
86
+ const prototype = Object.getPrototypeOf(value);
87
+ return (prototype === Object.prototype || null === prototype) && 0 === Object.keys(value).length;
88
+ }
44
89
  class RulesEngine {
45
90
  static evaluateConditions(conditions, values, operator = 'AND') {
46
91
  if (0 === conditions.length) return true;
@@ -53,15 +98,27 @@ class RulesEngine {
53
98
  const result = RulesEngine.evaluateExpression(condition.custom, values);
54
99
  return 'boolean' == typeof result ? result : Boolean(result);
55
100
  }
56
- if (void 0 !== condition.is) return fieldValue === condition.is;
57
- if (void 0 !== condition.isNot) return fieldValue !== condition.isNot;
58
- if (void 0 !== condition.in) return condition.in.includes(fieldValue);
59
- if (void 0 !== condition.notIn) return !condition.notIn.includes(fieldValue);
101
+ if (void 0 !== condition.is) {
102
+ const [value, is] = normalizeDateValues(fieldValue, condition.is);
103
+ return value === is;
104
+ }
105
+ if (void 0 !== condition.isNot) {
106
+ const [value, isNot] = normalizeDateValues(fieldValue, condition.isNot);
107
+ return value !== isNot;
108
+ }
109
+ if (void 0 !== condition.in) return includesValue(condition.in, fieldValue);
110
+ if (void 0 !== condition.notIn) return !includesValue(condition.notIn, fieldValue);
60
111
  if (void 0 !== condition.matches) {
61
112
  if ((0, external_opaque_value_cjs_namespaceObject.isValueModeOpaque)(fieldValue)) return false;
62
- const regex = new RegExp(condition.matches);
113
+ let regex;
114
+ try {
115
+ regex = new RegExp(condition.matches);
116
+ } catch {
117
+ return false;
118
+ }
63
119
  return regex.test(String(fieldValue));
64
120
  }
121
+ if (void 0 !== condition.empty) return isEmptyValue(fieldValue) === condition.empty;
65
122
  return false;
66
123
  }
67
124
  static applyRules(rules, values, _context) {
@@ -106,8 +163,8 @@ class RulesEngine {
106
163
  case 'BinaryExpression':
107
164
  {
108
165
  const binary = node;
109
- const left = RulesEngine.evaluateNode(binary.left, values);
110
- const right = RulesEngine.evaluateNode(binary.right, values);
166
+ let left = RulesEngine.evaluateNode(binary.left, values);
167
+ let right = RulesEngine.evaluateNode(binary.right, values);
111
168
  if ((0, external_opaque_value_cjs_namespaceObject.isValueModeOpaque)(left) || (0, external_opaque_value_cjs_namespaceObject.isValueModeOpaque)(right)) {
112
169
  if ('!=' === binary.operator || '!==' === binary.operator) return true;
113
170
  if ([
@@ -119,6 +176,7 @@ class RulesEngine {
119
176
  '>='
120
177
  ].includes(binary.operator)) return false;
121
178
  }
179
+ if (COMPARISON_OPERATORS.has(binary.operator)) [left, right] = normalizeDateValues(left, right);
122
180
  switch(binary.operator){
123
181
  case '==':
124
182
  return left == right;
@@ -194,15 +252,46 @@ class RulesEngine {
194
252
  if (hasShowRule) return false;
195
253
  return true;
196
254
  }
255
+ static conditionFields(condition) {
256
+ const fields = new Set();
257
+ if (condition.when) fields.add(condition.when);
258
+ if (condition.custom) try {
259
+ collectFields(external_jsep_default()(condition.custom), fields);
260
+ } catch {}
261
+ return Array.from(fields);
262
+ }
197
263
  static buildDependencyGraph(rules) {
198
264
  const graph = new Map();
199
- for (const rule of rules)for (const condition of rule.conditions){
200
- if (!graph.has(condition.when)) graph.set(condition.when, new Set());
201
- graph.get(condition.when).add(rule.id);
265
+ for (const rule of rules)for (const condition of rule.conditions)for (const field of RulesEngine.conditionFields(condition)){
266
+ if (!graph.has(field)) graph.set(field, new Set());
267
+ graph.get(field).add(rule.id);
202
268
  }
203
269
  return graph;
204
270
  }
205
271
  }
272
+ function memberPath(node) {
273
+ if ('Identifier' === node.type) return node.name;
274
+ const member = node;
275
+ if ('MemberExpression' !== member.type || member.computed) return;
276
+ const object = memberPath(member.object);
277
+ return void 0 === object ? void 0 : `${object}.${member.property.name}`;
278
+ }
279
+ function collectFields(node, fields) {
280
+ const path = memberPath(node);
281
+ if (void 0 !== path) return void fields.add(path);
282
+ if ('MemberExpression' === node.type) {
283
+ const member = node;
284
+ collectFields(member.object, fields);
285
+ if (member.computed) collectFields(member.property, fields);
286
+ return;
287
+ }
288
+ for (const value of Object.values(node)){
289
+ const children = Array.isArray(value) ? value : [
290
+ value
291
+ ];
292
+ for (const child of children)if (child && 'object' == typeof child && 'type' in child) collectFields(child, fields);
293
+ }
294
+ }
206
295
  class ExpressionBuilder {
207
296
  static equals(field, value) {
208
297
  return `${field} == ${JSON.stringify(value)}`;
@@ -58,6 +58,11 @@ export declare class RulesEngine {
58
58
  * Extracted for reuse in validation and field rendering
59
59
  */
60
60
  static isFieldVisible(rules: FieldRule[] | undefined, values: Record<string, unknown>): boolean;
61
+ /**
62
+ * The fields a condition reads: its `when`, and every field its `custom` expression names. A
63
+ * form re-checks the condition when any of them changes.
64
+ */
65
+ static conditionFields(condition: FieldCondition): string[];
61
66
  /**
62
67
  * Build a dependency graph for optimized field watching
63
68
  */
@@ -1,6 +1,51 @@
1
+ import { format, isValid } from "date-fns";
1
2
  import jsep from "jsep";
2
3
  import { get } from "../../lib/index.js";
4
+ import { toDateValue } from "../../lib/date-value.js";
3
5
  import { isValueModeOpaque } from "./opaque-value.js";
6
+ const COMPARISON_OPERATORS = new Set([
7
+ '==',
8
+ '===',
9
+ '!=',
10
+ '!==',
11
+ '<',
12
+ '>',
13
+ '<=',
14
+ '>='
15
+ ]);
16
+ const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
17
+ function isValidDate(value) {
18
+ return value instanceof Date && isValid(value);
19
+ }
20
+ function normalizeDateValues(left, right) {
21
+ if (!isValidDate(left) && !isValidDate(right)) return [
22
+ left,
23
+ right
24
+ ];
25
+ return [
26
+ normalizeDateValue(left, right),
27
+ normalizeDateValue(right, left)
28
+ ];
29
+ }
30
+ function normalizeDateValue(value, other) {
31
+ if (isValidDate(value)) return 'string' == typeof other && DATE_ONLY.test(other) ? format(value, 'yyyy-MM-dd') : value.getTime();
32
+ if ('string' == typeof value && !DATE_ONLY.test(value) && isValidDate(other)) return toDateValue(value)?.getTime() ?? value;
33
+ return value;
34
+ }
35
+ function includesValue(list, value) {
36
+ if (!isValidDate(value)) return list.includes(value);
37
+ return list.some((item)=>{
38
+ const [a, b] = normalizeDateValues(value, item);
39
+ return a === b;
40
+ });
41
+ }
42
+ function isEmptyValue(value) {
43
+ if (null == value || '' === value) return true;
44
+ if (Array.isArray(value)) return 0 === value.length;
45
+ if ('object' != typeof value || isValueModeOpaque(value)) return false;
46
+ const prototype = Object.getPrototypeOf(value);
47
+ return (prototype === Object.prototype || null === prototype) && 0 === Object.keys(value).length;
48
+ }
4
49
  class RulesEngine {
5
50
  static evaluateConditions(conditions, values, operator = 'AND') {
6
51
  if (0 === conditions.length) return true;
@@ -13,15 +58,27 @@ class RulesEngine {
13
58
  const result = RulesEngine.evaluateExpression(condition.custom, values);
14
59
  return 'boolean' == typeof result ? result : Boolean(result);
15
60
  }
16
- if (void 0 !== condition.is) return fieldValue === condition.is;
17
- if (void 0 !== condition.isNot) return fieldValue !== condition.isNot;
18
- if (void 0 !== condition.in) return condition.in.includes(fieldValue);
19
- if (void 0 !== condition.notIn) return !condition.notIn.includes(fieldValue);
61
+ if (void 0 !== condition.is) {
62
+ const [value, is] = normalizeDateValues(fieldValue, condition.is);
63
+ return value === is;
64
+ }
65
+ if (void 0 !== condition.isNot) {
66
+ const [value, isNot] = normalizeDateValues(fieldValue, condition.isNot);
67
+ return value !== isNot;
68
+ }
69
+ if (void 0 !== condition.in) return includesValue(condition.in, fieldValue);
70
+ if (void 0 !== condition.notIn) return !includesValue(condition.notIn, fieldValue);
20
71
  if (void 0 !== condition.matches) {
21
72
  if (isValueModeOpaque(fieldValue)) return false;
22
- const regex = new RegExp(condition.matches);
73
+ let regex;
74
+ try {
75
+ regex = new RegExp(condition.matches);
76
+ } catch {
77
+ return false;
78
+ }
23
79
  return regex.test(String(fieldValue));
24
80
  }
81
+ if (void 0 !== condition.empty) return isEmptyValue(fieldValue) === condition.empty;
25
82
  return false;
26
83
  }
27
84
  static applyRules(rules, values, _context) {
@@ -66,8 +123,8 @@ class RulesEngine {
66
123
  case 'BinaryExpression':
67
124
  {
68
125
  const binary = node;
69
- const left = RulesEngine.evaluateNode(binary.left, values);
70
- const right = RulesEngine.evaluateNode(binary.right, values);
126
+ let left = RulesEngine.evaluateNode(binary.left, values);
127
+ let right = RulesEngine.evaluateNode(binary.right, values);
71
128
  if (isValueModeOpaque(left) || isValueModeOpaque(right)) {
72
129
  if ('!=' === binary.operator || '!==' === binary.operator) return true;
73
130
  if ([
@@ -79,6 +136,7 @@ class RulesEngine {
79
136
  '>='
80
137
  ].includes(binary.operator)) return false;
81
138
  }
139
+ if (COMPARISON_OPERATORS.has(binary.operator)) [left, right] = normalizeDateValues(left, right);
82
140
  switch(binary.operator){
83
141
  case '==':
84
142
  return left == right;
@@ -154,15 +212,46 @@ class RulesEngine {
154
212
  if (hasShowRule) return false;
155
213
  return true;
156
214
  }
215
+ static conditionFields(condition) {
216
+ const fields = new Set();
217
+ if (condition.when) fields.add(condition.when);
218
+ if (condition.custom) try {
219
+ collectFields(jsep(condition.custom), fields);
220
+ } catch {}
221
+ return Array.from(fields);
222
+ }
157
223
  static buildDependencyGraph(rules) {
158
224
  const graph = new Map();
159
- for (const rule of rules)for (const condition of rule.conditions){
160
- if (!graph.has(condition.when)) graph.set(condition.when, new Set());
161
- graph.get(condition.when).add(rule.id);
225
+ for (const rule of rules)for (const condition of rule.conditions)for (const field of RulesEngine.conditionFields(condition)){
226
+ if (!graph.has(field)) graph.set(field, new Set());
227
+ graph.get(field).add(rule.id);
162
228
  }
163
229
  return graph;
164
230
  }
165
231
  }
232
+ function memberPath(node) {
233
+ if ('Identifier' === node.type) return node.name;
234
+ const member = node;
235
+ if ('MemberExpression' !== member.type || member.computed) return;
236
+ const object = memberPath(member.object);
237
+ return void 0 === object ? void 0 : `${object}.${member.property.name}`;
238
+ }
239
+ function collectFields(node, fields) {
240
+ const path = memberPath(node);
241
+ if (void 0 !== path) return void fields.add(path);
242
+ if ('MemberExpression' === node.type) {
243
+ const member = node;
244
+ collectFields(member.object, fields);
245
+ if (member.computed) collectFields(member.property, fields);
246
+ return;
247
+ }
248
+ for (const value of Object.values(node)){
249
+ const children = Array.isArray(value) ? value : [
250
+ value
251
+ ];
252
+ for (const child of children)if (child && 'object' == typeof child && 'type' in child) collectFields(child, fields);
253
+ }
254
+ }
166
255
  class ExpressionBuilder {
167
256
  static equals(field, value) {
168
257
  return `${field} == ${JSON.stringify(value)}`;
@@ -0,0 +1,122 @@
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
+ useFieldRules: ()=>useFieldRules
28
+ });
29
+ const external_react_namespaceObject = require("react");
30
+ const index_cjs_namespaceObject = require("../ui/rules-editor/index.cjs");
31
+ const external_field_rules_cjs_namespaceObject = require("./field-rules.cjs");
32
+ const external_rules_engine_dialect_cjs_namespaceObject = require("./rules-engine-dialect.cjs");
33
+ function canonicalJson(value) {
34
+ return JSON.stringify(value, (_key, inner)=>inner && 'object' == typeof inner && !Array.isArray(inner) ? Object.fromEntries(Object.entries(inner).sort(([a], [b])=>a < b ? -1 : a > b ? 1 : 0)) : inner);
35
+ }
36
+ const contentKey = (rules, flag)=>canonicalJson([
37
+ rules ?? null,
38
+ flag ?? null
39
+ ]);
40
+ function useFieldRules(stored, onChange, options) {
41
+ const flag = (0, external_field_rules_cjs_namespaceObject.flagOutcome)(options) ? !!stored.required : void 0;
42
+ const [state, setState] = external_react_namespaceObject.useState(()=>({
43
+ source: stored.rules,
44
+ flag,
45
+ key: contentKey(stored.rules, flag),
46
+ rules: (0, external_field_rules_cjs_namespaceObject.readStoredRules)(stored, options)
47
+ }));
48
+ const [written] = external_react_namespaceObject.useState(()=>new WeakMap());
49
+ const lastWritten = external_react_namespaceObject.useRef(void 0);
50
+ const always = external_react_namespaceObject.useRef(null);
51
+ always.current ??= (0, external_field_rules_cjs_namespaceObject.alwaysApplying)(state.rules);
52
+ let current = state;
53
+ if (stored.rules !== state.source || flag !== state.flag) {
54
+ const echo = void 0 !== stored.rules && written.has(stored.rules) && written.get(stored.rules) === flag;
55
+ const key = contentKey(stored.rules, flag);
56
+ if (echo || key !== state.key) {
57
+ const own = echo || key === lastWritten.current;
58
+ const rules = own ? state.rules : (0, external_field_rules_cjs_namespaceObject.readStoredRules)(stored, options);
59
+ if (!own) always.current = (0, external_field_rules_cjs_namespaceObject.alwaysApplying)(rules);
60
+ current = {
61
+ source: stored.rules,
62
+ flag,
63
+ key,
64
+ rules
65
+ };
66
+ setState(current);
67
+ }
68
+ }
69
+ const latest = external_react_namespaceObject.useRef({
70
+ onChange,
71
+ options,
72
+ required: !!stored.required
73
+ });
74
+ latest.current = {
75
+ onChange,
76
+ options,
77
+ required: !!stored.required
78
+ };
79
+ const change = external_react_namespaceObject.useCallback((next)=>{
80
+ const { onChange, options, required } = latest.current;
81
+ const settled = (0, external_field_rules_cjs_namespaceObject.settleAlways)(next, options, always.current ?? new Set());
82
+ always.current = (0, external_field_rules_cjs_namespaceObject.alwaysApplying)(settled);
83
+ const result = (0, external_field_rules_cjs_namespaceObject.writeStoredRules)(settled, options);
84
+ const owned = void 0 !== (0, external_field_rules_cjs_namespaceObject.flagOutcome)(options);
85
+ const nextRequired = owned ? result.required : required;
86
+ written.set(result.rules, owned ? nextRequired : void 0);
87
+ lastWritten.current = contentKey(result.rules, owned ? nextRequired : void 0);
88
+ setState((previous)=>({
89
+ ...previous,
90
+ rules: next
91
+ }));
92
+ onChange({
93
+ rules: result.rules,
94
+ required: nextRequired
95
+ });
96
+ }, [
97
+ written
98
+ ]);
99
+ const issues = external_react_namespaceObject.useMemo(()=>(0, index_cjs_namespaceObject.findRuleIssues)(current.rules, {
100
+ outcomes: options.outcomes,
101
+ fields: options.fields,
102
+ operators: options.operators ?? external_rules_engine_dialect_cjs_namespaceObject.RULES_ENGINE_OPERATORS,
103
+ valueModes: external_rules_engine_dialect_cjs_namespaceObject.rulesEngineVocabulary.valueModes
104
+ }, external_rules_engine_dialect_cjs_namespaceObject.rulesEngineDialect), [
105
+ current.rules,
106
+ options.outcomes,
107
+ options.fields,
108
+ options.operators
109
+ ]);
110
+ return {
111
+ value: current.rules,
112
+ onChange: change,
113
+ issues
114
+ };
115
+ }
116
+ exports.useFieldRules = __webpack_exports__.useFieldRules;
117
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
118
+ "useFieldRules"
119
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
120
+ Object.defineProperty(exports, '__esModule', {
121
+ value: true
122
+ });
@@ -0,0 +1,31 @@
1
+ import { type Rule } from '../ui/rules-editor';
2
+ import { type FieldRulesOptions, type StoredFieldRules } from './field-rules';
3
+ import type { FieldRule } from './form-schema';
4
+ /**
5
+ * Connects a RulesEditor to a field's stored `FieldRule`s. The editor keeps its own rules, so a
6
+ * host that writes on every change keeps blank rows and focus, and the stored rules are read again
7
+ * only when their content changes from outside. A host may pass a new array on every render, such
8
+ * as one parsed again from its schema: an array with the content last read or written, in any key
9
+ * order, is not news.
10
+ *
11
+ * With `options.requiredOutcome`, the field's own `required` flag reads as a rule of that outcome
12
+ * with no conditions, and `onChange` writes that rule back as the flag, in the same call as the
13
+ * rules.
14
+ *
15
+ * A rule that applied always goes on being stored that way once it is given a condition, until one
16
+ * of its conditions is finished: a required field stays required while its first condition is
17
+ * filled in.
18
+ *
19
+ * `issues` lists what needs attention in the editor's rules, unfinished ones included, as
20
+ * `findRuleIssues` finds it with `rulesEngineDialect`: such as to flag the field elsewhere.
21
+ *
22
+ * Pass `options` with a stable identity: a new object re-reads nothing, but writes use the latest.
23
+ */
24
+ export declare function useFieldRules(stored: StoredFieldRules, onChange: (next: {
25
+ rules: FieldRule[];
26
+ required: boolean;
27
+ }) => void, options: FieldRulesOptions): {
28
+ value: Rule[];
29
+ onChange: (next: Rule[]) => void;
30
+ issues: import("../ui/rules-editor").RuleIssue[];
31
+ };
@@ -0,0 +1,88 @@
1
+ import { useCallback, useMemo, useRef, useState } from "react";
2
+ import { findRuleIssues } from "../ui/rules-editor/index.js";
3
+ import { alwaysApplying, flagOutcome, readStoredRules, settleAlways, writeStoredRules } from "./field-rules.js";
4
+ import { RULES_ENGINE_OPERATORS, rulesEngineDialect, rulesEngineVocabulary } from "./rules-engine-dialect.js";
5
+ function canonicalJson(value) {
6
+ return JSON.stringify(value, (_key, inner)=>inner && 'object' == typeof inner && !Array.isArray(inner) ? Object.fromEntries(Object.entries(inner).sort(([a], [b])=>a < b ? -1 : a > b ? 1 : 0)) : inner);
7
+ }
8
+ const contentKey = (rules, flag)=>canonicalJson([
9
+ rules ?? null,
10
+ flag ?? null
11
+ ]);
12
+ function useFieldRules(stored, onChange, options) {
13
+ const flag = flagOutcome(options) ? !!stored.required : void 0;
14
+ const [state, setState] = useState(()=>({
15
+ source: stored.rules,
16
+ flag,
17
+ key: contentKey(stored.rules, flag),
18
+ rules: readStoredRules(stored, options)
19
+ }));
20
+ const [written] = useState(()=>new WeakMap());
21
+ const lastWritten = useRef(void 0);
22
+ const always = useRef(null);
23
+ always.current ??= alwaysApplying(state.rules);
24
+ let current = state;
25
+ if (stored.rules !== state.source || flag !== state.flag) {
26
+ const echo = void 0 !== stored.rules && written.has(stored.rules) && written.get(stored.rules) === flag;
27
+ const key = contentKey(stored.rules, flag);
28
+ if (echo || key !== state.key) {
29
+ const own = echo || key === lastWritten.current;
30
+ const rules = own ? state.rules : readStoredRules(stored, options);
31
+ if (!own) always.current = alwaysApplying(rules);
32
+ current = {
33
+ source: stored.rules,
34
+ flag,
35
+ key,
36
+ rules
37
+ };
38
+ setState(current);
39
+ }
40
+ }
41
+ const latest = useRef({
42
+ onChange,
43
+ options,
44
+ required: !!stored.required
45
+ });
46
+ latest.current = {
47
+ onChange,
48
+ options,
49
+ required: !!stored.required
50
+ };
51
+ const change = useCallback((next)=>{
52
+ const { onChange, options, required } = latest.current;
53
+ const settled = settleAlways(next, options, always.current ?? new Set());
54
+ always.current = alwaysApplying(settled);
55
+ const result = writeStoredRules(settled, options);
56
+ const owned = void 0 !== flagOutcome(options);
57
+ const nextRequired = owned ? result.required : required;
58
+ written.set(result.rules, owned ? nextRequired : void 0);
59
+ lastWritten.current = contentKey(result.rules, owned ? nextRequired : void 0);
60
+ setState((previous)=>({
61
+ ...previous,
62
+ rules: next
63
+ }));
64
+ onChange({
65
+ rules: result.rules,
66
+ required: nextRequired
67
+ });
68
+ }, [
69
+ written
70
+ ]);
71
+ const issues = useMemo(()=>findRuleIssues(current.rules, {
72
+ outcomes: options.outcomes,
73
+ fields: options.fields,
74
+ operators: options.operators ?? RULES_ENGINE_OPERATORS,
75
+ valueModes: rulesEngineVocabulary.valueModes
76
+ }, rulesEngineDialect), [
77
+ current.rules,
78
+ options.outcomes,
79
+ options.fields,
80
+ options.operators
81
+ ]);
82
+ return {
83
+ value: current.rules,
84
+ onChange: change,
85
+ issues
86
+ };
87
+ }
88
+ export { useFieldRules };