@sfxcode/nuxt-ui-formkit 1.2.0 → 1.2.2

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 (47) hide show
  1. package/README.md +25 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +1 -1
  4. package/dist/runtime/components/FUAutoForm.d.vue.ts +65 -0
  5. package/dist/runtime/components/FUAutoForm.vue +59 -0
  6. package/dist/runtime/components/FUAutoForm.vue.d.ts +65 -0
  7. package/dist/runtime/components/FUDataEdit.d.vue.ts +1 -1
  8. package/dist/runtime/components/FUDataEdit.vue.d.ts +1 -1
  9. package/dist/runtime/components/FUDataView.d.vue.ts +1 -1
  10. package/dist/runtime/components/FUDataView.vue.d.ts +1 -1
  11. package/dist/runtime/components/inputs/FUCalendar.d.vue.ts +15 -5
  12. package/dist/runtime/components/inputs/FUCalendar.vue +16 -4
  13. package/dist/runtime/components/inputs/FUCalendar.vue.d.ts +15 -5
  14. package/dist/runtime/components/inputs/FUInputDate.d.vue.ts +18 -5
  15. package/dist/runtime/components/inputs/FUInputDate.vue +24 -6
  16. package/dist/runtime/components/inputs/FUInputDate.vue.d.ts +18 -5
  17. package/dist/runtime/composables/useFormKitAutoForm.d.ts +38 -0
  18. package/dist/runtime/composables/useFormKitAutoForm.js +349 -0
  19. package/dist/runtime/composables/useFormKitForm.d.ts +11 -0
  20. package/dist/runtime/composables/useFormKitForm.js +38 -0
  21. package/dist/runtime/composables/useFormKitMultiStep.d.ts +5 -0
  22. package/dist/runtime/composables/useFormKitMultiStep.js +65 -0
  23. package/dist/runtime/composables/useFormKitRepeater.d.ts +4 -0
  24. package/dist/runtime/composables/useFormKitRepeater.js +138 -0
  25. package/dist/runtime/formkit/createNuxtUiFormkitConfig.d.ts +19 -0
  26. package/dist/runtime/formkit/createNuxtUiFormkitConfig.js +12 -0
  27. package/dist/runtime/formkit/createNuxtUiFormkitConfig.mjs +12 -0
  28. package/dist/runtime/formkit/definitions/index.d.ts +3 -0
  29. package/dist/runtime/formkit/definitions/index.js +4 -0
  30. package/dist/runtime/formkit/definitions/index.mjs +4 -0
  31. package/dist/runtime/formkit/definitions/input.js +2 -2
  32. package/dist/runtime/formkit/definitions/input.mjs +2 -2
  33. package/dist/runtime/formkit/definitions/multiStep.d.ts +3 -0
  34. package/dist/runtime/formkit/definitions/multiStep.js +90 -0
  35. package/dist/runtime/formkit/definitions/multiStep.mjs +90 -0
  36. package/dist/runtime/formkit/definitions/repeater.js +3 -119
  37. package/dist/runtime/formkit/definitions/repeater.mjs +3 -119
  38. package/dist/runtime/formkit/index.d.ts +10 -0
  39. package/dist/runtime/formkit/index.js +1 -0
  40. package/dist/runtime/formkit/index.mjs +1 -0
  41. package/dist/runtime/formkit/plugins/index.d.ts +1 -0
  42. package/dist/runtime/formkit/plugins/index.js +1 -0
  43. package/dist/runtime/formkit/plugins/index.mjs +1 -0
  44. package/dist/runtime/plugin.js +2 -1
  45. package/dist/runtime/utils/dateValueConversion.d.ts +36 -0
  46. package/dist/runtime/utils/dateValueConversion.js +80 -0
  47. package/package.json +6 -3
package/README.md CHANGED
@@ -43,6 +43,10 @@ FormKit Nuxt UI bridges the gap between [FormKit](https://formkit.com/)'s powerf
43
43
  🔁 **Repeater Component** - Dynamic repeatable form sections
44
44
  - `nuxtUIRepeater` - Create dynamic lists with add, remove, clone, and reorder functionality
45
45
 
46
+ 🧭 **Multi-Step Forms** - Wizard-style forms with tab navigation and validation gating
47
+ - `nuxtUIMultiStep` - Tab-strip wizard container built on `@formkit/addons`' `createMultiStepPlugin`
48
+ - `nuxtUIStep` - A single step's content, with Nuxt UI-styled previous/next actions
49
+
46
50
  📊 **6 Output Components** - Display-only components for read-only data
47
51
  - `nuxtUIOutputBoolean` - Boolean display with custom icons
48
52
  - `nuxtUIOutputDate` - Formatted date/time display
@@ -55,11 +59,19 @@ FormKit Nuxt UI bridges the gap between [FormKit](https://formkit.com/)'s powerf
55
59
  - `FUDataEdit` - Edit forms with schema-based configuration
56
60
  - `FUDataView` - Read-only data display with schema support
57
61
  - `FUDataDebug` - Development tool for form debugging
62
+ - `FUAutoForm` - Schema-free forms: inputs inferred from your data's value shapes, or a Valibot/Zod schema, with an override map for fine-tuning
63
+
64
+ ⚙️ **Config Helper** - One-line `formkit.config.ts` setup
65
+ - `createNuxtUiFormkitConfig` - Assembles all `nuxtUIXxx` inputs/outputs and this module's plugins into `{ inputs, plugins }` you spread into your own config
58
66
 
59
67
  🔧 **Composables & Utilities** - Reusable form logic
60
68
  - `useFormKitSchema` - Schema-based form generation with element builders
61
69
  - `useFormKitInput` - Input component utilities and prop handling
62
70
  - `useFormKitOutput` - Output component utilities and prop handling
71
+ - `useFormKitRepeater` - Repeater insert/remove/clone/move/drag handlers
72
+ - `useFormKitMultiStep` - Multi-step tab-item mapping and navigation bridging
73
+ - `useFormKitForm` - Submit/reset/error-management wrapper for a form's imperative APIs, callable from outside the form
74
+ - `useFormKitAutoForm` - Schema inference from data value shapes, Valibot, or Zod schemas (`inferFormSchema`/`inferFormSchemaFromValibot`/`inferFormSchemaFromZod`)
63
75
  - `colorConverter` - Color format conversion utilities
64
76
  - `durationConverter` - Duration format conversion utilities
65
77
 
@@ -288,9 +300,12 @@ Refer to the [Nuxt UI documentation](https://ui.nuxt.com/) for component-specifi
288
300
  The playground includes comprehensive examples for all components:
289
301
 
290
302
  ### Input Components
303
+ - [Calendar](./playground/app/pages/components/input/calendar.vue)
291
304
  - [Checkbox](./playground/app/pages/components/input/checkbox.vue)
292
305
  - [CheckboxGroup](./playground/app/pages/components/input/checkbox-group.vue)
293
306
  - [ColorPicker](./playground/app/pages/components/input/color-picker.vue)
307
+ - [Editor](./playground/app/pages/components/input/editor.vue)
308
+ - [FileUpload](./playground/app/pages/components/input/file-upload.vue)
294
309
  - [Input](./playground/app/pages/components/input/input.vue)
295
310
  - [InputDate](./playground/app/pages/components/input/input-date.vue)
296
311
  - [InputMenu](./playground/app/pages/components/input/input-menu.vue)
@@ -314,6 +329,16 @@ The playground includes comprehensive examples for all components:
314
329
  - [OutputNumber](./playground/app/pages/components/output/number.vue)
315
330
  - [OutputText](./playground/app/pages/components/output/text.vue)
316
331
 
332
+ ### Repeater
333
+ - [Repeater](./playground/app/pages/form/repeater-sample.vue)
334
+ - [Drag-and-Drop Repeater](./playground/app/pages/form/repeater-drag.vue)
335
+
336
+ ### Multi-Step
337
+ - [Multi-Step Form](./playground/app/pages/form/multi-step.vue)
338
+
339
+ ### Form Composable
340
+ - [useFormKitForm](./playground/app/pages/form/form-composable.vue)
341
+
317
342
  ## Development
318
343
 
319
344
  <details>
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "1.2.0",
7
+ "version": "1.2.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -15,7 +15,7 @@ const module$1 = defineNuxtModule({
15
15
  addPlugin(resolver.resolve("./runtime/plugin"));
16
16
  addImportsDir(resolver.resolve("./runtime/composables"));
17
17
  const NPM_PCK_FORMKIT_NUXT_UI = "@sfxcode/nuxt-ui-formkit";
18
- const componentNames = ["FUDataView", "FUDataEdit", "FUDataDebug"];
18
+ const componentNames = ["FUDataView", "FUDataEdit", "FUDataDebug", "FUAutoForm"];
19
19
  componentNames.forEach(
20
20
  (name) => addComponent({
21
21
  name,
@@ -0,0 +1,65 @@
1
+ import type { FormKitSchemaDefinition } from '@formkit/core';
2
+ import type { PropType } from 'vue';
3
+ import type { AutoFormOverrides, ValibotLikeSchema, ZodLikeSchema } from '../composables/useFormKitAutoForm.js';
4
+ declare var __VLS_10: string, __VLS_11: any;
5
+ type __VLS_Slots = {} & {
6
+ [K in NonNullable<typeof __VLS_10>]?: (props: typeof __VLS_11) => any;
7
+ };
8
+ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
9
+ data: {
10
+ type: ObjectConstructor;
11
+ default: null;
12
+ };
13
+ overrides: {
14
+ type: PropType<AutoFormOverrides>;
15
+ default: undefined;
16
+ };
17
+ valibotSchema: {
18
+ type: PropType<ValibotLikeSchema>;
19
+ default: undefined;
20
+ };
21
+ zodSchema: {
22
+ type: PropType<ZodLikeSchema>;
23
+ default: undefined;
24
+ };
25
+ modelValue: {
26
+ type: PropType<FormKitSchemaDefinition>;
27
+ };
28
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
29
+ "update:modelValue": (value: FormKitSchemaDefinition | undefined) => any;
30
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
31
+ data: {
32
+ type: ObjectConstructor;
33
+ default: null;
34
+ };
35
+ overrides: {
36
+ type: PropType<AutoFormOverrides>;
37
+ default: undefined;
38
+ };
39
+ valibotSchema: {
40
+ type: PropType<ValibotLikeSchema>;
41
+ default: undefined;
42
+ };
43
+ zodSchema: {
44
+ type: PropType<ZodLikeSchema>;
45
+ default: undefined;
46
+ };
47
+ modelValue: {
48
+ type: PropType<FormKitSchemaDefinition>;
49
+ };
50
+ }>> & Readonly<{
51
+ "onUpdate:modelValue"?: ((value: FormKitSchemaDefinition | undefined) => any) | undefined;
52
+ }>, {
53
+ data: Record<string, any>;
54
+ overrides: AutoFormOverrides;
55
+ valibotSchema: ValibotLikeSchema;
56
+ zodSchema: ZodLikeSchema;
57
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
58
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
59
+ declare const _default: typeof __VLS_export;
60
+ export default _default;
61
+ type __VLS_WithSlots<T, S> = T & {
62
+ new (): {
63
+ $slots: S;
64
+ };
65
+ };
@@ -0,0 +1,59 @@
1
+ <script setup>
2
+ import { ref, watch } from "vue";
3
+ import { inferFormSchema, inferFormSchemaFromValibot, inferFormSchemaFromZod } from "../composables/useFormKitAutoForm";
4
+ import FUDataEdit from "./FUDataEdit.vue";
5
+ defineOptions({ inheritAttrs: false });
6
+ const props = defineProps({
7
+ data: {
8
+ type: Object,
9
+ default: null
10
+ },
11
+ overrides: {
12
+ type: Object,
13
+ default: void 0
14
+ },
15
+ valibotSchema: {
16
+ type: Object,
17
+ default: void 0
18
+ },
19
+ zodSchema: {
20
+ type: Object,
21
+ default: void 0
22
+ }
23
+ });
24
+ const formData = defineModel({ type: [Object, String, Array] });
25
+ if (!formData.value && props.data) {
26
+ formData.value = props.data;
27
+ }
28
+ function buildSchema(data) {
29
+ if (props.valibotSchema) {
30
+ return inferFormSchemaFromValibot(props.valibotSchema, props.overrides);
31
+ }
32
+ if (props.zodSchema) {
33
+ return inferFormSchemaFromZod(props.zodSchema, props.overrides);
34
+ }
35
+ return inferFormSchema(data ?? formData.value ?? {}, props.overrides);
36
+ }
37
+ const formSchema = ref(buildSchema(props.data));
38
+ watch([() => props.data, () => props.overrides, () => props.valibotSchema, () => props.zodSchema], ([data]) => {
39
+ formSchema.value = buildSchema(data);
40
+ });
41
+ </script>
42
+
43
+ <template>
44
+ <FUDataEdit
45
+ v-bind="$attrs"
46
+ v-model="formData"
47
+ :schema="formSchema"
48
+ >
49
+ <template
50
+ v-for="(_, name) in $slots"
51
+ #[name]="slotProps"
52
+ >
53
+ <slot
54
+ :name="name"
55
+ v-bind="slotProps ?? {}"
56
+ />
57
+ </template>
58
+ </FUDataEdit>
59
+ </template>
@@ -0,0 +1,65 @@
1
+ import type { FormKitSchemaDefinition } from '@formkit/core';
2
+ import type { PropType } from 'vue';
3
+ import type { AutoFormOverrides, ValibotLikeSchema, ZodLikeSchema } from '../composables/useFormKitAutoForm.js';
4
+ declare var __VLS_10: string, __VLS_11: any;
5
+ type __VLS_Slots = {} & {
6
+ [K in NonNullable<typeof __VLS_10>]?: (props: typeof __VLS_11) => any;
7
+ };
8
+ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
9
+ data: {
10
+ type: ObjectConstructor;
11
+ default: null;
12
+ };
13
+ overrides: {
14
+ type: PropType<AutoFormOverrides>;
15
+ default: undefined;
16
+ };
17
+ valibotSchema: {
18
+ type: PropType<ValibotLikeSchema>;
19
+ default: undefined;
20
+ };
21
+ zodSchema: {
22
+ type: PropType<ZodLikeSchema>;
23
+ default: undefined;
24
+ };
25
+ modelValue: {
26
+ type: PropType<FormKitSchemaDefinition>;
27
+ };
28
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
29
+ "update:modelValue": (value: FormKitSchemaDefinition | undefined) => any;
30
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
31
+ data: {
32
+ type: ObjectConstructor;
33
+ default: null;
34
+ };
35
+ overrides: {
36
+ type: PropType<AutoFormOverrides>;
37
+ default: undefined;
38
+ };
39
+ valibotSchema: {
40
+ type: PropType<ValibotLikeSchema>;
41
+ default: undefined;
42
+ };
43
+ zodSchema: {
44
+ type: PropType<ZodLikeSchema>;
45
+ default: undefined;
46
+ };
47
+ modelValue: {
48
+ type: PropType<FormKitSchemaDefinition>;
49
+ };
50
+ }>> & Readonly<{
51
+ "onUpdate:modelValue"?: ((value: FormKitSchemaDefinition | undefined) => any) | undefined;
52
+ }>, {
53
+ data: Record<string, any>;
54
+ overrides: AutoFormOverrides;
55
+ valibotSchema: ValibotLikeSchema;
56
+ zodSchema: ZodLikeSchema;
57
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
58
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
59
+ declare const _default: typeof __VLS_export;
60
+ export default _default;
61
+ type __VLS_WithSlots<T, S> = T & {
62
+ new (): {
63
+ $slots: S;
64
+ };
65
+ };
@@ -149,9 +149,9 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
149
149
  }>> & Readonly<{
150
150
  "onUpdate:modelValue"?: ((value: FormKitSchemaDefinition | undefined) => any) | undefined;
151
151
  }>, {
152
+ schema: FormKitSchemaDefinition;
152
153
  data: Record<string, any>;
153
154
  id: string;
154
- schema: FormKitSchemaDefinition;
155
155
  formClass: string;
156
156
  actionsClass: string;
157
157
  submitSeverity: string;
@@ -149,9 +149,9 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
149
149
  }>> & Readonly<{
150
150
  "onUpdate:modelValue"?: ((value: FormKitSchemaDefinition | undefined) => any) | undefined;
151
151
  }>, {
152
+ schema: FormKitSchemaDefinition;
152
153
  data: Record<string, any>;
153
154
  id: string;
154
- schema: FormKitSchemaDefinition;
155
155
  formClass: string;
156
156
  actionsClass: string;
157
157
  submitSeverity: string;
@@ -57,8 +57,8 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
57
57
  }>> & Readonly<{
58
58
  "onUpdate:modelValue"?: ((value: FormKitSchemaDefinition | undefined) => any) | undefined;
59
59
  }>, {
60
- data: Record<string, any>;
61
60
  schema: FormKitSchemaDefinition;
61
+ data: Record<string, any>;
62
62
  formClass: string;
63
63
  debugData: boolean;
64
64
  debugSchema: boolean;
@@ -57,8 +57,8 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
57
57
  }>> & Readonly<{
58
58
  "onUpdate:modelValue"?: ((value: FormKitSchemaDefinition | undefined) => any) | undefined;
59
59
  }>, {
60
- data: Record<string, any>;
61
60
  schema: FormKitSchemaDefinition;
61
+ data: Record<string, any>;
62
62
  formClass: string;
63
63
  debugData: boolean;
64
64
  debugSchema: boolean;
@@ -1,9 +1,11 @@
1
1
  import type { FormKitFrameworkContext } from '@formkit/core';
2
2
  import type { DateValue } from '@internationalized/date';
3
3
  import type { PropType } from 'vue';
4
+ import type { DateValueType } from '../../utils/dateValueConversion.js';
5
+ type DateLike = DateValue | Date | string;
4
6
  export interface CalendarDateRange {
5
- start: DateValue;
6
- end: DateValue;
7
+ start: DateLike;
8
+ end: DateLike;
7
9
  }
8
10
  export interface FormKitCalendarProps {
9
11
  type?: 'date' | 'month' | 'year';
@@ -16,9 +18,17 @@ export interface FormKitCalendarProps {
16
18
  monthControls?: boolean;
17
19
  yearControls?: boolean;
18
20
  viewControl?: boolean;
19
- defaultValue?: DateValue | DateValue[] | CalendarDateRange;
20
- minValue?: DateValue;
21
- maxValue?: DateValue;
21
+ /**
22
+ * Shape of the value read from / written to the FormKit form data.
23
+ * `'calendar'` (default) keeps the native `@internationalized/date` `DateValue`.
24
+ * `'date'` converts to/from a JS `Date`. `'iso'` converts to/from an ISO 8601 string.
25
+ */
26
+ valueType?: DateValueType;
27
+ /** Timezone used when converting to/from `'date'`/`'iso'`. Defaults to the local timezone. */
28
+ timeZone?: string;
29
+ defaultValue?: DateLike | DateLike[] | CalendarDateRange;
30
+ minValue?: DateLike;
31
+ maxValue?: DateLike;
22
32
  isDateDisabled?: (date: DateValue) => boolean;
23
33
  isDateUnavailable?: (date: DateValue) => boolean;
24
34
  ui?: Record<string, unknown>;
@@ -1,12 +1,24 @@
1
1
  <script setup>
2
+ import { computed } from "vue";
2
3
  import { useFormKitInput } from "../../utils/useFormKitInput";
4
+ import { toDateValue, toDateValueOrRangeOrArray, fromDateValueOrRangeOrArray } from "../../utils/dateValueConversion";
3
5
  const props = defineProps({
4
6
  context: {
5
7
  type: Object,
6
8
  required: true
7
9
  }
8
10
  });
9
- const { handleInput, styleClass, color, modelValue, validSlotNames } = useFormKitInput(props.context);
11
+ const { handleInput, styleClass, color, validSlotNames } = useFormKitInput(props.context);
12
+ const conversionOptions = computed(() => ({ timeZone: props.context.timeZone }));
13
+ const modelValue = computed({
14
+ get: () => toDateValueOrRangeOrArray(props.context._value, conversionOptions.value),
15
+ set: (value) => {
16
+ props.context.node.input(fromDateValueOrRangeOrArray(value, props.context.valueType ?? "calendar", props.context.timeZone));
17
+ }
18
+ });
19
+ const defaultValue = computed(() => toDateValueOrRangeOrArray(props.context.defaultValue, conversionOptions.value));
20
+ const minValue = computed(() => toDateValue(props.context.minValue, conversionOptions.value));
21
+ const maxValue = computed(() => toDateValue(props.context.maxValue, conversionOptions.value));
10
22
  </script>
11
23
 
12
24
  <template>
@@ -27,9 +39,9 @@ const { handleInput, styleClass, color, modelValue, validSlotNames } = useFormKi
27
39
  :month-controls="context.monthControls"
28
40
  :year-controls="context.yearControls"
29
41
  :view-control="context.viewControl"
30
- :default-value="context.defaultValue"
31
- :min-value="context.minValue"
32
- :max-value="context.maxValue"
42
+ :default-value="defaultValue"
43
+ :min-value="minValue"
44
+ :max-value="maxValue"
33
45
  :is-date-disabled="context.isDateDisabled"
34
46
  :is-date-unavailable="context.isDateUnavailable"
35
47
  :ui="context.ui"
@@ -1,9 +1,11 @@
1
1
  import type { FormKitFrameworkContext } from '@formkit/core';
2
2
  import type { DateValue } from '@internationalized/date';
3
3
  import type { PropType } from 'vue';
4
+ import type { DateValueType } from '../../utils/dateValueConversion.js';
5
+ type DateLike = DateValue | Date | string;
4
6
  export interface CalendarDateRange {
5
- start: DateValue;
6
- end: DateValue;
7
+ start: DateLike;
8
+ end: DateLike;
7
9
  }
8
10
  export interface FormKitCalendarProps {
9
11
  type?: 'date' | 'month' | 'year';
@@ -16,9 +18,17 @@ export interface FormKitCalendarProps {
16
18
  monthControls?: boolean;
17
19
  yearControls?: boolean;
18
20
  viewControl?: boolean;
19
- defaultValue?: DateValue | DateValue[] | CalendarDateRange;
20
- minValue?: DateValue;
21
- maxValue?: DateValue;
21
+ /**
22
+ * Shape of the value read from / written to the FormKit form data.
23
+ * `'calendar'` (default) keeps the native `@internationalized/date` `DateValue`.
24
+ * `'date'` converts to/from a JS `Date`. `'iso'` converts to/from an ISO 8601 string.
25
+ */
26
+ valueType?: DateValueType;
27
+ /** Timezone used when converting to/from `'date'`/`'iso'`. Defaults to the local timezone. */
28
+ timeZone?: string;
29
+ defaultValue?: DateLike | DateLike[] | CalendarDateRange;
30
+ minValue?: DateLike;
31
+ maxValue?: DateLike;
22
32
  isDateDisabled?: (date: DateValue) => boolean;
23
33
  isDateUnavailable?: (date: DateValue) => boolean;
24
34
  ui?: Record<string, unknown>;
@@ -1,11 +1,13 @@
1
1
  import type { FormKitFrameworkContext } from '@formkit/core';
2
2
  import type { CalendarDate, CalendarDateTime, DateValue, ZonedDateTime } from '@internationalized/date';
3
3
  import type { PropType } from 'vue';
4
+ import type { DateValueType } from '../../utils/dateValueConversion.js';
4
5
  import type { AvatarProps } from '#ui/components/Avatar.vue';
5
6
  export interface DateRange {
6
7
  start: CalendarDate | CalendarDateTime | ZonedDateTime;
7
8
  end: CalendarDate | CalendarDateTime | ZonedDateTime;
8
9
  }
10
+ type DateLike = CalendarDate | CalendarDateTime | ZonedDateTime | Date | string;
9
11
  export interface FormKitInputDateProps {
10
12
  color?: 'primary' | 'secondary' | 'success' | 'info' | 'warning' | 'error' | 'neutral';
11
13
  variant?: 'outline' | 'soft' | 'subtle' | 'ghost' | 'none';
@@ -24,15 +26,26 @@ export interface FormKitInputDateProps {
24
26
  trailingIcon?: string;
25
27
  loading?: boolean;
26
28
  loadingIcon?: string;
27
- defaultValue: CalendarDate | CalendarDateTime | ZonedDateTime | DateRange;
28
- placeholder?: CalendarDate | CalendarDateTime | ZonedDateTime;
29
- defaultPlaceholder?: CalendarDate | CalendarDateTime | ZonedDateTime;
29
+ /**
30
+ * Shape of the value read from / written to the FormKit form data.
31
+ * `'calendar'` (default) keeps the native `@internationalized/date` `DateValue`.
32
+ * `'date'` converts to/from a JS `Date`. `'iso'` converts to/from an ISO 8601 string.
33
+ */
34
+ valueType?: DateValueType;
35
+ /** Timezone used when converting to/from `'date'`/`'iso'`. Defaults to the local timezone. */
36
+ timeZone?: string;
37
+ defaultValue: DateLike | {
38
+ start: DateLike;
39
+ end: DateLike;
40
+ };
41
+ placeholder?: DateLike;
42
+ defaultPlaceholder?: DateLike;
30
43
  hourCycle?: 12 | 24;
31
44
  step?: Record<string, number>;
32
45
  granularity?: 'day' | 'hour' | 'minute' | 'second';
33
46
  hideTimeZone?: boolean;
34
- maxValue?: CalendarDate | CalendarDateTime | ZonedDateTime;
35
- minValue?: CalendarDate | CalendarDateTime | ZonedDateTime;
47
+ maxValue?: DateLike;
48
+ minValue?: DateLike;
36
49
  isDateUnavailable?: (date: DateValue) => boolean;
37
50
  ui?: Record<string, unknown>;
38
51
  }
@@ -1,12 +1,30 @@
1
1
  <script setup>
2
+ import { computed } from "vue";
2
3
  import { useFormKitInput } from "../../utils/useFormKitInput";
4
+ import { fromDateValueOrRange, toDateValue, toDateValueOrRange } from "../../utils/dateValueConversion";
3
5
  const props = defineProps({
4
6
  context: {
5
7
  type: Object,
6
8
  required: true
7
9
  }
8
10
  });
9
- const { handleInput, handleChange, isInvalid, styleClass, color, modelValue, validSlotNames } = useFormKitInput(props.context);
11
+ const { handleInput, handleChange, isInvalid, styleClass, color, validSlotNames } = useFormKitInput(props.context);
12
+ const conversionOptions = computed(() => ({
13
+ granularity: props.context.granularity,
14
+ hideTimeZone: props.context.hideTimeZone,
15
+ timeZone: props.context.timeZone
16
+ }));
17
+ const modelValue = computed({
18
+ get: () => toDateValueOrRange(props.context._value, conversionOptions.value),
19
+ set: (value) => {
20
+ props.context.node.input(fromDateValueOrRange(value, props.context.valueType ?? "calendar", props.context.timeZone));
21
+ }
22
+ });
23
+ const defaultValue = computed(() => toDateValueOrRange(props.context.defaultValue, conversionOptions.value));
24
+ const placeholder = computed(() => toDateValue(props.context.placeholder, conversionOptions.value));
25
+ const defaultPlaceholder = computed(() => toDateValue(props.context.defaultPlaceholder, conversionOptions.value));
26
+ const maxValue = computed(() => toDateValue(props.context.maxValue, conversionOptions.value));
27
+ const minValue = computed(() => toDateValue(props.context.minValue, conversionOptions.value));
10
28
  </script>
11
29
 
12
30
  <template>
@@ -14,7 +32,7 @@ const { handleInput, handleChange, isInvalid, styleClass, color, modelValue, val
14
32
  :id="context.id"
15
33
  v-model="modelValue"
16
34
  v-bind="{ ...context?.attrs }"
17
- :default-value="context.defaultValue"
35
+ :default-value="defaultValue"
18
36
  :class="styleClass"
19
37
  :disabled="!!context?.disabled"
20
38
  :readonly="context?.attrs.readonly ?? false"
@@ -23,8 +41,8 @@ const { handleInput, handleChange, isInvalid, styleClass, color, modelValue, val
23
41
  :highlight="isInvalid || context.highlight"
24
42
  :size="context.size ?? 'md'"
25
43
  :variant="context.variant ?? 'outline'"
26
- :placeholder="context.placeholder"
27
- :default-placeholder="context.defaultPlaceholder"
44
+ :placeholder="placeholder"
45
+ :default-placeholder="defaultPlaceholder"
28
46
  :autofocus="context.autofocus"
29
47
  :autofocus-delay="context.autofocusDelay"
30
48
  :fixed="context.fixed"
@@ -42,8 +60,8 @@ const { handleInput, handleChange, isInvalid, styleClass, color, modelValue, val
42
60
  :step="context.step"
43
61
  :granularity="context.granularity"
44
62
  :hide-time-zone="context.hideTimeZone"
45
- :max-value="context.maxValue"
46
- :min-value="context.minValue"
63
+ :max-value="maxValue"
64
+ :min-value="minValue"
47
65
  :is-date-unavailable="context.isDateUnavailable"
48
66
  :ui="context.ui"
49
67
  @change="handleChange"
@@ -1,11 +1,13 @@
1
1
  import type { FormKitFrameworkContext } from '@formkit/core';
2
2
  import type { CalendarDate, CalendarDateTime, DateValue, ZonedDateTime } from '@internationalized/date';
3
3
  import type { PropType } from 'vue';
4
+ import type { DateValueType } from '../../utils/dateValueConversion.js';
4
5
  import type { AvatarProps } from '#ui/components/Avatar.vue';
5
6
  export interface DateRange {
6
7
  start: CalendarDate | CalendarDateTime | ZonedDateTime;
7
8
  end: CalendarDate | CalendarDateTime | ZonedDateTime;
8
9
  }
10
+ type DateLike = CalendarDate | CalendarDateTime | ZonedDateTime | Date | string;
9
11
  export interface FormKitInputDateProps {
10
12
  color?: 'primary' | 'secondary' | 'success' | 'info' | 'warning' | 'error' | 'neutral';
11
13
  variant?: 'outline' | 'soft' | 'subtle' | 'ghost' | 'none';
@@ -24,15 +26,26 @@ export interface FormKitInputDateProps {
24
26
  trailingIcon?: string;
25
27
  loading?: boolean;
26
28
  loadingIcon?: string;
27
- defaultValue: CalendarDate | CalendarDateTime | ZonedDateTime | DateRange;
28
- placeholder?: CalendarDate | CalendarDateTime | ZonedDateTime;
29
- defaultPlaceholder?: CalendarDate | CalendarDateTime | ZonedDateTime;
29
+ /**
30
+ * Shape of the value read from / written to the FormKit form data.
31
+ * `'calendar'` (default) keeps the native `@internationalized/date` `DateValue`.
32
+ * `'date'` converts to/from a JS `Date`. `'iso'` converts to/from an ISO 8601 string.
33
+ */
34
+ valueType?: DateValueType;
35
+ /** Timezone used when converting to/from `'date'`/`'iso'`. Defaults to the local timezone. */
36
+ timeZone?: string;
37
+ defaultValue: DateLike | {
38
+ start: DateLike;
39
+ end: DateLike;
40
+ };
41
+ placeholder?: DateLike;
42
+ defaultPlaceholder?: DateLike;
30
43
  hourCycle?: 12 | 24;
31
44
  step?: Record<string, number>;
32
45
  granularity?: 'day' | 'hour' | 'minute' | 'second';
33
46
  hideTimeZone?: boolean;
34
- maxValue?: CalendarDate | CalendarDateTime | ZonedDateTime;
35
- minValue?: CalendarDate | CalendarDateTime | ZonedDateTime;
47
+ maxValue?: DateLike;
48
+ minValue?: DateLike;
36
49
  isDateUnavailable?: (date: DateValue) => boolean;
37
50
  ui?: Record<string, unknown>;
38
51
  }
@@ -0,0 +1,38 @@
1
+ import type { FormKitSchemaNode } from '@formkit/core';
2
+ export type AutoFormOverrides = Record<string, Record<string, unknown> | boolean>;
3
+ export declare function inferFormSchema(data: Record<string, unknown>, overrides?: AutoFormOverrides): FormKitSchemaNode[];
4
+ export interface ValibotLikePipeEntry {
5
+ kind: string;
6
+ type: string;
7
+ requirement?: unknown;
8
+ }
9
+ export interface ValibotLikeSchema {
10
+ kind: 'schema';
11
+ type: string;
12
+ entries?: Record<string, ValibotLikeSchema>;
13
+ item?: ValibotLikeSchema;
14
+ wrapped?: ValibotLikeSchema;
15
+ default?: unknown;
16
+ pipe?: readonly ValibotLikePipeEntry[];
17
+ }
18
+ export declare function inferFormSchemaFromValibot(schema: object, overrides?: AutoFormOverrides): FormKitSchemaNode[];
19
+ export interface ZodLikeSchema {
20
+ type: string;
21
+ shape?: Record<string, ZodLikeSchema>;
22
+ element?: ZodLikeSchema;
23
+ minLength?: number | null;
24
+ maxLength?: number | null;
25
+ minValue?: number | null;
26
+ maxValue?: number | null;
27
+ format?: string | null;
28
+ unwrap?: () => ZodLikeSchema;
29
+ def?: {
30
+ defaultValue?: unknown;
31
+ };
32
+ }
33
+ export declare function inferFormSchemaFromZod(schema: object, overrides?: AutoFormOverrides): FormKitSchemaNode[];
34
+ export declare function useFormKitAutoForm(): {
35
+ inferFormSchema: typeof inferFormSchema;
36
+ inferFormSchemaFromValibot: typeof inferFormSchemaFromValibot;
37
+ inferFormSchemaFromZod: typeof inferFormSchemaFromZod;
38
+ };