@bach.software/vue-dynamic-form 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/src/components/DynamicForm.test.d.ts +1 -0
- package/dist/src/components/DynamicForm.vue.d.ts +19 -0
- package/dist/src/components/DynamicFormItem.vue.d.ts +16 -0
- package/dist/src/components/DynamicFormItemArray.vue.d.ts +16 -0
- package/dist/src/components/DynamicFormItemChoice.vue.d.ts +16 -0
- package/dist/src/components/DynamicFormTemplate.vue.d.ts +41 -0
- package/dist/src/core/defineMetadata.d.ts +10 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/types/DynamicFormItemProps.d.ts +13 -0
- package/dist/src/types/FieldMetadata.d.ts +101 -0
- package/dist/src/types/GetMetadataType.d.ts +3 -0
- package/dist/src/types/InternalFieldMetadata.d.ts +3 -0
- package/dist/src/types/MetadataConfiguration.d.ts +4 -0
- package/dist/src/types/RequireOnly.d.ts +1 -0
- package/dist/vite.config.d.ts +2 -0
- package/dist/vue-dynamic-form.es.js +180 -0
- package/dist/vue-dynamic-form.umd.js +1 -0
- package/package.json +48 -22
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/utils.d.ts +0 -2
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -2
- package/dist/utils.js.map +0 -1
- package/dist/utils.test.d.ts +0 -2
- package/dist/utils.test.d.ts.map +0 -1
- package/dist/utils.test.js +0 -6
- package/dist/utils.test.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
# Vue Dynamic Form
|
|
2
2
|
|
|
3
3
|
A simple yet highly extendable dynamic form system, inspired by the flexibility of XSD and powered by Vee-Validate.
|
|
4
|
+
|
|
5
|
+
## Create a new release
|
|
6
|
+
|
|
7
|
+
To create a new release for you PR, follow these steps:
|
|
8
|
+
|
|
9
|
+
1. Create a new changeset by running `pnpm changeset`.
|
|
10
|
+
2. Create your PR into the main branch.
|
|
11
|
+
3. The release workflow will automatically be triggered.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue';
|
|
2
|
+
import type { FieldMetadata } from '../types/FieldMetadata';
|
|
3
|
+
export interface DynamicFormProps<Metadata extends FieldMetadata> {
|
|
4
|
+
metadata: Metadata | Metadata[];
|
|
5
|
+
template: DefineComponent<object, object, any>;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: <Metadata extends FieldMetadata>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
8
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & DynamicFormProps<Metadata> & Partial<{}>> & import("vue").PublicProps;
|
|
9
|
+
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
|
10
|
+
attrs: any;
|
|
11
|
+
slots: {};
|
|
12
|
+
emit: {};
|
|
13
|
+
}>) => import("vue").VNode & {
|
|
14
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
17
|
+
type __VLS_PrettifyLocal<T> = {
|
|
18
|
+
[K in keyof T as K]: T[K];
|
|
19
|
+
} & {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DynamicFormItemProps } from '../types/DynamicFormItemProps';
|
|
2
|
+
import type { FieldMetadata } from '../types/FieldMetadata';
|
|
3
|
+
import type { InternalFieldMetadata } from '../types/InternalFieldMetadata';
|
|
4
|
+
declare const _default: <InternalMetadata extends InternalFieldMetadata<FieldMetadata>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
5
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & DynamicFormItemProps<InternalMetadata> & Partial<{}>> & import("vue").PublicProps;
|
|
6
|
+
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
|
7
|
+
attrs: any;
|
|
8
|
+
slots: {};
|
|
9
|
+
emit: {};
|
|
10
|
+
}>) => import("vue").VNode & {
|
|
11
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
type __VLS_PrettifyLocal<T> = {
|
|
15
|
+
[K in keyof T as K]: T[K];
|
|
16
|
+
} & {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DynamicFormItemProps } from '../types/DynamicFormItemProps';
|
|
2
|
+
import type { FieldMetadata } from '../types/FieldMetadata';
|
|
3
|
+
import type { InternalFieldMetadata } from '../types/InternalFieldMetadata';
|
|
4
|
+
declare const _default: <InternalMetadata extends InternalFieldMetadata<FieldMetadata>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
5
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & DynamicFormItemProps<InternalMetadata> & Partial<{}>> & import("vue").PublicProps;
|
|
6
|
+
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
|
7
|
+
attrs: any;
|
|
8
|
+
slots: {};
|
|
9
|
+
emit: {};
|
|
10
|
+
}>) => import("vue").VNode & {
|
|
11
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
type __VLS_PrettifyLocal<T> = {
|
|
15
|
+
[K in keyof T as K]: T[K];
|
|
16
|
+
} & {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DynamicFormItemProps } from '../types/DynamicFormItemProps';
|
|
2
|
+
import type { FieldMetadata } from '../types/FieldMetadata';
|
|
3
|
+
import type { InternalFieldMetadata } from '../types/InternalFieldMetadata';
|
|
4
|
+
declare const _default: <InternalMetadata extends InternalFieldMetadata<FieldMetadata>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
5
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & DynamicFormItemProps<InternalMetadata> & Partial<{}>> & import("vue").PublicProps;
|
|
6
|
+
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
|
7
|
+
attrs: any;
|
|
8
|
+
slots: {};
|
|
9
|
+
emit: {};
|
|
10
|
+
}>) => import("vue").VNode & {
|
|
11
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
14
|
+
type __VLS_PrettifyLocal<T> = {
|
|
15
|
+
[K in keyof T as K]: T[K];
|
|
16
|
+
} & {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { FieldMetadata } from '../types/FieldMetadata';
|
|
2
|
+
import type { MetadataConfiguration } from '../types/MetadataConfiguration';
|
|
3
|
+
export interface DynamicFormConfigurationProps<TMetadataConfiguration extends MetadataConfiguration> {
|
|
4
|
+
type?: TMetadataConfiguration['fieldTypes'][number] | 'default';
|
|
5
|
+
metadataConfiguration: TMetadataConfiguration;
|
|
6
|
+
field?: FieldMetadata<TMetadataConfiguration['fieldTypes'][number], TMetadataConfiguration['extendedProperties']>;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: <TMetadataConfiguration extends MetadataConfiguration>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
9
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & DynamicFormConfigurationProps<TMetadataConfiguration> & Partial<{}>> & import("vue").PublicProps;
|
|
10
|
+
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
|
|
11
|
+
attrs: any;
|
|
12
|
+
slots: {
|
|
13
|
+
default: (props: {
|
|
14
|
+
field: NonNullable<FieldMetadata<TMetadataConfiguration["fieldTypes"][number], TMetadataConfiguration["extendedProperties"]> | undefined>;
|
|
15
|
+
type: "default" | TMetadataConfiguration["fieldTypes"][number] | undefined;
|
|
16
|
+
}) => any;
|
|
17
|
+
} & {
|
|
18
|
+
'default-input': (props: {
|
|
19
|
+
field: NonNullable<FieldMetadata<TMetadataConfiguration["fieldTypes"][number], TMetadataConfiguration["extendedProperties"]> | undefined>;
|
|
20
|
+
}) => any;
|
|
21
|
+
} & {
|
|
22
|
+
array: (props: {
|
|
23
|
+
field: NonNullable<FieldMetadata<TMetadataConfiguration["fieldTypes"][number], TMetadataConfiguration["extendedProperties"]> | undefined>;
|
|
24
|
+
}) => any;
|
|
25
|
+
} & {
|
|
26
|
+
choice: (props: {
|
|
27
|
+
field: NonNullable<FieldMetadata<TMetadataConfiguration["fieldTypes"][number], TMetadataConfiguration["extendedProperties"]> | undefined>;
|
|
28
|
+
}) => any;
|
|
29
|
+
} & { [K in TMetadataConfiguration["fieldTypes"][number]]: (props: {
|
|
30
|
+
field: NonNullable<FieldMetadata<TMetadataConfiguration["fieldTypes"][number], TMetadataConfiguration["extendedProperties"]> | undefined>;
|
|
31
|
+
}) => any; } & { [K_1 in `${TMetadataConfiguration["fieldTypes"][number]}-input`]: (props: {
|
|
32
|
+
field: NonNullable<FieldMetadata<TMetadataConfiguration["fieldTypes"][number], TMetadataConfiguration["extendedProperties"]> | undefined>;
|
|
33
|
+
}) => any; };
|
|
34
|
+
emit: {};
|
|
35
|
+
}>) => import("vue").VNode & {
|
|
36
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
37
|
+
};
|
|
38
|
+
export default _default;
|
|
39
|
+
type __VLS_PrettifyLocal<T> = {
|
|
40
|
+
[K in keyof T as K]: T[K];
|
|
41
|
+
} & {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates metadata based on your configuration.
|
|
3
|
+
* @param fieldTypes an array of fields that you would like to define. (Note: you can't use 'input' or 'children', they're reserved)
|
|
4
|
+
* @param extendedProperties extra properties that you would like to include in your metadata
|
|
5
|
+
* @returns a metadata object that can be passed to the DynamicFormTemplate component
|
|
6
|
+
*/
|
|
7
|
+
export declare function defineMetadata<ExtendedProperties extends object, const FieldTypes extends readonly string[]>(fieldTypes: FieldTypes, extendedProperties: ExtendedProperties): {
|
|
8
|
+
fieldTypes: readonly ("text" | Exclude<FieldTypes[number], "children" | "choice" | "input" | "array" | "text">)[];
|
|
9
|
+
extendedProperties: ExtendedProperties;
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as DynamicForm } from './components/DynamicForm.vue';
|
|
2
|
+
export { default as DynamicFormItem } from './components/DynamicFormItem.vue';
|
|
3
|
+
export { default as DynamicFormItemArray } from './components/DynamicFormItemArray.vue';
|
|
4
|
+
export { default as DynamicFormItemChoice } from './components/DynamicFormItemChoice.vue';
|
|
5
|
+
export { default as DynamicFormTemplate } from './components/DynamicFormTemplate.vue';
|
|
6
|
+
export * from './core/defineMetadata';
|
|
7
|
+
export * from './types/DynamicFormItemProps';
|
|
8
|
+
export * from './types/FieldMetadata';
|
|
9
|
+
export * from './types/GetMetadataType';
|
|
10
|
+
export * from './types/RequireOnly';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue';
|
|
2
|
+
import type { FieldMetadata } from '../types/FieldMetadata';
|
|
3
|
+
import type { InternalFieldMetadata } from '../types/InternalFieldMetadata';
|
|
4
|
+
export interface DynamicFormItemProps<InternalMetadata extends InternalFieldMetadata<FieldMetadata>> {
|
|
5
|
+
template: DefineComponent<object, object, {
|
|
6
|
+
input?: ((props: object) => any) | undefined;
|
|
7
|
+
children?: ((props: object) => any) | undefined;
|
|
8
|
+
attributes?: ((props: object) => any) | undefined;
|
|
9
|
+
choice?: ((props: object) => any) | undefined;
|
|
10
|
+
array?: ((props: object) => any) | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
field: InternalMetadata;
|
|
13
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { WatchSource } from 'vue';
|
|
2
|
+
export type FieldMetadata<ExtendedFieldTypes extends string = string, ExtendedProperties extends object = object> = {
|
|
3
|
+
name?: string;
|
|
4
|
+
type?: ExtendedFieldTypes;
|
|
5
|
+
path?: string;
|
|
6
|
+
minOccurs?: number;
|
|
7
|
+
maxOccurs?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Simple restrictions to the data
|
|
10
|
+
*/
|
|
11
|
+
restrictions?: {
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
minLength?: number;
|
|
14
|
+
pattern?: string;
|
|
15
|
+
minInclusive?: number;
|
|
16
|
+
maxInclusive?: number;
|
|
17
|
+
enumeration?: string;
|
|
18
|
+
length?: number;
|
|
19
|
+
whiteSpace?: string;
|
|
20
|
+
fractionDigits?: number;
|
|
21
|
+
totalDigits?: number;
|
|
22
|
+
};
|
|
23
|
+
children?: FieldMetadata<ExtendedFieldTypes, ExtendedProperties>[];
|
|
24
|
+
/**
|
|
25
|
+
* Choice is similar to children, with the difference that only one of the items in the array
|
|
26
|
+
* needs to be present. If you combine this with minOccurs, you can for example create a form where
|
|
27
|
+
* only the email or phone number is required.
|
|
28
|
+
*
|
|
29
|
+
* This is inspired by the choice element in xsd (XML Schema Definition), for example:
|
|
30
|
+
*
|
|
31
|
+
* ```xml
|
|
32
|
+
* <?xml version="1.0" encoding="UTF-8"?>
|
|
33
|
+
* <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
34
|
+
*
|
|
35
|
+
* <xs:element name="ContactInfo">
|
|
36
|
+
* <xs:complexType>
|
|
37
|
+
* <xs:choice>
|
|
38
|
+
* <xs:element name="Email" type="xs:string"/>
|
|
39
|
+
* <xs:element name="Phone" type="xs:string"/>
|
|
40
|
+
* <xs:element name="Fax" type="xs:string"/>
|
|
41
|
+
* </xs:choice>
|
|
42
|
+
* </xs:complexType>
|
|
43
|
+
* </xs:element>
|
|
44
|
+
*
|
|
45
|
+
* </xs:schema>
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* This will allow the following xml options
|
|
49
|
+
* ```xml
|
|
50
|
+
* <ContactInfo>
|
|
51
|
+
* <Email>someone@example.com</Email>
|
|
52
|
+
* </ContactInfo>
|
|
53
|
+
* or
|
|
54
|
+
* <ContactInfo>
|
|
55
|
+
* <Phone>+31 123 456 789</Phone>
|
|
56
|
+
* </ContactInfo>
|
|
57
|
+
*
|
|
58
|
+
* but this is invalid:
|
|
59
|
+
* <ContactInfo>
|
|
60
|
+
* </ContactInfo>
|
|
61
|
+
*
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
65
|
+
choice?: FieldMetadata<ExtendedFieldTypes, ExtendedProperties>[];
|
|
66
|
+
/**
|
|
67
|
+
* Attributes are additional metadata that can be attached to a field.
|
|
68
|
+
* These attributes can be used to provide extra information about the field,
|
|
69
|
+
* such as for example whether the data is verified.
|
|
70
|
+
*
|
|
71
|
+
* These attributes will be shown when the parent will have a value filled in.
|
|
72
|
+
*
|
|
73
|
+
* For example:
|
|
74
|
+
* ```
|
|
75
|
+
* <ContactInfo>
|
|
76
|
+
* <Phone certainty="unverified">+31 123 456 789</Phone>
|
|
77
|
+
* </ContactInfo>
|
|
78
|
+
* or
|
|
79
|
+
* <ContactInfo>
|
|
80
|
+
* <Phone certainty="verified">+31 123 456 789</Phone>
|
|
81
|
+
* </ContactInfo>
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
attributes?: FieldMetadata<ExtendedFieldTypes, ExtendedProperties>[];
|
|
85
|
+
/**
|
|
86
|
+
* The parent of the current field.
|
|
87
|
+
*/
|
|
88
|
+
parent?: FieldMetadata<ExtendedFieldTypes, ExtendedProperties>;
|
|
89
|
+
/**
|
|
90
|
+
* You can add methods that transform the field metadata based on other external values.
|
|
91
|
+
* Make sure to include the reactive value's in your function, so that the function is re-evaluated once
|
|
92
|
+
* the value changes (internally we use a computed that is re-valuated when one of the used reactive values is changed).
|
|
93
|
+
* This way we can for example change the property minOccurs to 1 (required) if another field has a value or change one of the ExtendedAttributes.
|
|
94
|
+
*
|
|
95
|
+
* @param thisField the reactive & cloned current MetadataField that can be changed.
|
|
96
|
+
* @returns A transformed FieldMetadata
|
|
97
|
+
*/
|
|
98
|
+
transformReactively?: ((thisField: Omit<FieldMetadata<ExtendedFieldTypes, ExtendedProperties>, 'name' | 'children' | 'choice' | 'attributes'> & {
|
|
99
|
+
name: string;
|
|
100
|
+
}, fieldValue?: WatchSource<any>) => Omit<FieldMetadata<ExtendedFieldTypes, ExtendedProperties>, 'children'>)[];
|
|
101
|
+
} & ExtendedProperties;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RequireOnly<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { defineComponent as y, resolveComponent as I, createElementBlock as D, openBlock as l, Fragment as F, renderList as k, createBlock as c, resolveDynamicComponent as f, withCtx as s, computed as p, createVNode as C, useSlots as A, renderSlot as $, createCommentVNode as _ } from "vue";
|
|
2
|
+
const b = /* @__PURE__ */ y({
|
|
3
|
+
__name: "DynamicFormItemArray",
|
|
4
|
+
props: {
|
|
5
|
+
template: {},
|
|
6
|
+
field: {}
|
|
7
|
+
},
|
|
8
|
+
setup(t) {
|
|
9
|
+
return (a, r) => {
|
|
10
|
+
const e = I("DynamicFormItem");
|
|
11
|
+
return l(!0), D(F, null, k(a.field.children, (m) => (l(), c(e, {
|
|
12
|
+
key: m.name,
|
|
13
|
+
template: a.template,
|
|
14
|
+
field: m
|
|
15
|
+
}, null, 8, ["template", "field"]))), 128);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}), g = /* @__PURE__ */ y({
|
|
19
|
+
__name: "DynamicFormItemChoice",
|
|
20
|
+
props: {
|
|
21
|
+
template: {},
|
|
22
|
+
field: {}
|
|
23
|
+
},
|
|
24
|
+
setup(t) {
|
|
25
|
+
return (a, r) => {
|
|
26
|
+
const e = I("DynamicFormItem");
|
|
27
|
+
return l(), c(f(a.template), {
|
|
28
|
+
type: "choice",
|
|
29
|
+
field: a.field
|
|
30
|
+
}, {
|
|
31
|
+
children: s(() => [
|
|
32
|
+
(l(!0), D(F, null, k(a.field.choice, (m) => (l(), c(e, {
|
|
33
|
+
key: m.name,
|
|
34
|
+
field: m,
|
|
35
|
+
template: a.template
|
|
36
|
+
}, null, 8, ["field", "template"]))), 128))
|
|
37
|
+
]),
|
|
38
|
+
_: 1
|
|
39
|
+
}, 8, ["field"]);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}), S = /* @__PURE__ */ y({
|
|
43
|
+
__name: "DynamicFormItem",
|
|
44
|
+
props: {
|
|
45
|
+
template: {},
|
|
46
|
+
field: {}
|
|
47
|
+
},
|
|
48
|
+
setup(t) {
|
|
49
|
+
const a = p(() => !!t.field.choice?.length), r = p(() => t.field.maxOccurs > 1);
|
|
50
|
+
return (e, m) => {
|
|
51
|
+
const n = I("DynamicFormItem", !0);
|
|
52
|
+
return a.value ? (l(), c(f(e.template), {
|
|
53
|
+
key: 0,
|
|
54
|
+
type: "choice",
|
|
55
|
+
field: e.field
|
|
56
|
+
}, {
|
|
57
|
+
children: s(() => [
|
|
58
|
+
C(g, {
|
|
59
|
+
field: e.field,
|
|
60
|
+
template: e.template
|
|
61
|
+
}, null, 8, ["field", "template"])
|
|
62
|
+
]),
|
|
63
|
+
_: 1
|
|
64
|
+
}, 8, ["field"])) : r.value ? (l(), c(f(e.template), {
|
|
65
|
+
key: 1,
|
|
66
|
+
type: "array",
|
|
67
|
+
field: e.field
|
|
68
|
+
}, {
|
|
69
|
+
children: s(() => [
|
|
70
|
+
C(b, {
|
|
71
|
+
field: e.field,
|
|
72
|
+
template: e.template
|
|
73
|
+
}, null, 8, ["field", "template"])
|
|
74
|
+
]),
|
|
75
|
+
_: 1
|
|
76
|
+
}, 8, ["field"])) : (l(), c(f(e.template), {
|
|
77
|
+
key: 2,
|
|
78
|
+
type: e.field.type,
|
|
79
|
+
field: e.field
|
|
80
|
+
}, {
|
|
81
|
+
input: s(() => [
|
|
82
|
+
(l(), c(f(e.template), {
|
|
83
|
+
type: `${e.field.type}-input`,
|
|
84
|
+
field: e.field
|
|
85
|
+
}, null, 8, ["type", "field"]))
|
|
86
|
+
]),
|
|
87
|
+
children: s(() => [
|
|
88
|
+
(l(!0), D(F, null, k(e.field.children, (i) => (l(), c(n, {
|
|
89
|
+
key: i.name,
|
|
90
|
+
field: i,
|
|
91
|
+
template: e.template
|
|
92
|
+
}, null, 8, ["field", "template"]))), 128))
|
|
93
|
+
]),
|
|
94
|
+
_: 1
|
|
95
|
+
}, 8, ["type", "field"]));
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}), B = /* @__PURE__ */ y({
|
|
99
|
+
name: "DynamicForm",
|
|
100
|
+
inheritAttrs: !1,
|
|
101
|
+
__name: "DynamicForm",
|
|
102
|
+
props: {
|
|
103
|
+
metadata: {},
|
|
104
|
+
template: {}
|
|
105
|
+
},
|
|
106
|
+
setup(t) {
|
|
107
|
+
const a = p(
|
|
108
|
+
() => Array.isArray(t.metadata) ? t.metadata : [t.metadata]
|
|
109
|
+
), r = p(
|
|
110
|
+
() => a.value?.map((n, i) => e(n, i))
|
|
111
|
+
);
|
|
112
|
+
function e(n, i, h) {
|
|
113
|
+
if (!n)
|
|
114
|
+
return n;
|
|
115
|
+
const v = `field-${i}`, o = {
|
|
116
|
+
// Set defaults
|
|
117
|
+
name: v,
|
|
118
|
+
type: "text",
|
|
119
|
+
// Default type
|
|
120
|
+
path: n.name ?? v,
|
|
121
|
+
minOccurs: 1,
|
|
122
|
+
// by default required
|
|
123
|
+
maxOccurs: 1,
|
|
124
|
+
// by default not repeatable
|
|
125
|
+
...n,
|
|
126
|
+
// Override some of the field properties
|
|
127
|
+
transformReactively: [...n.transformReactively ?? []],
|
|
128
|
+
parent: h
|
|
129
|
+
};
|
|
130
|
+
return o.children = (n.children ?? []).map(
|
|
131
|
+
(u, d) => e(u, d, o)
|
|
132
|
+
), o.choice = (n.choice ?? []).map(
|
|
133
|
+
(u, d) => e(u, d, o)
|
|
134
|
+
), o.attributes = (n.attributes ?? []).map(
|
|
135
|
+
(u, d) => e(u, d, o)
|
|
136
|
+
), o;
|
|
137
|
+
}
|
|
138
|
+
const m = p(
|
|
139
|
+
() => t.template
|
|
140
|
+
);
|
|
141
|
+
return (n, i) => (l(!0), D(F, null, k(r.value, (h) => (l(), c(S, {
|
|
142
|
+
key: h.name,
|
|
143
|
+
template: m.value,
|
|
144
|
+
field: h
|
|
145
|
+
}, null, 8, ["template", "field"]))), 128));
|
|
146
|
+
}
|
|
147
|
+
}), N = /* @__PURE__ */ y({
|
|
148
|
+
name: "DynamicFormConfiguration",
|
|
149
|
+
__name: "DynamicFormTemplate",
|
|
150
|
+
props: {
|
|
151
|
+
type: { default: "default" },
|
|
152
|
+
metadataConfiguration: {},
|
|
153
|
+
field: {}
|
|
154
|
+
},
|
|
155
|
+
setup(t) {
|
|
156
|
+
const a = A(), r = p(() => t.type && a[t.type] ? t.type : t.type?.includes("-input") ? "default-input" : "default");
|
|
157
|
+
return (e, m) => e.field ? $(e.$slots, r.value, {
|
|
158
|
+
key: 0,
|
|
159
|
+
field: e.field
|
|
160
|
+
}) : _("", !0);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
function O(t, a) {
|
|
164
|
+
const r = ["text", "input", "children", "choice", "array"], e = ["text"], m = new Set(r);
|
|
165
|
+
return {
|
|
166
|
+
fieldTypes: [
|
|
167
|
+
...e,
|
|
168
|
+
...t.filter((i) => !m.has(i))
|
|
169
|
+
],
|
|
170
|
+
extendedProperties: a
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
B as DynamicForm,
|
|
175
|
+
S as DynamicFormItem,
|
|
176
|
+
b as DynamicFormItemArray,
|
|
177
|
+
g as DynamicFormItemChoice,
|
|
178
|
+
N as DynamicFormTemplate,
|
|
179
|
+
O as defineMetadata
|
|
180
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(o,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(o=typeof globalThis<"u"?globalThis:o||self,e(o.VueDynamicForm={},o.Vue))})(this,(function(o,e){"use strict";const s=e.defineComponent({__name:"DynamicFormItemArray",props:{template:{},field:{}},setup(n){return(a,r)=>{const t=e.resolveComponent("DynamicFormItem");return e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.field.children,m=>(e.openBlock(),e.createBlock(t,{key:m.name,template:a.template,field:m},null,8,["template","field"]))),128)}}}),y=e.defineComponent({__name:"DynamicFormItemChoice",props:{template:{},field:{}},setup(n){return(a,r)=>{const t=e.resolveComponent("DynamicFormItem");return e.openBlock(),e.createBlock(e.resolveDynamicComponent(a.template),{type:"choice",field:a.field},{children:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.field.choice,m=>(e.openBlock(),e.createBlock(t,{key:m.name,field:m,template:a.template},null,8,["field","template"]))),128))]),_:1},8,["field"])}}}),h=e.defineComponent({__name:"DynamicFormItem",props:{template:{},field:{}},setup(n){const a=e.computed(()=>!!n.field.choice?.length),r=e.computed(()=>n.field.maxOccurs>1);return(t,m)=>{const l=e.resolveComponent("DynamicFormItem",!0);return a.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.template),{key:0,type:"choice",field:t.field},{children:e.withCtx(()=>[e.createVNode(y,{field:t.field,template:t.template},null,8,["field","template"])]),_:1},8,["field"])):r.value?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.template),{key:1,type:"array",field:t.field},{children:e.withCtx(()=>[e.createVNode(s,{field:t.field,template:t.template},null,8,["field","template"])]),_:1},8,["field"])):(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.template),{key:2,type:t.field.type,field:t.field},{input:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.template),{type:`${t.field.type}-input`,field:t.field},null,8,["type","field"]))]),children:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.field.children,i=>(e.openBlock(),e.createBlock(l,{key:i.name,field:i,template:t.template},null,8,["field","template"]))),128))]),_:1},8,["type","field"]))}}}),u=e.defineComponent({name:"DynamicForm",inheritAttrs:!1,__name:"DynamicForm",props:{metadata:{},template:{}},setup(n){const a=e.computed(()=>Array.isArray(n.metadata)?n.metadata:[n.metadata]),r=e.computed(()=>a.value?.map((l,i)=>t(l,i)));function t(l,i,f){if(!l)return l;const k=`field-${i}`,c={name:k,type:"text",path:l.name??k,minOccurs:1,maxOccurs:1,...l,transformReactively:[...l.transformReactively??[]],parent:f};return c.children=(l.children??[]).map((p,d)=>t(p,d,c)),c.choice=(l.choice??[]).map((p,d)=>t(p,d,c)),c.attributes=(l.attributes??[]).map((p,d)=>t(p,d,c)),c}const m=e.computed(()=>n.template);return(l,i)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.value,f=>(e.openBlock(),e.createBlock(h,{key:f.name,template:m.value,field:f},null,8,["template","field"]))),128))}}),B=e.defineComponent({name:"DynamicFormConfiguration",__name:"DynamicFormTemplate",props:{type:{default:"default"},metadataConfiguration:{},field:{}},setup(n){const a=e.useSlots(),r=e.computed(()=>n.type&&a[n.type]?n.type:n.type?.includes("-input")?"default-input":"default");return(t,m)=>t.field?e.renderSlot(t.$slots,r.value,{key:0,field:t.field}):e.createCommentVNode("",!0)}});function D(n,a){const r=["text","input","children","choice","array"],t=["text"],m=new Set(r);return{fieldTypes:[...t,...n.filter(i=>!m.has(i))],extendedProperties:a}}o.DynamicForm=u,o.DynamicFormItem=h,o.DynamicFormItemArray=s,o.DynamicFormItemChoice=y,o.DynamicFormTemplate=B,o.defineMetadata=D,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bach.software/vue-dynamic-form",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.2",
|
|
4
5
|
"description": "A simple yet highly extendable dynamic form system, inspired by the flexibility of XSD and powered by Vee-Validate.",
|
|
6
|
+
"author": "Jeroen Bach <jeroen@bach.software> (https://bach.software)",
|
|
7
|
+
"homepage": "https://github.com/jeroenbach/dynamic-form",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/jeroenbach/dynamic-form.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/jeroenbach/dynamic-form/issues"
|
|
14
|
+
},
|
|
5
15
|
"keywords": [
|
|
6
16
|
"dynamic-form",
|
|
7
17
|
"typescript",
|
|
@@ -9,35 +19,51 @@
|
|
|
9
19
|
"form",
|
|
10
20
|
"vue"
|
|
11
21
|
],
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/jeroenbach/dynamic-form.git"
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/src/index.d.ts",
|
|
25
|
+
"import": "./dist/vue-dynamic-form.es.js",
|
|
26
|
+
"require": "./dist/vue-dynamic-form.umd.js"
|
|
27
|
+
}
|
|
20
28
|
},
|
|
29
|
+
"main": "./dist/vue-dynamic-form.umd.js",
|
|
30
|
+
"module": "./dist/vue-dynamic-form.es.js",
|
|
31
|
+
"types": "./dist/src/index.d.ts",
|
|
21
32
|
"files": [
|
|
22
33
|
"dist"
|
|
23
34
|
],
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"vee-validate": ">=4.15",
|
|
37
|
+
"vue": ">=3.5"
|
|
38
|
+
},
|
|
27
39
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
40
|
+
"@antfu/eslint-config": "^5.2.1",
|
|
41
|
+
"@changesets/cli": "2.29.5",
|
|
42
|
+
"@types/node": "24.2.1",
|
|
43
|
+
"@vitejs/plugin-vue": "6.0.1",
|
|
44
|
+
"eslint": "9.33.0",
|
|
45
|
+
"eslint-plugin-format": "^1.0.1",
|
|
46
|
+
"tsc-alias": "1.8.16",
|
|
47
|
+
"typescript": "5.9.2",
|
|
48
|
+
"vee-validate": "4.15.1",
|
|
49
|
+
"vite": "7.1.2",
|
|
50
|
+
"vitest": "^3.2.4",
|
|
51
|
+
"vue": ">=3.5",
|
|
52
|
+
"vue-tsc": "3.0.5"
|
|
32
53
|
},
|
|
33
54
|
"scripts": {
|
|
34
|
-
"
|
|
35
|
-
"dev": "
|
|
55
|
+
"check-updates": "pnpm dlx npm-check-updates -i --format group",
|
|
56
|
+
"dev": "pnpm build:watch & cd ./playgrounds/storybook && pnpm dev",
|
|
57
|
+
"build": "vite build && vue-tsc --emitDeclarationOnly && tsc-alias",
|
|
58
|
+
"build:watch": "vite build --watch & vue-tsc --emitDeclarationOnly --watch & tsc-alias --watch",
|
|
59
|
+
"typecheck": "vue-tsc --noEmit",
|
|
60
|
+
"lint": "eslint",
|
|
61
|
+
"lint:fix": "eslint --fix",
|
|
36
62
|
"test": "vitest run",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"ci": "
|
|
40
|
-
"
|
|
63
|
+
"ci": "pnpm ci:test && pnpm ci:lint && pnpm ci:typecheck",
|
|
64
|
+
"ci:test": "TZ=Europe/Amsterdam vitest run",
|
|
65
|
+
"ci:lint": "eslint",
|
|
66
|
+
"ci:typecheck": "vue-tsc --noEmit",
|
|
41
67
|
"changeset": "changeset"
|
|
42
68
|
}
|
|
43
69
|
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,cAAc,YAAY,CAAC"}
|
package/dist/utils.d.ts
DELETED
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,WAAU,CAAC"}
|
package/dist/utils.js
DELETED
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC"}
|
package/dist/utils.test.d.ts
DELETED
package/dist/utils.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../src/utils.test.ts"],"names":[],"mappings":""}
|
package/dist/utils.test.js
DELETED
package/dist/utils.test.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.js","sourceRoot":"","sources":["../src/utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;IACf,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC,CAAC,CAAC"}
|