@former-ui/former 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -134,7 +134,8 @@ Just configure your form layout, define the components and let former do the res
134
134
  </template>
135
135
 
136
136
  <script setup lang="ts">
137
- import { FormAdd, type FormComponents, FormContent, type FormData, Former, FormNodeProps, type Mode, type SchemaNode } from '@former-ui/former';
137
+ import type { FormComponents, FormData, Mode, SchemaNode } from '@former-ui/former';
138
+ import { FormAdd, FormContent, Former, FormNodeProps } from '@former-ui/former';
138
139
  import { markRaw, ref } from 'vue';
139
140
 
140
141
  import TextInput from './TextInput.vue';
@@ -251,6 +252,13 @@ const modelValue = defineModel<string>();
251
252
 
252
253
  For more detailed usage example check out the [Playground](https://github.com/geprog/former/blob/main/packages/playground/src/Playground.vue) implementation.
253
254
 
255
+ ### Path of the selected node
256
+
257
+ Next to the selected node, Former provides its path: the parents of the node from the top of the form down to it, e.g. the groups or repeaters it is in (empty for nodes at the top). The path updates when the selection changes or the selected node is moved.
258
+
259
+ - the default slot of `Former` passes it as `selectedNodePath`: `<Former v-slot="{ selectedNode, selectedNodePath }" ...>`
260
+ - the `node-actions` slot of `FormNodeProps` passes it as `path` next to `node`
261
+
254
262
  ## Form data and validation
255
263
 
256
264
  Each component validates its data with a schema built from the props of its node, e.g. `required`, `min` or `max`. Add a `validation` to its definition in the `components`, which is applied to every node of the component, including the props of the nodes in build mode. The first issue of the schema is passed as `error` to the component, while a form with an error emits `valid` as `false`.
@@ -273,7 +281,9 @@ const components: FormComponents = {
273
281
  if (max !== undefined) {
274
282
  schema = schema.max(max, `At most ${max}`);
275
283
  }
276
- return required ? schema : schema.nullish();
284
+ return required
285
+ ? schema
286
+ : schema.nullish();
277
287
  },
278
288
  },
279
289
  };
@@ -290,7 +300,9 @@ The second parameter of the validation is the context of the node, so the valida
290
300
  const validation: FormFieldType['validation'] = (props, { scopes }) => {
291
301
  // the data of a scope is unset until something was filled in
292
302
  const { start } = (scopes[0].data ?? {}) as FormData;
293
- const end = typeof start === 'number' ? z.number().min(start, 'The end must be after the start') : z.number();
303
+ const end = typeof start === 'number'
304
+ ? z.number().min(start, 'The end must be after the start')
305
+ : z.number();
294
306
  return end.nullish();
295
307
  };
296
308
  ```
@@ -1,15 +1,14 @@
1
- declare function __VLS_template(): {
2
- slots: {
3
- default?(_: {}): any;
1
+ declare const __VLS_template: () => {
2
+ __VLS_Slots: {
3
+ default?: (props: {}) => any;
4
4
  };
5
- refs: {};
6
- attrs: Partial<{}>;
7
5
  };
8
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
9
- declare const __VLS_component: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
10
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
6
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
7
+ declare const __VLS_base: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
8
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
9
+ declare const _default: typeof __VLS_export;
11
10
  export default _default;
12
- type __VLS_WithTemplateSlots<T, S> = T & {
11
+ type __VLS_WithSlots<T, S> = T & {
13
12
  new (): {
14
13
  $slots: S;
15
14
  };
@@ -1,2 +1,3 @@
1
- declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
1
+ declare const __VLS_export: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
2
3
  export default _default;
@@ -1,22 +1,19 @@
1
1
  import { FormData } from '../types';
2
- declare function __VLS_template(): {
3
- slots: {
4
- default?(_: {}): any;
5
- };
6
- refs: {};
7
- attrs: Partial<{}>;
8
- };
9
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
10
- declare const __VLS_component: import('vue').DefineComponent<{
11
- data: FormData;
12
- index: number;
13
- }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{
2
+ type __VLS_Props = {
14
3
  data: FormData;
15
4
  index: number;
16
- }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
17
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
5
+ };
6
+ declare const __VLS_template: () => {
7
+ __VLS_Slots: {
8
+ default?: (props: {}) => any;
9
+ };
10
+ };
11
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
12
+ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
13
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
14
+ declare const _default: typeof __VLS_export;
18
15
  export default _default;
19
- type __VLS_WithTemplateSlots<T, S> = T & {
16
+ type __VLS_WithSlots<T, S> = T & {
20
17
  new (): {
21
18
  $slots: S;
22
19
  };
@@ -1,19 +1,17 @@
1
- declare function __VLS_template(): {
2
- slots: {
3
- default?(_: {}): any;
1
+ type __VLS_Props = {
2
+ category?: string;
3
+ };
4
+ declare const __VLS_template: () => {
5
+ __VLS_Slots: {
6
+ default?: (props: {}) => any;
4
7
  };
5
- refs: {};
6
- attrs: Partial<{}>;
7
8
  };
8
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
9
- declare const __VLS_component: import('vue').DefineComponent<{
10
- category?: string;
11
- }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{
12
- category?: string;
13
- }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
14
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
9
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
10
+ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
11
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
12
+ declare const _default: typeof __VLS_export;
15
13
  export default _default;
16
- type __VLS_WithTemplateSlots<T, S> = T & {
14
+ type __VLS_WithSlots<T, S> = T & {
17
15
  new (): {
18
16
  $slots: S;
19
17
  };
@@ -1,20 +1,18 @@
1
1
  import { InternalSchemaNode } from '../types';
2
- declare function __VLS_template(): {
3
- slots: {
4
- default?(_: {}): any;
2
+ type __VLS_Props = {
3
+ node: InternalSchemaNode;
4
+ };
5
+ declare const __VLS_template: () => {
6
+ __VLS_Slots: {
7
+ default?: (props: {}) => any;
5
8
  };
6
- refs: {};
7
- attrs: Partial<{}>;
8
9
  };
9
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
10
- declare const __VLS_component: import('vue').DefineComponent<{
11
- node: InternalSchemaNode;
12
- }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{
13
- node: InternalSchemaNode;
14
- }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
15
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
10
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
11
+ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
12
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
13
+ declare const _default: typeof __VLS_export;
16
14
  export default _default;
17
- type __VLS_WithTemplateSlots<T, S> = T & {
15
+ type __VLS_WithSlots<T, S> = T & {
18
16
  new (): {
19
17
  $slots: S;
20
18
  };
@@ -3,33 +3,36 @@ declare function addNode(newNode: SchemaNode): void;
3
3
  declare function removeNode(): void;
4
4
  declare function unselectComponent(): void;
5
5
  declare function deleteComponent(): void;
6
- declare function __VLS_template(): {
7
- slots: {
8
- "delete-button"?(_: {
6
+ declare const __VLS_template: () => {
7
+ __VLS_Slots: {
8
+ 'delete-button'?: (props: {
9
9
  delete: typeof deleteComponent;
10
- }): any;
11
- "node-actions"?(_: {
10
+ }) => any;
11
+ } & {
12
+ 'node-actions'?: (props: {
12
13
  node: SchemaNode;
14
+ path: SchemaNode[];
13
15
  addNode: typeof addNode;
14
16
  removeNode: typeof removeNode;
15
- }): any;
16
- "unselect-button"?(_: {
17
+ }) => any;
18
+ } & {
19
+ 'unselect-button'?: (props: {
17
20
  unselect: typeof unselectComponent;
18
- }): any;
19
- "nothing-selected"?(_: {}): any;
21
+ }) => any;
22
+ } & {
23
+ 'nothing-selected'?: (props: {}) => any;
20
24
  };
21
- refs: {};
22
- attrs: Partial<{}>;
23
25
  };
24
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
25
- declare const __VLS_component: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
26
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
27
+ declare const __VLS_base: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
26
28
  valid: (valid: boolean) => any;
27
29
  }, string, import('vue').PublicProps, Readonly<{}> & Readonly<{
28
30
  onValid?: ((valid: boolean) => any) | undefined;
29
31
  }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
30
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
32
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
33
+ declare const _default: typeof __VLS_export;
31
34
  export default _default;
32
- type __VLS_WithTemplateSlots<T, S> = T & {
35
+ type __VLS_WithSlots<T, S> = T & {
33
36
  new (): {
34
37
  $slots: S;
35
38
  };
@@ -1,6 +1,6 @@
1
- declare const _default: import('vue').DefineComponent<{
1
+ type __VLS_Props = {
2
2
  category?: string;
3
- }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{
4
- category?: string;
5
- }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
3
+ };
4
+ declare const __VLS_export: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
5
+ declare const _default: typeof __VLS_export;
6
6
  export default _default;
@@ -1,18 +1,18 @@
1
1
  import { FormComponents, FormData, InternalSchemaNode, Mode, SchemaNode, ShowIfPredicate, Texts } from '../types';
2
- declare let __VLS_typeProps: {
2
+ type __VLS_Props = {
3
3
  components: FormComponents;
4
4
  showIf?: ShowIfPredicate;
5
5
  mode?: Mode;
6
6
  texts?: Partial<Texts>;
7
- isUpdating?: boolean;
8
7
  };
9
- type __VLS_PublicProps = {
8
+ type __VLS_ModelProps = {
10
9
  'schema': SchemaNode[];
11
10
  'data'?: FormData;
12
- } & typeof __VLS_typeProps;
13
- declare function __VLS_template(): {
14
- slots: {
15
- default?(_: {
11
+ };
12
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
13
+ declare const __VLS_template: () => {
14
+ __VLS_Slots: {
15
+ default?: (props: {
16
16
  selectedNode: {
17
17
  type: string;
18
18
  name?: string | undefined;
@@ -40,31 +40,30 @@ declare function __VLS_template(): {
40
40
  } | /*elided*/ any[] | undefined;
41
41
  }[] | undefined;
42
42
  } | undefined;
43
- }): any;
43
+ selectedNodePath: InternalSchemaNode[];
44
+ }) => any;
44
45
  };
45
- refs: {};
46
- attrs: Partial<{}>;
47
46
  };
48
- type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
49
- declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
50
- "update:schema": (schema: SchemaNode[]) => any;
51
- "update:data": (data: FormData) => any;
47
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
48
+ declare const __VLS_base: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
49
+ "update:schema": (value: SchemaNode[]) => any;
50
+ "update:data": (value: FormData) => any;
52
51
  } & {
53
52
  valid: (valid: boolean) => any;
54
53
  schemaValid: (valid: boolean) => any;
55
54
  }, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
56
55
  onValid?: ((valid: boolean) => any) | undefined;
57
56
  onSchemaValid?: ((valid: boolean) => any) | undefined;
58
- "onUpdate:schema"?: ((schema: SchemaNode[]) => any) | undefined;
59
- "onUpdate:data"?: ((data: FormData) => any) | undefined;
57
+ "onUpdate:schema"?: ((value: SchemaNode[]) => any) | undefined;
58
+ "onUpdate:data"?: ((value: FormData) => any) | undefined;
60
59
  }>, {
61
60
  mode: Mode;
62
61
  texts: Partial<Texts>;
63
- isUpdating: boolean;
64
62
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
65
- declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
63
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
64
+ declare const _default: typeof __VLS_export;
66
65
  export default _default;
67
- type __VLS_WithTemplateSlots<T, S> = T & {
66
+ type __VLS_WithSlots<T, S> = T & {
68
67
  new (): {
69
68
  $slots: S;
70
69
  };
@@ -1,13 +1,13 @@
1
- import { DataScope, FieldData, FormComponents, FormData, InternalSchemaNode, InternalShowIfPredicate, Mode, Texts } from '../types';
2
1
  import { InjectionKey, Ref } from 'vue';
2
+ import { DataScope, FieldData, FormComponents, FormData, InternalSchemaNode, InternalShowIfPredicate, Mode, Texts } from '../types';
3
3
  export type InjectKeys = {
4
4
  mode: Ref<Mode>;
5
5
  formId: Ref<string>;
6
- formerIsUpdating: Ref<boolean>;
7
6
  schema: Ref<InternalSchemaNode[]>;
8
7
  data: Ref<FormData | FieldData>;
9
8
  components: Ref<FormComponents>;
10
9
  selectedNode: Ref<InternalSchemaNode | undefined>;
10
+ selectedNodePath: Ref<InternalSchemaNode[]>;
11
11
  validityMap: Ref<Record<string, boolean | undefined>>;
12
12
  propsValidity: Ref<Record<string, boolean | string>>;
13
13
  showIf?: InternalShowIfPredicate;
@@ -1,3 +1,3 @@
1
- import { FieldData, FormData, SchemaNode } from '../types';
2
1
  import { MaybeRefOrGetter } from 'vue';
2
+ import { FieldData, FormData, SchemaNode } from '../types';
3
3
  export declare function useHasContent(nodes: MaybeRefOrGetter<SchemaNode[]>, data: MaybeRefOrGetter<FieldData | FormData>): import('vue').ComputedRef<boolean>;
@@ -1,5 +1,5 @@
1
- import { InternalSchemaNode } from '../types';
2
1
  import { Ref } from 'vue';
2
+ import { InternalSchemaNode } from '../types';
3
3
  export default function useNode(node: Ref<InternalSchemaNode>): {
4
4
  component: import('vue').ComputedRef<(import('vue').ConcreteComponent<any, any, any, import('vue').ComputedOptions, import('vue').MethodOptions, {}, any> | {
5
5
  new (...args: any[]): any;
@@ -1,5 +1,5 @@
1
- import { FormComponents, InternalSchemaNode } from '../types';
2
1
  import { MaybeRefOrGetter, Ref } from 'vue';
2
+ import { FormComponents, InternalSchemaNode } from '../types';
3
3
  export type PropsValidity = Record<string, boolean | string>;
4
4
  export default function useSchema(schema: Ref<InternalSchemaNode[]>, components: MaybeRefOrGetter<FormComponents>): {
5
5
  isValid: import('vue').ComputedRef<boolean>;