@sfxcode/nuxt-ui-formkit 1.0.1 → 1.0.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.
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "1.0.1",
7
+ "version": "1.0.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -1,40 +1,58 @@
1
1
  import { createInput } from "@formkit/vue";
2
2
  import { useFormKitSchema } from "../../composables/useFormKitSchema.js";
3
- const { addList, addElement, addListGroup, addComponent, addElementsInOuterDiv } = useFormKitSchema();
4
- function addActionButtons(innerClass = "", outerClass = "", label, help = "", render = "true") {
5
- const addButtonComponent = (onClick = "", icon = "", color = "", render2 = "true", disabled) => {
6
- return addComponent("UButton", { onClick, icon, color, disabled }, render2);
3
+ const { addList, addElement, addListGroup, addComponent } = useFormKitSchema();
4
+ function addButtonGroup(buttonGroupClass = "", buttonGroupItemClass = "", buttonSize, render = "true") {
5
+ const addActionButtonComponent = (onClick = "", icon = "", color = "", render2 = "true", disabled) => {
6
+ return addElement("div", [addComponent("UButton", { onClick, icon, color, disabled, size: buttonSize })], { class: buttonGroupItemClass }, render2);
7
7
  };
8
- return addElementsInOuterDiv([
9
- addButtonComponent("$removeNode($node.parent, $index)", "i-lucide-x", "error"),
10
- addButtonComponent("$cloneNode($node.parent, $index)", "i-lucide-copy", "secondary", "$displayCloneButton"),
11
- addButtonComponent("$moveNodeDown($node.parent, $index)", "i-lucide-arrow-down", "primary", "true", "$index === $node.parent.value.length -1"),
12
- addButtonComponent("$moveNodeUp($node.parent, $index)", "i-lucide-arrow-up", "primary", "true", "$index === 0")
13
- ], innerClass, outerClass, label, help, render);
8
+ return addElement("div", [
9
+ addActionButtonComponent("$moveNodeUp($node.parent, $index)", "i-lucide-arrow-up", "primary", "$renderMoveButtons", "$index === 0"),
10
+ addActionButtonComponent("$removeNode($node.parent, $index)", "i-lucide-trash", "error", "$displayDeleteButton"),
11
+ addActionButtonComponent("$cloneNode($node.parent, $index)", "i-lucide-copy", "secondary", "$displayCloneButton"),
12
+ addActionButtonComponent("$addNode($node.parent, $index)", "i-lucide-plus", "secondary", "$displayAddButton"),
13
+ addActionButtonComponent("$moveNodeDown($node.parent, $index)", "i-lucide-arrow-down", "primary", "$renderMoveButtons", "$index === $node.parent.value.length -1")
14
+ ], { class: buttonGroupClass }, render);
14
15
  }
15
- function addInsertButton(label = "Add Item", icon = "i-lucide-plus", styleClass = "", render = "true") {
16
+ function addInsertButton(label = "Add Item", icon = "i-lucide-plus", styleClass = "", buttonSize, render = "true") {
16
17
  return addElement("div", [
17
- addComponent("UButton", { onClick: "$addNode($node)", label, icon })
18
+ addComponent("UButton", { onClick: "$insertNode($node)", label, icon, size: buttonSize })
18
19
  ], { class: styleClass }, render);
19
20
  }
20
21
  export const nuxtUIRepeaterDefinition = createInput(
21
22
  [
22
23
  addElement("div", [
23
24
  addList("$listName", [
24
- addInsertButton("$addButtonLabel", "i-lucide-plus", "$addButtonClass", "$node.children.length == 0 || $alwaysDisplayAddButton"),
25
- addListGroup([
26
- addElement("div", [
27
- {
28
- children: "$slots.default"
29
- },
30
- addActionButtons("$buttonsInnerClass", "$buttonsOuterClass", "$buttonsLabel")
31
- ], { class: "$itemClass" })
32
- ])
25
+ addInsertButton("$insertButtonLabel", "i-lucide-plus", "$insertButtonClass", "$insertButtonSize", "$node.children.length == 0 || $alwaysDisplayInsertButton"),
26
+ addListGroup(
27
+ [
28
+ addElement("div", [
29
+ addElement("div", [{ children: "$slots.default" }], { class: "$groupClass" }),
30
+ addButtonGroup("$buttonGroupClass", "$buttonGroupItemClass", "$buttonSize", "$renderButtons")
31
+ ], { class: "$listItemClass" })
32
+ ]
33
+ )
33
34
  ], true, "true")
34
35
  ], { class: "$listClass" })
35
36
  ],
36
37
  {
37
- props: ["buttonsOuterClass", "buttonsInnerClass", "buttonsLabel", "addButtonLabel", "addButtonClass", "newItem", "itemClass", "listClass", "displayCloneButton", "alwaysDisplayAddButton"],
38
+ props: [
39
+ "insertButtonLabel",
40
+ "insertButtonClass",
41
+ "insertButtonSize",
42
+ "alwaysDisplayInsertButton",
43
+ "newItem",
44
+ "listClass",
45
+ "listItemClass",
46
+ "groupClass",
47
+ "hideButtonGroup",
48
+ "hideMoveButtons",
49
+ "buttonGroupClass",
50
+ "buttonGroupItemClass",
51
+ "buttonSize",
52
+ "displayCloneButton",
53
+ "displayAddButton",
54
+ "displayDeleteButton"
55
+ ],
38
56
  features: [addRepeaterHandler]
39
57
  }
40
58
  );
@@ -48,21 +66,33 @@ function addRepeaterHandler(node) {
48
66
  };
49
67
  node.on("created", () => {
50
68
  node.context.listName = node.name;
69
+ node.context.renderButtons = !node.context.hideButtonGroup;
70
+ node.context.insertButtonSize = node.context.insertButtonSize ? node.context.insertButtonSize : "md";
71
+ node.context.buttonSize = node.context.buttonSize ? node.context.buttonSize : "md";
72
+ node.context.renderMoveButtons = !node.context.hideMoveButtons;
73
+ node.context.insertNode = (parentNode) => () => {
74
+ if (parentNode && parentNode._value instanceof Array) {
75
+ const item = node.context.newItem ? { ...node.context.newItem } : {};
76
+ const newArray = [item, ...parentNode.value];
77
+ parentNode.input(newArray, false);
78
+ }
79
+ };
51
80
  node.context.removeNode = (parentNode, index) => () => {
52
81
  if (parentNode && parentNode._value instanceof Array) {
53
82
  parentNode.input(parentNode._value.filter((_, i) => i !== index), false);
54
83
  }
55
84
  };
56
- node.context.addNode = (parentNode) => () => {
85
+ node.context.addNode = (parentNode, index) => () => {
57
86
  if (parentNode && parentNode._value instanceof Array) {
58
- const newArray = [...parentNode.value, node.context.newItem || {}];
59
- parentNode.input(newArray, false);
87
+ const item = node.context.newItem ? { ...node.context.newItem } : {};
88
+ const newArray = [...parentNode.value.slice(0, index + 1), { ...item }, ...parentNode.value.slice(index + 1)];
89
+ parentNode.input([...newArray], false);
60
90
  }
61
91
  };
62
92
  node.context.cloneNode = (parentNode, index) => () => {
63
93
  if (parentNode && parentNode._value instanceof Array) {
64
94
  const item = parentNode.value[index];
65
- const newArray = [...parentNode.value.slice(0, index), { ...item }, ...parentNode.value.slice(index)];
95
+ const newArray = [...parentNode.value.slice(0, index + 1), { ...item }, ...parentNode.value.slice(index + 1)];
66
96
  parentNode.input([...newArray], false);
67
97
  }
68
98
  };
@@ -1,40 +1,58 @@
1
1
  import { createInput } from "@formkit/vue";
2
2
  import { useFormKitSchema } from "../../composables/useFormKitSchema";
3
- const { addList, addElement, addListGroup, addComponent, addElementsInOuterDiv } = useFormKitSchema();
4
- function addActionButtons(innerClass = "", outerClass = "", label, help = "", render = "true") {
5
- const addButtonComponent = (onClick = "", icon = "", color = "", render2 = "true", disabled) => {
6
- return addComponent("UButton", { onClick, icon, color, disabled }, render2);
3
+ const { addList, addElement, addListGroup, addComponent } = useFormKitSchema();
4
+ function addButtonGroup(buttonGroupClass = "", buttonGroupItemClass = "", buttonSize, render = "true") {
5
+ const addActionButtonComponent = (onClick = "", icon = "", color = "", render2 = "true", disabled) => {
6
+ return addElement("div", [addComponent("UButton", { onClick, icon, color, disabled, size: buttonSize })], { class: buttonGroupItemClass }, render2);
7
7
  };
8
- return addElementsInOuterDiv([
9
- addButtonComponent("$removeNode($node.parent, $index)", "i-lucide-x", "error"),
10
- addButtonComponent("$cloneNode($node.parent, $index)", "i-lucide-copy", "secondary", "$displayCloneButton"),
11
- addButtonComponent("$moveNodeDown($node.parent, $index)", "i-lucide-arrow-down", "primary", "true", "$index === $node.parent.value.length -1"),
12
- addButtonComponent("$moveNodeUp($node.parent, $index)", "i-lucide-arrow-up", "primary", "true", "$index === 0")
13
- ], innerClass, outerClass, label, help, render);
8
+ return addElement("div", [
9
+ addActionButtonComponent("$moveNodeUp($node.parent, $index)", "i-lucide-arrow-up", "primary", "$renderMoveButtons", "$index === 0"),
10
+ addActionButtonComponent("$removeNode($node.parent, $index)", "i-lucide-trash", "error", "$displayDeleteButton"),
11
+ addActionButtonComponent("$cloneNode($node.parent, $index)", "i-lucide-copy", "secondary", "$displayCloneButton"),
12
+ addActionButtonComponent("$addNode($node.parent, $index)", "i-lucide-plus", "secondary", "$displayAddButton"),
13
+ addActionButtonComponent("$moveNodeDown($node.parent, $index)", "i-lucide-arrow-down", "primary", "$renderMoveButtons", "$index === $node.parent.value.length -1")
14
+ ], { class: buttonGroupClass }, render);
14
15
  }
15
- function addInsertButton(label = "Add Item", icon = "i-lucide-plus", styleClass = "", render = "true") {
16
+ function addInsertButton(label = "Add Item", icon = "i-lucide-plus", styleClass = "", buttonSize, render = "true") {
16
17
  return addElement("div", [
17
- addComponent("UButton", { onClick: "$addNode($node)", label, icon })
18
+ addComponent("UButton", { onClick: "$insertNode($node)", label, icon, size: buttonSize })
18
19
  ], { class: styleClass }, render);
19
20
  }
20
21
  export const nuxtUIRepeaterDefinition = createInput(
21
22
  [
22
23
  addElement("div", [
23
24
  addList("$listName", [
24
- addInsertButton("$addButtonLabel", "i-lucide-plus", "$addButtonClass", "$node.children.length == 0 || $alwaysDisplayAddButton"),
25
- addListGroup([
26
- addElement("div", [
27
- {
28
- children: "$slots.default"
29
- },
30
- addActionButtons("$buttonsInnerClass", "$buttonsOuterClass", "$buttonsLabel")
31
- ], { class: "$itemClass" })
32
- ])
25
+ addInsertButton("$insertButtonLabel", "i-lucide-plus", "$insertButtonClass", "$insertButtonSize", "$node.children.length == 0 || $alwaysDisplayInsertButton"),
26
+ addListGroup(
27
+ [
28
+ addElement("div", [
29
+ addElement("div", [{ children: "$slots.default" }], { class: "$groupClass" }),
30
+ addButtonGroup("$buttonGroupClass", "$buttonGroupItemClass", "$buttonSize", "$renderButtons")
31
+ ], { class: "$listItemClass" })
32
+ ]
33
+ )
33
34
  ], true, "true")
34
35
  ], { class: "$listClass" })
35
36
  ],
36
37
  {
37
- props: ["buttonsOuterClass", "buttonsInnerClass", "buttonsLabel", "addButtonLabel", "addButtonClass", "newItem", "itemClass", "listClass", "displayCloneButton", "alwaysDisplayAddButton"],
38
+ props: [
39
+ "insertButtonLabel",
40
+ "insertButtonClass",
41
+ "insertButtonSize",
42
+ "alwaysDisplayInsertButton",
43
+ "newItem",
44
+ "listClass",
45
+ "listItemClass",
46
+ "groupClass",
47
+ "hideButtonGroup",
48
+ "hideMoveButtons",
49
+ "buttonGroupClass",
50
+ "buttonGroupItemClass",
51
+ "buttonSize",
52
+ "displayCloneButton",
53
+ "displayAddButton",
54
+ "displayDeleteButton"
55
+ ],
38
56
  features: [addRepeaterHandler]
39
57
  }
40
58
  );
@@ -48,21 +66,33 @@ function addRepeaterHandler(node) {
48
66
  };
49
67
  node.on("created", () => {
50
68
  node.context.listName = node.name;
69
+ node.context.renderButtons = !node.context.hideButtonGroup;
70
+ node.context.insertButtonSize = node.context.insertButtonSize ? node.context.insertButtonSize : "md";
71
+ node.context.buttonSize = node.context.buttonSize ? node.context.buttonSize : "md";
72
+ node.context.renderMoveButtons = !node.context.hideMoveButtons;
73
+ node.context.insertNode = (parentNode) => () => {
74
+ if (parentNode && parentNode._value instanceof Array) {
75
+ const item = node.context.newItem ? { ...node.context.newItem } : {};
76
+ const newArray = [item, ...parentNode.value];
77
+ parentNode.input(newArray, false);
78
+ }
79
+ };
51
80
  node.context.removeNode = (parentNode, index) => () => {
52
81
  if (parentNode && parentNode._value instanceof Array) {
53
82
  parentNode.input(parentNode._value.filter((_, i) => i !== index), false);
54
83
  }
55
84
  };
56
- node.context.addNode = (parentNode) => () => {
85
+ node.context.addNode = (parentNode, index) => () => {
57
86
  if (parentNode && parentNode._value instanceof Array) {
58
- const newArray = [...parentNode.value, node.context.newItem || {}];
59
- parentNode.input(newArray, false);
87
+ const item = node.context.newItem ? { ...node.context.newItem } : {};
88
+ const newArray = [...parentNode.value.slice(0, index + 1), { ...item }, ...parentNode.value.slice(index + 1)];
89
+ parentNode.input([...newArray], false);
60
90
  }
61
91
  };
62
92
  node.context.cloneNode = (parentNode, index) => () => {
63
93
  if (parentNode && parentNode._value instanceof Array) {
64
94
  const item = parentNode.value[index];
65
- const newArray = [...parentNode.value.slice(0, index), { ...item }, ...parentNode.value.slice(index)];
95
+ const newArray = [...parentNode.value.slice(0, index + 1), { ...item }, ...parentNode.value.slice(index + 1)];
66
96
  parentNode.input([...newArray], false);
67
97
  }
68
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-ui-formkit",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "FormKit integration for Nuxt UI - Seamlessly connect FormKit form handling with Nuxt UI components",
5
5
  "author": {
6
6
  "name": "Tom",