@sfxcode/formkit-primevue 3.3.1 → 3.3.4
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/components/FormKitDataDebug.vue +19 -0
- package/dist/components/FormKitDataEdit.vue +133 -0
- package/dist/components/FormKitDataView.vue +51 -0
- package/dist/components/FormKitIcon.vue +18 -0
- package/dist/components/FormKitPrefix.vue +11 -0
- package/dist/components/FormKitSuffix.vue +11 -0
- package/dist/components/PrimeAutoComplete.vue +95 -0
- package/dist/components/PrimeCascadeSelect.vue +43 -0
- package/dist/components/PrimeCheckbox.vue +51 -0
- package/dist/components/PrimeColorPicker.vue +33 -0
- package/dist/components/PrimeDatePicker.vue +97 -0
- package/dist/components/PrimeInputMask.vue +69 -0
- package/dist/components/PrimeInputNumber.vue +75 -0
- package/dist/components/PrimeInputOtp.vue +42 -0
- package/dist/components/PrimeInputText.vue +65 -0
- package/dist/components/PrimeKnob.vue +50 -0
- package/dist/components/PrimeListbox.vue +54 -0
- package/dist/components/PrimeMultiSelect.vue +70 -0
- package/dist/components/PrimeOutputBoolean.vue +42 -0
- package/dist/components/PrimeOutputDate.vue +51 -0
- package/dist/components/PrimeOutputDuration.vue +36 -0
- package/dist/components/PrimeOutputLink.vue +52 -0
- package/dist/components/PrimeOutputList.vue +106 -0
- package/dist/components/PrimeOutputNumber.vue +56 -0
- package/dist/components/PrimeOutputReference.vue +64 -0
- package/dist/components/PrimeOutputText.vue +72 -0
- package/dist/components/PrimePassword.vue +52 -0
- package/dist/components/PrimeRadioButton.vue +48 -0
- package/dist/components/PrimeRating.vue +40 -0
- package/dist/components/PrimeSelect.vue +71 -0
- package/dist/components/PrimeSelectButton.vue +44 -0
- package/dist/components/PrimeSlider.vue +42 -0
- package/dist/components/PrimeTextarea.vue +37 -0
- package/dist/components/PrimeToggleButton.vue +42 -0
- package/dist/components/PrimeToggleSwitch.vue +42 -0
- package/dist/components/PrimeTreeSelect.vue +48 -0
- package/dist/components/index.d.ts +24 -2
- package/dist/components/index.js +167 -4
- package/dist/components/index.mjs +48 -0
- package/dist/composables/index.d.ts +9 -2
- package/dist/composables/index.js +61 -2
- package/dist/composables/index.mjs +18 -0
- package/dist/composables/useFormKitInput.d.ts +11 -0
- package/dist/composables/useFormKitInput.js +62 -0
- package/dist/composables/useFormKitInput.mjs +57 -0
- package/dist/composables/useFormKitRepeater.d.ts +15 -0
- package/dist/composables/useFormKitRepeater.js +74 -0
- package/dist/composables/useFormKitRepeater.mjs +82 -0
- package/dist/composables/useFormKitSchema.d.ts +36 -0
- package/dist/composables/useFormKitSchema.js +83 -0
- package/dist/composables/useFormKitSchema.mjs +66 -0
- package/dist/composables/useFormKitSection.d.ts +7 -0
- package/dist/composables/useFormKitSection.js +31 -0
- package/dist/composables/useFormKitSection.mjs +19 -0
- package/dist/composables/useInputEditor.d.ts +8 -0
- package/dist/composables/useInputEditor.js +148 -0
- package/dist/composables/useInputEditor.mjs +171 -0
- package/dist/composables/useInputEditorSchema.d.ts +163 -0
- package/dist/composables/useInputEditorSchema.js +313 -0
- package/dist/composables/useInputEditorSchema.mjs +323 -0
- package/dist/composables/useOutputDuration.d.ts +4 -0
- package/dist/composables/useOutputDuration.js +40 -0
- package/dist/composables/useOutputDuration.mjs +32 -0
- package/dist/composables/usePrimeInputs.d.ts +3 -0
- package/dist/composables/usePrimeInputs.js +62 -0
- package/dist/composables/usePrimeInputs.mjs +53 -0
- package/dist/definitions/index.d.ts +32 -37
- package/dist/definitions/index.js +42 -4
- package/dist/definitions/index.mjs +68 -0
- package/dist/definitions/input.d.ts +47 -0
- package/dist/definitions/input.js +142 -0
- package/dist/definitions/input.mjs +421 -0
- package/dist/definitions/output.d.ts +9 -0
- package/dist/definitions/output.js +46 -0
- package/dist/definitions/output.mjs +120 -0
- package/dist/index.d.ts +142 -145
- package/dist/index.js +62 -5
- package/dist/index.mjs +20 -0
- package/dist/plugins/index.d.ts +3 -7
- package/dist/plugins/index.js +57 -45
- package/dist/plugins/index.mjs +59 -0
- package/dist/vue.d.ts +5 -0
- package/package.json +88 -40
- package/dist/PrimeTreeSelect-Dksx7tL-.js +0 -1881
- package/dist/components-HJnJ39cU.js +0 -255
- package/dist/composables-CZ6f1QYe.js +0 -820
- package/dist/definitions-BHwWaom7.js +0 -1196
- package/dist/index-Ch3MtT1C.d.ts +0 -266
- package/dist/index-EJ8M51RO.d.ts +0 -917
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare function useFormKitSchema(): {
|
|
2
|
+
addComponent: (component?: string, props?: object, render?: string | boolean, formKitAttrs?: object) => object;
|
|
3
|
+
addElement: (element?: string, children?: any[] | string, attrs?: object, render?: string | boolean, formKitAttrs?: object) => {
|
|
4
|
+
$el: string;
|
|
5
|
+
if: string;
|
|
6
|
+
attrs: object;
|
|
7
|
+
children: string | any[];
|
|
8
|
+
};
|
|
9
|
+
addGroup: (name: string, children?: object[], render?: string | boolean, formKitAttrs?: object) => {
|
|
10
|
+
$formkit: string;
|
|
11
|
+
if: string;
|
|
12
|
+
name: string;
|
|
13
|
+
children: object[];
|
|
14
|
+
};
|
|
15
|
+
addList: (name: string, children?: object[], dynamic?: boolean, render?: string | boolean, formKitAttrs?: object) => {
|
|
16
|
+
$formkit: string;
|
|
17
|
+
if: string;
|
|
18
|
+
name: string;
|
|
19
|
+
dynamic: boolean;
|
|
20
|
+
children: object[];
|
|
21
|
+
};
|
|
22
|
+
addListGroup: (children?: object[], render?: string | boolean, formKitAttrs?: object) => {
|
|
23
|
+
$formkit: string;
|
|
24
|
+
if: string;
|
|
25
|
+
for: string[];
|
|
26
|
+
key: string;
|
|
27
|
+
index: string;
|
|
28
|
+
children: object[];
|
|
29
|
+
};
|
|
30
|
+
addElementsInOuterDiv: (children?: object[], innerClass?: string, outerClass?: string, label?: string, help?: string, render?: string | boolean) => {
|
|
31
|
+
$el: string;
|
|
32
|
+
if: string;
|
|
33
|
+
attrs: object;
|
|
34
|
+
children: string | any[];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFormKitSchema = useFormKitSchema;
|
|
7
|
+
function useFormKitSchema() {
|
|
8
|
+
const addComponent = (component = "Button", props = {}, render = true, formKitAttrs = {}) => {
|
|
9
|
+
return {
|
|
10
|
+
$cmp: component,
|
|
11
|
+
if: render.toString(),
|
|
12
|
+
props,
|
|
13
|
+
...formKitAttrs
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const addElement = (element = "div", children = [], attrs = {}, render = true, formKitAttrs = {}) => {
|
|
17
|
+
return {
|
|
18
|
+
$el: element,
|
|
19
|
+
if: render.toString(),
|
|
20
|
+
attrs,
|
|
21
|
+
children,
|
|
22
|
+
...formKitAttrs
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
const addGroup = (name, children = [], render = true, formKitAttrs = {}) => {
|
|
26
|
+
return {
|
|
27
|
+
$formkit: "group",
|
|
28
|
+
if: render.toString(),
|
|
29
|
+
name,
|
|
30
|
+
children,
|
|
31
|
+
...formKitAttrs
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const addList = (name, children = [], dynamic = true, render = true, formKitAttrs = {}) => {
|
|
35
|
+
return {
|
|
36
|
+
$formkit: "list",
|
|
37
|
+
if: render.toString(),
|
|
38
|
+
name,
|
|
39
|
+
dynamic,
|
|
40
|
+
children,
|
|
41
|
+
...formKitAttrs
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const addListGroup = (children = [], render = true, formKitAttrs = {}) => {
|
|
45
|
+
return {
|
|
46
|
+
$formkit: "group",
|
|
47
|
+
if: render.toString(),
|
|
48
|
+
for: ["item", "index", "$items"],
|
|
49
|
+
// 👈 $items is in the slot’s scope
|
|
50
|
+
key: "$item",
|
|
51
|
+
index: "$index",
|
|
52
|
+
children,
|
|
53
|
+
...formKitAttrs
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const addElementsInOuterDiv = (children = [], innerClass = "", outerClass = "", label = "", help = "", render = true) => {
|
|
57
|
+
const inner = addElement("div", children, {
|
|
58
|
+
class: `formkit-inner ${innerClass}`,
|
|
59
|
+
style: "position: relative;"
|
|
60
|
+
});
|
|
61
|
+
const labelDiv = addElement("label", [label], {
|
|
62
|
+
class: "formkit-label"
|
|
63
|
+
});
|
|
64
|
+
const wrapperDiv = addElement("div", [labelDiv, inner], {
|
|
65
|
+
class: "formkit-wrapper"
|
|
66
|
+
});
|
|
67
|
+
const helpDiv = addElement("div", [help], {
|
|
68
|
+
class: "formkit-help"
|
|
69
|
+
});
|
|
70
|
+
return addElement("div", [wrapperDiv, helpDiv], {
|
|
71
|
+
class: `formkit-outer ${outerClass}`,
|
|
72
|
+
style: "position: relative;"
|
|
73
|
+
}, render);
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
addComponent,
|
|
77
|
+
addElement,
|
|
78
|
+
addGroup,
|
|
79
|
+
addList,
|
|
80
|
+
addListGroup,
|
|
81
|
+
addElementsInOuterDiv
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function useFormKitSchema() {
|
|
2
|
+
const addComponent = (component = "Button", props = {}, render = true, formKitAttrs = {}) => {
|
|
3
|
+
return {
|
|
4
|
+
$cmp: component,
|
|
5
|
+
if: render.toString(),
|
|
6
|
+
props,
|
|
7
|
+
...formKitAttrs
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const addElement = (element = "div", children = [], attrs = {}, render = true, formKitAttrs = {}) => {
|
|
11
|
+
return {
|
|
12
|
+
$el: element,
|
|
13
|
+
if: render.toString(),
|
|
14
|
+
attrs,
|
|
15
|
+
children,
|
|
16
|
+
...formKitAttrs
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const addGroup = (name, children = [], render = true, formKitAttrs = {}) => {
|
|
20
|
+
return {
|
|
21
|
+
$formkit: "group",
|
|
22
|
+
if: render.toString(),
|
|
23
|
+
name,
|
|
24
|
+
children,
|
|
25
|
+
...formKitAttrs
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const addList = (name, children = [], dynamic = true, render = true, formKitAttrs = {}) => {
|
|
29
|
+
return {
|
|
30
|
+
$formkit: "list",
|
|
31
|
+
if: render.toString(),
|
|
32
|
+
name,
|
|
33
|
+
dynamic,
|
|
34
|
+
children,
|
|
35
|
+
...formKitAttrs
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const addListGroup = (children = [], render = true, formKitAttrs = {}) => {
|
|
39
|
+
return {
|
|
40
|
+
$formkit: "group",
|
|
41
|
+
if: render.toString(),
|
|
42
|
+
for: ["item", "index", "$items"],
|
|
43
|
+
// 👈 $items is in the slot’s scope
|
|
44
|
+
key: "$item",
|
|
45
|
+
index: "$index",
|
|
46
|
+
children,
|
|
47
|
+
...formKitAttrs
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const addElementsInOuterDiv = (children = [], innerClass = "", outerClass = "", label = "", help = "", render = true) => {
|
|
51
|
+
const inner = addElement("div", children, {
|
|
52
|
+
class: `formkit-inner ${innerClass}`,
|
|
53
|
+
style: "position: relative;"
|
|
54
|
+
});
|
|
55
|
+
const labelDiv = addElement("label", [label], { class: "formkit-label" });
|
|
56
|
+
const wrapperDiv = addElement("div", [labelDiv, inner], { class: "formkit-wrapper" });
|
|
57
|
+
const helpDiv = addElement("div", [help], { class: "formkit-help" });
|
|
58
|
+
return addElement(
|
|
59
|
+
"div",
|
|
60
|
+
[wrapperDiv, helpDiv],
|
|
61
|
+
{ class: `formkit-outer ${outerClass}`, style: "position: relative;" },
|
|
62
|
+
render
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
return { addComponent, addElement, addGroup, addList, addListGroup, addElementsInOuterDiv };
|
|
66
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function useFormKitSection(context: any): {
|
|
2
|
+
generateId: () => string;
|
|
3
|
+
hasPrefix: import("vue").ComputedRef<boolean>;
|
|
4
|
+
hasPrefixIcon: import("vue").ComputedRef<boolean>;
|
|
5
|
+
hasSuffix: import("vue").ComputedRef<boolean>;
|
|
6
|
+
hasSuffixIcon: import("vue").ComputedRef<boolean>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFormKitSection = useFormKitSection;
|
|
7
|
+
var _vue = require("vue");
|
|
8
|
+
function useFormKitSection(context) {
|
|
9
|
+
const hasPrefix = (0, _vue.computed)(() => {
|
|
10
|
+
return Boolean(context?.prefix?.length > 0);
|
|
11
|
+
});
|
|
12
|
+
const hasPrefixIcon = (0, _vue.computed)(() => {
|
|
13
|
+
return Boolean(context?.iconPrefix?.length > 0);
|
|
14
|
+
});
|
|
15
|
+
const hasSuffixIcon = (0, _vue.computed)(() => {
|
|
16
|
+
return Boolean(context?.iconSuffix?.length > 0);
|
|
17
|
+
});
|
|
18
|
+
const hasSuffix = (0, _vue.computed)(() => {
|
|
19
|
+
return Boolean(context?.suffix?.length > 0);
|
|
20
|
+
});
|
|
21
|
+
function generateId() {
|
|
22
|
+
return typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
generateId,
|
|
26
|
+
hasPrefix,
|
|
27
|
+
hasPrefixIcon,
|
|
28
|
+
hasSuffix,
|
|
29
|
+
hasSuffixIcon
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
export function useFormKitSection(context) {
|
|
3
|
+
const hasPrefix = computed(() => {
|
|
4
|
+
return Boolean(context?.prefix?.length > 0);
|
|
5
|
+
});
|
|
6
|
+
const hasPrefixIcon = computed(() => {
|
|
7
|
+
return Boolean(context?.iconPrefix?.length > 0);
|
|
8
|
+
});
|
|
9
|
+
const hasSuffixIcon = computed(() => {
|
|
10
|
+
return Boolean(context?.iconSuffix?.length > 0);
|
|
11
|
+
});
|
|
12
|
+
const hasSuffix = computed(() => {
|
|
13
|
+
return Boolean(context?.suffix?.length > 0);
|
|
14
|
+
});
|
|
15
|
+
function generateId() {
|
|
16
|
+
return typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2);
|
|
17
|
+
}
|
|
18
|
+
return { generateId, hasPrefix, hasPrefixIcon, hasSuffix, hasSuffixIcon };
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function useInputEditor(): {
|
|
2
|
+
primeInputNames: string[];
|
|
3
|
+
primeOutputNames: string[];
|
|
4
|
+
editorDataToSchema: (data: any) => any;
|
|
5
|
+
editorDataToJson: (data: any) => string;
|
|
6
|
+
editorDataToCode: (data: any) => string;
|
|
7
|
+
schemaToEditorData: (schema: any) => any;
|
|
8
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useInputEditor = useInputEditor;
|
|
7
|
+
function useInputEditor() {
|
|
8
|
+
const primeInputWithOptionNames = ["CascadeSelect", "Listbox", "MultiSelect", "RadioButton", "Select", "SelectButton", "TreeSelect"];
|
|
9
|
+
const primeInputNames = [...primeInputWithOptionNames, "AutoComplete", "Checkbox", "ColorPicker", "DatePicker", "Editor", "InputMask", "InputNumber", "InputOtp", "InputText", "Knob", "Password", "Rating", "Slider", "Textarea", "ToggleButton", "ToggleSwitch"].sort();
|
|
10
|
+
const primeOutputNames = ["OutputBoolean", "OutputDate", "OutputDuration", "OutputLink", "OutputList", "OutputNumber", "OutputReference", "OutputText"];
|
|
11
|
+
function editorDataToSchema(data) {
|
|
12
|
+
if (!data) return {};
|
|
13
|
+
const formkitInput = data?._dollar_formkit;
|
|
14
|
+
let tempData = {};
|
|
15
|
+
if (data.prime && Array.isArray(data.prime) && data.prime.length > 0) {
|
|
16
|
+
const mapped = data.prime.filter(entry => entry && typeof entry === "object" && "prime_key" in entry && "prime_value" in entry).map(entry => {
|
|
17
|
+
const key = entry.prime_key || "";
|
|
18
|
+
let value = entry.prime_value;
|
|
19
|
+
if (formkitInput === "primeInputOtp" && key === "length" && value !== void 0) {
|
|
20
|
+
value = Number(value);
|
|
21
|
+
}
|
|
22
|
+
return [key, value];
|
|
23
|
+
});
|
|
24
|
+
tempData = Object.assign({}, ...mapped.map(([key, val]) => ({
|
|
25
|
+
[key]: val
|
|
26
|
+
})));
|
|
27
|
+
}
|
|
28
|
+
const readonlyValue = data.readonly === true ? true : void 0;
|
|
29
|
+
const disabledValue = data.disabled === true ? true : void 0;
|
|
30
|
+
const preserveValue = data.preserve === true ? true : void 0;
|
|
31
|
+
const defaultObject = {
|
|
32
|
+
readonly: readonlyValue,
|
|
33
|
+
disabled: disabledValue,
|
|
34
|
+
preserve: preserveValue
|
|
35
|
+
};
|
|
36
|
+
let outerClass = "";
|
|
37
|
+
if (data.outerClass) outerClass = `${outerClass} ${data.outerClass}`.trim();
|
|
38
|
+
let wrapperClass = "";
|
|
39
|
+
if (data.wrapperClass) wrapperClass = `${wrapperClass} ${data.wrapperClass}`.trim();
|
|
40
|
+
let innerClass = "";
|
|
41
|
+
if (data.innerClass) innerClass = `${innerClass} ${data.innerClass}`.trim();
|
|
42
|
+
const undefinedObject = {
|
|
43
|
+
prime: void 0,
|
|
44
|
+
schemaResultFormKey: void 0,
|
|
45
|
+
_dollar_formkit: void 0,
|
|
46
|
+
slots: void 0,
|
|
47
|
+
selectButton: void 0
|
|
48
|
+
};
|
|
49
|
+
const useOptions = formkitInput ? primeInputWithOptionNames.map(s => `prime${s}`).includes(formkitInput) : false;
|
|
50
|
+
let result = {};
|
|
51
|
+
if (useOptions) {
|
|
52
|
+
result = {
|
|
53
|
+
...data,
|
|
54
|
+
$formkit: formkitInput,
|
|
55
|
+
...tempData,
|
|
56
|
+
...undefinedObject,
|
|
57
|
+
...defaultObject,
|
|
58
|
+
outerClass,
|
|
59
|
+
wrapperClass,
|
|
60
|
+
innerClass,
|
|
61
|
+
optionLabel: "label",
|
|
62
|
+
optionValue: "value"
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
65
|
+
result = {
|
|
66
|
+
...data,
|
|
67
|
+
$formkit: formkitInput,
|
|
68
|
+
...tempData,
|
|
69
|
+
...undefinedObject,
|
|
70
|
+
...defaultObject,
|
|
71
|
+
outerClass,
|
|
72
|
+
wrapperClass,
|
|
73
|
+
innerClass,
|
|
74
|
+
options: void 0
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
for (const key in result) {
|
|
78
|
+
const value = result[key];
|
|
79
|
+
if (value !== null && value !== void 0 && typeof value === "string") {
|
|
80
|
+
if (value.trim().length === 0) {
|
|
81
|
+
result[key] = void 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
function dataToSchema(data) {
|
|
88
|
+
if (!data) return {};
|
|
89
|
+
const schema = editorDataToSchema(data);
|
|
90
|
+
if (schema?.options && Array.isArray(schema.options)) {
|
|
91
|
+
const options = schema.options.map(o => o ? JSON.parse(JSON.stringify(o)) : {});
|
|
92
|
+
return {
|
|
93
|
+
...schema,
|
|
94
|
+
options
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
return schema;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function editorDataToJson(data) {
|
|
101
|
+
if (!data) return "{}";
|
|
102
|
+
return JSON.stringify(dataToSchema(data));
|
|
103
|
+
}
|
|
104
|
+
function objectToString(data) {
|
|
105
|
+
if (!data) return "{}";
|
|
106
|
+
return `{${Object.entries(data).map(([key, value]) => {
|
|
107
|
+
if (key === "options" && Array.isArray(value) && value.length > 0) {
|
|
108
|
+
let result = "[";
|
|
109
|
+
value.forEach(o => {
|
|
110
|
+
if (o && typeof o === "object") {
|
|
111
|
+
result = `${result + objectToString(o)}, `;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return `${key}: ${result.substring(0, result.length - 2)}]`;
|
|
115
|
+
} else if (key === "primeInputOtp") {
|
|
116
|
+
return `${key}: ${value}`;
|
|
117
|
+
} else {
|
|
118
|
+
return `${key}: '${value}'`;
|
|
119
|
+
}
|
|
120
|
+
}).join()}}`;
|
|
121
|
+
}
|
|
122
|
+
function editorDataToObject(data) {
|
|
123
|
+
if (!data) return "{}";
|
|
124
|
+
try {
|
|
125
|
+
const jsonData = editorDataToJson(data);
|
|
126
|
+
return objectToString(JSON.parse(jsonData));
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error("Error in editorDataToObject:", error);
|
|
129
|
+
return "{}";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function schemaToEditorData(schema) {
|
|
133
|
+
if (!schema) return {};
|
|
134
|
+
const formkitInput = schema?.$formkit;
|
|
135
|
+
return {
|
|
136
|
+
...schema,
|
|
137
|
+
_dollar_formkit: formkitInput
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
primeInputNames,
|
|
142
|
+
primeOutputNames,
|
|
143
|
+
editorDataToSchema,
|
|
144
|
+
editorDataToJson,
|
|
145
|
+
editorDataToCode: editorDataToObject,
|
|
146
|
+
schemaToEditorData
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export function useInputEditor() {
|
|
2
|
+
const primeInputWithOptionNames = [
|
|
3
|
+
"CascadeSelect",
|
|
4
|
+
"Listbox",
|
|
5
|
+
"MultiSelect",
|
|
6
|
+
"RadioButton",
|
|
7
|
+
"Select",
|
|
8
|
+
"SelectButton",
|
|
9
|
+
"TreeSelect"
|
|
10
|
+
];
|
|
11
|
+
const primeInputNames = [
|
|
12
|
+
...primeInputWithOptionNames,
|
|
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 primeOutputNames = [
|
|
31
|
+
"OutputBoolean",
|
|
32
|
+
"OutputDate",
|
|
33
|
+
"OutputDuration",
|
|
34
|
+
"OutputLink",
|
|
35
|
+
"OutputList",
|
|
36
|
+
"OutputNumber",
|
|
37
|
+
"OutputReference",
|
|
38
|
+
"OutputText"
|
|
39
|
+
];
|
|
40
|
+
function editorDataToSchema(data) {
|
|
41
|
+
if (!data) return {};
|
|
42
|
+
const formkitInput = data?._dollar_formkit;
|
|
43
|
+
let tempData = {};
|
|
44
|
+
if (data.prime && Array.isArray(data.prime) && data.prime.length > 0) {
|
|
45
|
+
const mapped = data.prime.filter(
|
|
46
|
+
(entry) => entry && typeof entry === "object" && "prime_key" in entry && "prime_value" in entry
|
|
47
|
+
).map((entry) => {
|
|
48
|
+
const key = entry.prime_key || "";
|
|
49
|
+
let value = entry.prime_value;
|
|
50
|
+
if (formkitInput === "primeInputOtp" && key === "length" && value !== void 0) {
|
|
51
|
+
value = Number(value);
|
|
52
|
+
}
|
|
53
|
+
return [key, value];
|
|
54
|
+
});
|
|
55
|
+
tempData = Object.assign({}, ...mapped.map(([key, val]) => ({ [key]: val })));
|
|
56
|
+
}
|
|
57
|
+
const readonlyValue = data.readonly === true ? true : void 0;
|
|
58
|
+
const disabledValue = data.disabled === true ? true : void 0;
|
|
59
|
+
const preserveValue = data.preserve === true ? true : void 0;
|
|
60
|
+
const defaultObject = {
|
|
61
|
+
readonly: readonlyValue,
|
|
62
|
+
disabled: disabledValue,
|
|
63
|
+
preserve: preserveValue
|
|
64
|
+
};
|
|
65
|
+
let outerClass = "";
|
|
66
|
+
if (data.outerClass) outerClass = `${outerClass} ${data.outerClass}`.trim();
|
|
67
|
+
let wrapperClass = "";
|
|
68
|
+
if (data.wrapperClass) wrapperClass = `${wrapperClass} ${data.wrapperClass}`.trim();
|
|
69
|
+
let innerClass = "";
|
|
70
|
+
if (data.innerClass) innerClass = `${innerClass} ${data.innerClass}`.trim();
|
|
71
|
+
const undefinedObject = {
|
|
72
|
+
prime: void 0,
|
|
73
|
+
schemaResultFormKey: void 0,
|
|
74
|
+
_dollar_formkit: void 0,
|
|
75
|
+
slots: void 0,
|
|
76
|
+
selectButton: void 0
|
|
77
|
+
};
|
|
78
|
+
const useOptions = formkitInput ? primeInputWithOptionNames.map((s) => `prime${s}`).includes(formkitInput) : false;
|
|
79
|
+
let result = {};
|
|
80
|
+
if (useOptions) {
|
|
81
|
+
result = {
|
|
82
|
+
...data,
|
|
83
|
+
$formkit: formkitInput,
|
|
84
|
+
...tempData,
|
|
85
|
+
...undefinedObject,
|
|
86
|
+
...defaultObject,
|
|
87
|
+
outerClass,
|
|
88
|
+
wrapperClass,
|
|
89
|
+
innerClass,
|
|
90
|
+
optionLabel: "label",
|
|
91
|
+
optionValue: "value"
|
|
92
|
+
};
|
|
93
|
+
} else {
|
|
94
|
+
result = {
|
|
95
|
+
...data,
|
|
96
|
+
$formkit: formkitInput,
|
|
97
|
+
...tempData,
|
|
98
|
+
...undefinedObject,
|
|
99
|
+
...defaultObject,
|
|
100
|
+
outerClass,
|
|
101
|
+
wrapperClass,
|
|
102
|
+
innerClass,
|
|
103
|
+
options: void 0
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
for (const key in result) {
|
|
107
|
+
const value = result[key];
|
|
108
|
+
if (value !== null && value !== void 0 && typeof value === "string") {
|
|
109
|
+
if (value.trim().length === 0) {
|
|
110
|
+
result[key] = void 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
function dataToSchema(data) {
|
|
117
|
+
if (!data) return {};
|
|
118
|
+
const schema = editorDataToSchema(data);
|
|
119
|
+
if (schema?.options && Array.isArray(schema.options)) {
|
|
120
|
+
const options = schema.options.map((o) => o ? JSON.parse(JSON.stringify(o)) : {});
|
|
121
|
+
return { ...schema, options };
|
|
122
|
+
} else {
|
|
123
|
+
return schema;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function editorDataToJson(data) {
|
|
127
|
+
if (!data) return "{}";
|
|
128
|
+
return JSON.stringify(dataToSchema(data));
|
|
129
|
+
}
|
|
130
|
+
function objectToString(data) {
|
|
131
|
+
if (!data) return "{}";
|
|
132
|
+
return `{${Object.entries(data).map(([key, value]) => {
|
|
133
|
+
if (key === "options" && Array.isArray(value) && value.length > 0) {
|
|
134
|
+
let result = "[";
|
|
135
|
+
value.forEach((o) => {
|
|
136
|
+
if (o && typeof o === "object") {
|
|
137
|
+
result = `${result + objectToString(o)}, `;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return `${key}: ${result.substring(0, result.length - 2)}]`;
|
|
141
|
+
} else if (key === "primeInputOtp") {
|
|
142
|
+
return `${key}: ${value}`;
|
|
143
|
+
} else {
|
|
144
|
+
return `${key}: '${value}'`;
|
|
145
|
+
}
|
|
146
|
+
}).join()}}`;
|
|
147
|
+
}
|
|
148
|
+
function editorDataToObject(data) {
|
|
149
|
+
if (!data) return "{}";
|
|
150
|
+
try {
|
|
151
|
+
const jsonData = editorDataToJson(data);
|
|
152
|
+
return objectToString(JSON.parse(jsonData));
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error("Error in editorDataToObject:", error);
|
|
155
|
+
return "{}";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function schemaToEditorData(schema) {
|
|
159
|
+
if (!schema) return {};
|
|
160
|
+
const formkitInput = schema?.$formkit;
|
|
161
|
+
return { ...schema, _dollar_formkit: formkitInput };
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
primeInputNames,
|
|
165
|
+
primeOutputNames,
|
|
166
|
+
editorDataToSchema,
|
|
167
|
+
editorDataToJson,
|
|
168
|
+
editorDataToCode: editorDataToObject,
|
|
169
|
+
schemaToEditorData
|
|
170
|
+
};
|
|
171
|
+
}
|