@former-ui/former 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 GEPROG GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,320 @@
1
- # Temporary Holding Version
1
+ # 👩🏾‍🌾 Former
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Former is a headless library for building and handling forms for Vue using an UI. The available components must be configured externally so that it is highly customizable per use case.
4
+
5
+ It includes further headless features like:
6
+
7
+ - conditional showing elements
8
+ - validation
9
+
10
+ ## Playground
11
+
12
+ Create and test your own form at the [playground](https://geprog.github.io/former).
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pnpm add @former-ui/former
18
+ ```
19
+
20
+ ```bash
21
+ npm install @former-ui/former
22
+ ```
23
+
24
+ ```bash
25
+ yarn add @former-ui/former
26
+ ```
27
+
28
+ ## Tailwind CSS Configuration
29
+
30
+ Former UI uses Tailwind CSS for styling. The library's build **excludes** Tailwind's base reset styles (preflight) to avoid conflicts with your app's own CSS reset.
31
+
32
+ ### Option 1: Import the library's CSS file (Recommended)
33
+
34
+ Import the pre-built CSS file in your app:
35
+
36
+ ```js
37
+ // In your main.js or main.ts
38
+ import '@former-ui/former/former-ui.css';
39
+ ```
40
+
41
+ Make sure your consuming app includes Tailwind's base reset in your own CSS:
42
+
43
+ ```css
44
+ /* In your app's main CSS file */
45
+ @tailwind base; /* Include this in your app */
46
+ @tailwind components;
47
+ @tailwind utilities;
48
+ ```
49
+
50
+ ### Option 2: Include Former UI in your Tailwind build
51
+
52
+ If you want to include Former UI's classes in your own Tailwind build, add the library's build files to your Tailwind `content` configuration:
53
+
54
+ ```js
55
+ // tailwind.config.js
56
+ export default {
57
+ content: [
58
+ './index.html',
59
+ './src/**/*.{vue,js,ts,jsx,tsx}',
60
+ // Include Former UI's build files so Tailwind can scan them
61
+ './node_modules/@former-ui/former/dist/**/*.js',
62
+ ],
63
+ theme: {
64
+ extend: {
65
+ // Your theme customizations
66
+ },
67
+ },
68
+ plugins: [],
69
+ };
70
+ ```
71
+
72
+ This way, Tailwind will generate only the classes used by both your app and Former UI.
73
+
74
+ #### Tailwind v4 (CSS-first)
75
+
76
+ If your app uses Tailwind v4’s CSS entry (for example `@import "tailwindcss"` in your main stylesheet), add Former as a **`@source`** so utilities referenced in Former’s components are generated. Paths are relative to that CSS file.
77
+
78
+ By default, Tailwind v4’s `dark` variant follows **`prefers-color-scheme`**. Former’s components expect **`dark:`** utilities to apply when a **`dark` class** sits on an ancestor (same idea as `darkMode: 'selector'` in v3). Override the variant if you toggle dark mode that way:
79
+
80
+ ```css
81
+ @import 'tailwindcss';
82
+
83
+ @custom-variant dark (&:where(.dark, .dark *));
84
+
85
+ @source '../node_modules/@former-ui/former/dist';
86
+ ```
87
+
88
+ You do **not** need `import '@former-ui/former/former-ui.css'` when Former is covered by your Tailwind build this way.
89
+
90
+ ### Dark Mode Configuration
91
+
92
+ **Important:** Former UI uses Tailwind’s **selector**-based dark mode (`dark` class on an ancestor), not only `prefers-color-scheme`.
93
+
94
+ - **Tailwind v3 (`tailwind.config.js`):** set `darkMode: 'selector'`.
95
+ - **Tailwind v4 (CSS-first):** define a class-based `dark` variant as in the snippet above (for example `@custom-variant dark (&:where(.dark, .dark *));`). If another part of your stack also toggles a `dark` class on `<html>` from system settings, align that behavior with how you want Former to behave.
96
+
97
+ If you’re using Option 1 (importing the pre-built CSS), dark utilities are already in that bundle; you still need selector-style `dark` on a parent if you toggle dark mode with a class (same as Option 2).
98
+
99
+ ## Usage
100
+
101
+ Just configure your form layout, define the components and let former do the rest.
102
+
103
+ ```vue
104
+ <template>
105
+ <div>
106
+ <label>Former mode:</label>
107
+ <select v-model="mode">
108
+ <option value="build">
109
+ build
110
+ </option>
111
+ <option value="edit">
112
+ edit
113
+ </option>
114
+ <option value="read">
115
+ read
116
+ </option>
117
+ </select>
118
+ </div>
119
+ <Former v-slot="{ selectedNode }" v-model:schema="schema" v-model:data="data" :mode :components>
120
+ <main>
121
+ <h1>My Form</h1>
122
+ <FormContent />
123
+ </main>
124
+
125
+ <aside>
126
+ <h2>Form Config</h2>
127
+ <template v-if="mode === 'build'">
128
+ <FormNodeProps v-if="selectedNode" />
129
+ <FormAdd v-else />
130
+ </template>
131
+ <pre>{{ data }}</pre>
132
+ </aside>
133
+ </Former>
134
+ </template>
135
+
136
+ <script setup lang="ts">
137
+ import type { FormComponents, FormData, Mode, SchemaNode } from '@former-ui/former';
138
+ import { FormAdd, FormContent, Former, FormNodeProps } from '@former-ui/former';
139
+ import { markRaw, ref } from 'vue';
140
+
141
+ import TextInput from './TextInput.vue';
142
+
143
+ const schema = ref<SchemaNode[]>([
144
+ {
145
+ type: 'text',
146
+ name: 'name',
147
+ props: {
148
+ label: 'Name',
149
+ placeholder: 'Enter your name',
150
+ },
151
+ },
152
+ {
153
+ type: 'text',
154
+ name: 'email',
155
+ props: {
156
+ label: 'Email',
157
+ placeholder: 'Enter your e-mail',
158
+ type: 'email'
159
+ },
160
+ },
161
+ {
162
+ type: 'text',
163
+ name: 'password',
164
+ props: {
165
+ label: 'Password',
166
+ placeholder: 'Enter your password',
167
+ type: 'password'
168
+ },
169
+ },
170
+ ]);
171
+
172
+ const components: FormComponents = {
173
+ text: {
174
+ label: 'Text',
175
+ component: markRaw(TextInput),
176
+ propsSchema: [
177
+ {
178
+ type: 'text',
179
+ name: '$name',
180
+ props: {
181
+ label: 'Name',
182
+ placeholder: 'Enter the name of the data field',
183
+ },
184
+ },
185
+
186
+ {
187
+ type: 'text',
188
+ name: 'label',
189
+ props: {
190
+ label: 'Label',
191
+ placeholder: 'Enter a label',
192
+ },
193
+ },
194
+ {
195
+ type: 'text',
196
+ name: 'placeholder',
197
+ props: {
198
+ label: 'Placeholder',
199
+ placeholder: 'Enter a placeholder',
200
+ },
201
+ },
202
+ {
203
+ type: 'text',
204
+ name: 'type',
205
+ props: {
206
+ label: 'Text input type',
207
+ placeholder: 'Specify the text input type e.g. "text", "password", "email", ...'
208
+ }
209
+ }
210
+ ],
211
+ },
212
+ };
213
+
214
+ const mode = ref<Mode>('edit');
215
+
216
+ const data = ref<FormData>({});
217
+ </script>
218
+ ```
219
+
220
+ Of course you need to provide the relevant component implementations.
221
+ Here is a sample text input implementation that is suitable for the above sample
222
+
223
+ ```vue
224
+ <template>
225
+ <div>
226
+ <label v-if="label" :for="id">{{ label }}</label>
227
+ <div>
228
+ <input :id v-model="modelValue" :disabled="mode === 'read'" :type :placeholder>
229
+ </div>
230
+ <div v-if="error">
231
+ {{ error }}
232
+ </div>
233
+ </div>
234
+ </template>
235
+
236
+ <script setup lang="ts">
237
+ import type { FormerProps } from '@former-ui/former';
238
+
239
+ withDefaults(
240
+ defineProps<{
241
+ label?: string;
242
+ type?: 'text' | 'password' | 'email';
243
+ placeholder?: string;
244
+ } & FormerProps>(),
245
+ {
246
+ type: 'text',
247
+ },
248
+ );
249
+ const modelValue = defineModel<string>();
250
+ </script>
251
+ ```
252
+
253
+ For more detailed usage example check out the [Playground](https://github.com/geprog/former/blob/main/packages/playground/src/Playground.vue) implementation.
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
+
262
+ ## Form data and validation
263
+
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`.
265
+
266
+ The validation supports [Standard Schema](https://standardschema.dev), so any compliant library like [Zod](https://zod.dev), [Valibot](https://valibot.dev), [ArkType](https://arktype.io) or [Yup](https://github.com/jquense/yup) can be used, also with async schemas:
267
+
268
+ ```ts
269
+ import { z } from 'zod';
270
+
271
+ const components: FormComponents = {
272
+ number: {
273
+ label: 'Number',
274
+ component: NumberField,
275
+ propsSchema: [/* ... */],
276
+ validation: ({ required, min, max }) => {
277
+ let schema = z.number('Not a number');
278
+ if (min !== undefined) {
279
+ schema = schema.min(min, `At least ${min}`);
280
+ }
281
+ if (max !== undefined) {
282
+ schema = schema.max(max, `At most ${max}`);
283
+ }
284
+ return required
285
+ ? schema
286
+ : schema.nullish();
287
+ },
288
+ },
289
+ };
290
+ ```
291
+
292
+ The second parameter of the validation is the context of the node, so the validation can be relative to other data:
293
+
294
+ - `scopes`: all scopes containing the node from the closest one to the form data, e.g. `[repeater item, group, form]` for a field in a repeater item inside of a group. Each scope has its `data`, its `path` and the `node` providing it (the group or repeater, unset for the form)
295
+ - `path`: the path of the data of the node in the form data, e.g. `['periods', 1, 'end']`
296
+ - `node`: the node itself
297
+
298
+ ```ts
299
+ // the end of a period must not be before the start of the same repeater item
300
+ const validation: FormFieldType['validation'] = (props, { scopes }) => {
301
+ // the data of a scope is unset until something was filled in
302
+ const { start } = (scopes[0].data ?? {}) as FormData;
303
+ const end = typeof start === 'number'
304
+ ? z.number().min(start, 'The end must be after the start')
305
+ : z.number();
306
+ return end.nullish();
307
+ };
308
+ ```
309
+
310
+ Data from outside of the form (e.g. options loaded from a server) can be used by creating the `components` in a function receiving it.
311
+
312
+ Hidden nodes (see `showIf`) are not validated.
313
+
314
+ While an async schema is pending, the form emits `valid` as `false`. If the validation throws or its promise rejects (e.g. a server isn't reachable), the message of the error is passed as `error` to the component.
315
+
316
+ When the user clears a field, its value is set to `null` instead of being removed from the data. This way the key survives JSON serialization and e.g. a preset value is not applied again after the data was saved and loaded. A field that was never filled in is `undefined`, so check for both when testing for an empty value. The exported `hasValue` helper treats `undefined`, `null`, `''`, `false` and empty lists and objects without any filled in value as empty, while a list with items counts as filled in even if its items are empty. With a schema, optional fields therefore need to accept `null` as well, e.g. with `.nullish()` of Zod. Cleared props on the other hand are passed to the `validation` (like to the components) as not set.
317
+
318
+ ## Ready-to-use components
319
+
320
+ If you use [Nuxt UI](https://ui.nuxt.com), [`@former-ui/preset-nuxt-ui`](https://github.com/geprog/former/blob/main/packages/preset-nuxt-ui/README.md) provides form components for text, numbers, dates, selections, file uploads, groups, columns, repeaters and more.
@@ -0,0 +1,15 @@
1
+ declare const __VLS_template: () => {
2
+ __VLS_Slots: {
3
+ default?: (props: {}) => any;
4
+ };
5
+ };
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;
10
+ export default _default;
11
+ type __VLS_WithSlots<T, S> = T & {
12
+ new (): {
13
+ $slots: S;
14
+ };
15
+ };
@@ -0,0 +1,3 @@
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;
3
+ export default _default;
@@ -0,0 +1,20 @@
1
+ import { FormData } from '../types';
2
+ type __VLS_Props = {
3
+ data: FormData;
4
+ index: number;
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;
15
+ export default _default;
16
+ type __VLS_WithSlots<T, S> = T & {
17
+ new (): {
18
+ $slots: S;
19
+ };
20
+ };
@@ -0,0 +1,18 @@
1
+ type __VLS_Props = {
2
+ category?: string;
3
+ };
4
+ declare const __VLS_template: () => {
5
+ __VLS_Slots: {
6
+ default?: (props: {}) => any;
7
+ };
8
+ };
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;
13
+ export default _default;
14
+ type __VLS_WithSlots<T, S> = T & {
15
+ new (): {
16
+ $slots: S;
17
+ };
18
+ };
@@ -0,0 +1,19 @@
1
+ import { InternalSchemaNode } from '../types';
2
+ type __VLS_Props = {
3
+ node: InternalSchemaNode;
4
+ };
5
+ declare const __VLS_template: () => {
6
+ __VLS_Slots: {
7
+ default?: (props: {}) => any;
8
+ };
9
+ };
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;
14
+ export default _default;
15
+ type __VLS_WithSlots<T, S> = T & {
16
+ new (): {
17
+ $slots: S;
18
+ };
19
+ };
@@ -0,0 +1,39 @@
1
+ import { SchemaNode } from '../types';
2
+ declare function addNode(newNode: SchemaNode): void;
3
+ declare function removeNode(): void;
4
+ declare function unselectComponent(): void;
5
+ declare function deleteComponent(): void;
6
+ declare const __VLS_template: () => {
7
+ __VLS_Slots: {
8
+ 'delete-button'?: (props: {
9
+ delete: typeof deleteComponent;
10
+ }) => any;
11
+ } & {
12
+ 'node-actions'?: (props: {
13
+ node: SchemaNode;
14
+ path: SchemaNode[];
15
+ addNode: typeof addNode;
16
+ removeNode: typeof removeNode;
17
+ }) => any;
18
+ } & {
19
+ 'unselect-button'?: (props: {
20
+ unselect: typeof unselectComponent;
21
+ }) => any;
22
+ } & {
23
+ 'nothing-selected'?: (props: {}) => any;
24
+ };
25
+ };
26
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
27
+ declare const __VLS_base: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
28
+ valid: (valid: boolean) => any;
29
+ }, string, import('vue').PublicProps, Readonly<{}> & Readonly<{
30
+ onValid?: ((valid: boolean) => any) | undefined;
31
+ }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
32
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
33
+ declare const _default: typeof __VLS_export;
34
+ export default _default;
35
+ type __VLS_WithSlots<T, S> = T & {
36
+ new (): {
37
+ $slots: S;
38
+ };
39
+ };
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ category?: string;
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
+ export default _default;
@@ -0,0 +1,70 @@
1
+ import { FormComponents, FormData, InternalSchemaNode, Mode, SchemaNode, ShowIfPredicate, Texts } from '../types';
2
+ type __VLS_Props = {
3
+ components: FormComponents;
4
+ showIf?: ShowIfPredicate;
5
+ mode?: Mode;
6
+ texts?: Partial<Texts>;
7
+ };
8
+ type __VLS_ModelProps = {
9
+ 'schema': SchemaNode[];
10
+ 'data'?: FormData;
11
+ };
12
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
13
+ declare const __VLS_template: () => {
14
+ __VLS_Slots: {
15
+ default?: (props: {
16
+ selectedNode: {
17
+ type: string;
18
+ name?: string | undefined;
19
+ props?: {
20
+ [key: string]: any;
21
+ } | undefined;
22
+ showIf?: string | undefined;
23
+ _id: string;
24
+ children?: {
25
+ [category: string]: InternalSchemaNode<{
26
+ [key: string]: any;
27
+ }>[];
28
+ } | {
29
+ type: string;
30
+ name?: string | undefined;
31
+ props?: {
32
+ [key: string]: any;
33
+ } | undefined;
34
+ showIf?: string | undefined;
35
+ _id: string;
36
+ children?: {
37
+ [category: string]: InternalSchemaNode<{
38
+ [key: string]: any;
39
+ }>[];
40
+ } | /*elided*/ any[] | undefined;
41
+ }[] | undefined;
42
+ } | undefined;
43
+ selectedNodePath: InternalSchemaNode[];
44
+ }) => any;
45
+ };
46
+ };
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;
51
+ } & {
52
+ valid: (valid: boolean) => any;
53
+ schemaValid: (valid: boolean) => any;
54
+ }, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
55
+ onValid?: ((valid: boolean) => any) | undefined;
56
+ onSchemaValid?: ((valid: boolean) => any) | undefined;
57
+ "onUpdate:schema"?: ((value: SchemaNode[]) => any) | undefined;
58
+ "onUpdate:data"?: ((value: FormData) => any) | undefined;
59
+ }>, {
60
+ mode: Mode;
61
+ texts: Partial<Texts>;
62
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
63
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
64
+ declare const _default: typeof __VLS_export;
65
+ export default _default;
66
+ type __VLS_WithSlots<T, S> = T & {
67
+ new (): {
68
+ $slots: S;
69
+ };
70
+ };
@@ -0,0 +1,23 @@
1
+ import { InjectionKey, Ref } from 'vue';
2
+ import { DataScope, FieldData, FormComponents, FormData, InternalSchemaNode, InternalShowIfPredicate, Mode, Texts } from '../types';
3
+ export type InjectKeys = {
4
+ mode: Ref<Mode>;
5
+ formId: Ref<string>;
6
+ schema: Ref<InternalSchemaNode[]>;
7
+ data: Ref<FormData | FieldData>;
8
+ components: Ref<FormComponents>;
9
+ selectedNode: Ref<InternalSchemaNode | undefined>;
10
+ selectedNodePath: Ref<InternalSchemaNode[]>;
11
+ validityMap: Ref<Record<string, boolean | undefined>>;
12
+ propsValidity: Ref<Record<string, boolean | string>>;
13
+ showIf?: InternalShowIfPredicate;
14
+ dataScopes?: Ref<DataScope[]>;
15
+ texts: Ref<Texts>;
16
+ node: Ref<InternalSchemaNode>;
17
+ hasDataKey?: Ref<boolean>;
18
+ isShown?: Ref<boolean>;
19
+ };
20
+ export declare function inject<T extends keyof InjectKeys>(key: T): InjectKeys[T];
21
+ export declare function inject<T extends keyof InjectKeys>(key: T, failIfNotProvided: true): InjectKeys[T];
22
+ export declare function inject<T extends keyof InjectKeys>(key: T, failIfNotProvided: false): InjectKeys[T] | undefined;
23
+ export declare function provide<T extends keyof InjectKeys>(key: T, value: T extends InjectionKey<infer V> ? V : InjectKeys[T]): void;
@@ -0,0 +1,3 @@
1
+ import { MaybeRefOrGetter } from 'vue';
2
+ import { FieldData, FormData, SchemaNode } from '../types';
3
+ export declare function useHasContent(nodes: MaybeRefOrGetter<SchemaNode[]>, data: MaybeRefOrGetter<FieldData | FormData>): import('vue').ComputedRef<boolean>;
@@ -0,0 +1,23 @@
1
+ import { Ref } from 'vue';
2
+ import { InternalSchemaNode } from '../types';
3
+ export default function useNode(node: Ref<InternalSchemaNode>): {
4
+ component: import('vue').ComputedRef<(import('vue').ConcreteComponent<any, any, any, import('vue').ComputedOptions, import('vue').MethodOptions, {}, any> | {
5
+ new (...args: any[]): any;
6
+ __isFragment?: never;
7
+ __isTeleport?: never;
8
+ __isSuspense?: never;
9
+ }) | import('vue').Raw<import('vue').ConcreteComponent<any, any, any, import('vue').ComputedOptions, import('vue').MethodOptions, {}, any> | {
10
+ new (...args: any[]): any;
11
+ __isFragment?: never;
12
+ __isTeleport?: never;
13
+ __isSuspense?: never;
14
+ }>>;
15
+ isLayoutComponent: import('vue').ComputedRef<boolean>;
16
+ modelValue: import('vue').WritableComputedRef<import('../types').FormData | import('../types').FieldData, import('../types').FormData | import('../types').FieldData>;
17
+ error: Ref<string | undefined, string | undefined>;
18
+ isShown: import('vue').ComputedRef<boolean>;
19
+ isValid: import('vue').ComputedRef<boolean>;
20
+ validityMap: Ref<Record<string, boolean | undefined>, Record<string, boolean | undefined>>;
21
+ hasDataKey: import('vue').ComputedRef<boolean>;
22
+ hasContent: import('vue').ComputedRef<boolean>;
23
+ };
@@ -0,0 +1,15 @@
1
+ import { MaybeRefOrGetter, Ref } from 'vue';
2
+ /**
3
+ * Applies a preset value to the model value of a form field whenever the field's key
4
+ * does not exist in the form data. Once the key exists (even with `null`, e.g. because
5
+ * the user cleared the field on purpose) the preset is not applied again. Fields that are
6
+ * newly added to a schema, that become visible again (their key gets removed when hidden)
7
+ * or whose key is removed from the data otherwise do get their preset.
8
+ *
9
+ * In read mode presets are never applied, so no values are shown that nobody entered.
10
+ * Hidden fields (they stay mounted in build mode) get their preset once they are shown again.
11
+ *
12
+ * Outside of a form node the key can't be checked, so the preset is applied as long as
13
+ * the model value is `undefined`.
14
+ */
15
+ export declare function usePresetValue<T>(modelValue: Ref<T | null | undefined>, preset: MaybeRefOrGetter<T | null | undefined>): void;
@@ -0,0 +1,7 @@
1
+ import { MaybeRefOrGetter, Ref } from 'vue';
2
+ import { FormComponents, InternalSchemaNode } from '../types';
3
+ export type PropsValidity = Record<string, boolean | string>;
4
+ export default function useSchema(schema: Ref<InternalSchemaNode[]>, components: MaybeRefOrGetter<FormComponents>): {
5
+ isValid: import('vue').ComputedRef<boolean>;
6
+ propsValidity: import('vue').ComputedRef<PropsValidity>;
7
+ };
@@ -0,0 +1,5 @@
1
+ export declare const isTouchDragging: import('vue').Ref<boolean, boolean>;
2
+ export declare function useTouchDrag(dragThreshold?: number): {
3
+ enable: () => void;
4
+ disable: () => void;
5
+ };