@morscherlab/mld-sdk 0.6.5 → 0.7.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/dist/__tests__/composables/formBuilderRegistry.test.d.ts +1 -0
- package/dist/__tests__/composables/useFormBuilder.test.d.ts +1 -0
- package/dist/components/BaseButton.vue.d.ts +1 -1
- package/dist/components/BasePill.vue.d.ts +1 -1
- package/dist/components/DropdownButton.vue.d.ts +1 -1
- package/dist/components/FormActions.vue.d.ts +33 -0
- package/dist/components/FormActions.vue.js +76 -0
- package/dist/components/FormActions.vue.js.map +1 -0
- package/dist/components/FormActions.vue3.js +6 -0
- package/dist/components/FormActions.vue3.js.map +1 -0
- package/dist/components/FormBuilder.vue.js +205 -0
- package/dist/components/FormBuilder.vue.js.map +1 -0
- package/dist/components/FormBuilder.vue3.js +6 -0
- package/dist/components/FormBuilder.vue3.js.map +1 -0
- package/dist/components/FormFieldRenderer.vue.d.ts +31 -0
- package/dist/components/FormFieldRenderer.vue.js +48 -0
- package/dist/components/FormFieldRenderer.vue.js.map +1 -0
- package/dist/components/FormFieldRenderer.vue2.js +5 -0
- package/dist/components/FormFieldRenderer.vue2.js.map +1 -0
- package/dist/components/FormSection.vue.d.ts +43 -0
- package/dist/components/FormSection.vue.js +117 -0
- package/dist/components/FormSection.vue.js.map +1 -0
- package/dist/components/FormSection.vue3.js +6 -0
- package/dist/components/FormSection.vue3.js.map +1 -0
- package/dist/components/IconButton.vue.d.ts +1 -1
- package/dist/components/LoadingSpinner.vue.d.ts +1 -1
- package/dist/components/ProgressBar.vue.d.ts +1 -1
- package/dist/components/ReagentList.vue.d.ts +2 -2
- package/dist/components/ResourceCard.vue.d.ts +1 -1
- package/dist/components/SegmentedControl.vue.d.ts +1 -1
- package/dist/components/WellEditPopup.vue.d.ts +2 -2
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +19 -8
- package/dist/components/index.js.map +1 -1
- package/dist/composables/formBuilderRegistry.d.ts +13 -0
- package/dist/composables/formBuilderRegistry.js +87 -0
- package/dist/composables/formBuilderRegistry.js.map +1 -0
- package/dist/composables/index.d.ts +3 -0
- package/dist/composables/index.js +8 -0
- package/dist/composables/index.js.map +1 -1
- package/dist/composables/useFormBuilder.d.ts +23 -0
- package/dist/composables/useFormBuilder.js +264 -0
- package/dist/composables/useFormBuilder.js.map +1 -0
- package/dist/composables/usePluginConfig.d.ts +12 -0
- package/dist/composables/usePluginConfig.js +77 -0
- package/dist/composables/usePluginConfig.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.css +247 -6
- package/dist/types/form-builder.d.ts +167 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/__tests__/composables/formBuilderRegistry.test.ts +187 -0
- package/src/__tests__/composables/useFormBuilder.test.ts +917 -0
- package/src/components/FormActions.vue +92 -0
- package/src/components/FormBuilder.vue +214 -0
- package/src/components/FormFieldRenderer.vue +58 -0
- package/src/components/FormSection.vue +90 -0
- package/src/components/index.ts +6 -0
- package/src/composables/formBuilderRegistry.ts +79 -0
- package/src/composables/index.ts +7 -0
- package/src/composables/useFormBuilder.ts +382 -0
- package/src/composables/usePluginConfig.ts +92 -0
- package/src/index.ts +3 -0
- package/src/styles/components/app-container.css +1 -0
- package/src/styles/components/app-layout.css +1 -2
- package/src/styles/components/form-builder.css +69 -0
- package/src/styles/components/number-input.css +4 -1
- package/src/styles/index.css +1 -0
- package/src/types/form-builder.ts +197 -0
- package/src/types/index.ts +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -22,8 +22,8 @@ declare const __VLS_component: import('vue').DefineComponent<Props, {}, {}, {},
|
|
|
22
22
|
onClick?: ((event: MouseEvent) => any) | undefined;
|
|
23
23
|
}>, {
|
|
24
24
|
disabled: boolean;
|
|
25
|
-
variant: ButtonVariant;
|
|
26
25
|
size: ButtonSize;
|
|
26
|
+
variant: ButtonVariant;
|
|
27
27
|
loading: boolean;
|
|
28
28
|
type: "button" | "submit" | "reset";
|
|
29
29
|
fullWidth: boolean;
|
|
@@ -40,8 +40,8 @@ declare const __VLS_component: import('vue').DefineComponent<Props, {}, {}, {},
|
|
|
40
40
|
onRemove?: (() => any) | undefined;
|
|
41
41
|
}>, {
|
|
42
42
|
disabled: boolean;
|
|
43
|
-
variant: PillVariant;
|
|
44
43
|
size: PillSize;
|
|
44
|
+
variant: PillVariant;
|
|
45
45
|
removable: boolean;
|
|
46
46
|
icon: boolean;
|
|
47
47
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLSpanElement>;
|
|
@@ -38,8 +38,8 @@ declare const _default: import('vue').DefineComponent<Props, {}, {}, {}, {}, imp
|
|
|
38
38
|
"onUpdate:modelValue"?: ((value: string | number) => any) | undefined;
|
|
39
39
|
}>, {
|
|
40
40
|
disabled: boolean;
|
|
41
|
-
variant: ButtonVariant;
|
|
42
41
|
size: ButtonSize;
|
|
42
|
+
variant: ButtonVariant;
|
|
43
43
|
loading: boolean;
|
|
44
44
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
|
|
45
45
|
containerRef: HTMLDivElement;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
isWizard?: boolean;
|
|
3
|
+
isFirst?: boolean;
|
|
4
|
+
isLast?: boolean;
|
|
5
|
+
canProceed?: boolean;
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
submitLabel?: string;
|
|
9
|
+
cancelLabel?: string;
|
|
10
|
+
showCancel?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
13
|
+
submit: () => any;
|
|
14
|
+
cancel: () => any;
|
|
15
|
+
next: () => any;
|
|
16
|
+
back: () => any;
|
|
17
|
+
}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{
|
|
18
|
+
onSubmit?: (() => any) | undefined;
|
|
19
|
+
onCancel?: (() => any) | undefined;
|
|
20
|
+
onNext?: (() => any) | undefined;
|
|
21
|
+
onBack?: (() => any) | undefined;
|
|
22
|
+
}>, {
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
loading: boolean;
|
|
25
|
+
cancelLabel: string;
|
|
26
|
+
isWizard: boolean;
|
|
27
|
+
isFirst: boolean;
|
|
28
|
+
isLast: boolean;
|
|
29
|
+
canProceed: boolean;
|
|
30
|
+
submitLabel: string;
|
|
31
|
+
showCancel: boolean;
|
|
32
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
33
|
+
export default _default;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { defineComponent, openBlock, createElementBlock, createBlock, withCtx, createTextVNode, toDisplayString, createCommentVNode, createElementVNode } from "vue";
|
|
2
|
+
import _sfc_main$1 from "./BaseButton.vue.js";
|
|
3
|
+
/* empty css */
|
|
4
|
+
const _hoisted_1 = { class: "mld-form-actions" };
|
|
5
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
6
|
+
__name: "FormActions",
|
|
7
|
+
props: {
|
|
8
|
+
isWizard: { type: Boolean, default: false },
|
|
9
|
+
isFirst: { type: Boolean, default: true },
|
|
10
|
+
isLast: { type: Boolean, default: true },
|
|
11
|
+
canProceed: { type: Boolean, default: true },
|
|
12
|
+
loading: { type: Boolean, default: false },
|
|
13
|
+
disabled: { type: Boolean, default: false },
|
|
14
|
+
submitLabel: { default: "Submit" },
|
|
15
|
+
cancelLabel: { default: "Cancel" },
|
|
16
|
+
showCancel: { type: Boolean, default: false }
|
|
17
|
+
},
|
|
18
|
+
emits: ["submit", "cancel", "back", "next"],
|
|
19
|
+
setup(__props, { emit: __emit }) {
|
|
20
|
+
const emit = __emit;
|
|
21
|
+
return (_ctx, _cache) => {
|
|
22
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
23
|
+
__props.showCancel ? (openBlock(), createBlock(_sfc_main$1, {
|
|
24
|
+
key: 0,
|
|
25
|
+
variant: "ghost",
|
|
26
|
+
disabled: __props.loading || __props.disabled,
|
|
27
|
+
onClick: _cache[0] || (_cache[0] = ($event) => emit("cancel"))
|
|
28
|
+
}, {
|
|
29
|
+
default: withCtx(() => [
|
|
30
|
+
createTextVNode(toDisplayString(__props.cancelLabel), 1)
|
|
31
|
+
]),
|
|
32
|
+
_: 1
|
|
33
|
+
}, 8, ["disabled"])) : createCommentVNode("", true),
|
|
34
|
+
_cache[6] || (_cache[6] = createElementVNode("div", { style: { "flex": "1" } }, null, -1)),
|
|
35
|
+
__props.isWizard && !__props.isFirst ? (openBlock(), createBlock(_sfc_main$1, {
|
|
36
|
+
key: 1,
|
|
37
|
+
variant: "secondary",
|
|
38
|
+
disabled: __props.loading || __props.disabled,
|
|
39
|
+
onClick: _cache[1] || (_cache[1] = ($event) => emit("back"))
|
|
40
|
+
}, {
|
|
41
|
+
default: withCtx(() => [..._cache[4] || (_cache[4] = [
|
|
42
|
+
createTextVNode(" Back ", -1)
|
|
43
|
+
])]),
|
|
44
|
+
_: 1
|
|
45
|
+
}, 8, ["disabled"])) : createCommentVNode("", true),
|
|
46
|
+
__props.isWizard && !__props.isLast ? (openBlock(), createBlock(_sfc_main$1, {
|
|
47
|
+
key: 2,
|
|
48
|
+
variant: "primary",
|
|
49
|
+
disabled: !__props.canProceed || __props.loading || __props.disabled,
|
|
50
|
+
onClick: _cache[2] || (_cache[2] = ($event) => emit("next"))
|
|
51
|
+
}, {
|
|
52
|
+
default: withCtx(() => [..._cache[5] || (_cache[5] = [
|
|
53
|
+
createTextVNode(" Next ", -1)
|
|
54
|
+
])]),
|
|
55
|
+
_: 1
|
|
56
|
+
}, 8, ["disabled"])) : createCommentVNode("", true),
|
|
57
|
+
!__props.isWizard || __props.isLast ? (openBlock(), createBlock(_sfc_main$1, {
|
|
58
|
+
key: 3,
|
|
59
|
+
variant: "primary",
|
|
60
|
+
loading: __props.loading,
|
|
61
|
+
disabled: !__props.canProceed || __props.loading || __props.disabled,
|
|
62
|
+
onClick: _cache[3] || (_cache[3] = ($event) => emit("submit"))
|
|
63
|
+
}, {
|
|
64
|
+
default: withCtx(() => [
|
|
65
|
+
createTextVNode(toDisplayString(__props.submitLabel), 1)
|
|
66
|
+
]),
|
|
67
|
+
_: 1
|
|
68
|
+
}, 8, ["loading", "disabled"])) : createCommentVNode("", true)
|
|
69
|
+
]);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
export {
|
|
74
|
+
_sfc_main as default
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=FormActions.vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormActions.vue.js","sources":["../../src/components/FormActions.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * Action bar rendered at the bottom of a FormBuilder.\n *\n * Supports two modes:\n * - Flat form: shows an optional Cancel button and a Submit button.\n * - Wizard (`isWizard=true`): shows Back / Next on intermediate steps and\n * Submit only on the last step. Back is hidden on the first step.\n *\n * The `canProceed` prop gates the primary action (Next or Submit) to prevent\n * advancing when the current step has validation errors.\n */\nimport BaseButton from './BaseButton.vue'\n\ninterface Props {\n isWizard?: boolean\n isFirst?: boolean\n isLast?: boolean\n canProceed?: boolean\n loading?: boolean\n disabled?: boolean\n submitLabel?: string\n cancelLabel?: string\n showCancel?: boolean\n}\n\nwithDefaults(defineProps<Props>(), {\n isWizard: false,\n isFirst: true,\n isLast: true,\n canProceed: true,\n loading: false,\n disabled: false,\n submitLabel: 'Submit',\n cancelLabel: 'Cancel',\n showCancel: false,\n})\n\nconst emit = defineEmits<{\n submit: []\n cancel: []\n back: []\n next: []\n}>()\n</script>\n\n<template>\n <div class=\"mld-form-actions\">\n <BaseButton\n v-if=\"showCancel\"\n variant=\"ghost\"\n :disabled=\"loading || disabled\"\n @click=\"emit('cancel')\"\n >\n {{ cancelLabel }}\n </BaseButton>\n\n <div style=\"flex: 1\" />\n\n <BaseButton\n v-if=\"isWizard && !isFirst\"\n variant=\"secondary\"\n :disabled=\"loading || disabled\"\n @click=\"emit('back')\"\n >\n Back\n </BaseButton>\n\n <BaseButton\n v-if=\"isWizard && !isLast\"\n variant=\"primary\"\n :disabled=\"!canProceed || loading || disabled\"\n @click=\"emit('next')\"\n >\n Next\n </BaseButton>\n\n <BaseButton\n v-if=\"!isWizard || isLast\"\n variant=\"primary\"\n :loading=\"loading\"\n :disabled=\"!canProceed || loading || disabled\"\n @click=\"emit('submit')\"\n >\n {{ submitLabel }}\n </BaseButton>\n </div>\n</template>\n\n<style>\n@import '../styles/components/form-builder.css';\n</style>\n"],"names":["_openBlock","_createElementBlock","_createBlock","BaseButton","_createElementVNode"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,UAAM,OAAO;;AASX,aAAAA,UAAA,GAAAC,mBAuCM,OAvCN,YAuCM;AAAA,QArCI,QAAA,2BADRC,YAOaC,aAAA;AAAA;UALX,SAAQ;AAAA,UACP,UAAU,QAAA,WAAW,QAAA;AAAA,UACrB,+CAAO,KAAI,QAAA;AAAA,QAAA;2BAEZ,MAAiB;AAAA,4CAAd,QAAA,WAAW,GAAA,CAAA;AAAA,UAAA;;;kCAGhBC,mBAAuB,OAAA,EAAlB,OAAA,EAAA,QAAA,IAAA,EAAA,GAAe,MAAA,EAAA;AAAA,QAGZ,QAAA,aAAa,QAAA,wBADrBF,YAOaC,aAAA;AAAA;UALX,SAAQ;AAAA,UACP,UAAU,QAAA,WAAW,QAAA;AAAA,UACrB,+CAAO,KAAI,MAAA;AAAA,QAAA;2BACb,MAED,CAAA,GAAA,OAAA,CAAA,MAAA,OAAA,CAAA,IAAA;AAAA,4BAFC,UAED,EAAA;AAAA,UAAA;;;QAGQ,QAAA,aAAa,QAAA,uBADrBD,YAOaC,aAAA;AAAA;UALX,SAAQ;AAAA,UACP,UAAQ,CAAG,QAAA,cAAc,QAAA,WAAW,QAAA;AAAA,UACpC,+CAAO,KAAI,MAAA;AAAA,QAAA;2BACb,MAED,CAAA,GAAA,OAAA,CAAA,MAAA,OAAA,CAAA,IAAA;AAAA,4BAFC,UAED,EAAA;AAAA,UAAA;;;QAGS,CAAA,QAAA,YAAY,QAAA,uBADrBD,YAQaC,aAAA;AAAA;UANX,SAAQ;AAAA,UACP,SAAS,QAAA;AAAA,UACT,UAAQ,CAAG,QAAA,cAAc,QAAA,WAAW,QAAA;AAAA,UACpC,+CAAO,KAAI,QAAA;AAAA,QAAA;2BAEZ,MAAiB;AAAA,4CAAd,QAAA,WAAW,GAAA,CAAA;AAAA,UAAA;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormActions.vue3.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { defineComponent, watch, computed, ref, openBlock, createElementBlock, normalizeClass, createBlock, unref, createSlots, withCtx, renderSlot, createVNode, renderList, createElementVNode, Fragment, mergeProps, createCommentVNode } from "vue";
|
|
2
|
+
import { useFormBuilder } from "../composables/useFormBuilder.js";
|
|
3
|
+
import _sfc_main$1 from "./StepWizard.vue.js";
|
|
4
|
+
/* empty css */
|
|
5
|
+
import _sfc_main$3 from "./FormSection.vue.js";
|
|
6
|
+
/* empty css */
|
|
7
|
+
import _sfc_main$2 from "./FormActions.vue.js";
|
|
8
|
+
/* empty css */
|
|
9
|
+
const _hoisted_1 = { class: "mld-form-builder__step" };
|
|
10
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
11
|
+
__name: "FormBuilder",
|
|
12
|
+
props: {
|
|
13
|
+
schema: {},
|
|
14
|
+
modelValue: {},
|
|
15
|
+
enhancements: {},
|
|
16
|
+
loading: { type: Boolean, default: false },
|
|
17
|
+
disabled: { type: Boolean, default: false },
|
|
18
|
+
size: {},
|
|
19
|
+
readonly: { type: Boolean, default: false }
|
|
20
|
+
},
|
|
21
|
+
emits: ["update:modelValue", "submit", "cancel"],
|
|
22
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
23
|
+
const props = __props;
|
|
24
|
+
const emit = __emit;
|
|
25
|
+
const builder = useFormBuilder(
|
|
26
|
+
props.schema,
|
|
27
|
+
props.modelValue,
|
|
28
|
+
props.enhancements
|
|
29
|
+
);
|
|
30
|
+
watch(
|
|
31
|
+
() => ({ ...builder.form.data }),
|
|
32
|
+
(data) => emit("update:modelValue", data),
|
|
33
|
+
{ deep: true }
|
|
34
|
+
);
|
|
35
|
+
const isWizard = computed(() => !!props.schema.steps);
|
|
36
|
+
const wizardRef = ref(null);
|
|
37
|
+
const wizardSteps = computed(() => {
|
|
38
|
+
if (!props.schema.steps) return [];
|
|
39
|
+
return props.schema.steps.map((step) => ({
|
|
40
|
+
id: step.id,
|
|
41
|
+
label: step.label,
|
|
42
|
+
description: step.description,
|
|
43
|
+
icon: step.icon,
|
|
44
|
+
optional: step.optional
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
47
|
+
watch(
|
|
48
|
+
() => builder.isCurrentStepValid.value,
|
|
49
|
+
(valid) => {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = wizardRef.value) == null ? void 0 : _a.setStepValid(builder.currentStep.value, valid);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
function handleNext() {
|
|
55
|
+
var _a;
|
|
56
|
+
const success = builder.goNext();
|
|
57
|
+
if (success) {
|
|
58
|
+
(_a = wizardRef.value) == null ? void 0 : _a.setStepValid(builder.currentStep.value - 1, true);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function handleSubmit() {
|
|
62
|
+
await builder.submit();
|
|
63
|
+
const formData = builder.form.data;
|
|
64
|
+
const visibleData = Object.fromEntries(
|
|
65
|
+
builder.fields.filter((f) => builder.isFieldVisible(f.name)).map((f) => [f.name, formData[f.name]])
|
|
66
|
+
);
|
|
67
|
+
emit("submit", visibleData);
|
|
68
|
+
}
|
|
69
|
+
function handleCancel() {
|
|
70
|
+
emit("cancel");
|
|
71
|
+
}
|
|
72
|
+
__expose({
|
|
73
|
+
form: builder.form,
|
|
74
|
+
validate: builder.validate,
|
|
75
|
+
reset: builder.reset,
|
|
76
|
+
goNext: builder.goNext,
|
|
77
|
+
goBack: builder.goBack,
|
|
78
|
+
goToStep: builder.goToStep,
|
|
79
|
+
builder
|
|
80
|
+
});
|
|
81
|
+
return (_ctx, _cache) => {
|
|
82
|
+
return openBlock(), createElementBlock("div", {
|
|
83
|
+
class: normalizeClass(["mld-form-builder", __props.size ? `mld-form-builder--${__props.size}` : ""])
|
|
84
|
+
}, [
|
|
85
|
+
isWizard.value && __props.schema.steps ? (openBlock(), createBlock(_sfc_main$1, {
|
|
86
|
+
key: 0,
|
|
87
|
+
ref_key: "wizardRef",
|
|
88
|
+
ref: wizardRef,
|
|
89
|
+
steps: wizardSteps.value,
|
|
90
|
+
"model-value": unref(builder).currentStep.value,
|
|
91
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(builder).goToStep($event))
|
|
92
|
+
}, createSlots({
|
|
93
|
+
navigation: withCtx(({ isFirst, isLast }) => [
|
|
94
|
+
renderSlot(_ctx.$slots, "actions", {
|
|
95
|
+
form: unref(builder).form,
|
|
96
|
+
builder: unref(builder)
|
|
97
|
+
}, () => [
|
|
98
|
+
createVNode(_sfc_main$2, {
|
|
99
|
+
"is-wizard": "",
|
|
100
|
+
"is-first": isFirst,
|
|
101
|
+
"is-last": isLast,
|
|
102
|
+
"can-proceed": unref(builder).isCurrentStepValid.value,
|
|
103
|
+
loading: __props.loading || unref(builder).form.isSubmitting.value,
|
|
104
|
+
disabled: __props.disabled,
|
|
105
|
+
"submit-label": __props.schema.submitLabel ?? "Submit",
|
|
106
|
+
"cancel-label": __props.schema.cancelLabel ?? "Cancel",
|
|
107
|
+
"show-cancel": __props.schema.showCancel ?? false,
|
|
108
|
+
onNext: handleNext,
|
|
109
|
+
onBack: unref(builder).goBack,
|
|
110
|
+
onSubmit: handleSubmit,
|
|
111
|
+
onCancel: handleCancel
|
|
112
|
+
}, null, 8, ["is-first", "is-last", "can-proceed", "loading", "disabled", "submit-label", "cancel-label", "show-cancel", "onBack"])
|
|
113
|
+
])
|
|
114
|
+
]),
|
|
115
|
+
_: 2
|
|
116
|
+
}, [
|
|
117
|
+
renderList(__props.schema.steps, (step) => {
|
|
118
|
+
return {
|
|
119
|
+
name: `step-${step.id}`,
|
|
120
|
+
fn: withCtx(() => [
|
|
121
|
+
createElementVNode("div", _hoisted_1, [
|
|
122
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(step.sections, (section) => {
|
|
123
|
+
return openBlock(), createElementBlock(Fragment, {
|
|
124
|
+
key: section.id
|
|
125
|
+
}, [
|
|
126
|
+
unref(builder).isSectionVisible(section.id) ? (openBlock(), createBlock(_sfc_main$3, {
|
|
127
|
+
key: 0,
|
|
128
|
+
section,
|
|
129
|
+
builder: unref(builder)
|
|
130
|
+
}, createSlots({
|
|
131
|
+
[`section:${section.id}`]: withCtx((slotProps) => [
|
|
132
|
+
renderSlot(_ctx.$slots, `section:${section.id}`, mergeProps({ ref_for: true }, slotProps))
|
|
133
|
+
]),
|
|
134
|
+
[`section:${section.id}:after`]: withCtx((slotProps) => [
|
|
135
|
+
renderSlot(_ctx.$slots, `section:${section.id}:after`, mergeProps({ ref_for: true }, slotProps))
|
|
136
|
+
]),
|
|
137
|
+
_: 2
|
|
138
|
+
}, [
|
|
139
|
+
renderList(section.fields, (field) => {
|
|
140
|
+
return {
|
|
141
|
+
name: `field:${field.name}`,
|
|
142
|
+
fn: withCtx((slotProps) => [
|
|
143
|
+
renderSlot(_ctx.$slots, `field:${field.name}`, mergeProps({ ref_for: true }, slotProps))
|
|
144
|
+
])
|
|
145
|
+
};
|
|
146
|
+
})
|
|
147
|
+
]), 1032, ["section", "builder"])) : createCommentVNode("", true)
|
|
148
|
+
], 64);
|
|
149
|
+
}), 128))
|
|
150
|
+
])
|
|
151
|
+
])
|
|
152
|
+
};
|
|
153
|
+
})
|
|
154
|
+
]), 1032, ["steps", "model-value"])) : __props.schema.sections ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
155
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.schema.sections, (section) => {
|
|
156
|
+
return openBlock(), createElementBlock(Fragment, {
|
|
157
|
+
key: section.id
|
|
158
|
+
}, [
|
|
159
|
+
unref(builder).isSectionVisible(section.id) ? (openBlock(), createBlock(_sfc_main$3, {
|
|
160
|
+
key: 0,
|
|
161
|
+
section,
|
|
162
|
+
builder: unref(builder)
|
|
163
|
+
}, createSlots({
|
|
164
|
+
[`section:${section.id}`]: withCtx((slotProps) => [
|
|
165
|
+
renderSlot(_ctx.$slots, `section:${section.id}`, mergeProps({ ref_for: true }, slotProps))
|
|
166
|
+
]),
|
|
167
|
+
[`section:${section.id}:after`]: withCtx((slotProps) => [
|
|
168
|
+
renderSlot(_ctx.$slots, `section:${section.id}:after`, mergeProps({ ref_for: true }, slotProps))
|
|
169
|
+
]),
|
|
170
|
+
_: 2
|
|
171
|
+
}, [
|
|
172
|
+
renderList(section.fields, (field) => {
|
|
173
|
+
return {
|
|
174
|
+
name: `field:${field.name}`,
|
|
175
|
+
fn: withCtx((slotProps) => [
|
|
176
|
+
renderSlot(_ctx.$slots, `field:${field.name}`, mergeProps({ ref_for: true }, slotProps))
|
|
177
|
+
])
|
|
178
|
+
};
|
|
179
|
+
})
|
|
180
|
+
]), 1032, ["section", "builder"])) : createCommentVNode("", true)
|
|
181
|
+
], 64);
|
|
182
|
+
}), 128)),
|
|
183
|
+
renderSlot(_ctx.$slots, "actions", {
|
|
184
|
+
form: unref(builder).form,
|
|
185
|
+
builder: unref(builder)
|
|
186
|
+
}, () => [
|
|
187
|
+
createVNode(_sfc_main$2, {
|
|
188
|
+
loading: __props.loading || unref(builder).form.isSubmitting.value,
|
|
189
|
+
disabled: __props.disabled,
|
|
190
|
+
"submit-label": __props.schema.submitLabel ?? "Submit",
|
|
191
|
+
"cancel-label": __props.schema.cancelLabel ?? "Cancel",
|
|
192
|
+
"show-cancel": __props.schema.showCancel ?? false,
|
|
193
|
+
onSubmit: handleSubmit,
|
|
194
|
+
onCancel: handleCancel
|
|
195
|
+
}, null, 8, ["loading", "disabled", "submit-label", "cancel-label", "show-cancel"])
|
|
196
|
+
])
|
|
197
|
+
], 64)) : createCommentVNode("", true)
|
|
198
|
+
], 2);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
export {
|
|
203
|
+
_sfc_main as default
|
|
204
|
+
};
|
|
205
|
+
//# sourceMappingURL=FormBuilder.vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormBuilder.vue.js","sources":["../../src/components/FormBuilder.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * Schema-driven form component that renders flat or multi-step wizard forms.\n *\n * Pass a `FormSchema` with either `sections` (flat) or `steps` (wizard).\n * Use `v-model` for two-way binding of the form data; the `submit` event\n * carries only the data for currently-visible fields. Supply `enhancements`\n * for dynamic options, custom validators, a submit handler, and field-change\n * callbacks that cannot be expressed in JSON.\n *\n * Exposes `form`, `validate`, `reset`, `goNext`, `goBack`, `goToStep`, and\n * `builder` for imperative control via template refs.\n *\n * Slots:\n * - `field:<name>` — override a single field's input component\n * - `section:<id>` — replace an entire section body\n * - `section:<id>:after` — inject content after a section\n * - `actions` — replace the default FormActions bar\n */\nimport { ref, computed, watch } from 'vue'\nimport type { FormSchema, FormEnhancements, UseFormBuilderReturn } from '../types/form-builder'\nimport type { WizardStep } from '../types'\nimport { useFormBuilder } from '../composables/useFormBuilder'\nimport StepWizard from './StepWizard.vue'\nimport FormSection from './FormSection.vue'\nimport FormActions from './FormActions.vue'\n\ninterface Props {\n schema: FormSchema\n modelValue?: Record<string, unknown>\n enhancements?: FormEnhancements<Record<string, unknown>>\n loading?: boolean\n disabled?: boolean\n size?: 'sm' | 'md' | 'lg'\n readonly?: boolean\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n loading: false,\n disabled: false,\n readonly: false,\n})\n\nconst emit = defineEmits<{\n 'update:modelValue': [data: Record<string, unknown>]\n submit: [data: Record<string, unknown>]\n cancel: []\n}>()\n\nconst builder = useFormBuilder(\n props.schema,\n props.modelValue,\n props.enhancements,\n)\n\n// Sync modelValue changes back to parent\nwatch(\n () => ({ ...builder.form.data }),\n (data) => emit('update:modelValue', data as Record<string, unknown>),\n { deep: true },\n)\n\n// Wizard support\nconst isWizard = computed(() => !!props.schema.steps)\nconst wizardRef = ref<InstanceType<typeof StepWizard> | null>(null)\n\nconst wizardSteps = computed<WizardStep[]>(() => {\n if (!props.schema.steps) return []\n return props.schema.steps.map((step) => ({\n id: step.id,\n label: step.label,\n description: step.description,\n icon: step.icon,\n optional: step.optional,\n }))\n})\n\n// Sync step validation state with StepWizard\nwatch(\n () => builder.isCurrentStepValid.value,\n (valid) => {\n wizardRef.value?.setStepValid(builder.currentStep.value, valid)\n },\n)\n\nfunction handleNext() {\n const success = builder.goNext()\n if (success) {\n wizardRef.value?.setStepValid(builder.currentStep.value - 1, true)\n }\n}\n\nasync function handleSubmit() {\n await builder.submit()\n const formData = builder.form.data as Record<string, unknown>\n const visibleData = Object.fromEntries(\n builder.fields\n .filter((f) => builder.isFieldVisible(f.name))\n .map((f) => [f.name, formData[f.name]]),\n )\n emit('submit', visibleData)\n}\n\nfunction handleCancel() {\n emit('cancel')\n}\n\ndefineExpose({\n form: builder.form,\n validate: builder.validate,\n reset: builder.reset,\n goNext: builder.goNext,\n goBack: builder.goBack,\n goToStep: builder.goToStep,\n builder,\n})\n</script>\n\n<template>\n <div :class=\"['mld-form-builder', size ? `mld-form-builder--${size}` : '']\">\n <!-- Wizard mode -->\n <template v-if=\"isWizard && schema.steps\">\n <StepWizard\n ref=\"wizardRef\"\n :steps=\"wizardSteps\"\n :model-value=\"builder.currentStep.value\"\n @update:model-value=\"builder.goToStep($event)\"\n >\n <template v-for=\"step in schema.steps\" :key=\"step.id\" #[`step-${step.id}`]>\n <div class=\"mld-form-builder__step\">\n <template v-for=\"section in step.sections\" :key=\"section.id\">\n <FormSection\n v-if=\"builder.isSectionVisible(section.id)\"\n :section=\"section\"\n :builder=\"(builder as UseFormBuilderReturn<Record<string, unknown>>)\"\n >\n <!-- Forward field slots -->\n <template v-for=\"field in section.fields\" :key=\"field.name\" #[`field:${field.name}`]=\"slotProps\">\n <slot :name=\"`field:${field.name}`\" v-bind=\"slotProps\" />\n </template>\n <!-- Forward section slots -->\n <template #[`section:${section.id}`]=\"slotProps\">\n <slot :name=\"`section:${section.id}`\" v-bind=\"slotProps\" />\n </template>\n <template #[`section:${section.id}:after`]=\"slotProps\">\n <slot :name=\"`section:${section.id}:after`\" v-bind=\"slotProps\" />\n </template>\n </FormSection>\n </template>\n </div>\n </template>\n\n <template #navigation=\"{ isFirst, isLast }\">\n <slot name=\"actions\" :form=\"builder.form\" :builder=\"builder\">\n <FormActions\n is-wizard\n :is-first=\"isFirst\"\n :is-last=\"isLast\"\n :can-proceed=\"builder.isCurrentStepValid.value\"\n :loading=\"loading || builder.form.isSubmitting.value\"\n :disabled=\"disabled\"\n :submit-label=\"schema.submitLabel ?? 'Submit'\"\n :cancel-label=\"schema.cancelLabel ?? 'Cancel'\"\n :show-cancel=\"schema.showCancel ?? false\"\n @next=\"handleNext\"\n @back=\"builder.goBack\"\n @submit=\"handleSubmit\"\n @cancel=\"handleCancel\"\n />\n </slot>\n </template>\n </StepWizard>\n </template>\n\n <!-- Flat mode -->\n <template v-else-if=\"schema.sections\">\n <template v-for=\"section in schema.sections\" :key=\"section.id\">\n <FormSection\n v-if=\"builder.isSectionVisible(section.id)\"\n :section=\"section\"\n :builder=\"(builder as UseFormBuilderReturn<Record<string, unknown>>)\"\n >\n <!-- Forward field slots -->\n <template v-for=\"field in section.fields\" :key=\"field.name\" #[`field:${field.name}`]=\"slotProps\">\n <slot :name=\"`field:${field.name}`\" v-bind=\"slotProps\" />\n </template>\n <!-- Forward section slots -->\n <template #[`section:${section.id}`]=\"slotProps\">\n <slot :name=\"`section:${section.id}`\" v-bind=\"slotProps\" />\n </template>\n <template #[`section:${section.id}:after`]=\"slotProps\">\n <slot :name=\"`section:${section.id}:after`\" v-bind=\"slotProps\" />\n </template>\n </FormSection>\n </template>\n\n <slot name=\"actions\" :form=\"builder.form\" :builder=\"builder\">\n <FormActions\n :loading=\"loading || builder.form.isSubmitting.value\"\n :disabled=\"disabled\"\n :submit-label=\"schema.submitLabel ?? 'Submit'\"\n :cancel-label=\"schema.cancelLabel ?? 'Cancel'\"\n :show-cancel=\"schema.showCancel ?? false\"\n @submit=\"handleSubmit\"\n @cancel=\"handleCancel\"\n />\n </slot>\n </template>\n </div>\n</template>\n\n<style>\n@import '../styles/components/form-builder.css';\n</style>\n"],"names":["_createElementBlock","_normalizeClass","_createBlock","StepWizard","_unref","_withCtx","_renderSlot","_createVNode","FormActions","_createElementVNode","_openBlock","_Fragment","_renderList","FormSection","_mergeProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqCA,UAAM,QAAQ;AAMd,UAAM,OAAO;AAMb,UAAM,UAAU;AAAA,MACd,MAAM;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IAAA;AAIR;AAAA,MACE,OAAO,EAAE,GAAG,QAAQ,KAAK,KAAA;AAAA,MACzB,CAAC,SAAS,KAAK,qBAAqB,IAA+B;AAAA,MACnE,EAAE,MAAM,KAAA;AAAA,IAAK;AAIf,UAAM,WAAW,SAAS,MAAM,CAAC,CAAC,MAAM,OAAO,KAAK;AACpD,UAAM,YAAY,IAA4C,IAAI;AAElE,UAAM,cAAc,SAAuB,MAAM;AAC/C,UAAI,CAAC,MAAM,OAAO,cAAc,CAAA;AAChC,aAAO,MAAM,OAAO,MAAM,IAAI,CAAC,UAAU;AAAA,QACvC,IAAI,KAAK;AAAA,QACT,OAAO,KAA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A;AAAA,oBAAA;;;;;;UAY3DR,WAUO,KAAA,QAAA,WAAA;AAAA,YAVe,MAAMF,MAAA,OAAA,EAAQ;AAAA,YAAO,SAASA,MAAA,OAAA;AAAA,UAAA,GAApD,MAUO;AAAA,YATLG,YAQEC,aAAA;AAAA,cAPC,SAAS,mBAAWJ,MAAA,OAAA,EAAQ,KAAK,aAAa;AAAA,cAC9C,UAAU,QAAA;AAAA,cACV,gBAAc,QAAA,OAAO,eAAW;AAAA,cAChC,gBAAc,QAAA,OAAO,eAAW;AAAA,cAChC,eAAa,QAAA,OAAO,cAAU;AAAA,cAC9B,UAAQ;AAAA,cACR,UAAQ;AAAA,YAAA;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormBuilder.vue3.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FormFieldSchema } from '../types/form-builder';
|
|
2
|
+
import { UseFormReturn } from '../composables/useForm';
|
|
3
|
+
interface Props {
|
|
4
|
+
field: FormFieldSchema;
|
|
5
|
+
resolvedProps: Record<string, unknown>;
|
|
6
|
+
form: UseFormReturn<Record<string, unknown>>;
|
|
7
|
+
}
|
|
8
|
+
declare function __VLS_template(): {
|
|
9
|
+
attrs: Partial<{}>;
|
|
10
|
+
slots: Partial<Record<`field:${string}`, (_: {
|
|
11
|
+
field: FormFieldSchema;
|
|
12
|
+
form: UseFormReturn<Record<string, unknown>>;
|
|
13
|
+
fieldProps: {
|
|
14
|
+
modelValue: unknown;
|
|
15
|
+
'onUpdate:modelValue': (value: unknown) => void;
|
|
16
|
+
onBlur: () => void;
|
|
17
|
+
error: string | null;
|
|
18
|
+
};
|
|
19
|
+
}) => any>>;
|
|
20
|
+
refs: {};
|
|
21
|
+
rootEl: HTMLDivElement;
|
|
22
|
+
};
|
|
23
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
24
|
+
declare const __VLS_component: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
25
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
26
|
+
export default _default;
|
|
27
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
28
|
+
new (): {
|
|
29
|
+
$slots: S;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defineComponent, computed, openBlock, createBlock, withCtx, renderSlot, resolveDynamicComponent, normalizeProps, mergeProps } from "vue";
|
|
2
|
+
import { getFieldRegistryEntry } from "../composables/formBuilderRegistry.js";
|
|
3
|
+
import _sfc_main$1 from "./FormField.vue.js";
|
|
4
|
+
/* empty css */
|
|
5
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
6
|
+
__name: "FormFieldRenderer",
|
|
7
|
+
props: {
|
|
8
|
+
field: {},
|
|
9
|
+
resolvedProps: {},
|
|
10
|
+
form: {}
|
|
11
|
+
},
|
|
12
|
+
setup(__props) {
|
|
13
|
+
const props = __props;
|
|
14
|
+
const entry = computed(() => getFieldRegistryEntry(props.field.type));
|
|
15
|
+
const errorMessage = computed(() => {
|
|
16
|
+
const name = props.field.name;
|
|
17
|
+
return props.form.touched[name] ? props.form.errors[name] : null;
|
|
18
|
+
});
|
|
19
|
+
function handleUpload(files) {
|
|
20
|
+
props.form.setFieldValue(props.field.name, files);
|
|
21
|
+
}
|
|
22
|
+
return (_ctx, _cache) => {
|
|
23
|
+
var _a;
|
|
24
|
+
return openBlock(), createBlock(_sfc_main$1, {
|
|
25
|
+
label: __props.field.label,
|
|
26
|
+
error: errorMessage.value ?? void 0,
|
|
27
|
+
hint: __props.field.hint,
|
|
28
|
+
required: !!((_a = __props.field.validation) == null ? void 0 : _a.required),
|
|
29
|
+
"html-for": __props.field.name
|
|
30
|
+
}, {
|
|
31
|
+
default: withCtx(() => [
|
|
32
|
+
renderSlot(_ctx.$slots, `field:${__props.field.name}`, {
|
|
33
|
+
field: __props.field,
|
|
34
|
+
form: __props.form,
|
|
35
|
+
fieldProps: __props.form.getFieldProps(__props.field.name)
|
|
36
|
+
}, () => [
|
|
37
|
+
entry.value.vModel ? (openBlock(), createBlock(resolveDynamicComponent(entry.value.component), normalizeProps(mergeProps({ key: 0 }, __props.resolvedProps)), null, 16)) : (openBlock(), createBlock(resolveDynamicComponent(entry.value.component), mergeProps({ key: 1 }, __props.resolvedProps, { onUpload: handleUpload }), null, 16))
|
|
38
|
+
])
|
|
39
|
+
]),
|
|
40
|
+
_: 3
|
|
41
|
+
}, 8, ["label", "error", "hint", "required", "html-for"]);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export {
|
|
46
|
+
_sfc_main as default
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=FormFieldRenderer.vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldRenderer.vue.js","sources":["../../src/components/FormFieldRenderer.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/**\n * Renders a single form field inside a FormField wrapper.\n *\n * Resolves the SDK component for the field type from the registry, shows\n * validation errors only after the field has been touched, and handles the\n * FileUploader's event-based upload pattern via `handleUpload`. Consumers can\n * override rendering via the `field:<name>` slot.\n */\nimport { computed } from 'vue'\nimport type { FormFieldSchema } from '../types/form-builder'\nimport type { UseFormReturn } from '../composables/useForm'\nimport { getFieldRegistryEntry } from '../composables/formBuilderRegistry'\nimport FormField from './FormField.vue'\n\ninterface Props {\n field: FormFieldSchema\n resolvedProps: Record<string, unknown>\n form: UseFormReturn<Record<string, unknown>>\n}\n\nconst props = defineProps<Props>()\n\nconst entry = computed(() => getFieldRegistryEntry(props.field.type))\n\nconst errorMessage = computed(() => {\n const name = props.field.name\n return props.form.touched[name] ? props.form.errors[name] : null\n})\n\nfunction handleUpload(files: File[]) {\n props.form.setFieldValue(props.field.name, files)\n}\n</script>\n\n<template>\n <FormField\n :label=\"field.label\"\n :error=\"errorMessage ?? undefined\"\n :hint=\"field.hint\"\n :required=\"!!field.validation?.required\"\n :html-for=\"field.name\"\n >\n <slot :name=\"`field:${field.name}`\" :field=\"field\" :form=\"form\" :field-props=\"form.getFieldProps(field.name)\">\n <component\n :is=\"entry.component\"\n v-if=\"entry.vModel\"\n v-bind=\"resolvedProps\"\n />\n <component\n :is=\"entry.component\"\n v-else\n v-bind=\"resolvedProps\"\n @upload=\"handleUpload\"\n />\n </slot>\n </FormField>\n</template>\n"],"names":["_createBlock","FormField","_renderSlot","_openBlock","_resolveDynamicComponent","_mergeProps"],"mappings":";;;;;;;;;;;;AAqBA,UAAM,QAAQ;AAEd,UAAM,QAAQ,SAAS,MAAM,sBAAsB,MAAM,MAAM,IAAI,CAAC;AAEpE,UAAM,eAAe,SAAS,MAAM;AAClC,YAAM,OAAO,MAAM,MAAM;AACzB,aAAO,MAAM,KAAK,QAAQ,IAAI,IAAI,MAAM,KAAK,OAAO,IAAI,IAAI;AAAA,IAC9D,CAAC;AAED,aAAS,aAAa,OAAe;AACnC,YAAM,KAAK,cAAc,MAAM,MAAM,MAAM,KAAK;AAAA,IAClD;;;0BAIEA,YAoBYC,aAAA;AAAA,QAnBT,OAAO,QAAA,MAAM;AAAA,QACb,OAAO,aAAA,SAAgB;AAAA,QACvB,MAAM,QAAA,MAAM;AAAA,QACZ,UAAQ,CAAA,GAAI,aAAA,MAAM,eAAN,mBAAkB;AAAA,QAC9B,YAAU,QAAA,MAAM;AAAA,MAAA;yBAEjB,MAYO;AAAA,UAZPC,WAYO,KAAA,QAAA,SAZe,QAAA,MAAM,IAAI,IAAA;AAAA,YAAK,OAAO,QAAA;AAAA,YAAQ,MAAM,QAAA;AAAA,YAAO,YAAa,QAAA,KAAK,cAAc,QAAA,MAAM,IAAI;AAAA,UAAA,GAA3G,MAYO;AAAA,YATG,MAAA,MAAM,UAFdC,UAAA,GAAAH,YAIEI,wBAHK,MAAA,MAAM,SAAS,yCAEZ,QAAA,aAAa,CAAA,GAAA,MAAA,EAAA,mBAEvBJ,YAKEI,wBAJK,MAAA,MAAM,SAAS,GADtBC,WAKE,EAAA,KAAA,EAAA,GAFQ,QAAA,eAAa,EACpB,UAAQ,aAAA,CAAY,GAAA,MAAA,EAAA;AAAA,UAAA;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormFieldRenderer.vue2.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FormSectionSchema, UseFormBuilderReturn } from '../types/form-builder';
|
|
2
|
+
interface Props {
|
|
3
|
+
section: FormSectionSchema;
|
|
4
|
+
builder: UseFormBuilderReturn<Record<string, unknown>>;
|
|
5
|
+
}
|
|
6
|
+
declare function __VLS_template(): {
|
|
7
|
+
attrs: Partial<{}>;
|
|
8
|
+
slots: Partial<Record<`section:${string}`, (_: {
|
|
9
|
+
section: FormSectionSchema;
|
|
10
|
+
form: import('../composables').UseFormReturn<Record<string, unknown>>;
|
|
11
|
+
}) => any>> & Partial<Record<`field:${string}`, (_: {
|
|
12
|
+
field: import('../types').FormFieldSchema;
|
|
13
|
+
form: import('../composables').UseFormReturn<Record<string, unknown>>;
|
|
14
|
+
fieldProps: {
|
|
15
|
+
modelValue: unknown;
|
|
16
|
+
'onUpdate:modelValue': (value: unknown) => void;
|
|
17
|
+
onBlur: () => void;
|
|
18
|
+
error: string | null;
|
|
19
|
+
};
|
|
20
|
+
}) => any>> & Partial<Record<`field:${string}`, (_: {
|
|
21
|
+
field: import('../types').FormFieldSchema;
|
|
22
|
+
form: import('../composables').UseFormReturn<Record<string, unknown>>;
|
|
23
|
+
fieldProps: {
|
|
24
|
+
modelValue: unknown;
|
|
25
|
+
'onUpdate:modelValue': (value: unknown) => void;
|
|
26
|
+
onBlur: () => void;
|
|
27
|
+
error: string | null;
|
|
28
|
+
};
|
|
29
|
+
}) => any>> & Partial<Record<`section:${string}:after`, (_: {
|
|
30
|
+
form: import('../composables').UseFormReturn<Record<string, unknown>>;
|
|
31
|
+
}) => any>>;
|
|
32
|
+
refs: {};
|
|
33
|
+
rootEl: any;
|
|
34
|
+
};
|
|
35
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
36
|
+
declare const __VLS_component: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
37
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
38
|
+
export default _default;
|
|
39
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
40
|
+
new (): {
|
|
41
|
+
$slots: S;
|
|
42
|
+
};
|
|
43
|
+
};
|