@shwfed/nuxt 0.7.9 → 0.7.11
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.
- package/dist/module.json +1 -1
- package/dist/runtime/components/app.d.vue.ts +7 -56
- package/dist/runtime/components/app.vue +17 -404
- package/dist/runtime/components/app.vue.d.ts +7 -56
- package/dist/runtime/components/fields.d.vue.ts +154 -132
- package/dist/runtime/components/fields.vue +30 -295
- package/dist/runtime/components/fields.vue.d.ts +154 -132
- package/dist/runtime/components/table.d.vue.ts +129 -59
- package/dist/runtime/components/table.vue +51 -617
- package/dist/runtime/components/table.vue.d.ts +129 -59
- package/dist/runtime/components/ui/app/App.d.vue.ts +86 -0
- package/dist/runtime/components/ui/app/App.vue +414 -0
- package/dist/runtime/components/ui/app/App.vue.d.ts +86 -0
- package/dist/runtime/components/ui/checkbox/Checkbox.vue +6 -2
- package/dist/runtime/components/ui/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/dist/runtime/components/ui/expression-editor/ExpressionEditor.d.vue.ts +30 -0
- package/dist/runtime/components/ui/expression-editor/ExpressionEditor.vue +87 -0
- package/dist/runtime/components/ui/expression-editor/ExpressionEditor.vue.d.ts +30 -0
- package/dist/runtime/components/ui/expression-editor/index.d.ts +1 -0
- package/dist/runtime/components/ui/expression-editor/index.js +1 -0
- package/dist/runtime/components/ui/field/FieldContent.vue +1 -1
- package/dist/runtime/components/ui/field/FieldError.vue +2 -2
- package/dist/runtime/components/ui/field/FieldLabel.vue +1 -1
- package/dist/runtime/components/ui/fields/Fields.d.vue.ts +376 -0
- package/dist/runtime/components/ui/fields/Fields.vue +441 -0
- package/dist/runtime/components/ui/fields/Fields.vue.d.ts +376 -0
- package/dist/runtime/components/ui/fields-configurator/FieldsConfiguratorDialog.d.vue.ts +163 -0
- package/dist/runtime/components/ui/fields-configurator/FieldsConfiguratorDialog.vue +363 -0
- package/dist/runtime/components/ui/fields-configurator/FieldsConfiguratorDialog.vue.d.ts +163 -0
- package/dist/runtime/components/ui/icon-picker/IconPicker.d.vue.ts +15 -0
- package/dist/runtime/components/ui/icon-picker/IconPicker.vue +178 -0
- package/dist/runtime/components/ui/icon-picker/IconPicker.vue.d.ts +15 -0
- package/dist/runtime/components/ui/icon-picker/index.d.ts +1 -0
- package/dist/runtime/components/ui/icon-picker/index.js +1 -0
- package/dist/runtime/components/ui/input/Input.d.vue.ts +1 -0
- package/dist/runtime/components/ui/input/Input.vue +2 -0
- package/dist/runtime/components/ui/input/Input.vue.d.ts +1 -0
- package/dist/runtime/components/ui/input-group/InputGroupAddon.vue +4 -1
- package/dist/runtime/components/ui/input-group/InputGroupCombobox.d.vue.ts +8 -3
- package/dist/runtime/components/ui/input-group/InputGroupCombobox.vue +8 -3
- package/dist/runtime/components/ui/input-group/InputGroupCombobox.vue.d.ts +8 -3
- package/dist/runtime/components/ui/input-group/InputGroupComboboxInput.d.vue.ts +8 -1
- package/dist/runtime/components/ui/input-group/InputGroupComboboxInput.vue +11 -2
- package/dist/runtime/components/ui/input-group/InputGroupComboboxInput.vue.d.ts +8 -1
- package/dist/runtime/components/ui/input-group/InputGroupInput.vue +1 -1
- package/dist/runtime/components/ui/input-group/InputGroupNumberField.d.vue.ts +5 -2
- package/dist/runtime/components/ui/input-group/InputGroupNumberField.vue +10 -4
- package/dist/runtime/components/ui/input-group/InputGroupNumberField.vue.d.ts +5 -2
- package/dist/runtime/components/ui/input-group/InputGroupTextarea.vue +1 -1
- package/dist/runtime/components/ui/input-group/index.js +1 -1
- package/dist/runtime/components/ui/locale/Locale.d.vue.ts +20 -0
- package/dist/runtime/components/ui/locale/Locale.vue +291 -0
- package/dist/runtime/components/ui/locale/Locale.vue.d.ts +20 -0
- package/dist/runtime/components/ui/locale/index.d.ts +1 -0
- package/dist/runtime/components/ui/locale/index.js +1 -0
- package/dist/runtime/components/ui/native-select/NativeSelect.d.vue.ts +2 -2
- package/dist/runtime/components/ui/native-select/NativeSelect.vue +1 -1
- package/dist/runtime/components/ui/native-select/NativeSelect.vue.d.ts +2 -2
- package/dist/runtime/components/ui/native-select/NativeSelectOption.d.vue.ts +1 -0
- package/dist/runtime/components/ui/native-select/NativeSelectOption.vue +4 -1
- package/dist/runtime/components/ui/native-select/NativeSelectOption.vue.d.ts +1 -0
- package/dist/runtime/components/ui/number-field/NumberFieldInput.vue +1 -1
- package/dist/runtime/components/ui/switch/Switch.vue +2 -2
- package/dist/runtime/components/ui/table/Table.d.vue.ts +147 -0
- package/dist/runtime/components/ui/table/Table.vue +952 -0
- package/dist/runtime/components/ui/table/Table.vue.d.ts +147 -0
- package/dist/runtime/components/ui/table/schema.d.ts +151 -0
- package/dist/runtime/components/ui/table/schema.js +142 -0
- package/dist/runtime/components/ui/table-configurator/TableConfiguratorDialog.d.vue.ts +128 -0
- package/dist/runtime/components/ui/table-configurator/TableConfiguratorDialog.vue +2719 -0
- package/dist/runtime/components/ui/table-configurator/TableConfiguratorDialog.vue.d.ts +128 -0
- package/dist/runtime/components/ui/table-configurator/menu.d.ts +37 -0
- package/dist/runtime/components/ui/table-configurator/menu.js +227 -0
- package/dist/runtime/components/ui/tabs/Tabs.d.vue.ts +24 -0
- package/dist/runtime/components/ui/tabs/Tabs.vue +30 -0
- package/dist/runtime/components/ui/tabs/Tabs.vue.d.ts +24 -0
- package/dist/runtime/components/ui/tabs/TabsContent.d.vue.ts +18 -0
- package/dist/runtime/components/ui/tabs/TabsContent.vue +23 -0
- package/dist/runtime/components/ui/tabs/TabsContent.vue.d.ts +18 -0
- package/dist/runtime/components/ui/tabs/TabsList.d.vue.ts +18 -0
- package/dist/runtime/components/ui/tabs/TabsList.vue +25 -0
- package/dist/runtime/components/ui/tabs/TabsList.vue.d.ts +18 -0
- package/dist/runtime/components/ui/tabs/TabsTrigger.d.vue.ts +18 -0
- package/dist/runtime/components/ui/tabs/TabsTrigger.vue +27 -0
- package/dist/runtime/components/ui/tabs/TabsTrigger.vue.d.ts +18 -0
- package/dist/runtime/components/ui/tabs/index.d.ts +4 -0
- package/dist/runtime/components/ui/tabs/index.js +4 -0
- package/dist/runtime/components/ui/textarea/Textarea.d.vue.ts +1 -0
- package/dist/runtime/components/ui/textarea/Textarea.vue +4 -2
- package/dist/runtime/components/ui/textarea/Textarea.vue.d.ts +1 -0
- package/dist/runtime/components/ui/toggle/Toggle.d.vue.ts +34 -0
- package/dist/runtime/components/ui/toggle/Toggle.vue +32 -0
- package/dist/runtime/components/ui/toggle/Toggle.vue.d.ts +34 -0
- package/dist/runtime/components/ui/toggle/index.d.ts +7 -0
- package/dist/runtime/components/ui/toggle/index.js +22 -0
- package/dist/runtime/composables/useTableRenderers.d.ts +2 -1
- package/dist/runtime/composables/useTableRenderers.js +2 -1
- package/dist/runtime/plugins/toast/index.d.ts +2 -2
- package/dist/runtime/style.css +1 -1
- package/dist/runtime/table-renderers/builtins.js +328 -137
- package/dist/runtime/table-renderers/registry.d.ts +2 -1
- package/dist/runtime/table-renderers/registry.js +3 -0
- package/dist/runtime/utils/coders.d.ts +29 -2
- package/dist/runtime/utils/coders.js +40 -2
- package/package.json +8 -6
- /package/dist/runtime/components/{logo.d.vue.ts → ui/logo/Logo.d.vue.ts} +0 -0
- /package/dist/runtime/components/{logo.vue → ui/logo/Logo.vue} +0 -0
- /package/dist/runtime/components/{logo.vue.d.ts → ui/logo/Logo.vue.d.ts} +0 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { Icon } from "@iconify/vue";
|
|
3
|
+
import { useNuxtApp } from "#app";
|
|
4
|
+
import { ref, toRaw, useId, watchEffect } from "vue";
|
|
5
|
+
import { Field, FieldContent, FieldError, FieldLabel } from "../field";
|
|
6
|
+
import { Button } from "../button";
|
|
7
|
+
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupCombobox, InputGroupInput, InputGroupNumberField } from "../input-group";
|
|
8
|
+
import { CommandGroup, CommandItem } from "../command";
|
|
9
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip";
|
|
10
|
+
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../popover";
|
|
11
|
+
import { Calendar } from "../calendar";
|
|
12
|
+
import { useI18n } from "vue-i18n";
|
|
13
|
+
import { deleteProperty, getProperty, hasProperty, setProperty } from "dot-prop";
|
|
14
|
+
import { useCheating } from "#imports";
|
|
15
|
+
import { Skeleton } from "../skeleton";
|
|
16
|
+
import z from "zod";
|
|
17
|
+
import { Effect } from "effect";
|
|
18
|
+
import { computedAsync } from "@vueuse/core";
|
|
19
|
+
import { localeC, dotPropC, expressionC } from "../../../utils/coders";
|
|
20
|
+
import { CalendarDate, getLocalTimeZone } from "@internationalized/date";
|
|
21
|
+
import { format, parse } from "date-fns";
|
|
22
|
+
import { TZDate } from "@date-fns/tz";
|
|
23
|
+
import FieldsConfiguratorDialog from "../fields-configurator/FieldsConfiguratorDialog.vue";
|
|
24
|
+
const ValidationRuleC = z.object({
|
|
25
|
+
expression: expressionC("bool", { value: "dyn", form: "map<string, dyn>" }).describe("\u8FD4\u56DE\u5E03\u5C14\u503C\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u53EF\u4F7F\u7528 value \u548C form \u53D8\u91CF"),
|
|
26
|
+
message: z.string().describe("\u6821\u9A8C\u5931\u8D25\u65F6\u5C55\u793A\u7684 Markdown \u6D88\u606F\uFF0C\u53EF\u5728 {{ expression }} \u4E2D\u4F7F\u7528 value \u548C form \u53D8\u91CF")
|
|
27
|
+
}).readonly();
|
|
28
|
+
const validationC = z.array(ValidationRuleC).readonly().optional().describe("\u5B57\u6BB5\u5931\u7126\u65F6\u6309\u987A\u5E8F\u6267\u884C\u7684\u6821\u9A8C\u89C4\u5219\uFF0C\u547D\u4E2D\u7B2C\u4E00\u4E2A\u5931\u8D25\u89C4\u5219\u540E\u505C\u6B62");
|
|
29
|
+
export const StringFieldC = z.object({
|
|
30
|
+
type: z.literal("string").describe("\u5355\u884C\u6587\u672C\u8F93\u5165\u5B57\u6BB5\uFF0C\u7ED1\u5B9A string \u7C7B\u578B\u7684\u503C"),
|
|
31
|
+
path: dotPropC,
|
|
32
|
+
title: localeC.describe("\u5B57\u6BB5\u6807\u7B7E\u7684\u672C\u5730\u5316\u663E\u793A\u6587\u672C"),
|
|
33
|
+
icon: z.string().optional().describe("Iconify \u56FE\u6807\u6807\u8BC6\u7B26\uFF0C\u663E\u793A\u5728\u8F93\u5165\u6846\u5185\u4FA7"),
|
|
34
|
+
style: z.string().optional().describe("CSS \u6837\u5F0F\u5BF9\u8C61\u8868\u8FBE\u5F0F\uFF0C\u63A7\u5236\u5B57\u6BB5\u7684\u5E03\u5C40\u4E0E\u5916\u89C2"),
|
|
35
|
+
discardEmptyString: z.boolean().optional().describe("\u4E3A true \u65F6\uFF0C\u7A7A\u5B57\u7B26\u4E32\u4F5C\u4E3A\u6709\u6548\u503C\u5B58\u50A8\uFF1B\u5426\u5219\u6E05\u7A7A\u8F93\u5165\u5C06\u5220\u9664\u5BF9\u5E94\u5C5E\u6027"),
|
|
36
|
+
maxLength: expressionC("int").optional().describe('\u8FD4\u56DE\u6574\u6570\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u9650\u5236\u8F93\u5165\u7684\u6700\u5927\u5B57\u7B26\u6570\uFF0C\u5982 "100"'),
|
|
37
|
+
hidden: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u9690\u85CF\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
38
|
+
disabled: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u7981\u7528\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
39
|
+
validation: validationC
|
|
40
|
+
});
|
|
41
|
+
export const NumberFieldC = z.object({
|
|
42
|
+
type: z.literal("number").describe("\u6570\u5B57\u8F93\u5165\u5B57\u6BB5\uFF0C\u7ED1\u5B9A number \u7C7B\u578B\u7684\u503C"),
|
|
43
|
+
path: dotPropC,
|
|
44
|
+
title: localeC.describe("\u5B57\u6BB5\u6807\u7B7E\u7684\u672C\u5730\u5316\u663E\u793A\u6587\u672C"),
|
|
45
|
+
icon: z.string().optional().describe("Iconify \u56FE\u6807\u6807\u8BC6\u7B26\uFF0C\u663E\u793A\u5728\u8F93\u5165\u6846\u5185\u4FA7"),
|
|
46
|
+
style: z.string().optional().describe("CSS \u6837\u5F0F\u5BF9\u8C61\u8868\u8FBE\u5F0F\uFF0C\u63A7\u5236\u5B57\u6BB5\u7684\u5E03\u5C40\u4E0E\u5916\u89C2"),
|
|
47
|
+
min: expressionC("double").optional().describe('\u8FD4\u56DE\u6D6E\u70B9\u6570\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u9650\u5236\u5141\u8BB8\u7684\u6700\u5C0F\u503C\uFF0C\u5982 "0.0"'),
|
|
48
|
+
max: expressionC("double").optional().describe('\u8FD4\u56DE\u6D6E\u70B9\u6570\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u9650\u5236\u5141\u8BB8\u7684\u6700\u5927\u503C\uFF0C\u5982 "100.0"'),
|
|
49
|
+
step: expressionC("double").optional().describe('\u8FD4\u56DE\u6D6E\u70B9\u6570\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u63A7\u5236\u6570\u503C\u9012\u589E\u6B65\u957F\uFF0C\u5982 "0.5"'),
|
|
50
|
+
hidden: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u9690\u85CF\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
51
|
+
disabled: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u7981\u7528\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
52
|
+
validation: validationC
|
|
53
|
+
});
|
|
54
|
+
export const SelectFieldC = z.object({
|
|
55
|
+
type: z.literal("select").describe("\u4E0B\u62C9\u9009\u62E9\u5B57\u6BB5\uFF0C\u4ECE\u9884\u5B9A\u4E49\u9009\u9879\u4E2D\u9009\u53D6\u4E00\u4E2A\u503C"),
|
|
56
|
+
path: dotPropC,
|
|
57
|
+
title: localeC.describe("\u5B57\u6BB5\u6807\u7B7E\u7684\u672C\u5730\u5316\u663E\u793A\u6587\u672C"),
|
|
58
|
+
icon: z.string().optional().describe("Iconify \u56FE\u6807\u6807\u8BC6\u7B26\uFF0C\u663E\u793A\u5728\u8F93\u5165\u6846\u5185\u4FA7"),
|
|
59
|
+
options: expressionC(/^list/).describe("\u5168\u90E8\u5019\u9009\u9879"),
|
|
60
|
+
label: expressionC("string", { option: "dyn" }).describe("\u8FD4\u56DE\u5B57\u7B26\u4E32\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u63D0\u4F9B option \u53D8\u91CF\uFF0C\u751F\u6210\u8BE5\u9009\u9879\u7684\u663E\u793A\u6587\u672C"),
|
|
61
|
+
value: expressionC(/.+/, { option: "dyn" }).describe("\u8FD4\u56DE\u4EFB\u610F\u503C\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u63D0\u4F9B option \u53D8\u91CF\uFF0C\u8FD4\u56DE\u503C\u5C06\u88AB\u5199\u5165\u7ED1\u5B9A\u5B57\u6BB5"),
|
|
62
|
+
key: expressionC("string", { option: "dyn" }).describe("\u8FD4\u56DE\u5B57\u7B26\u4E32\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u63D0\u4F9B option \u53D8\u91CF\uFF0C\u8FD4\u56DE\u503C\u4E0E\u9009\u9879\u6784\u6210\u5168\u6620\u5C04"),
|
|
63
|
+
style: z.string().optional().describe("CSS \u6837\u5F0F\u5BF9\u8C61\u8868\u8FBE\u5F0F\uFF0C\u63A7\u5236\u5B57\u6BB5\u7684\u5E03\u5C40\u4E0E\u5916\u89C2"),
|
|
64
|
+
hidden: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u9690\u85CF\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
65
|
+
disabled: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u7981\u7528\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
66
|
+
validation: validationC
|
|
67
|
+
});
|
|
68
|
+
export const CalendarFieldC = z.object({
|
|
69
|
+
type: z.literal("calendar").describe("\u65E5\u671F\u9009\u62E9\u5B57\u6BB5\uFF0C\u901A\u8FC7\u5F39\u51FA\u65E5\u5386\u9762\u677F\u9009\u62E9\u65E5\u671F"),
|
|
70
|
+
path: dotPropC,
|
|
71
|
+
title: localeC.describe("\u5B57\u6BB5\u6807\u7B7E\u7684\u672C\u5730\u5316\u663E\u793A\u6587\u672C"),
|
|
72
|
+
icon: z.string().optional().describe("Iconify \u56FE\u6807\u6807\u8BC6\u7B26\uFF0C\u663E\u793A\u5728\u8F93\u5165\u6846\u5185\u4FA7"),
|
|
73
|
+
style: z.string().optional().describe("CSS \u6837\u5F0F\u5BF9\u8C61\u8868\u8FBE\u5F0F\uFF0C\u63A7\u5236\u5B57\u6BB5\u7684\u5E03\u5C40\u4E0E\u5916\u89C2"),
|
|
74
|
+
mode: z.enum(["year", "month", "date"]).describe("\u65E5\u5386\u9009\u62E9\u7CBE\u5EA6\uFF1Ayear \u4EC5\u9009\u5E74\uFF0Cmonth \u9009\u5E74\u6708\uFF0Cdate \u9009\u5E74\u6708\u65E5"),
|
|
75
|
+
display: z.string().optional().describe('date-fns \u683C\u5F0F\u5B57\u7B26\u4E32\uFF0C\u63A7\u5236\u8F93\u5165\u6846\u4E2D\u7684\u5C55\u793A\u683C\u5F0F\uFF0C\u5982 "yyyy\u5E74MM\u6708dd\u65E5"\uFF1B\u7559\u7A7A\u5219\u663E\u793A\u539F\u59CB\u5B58\u50A8\u503C'),
|
|
76
|
+
value: z.string().describe('date-fns \u683C\u5F0F\u5B57\u7B26\u4E32\uFF0C\u5B9A\u4E49\u65E5\u671F\u5728 model \u4E2D\u7684\u5B58\u50A8\u683C\u5F0F\uFF0C\u5982 "yyyy-MM-dd"'),
|
|
77
|
+
disableDate: expressionC("bool", { date: "Date" }).optional().describe("\u8FD4\u56DE\u5E03\u5C14\u503C\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u4EE5 date\uFF08Date \u7C7B\u578B\uFF09\u4E3A\u53D8\u91CF\uFF0C\u8FD4\u56DE true \u65F6\u8BE5\u65E5\u671F\u5728\u65E5\u5386\u4E2D\u88AB\u7981\u7528"),
|
|
78
|
+
hidden: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u9690\u85CF\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
79
|
+
disabled: expressionC("bool", { form: "map<string, dyn>" }).optional().describe("\u4E3A true \u65F6\uFF0C\u7981\u7528\u8FD9\u4E2A\u5B57\u6BB5"),
|
|
80
|
+
validation: validationC
|
|
81
|
+
});
|
|
82
|
+
export const FieldC = z.union([
|
|
83
|
+
StringFieldC,
|
|
84
|
+
NumberFieldC,
|
|
85
|
+
SelectFieldC,
|
|
86
|
+
CalendarFieldC
|
|
87
|
+
]);
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<script setup>
|
|
91
|
+
const id = useId();
|
|
92
|
+
const props = defineProps({
|
|
93
|
+
orientation: { type: String, required: false, default: "horizontal" },
|
|
94
|
+
fields: { type: null, required: true }
|
|
95
|
+
});
|
|
96
|
+
const emit = defineEmits(["update:fields"]);
|
|
97
|
+
const fields = computedAsync(async () => z.array(FieldC).readonly().parse(await props.fields.pipe(Effect.runPromise)));
|
|
98
|
+
const { t, locale } = useI18n();
|
|
99
|
+
const { $dsl, $md } = useNuxtApp();
|
|
100
|
+
const modelValue = defineModel("modelValue", { type: Object, ...{
|
|
101
|
+
default: () => ({})
|
|
102
|
+
} });
|
|
103
|
+
const isCheating = useCheating();
|
|
104
|
+
const isConfiguratorOpen = ref(false);
|
|
105
|
+
const validationErrors = ref({});
|
|
106
|
+
const calendarOpen = ref({});
|
|
107
|
+
function toCalendarDateValue(value, valueFormat) {
|
|
108
|
+
if (typeof value !== "string") return void 0;
|
|
109
|
+
const date = parse(value, valueFormat, /* @__PURE__ */ new Date());
|
|
110
|
+
if (Number.isNaN(date.getTime())) return void 0;
|
|
111
|
+
return new CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
|
112
|
+
}
|
|
113
|
+
function displayCalendarValue(stored, displayFormat, valueFormat) {
|
|
114
|
+
if (displayFormat) {
|
|
115
|
+
const dateVal = toCalendarDateValue(stored, valueFormat);
|
|
116
|
+
if (dateVal) return format(dateVal.toDate(getLocalTimeZone()), displayFormat);
|
|
117
|
+
}
|
|
118
|
+
return stored ?? "";
|
|
119
|
+
}
|
|
120
|
+
function isFieldHidden(field) {
|
|
121
|
+
return $dsl.evaluate`${field.hidden || "false"}`({ form: modelValue.value });
|
|
122
|
+
}
|
|
123
|
+
function isFieldDisabled(field) {
|
|
124
|
+
return $dsl.evaluate`${field.disabled || "false"}`({ form: modelValue.value });
|
|
125
|
+
}
|
|
126
|
+
function getFieldValue(field) {
|
|
127
|
+
return getProperty(modelValue.value, field.path);
|
|
128
|
+
}
|
|
129
|
+
function clearFieldValidation(path) {
|
|
130
|
+
Reflect.deleteProperty(validationErrors.value, path);
|
|
131
|
+
}
|
|
132
|
+
function snapshotValidationContext(field) {
|
|
133
|
+
const form = structuredClone(toRaw(modelValue.value));
|
|
134
|
+
return {
|
|
135
|
+
value: getProperty(form, field.path),
|
|
136
|
+
form
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function validateField(field) {
|
|
140
|
+
if (!field.validation?.length || isFieldHidden(field) || isFieldDisabled(field)) {
|
|
141
|
+
clearFieldValidation(field.path);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const context = {
|
|
145
|
+
value: getFieldValue(field),
|
|
146
|
+
form: modelValue.value
|
|
147
|
+
};
|
|
148
|
+
for (const rule of field.validation) {
|
|
149
|
+
if (!$dsl.evaluate`${rule.expression}`(context)) {
|
|
150
|
+
validationErrors.value[field.path] = {
|
|
151
|
+
message: rule.message,
|
|
152
|
+
context: snapshotValidationContext(field)
|
|
153
|
+
};
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
clearFieldValidation(field.path);
|
|
158
|
+
}
|
|
159
|
+
function isFieldInvalid(field) {
|
|
160
|
+
return validationErrors.value[field.path] !== void 0;
|
|
161
|
+
}
|
|
162
|
+
function renderValidationMessage(field) {
|
|
163
|
+
const error = validationErrors.value[field.path];
|
|
164
|
+
if (!error) return "";
|
|
165
|
+
return $md.inline`${error.message}`(error.context);
|
|
166
|
+
}
|
|
167
|
+
function handleCalendarOpenChange(field, open) {
|
|
168
|
+
if (open) {
|
|
169
|
+
calendarOpen.value[field.path] = true;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
Reflect.deleteProperty(calendarOpen.value, field.path);
|
|
173
|
+
validateField(field);
|
|
174
|
+
}
|
|
175
|
+
function handleCalendarBlur(field) {
|
|
176
|
+
window.setTimeout(() => {
|
|
177
|
+
if (!calendarOpen.value[field.path]) {
|
|
178
|
+
validateField(field);
|
|
179
|
+
}
|
|
180
|
+
}, 0);
|
|
181
|
+
}
|
|
182
|
+
function handleConfiguratorConfirm(nextFields) {
|
|
183
|
+
emit("update:fields", nextFields);
|
|
184
|
+
}
|
|
185
|
+
watchEffect(() => {
|
|
186
|
+
const activePaths = /* @__PURE__ */ new Set();
|
|
187
|
+
for (const field of fields.value ?? []) {
|
|
188
|
+
if (!isFieldHidden(field) && !isFieldDisabled(field)) {
|
|
189
|
+
activePaths.add(field.path);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const path of Object.keys(validationErrors.value)) {
|
|
193
|
+
if (!activePaths.has(path)) {
|
|
194
|
+
clearFieldValidation(path);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
for (const path of Object.keys(calendarOpen.value)) {
|
|
198
|
+
if (!activePaths.has(path)) {
|
|
199
|
+
Reflect.deleteProperty(calendarOpen.value, path);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
</script>
|
|
204
|
+
|
|
205
|
+
<template>
|
|
206
|
+
<div
|
|
207
|
+
:class="[
|
|
208
|
+
'relative p-1 border border-dashed',
|
|
209
|
+
isCheating ? 'border-(--primary)/20 rounded hover:border-(--primary)/40 transition-colors duration-150 group cursor-pointer' : 'border-transparent'
|
|
210
|
+
]"
|
|
211
|
+
>
|
|
212
|
+
<Button
|
|
213
|
+
v-if="isCheating"
|
|
214
|
+
data-slot="fields-configurator-trigger"
|
|
215
|
+
variant="ghost"
|
|
216
|
+
size="sm"
|
|
217
|
+
type="button"
|
|
218
|
+
class="absolute right-3 top-3 z-20 bg-white/90 shadow-xs backdrop-blur-sm hover:bg-white"
|
|
219
|
+
@click="isConfiguratorOpen = true"
|
|
220
|
+
>
|
|
221
|
+
<Icon icon="fluent:settings-20-regular" />
|
|
222
|
+
</Button>
|
|
223
|
+
|
|
224
|
+
<FieldsConfiguratorDialog
|
|
225
|
+
v-if="fields"
|
|
226
|
+
v-model:open="isConfiguratorOpen"
|
|
227
|
+
:fields="fields"
|
|
228
|
+
@confirm="handleConfiguratorConfirm"
|
|
229
|
+
/>
|
|
230
|
+
|
|
231
|
+
<Skeleton
|
|
232
|
+
v-if="fields === void 0"
|
|
233
|
+
class="absolute inset-0 z-10 w-full h-full"
|
|
234
|
+
/>
|
|
235
|
+
|
|
236
|
+
<template
|
|
237
|
+
v-for="field in fields"
|
|
238
|
+
:key="field.path"
|
|
239
|
+
>
|
|
240
|
+
<Field
|
|
241
|
+
v-if="!isFieldHidden(field)"
|
|
242
|
+
:data-disabled="isFieldDisabled(field) ? 'true' : void 0"
|
|
243
|
+
:data-invalid="isFieldInvalid(field) ? 'true' : void 0"
|
|
244
|
+
:orientation="orientation"
|
|
245
|
+
:style="field.style ? $dsl.evaluate`${field.style}`() : {}"
|
|
246
|
+
>
|
|
247
|
+
<FieldLabel :for="['string', 'number'].includes(field.type) ? `${id}:${field.path}` : void 0">
|
|
248
|
+
{{ field.title.find((r) => r.locale === locale)?.message ?? field.title[0]?.message }}
|
|
249
|
+
<span v-if="isCheating">
|
|
250
|
+
<span class="font-mono">{{ field.path }}</span>
|
|
251
|
+
</span>
|
|
252
|
+
</FieldLabel>
|
|
253
|
+
<FieldContent>
|
|
254
|
+
<Popover
|
|
255
|
+
v-if="field.type === 'calendar'"
|
|
256
|
+
@update:open="(open) => handleCalendarOpenChange(field, open)"
|
|
257
|
+
>
|
|
258
|
+
<PopoverAnchor as-child>
|
|
259
|
+
<InputGroup :data-disabled="isFieldDisabled(field) ? 'true' : void 0">
|
|
260
|
+
<PopoverTrigger as-child>
|
|
261
|
+
<InputGroupInput
|
|
262
|
+
:model-value="displayCalendarValue(getProperty(modelValue, field.path), field.display, field.value)"
|
|
263
|
+
class="text-left"
|
|
264
|
+
:disabled="isFieldDisabled(field)"
|
|
265
|
+
:aria-invalid="isFieldInvalid(field) ? 'true' : void 0"
|
|
266
|
+
readonly
|
|
267
|
+
@blur="handleCalendarBlur(field)"
|
|
268
|
+
/>
|
|
269
|
+
</PopoverTrigger>
|
|
270
|
+
<InputGroupAddon v-if="field.icon">
|
|
271
|
+
<Icon
|
|
272
|
+
:icon="field.icon"
|
|
273
|
+
/>
|
|
274
|
+
</InputGroupAddon>
|
|
275
|
+
<InputGroupAddon
|
|
276
|
+
v-if="hasProperty(modelValue, field.path)"
|
|
277
|
+
align="inline-end"
|
|
278
|
+
:class="orientation === 'floating' ? 'group-data-[disabled=true]/input-group:hidden' : void 0"
|
|
279
|
+
>
|
|
280
|
+
<Tooltip :delay-duration="800">
|
|
281
|
+
<TooltipTrigger>
|
|
282
|
+
<InputGroupButton as-child>
|
|
283
|
+
<button
|
|
284
|
+
type="button"
|
|
285
|
+
class="text-zinc-300 hover:text-zinc-500 transition-colors"
|
|
286
|
+
:disabled="isFieldDisabled(field)"
|
|
287
|
+
@click="deleteProperty(modelValue, field.path)"
|
|
288
|
+
>
|
|
289
|
+
<Icon
|
|
290
|
+
icon="fluent:dismiss-20-regular"
|
|
291
|
+
/>
|
|
292
|
+
</button>
|
|
293
|
+
</InputGroupButton>
|
|
294
|
+
</TooltipTrigger>
|
|
295
|
+
<TooltipContent>
|
|
296
|
+
{{ t("clear") }}
|
|
297
|
+
</TooltipContent>
|
|
298
|
+
</Tooltip>
|
|
299
|
+
</InputGroupAddon>
|
|
300
|
+
</InputGroup>
|
|
301
|
+
</PopoverAnchor>
|
|
302
|
+
<PopoverContent class="w-72">
|
|
303
|
+
<Calendar
|
|
304
|
+
:locale="locale"
|
|
305
|
+
:layout="field.mode"
|
|
306
|
+
:model-value="toCalendarDateValue(getProperty(modelValue, field.path), field.value)"
|
|
307
|
+
:disabled="isFieldDisabled(field)"
|
|
308
|
+
:is-date-disabled="field.disableDate ? (date) => !!$dsl.evaluate`${field.disableDate}`({ date: new TZDate(date.toDate(getLocalTimeZone())) }) : void 0"
|
|
309
|
+
@update:model-value="(value) => {
|
|
310
|
+
if (value === void 0) {
|
|
311
|
+
deleteProperty(modelValue, field.path);
|
|
312
|
+
} else {
|
|
313
|
+
setProperty(modelValue, field.path, format(value.toDate(getLocalTimeZone()), field.value));
|
|
314
|
+
}
|
|
315
|
+
}"
|
|
316
|
+
/>
|
|
317
|
+
</PopoverContent>
|
|
318
|
+
</Popover>
|
|
319
|
+
<InputGroup
|
|
320
|
+
v-else
|
|
321
|
+
:data-disabled="isFieldDisabled(field) ? 'true' : void 0"
|
|
322
|
+
>
|
|
323
|
+
<InputGroupInput
|
|
324
|
+
v-if="field.type === 'string'"
|
|
325
|
+
:id="`${id}:${field.path}`"
|
|
326
|
+
:treat-empty-as-different-state-from-null="!!field.discardEmptyString"
|
|
327
|
+
:model-value="getProperty(modelValue, field.path)"
|
|
328
|
+
:maxlength="field.maxLength ? $dsl.evaluate`${field.maxLength}`() : void 0"
|
|
329
|
+
:disabled="isFieldDisabled(field)"
|
|
330
|
+
:aria-invalid="isFieldInvalid(field) ? 'true' : void 0"
|
|
331
|
+
@update:model-value="(value) => {
|
|
332
|
+
if (!value && !field.discardEmptyString) {
|
|
333
|
+
deleteProperty(modelValue, field.path);
|
|
334
|
+
} else {
|
|
335
|
+
setProperty(modelValue, field.path, value);
|
|
336
|
+
}
|
|
337
|
+
}"
|
|
338
|
+
@blur="validateField(field)"
|
|
339
|
+
/>
|
|
340
|
+
<InputGroupNumberField
|
|
341
|
+
v-if="field.type === 'number'"
|
|
342
|
+
:id="`${id}:${field.path}`"
|
|
343
|
+
:model-value="getProperty(modelValue, field.path) ?? null"
|
|
344
|
+
:min="field.min ? $dsl.evaluate`${field.min}`() : void 0"
|
|
345
|
+
:max="field.max ? $dsl.evaluate`${field.max}`() : void 0"
|
|
346
|
+
:step="field.step ? $dsl.evaluate`${field.step}`() : void 0"
|
|
347
|
+
:disabled="isFieldDisabled(field)"
|
|
348
|
+
:invalid="isFieldInvalid(field)"
|
|
349
|
+
@update:model-value="(value) => {
|
|
350
|
+
if (!value && value !== 0) {
|
|
351
|
+
deleteProperty(modelValue, field.path);
|
|
352
|
+
} else {
|
|
353
|
+
setProperty(modelValue, field.path, value);
|
|
354
|
+
}
|
|
355
|
+
}"
|
|
356
|
+
@blur="validateField(field)"
|
|
357
|
+
/>
|
|
358
|
+
<InputGroupCombobox
|
|
359
|
+
v-if="field.type === 'select'"
|
|
360
|
+
:disabled="isFieldDisabled(field)"
|
|
361
|
+
:invalid="isFieldInvalid(field)"
|
|
362
|
+
@blur="validateField(field)"
|
|
363
|
+
>
|
|
364
|
+
<CommandGroup>
|
|
365
|
+
<CommandItem
|
|
366
|
+
v-for="option in $dsl.evaluate`${field.options}`()"
|
|
367
|
+
:key="$dsl.evaluate`${field.key}`({ option })"
|
|
368
|
+
:value="$dsl.evaluate`${field.key}`({ option })"
|
|
369
|
+
@select="setProperty(modelValue, field.path, $dsl.evaluate`${field.value}`({ option }))"
|
|
370
|
+
>
|
|
371
|
+
{{ $dsl.evaluate`${field.label}`({ option }) }}
|
|
372
|
+
</CommandItem>
|
|
373
|
+
</CommandGroup>
|
|
374
|
+
</InputGroupCombobox>
|
|
375
|
+
<InputGroupAddon v-if="field.icon">
|
|
376
|
+
<Icon
|
|
377
|
+
:icon="field.icon"
|
|
378
|
+
/>
|
|
379
|
+
</InputGroupAddon>
|
|
380
|
+
<InputGroupAddon
|
|
381
|
+
v-if="hasProperty(modelValue, field.path)"
|
|
382
|
+
align="inline-end"
|
|
383
|
+
:class="orientation === 'floating' ? 'group-data-[disabled=true]/input-group:hidden' : void 0"
|
|
384
|
+
>
|
|
385
|
+
<Tooltip :delay-duration="800">
|
|
386
|
+
<TooltipTrigger>
|
|
387
|
+
<InputGroupButton as-child>
|
|
388
|
+
<button
|
|
389
|
+
type="button"
|
|
390
|
+
class="text-zinc-300 hover:text-zinc-500 transition-colors"
|
|
391
|
+
:disabled="isFieldDisabled(field)"
|
|
392
|
+
@click="deleteProperty(modelValue, field.path)"
|
|
393
|
+
>
|
|
394
|
+
<Icon
|
|
395
|
+
icon="fluent:dismiss-20-regular"
|
|
396
|
+
/>
|
|
397
|
+
</button>
|
|
398
|
+
</InputGroupButton>
|
|
399
|
+
</TooltipTrigger>
|
|
400
|
+
<TooltipContent>
|
|
401
|
+
{{ t("clear") }}
|
|
402
|
+
</TooltipContent>
|
|
403
|
+
</Tooltip>
|
|
404
|
+
</InputGroupAddon>
|
|
405
|
+
<InputGroupAddon
|
|
406
|
+
v-if="field.type === 'string' && field.maxLength && getProperty(modelValue, field.path)"
|
|
407
|
+
align="inline-end"
|
|
408
|
+
>
|
|
409
|
+
<span class="text-xs text-zinc-400 font-mono">
|
|
410
|
+
<span class="inline-block text-right">{{ String(getProperty(modelValue, field.path) ?? "").length }}</span>/{{ field.maxLength }}
|
|
411
|
+
</span>
|
|
412
|
+
</InputGroupAddon>
|
|
413
|
+
</InputGroup>
|
|
414
|
+
|
|
415
|
+
<FieldError v-if="isFieldInvalid(field)">
|
|
416
|
+
<span v-html="renderValidationMessage(field)" />
|
|
417
|
+
</FieldError>
|
|
418
|
+
</FieldContent>
|
|
419
|
+
</Field>
|
|
420
|
+
</template>
|
|
421
|
+
|
|
422
|
+
<slot />
|
|
423
|
+
</div>
|
|
424
|
+
</template>
|
|
425
|
+
|
|
426
|
+
<i18n lang="json">
|
|
427
|
+
{
|
|
428
|
+
"zh": {
|
|
429
|
+
"clear": "清空",
|
|
430
|
+
"select-placeholder": "选择…"
|
|
431
|
+
},
|
|
432
|
+
"ja": {
|
|
433
|
+
"clear": "クリア",
|
|
434
|
+
"select-placeholder": "選択…"
|
|
435
|
+
},
|
|
436
|
+
"en": {
|
|
437
|
+
"clear": "Clear",
|
|
438
|
+
"select-placeholder": "Select…"
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
</i18n>
|