@formisch/vue 0.2.0 → 0.2.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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Fabian Hiller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Formisch is a schema-based, headless form library for Vue. It manages form state and validation. It is type-safe, fast by default and its bundle size is small due to its modular design. Try it out in our [playground](https://stackblitz.com/edit/formisch-playground-vue)!
4
4
 
5
- Formisch is also available for [Preact][formisch-preact], [Qwik][formisch-qwik], and [SolidJS][formisch-solid]. Svelte will follow soon.
5
+ Formisch is also available for [Preact][formisch-preact], [Qwik][formisch-qwik], [SolidJS][formisch-solid] and [Svelte][formisch-svelte].
6
6
 
7
7
  ## Highlights
8
8
 
@@ -72,4 +72,4 @@ This project is available free of charge and licensed under the [MIT license](ht
72
72
  [formisch-preact]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/preact
73
73
  [formisch-qwik]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/qwik
74
74
  [formisch-solid]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/solid
75
- [formisch-vue]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/vue
75
+ [formisch-svelte]: https://github.com/fabian-hiller/formisch/tree/main/frameworks/svelte
package/dist/index.d.ts CHANGED
@@ -289,8 +289,8 @@ declare function validate<TSchema extends Schema>(form: BaseFormStore<TSchema>,
289
289
  //#endregion
290
290
  //#region src/types/field.d.ts
291
291
  /**
292
- * Value type of the field element props.
293
- */
292
+ * Value type of the field element props.
293
+ */
294
294
  interface FieldElementProps {
295
295
  readonly name: string;
296
296
  readonly autofocus: boolean;
@@ -300,8 +300,8 @@ interface FieldElementProps {
300
300
  readonly onBlur: (event: FocusEvent) => void;
301
301
  }
302
302
  /**
303
- * Value type of the field store.
304
- */
303
+ * Value type of the field store.
304
+ */
305
305
  interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends RequiredPath = RequiredPath> {
306
306
  readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
307
307
  get input(): PartialValues<PathValue<v.InferInput<TSchema>, TFieldPath>>;
@@ -313,8 +313,8 @@ interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends Require
313
313
  readonly props: FieldElementProps;
314
314
  }
315
315
  /**
316
- * Value type of the field array store.
317
- */
316
+ * Value type of the field array store.
317
+ */
318
318
  interface FieldArrayStore<TSchema extends Schema = Schema, TFieldArrayPath extends RequiredPath = RequiredPath> {
319
319
  readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
320
320
  readonly items: string[];
@@ -344,7 +344,7 @@ interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends Require
344
344
  readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
345
345
  }
346
346
  declare const _default: <TSchema extends Schema, TFieldPath extends RequiredPath>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal$2<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
347
- props: __VLS_PrettifyLocal$2<Pick<Partial<{}> & Omit<{} & vue5.VNodeProps & vue5.AllowedComponentProps & vue5.ComponentCustomProps, never>, never> & FieldProps<TSchema, TFieldPath> & Partial<{}>> & vue5.PublicProps;
347
+ props: __VLS_PrettifyLocal$2<Pick<Partial<{}> & Omit<{} & vue5.VNodeProps & vue5.AllowedComponentProps & vue5.ComponentCustomProps, never>, never> & FieldProps<TSchema, TFieldPath> & {}> & vue5.PublicProps;
348
348
  expose(exposed: vue5.ShallowUnwrapRef<{}>): void;
349
349
  attrs: any;
350
350
  slots: {
@@ -365,7 +365,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
365
365
  readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
366
366
  }
367
367
  declare const _default$1: <TSchema extends Schema, TFieldArrayPath extends RequiredPath>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal$1<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
368
- props: __VLS_PrettifyLocal$1<Pick<Partial<{}> & Omit<{} & vue5.VNodeProps & vue5.AllowedComponentProps & vue5.ComponentCustomProps, never>, never> & FieldArrayProps<TSchema, TFieldArrayPath> & Partial<{}>> & vue5.PublicProps;
368
+ props: __VLS_PrettifyLocal$1<Pick<Partial<{}> & Omit<{} & vue5.VNodeProps & vue5.AllowedComponentProps & vue5.ComponentCustomProps, never>, never> & FieldArrayProps<TSchema, TFieldArrayPath> & {}> & vue5.PublicProps;
369
369
  expose(exposed: vue5.ShallowUnwrapRef<{}>): void;
370
370
  attrs: any;
371
371
  slots: {
@@ -378,12 +378,12 @@ declare const _default$1: <TSchema extends Schema, TFieldArrayPath extends Requi
378
378
  type __VLS_PrettifyLocal$1<T> = { [K in keyof T as K]: T[K] } & {};
379
379
  //#endregion
380
380
  //#region src/components/Form/Form.vue.d.ts
381
- type FormProps<TSchema extends Schema = Schema> = {
381
+ interface FormProps<TSchema extends Schema = Schema> {
382
382
  of: FormStore<TSchema>;
383
383
  onSubmit: SubmitHandler<TSchema>;
384
- };
384
+ }
385
385
  declare const _default$2: <TSchema extends Schema = Schema>(__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<{
386
- props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & vue5.VNodeProps & vue5.AllowedComponentProps & vue5.ComponentCustomProps, never>, never> & FormProps<TSchema> & Partial<{}>> & vue5.PublicProps;
386
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & vue5.VNodeProps & vue5.AllowedComponentProps & vue5.ComponentCustomProps, never>, never> & FormProps<TSchema> & {}> & vue5.PublicProps;
387
387
  expose(exposed: vue5.ShallowUnwrapRef<{}>): void;
388
388
  attrs: any;
389
389
  slots: {
package/dist/index.js CHANGED
@@ -41,7 +41,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
41
41
  } else for (let index = 0; index < schema.items; index++) {
42
42
  internalFieldStore.children[index] = {};
43
43
  path.push(index);
44
- initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput && initialInput[index], path);
44
+ initializeFieldStore(internalFieldStore.children[index], schema.items[index], initialInput?.[index], path);
45
45
  path.pop();
46
46
  }
47
47
  const initialItems = internalFieldStore.children.map(createId);
@@ -59,7 +59,7 @@ function initializeFieldStore(internalFieldStore, schema, initialInput, path) {
59
59
  for (const key in schema.entries) {
60
60
  internalFieldStore.children[key] = {};
61
61
  path.push(key);
62
- initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput && initialInput[key], path);
62
+ initializeFieldStore(internalFieldStore.children[key], schema.entries[key], initialInput?.[key], path);
63
63
  path.pop();
64
64
  }
65
65
  }
@@ -253,23 +253,24 @@ function setFieldBool(internalFieldStore, type, bool) {
253
253
  function setFieldInput(internalFieldStore, input) {
254
254
  batch(() => {
255
255
  if (internalFieldStore.kind === "array") {
256
+ const arrayInput = input ?? [];
256
257
  const items = untrack(() => internalFieldStore.items.value);
257
- if (input.length < items.length) internalFieldStore.items.value = items.slice(0, input.length);
258
- else if (input.length > items.length) {
259
- if (input.length > internalFieldStore.children.length) {
258
+ if (arrayInput.length < items.length) internalFieldStore.items.value = items.slice(0, arrayInput.length);
259
+ else if (arrayInput.length > items.length) {
260
+ if (arrayInput.length > internalFieldStore.children.length) {
260
261
  const path = JSON.parse(internalFieldStore.name);
261
- for (let index = internalFieldStore.children.length; index < input.length; index++) {
262
+ for (let index = internalFieldStore.children.length; index < arrayInput.length; index++) {
262
263
  internalFieldStore.children[index] = {};
263
264
  path.push(index);
264
- initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, input[index], path);
265
+ initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, arrayInput[index], path);
265
266
  path.pop();
266
267
  }
267
268
  }
268
- internalFieldStore.items.value = [...items, ...input.slice(items.length).map(createId)];
269
+ internalFieldStore.items.value = [...items, ...arrayInput.slice(items.length).map(createId)];
269
270
  }
270
- for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], input[index]);
271
+ for (let index = 0; index < items.length; index++) setFieldInput(internalFieldStore.children[index], arrayInput[index]);
271
272
  internalFieldStore.isDirty.value = untrack(() => internalFieldStore.startItems.value).length !== items.length;
272
- } else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input[key]);
273
+ } else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setFieldInput(internalFieldStore.children[key], input?.[key]);
273
274
  else {
274
275
  internalFieldStore.input.value = input;
275
276
  internalFieldStore.isTouched.value = true;
@@ -281,17 +282,18 @@ function setFieldInput(internalFieldStore, input) {
281
282
  function setInitialFieldInput(internalFieldStore, initialInput) {
282
283
  batch(() => {
283
284
  if (internalFieldStore.kind === "array") {
284
- if (initialInput.length > internalFieldStore.children.length) {
285
+ const initialArrayInput = initialInput ?? [];
286
+ if (initialArrayInput.length > internalFieldStore.children.length) {
285
287
  const path = JSON.parse(internalFieldStore.name);
286
- for (let index = internalFieldStore.children.length; index < initialInput.length; index++) {
288
+ for (let index = internalFieldStore.children.length; index < initialArrayInput.length; index++) {
287
289
  internalFieldStore.children[index] = {};
288
290
  path.push(index);
289
- initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialInput[index], path);
291
+ initializeFieldStore(internalFieldStore.children[index], internalFieldStore.schema.item, initialArrayInput[index], path);
290
292
  path.pop();
291
293
  }
292
294
  }
293
- internalFieldStore.initialItems.value = initialInput.map(createId);
294
- for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialInput?.[index]);
295
+ internalFieldStore.initialItems.value = initialArrayInput.map(createId);
296
+ for (let index = 0; index < internalFieldStore.children.length; index++) setInitialFieldInput(internalFieldStore.children[index], initialArrayInput[index]);
295
297
  } else if (internalFieldStore.kind === "object") for (const key in internalFieldStore.children) setInitialFieldInput(internalFieldStore.children[key], initialInput?.[key]);
296
298
  else internalFieldStore.initialInput.value = initialInput;
297
299
  });
@@ -613,7 +615,7 @@ function useFieldArray(form, config) {
613
615
  //#endregion
614
616
  //#region src/composables/useForm/useForm.ts
615
617
  function useForm(config) {
616
- const internalFormStore = createFormStore(config, async (input) => v.safeParseAsync(config.schema, input));
618
+ const internalFormStore = createFormStore(config, (input) => v.safeParseAsync(config.schema, input));
617
619
  onBeforeMount(async () => {
618
620
  if (config.validate === "initial") await validateFormInput(internalFormStore);
619
621
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/vue",
3
3
  "description": "The modular and type-safe form library for Vue",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -32,17 +32,7 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "scripts": {
36
- "build": "tsdown",
37
- "lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
38
- "lint.fix": "eslint \"src/**/*.ts*\" --fix",
39
- "format": "prettier --write ./src",
40
- "format.check": "prettier --check ./src",
41
- "vite": "vite"
42
- },
43
35
  "devDependencies": {
44
- "@formisch/core": "workspace:*",
45
- "@formisch/methods": "workspace:*",
46
36
  "@types/node": "^24.1.0",
47
37
  "@vue/eslint-config-typescript": "^14.6.0",
48
38
  "eslint": "^9.32.0",
@@ -52,7 +42,9 @@
52
42
  "unplugin-vue": "^7.0.0",
53
43
  "valibot": "^1.1.0",
54
44
  "vue": "^3.5.18",
55
- "vue-tsc": "^3.0.4"
45
+ "vue-tsc": "^3.0.4",
46
+ "@formisch/core": "0.3.1",
47
+ "@formisch/methods": "0.2.0"
56
48
  },
57
49
  "peerDependencies": {
58
50
  "typescript": ">=5",
@@ -63,5 +55,13 @@
63
55
  "typescript": {
64
56
  "optional": true
65
57
  }
58
+ },
59
+ "scripts": {
60
+ "build": "tsdown",
61
+ "lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
62
+ "lint.fix": "eslint \"src/**/*.ts*\" --fix",
63
+ "format": "prettier --write ./src",
64
+ "format.check": "prettier --check ./src",
65
+ "vite": "vite"
66
66
  }
67
- }
67
+ }