@shwfed/nuxt 0.8.3 → 0.9.1

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.
@@ -1,175 +1,327 @@
1
1
  import { Effect } from 'effect';
2
- import z from 'zod';
3
- import { FieldC } from './schema.js';
4
- export { CalendarFieldC, FieldC, NumberFieldC, SelectFieldC, StringFieldC, ValidationRuleC, validationC, } from './schema.js';
5
- export type { Field, ValidationRule } from './schema.js';
2
+ export { CalendarFieldC, FieldC, FieldsConfigC, NumberFieldC, SelectFieldC, StringFieldC, ValidationRuleC, validationC, } from './schema.js';
3
+ export type { Field, FieldsConfig, ValidationRule } from './schema.js';
6
4
  declare const _default: typeof __VLS_export;
7
5
  export default _default;
8
6
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
9
- orientation?: "horizontal" | "vertical" | "floating";
10
- fields: Effect.Effect<ReadonlyArray<z.infer<typeof FieldC>>>;
7
+ config: Effect.Effect<Readonly<{
8
+ fields: readonly ({
9
+ type: "string";
10
+ path: string;
11
+ title: readonly {
12
+ locale: "zh" | "ja" | "en" | "ko";
13
+ message: string;
14
+ }[];
15
+ icon?: string | undefined;
16
+ style?: string | undefined;
17
+ discardEmptyString?: boolean | undefined;
18
+ maxLength?: string | undefined;
19
+ hidden?: string | undefined;
20
+ disabled?: string | undefined;
21
+ validation?: readonly Readonly<{
22
+ expression: string;
23
+ message: string;
24
+ }>[] | undefined;
25
+ } | {
26
+ type: "number";
27
+ path: string;
28
+ title: readonly {
29
+ locale: "zh" | "ja" | "en" | "ko";
30
+ message: string;
31
+ }[];
32
+ icon?: string | undefined;
33
+ style?: string | undefined;
34
+ min?: string | undefined;
35
+ max?: string | undefined;
36
+ step?: string | undefined;
37
+ hidden?: string | undefined;
38
+ disabled?: string | undefined;
39
+ validation?: readonly Readonly<{
40
+ expression: string;
41
+ message: string;
42
+ }>[] | undefined;
43
+ } | {
44
+ type: "select";
45
+ path: string;
46
+ title: readonly {
47
+ locale: "zh" | "ja" | "en" | "ko";
48
+ message: string;
49
+ }[];
50
+ options: string;
51
+ label: string;
52
+ value: string;
53
+ key: string;
54
+ icon?: string | undefined;
55
+ style?: string | undefined;
56
+ hidden?: string | undefined;
57
+ disabled?: string | undefined;
58
+ validation?: readonly Readonly<{
59
+ expression: string;
60
+ message: string;
61
+ }>[] | undefined;
62
+ } | {
63
+ type: "calendar";
64
+ path: string;
65
+ title: readonly {
66
+ locale: "zh" | "ja" | "en" | "ko";
67
+ message: string;
68
+ }[];
69
+ mode: "date" | "month" | "year";
70
+ value: string;
71
+ icon?: string | undefined;
72
+ style?: string | undefined;
73
+ display?: string | undefined;
74
+ disableDate?: string | undefined;
75
+ hidden?: string | undefined;
76
+ disabled?: string | undefined;
77
+ validation?: readonly Readonly<{
78
+ expression: string;
79
+ message: string;
80
+ }>[] | undefined;
81
+ })[];
82
+ orientation?: "vertical" | "horizontal" | "floating" | undefined;
83
+ }> | undefined>;
11
84
  } & {
12
85
  modelValue?: Record<string, unknown>;
13
86
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
14
87
  "update:modelValue": (value: Record<string, unknown>) => any;
15
- "update:fields": (args_0: readonly ({
16
- type: "string";
17
- path: string;
18
- title: readonly {
19
- locale: "zh" | "ja" | "en" | "ko";
20
- message: string;
21
- }[];
22
- icon?: string | undefined;
23
- style?: string | undefined;
24
- discardEmptyString?: boolean | undefined;
25
- maxLength?: string | undefined;
26
- hidden?: string | undefined;
27
- disabled?: string | undefined;
28
- validation?: readonly Readonly<{
29
- expression: string;
30
- message: string;
31
- }>[] | undefined;
32
- } | {
33
- type: "number";
34
- path: string;
35
- title: readonly {
36
- locale: "zh" | "ja" | "en" | "ko";
37
- message: string;
38
- }[];
39
- icon?: string | undefined;
40
- style?: string | undefined;
41
- min?: string | undefined;
42
- max?: string | undefined;
43
- step?: string | undefined;
44
- hidden?: string | undefined;
45
- disabled?: string | undefined;
46
- validation?: readonly Readonly<{
47
- expression: string;
48
- message: string;
49
- }>[] | undefined;
50
- } | {
51
- type: "select";
52
- path: string;
53
- title: readonly {
54
- locale: "zh" | "ja" | "en" | "ko";
55
- message: string;
56
- }[];
57
- options: string;
58
- label: string;
59
- value: string;
60
- key: string;
61
- icon?: string | undefined;
62
- style?: string | undefined;
63
- hidden?: string | undefined;
64
- disabled?: string | undefined;
65
- validation?: readonly Readonly<{
66
- expression: string;
67
- message: string;
68
- }>[] | undefined;
69
- } | {
70
- type: "calendar";
71
- path: string;
72
- title: readonly {
73
- locale: "zh" | "ja" | "en" | "ko";
74
- message: string;
75
- }[];
76
- mode: "date" | "month" | "year";
77
- value: string;
78
- icon?: string | undefined;
79
- style?: string | undefined;
80
- display?: string | undefined;
81
- disableDate?: string | undefined;
82
- hidden?: string | undefined;
83
- disabled?: string | undefined;
84
- validation?: readonly Readonly<{
85
- expression: string;
86
- message: string;
87
- }>[] | undefined;
88
- })[]) => any;
88
+ "update:config": (args_0: Readonly<{
89
+ fields: readonly ({
90
+ type: "string";
91
+ path: string;
92
+ title: readonly {
93
+ locale: "zh" | "ja" | "en" | "ko";
94
+ message: string;
95
+ }[];
96
+ icon?: string | undefined;
97
+ style?: string | undefined;
98
+ discardEmptyString?: boolean | undefined;
99
+ maxLength?: string | undefined;
100
+ hidden?: string | undefined;
101
+ disabled?: string | undefined;
102
+ validation?: readonly Readonly<{
103
+ expression: string;
104
+ message: string;
105
+ }>[] | undefined;
106
+ } | {
107
+ type: "number";
108
+ path: string;
109
+ title: readonly {
110
+ locale: "zh" | "ja" | "en" | "ko";
111
+ message: string;
112
+ }[];
113
+ icon?: string | undefined;
114
+ style?: string | undefined;
115
+ min?: string | undefined;
116
+ max?: string | undefined;
117
+ step?: string | undefined;
118
+ hidden?: string | undefined;
119
+ disabled?: string | undefined;
120
+ validation?: readonly Readonly<{
121
+ expression: string;
122
+ message: string;
123
+ }>[] | undefined;
124
+ } | {
125
+ type: "select";
126
+ path: string;
127
+ title: readonly {
128
+ locale: "zh" | "ja" | "en" | "ko";
129
+ message: string;
130
+ }[];
131
+ options: string;
132
+ label: string;
133
+ value: string;
134
+ key: string;
135
+ icon?: string | undefined;
136
+ style?: string | undefined;
137
+ hidden?: string | undefined;
138
+ disabled?: string | undefined;
139
+ validation?: readonly Readonly<{
140
+ expression: string;
141
+ message: string;
142
+ }>[] | undefined;
143
+ } | {
144
+ type: "calendar";
145
+ path: string;
146
+ title: readonly {
147
+ locale: "zh" | "ja" | "en" | "ko";
148
+ message: string;
149
+ }[];
150
+ mode: "date" | "month" | "year";
151
+ value: string;
152
+ icon?: string | undefined;
153
+ style?: string | undefined;
154
+ display?: string | undefined;
155
+ disableDate?: string | undefined;
156
+ hidden?: string | undefined;
157
+ disabled?: string | undefined;
158
+ validation?: readonly Readonly<{
159
+ expression: string;
160
+ message: string;
161
+ }>[] | undefined;
162
+ })[];
163
+ orientation?: "vertical" | "horizontal" | "floating" | undefined;
164
+ }>) => any;
89
165
  }, string, import("vue").PublicProps, Readonly<{
90
- orientation?: "horizontal" | "vertical" | "floating";
91
- fields: Effect.Effect<ReadonlyArray<z.infer<typeof FieldC>>>;
166
+ config: Effect.Effect<Readonly<{
167
+ fields: readonly ({
168
+ type: "string";
169
+ path: string;
170
+ title: readonly {
171
+ locale: "zh" | "ja" | "en" | "ko";
172
+ message: string;
173
+ }[];
174
+ icon?: string | undefined;
175
+ style?: string | undefined;
176
+ discardEmptyString?: boolean | undefined;
177
+ maxLength?: string | undefined;
178
+ hidden?: string | undefined;
179
+ disabled?: string | undefined;
180
+ validation?: readonly Readonly<{
181
+ expression: string;
182
+ message: string;
183
+ }>[] | undefined;
184
+ } | {
185
+ type: "number";
186
+ path: string;
187
+ title: readonly {
188
+ locale: "zh" | "ja" | "en" | "ko";
189
+ message: string;
190
+ }[];
191
+ icon?: string | undefined;
192
+ style?: string | undefined;
193
+ min?: string | undefined;
194
+ max?: string | undefined;
195
+ step?: string | undefined;
196
+ hidden?: string | undefined;
197
+ disabled?: string | undefined;
198
+ validation?: readonly Readonly<{
199
+ expression: string;
200
+ message: string;
201
+ }>[] | undefined;
202
+ } | {
203
+ type: "select";
204
+ path: string;
205
+ title: readonly {
206
+ locale: "zh" | "ja" | "en" | "ko";
207
+ message: string;
208
+ }[];
209
+ options: string;
210
+ label: string;
211
+ value: string;
212
+ key: string;
213
+ icon?: string | undefined;
214
+ style?: string | undefined;
215
+ hidden?: string | undefined;
216
+ disabled?: string | undefined;
217
+ validation?: readonly Readonly<{
218
+ expression: string;
219
+ message: string;
220
+ }>[] | undefined;
221
+ } | {
222
+ type: "calendar";
223
+ path: string;
224
+ title: readonly {
225
+ locale: "zh" | "ja" | "en" | "ko";
226
+ message: string;
227
+ }[];
228
+ mode: "date" | "month" | "year";
229
+ value: string;
230
+ icon?: string | undefined;
231
+ style?: string | undefined;
232
+ display?: string | undefined;
233
+ disableDate?: string | undefined;
234
+ hidden?: string | undefined;
235
+ disabled?: string | undefined;
236
+ validation?: readonly Readonly<{
237
+ expression: string;
238
+ message: string;
239
+ }>[] | undefined;
240
+ })[];
241
+ orientation?: "vertical" | "horizontal" | "floating" | undefined;
242
+ }> | undefined>;
92
243
  } & {
93
244
  modelValue?: Record<string, unknown>;
94
245
  }> & Readonly<{
95
246
  "onUpdate:modelValue"?: ((value: Record<string, unknown>) => any) | undefined;
96
- "onUpdate:fields"?: ((args_0: readonly ({
97
- type: "string";
98
- path: string;
99
- title: readonly {
100
- locale: "zh" | "ja" | "en" | "ko";
101
- message: string;
102
- }[];
103
- icon?: string | undefined;
104
- style?: string | undefined;
105
- discardEmptyString?: boolean | undefined;
106
- maxLength?: string | undefined;
107
- hidden?: string | undefined;
108
- disabled?: string | undefined;
109
- validation?: readonly Readonly<{
110
- expression: string;
111
- message: string;
112
- }>[] | undefined;
113
- } | {
114
- type: "number";
115
- path: string;
116
- title: readonly {
117
- locale: "zh" | "ja" | "en" | "ko";
118
- message: string;
119
- }[];
120
- icon?: string | undefined;
121
- style?: string | undefined;
122
- min?: string | undefined;
123
- max?: string | undefined;
124
- step?: string | undefined;
125
- hidden?: string | undefined;
126
- disabled?: string | undefined;
127
- validation?: readonly Readonly<{
128
- expression: string;
129
- message: string;
130
- }>[] | undefined;
131
- } | {
132
- type: "select";
133
- path: string;
134
- title: readonly {
135
- locale: "zh" | "ja" | "en" | "ko";
136
- message: string;
137
- }[];
138
- options: string;
139
- label: string;
140
- value: string;
141
- key: string;
142
- icon?: string | undefined;
143
- style?: string | undefined;
144
- hidden?: string | undefined;
145
- disabled?: string | undefined;
146
- validation?: readonly Readonly<{
147
- expression: string;
148
- message: string;
149
- }>[] | undefined;
150
- } | {
151
- type: "calendar";
152
- path: string;
153
- title: readonly {
154
- locale: "zh" | "ja" | "en" | "ko";
155
- message: string;
156
- }[];
157
- mode: "date" | "month" | "year";
158
- value: string;
159
- icon?: string | undefined;
160
- style?: string | undefined;
161
- display?: string | undefined;
162
- disableDate?: string | undefined;
163
- hidden?: string | undefined;
164
- disabled?: string | undefined;
165
- validation?: readonly Readonly<{
166
- expression: string;
167
- message: string;
168
- }>[] | undefined;
169
- })[]) => any) | undefined;
170
- }>, {
171
- orientation: "horizontal" | "vertical" | "floating";
172
- }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
247
+ "onUpdate:config"?: ((args_0: Readonly<{
248
+ fields: readonly ({
249
+ type: "string";
250
+ path: string;
251
+ title: readonly {
252
+ locale: "zh" | "ja" | "en" | "ko";
253
+ message: string;
254
+ }[];
255
+ icon?: string | undefined;
256
+ style?: string | undefined;
257
+ discardEmptyString?: boolean | undefined;
258
+ maxLength?: string | undefined;
259
+ hidden?: string | undefined;
260
+ disabled?: string | undefined;
261
+ validation?: readonly Readonly<{
262
+ expression: string;
263
+ message: string;
264
+ }>[] | undefined;
265
+ } | {
266
+ type: "number";
267
+ path: string;
268
+ title: readonly {
269
+ locale: "zh" | "ja" | "en" | "ko";
270
+ message: string;
271
+ }[];
272
+ icon?: string | undefined;
273
+ style?: string | undefined;
274
+ min?: string | undefined;
275
+ max?: string | undefined;
276
+ step?: string | undefined;
277
+ hidden?: string | undefined;
278
+ disabled?: string | undefined;
279
+ validation?: readonly Readonly<{
280
+ expression: string;
281
+ message: string;
282
+ }>[] | undefined;
283
+ } | {
284
+ type: "select";
285
+ path: string;
286
+ title: readonly {
287
+ locale: "zh" | "ja" | "en" | "ko";
288
+ message: string;
289
+ }[];
290
+ options: string;
291
+ label: string;
292
+ value: string;
293
+ key: string;
294
+ icon?: string | undefined;
295
+ style?: string | undefined;
296
+ hidden?: string | undefined;
297
+ disabled?: string | undefined;
298
+ validation?: readonly Readonly<{
299
+ expression: string;
300
+ message: string;
301
+ }>[] | undefined;
302
+ } | {
303
+ type: "calendar";
304
+ path: string;
305
+ title: readonly {
306
+ locale: "zh" | "ja" | "en" | "ko";
307
+ message: string;
308
+ }[];
309
+ mode: "date" | "month" | "year";
310
+ value: string;
311
+ icon?: string | undefined;
312
+ style?: string | undefined;
313
+ display?: string | undefined;
314
+ disableDate?: string | undefined;
315
+ hidden?: string | undefined;
316
+ disabled?: string | undefined;
317
+ validation?: readonly Readonly<{
318
+ expression: string;
319
+ message: string;
320
+ }>[] | undefined;
321
+ })[];
322
+ orientation?: "vertical" | "horizontal" | "floating" | undefined;
323
+ }>) => any) | undefined;
324
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
173
325
  default?: (props: {}) => any;
174
326
  }>;
175
327
  type __VLS_WithSlots<T, S> = T & {
@@ -9,7 +9,6 @@ import { format, parse } from "date-fns";
9
9
  import { deleteProperty, getProperty, hasProperty, setProperty } from "dot-prop";
10
10
  import { ref, toRaw, useId, watch, watchEffect } from "vue";
11
11
  import { useI18n } from "vue-i18n";
12
- import z from "zod";
13
12
  import { useCheating } from "#imports";
14
13
  import { Calendar } from "../calendar";
15
14
  import { Button } from "../button";
@@ -21,14 +20,16 @@ import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../popov
21
20
  import { Skeleton } from "../skeleton";
22
21
  import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip";
23
22
  import { getLocalizedText } from "../../../utils/coders";
24
- import { FieldC } from "./schema";
23
+ import { FieldsConfigC } from "./schema";
25
24
  const id = useId();
25
+ const defaultConfig = {
26
+ fields: []
27
+ };
26
28
  const props = defineProps({
27
- orientation: { type: String, required: false, default: "horizontal" },
28
- fields: { type: null, required: true }
29
+ config: { type: null, required: true }
29
30
  });
30
- const emit = defineEmits(["update:fields"]);
31
- const fields = computedAsync(async () => z.array(FieldC).readonly().parse(await props.fields.pipe(Effect.runPromise)));
31
+ const emit = defineEmits(["update:config"]);
32
+ const config = computedAsync(async () => FieldsConfigC.parse(await props.config.pipe(Effect.runPromise) ?? defaultConfig));
32
33
  const { t, locale } = useI18n();
33
34
  const { $dsl, $md } = useNuxtApp();
34
35
  const modelValue = defineModel("modelValue", { type: Object, ...{
@@ -36,9 +37,23 @@ const modelValue = defineModel("modelValue", { type: Object, ...{
36
37
  } });
37
38
  const isCheating = useCheating();
38
39
  const isConfiguratorOpen = ref(false);
39
- const displayFields = ref([]);
40
+ const displayConfig = ref(defaultConfig);
40
41
  const validationErrors = ref({});
41
42
  const calendarOpen = ref({});
43
+ function cloneConfig(config2) {
44
+ if (config2.orientation) {
45
+ return {
46
+ orientation: config2.orientation,
47
+ fields: config2.fields.slice()
48
+ };
49
+ }
50
+ return {
51
+ fields: config2.fields.slice()
52
+ };
53
+ }
54
+ function getConfigOrientation(config2) {
55
+ return config2.orientation ?? "horizontal";
56
+ }
42
57
  function toCalendarDateValue(value, valueFormat) {
43
58
  if (typeof value !== "string") return void 0;
44
59
  const date = parse(value, valueFormat, /* @__PURE__ */ new Date());
@@ -117,16 +132,19 @@ function handleCalendarBlur(field) {
117
132
  }
118
133
  }, 0);
119
134
  }
120
- function handleConfiguratorConfirm(nextFields) {
121
- displayFields.value = nextFields.slice();
122
- emit("update:fields", nextFields);
135
+ function handleConfiguratorConfirm(nextConfig) {
136
+ displayConfig.value = cloneConfig(nextConfig);
137
+ emit("update:config", nextConfig);
123
138
  }
124
- watch(fields, (value) => {
125
- displayFields.value = (value ?? []).slice();
139
+ watch(config, (value) => {
140
+ if (!value) {
141
+ return;
142
+ }
143
+ displayConfig.value = cloneConfig(value);
126
144
  }, { immediate: true });
127
145
  watchEffect(() => {
128
146
  const activePaths = /* @__PURE__ */ new Set();
129
- for (const field of displayFields.value) {
147
+ for (const field of displayConfig.value.fields) {
130
148
  if (!isFieldHidden(field) && !isFieldDisabled(field)) {
131
149
  activePaths.add(field.path);
132
150
  }
@@ -148,6 +166,7 @@ watchEffect(() => {
148
166
  export {
149
167
  CalendarFieldC,
150
168
  FieldC,
169
+ FieldsConfigC,
151
170
  NumberFieldC,
152
171
  SelectFieldC,
153
172
  StringFieldC,
@@ -176,26 +195,26 @@ export {
176
195
  </Button>
177
196
 
178
197
  <FieldsConfiguratorDialog
179
- v-if="fields"
198
+ v-if="config"
180
199
  v-model:open="isConfiguratorOpen"
181
- :fields="displayFields"
200
+ :config="displayConfig"
182
201
  @confirm="handleConfiguratorConfirm"
183
202
  />
184
203
 
185
204
  <Skeleton
186
- v-if="fields === void 0"
205
+ v-if="config === void 0"
187
206
  class="absolute inset-0 z-10 w-full h-full"
188
207
  />
189
208
 
190
209
  <template
191
- v-for="field in displayFields"
210
+ v-for="field in displayConfig.fields"
192
211
  :key="field.path"
193
212
  >
194
213
  <Field
195
214
  v-if="!isFieldHidden(field)"
196
215
  :data-disabled="isFieldDisabled(field) ? 'true' : void 0"
197
216
  :data-invalid="isFieldInvalid(field) ? 'true' : void 0"
198
- :orientation="orientation"
217
+ :orientation="getConfigOrientation(displayConfig)"
199
218
  :style="field.style ? $dsl.evaluate`${field.style}`() : {}"
200
219
  >
201
220
  <FieldLabel :for="['string', 'number'].includes(field.type) ? `${id}:${field.path}` : void 0">
@@ -229,7 +248,7 @@ export {
229
248
  <InputGroupAddon
230
249
  v-if="hasProperty(modelValue, field.path)"
231
250
  align="inline-end"
232
- :class="orientation === 'floating' ? 'group-data-[disabled=true]/input-group:hidden' : void 0"
251
+ :class="getConfigOrientation(displayConfig) === 'floating' ? 'group-data-[disabled=true]/input-group:hidden' : void 0"
233
252
  >
234
253
  <Tooltip :delay-duration="800">
235
254
  <TooltipTrigger>
@@ -334,7 +353,7 @@ export {
334
353
  <InputGroupAddon
335
354
  v-if="hasProperty(modelValue, field.path)"
336
355
  align="inline-end"
337
- :class="orientation === 'floating' ? 'group-data-[disabled=true]/input-group:hidden' : void 0"
356
+ :class="getConfigOrientation(displayConfig) === 'floating' ? 'group-data-[disabled=true]/input-group:hidden' : void 0"
338
357
  >
339
358
  <Tooltip :delay-duration="800">
340
359
  <TooltipTrigger>