@sfxcode/formkit-primevue 1.10.1 → 1.11.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
@@ -22,10 +22,16 @@ app.use(plugin, defaultConfig({
22
22
  }))
23
23
  ```
24
24
 
25
+ ## Limitations
26
+
27
+ Prefixing of the PrimeVue component names is not supported.
28
+
25
29
  ### Schema Helper Functions
26
30
 
27
31
  [useFormKitSchema](https://github.com/sfxcode/formkit-primevue/blob/main/src/composables/useFormKitSchema.ts) provide functions to simplify the usage of elements, components, lists, ...
28
32
 
33
+ [useInputEditorSchema](https://github.com/sfxcode/formkit-primevue/blob/main/src/composables/useInputEditorSchema.ts) provide functions for a component schema generation builder
34
+
29
35
  ### Basic Styling
30
36
 
31
37
  Basic styling is provided with the [formkit-primevue.scss](https://github.com/sfxcode/formkit-primevue/blob/main/src/sass/formkit-primevue.scss) file.
@@ -51,6 +57,7 @@ Some samples for common tasks are available
51
57
 
52
58
  - [Repeater](https://formkit-primevue.netlify.app/samples/repeater) (with the help of the useFormKitSchema composable)
53
59
  - [Grid](https://formkit-primevue.netlify.app/samples/grid)
60
+ - [Input Editor](https://formkit-primevue.netlify.app/samples/inputEditor) (let you test the configurations in your schema file)
54
61
 
55
62
  ## Showcases
56
63
 
@@ -1,2 +1,3 @@
1
1
  import { useFormKitSchema } from './useFormKitSchema';
2
- export { useFormKitSchema, };
2
+ import { useInputEditorSchema } from './useInputEditorSchema';
3
+ export { useFormKitSchema, useInputEditorSchema, };
@@ -9,4 +9,11 @@ Object.defineProperty(exports, "useFormKitSchema", {
9
9
  return _useFormKitSchema.useFormKitSchema;
10
10
  }
11
11
  });
12
- var _useFormKitSchema = require("./useFormKitSchema");
12
+ Object.defineProperty(exports, "useInputEditorSchema", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _useInputEditorSchema.useInputEditorSchema;
16
+ }
17
+ });
18
+ var _useFormKitSchema = require("./useFormKitSchema");
19
+ var _useInputEditorSchema = require("./useInputEditorSchema");
@@ -1,4 +1,6 @@
1
1
  import { useFormKitSchema } from "./useFormKitSchema.mjs";
2
+ import { useInputEditorSchema } from "./useInputEditorSchema.mjs";
2
3
  export {
3
- useFormKitSchema
4
+ useFormKitSchema,
5
+ useInputEditorSchema
4
6
  };
@@ -1,25 +1,25 @@
1
1
  export declare function useFormKitSchema(): {
2
- addComponent: (component?: string, props?: object, render?: string) => object;
3
- addElement: (element?: string, children?: any[] | string, attrs?: object, render?: string) => {
2
+ addComponent: (component?: string, props?: object, render?: string, formKitAttrs?: object) => object;
3
+ addElement: (element?: string, children?: any[] | string, attrs?: object, render?: string, formKitAttrs?: object) => {
4
4
  $el: string;
5
5
  if: string;
6
6
  attrs: object;
7
7
  children: string | any[];
8
8
  };
9
- addGroup: (name: string, children?: object[], render?: string) => {
9
+ addGroup: (name: string, children?: object[], render?: string, formKitAttrs?: object) => {
10
10
  $formkit: string;
11
11
  if: string;
12
12
  name: string;
13
13
  children: object[];
14
14
  };
15
- addList: (name: string, children: object[], dynamic?: boolean, render?: string) => {
15
+ addList: (name: string, children: object[], dynamic?: boolean, render?: string, formKitAttrs?: object) => {
16
16
  $formkit: string;
17
17
  if: string;
18
18
  name: string;
19
19
  dynamic: boolean;
20
20
  children: object[];
21
21
  };
22
- addListGroup: (children?: object[], render?: string) => {
22
+ addListGroup: (children?: object[], render?: string, formKitAttrs?: object) => {
23
23
  $formkit: string;
24
24
  if: string;
25
25
  for: string[];
@@ -5,39 +5,43 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useFormKitSchema = useFormKitSchema;
7
7
  function useFormKitSchema() {
8
- const addComponent = (component = "Button", props = {}, render = "true") => {
8
+ const addComponent = (component = "Button", props = {}, render = "true", formKitAttrs = {}) => {
9
9
  return {
10
10
  $cmp: component,
11
11
  if: render,
12
- props
12
+ props,
13
+ ...formKitAttrs
13
14
  };
14
15
  };
15
- const addElement = (element = "div", children = [], attrs = {}, render = "true") => {
16
+ const addElement = (element = "div", children = [], attrs = {}, render = "true", formKitAttrs = {}) => {
16
17
  return {
17
18
  $el: element,
18
19
  if: render,
19
20
  attrs,
20
- children
21
+ children,
22
+ ...formKitAttrs
21
23
  };
22
24
  };
23
- const addGroup = (name, children = [], render = "true") => {
25
+ const addGroup = (name, children = [], render = "true", formKitAttrs = {}) => {
24
26
  return {
25
27
  $formkit: "group",
26
28
  if: render,
27
29
  name,
28
- children
30
+ children,
31
+ ...formKitAttrs
29
32
  };
30
33
  };
31
- const addList = (name, children, dynamic = true, render = "true") => {
34
+ const addList = (name, children, dynamic = true, render = "true", formKitAttrs = {}) => {
32
35
  return {
33
36
  $formkit: "list",
34
37
  if: render,
35
38
  name,
36
39
  dynamic,
37
- children
40
+ children,
41
+ ...formKitAttrs
38
42
  };
39
43
  };
40
- const addListGroup = (children = [], render = "true") => {
44
+ const addListGroup = (children = [], render = "true", formKitAttrs = {}) => {
41
45
  return {
42
46
  $formkit: "group",
43
47
  if: render,
@@ -45,7 +49,8 @@ function useFormKitSchema() {
45
49
  // 👈 $items is in the slot’s scope
46
50
  key: "$item",
47
51
  index: "$index",
48
- children
52
+ children,
53
+ ...formKitAttrs
49
54
  };
50
55
  };
51
56
  function addListGroupFunctions(data, addNodeDefaultObject = {}) {
@@ -1,37 +1,41 @@
1
1
  export function useFormKitSchema() {
2
- const addComponent = (component = "Button", props = {}, render = "true") => {
2
+ const addComponent = (component = "Button", props = {}, render = "true", formKitAttrs = {}) => {
3
3
  return {
4
4
  $cmp: component,
5
5
  if: render,
6
- props
6
+ props,
7
+ ...formKitAttrs
7
8
  };
8
9
  };
9
- const addElement = (element = "div", children = [], attrs = {}, render = "true") => {
10
+ const addElement = (element = "div", children = [], attrs = {}, render = "true", formKitAttrs = {}) => {
10
11
  return {
11
12
  $el: element,
12
13
  if: render,
13
14
  attrs,
14
- children
15
+ children,
16
+ ...formKitAttrs
15
17
  };
16
18
  };
17
- const addGroup = (name, children = [], render = "true") => {
19
+ const addGroup = (name, children = [], render = "true", formKitAttrs = {}) => {
18
20
  return {
19
21
  $formkit: "group",
20
22
  if: render,
21
23
  name,
22
- children
24
+ children,
25
+ ...formKitAttrs
23
26
  };
24
27
  };
25
- const addList = (name, children, dynamic = true, render = "true") => {
28
+ const addList = (name, children, dynamic = true, render = "true", formKitAttrs = {}) => {
26
29
  return {
27
30
  $formkit: "list",
28
31
  if: render,
29
32
  name,
30
33
  dynamic,
31
- children
34
+ children,
35
+ ...formKitAttrs
32
36
  };
33
37
  };
34
- const addListGroup = (children = [], render = "true") => {
38
+ const addListGroup = (children = [], render = "true", formKitAttrs = {}) => {
35
39
  return {
36
40
  $formkit: "group",
37
41
  if: render,
@@ -39,7 +43,8 @@ export function useFormKitSchema() {
39
43
  // 👈 $items is in the slot’s scope
40
44
  key: "$item",
41
45
  index: "$index",
42
- children
46
+ children,
47
+ ...formKitAttrs
43
48
  };
44
49
  };
45
50
  function addListGroupFunctions(data, addNodeDefaultObject = {}) {
@@ -0,0 +1,132 @@
1
+ export declare function useInputEditorSchema(): {
2
+ editorSchema: (inputOptions?: any[]) => ({
3
+ $formkit: string;
4
+ if: string;
5
+ name: string;
6
+ dynamic: boolean;
7
+ children: object[];
8
+ } | {
9
+ $formkit: string;
10
+ id: string;
11
+ name: string;
12
+ label: string;
13
+ value: string;
14
+ optionLabel: string;
15
+ optionValue: string;
16
+ options: any[];
17
+ key: string;
18
+ preserve: boolean;
19
+ validation?: undefined;
20
+ validationVisibility?: undefined;
21
+ allowEmpty?: undefined;
22
+ if?: undefined;
23
+ } | {
24
+ $formkit: string;
25
+ name: string;
26
+ label: string;
27
+ validation: string;
28
+ validationVisibility: string;
29
+ key: string;
30
+ preserve: boolean;
31
+ id?: undefined;
32
+ value?: undefined;
33
+ optionLabel?: undefined;
34
+ optionValue?: undefined;
35
+ options?: undefined;
36
+ allowEmpty?: undefined;
37
+ if?: undefined;
38
+ } | {
39
+ $formkit: string;
40
+ id: string;
41
+ name: string;
42
+ options: {
43
+ label: string;
44
+ value: string;
45
+ }[];
46
+ optionLabel: string;
47
+ optionValue: string;
48
+ value: string;
49
+ allowEmpty: boolean;
50
+ key: string;
51
+ preserve: boolean;
52
+ label?: undefined;
53
+ validation?: undefined;
54
+ validationVisibility?: undefined;
55
+ if?: undefined;
56
+ } | {
57
+ $formkit: string;
58
+ if: string;
59
+ name: string;
60
+ label: string;
61
+ key: string;
62
+ preserve: boolean;
63
+ id?: undefined;
64
+ value?: undefined;
65
+ optionLabel?: undefined;
66
+ optionValue?: undefined;
67
+ options?: undefined;
68
+ validation?: undefined;
69
+ validationVisibility?: undefined;
70
+ allowEmpty?: undefined;
71
+ } | {
72
+ $formkit: string;
73
+ if: string;
74
+ name: string;
75
+ label: string;
76
+ key: string;
77
+ value: boolean;
78
+ preserve: boolean;
79
+ id?: undefined;
80
+ optionLabel?: undefined;
81
+ optionValue?: undefined;
82
+ options?: undefined;
83
+ validation?: undefined;
84
+ validationVisibility?: undefined;
85
+ allowEmpty?: undefined;
86
+ } | {
87
+ $formkit: string;
88
+ if: string;
89
+ name: string;
90
+ label: string;
91
+ value: string;
92
+ optionLabel: string;
93
+ optionValue: string;
94
+ options: {
95
+ label: string;
96
+ value: string;
97
+ }[];
98
+ key: string;
99
+ preserve: boolean;
100
+ id?: undefined;
101
+ validation?: undefined;
102
+ validationVisibility?: undefined;
103
+ allowEmpty?: undefined;
104
+ } | {
105
+ $formkit: string;
106
+ if: string;
107
+ name: string;
108
+ label: string;
109
+ optionLabel: string;
110
+ optionValue: string;
111
+ options: {
112
+ label: string;
113
+ value: string;
114
+ }[];
115
+ key: string;
116
+ preserve: boolean;
117
+ id?: undefined;
118
+ value?: undefined;
119
+ validation?: undefined;
120
+ validationVisibility?: undefined;
121
+ allowEmpty?: undefined;
122
+ })[];
123
+ primeInputNames: string[];
124
+ primeInputOptions: (list: string[]) => {
125
+ label: string;
126
+ value: string;
127
+ }[];
128
+ editorDataToSchema: (data: any) => any;
129
+ editorDataToJson: (data: any) => string;
130
+ editorDataToCode: (data: any) => string;
131
+ schemaToEditorData: (schema: any) => any;
132
+ };
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useInputEditorSchema = useInputEditorSchema;
7
+ var _useFormKitSchema = require("./useFormKitSchema");
8
+ function useInputEditorSchema() {
9
+ const {
10
+ addElement,
11
+ addList,
12
+ addListGroup,
13
+ addComponent
14
+ } = (0, _useFormKitSchema.useFormKitSchema)();
15
+ function addFlexElement(children) {
16
+ return addElement("div", children, {
17
+ style: "min-width: 40rem;display: flex;gap: 1rem;"
18
+ });
19
+ }
20
+ function addGroupButtons() {
21
+ const addButtonComponent = (onClick = "", label = "", icon = "", severity = "", render = "true", styleClass = "p-button-sm", style = "margin-left: 0.5rem;") => {
22
+ return addComponent("Button", {
23
+ onClick,
24
+ label,
25
+ icon,
26
+ class: styleClass,
27
+ style,
28
+ severity
29
+ }, render);
30
+ };
31
+ return addElement("div", [addButtonComponent("$removeNode($node, $index)", "", "pi pi-times", "danger"), addButtonComponent("$copyNode($node, $index)", "", "pi pi-plus"), addButtonComponent("$moveNodeUp($node, $index)", "", "pi pi-arrow-up", "secondary", "$index != 0"), addElement("span", [], {
32
+ style: "margin-left: 0.5rem;margin-right: 2.5rem;"
33
+ }, "$index == 0"), addButtonComponent("$moveNodeDown($node, $index)", "", "pi pi-arrow-down", "secondary", "$index < $node.value.length -1"), addElement("span", [], {
34
+ style: "margin-left: 0.5rem;margin-right: 2.5rem;"
35
+ }, "$index == $node.value.length -1")], {
36
+ style: "padding-top: 1.5rem;"
37
+ });
38
+ }
39
+ const primeInputWithOptionNames = ["CascadeSelect", "Dropdown", "Listbox", "MultiSelect", "RadioButton", "SelectButton", "TreeSelect"];
40
+ const primeInputNames = [...primeInputWithOptionNames, "AutoComplete", "Calendar", "Checkbox", "Chips", "ColorPicker", "Editor", "InputMask", "InputNumber", "InputOtp", "InputSwitch", "InputText", "Knob", "Password", "Rating", "Slider", "Textarea", "ToggleButton", "TriStateCheckbox"].sort();
41
+ function primeInputOptions(list) {
42
+ return list.map(name => {
43
+ return {
44
+ label: name,
45
+ value: `prime${name}`
46
+ };
47
+ });
48
+ }
49
+ const selectOptions = [{
50
+ label: "Base",
51
+ value: "showBasic"
52
+ }, {
53
+ label: "Display",
54
+ value: "showDisplay"
55
+ }, {
56
+ label: "Validation",
57
+ value: "showValidation"
58
+ }, {
59
+ label: "Options",
60
+ value: "showOptions"
61
+ }, {
62
+ label: "Prime",
63
+ value: "showPrime"
64
+ }];
65
+ const validationOptions = [{
66
+ label: "Blur",
67
+ value: "blur"
68
+ }, {
69
+ label: "Live",
70
+ value: "live"
71
+ }, {
72
+ label: "Dirty",
73
+ value: "dirty"
74
+ }, {
75
+ label: "Submit",
76
+ value: "submit"
77
+ }];
78
+ const positionOptions = [{
79
+ label: "Left",
80
+ value: "left"
81
+ }, {
82
+ label: "Right",
83
+ value: "right"
84
+ }];
85
+ function editorDataToSchema(data) {
86
+ const formkitInput = data?._dollar_formkit;
87
+ let tempData = {};
88
+ if (data.prime?.length > 0) {
89
+ const mapped = data.prime?.map(entry => [entry.prime_key, entry.prime_value]);
90
+ tempData = Object.assign(...mapped.map(([key, val]) => ({
91
+ [key]: val
92
+ })));
93
+ }
94
+ const readonlyValue = data.readonly ? true : void 0;
95
+ const disabledValue = data.disabled ? true : void 0;
96
+ const preserveValue = data.preserve ? true : void 0;
97
+ const defaultObject = {
98
+ readonly: readonlyValue,
99
+ disabled: disabledValue,
100
+ preserve: preserveValue
101
+ };
102
+ const undefinedObject = {
103
+ prime: void 0,
104
+ schemaResultFormKey: void 0,
105
+ _dollar_formkit: void 0,
106
+ slots: void 0,
107
+ selectButton: void 0
108
+ };
109
+ const useOptions = primeInputWithOptionNames.map(s => `prime${s}`).includes(formkitInput);
110
+ if (useOptions) return {
111
+ ...data,
112
+ $formkit: formkitInput,
113
+ ...tempData,
114
+ ...undefinedObject,
115
+ ...defaultObject,
116
+ optionLabel: "label",
117
+ optionValue: "value"
118
+ };else return {
119
+ ...data,
120
+ $formkit: formkitInput,
121
+ ...tempData,
122
+ ...undefinedObject,
123
+ ...defaultObject,
124
+ options: void 0
125
+ };
126
+ }
127
+ function editorDataToJson(data) {
128
+ return JSON.stringify(editorDataToSchema(data));
129
+ }
130
+ function editorDataToObject(data) {
131
+ return `{${Object.entries(JSON.parse(editorDataToJson(data))).map(([key, value]) => `${key}: '${value}'`).join()}}`;
132
+ }
133
+ function schemaToEditorData(schema) {
134
+ const formkitInput = schema?.$formkit;
135
+ return {
136
+ ...schema,
137
+ _dollar_formkit: formkitInput
138
+ };
139
+ }
140
+ function editorSchema(inputOptions = primeInputOptions(primeInputNames)) {
141
+ return [{
142
+ $formkit: "primeDropdown",
143
+ id: "inputSelection",
144
+ name: "_dollar_formkit",
145
+ label: "Prime Input",
146
+ value: "primeInputText",
147
+ optionLabel: "label",
148
+ optionValue: "value",
149
+ options: inputOptions,
150
+ key: "schema_inputSelection",
151
+ preserve: true
152
+ }, {
153
+ $formkit: "primeInputText",
154
+ name: "name",
155
+ label: "Field Name",
156
+ validation: "required",
157
+ validationVisibility: "live",
158
+ key: "schema_name",
159
+ preserve: true
160
+ }, {
161
+ $formkit: "primeSelectButton",
162
+ id: "selectButton",
163
+ name: "selectButton",
164
+ options: selectOptions,
165
+ optionLabel: "label",
166
+ optionValue: "value",
167
+ value: "showBasic",
168
+ allowEmpty: false,
169
+ key: "schema_selectButton",
170
+ preserve: true
171
+ }, {
172
+ $formkit: "primeInputText",
173
+ if: "$get(selectButton).value === 'showBasic'",
174
+ name: "label",
175
+ label: "Input Label",
176
+ key: "schema_label",
177
+ preserve: true
178
+ }, {
179
+ $formkit: "primeInputText",
180
+ if: "$get(selectButton).value === 'showBasic'",
181
+ name: "help",
182
+ label: "Input Help",
183
+ key: "schema_help",
184
+ preserve: true
185
+ }, {
186
+ $formkit: "primeInputText",
187
+ if: "$get(selectButton).value === 'showBasic'",
188
+ name: "id",
189
+ label: "Input ID",
190
+ key: "schema_id",
191
+ preserve: true
192
+ }, {
193
+ $formkit: "primeInputText",
194
+ if: "$get(selectButton).value === 'showBasic'",
195
+ name: "value",
196
+ label: "Input Value",
197
+ key: "schema_value",
198
+ preserve: true
199
+ }, {
200
+ $formkit: "primeInputText",
201
+ if: "$get(selectButton).value === 'showBasic'",
202
+ name: "key",
203
+ label: "Input Key",
204
+ key: "schema_key",
205
+ preserve: true
206
+ }, {
207
+ $formkit: "primeCheckbox",
208
+ if: "$get(selectButton).value === 'showBasic'",
209
+ name: "preserve",
210
+ label: "Input Preserve",
211
+ key: "schema_preserve",
212
+ value: false,
213
+ preserve: true
214
+ }, {
215
+ $formkit: "primeInputText",
216
+ if: "$get(selectButton).value === 'showValidation'",
217
+ name: "validation",
218
+ label: "Field Validation",
219
+ key: "schema_validation",
220
+ preserve: true
221
+ }, {
222
+ $formkit: "primeDropdown",
223
+ if: "$get(selectButton).value === 'showValidation'",
224
+ name: "validation-visibility",
225
+ label: "Field Validation Visibility",
226
+ value: "blur",
227
+ optionLabel: "label",
228
+ optionValue: "value",
229
+ options: validationOptions,
230
+ key: "schema_validation-visibility",
231
+ preserve: true
232
+ }, {
233
+ $formkit: "primeInputText",
234
+ if: "$get(selectButton).value === 'showValidation'",
235
+ name: "validation-label",
236
+ label: "Field Validation Label",
237
+ key: "schema_validation-label",
238
+ preserve: true
239
+ }, {
240
+ $formkit: "primeInputText",
241
+ if: "$get(selectButton).value === 'showDisplay'",
242
+ name: "tabindex",
243
+ label: "Tab Index",
244
+ key: "schema_tabindex",
245
+ preserve: true
246
+ }, {
247
+ $formkit: "primeInputText",
248
+ if: "$get(selectButton).value === 'showDisplay'",
249
+ name: "if",
250
+ label: "Should Render",
251
+ key: "schema_if",
252
+ preserve: true
253
+ }, {
254
+ $formkit: "primeInputText",
255
+ if: "$get(selectButton).value === 'showDisplay'",
256
+ name: "style",
257
+ label: "Input Style",
258
+ key: "schema_style",
259
+ preserve: true
260
+ }, {
261
+ $formkit: "primeInputText",
262
+ if: "$get(selectButton).value === 'showDisplay'",
263
+ name: "class",
264
+ label: "Input StyleClass",
265
+ key: "schema_class",
266
+ preserve: true
267
+ }, {
268
+ $formkit: "primeInputText",
269
+ if: "$get(selectButton).value === 'showDisplay'",
270
+ name: "icon",
271
+ label: "Icon",
272
+ key: "schema_icon",
273
+ preserve: true
274
+ }, {
275
+ $formkit: "primeDropdown",
276
+ if: "$get(selectButton).value === 'showDisplay'",
277
+ name: "iconPosition",
278
+ label: "Icon Position",
279
+ optionLabel: "label",
280
+ optionValue: "value",
281
+ options: positionOptions,
282
+ key: "schema_iconPosition",
283
+ preserve: true
284
+ }, {
285
+ $formkit: "primeCheckbox",
286
+ if: "$get(selectButton).value === 'showDisplay'",
287
+ name: "disabled",
288
+ label: "Input Disabled",
289
+ key: "schema_disabled",
290
+ value: false,
291
+ preserve: true
292
+ }, {
293
+ $formkit: "primeCheckbox",
294
+ if: "$get(selectButton).value === 'showDisplay'",
295
+ name: "readonly",
296
+ label: "Input Read Only",
297
+ key: "schema_readonly",
298
+ value: false,
299
+ preserve: true
300
+ }, addList("options", [addFlexElement([addComponent("Button", {
301
+ onClick: "$addNode($node)",
302
+ label: "Add Option",
303
+ class: "p-button-sm",
304
+ style: "margin-bottom: 2rem;",
305
+ icon: "pi pi-plus"
306
+ }, "$node.value.length == 0")]), addListGroup([addFlexElement([{
307
+ $formkit: "primeInputText",
308
+ label: "Label",
309
+ name: "label"
310
+ }, {
311
+ $formkit: "primeInputText",
312
+ label: "Value",
313
+ name: "value"
314
+ }, addGroupButtons()])])], true, "$get(selectButton).value === 'showOptions'", {
315
+ key: "schema_options",
316
+ preserve: true
317
+ }), addList("prime", [addFlexElement([addComponent("Button", {
318
+ onClick: "$addNode($node)",
319
+ label: "Add PrimeVue Attribute",
320
+ class: "p-button-sm",
321
+ style: "margin-bottom: 2rem;",
322
+ icon: "pi pi-plus"
323
+ }, "$node.value.length == 0")]), addListGroup([addFlexElement([{
324
+ $formkit: "primeInputText",
325
+ label: "PrimeVue Property",
326
+ name: "prime_key"
327
+ }, {
328
+ $formkit: "primeInputText",
329
+ label: "Value",
330
+ name: "prime_value"
331
+ }, addGroupButtons()])])], true, "$get(selectButton).value === 'showPrime'", {
332
+ key: "schema_prime",
333
+ preserve: true
334
+ })];
335
+ }
336
+ return {
337
+ editorSchema,
338
+ primeInputNames,
339
+ primeInputOptions,
340
+ editorDataToSchema,
341
+ editorDataToJson,
342
+ editorDataToCode: editorDataToObject,
343
+ schemaToEditorData
344
+ };
345
+ }
@@ -0,0 +1,300 @@
1
+ import { useFormKitSchema } from "./useFormKitSchema.mjs";
2
+ export function useInputEditorSchema() {
3
+ const { addElement, addList, addListGroup, addComponent } = useFormKitSchema();
4
+ function addFlexElement(children) {
5
+ return addElement("div", children, { style: "min-width: 40rem;display: flex;gap: 1rem;" });
6
+ }
7
+ function addGroupButtons() {
8
+ const addButtonComponent = (onClick = "", label = "", icon = "", severity = "", render = "true", styleClass = "p-button-sm", style = "margin-left: 0.5rem;") => {
9
+ return addComponent("Button", { onClick, label, icon, class: styleClass, style, severity }, render);
10
+ };
11
+ return addElement("div", [
12
+ addButtonComponent("$removeNode($node, $index)", "", "pi pi-times", "danger"),
13
+ addButtonComponent("$copyNode($node, $index)", "", "pi pi-plus"),
14
+ addButtonComponent("$moveNodeUp($node, $index)", "", "pi pi-arrow-up", "secondary", "$index != 0"),
15
+ addElement("span", [], { style: "margin-left: 0.5rem;margin-right: 2.5rem;" }, "$index == 0"),
16
+ addButtonComponent("$moveNodeDown($node, $index)", "", "pi pi-arrow-down", "secondary", "$index < $node.value.length -1"),
17
+ addElement("span", [], { style: "margin-left: 0.5rem;margin-right: 2.5rem;" }, "$index == $node.value.length -1")
18
+ ], { style: "padding-top: 1.5rem;" });
19
+ }
20
+ const primeInputWithOptionNames = ["CascadeSelect", "Dropdown", "Listbox", "MultiSelect", "RadioButton", "SelectButton", "TreeSelect"];
21
+ const primeInputNames = [...primeInputWithOptionNames, "AutoComplete", "Calendar", "Checkbox", "Chips", "ColorPicker", "Editor", "InputMask", "InputNumber", "InputOtp", "InputSwitch", "InputText", "Knob", "Password", "Rating", "Slider", "Textarea", "ToggleButton", "TriStateCheckbox"].sort();
22
+ function primeInputOptions(list) {
23
+ return list.map((name) => {
24
+ return { label: name, value: `prime${name}` };
25
+ });
26
+ }
27
+ const selectOptions = [
28
+ { label: "Base", value: "showBasic" },
29
+ { label: "Display", value: "showDisplay" },
30
+ { label: "Validation", value: "showValidation" },
31
+ { label: "Options", value: "showOptions" },
32
+ { label: "Prime", value: "showPrime" }
33
+ ];
34
+ const validationOptions = [
35
+ { label: "Blur", value: "blur" },
36
+ { label: "Live", value: "live" },
37
+ { label: "Dirty", value: "dirty" },
38
+ { label: "Submit", value: "submit" }
39
+ ];
40
+ const positionOptions = [
41
+ { label: "Left", value: "left" },
42
+ { label: "Right", value: "right" }
43
+ ];
44
+ function editorDataToSchema(data) {
45
+ const formkitInput = data?._dollar_formkit;
46
+ let tempData = {};
47
+ if (data.prime?.length > 0) {
48
+ const mapped = data.prime?.map((entry) => [entry.prime_key, entry.prime_value]);
49
+ tempData = Object.assign(...mapped.map(([key, val]) => ({ [key]: val })));
50
+ }
51
+ const readonlyValue = data.readonly ? true : void 0;
52
+ const disabledValue = data.disabled ? true : void 0;
53
+ const preserveValue = data.preserve ? true : void 0;
54
+ const defaultObject = { readonly: readonlyValue, disabled: disabledValue, preserve: preserveValue };
55
+ const undefinedObject = { prime: void 0, schemaResultFormKey: void 0, _dollar_formkit: void 0, slots: void 0, selectButton: void 0 };
56
+ const useOptions = primeInputWithOptionNames.map((s) => `prime${s}`).includes(formkitInput);
57
+ if (useOptions)
58
+ return { ...data, $formkit: formkitInput, ...tempData, ...undefinedObject, ...defaultObject, optionLabel: "label", optionValue: "value" };
59
+ else
60
+ return { ...data, $formkit: formkitInput, ...tempData, ...undefinedObject, ...defaultObject, options: void 0 };
61
+ }
62
+ function editorDataToJson(data) {
63
+ return JSON.stringify(editorDataToSchema(data));
64
+ }
65
+ function editorDataToObject(data) {
66
+ return `{${Object.entries(JSON.parse(editorDataToJson(data))).map(([key, value]) => `${key}: '${value}'`).join()}}`;
67
+ }
68
+ function schemaToEditorData(schema) {
69
+ const formkitInput = schema?.$formkit;
70
+ return { ...schema, _dollar_formkit: formkitInput };
71
+ }
72
+ function editorSchema(inputOptions = primeInputOptions(primeInputNames)) {
73
+ return [
74
+ {
75
+ $formkit: "primeDropdown",
76
+ id: "inputSelection",
77
+ name: "_dollar_formkit",
78
+ label: "Prime Input",
79
+ value: "primeInputText",
80
+ optionLabel: "label",
81
+ optionValue: "value",
82
+ options: inputOptions,
83
+ key: "schema_inputSelection",
84
+ preserve: true
85
+ },
86
+ {
87
+ $formkit: "primeInputText",
88
+ name: "name",
89
+ label: "Field Name",
90
+ validation: "required",
91
+ validationVisibility: "live",
92
+ key: "schema_name",
93
+ preserve: true
94
+ },
95
+ {
96
+ $formkit: "primeSelectButton",
97
+ id: "selectButton",
98
+ name: "selectButton",
99
+ options: selectOptions,
100
+ optionLabel: "label",
101
+ optionValue: "value",
102
+ value: "showBasic",
103
+ allowEmpty: false,
104
+ key: "schema_selectButton",
105
+ preserve: true
106
+ },
107
+ {
108
+ $formkit: "primeInputText",
109
+ if: "$get(selectButton).value === 'showBasic'",
110
+ name: "label",
111
+ label: "Input Label",
112
+ key: "schema_label",
113
+ preserve: true
114
+ },
115
+ {
116
+ $formkit: "primeInputText",
117
+ if: "$get(selectButton).value === 'showBasic'",
118
+ name: "help",
119
+ label: "Input Help",
120
+ key: "schema_help",
121
+ preserve: true
122
+ },
123
+ {
124
+ $formkit: "primeInputText",
125
+ if: "$get(selectButton).value === 'showBasic'",
126
+ name: "id",
127
+ label: "Input ID",
128
+ key: "schema_id",
129
+ preserve: true
130
+ },
131
+ {
132
+ $formkit: "primeInputText",
133
+ if: "$get(selectButton).value === 'showBasic'",
134
+ name: "value",
135
+ label: "Input Value",
136
+ key: "schema_value",
137
+ preserve: true
138
+ },
139
+ {
140
+ $formkit: "primeInputText",
141
+ if: "$get(selectButton).value === 'showBasic'",
142
+ name: "key",
143
+ label: "Input Key",
144
+ key: "schema_key",
145
+ preserve: true
146
+ },
147
+ {
148
+ $formkit: "primeCheckbox",
149
+ if: "$get(selectButton).value === 'showBasic'",
150
+ name: "preserve",
151
+ label: "Input Preserve",
152
+ key: "schema_preserve",
153
+ value: false,
154
+ preserve: true
155
+ },
156
+ {
157
+ $formkit: "primeInputText",
158
+ if: "$get(selectButton).value === 'showValidation'",
159
+ name: "validation",
160
+ label: "Field Validation",
161
+ key: "schema_validation",
162
+ preserve: true
163
+ },
164
+ {
165
+ $formkit: "primeDropdown",
166
+ if: "$get(selectButton).value === 'showValidation'",
167
+ name: "validation-visibility",
168
+ label: "Field Validation Visibility",
169
+ value: "blur",
170
+ optionLabel: "label",
171
+ optionValue: "value",
172
+ options: validationOptions,
173
+ key: "schema_validation-visibility",
174
+ preserve: true
175
+ },
176
+ {
177
+ $formkit: "primeInputText",
178
+ if: "$get(selectButton).value === 'showValidation'",
179
+ name: "validation-label",
180
+ label: "Field Validation Label",
181
+ key: "schema_validation-label",
182
+ preserve: true
183
+ },
184
+ {
185
+ $formkit: "primeInputText",
186
+ if: "$get(selectButton).value === 'showDisplay'",
187
+ name: "tabindex",
188
+ label: "Tab Index",
189
+ key: "schema_tabindex",
190
+ preserve: true
191
+ },
192
+ {
193
+ $formkit: "primeInputText",
194
+ if: "$get(selectButton).value === 'showDisplay'",
195
+ name: "if",
196
+ label: "Should Render",
197
+ key: "schema_if",
198
+ preserve: true
199
+ },
200
+ {
201
+ $formkit: "primeInputText",
202
+ if: "$get(selectButton).value === 'showDisplay'",
203
+ name: "style",
204
+ label: "Input Style",
205
+ key: "schema_style",
206
+ preserve: true
207
+ },
208
+ {
209
+ $formkit: "primeInputText",
210
+ if: "$get(selectButton).value === 'showDisplay'",
211
+ name: "class",
212
+ label: "Input StyleClass",
213
+ key: "schema_class",
214
+ preserve: true
215
+ },
216
+ {
217
+ $formkit: "primeInputText",
218
+ if: "$get(selectButton).value === 'showDisplay'",
219
+ name: "icon",
220
+ label: "Icon",
221
+ key: "schema_icon",
222
+ preserve: true
223
+ },
224
+ {
225
+ $formkit: "primeDropdown",
226
+ if: "$get(selectButton).value === 'showDisplay'",
227
+ name: "iconPosition",
228
+ label: "Icon Position",
229
+ optionLabel: "label",
230
+ optionValue: "value",
231
+ options: positionOptions,
232
+ key: "schema_iconPosition",
233
+ preserve: true
234
+ },
235
+ {
236
+ $formkit: "primeCheckbox",
237
+ if: "$get(selectButton).value === 'showDisplay'",
238
+ name: "disabled",
239
+ label: "Input Disabled",
240
+ key: "schema_disabled",
241
+ value: false,
242
+ preserve: true
243
+ },
244
+ {
245
+ $formkit: "primeCheckbox",
246
+ if: "$get(selectButton).value === 'showDisplay'",
247
+ name: "readonly",
248
+ label: "Input Read Only",
249
+ key: "schema_readonly",
250
+ value: false,
251
+ preserve: true
252
+ },
253
+ addList("options", [
254
+ addFlexElement([
255
+ addComponent("Button", { onClick: "$addNode($node)", label: "Add Option", class: "p-button-sm", style: "margin-bottom: 2rem;", icon: "pi pi-plus" }, "$node.value.length == 0")
256
+ ]),
257
+ addListGroup(
258
+ [
259
+ addFlexElement([
260
+ {
261
+ $formkit: "primeInputText",
262
+ label: "Label",
263
+ name: "label"
264
+ },
265
+ {
266
+ $formkit: "primeInputText",
267
+ label: "Value",
268
+ name: "value"
269
+ },
270
+ addGroupButtons()
271
+ ])
272
+ ]
273
+ )
274
+ ], true, "$get(selectButton).value === 'showOptions'", { key: "schema_options", preserve: true }),
275
+ addList("prime", [
276
+ addFlexElement([
277
+ addComponent("Button", { onClick: "$addNode($node)", label: "Add PrimeVue Attribute", class: "p-button-sm", style: "margin-bottom: 2rem;", icon: "pi pi-plus" }, "$node.value.length == 0")
278
+ ]),
279
+ addListGroup(
280
+ [
281
+ addFlexElement([
282
+ {
283
+ $formkit: "primeInputText",
284
+ label: "PrimeVue Property",
285
+ name: "prime_key"
286
+ },
287
+ {
288
+ $formkit: "primeInputText",
289
+ label: "Value",
290
+ name: "prime_value"
291
+ },
292
+ addGroupButtons()
293
+ ])
294
+ ]
295
+ )
296
+ ], true, "$get(selectButton).value === 'showPrime'", { key: "schema_prime", preserve: true })
297
+ ];
298
+ }
299
+ return { editorSchema, primeInputNames, primeInputOptions, editorDataToSchema, editorDataToJson, editorDataToCode: editorDataToObject, schemaToEditorData };
300
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { useFormKitSchema } from './composables';
1
+ import { useFormKitSchema, useInputEditorSchema } from './composables';
2
2
  import { primeInputs } from './definitions';
3
- export { useFormKitSchema, primeInputs, };
3
+ export { useFormKitSchema, useInputEditorSchema, primeInputs, };
package/dist/index.js CHANGED
@@ -15,5 +15,11 @@ Object.defineProperty(exports, "useFormKitSchema", {
15
15
  return _composables.useFormKitSchema;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "useInputEditorSchema", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _composables.useInputEditorSchema;
22
+ }
23
+ });
18
24
  var _composables = require("./composables");
19
25
  var _definitions = require("./definitions");
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { useFormKitSchema } from "./composables/index.mjs";
1
+ import { useFormKitSchema, useInputEditorSchema } from "./composables/index.mjs";
2
2
  import { primeInputs } from "./definitions/index.mjs";
3
3
  export {
4
4
  useFormKitSchema,
5
+ useInputEditorSchema,
5
6
  primeInputs
6
7
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sfxcode/formkit-primevue",
3
3
  "type": "module",
4
- "version": "1.10.1",
4
+ "version": "1.11.1",
5
5
  "author": {
6
6
  "name": "Tom",
7
7
  "email": "tom@sfxcode.com"
@@ -81,18 +81,18 @@
81
81
  "vue": "^3.4.0"
82
82
  },
83
83
  "dependencies": {
84
- "@formkit/addons": "^1.6.2",
85
- "@formkit/i18n": "^1.6.2",
86
- "@formkit/vue": "^1.6.2",
84
+ "@formkit/addons": "^1.6.3",
85
+ "@formkit/i18n": "^1.6.3",
86
+ "@formkit/vue": "^1.6.3",
87
87
  "primeicons": "^7.0.0",
88
88
  "primevue": "^3.52.0"
89
89
  },
90
90
  "devDependencies": {
91
- "@antfu/eslint-config": "2.16.2",
92
- "@formkit/core": "^1.6.2",
93
- "@types/node": "^20.12.10",
94
- "@unocss/preset-icons": "0.59.4",
95
- "@unocss/preset-uno": "0.59.4",
91
+ "@antfu/eslint-config": "2.18.0",
92
+ "@formkit/core": "^1.6.3",
93
+ "@types/node": "^20.12.12",
94
+ "@unocss/preset-icons": "0.60.2",
95
+ "@unocss/preset-uno": "0.60.2",
96
96
  "@vitejs/plugin-vue": "^5.0.4",
97
97
  "@vitest/coverage-v8": "^1.6.0",
98
98
  "@vitest/ui": "^1.6.0",
@@ -108,18 +108,18 @@
108
108
  "chart.js": "^4.4.2",
109
109
  "consola": "^3.2.3",
110
110
  "eslint": "^9.2.0",
111
- "happy-dom": "^14.10.1",
111
+ "happy-dom": "^14.11.0",
112
112
  "json-editor-vue": "^0.15.1",
113
113
  "mkdist": "^1.5.1",
114
- "quill": "^2.0.1",
115
- "sass": "^1.77.0",
114
+ "quill": "^2.0.2",
115
+ "sass": "^1.77.1",
116
116
  "tslib": "^2.6.2",
117
117
  "typescript": "^5.4.5",
118
118
  "unbuild": "2.0.0",
119
- "unocss": "0.59.4",
120
- "unplugin-auto-import": "^0.17.5",
119
+ "unocss": "0.60.2",
120
+ "unplugin-auto-import": "^0.17.6",
121
121
  "unplugin-vue-components": "^0.27.0",
122
- "vanilla-jsoneditor": "^0.23.3",
122
+ "vanilla-jsoneditor": "^0.23.4",
123
123
  "vite": "^5.2.11",
124
124
  "vite-plugin-dts": "^3.9.1",
125
125
  "vite-plugin-eslint": "^1.8.1",
@@ -130,6 +130,6 @@
130
130
  "vue": "^3.4.27",
131
131
  "vue-demi": "^0.14.7",
132
132
  "vue-router": "^4.3.2",
133
- "vue-tsc": "^2.0.16"
133
+ "vue-tsc": "^2.0.18"
134
134
  }
135
135
  }