@sfxcode/nuxt-ui-formkit 1.2.1 → 1.2.3

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 (44) hide show
  1. package/README.md +24 -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 +11 -1
  8. package/dist/runtime/components/FUDataEdit.vue +13 -2
  9. package/dist/runtime/components/FUDataEdit.vue.d.ts +11 -1
  10. package/dist/runtime/components/FUDataView.d.vue.ts +1 -1
  11. package/dist/runtime/components/FUDataView.vue.d.ts +1 -1
  12. package/dist/runtime/composables/useFormKitAutoForm.d.ts +38 -0
  13. package/dist/runtime/composables/useFormKitAutoForm.js +349 -0
  14. package/dist/runtime/composables/useFormKitForm.d.ts +15 -0
  15. package/dist/runtime/composables/useFormKitForm.js +44 -0
  16. package/dist/runtime/composables/useFormKitMultiStep.d.ts +5 -0
  17. package/dist/runtime/composables/useFormKitMultiStep.js +65 -0
  18. package/dist/runtime/composables/useFormKitRepeater.d.ts +4 -0
  19. package/dist/runtime/composables/useFormKitRepeater.js +138 -0
  20. package/dist/runtime/composables/useFormKitStandardSchema.d.ts +20 -0
  21. package/dist/runtime/composables/useFormKitStandardSchema.js +68 -0
  22. package/dist/runtime/formkit/createNuxtUiFormkitConfig.d.ts +19 -0
  23. package/dist/runtime/formkit/createNuxtUiFormkitConfig.js +12 -0
  24. package/dist/runtime/formkit/createNuxtUiFormkitConfig.mjs +12 -0
  25. package/dist/runtime/formkit/definitions/index.d.ts +3 -0
  26. package/dist/runtime/formkit/definitions/index.js +4 -0
  27. package/dist/runtime/formkit/definitions/index.mjs +4 -0
  28. package/dist/runtime/formkit/definitions/multiStep.d.ts +3 -0
  29. package/dist/runtime/formkit/definitions/multiStep.js +90 -0
  30. package/dist/runtime/formkit/definitions/multiStep.mjs +90 -0
  31. package/dist/runtime/formkit/definitions/repeater.js +3 -119
  32. package/dist/runtime/formkit/definitions/repeater.mjs +3 -119
  33. package/dist/runtime/formkit/index.d.ts +10 -0
  34. package/dist/runtime/formkit/index.js +1 -0
  35. package/dist/runtime/formkit/index.mjs +1 -0
  36. package/dist/runtime/formkit/plugins/index.d.ts +1 -0
  37. package/dist/runtime/formkit/plugins/index.js +1 -0
  38. package/dist/runtime/formkit/plugins/index.mjs +1 -0
  39. package/dist/runtime/plugin.js +2 -1
  40. package/dist/runtime/utils/dateValueConversion.d.ts +8 -7
  41. package/dist/runtime/utils/dateValueConversion.js +1 -1
  42. package/dist/runtime/utils/standardSchemaErrors.d.ts +14 -0
  43. package/dist/runtime/utils/standardSchemaErrors.js +15 -0
  44. package/package.json +6 -2
@@ -0,0 +1,68 @@
1
+ import { createMessage, isNode } from "@formkit/core";
2
+ import { issuesToFormKitErrors } from "../utils/standardSchemaErrors.js";
3
+ const STANDARD_SCHEMA_SOURCE = "standard-schema";
4
+ function isStandardSchemaMessage(message) {
5
+ return message.meta.source === STANDARD_SCHEMA_SOURCE;
6
+ }
7
+ function clearStandardSchemaMessages(node) {
8
+ node.store.filter((message) => !isStandardSchemaMessage(message), "validation");
9
+ }
10
+ function setStandardSchemaMessages(node, values) {
11
+ clearStandardSchemaMessages(node);
12
+ values.forEach((value, index) => {
13
+ node.store.set(createMessage({
14
+ key: `standard_schema_${index}`,
15
+ type: "validation",
16
+ blocking: true,
17
+ value,
18
+ meta: { source: STANDARD_SCHEMA_SOURCE }
19
+ }));
20
+ });
21
+ }
22
+ function resolveAddress(root, address) {
23
+ let pointer = root;
24
+ for (const segment of address.split(root.config.delimiter)) {
25
+ if (!pointer)
26
+ return void 0;
27
+ const matches = pointer.children.filter(isNode).filter((child) => String(child.name) === segment);
28
+ pointer = matches.find((child) => child.type !== "input") ?? matches[0];
29
+ }
30
+ return pointer;
31
+ }
32
+ export function attachStandardSchema(node, schema) {
33
+ let previousAddresses = /* @__PURE__ */ new Set();
34
+ let runToken = 0;
35
+ async function validate() {
36
+ const token = ++runToken;
37
+ const result = await schema["~standard"].validate(node.value);
38
+ if (token !== runToken)
39
+ return;
40
+ const { localErrors, childErrors } = issuesToFormKitErrors(result.issues ?? []);
41
+ setStandardSchemaMessages(node, localErrors);
42
+ const currentAddresses = new Set(Object.keys(childErrors));
43
+ for (const address of previousAddresses) {
44
+ if (currentAddresses.has(address))
45
+ continue;
46
+ const target = resolveAddress(node, address);
47
+ if (target)
48
+ clearStandardSchemaMessages(target);
49
+ }
50
+ for (const [address, messages] of Object.entries(childErrors)) {
51
+ const target = resolveAddress(node, address);
52
+ if (target)
53
+ setStandardSchemaMessages(target, messages);
54
+ }
55
+ previousAddresses = currentAddresses;
56
+ }
57
+ const receipt = node.on("commit", () => void validate());
58
+ void validate();
59
+ return function detachStandardSchema() {
60
+ node.off(receipt);
61
+ clearStandardSchemaMessages(node);
62
+ for (const address of previousAddresses) {
63
+ const target = resolveAddress(node, address);
64
+ if (target)
65
+ clearStandardSchemaMessages(target);
66
+ }
67
+ };
68
+ }
@@ -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
+ );
@@ -1,6 +1,8 @@
1
1
  import { createInput } from "@formkit/vue";
2
+ import { useFormKitRepeater } from "../../composables/useFormKitRepeater.js";
2
3
  import { useFormKitSchema } from "../../composables/useFormKitSchema.js";
3
4
  const { addList, addElement, addListGroup, addComponent } = useFormKitSchema();
5
+ const { addRepeaterHandler } = useFormKitRepeater();
4
6
  function addButtonGroup(buttonGroupClass = "", buttonGroupItemClass = "", buttonSize, render = "true") {
5
7
  const addActionButtonComponent = (onClick = "", icon = "", color = "", render2 = "true", disabled = "false") => {
6
8
  return addElement("div", [addComponent("UButton", { onClick, icon, color, disabled, size: buttonSize })], { class: buttonGroupItemClass }, render2);
@@ -53,7 +55,7 @@ export const nuxtUIRepeaterDefinition = createInput(
53
55
  onDragend: "$dragNodeEnd"
54
56
  })
55
57
  ], true, {})
56
- ], true, "true", { value: "$value" })
58
+ ], true, "true", { value: "$value", validation: "$repeaterValidation" })
57
59
  ], { class: "$internalListClass", id: "$internalListId" }, true),
58
60
  {
59
61
  props: [
@@ -82,121 +84,3 @@ export const nuxtUIRepeaterDefinition = createInput(
82
84
  features: [addRepeaterHandler]
83
85
  }
84
86
  );
85
- function addRepeaterHandler(node) {
86
- const swapElements = (array, index1, index2) => {
87
- const [element] = array.splice(index1, 1);
88
- if (element !== void 0) {
89
- array.splice(index2, 0, element);
90
- }
91
- return array;
92
- };
93
- const uuid = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2);
94
- node.on("created", () => {
95
- if (node.context) {
96
- let dragStartIndex = null;
97
- let dragOverIndex = null;
98
- const newItem = node.context.newItem || {};
99
- node.context.listName = node.name;
100
- node.context.renderButtons = !node.context.hideButtonGroup;
101
- node.context.insertButtonSize = node.context.insertButtonSize ? node.context.insertButtonSize : "md";
102
- node.context.buttonSize = node.context.buttonSize ? node.context.buttonSize : "md";
103
- node.context.renderMoveButtons = !node.context.hideMoveButtons;
104
- node.context.draggable = !!node.context.draggable;
105
- node.context.renderDragHandle = !!node.context.displayDragHandle;
106
- node.context.dragHandleIconName = node.context.dragHandleIconName || "i-lucide-grip-vertical";
107
- node.context.internalDragHandleClass = node.context.dragHandleClass ? `formkit-repeater-drag-handle ${node.context.dragHandleClass}` : "formkit-repeater-drag-handle";
108
- node.context.internalListClass = node.context.listClass ? `formkit-items ${node.context.listClass}` : "formkit-items";
109
- node.context.internalListItemClass = node.context.listItemClass ? `formkit-item ${node.context.listItemClass}` : "formkit-item";
110
- node.context.internalListId = `formkit-items-${uuid}`;
111
- node.context.minItems = node.context.minItems !== void 0 ? node.context.minItems : 0;
112
- node.context.maxItems = node.context.maxItems !== void 0 ? node.context.maxItems : Number.POSITIVE_INFINITY;
113
- node.context.getListItemClass = (index) => {
114
- if (dragOverIndex === index && dragStartIndex !== index)
115
- return `${node.context?.internalListItemClass} formkit-repeater-drop-target`;
116
- return node.context?.internalListItemClass?.toString() ?? "";
117
- };
118
- node.context.getListItemId = (index) => {
119
- return `formkit-item-${index}-${uuid}`;
120
- };
121
- node.context.insertNode = (parentNode) => () => {
122
- if (parentNode && Array.isArray(parentNode._value)) {
123
- const newArray = [{ ...newItem }, ...parentNode.value];
124
- parentNode.input(newArray, false);
125
- }
126
- };
127
- node.context.removeNode = (parentNode, index) => () => {
128
- if (parentNode && Array.isArray(parentNode._value)) {
129
- parentNode.input(parentNode._value.filter((_, i) => i !== index), false);
130
- }
131
- };
132
- node.context.addNode = (parentNode, index) => () => {
133
- if (parentNode && Array.isArray(parentNode._value)) {
134
- const array = parentNode.value;
135
- array.splice(index + 1, 0, { ...newItem });
136
- parentNode.input(array, false);
137
- }
138
- };
139
- node.context.cloneNode = (parentNode, index) => () => {
140
- if (parentNode && Array.isArray(parentNode._value)) {
141
- const item = parentNode.value[index];
142
- const array = parentNode.value;
143
- array.splice(index + 1, 0, { ...item });
144
- parentNode.input(array, false);
145
- }
146
- };
147
- node.context.moveNodeUp = (parentNode, index) => () => {
148
- if (parentNode && Array.isArray(parentNode._value)) {
149
- if (index > 0)
150
- parentNode.input(swapElements(parentNode.value, index - 1, index), false);
151
- }
152
- };
153
- node.context.moveNodeDown = (parentNode, index) => () => {
154
- if (parentNode && Array.isArray(parentNode._value)) {
155
- if (index < parentNode.value.length - 1)
156
- parentNode.input(swapElements(parentNode.value, index, index + 1), false);
157
- }
158
- };
159
- node.context.dragNodeStart = (_parentNode, index) => (event) => {
160
- dragStartIndex = index;
161
- if (event?.dataTransfer) {
162
- event.dataTransfer.effectAllowed = "move";
163
- event.dataTransfer.setData("text/plain", String(index));
164
- }
165
- };
166
- node.context.dragNodeOver = (targetIndex) => (event) => {
167
- event?.preventDefault();
168
- dragOverIndex = targetIndex;
169
- if (event?.dataTransfer)
170
- event.dataTransfer.dropEffect = "move";
171
- };
172
- node.context.dragNodeLeave = (targetIndex) => () => {
173
- if (dragOverIndex === targetIndex)
174
- dragOverIndex = null;
175
- };
176
- node.context.dropNode = (parentNode, targetIndex) => (event) => {
177
- event?.preventDefault();
178
- if (!parentNode || !Array.isArray(parentNode._value)) {
179
- dragOverIndex = null;
180
- return;
181
- }
182
- const sourceFromEvent = Number.parseInt(event?.dataTransfer?.getData("text/plain") || "", 10);
183
- const sourceIndex = Number.isInteger(sourceFromEvent) ? sourceFromEvent : dragStartIndex;
184
- if (sourceIndex === null || sourceIndex === targetIndex) {
185
- dragOverIndex = null;
186
- return;
187
- }
188
- if (sourceIndex < 0 || sourceIndex >= parentNode.value.length) {
189
- dragOverIndex = null;
190
- return;
191
- }
192
- parentNode.input(swapElements(parentNode.value, sourceIndex, targetIndex), false);
193
- dragStartIndex = null;
194
- dragOverIndex = null;
195
- };
196
- node.context.dragNodeEnd = () => {
197
- dragStartIndex = null;
198
- dragOverIndex = null;
199
- };
200
- }
201
- });
202
- }
@@ -1,6 +1,8 @@
1
1
  import { createInput } from "@formkit/vue";
2
+ import { useFormKitRepeater } from "../../composables/useFormKitRepeater";
2
3
  import { useFormKitSchema } from "../../composables/useFormKitSchema";
3
4
  const { addList, addElement, addListGroup, addComponent } = useFormKitSchema();
5
+ const { addRepeaterHandler } = useFormKitRepeater();
4
6
  function addButtonGroup(buttonGroupClass = "", buttonGroupItemClass = "", buttonSize, render = "true") {
5
7
  const addActionButtonComponent = (onClick = "", icon = "", color = "", render2 = "true", disabled = "false") => {
6
8
  return addElement("div", [addComponent("UButton", { onClick, icon, color, disabled, size: buttonSize })], { class: buttonGroupItemClass }, render2);
@@ -53,7 +55,7 @@ export const nuxtUIRepeaterDefinition = createInput(
53
55
  onDragend: "$dragNodeEnd"
54
56
  })
55
57
  ], true, {})
56
- ], true, "true", { value: "$value" })
58
+ ], true, "true", { value: "$value", validation: "$repeaterValidation" })
57
59
  ], { class: "$internalListClass", id: "$internalListId" }, true),
58
60
  {
59
61
  props: [
@@ -82,121 +84,3 @@ export const nuxtUIRepeaterDefinition = createInput(
82
84
  features: [addRepeaterHandler]
83
85
  }
84
86
  );
85
- function addRepeaterHandler(node) {
86
- const swapElements = (array, index1, index2) => {
87
- const [element] = array.splice(index1, 1);
88
- if (element !== void 0) {
89
- array.splice(index2, 0, element);
90
- }
91
- return array;
92
- };
93
- const uuid = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2);
94
- node.on("created", () => {
95
- if (node.context) {
96
- let dragStartIndex = null;
97
- let dragOverIndex = null;
98
- const newItem = node.context.newItem || {};
99
- node.context.listName = node.name;
100
- node.context.renderButtons = !node.context.hideButtonGroup;
101
- node.context.insertButtonSize = node.context.insertButtonSize ? node.context.insertButtonSize : "md";
102
- node.context.buttonSize = node.context.buttonSize ? node.context.buttonSize : "md";
103
- node.context.renderMoveButtons = !node.context.hideMoveButtons;
104
- node.context.draggable = !!node.context.draggable;
105
- node.context.renderDragHandle = !!node.context.displayDragHandle;
106
- node.context.dragHandleIconName = node.context.dragHandleIconName || "i-lucide-grip-vertical";
107
- node.context.internalDragHandleClass = node.context.dragHandleClass ? `formkit-repeater-drag-handle ${node.context.dragHandleClass}` : "formkit-repeater-drag-handle";
108
- node.context.internalListClass = node.context.listClass ? `formkit-items ${node.context.listClass}` : "formkit-items";
109
- node.context.internalListItemClass = node.context.listItemClass ? `formkit-item ${node.context.listItemClass}` : "formkit-item";
110
- node.context.internalListId = `formkit-items-${uuid}`;
111
- node.context.minItems = node.context.minItems !== void 0 ? node.context.minItems : 0;
112
- node.context.maxItems = node.context.maxItems !== void 0 ? node.context.maxItems : Number.POSITIVE_INFINITY;
113
- node.context.getListItemClass = (index) => {
114
- if (dragOverIndex === index && dragStartIndex !== index)
115
- return `${node.context?.internalListItemClass} formkit-repeater-drop-target`;
116
- return node.context?.internalListItemClass?.toString() ?? "";
117
- };
118
- node.context.getListItemId = (index) => {
119
- return `formkit-item-${index}-${uuid}`;
120
- };
121
- node.context.insertNode = (parentNode) => () => {
122
- if (parentNode && Array.isArray(parentNode._value)) {
123
- const newArray = [{ ...newItem }, ...parentNode.value];
124
- parentNode.input(newArray, false);
125
- }
126
- };
127
- node.context.removeNode = (parentNode, index) => () => {
128
- if (parentNode && Array.isArray(parentNode._value)) {
129
- parentNode.input(parentNode._value.filter((_, i) => i !== index), false);
130
- }
131
- };
132
- node.context.addNode = (parentNode, index) => () => {
133
- if (parentNode && Array.isArray(parentNode._value)) {
134
- const array = parentNode.value;
135
- array.splice(index + 1, 0, { ...newItem });
136
- parentNode.input(array, false);
137
- }
138
- };
139
- node.context.cloneNode = (parentNode, index) => () => {
140
- if (parentNode && Array.isArray(parentNode._value)) {
141
- const item = parentNode.value[index];
142
- const array = parentNode.value;
143
- array.splice(index + 1, 0, { ...item });
144
- parentNode.input(array, false);
145
- }
146
- };
147
- node.context.moveNodeUp = (parentNode, index) => () => {
148
- if (parentNode && Array.isArray(parentNode._value)) {
149
- if (index > 0)
150
- parentNode.input(swapElements(parentNode.value, index - 1, index), false);
151
- }
152
- };
153
- node.context.moveNodeDown = (parentNode, index) => () => {
154
- if (parentNode && Array.isArray(parentNode._value)) {
155
- if (index < parentNode.value.length - 1)
156
- parentNode.input(swapElements(parentNode.value, index, index + 1), false);
157
- }
158
- };
159
- node.context.dragNodeStart = (_parentNode, index) => (event) => {
160
- dragStartIndex = index;
161
- if (event?.dataTransfer) {
162
- event.dataTransfer.effectAllowed = "move";
163
- event.dataTransfer.setData("text/plain", String(index));
164
- }
165
- };
166
- node.context.dragNodeOver = (targetIndex) => (event) => {
167
- event?.preventDefault();
168
- dragOverIndex = targetIndex;
169
- if (event?.dataTransfer)
170
- event.dataTransfer.dropEffect = "move";
171
- };
172
- node.context.dragNodeLeave = (targetIndex) => () => {
173
- if (dragOverIndex === targetIndex)
174
- dragOverIndex = null;
175
- };
176
- node.context.dropNode = (parentNode, targetIndex) => (event) => {
177
- event?.preventDefault();
178
- if (!parentNode || !Array.isArray(parentNode._value)) {
179
- dragOverIndex = null;
180
- return;
181
- }
182
- const sourceFromEvent = Number.parseInt(event?.dataTransfer?.getData("text/plain") || "", 10);
183
- const sourceIndex = Number.isInteger(sourceFromEvent) ? sourceFromEvent : dragStartIndex;
184
- if (sourceIndex === null || sourceIndex === targetIndex) {
185
- dragOverIndex = null;
186
- return;
187
- }
188
- if (sourceIndex < 0 || sourceIndex >= parentNode.value.length) {
189
- dragOverIndex = null;
190
- return;
191
- }
192
- parentNode.input(swapElements(parentNode.value, sourceIndex, targetIndex), false);
193
- dragStartIndex = null;
194
- dragOverIndex = null;
195
- };
196
- node.context.dragNodeEnd = () => {
197
- dragStartIndex = null;
198
- dragOverIndex = null;
199
- };
200
- }
201
- });
202
- }