@sfxcode/formkit-openvue 0.8.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -49,7 +49,7 @@ Migrating from `@sfxcode/formkit-primevue` to `@sfxcode/formkit-openvue`:
49
49
 
50
50
  5. Update custom CSS: selectors like `[data-type="primeCheckbox"]` become `[data-type="formCheckbox"]`.
51
51
 
52
- Also rename the `primeAttributes` prop to `formAttributes` (`prime-attributes` to `form-attributes` in templates). Rename the i18n keys `formkit.prime.true` / `formkit.prime.false` to `formkit.form.true` / `formkit.form.false`. Not changed: the `p-formkit` wrapper class. The stylesheet is now `formkit-openvue.scss` (update imports of `dist/sass/formkit-primevue.scss`).
52
+ Also rename the i18n keys `formkit.prime.true` / `formkit.prime.false` to `formkit.form.true` / `formkit.form.false`. If you use `useInputEditor`, its data fields `prime`, `prime_key` and `prime_value` are now `form`, `form_key` and `form_value`. The stylesheet is now `formkit-openvue.scss` (update imports of `dist/sass/formkit-primevue.scss`). Not changed: the `p-formkit` wrapper class.
53
53
 
54
54
  ## Build
55
55
 
@@ -63,6 +63,64 @@ Also rename the `primeAttributes` prop to `formAttributes` (`prime-attributes` t
63
63
 
64
64
  [Demo/Playground](https://formkit-openvue.netlify.app/)
65
65
 
66
+ ## Getting Started
67
+
68
+ Install the latest release of [`@sfxcode/formkit-openvue`](https://www.npmjs.com/package/@sfxcode/formkit-openvue) together with OpenVue:
69
+
70
+ ```bash
71
+ pnpm add @sfxcode/formkit-openvue openvue @openvue/themes @openvue/openicons
72
+ # or: npm install ... / yarn add ...
73
+ ```
74
+
75
+ Set up OpenVue, FormKit and the form inputs in your *main.ts*:
76
+
77
+ ```typescript
78
+ import Aura from '@openvue/themes/aura'
79
+ import { defaultConfig, plugin } from '@formkit/vue'
80
+ import { formInputs, useFormInputs } from '@sfxcode/formkit-openvue'
81
+ import OpenVue from 'openvue/config'
82
+ import { createApp } from 'vue'
83
+ import App from './App.vue'
84
+ import '@openvue/openicons/openicons.css'
85
+ import '@sfxcode/formkit-openvue/dist/style.css'
86
+
87
+ const app = createApp(App)
88
+
89
+ // OpenVue with theme
90
+ app.use(OpenVue, { theme: { preset: Aura } })
91
+
92
+ // register the OpenVue components used by the form inputs
93
+ const { registerInputs } = useFormInputs()
94
+ registerInputs(app)
95
+
96
+ // FormKit with the OpenVue inputs
97
+ app.use(plugin, defaultConfig({ inputs: formInputs }))
98
+
99
+ app.mount('#app')
100
+ ```
101
+
102
+ Use the inputs in a FormKit schema (or as `<FormKit type="formInputText" ... />`):
103
+
104
+ ```vue
105
+ <script setup lang="ts">
106
+ import { ref } from 'vue'
107
+
108
+ const data = ref({ email: '' })
109
+ const schema = [
110
+ { $formkit: 'formInputText', name: 'email', label: 'Email', validation: 'required|email' },
111
+ { $formkit: 'formCheckbox', name: 'newsletter', label: 'Subscribe to the newsletter' },
112
+ ]
113
+ </script>
114
+
115
+ <template>
116
+ <FormKit v-model="data" type="form">
117
+ <FormKitSchema :schema="schema" :data="data" />
118
+ </FormKit>
119
+ </template>
120
+ ```
121
+
122
+ See [Usage](#usage) for outputs, i18n and more configuration.
123
+
66
124
  ## Usage
67
125
 
68
126
  ### Configuration
@@ -10,8 +10,11 @@ const props = defineProps({ context: {
10
10
  } });
11
11
  const { hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon } = useFormKitSection(props.context);
12
12
  const url = computed(() => {
13
- if (props.context?._value) return props.context?._value.indexOf("http") > -1 ? props.context?._value : `https://${props.context?._value}`;
14
- else return "";
13
+ if (props.context?._value) {
14
+ return props.context?._value.indexOf("http") > -1 ? props.context?._value : `https://${props.context?._value}`;
15
+ } else {
16
+ return "";
17
+ }
15
18
  });
16
19
  const title = computed(() => {
17
20
  const value = props.context?._value ?? "";
@@ -19,7 +19,13 @@ export function useFormKitInput(context) {
19
19
  const unstyled = computed(() => {
20
20
  return context?.unstyled ?? isGlobalUnstyledMode();
21
21
  });
22
- const formKitCreateInputSlots = /* @__PURE__ */ new Set(["label", "help", "messages", "message", "input"]);
22
+ const formKitCreateInputSlots = /* @__PURE__ */ new Set([
23
+ "label",
24
+ "help",
25
+ "messages",
26
+ "message",
27
+ "input"
28
+ ]);
23
29
  const validSlotNames = computed(
24
30
  () => Object.keys(context?.slots || {}).filter((slotName) => !formKitCreateInputSlots.has(slotName))
25
31
  );
@@ -41,5 +47,15 @@ export function useFormKitInput(context) {
41
47
  context.node.input(value);
42
48
  }
43
49
  });
44
- return { isInvalid, validSlotNames, styleClass, unstyled, handleBlur, handleChange, handleInput, handleSelect, modelValue };
50
+ return {
51
+ isInvalid,
52
+ validSlotNames,
53
+ styleClass,
54
+ unstyled,
55
+ handleBlur,
56
+ handleChange,
57
+ handleInput,
58
+ handleSelect,
59
+ modelValue
60
+ };
45
61
  }
@@ -3,7 +3,12 @@ export function useFormKitRepeater() {
3
3
  const { addElement, addComponent, addElementsInOuterDiv } = useFormKitSchema();
4
4
  function addInsertButton(label = "Add", innerClass = "", outerClass = "", buttonClass = "p-button-sm", iconClass = "oi oi-plus") {
5
5
  return addElementsInOuterDiv([
6
- addComponent("Button", { onClick: "$addNode($node)", label, class: buttonClass, icon: iconClass }, "$node.children.length == 0")
6
+ addComponent("Button", {
7
+ onClick: "$addNode($node)",
8
+ label,
9
+ class: buttonClass,
10
+ icon: iconClass
11
+ }, "$node.children.length == 0")
7
12
  ], innerClass, outerClass);
8
13
  }
9
14
  function addListGroupFunctions(data, addNodeDefaultObject = {}) {
@@ -33,13 +38,22 @@ export function useFormKitRepeater() {
33
38
  };
34
39
  data.copyNode = (parentNode, index) => () => {
35
40
  const obj = parentNode.value[index];
36
- const newArray = [...parentNode.value, { ...obj }];
41
+ const newArray = [
42
+ ...parentNode.value,
43
+ { ...obj }
44
+ ];
37
45
  parentNode.input(newArray, false);
38
46
  };
39
47
  }
40
48
  function addGroupButtons(innerClass = "", outerClass = "col-4", label = "Actions", help = "", render = "true") {
41
49
  const addButtonComponent = (onClick = "", label2 = "", icon = "", severity = "", render2 = "true", styleClass = "p-button-sm") => {
42
- return addComponent("Button", { onClick, label: label2, icon, class: styleClass, severity }, render2);
50
+ return addComponent("Button", {
51
+ onClick,
52
+ label: label2,
53
+ icon,
54
+ class: styleClass,
55
+ severity
56
+ }, render2);
43
57
  };
44
58
  return addElementsInOuterDiv([
45
59
  addButtonComponent("$removeNode($node.parent, $index)", "", "oi oi-times", "danger"),
@@ -54,5 +54,12 @@ export function useFormKitSchema() {
54
54
  const helpDiv = addElement("div", [help], { class: "formkit-help" });
55
55
  return addElement("div", [wrapperDiv, helpDiv], { class: outerClass, style: "position: relative;" }, render);
56
56
  };
57
- return { addComponent, addElement, addGroup, addList, addListGroup, addElementsInOuterDiv };
57
+ return {
58
+ addComponent,
59
+ addElement,
60
+ addGroup,
61
+ addList,
62
+ addListGroup,
63
+ addElementsInOuterDiv
64
+ };
58
65
  }
@@ -15,5 +15,11 @@ export function useFormKitSection(context) {
15
15
  function generateId() {
16
16
  return typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2);
17
17
  }
18
- return { generateId, hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon };
18
+ return {
19
+ generateId,
20
+ hasPrefix,
21
+ hasPrefixIcon,
22
+ hasSuffix,
23
+ hasSuffixIcon
24
+ };
19
25
  }
@@ -1,7 +1,42 @@
1
1
  export function useInputEditor() {
2
- const formInputWithOptionNames = ["CascadeSelect", "Listbox", "MultiSelect", "RadioButton", "Select", "SelectButton", "TreeSelect"];
3
- const formInputNames = [...formInputWithOptionNames, "AutoComplete", "Checkbox", "ColorPicker", "DatePicker", "Editor", "InputMask", "InputNumber", "InputOtp", "InputText", "Knob", "Password", "Rating", "Slider", "Textarea", "ToggleButton", "ToggleSwitch"].sort();
4
- const formOutputNames = ["OutputBoolean", "OutputDate", "OutputDuration", "OutputLink", "OutputList", "OutputNumber", "OutputReference", "OutputText"];
2
+ const formInputWithOptionNames = [
3
+ "CascadeSelect",
4
+ "Listbox",
5
+ "MultiSelect",
6
+ "RadioButton",
7
+ "Select",
8
+ "SelectButton",
9
+ "TreeSelect"
10
+ ];
11
+ const formInputNames = [
12
+ ...formInputWithOptionNames,
13
+ "AutoComplete",
14
+ "Checkbox",
15
+ "ColorPicker",
16
+ "DatePicker",
17
+ "Editor",
18
+ "InputMask",
19
+ "InputNumber",
20
+ "InputOtp",
21
+ "InputText",
22
+ "Knob",
23
+ "Password",
24
+ "Rating",
25
+ "Slider",
26
+ "Textarea",
27
+ "ToggleButton",
28
+ "ToggleSwitch"
29
+ ].sort();
30
+ const formOutputNames = [
31
+ "OutputBoolean",
32
+ "OutputDate",
33
+ "OutputDuration",
34
+ "OutputLink",
35
+ "OutputList",
36
+ "OutputNumber",
37
+ "OutputReference",
38
+ "OutputText"
39
+ ];
5
40
  function editorDataToSchema(data) {
6
41
  if (!data)
7
42
  return {};
@@ -16,7 +51,9 @@ export function useInputEditor() {
16
51
  }
17
52
  return [key, value];
18
53
  });
19
- tempData = { ...Object.fromEntries(mapped) };
54
+ tempData = {
55
+ ...Object.fromEntries(mapped)
56
+ };
20
57
  }
21
58
  const readonlyValue = data.readonly === true ? true : void 0;
22
59
  const disabledValue = data.disabled === true ? true : void 0;
@@ -24,7 +24,10 @@ export function useInputEditorSchema() {
24
24
  { label: "Dirty", value: "dirty" },
25
25
  { label: "Submit", value: "submit" }
26
26
  ];
27
- function editorSchema(inputOptions = formInputOptions([...formInputNames, ...formOutputNames])) {
27
+ function editorSchema(inputOptions = formInputOptions([
28
+ ...formInputNames,
29
+ ...formOutputNames
30
+ ])) {
28
31
  return [
29
32
  {
30
33
  $formkit: "formSelect",