@veltra/desktop 1.1.3 → 1.1.5

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 (163) hide show
  1. package/dist/components/action/action-group.js +3 -110
  2. package/dist/components/action/action-group.js.map +1 -1
  3. package/dist/components/action/action-group.vue.d.ts +5 -14
  4. package/dist/components/action/action-group.vue_vue_type_script_setup_true_lang.js +105 -0
  5. package/dist/components/action/action-group.vue_vue_type_script_setup_true_lang.js.map +1 -0
  6. package/dist/components/action/action.js +5 -1
  7. package/dist/components/action/action.js.map +1 -1
  8. package/dist/components/action/di.js.map +1 -1
  9. package/dist/components/action/style2.css +17 -14
  10. package/dist/components/auto-complete/auto-complete.js +1 -1
  11. package/dist/components/auto-complete/auto-complete.vue.d.ts +2 -2
  12. package/dist/components/badge/badge.js +1 -1
  13. package/dist/components/batch-edit/batch-edit-form.js +94 -101
  14. package/dist/components/batch-edit/batch-edit-form.js.map +1 -1
  15. package/dist/components/batch-edit/batch-edit-list.js +52 -68
  16. package/dist/components/batch-edit/batch-edit-list.js.map +1 -1
  17. package/dist/components/batch-edit/style2.css +13 -89
  18. package/dist/components/breadcrumb/breadcrumb.js +1 -1
  19. package/dist/components/button/button.js +1 -1
  20. package/dist/components/card/card.js +1 -1
  21. package/dist/components/cascade/cascade-panel-item.js +4 -4
  22. package/dist/components/cascade/cascade.js +2 -2
  23. package/dist/components/cascade/cascade.vue.d.ts +5 -5
  24. package/dist/components/checkbox/checkbox-button.js +1 -1
  25. package/dist/components/checkbox/checkbox.js +1 -1
  26. package/dist/components/checkbox-group/checkbox-group.js +1 -1
  27. package/dist/components/code-editor/code-editor.js +1 -1
  28. package/dist/components/collapse/collapse.js +1 -1
  29. package/dist/components/condition-editor/components/condition-group.js +152 -0
  30. package/dist/components/condition-editor/components/condition-group.js.map +1 -0
  31. package/dist/components/condition-editor/components/condition-row.js +217 -0
  32. package/dist/components/condition-editor/components/condition-row.js.map +1 -0
  33. package/dist/components/condition-editor/condition-editor.js +134 -5
  34. package/dist/components/condition-editor/condition-editor.js.map +1 -1
  35. package/dist/components/condition-editor/condition-editor.vue.d.ts +10 -2
  36. package/dist/components/condition-editor/core/evaluator.js +75 -0
  37. package/dist/components/condition-editor/core/evaluator.js.map +1 -0
  38. package/dist/components/condition-editor/core/operators.js +123 -0
  39. package/dist/components/condition-editor/core/operators.js.map +1 -0
  40. package/dist/components/condition-editor/style.js +7 -0
  41. package/dist/components/condition-editor/style2.css +186 -0
  42. package/dist/components/context-menu/context-menu.js +1 -1
  43. package/dist/components/date-picker/date-picker.js +2 -2
  44. package/dist/components/date-picker/date-picker.vue.d.ts +2 -2
  45. package/dist/components/date-range-picker/date-range-picker.js +2 -2
  46. package/dist/components/date-range-picker/date-range-picker.vue.d.ts +2 -2
  47. package/dist/components/dialog/dialog.js +7 -7
  48. package/dist/components/dialog/style2.css +8 -0
  49. package/dist/components/dialog/use-maximum.js +1 -1
  50. package/dist/components/drawer/style2.css +8 -0
  51. package/dist/components/dropdown/dropdown.js +1 -1
  52. package/dist/components/expression-editor/components/variable-picker.js +8 -8
  53. package/dist/components/expression-editor/expression-editor.js +1 -1
  54. package/dist/components/expression-editor/style2.css +1 -0
  55. package/dist/components/file-viewer/file-viewer.js +13 -13
  56. package/dist/components/form-item/form-item.js.map +1 -1
  57. package/dist/components/form-item/form-item.vue_vue_type_script_setup_true_lang.js +6 -6
  58. package/dist/components/form-item/form-item.vue_vue_type_script_setup_true_lang.js.map +1 -1
  59. package/dist/components/grid-input/grid-input.js +1 -1
  60. package/dist/components/group-input/group-input.js +2 -1
  61. package/dist/components/group-input/group-input.js.map +1 -1
  62. package/dist/components/group-input/style.js +1 -0
  63. package/dist/components/index.js +154 -154
  64. package/dist/components/input/input.vue.d.ts +4 -4
  65. package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js +1 -1
  66. package/dist/components/layout/layout-resizer.js +1 -1
  67. package/dist/components/layout/layout.js +1 -1
  68. package/dist/components/list/list.js +1 -1
  69. package/dist/components/loading/loading.js +1 -1
  70. package/dist/components/menu/menu-sub-collapsed.js +4 -4
  71. package/dist/components/menu/menu.js +1 -1
  72. package/dist/components/message/message.js +1 -1
  73. package/dist/components/message-confirm/message-confirm.js +1 -1
  74. package/dist/components/multi-select/multi-select-option.js +19 -14
  75. package/dist/components/multi-select/multi-select-option.js.map +1 -1
  76. package/dist/components/multi-select/multi-select.js +15 -15
  77. package/dist/components/multi-select/multi-select.vue.d.ts +4 -4
  78. package/dist/components/multi-tree-select/multi-tree-select.js +8 -8
  79. package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +6 -6
  80. package/dist/components/notification/notification.js +1 -1
  81. package/dist/components/notification/notification.vue.d.ts +1 -1
  82. package/dist/components/number/number.vue.d.ts +1 -1
  83. package/dist/components/number-input/number-input.js +2 -2
  84. package/dist/components/number-input/number-input.vue.d.ts +4 -4
  85. package/dist/components/number-range-input/number-range-input.js +1 -1
  86. package/dist/components/number-range-input/number-range-input.vue.d.ts +1 -1
  87. package/dist/components/number-range-input/style2.css +1 -0
  88. package/dist/components/paginator/paginator.js +6 -6
  89. package/dist/components/paginator/style.js +1 -1
  90. package/dist/components/palette/palette.js +1 -1
  91. package/dist/components/password-input/password-input.js +2 -2
  92. package/dist/components/password-input/password-input.vue.d.ts +1 -1
  93. package/dist/components/pop-confirm/pop-confirm.js +1 -1
  94. package/dist/components/pop-confirm/pop-confirm.vue.d.ts +1 -1
  95. package/dist/components/progress-nodes/progress-nodes.js +1 -1
  96. package/dist/components/radio/radio.js +1 -1
  97. package/dist/components/radio-group/radio-group.js +1 -1
  98. package/dist/components/rich-text-editor/rich-text-editor.js +1 -1
  99. package/dist/components/rich-text-editor/rich-text-editor.vue.d.ts +1 -1
  100. package/dist/components/scroll/scroll-bar.js +1 -1
  101. package/dist/components/scroll/scroll.js +1 -1
  102. package/dist/components/select/select.js +10 -10
  103. package/dist/components/select/select.vue.d.ts +2 -2
  104. package/dist/components/slider/slider.js +1 -1
  105. package/dist/components/steps/steps.js +2 -2
  106. package/dist/components/switch/switch.js +1 -1
  107. package/dist/components/table/style2.css +4 -1
  108. package/dist/components/table/table.js +2 -2
  109. package/dist/components/table/table.js.map +1 -1
  110. package/dist/components/table/use-columns.js +1 -1
  111. package/dist/components/table/use-fixed-columns.js +8 -31
  112. package/dist/components/table/use-fixed-columns.js.map +1 -1
  113. package/dist/components/table-editor/table-editor.js +1 -1
  114. package/dist/components/tabs/tabs-horizontal.js +1 -1
  115. package/dist/components/tabs/tabs-horizontal.vue.d.ts +4 -4
  116. package/dist/components/tabs/tabs-vertical.js +1 -1
  117. package/dist/components/tabs/tabs-vertical.vue.d.ts +3 -3
  118. package/dist/components/tabs/tabs.js +1 -1
  119. package/dist/components/tabs/tabs.vue.d.ts +4 -4
  120. package/dist/components/tag/tag.js +1 -1
  121. package/dist/components/textarea/textarea.js +1 -1
  122. package/dist/components/textarea/textarea.vue.d.ts +4 -4
  123. package/dist/components/theme/style.js +1 -1
  124. package/dist/components/theme/theme.js +11 -11
  125. package/dist/components/tip/tip.js +1 -1
  126. package/dist/components/tree/tree-node.js +1 -1
  127. package/dist/components/tree/tree.js +5 -5
  128. package/dist/components/tree-select/tree-select.js +6 -6
  129. package/dist/components/tree-select/tree-select.vue.d.ts +5 -5
  130. package/dist/index.d.ts +5 -5
  131. package/dist/index.js +83 -83
  132. package/dist/style.js +2 -2
  133. package/dist/types/action.d.ts +5 -11
  134. package/dist/types/condition-editor.d.ts +41 -8
  135. package/dist/types/index.d.ts +4 -4
  136. package/package.json +11 -11
  137. package/src/components/action/action-group.vue +68 -82
  138. package/src/components/action/action.vue +9 -1
  139. package/src/components/action/di.ts +2 -1
  140. package/src/components/action/style.scss +22 -27
  141. package/src/components/batch-edit/batch-edit-form.vue +65 -70
  142. package/src/components/batch-edit/batch-edit-list.vue +35 -41
  143. package/src/components/batch-edit/style.scss +19 -118
  144. package/src/components/condition-editor/components/condition-group.vue +131 -0
  145. package/src/components/condition-editor/components/condition-row.vue +208 -0
  146. package/src/components/condition-editor/condition-editor.vue +145 -6
  147. package/src/components/condition-editor/core/evaluator.ts +93 -0
  148. package/src/components/condition-editor/core/operators.ts +57 -0
  149. package/src/components/condition-editor/style.scss +239 -1
  150. package/src/components/condition-editor/style.ts +7 -0
  151. package/src/components/dialog/style.scss +13 -0
  152. package/src/components/drawer/style.scss +13 -0
  153. package/src/components/expression-editor/style.scss +1 -0
  154. package/src/components/form-item/form-item.vue +1 -1
  155. package/src/components/group-input/group-input.vue +8 -1
  156. package/src/components/group-input/style.ts +1 -0
  157. package/src/components/multi-select/multi-select-option.vue +19 -13
  158. package/src/components/number-range-input/style.scss +1 -0
  159. package/src/components/table/style.scss +9 -1
  160. package/src/components/table/table.vue +1 -3
  161. package/src/components/table/use-fixed-columns.ts +5 -49
  162. package/src/types/action.ts +6 -11
  163. package/src/types/condition-editor.ts +39 -7
@@ -0,0 +1,217 @@
1
+ import _sfc_main$1 from "../../select/select.js";
2
+ import { getOperatorsByFieldType } from "../core/operators.js";
3
+ import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, normalizeClass, openBlock, ref, toDisplayString, unref, useTemplateRef, withKeys, withModifiers } from "vue";
4
+ import { useFormFallbackProps } from "@veltra/compositions";
5
+ import { bem, injectFormContext } from "@veltra/utils";
6
+ //#region src/components/condition-editor/components/condition-row.vue
7
+ const _hoisted_1 = [
8
+ "value",
9
+ "placeholder",
10
+ "disabled",
11
+ "readonly"
12
+ ];
13
+ const _sfc_main = /* @__PURE__ */ defineComponent({
14
+ name: "ConditionRow",
15
+ __name: "condition-row",
16
+ props: {
17
+ item: {},
18
+ fields: {},
19
+ size: {},
20
+ disabled: { type: Boolean },
21
+ readonly: { type: Boolean }
22
+ },
23
+ emits: [
24
+ "update:item",
25
+ "delete",
26
+ "mention"
27
+ ],
28
+ setup(__props, { emit: __emit }) {
29
+ const props = __props;
30
+ const { formProps } = injectFormContext();
31
+ const { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {
32
+ size: "default",
33
+ disabled: false,
34
+ readonly: false
35
+ });
36
+ const emit = __emit;
37
+ const cls = bem("condition-editor");
38
+ const valueInputRef = useTemplateRef("valueInputRef");
39
+ const focused = ref(false);
40
+ const fieldOptions = computed(() => (props.fields ?? []).map((f) => ({
41
+ label: f.label,
42
+ value: f.value
43
+ })));
44
+ const currentField = computed(() => props.fields?.find((f) => f.value === props.item.field));
45
+ const operatorOptions = computed(() => {
46
+ if (!currentField.value) return props.item.operator ? [{
47
+ label: props.item.operator,
48
+ value: props.item.operator
49
+ }] : [];
50
+ return getOperatorsByFieldType(currentField.value.type);
51
+ });
52
+ const needValue = computed(() => {
53
+ return operatorOptions.value.find((o) => o.value === props.item.operator)?.needValue ?? true;
54
+ });
55
+ const hasResult = computed(() => props.item._result !== void 0);
56
+ const placeholder = computed(() => props.fields?.length ? "输入值或 @ 引用变量" : "");
57
+ const variableLabel = computed(() => {
58
+ if (props.item.value.kind !== "variable") return "";
59
+ return props.item.value.name;
60
+ });
61
+ function onFieldChange(val) {
62
+ const field = props.fields?.find((f) => f.value === val);
63
+ emit("update:item", {
64
+ ...props.item,
65
+ field: val,
66
+ operator: field ? getOperatorsByFieldType(field.type)[0].value : "eq",
67
+ value: {
68
+ kind: "constant",
69
+ value: ""
70
+ }
71
+ });
72
+ }
73
+ function onOperatorChange(val) {
74
+ emit("update:item", {
75
+ ...props.item,
76
+ operator: val,
77
+ value: {
78
+ kind: "constant",
79
+ value: ""
80
+ }
81
+ });
82
+ }
83
+ function onValueInput(e) {
84
+ const val = e.target.value;
85
+ emit("update:item", {
86
+ ...props.item,
87
+ value: {
88
+ kind: "constant",
89
+ value: val
90
+ }
91
+ });
92
+ }
93
+ function onValueKeydown(e) {
94
+ if (disabled.value || readonly.value) return;
95
+ if (e.key === "@" && valueInputRef.value) {
96
+ e.preventDefault();
97
+ emit("mention", {
98
+ triggerDom: valueInputRef.value,
99
+ setValue: (val) => {
100
+ emit("update:item", {
101
+ ...props.item,
102
+ value: val
103
+ });
104
+ }
105
+ });
106
+ }
107
+ }
108
+ function onChipClick() {
109
+ if (disabled.value || readonly.value) return;
110
+ if (valueInputRef.value) emit("mention", {
111
+ triggerDom: valueInputRef.value,
112
+ setValue: (val) => {
113
+ emit("update:item", {
114
+ ...props.item,
115
+ value: val
116
+ });
117
+ }
118
+ });
119
+ }
120
+ function onChipDelete() {
121
+ emit("update:item", {
122
+ ...props.item,
123
+ value: {
124
+ kind: "constant",
125
+ value: ""
126
+ }
127
+ });
128
+ }
129
+ return (_ctx, _cache) => {
130
+ return openBlock(), createElementBlock("div", { class: normalizeClass([unref(cls).e("row"), unref(bem).is("focused", focused.value)]) }, [
131
+ createCommentVNode(" 字段选择 "),
132
+ createVNode(unref(_sfc_main$1), {
133
+ class: normalizeClass(unref(cls).e("field")),
134
+ "model-value": __props.item.field,
135
+ options: fieldOptions.value,
136
+ "value-key": "value",
137
+ "label-key": "label",
138
+ placeholder: "字段",
139
+ size: unref(size),
140
+ disabled: unref(disabled) || unref(readonly),
141
+ clearable: false,
142
+ "onUpdate:modelValue": onFieldChange
143
+ }, null, 8, [
144
+ "class",
145
+ "model-value",
146
+ "options",
147
+ "size",
148
+ "disabled"
149
+ ]),
150
+ createCommentVNode(" 运算符选择 "),
151
+ createVNode(unref(_sfc_main$1), {
152
+ class: normalizeClass(unref(cls).e("operator")),
153
+ "model-value": __props.item.operator,
154
+ options: operatorOptions.value,
155
+ "value-key": "value",
156
+ "label-key": "label",
157
+ placeholder: "运算符",
158
+ size: unref(size),
159
+ disabled: unref(disabled) || unref(readonly),
160
+ clearable: false,
161
+ "onUpdate:modelValue": onOperatorChange
162
+ }, null, 8, [
163
+ "class",
164
+ "model-value",
165
+ "options",
166
+ "size",
167
+ "disabled"
168
+ ]),
169
+ createCommentVNode(" 值输入 "),
170
+ createElementVNode("div", { class: normalizeClass(unref(cls).e("value")) }, [needValue.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [__props.item.value.kind === "constant" ? (openBlock(), createElementBlock("input", {
171
+ key: 0,
172
+ ref_key: "valueInputRef",
173
+ ref: valueInputRef,
174
+ class: normalizeClass(unref(cls).e("value-input")),
175
+ value: __props.item.value.value,
176
+ placeholder: placeholder.value,
177
+ disabled: unref(disabled),
178
+ readonly: unref(readonly),
179
+ onInput: onValueInput,
180
+ onKeydown: onValueKeydown,
181
+ onFocus: _cache[0] || (_cache[0] = ($event) => focused.value = true),
182
+ onBlur: _cache[1] || (_cache[1] = ($event) => focused.value = false)
183
+ }, null, 42, _hoisted_1)) : (openBlock(), createElementBlock("span", {
184
+ key: 1,
185
+ class: normalizeClass(unref(cls).e("value-chip")),
186
+ tabindex: "0",
187
+ onClick: onChipClick,
188
+ onKeydown: withKeys(onChipDelete, ["delete"])
189
+ }, [createElementVNode("span", { class: normalizeClass(unref(cls).e("value-chip-label")) }, toDisplayString(variableLabel.value), 3), createElementVNode("span", {
190
+ class: normalizeClass(unref(cls).e("value-chip-close")),
191
+ onClick: withModifiers(onChipDelete, ["stop"])
192
+ }, "×", 2)], 34))], 64)) : (openBlock(), createElementBlock("span", {
193
+ key: 1,
194
+ class: normalizeClass(unref(cls).e("value-empty"))
195
+ }, "—", 2))], 2),
196
+ createCommentVNode(" 删除 "),
197
+ !unref(readonly) ? (openBlock(), createElementBlock("span", {
198
+ key: 0,
199
+ class: normalizeClass(unref(cls).e("row-delete")),
200
+ onClick: _cache[2] || (_cache[2] = ($event) => emit("delete"))
201
+ }, "×", 2)) : createCommentVNode("v-if", true),
202
+ createCommentVNode(" 结果指示 "),
203
+ hasResult.value ? (openBlock(), createElementBlock("span", {
204
+ key: 1,
205
+ class: normalizeClass([unref(cls).e("result"), unref(cls).em("result", __props.item._result ? "pass" : "fail")])
206
+ }, toDisplayString(__props.item._result ? "✓" : "✗"), 3)) : (openBlock(), createElementBlock("span", {
207
+ key: 2,
208
+ class: normalizeClass([unref(cls).e("result"), unref(cls).em("result", "none")])
209
+ }, "—", 2))
210
+ ], 2);
211
+ };
212
+ }
213
+ });
214
+ //#endregion
215
+ export { _sfc_main as default };
216
+
217
+ //# sourceMappingURL=condition-row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"condition-row.js","names":[],"sources":["../../../../src/components/condition-editor/components/condition-row.vue"],"sourcesContent":["<template>\n <div :class=\"[cls.e('row'), bem.is('focused', focused)]\">\n <!-- 字段选择 -->\n <u-select\n :class=\"cls.e('field')\"\n :model-value=\"item.field\"\n :options=\"fieldOptions\"\n value-key=\"value\"\n label-key=\"label\"\n placeholder=\"字段\"\n :size=\"size\"\n :disabled=\"disabled || readonly\"\n :clearable=\"false\"\n @update:model-value=\"onFieldChange\"\n />\n\n <!-- 运算符选择 -->\n <u-select\n :class=\"cls.e('operator')\"\n :model-value=\"item.operator\"\n :options=\"operatorOptions\"\n value-key=\"value\"\n label-key=\"label\"\n placeholder=\"运算符\"\n :size=\"size\"\n :disabled=\"disabled || readonly\"\n :clearable=\"false\"\n @update:model-value=\"onOperatorChange\"\n />\n\n <!-- 值输入 -->\n <div :class=\"cls.e('value')\">\n <template v-if=\"needValue\">\n <input\n v-if=\"item.value.kind === 'constant'\"\n ref=\"valueInputRef\"\n :class=\"cls.e('value-input')\"\n :value=\"item.value.value\"\n :placeholder=\"placeholder\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n @input=\"onValueInput\"\n @keydown=\"onValueKeydown\"\n @focus=\"focused = true\"\n @blur=\"focused = false\"\n />\n <span\n v-else\n :class=\"cls.e('value-chip')\"\n tabindex=\"0\"\n @click=\"onChipClick\"\n @keydown.delete=\"onChipDelete\"\n >\n <span :class=\"cls.e('value-chip-label')\">{{ variableLabel }}</span>\n <span :class=\"cls.e('value-chip-close')\" @click.stop=\"onChipDelete\">×</span>\n </span>\n </template>\n <span v-else :class=\"cls.e('value-empty')\">—</span>\n </div>\n\n <!-- 删除 -->\n <span v-if=\"!readonly\" :class=\"cls.e('row-delete')\" @click=\"emit('delete')\">×</span>\n\n <!-- 结果指示 -->\n <span\n v-if=\"hasResult\"\n :class=\"[cls.e('result'), cls.em('result', item._result ? 'pass' : 'fail')]\"\n >\n {{ item._result ? '✓' : '✗' }}\n </span>\n <span v-else :class=\"[cls.e('result'), cls.em('result', 'none')]\">—</span>\n </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, injectFormContext } from '@veltra/utils'\nimport { computed, ref, useTemplateRef } from 'vue'\n\nimport type { ConditionField, ConditionItem, ConditionValue } from '../../../types'\nimport { USelect } from '../../select'\nimport { getOperatorsByFieldType, type OperatorDef } from '../core/operators'\n\ndefineOptions({ name: 'ConditionRow' })\n\nexport interface MentionPayload {\n triggerDom: HTMLElement\n setValue: (val: ConditionValue) => void\n}\n\nconst props = withDefaults(\n defineProps<{\n item: ConditionItem\n fields?: ConditionField[]\n size?: string\n disabled?: boolean\n readonly?: boolean\n }>(),\n {}\n)\n\nconst { formProps } = injectFormContext()\n\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {\n size: 'default',\n disabled: false,\n readonly: false\n})\n\nconst emit = defineEmits<{\n (e: 'update:item', item: ConditionItem): void\n (e: 'delete'): void\n (e: 'mention', payload: MentionPayload): void\n}>()\n\nconst cls = bem('condition-editor')\n\nconst valueInputRef = useTemplateRef<HTMLInputElement>('valueInputRef')\nconst focused = ref(false)\n\nconst fieldOptions = computed(() =>\n (props.fields ?? []).map((f) => ({ label: f.label, value: f.value }))\n)\n\nconst currentField = computed(() => props.fields?.find((f) => f.value === props.item.field))\n\nconst operatorOptions = computed(() => {\n if (!currentField.value) {\n return props.item.operator ? [{ label: props.item.operator, value: props.item.operator }] : []\n }\n return getOperatorsByFieldType(currentField.value.type)\n})\n\nconst needValue = computed(() => {\n const ops = operatorOptions.value as OperatorDef[]\n const op = ops.find((o) => o.value === props.item.operator)\n return op?.needValue ?? true\n})\n\nconst hasResult = computed(() => props.item._result !== undefined)\n\nconst placeholder = computed(() => (props.fields?.length ? '输入值或 @ 引用变量' : ''))\n\nconst variableLabel = computed(() => {\n if (props.item.value.kind !== 'variable') return ''\n return props.item.value.name\n})\n\nfunction onFieldChange(val: string) {\n const field = props.fields?.find((f) => f.value === val)\n const newItem: ConditionItem = {\n ...props.item,\n field: val,\n operator: field ? getOperatorsByFieldType(field.type)[0]!.value : 'eq',\n value: { kind: 'constant', value: '' }\n }\n emit('update:item', newItem)\n}\n\nfunction onOperatorChange(val: string) {\n const newItem: ConditionItem = {\n ...props.item,\n operator: val,\n value: { kind: 'constant', value: '' }\n }\n emit('update:item', newItem)\n}\n\nfunction onValueInput(e: Event) {\n const val = (e.target as HTMLInputElement).value\n emit('update:item', {\n ...props.item,\n value: { kind: 'constant', value: val }\n })\n}\n\nfunction onValueKeydown(e: KeyboardEvent) {\n if (disabled.value || readonly.value) return\n if (e.key === '@' && valueInputRef.value) {\n e.preventDefault()\n emit('mention', {\n triggerDom: valueInputRef.value,\n setValue: (val: ConditionValue) => {\n emit('update:item', { ...props.item, value: val })\n }\n })\n }\n}\n\nfunction onChipClick() {\n if (disabled.value || readonly.value) return\n if (valueInputRef.value) {\n emit('mention', {\n triggerDom: valueInputRef.value,\n setValue: (val: ConditionValue) => {\n emit('update:item', { ...props.item, value: val })\n }\n })\n }\n}\n\nfunction onChipDelete() {\n emit('update:item', {\n ...props.item,\n value: { kind: 'constant', value: '' }\n })\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0FA,MAAM,QAAQ;EAWd,MAAM,EAAE,cAAc,mBAAkB;EAExC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE;GAClF,MAAM;GACN,UAAU;GACV,UAAU;GACX,CAAA;EAED,MAAM,OAAO;EAMb,MAAM,MAAM,IAAI,mBAAkB;EAElC,MAAM,gBAAgB,eAAiC,gBAAe;EACtE,MAAM,UAAU,IAAI,MAAK;EAEzB,MAAM,eAAe,gBAClB,MAAM,UAAU,EAAE,EAAE,K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,IAAG,CAAC,EAAC,aAAA,CAAA;KAAiB,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,KAAI,SAAA;OAAY,KAAC,EAAA,IAAA,mBAAA,QAAA,KAAA;IAE7E,mBAAA,SAAa;IAEL,UAAA,SAAA,WAAA,EADR,mBAKO,QAAA;;KAHJ,OAAK,eAAA,CAAG,MAAA,IAAG,CAAC,EAAC,SAAA,EAAY,MAAA,IAAG,CAAC,GAAE,UAAW,QAAA,KAAK,UAAO,SAAA,OAAA,CAAA,CAAA;uBAEpD,QAAA,KAAK,UAAO,MAAA,IAAA,EAAA,EAAA,KAAA,WAAA,EAEjB,mBAA0E,QAAA;;KAA5D,OAAK,eAAA,CAAG,MAAA,IAAG,CAAC,EAAC,SAAA,EAAY,MAAA,IAAG,CAAC,GAAE,UAAA,OAAA,CAAA,CAAA;OAAqB,KAAC,EAAA"}
@@ -1,14 +1,143 @@
1
- import { createElementBlock, defineComponent, normalizeClass, openBlock, unref } from "vue";
2
- import { bem } from "@veltra/utils";
1
+ import _sfc_main$1 from "../expression-editor/components/variable-picker.js";
2
+ import { createEmptyGroup, evaluate } from "./core/evaluator.js";
3
+ import _sfc_main$2 from "./components/condition-group.js";
4
+ import { computed, createElementBlock, createVNode, defineComponent, nextTick, normalizeClass, openBlock, shallowRef, unref, useTemplateRef, watch } from "vue";
5
+ import { useFormFallbackProps } from "@veltra/compositions";
6
+ import { bem, injectFormContext } from "@veltra/utils";
3
7
  //#region src/components/condition-editor/condition-editor.vue
4
8
  const _sfc_main = /* @__PURE__ */ defineComponent({
5
9
  name: "ConditionEditor",
6
10
  __name: "condition-editor",
7
- props: { modelValue: {} },
8
- setup(__props) {
11
+ props: {
12
+ modelValue: {},
13
+ fields: { default: () => [] },
14
+ variables: {},
15
+ data: {},
16
+ size: {},
17
+ disabled: { type: Boolean },
18
+ readonly: { type: Boolean }
19
+ },
20
+ emits: ["update:modelValue", "evaluate"],
21
+ setup(__props, { emit: __emit }) {
22
+ const props = __props;
23
+ const emit = __emit;
9
24
  const cls = bem("condition-editor");
25
+ const { formProps } = injectFormContext();
26
+ const { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props]);
27
+ const className = computed(() => [
28
+ cls.b,
29
+ cls.m(size.value),
30
+ bem.is("disabled", disabled.value),
31
+ bem.is("readonly", readonly.value)
32
+ ]);
33
+ const rootGroup = shallowRef(props.modelValue ? JSON.parse(JSON.stringify(props.modelValue)) : createEmptyGroup());
34
+ function serialize() {
35
+ function clean(group) {
36
+ return {
37
+ logic: group.logic,
38
+ conditions: group.conditions.map((c) => {
39
+ const { _result, ...rest } = c;
40
+ return rest;
41
+ }),
42
+ groups: group.groups.map(clean).filter((g) => g.conditions.length > 0 || g.groups.length > 0)
43
+ };
44
+ }
45
+ return clean(JSON.parse(JSON.stringify(rootGroup.value)));
46
+ }
47
+ function emitUpdate() {
48
+ emit("update:modelValue", serialize());
49
+ }
50
+ function runEvaluate() {
51
+ if (!props.data) return;
52
+ rootGroup.value = evaluate(JSON.parse(JSON.stringify(rootGroup.value)), props.data);
53
+ emit("evaluate", serialize());
54
+ }
55
+ const pickerRef = useTemplateRef("pickerRef");
56
+ const pickerVisible = shallowRef(false);
57
+ const pickerTriggerDom = shallowRef(void 0);
58
+ const pickerFilter = shallowRef("");
59
+ const mentionTarget = shallowRef(null);
60
+ function onMention(payload) {
61
+ if (disabled.value || readonly.value) return;
62
+ mentionTarget.value = payload;
63
+ pickerTriggerDom.value = payload.triggerDom;
64
+ pickerFilter.value = "";
65
+ pickerVisible.value = true;
66
+ }
67
+ function onPickerSelect(item) {
68
+ mentionTarget.value?.setValue({
69
+ kind: "variable",
70
+ name: item.value
71
+ });
72
+ pickerVisible.value = false;
73
+ mentionTarget.value = null;
74
+ }
75
+ function onPickerDismiss() {
76
+ pickerVisible.value = false;
77
+ mentionTarget.value = null;
78
+ }
79
+ function onPickerVisibleChange(v) {
80
+ if (!v) {
81
+ pickerVisible.value = false;
82
+ mentionTarget.value = null;
83
+ }
84
+ }
85
+ function onGroupUpdate(group) {
86
+ rootGroup.value = group;
87
+ emitUpdate();
88
+ nextTick(() => runEvaluate());
89
+ }
90
+ watch(() => props.modelValue, (v) => {
91
+ if (!v) return;
92
+ const current = serialize();
93
+ if (JSON.stringify(v) === JSON.stringify(current)) return;
94
+ rootGroup.value = JSON.parse(JSON.stringify(v));
95
+ });
96
+ watch(() => props.data, () => runEvaluate(), { deep: true });
97
+ function onKeydown(e) {
98
+ if (disabled.value || readonly.value) return;
99
+ if (pickerVisible.value) {
100
+ if (pickerRef.value?.handleKeydown(e)) {
101
+ e.preventDefault();
102
+ return;
103
+ }
104
+ }
105
+ }
10
106
  return (_ctx, _cache) => {
11
- return openBlock(), createElementBlock("div", { class: normalizeClass(unref(cls).b) }, null, 2);
107
+ return openBlock(), createElementBlock("div", {
108
+ class: normalizeClass(className.value),
109
+ onKeydown
110
+ }, [createVNode(_sfc_main$2, {
111
+ group: rootGroup.value,
112
+ fields: props.fields,
113
+ size: unref(size),
114
+ disabled: unref(disabled),
115
+ readonly: unref(readonly),
116
+ "onUpdate:group": onGroupUpdate,
117
+ onMention
118
+ }, null, 8, [
119
+ "group",
120
+ "fields",
121
+ "size",
122
+ "disabled",
123
+ "readonly"
124
+ ]), createVNode(_sfc_main$1, {
125
+ ref_key: "pickerRef",
126
+ ref: pickerRef,
127
+ visible: pickerVisible.value,
128
+ "trigger-dom": pickerTriggerDom.value,
129
+ variables: props.variables,
130
+ filter: pickerFilter.value,
131
+ "selectable-levels": "leaf",
132
+ onSelect: onPickerSelect,
133
+ onDismiss: onPickerDismiss,
134
+ "onUpdate:visible": onPickerVisibleChange
135
+ }, null, 8, [
136
+ "visible",
137
+ "trigger-dom",
138
+ "variables",
139
+ "filter"
140
+ ])], 34);
12
141
  };
13
142
  }
14
143
  });
@@ -1 +1 @@
1
- {"version":3,"file":"condition-editor.js","names":[],"sources":["../../../src/components/condition-editor/condition-editor.vue"],"sourcesContent":["<template>\n <div :class=\"cls.b\"></div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { bem } from '@veltra/utils'\n\nimport type { ConditionEditorProps } from '../../types'\n\ndefineOptions({\n name: 'ConditionEditor'\n})\n\ndefineProps<ConditionEditorProps>()\n\nconst cls = bem('condition-editor')\n</script>\n"],"mappings":";;;;;;;;EAeA,MAAM,MAAM,IAAI,mBAAkB;;uBAdhC,mBAA0B,OAAA,EAApB,OAAK,eAAE,MAAA,IAAG,CAAC,EAAC,EAAA,EAAA,MAAA,EAAA"}
1
+ {"version":3,"file":"condition-editor.js","names":[],"sources":["../../../src/components/condition-editor/condition-editor.vue"],"sourcesContent":["<template>\n <div :class=\"className\" @keydown=\"onKeydown\">\n <ConditionGroup\n :group=\"rootGroup\"\n :fields=\"props.fields\"\n :size=\"size\"\n :disabled=\"disabled\"\n :readonly=\"readonly\"\n @update:group=\"onGroupUpdate\"\n @mention=\"onMention\"\n />\n\n <VariablePicker\n ref=\"pickerRef\"\n :visible=\"pickerVisible\"\n :trigger-dom=\"pickerTriggerDom\"\n :variables=\"props.variables\"\n :filter=\"pickerFilter\"\n :selectable-levels=\"'leaf'\"\n @select=\"onPickerSelect\"\n @dismiss=\"onPickerDismiss\"\n @update:visible=\"onPickerVisibleChange\"\n />\n </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { useFormFallbackProps } from '@veltra/compositions'\nimport { bem, injectFormContext } from '@veltra/utils'\nimport { computed, nextTick, shallowRef, useTemplateRef, watch } from 'vue'\n\nimport type { ConditionEditorProps, ConditionExpression } from '../../types'\nimport VariablePicker from '../expression-editor/components/variable-picker.vue'\nimport ConditionGroup from './components/condition-group.vue'\nimport type { MentionPayload } from './components/condition-row.vue'\nimport { createEmptyGroup, evaluate } from './core/evaluator'\n\ndefineOptions({ name: 'ConditionEditor' })\n\nconst props = withDefaults(defineProps<ConditionEditorProps>(), {\n fields: () => []\n})\n\nconst emit = defineEmits<{\n (e: 'update:modelValue', value: ConditionExpression): void\n (e: 'evaluate', results: ConditionExpression): void\n}>()\n\nconst cls = bem('condition-editor')\nconst { formProps } = injectFormContext()\nconst { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props])\n\nconst className = computed(() => [\n cls.b,\n cls.m(size.value),\n bem.is('disabled', disabled.value),\n bem.is('readonly', readonly.value)\n])\n\nconst rootGroup = shallowRef<ConditionExpression>(\n props.modelValue ? JSON.parse(JSON.stringify(props.modelValue)) : createEmptyGroup()\n)\n\nfunction serialize(): ConditionExpression {\n function clean(group: ConditionExpression): ConditionExpression {\n return {\n logic: group.logic,\n conditions: group.conditions.map((c) => {\n const { _result, ...rest } = c\n return rest\n }),\n groups: group.groups.map(clean).filter((g) => g.conditions.length > 0 || g.groups.length > 0)\n }\n }\n return clean(JSON.parse(JSON.stringify(rootGroup.value)))\n}\n\nfunction emitUpdate() {\n emit('update:modelValue', serialize())\n}\n\nfunction runEvaluate() {\n if (!props.data) return\n const cloned = JSON.parse(JSON.stringify(rootGroup.value)) as ConditionExpression\n const result = evaluate(cloned, props.data)\n rootGroup.value = result\n emit('evaluate', serialize())\n}\n\n// ── VariablePicker ──\n\nconst pickerRef = useTemplateRef<{ handleKeydown: (e: KeyboardEvent) => boolean }>('pickerRef')\nconst pickerVisible = shallowRef(false)\nconst pickerTriggerDom = shallowRef<HTMLElement | undefined>(undefined)\nconst pickerFilter = shallowRef('')\nconst mentionTarget = shallowRef<MentionPayload | null>(null)\n\nfunction onMention(payload: MentionPayload) {\n if (disabled.value || readonly.value) return\n mentionTarget.value = payload\n pickerTriggerDom.value = payload.triggerDom\n pickerFilter.value = ''\n pickerVisible.value = true\n}\n\nfunction onPickerSelect(item: { label: string; value: string }) {\n mentionTarget.value?.setValue({ kind: 'variable', name: item.value })\n pickerVisible.value = false\n mentionTarget.value = null\n}\n\nfunction onPickerDismiss() {\n pickerVisible.value = false\n mentionTarget.value = null\n}\n\nfunction onPickerVisibleChange(v: boolean) {\n if (!v) {\n pickerVisible.value = false\n mentionTarget.value = null\n }\n}\n\nfunction onGroupUpdate(group: ConditionExpression) {\n rootGroup.value = group\n emitUpdate()\n void nextTick(() => runEvaluate())\n}\n\nwatch(\n () => props.modelValue,\n (v) => {\n if (!v) return\n const current = serialize()\n if (JSON.stringify(v) === JSON.stringify(current)) return\n rootGroup.value = JSON.parse(JSON.stringify(v))\n }\n)\n\nwatch(\n () => props.data,\n () => runEvaluate(),\n { deep: true }\n)\n\nfunction onKeydown(e: KeyboardEvent) {\n if (disabled.value || readonly.value) return\n if (pickerVisible.value) {\n const handled = pickerRef.value?.handleKeydown(e)\n if (handled) {\n e.preventDefault()\n return\n }\n }\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;EAuCA,MAAM,QAAQ;EAId,MAAM,OAAO;EAKb,MAAM,MAAM,IAAI,mBAAkB;EAClC,MAAM,EAAE,cAAc,mBAAkB;EACxC,MAAM,EAAE,MAAM,UAAU,aAAa,qBAAqB,CAAC,aAAa,EAAE,EAAE,MAAM,CAAA;EAElF,MAAM,YAAY,eAAe;GAC/B,IAAI;GACJ,IAAI,EAAE,KAAK,MAAM;GACjB,IAAI,GAAG,YAAY,SAAS,MAAM;GAClC,IAAI,GAAG,YAAY,SAAS,MAAK;GAClC,CAAA;EAED,MAAM,YAAY,WAChB,MAAM,aAAa,KAAK,MAAM,KAAK,UAAU,MAAM,WAAW,CAAC,GAAG,kBAAiB,CACrF;EAEA,SAAS,YAAiC;GACxC,SAAS,MAAM,OAAiD;AAC9D,WAAO;KACL,OAAO,MAAM;KACb,YAAY,MAAM,WAAW,KAAK,MAAM;MACtC,MAAM,EAAE,SAAS,GAAG,SAAS;AAC7B,aAAO;OACP;KACF,QAAQ,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,MAAM,EAAE,WAAW,SAAS,KAAK,EAAE,OAAO,SAAS,EAAC;KAC9F;;AAEF,UAAO,MAAM,KAAK,MAAM,KAAK,UAAU,UAAU,MAAM,CAAC,CAAA;;EAG1D,SAAS,aAAa;AACpB,QAAK,qBAAqB,WAAW,CAAA;;EAGvC,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AACX,OAAE,gBAAe;AACjB;;;;;uBAtJJ,mBAsBM,OAAA;IAtBA,OAAK,eAAE,UAAA,MAAS;IAAY;OAChC,YAQE,aAAA;IAPC,OAAO,UAAA;IACP,QAAQ,MAAM;IACd,MAAM,MAAA,KAAI;IACV,UAAU,MAAA,SAAQ;IAClB,UAAU,MAAA,SAAQ;IAClB,kBAAc;IACL;;;;;;;OAGZ,YAUE,aAAA;aATI;IAAJ,KAAI;IACH,SAAS,cAAA;IACT,eAAa,iBAAA;IACb,WAAW,MAAM;IACjB,QAAQ,aAAA;IACR,qBAAmB;IACnB,UAAQ;IACR,WAAS;IACT,oBAAgB"}
@@ -1,8 +1,16 @@
1
- import { ConditionEditorProps } from "../../types/condition-editor.js";
1
+ import { ConditionEditorProps, ConditionField, ConditionGroup } from "../../types/condition-editor.js";
2
2
  import * as _$vue from "vue";
3
3
 
4
4
  //#region src/components/condition-editor/condition-editor.vue.d.ts
5
- declare const __VLS_export: _$vue.DefineComponent<ConditionEditorProps, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<ConditionEditorProps> & Readonly<{}>, {}, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
5
+ declare const __VLS_export: _$vue.DefineComponent<ConditionEditorProps, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {} & {
6
+ "update:modelValue": (value: ConditionGroup) => any;
7
+ evaluate: (results: ConditionGroup) => any;
8
+ }, string, _$vue.PublicProps, Readonly<ConditionEditorProps> & Readonly<{
9
+ "onUpdate:modelValue"?: ((value: ConditionGroup) => any) | undefined;
10
+ onEvaluate?: ((results: ConditionGroup) => any) | undefined;
11
+ }>, {
12
+ fields: ConditionField[];
13
+ }, {}, {}, {}, string, _$vue.ComponentProvideOptions, false, {}, any>;
6
14
  declare const _default: typeof __VLS_export;
7
15
  //#endregion
8
16
  export { _default };
@@ -0,0 +1,75 @@
1
+ //#region src/components/condition-editor/core/evaluator.ts
2
+ function resolveValue(item, data) {
3
+ if (item.value.kind === "constant") return item.value.value;
4
+ return String(getByPath(data, item.value.name) ?? "");
5
+ }
6
+ function resolveCompareValue(item, data) {
7
+ if (item.value.kind === "constant") return item.value.value;
8
+ return String(getByPath(data, item.value.name) ?? "");
9
+ }
10
+ function getByPath(obj, path) {
11
+ return path.split(".").reduce((acc, key) => acc != null ? acc[key] : void 0, obj);
12
+ }
13
+ function evaluateItem(item, data) {
14
+ const resolved = resolveValue(item, data);
15
+ const compareValue = resolveCompareValue(item, data);
16
+ switch (item.operator) {
17
+ case "empty": return resolved === "" || resolved === "undefined" || resolved === "null";
18
+ case "not_empty": return resolved !== "" && resolved !== "undefined" && resolved !== "null";
19
+ case "is_true": return resolved === "true" || resolved === "1";
20
+ case "is_false": return resolved === "false" || resolved === "0" || resolved === "";
21
+ case "eq": return resolved === compareValue;
22
+ case "ne": return resolved !== compareValue;
23
+ case "contains": return resolved.includes(compareValue);
24
+ case "not_contains": return !resolved.includes(compareValue);
25
+ case "gt": return Number(resolved) > Number(compareValue);
26
+ case "lt": return Number(resolved) < Number(compareValue);
27
+ case "gte": return Number(resolved) >= Number(compareValue);
28
+ case "lte": return Number(resolved) <= Number(compareValue);
29
+ case "before": return new Date(resolved).getTime() < new Date(compareValue).getTime();
30
+ case "after": return new Date(resolved).getTime() > new Date(compareValue).getTime();
31
+ case "in": return compareValue.split(",").map((s) => s.trim()).includes(resolved);
32
+ default: return false;
33
+ }
34
+ }
35
+ function evaluateGroup(group, data) {
36
+ const conditionsResult = group.conditions.map((item) => {
37
+ const result = evaluateItem(item, data);
38
+ item._result = result;
39
+ return result;
40
+ });
41
+ const groupsResult = group.groups.map((sub) => {
42
+ const result = evaluateGroup(sub, data);
43
+ sub._result = result;
44
+ return result;
45
+ });
46
+ const allResults = [...conditionsResult, ...groupsResult];
47
+ if (allResults.length === 0) return false;
48
+ return group.logic === "and" ? allResults.every(Boolean) : allResults.some(Boolean);
49
+ }
50
+ function evaluate(expression, data) {
51
+ const cloned = JSON.parse(JSON.stringify(expression));
52
+ evaluateGroup(cloned, data);
53
+ return cloned;
54
+ }
55
+ function createEmptyGroup() {
56
+ return {
57
+ logic: "and",
58
+ conditions: [],
59
+ groups: []
60
+ };
61
+ }
62
+ function createEmptyItem() {
63
+ return {
64
+ field: "",
65
+ operator: "eq",
66
+ value: {
67
+ kind: "constant",
68
+ value: ""
69
+ }
70
+ };
71
+ }
72
+ //#endregion
73
+ export { createEmptyGroup, createEmptyItem, evaluate };
74
+
75
+ //# sourceMappingURL=evaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluator.js","names":[],"sources":["../../../../src/components/condition-editor/core/evaluator.ts"],"sourcesContent":["import type { ConditionExpression, ConditionGroup, ConditionItem } from '../../../types'\n\nfunction resolveValue(item: ConditionItem, data: Record<string, unknown>): string {\n if (item.value.kind === 'constant') return item.value.value\n return String(getByPath(data, item.value.name) ?? '')\n}\n\nfunction resolveCompareValue(item: ConditionItem, data: Record<string, unknown>): string {\n if (item.value.kind === 'constant') return item.value.value\n return String(getByPath(data, item.value.name) ?? '')\n}\n\nfunction getByPath(obj: Record<string, unknown>, path: string): unknown {\n return path.split('.').reduce((acc: any, key) => (acc != null ? acc[key] : undefined), obj)\n}\n\nfunction evaluateItem(item: ConditionItem, data: Record<string, unknown>): boolean {\n const resolved = resolveValue(item, data)\n const compareValue = resolveCompareValue(item, data)\n\n switch (item.operator) {\n case 'empty':\n return resolved === '' || resolved === 'undefined' || resolved === 'null'\n case 'not_empty':\n return resolved !== '' && resolved !== 'undefined' && resolved !== 'null'\n case 'is_true':\n return resolved === 'true' || resolved === '1'\n case 'is_false':\n return resolved === 'false' || resolved === '0' || resolved === ''\n case 'eq':\n return resolved === compareValue\n case 'ne':\n return resolved !== compareValue\n case 'contains':\n return resolved.includes(compareValue)\n case 'not_contains':\n return !resolved.includes(compareValue)\n case 'gt':\n return Number(resolved) > Number(compareValue)\n case 'lt':\n return Number(resolved) < Number(compareValue)\n case 'gte':\n return Number(resolved) >= Number(compareValue)\n case 'lte':\n return Number(resolved) <= Number(compareValue)\n case 'before':\n return new Date(resolved).getTime() < new Date(compareValue).getTime()\n case 'after':\n return new Date(resolved).getTime() > new Date(compareValue).getTime()\n case 'in': {\n const vals = compareValue.split(',').map((s) => s.trim())\n return vals.includes(resolved)\n }\n default:\n return false\n }\n}\n\nfunction evaluateGroup(group: ConditionGroup, data: Record<string, unknown>): boolean {\n const conditionsResult = group.conditions.map((item) => {\n const result = evaluateItem(item, data)\n item._result = result\n return result\n })\n\n const groupsResult = group.groups.map((sub) => {\n const result = evaluateGroup(sub, data)\n sub._result = result\n return result\n })\n\n const allResults = [...conditionsResult, ...groupsResult]\n if (allResults.length === 0) return false\n\n return group.logic === 'and' ? allResults.every(Boolean) : allResults.some(Boolean)\n}\n\nexport function evaluate(\n expression: ConditionExpression,\n data: Record<string, unknown>\n): ConditionExpression {\n const cloned = JSON.parse(JSON.stringify(expression)) as ConditionExpression\n evaluateGroup(cloned, data)\n return cloned\n}\n\nexport function createEmptyGroup(): ConditionGroup {\n return { logic: 'and', conditions: [], groups: [] }\n}\n\nexport function createEmptyItem(): ConditionItem {\n return { field: '', operator: 'eq', value: { kind: 'constant', value: '' } }\n}\n"],"mappings":";AAEA,SAAS,aAAa,MAAqB,MAAuC;AAChF,KAAI,KAAK,MAAM,SAAS,WAAY,QAAO,KAAK,MAAM;AACtD,QAAO,OAAO,UAAU,MAAM,KAAK,MAAM,KAAK,IAAI,GAAG;;AAGvD,SAAS,oBAAoB,MAAqB,MAAuC;AACvF,KAAI,KAAK,MAAM,SAAS,WAAY,QAAO,KAAK,MAAM;AACtD,QAAO,OAAO,UAAU,MAAM,KAAK,MAAM,KAAK,IAAI,GAAG;;AAGvD,SAAS,UAAU,KAA8B,MAAuB;AACtE,QAAO,KAAK,MAAM,IAAI,CAAC,QAAQ,KAAU,QAAS,OAAO,OAAO,IAAI,OAAO,KAAA,GAAY,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,UAAU;AACd,SAAO;GACP;CAEF,MAAM,aAAa,CAAC,GAAG,kBAAkB,GAAG,aAAa;AACzD,KAAI,WAAW,WAAW,EAAG,QAAO;AAEpC,QAAO,MAAM,UAAU,QAAQ,WAAW,MAAM,QAAQ,GAAG,WAAW,KAAK,QAAQ;;AAGrF,SAAgB,SACd,YACA,MACqB;CACrB,MAAM,SAAS,KAAK,MAAM,KAAK,UAAU,WAAW,CAAC;AACrD,eAAc,QAAQ,KAAK;AAC3B,QAAO;;AAGT,SAAgB,mBAAmC;AACjD,QAAO;EAAE,OAAO;EAAO,YAAY,EAAE;EAAE,QAAQ,EAAE;EAAE;;AAGrD,SAAgB,kBAAiC;AAC/C,QAAO;EAAE,OAAO;EAAI,UAAU;EAAM,OAAO;GAAE,MAAM;GAAY,OAAO;GAAI;EAAE"}
@@ -0,0 +1,123 @@
1
+ //#region src/components/condition-editor/core/operators.ts
2
+ const STRING_OPERATORS = [
3
+ {
4
+ label: "等于",
5
+ value: "eq",
6
+ needValue: true
7
+ },
8
+ {
9
+ label: "不等于",
10
+ value: "ne",
11
+ needValue: true
12
+ },
13
+ {
14
+ label: "包含",
15
+ value: "contains",
16
+ needValue: true
17
+ },
18
+ {
19
+ label: "不包含",
20
+ value: "not_contains",
21
+ needValue: true
22
+ },
23
+ {
24
+ label: "为空",
25
+ value: "empty",
26
+ needValue: false
27
+ },
28
+ {
29
+ label: "不为空",
30
+ value: "not_empty",
31
+ needValue: false
32
+ }
33
+ ];
34
+ const OPERATOR_MAP = {
35
+ string: STRING_OPERATORS,
36
+ number: [
37
+ {
38
+ label: "等于",
39
+ value: "eq",
40
+ needValue: true
41
+ },
42
+ {
43
+ label: "不等于",
44
+ value: "ne",
45
+ needValue: true
46
+ },
47
+ {
48
+ label: "大于",
49
+ value: "gt",
50
+ needValue: true
51
+ },
52
+ {
53
+ label: "小于",
54
+ value: "lt",
55
+ needValue: true
56
+ },
57
+ {
58
+ label: "大于等于",
59
+ value: "gte",
60
+ needValue: true
61
+ },
62
+ {
63
+ label: "小于等于",
64
+ value: "lte",
65
+ needValue: true
66
+ }
67
+ ],
68
+ boolean: [{
69
+ label: "是",
70
+ value: "is_true",
71
+ needValue: false
72
+ }, {
73
+ label: "否",
74
+ value: "is_false",
75
+ needValue: false
76
+ }],
77
+ date: [
78
+ {
79
+ label: "等于",
80
+ value: "eq",
81
+ needValue: true
82
+ },
83
+ {
84
+ label: "不等于",
85
+ value: "ne",
86
+ needValue: true
87
+ },
88
+ {
89
+ label: "早于",
90
+ value: "before",
91
+ needValue: true
92
+ },
93
+ {
94
+ label: "晚于",
95
+ value: "after",
96
+ needValue: true
97
+ }
98
+ ],
99
+ enum: [
100
+ {
101
+ label: "等于",
102
+ value: "eq",
103
+ needValue: true
104
+ },
105
+ {
106
+ label: "不等于",
107
+ value: "ne",
108
+ needValue: true
109
+ },
110
+ {
111
+ label: "包含于",
112
+ value: "in",
113
+ needValue: true
114
+ }
115
+ ]
116
+ };
117
+ function getOperatorsByFieldType(type) {
118
+ return OPERATOR_MAP[type] ?? STRING_OPERATORS;
119
+ }
120
+ //#endregion
121
+ export { getOperatorsByFieldType };
122
+
123
+ //# sourceMappingURL=operators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operators.js","names":[],"sources":["../../../../src/components/condition-editor/core/operators.ts"],"sourcesContent":["export interface OperatorDef {\n label: string\n value: string\n needValue: boolean\n}\n\nconst STRING_OPERATORS: OperatorDef[] = [\n { label: '等于', value: 'eq', needValue: true },\n { label: '不等于', value: 'ne', needValue: true },\n { label: '包含', value: 'contains', needValue: true },\n { label: '不包含', value: 'not_contains', needValue: true },\n { label: '为空', value: 'empty', needValue: false },\n { label: '不为空', value: 'not_empty', needValue: false }\n]\n\nconst NUMBER_OPERATORS: OperatorDef[] = [\n { label: '等于', value: 'eq', needValue: true },\n { label: '不等于', value: 'ne', needValue: true },\n { label: '大于', value: 'gt', needValue: true },\n { label: '小于', value: 'lt', needValue: true },\n { label: '大于等于', value: 'gte', needValue: true },\n { label: '小于等于', value: 'lte', needValue: true }\n]\n\nconst BOOLEAN_OPERATORS: OperatorDef[] = [\n { label: '是', value: 'is_true', needValue: false },\n { label: '否', value: 'is_false', needValue: false }\n]\n\nconst DATE_OPERATORS: OperatorDef[] = [\n { label: '等于', value: 'eq', needValue: true },\n { label: '不等于', value: 'ne', needValue: true },\n { label: '早于', value: 'before', needValue: true },\n { label: '晚于', value: 'after', needValue: true }\n]\n\nconst ENUM_OPERATORS: OperatorDef[] = [\n { label: '等于', value: 'eq', needValue: true },\n { label: '不等于', value: 'ne', needValue: true },\n { label: '包含于', value: 'in', needValue: true }\n]\n\nconst OPERATOR_MAP: Record<string, OperatorDef[]> = {\n string: STRING_OPERATORS,\n number: NUMBER_OPERATORS,\n boolean: BOOLEAN_OPERATORS,\n date: DATE_OPERATORS,\n enum: ENUM_OPERATORS\n}\n\nexport function getOperatorsByFieldType(type: string): OperatorDef[] {\n return OPERATOR_MAP[type] ?? STRING_OPERATORS\n}\n\nexport function getOperatorDef(type: string, operator: string): OperatorDef | undefined {\n return getOperatorsByFieldType(type).find((op) => op.value === operator)\n}\n"],"mappings":";AAMA,MAAM,mBAAkC;CACtC;EAAE,OAAO;EAAM,OAAO;EAAM,WAAW;EAAM;CAC7C;EAAE,OAAO;EAAO,OAAO;EAAM,WAAW;EAAM;CAC9C;EAAE,OAAO;EAAM,OAAO;EAAY,WAAW;EAAM;CACnD;EAAE,OAAO;EAAO,OAAO;EAAgB,WAAW;EAAM;CACxD;EAAE,OAAO;EAAM,OAAO;EAAS,WAAW;EAAO;CACjD;EAAE,OAAO;EAAO,OAAO;EAAa,WAAW;EAAO;CACvD;AA6BD,MAAM,eAA8C;CAClD,QAAQ;CACR,QAAQ;EA5BR;GAAE,OAAO;GAAM,OAAO;GAAM,WAAW;GAAM;EAC7C;GAAE,OAAO;GAAO,OAAO;GAAM,WAAW;GAAM;EAC9C;GAAE,OAAO;GAAM,OAAO;GAAM,WAAW;GAAM;EAC7C;GAAE,OAAO;GAAM,OAAO;GAAM,WAAW;GAAM;EAC7C;GAAE,OAAO;GAAQ,OAAO;GAAO,WAAW;GAAM;EAChD;GAAE,OAAO;GAAQ,OAAO;GAAO,WAAW;GAAM;EAuBxB;CACxB,SAAS,CApBT;EAAE,OAAO;EAAK,OAAO;EAAW,WAAW;EAAO,EAClD;EAAE,OAAO;EAAK,OAAO;EAAY,WAAW;EAAO,CAmBzB;CAC1B,MAAM;EAhBN;GAAE,OAAO;GAAM,OAAO;GAAM,WAAW;GAAM;EAC7C;GAAE,OAAO;GAAO,OAAO;GAAM,WAAW;GAAM;EAC9C;GAAE,OAAO;GAAM,OAAO;GAAU,WAAW;GAAM;EACjD;GAAE,OAAO;GAAM,OAAO;GAAS,WAAW;GAAM;EAa5B;CACpB,MAAM;EAVN;GAAE,OAAO;GAAM,OAAO;GAAM,WAAW;GAAM;EAC7C;GAAE,OAAO;GAAO,OAAO;GAAM,WAAW;GAAM;EAC9C;GAAE,OAAO;GAAO,OAAO;GAAM,WAAW;GAAM;EAQ1B;CACrB;AAED,SAAgB,wBAAwB,MAA6B;AACnE,QAAO,aAAa,SAAS"}
@@ -1 +1,8 @@
1
+ import "../icon/style.js";
2
+ import "../tip/style.js";
3
+ import "../scroll/style.js";
4
+ import "../input/style.js";
5
+ import "../empty/style.js";
6
+ import "../select/style.js";
7
+ import "../expression-editor/style.js";
1
8
  import "./style2.css";