@sfxcode/nuxt-ui-formkit 1.2.1 → 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 (39) hide show
  1. package/README.md +18 -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/composables/useFormKitAutoForm.d.ts +38 -0
  12. package/dist/runtime/composables/useFormKitAutoForm.js +349 -0
  13. package/dist/runtime/composables/useFormKitForm.d.ts +11 -0
  14. package/dist/runtime/composables/useFormKitForm.js +38 -0
  15. package/dist/runtime/composables/useFormKitMultiStep.d.ts +5 -0
  16. package/dist/runtime/composables/useFormKitMultiStep.js +65 -0
  17. package/dist/runtime/composables/useFormKitRepeater.d.ts +4 -0
  18. package/dist/runtime/composables/useFormKitRepeater.js +138 -0
  19. package/dist/runtime/formkit/createNuxtUiFormkitConfig.d.ts +19 -0
  20. package/dist/runtime/formkit/createNuxtUiFormkitConfig.js +12 -0
  21. package/dist/runtime/formkit/createNuxtUiFormkitConfig.mjs +12 -0
  22. package/dist/runtime/formkit/definitions/index.d.ts +3 -0
  23. package/dist/runtime/formkit/definitions/index.js +4 -0
  24. package/dist/runtime/formkit/definitions/index.mjs +4 -0
  25. package/dist/runtime/formkit/definitions/multiStep.d.ts +3 -0
  26. package/dist/runtime/formkit/definitions/multiStep.js +90 -0
  27. package/dist/runtime/formkit/definitions/multiStep.mjs +90 -0
  28. package/dist/runtime/formkit/definitions/repeater.js +3 -119
  29. package/dist/runtime/formkit/definitions/repeater.mjs +3 -119
  30. package/dist/runtime/formkit/index.d.ts +10 -0
  31. package/dist/runtime/formkit/index.js +1 -0
  32. package/dist/runtime/formkit/index.mjs +1 -0
  33. package/dist/runtime/formkit/plugins/index.d.ts +1 -0
  34. package/dist/runtime/formkit/plugins/index.js +1 -0
  35. package/dist/runtime/formkit/plugins/index.mjs +1 -0
  36. package/dist/runtime/plugin.js +2 -1
  37. package/dist/runtime/utils/dateValueConversion.d.ts +8 -7
  38. package/dist/runtime/utils/dateValueConversion.js +1 -1
  39. package/package.json +5 -2
@@ -0,0 +1,11 @@
1
+ import type { ErrorMessages } from '@formkit/core';
2
+ export declare function useFormKitForm(id: string): {
3
+ submit: (handler?: () => unknown | Promise<unknown>) => void;
4
+ reset: (resetTo?: unknown) => void;
5
+ setErrors: (localErrors: ErrorMessages, childErrors?: ErrorMessages) => void;
6
+ clearErrors: (clearChildren?: boolean) => void;
7
+ isValid: import("vue").ComputedRef<boolean>;
8
+ isSubmitted: import("vue").ComputedRef<boolean>;
9
+ hasErrors: import("vue").ComputedRef<boolean>;
10
+ isLoading: import("vue").Ref<boolean, boolean>;
11
+ };
@@ -0,0 +1,38 @@
1
+ import { clearErrors, reset, setErrors, submitForm } from "@formkit/core";
2
+ import { useFormKitContextById } from "@formkit/vue";
3
+ import { computed, ref } from "vue";
4
+ export function useFormKitForm(id) {
5
+ const context = useFormKitContextById(id);
6
+ const isLoading = ref(false);
7
+ const isValid = computed(() => context.value?.state.valid ?? false);
8
+ const isSubmitted = computed(() => context.value?.state.submitted ?? false);
9
+ const hasErrors = computed(() => context.value?.state.errors ?? false);
10
+ function submit(handler) {
11
+ submitForm(id);
12
+ if (!handler)
13
+ return;
14
+ isLoading.value = true;
15
+ void Promise.resolve(handler()).finally(() => {
16
+ isLoading.value = false;
17
+ });
18
+ }
19
+ function resetForm(resetTo) {
20
+ reset(id, resetTo);
21
+ }
22
+ function setFormErrors(localErrors, childErrors) {
23
+ setErrors(id, localErrors, childErrors);
24
+ }
25
+ function clearFormErrors(clearChildren) {
26
+ clearErrors(id, clearChildren);
27
+ }
28
+ return {
29
+ submit,
30
+ reset: resetForm,
31
+ setErrors: setFormErrors,
32
+ clearErrors: clearFormErrors,
33
+ isValid,
34
+ isSubmitted,
35
+ hasErrors,
36
+ isLoading
37
+ };
38
+ }
@@ -0,0 +1,5 @@
1
+ import type { FormKitNode } from '@formkit/core';
2
+ export declare function useFormKitMultiStep(): {
3
+ addMultiStepHandler: (node: FormKitNode) => void;
4
+ addStepHandler: (node: FormKitNode) => void;
5
+ };
@@ -0,0 +1,65 @@
1
+ import { ref, watchEffect } from "vue";
2
+ export function useFormKitMultiStep() {
3
+ function buildTabItems(node) {
4
+ const steps = Array.isArray(node.props.steps) ? node.props.steps : [];
5
+ const validStepIcon = typeof node.props.validStepIcon === "string" ? node.props.validStepIcon : "i-lucide-check";
6
+ const allowIncomplete = node.props.allowIncomplete !== false;
7
+ const activeIndex = steps.findIndex((step) => step.node?.name === node.props.activeStep);
8
+ const activeStepInvalid = activeIndex >= 0 && steps[activeIndex]?.isValid === false;
9
+ return steps.map((step, index) => {
10
+ const totalErrorCount = (step.errorCount ?? 0) + (step.blockingCount ?? 0);
11
+ const item = {
12
+ label: step.stepName,
13
+ value: step.node?.name,
14
+ // Jumping ahead to a step you haven't visited yet while the current
15
+ // step is invalid would just be silently blocked by the addon's own
16
+ // `isTargetStepAllowed` gating on click - disable it proactively
17
+ // instead so it's not clickable-but-inert. Steps already visited
18
+ // (including the active one) stay enabled, matching the addon's own
19
+ // "moving backward is always allowed" rule.
20
+ disabled: !allowIncomplete && !step.hasBeenVisited && index > activeIndex && activeStepInvalid
21
+ };
22
+ const isActive = index === activeIndex;
23
+ if (step.showStepErrors && totalErrorCount > 0)
24
+ item.badge = { label: totalErrorCount, color: "error", variant: isActive ? "solid" : void 0 };
25
+ else if (step.isValid && step.hasBeenVisited)
26
+ item.badge = { icon: validStepIcon, color: "success", variant: isActive ? "solid" : void 0 };
27
+ return item;
28
+ });
29
+ }
30
+ function addMultiStepHandler(node) {
31
+ const structuralVersion = ref(0);
32
+ const bumpStructuralVersion = () => {
33
+ structuralVersion.value++;
34
+ };
35
+ node.on("child", bumpStructuralVersion);
36
+ node.on("childRemoved", bumpStructuralVersion);
37
+ node.on("prop:steps", bumpStructuralVersion);
38
+ node.on("prop:activeStep", bumpStructuralVersion);
39
+ node.on("created", () => {
40
+ if (!node.context)
41
+ return;
42
+ watchEffect(() => {
43
+ void structuralVersion.value;
44
+ if (node.context)
45
+ node.context.tabItems = buildTabItems(node);
46
+ });
47
+ node.context.handleTabChange = (value) => {
48
+ node.goTo(value);
49
+ };
50
+ });
51
+ }
52
+ function addStepHandler(node) {
53
+ node.on("created", () => {
54
+ if (!node.context)
55
+ return;
56
+ node.context.internalStepActionsClass = node.context.stepActionsClass ? `formkit-step-actions ${node.context.stepActionsClass}` : "formkit-step-actions flex gap-2 pt-2";
57
+ watchEffect(() => {
58
+ const allowIncomplete = node.parent?.props.allowIncomplete !== false;
59
+ if (node.context)
60
+ node.context.nextDisabled = !allowIncomplete && node.context.isValid === false;
61
+ });
62
+ });
63
+ }
64
+ return { addMultiStepHandler, addStepHandler };
65
+ }
@@ -0,0 +1,4 @@
1
+ import type { FormKitNode } from '@formkit/core';
2
+ export declare function useFormKitRepeater(): {
3
+ addRepeaterHandler: (node: FormKitNode) => void;
4
+ };
@@ -0,0 +1,138 @@
1
+ export function useFormKitRepeater() {
2
+ function addRepeaterHandler(node) {
3
+ const swapElements = (array, index1, index2) => {
4
+ const [element] = array.splice(index1, 1);
5
+ if (element !== void 0) {
6
+ array.splice(index2, 0, element);
7
+ }
8
+ return array;
9
+ };
10
+ const uuid = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2);
11
+ const syncOuterValue = (value) => {
12
+ node.input(value, false);
13
+ };
14
+ node.on("created", () => {
15
+ if (node.context) {
16
+ let dragStartIndex = null;
17
+ let dragOverIndex = null;
18
+ const newItem = node.context.newItem || {};
19
+ node.context.listName = node.name;
20
+ node.context.renderButtons = !node.context.hideButtonGroup;
21
+ node.context.insertButtonSize = node.context.insertButtonSize ? node.context.insertButtonSize : "md";
22
+ node.context.buttonSize = node.context.buttonSize ? node.context.buttonSize : "md";
23
+ node.context.renderMoveButtons = !node.context.hideMoveButtons;
24
+ node.context.draggable = !!node.context.draggable;
25
+ node.context.renderDragHandle = !!node.context.displayDragHandle;
26
+ node.context.dragHandleIconName = node.context.dragHandleIconName || "i-lucide-grip-vertical";
27
+ node.context.internalDragHandleClass = node.context.dragHandleClass ? `formkit-repeater-drag-handle ${node.context.dragHandleClass}` : "formkit-repeater-drag-handle";
28
+ node.context.internalListClass = node.context.listClass ? `formkit-items ${node.context.listClass}` : "formkit-items";
29
+ node.context.internalListItemClass = node.context.listItemClass ? `formkit-item ${node.context.listItemClass}` : "formkit-item";
30
+ node.context.internalListId = `formkit-items-${uuid}`;
31
+ node.context.minItems = node.context.minItems !== void 0 ? node.context.minItems : 0;
32
+ node.context.maxItems = node.context.maxItems !== void 0 ? node.context.maxItems : Number.POSITIVE_INFINITY;
33
+ node.context.repeaterValidation = [["length", node.context.minItems, node.context.maxItems]];
34
+ node.context.getListItemClass = (index) => {
35
+ if (dragOverIndex === index && dragStartIndex !== index)
36
+ return `${node.context?.internalListItemClass} formkit-repeater-drop-target`;
37
+ return node.context?.internalListItemClass?.toString() ?? "";
38
+ };
39
+ node.context.getListItemId = (index) => {
40
+ return `formkit-item-${index}-${uuid}`;
41
+ };
42
+ node.context.insertNode = (parentNode) => () => {
43
+ if (parentNode && Array.isArray(parentNode._value)) {
44
+ const newArray = [{ ...newItem }, ...parentNode.value];
45
+ parentNode.input(newArray, false);
46
+ syncOuterValue(newArray);
47
+ }
48
+ };
49
+ node.context.removeNode = (parentNode, index) => () => {
50
+ if (parentNode && Array.isArray(parentNode._value)) {
51
+ const newArray = parentNode._value.filter((_, i) => i !== index);
52
+ parentNode.input(newArray, false);
53
+ syncOuterValue(newArray);
54
+ }
55
+ };
56
+ node.context.addNode = (parentNode, index) => () => {
57
+ if (parentNode && Array.isArray(parentNode._value)) {
58
+ const array = parentNode.value;
59
+ array.splice(index + 1, 0, { ...newItem });
60
+ parentNode.input(array, false);
61
+ syncOuterValue(array);
62
+ }
63
+ };
64
+ node.context.cloneNode = (parentNode, index) => () => {
65
+ if (parentNode && Array.isArray(parentNode._value)) {
66
+ const item = parentNode.value[index];
67
+ const array = parentNode.value;
68
+ array.splice(index + 1, 0, { ...item });
69
+ parentNode.input(array, false);
70
+ syncOuterValue(array);
71
+ }
72
+ };
73
+ node.context.moveNodeUp = (parentNode, index) => () => {
74
+ if (parentNode && Array.isArray(parentNode._value)) {
75
+ if (index > 0) {
76
+ const newArray = swapElements(parentNode.value, index - 1, index);
77
+ parentNode.input(newArray, false);
78
+ syncOuterValue(newArray);
79
+ }
80
+ }
81
+ };
82
+ node.context.moveNodeDown = (parentNode, index) => () => {
83
+ if (parentNode && Array.isArray(parentNode._value)) {
84
+ if (index < parentNode.value.length - 1) {
85
+ const newArray = swapElements(parentNode.value, index, index + 1);
86
+ parentNode.input(newArray, false);
87
+ syncOuterValue(newArray);
88
+ }
89
+ }
90
+ };
91
+ node.context.dragNodeStart = (_parentNode, index) => (event) => {
92
+ dragStartIndex = index;
93
+ if (event?.dataTransfer) {
94
+ event.dataTransfer.effectAllowed = "move";
95
+ event.dataTransfer.setData("text/plain", String(index));
96
+ }
97
+ };
98
+ node.context.dragNodeOver = (targetIndex) => (event) => {
99
+ event?.preventDefault();
100
+ dragOverIndex = targetIndex;
101
+ if (event?.dataTransfer)
102
+ event.dataTransfer.dropEffect = "move";
103
+ };
104
+ node.context.dragNodeLeave = (targetIndex) => () => {
105
+ if (dragOverIndex === targetIndex)
106
+ dragOverIndex = null;
107
+ };
108
+ node.context.dropNode = (parentNode, targetIndex) => (event) => {
109
+ event?.preventDefault();
110
+ if (!parentNode || !Array.isArray(parentNode._value)) {
111
+ dragOverIndex = null;
112
+ return;
113
+ }
114
+ const sourceFromEvent = Number.parseInt(event?.dataTransfer?.getData("text/plain") || "", 10);
115
+ const sourceIndex = Number.isInteger(sourceFromEvent) ? sourceFromEvent : dragStartIndex;
116
+ if (sourceIndex === null || sourceIndex === targetIndex) {
117
+ dragOverIndex = null;
118
+ return;
119
+ }
120
+ if (sourceIndex < 0 || sourceIndex >= parentNode.value.length) {
121
+ dragOverIndex = null;
122
+ return;
123
+ }
124
+ const newArray = swapElements(parentNode.value, sourceIndex, targetIndex);
125
+ parentNode.input(newArray, false);
126
+ syncOuterValue(newArray);
127
+ dragStartIndex = null;
128
+ dragOverIndex = null;
129
+ };
130
+ node.context.dragNodeEnd = () => {
131
+ dragStartIndex = null;
132
+ dragOverIndex = null;
133
+ };
134
+ }
135
+ });
136
+ }
137
+ return { addRepeaterHandler };
138
+ }
@@ -0,0 +1,19 @@
1
+ import type { DefaultConfigOptions } from '@formkit/vue';
2
+ export interface CreateNuxtUiFormkitConfigOptions {
3
+ /**
4
+ * Registers `createMultiStepPlugin()` so `nuxtUIMultiStep`/`nuxtUIStep`
5
+ * actually work. The input type registrations themselves are always
6
+ * included below regardless of this flag - they're inert for forms that
7
+ * don't use them, but the plugin has real runtime behavior (it hooks
8
+ * every node to check its type), so it's opt-in.
9
+ */
10
+ multiStep?: boolean;
11
+ }
12
+ /**
13
+ * Assembles the `inputs`/`plugins` this module needs into a plain object a
14
+ * consumer spreads into their own `defaultConfig({ ...createNuxtUiFormkitConfig(), ... })`
15
+ * call inside `formkit.config.ts` - it doesn't call `defaultConfig` itself,
16
+ * so it stays composable with whatever else that config already does
17
+ * (locales, `iconLoader`, other plugins like `createAutoAnimatePlugin`).
18
+ */
19
+ export declare function createNuxtUiFormkitConfig(options?: CreateNuxtUiFormkitConfigOptions): Pick<DefaultConfigOptions, 'inputs' | 'plugins'>;
@@ -0,0 +1,12 @@
1
+ import { createMultiStepPlugin } from "@formkit/addons";
2
+ import { nuxtUIInputs, nuxtUIOutputs } from "./definitions/index.js";
3
+ import { addNuxtAsteriskPlugin } from "./plugins/index.js";
4
+ export function createNuxtUiFormkitConfig(options = {}) {
5
+ const plugins = [addNuxtAsteriskPlugin];
6
+ if (options.multiStep)
7
+ plugins.push(createMultiStepPlugin());
8
+ return {
9
+ inputs: { ...nuxtUIInputs, ...nuxtUIOutputs },
10
+ plugins
11
+ };
12
+ }
@@ -0,0 +1,12 @@
1
+ import { createMultiStepPlugin } from "@formkit/addons";
2
+ import { nuxtUIInputs, nuxtUIOutputs } from "./definitions/index.mjs";
3
+ import { addNuxtAsteriskPlugin } from "./plugins/index.mjs";
4
+ export function createNuxtUiFormkitConfig(options = {}) {
5
+ const plugins = [addNuxtAsteriskPlugin];
6
+ if (options.multiStep)
7
+ plugins.push(createMultiStepPlugin());
8
+ return {
9
+ inputs: { ...nuxtUIInputs, ...nuxtUIOutputs },
10
+ plugins
11
+ };
12
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './input.js';
2
+ export * from './multiStep.js';
2
3
  export * from './output.js';
3
4
  export declare const nuxtUIInputs: {
4
5
  nuxtUICalendar: import("@formkit/core").FormKitTypeDefinition;
@@ -14,11 +15,13 @@ export declare const nuxtUIInputs: {
14
15
  nuxtUIInputTags: import("@formkit/core").FormKitTypeDefinition;
15
16
  nuxtUIInputTime: import("@formkit/core").FormKitTypeDefinition;
16
17
  nuxtUIListbox: import("@formkit/core").FormKitTypeDefinition;
18
+ nuxtUIMultiStep: import("@formkit/core").FormKitTypeDefinition;
17
19
  nuxtUIPinInput: import("@formkit/core").FormKitTypeDefinition;
18
20
  nuxtUIRadioGroup: import("@formkit/core").FormKitTypeDefinition;
19
21
  nuxtUISelect: import("@formkit/core").FormKitTypeDefinition;
20
22
  nuxtUISelectMenu: import("@formkit/core").FormKitTypeDefinition;
21
23
  nuxtUISlider: import("@formkit/core").FormKitTypeDefinition;
24
+ nuxtUIStep: import("@formkit/core").FormKitTypeDefinition;
22
25
  nuxtUISwitch: import("@formkit/core").FormKitTypeDefinition;
23
26
  nuxtUITextarea: import("@formkit/core").FormKitTypeDefinition;
24
27
  nuxtUIRepeater: import("@formkit/core").FormKitTypeDefinition;
@@ -1,7 +1,9 @@
1
1
  import { nuxtUICalendarDefinition, nuxtUICheckboxDefinition, nuxtUICheckboxGroupDefinition, nuxtUIColorPickerDefinition, nuxtUIEditorDefinition, nuxtUIFileUploadDefinition, nuxtUIInputDateDefinition, nuxtUIInputDefinition, nuxtUIInputMenuDefinition, nuxtUIInputNumberDefinition, nuxtUIInputTagsDefinition, nuxtUIInputTimeDefinition, nuxtUIListboxDefinition, nuxtUIPinInputDefinition, nuxtUIRadioGroupDefinition, nuxtUISelectDefinition, nuxtUISelectMenuDefinition, nuxtUISliderDefinition, nuxtUISwitchDefinition, nuxtUITextareaDefinition } from "./input.js";
2
+ import { nuxtUIMultiStepDefinition, nuxtUIStepDefinition } from "./multiStep.js";
2
3
  import { nuxtUIOutputBooleanDefinition, nuxtUIOutputDateDefinition, nuxtUIOutputLinkDefinition, nuxtUIOutputListDefinition, nuxtUIOutputNumberDefinition, nuxtUIOutputTextDefinition } from "./output.js";
3
4
  import { nuxtUIRepeaterDefinition } from "./repeater.js";
4
5
  export * from "./input.js";
6
+ export * from "./multiStep.js";
5
7
  export * from "./output.js";
6
8
  export const nuxtUIInputs = {
7
9
  nuxtUICalendar: nuxtUICalendarDefinition,
@@ -17,11 +19,13 @@ export const nuxtUIInputs = {
17
19
  nuxtUIInputTags: nuxtUIInputTagsDefinition,
18
20
  nuxtUIInputTime: nuxtUIInputTimeDefinition,
19
21
  nuxtUIListbox: nuxtUIListboxDefinition,
22
+ nuxtUIMultiStep: nuxtUIMultiStepDefinition,
20
23
  nuxtUIPinInput: nuxtUIPinInputDefinition,
21
24
  nuxtUIRadioGroup: nuxtUIRadioGroupDefinition,
22
25
  nuxtUISelect: nuxtUISelectDefinition,
23
26
  nuxtUISelectMenu: nuxtUISelectMenuDefinition,
24
27
  nuxtUISlider: nuxtUISliderDefinition,
28
+ nuxtUIStep: nuxtUIStepDefinition,
25
29
  nuxtUISwitch: nuxtUISwitchDefinition,
26
30
  nuxtUITextarea: nuxtUITextareaDefinition,
27
31
  nuxtUIRepeater: nuxtUIRepeaterDefinition
@@ -1,7 +1,9 @@
1
1
  import { nuxtUICalendarDefinition, nuxtUICheckboxDefinition, nuxtUICheckboxGroupDefinition, nuxtUIColorPickerDefinition, nuxtUIEditorDefinition, nuxtUIFileUploadDefinition, nuxtUIInputDateDefinition, nuxtUIInputDefinition, nuxtUIInputMenuDefinition, nuxtUIInputNumberDefinition, nuxtUIInputTagsDefinition, nuxtUIInputTimeDefinition, nuxtUIListboxDefinition, nuxtUIPinInputDefinition, nuxtUIRadioGroupDefinition, nuxtUISelectDefinition, nuxtUISelectMenuDefinition, nuxtUISliderDefinition, nuxtUISwitchDefinition, nuxtUITextareaDefinition } from "./input.mjs";
2
+ import { nuxtUIMultiStepDefinition, nuxtUIStepDefinition } from "./multiStep.mjs";
2
3
  import { nuxtUIOutputBooleanDefinition, nuxtUIOutputDateDefinition, nuxtUIOutputLinkDefinition, nuxtUIOutputListDefinition, nuxtUIOutputNumberDefinition, nuxtUIOutputTextDefinition } from "./output.mjs";
3
4
  import { nuxtUIRepeaterDefinition } from "./repeater.mjs";
4
5
  export * from "./input.mjs";
6
+ export * from "./multiStep.mjs";
5
7
  export * from "./output.mjs";
6
8
  export const nuxtUIInputs = {
7
9
  nuxtUICalendar: nuxtUICalendarDefinition,
@@ -17,11 +19,13 @@ export const nuxtUIInputs = {
17
19
  nuxtUIInputTags: nuxtUIInputTagsDefinition,
18
20
  nuxtUIInputTime: nuxtUIInputTimeDefinition,
19
21
  nuxtUIListbox: nuxtUIListboxDefinition,
22
+ nuxtUIMultiStep: nuxtUIMultiStepDefinition,
20
23
  nuxtUIPinInput: nuxtUIPinInputDefinition,
21
24
  nuxtUIRadioGroup: nuxtUIRadioGroupDefinition,
22
25
  nuxtUISelect: nuxtUISelectDefinition,
23
26
  nuxtUISelectMenu: nuxtUISelectMenuDefinition,
24
27
  nuxtUISlider: nuxtUISliderDefinition,
28
+ nuxtUIStep: nuxtUIStepDefinition,
25
29
  nuxtUISwitch: nuxtUISwitchDefinition,
26
30
  nuxtUITextarea: nuxtUITextareaDefinition,
27
31
  nuxtUIRepeater: nuxtUIRepeaterDefinition
@@ -0,0 +1,3 @@
1
+ import type { FormKitTypeDefinition } from '@formkit/core';
2
+ export declare const nuxtUIStepDefinition: FormKitTypeDefinition;
3
+ export declare const nuxtUIMultiStepDefinition: FormKitTypeDefinition;
@@ -0,0 +1,90 @@
1
+ import { disablesChildren } from "@formkit/inputs";
2
+ import { createInput } from "@formkit/vue";
3
+ import { useFormKitMultiStep } from "../../composables/useFormKitMultiStep.js";
4
+ import { useFormKitSchema } from "../../composables/useFormKitSchema.js";
5
+ const { addElement, addComponent } = useFormKitSchema();
6
+ const { addMultiStepHandler, addStepHandler } = useFormKitMultiStep();
7
+ function addStepActionButton(label, onClick, bindAttrs, render, variant, disabled) {
8
+ return addElement("div", [
9
+ addComponent("UButton", { label, onClick, variant, disabled, ui: "$ui" }, true, { bind: bindAttrs })
10
+ ], {}, render);
11
+ }
12
+ export const nuxtUIStepDefinition = createInput(
13
+ addElement("div", [
14
+ addElement("div", "$slots.default", { class: "formkit-step-inner" }),
15
+ addElement("div", [
16
+ addStepActionButton(
17
+ { if: "$previousLabel", then: "$previousLabel", else: "Previous" },
18
+ "$handlers.previous",
19
+ "$previousAttrs",
20
+ "$isFirstStep === false",
21
+ "outline"
22
+ ),
23
+ addStepActionButton(
24
+ { if: "$nextLabel", then: "$nextLabel", else: "Next" },
25
+ "$handlers.next",
26
+ "$nextAttrs",
27
+ "$isLastStep === false || $stepIndex === 0",
28
+ void 0,
29
+ "$nextDisabled"
30
+ )
31
+ ], { class: "$internalStepActionsClass" })
32
+ ], {
33
+ "id": "$id",
34
+ "role": "tabpanel",
35
+ "aria-labelledby": '$node.parent.props.id + "_tab_" + $stepIndex'
36
+ }, true),
37
+ {
38
+ // The core node `type` (input|list|group) - not to be confused with
39
+ // `forceTypeProp` below, which is what makes `@formkit/addons`' own
40
+ // `createMultiStepPlugin` recognize this node as a `step`.
41
+ type: "group",
42
+ forceTypeProp: "step",
43
+ family: "NuxtUIInput",
44
+ props: ["beforeStepChange", "nextAttrs", "nextLabel", "previousAttrs", "previousLabel", "validStepIcon", "ui", "stepActionsClass"],
45
+ features: [disablesChildren, addStepHandler]
46
+ },
47
+ {
48
+ // `createInput()` always wraps the given schema in FormKit's standard
49
+ // outer/wrapper/label/inner/help/messages chrome (`useSchema()`) - the
50
+ // `hidden` attr on our own inner div (above) only hid *that* div, while
51
+ // the auto-generated `label` section (which renders whenever `$label`
52
+ // is set - and every step needs a `label` prop so `stepName` has
53
+ // something better than the raw step name to show in the tab strip)
54
+ // is a *sibling* of it, one level up, and stayed visible regardless -
55
+ // every inactive step's label text leaked into the page between the
56
+ // active step's "Next" button and the form's own submit button. Move
57
+ // `hidden` to the actual outermost element instead, and suppress the
58
+ // redundant label section entirely (a wizard step isn't a labeled
59
+ // field - its `label` prop only feeds the tab strip's text).
60
+ outer: {
61
+ attrs: {
62
+ hidden: "$isActiveStep === false || undefined"
63
+ }
64
+ },
65
+ label: {
66
+ if: "false"
67
+ }
68
+ }
69
+ );
70
+ export const nuxtUIMultiStepDefinition = createInput(
71
+ addElement("div", [
72
+ addElement("div", [
73
+ addComponent("UTabs", {
74
+ "items": "$tabItems",
75
+ "modelValue": "$activeStep",
76
+ "content": false,
77
+ "onUpdate:modelValue": "$handleTabChange",
78
+ "ui": "$ui"
79
+ })
80
+ ], { class: "formkit-multi-step-tabs" }),
81
+ addElement("div", "$slots.default", { class: "formkit-multi-step-steps" })
82
+ ], { id: "$id" }, true),
83
+ {
84
+ type: "group",
85
+ forceTypeProp: "multi-step",
86
+ family: "NuxtUIInput",
87
+ props: ["allowIncomplete", "tabStyle", "hideProgressLabels", "validStepIcon", "beforeStepChange", "ui"],
88
+ features: [disablesChildren, addMultiStepHandler]
89
+ }
90
+ );
@@ -0,0 +1,90 @@
1
+ import { disablesChildren } from "@formkit/inputs";
2
+ import { createInput } from "@formkit/vue";
3
+ import { useFormKitMultiStep } from "../../composables/useFormKitMultiStep";
4
+ import { useFormKitSchema } from "../../composables/useFormKitSchema";
5
+ const { addElement, addComponent } = useFormKitSchema();
6
+ const { addMultiStepHandler, addStepHandler } = useFormKitMultiStep();
7
+ function addStepActionButton(label, onClick, bindAttrs, render, variant, disabled) {
8
+ return addElement("div", [
9
+ addComponent("UButton", { label, onClick, variant, disabled, ui: "$ui" }, true, { bind: bindAttrs })
10
+ ], {}, render);
11
+ }
12
+ export const nuxtUIStepDefinition = createInput(
13
+ addElement("div", [
14
+ addElement("div", "$slots.default", { class: "formkit-step-inner" }),
15
+ addElement("div", [
16
+ addStepActionButton(
17
+ { if: "$previousLabel", then: "$previousLabel", else: "Previous" },
18
+ "$handlers.previous",
19
+ "$previousAttrs",
20
+ "$isFirstStep === false",
21
+ "outline"
22
+ ),
23
+ addStepActionButton(
24
+ { if: "$nextLabel", then: "$nextLabel", else: "Next" },
25
+ "$handlers.next",
26
+ "$nextAttrs",
27
+ "$isLastStep === false || $stepIndex === 0",
28
+ void 0,
29
+ "$nextDisabled"
30
+ )
31
+ ], { class: "$internalStepActionsClass" })
32
+ ], {
33
+ "id": "$id",
34
+ "role": "tabpanel",
35
+ "aria-labelledby": '$node.parent.props.id + "_tab_" + $stepIndex'
36
+ }, true),
37
+ {
38
+ // The core node `type` (input|list|group) - not to be confused with
39
+ // `forceTypeProp` below, which is what makes `@formkit/addons`' own
40
+ // `createMultiStepPlugin` recognize this node as a `step`.
41
+ type: "group",
42
+ forceTypeProp: "step",
43
+ family: "NuxtUIInput",
44
+ props: ["beforeStepChange", "nextAttrs", "nextLabel", "previousAttrs", "previousLabel", "validStepIcon", "ui", "stepActionsClass"],
45
+ features: [disablesChildren, addStepHandler]
46
+ },
47
+ {
48
+ // `createInput()` always wraps the given schema in FormKit's standard
49
+ // outer/wrapper/label/inner/help/messages chrome (`useSchema()`) - the
50
+ // `hidden` attr on our own inner div (above) only hid *that* div, while
51
+ // the auto-generated `label` section (which renders whenever `$label`
52
+ // is set - and every step needs a `label` prop so `stepName` has
53
+ // something better than the raw step name to show in the tab strip)
54
+ // is a *sibling* of it, one level up, and stayed visible regardless -
55
+ // every inactive step's label text leaked into the page between the
56
+ // active step's "Next" button and the form's own submit button. Move
57
+ // `hidden` to the actual outermost element instead, and suppress the
58
+ // redundant label section entirely (a wizard step isn't a labeled
59
+ // field - its `label` prop only feeds the tab strip's text).
60
+ outer: {
61
+ attrs: {
62
+ hidden: "$isActiveStep === false || undefined"
63
+ }
64
+ },
65
+ label: {
66
+ if: "false"
67
+ }
68
+ }
69
+ );
70
+ export const nuxtUIMultiStepDefinition = createInput(
71
+ addElement("div", [
72
+ addElement("div", [
73
+ addComponent("UTabs", {
74
+ "items": "$tabItems",
75
+ "modelValue": "$activeStep",
76
+ "content": false,
77
+ "onUpdate:modelValue": "$handleTabChange",
78
+ "ui": "$ui"
79
+ })
80
+ ], { class: "formkit-multi-step-tabs" }),
81
+ addElement("div", "$slots.default", { class: "formkit-multi-step-steps" })
82
+ ], { id: "$id" }, true),
83
+ {
84
+ type: "group",
85
+ forceTypeProp: "multi-step",
86
+ family: "NuxtUIInput",
87
+ props: ["allowIncomplete", "tabStyle", "hideProgressLabels", "validStepIcon", "beforeStepChange", "ui"],
88
+ features: [disablesChildren, addMultiStepHandler]
89
+ }
90
+ );