@formisch/qwik 0.1.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.
Files changed (65) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +69 -0
  3. package/lib/components/Field/Field.qwik.cjs +14 -0
  4. package/lib/components/Field/Field.qwik.mjs +14 -0
  5. package/lib/components/FieldArray/FieldArray.qwik.cjs +14 -0
  6. package/lib/components/FieldArray/FieldArray.qwik.mjs +14 -0
  7. package/lib/components/Form/Form.qwik.cjs +36 -0
  8. package/lib/components/Form/Form.qwik.mjs +36 -0
  9. package/lib/hooks/useField/useField.qwik.cjs +48 -0
  10. package/lib/hooks/useField/useField.qwik.mjs +48 -0
  11. package/lib/hooks/useFieldArray/useFieldArray.qwik.cjs +18 -0
  12. package/lib/hooks/useFieldArray/useFieldArray.qwik.mjs +18 -0
  13. package/lib/hooks/useForm_/useForm_.qwik.cjs +52 -0
  14. package/lib/hooks/useForm_/useForm_.qwik.mjs +35 -0
  15. package/lib/hooks/usePathSignal/usePathSignal.qwik.cjs +18 -0
  16. package/lib/hooks/usePathSignal/usePathSignal.qwik.mjs +18 -0
  17. package/lib/hooks/useResolvedQrl/useResolvedQrl.qwik.cjs +14 -0
  18. package/lib/hooks/useResolvedQrl/useResolvedQrl.qwik.mjs +14 -0
  19. package/lib/index.qwik.cjs +30 -0
  20. package/lib/index.qwik.mjs +30 -0
  21. package/lib/packages/core/dist/index.qwik.qwik.cjs +401 -0
  22. package/lib/packages/core/dist/index.qwik.qwik.mjs +379 -0
  23. package/lib/packages/methods/dist/index.qwik.qwik.cjs +178 -0
  24. package/lib/packages/methods/dist/index.qwik.qwik.mjs +178 -0
  25. package/lib-types/components/Field/Field.d.ts +16 -0
  26. package/lib-types/components/Field/index.d.ts +1 -0
  27. package/lib-types/components/FieldArray/FieldArray.d.ts +16 -0
  28. package/lib-types/components/FieldArray/index.d.ts +1 -0
  29. package/lib-types/components/Form/Form.d.ts +8 -0
  30. package/lib-types/components/Form/index.d.ts +1 -0
  31. package/lib-types/components/Lifecycle/Lifecycle.d.ts +6 -0
  32. package/lib-types/components/Lifecycle/index.d.ts +1 -0
  33. package/lib-types/components/counter/counter.d.ts +1 -0
  34. package/lib-types/components/index.d.ts +3 -0
  35. package/lib-types/components/logo/logo.d.ts +1 -0
  36. package/lib-types/entry.dev.d.ts +2 -0
  37. package/lib-types/entry.ssr.d.ts +14 -0
  38. package/lib-types/hooks/index.d.ts +3 -0
  39. package/lib-types/hooks/useField/index.d.ts +1 -0
  40. package/lib-types/hooks/useField/useField.d.ts +7 -0
  41. package/lib-types/hooks/useField/useField_2.d.ts +7 -0
  42. package/lib-types/hooks/useFieldArray/index.d.ts +1 -0
  43. package/lib-types/hooks/useFieldArray/useFieldArray.d.ts +7 -0
  44. package/lib-types/hooks/useForm/index.d.ts +1 -0
  45. package/lib-types/hooks/useForm/useForm copy.d.ts +9 -0
  46. package/lib-types/hooks/useForm/useForm.d.ts +5 -0
  47. package/lib-types/hooks/useForm$/index.d.ts +1 -0
  48. package/lib-types/hooks/useForm$/useForm$.d.ts +5 -0
  49. package/lib-types/hooks/useFormStore/index.d.ts +1 -0
  50. package/lib-types/hooks/useFormStore/useFormStore.d.ts +5 -0
  51. package/lib-types/hooks/useLiveSignal copy/index.d.ts +1 -0
  52. package/lib-types/hooks/useLiveSignal copy/useLiveSignal.d.ts +2 -0
  53. package/lib-types/hooks/usePathSignal/index.d.ts +1 -0
  54. package/lib-types/hooks/usePathSignal/usePathSignal.d.ts +3 -0
  55. package/lib-types/hooks/useResolvedQrl/index.d.ts +1 -0
  56. package/lib-types/hooks/useResolvedQrl/useResolvedQrl.d.ts +2 -0
  57. package/lib-types/index.d.ts +4 -0
  58. package/lib-types/root.d.ts +2 -0
  59. package/lib-types/types/field.d.ts +38 -0
  60. package/lib-types/types/form.d.ts +11 -0
  61. package/lib-types/types/index.d.ts +2 -0
  62. package/lib-types/utils/createInternalSignal/createInternalSignal.d.ts +3 -0
  63. package/lib-types/utils/createInternalSignal/index.d.ts +1 -0
  64. package/lib-types/utils/index.d.ts +0 -0
  65. package/package.json +83 -0
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 ADDED
@@ -0,0 +1,69 @@
1
+ # Formisch for Qwik
2
+
3
+ Formisch is a schema-based, headless form library for Qwik. 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-qwik)!
4
+
5
+ ## Highlights
6
+
7
+ - Small bundle size starting at 2.5 kB
8
+ - Schema-based validation with Valibot
9
+ - Type safety with autocompletion in editor
10
+ - It's fast – DOM updates are fine-grained
11
+ - Minimal, readable and well thought out API
12
+ - Supports all native HTML form fields
13
+
14
+ ## Example
15
+
16
+ Every form starts with the `useForm$` hook. It initializes your form's store based on the provided Valibot schema and infers its types. Next, wrap your form in the `<Form />` component. It's a thin layer around the native `<form />` element that handles form validation and submission. Then, you can access the state of a field with the `useField` hook or the `<Field />` component to connect your inputs.
17
+
18
+ ```tsx
19
+ import { Field, Form, useForm$ } from '@formisch/qwik';
20
+ import { component$ } from '@qwik.dev/core';
21
+ import * as v from 'valibot';
22
+
23
+ const LoginSchema = v.object({
24
+ email: v.pipe(v.string(), v.email()),
25
+ password: v.pipe(v.string(), v.minLength(8)),
26
+ });
27
+
28
+ export default component$(() => {
29
+ const loginForm = useForm$({
30
+ schema: LoginSchema,
31
+ });
32
+
33
+ return (
34
+ <Form of={loginForm} onSubmit$={(output) => console.log(output)}>
35
+ <Field
36
+ of={loginForm}
37
+ path={['email']}
38
+ render$={(field) => (
39
+ <div>
40
+ <input {...field.props} value={field.input.value} type="email" />
41
+ {field.errors.value && <div>{field.errors.value[0]}</div>}
42
+ </div>
43
+ )}
44
+ />
45
+ <Field
46
+ of={loginForm}
47
+ path={['password']}
48
+ render$={(field) => (
49
+ <div>
50
+ <input {...field.props} value={field.input.value} type="password" />
51
+ {field.errors.value && <div>{field.errors.value[0]}</div>}
52
+ </div>
53
+ )}
54
+ />
55
+ <button type="submit">Login</button>
56
+ </Form>
57
+ );
58
+ });
59
+ ```
60
+
61
+ In addition, Formisch offers several functions (we call them "methods") that can be used to manipulate the form state. These include `reset`, `setInput`, and `setErrors`. These methods allow you to control the form programmatically.
62
+
63
+ ## Feedback
64
+
65
+ Find a bug or have an idea how to improve the library? Please fill out an [issue](https://github.com/fabian-hiller/formisch/issues/new). Together we can make forms even better!
66
+
67
+ ## License
68
+
69
+ This project is available free of charge and licensed under the [MIT license](https://github.com/fabian-hiller/formisch/blob/main/LICENSE.md).
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const core = require("@qwik.dev/core");
4
+ const useField = require("../../hooks/useField/useField.qwik.cjs");
5
+ require("../../hooks/useForm_/useForm_.qwik.cjs");
6
+ const useResolvedQrl = require("../../hooks/useResolvedQrl/useResolvedQrl.qwik.cjs");
7
+ const Field = core.component$(({ of, path, render$ }) => {
8
+ const field = useField.useField(of, {
9
+ path
10
+ });
11
+ const render = useResolvedQrl.useResolvedQrl(render$);
12
+ return render(field);
13
+ });
14
+ exports.Field = Field;
@@ -0,0 +1,14 @@
1
+ import { component$ } from "@qwik.dev/core";
2
+ import { useField } from "../../hooks/useField/useField.qwik.mjs";
3
+ import "../../hooks/useForm_/useForm_.qwik.mjs";
4
+ import { useResolvedQrl } from "../../hooks/useResolvedQrl/useResolvedQrl.qwik.mjs";
5
+ const Field = component$(({ of, path, render$ }) => {
6
+ const field = useField(of, {
7
+ path
8
+ });
9
+ const render = useResolvedQrl(render$);
10
+ return render(field);
11
+ });
12
+ export {
13
+ Field
14
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const core = require("@qwik.dev/core");
4
+ const useFieldArray = require("../../hooks/useFieldArray/useFieldArray.qwik.cjs");
5
+ require("../../hooks/useForm_/useForm_.qwik.cjs");
6
+ const useResolvedQrl = require("../../hooks/useResolvedQrl/useResolvedQrl.qwik.cjs");
7
+ const FieldArray = core.component$(({ of, path, render$ }) => {
8
+ const field = useFieldArray.useFieldArray(of, {
9
+ path
10
+ });
11
+ const render = useResolvedQrl.useResolvedQrl(render$);
12
+ return render(field);
13
+ });
14
+ exports.FieldArray = FieldArray;
@@ -0,0 +1,14 @@
1
+ import { component$ } from "@qwik.dev/core";
2
+ import { useFieldArray } from "../../hooks/useFieldArray/useFieldArray.qwik.mjs";
3
+ import "../../hooks/useForm_/useForm_.qwik.mjs";
4
+ import { useResolvedQrl } from "../../hooks/useResolvedQrl/useResolvedQrl.qwik.mjs";
5
+ const FieldArray = component$(({ of, path, render$ }) => {
6
+ const field = useFieldArray(of, {
7
+ path
8
+ });
9
+ const render = useResolvedQrl(render$);
10
+ return render(field);
11
+ });
12
+ export {
13
+ FieldArray
14
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("@qwik.dev/core/jsx-runtime");
4
+ const index_qwik = require("../../packages/core/dist/index.qwik.qwik.cjs");
5
+ const core = require("@qwik.dev/core");
6
+ const Form = core.component$(({ of, onSubmit$, ...other }) => {
7
+ return /* @__PURE__ */ jsxRuntime.jsx("form", {
8
+ ...other,
9
+ noValidate: true,
10
+ "preventdefault:submit": true,
11
+ ref: (element) => {
12
+ of[index_qwik.INTERNAL].element = element;
13
+ },
14
+ onSubmit$: async (event) => {
15
+ const internalFormStore = of[index_qwik.INTERNAL];
16
+ internalFormStore.isSubmitted.value = true;
17
+ internalFormStore.isSubmitting.value = true;
18
+ try {
19
+ const result = await index_qwik.validateFormInput(internalFormStore, {
20
+ shouldFocus: true
21
+ });
22
+ if (result.success) {
23
+ await onSubmit$(result.output, event);
24
+ }
25
+ } catch (error) {
26
+ internalFormStore.errors.value = [
27
+ error instanceof Error ? error.message : "An unknown error has occurred."
28
+ ];
29
+ } finally {
30
+ internalFormStore.isSubmitting.value = false;
31
+ }
32
+ },
33
+ children: /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {})
34
+ });
35
+ });
36
+ exports.Form = Form;
@@ -0,0 +1,36 @@
1
+ import { jsx } from "@qwik.dev/core/jsx-runtime";
2
+ import { INTERNAL, validateFormInput } from "../../packages/core/dist/index.qwik.qwik.mjs";
3
+ import { component$, Slot } from "@qwik.dev/core";
4
+ const Form = component$(({ of, onSubmit$, ...other }) => {
5
+ return /* @__PURE__ */ jsx("form", {
6
+ ...other,
7
+ noValidate: true,
8
+ "preventdefault:submit": true,
9
+ ref: (element) => {
10
+ of[INTERNAL].element = element;
11
+ },
12
+ onSubmit$: async (event) => {
13
+ const internalFormStore = of[INTERNAL];
14
+ internalFormStore.isSubmitted.value = true;
15
+ internalFormStore.isSubmitting.value = true;
16
+ try {
17
+ const result = await validateFormInput(internalFormStore, {
18
+ shouldFocus: true
19
+ });
20
+ if (result.success) {
21
+ await onSubmit$(result.output, event);
22
+ }
23
+ } catch (error) {
24
+ internalFormStore.errors.value = [
25
+ error instanceof Error ? error.message : "An unknown error has occurred."
26
+ ];
27
+ } finally {
28
+ internalFormStore.isSubmitting.value = false;
29
+ }
30
+ },
31
+ children: /* @__PURE__ */ jsx(Slot, {})
32
+ });
33
+ });
34
+ export {
35
+ Form
36
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index_qwik = require("../../packages/core/dist/index.qwik.qwik.cjs");
4
+ const core = require("@qwik.dev/core");
5
+ const usePathSignal = require("../usePathSignal/usePathSignal.qwik.cjs");
6
+ function useField(form, config) {
7
+ const pathSignal = usePathSignal.usePathSignal(config.path);
8
+ const internalFieldStore = core.useComputed$(() => index_qwik.getFieldStore(form[index_qwik.INTERNAL], pathSignal.value));
9
+ core.useTask$(({ track, cleanup }) => {
10
+ track(internalFieldStore);
11
+ cleanup(() => {
12
+ internalFieldStore.value.elements = internalFieldStore.value.elements.filter((element) => element.isConnected);
13
+ });
14
+ });
15
+ return core.useConstant(() => ({
16
+ path: pathSignal,
17
+ input: core.createComputed$(() => index_qwik.getFieldInput(internalFieldStore.value)),
18
+ errors: core.createComputed$(() => internalFieldStore.value.errors.value),
19
+ isTouched: core.createComputed$(() => index_qwik.getFieldBool(internalFieldStore.value, "isTouched")),
20
+ isDirty: core.createComputed$(() => index_qwik.getFieldBool(internalFieldStore.value, "isDirty")),
21
+ isValid: core.createComputed$(() => !index_qwik.getFieldBool(internalFieldStore.value, "errors")),
22
+ props: {
23
+ get name() {
24
+ return internalFieldStore.value.name;
25
+ },
26
+ autofocus: !!internalFieldStore.value.errors.value,
27
+ ref: core.$((element) => {
28
+ internalFieldStore.value.elements.push(element);
29
+ }),
30
+ onFocus$: core.$(() => {
31
+ index_qwik.setFieldBool(internalFieldStore.value, "isTouched", true);
32
+ index_qwik.validateIfRequired(form[index_qwik.INTERNAL], internalFieldStore.value, "touch");
33
+ }),
34
+ onInput$: core.$((_, element) => {
35
+ const nextValue = index_qwik.getElementInput(element, internalFieldStore.value);
36
+ index_qwik.setFieldInput(internalFieldStore.value, nextValue);
37
+ index_qwik.validateIfRequired(form[index_qwik.INTERNAL], internalFieldStore.value, "input");
38
+ }),
39
+ onChange$: core.$(() => {
40
+ index_qwik.validateIfRequired(form[index_qwik.INTERNAL], internalFieldStore.value, "change");
41
+ }),
42
+ onBlur$: core.$(() => {
43
+ index_qwik.validateIfRequired(form[index_qwik.INTERNAL], internalFieldStore.value, "blur");
44
+ })
45
+ }
46
+ }));
47
+ }
48
+ exports.useField = useField;
@@ -0,0 +1,48 @@
1
+ import { getFieldStore, INTERNAL, validateIfRequired, getElementInput, setFieldInput, setFieldBool, getFieldBool, getFieldInput } from "../../packages/core/dist/index.qwik.qwik.mjs";
2
+ import { useComputed$, useTask$, useConstant, $, createComputed$ } from "@qwik.dev/core";
3
+ import { usePathSignal } from "../usePathSignal/usePathSignal.qwik.mjs";
4
+ function useField(form, config) {
5
+ const pathSignal = usePathSignal(config.path);
6
+ const internalFieldStore = useComputed$(() => getFieldStore(form[INTERNAL], pathSignal.value));
7
+ useTask$(({ track, cleanup }) => {
8
+ track(internalFieldStore);
9
+ cleanup(() => {
10
+ internalFieldStore.value.elements = internalFieldStore.value.elements.filter((element) => element.isConnected);
11
+ });
12
+ });
13
+ return useConstant(() => ({
14
+ path: pathSignal,
15
+ input: createComputed$(() => getFieldInput(internalFieldStore.value)),
16
+ errors: createComputed$(() => internalFieldStore.value.errors.value),
17
+ isTouched: createComputed$(() => getFieldBool(internalFieldStore.value, "isTouched")),
18
+ isDirty: createComputed$(() => getFieldBool(internalFieldStore.value, "isDirty")),
19
+ isValid: createComputed$(() => !getFieldBool(internalFieldStore.value, "errors")),
20
+ props: {
21
+ get name() {
22
+ return internalFieldStore.value.name;
23
+ },
24
+ autofocus: !!internalFieldStore.value.errors.value,
25
+ ref: $((element) => {
26
+ internalFieldStore.value.elements.push(element);
27
+ }),
28
+ onFocus$: $(() => {
29
+ setFieldBool(internalFieldStore.value, "isTouched", true);
30
+ validateIfRequired(form[INTERNAL], internalFieldStore.value, "touch");
31
+ }),
32
+ onInput$: $((_, element) => {
33
+ const nextValue = getElementInput(element, internalFieldStore.value);
34
+ setFieldInput(internalFieldStore.value, nextValue);
35
+ validateIfRequired(form[INTERNAL], internalFieldStore.value, "input");
36
+ }),
37
+ onChange$: $(() => {
38
+ validateIfRequired(form[INTERNAL], internalFieldStore.value, "change");
39
+ }),
40
+ onBlur$: $(() => {
41
+ validateIfRequired(form[INTERNAL], internalFieldStore.value, "blur");
42
+ })
43
+ }
44
+ }));
45
+ }
46
+ export {
47
+ useField
48
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index_qwik = require("../../packages/core/dist/index.qwik.qwik.cjs");
4
+ const core = require("@qwik.dev/core");
5
+ const usePathSignal = require("../usePathSignal/usePathSignal.qwik.cjs");
6
+ function useFieldArray(form, config) {
7
+ const pathSignal = usePathSignal.usePathSignal(config.path);
8
+ const internalFieldStore = core.useComputed$(() => index_qwik.getFieldStore(form[index_qwik.INTERNAL], pathSignal.value));
9
+ return core.useConstant(() => ({
10
+ path: pathSignal,
11
+ items: core.createComputed$(() => internalFieldStore.value.items.value),
12
+ errors: core.createComputed$(() => internalFieldStore.value.errors.value),
13
+ isTouched: core.createComputed$(() => index_qwik.getFieldBool(internalFieldStore.value, "isTouched")),
14
+ isDirty: core.createComputed$(() => index_qwik.getFieldBool(internalFieldStore.value, "isDirty")),
15
+ isValid: core.createComputed$(() => !index_qwik.getFieldBool(internalFieldStore.value, "errors"))
16
+ }));
17
+ }
18
+ exports.useFieldArray = useFieldArray;
@@ -0,0 +1,18 @@
1
+ import { getFieldStore, INTERNAL, getFieldBool } from "../../packages/core/dist/index.qwik.qwik.mjs";
2
+ import { useComputed$, useConstant, createComputed$ } from "@qwik.dev/core";
3
+ import { usePathSignal } from "../usePathSignal/usePathSignal.qwik.mjs";
4
+ function useFieldArray(form, config) {
5
+ const pathSignal = usePathSignal(config.path);
6
+ const internalFieldStore = useComputed$(() => getFieldStore(form[INTERNAL], pathSignal.value));
7
+ return useConstant(() => ({
8
+ path: pathSignal,
9
+ items: createComputed$(() => internalFieldStore.value.items.value),
10
+ errors: createComputed$(() => internalFieldStore.value.errors.value),
11
+ isTouched: createComputed$(() => getFieldBool(internalFieldStore.value, "isTouched")),
12
+ isDirty: createComputed$(() => getFieldBool(internalFieldStore.value, "isDirty")),
13
+ isValid: createComputed$(() => !getFieldBool(internalFieldStore.value, "errors"))
14
+ }));
15
+ }
16
+ export {
17
+ useFieldArray
18
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index_qwik = require("../../packages/core/dist/index.qwik.qwik.cjs");
4
+ const core = require("@qwik.dev/core");
5
+ const v = require("valibot");
6
+ const useResolvedQrl = require("../useResolvedQrl/useResolvedQrl.qwik.cjs");
7
+ function _interopNamespaceDefault(e) {
8
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
9
+ if (e) {
10
+ for (const k in e) {
11
+ if (k !== "default") {
12
+ const d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: () => e[k]
16
+ });
17
+ }
18
+ }
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+ const v__namespace = /* @__PURE__ */ _interopNamespaceDefault(v);
24
+ function useFormQrl(configQrl) {
25
+ const config = useResolvedQrl.useResolvedQrl(configQrl);
26
+ const form = core.useConstant(() => {
27
+ const internalFormStore = index_qwik.createFormStore({
28
+ ...config,
29
+ schema: JSON.parse(JSON.stringify(config.schema))
30
+ }, core.$(async (input) => v__namespace.safeParseAsync((await configQrl.resolve()).schema, input)));
31
+ return {
32
+ [index_qwik.INTERNAL]: internalFormStore,
33
+ isSubmitting: internalFormStore.isSubmitting,
34
+ isSubmitted: internalFormStore.isSubmitted,
35
+ isValidating: internalFormStore.isValidating,
36
+ isTouched: core.createComputed$(() => index_qwik.getFieldBool(internalFormStore, "isTouched")),
37
+ isDirty: core.createComputed$(() => index_qwik.getFieldBool(internalFormStore, "isDirty")),
38
+ isValid: core.createComputed$(() => !index_qwik.getFieldBool(internalFormStore, "errors")),
39
+ errors: internalFormStore.errors
40
+ };
41
+ });
42
+ const validateOn = config.validateOn;
43
+ core.useTask$(async () => {
44
+ if (validateOn === "initial") {
45
+ await index_qwik.validateFormInput(form[index_qwik.INTERNAL]);
46
+ }
47
+ });
48
+ return form;
49
+ }
50
+ const useForm$ = core.implicit$FirstArg(useFormQrl);
51
+ exports.useForm$ = useForm$;
52
+ exports.useFormQrl = useFormQrl;
@@ -0,0 +1,35 @@
1
+ import { createFormStore, getFieldBool, INTERNAL, validateFormInput } from "../../packages/core/dist/index.qwik.qwik.mjs";
2
+ import { implicit$FirstArg, useConstant, $, createComputed$, useTask$ } from "@qwik.dev/core";
3
+ import * as v from "valibot";
4
+ import { useResolvedQrl } from "../useResolvedQrl/useResolvedQrl.qwik.mjs";
5
+ function useFormQrl(configQrl) {
6
+ const config = useResolvedQrl(configQrl);
7
+ const form = useConstant(() => {
8
+ const internalFormStore = createFormStore({
9
+ ...config,
10
+ schema: JSON.parse(JSON.stringify(config.schema))
11
+ }, $(async (input) => v.safeParseAsync((await configQrl.resolve()).schema, input)));
12
+ return {
13
+ [INTERNAL]: internalFormStore,
14
+ isSubmitting: internalFormStore.isSubmitting,
15
+ isSubmitted: internalFormStore.isSubmitted,
16
+ isValidating: internalFormStore.isValidating,
17
+ isTouched: createComputed$(() => getFieldBool(internalFormStore, "isTouched")),
18
+ isDirty: createComputed$(() => getFieldBool(internalFormStore, "isDirty")),
19
+ isValid: createComputed$(() => !getFieldBool(internalFormStore, "errors")),
20
+ errors: internalFormStore.errors
21
+ };
22
+ });
23
+ const validateOn = config.validateOn;
24
+ useTask$(async () => {
25
+ if (validateOn === "initial") {
26
+ await validateFormInput(form[INTERNAL]);
27
+ }
28
+ });
29
+ return form;
30
+ }
31
+ const useForm$ = implicit$FirstArg(useFormQrl);
32
+ export {
33
+ useForm$,
34
+ useFormQrl
35
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const core = require("@qwik.dev/core");
4
+ function isEqual(a, b) {
5
+ if (a.length !== b.length) return false;
6
+ for (let i = 0; i < a.length; i++) {
7
+ if (a[i] !== b[i]) return false;
8
+ }
9
+ return true;
10
+ }
11
+ function usePathSignal(path) {
12
+ const signal = core.useSignal(path);
13
+ if (!isEqual(signal.value, path)) {
14
+ signal.value = path;
15
+ }
16
+ return signal;
17
+ }
18
+ exports.usePathSignal = usePathSignal;
@@ -0,0 +1,18 @@
1
+ import { useSignal } from "@qwik.dev/core";
2
+ function isEqual(a, b) {
3
+ if (a.length !== b.length) return false;
4
+ for (let i = 0; i < a.length; i++) {
5
+ if (a[i] !== b[i]) return false;
6
+ }
7
+ return true;
8
+ }
9
+ function usePathSignal(path) {
10
+ const signal = useSignal(path);
11
+ if (!isEqual(signal.value, path)) {
12
+ signal.value = path;
13
+ }
14
+ return signal;
15
+ }
16
+ export {
17
+ usePathSignal
18
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const core = require("@qwik.dev/core");
4
+ function useResolvedQrl(qrl) {
5
+ const store = core.useSignal();
6
+ const resolved = qrl.resolved ?? store.value;
7
+ if (!resolved) {
8
+ throw qrl.resolve().then((resolved2) => {
9
+ store.value = resolved2;
10
+ });
11
+ }
12
+ return resolved;
13
+ }
14
+ exports.useResolvedQrl = useResolvedQrl;
@@ -0,0 +1,14 @@
1
+ import { useSignal } from "@qwik.dev/core";
2
+ function useResolvedQrl(qrl) {
3
+ const store = useSignal();
4
+ const resolved = qrl.resolved ?? store.value;
5
+ if (!resolved) {
6
+ throw qrl.resolve().then((resolved2) => {
7
+ store.value = resolved2;
8
+ });
9
+ }
10
+ return resolved;
11
+ }
12
+ export {
13
+ useResolvedQrl
14
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index_qwik = require("./packages/methods/dist/index.qwik.qwik.cjs");
4
+ const Field = require("./components/Field/Field.qwik.cjs");
5
+ const FieldArray = require("./components/FieldArray/FieldArray.qwik.cjs");
6
+ const Form = require("./components/Form/Form.qwik.cjs");
7
+ const useField = require("./hooks/useField/useField.qwik.cjs");
8
+ const useFieldArray = require("./hooks/useFieldArray/useFieldArray.qwik.cjs");
9
+ const useForm$ = require("./hooks/useForm_/useForm_.qwik.cjs");
10
+ exports.focus = index_qwik.focus;
11
+ exports.getAllErrors = index_qwik.getAllErrors;
12
+ exports.getErrors = index_qwik.getErrors;
13
+ exports.getInput = index_qwik.getInput;
14
+ exports.insert = index_qwik.insert;
15
+ exports.move = index_qwik.move;
16
+ exports.remove = index_qwik.remove;
17
+ exports.replace = index_qwik.replace;
18
+ exports.reset = index_qwik.reset;
19
+ exports.setErrors = index_qwik.setErrors;
20
+ exports.setInput = index_qwik.setInput;
21
+ exports.submit = index_qwik.submit;
22
+ exports.swap = index_qwik.swap;
23
+ exports.validate = index_qwik.validate;
24
+ exports.Field = Field.Field;
25
+ exports.FieldArray = FieldArray.FieldArray;
26
+ exports.Form = Form.Form;
27
+ exports.useField = useField.useField;
28
+ exports.useFieldArray = useFieldArray.useFieldArray;
29
+ exports.useForm$ = useForm$.useForm$;
30
+ exports.useFormQrl = useForm$.useFormQrl;
@@ -0,0 +1,30 @@
1
+ import { focus, getAllErrors, getErrors, getInput, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, validate } from "./packages/methods/dist/index.qwik.qwik.mjs";
2
+ import { Field } from "./components/Field/Field.qwik.mjs";
3
+ import { FieldArray } from "./components/FieldArray/FieldArray.qwik.mjs";
4
+ import { Form } from "./components/Form/Form.qwik.mjs";
5
+ import { useField } from "./hooks/useField/useField.qwik.mjs";
6
+ import { useFieldArray } from "./hooks/useFieldArray/useFieldArray.qwik.mjs";
7
+ import { useForm$, useFormQrl } from "./hooks/useForm_/useForm_.qwik.mjs";
8
+ export {
9
+ Field,
10
+ FieldArray,
11
+ Form,
12
+ focus,
13
+ getAllErrors,
14
+ getErrors,
15
+ getInput,
16
+ insert,
17
+ move,
18
+ remove,
19
+ replace,
20
+ reset,
21
+ setErrors,
22
+ setInput,
23
+ submit,
24
+ swap,
25
+ useField,
26
+ useFieldArray,
27
+ useForm$,
28
+ useFormQrl,
29
+ validate
30
+ };