@uipath/apollo-wind 2.92.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 (130) 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/data-table.cjs +493 -104
  51. package/dist/components/ui/data-table.d.ts +88 -5
  52. package/dist/components/ui/data-table.js +491 -105
  53. package/dist/components/ui/editable-cell.cjs +91 -27
  54. package/dist/components/ui/editable-cell.d.ts +14 -1
  55. package/dist/components/ui/editable-cell.js +91 -27
  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 +282 -243
  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/index.cjs +132 -8
  127. package/dist/index.d.ts +19 -6
  128. package/dist/index.js +11 -4
  129. package/dist/styles.css +119 -24
  130. package/package.json +2 -2
@@ -1,21 +1,26 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { AlertTriangle, Asterisk, Ban, ChevronRight, Code, Database, Eye, EyeOff, GitBranch, GripVertical, Layers, MoveDown, MoveUp, Plus, Settings, Trash2, View } from "lucide-react";
3
- import { useEffect, useMemo, useState } from "react";
2
+ import { AlertTriangle, Asterisk, ChevronRight, Code, Database, Eye, GitBranch, GripVertical, Layers, MoveDown, MoveUp, Plus, Settings, Trash2, View } from "lucide-react";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
4
  import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "../ui/accordion.js";
5
5
  import { Button } from "../ui/button.js";
6
6
  import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card.js";
7
7
  import { Checkbox } from "../ui/checkbox.js";
8
+ import { createConditionGroup } from "../ui/conditions-editor/index.js";
8
9
  import { Input } from "../ui/input.js";
9
10
  import { Label, RequiredIndicator } from "../ui/label.js";
10
11
  import { Grid } from "../ui/layout/grid.js";
12
+ import { RulesEditor, createRule, findRuleIssues, isUnconditionalRule, issueIds } from "../ui/rules-editor/index.js";
11
13
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select.js";
12
14
  import { Separator } from "../ui/separator.js";
13
15
  import { Switch } from "../ui/switch.js";
14
16
  import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs.js";
15
17
  import { Textarea } from "../ui/textarea.js";
16
18
  import { createAiAssistAction, createInsertVariableAction } from "./field-actions.js";
19
+ import { fromFieldRules, renameFieldInRules } from "./field-rules.js";
17
20
  import { MetadataForm } from "./metadata-form.js";
21
+ import { rulesEngineDialect, rulesEngineVocabulary } from "./rules-engine-dialect.js";
18
22
  import { schemaToJson } from "./schema-serializer.js";
23
+ import { useFieldRules } from "./use-field-rules.js";
19
24
  const FIELD_TYPE_METADATA = [
20
25
  {
21
26
  value: 'text',
@@ -971,20 +976,11 @@ function FieldConfigForm({ field, onUpdate, allFields, existingFieldNames }) {
971
976
  }),
972
977
  /*#__PURE__*/ jsx(AccordionContent, {
973
978
  className: "pt-2",
974
- children: /*#__PURE__*/ jsx(RulesEditor, {
975
- rules: field.rules,
976
- onChange: (rules)=>onUpdate({
977
- rules
978
- }),
979
+ children: /*#__PURE__*/ jsx(FieldRulesEditor, {
980
+ field: field,
979
981
  allFields: allFields,
980
- requiredMessage: field.validation?.requiredMessage,
981
- onRequiredMessageChange: (message)=>onUpdate({
982
- validation: {
983
- ...field.validation,
984
- requiredMessage: message
985
- }
986
- })
987
- })
982
+ onUpdate: onUpdate
983
+ }, field.id)
988
984
  })
989
985
  ]
990
986
  })
@@ -1019,6 +1015,11 @@ function FormDesigner() {
1019
1015
  ]);
1020
1016
  const [previewDisabled, setPreviewDisabled] = useState(false);
1021
1017
  const allFields = sections.flatMap((s)=>s.fields);
1018
+ const ruleOptions = useRuleOptions(allFields);
1019
+ const lastNames = useRef(new Map());
1020
+ useEffect(()=>{
1021
+ for (const field of allFields)if (field.name) lastNames.current.set(field.id, field.name);
1022
+ });
1022
1023
  const selectedSection = sections.find((s)=>s.id === selectedSectionId);
1023
1024
  const selectedField = allFields.find((f)=>f.id === selectedFieldId);
1024
1025
  const generatedSchema = {
@@ -1148,12 +1149,21 @@ function FormDesigner() {
1148
1149
  }
1149
1150
  }
1150
1151
  }
1152
+ const previousName = prevAllFields.find((f)=>f.id === fieldId)?.name || lastNames.current.get(fieldId);
1153
+ const renamed = finalUpdates.name && previousName && finalUpdates.name !== previousName ? {
1154
+ from: previousName,
1155
+ to: finalUpdates.name
1156
+ } : void 0;
1157
+ const follow = (f)=>renamed && f.rules ? {
1158
+ ...f,
1159
+ rules: renameFieldInRules(f.rules, renamed.from, renamed.to)
1160
+ } : f;
1151
1161
  return prevSections.map((s)=>({
1152
1162
  ...s,
1153
- fields: s.fields.map((f)=>f.id === fieldId ? {
1163
+ fields: s.fields.map((f)=>follow(f.id === fieldId ? {
1154
1164
  ...f,
1155
1165
  ...finalUpdates
1156
- } : f)
1166
+ } : f))
1157
1167
  }));
1158
1168
  });
1159
1169
  };
@@ -1349,6 +1359,11 @@ function FormDesigner() {
1349
1359
  }),
1350
1360
  field.rules?.some((r)=>r.effects.required) && /*#__PURE__*/ jsx(RequiredIndicator, {
1351
1361
  className: "ml-0 text-[10px]"
1362
+ }),
1363
+ rulesNeedAttention(field.rules, ruleOptions) && /*#__PURE__*/ jsx(AlertTriangle, {
1364
+ role: "img",
1365
+ "aria-label": "Rules need attention",
1366
+ className: "h-3 w-3 shrink-0 text-destructive"
1352
1367
  })
1353
1368
  ]
1354
1369
  }),
@@ -1861,286 +1876,188 @@ function DataSourceEditor({ dataSource, onChange }) {
1861
1876
  ]
1862
1877
  });
1863
1878
  }
1864
- const CONDITION_OPERATORS = [
1865
- {
1866
- value: 'is',
1867
- label: 'equals',
1868
- description: 'Field value equals'
1869
- },
1879
+ const DESIGNER_OUTCOMES = [
1870
1880
  {
1871
- value: 'isNot',
1872
- label: 'not equals',
1873
- description: 'Field value does not equal'
1881
+ value: 'show',
1882
+ label: 'Show',
1883
+ effects: {
1884
+ visible: true
1885
+ }
1874
1886
  },
1875
1887
  {
1876
- value: 'in',
1877
- label: 'is one of',
1878
- description: 'Field value is one of'
1888
+ value: 'hide',
1889
+ label: 'Hide',
1890
+ effects: {
1891
+ visible: false
1892
+ }
1879
1893
  },
1880
1894
  {
1881
- value: 'notIn',
1882
- label: 'is not one of',
1883
- description: 'Field value is not one of'
1895
+ value: 'require',
1896
+ label: 'Require',
1897
+ effects: {
1898
+ required: true
1899
+ }
1884
1900
  },
1885
1901
  {
1886
- value: 'matches',
1887
- label: 'matches pattern',
1888
- description: 'Field value matches regex'
1902
+ value: 'disable',
1903
+ label: 'Disable',
1904
+ effects: {
1905
+ disabled: true
1906
+ }
1889
1907
  }
1890
1908
  ];
1891
- const RULE_EFFECTS = [
1909
+ const ALWAYS_REQUIRED_ID = 'always-required';
1910
+ const BOOLEAN_OPTIONS = [
1892
1911
  {
1893
- value: 'show',
1894
- label: 'Show field',
1895
- description: 'Show this field when conditions are met',
1896
- Icon: Eye,
1897
- color: 'text-success bg-success-background border-success/30'
1912
+ value: 'true',
1913
+ label: 'Yes'
1898
1914
  },
1899
1915
  {
1900
- value: 'hide',
1901
- label: 'Hide field',
1902
- description: 'Hide this field when conditions are met',
1903
- Icon: EyeOff,
1904
- color: 'text-warning bg-warning-background border-warning/30'
1905
- },
1906
- {
1907
- value: 'require',
1908
- label: 'Make required',
1909
- description: 'Require this field when conditions are met',
1910
- Icon: Asterisk,
1911
- color: 'text-error bg-error-background border-error/30'
1912
- },
1913
- {
1914
- value: 'disable',
1915
- label: 'Disable field',
1916
- description: 'Disable this field when conditions are met',
1917
- Icon: Ban,
1918
- color: 'text-muted-foreground bg-muted border-border'
1916
+ value: 'false',
1917
+ label: 'No'
1919
1918
  }
1920
1919
  ];
1921
- function RulesEditor({ rules = [], onChange, allFields, requiredMessage, onRequiredMessageChange }) {
1922
- const [isAddingRule, setIsAddingRule] = useState(false);
1923
- const [editingRuleIndex, setEditingRuleIndex] = useState(null);
1924
- const [selectedEffect, setSelectedEffect] = useState('show');
1925
- const [conditions, setConditions] = useState([
1926
- {
1927
- field: '',
1928
- operator: 'is',
1929
- value: ''
1930
- }
1931
- ]);
1932
- const [conditionOperator, setConditionOperator] = useState('AND');
1933
- const isAlwaysRequired = rules.some((r)=>true === r.effects.required && 0 === r.conditions.length);
1934
- const resetBuilder = ()=>{
1935
- setSelectedEffect('show');
1936
- setConditions([
1937
- {
1938
- field: '',
1939
- operator: 'is',
1940
- value: ''
1941
- }
1942
- ]);
1943
- setConditionOperator('AND');
1944
- setIsAddingRule(false);
1945
- setEditingRuleIndex(null);
1946
- };
1947
- const addCondition = ()=>{
1948
- setConditions([
1949
- ...conditions,
1950
- {
1951
- field: '',
1952
- operator: 'is',
1953
- value: ''
1954
- }
1955
- ]);
1956
- };
1957
- const updateCondition = (index, updates)=>{
1958
- const newConditions = [
1959
- ...conditions
1960
- ];
1961
- newConditions[index] = {
1962
- ...newConditions[index],
1963
- ...updates
1964
- };
1965
- setConditions(newConditions);
1966
- };
1967
- const removeCondition = (index)=>{
1968
- if (conditions.length > 1) setConditions(conditions.filter((_, i)=>i !== index));
1920
+ function ruleFieldFor(field) {
1921
+ const base = {
1922
+ value: field.name,
1923
+ label: field.label || field.name
1969
1924
  };
1970
- const buildCondition = (cond)=>{
1971
- const condition = {
1972
- when: cond.field
1973
- };
1974
- const targetField = allFields.find((f)=>f.name === cond.field);
1975
- const isNumericField = targetField?.type === 'number' || targetField?.type === 'slider';
1976
- const isBooleanField = targetField?.type === 'checkbox' || targetField?.type === 'switch' || targetField?.type === 'boolean';
1977
- const parseValue = (val)=>{
1978
- if (isBooleanField) {
1979
- if ('true' === val.toLowerCase()) return true;
1980
- if ('false' === val.toLowerCase()) return false;
1981
- }
1982
- if (isNumericField) {
1983
- const num = Number(val);
1984
- if (!isNaN(num)) return num;
1985
- }
1986
- if ('true' === val.toLowerCase()) return true;
1987
- if ('false' === val.toLowerCase()) return false;
1988
- return val;
1989
- };
1990
- switch(cond.operator){
1991
- case 'is':
1992
- condition.is = parseValue(cond.value);
1993
- break;
1994
- case 'isNot':
1995
- condition.isNot = parseValue(cond.value);
1996
- break;
1997
- case 'in':
1998
- condition.in = cond.value.split(',').map((v)=>parseValue(v.trim()));
1999
- break;
2000
- case 'notIn':
2001
- condition.notIn = cond.value.split(',').map((v)=>parseValue(v.trim()));
2002
- break;
2003
- case 'matches':
2004
- condition.matches = cond.value;
2005
- break;
2006
- }
2007
- return condition;
1925
+ const enumOf = (options)=>options.map((option)=>({
1926
+ value: String(option.value),
1927
+ label: option.label
1928
+ }));
1929
+ const boolean = {
1930
+ ...base,
1931
+ type: 'enum',
1932
+ valueType: 'boolean',
1933
+ options: BOOLEAN_OPTIONS
2008
1934
  };
2009
- const saveRule = ()=>{
2010
- const validConditions = conditions.filter((c)=>c.field);
2011
- if (0 === validConditions.length) return;
2012
- const newRule = {
2013
- id: `rule-${Date.now()}`,
2014
- conditions: validConditions.map(buildCondition),
2015
- operator: conditionOperator,
2016
- effects: {}
2017
- };
2018
- switch(selectedEffect){
2019
- case 'show':
2020
- newRule.effects.visible = true;
2021
- break;
2022
- case 'hide':
2023
- newRule.effects.visible = false;
2024
- break;
2025
- case 'require':
2026
- newRule.effects.required = true;
2027
- break;
2028
- case 'disable':
2029
- newRule.effects.disabled = true;
2030
- break;
2031
- }
2032
- if (null !== editingRuleIndex) {
2033
- const newRules = [
2034
- ...rules
2035
- ];
2036
- newRules[editingRuleIndex] = newRule;
2037
- onChange(newRules);
2038
- } else onChange([
2039
- ...rules,
2040
- newRule
2041
- ]);
2042
- resetBuilder();
2043
- };
2044
- const editRule = (index)=>{
2045
- const rule = rules[index];
2046
- if (!rule) return;
2047
- let effect = 'show';
2048
- if (true === rule.effects.visible) effect = 'show';
2049
- else if (false === rule.effects.visible) effect = 'hide';
2050
- else if (true === rule.effects.required) effect = 'require';
2051
- else if (true === rule.effects.disabled) effect = 'disable';
2052
- setSelectedEffect(effect);
2053
- setConditionOperator(rule.operator || 'AND');
2054
- const editableConditions = rule.conditions.map((cond)=>{
2055
- let operator = 'is';
2056
- let value = '';
2057
- if (void 0 !== cond.is) {
2058
- operator = 'is';
2059
- value = String(cond.is);
2060
- } else if (void 0 !== cond.isNot) {
2061
- operator = 'isNot';
2062
- value = String(cond.isNot);
2063
- } else if (void 0 !== cond.in) {
2064
- operator = 'in';
2065
- value = cond.in.map(String).join(', ');
2066
- } else if (void 0 !== cond.notIn) {
2067
- operator = 'notIn';
2068
- value = cond.notIn.map(String).join(', ');
2069
- } else if (void 0 !== cond.matches) {
2070
- operator = 'matches';
2071
- value = cond.matches;
2072
- }
1935
+ switch(field.type){
1936
+ case 'text':
1937
+ case 'email':
1938
+ case 'textarea':
2073
1939
  return {
2074
- field: cond.when,
2075
- operator,
2076
- value
1940
+ ...base,
1941
+ type: 'string'
2077
1942
  };
2078
- });
2079
- setConditions(editableConditions.length > 0 ? editableConditions : [
1943
+ case 'number':
1944
+ case 'slider':
1945
+ return {
1946
+ ...base,
1947
+ type: 'number'
1948
+ };
1949
+ case 'date':
1950
+ case 'datetime':
1951
+ return {
1952
+ ...base,
1953
+ type: 'date'
1954
+ };
1955
+ case 'select':
1956
+ case 'radio':
1957
+ return {
1958
+ ...base,
1959
+ type: 'enum',
1960
+ options: enumOf(field.options ?? [])
1961
+ };
1962
+ case 'checkbox':
1963
+ case 'switch':
1964
+ case 'boolean':
1965
+ return boolean;
1966
+ case 'custom':
2080
1967
  {
2081
- field: '',
2082
- operator: 'is',
2083
- value: ''
1968
+ const { valueType } = field;
1969
+ if ('string' === valueType) return {
1970
+ ...base,
1971
+ type: 'string'
1972
+ };
1973
+ if ('number' === valueType) return {
1974
+ ...base,
1975
+ type: 'number'
1976
+ };
1977
+ if ('boolean' === valueType) return boolean;
1978
+ return {
1979
+ ...base,
1980
+ type: 'other'
1981
+ };
2084
1982
  }
2085
- ]);
2086
- setEditingRuleIndex(index);
2087
- setIsAddingRule(true);
2088
- };
2089
- const deleteRule = (index)=>{
2090
- onChange(rules.filter((_, i)=>i !== index));
2091
- };
2092
- const getFieldLabel = (fieldName)=>{
2093
- const field = allFields.find((f)=>f.name === fieldName);
2094
- return field?.label || fieldName;
1983
+ default:
1984
+ return {
1985
+ ...base,
1986
+ type: 'other'
1987
+ };
1988
+ }
1989
+ }
1990
+ function useRuleOptions(allFields) {
1991
+ const fields = allFields.flatMap((field)=>field.name ? ruleFieldFor(field) : []);
1992
+ const key = JSON.stringify(fields);
1993
+ return useMemo(()=>({
1994
+ outcomes: DESIGNER_OUTCOMES,
1995
+ fields
1996
+ }), [
1997
+ key
1998
+ ]);
1999
+ }
2000
+ const attention = new WeakMap();
2001
+ function rulesNeedAttention(rules, options) {
2002
+ if (!rules?.length) return false;
2003
+ let byRules = attention.get(options);
2004
+ if (!byRules) {
2005
+ byRules = new WeakMap();
2006
+ attention.set(options, byRules);
2007
+ }
2008
+ const known = byRules.get(rules);
2009
+ if (void 0 !== known) return known;
2010
+ const vocabulary = {
2011
+ ...options,
2012
+ ...rulesEngineVocabulary
2095
2013
  };
2096
- const describeRule = (rule)=>{
2097
- if (0 === rule.conditions.length) {
2098
- if (rule.effects.required) return 'Always required';
2099
- return 'Always applies';
2100
- }
2101
- const conditionDescriptions = rule.conditions.map((cond)=>{
2102
- const fieldLabel = getFieldLabel(cond.when);
2103
- if (void 0 !== cond.is) return `"${fieldLabel}" = ${JSON.stringify(cond.is)}`;
2104
- if (void 0 !== cond.isNot) return `"${fieldLabel}" ≠ ${JSON.stringify(cond.isNot)}`;
2105
- if (void 0 !== cond.in) return `"${fieldLabel}" in [${cond.in.map((v)=>JSON.stringify(v)).join(', ')}]`;
2106
- if (void 0 !== cond.notIn) return `"${fieldLabel}" not in [${cond.notIn.map((v)=>JSON.stringify(v)).join(', ')}]`;
2107
- if (void 0 !== cond.matches) return `"${fieldLabel}" matches /${cond.matches}/`;
2108
- return `"${fieldLabel}"`;
2014
+ const flagged = findRuleIssues(fromFieldRules(rules, options), vocabulary, rulesEngineDialect).length > 0;
2015
+ byRules.set(rules, flagged);
2016
+ return flagged;
2017
+ }
2018
+ const form_designer_isAlwaysRequired = (rule)=>'require' === rule.outcome && isUnconditionalRule(rule);
2019
+ function FieldRulesEditor({ field, allFields, onUpdate }) {
2020
+ const options = useRuleOptions(allFields);
2021
+ const requiredMessage = field.validation?.requiredMessage;
2022
+ const editor = useFieldRules({
2023
+ rules: field.rules
2024
+ }, ({ rules })=>{
2025
+ const stillRequired = rules.some((rule)=>true === rule.effects.required && 0 === rule.conditions.length);
2026
+ onUpdate({
2027
+ rules,
2028
+ ...stillRequired || !requiredMessage ? {} : {
2029
+ validation: {
2030
+ ...field.validation,
2031
+ requiredMessage: void 0
2032
+ }
2033
+ }
2109
2034
  });
2110
- const operator = 'OR' === rule.operator ? ' OR ' : ' AND ';
2111
- return conditionDescriptions.join(operator);
2112
- };
2113
- const getEffectDescription = (rule)=>{
2114
- if (true === rule.effects.visible) return {
2115
- label: 'Show',
2116
- color: 'text-success bg-success-background'
2117
- };
2118
- if (false === rule.effects.visible) return {
2119
- label: 'Hide',
2120
- color: 'text-warning bg-warning-background'
2121
- };
2122
- if (true === rule.effects.required) return {
2123
- label: 'Required',
2124
- color: 'text-error bg-error-background'
2125
- };
2126
- if (true === rule.effects.disabled) return {
2127
- label: 'Disabled',
2128
- color: 'text-muted-foreground bg-muted'
2129
- };
2130
- return {
2131
- label: 'Unknown',
2132
- color: 'text-muted-foreground bg-muted'
2133
- };
2134
- };
2135
- const getFieldOptions = (fieldName)=>{
2136
- const field = allFields.find((f)=>f.name === fieldName);
2137
- return field?.options || [];
2138
- };
2035
+ }, options);
2036
+ const alwaysRequired = editor.value.find(form_designer_isAlwaysRequired);
2037
+ const rules = alwaysRequired ? editor.value.filter((rule)=>rule !== alwaysRequired) : editor.value;
2038
+ const changeRules = (next)=>editor.onChange(alwaysRequired ? [
2039
+ ...next,
2040
+ alwaysRequired
2041
+ ] : next);
2042
+ const setAlwaysRequired = (on)=>editor.onChange(on ? [
2043
+ ...editor.value,
2044
+ createRule({
2045
+ id: ALWAYS_REQUIRED_ID,
2046
+ outcome: 'require',
2047
+ conditions: createConditionGroup()
2048
+ })
2049
+ ] : [
2050
+ ...rules
2051
+ ]);
2052
+ const editorKey = options.fields.map((option)=>option.value).join('\n');
2053
+ const touched = useMemo(()=>issueIds(editor.issues), [
2054
+ editorKey
2055
+ ]);
2139
2056
  return /*#__PURE__*/ jsxs("div", {
2140
2057
  className: "space-y-4",
2141
2058
  children: [
2142
2059
  /*#__PURE__*/ jsxs("div", {
2143
- className: "space-y-3 p-3 border rounded-lg bg-muted/30",
2060
+ className: "space-y-3 rounded-lg border bg-muted/30 p-3",
2144
2061
  children: [
2145
2062
  /*#__PURE__*/ jsxs("div", {
2146
2063
  className: "flex items-center justify-between",
@@ -2154,6 +2071,7 @@ function RulesEditor({ rules = [], onChange, allFields, requiredMessage, onRequi
2154
2071
  /*#__PURE__*/ jsxs("div", {
2155
2072
  children: [
2156
2073
  /*#__PURE__*/ jsx(Label, {
2074
+ htmlFor: `always-required-${field.id}`,
2157
2075
  className: "cursor-pointer font-medium",
2158
2076
  children: "Always required"
2159
2077
  }),
@@ -2166,31 +2084,13 @@ function RulesEditor({ rules = [], onChange, allFields, requiredMessage, onRequi
2166
2084
  ]
2167
2085
  }),
2168
2086
  /*#__PURE__*/ jsx(Checkbox, {
2169
- "aria-label": "Always required",
2170
- checked: isAlwaysRequired,
2171
- onCheckedChange: (checked)=>{
2172
- if (checked) {
2173
- const requiredRule = {
2174
- id: 'always-required',
2175
- conditions: [],
2176
- operator: 'AND',
2177
- effects: {
2178
- required: true
2179
- }
2180
- };
2181
- onChange([
2182
- ...rules.filter((r)=>!(r.effects.required && 0 === r.conditions.length)),
2183
- requiredRule
2184
- ]);
2185
- } else {
2186
- onChange(rules.filter((r)=>!(r.effects.required && 0 === r.conditions.length)));
2187
- onRequiredMessageChange(void 0);
2188
- }
2189
- }
2087
+ id: `always-required-${field.id}`,
2088
+ checked: !!alwaysRequired,
2089
+ onCheckedChange: (checked)=>setAlwaysRequired(true === checked)
2190
2090
  })
2191
2091
  ]
2192
2092
  }),
2193
- isAlwaysRequired && /*#__PURE__*/ jsxs("div", {
2093
+ alwaysRequired && /*#__PURE__*/ jsxs("div", {
2194
2094
  className: "space-y-1.5 pl-8",
2195
2095
  children: [
2196
2096
  /*#__PURE__*/ jsx(Label, {
@@ -2202,313 +2102,29 @@ function RulesEditor({ rules = [], onChange, allFields, requiredMessage, onRequi
2202
2102
  id: "required-message",
2203
2103
  placeholder: "This field is required",
2204
2104
  value: requiredMessage || '',
2205
- onChange: (e)=>onRequiredMessageChange(e.target.value || void 0),
2105
+ onChange: (e)=>onUpdate({
2106
+ validation: {
2107
+ ...field.validation,
2108
+ requiredMessage: e.target.value || void 0
2109
+ }
2110
+ }),
2206
2111
  className: "h-8 text-sm"
2207
2112
  })
2208
2113
  ]
2209
2114
  })
2210
2115
  ]
2211
2116
  }),
2212
- rules.filter((r)=>r.conditions.length > 0 || !r.effects.required).length > 0 && /*#__PURE__*/ jsxs("div", {
2213
- className: "space-y-2",
2214
- children: [
2215
- /*#__PURE__*/ jsx(Label, {
2216
- className: "text-xs text-muted-foreground uppercase tracking-wide",
2217
- children: "Conditional rules"
2218
- }),
2219
- rules.map((rule, index)=>({
2220
- rule,
2221
- index
2222
- })).filter(({ rule })=>rule.conditions.length > 0 || !rule.effects.required).map(({ rule, index })=>{
2223
- const effect = getEffectDescription(rule);
2224
- return /*#__PURE__*/ jsx("div", {
2225
- className: "group border rounded-lg p-3 hover:border-primary/50 transition-colors",
2226
- children: /*#__PURE__*/ jsxs("div", {
2227
- className: "flex items-start justify-between gap-2",
2228
- children: [
2229
- /*#__PURE__*/ jsxs("div", {
2230
- className: "flex-1 min-w-0",
2231
- children: [
2232
- /*#__PURE__*/ jsxs("div", {
2233
- className: "flex items-center gap-2 mb-1",
2234
- children: [
2235
- /*#__PURE__*/ jsx("span", {
2236
- className: `text-xs font-medium px-2 py-0.5 rounded ${effect.color}`,
2237
- children: effect.label
2238
- }),
2239
- rule.conditions.length > 1 && /*#__PURE__*/ jsxs("span", {
2240
- className: "text-xs text-muted-foreground",
2241
- children: [
2242
- "(",
2243
- rule.operator,
2244
- ")"
2245
- ]
2246
- })
2247
- ]
2248
- }),
2249
- /*#__PURE__*/ jsx("p", {
2250
- className: "text-sm text-muted-foreground truncate",
2251
- children: describeRule(rule)
2252
- })
2253
- ]
2254
- }),
2255
- /*#__PURE__*/ jsxs("div", {
2256
- className: "flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",
2257
- children: [
2258
- /*#__PURE__*/ jsx(Button, {
2259
- variant: "ghost",
2260
- size: "sm",
2261
- className: "h-7 w-7 p-0",
2262
- onClick: ()=>editRule(index),
2263
- "aria-label": "Edit rule",
2264
- children: /*#__PURE__*/ jsx(Settings, {
2265
- className: "h-3.5 w-3.5"
2266
- })
2267
- }),
2268
- /*#__PURE__*/ jsx(Button, {
2269
- variant: "ghost",
2270
- size: "2xs",
2271
- icon: true,
2272
- className: "text-destructive hover:text-destructive",
2273
- onClick: ()=>deleteRule(index),
2274
- "aria-label": "Delete rule",
2275
- children: /*#__PURE__*/ jsx(Trash2, {
2276
- className: "h-3.5 w-3.5"
2277
- })
2278
- })
2279
- ]
2280
- })
2281
- ]
2282
- })
2283
- }, index);
2284
- })
2285
- ]
2286
- }),
2287
- isAddingRule ? /*#__PURE__*/ jsxs("div", {
2288
- className: "border rounded-lg p-4 space-y-4 bg-muted/20",
2289
- children: [
2290
- /*#__PURE__*/ jsxs("div", {
2291
- className: "flex items-center justify-between",
2292
- children: [
2293
- /*#__PURE__*/ jsx(Label, {
2294
- className: "font-medium",
2295
- children: null !== editingRuleIndex ? 'Edit rule' : 'New rule'
2296
- }),
2297
- /*#__PURE__*/ jsx(Button, {
2298
- variant: "ghost",
2299
- size: "sm",
2300
- onClick: resetBuilder,
2301
- children: "Cancel"
2302
- })
2303
- ]
2304
- }),
2305
- /*#__PURE__*/ jsxs("div", {
2306
- className: "space-y-2",
2307
- children: [
2308
- /*#__PURE__*/ jsx(Label, {
2309
- className: "text-xs text-muted-foreground",
2310
- children: "When conditions are met:"
2311
- }),
2312
- /*#__PURE__*/ jsx("div", {
2313
- className: "grid grid-cols-2 gap-2",
2314
- children: RULE_EFFECTS.map((effect)=>/*#__PURE__*/ jsxs("button", {
2315
- type: "button",
2316
- className: `flex items-center gap-2 p-2 rounded-lg border text-left text-sm transition-all ${selectedEffect === effect.value ? effect.color + ' border-current' : 'hover:bg-muted'}`,
2317
- onClick: ()=>setSelectedEffect(effect.value),
2318
- children: [
2319
- /*#__PURE__*/ jsx(effect.Icon, {
2320
- className: "h-4 w-4"
2321
- }),
2322
- /*#__PURE__*/ jsx("span", {
2323
- className: "font-medium",
2324
- children: effect.label
2325
- })
2326
- ]
2327
- }, effect.value))
2328
- })
2329
- ]
2330
- }),
2331
- /*#__PURE__*/ jsxs("div", {
2332
- className: "space-y-3",
2333
- children: [
2334
- /*#__PURE__*/ jsxs("div", {
2335
- className: "flex items-center justify-between",
2336
- children: [
2337
- /*#__PURE__*/ jsx(Label, {
2338
- className: "text-xs text-muted-foreground",
2339
- children: "Conditions:"
2340
- }),
2341
- conditions.length > 1 && /*#__PURE__*/ jsxs(Select, {
2342
- value: conditionOperator,
2343
- onValueChange: (v)=>setConditionOperator(v),
2344
- children: [
2345
- /*#__PURE__*/ jsx(SelectTrigger, {
2346
- "aria-label": "Condition match mode",
2347
- className: "w-24 h-7 text-xs",
2348
- children: /*#__PURE__*/ jsx(SelectValue, {})
2349
- }),
2350
- /*#__PURE__*/ jsxs(SelectContent, {
2351
- children: [
2352
- /*#__PURE__*/ jsx(SelectItem, {
2353
- value: "AND",
2354
- children: "Match ALL"
2355
- }),
2356
- /*#__PURE__*/ jsx(SelectItem, {
2357
- value: "OR",
2358
- children: "Match ANY"
2359
- })
2360
- ]
2361
- })
2362
- ]
2363
- })
2364
- ]
2365
- }),
2366
- conditions.map((cond, index)=>/*#__PURE__*/ jsxs("div", {
2367
- className: "space-y-2",
2368
- children: [
2369
- index > 0 && /*#__PURE__*/ jsxs("div", {
2370
- className: "flex items-center gap-2 text-xs text-muted-foreground",
2371
- children: [
2372
- /*#__PURE__*/ jsx(Separator, {
2373
- className: "flex-1"
2374
- }),
2375
- /*#__PURE__*/ jsx("span", {
2376
- children: conditionOperator
2377
- }),
2378
- /*#__PURE__*/ jsx(Separator, {
2379
- className: "flex-1"
2380
- })
2381
- ]
2382
- }),
2383
- /*#__PURE__*/ jsxs("div", {
2384
- className: "flex gap-2 items-start",
2385
- children: [
2386
- /*#__PURE__*/ jsxs("div", {
2387
- className: "flex-1 space-y-2",
2388
- children: [
2389
- /*#__PURE__*/ jsxs(Select, {
2390
- value: cond.field,
2391
- onValueChange: (v)=>updateCondition(index, {
2392
- field: v
2393
- }),
2394
- children: [
2395
- /*#__PURE__*/ jsx(SelectTrigger, {
2396
- "aria-label": "Condition field",
2397
- className: "h-8 text-sm",
2398
- children: /*#__PURE__*/ jsx(SelectValue, {
2399
- placeholder: "Select field..."
2400
- })
2401
- }),
2402
- /*#__PURE__*/ jsx(SelectContent, {
2403
- children: allFields.map((field)=>/*#__PURE__*/ jsx(SelectItem, {
2404
- value: field.name,
2405
- children: field.label
2406
- }, field.id))
2407
- })
2408
- ]
2409
- }),
2410
- /*#__PURE__*/ jsxs("div", {
2411
- className: "flex gap-2",
2412
- children: [
2413
- /*#__PURE__*/ jsxs(Select, {
2414
- value: cond.operator,
2415
- onValueChange: (v)=>updateCondition(index, {
2416
- operator: v
2417
- }),
2418
- children: [
2419
- /*#__PURE__*/ jsx(SelectTrigger, {
2420
- "aria-label": "Condition operator",
2421
- className: "w-32 h-8 text-sm",
2422
- children: /*#__PURE__*/ jsx(SelectValue, {})
2423
- }),
2424
- /*#__PURE__*/ jsx(SelectContent, {
2425
- children: CONDITION_OPERATORS.map((op)=>/*#__PURE__*/ jsx(SelectItem, {
2426
- value: op.value,
2427
- children: op.label
2428
- }, op.value))
2429
- })
2430
- ]
2431
- }),
2432
- /*#__PURE__*/ jsx("div", {
2433
- className: "flex-1",
2434
- children: cond.field && getFieldOptions(cond.field).length > 0 && ('is' === cond.operator || 'isNot' === cond.operator) ? /*#__PURE__*/ jsxs(Select, {
2435
- value: cond.value,
2436
- onValueChange: (v)=>updateCondition(index, {
2437
- value: v
2438
- }),
2439
- children: [
2440
- /*#__PURE__*/ jsx(SelectTrigger, {
2441
- "aria-label": "Condition value",
2442
- className: "h-8 text-sm",
2443
- children: /*#__PURE__*/ jsx(SelectValue, {
2444
- placeholder: "Select value..."
2445
- })
2446
- }),
2447
- /*#__PURE__*/ jsx(SelectContent, {
2448
- children: getFieldOptions(cond.field).map((opt)=>/*#__PURE__*/ jsx(SelectItem, {
2449
- value: String(opt.value),
2450
- children: opt.label
2451
- }, String(opt.value)))
2452
- })
2453
- ]
2454
- }) : /*#__PURE__*/ jsx(Input, {
2455
- className: "h-8 text-sm",
2456
- placeholder: 'in' === cond.operator || 'notIn' === cond.operator ? 'value1, value2, ...' : 'matches' === cond.operator ? 'regex pattern' : 'value',
2457
- value: cond.value,
2458
- onChange: (e)=>updateCondition(index, {
2459
- value: e.target.value
2460
- })
2461
- })
2462
- })
2463
- ]
2464
- })
2465
- ]
2466
- }),
2467
- conditions.length > 1 && /*#__PURE__*/ jsx(Button, {
2468
- variant: "ghost",
2469
- size: "sm",
2470
- className: "h-8 w-8 p-0 text-muted-foreground",
2471
- onClick: ()=>removeCondition(index),
2472
- children: /*#__PURE__*/ jsx(Trash2, {
2473
- className: "h-3.5 w-3.5"
2474
- })
2475
- })
2476
- ]
2477
- })
2478
- ]
2479
- }, index)),
2480
- /*#__PURE__*/ jsxs(Button, {
2481
- variant: "outline",
2482
- size: "sm",
2483
- className: "w-full",
2484
- onClick: addCondition,
2485
- children: [
2486
- /*#__PURE__*/ jsx(Plus, {
2487
- className: "h-3 w-3 mr-2"
2488
- }),
2489
- "Add condition"
2490
- ]
2491
- })
2492
- ]
2493
- }),
2494
- /*#__PURE__*/ jsx(Button, {
2495
- className: "w-full",
2496
- onClick: saveRule,
2497
- disabled: !conditions.some((c)=>c.field),
2498
- children: null !== editingRuleIndex ? 'Update rule' : 'Add rule'
2499
- })
2500
- ]
2501
- }) : /*#__PURE__*/ jsxs(Button, {
2502
- variant: "outline",
2503
- className: "w-full",
2504
- onClick: ()=>setIsAddingRule(true),
2505
- children: [
2506
- /*#__PURE__*/ jsx(Plus, {
2507
- className: "h-4 w-4 mr-2"
2508
- }),
2509
- "Add conditional rule"
2510
- ]
2511
- })
2117
+ /*#__PURE__*/ jsx(RulesEditor, {
2118
+ label: "Field rules",
2119
+ value: rules,
2120
+ onChange: changeRules,
2121
+ outcomes: DESIGNER_OUTCOMES,
2122
+ fields: options.fields,
2123
+ operators: rulesEngineVocabulary.operators,
2124
+ valueModes: rulesEngineVocabulary.valueModes,
2125
+ dialect: rulesEngineDialect,
2126
+ defaultTouched: touched
2127
+ }, editorKey)
2512
2128
  ]
2513
2129
  });
2514
2130
  }