@kozou/svelte-ui 1.15.1 → 1.17.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 +33 -0
- package/build/client/_app/immutable/assets/0.BFw6nhto.css +2 -0
- package/build/client/_app/immutable/assets/0.BFw6nhto.css.br +0 -0
- package/build/client/_app/immutable/assets/0.BFw6nhto.css.gz +0 -0
- package/build/client/_app/immutable/chunks/{B6V1pYSH.js → BWWvKZIn.js} +1 -1
- package/build/client/_app/immutable/chunks/BWWvKZIn.js.br +0 -0
- package/build/client/_app/immutable/chunks/BWWvKZIn.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Bjn-300u.js +3 -0
- package/build/client/_app/immutable/chunks/Bjn-300u.js.br +0 -0
- package/build/client/_app/immutable/chunks/Bjn-300u.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Bjy-W4x2.js +81 -0
- package/build/client/_app/immutable/chunks/Bjy-W4x2.js.br +0 -0
- package/build/client/_app/immutable/chunks/Bjy-W4x2.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{CWZB5aRo.js → CdzXNSLM.js} +1 -1
- package/build/client/_app/immutable/chunks/CdzXNSLM.js.br +0 -0
- package/build/client/_app/immutable/chunks/CdzXNSLM.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{C9uV8Vbp.js → OhDywA02.js} +1 -1
- package/build/client/_app/immutable/chunks/OhDywA02.js.br +0 -0
- package/build/client/_app/immutable/chunks/OhDywA02.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.DHQ72uwh.js → app.CXrj_tz3.js} +2 -2
- package/build/client/_app/immutable/entry/app.CXrj_tz3.js.br +0 -0
- package/build/client/_app/immutable/entry/app.CXrj_tz3.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.Itp5t-Yk.js +1 -0
- package/build/client/_app/immutable/entry/start.Itp5t-Yk.js.br +0 -0
- package/build/client/_app/immutable/entry/start.Itp5t-Yk.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.ifyNoaZz.js +1 -0
- package/build/client/_app/immutable/nodes/0.ifyNoaZz.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.ifyNoaZz.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.CRI7xzqE.js +1 -0
- package/build/client/_app/immutable/nodes/1.CRI7xzqE.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.CRI7xzqE.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.D_d90ZDd.js +2 -0
- package/build/client/_app/immutable/nodes/2.D_d90ZDd.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.D_d90ZDd.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{3.CFgjEkz5.js → 3.CyWCIPgV.js} +1 -1
- package/build/client/_app/immutable/nodes/3.CyWCIPgV.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.CyWCIPgV.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{4.CkPz2ou2.js → 4.D3j4ZWuz.js} +4 -5
- package/build/client/_app/immutable/nodes/4.D3j4ZWuz.js.br +0 -0
- package/build/client/_app/immutable/nodes/4.D3j4ZWuz.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{6.DG-7gHN5.js → 6.BDB6GDLX.js} +1 -1
- package/build/client/_app/immutable/nodes/6.BDB6GDLX.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.BDB6GDLX.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{7.CTFoDlKq.js → 7.x-apVi4n.js} +1 -1
- package/build/client/_app/immutable/nodes/7.x-apVi4n.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.x-apVi4n.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{8.DpgB7F8V.js → 8.DXu_2Qdx.js} +1 -1
- package/build/client/_app/immutable/nodes/8.DXu_2Qdx.js.br +0 -0
- package/build/client/_app/immutable/nodes/8.DXu_2Qdx.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/server/chunks/{0-woVFSmwh.js → 0-DTnqeCaT.js} +8 -5
- package/build/server/chunks/0-DTnqeCaT.js.map +1 -0
- package/build/server/chunks/{1-BeE95WNv.js → 1-CApJvP3C.js} +3 -3
- package/build/server/chunks/{1-BeE95WNv.js.map → 1-CApJvP3C.js.map} +1 -1
- package/build/server/chunks/{2-zIg9Y59a.js → 2-DGOJW-s_.js} +3 -3
- package/build/server/chunks/{2-zIg9Y59a.js.map → 2-DGOJW-s_.js.map} +1 -1
- package/build/server/chunks/{3-DNGoyL-W.js → 3-BFEYL0s0.js} +9 -9
- package/build/server/chunks/{3-DNGoyL-W.js.map → 3-BFEYL0s0.js.map} +1 -1
- package/build/server/chunks/4-BNWbTUVb.js +31 -0
- package/build/server/chunks/4-BNWbTUVb.js.map +1 -0
- package/build/server/chunks/{5-VZXG8pNB.js → 5-D-48ExuO.js} +2 -2
- package/build/server/chunks/{5-VZXG8pNB.js.map → 5-D-48ExuO.js.map} +1 -1
- package/build/server/chunks/{6-GLxgewYC.js → 6-BXAzsPrE.js} +3 -3
- package/build/server/chunks/{6-GLxgewYC.js.map → 6-BXAzsPrE.js.map} +1 -1
- package/build/server/chunks/{7-BLMy8BP-.js → 7-D4VY7Eta.js} +9 -9
- package/build/server/chunks/{7-BLMy8BP-.js.map → 7-D4VY7Eta.js.map} +1 -1
- package/build/server/chunks/{8-BpPpWG8g.js → 8-CAkMPSY4.js} +9 -9
- package/build/server/chunks/{8-BpPpWG8g.js.map → 8-CAkMPSY4.js.map} +1 -1
- package/build/server/chunks/{9-Dj6HXa42.js → 9-DRxhju5a.js} +2 -2
- package/build/server/chunks/{9-Dj6HXa42.js.map → 9-DRxhju5a.js.map} +1 -1
- package/build/server/chunks/{ListTable-wSR_j9wZ.js → ListTable-D8OnEdye.js} +2 -2
- package/build/server/chunks/ListTable-D8OnEdye.js.map +1 -0
- package/build/server/chunks/{_layout.svelte-BzBYfRFe.js → _layout.svelte-CouhggA0.js} +8 -3
- package/build/server/chunks/_layout.svelte-CouhggA0.js.map +1 -0
- package/build/server/chunks/{_page.svelte-O-L4fMK7.js → _page.svelte-5hyURw8O.js} +5 -5
- package/build/server/chunks/_page.svelte-5hyURw8O.js.map +1 -0
- package/build/server/chunks/{_page.svelte-D9z7ezJ4.js → _page.svelte-BHW_BBcE.js} +3 -3
- package/build/server/chunks/_page.svelte-BHW_BBcE.js.map +1 -0
- package/build/server/chunks/{_page.svelte-ChvgRQpR.js → _page.svelte-Bqk7F3CL.js} +9 -9
- package/build/server/chunks/_page.svelte-Bqk7F3CL.js.map +1 -0
- package/build/server/chunks/{_page.svelte-BC4aUN4q.js → _page.svelte-CBJR_AG2.js} +9 -9
- package/build/server/chunks/_page.svelte-CBJR_AG2.js.map +1 -0
- package/build/server/chunks/{_page.svelte-CwYTEs9l.js → _page.svelte-Cd_z7eFO.js} +5 -6
- package/build/server/chunks/_page.svelte-Cd_z7eFO.js.map +1 -0
- package/build/server/chunks/{_page.svelte-swWuZCGb.js → _page.svelte-D8nYMywt.js} +3 -3
- package/build/server/chunks/_page.svelte-D8nYMywt.js.map +1 -0
- package/build/server/chunks/{_page.svelte-DdqVHsEz.js → _page.svelte-D9WnRc7S.js} +8 -8
- package/build/server/chunks/_page.svelte-D9WnRc7S.js.map +1 -0
- package/build/server/chunks/{_page.svelte-BvzDTw9r.js → _page.svelte-DeVGBJ28.js} +9 -4
- package/build/server/chunks/_page.svelte-DeVGBJ28.js.map +1 -0
- package/build/server/chunks/{app-Do0K3Mhs.js → app-CYD2rz7t.js} +2 -2
- package/build/server/chunks/{app-Do0K3Mhs.js.map → app-CYD2rz7t.js.map} +1 -1
- package/build/server/chunks/{client-DQvKabLZ.js → client-BBFG1zLB.js} +5 -4
- package/build/server/chunks/client-BBFG1zLB.js.map +1 -0
- package/build/server/chunks/composite-form-KsMxMbgc.js +2964 -0
- package/build/server/chunks/composite-form-KsMxMbgc.js.map +1 -0
- package/build/server/chunks/{error.svelte-lMRXIb5g.js → error.svelte-C_s6PHRr.js} +8 -8
- package/build/server/chunks/error.svelte-C_s6PHRr.js.map +1 -0
- package/build/server/chunks/{hooks.server-DZdG1Yea.js → hooks.server-ud8twg77.js} +4 -4
- package/build/server/chunks/{hooks.server-DZdG1Yea.js.map → hooks.server-ud8twg77.js.map} +1 -1
- package/build/server/chunks/index-CVekYGHP.js.map +1 -1
- package/build/server/chunks/index-DBqjc0Yf.js.map +1 -1
- package/build/server/chunks/{internal-DXINBq6z.js → internal2-BaDAe3C9.js} +170 -187
- package/build/server/chunks/internal2-BaDAe3C9.js.map +1 -0
- package/build/server/chunks/mcp-connection-C9Efo8-2.js +73 -0
- package/build/server/chunks/mcp-connection-C9Efo8-2.js.map +1 -0
- package/build/server/chunks/{relation-select-composite-field-HGR09xAi.js → relation-select-composite-field-D0FbNYK6.js} +4 -4
- package/build/server/chunks/relation-select-composite-field-D0FbNYK6.js.map +1 -0
- package/build/server/chunks/{dev-aF1HGl8f.js → server-1sE9LKAu.js} +790 -790
- package/build/server/chunks/server-1sE9LKAu.js.map +1 -0
- package/build/server/chunks/{widget-registry-BCxIAl3a.js → widget-registry-D4uP1dwJ.js} +2 -2
- package/build/server/chunks/widget-registry-D4uP1dwJ.js.map +1 -0
- package/build/server/index.js +801 -725
- package/build/server/index.js.map +1 -1
- package/build/server/manifest.js +11 -11
- package/build/server/manifest.js.map +1 -1
- package/package.json +8 -8
- package/build/client/_app/immutable/assets/0.C7i1Dz29.css +0 -2
- package/build/client/_app/immutable/assets/0.C7i1Dz29.css.br +0 -0
- package/build/client/_app/immutable/assets/0.C7i1Dz29.css.gz +0 -0
- package/build/client/_app/immutable/chunks/B6V1pYSH.js.br +0 -0
- package/build/client/_app/immutable/chunks/B6V1pYSH.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C9uV8Vbp.js.br +0 -0
- package/build/client/_app/immutable/chunks/C9uV8Vbp.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CFtX8tSj.js +0 -4
- package/build/client/_app/immutable/chunks/CFtX8tSj.js.br +0 -0
- package/build/client/_app/immutable/chunks/CFtX8tSj.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CWZB5aRo.js.br +0 -0
- package/build/client/_app/immutable/chunks/CWZB5aRo.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.DHQ72uwh.js.br +0 -0
- package/build/client/_app/immutable/entry/app.DHQ72uwh.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.BdOXQ4uu.js +0 -1
- package/build/client/_app/immutable/entry/start.BdOXQ4uu.js.br +0 -0
- package/build/client/_app/immutable/entry/start.BdOXQ4uu.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.Bubr-rD_.js +0 -1
- package/build/client/_app/immutable/nodes/0.Bubr-rD_.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.Bubr-rD_.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.D-iY5UiQ.js +0 -1
- package/build/client/_app/immutable/nodes/1.D-iY5UiQ.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.D-iY5UiQ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.BEj9B8Ni.js +0 -2
- package/build/client/_app/immutable/nodes/2.BEj9B8Ni.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.BEj9B8Ni.js.gz +0 -0
- package/build/client/_app/immutable/nodes/3.CFgjEkz5.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.CFgjEkz5.js.gz +0 -0
- package/build/client/_app/immutable/nodes/4.CkPz2ou2.js.br +0 -0
- package/build/client/_app/immutable/nodes/4.CkPz2ou2.js.gz +0 -0
- package/build/client/_app/immutable/nodes/6.DG-7gHN5.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.DG-7gHN5.js.gz +0 -0
- package/build/client/_app/immutable/nodes/7.CTFoDlKq.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.CTFoDlKq.js.gz +0 -0
- package/build/client/_app/immutable/nodes/8.DpgB7F8V.js.br +0 -0
- package/build/client/_app/immutable/nodes/8.DpgB7F8V.js.gz +0 -0
- package/build/server/chunks/0-woVFSmwh.js.map +0 -1
- package/build/server/chunks/4-Zn1moNCA.js +0 -51
- package/build/server/chunks/4-Zn1moNCA.js.map +0 -1
- package/build/server/chunks/ListTable-wSR_j9wZ.js.map +0 -1
- package/build/server/chunks/_layout.svelte-BzBYfRFe.js.map +0 -1
- package/build/server/chunks/_page.svelte-BC4aUN4q.js.map +0 -1
- package/build/server/chunks/_page.svelte-BvzDTw9r.js.map +0 -1
- package/build/server/chunks/_page.svelte-ChvgRQpR.js.map +0 -1
- package/build/server/chunks/_page.svelte-CwYTEs9l.js.map +0 -1
- package/build/server/chunks/_page.svelte-D9z7ezJ4.js.map +0 -1
- package/build/server/chunks/_page.svelte-DdqVHsEz.js.map +0 -1
- package/build/server/chunks/_page.svelte-O-L4fMK7.js.map +0 -1
- package/build/server/chunks/_page.svelte-swWuZCGb.js.map +0 -1
- package/build/server/chunks/client-DQvKabLZ.js.map +0 -1
- package/build/server/chunks/composite-form-DNDE40T9.js +0 -7225
- package/build/server/chunks/composite-form-DNDE40T9.js.map +0 -1
- package/build/server/chunks/dev-aF1HGl8f.js.map +0 -1
- package/build/server/chunks/error.svelte-lMRXIb5g.js.map +0 -1
- package/build/server/chunks/internal-DXINBq6z.js.map +0 -1
- package/build/server/chunks/relation-select-composite-field-HGR09xAi.js.map +0 -1
- package/build/server/chunks/widget-registry-BCxIAl3a.js.map +0 -1
|
@@ -0,0 +1,2964 @@
|
|
|
1
|
+
import { u as noop, B as parse, y as onDestroy, N as tick, J as stringify$1, b as __toESM, _ as __commonJSMin } from './internal2-BaDAe3C9.js';
|
|
2
|
+
import { t as get, ad as writable, n as derived$1, Y as readonly, x as getContext } from './server-1sE9LKAu.js';
|
|
3
|
+
import { i as invalidateAll, b as applyAction, a as afterNavigate } from './client-BBFG1zLB.js';
|
|
4
|
+
import { a as app } from './app-CYD2rz7t.js';
|
|
5
|
+
import './index-CVekYGHP.js';
|
|
6
|
+
import { toJSONSchema, config, safeParseAsync } from 'zod/v4/core';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
|
|
9
|
+
//#region ../../node_modules/.pnpm/@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_svelte@5.55.9_@typescript-eslin_08bef01bde8c45f52f20ef8da13b7bd4/node_modules/@sveltejs/kit/src/runtime/app/forms.js
|
|
10
|
+
/**
|
|
11
|
+
* Use this function to deserialize the response from a form submission.
|
|
12
|
+
* Usage:
|
|
13
|
+
*
|
|
14
|
+
* ```js
|
|
15
|
+
* import { deserialize } from '$app/forms';
|
|
16
|
+
*
|
|
17
|
+
* async function handleSubmit(event) {
|
|
18
|
+
* const response = await fetch('/form?/action', {
|
|
19
|
+
* method: 'POST',
|
|
20
|
+
* body: new FormData(event.target)
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const result = deserialize(await response.text());
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
* @template {Record<string, unknown> | undefined} Success
|
|
28
|
+
* @template {Record<string, unknown> | undefined} Failure
|
|
29
|
+
* @param {string} result
|
|
30
|
+
* @returns {import('@sveltejs/kit').ActionResult<Success, Failure>}
|
|
31
|
+
*/
|
|
32
|
+
function deserialize(result) {
|
|
33
|
+
const parsed = JSON.parse(result);
|
|
34
|
+
if (parsed.data) parsed.data = parse(parsed.data, app.decoders);
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Shallow clone an element, so that we can access e.g. `form.action` without worrying
|
|
39
|
+
* that someone has added an `<input name="action">` (https://github.com/sveltejs/kit/issues/7593)
|
|
40
|
+
* @template {HTMLElement} T
|
|
41
|
+
* @param {T} element
|
|
42
|
+
* @returns {T}
|
|
43
|
+
*/
|
|
44
|
+
function clone$2(element) {
|
|
45
|
+
return HTMLElement.prototype.cloneNode.call(element);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* This action enhances a `<form>` element that otherwise would work without JavaScript.
|
|
49
|
+
*
|
|
50
|
+
* The `submit` function is called upon submission with the given FormData and the `action` that should be triggered.
|
|
51
|
+
* If `cancel` is called, the form will not be submitted.
|
|
52
|
+
* You can use the abort `controller` to cancel the submission in case another one starts.
|
|
53
|
+
* If a function is returned, that function is called with the response from the server.
|
|
54
|
+
* If nothing is returned, the fallback will be used.
|
|
55
|
+
*
|
|
56
|
+
* If this function or its return value isn't set, it
|
|
57
|
+
* - falls back to updating the `form` prop with the returned data if the action is on the same page as the form
|
|
58
|
+
* - updates `page.status`
|
|
59
|
+
* - resets the `<form>` element and invalidates all data in case of successful submission with no redirect response
|
|
60
|
+
* - redirects in case of a redirect response
|
|
61
|
+
* - redirects to the nearest error page in case of an unexpected error
|
|
62
|
+
*
|
|
63
|
+
* If you provide a custom function with a callback and want to use the default behavior, invoke `update` in your callback.
|
|
64
|
+
* It accepts an options object
|
|
65
|
+
* - `reset: false` if you don't want the `<form>` values to be reset after a successful submission
|
|
66
|
+
* - `invalidateAll: false` if you don't want the action to call `invalidateAll` after submission
|
|
67
|
+
* @template {Record<string, unknown> | undefined} Success
|
|
68
|
+
* @template {Record<string, unknown> | undefined} Failure
|
|
69
|
+
* @param {HTMLFormElement} form_element The form element
|
|
70
|
+
* @param {import('@sveltejs/kit').SubmitFunction<Success, Failure>} submit Submit callback
|
|
71
|
+
*/
|
|
72
|
+
function enhance(form_element, submit = noop) {
|
|
73
|
+
/**
|
|
74
|
+
* @param {{
|
|
75
|
+
* action: URL;
|
|
76
|
+
* invalidateAll?: boolean;
|
|
77
|
+
* result: import('@sveltejs/kit').ActionResult;
|
|
78
|
+
* reset?: boolean
|
|
79
|
+
* }} opts
|
|
80
|
+
*/
|
|
81
|
+
const fallback_callback = async ({ action, result, reset = true, invalidateAll: shouldInvalidateAll = true }) => {
|
|
82
|
+
if (result.type === "success") {
|
|
83
|
+
if (reset) HTMLFormElement.prototype.reset.call(form_element);
|
|
84
|
+
if (shouldInvalidateAll) await invalidateAll();
|
|
85
|
+
}
|
|
86
|
+
if (location.origin + location.pathname === action.origin + action.pathname || result.type === "redirect" || result.type === "error") await applyAction();
|
|
87
|
+
};
|
|
88
|
+
/** @param {SubmitEvent} event */
|
|
89
|
+
async function handle_submit(event) {
|
|
90
|
+
if ((event.submitter?.hasAttribute("formmethod") ? event.submitter.formMethod : clone$2(form_element).method) !== "post") return;
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
const action = new URL(event.submitter?.hasAttribute("formaction") ? event.submitter.formAction : clone$2(form_element).action);
|
|
93
|
+
const enctype = event.submitter?.hasAttribute("formenctype") ? event.submitter.formEnctype : clone$2(form_element).enctype;
|
|
94
|
+
const form_data = new FormData(form_element, event.submitter);
|
|
95
|
+
const controller = new AbortController();
|
|
96
|
+
let cancelled = false;
|
|
97
|
+
const cancel = () => cancelled = true;
|
|
98
|
+
const callback = await submit({
|
|
99
|
+
action,
|
|
100
|
+
cancel,
|
|
101
|
+
controller,
|
|
102
|
+
formData: form_data,
|
|
103
|
+
formElement: form_element,
|
|
104
|
+
submitter: event.submitter
|
|
105
|
+
}) ?? fallback_callback;
|
|
106
|
+
if (cancelled) return;
|
|
107
|
+
/** @type {import('@sveltejs/kit').ActionResult} */
|
|
108
|
+
let result;
|
|
109
|
+
try {
|
|
110
|
+
const headers = new Headers({
|
|
111
|
+
accept: "application/json",
|
|
112
|
+
"x-sveltekit-action": "true"
|
|
113
|
+
});
|
|
114
|
+
if (enctype !== "multipart/form-data") headers.set("Content-Type", /^(:?application\/x-www-form-urlencoded|text\/plain)$/.test(enctype) ? enctype : "application/x-www-form-urlencoded");
|
|
115
|
+
const body = enctype === "multipart/form-data" ? form_data : new URLSearchParams(form_data);
|
|
116
|
+
const response = await fetch(action, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers,
|
|
119
|
+
cache: "no-store",
|
|
120
|
+
body,
|
|
121
|
+
signal: controller.signal
|
|
122
|
+
});
|
|
123
|
+
result = deserialize(await response.text());
|
|
124
|
+
if (result.type === "error") result.status = response.status;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error?.name === "AbortError") return;
|
|
127
|
+
result = {
|
|
128
|
+
type: "error",
|
|
129
|
+
error
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
await callback({
|
|
133
|
+
action,
|
|
134
|
+
formData: form_data,
|
|
135
|
+
formElement: form_element,
|
|
136
|
+
update: (opts) => fallback_callback({
|
|
137
|
+
action,
|
|
138
|
+
result,
|
|
139
|
+
reset: opts?.reset,
|
|
140
|
+
invalidateAll: opts?.invalidateAll
|
|
141
|
+
}),
|
|
142
|
+
result
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
HTMLFormElement.prototype.addEventListener.call(form_element, "submit", handle_submit);
|
|
146
|
+
return { destroy() {
|
|
147
|
+
HTMLFormElement.prototype.removeEventListener.call(form_element, "submit", handle_submit);
|
|
148
|
+
} };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#region ../../node_modules/.pnpm/@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_svelte@5.55.9_@typescript-eslin_08bef01bde8c45f52f20ef8da13b7bd4/node_modules/@sveltejs/kit/src/runtime/app/stores.js
|
|
152
|
+
/**
|
|
153
|
+
* A function that returns all of the contextual stores. On the server, this must be called during component initialization.
|
|
154
|
+
* Only use this if you need to defer store subscription until after the component has mounted, for some reason.
|
|
155
|
+
*
|
|
156
|
+
* @deprecated Use `$app/state` instead (requires Svelte 5, [see docs for more info](https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated))
|
|
157
|
+
*/
|
|
158
|
+
var getStores = () => {
|
|
159
|
+
const stores$1 = getContext("__svelte__");
|
|
160
|
+
return {
|
|
161
|
+
/** @type {typeof page} */
|
|
162
|
+
page: { subscribe: stores$1.page.subscribe },
|
|
163
|
+
/** @type {typeof navigating} */
|
|
164
|
+
navigating: { subscribe: stores$1.navigating.subscribe },
|
|
165
|
+
/** @type {typeof updated} */
|
|
166
|
+
updated: stores$1.updated
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* A readable store whose value contains page data.
|
|
171
|
+
*
|
|
172
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
173
|
+
*
|
|
174
|
+
* @deprecated Use `page` from `$app/state` instead (requires Svelte 5, [see docs for more info](https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated))
|
|
175
|
+
* @type {import('svelte/store').Readable<import('@sveltejs/kit').Page>}
|
|
176
|
+
*/
|
|
177
|
+
var page = { subscribe(fn) {
|
|
178
|
+
return getStores().page.subscribe(fn);
|
|
179
|
+
} };
|
|
180
|
+
/**
|
|
181
|
+
* A readable store.
|
|
182
|
+
* When navigating starts, its value is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
|
|
183
|
+
* When navigating finishes, its value reverts to `null`.
|
|
184
|
+
*
|
|
185
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
186
|
+
*
|
|
187
|
+
* @deprecated Use `navigating` from `$app/state` instead (requires Svelte 5, [see docs for more info](https://svelte.dev/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated))
|
|
188
|
+
* @type {import('svelte/store').Readable<import('@sveltejs/kit').Navigation | null>}
|
|
189
|
+
*/
|
|
190
|
+
var navigating = { subscribe(fn) {
|
|
191
|
+
return getStores().navigating.subscribe(fn);
|
|
192
|
+
} };
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/traversal.js
|
|
195
|
+
function setPath(parent, key, value) {
|
|
196
|
+
if (key === "__proto__" || key === "prototype") throw new Error("Cannot set an object's `__proto__` or `prototype` property");
|
|
197
|
+
parent[key] = value;
|
|
198
|
+
return "skip";
|
|
199
|
+
}
|
|
200
|
+
function isInvalidPath(originalPath, pathData) {
|
|
201
|
+
return pathData.value !== void 0 && typeof pathData.value !== "object" && pathData.path.length < originalPath.length;
|
|
202
|
+
}
|
|
203
|
+
function pathExists(obj, path, options = {}) {
|
|
204
|
+
if (!options.modifier) options.modifier = (pathData) => isInvalidPath(path, pathData) ? void 0 : pathData.value;
|
|
205
|
+
const exists = traversePath(obj, path, options.modifier);
|
|
206
|
+
if (!exists) return void 0;
|
|
207
|
+
if (options.value === void 0) return exists;
|
|
208
|
+
return options.value(exists.value) ? exists : void 0;
|
|
209
|
+
}
|
|
210
|
+
function traversePath(obj, realPath, modifier) {
|
|
211
|
+
if (!realPath.length) return void 0;
|
|
212
|
+
if (realPath.includes("__proto__") || realPath.includes("prototype")) throw new Error("Cannot set an object's `__proto__` or `prototype` property");
|
|
213
|
+
const path = [realPath[0]];
|
|
214
|
+
let parent = obj;
|
|
215
|
+
while (parent && path.length < realPath.length) {
|
|
216
|
+
const key = path[path.length - 1];
|
|
217
|
+
const value = modifier ? modifier({
|
|
218
|
+
parent,
|
|
219
|
+
key: String(key),
|
|
220
|
+
value: parent[key],
|
|
221
|
+
path: path.map((p) => String(p)),
|
|
222
|
+
isLeaf: false,
|
|
223
|
+
set: (v) => setPath(parent, key, v)
|
|
224
|
+
}) : parent[key];
|
|
225
|
+
if (value === void 0) return void 0;
|
|
226
|
+
else parent = value;
|
|
227
|
+
path.push(realPath[path.length]);
|
|
228
|
+
}
|
|
229
|
+
if (!parent) return void 0;
|
|
230
|
+
const key = realPath[realPath.length - 1];
|
|
231
|
+
return {
|
|
232
|
+
parent,
|
|
233
|
+
key: String(key),
|
|
234
|
+
value: parent[key],
|
|
235
|
+
path: realPath.map((p) => String(p)),
|
|
236
|
+
isLeaf: true,
|
|
237
|
+
set: (v) => setPath(parent, key, v)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function traversePaths(parent, modifier, path = []) {
|
|
241
|
+
for (const key in parent) {
|
|
242
|
+
const value = parent[key];
|
|
243
|
+
const isLeaf = value === null || typeof value !== "object";
|
|
244
|
+
const pathData = {
|
|
245
|
+
parent,
|
|
246
|
+
key,
|
|
247
|
+
value,
|
|
248
|
+
path: path.concat([key]),
|
|
249
|
+
isLeaf,
|
|
250
|
+
set: (v) => setPath(parent, key, v)
|
|
251
|
+
};
|
|
252
|
+
const status = modifier(pathData);
|
|
253
|
+
if (status === "abort") return status;
|
|
254
|
+
else if (status === "skip") continue;
|
|
255
|
+
else if (!isLeaf) {
|
|
256
|
+
const status = traversePaths(value, modifier, pathData.path);
|
|
257
|
+
if (status === "abort") return status;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function eqSet(xs, ys) {
|
|
262
|
+
return xs === ys || xs.size === ys.size && [...xs].every((x) => ys.has(x));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Compare two objects and return the differences as paths.
|
|
266
|
+
*/
|
|
267
|
+
function comparePaths(newObj, oldObj) {
|
|
268
|
+
const diffPaths = /* @__PURE__ */ new Map();
|
|
269
|
+
function builtInDiff(one, other) {
|
|
270
|
+
if (one instanceof Date && other instanceof Date && one.getTime() !== other.getTime()) return true;
|
|
271
|
+
if (one instanceof Set && other instanceof Set && !eqSet(one, other)) return true;
|
|
272
|
+
if (one instanceof File && other instanceof File && one !== other) return true;
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
function isBuiltin(data) {
|
|
276
|
+
return data instanceof Date || data instanceof Set || data instanceof File;
|
|
277
|
+
}
|
|
278
|
+
function checkPath(data, compareTo) {
|
|
279
|
+
const otherData = compareTo ? traversePath(compareTo, data.path) : void 0;
|
|
280
|
+
function addDiff() {
|
|
281
|
+
diffPaths.set(data.path.join(" "), data.path);
|
|
282
|
+
return "skip";
|
|
283
|
+
}
|
|
284
|
+
if (isBuiltin(data.value)) {
|
|
285
|
+
if (!isBuiltin(otherData?.value) || builtInDiff(data.value, otherData.value)) return addDiff();
|
|
286
|
+
}
|
|
287
|
+
if (data.isLeaf) {
|
|
288
|
+
if (!otherData || data.value !== otherData.value) addDiff();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
traversePaths(newObj, (data) => checkPath(data, oldObj));
|
|
292
|
+
traversePaths(oldObj, (data) => checkPath(data, newObj));
|
|
293
|
+
const output = Array.from(diffPaths.values());
|
|
294
|
+
output.sort((a, b) => a.length - b.length);
|
|
295
|
+
return output;
|
|
296
|
+
}
|
|
297
|
+
function setPaths(obj, paths, value) {
|
|
298
|
+
const isFunction = typeof value === "function";
|
|
299
|
+
for (const path of paths) {
|
|
300
|
+
const leaf = traversePath(obj, path, ({ parent, key, value }) => {
|
|
301
|
+
if (value === void 0 || typeof value !== "object") parent[key] = {};
|
|
302
|
+
return parent[key];
|
|
303
|
+
});
|
|
304
|
+
if (leaf) {
|
|
305
|
+
if (leaf.key === "__proto__" || leaf.key === "prototype") throw new Error("Cannot set an object's `__proto__` or `prototype` property");
|
|
306
|
+
leaf.parent[leaf.key] = isFunction ? value(path, leaf) : value;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/stringPath.js
|
|
312
|
+
function splitPath(path) {
|
|
313
|
+
return path.toString().split(/[[\].]+/).filter((p) => p);
|
|
314
|
+
}
|
|
315
|
+
function mergePath(path) {
|
|
316
|
+
return path.reduce((acc, next) => {
|
|
317
|
+
const key = String(next);
|
|
318
|
+
if (typeof next === "number" || /^\d+$/.test(key)) acc += `[${key}]`;
|
|
319
|
+
else if (!acc) acc += key;
|
|
320
|
+
else acc += `.${key}`;
|
|
321
|
+
return acc;
|
|
322
|
+
}, "");
|
|
323
|
+
}
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/justClone.js
|
|
326
|
+
function clone$1(obj) {
|
|
327
|
+
const type = {}.toString.call(obj).slice(8, -1);
|
|
328
|
+
if (type == "Set") return new Set([...obj].map((value) => clone$1(value)));
|
|
329
|
+
if (type == "Map") return new Map([...obj].map((kv) => [clone$1(kv[0]), clone$1(kv[1])]));
|
|
330
|
+
if (type == "Date") return new Date(obj.getTime());
|
|
331
|
+
if (type == "RegExp") return RegExp(obj.source, obj.flags);
|
|
332
|
+
if (type == "Array" || type == "Object") {
|
|
333
|
+
const result = type == "Object" ? Object.create(Object.getPrototypeOf(obj)) : [];
|
|
334
|
+
for (const key in obj) result[key] = clone$1(obj[key]);
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
return obj;
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/utils.js
|
|
341
|
+
function clone(data) {
|
|
342
|
+
return data && typeof data === "object" ? clone$1(data) : data;
|
|
343
|
+
}
|
|
344
|
+
function assertSchema(schema, path) {
|
|
345
|
+
if (typeof schema === "boolean") throw new SchemaError("Schema property cannot be defined as boolean.", path);
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region ../../node_modules/.pnpm/ts-deepmerge@8.0.0/node_modules/ts-deepmerge/esm/index.js
|
|
349
|
+
// istanbul ignore next
|
|
350
|
+
var isObject = (obj) => {
|
|
351
|
+
if (typeof obj === "object" && obj !== null) {
|
|
352
|
+
if (typeof Object.getPrototypeOf === "function") {
|
|
353
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
354
|
+
return prototype === Object.prototype || prototype === null;
|
|
355
|
+
}
|
|
356
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
357
|
+
}
|
|
358
|
+
return false;
|
|
359
|
+
};
|
|
360
|
+
var UNSAFE_KEYS = new Set([
|
|
361
|
+
"__proto__",
|
|
362
|
+
"constructor",
|
|
363
|
+
"prototype",
|
|
364
|
+
"toString",
|
|
365
|
+
"valueOf",
|
|
366
|
+
"hasOwnProperty",
|
|
367
|
+
"isPrototypeOf",
|
|
368
|
+
"propertyIsEnumerable",
|
|
369
|
+
"toLocaleString"
|
|
370
|
+
]);
|
|
371
|
+
var merge$1 = (...objects) => objects.reduce((result, current) => {
|
|
372
|
+
if (current === void 0) return result;
|
|
373
|
+
if (Array.isArray(current)) throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");
|
|
374
|
+
Object.keys(current).forEach((key) => {
|
|
375
|
+
if (UNSAFE_KEYS.has(key)) return;
|
|
376
|
+
if (Array.isArray(result[key]) && Array.isArray(current[key])) result[key] = merge$1.options.mergeArrays ? merge$1.options.uniqueArrayItems ? Array.from(new Set(result[key].concat(current[key]))) : [...result[key], ...current[key]] : current[key];
|
|
377
|
+
else if (isObject(result[key]) && isObject(current[key])) result[key] = merge$1(result[key], current[key]);
|
|
378
|
+
else if (!isObject(result[key]) && isObject(current[key])) result[key] = merge$1(current[key], void 0);
|
|
379
|
+
else result[key] = current[key] === void 0 ? merge$1.options.allowUndefinedOverrides ? current[key] : result[key] : current[key];
|
|
380
|
+
});
|
|
381
|
+
return result;
|
|
382
|
+
}, {});
|
|
383
|
+
var defaultOptions = {
|
|
384
|
+
allowUndefinedOverrides: true,
|
|
385
|
+
mergeArrays: true,
|
|
386
|
+
uniqueArrayItems: true
|
|
387
|
+
};
|
|
388
|
+
merge$1.options = defaultOptions;
|
|
389
|
+
merge$1.withOptions = (options, ...objects) => {
|
|
390
|
+
merge$1.options = Object.assign(Object.assign({}, defaultOptions), options);
|
|
391
|
+
const result = merge$1(...objects);
|
|
392
|
+
merge$1.options = defaultOptions;
|
|
393
|
+
return result;
|
|
394
|
+
};
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/jsonSchema/schemaInfo.js
|
|
397
|
+
var conversionFormatTypes = [
|
|
398
|
+
"unix-time",
|
|
399
|
+
"bigint",
|
|
400
|
+
"any",
|
|
401
|
+
"symbol",
|
|
402
|
+
"set",
|
|
403
|
+
"map",
|
|
404
|
+
"int64",
|
|
405
|
+
"stringbool"
|
|
406
|
+
];
|
|
407
|
+
/**
|
|
408
|
+
* Normalizes the different kind of schema variations (anyOf, oneOf, union, const null, etc)
|
|
409
|
+
* to figure out the field type, optional, nullable, etc.
|
|
410
|
+
*/
|
|
411
|
+
function schemaInfo(schema, isOptional, path) {
|
|
412
|
+
assertSchema(schema, path);
|
|
413
|
+
const types = schemaTypes(schema, path);
|
|
414
|
+
const array = schema.items && types.includes("array") ? (Array.isArray(schema.items) ? schema.items : [schema.items]).filter((s) => typeof s !== "boolean") : void 0;
|
|
415
|
+
const additionalProperties = schema.additionalProperties && typeof schema.additionalProperties === "object" && types.includes("object") ? Object.fromEntries(Object.entries(schema.additionalProperties).filter(([, value]) => typeof value !== "boolean")) : void 0;
|
|
416
|
+
const properties = schema.properties && types.includes("object") ? Object.fromEntries(Object.entries(schema.properties).filter(([, value]) => typeof value !== "boolean")) : void 0;
|
|
417
|
+
const union = unionInfo(schema)?.filter((u) => u.type !== "null" && u.const !== null);
|
|
418
|
+
const result = {
|
|
419
|
+
types: types.filter((s) => s !== "null"),
|
|
420
|
+
isOptional,
|
|
421
|
+
isNullable: types.includes("null"),
|
|
422
|
+
schema,
|
|
423
|
+
union: union?.length ? union : void 0,
|
|
424
|
+
array,
|
|
425
|
+
properties,
|
|
426
|
+
additionalProperties,
|
|
427
|
+
required: schema.required
|
|
428
|
+
};
|
|
429
|
+
if (!schema.allOf || !schema.allOf.length) return result;
|
|
430
|
+
return {
|
|
431
|
+
...merge$1.withOptions({ allowUndefinedOverrides: false }, result, ...schema.allOf.map((s) => schemaInfo(s, false, []))),
|
|
432
|
+
schema
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function schemaTypes(schema, path) {
|
|
436
|
+
assertSchema(schema, path);
|
|
437
|
+
let types = schema.const === null ? ["null"] : [];
|
|
438
|
+
if (schema.type) types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
439
|
+
if (schema.anyOf) types = schema.anyOf.flatMap((s) => schemaTypes(s, path));
|
|
440
|
+
if (schema.oneOf) types = schema.oneOf.flatMap((s) => schemaTypes(s, path));
|
|
441
|
+
if (types.includes("array") && schema.uniqueItems) {
|
|
442
|
+
const i = types.findIndex((t) => t === "array");
|
|
443
|
+
if (i !== -1) types[i] = "set";
|
|
444
|
+
} else if (schema.format && conversionFormatTypes.includes(schema.format)) {
|
|
445
|
+
types.unshift(schema.format);
|
|
446
|
+
if (schema.format == "unix-time" || schema.format == "int64") {
|
|
447
|
+
const i = types.findIndex((t) => t == "integer");
|
|
448
|
+
types.splice(i, 1);
|
|
449
|
+
}
|
|
450
|
+
if (schema.format == "bigint") {
|
|
451
|
+
const i = types.findIndex((t) => t == "string");
|
|
452
|
+
types.splice(i, 1);
|
|
453
|
+
}
|
|
454
|
+
if (schema.format == "stringbool") {
|
|
455
|
+
const i = types.findIndex((t) => t == "string");
|
|
456
|
+
if (i !== -1) types.splice(i, 1);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (schema.const && schema.const !== null && typeof schema.const !== "function") types.push(typeof schema.const);
|
|
460
|
+
return Array.from(new Set(types));
|
|
461
|
+
}
|
|
462
|
+
function unionInfo(schema) {
|
|
463
|
+
if (!schema.oneOf && !schema.anyOf) return void 0;
|
|
464
|
+
if (schema.oneOf && schema.oneOf.length) return schema.oneOf.filter((s) => typeof s !== "boolean");
|
|
465
|
+
if (schema.anyOf && schema.anyOf.length) return schema.anyOf.filter((s) => typeof s !== "boolean");
|
|
466
|
+
}
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/jsonSchema/schemaDefaults.js
|
|
469
|
+
function defaultValues(schema, isOptional = false, path = []) {
|
|
470
|
+
return _defaultValues(schema, isOptional, path);
|
|
471
|
+
}
|
|
472
|
+
function _defaultValues(schema, isOptional, path) {
|
|
473
|
+
if (!schema) throw new SchemaError("Schema was undefined", path);
|
|
474
|
+
const info = schemaInfo(schema, isOptional, path);
|
|
475
|
+
if (!info) return void 0;
|
|
476
|
+
let objectDefaults = void 0;
|
|
477
|
+
if ("default" in schema) if (info.types.includes("object") && schema.default && typeof schema.default == "object" && !Array.isArray(schema.default)) objectDefaults = schema.default;
|
|
478
|
+
else {
|
|
479
|
+
if (info.types.length > 1) {
|
|
480
|
+
if (info.types.includes("unix-time") && (info.types.includes("integer") || info.types.includes("number"))) throw new SchemaError("Cannot resolve a default value with a union that includes a date and a number/integer.", path);
|
|
481
|
+
}
|
|
482
|
+
const [type] = info.types;
|
|
483
|
+
return formatDefaultValue(type, schema.default);
|
|
484
|
+
}
|
|
485
|
+
let _multiType;
|
|
486
|
+
const isMultiTypeUnion = () => {
|
|
487
|
+
if (!info.union || info.union.length < 2) return false;
|
|
488
|
+
if (info.union.some((i) => i.enum)) return true;
|
|
489
|
+
if (!_multiType) _multiType = new Set(info.types.map((i) => {
|
|
490
|
+
return ["integer", "unix-time"].includes(i) ? "number" : i;
|
|
491
|
+
}));
|
|
492
|
+
return _multiType.size > 1;
|
|
493
|
+
};
|
|
494
|
+
let output = void 0;
|
|
495
|
+
if (!objectDefaults && info.union) {
|
|
496
|
+
const singleDefault = info.union.filter((s) => typeof s !== "boolean" && s.default !== void 0);
|
|
497
|
+
if (singleDefault.length == 1) return _defaultValues(singleDefault[0], isOptional, path);
|
|
498
|
+
else if (singleDefault.length > 1) throw new SchemaError("Only one default value can exist in a union, or set a default value for the whole union.", path);
|
|
499
|
+
else {
|
|
500
|
+
if (info.isNullable) return null;
|
|
501
|
+
if (info.isOptional) return void 0;
|
|
502
|
+
if (isMultiTypeUnion()) throw new SchemaError("Multi-type unions must have a default value, or exactly one of the union types must have.", path);
|
|
503
|
+
if (info.union.length) if (info.types[0] == "object") {
|
|
504
|
+
if (output === void 0) output = {};
|
|
505
|
+
output = info.union.length > 1 ? merge$1.withOptions({ allowUndefinedOverrides: true }, ...info.union.map((s) => _defaultValues(s, isOptional, path))) : _defaultValues(info.union[0], isOptional, path);
|
|
506
|
+
} else return _defaultValues(info.union[0], isOptional, path);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (!objectDefaults) {
|
|
510
|
+
if (info.isNullable) return null;
|
|
511
|
+
if (info.isOptional) return void 0;
|
|
512
|
+
}
|
|
513
|
+
if (info.properties) for (const [key, objSchema] of Object.entries(info.properties)) {
|
|
514
|
+
assertSchema(objSchema, [...path, key]);
|
|
515
|
+
let def;
|
|
516
|
+
if (objectDefaults && objectDefaults[key] !== void 0) try {
|
|
517
|
+
const propInfo = schemaInfo(objSchema, !info.required?.includes(key), [...path, key]);
|
|
518
|
+
if (propInfo) {
|
|
519
|
+
const propType = propInfo.types[0];
|
|
520
|
+
if (propType === "object" && typeof objectDefaults[key] === "object" && objectDefaults[key] !== null && !Array.isArray(objectDefaults[key])) def = _defaultValues({
|
|
521
|
+
...objSchema,
|
|
522
|
+
default: objectDefaults[key]
|
|
523
|
+
}, !info.required?.includes(key), [...path, key]);
|
|
524
|
+
else def = formatDefaultValue(propType, objectDefaults[key]);
|
|
525
|
+
} else def = objectDefaults[key];
|
|
526
|
+
} catch {
|
|
527
|
+
def = objectDefaults[key];
|
|
528
|
+
}
|
|
529
|
+
else def = _defaultValues(objSchema, !info.required?.includes(key), [...path, key]);
|
|
530
|
+
if (output === void 0) output = {};
|
|
531
|
+
output[key] = def;
|
|
532
|
+
}
|
|
533
|
+
else if (objectDefaults) return objectDefaults;
|
|
534
|
+
if (schema.enum) return schema.enum[0];
|
|
535
|
+
if ("const" in schema) return schema.const;
|
|
536
|
+
if (isMultiTypeUnion()) throw new SchemaError("Default values cannot have more than one type.", path);
|
|
537
|
+
else if (info.types.length == 0) return;
|
|
538
|
+
const [formatType] = info.types;
|
|
539
|
+
return output ?? defaultValue(formatType, schema.enum);
|
|
540
|
+
}
|
|
541
|
+
function formatDefaultValue(type, value) {
|
|
542
|
+
switch (type) {
|
|
543
|
+
case "set": return Array.isArray(value) ? new Set(value) : value;
|
|
544
|
+
case "map": return Array.isArray(value) ? new Map(value) : value;
|
|
545
|
+
case "Date":
|
|
546
|
+
case "date":
|
|
547
|
+
case "unix-time":
|
|
548
|
+
if (typeof value === "string" || typeof value === "number") return new Date(value);
|
|
549
|
+
break;
|
|
550
|
+
case "bigint":
|
|
551
|
+
if (typeof value === "string" || typeof value === "number") return BigInt(value);
|
|
552
|
+
break;
|
|
553
|
+
case "symbol":
|
|
554
|
+
if (typeof value === "string" || typeof value === "number") return Symbol(value);
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
return value;
|
|
558
|
+
}
|
|
559
|
+
function defaultValue(type, enumType) {
|
|
560
|
+
switch (type) {
|
|
561
|
+
case "string": return enumType && enumType.length > 0 ? enumType[0] : "";
|
|
562
|
+
case "number":
|
|
563
|
+
case "integer": return enumType && enumType.length > 0 ? enumType[0] : 0;
|
|
564
|
+
case "boolean": return false;
|
|
565
|
+
case "array": return [];
|
|
566
|
+
case "object": return {};
|
|
567
|
+
case "null": return null;
|
|
568
|
+
case "Date":
|
|
569
|
+
case "date":
|
|
570
|
+
case "unix-time": return;
|
|
571
|
+
case "int64":
|
|
572
|
+
case "bigint": return BigInt(0);
|
|
573
|
+
case "stringbool": return "";
|
|
574
|
+
case "set": return /* @__PURE__ */ new Set();
|
|
575
|
+
case "map": return /* @__PURE__ */ new Map();
|
|
576
|
+
case "symbol": return Symbol();
|
|
577
|
+
case "undefined":
|
|
578
|
+
case "any": return;
|
|
579
|
+
default: throw new SchemaError("Schema type or format not supported, requires explicit default value: " + type);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function defaultTypes(schema, path = []) {
|
|
583
|
+
return _defaultTypes(schema, false, path);
|
|
584
|
+
}
|
|
585
|
+
function _defaultTypes(schema, isOptional, path) {
|
|
586
|
+
if (!schema) throw new SchemaError("Schema was undefined", path);
|
|
587
|
+
const info = schemaInfo(schema, isOptional, path);
|
|
588
|
+
let output = { __types: info.types };
|
|
589
|
+
if (info.union) output = merge$1(output, ...info.union.map((u) => _defaultTypes(u, info.isOptional, path)));
|
|
590
|
+
if (info.schema.items && typeof info.schema.items == "object" && !Array.isArray(info.schema.items)) output.__items = _defaultTypes(info.schema.items, info.isOptional, path);
|
|
591
|
+
if (info.properties) for (const [key, value] of Object.entries(info.properties)) {
|
|
592
|
+
assertSchema(value, [...path, key]);
|
|
593
|
+
output[key] = _defaultTypes(info.properties[key], !info.required?.includes(key), [...path, key]);
|
|
594
|
+
}
|
|
595
|
+
if (info.additionalProperties && info.types.includes("object")) {
|
|
596
|
+
const additionalInfo = schemaInfo(info.additionalProperties, info.isOptional, path);
|
|
597
|
+
if (additionalInfo.properties && additionalInfo.types.includes("object")) for (const [key] of Object.entries(additionalInfo.properties)) output[key] = _defaultTypes(additionalInfo.properties[key], !additionalInfo.required?.includes(key), [...path, key]);
|
|
598
|
+
}
|
|
599
|
+
if (info.isNullable && !output.__types.includes("null")) output.__types.push("null");
|
|
600
|
+
if (info.isOptional && !output.__types.includes("undefined")) output.__types.push("undefined");
|
|
601
|
+
return output;
|
|
602
|
+
}
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/errors.js
|
|
605
|
+
var SuperFormError = class SuperFormError extends Error {
|
|
606
|
+
constructor(message) {
|
|
607
|
+
super(message);
|
|
608
|
+
Object.setPrototypeOf(this, SuperFormError.prototype);
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var SchemaError = class SchemaError extends SuperFormError {
|
|
612
|
+
path;
|
|
613
|
+
constructor(message, path) {
|
|
614
|
+
super((path && path.length ? `[${Array.isArray(path) ? path.join(".") : path}] ` : "") + message);
|
|
615
|
+
this.path = Array.isArray(path) ? path.join(".") : path;
|
|
616
|
+
Object.setPrototypeOf(this, SchemaError.prototype);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
function mapErrors(errors, shape) {
|
|
620
|
+
const output = {};
|
|
621
|
+
function addFormLevelError(error) {
|
|
622
|
+
if (!("_errors" in output)) output._errors = [];
|
|
623
|
+
if (!Array.isArray(output._errors)) if (typeof output._errors === "string") output._errors = [output._errors];
|
|
624
|
+
else throw new SuperFormError("Form-level error was not an array.");
|
|
625
|
+
output._errors.push(error.message);
|
|
626
|
+
}
|
|
627
|
+
for (const error of errors) {
|
|
628
|
+
if (!error.path || error.path.length == 1 && !error.path[0]) {
|
|
629
|
+
addFormLevelError(error);
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
const objectError = !/^\d$/.test(String(error.path[error.path.length - 1])) && pathExists(shape, error.path.filter((p) => /\D/.test(String(p))))?.value;
|
|
633
|
+
const leaf = traversePath(output, error.path, ({ value, parent, key }) => {
|
|
634
|
+
if (value === void 0) parent[key] = {};
|
|
635
|
+
return parent[key];
|
|
636
|
+
});
|
|
637
|
+
if (!leaf) {
|
|
638
|
+
addFormLevelError(error);
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
const { parent, key } = leaf;
|
|
642
|
+
if (objectError) {
|
|
643
|
+
if (!(key in parent)) parent[key] = {};
|
|
644
|
+
if (!("_errors" in parent[key])) parent[key]._errors = [error.message];
|
|
645
|
+
else parent[key]._errors.push(error.message);
|
|
646
|
+
} else if (!(key in parent)) parent[key] = [error.message];
|
|
647
|
+
else parent[key].push(error.message);
|
|
648
|
+
}
|
|
649
|
+
return output;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Filter errors based on validation method.
|
|
653
|
+
* auto = Requires the existence of errors and tainted (field in store) to show
|
|
654
|
+
* oninput = Set directly
|
|
655
|
+
*/
|
|
656
|
+
function updateErrors(New, Previous, force) {
|
|
657
|
+
if (force) return New;
|
|
658
|
+
traversePaths(Previous, (errors) => {
|
|
659
|
+
if (!Array.isArray(errors.value)) return;
|
|
660
|
+
errors.set(void 0);
|
|
661
|
+
});
|
|
662
|
+
traversePaths(New, (error) => {
|
|
663
|
+
if (!Array.isArray(error.value) && error.value !== void 0) return;
|
|
664
|
+
setPaths(Previous, [error.path], error.value);
|
|
665
|
+
});
|
|
666
|
+
return Previous;
|
|
667
|
+
}
|
|
668
|
+
function flattenErrors(errors) {
|
|
669
|
+
return _flattenErrors(errors, []);
|
|
670
|
+
}
|
|
671
|
+
function _flattenErrors(errors, path) {
|
|
672
|
+
return Object.entries(errors).filter(([, value]) => value !== void 0).flatMap(([key, messages]) => {
|
|
673
|
+
if (Array.isArray(messages) && messages.length > 0) return {
|
|
674
|
+
path: mergePath(path.concat([key])),
|
|
675
|
+
messages
|
|
676
|
+
};
|
|
677
|
+
else return _flattenErrors(errors[key], path.concat([key]));
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Merge defaults with parsed data.
|
|
682
|
+
*/
|
|
683
|
+
function mergeDefaults(parsedData, defaults) {
|
|
684
|
+
if (!parsedData) return clone(defaults);
|
|
685
|
+
return merge$1.withOptions({ mergeArrays: false }, defaults, parsedData);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Merge defaults with (important!) *already validated and merged data*.
|
|
689
|
+
* @DCI-context
|
|
690
|
+
*/
|
|
691
|
+
function replaceInvalidDefaults(Data, Defaults, _schema, Errors, preprocessed) {
|
|
692
|
+
const defaultType = _schema.additionalProperties && typeof _schema.additionalProperties == "object" ? { __types: schemaInfo(_schema.additionalProperties, false, []).types } : void 0;
|
|
693
|
+
const Types = defaultTypes(_schema);
|
|
694
|
+
function Types_correctValue(dataValue, defValue, type) {
|
|
695
|
+
const types = type.__types;
|
|
696
|
+
if (!types.length || types.every((t) => t == "undefined" || t == "null" || t == "any")) return dataValue;
|
|
697
|
+
else if (types.length == 1 && types[0] == "array" && !type.__items) return dataValue;
|
|
698
|
+
const dateTypes = [
|
|
699
|
+
"unix-time",
|
|
700
|
+
"Date",
|
|
701
|
+
"date"
|
|
702
|
+
];
|
|
703
|
+
for (const schemaType of types) {
|
|
704
|
+
const defaultTypeValue = defaultValue(schemaType, void 0);
|
|
705
|
+
const sameType = typeof dataValue === typeof defaultTypeValue || dateTypes.includes(schemaType) && dataValue instanceof Date;
|
|
706
|
+
if (sameType && sameType && dataValue === null === (defaultTypeValue === null)) return dataValue;
|
|
707
|
+
else if (type.__items) return Types_correctValue(dataValue, defValue, type.__items);
|
|
708
|
+
}
|
|
709
|
+
if (defValue === void 0 && types.includes("null")) return null;
|
|
710
|
+
return defValue;
|
|
711
|
+
}
|
|
712
|
+
function Data_traverse() {
|
|
713
|
+
traversePaths(Defaults, Defaults_traverseAndReplace);
|
|
714
|
+
Errors_traverseAndReplace();
|
|
715
|
+
return Data;
|
|
716
|
+
}
|
|
717
|
+
function Data_setValue(currentPath, newValue) {
|
|
718
|
+
setPaths(Data, [currentPath], newValue);
|
|
719
|
+
}
|
|
720
|
+
function Errors_traverseAndReplace() {
|
|
721
|
+
for (const error of Errors) {
|
|
722
|
+
if (!error.path) continue;
|
|
723
|
+
Defaults_traverseAndReplace({
|
|
724
|
+
path: error.path,
|
|
725
|
+
value: pathExists(Defaults, error.path)?.value
|
|
726
|
+
}, true);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
function Defaults_traverseAndReplace(defaultPath, traversingErrors = false) {
|
|
730
|
+
const currentPath = defaultPath.path;
|
|
731
|
+
if (!currentPath || !currentPath[0]) return;
|
|
732
|
+
if (typeof currentPath[0] === "string" && preprocessed?.includes(currentPath[0])) return;
|
|
733
|
+
const dataPath = pathExists(Data, currentPath);
|
|
734
|
+
if (!dataPath && defaultPath.value !== void 0 || dataPath && dataPath.value === void 0) Data_setValue(currentPath, defaultPath.value);
|
|
735
|
+
else if (dataPath) {
|
|
736
|
+
const defValue = defaultPath.value;
|
|
737
|
+
const dataValue = dataPath.value;
|
|
738
|
+
if (defValue !== void 0 && typeof dataValue === typeof defValue && dataValue === null === (defValue === null)) return;
|
|
739
|
+
const pathTypes = traversePath(Types, currentPath.filter((p) => /\D/.test(String(p))), (path) => {
|
|
740
|
+
return path.value && "__items" in path.value ? path.value.__items : path.value;
|
|
741
|
+
});
|
|
742
|
+
if (!pathTypes) {
|
|
743
|
+
if (traversingErrors) return;
|
|
744
|
+
throw new SchemaError("No types found for defaults", currentPath);
|
|
745
|
+
}
|
|
746
|
+
const fieldType = pathTypes.value ?? defaultType;
|
|
747
|
+
if (fieldType) {
|
|
748
|
+
const corrected = Types_correctValue(dataValue, defValue, fieldType);
|
|
749
|
+
if (corrected === dataValue) return "skip";
|
|
750
|
+
Data_setValue(currentPath, corrected);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return Data_traverse();
|
|
755
|
+
}
|
|
756
|
+
//#endregion
|
|
757
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/client/flash.js
|
|
758
|
+
function cancelFlash(options) {
|
|
759
|
+
if (!options.flashMessage || true) return;
|
|
760
|
+
}
|
|
761
|
+
function shouldSyncFlash(options) {
|
|
762
|
+
if (!options.flashMessage || true) return false;
|
|
763
|
+
}
|
|
764
|
+
//#endregion
|
|
765
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/client/customValidity.js
|
|
766
|
+
var noCustomValidityDataAttribute = "noCustomValidity";
|
|
767
|
+
async function updateCustomValidity(validityEl, errors) {
|
|
768
|
+
if ("setCustomValidity" in validityEl) validityEl.setCustomValidity("");
|
|
769
|
+
if (noCustomValidityDataAttribute in validityEl.dataset) return;
|
|
770
|
+
setCustomValidity(validityEl, errors);
|
|
771
|
+
}
|
|
772
|
+
function setCustomValidityForm(formElement, errors) {
|
|
773
|
+
for (const el of formElement.querySelectorAll("input,select,textarea,button")) {
|
|
774
|
+
if ("dataset" in el && noCustomValidityDataAttribute in el.dataset || !el.name) continue;
|
|
775
|
+
const path = traversePath(errors, splitPath(el.name));
|
|
776
|
+
const error = path && typeof path.value === "object" && "_errors" in path.value ? path.value._errors : path?.value;
|
|
777
|
+
setCustomValidity(el, error);
|
|
778
|
+
if (error) return;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function setCustomValidity(el, errors) {
|
|
782
|
+
if (!("setCustomValidity" in el)) return;
|
|
783
|
+
const message = errors && errors.length ? errors.join("\n") : "";
|
|
784
|
+
el.setCustomValidity(message);
|
|
785
|
+
if (message) el.reportValidity();
|
|
786
|
+
}
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/client/elements.js
|
|
789
|
+
var isElementInViewport = (el, topOffset = 0) => {
|
|
790
|
+
const rect = el.getBoundingClientRect();
|
|
791
|
+
return rect.top >= topOffset && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
|
|
792
|
+
};
|
|
793
|
+
var scrollToAndCenter = (el, offset = 1.125, behavior = "smooth") => {
|
|
794
|
+
const top = el.getBoundingClientRect().top + window.pageYOffset - window.innerHeight / (2 * offset);
|
|
795
|
+
window.scrollTo({
|
|
796
|
+
left: 0,
|
|
797
|
+
top,
|
|
798
|
+
behavior
|
|
799
|
+
});
|
|
800
|
+
};
|
|
801
|
+
var immediateInputTypes = [
|
|
802
|
+
"checkbox",
|
|
803
|
+
"radio",
|
|
804
|
+
"range",
|
|
805
|
+
"file"
|
|
806
|
+
];
|
|
807
|
+
/**
|
|
808
|
+
* Information about a HTML element, for determining when to display errors.
|
|
809
|
+
*/
|
|
810
|
+
function inputInfo(el) {
|
|
811
|
+
return {
|
|
812
|
+
immediate: !!el && (el instanceof HTMLSelectElement || el instanceof HTMLInputElement && immediateInputTypes.includes(el.type)),
|
|
813
|
+
multiple: !!el && el instanceof HTMLSelectElement && el.multiple,
|
|
814
|
+
file: !!el && el instanceof HTMLInputElement && el.type == "file"
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
//#endregion
|
|
818
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/client/form.js
|
|
819
|
+
var FetchStatus;
|
|
820
|
+
(function(FetchStatus) {
|
|
821
|
+
FetchStatus[FetchStatus["Idle"] = 0] = "Idle";
|
|
822
|
+
FetchStatus[FetchStatus["Submitting"] = 1] = "Submitting";
|
|
823
|
+
FetchStatus[FetchStatus["Delayed"] = 2] = "Delayed";
|
|
824
|
+
FetchStatus[FetchStatus["Timeout"] = 3] = "Timeout";
|
|
825
|
+
})(FetchStatus || (FetchStatus = {}));
|
|
826
|
+
var activeTimers = /* @__PURE__ */ new Set();
|
|
827
|
+
/**
|
|
828
|
+
* @DCI-context
|
|
829
|
+
*/
|
|
830
|
+
function Form(formElement, timers, options) {
|
|
831
|
+
let state = FetchStatus.Idle;
|
|
832
|
+
let delayedTimeout, timeoutTimeout;
|
|
833
|
+
const Timers = activeTimers;
|
|
834
|
+
function Timers_start() {
|
|
835
|
+
Timers_clear();
|
|
836
|
+
Timers_setState(state != FetchStatus.Delayed ? FetchStatus.Submitting : FetchStatus.Delayed);
|
|
837
|
+
delayedTimeout = window.setTimeout(() => {
|
|
838
|
+
if (delayedTimeout && state == FetchStatus.Submitting) Timers_setState(FetchStatus.Delayed);
|
|
839
|
+
}, options.delayMs);
|
|
840
|
+
timeoutTimeout = window.setTimeout(() => {
|
|
841
|
+
if (timeoutTimeout && state == FetchStatus.Delayed) Timers_setState(FetchStatus.Timeout);
|
|
842
|
+
}, options.timeoutMs);
|
|
843
|
+
Timers.add(Timers_clear);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Clear timers and set state to Idle.
|
|
847
|
+
*/
|
|
848
|
+
function Timers_clear() {
|
|
849
|
+
clearTimeout(delayedTimeout);
|
|
850
|
+
clearTimeout(timeoutTimeout);
|
|
851
|
+
delayedTimeout = timeoutTimeout = 0;
|
|
852
|
+
Timers.delete(Timers_clear);
|
|
853
|
+
Timers_setState(FetchStatus.Idle);
|
|
854
|
+
}
|
|
855
|
+
function Timers_clearAll() {
|
|
856
|
+
Timers.forEach((t) => t());
|
|
857
|
+
Timers.clear();
|
|
858
|
+
}
|
|
859
|
+
function Timers_setState(s) {
|
|
860
|
+
state = s;
|
|
861
|
+
timers.submitting.set(state >= FetchStatus.Submitting);
|
|
862
|
+
timers.delayed.set(state >= FetchStatus.Delayed);
|
|
863
|
+
timers.timeout.set(state >= FetchStatus.Timeout);
|
|
864
|
+
}
|
|
865
|
+
const ErrorTextEvents = formElement;
|
|
866
|
+
function ErrorTextEvents__selectText(e) {
|
|
867
|
+
const target = e.target;
|
|
868
|
+
if (options.selectErrorText) target.select();
|
|
869
|
+
}
|
|
870
|
+
function ErrorTextEvents_addErrorTextListeners() {
|
|
871
|
+
if (!options.selectErrorText) return;
|
|
872
|
+
ErrorTextEvents.querySelectorAll("input").forEach((el) => {
|
|
873
|
+
el.addEventListener("invalid", ErrorTextEvents__selectText);
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
function ErrorTextEvents_removeErrorTextListeners() {
|
|
877
|
+
if (!options.selectErrorText) return;
|
|
878
|
+
ErrorTextEvents.querySelectorAll("input").forEach((el) => el.removeEventListener("invalid", ErrorTextEvents__selectText));
|
|
879
|
+
}
|
|
880
|
+
const Form = formElement;
|
|
881
|
+
{
|
|
882
|
+
ErrorTextEvents_addErrorTextListeners();
|
|
883
|
+
let processingEvents = false;
|
|
884
|
+
const completed = (opts) => {
|
|
885
|
+
if (!opts.clearAll) Timers_clear();
|
|
886
|
+
else Timers_clearAll();
|
|
887
|
+
if (!opts.cancelled) setTimeout(() => scrollToFirstError(Form, options), 1);
|
|
888
|
+
};
|
|
889
|
+
onDestroy(() => {
|
|
890
|
+
ErrorTextEvents_removeErrorTextListeners();
|
|
891
|
+
completed({ cancelled: true });
|
|
892
|
+
});
|
|
893
|
+
afterNavigate(() => {
|
|
894
|
+
ErrorTextEvents_removeErrorTextListeners();
|
|
895
|
+
if (!processingEvents) completed({ cancelled: false });
|
|
896
|
+
});
|
|
897
|
+
return {
|
|
898
|
+
submitting() {
|
|
899
|
+
Timers_start();
|
|
900
|
+
},
|
|
901
|
+
completed,
|
|
902
|
+
scrollToFirstError() {
|
|
903
|
+
setTimeout(() => scrollToFirstError(Form, options), 1);
|
|
904
|
+
},
|
|
905
|
+
isSubmitting: () => state === FetchStatus.Submitting || state === FetchStatus.Delayed,
|
|
906
|
+
setProcessingEvents(value) {
|
|
907
|
+
processingEvents = value;
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
var scrollToFirstError = async (Form, options) => {
|
|
913
|
+
if (options.scrollToError == "off") return;
|
|
914
|
+
const selector = options.errorSelector;
|
|
915
|
+
if (!selector) return;
|
|
916
|
+
await tick();
|
|
917
|
+
let el;
|
|
918
|
+
el = Form.querySelector(selector);
|
|
919
|
+
if (!el) return;
|
|
920
|
+
el = el.querySelector(selector) ?? el;
|
|
921
|
+
const nav = options.stickyNavbar ? document.querySelector(options.stickyNavbar) : null;
|
|
922
|
+
if (typeof options.scrollToError != "string") el.scrollIntoView(options.scrollToError);
|
|
923
|
+
else if (!isElementInViewport(el, nav?.offsetHeight ?? 0)) scrollToAndCenter(el, void 0, options.scrollToError);
|
|
924
|
+
function Form_shouldAutoFocus(userAgent) {
|
|
925
|
+
if (typeof options.autoFocusOnError === "boolean") return options.autoFocusOnError;
|
|
926
|
+
else return !/iPhone|iPad|iPod|Android/i.test(userAgent);
|
|
927
|
+
}
|
|
928
|
+
if (!Form_shouldAutoFocus(navigator.userAgent)) return;
|
|
929
|
+
let focusEl;
|
|
930
|
+
focusEl = el;
|
|
931
|
+
if (![
|
|
932
|
+
"INPUT",
|
|
933
|
+
"SELECT",
|
|
934
|
+
"BUTTON",
|
|
935
|
+
"TEXTAREA"
|
|
936
|
+
].includes(focusEl.tagName)) focusEl = focusEl.querySelector("input:not([type=\"hidden\"]):not(.flatpickr-input), select, textarea");
|
|
937
|
+
if (focusEl) try {
|
|
938
|
+
focusEl.focus({ preventScroll: true });
|
|
939
|
+
if (options.selectErrorText && focusEl.tagName == "INPUT") focusEl.select();
|
|
940
|
+
} catch {}
|
|
941
|
+
};
|
|
942
|
+
//#endregion
|
|
943
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/client/proxies.js
|
|
944
|
+
function updateProxyField(obj, path, updater) {
|
|
945
|
+
const output = traversePath(obj, path, ({ parent, key, value }) => {
|
|
946
|
+
if (value === void 0) parent[key] = /\D/.test(key) ? {} : [];
|
|
947
|
+
return parent[key];
|
|
948
|
+
});
|
|
949
|
+
if (output) {
|
|
950
|
+
const newValue = updater(output.value);
|
|
951
|
+
output.parent[output.key] = newValue;
|
|
952
|
+
}
|
|
953
|
+
return obj;
|
|
954
|
+
}
|
|
955
|
+
function superFieldProxy(superForm, path, baseOptions) {
|
|
956
|
+
const form = superForm.form;
|
|
957
|
+
const path2 = splitPath(path);
|
|
958
|
+
const proxy = derived$1(form, ($form) => {
|
|
959
|
+
return traversePath($form, path2)?.value;
|
|
960
|
+
});
|
|
961
|
+
return {
|
|
962
|
+
subscribe(...params) {
|
|
963
|
+
const unsub = proxy.subscribe(...params);
|
|
964
|
+
return () => unsub();
|
|
965
|
+
},
|
|
966
|
+
update(upd, options) {
|
|
967
|
+
form.update((data) => updateProxyField(data, path2, upd), options ?? baseOptions);
|
|
968
|
+
},
|
|
969
|
+
set(value, options) {
|
|
970
|
+
form.update((data) => updateProxyField(data, path2, () => value), options ?? baseOptions);
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
function isSuperForm(form, options) {
|
|
975
|
+
const isSuperForm = "form" in form;
|
|
976
|
+
if (!isSuperForm && options?.taint !== void 0) throw new SuperFormError("If options.taint is set, the whole superForm object must be used as a proxy.");
|
|
977
|
+
return isSuperForm;
|
|
978
|
+
}
|
|
979
|
+
function fieldProxy(form, path, options) {
|
|
980
|
+
const path2 = splitPath(path);
|
|
981
|
+
if (isSuperForm(form, options)) return superFieldProxy(form, path, options);
|
|
982
|
+
const proxy = derived$1(form, ($form) => {
|
|
983
|
+
return traversePath($form, path2)?.value;
|
|
984
|
+
});
|
|
985
|
+
return {
|
|
986
|
+
subscribe(...params) {
|
|
987
|
+
const unsub = proxy.subscribe(...params);
|
|
988
|
+
return () => unsub();
|
|
989
|
+
},
|
|
990
|
+
update(upd) {
|
|
991
|
+
form.update((data) => updateProxyField(data, path2, upd));
|
|
992
|
+
},
|
|
993
|
+
set(value) {
|
|
994
|
+
form.update((data) => updateProxyField(data, path2, () => value));
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/jsonSchema/schemaShape.js
|
|
1000
|
+
function schemaShape(schema, path = []) {
|
|
1001
|
+
const output = _schemaShape(schema, path);
|
|
1002
|
+
if (!output) throw new SchemaError("No shape could be created for schema. If using Zod v4, import { zod4 } from \"sveltekit-superforms/adapters\" instead of { zod }.", path);
|
|
1003
|
+
return output;
|
|
1004
|
+
}
|
|
1005
|
+
function _schemaShape(schema, path) {
|
|
1006
|
+
assertSchema(schema, path);
|
|
1007
|
+
const info = schemaInfo(schema, false, path);
|
|
1008
|
+
if (info.array || info.union) {
|
|
1009
|
+
const arr = info.array || [];
|
|
1010
|
+
const union = info.union || [];
|
|
1011
|
+
return arr.concat(union).reduce((shape, next) => {
|
|
1012
|
+
const nextShape = _schemaShape(next, path);
|
|
1013
|
+
if (nextShape) shape = {
|
|
1014
|
+
...shape ?? {},
|
|
1015
|
+
...nextShape
|
|
1016
|
+
};
|
|
1017
|
+
return shape;
|
|
1018
|
+
}, arr.length ? {} : void 0);
|
|
1019
|
+
}
|
|
1020
|
+
if (info.properties) {
|
|
1021
|
+
const output = {};
|
|
1022
|
+
for (const [key, prop] of Object.entries(info.properties)) {
|
|
1023
|
+
const shape = _schemaShape(prop, [...path, key]);
|
|
1024
|
+
if (shape) output[key] = shape;
|
|
1025
|
+
}
|
|
1026
|
+
return output;
|
|
1027
|
+
}
|
|
1028
|
+
return info.types.includes("array") || info.types.includes("object") ? {} : void 0;
|
|
1029
|
+
}
|
|
1030
|
+
function shapeFromObject(obj) {
|
|
1031
|
+
let output = {};
|
|
1032
|
+
const isArray = Array.isArray(obj);
|
|
1033
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1034
|
+
if (!value || typeof value !== "object") continue;
|
|
1035
|
+
if (isArray) output = {
|
|
1036
|
+
...output,
|
|
1037
|
+
...shapeFromObject(value)
|
|
1038
|
+
};
|
|
1039
|
+
else output[key] = shapeFromObject(value);
|
|
1040
|
+
}
|
|
1041
|
+
return output;
|
|
1042
|
+
}
|
|
1043
|
+
//#endregion
|
|
1044
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/client/superForm.js
|
|
1045
|
+
var formIds = /* @__PURE__ */ new WeakMap();
|
|
1046
|
+
var initialForms = /* @__PURE__ */ new WeakMap();
|
|
1047
|
+
var defaultOnError = (event) => {
|
|
1048
|
+
throw event.result.error;
|
|
1049
|
+
};
|
|
1050
|
+
var defaultFormOptions = {
|
|
1051
|
+
applyAction: true,
|
|
1052
|
+
invalidateAll: true,
|
|
1053
|
+
resetForm: true,
|
|
1054
|
+
autoFocusOnError: "detect",
|
|
1055
|
+
scrollToError: "smooth",
|
|
1056
|
+
errorSelector: "[aria-invalid=\"true\"],[data-invalid]",
|
|
1057
|
+
selectErrorText: false,
|
|
1058
|
+
stickyNavbar: void 0,
|
|
1059
|
+
taintedMessage: false,
|
|
1060
|
+
onSubmit: void 0,
|
|
1061
|
+
onResult: void 0,
|
|
1062
|
+
onUpdate: void 0,
|
|
1063
|
+
onUpdated: void 0,
|
|
1064
|
+
onError: defaultOnError,
|
|
1065
|
+
dataType: "form",
|
|
1066
|
+
validators: void 0,
|
|
1067
|
+
customValidity: false,
|
|
1068
|
+
clearOnSubmit: "message",
|
|
1069
|
+
delayMs: 500,
|
|
1070
|
+
timeoutMs: 8e3,
|
|
1071
|
+
multipleSubmits: "prevent",
|
|
1072
|
+
SPA: void 0,
|
|
1073
|
+
validationMethod: "auto"
|
|
1074
|
+
};
|
|
1075
|
+
/**
|
|
1076
|
+
* V1 compatibilty. resetForm = false and taintedMessage = true
|
|
1077
|
+
*/
|
|
1078
|
+
var LEGACY_MODE = false;
|
|
1079
|
+
try {
|
|
1080
|
+
if (SUPERFORMS_LEGACY) LEGACY_MODE = true;
|
|
1081
|
+
} catch {}
|
|
1082
|
+
/**
|
|
1083
|
+
* Storybook compatibility mode, basically disables the navigating store.
|
|
1084
|
+
*/
|
|
1085
|
+
var STORYBOOK_MODE = false;
|
|
1086
|
+
try {
|
|
1087
|
+
if (globalThis.STORIES) STORYBOOK_MODE = true;
|
|
1088
|
+
} catch {}
|
|
1089
|
+
/**
|
|
1090
|
+
* Initializes a SvelteKit form, for convenient handling of values, errors and sumbitting data.
|
|
1091
|
+
* @param {SuperValidated} form Usually data.form from PageData or defaults, but can also be an object with default values, but then constraints won't be available.
|
|
1092
|
+
* @param {FormOptions} formOptions Configuration for the form.
|
|
1093
|
+
* @returns {SuperForm} A SuperForm object that can be used in a Svelte component.
|
|
1094
|
+
* @DCI-context
|
|
1095
|
+
*/
|
|
1096
|
+
function superForm(form, formOptions) {
|
|
1097
|
+
let initialForm;
|
|
1098
|
+
let options = formOptions ?? {};
|
|
1099
|
+
let initialValidator = void 0;
|
|
1100
|
+
{
|
|
1101
|
+
if (options.legacy ?? LEGACY_MODE) {
|
|
1102
|
+
if (options.resetForm === void 0) options.resetForm = false;
|
|
1103
|
+
if (options.taintedMessage === void 0) options.taintedMessage = true;
|
|
1104
|
+
}
|
|
1105
|
+
if (STORYBOOK_MODE) {
|
|
1106
|
+
if (options.applyAction === void 0) options.applyAction = false;
|
|
1107
|
+
}
|
|
1108
|
+
if (typeof options.SPA === "string") {
|
|
1109
|
+
if (options.invalidateAll === void 0) options.invalidateAll = false;
|
|
1110
|
+
if (options.applyAction === void 0) options.applyAction = false;
|
|
1111
|
+
}
|
|
1112
|
+
initialValidator = options.validators;
|
|
1113
|
+
options = {
|
|
1114
|
+
...defaultFormOptions,
|
|
1115
|
+
...options
|
|
1116
|
+
};
|
|
1117
|
+
if ((options.SPA === true || typeof options.SPA === "object") && options.validators === void 0) console.warn("No validators set for superForm in SPA mode. Add a validation adapter to the validators option, or set it to false to disable this warning.");
|
|
1118
|
+
if (!form) throw new SuperFormError("No form data sent to superForm. Make sure the output from superValidate is used (usually data.form) and that it's not null or undefined. Alternatively, an object with default values for the form can also be used, but then constraints won't be available.");
|
|
1119
|
+
if (Context_isValidationObject(form) === false) form = {
|
|
1120
|
+
id: options.id ?? Math.random().toString(36).slice(2, 10),
|
|
1121
|
+
valid: false,
|
|
1122
|
+
posted: false,
|
|
1123
|
+
errors: {},
|
|
1124
|
+
data: form,
|
|
1125
|
+
shape: shapeFromObject(form)
|
|
1126
|
+
};
|
|
1127
|
+
form = form;
|
|
1128
|
+
const _initialFormId = form.id = options.id ?? form.id;
|
|
1129
|
+
const _currentPage = get(page) ?? (STORYBOOK_MODE ? {} : void 0);
|
|
1130
|
+
/**
|
|
1131
|
+
* Need to clone the form data, in case it's used to populate multiple forms
|
|
1132
|
+
* and in components that are mounted and destroyed multiple times.
|
|
1133
|
+
* This also means that it needs to be set here, before it's cloned further below.
|
|
1134
|
+
*/
|
|
1135
|
+
if (!initialForms.has(form)) initialForms.set(form, form);
|
|
1136
|
+
initialForm = initialForms.get(form);
|
|
1137
|
+
if (_currentPage.form && typeof _currentPage.form === "object") {
|
|
1138
|
+
const postedData = _currentPage.form;
|
|
1139
|
+
for (const postedForm of Context_findValidationForms(postedData).reverse()) if (postedForm.id == _initialFormId && !initialForms.has(postedForm)) {
|
|
1140
|
+
initialForms.set(postedData, postedData);
|
|
1141
|
+
const pageDataForm = form;
|
|
1142
|
+
form = postedForm;
|
|
1143
|
+
form.constraints = pageDataForm.constraints;
|
|
1144
|
+
form.shape = pageDataForm.shape;
|
|
1145
|
+
if (form.valid && options.resetForm && (options.resetForm === true || options.resetForm())) {
|
|
1146
|
+
form = clone(pageDataForm);
|
|
1147
|
+
form.message = clone(postedForm.message);
|
|
1148
|
+
}
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
} else form = clone(initialForm);
|
|
1152
|
+
onDestroy(() => {
|
|
1153
|
+
Unsubscriptions_unsubscribe();
|
|
1154
|
+
NextChange_clear();
|
|
1155
|
+
EnhancedForm_destroy();
|
|
1156
|
+
for (const events of Object.values(formEvents)) events.length = 0;
|
|
1157
|
+
formIds.get(_currentPage)?.delete(_initialFormId);
|
|
1158
|
+
});
|
|
1159
|
+
if (options.dataType !== "json") {
|
|
1160
|
+
const checkForNestedData = (key, value) => {
|
|
1161
|
+
if (!value || typeof value !== "object") return;
|
|
1162
|
+
if (Array.isArray(value)) {
|
|
1163
|
+
if (value.length > 0) checkForNestedData(key, value[0]);
|
|
1164
|
+
} else if (!(value instanceof Date) && !(value instanceof File) && true) throw new SuperFormError(`Object found in form field "${key}". Set the dataType option to "json" and add use:enhance to use nested data structures. More information: https://superforms.rocks/concepts/nested-data`);
|
|
1165
|
+
};
|
|
1166
|
+
for (const [key, value] of Object.entries(form.data)) checkForNestedData(key, value);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Container for store data, subscribed to with Unsubscriptions
|
|
1171
|
+
* to avoid "get" usage.
|
|
1172
|
+
*/
|
|
1173
|
+
const __data = {
|
|
1174
|
+
formId: form.id,
|
|
1175
|
+
form: clone(form.data),
|
|
1176
|
+
constraints: form.constraints ?? {},
|
|
1177
|
+
posted: form.posted,
|
|
1178
|
+
errors: clone(form.errors),
|
|
1179
|
+
message: clone(form.message),
|
|
1180
|
+
tainted: void 0,
|
|
1181
|
+
valid: form.valid,
|
|
1182
|
+
submitting: false,
|
|
1183
|
+
shape: form.shape
|
|
1184
|
+
};
|
|
1185
|
+
const Data = __data;
|
|
1186
|
+
const FormId = writable(options.id ?? form.id);
|
|
1187
|
+
function Context_findValidationForms(data) {
|
|
1188
|
+
return Object.values(data).filter((v) => Context_isValidationObject(v) !== false);
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Return false if object isn't a validation object, otherwise the form id,
|
|
1192
|
+
* which can be an empty string, so always check with === false
|
|
1193
|
+
*/
|
|
1194
|
+
function Context_isValidationObject(object) {
|
|
1195
|
+
if (!object || typeof object !== "object") return false;
|
|
1196
|
+
if (!("valid" in object && "errors" in object && typeof object.valid === "boolean")) return false;
|
|
1197
|
+
return "id" in object && typeof object.id === "string" ? object.id : false;
|
|
1198
|
+
}
|
|
1199
|
+
const _formData = writable(form.data);
|
|
1200
|
+
const Form$1 = {
|
|
1201
|
+
subscribe: _formData.subscribe,
|
|
1202
|
+
set: (value, options = {}) => {
|
|
1203
|
+
const newData = clone(value);
|
|
1204
|
+
Tainted_update(newData, options.taint ?? true);
|
|
1205
|
+
return _formData.set(newData);
|
|
1206
|
+
},
|
|
1207
|
+
update: (updater, options = {}) => {
|
|
1208
|
+
return _formData.update((value) => {
|
|
1209
|
+
const newData = updater(value);
|
|
1210
|
+
Tainted_update(newData, options.taint ?? true);
|
|
1211
|
+
return newData;
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
function Form_isSPA() {
|
|
1216
|
+
return options.SPA === true || typeof options.SPA === "object";
|
|
1217
|
+
}
|
|
1218
|
+
function Form_resultStatus(defaultStatus) {
|
|
1219
|
+
if (defaultStatus > 400) return defaultStatus;
|
|
1220
|
+
return (typeof options.SPA === "boolean" || typeof options.SPA === "string" ? void 0 : options.SPA?.failStatus) || defaultStatus;
|
|
1221
|
+
}
|
|
1222
|
+
async function Form_validate(opts = {}) {
|
|
1223
|
+
const dataToValidate = opts.formData ?? Data.form;
|
|
1224
|
+
let errors = {};
|
|
1225
|
+
let status;
|
|
1226
|
+
const validator = opts.adapter ?? options.validators;
|
|
1227
|
+
if (typeof validator == "object") {
|
|
1228
|
+
if (validator != initialValidator && !("jsonSchema" in validator)) throw new SuperFormError("Client validation adapter found in options.validators. A full adapter must be used when changing validators dynamically, for example \"zod\" instead of \"zodClient\".");
|
|
1229
|
+
status = await validator.validate(dataToValidate);
|
|
1230
|
+
if (!status.success) errors = mapErrors(status.issues, validator.shape ?? Data.shape ?? {});
|
|
1231
|
+
else if (opts.recheckValidData !== false) return Form_validate({
|
|
1232
|
+
...opts,
|
|
1233
|
+
recheckValidData: false
|
|
1234
|
+
});
|
|
1235
|
+
} else status = {
|
|
1236
|
+
success: true,
|
|
1237
|
+
data: {}
|
|
1238
|
+
};
|
|
1239
|
+
const data = {
|
|
1240
|
+
...Data.form,
|
|
1241
|
+
...dataToValidate,
|
|
1242
|
+
...status.success ? status.data : {}
|
|
1243
|
+
};
|
|
1244
|
+
return {
|
|
1245
|
+
valid: status.success,
|
|
1246
|
+
posted: false,
|
|
1247
|
+
errors,
|
|
1248
|
+
data,
|
|
1249
|
+
constraints: Data.constraints,
|
|
1250
|
+
message: void 0,
|
|
1251
|
+
id: Data.formId,
|
|
1252
|
+
shape: Data.shape
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
function Form__changeEvent(event) {
|
|
1256
|
+
if (!options.onChange || !event.paths.length || event.type == "blur") return;
|
|
1257
|
+
let changeEvent;
|
|
1258
|
+
const paths = event.paths.map(mergePath);
|
|
1259
|
+
if (event.type && event.paths.length == 1 && event.formElement && event.target instanceof Element) changeEvent = {
|
|
1260
|
+
path: paths[0],
|
|
1261
|
+
paths,
|
|
1262
|
+
formElement: event.formElement,
|
|
1263
|
+
target: event.target,
|
|
1264
|
+
set(path, value, options) {
|
|
1265
|
+
fieldProxy({ form: Form$1 }, path, options).set(value);
|
|
1266
|
+
},
|
|
1267
|
+
get(path) {
|
|
1268
|
+
return get(fieldProxy(Form$1, path));
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
else changeEvent = {
|
|
1272
|
+
paths,
|
|
1273
|
+
target: void 0,
|
|
1274
|
+
set(path, value, options) {
|
|
1275
|
+
fieldProxy({ form: Form$1 }, path, options).set(value);
|
|
1276
|
+
},
|
|
1277
|
+
get(path) {
|
|
1278
|
+
return get(fieldProxy(Form$1, path));
|
|
1279
|
+
}
|
|
1280
|
+
};
|
|
1281
|
+
options.onChange(changeEvent);
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Make a client-side validation, updating the form data if successful.
|
|
1285
|
+
* @param event A change event, from html input or programmatically
|
|
1286
|
+
* @param force Is true if called from validateForm with update: true
|
|
1287
|
+
* @param adapter ValidationAdapter, if called from validateForm with schema set
|
|
1288
|
+
* @returns SuperValidated, or undefined if options prevented validation.
|
|
1289
|
+
*/
|
|
1290
|
+
async function Form_clientValidation(event, force = false, adapter) {
|
|
1291
|
+
if (event) {
|
|
1292
|
+
if (options.validators == "clear") Errors.update(($errors) => {
|
|
1293
|
+
setPaths($errors, event.paths, void 0);
|
|
1294
|
+
return $errors;
|
|
1295
|
+
});
|
|
1296
|
+
setTimeout(() => Form__changeEvent(event));
|
|
1297
|
+
}
|
|
1298
|
+
let skipValidation = false;
|
|
1299
|
+
if (!force) {
|
|
1300
|
+
if (options.validationMethod == "onsubmit" || options.validationMethod == "submit-only") skipValidation = true;
|
|
1301
|
+
else if (options.validationMethod == "onblur" && event?.type == "input") skipValidation = true;
|
|
1302
|
+
else if (options.validationMethod == "oninput" && event?.type == "blur") skipValidation = true;
|
|
1303
|
+
}
|
|
1304
|
+
if (skipValidation || !event || !options.validators || options.validators == "clear") {
|
|
1305
|
+
if (event?.paths) {
|
|
1306
|
+
const formElement = event?.formElement ?? EnhancedForm_get();
|
|
1307
|
+
if (formElement) Form__clearCustomValidity(formElement);
|
|
1308
|
+
}
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
const result = await Form_validate({ adapter });
|
|
1312
|
+
if (result.valid && (event.immediate || event.type != "input")) Form$1.set(result.data, { taint: "ignore" });
|
|
1313
|
+
await tick();
|
|
1314
|
+
Form__displayNewErrors(result.errors, event, force);
|
|
1315
|
+
return result;
|
|
1316
|
+
}
|
|
1317
|
+
function Form__clearCustomValidity(formElement) {
|
|
1318
|
+
const validity = /* @__PURE__ */ new Map();
|
|
1319
|
+
if (options.customValidity && formElement) for (const el of formElement.querySelectorAll(`[name]`)) {
|
|
1320
|
+
if (typeof el.name !== "string" || !el.name.length) continue;
|
|
1321
|
+
const message = "validationMessage" in el ? String(el.validationMessage) : "";
|
|
1322
|
+
validity.set(el.name, {
|
|
1323
|
+
el,
|
|
1324
|
+
message
|
|
1325
|
+
});
|
|
1326
|
+
updateCustomValidity(el, void 0);
|
|
1327
|
+
}
|
|
1328
|
+
return validity;
|
|
1329
|
+
}
|
|
1330
|
+
async function Form__displayNewErrors(errors, event, force) {
|
|
1331
|
+
const { type, immediate, multiple, paths } = event;
|
|
1332
|
+
const previous = Data.errors;
|
|
1333
|
+
const output = {};
|
|
1334
|
+
let validity = /* @__PURE__ */ new Map();
|
|
1335
|
+
const formElement = event.formElement ?? EnhancedForm_get();
|
|
1336
|
+
if (formElement) validity = Form__clearCustomValidity(formElement);
|
|
1337
|
+
traversePaths(errors, (error) => {
|
|
1338
|
+
if (!Array.isArray(error.value)) return;
|
|
1339
|
+
const currentPath = [...error.path];
|
|
1340
|
+
if (currentPath[currentPath.length - 1] == "_errors") currentPath.pop();
|
|
1341
|
+
const joinedPath = currentPath.join(".");
|
|
1342
|
+
const isObjectError = error.path[error.path.length - 1] == "_errors";
|
|
1343
|
+
const isEventError = error.value && paths.some((path) => {
|
|
1344
|
+
return isObjectError ? currentPath && path && currentPath.length > 0 && currentPath[0] == path[0] : joinedPath == path.join(".");
|
|
1345
|
+
});
|
|
1346
|
+
function addError() {
|
|
1347
|
+
setPaths(output, [error.path], error.value);
|
|
1348
|
+
if (options.customValidity && isEventError && validity.has(joinedPath)) {
|
|
1349
|
+
const { el, message } = validity.get(joinedPath);
|
|
1350
|
+
if (message != error.value) {
|
|
1351
|
+
setTimeout(() => updateCustomValidity(el, error.value));
|
|
1352
|
+
validity.clear();
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
if (force) return addError();
|
|
1357
|
+
if (isEventError && options.validationMethod == "oninput") return addError();
|
|
1358
|
+
if (immediate && !multiple && isEventError) return addError();
|
|
1359
|
+
if (multiple) {
|
|
1360
|
+
const errorPath = pathExists(get(Errors), error.path.slice(0, -1));
|
|
1361
|
+
if (errorPath?.value && typeof errorPath?.value == "object") {
|
|
1362
|
+
for (const errors of Object.values(errorPath.value)) if (Array.isArray(errors)) return addError();
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
const previousError = pathExists(previous, error.path);
|
|
1366
|
+
if (previousError && previousError.key in previousError.parent) return addError();
|
|
1367
|
+
if (isObjectError) {
|
|
1368
|
+
if (options.validationMethod == "oninput" || type == "blur" && Tainted_hasBeenTainted(mergePath(error.path.slice(0, -1)))) return addError();
|
|
1369
|
+
} else if (type == "blur" && isEventError) return addError();
|
|
1370
|
+
});
|
|
1371
|
+
Errors.set(output);
|
|
1372
|
+
}
|
|
1373
|
+
function Form_set(data, options = {}) {
|
|
1374
|
+
if (options.keepFiles) traversePaths(Data.form, (info) => {
|
|
1375
|
+
if (info.value instanceof File || false) {
|
|
1376
|
+
const dataPath = pathExists(data, info.path);
|
|
1377
|
+
if (!dataPath || !(dataPath.key in dataPath.parent)) setPaths(data, [info.path], info.value);
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
return Form$1.set(data, options);
|
|
1381
|
+
}
|
|
1382
|
+
function Form_shouldReset(validForm, successActionResult) {
|
|
1383
|
+
return validForm && successActionResult && options.resetForm && (options.resetForm === true || options.resetForm());
|
|
1384
|
+
}
|
|
1385
|
+
function Form_capture(removeFilesfromData = true) {
|
|
1386
|
+
let data = Data.form;
|
|
1387
|
+
let tainted = Data.tainted;
|
|
1388
|
+
if (removeFilesfromData) {
|
|
1389
|
+
const removed = removeFiles(Data.form);
|
|
1390
|
+
data = removed.data;
|
|
1391
|
+
const paths = removed.paths;
|
|
1392
|
+
if (paths.length) {
|
|
1393
|
+
tainted = clone(tainted) ?? {};
|
|
1394
|
+
setPaths(tainted, paths, false);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return {
|
|
1398
|
+
valid: Data.valid,
|
|
1399
|
+
posted: Data.posted,
|
|
1400
|
+
errors: Data.errors,
|
|
1401
|
+
data,
|
|
1402
|
+
constraints: Data.constraints,
|
|
1403
|
+
message: Data.message,
|
|
1404
|
+
id: Data.formId,
|
|
1405
|
+
tainted,
|
|
1406
|
+
shape: Data.shape
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
async function Form_updateFromValidation(form2, successResult) {
|
|
1410
|
+
if (form2.valid && successResult && Form_shouldReset(form2.valid, successResult)) Form_reset({
|
|
1411
|
+
message: form2.message,
|
|
1412
|
+
posted: true
|
|
1413
|
+
});
|
|
1414
|
+
else rebind({
|
|
1415
|
+
form: form2,
|
|
1416
|
+
untaint: successResult,
|
|
1417
|
+
keepFiles: true,
|
|
1418
|
+
pessimisticUpdate: options.invalidateAll == "force" || options.invalidateAll == "pessimistic"
|
|
1419
|
+
});
|
|
1420
|
+
if (formEvents.onUpdated.length) await tick();
|
|
1421
|
+
for (const event of formEvents.onUpdated) event({ form: form2 });
|
|
1422
|
+
}
|
|
1423
|
+
function Form_reset(opts = {}) {
|
|
1424
|
+
if (opts.newState) initialForm.data = {
|
|
1425
|
+
...initialForm.data,
|
|
1426
|
+
...opts.newState
|
|
1427
|
+
};
|
|
1428
|
+
const resetData = clone(initialForm);
|
|
1429
|
+
resetData.data = {
|
|
1430
|
+
...resetData.data,
|
|
1431
|
+
...opts.data
|
|
1432
|
+
};
|
|
1433
|
+
if (opts.id !== void 0) resetData.id = opts.id;
|
|
1434
|
+
const currentTainted = clone(__data.tainted);
|
|
1435
|
+
const newTainted = {};
|
|
1436
|
+
if (currentTainted && opts.data) {
|
|
1437
|
+
for (const key in currentTainted) if (key in opts.data) newTainted[key] = currentTainted[key];
|
|
1438
|
+
}
|
|
1439
|
+
rebind({
|
|
1440
|
+
form: resetData,
|
|
1441
|
+
untaint: Object.keys(newTainted).length > 0 ? newTainted : true,
|
|
1442
|
+
message: opts.message,
|
|
1443
|
+
keepFiles: false,
|
|
1444
|
+
posted: opts.posted,
|
|
1445
|
+
resetted: true
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
async function Form_updateFromActionResult(result) {
|
|
1449
|
+
if (result.type == "error") throw new SuperFormError(`ActionResult of type "${result.type}" cannot be passed to update function.`);
|
|
1450
|
+
if (result.type == "redirect") {
|
|
1451
|
+
if (Form_shouldReset(true, true)) Form_reset({ posted: true });
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
if (typeof result.data !== "object") throw new SuperFormError("Non-object validation data returned from ActionResult.");
|
|
1455
|
+
const forms = Context_findValidationForms(result.data);
|
|
1456
|
+
if (!forms.length) throw new SuperFormError("No form data returned from ActionResult. Make sure you return { form } in the form actions.");
|
|
1457
|
+
for (const newForm of forms) {
|
|
1458
|
+
if (newForm.id !== Data.formId) continue;
|
|
1459
|
+
await Form_updateFromValidation(newForm, result.status >= 200 && result.status < 300);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const Message = writable(__data.message);
|
|
1463
|
+
const Constraints = writable(__data.constraints);
|
|
1464
|
+
const Posted = writable(__data.posted);
|
|
1465
|
+
const Shape = writable(__data.shape);
|
|
1466
|
+
const _errors = writable(form.errors);
|
|
1467
|
+
const Errors = {
|
|
1468
|
+
subscribe: _errors.subscribe,
|
|
1469
|
+
set(value, options) {
|
|
1470
|
+
return _errors.set(updateErrors(value, Data.errors, options?.force));
|
|
1471
|
+
},
|
|
1472
|
+
update(updater, options) {
|
|
1473
|
+
return _errors.update((value) => {
|
|
1474
|
+
return updateErrors(updater(value), Data.errors, options?.force);
|
|
1475
|
+
});
|
|
1476
|
+
},
|
|
1477
|
+
/**
|
|
1478
|
+
* To work with client-side validation, errors cannot be deleted but must
|
|
1479
|
+
* be set to undefined, to know where they existed before (tainted+error check in oninput)
|
|
1480
|
+
*/
|
|
1481
|
+
clear: () => Errors.set({})
|
|
1482
|
+
};
|
|
1483
|
+
let NextChange = null;
|
|
1484
|
+
function NextChange_setHtmlEvent(event) {
|
|
1485
|
+
if (NextChange && event && Object.keys(event).length == 1 && event.paths?.length && NextChange.target && NextChange.target instanceof HTMLInputElement && NextChange.target.type.toLowerCase() == "file") NextChange.paths = event.paths;
|
|
1486
|
+
else NextChange = event;
|
|
1487
|
+
setTimeout(() => {
|
|
1488
|
+
Form_clientValidation(NextChange);
|
|
1489
|
+
}, 0);
|
|
1490
|
+
}
|
|
1491
|
+
function NextChange_additionalEventInformation(event, immediate, multiple, formElement, target) {
|
|
1492
|
+
if (NextChange === null) NextChange = { paths: [] };
|
|
1493
|
+
NextChange.type = event;
|
|
1494
|
+
NextChange.immediate = immediate;
|
|
1495
|
+
NextChange.multiple = multiple;
|
|
1496
|
+
NextChange.formElement = formElement;
|
|
1497
|
+
NextChange.target = target;
|
|
1498
|
+
}
|
|
1499
|
+
function NextChange_paths() {
|
|
1500
|
+
return NextChange?.paths ?? [];
|
|
1501
|
+
}
|
|
1502
|
+
function NextChange_clear() {
|
|
1503
|
+
NextChange = null;
|
|
1504
|
+
}
|
|
1505
|
+
const Tainted = {
|
|
1506
|
+
state: writable(),
|
|
1507
|
+
message: options.taintedMessage,
|
|
1508
|
+
clean: clone(form.data)};
|
|
1509
|
+
function Tainted_enable() {
|
|
1510
|
+
options.taintedMessage = Tainted.message;
|
|
1511
|
+
}
|
|
1512
|
+
function Tainted_currentState() {
|
|
1513
|
+
return Tainted.state;
|
|
1514
|
+
}
|
|
1515
|
+
function Tainted_hasBeenTainted(path) {
|
|
1516
|
+
if (!Data.tainted) return false;
|
|
1517
|
+
if (!path) return !!Data.tainted;
|
|
1518
|
+
const field = pathExists(Data.tainted, splitPath(path));
|
|
1519
|
+
return !!field && field.key in field.parent;
|
|
1520
|
+
}
|
|
1521
|
+
function Tainted_isTainted(path) {
|
|
1522
|
+
if (!arguments.length) return Tainted__isObjectTainted(Data.tainted);
|
|
1523
|
+
if (typeof path === "boolean") return path;
|
|
1524
|
+
if (typeof path === "object") return Tainted__isObjectTainted(path);
|
|
1525
|
+
if (!Data.tainted || path === void 0) return false;
|
|
1526
|
+
return Tainted__isObjectTainted(pathExists(Data.tainted, splitPath(path))?.value);
|
|
1527
|
+
}
|
|
1528
|
+
function Tainted__isObjectTainted(obj) {
|
|
1529
|
+
if (!obj) return false;
|
|
1530
|
+
if (typeof obj === "object") {
|
|
1531
|
+
for (const obj2 of Object.values(obj)) if (Tainted__isObjectTainted(obj2)) return true;
|
|
1532
|
+
}
|
|
1533
|
+
return obj === true;
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Updates the tainted state. Use most of the time, except when submitting.
|
|
1537
|
+
*/
|
|
1538
|
+
function Tainted_update(newData, taintOptions) {
|
|
1539
|
+
if (taintOptions == "ignore") return;
|
|
1540
|
+
const paths = comparePaths(newData, Data.form);
|
|
1541
|
+
const newTainted = comparePaths(newData, Tainted.clean).map((path) => path.join());
|
|
1542
|
+
if (paths.length) {
|
|
1543
|
+
Tainted.state.update((currentlyTainted) => {
|
|
1544
|
+
if (!currentlyTainted) currentlyTainted = {};
|
|
1545
|
+
setPaths(currentlyTainted, paths, (path, data) => {
|
|
1546
|
+
if (!newTainted.includes(path.join())) return void 0;
|
|
1547
|
+
const currentValue = traversePath(newData, path);
|
|
1548
|
+
const cleanPath = traversePath(Tainted.clean, path);
|
|
1549
|
+
return currentValue && cleanPath && currentValue.value === cleanPath.value ? void 0 : taintOptions === true ? true : taintOptions === "untaint" ? void 0 : data.value;
|
|
1550
|
+
});
|
|
1551
|
+
return currentlyTainted;
|
|
1552
|
+
});
|
|
1553
|
+
NextChange_setHtmlEvent({ paths });
|
|
1554
|
+
}
|
|
1555
|
+
if (taintOptions == "untaint-all" || taintOptions == "untaint-form") Tainted.state.set(void 0);
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* Overwrites the current tainted state and setting a new clean state for the form data.
|
|
1559
|
+
* @param tainted
|
|
1560
|
+
* @param newClean
|
|
1561
|
+
*/
|
|
1562
|
+
function Tainted_set(tainted, newClean) {
|
|
1563
|
+
Tainted.state.set(tainted);
|
|
1564
|
+
if (newClean) Tainted.clean = newClean;
|
|
1565
|
+
}
|
|
1566
|
+
const Submitting = writable(false);
|
|
1567
|
+
const Delayed = writable(false);
|
|
1568
|
+
const Timeout = writable(false);
|
|
1569
|
+
/**
|
|
1570
|
+
* Subscribe to certain stores and store the current value in Data, to avoid using get.
|
|
1571
|
+
* Need to clone the form data, so it won't refer to the same object and prevent change detection
|
|
1572
|
+
*/
|
|
1573
|
+
const Unsubscriptions = [
|
|
1574
|
+
Tainted.state.subscribe((tainted) => __data.tainted = clone(tainted)),
|
|
1575
|
+
Form$1.subscribe((form) => __data.form = clone(form)),
|
|
1576
|
+
Errors.subscribe((errors) => __data.errors = clone(errors)),
|
|
1577
|
+
FormId.subscribe((id) => __data.formId = id),
|
|
1578
|
+
Constraints.subscribe((constraints) => __data.constraints = constraints),
|
|
1579
|
+
Posted.subscribe((posted) => __data.posted = posted),
|
|
1580
|
+
Message.subscribe((message) => __data.message = message),
|
|
1581
|
+
Submitting.subscribe((submitting) => __data.submitting = submitting),
|
|
1582
|
+
Shape.subscribe((shape) => __data.shape = shape)
|
|
1583
|
+
];
|
|
1584
|
+
function Unsubscriptions_unsubscribe() {
|
|
1585
|
+
Unsubscriptions.forEach((unsub) => unsub());
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Used for SPA action mode and options.customValidity to display errors, even if programmatically set
|
|
1589
|
+
*/
|
|
1590
|
+
let EnhancedForm;
|
|
1591
|
+
function EnhancedForm_get() {
|
|
1592
|
+
return EnhancedForm;
|
|
1593
|
+
}
|
|
1594
|
+
function EnhancedForm_setAction(action) {
|
|
1595
|
+
if (EnhancedForm) EnhancedForm.action = action;
|
|
1596
|
+
}
|
|
1597
|
+
function EnhancedForm_destroy() {
|
|
1598
|
+
if (EnhancedForm?.parentElement) EnhancedForm.remove();
|
|
1599
|
+
EnhancedForm = void 0;
|
|
1600
|
+
}
|
|
1601
|
+
const AllErrors = derived$1(Errors, ($errors) => $errors ? flattenErrors($errors) : []);
|
|
1602
|
+
options.taintedMessage = void 0;
|
|
1603
|
+
function rebind(opts) {
|
|
1604
|
+
const form = opts.form;
|
|
1605
|
+
const message = opts.message ?? form.message;
|
|
1606
|
+
if (opts.untaint || opts.resetted) Tainted_set(typeof opts.untaint === "boolean" ? void 0 : opts.untaint, form.data);
|
|
1607
|
+
if (!opts.pessimisticUpdate) Form_set(form.data, {
|
|
1608
|
+
taint: "ignore",
|
|
1609
|
+
keepFiles: opts.keepFiles
|
|
1610
|
+
});
|
|
1611
|
+
Message.set(message);
|
|
1612
|
+
if (opts.resetted) Errors.update(() => ({}), { force: true });
|
|
1613
|
+
else Errors.set(form.errors);
|
|
1614
|
+
FormId.set(form.id);
|
|
1615
|
+
Posted.set(opts.posted ?? form.posted);
|
|
1616
|
+
if (form.constraints) Constraints.set(form.constraints);
|
|
1617
|
+
if (form.shape) Shape.set(form.shape);
|
|
1618
|
+
__data.valid = form.valid;
|
|
1619
|
+
if (options.flashMessage && shouldSyncFlash(options)) {
|
|
1620
|
+
const flash = options.flashMessage.module.getFlash(page);
|
|
1621
|
+
if (message && get(flash) === void 0) flash.set(message);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
const formEvents = {
|
|
1625
|
+
onSubmit: options.onSubmit ? [options.onSubmit] : [],
|
|
1626
|
+
onResult: options.onResult ? [options.onResult] : [],
|
|
1627
|
+
onUpdate: options.onUpdate ? [options.onUpdate] : [],
|
|
1628
|
+
onUpdated: options.onUpdated ? [options.onUpdated] : [],
|
|
1629
|
+
onError: options.onError ? [options.onError] : []
|
|
1630
|
+
};
|
|
1631
|
+
/**
|
|
1632
|
+
* Custom use:enhance that enables all the client-side functionality.
|
|
1633
|
+
* @param FormElement
|
|
1634
|
+
* @param events
|
|
1635
|
+
* @DCI-context
|
|
1636
|
+
*/
|
|
1637
|
+
function superFormEnhance(FormElement, events) {
|
|
1638
|
+
if (options.SPA !== void 0 && FormElement.method == "get") FormElement.method = "post";
|
|
1639
|
+
if (typeof options.SPA === "string") {
|
|
1640
|
+
if (options.SPA.length && FormElement.action == document.location.href) FormElement.action = options.SPA;
|
|
1641
|
+
} else EnhancedForm = FormElement;
|
|
1642
|
+
if (events) {
|
|
1643
|
+
if (events.onError) {
|
|
1644
|
+
if (options.onError === "apply") throw new SuperFormError("options.onError is set to \"apply\", cannot add any onError events.");
|
|
1645
|
+
else if (events.onError === "apply") throw new SuperFormError("Cannot add \"apply\" as onError event in use:enhance.");
|
|
1646
|
+
formEvents.onError.push(events.onError);
|
|
1647
|
+
}
|
|
1648
|
+
if (events.onResult) formEvents.onResult.push(events.onResult);
|
|
1649
|
+
if (events.onSubmit) formEvents.onSubmit.push(events.onSubmit);
|
|
1650
|
+
if (events.onUpdate) formEvents.onUpdate.push(events.onUpdate);
|
|
1651
|
+
if (events.onUpdated) formEvents.onUpdated.push(events.onUpdated);
|
|
1652
|
+
}
|
|
1653
|
+
Tainted_enable();
|
|
1654
|
+
let lastInputChange;
|
|
1655
|
+
async function onInput(e) {
|
|
1656
|
+
const info = inputInfo(e.target);
|
|
1657
|
+
if (info.immediate && !info.file) await new Promise((r) => setTimeout(r, 0));
|
|
1658
|
+
lastInputChange = NextChange_paths();
|
|
1659
|
+
NextChange_additionalEventInformation("input", info.immediate, info.multiple, FormElement, e.target ?? void 0);
|
|
1660
|
+
}
|
|
1661
|
+
async function onBlur(e) {
|
|
1662
|
+
if (Data.submitting) return;
|
|
1663
|
+
if (!lastInputChange || NextChange_paths() != lastInputChange) return;
|
|
1664
|
+
const info = inputInfo(e.target);
|
|
1665
|
+
if (info.immediate && !info.file) await new Promise((r) => setTimeout(r, 0));
|
|
1666
|
+
if (lastInputChange === void 0) return;
|
|
1667
|
+
Form_clientValidation({
|
|
1668
|
+
paths: lastInputChange,
|
|
1669
|
+
immediate: info.multiple,
|
|
1670
|
+
multiple: info.multiple,
|
|
1671
|
+
type: "blur",
|
|
1672
|
+
formElement: FormElement,
|
|
1673
|
+
target: e.target ?? void 0
|
|
1674
|
+
});
|
|
1675
|
+
lastInputChange = void 0;
|
|
1676
|
+
}
|
|
1677
|
+
FormElement.addEventListener("focusout", onBlur);
|
|
1678
|
+
FormElement.addEventListener("input", onInput);
|
|
1679
|
+
onDestroy(() => {
|
|
1680
|
+
FormElement.removeEventListener("focusout", onBlur);
|
|
1681
|
+
FormElement.removeEventListener("input", onInput);
|
|
1682
|
+
});
|
|
1683
|
+
const htmlForm = Form(FormElement, {
|
|
1684
|
+
submitting: Submitting,
|
|
1685
|
+
delayed: Delayed,
|
|
1686
|
+
timeout: Timeout
|
|
1687
|
+
}, options);
|
|
1688
|
+
let currentRequest;
|
|
1689
|
+
let customRequest = void 0;
|
|
1690
|
+
const enhanced = enhance(FormElement, async (submitParams) => {
|
|
1691
|
+
let jsonData = void 0;
|
|
1692
|
+
let validationAdapter = options.validators;
|
|
1693
|
+
const submit = {
|
|
1694
|
+
...submitParams,
|
|
1695
|
+
jsonData(data) {
|
|
1696
|
+
if (options.dataType !== "json") throw new SuperFormError("options.dataType must be set to 'json' to use jsonData.");
|
|
1697
|
+
jsonData = data;
|
|
1698
|
+
},
|
|
1699
|
+
validators(adapter) {
|
|
1700
|
+
validationAdapter = adapter;
|
|
1701
|
+
},
|
|
1702
|
+
customRequest(request) {
|
|
1703
|
+
customRequest = request;
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
const _submitCancel = submit.cancel;
|
|
1707
|
+
let cancelled = false;
|
|
1708
|
+
function clientValidationResult(validation) {
|
|
1709
|
+
const validationResult = {
|
|
1710
|
+
...validation,
|
|
1711
|
+
posted: true
|
|
1712
|
+
};
|
|
1713
|
+
const status = validationResult.valid ? 200 : Form_resultStatus(400);
|
|
1714
|
+
const data = { form: validationResult };
|
|
1715
|
+
const result = validationResult.valid ? {
|
|
1716
|
+
type: "success",
|
|
1717
|
+
status,
|
|
1718
|
+
data
|
|
1719
|
+
} : {
|
|
1720
|
+
type: "failure",
|
|
1721
|
+
status,
|
|
1722
|
+
data
|
|
1723
|
+
};
|
|
1724
|
+
setTimeout(() => validationResponse({ result }), 0);
|
|
1725
|
+
}
|
|
1726
|
+
function clearOnSubmit() {
|
|
1727
|
+
switch (options.clearOnSubmit) {
|
|
1728
|
+
case "errors-and-message":
|
|
1729
|
+
Errors.clear();
|
|
1730
|
+
Message.set(void 0);
|
|
1731
|
+
break;
|
|
1732
|
+
case "errors":
|
|
1733
|
+
Errors.clear();
|
|
1734
|
+
break;
|
|
1735
|
+
case "message":
|
|
1736
|
+
Message.set(void 0);
|
|
1737
|
+
break;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
async function triggerOnError(result, status) {
|
|
1741
|
+
result.status = status;
|
|
1742
|
+
if (options.onError !== "apply") {
|
|
1743
|
+
const event = {
|
|
1744
|
+
result,
|
|
1745
|
+
message: Message,
|
|
1746
|
+
form
|
|
1747
|
+
};
|
|
1748
|
+
for (const onErrorEvent of formEvents.onError) if (onErrorEvent !== "apply" && (onErrorEvent != defaultOnError || !options.flashMessage?.onError)) await onErrorEvent(event);
|
|
1749
|
+
}
|
|
1750
|
+
if (options.flashMessage && options.flashMessage.onError) await options.flashMessage.onError({
|
|
1751
|
+
result,
|
|
1752
|
+
flashMessage: options.flashMessage.module.getFlash(page)
|
|
1753
|
+
});
|
|
1754
|
+
if (options.applyAction) if (options.onError == "apply") await applyAction();
|
|
1755
|
+
else await applyAction({
|
|
1756
|
+
status: Form_resultStatus(result.status)});
|
|
1757
|
+
}
|
|
1758
|
+
function cancel(opts = { resetTimers: true }) {
|
|
1759
|
+
cancelled = true;
|
|
1760
|
+
if (opts.resetTimers && htmlForm.isSubmitting()) htmlForm.completed({ cancelled });
|
|
1761
|
+
return _submitCancel();
|
|
1762
|
+
}
|
|
1763
|
+
submit.cancel = cancel;
|
|
1764
|
+
if (htmlForm.isSubmitting() && options.multipleSubmits == "prevent") cancel({ resetTimers: false });
|
|
1765
|
+
else {
|
|
1766
|
+
if (htmlForm.isSubmitting() && options.multipleSubmits == "abort") {
|
|
1767
|
+
if (currentRequest) currentRequest.abort();
|
|
1768
|
+
}
|
|
1769
|
+
htmlForm.submitting();
|
|
1770
|
+
currentRequest = submit.controller;
|
|
1771
|
+
for (const event of formEvents.onSubmit) try {
|
|
1772
|
+
await event(submit);
|
|
1773
|
+
} catch (error) {
|
|
1774
|
+
cancel();
|
|
1775
|
+
triggerOnError({
|
|
1776
|
+
type: "error",
|
|
1777
|
+
error
|
|
1778
|
+
}, 500);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
if (cancelled && options.flashMessage) cancelFlash(options);
|
|
1782
|
+
if (!cancelled) {
|
|
1783
|
+
const noValidate = !Form_isSPA() && (FormElement.noValidate || (submit.submitter instanceof HTMLButtonElement || submit.submitter instanceof HTMLInputElement) && submit.submitter.formNoValidate);
|
|
1784
|
+
let validation = void 0;
|
|
1785
|
+
const validateForm = async () => {
|
|
1786
|
+
return await Form_validate({ adapter: validationAdapter });
|
|
1787
|
+
};
|
|
1788
|
+
clearOnSubmit();
|
|
1789
|
+
if (!noValidate) {
|
|
1790
|
+
validation = await validateForm();
|
|
1791
|
+
if (!validation.valid) {
|
|
1792
|
+
cancel({ resetTimers: false });
|
|
1793
|
+
clientValidationResult(validation);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
if (!cancelled) {
|
|
1797
|
+
if (options.flashMessage && (options.clearOnSubmit == "errors-and-message" || options.clearOnSubmit == "message") && shouldSyncFlash(options)) options.flashMessage.module.getFlash(page).set(void 0);
|
|
1798
|
+
const submitData = "formData" in submit ? submit.formData : submit.data;
|
|
1799
|
+
lastInputChange = void 0;
|
|
1800
|
+
if (Form_isSPA()) {
|
|
1801
|
+
if (!validation) validation = await validateForm();
|
|
1802
|
+
cancel({ resetTimers: false });
|
|
1803
|
+
clientValidationResult(validation);
|
|
1804
|
+
} else if (options.dataType === "json") {
|
|
1805
|
+
if (!validation) validation = await validateForm();
|
|
1806
|
+
const postData = clone(jsonData ?? validation.data);
|
|
1807
|
+
traversePaths(postData, (data) => {
|
|
1808
|
+
if (data.value instanceof File) {
|
|
1809
|
+
const key = "__superform_file_" + mergePath(data.path);
|
|
1810
|
+
submitData.append(key, data.value);
|
|
1811
|
+
return data.set(void 0);
|
|
1812
|
+
} else if (Array.isArray(data.value) && data.value.length && data.value.every((v) => v instanceof File)) {
|
|
1813
|
+
const key = "__superform_files_" + mergePath(data.path);
|
|
1814
|
+
for (const file of data.value) submitData.append(key, file);
|
|
1815
|
+
return data.set(void 0);
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
Object.keys(postData).forEach((key) => {
|
|
1819
|
+
if (typeof submitData.get(key) === "string") submitData.delete(key);
|
|
1820
|
+
});
|
|
1821
|
+
const chunks = chunkSubstr(stringify$1(postData, options.transport ? Object.fromEntries(Object.entries(options.transport).map(([k, v]) => [k, v.encode])) : void 0), options.jsonChunkSize ?? 5e5);
|
|
1822
|
+
for (const chunk of chunks) submitData.append("__superform_json", chunk);
|
|
1823
|
+
}
|
|
1824
|
+
if (!submitData.has("__superform_id")) {
|
|
1825
|
+
const id = Data.formId;
|
|
1826
|
+
if (id !== void 0) submitData.set("__superform_id", id);
|
|
1827
|
+
}
|
|
1828
|
+
if (typeof options.SPA === "string") EnhancedForm_setAction(options.SPA);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
function chunkSubstr(str, size) {
|
|
1832
|
+
const numChunks = Math.ceil(str.length / size);
|
|
1833
|
+
const chunks = new Array(numChunks);
|
|
1834
|
+
for (let i = 0, o = 0; i < numChunks; ++i, o += size) chunks[i] = str.substring(o, o + size);
|
|
1835
|
+
return chunks;
|
|
1836
|
+
}
|
|
1837
|
+
async function validationResponse(event) {
|
|
1838
|
+
let cancelled = false;
|
|
1839
|
+
currentRequest = null;
|
|
1840
|
+
let result = "type" in event.result && "status" in event.result ? event.result : {
|
|
1841
|
+
type: "error",
|
|
1842
|
+
status: Form_resultStatus(parseInt(String(event.result.status)) || 500),
|
|
1843
|
+
error: event.result.error instanceof Error ? event.result.error : event.result
|
|
1844
|
+
};
|
|
1845
|
+
const cancel = () => cancelled = true;
|
|
1846
|
+
const data = {
|
|
1847
|
+
result,
|
|
1848
|
+
formEl: FormElement,
|
|
1849
|
+
formElement: FormElement,
|
|
1850
|
+
cancel
|
|
1851
|
+
};
|
|
1852
|
+
const unsubCheckforNav = STORYBOOK_MODE || !Form_isSPA() ? () => {} : navigating.subscribe(($nav) => {
|
|
1853
|
+
if (!$nav || $nav.from?.route.id === $nav.to?.route.id) return;
|
|
1854
|
+
cancel();
|
|
1855
|
+
});
|
|
1856
|
+
function setErrorResult(error, data, status) {
|
|
1857
|
+
data.result = {
|
|
1858
|
+
type: "error",
|
|
1859
|
+
error,
|
|
1860
|
+
status: Form_resultStatus(status)
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
htmlForm.setProcessingEvents(true);
|
|
1864
|
+
for (const event of formEvents.onResult) try {
|
|
1865
|
+
await event(data);
|
|
1866
|
+
} catch (error) {
|
|
1867
|
+
setErrorResult(error, data, Math.max(result.status ?? 500, 400));
|
|
1868
|
+
}
|
|
1869
|
+
result = data.result;
|
|
1870
|
+
if (!cancelled) {
|
|
1871
|
+
if ((result.type === "success" || result.type === "failure") && result.data) {
|
|
1872
|
+
const forms = Context_findValidationForms(result.data);
|
|
1873
|
+
if (!forms.length) throw new SuperFormError("No form data returned from ActionResult. Make sure you return { form } in the form actions.");
|
|
1874
|
+
for (const newForm of forms) {
|
|
1875
|
+
if (newForm.id !== Data.formId) continue;
|
|
1876
|
+
const data = {
|
|
1877
|
+
form: newForm,
|
|
1878
|
+
formEl: FormElement,
|
|
1879
|
+
formElement: FormElement,
|
|
1880
|
+
cancel: () => cancelled = true,
|
|
1881
|
+
result
|
|
1882
|
+
};
|
|
1883
|
+
for (const event of formEvents.onUpdate) try {
|
|
1884
|
+
await event(data);
|
|
1885
|
+
} catch (error) {
|
|
1886
|
+
setErrorResult(error, data, Math.max(result.status ?? 500, 400));
|
|
1887
|
+
}
|
|
1888
|
+
result = data.result;
|
|
1889
|
+
if (!cancelled) {
|
|
1890
|
+
if (options.customValidity) setCustomValidityForm(FormElement, data.form.errors);
|
|
1891
|
+
if (Form_shouldReset(data.form.valid, result.type == "success")) data.formElement.querySelectorAll("input[type=\"file\"]").forEach((e) => e.value = "");
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
if (!cancelled) if (result.type !== "error") {
|
|
1896
|
+
if (result.type === "success" && options.invalidateAll) await invalidateAll();
|
|
1897
|
+
if (options.applyAction) await applyAction();
|
|
1898
|
+
else await Form_updateFromActionResult(result);
|
|
1899
|
+
} else await triggerOnError(result, Math.max(result.status ?? 500, 400));
|
|
1900
|
+
}
|
|
1901
|
+
htmlForm.setProcessingEvents(false);
|
|
1902
|
+
if (cancelled && options.flashMessage) cancelFlash(options);
|
|
1903
|
+
if (cancelled || result.type != "redirect") htmlForm.completed({ cancelled });
|
|
1904
|
+
else if (STORYBOOK_MODE) htmlForm.completed({
|
|
1905
|
+
cancelled,
|
|
1906
|
+
clearAll: true
|
|
1907
|
+
});
|
|
1908
|
+
else {
|
|
1909
|
+
const unsub = navigating.subscribe(($nav) => {
|
|
1910
|
+
if ($nav) return;
|
|
1911
|
+
setTimeout(() => {
|
|
1912
|
+
try {
|
|
1913
|
+
if (unsub) unsub();
|
|
1914
|
+
} catch {}
|
|
1915
|
+
});
|
|
1916
|
+
if (htmlForm.isSubmitting()) htmlForm.completed({
|
|
1917
|
+
cancelled,
|
|
1918
|
+
clearAll: true
|
|
1919
|
+
});
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
unsubCheckforNav();
|
|
1923
|
+
}
|
|
1924
|
+
if (!cancelled && customRequest) {
|
|
1925
|
+
_submitCancel();
|
|
1926
|
+
const response = await customRequest(submitParams);
|
|
1927
|
+
let result;
|
|
1928
|
+
if (response instanceof Response) result = deserialize(await response.text());
|
|
1929
|
+
else if (response instanceof XMLHttpRequest) result = deserialize(response.responseText);
|
|
1930
|
+
else result = response;
|
|
1931
|
+
if (result.type === "error") result.status = response.status;
|
|
1932
|
+
validationResponse({ result });
|
|
1933
|
+
}
|
|
1934
|
+
return validationResponse;
|
|
1935
|
+
});
|
|
1936
|
+
return { destroy: () => {
|
|
1937
|
+
for (const [name, events] of Object.entries(formEvents)) formEvents[name] = events.filter((e) => e === options[name]);
|
|
1938
|
+
enhanced.destroy();
|
|
1939
|
+
} };
|
|
1940
|
+
}
|
|
1941
|
+
function removeFiles(formData) {
|
|
1942
|
+
const paths = [];
|
|
1943
|
+
traversePaths(formData, (data) => {
|
|
1944
|
+
if (data.value instanceof File) {
|
|
1945
|
+
paths.push(data.path);
|
|
1946
|
+
return "skip";
|
|
1947
|
+
} else if (Array.isArray(data.value) && data.value.length && data.value.every((d) => d instanceof File)) {
|
|
1948
|
+
paths.push(data.path);
|
|
1949
|
+
return "skip";
|
|
1950
|
+
}
|
|
1951
|
+
});
|
|
1952
|
+
if (!paths.length) return {
|
|
1953
|
+
data: formData,
|
|
1954
|
+
paths
|
|
1955
|
+
};
|
|
1956
|
+
const data = clone(formData);
|
|
1957
|
+
setPaths(data, paths, (path) => pathExists(initialForm.data, path)?.value);
|
|
1958
|
+
return {
|
|
1959
|
+
data,
|
|
1960
|
+
paths
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
return {
|
|
1964
|
+
form: Form$1,
|
|
1965
|
+
formId: FormId,
|
|
1966
|
+
errors: Errors,
|
|
1967
|
+
message: Message,
|
|
1968
|
+
constraints: Constraints,
|
|
1969
|
+
tainted: Tainted_currentState(),
|
|
1970
|
+
submitting: readonly(Submitting),
|
|
1971
|
+
delayed: readonly(Delayed),
|
|
1972
|
+
timeout: readonly(Timeout),
|
|
1973
|
+
options,
|
|
1974
|
+
capture: Form_capture,
|
|
1975
|
+
restore: ((snapshot) => {
|
|
1976
|
+
rebind({
|
|
1977
|
+
form: snapshot,
|
|
1978
|
+
untaint: snapshot.tainted ?? true
|
|
1979
|
+
});
|
|
1980
|
+
}),
|
|
1981
|
+
async validate(path, opts = {}) {
|
|
1982
|
+
if (!options.validators) throw new SuperFormError("options.validators must be set to use the validate method.");
|
|
1983
|
+
if (opts.update === void 0) opts.update = true;
|
|
1984
|
+
if (opts.taint === void 0) opts.taint = false;
|
|
1985
|
+
if (typeof opts.errors == "string") opts.errors = [opts.errors];
|
|
1986
|
+
let data;
|
|
1987
|
+
const splittedPath = splitPath(path);
|
|
1988
|
+
if ("value" in opts) if (opts.update === true || opts.update === "value") {
|
|
1989
|
+
Form$1.update(($form) => {
|
|
1990
|
+
setPaths($form, [splittedPath], opts.value);
|
|
1991
|
+
return $form;
|
|
1992
|
+
}, { taint: opts.taint });
|
|
1993
|
+
data = Data.form;
|
|
1994
|
+
} else {
|
|
1995
|
+
data = clone(Data.form);
|
|
1996
|
+
setPaths(data, [splittedPath], opts.value);
|
|
1997
|
+
}
|
|
1998
|
+
else data = Data.form;
|
|
1999
|
+
const error = pathExists((await Form_validate({ formData: data })).errors, splittedPath);
|
|
2000
|
+
if (error && error.value && opts.errors) error.value = opts.errors;
|
|
2001
|
+
if (opts.update === true || opts.update == "errors") Errors.update(($errors) => {
|
|
2002
|
+
setPaths($errors, [splittedPath], error?.value);
|
|
2003
|
+
return $errors;
|
|
2004
|
+
});
|
|
2005
|
+
return error?.value;
|
|
2006
|
+
},
|
|
2007
|
+
async validateForm(opts = {}) {
|
|
2008
|
+
if (!options.validators && !opts.schema) throw new SuperFormError("options.validators or the schema option must be set to use the validateForm method.");
|
|
2009
|
+
const result = opts.update ? await Form_clientValidation({ paths: [] }, true, opts.schema) : Form_validate({ adapter: opts.schema });
|
|
2010
|
+
const enhancedForm = EnhancedForm_get();
|
|
2011
|
+
if (opts.update && enhancedForm) setTimeout(() => {
|
|
2012
|
+
if (!enhancedForm) return;
|
|
2013
|
+
scrollToFirstError(enhancedForm, {
|
|
2014
|
+
...options,
|
|
2015
|
+
scrollToError: opts.focusOnError === false ? "off" : options.scrollToError
|
|
2016
|
+
});
|
|
2017
|
+
}, 1);
|
|
2018
|
+
return result || Form_validate({ adapter: opts.schema });
|
|
2019
|
+
},
|
|
2020
|
+
allErrors: AllErrors,
|
|
2021
|
+
posted: Posted,
|
|
2022
|
+
reset(options) {
|
|
2023
|
+
return Form_reset({
|
|
2024
|
+
message: options?.keepMessage ? Data.message : void 0,
|
|
2025
|
+
data: options?.data,
|
|
2026
|
+
id: options?.id,
|
|
2027
|
+
newState: options?.newState
|
|
2028
|
+
});
|
|
2029
|
+
},
|
|
2030
|
+
submit(submitter) {
|
|
2031
|
+
const form = EnhancedForm_get() ? EnhancedForm_get() : submitter && submitter instanceof HTMLElement ? submitter.closest("form") : void 0;
|
|
2032
|
+
if (!form) throw new SuperFormError("use:enhance must be added to the form to use submit, or pass a HTMLElement inside the form (or the form itself) as an argument.");
|
|
2033
|
+
if (!form.requestSubmit) return form.submit();
|
|
2034
|
+
const isSubmitButton = submitter && (submitter instanceof HTMLButtonElement && submitter.type == "submit" || submitter instanceof HTMLInputElement && ["submit", "image"].includes(submitter.type));
|
|
2035
|
+
form.requestSubmit(isSubmitButton ? submitter : void 0);
|
|
2036
|
+
},
|
|
2037
|
+
isTainted: Tainted_isTainted,
|
|
2038
|
+
enhance: superFormEnhance
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
//#endregion
|
|
2042
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/jsonSchema/constraints.js
|
|
2043
|
+
function constraints(schema) {
|
|
2044
|
+
return _constraints(schemaInfo(schema, false, []), []);
|
|
2045
|
+
}
|
|
2046
|
+
function merge(...constraints) {
|
|
2047
|
+
const filtered = constraints.filter((c) => !!c);
|
|
2048
|
+
if (!filtered.length) return void 0;
|
|
2049
|
+
if (filtered.length == 1) return filtered[0];
|
|
2050
|
+
return merge$1(...filtered);
|
|
2051
|
+
}
|
|
2052
|
+
function _constraints(info, path) {
|
|
2053
|
+
if (!info) return void 0;
|
|
2054
|
+
let output = void 0;
|
|
2055
|
+
if (info.union && info.union.length) {
|
|
2056
|
+
const infos = info.union.map((s) => schemaInfo(s, info.isOptional, path));
|
|
2057
|
+
const merged = infos.map((i) => _constraints(i, path));
|
|
2058
|
+
output = merge(output, ...merged);
|
|
2059
|
+
if (output && (info.isNullable || info.isOptional || infos.some((i) => i?.isNullable || i?.isOptional))) delete output.required;
|
|
2060
|
+
}
|
|
2061
|
+
if (info.array) output = merge(output, ...info.array.map((i) => _constraints(schemaInfo(i, info.isOptional, path), path)));
|
|
2062
|
+
if (info.properties) {
|
|
2063
|
+
const obj = {};
|
|
2064
|
+
for (const [key, prop] of Object.entries(info.properties)) {
|
|
2065
|
+
const propConstraint = _constraints(schemaInfo(prop, !info.required?.includes(key) || prop.default !== void 0, [key]), [...path, key]);
|
|
2066
|
+
if (typeof propConstraint === "object" && Object.values(propConstraint).length > 0) obj[key] = propConstraint;
|
|
2067
|
+
}
|
|
2068
|
+
output = merge(output, obj);
|
|
2069
|
+
}
|
|
2070
|
+
return output ?? constraint(info);
|
|
2071
|
+
}
|
|
2072
|
+
function constraint(info) {
|
|
2073
|
+
const output = {};
|
|
2074
|
+
const schema = info.schema;
|
|
2075
|
+
const type = schema.type;
|
|
2076
|
+
const format = schema.format;
|
|
2077
|
+
if (type == "integer" && format == "unix-time") {
|
|
2078
|
+
const date = schema;
|
|
2079
|
+
if (date.minimum !== void 0) output.min = new Date(date.minimum).toISOString();
|
|
2080
|
+
if (date.maximum !== void 0) output.max = new Date(date.maximum).toISOString();
|
|
2081
|
+
} else if (type == "string") {
|
|
2082
|
+
const str = schema;
|
|
2083
|
+
const patterns = [str.pattern, ...str.allOf ? str.allOf.map((s) => typeof s == "boolean" ? void 0 : s.pattern) : []].filter((s) => s !== void 0);
|
|
2084
|
+
if (patterns.length > 0) output.pattern = patterns[0];
|
|
2085
|
+
if (str.minLength !== void 0) output.minlength = str.minLength;
|
|
2086
|
+
if (str.maxLength !== void 0) output.maxlength = str.maxLength;
|
|
2087
|
+
} else if (type == "number" || type == "integer") {
|
|
2088
|
+
const num = schema;
|
|
2089
|
+
if (num.minimum !== void 0) output.min = num.minimum;
|
|
2090
|
+
else if (num.exclusiveMinimum !== void 0) output.min = num.exclusiveMinimum + (type == "integer" ? 1 : Number.MIN_VALUE);
|
|
2091
|
+
if (num.maximum !== void 0) output.max = num.maximum;
|
|
2092
|
+
else if (num.exclusiveMaximum !== void 0) output.max = num.exclusiveMaximum - (type == "integer" ? 1 : Number.MIN_VALUE);
|
|
2093
|
+
if (num.multipleOf !== void 0) output.step = num.multipleOf;
|
|
2094
|
+
} else if (type == "array") {
|
|
2095
|
+
const arr = schema;
|
|
2096
|
+
if (arr.minItems !== void 0) output.min = arr.minItems;
|
|
2097
|
+
if (arr.maxItems !== void 0) output.max = arr.maxItems;
|
|
2098
|
+
}
|
|
2099
|
+
if (!info.isNullable && !info.isOptional) output.required = true;
|
|
2100
|
+
return Object.keys(output).length > 0 ? output : void 0;
|
|
2101
|
+
}
|
|
2102
|
+
//#endregion
|
|
2103
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/jsonSchema/schemaHash.js
|
|
2104
|
+
function schemaHash(schema) {
|
|
2105
|
+
return hashCode(_schemaHash(schemaInfo(schema, false, []), 0, []));
|
|
2106
|
+
}
|
|
2107
|
+
function _schemaHash(info, depth, path) {
|
|
2108
|
+
if (!info) return "";
|
|
2109
|
+
function tab() {
|
|
2110
|
+
return " ".repeat(depth);
|
|
2111
|
+
}
|
|
2112
|
+
function mapSchemas(schemas) {
|
|
2113
|
+
return schemas.map((s) => _schemaHash(schemaInfo(s, info?.isOptional ?? false, path), depth + 1, path)).filter((s) => s).join("|");
|
|
2114
|
+
}
|
|
2115
|
+
function nullish() {
|
|
2116
|
+
const output = [];
|
|
2117
|
+
if (info?.isNullable) output.push("null");
|
|
2118
|
+
if (info?.isOptional) output.push("undefined");
|
|
2119
|
+
return !output.length ? "" : "|" + output.join("|");
|
|
2120
|
+
}
|
|
2121
|
+
if (info.union) return "Union {\n " + tab() + mapSchemas(info.union) + "\n" + tab() + "}" + nullish();
|
|
2122
|
+
if (info.properties) {
|
|
2123
|
+
const output = [];
|
|
2124
|
+
for (const [key, prop] of Object.entries(info.properties)) {
|
|
2125
|
+
const propInfo = schemaInfo(prop, !info.required?.includes(key) || prop.default !== void 0, [key]);
|
|
2126
|
+
output.push(key + ": " + _schemaHash(propInfo, depth + 1, path));
|
|
2127
|
+
}
|
|
2128
|
+
return "Object {\n " + tab() + output.join(",\n ") + "\n" + tab() + "}" + nullish();
|
|
2129
|
+
}
|
|
2130
|
+
if (info.array) return "Array[" + mapSchemas(info.array) + "]" + nullish();
|
|
2131
|
+
return info.types.join("|") + nullish();
|
|
2132
|
+
}
|
|
2133
|
+
function hashCode(str) {
|
|
2134
|
+
let hash = 0;
|
|
2135
|
+
for (let i = 0, len = str.length; i < len; i++) {
|
|
2136
|
+
const chr = str.charCodeAt(i);
|
|
2137
|
+
hash = (hash << 5) - hash + chr;
|
|
2138
|
+
hash |= 0;
|
|
2139
|
+
}
|
|
2140
|
+
if (hash < 0) hash = hash >>> 0;
|
|
2141
|
+
return hash.toString(36);
|
|
2142
|
+
}
|
|
2143
|
+
//#endregion
|
|
2144
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/adapters/adapters.js
|
|
2145
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
2146
|
+
function createAdapter(adapter, jsonSchema) {
|
|
2147
|
+
if (!adapter || !("superFormValidationLibrary" in adapter)) throw new SuperFormError("Superforms v2 requires a validation adapter for the schema. Import one of your choice from \"sveltekit-superforms/adapters\" and wrap the schema with it.");
|
|
2148
|
+
if (!jsonSchema) jsonSchema = adapter.jsonSchema;
|
|
2149
|
+
return {
|
|
2150
|
+
...adapter,
|
|
2151
|
+
constraints: adapter.constraints ?? constraints(jsonSchema),
|
|
2152
|
+
defaults: adapter.defaults ?? defaultValues(jsonSchema),
|
|
2153
|
+
shape: schemaShape(jsonSchema),
|
|
2154
|
+
id: schemaHash(jsonSchema)
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
//#endregion
|
|
2158
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/formData.js
|
|
2159
|
+
/**
|
|
2160
|
+
* V1 compatibilty. resetForm = false and taintedMessage = true
|
|
2161
|
+
*/
|
|
2162
|
+
var legacyMode = false;
|
|
2163
|
+
try {
|
|
2164
|
+
if (SUPERFORMS_LEGACY) legacyMode = true;
|
|
2165
|
+
} catch {}
|
|
2166
|
+
var unionError = "FormData parsing failed: Unions are only supported when the dataType option for superForm is set to \"json\".";
|
|
2167
|
+
/**
|
|
2168
|
+
* Check if multiple types represent compatible variations of the same base type
|
|
2169
|
+
*/
|
|
2170
|
+
function isCompatibleTypeUnion(types) {
|
|
2171
|
+
return new Set(types.map((type) => {
|
|
2172
|
+
if (["number", "integer"].includes(type)) return "number";
|
|
2173
|
+
if (type === "unix-time") return "number";
|
|
2174
|
+
return type;
|
|
2175
|
+
})).size <= 1;
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* Check if union schema represents compatible variations of the same base type
|
|
2179
|
+
*/
|
|
2180
|
+
function isCompatibleUnionSchema(union) {
|
|
2181
|
+
if (!union) return true;
|
|
2182
|
+
const unionTypes = new Set(union.flatMap((u) => u.type ? Array.isArray(u.type) ? u.type : [u.type] : u.const !== void 0 ? [typeof u.const] : []));
|
|
2183
|
+
return unionTypes.size <= 1 || unionTypes.size === 2 && unionTypes.has("null");
|
|
2184
|
+
}
|
|
2185
|
+
async function parseRequest(data, schemaData, options) {
|
|
2186
|
+
let parsed;
|
|
2187
|
+
if (data instanceof FormData) parsed = parseFormData(data, schemaData, options);
|
|
2188
|
+
else if (data instanceof URL || data instanceof URLSearchParams) parsed = parseSearchParams(data, schemaData, options);
|
|
2189
|
+
else if (data instanceof Request) parsed = await tryParseFormData(data, schemaData, options);
|
|
2190
|
+
else if (data && typeof data === "object" && "request" in data && data.request instanceof Request) parsed = await tryParseFormData(data.request, schemaData, options);
|
|
2191
|
+
else parsed = {
|
|
2192
|
+
id: void 0,
|
|
2193
|
+
data,
|
|
2194
|
+
posted: false
|
|
2195
|
+
};
|
|
2196
|
+
return parsed;
|
|
2197
|
+
}
|
|
2198
|
+
async function tryParseFormData(request, schemaData, options) {
|
|
2199
|
+
let formData = void 0;
|
|
2200
|
+
try {
|
|
2201
|
+
formData = await request.formData();
|
|
2202
|
+
} catch (e) {
|
|
2203
|
+
if (e instanceof TypeError && e.message.includes("already been consumed")) throw e;
|
|
2204
|
+
return {
|
|
2205
|
+
id: void 0,
|
|
2206
|
+
data: void 0,
|
|
2207
|
+
posted: false
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
return parseFormData(formData, schemaData, options);
|
|
2211
|
+
}
|
|
2212
|
+
function parseSearchParams(data, schemaData, options) {
|
|
2213
|
+
if (data instanceof URL) data = data.searchParams;
|
|
2214
|
+
const convert = new FormData();
|
|
2215
|
+
for (const [key, value] of data.entries()) convert.append(key, value);
|
|
2216
|
+
const output = parseFormData(convert, schemaData, options, true);
|
|
2217
|
+
output.posted = false;
|
|
2218
|
+
return output;
|
|
2219
|
+
}
|
|
2220
|
+
function parseFormData(formData, schemaData, options, fromURL = false) {
|
|
2221
|
+
function tryParseSuperJson() {
|
|
2222
|
+
if (formData.has("__superform_json")) try {
|
|
2223
|
+
const transport = options && options.transport ? Object.fromEntries(Object.entries(options.transport).map(([k, v]) => [k, v.decode])) : void 0;
|
|
2224
|
+
const output = parse(formData.getAll("__superform_json").join("") ?? "", transport);
|
|
2225
|
+
if (typeof output === "object") {
|
|
2226
|
+
const filePaths = Array.from(formData.keys());
|
|
2227
|
+
for (const path of filePaths.filter((path) => path.startsWith("__superform_file_"))) setPaths(output, [splitPath(path.substring(17))], formData.get(path));
|
|
2228
|
+
for (const path of filePaths.filter((path) => path.startsWith("__superform_files_"))) {
|
|
2229
|
+
const realPath = splitPath(path.substring(18));
|
|
2230
|
+
const allFiles = formData.getAll(path);
|
|
2231
|
+
setPaths(output, [realPath], Array.from(allFiles));
|
|
2232
|
+
}
|
|
2233
|
+
return output;
|
|
2234
|
+
}
|
|
2235
|
+
} catch {}
|
|
2236
|
+
return null;
|
|
2237
|
+
}
|
|
2238
|
+
const data = tryParseSuperJson();
|
|
2239
|
+
const id = formData.get("__superform_id")?.toString();
|
|
2240
|
+
return data ? {
|
|
2241
|
+
id,
|
|
2242
|
+
data,
|
|
2243
|
+
posted: true
|
|
2244
|
+
} : {
|
|
2245
|
+
id,
|
|
2246
|
+
data: _parseFormData(formData, schemaData, options, fromURL),
|
|
2247
|
+
posted: true
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
function _parseFormData(formData, schema, options, fromURL = false) {
|
|
2251
|
+
const output = {};
|
|
2252
|
+
let schemaKeys;
|
|
2253
|
+
let discriminatedUnionSchema;
|
|
2254
|
+
if (options?.strict) schemaKeys = new Set([...formData.keys()].filter((key) => !key.startsWith("__superform_")));
|
|
2255
|
+
else {
|
|
2256
|
+
let unionKeys = [];
|
|
2257
|
+
if (schema.anyOf || schema.oneOf) {
|
|
2258
|
+
const info = schemaInfo(schema, false, []);
|
|
2259
|
+
if (info.union?.some((s) => s.type !== "object")) throw new SchemaError("All form types must be an object if schema is a union.");
|
|
2260
|
+
unionKeys = info.union?.flatMap((s) => Object.keys(s.properties ?? {})) ?? [];
|
|
2261
|
+
if (info.union && info.union.length > 1) for (const variant of info.union) {
|
|
2262
|
+
const variantProps = variant.properties ?? {};
|
|
2263
|
+
const variantPropKeys = Object.keys(variantProps);
|
|
2264
|
+
let isMatch = true;
|
|
2265
|
+
for (const propKey of variantPropKeys) {
|
|
2266
|
+
const prop = variantProps[propKey];
|
|
2267
|
+
if (typeof prop !== "boolean" && prop?.const !== void 0) {
|
|
2268
|
+
if (formData.get(propKey) !== String(prop.const)) {
|
|
2269
|
+
isMatch = false;
|
|
2270
|
+
break;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
if (isMatch) {
|
|
2275
|
+
discriminatedUnionSchema = variant;
|
|
2276
|
+
break;
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
schemaKeys = new Set([
|
|
2281
|
+
...unionKeys,
|
|
2282
|
+
...Object.keys(schema.properties ?? {}),
|
|
2283
|
+
...schema.additionalProperties ? formData.keys() : []
|
|
2284
|
+
].filter((key) => !key.startsWith("__superform_")));
|
|
2285
|
+
}
|
|
2286
|
+
function parseSingleEntry(key, entry, info) {
|
|
2287
|
+
if (options?.preprocessed && options.preprocessed.includes(key)) return entry;
|
|
2288
|
+
if (entry && typeof entry !== "string") return !(legacyMode ? options?.allowFiles === true : options?.allowFiles !== false) ? void 0 : entry.size ? entry : info.isNullable ? null : void 0;
|
|
2289
|
+
if (info.types.length > 1 && !isCompatibleTypeUnion(info.types)) throw new SchemaError(unionError, key);
|
|
2290
|
+
let [type] = info.types;
|
|
2291
|
+
if (entry && !info.types.length && info.schema.enum) if (info.schema.enum.includes(entry)) type = "string";
|
|
2292
|
+
else type = Number.isInteger(parseInt(entry, 10)) ? "integer" : "string";
|
|
2293
|
+
return parseFormDataEntry(key, entry, type ?? "any", info, fromURL);
|
|
2294
|
+
}
|
|
2295
|
+
const defaultPropertyType = typeof schema.additionalProperties == "object" ? schema.additionalProperties : { type: "string" };
|
|
2296
|
+
for (const key of schemaKeys) {
|
|
2297
|
+
const property = discriminatedUnionSchema?.properties ? discriminatedUnionSchema.properties[key] : schema.properties ? schema.properties[key] : defaultPropertyType;
|
|
2298
|
+
assertSchema(property, key);
|
|
2299
|
+
const info = schemaInfo(property ?? defaultPropertyType, !schema.required?.includes(key), [key]);
|
|
2300
|
+
if (!info) continue;
|
|
2301
|
+
if (!info.types.includes("boolean") && !schema.additionalProperties && !formData.has(key)) continue;
|
|
2302
|
+
const entries = formData.getAll(key);
|
|
2303
|
+
if (info.union && info.union.length > 1 && !isCompatibleUnionSchema(info.union)) throw new SchemaError(unionError, key);
|
|
2304
|
+
if (info.types.includes("array") || info.types.includes("set")) {
|
|
2305
|
+
const items = property.items ?? (info.union?.length == 1 ? info.union[0] : void 0);
|
|
2306
|
+
if (!items || typeof items == "boolean" || Array.isArray(items) && items.length != 1) throw new SchemaError("Arrays must have a single \"items\" property that defines its type.", key);
|
|
2307
|
+
const arrayType = Array.isArray(items) ? items[0] : items;
|
|
2308
|
+
assertSchema(arrayType, key);
|
|
2309
|
+
const arrayInfo = schemaInfo(arrayType, info.isOptional, [key]);
|
|
2310
|
+
if (!arrayInfo) continue;
|
|
2311
|
+
const isFileArray = entries.length && entries.some((e) => e && typeof e !== "string");
|
|
2312
|
+
const arrayData = entries.map((e) => parseSingleEntry(key, e, arrayInfo));
|
|
2313
|
+
if (isFileArray && arrayData.every((file) => !file)) arrayData.length = 0;
|
|
2314
|
+
output[key] = info.types.includes("set") ? new Set(arrayData) : arrayData;
|
|
2315
|
+
} else output[key] = parseSingleEntry(key, entries[entries.length - 1], info);
|
|
2316
|
+
}
|
|
2317
|
+
return output;
|
|
2318
|
+
}
|
|
2319
|
+
function parseFormDataEntry(key, value, type, info, fromURL = false) {
|
|
2320
|
+
if (!value) {
|
|
2321
|
+
if (!fromURL && type == "boolean" && info.isOptional && info.schema.default === true) return false;
|
|
2322
|
+
const defaultValue = defaultValues(info.schema, info.isOptional, [key]);
|
|
2323
|
+
if (info.schema.enum && defaultValue !== null && defaultValue !== void 0) return value;
|
|
2324
|
+
if ("const" in info.schema) return value;
|
|
2325
|
+
if (defaultValue !== void 0) return defaultValue;
|
|
2326
|
+
if (info.isNullable) return null;
|
|
2327
|
+
if (info.isOptional) return void 0;
|
|
2328
|
+
}
|
|
2329
|
+
function typeError() {
|
|
2330
|
+
throw new SchemaError(type[0].toUpperCase() + type.slice(1) + " type found. Set the dataType option to \"json\" and add use:enhance on the client to use nested data structures. More information: https://superforms.rocks/concepts/nested-data", key);
|
|
2331
|
+
}
|
|
2332
|
+
switch (type) {
|
|
2333
|
+
case "string":
|
|
2334
|
+
case "any": return value;
|
|
2335
|
+
case "integer": return parseInt(value ?? "", 10);
|
|
2336
|
+
case "number": return parseFloat(value ?? "");
|
|
2337
|
+
case "boolean": return Boolean(value == "false" ? "" : value).valueOf();
|
|
2338
|
+
case "stringbool": return value;
|
|
2339
|
+
case "unix-time": {
|
|
2340
|
+
const date = new Date(value ?? "");
|
|
2341
|
+
return !isNaN(date) ? date : void 0;
|
|
2342
|
+
}
|
|
2343
|
+
case "int64":
|
|
2344
|
+
case "bigint": return BigInt(value ?? ".");
|
|
2345
|
+
case "symbol": return Symbol(String(value));
|
|
2346
|
+
case "set":
|
|
2347
|
+
case "array":
|
|
2348
|
+
case "object": return typeError();
|
|
2349
|
+
default: throw new SuperFormError("Unsupported schema type for FormData: " + type);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
//#endregion
|
|
2353
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/superValidate.js
|
|
2354
|
+
/**
|
|
2355
|
+
* Validates a schema for data validation and usage in superForm.
|
|
2356
|
+
* @param data Data corresponding to a schema, or RequestEvent/FormData/URL. If falsy, the schema's default values will be used.
|
|
2357
|
+
* @param schema The schema to validate against.
|
|
2358
|
+
*/
|
|
2359
|
+
async function superValidate(data, adapter, options) {
|
|
2360
|
+
if (data && "superFormValidationLibrary" in data) {
|
|
2361
|
+
options = adapter;
|
|
2362
|
+
adapter = data;
|
|
2363
|
+
data = void 0;
|
|
2364
|
+
}
|
|
2365
|
+
const validator = adapter;
|
|
2366
|
+
const defaults = options?.defaults ?? validator.defaults;
|
|
2367
|
+
const jsonSchema = validator.jsonSchema;
|
|
2368
|
+
const parsed = await parseRequest(data, jsonSchema, options);
|
|
2369
|
+
const addErrors = options?.errors ?? (options?.strict ? true : !!parsed.data);
|
|
2370
|
+
const parsedData = options?.strict ? parsed.data ?? {} : mergeDefaults(parsed.data, defaults);
|
|
2371
|
+
let status;
|
|
2372
|
+
if (!!parsed.data || addErrors) status = await validator.validate(parsedData);
|
|
2373
|
+
else status = {
|
|
2374
|
+
success: false,
|
|
2375
|
+
issues: []
|
|
2376
|
+
};
|
|
2377
|
+
const valid = status.success;
|
|
2378
|
+
const errors = valid || !addErrors ? {} : mapErrors(status.issues, validator.shape);
|
|
2379
|
+
const dataWithDefaults = valid ? status.data : replaceInvalidDefaults(options?.strict ? mergeDefaults(parsedData, defaults) : parsedData, defaults, jsonSchema, status.issues, options?.preprocessed);
|
|
2380
|
+
let outputData;
|
|
2381
|
+
if (jsonSchema.additionalProperties === false) {
|
|
2382
|
+
outputData = {};
|
|
2383
|
+
for (const key of Object.keys(jsonSchema.properties ?? {})) if (key in dataWithDefaults) outputData[key] = dataWithDefaults[key];
|
|
2384
|
+
} else outputData = dataWithDefaults;
|
|
2385
|
+
const output = {
|
|
2386
|
+
id: parsed.id ?? options?.id ?? validator.id,
|
|
2387
|
+
valid,
|
|
2388
|
+
posted: parsed.posted,
|
|
2389
|
+
errors,
|
|
2390
|
+
data: outputData
|
|
2391
|
+
};
|
|
2392
|
+
if (!parsed.posted) {
|
|
2393
|
+
output.constraints = validator.constraints;
|
|
2394
|
+
if (Object.keys(validator.shape).length) output.shape = validator.shape;
|
|
2395
|
+
}
|
|
2396
|
+
return output;
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
//#region src/lib/form/relation-field-config.ts
|
|
2400
|
+
/**
|
|
2401
|
+
* Whether an option can round-trip through the picker contract. A key
|
|
2402
|
+
* containing an EMPTY-STRING component collides with the contract's ''
|
|
2403
|
+
* unselected sentinel — picking it would corrupt the write (the component
|
|
2404
|
+
* would be normalized to null) — so such options are not offered (a
|
|
2405
|
+
* documented limitation, see {@link promoteCompositeMemberWidgets}).
|
|
2406
|
+
*/
|
|
2407
|
+
function isPickableOption(option) {
|
|
2408
|
+
return (Array.isArray(option.id) ? option.id : [option.id]).every((part) => part !== "");
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* The composite picker's explicit clear value. The empty string cannot mean
|
|
2412
|
+
* "clear" on the native path: an unselected (e.g. partial-null) current
|
|
2413
|
+
* value renders the select at '' too, and an untouched no-JS save must keep
|
|
2414
|
+
* the baseline values rather than erase them. A real composite option value
|
|
2415
|
+
* always contains a comma (two or more components), so this marker cannot
|
|
2416
|
+
* collide with one.
|
|
2417
|
+
*/
|
|
2418
|
+
var COMPOSITE_CLEAR_VALUE = "__clear__";
|
|
2419
|
+
/**
|
|
2420
|
+
* Name of the single form control a composite picker submits. A no-JS
|
|
2421
|
+
* (non-enhanced) submission cannot fan the selection out to the component
|
|
2422
|
+
* fields itself, so the picker's `<select>` carries the canonical encoded id
|
|
2423
|
+
* under this synthetic name and the server decodes it into the component
|
|
2424
|
+
* fields ahead of validation (see `readFormWithCompositePicks`). The enhanced
|
|
2425
|
+
* path ignores it (the form store travels in superforms' JSON envelope).
|
|
2426
|
+
*/
|
|
2427
|
+
function compositeParamName(field) {
|
|
2428
|
+
return `__composite__${field}`;
|
|
2429
|
+
}
|
|
2430
|
+
var TEXT_LIKE_BASE_TYPES = new Set([
|
|
2431
|
+
"text",
|
|
2432
|
+
"character varying",
|
|
2433
|
+
"varchar",
|
|
2434
|
+
"character",
|
|
2435
|
+
"char",
|
|
2436
|
+
"bpchar",
|
|
2437
|
+
"citext",
|
|
2438
|
+
"name"
|
|
2439
|
+
]);
|
|
2440
|
+
function isTextSearchable(dataType) {
|
|
2441
|
+
const lower = dataType.trim().toLowerCase();
|
|
2442
|
+
if (lower.includes("[")) return false;
|
|
2443
|
+
const paren = lower.indexOf("(");
|
|
2444
|
+
const base = (paren === -1 ? lower : lower.slice(0, paren)).trim();
|
|
2445
|
+
return TEXT_LIKE_BASE_TYPES.has(base);
|
|
2446
|
+
}
|
|
2447
|
+
/** Resolve the searchable label column of a picker target, or `null` when the
|
|
2448
|
+
* picker would be unusable (no text-searchable label). */
|
|
2449
|
+
function searchableLabel(target) {
|
|
2450
|
+
const labelField = target.displayField ?? target.primaryKey[0];
|
|
2451
|
+
const labelColumn = target.columns.find((c) => c.name === labelField);
|
|
2452
|
+
if (labelColumn === void 0 || !isTextSearchable(labelColumn.dataType)) return null;
|
|
2453
|
+
return {
|
|
2454
|
+
labelField,
|
|
2455
|
+
searchFields: [labelField]
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
/**
|
|
2459
|
+
* Build the single-column relation-select config for an RPC function argument
|
|
2460
|
+
* carrying an `@arg: <name> relation(<schema.table.column>)` hint (issue #103).
|
|
2461
|
+
*
|
|
2462
|
+
* The picker can only round-trip when the hint targets the referenced table's
|
|
2463
|
+
* single-column primary key — `searchRelation` projects that key as each
|
|
2464
|
+
* option's id, which is exactly the value the argument receives — and the
|
|
2465
|
+
* target has a text-searchable label. Otherwise (a hint at a non-PK column, a
|
|
2466
|
+
* composite-key target, an absent table, or an unsearchable label) the argument
|
|
2467
|
+
* falls back to a scalar input the operator types, so this returns null. Mirrors
|
|
2468
|
+
* the per-relation acceptance in {@link relationFieldConfigs} for a single
|
|
2469
|
+
* foreign key.
|
|
2470
|
+
*/
|
|
2471
|
+
function buildArgRelationConfig(argName, relation, schema) {
|
|
2472
|
+
const resource = `${relation.schema}.${relation.table}`;
|
|
2473
|
+
const target = schema.tables.find((t) => t.qualifiedName === resource);
|
|
2474
|
+
if (target === void 0) return null;
|
|
2475
|
+
if (target.primaryKey.length !== 1 || target.primaryKey[0] !== relation.column) return null;
|
|
2476
|
+
const label = searchableLabel(target);
|
|
2477
|
+
if (label === null) return null;
|
|
2478
|
+
return {
|
|
2479
|
+
field: argName,
|
|
2480
|
+
resource,
|
|
2481
|
+
...label
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
function relationFieldConfigs(table, schema) {
|
|
2485
|
+
const configs = [];
|
|
2486
|
+
for (const relation of table.relations) {
|
|
2487
|
+
const fields = relation.fields ?? [relation.field];
|
|
2488
|
+
const referencedColumns = relation.references.columns ?? [relation.references.column];
|
|
2489
|
+
if (referencedColumns.length !== fields.length) continue;
|
|
2490
|
+
const resource = `${relation.references.schema}.${relation.references.table}`;
|
|
2491
|
+
const target = schema.tables.find((t) => t.qualifiedName === resource);
|
|
2492
|
+
if (target === void 0) continue;
|
|
2493
|
+
const primaryKey = target.primaryKey;
|
|
2494
|
+
if (primaryKey.length !== referencedColumns.length || !primaryKey.every((column) => referencedColumns.includes(column))) continue;
|
|
2495
|
+
const label = searchableLabel(target);
|
|
2496
|
+
if (label === null) continue;
|
|
2497
|
+
if (fields.length === 1) {
|
|
2498
|
+
configs.push({
|
|
2499
|
+
field: fields[0],
|
|
2500
|
+
resource,
|
|
2501
|
+
...label
|
|
2502
|
+
});
|
|
2503
|
+
continue;
|
|
2504
|
+
}
|
|
2505
|
+
if (table.columns.some((c) => c.name === compositeParamName(fields[0]))) continue;
|
|
2506
|
+
const keyFields = primaryKey.map((column) => fields[referencedColumns.indexOf(column)]);
|
|
2507
|
+
configs.push({
|
|
2508
|
+
field: fields[0],
|
|
2509
|
+
fields: [...fields],
|
|
2510
|
+
keyFields,
|
|
2511
|
+
resource,
|
|
2512
|
+
...label
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
const claims = /* @__PURE__ */ new Map();
|
|
2516
|
+
for (const relation of table.relations) for (const field of relation.fields ?? [relation.field]) claims.set(field, (claims.get(field) ?? 0) + 1);
|
|
2517
|
+
return configs.filter((config) => {
|
|
2518
|
+
const fields = config.fields ?? [config.field];
|
|
2519
|
+
if (fields.length === 1) return true;
|
|
2520
|
+
return fields.every((field) => claims.get(field) === 1);
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
/**
|
|
2524
|
+
* Pick a scalar input widget for a column from its `dataType`.
|
|
2525
|
+
*
|
|
2526
|
+
* Used to demote a single-column foreign key that core marked `relation-select`
|
|
2527
|
+
* but that has no usable picker config (it references a non-PK unique column).
|
|
2528
|
+
* Without this it would render an empty, unselectable relation dropdown; the
|
|
2529
|
+
* scalar input lets the operator type the raw value instead. Mirrors the
|
|
2530
|
+
* type-based arm of core's widget inference, but keyed on the formatted
|
|
2531
|
+
* `dataType` exposed on `ColumnContext`.
|
|
2532
|
+
*/
|
|
2533
|
+
function scalarWidgetForDataType(dataType) {
|
|
2534
|
+
const type = dataType.toLowerCase();
|
|
2535
|
+
if (type === "uuid") return "uuid";
|
|
2536
|
+
if (type === "boolean" || type === "bool") return "boolean";
|
|
2537
|
+
if (type === "date") return "date";
|
|
2538
|
+
if (type.includes("timestamp") || type.startsWith("time")) return "datetime";
|
|
2539
|
+
if (type === "json" || type === "jsonb") return "json";
|
|
2540
|
+
if (type.includes("int") || type.includes("numeric") || type.includes("decimal") || type.includes("double") || type === "real") return "number";
|
|
2541
|
+
return "text";
|
|
2542
|
+
}
|
|
2543
|
+
/**
|
|
2544
|
+
* Return a copy of `table` with each unpickable single-column relation-select
|
|
2545
|
+
* column demoted to a scalar widget (see {@link scalarWidgetForDataType}).
|
|
2546
|
+
*
|
|
2547
|
+
* The create / edit routes build BOTH the rendered widget and the zod
|
|
2548
|
+
* validation schema from this, so a demoted field validates as the scalar type
|
|
2549
|
+
* the operator actually sees rather than the loose relation-select union.
|
|
2550
|
+
* Composite foreign-key columns are untouched: core never marks them
|
|
2551
|
+
* `relation-select` (they carry type-based scalar widgets), and the composite
|
|
2552
|
+
* picker writes through those scalar fields rather than replacing them.
|
|
2553
|
+
*/
|
|
2554
|
+
function demoteUnpickableRelations(table, relations) {
|
|
2555
|
+
const pickable = new Set(relations.filter((r) => (r.fields ?? [r.field]).length === 1).map((r) => r.field));
|
|
2556
|
+
return {
|
|
2557
|
+
...table,
|
|
2558
|
+
columns: table.columns.map((c) => c.widget === "relation-select" && !pickable.has(c.name) ? {
|
|
2559
|
+
...c,
|
|
2560
|
+
widget: scalarWidgetForDataType(c.dataType)
|
|
2561
|
+
} : c)
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* Return a copy of `table` with every composite-picker component column
|
|
2566
|
+
* switched to the `relation-select` widget, so the form layer treats it as a
|
|
2567
|
+
* picker-held value rather than a typed scalar input:
|
|
2568
|
+
*
|
|
2569
|
+
* - zodFromColumn applies the picker semantics: the unselected default is
|
|
2570
|
+
* `''` and a required component rejects an empty submission — without
|
|
2571
|
+
* this, superforms initializes an absent required numeric component to
|
|
2572
|
+
* `0`, and the suppressed (never-rendered) member columns would silently
|
|
2573
|
+
* submit a fabricated `(0, 0, ...)` reference;
|
|
2574
|
+
* - buildMutationPayload normalizes `''` to null (or drops it for a
|
|
2575
|
+
* DB-supplied column) instead of letting it coerce.
|
|
2576
|
+
*
|
|
2577
|
+
* The columns themselves are never rendered — the composite picker replaces
|
|
2578
|
+
* them — so the widget change is purely a validation / payload contract.
|
|
2579
|
+
* Apply AFTER {@link demoteUnpickableRelations} (which would demote the
|
|
2580
|
+
* promoted members straight back).
|
|
2581
|
+
*
|
|
2582
|
+
* Known limitation: the contract reserves '' as the unselected sentinel
|
|
2583
|
+
* (matching the single-column picker), so a key that contains an
|
|
2584
|
+
* EMPTY-STRING component cannot round-trip through the form — a required
|
|
2585
|
+
* component rejects it and an optional one normalizes it to null. The
|
|
2586
|
+
* picker therefore does not offer such options ({@link isPickableOption}),
|
|
2587
|
+
* the native decoder treats them as malformed, and the current-value seeding
|
|
2588
|
+
* skips them; an untouched edit save of a row already holding such a key
|
|
2589
|
+
* still normalizes the '' component (this predates composite support — the
|
|
2590
|
+
* single-column picker has the same property). Such keys are pathological
|
|
2591
|
+
* schema design and remain manageable through the API.
|
|
2592
|
+
*/
|
|
2593
|
+
function promoteCompositeMemberWidgets(table, relations) {
|
|
2594
|
+
const members = /* @__PURE__ */ new Set();
|
|
2595
|
+
for (const config of relations) {
|
|
2596
|
+
const fields = config.fields ?? [config.field];
|
|
2597
|
+
if (fields.length < 2) continue;
|
|
2598
|
+
for (const field of fields) members.add(field);
|
|
2599
|
+
}
|
|
2600
|
+
if (members.size === 0) return table;
|
|
2601
|
+
return {
|
|
2602
|
+
...table,
|
|
2603
|
+
columns: table.columns.map((c) => members.has(c.name) ? {
|
|
2604
|
+
...c,
|
|
2605
|
+
widget: "relation-select"
|
|
2606
|
+
} : c)
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
//#region ../../node_modules/.pnpm/memoize-weak@1.0.2/node_modules/memoize-weak/lib/memoize.js
|
|
2611
|
+
var require_memoize = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2612
|
+
function isPrimitive(value) {
|
|
2613
|
+
return typeof value !== "object" && typeof value !== "function" || value === null;
|
|
2614
|
+
}
|
|
2615
|
+
function MapTree() {
|
|
2616
|
+
this.childBranches = /* @__PURE__ */ new WeakMap();
|
|
2617
|
+
this.primitiveKeys = /* @__PURE__ */ new Map();
|
|
2618
|
+
this.hasValue = false;
|
|
2619
|
+
this.value = void 0;
|
|
2620
|
+
}
|
|
2621
|
+
MapTree.prototype.has = function has(key) {
|
|
2622
|
+
var keyObject = isPrimitive(key) ? this.primitiveKeys.get(key) : key;
|
|
2623
|
+
return keyObject ? this.childBranches.has(keyObject) : false;
|
|
2624
|
+
};
|
|
2625
|
+
MapTree.prototype.get = function get(key) {
|
|
2626
|
+
var keyObject = isPrimitive(key) ? this.primitiveKeys.get(key) : key;
|
|
2627
|
+
return keyObject ? this.childBranches.get(keyObject) : void 0;
|
|
2628
|
+
};
|
|
2629
|
+
MapTree.prototype.resolveBranch = function resolveBranch(key) {
|
|
2630
|
+
if (this.has(key)) return this.get(key);
|
|
2631
|
+
var newBranch = new MapTree();
|
|
2632
|
+
var keyObject = this.createKey(key);
|
|
2633
|
+
this.childBranches.set(keyObject, newBranch);
|
|
2634
|
+
return newBranch;
|
|
2635
|
+
};
|
|
2636
|
+
MapTree.prototype.setValue = function setValue(value) {
|
|
2637
|
+
this.hasValue = true;
|
|
2638
|
+
return this.value = value;
|
|
2639
|
+
};
|
|
2640
|
+
MapTree.prototype.createKey = function createKey(key) {
|
|
2641
|
+
if (isPrimitive(key)) {
|
|
2642
|
+
var keyObject = {};
|
|
2643
|
+
this.primitiveKeys.set(key, keyObject);
|
|
2644
|
+
return keyObject;
|
|
2645
|
+
}
|
|
2646
|
+
return key;
|
|
2647
|
+
};
|
|
2648
|
+
MapTree.prototype.clear = function clear() {
|
|
2649
|
+
if (arguments.length === 0) {
|
|
2650
|
+
this.childBranches = /* @__PURE__ */ new WeakMap();
|
|
2651
|
+
this.primitiveKeys.clear();
|
|
2652
|
+
this.hasValue = false;
|
|
2653
|
+
this.value = void 0;
|
|
2654
|
+
} else if (arguments.length === 1) {
|
|
2655
|
+
var key = arguments[0];
|
|
2656
|
+
if (isPrimitive(key)) {
|
|
2657
|
+
var keyObject = this.primitiveKeys.get(key);
|
|
2658
|
+
if (keyObject) {
|
|
2659
|
+
this.childBranches.delete(keyObject);
|
|
2660
|
+
this.primitiveKeys.delete(key);
|
|
2661
|
+
}
|
|
2662
|
+
} else this.childBranches.delete(key);
|
|
2663
|
+
} else {
|
|
2664
|
+
var childKey = arguments[0];
|
|
2665
|
+
if (this.has(childKey)) {
|
|
2666
|
+
var childBranch = this.get(childKey);
|
|
2667
|
+
childBranch.clear.apply(childBranch, Array.prototype.slice.call(arguments, 1));
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
};
|
|
2671
|
+
module.exports = function memoize(fn) {
|
|
2672
|
+
var argsTree = new MapTree();
|
|
2673
|
+
function memoized() {
|
|
2674
|
+
var args = Array.prototype.slice.call(arguments);
|
|
2675
|
+
var argNode = args.reduce(function getBranch(parentBranch, arg) {
|
|
2676
|
+
return parentBranch.resolveBranch(arg);
|
|
2677
|
+
}, argsTree);
|
|
2678
|
+
if (argNode.hasValue) return argNode.value;
|
|
2679
|
+
var value = fn.apply(null, args);
|
|
2680
|
+
return argNode.setValue(value);
|
|
2681
|
+
}
|
|
2682
|
+
memoized.clear = argsTree.clear.bind(argsTree);
|
|
2683
|
+
return memoized;
|
|
2684
|
+
};
|
|
2685
|
+
}));
|
|
2686
|
+
var memoize = (/* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2687
|
+
module.exports = require_memoize();
|
|
2688
|
+
})))())).default;
|
|
2689
|
+
/**
|
|
2690
|
+
* Joi Validation Object
|
|
2691
|
+
* @typedef {object} JoiValidation
|
|
2692
|
+
*/
|
|
2693
|
+
/**
|
|
2694
|
+
* Transformation Function - applied just before `convert()` returns and called as `function(object):object`
|
|
2695
|
+
* @typedef {function} TransformFunction
|
|
2696
|
+
*/
|
|
2697
|
+
/**
|
|
2698
|
+
* JSON Schema Object
|
|
2699
|
+
* @typedef {object} JSONSchema
|
|
2700
|
+
*/
|
|
2701
|
+
//#endregion
|
|
2702
|
+
//#region ../../node_modules/.pnpm/typebox@1.3.8/node_modules/typebox/build/system/hashing/hash.mjs
|
|
2703
|
+
var ByteMarker;
|
|
2704
|
+
(function(ByteMarker) {
|
|
2705
|
+
ByteMarker[ByteMarker["Array"] = 0] = "Array";
|
|
2706
|
+
ByteMarker[ByteMarker["BigInt"] = 1] = "BigInt";
|
|
2707
|
+
ByteMarker[ByteMarker["Boolean"] = 2] = "Boolean";
|
|
2708
|
+
ByteMarker[ByteMarker["Date"] = 3] = "Date";
|
|
2709
|
+
ByteMarker[ByteMarker["Constructor"] = 4] = "Constructor";
|
|
2710
|
+
ByteMarker[ByteMarker["Function"] = 5] = "Function";
|
|
2711
|
+
ByteMarker[ByteMarker["Null"] = 6] = "Null";
|
|
2712
|
+
ByteMarker[ByteMarker["Number"] = 7] = "Number";
|
|
2713
|
+
ByteMarker[ByteMarker["Object"] = 8] = "Object";
|
|
2714
|
+
ByteMarker[ByteMarker["RegExp"] = 9] = "RegExp";
|
|
2715
|
+
ByteMarker[ByteMarker["String"] = 10] = "String";
|
|
2716
|
+
ByteMarker[ByteMarker["Symbol"] = 11] = "Symbol";
|
|
2717
|
+
ByteMarker[ByteMarker["TypeArray"] = 12] = "TypeArray";
|
|
2718
|
+
ByteMarker[ByteMarker["Undefined"] = 13] = "Undefined";
|
|
2719
|
+
})(ByteMarker || (ByteMarker = {}));
|
|
2720
|
+
Array.from({ length: 256 }).map((_, i) => BigInt(i));
|
|
2721
|
+
var F64 = new Float64Array(1);
|
|
2722
|
+
new DataView(F64.buffer);
|
|
2723
|
+
new Uint8Array(F64.buffer);
|
|
2724
|
+
new TextEncoder();
|
|
2725
|
+
//#endregion
|
|
2726
|
+
//#region ../../node_modules/.pnpm/typebox@1.3.8/node_modules/typebox/build/type/script/token/internal/char.mjs
|
|
2727
|
+
function Range(start, end) {
|
|
2728
|
+
return Array.from({ length: end - start + 1 }, (_, i) => String.fromCharCode(start + i));
|
|
2729
|
+
}
|
|
2730
|
+
[...Range(97, 122), ...Range(65, 90)];
|
|
2731
|
+
["0", ...Range(49, 57)];
|
|
2732
|
+
//#endregion
|
|
2733
|
+
//#region ../../node_modules/.pnpm/sveltekit-superforms@2.30.2_@sveltejs+kit@2.70.1_@sveltejs+vite-plugin-svelte@7.1.2_sve_7a66204ca948e44eef2d0ac937337446/node_modules/sveltekit-superforms/dist/adapters/zod4.js
|
|
2734
|
+
var defaultJSONSchemaOptions = {
|
|
2735
|
+
unrepresentable: "any",
|
|
2736
|
+
override: (ctx) => {
|
|
2737
|
+
const def = ctx.zodSchema._zod.def;
|
|
2738
|
+
if (def.type === "date") {
|
|
2739
|
+
ctx.jsonSchema.type = "integer";
|
|
2740
|
+
ctx.jsonSchema.format = "unix-time";
|
|
2741
|
+
} else if (def.type === "bigint") {
|
|
2742
|
+
ctx.jsonSchema.type = "string";
|
|
2743
|
+
ctx.jsonSchema.format = "bigint";
|
|
2744
|
+
} else if (def.type === "pipe") {
|
|
2745
|
+
const pipeDef = def;
|
|
2746
|
+
const inSchema = pipeDef.in;
|
|
2747
|
+
const outSchema = pipeDef.out;
|
|
2748
|
+
if (inSchema?._zod?.def.type === "string") {
|
|
2749
|
+
let currentSchema = outSchema;
|
|
2750
|
+
let isStringBool = false;
|
|
2751
|
+
while (currentSchema?._zod?.def) {
|
|
2752
|
+
const currentDef = currentSchema._zod.def;
|
|
2753
|
+
if (currentDef.type === "boolean") {
|
|
2754
|
+
isStringBool = true;
|
|
2755
|
+
break;
|
|
2756
|
+
} else if (currentDef.type === "transform") break;
|
|
2757
|
+
else if (currentDef.type === "pipe") currentSchema = currentDef.out;
|
|
2758
|
+
else break;
|
|
2759
|
+
}
|
|
2760
|
+
if (!isStringBool && outSchema?._zod?.def.type === "boolean") isStringBool = true;
|
|
2761
|
+
if (isStringBool) {
|
|
2762
|
+
ctx.jsonSchema.type = "string";
|
|
2763
|
+
ctx.jsonSchema.format = "stringbool";
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2766
|
+
} else if (def.type === "set") {
|
|
2767
|
+
ctx.jsonSchema.type = "array";
|
|
2768
|
+
ctx.jsonSchema.uniqueItems = true;
|
|
2769
|
+
if ("default" in ctx.jsonSchema && ctx.jsonSchema.default instanceof Set) ctx.jsonSchema.default = Array.from(ctx.jsonSchema.default);
|
|
2770
|
+
} else if (def.type === "map") {
|
|
2771
|
+
ctx.jsonSchema.type = "array";
|
|
2772
|
+
ctx.jsonSchema.format = "map";
|
|
2773
|
+
if ("default" in ctx.jsonSchema && ctx.jsonSchema.default instanceof Map) ctx.jsonSchema.default = Array.from(ctx.jsonSchema.default);
|
|
2774
|
+
} else if (def.type === "default") {
|
|
2775
|
+
const innerDef = def.innerType._zod.def;
|
|
2776
|
+
if (innerDef.type === "set" && def.defaultValue instanceof Set) {
|
|
2777
|
+
ctx.jsonSchema.type = "array";
|
|
2778
|
+
ctx.jsonSchema.uniqueItems = true;
|
|
2779
|
+
ctx.jsonSchema.default = Array.from(def.defaultValue);
|
|
2780
|
+
} else if (innerDef.type === "map" && def.defaultValue instanceof Map) {
|
|
2781
|
+
ctx.jsonSchema.type = "array";
|
|
2782
|
+
ctx.jsonSchema.format = "map";
|
|
2783
|
+
ctx.jsonSchema.default = Array.from(def.defaultValue);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
};
|
|
2788
|
+
var zodToJSONSchema = /* @__NO_SIDE_EFFECTS__ */ (schema, options) => {
|
|
2789
|
+
return toJSONSchema(schema, {
|
|
2790
|
+
...defaultJSONSchemaOptions,
|
|
2791
|
+
...options
|
|
2792
|
+
});
|
|
2793
|
+
};
|
|
2794
|
+
async function validate(schema, data, error) {
|
|
2795
|
+
if (error === void 0) {
|
|
2796
|
+
const zConfig = config();
|
|
2797
|
+
error = zConfig.customError ?? zConfig.localeError;
|
|
2798
|
+
}
|
|
2799
|
+
const result = await safeParseAsync(schema, data, { error });
|
|
2800
|
+
if (result.success) return {
|
|
2801
|
+
data: result.data,
|
|
2802
|
+
success: true
|
|
2803
|
+
};
|
|
2804
|
+
return {
|
|
2805
|
+
issues: result.error.issues.map(({ message, path }) => ({
|
|
2806
|
+
message,
|
|
2807
|
+
path
|
|
2808
|
+
})),
|
|
2809
|
+
success: false
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
function _zod4(schema, options) {
|
|
2813
|
+
return /* @__PURE__ */ createAdapter({
|
|
2814
|
+
superFormValidationLibrary: "zod4",
|
|
2815
|
+
validate: async (data) => {
|
|
2816
|
+
return validate(schema, data, options?.error);
|
|
2817
|
+
},
|
|
2818
|
+
jsonSchema: options?.jsonSchema ?? /* @__PURE__ */ zodToJSONSchema(schema, options?.config),
|
|
2819
|
+
defaults: options?.defaults
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
var zod = /* @__PURE__ */ memoize(_zod4);
|
|
2823
|
+
//#endregion
|
|
2824
|
+
//#region src/lib/form/zod-from-column.ts
|
|
2825
|
+
function dbCanSupplyColumn(column) {
|
|
2826
|
+
return column.defaultExpr !== null || column.readonly;
|
|
2827
|
+
}
|
|
2828
|
+
function zodFromColumn(column) {
|
|
2829
|
+
if (column.widget === "relation-select") {
|
|
2830
|
+
const required = !column.nullable && !dbCanSupplyColumn(column);
|
|
2831
|
+
const id = z.union([required ? z.string().min(1) : z.string(), z.number()]);
|
|
2832
|
+
return (column.nullable ? id.nullable() : id).default("");
|
|
2833
|
+
}
|
|
2834
|
+
const base = pickBase(column);
|
|
2835
|
+
if (dbCanSupplyColumn(column)) {
|
|
2836
|
+
const inner = column.nullable ? base.nullable() : base;
|
|
2837
|
+
return z.union([z.literal(""), inner]).default("");
|
|
2838
|
+
}
|
|
2839
|
+
if (column.nullable) return base.nullable();
|
|
2840
|
+
return base;
|
|
2841
|
+
}
|
|
2842
|
+
function pickBase(column) {
|
|
2843
|
+
switch (column.widget) {
|
|
2844
|
+
case "number":
|
|
2845
|
+
case "currency": return z.coerce.number();
|
|
2846
|
+
case "boolean": return z.coerce.boolean();
|
|
2847
|
+
case "date":
|
|
2848
|
+
case "datetime": return z.coerce.date();
|
|
2849
|
+
case "enum-select":
|
|
2850
|
+
if (column.enumValues && column.enumValues.length > 0) return z.enum(column.enumValues);
|
|
2851
|
+
return z.string();
|
|
2852
|
+
case "uuid": return z.guid();
|
|
2853
|
+
case "json": return z.unknown();
|
|
2854
|
+
case "image-url":
|
|
2855
|
+
case "text":
|
|
2856
|
+
case "textarea": return z.string();
|
|
2857
|
+
default: return z.string();
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
//#endregion
|
|
2861
|
+
//#region src/lib/form/mutation-payload.ts
|
|
2862
|
+
function isEmpty(value) {
|
|
2863
|
+
return value === "" || value === void 0;
|
|
2864
|
+
}
|
|
2865
|
+
function buildMutationPayload(table, data, mode = "create") {
|
|
2866
|
+
const byName = new Map(table.columns.map((c) => [c.name, c]));
|
|
2867
|
+
const payload = {};
|
|
2868
|
+
for (const [key, value] of Object.entries(data)) {
|
|
2869
|
+
const column = byName.get(key);
|
|
2870
|
+
if (column?.readonly) continue;
|
|
2871
|
+
if (column?.widget === "relation-select" && value === "") {
|
|
2872
|
+
if (!(dbCanSupplyColumn(column) && (mode === "create" || column.readonly || !column.nullable))) {
|
|
2873
|
+
payload[key] = null;
|
|
2874
|
+
continue;
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
if (column && dbCanSupplyColumn(column) && isEmpty(value)) continue;
|
|
2878
|
+
payload[key] = value;
|
|
2879
|
+
}
|
|
2880
|
+
return payload;
|
|
2881
|
+
}
|
|
2882
|
+
//#endregion
|
|
2883
|
+
//#region src/lib/form/zod-from-table.ts
|
|
2884
|
+
function zodFromTable(table) {
|
|
2885
|
+
const shape = {};
|
|
2886
|
+
for (const column of table.columns) shape[column.name] = zodFromColumn(column);
|
|
2887
|
+
return z.object(shape);
|
|
2888
|
+
}
|
|
2889
|
+
//#endregion
|
|
2890
|
+
//#region src/lib/server/composite-form.ts
|
|
2891
|
+
/** A native FormData submission converted to a plain object, with blank
|
|
2892
|
+
* fields omitted so the schema defaults apply (mirroring how superforms
|
|
2893
|
+
* parses blank FormData entries). */
|
|
2894
|
+
function formDataToObject(data) {
|
|
2895
|
+
const fields = {};
|
|
2896
|
+
for (const [key, value] of data.entries()) if (typeof value === "string" && value !== "") fields[key] = value;
|
|
2897
|
+
return fields;
|
|
2898
|
+
}
|
|
2899
|
+
/**
|
|
2900
|
+
* What the RPC action route should hand to `superValidate`. A defaulted
|
|
2901
|
+
* argument carries a `z.union([literal(''), <base>])` schema, and superforms
|
|
2902
|
+
* rejects unions when parsing FormData directly ("Unions are only supported
|
|
2903
|
+
* when the dataType option for superForm is set to 'json'"); parsing a plain
|
|
2904
|
+
* object has no such restriction. So a native (no-JS) submission is converted
|
|
2905
|
+
* to an object — unconditionally, since an action form can carry a defaulted
|
|
2906
|
+
* non-text argument with no relation pickers at all. The enhanced path's
|
|
2907
|
+
* superforms JSON envelope is passed through untouched (superValidate handles
|
|
2908
|
+
* it), as is a non-form (JSON) body. Single-column relation-select arguments
|
|
2909
|
+
* submit as plain fields, so no composite decoding is needed here.
|
|
2910
|
+
*/
|
|
2911
|
+
async function readActionFormSubmission(request) {
|
|
2912
|
+
const contentType = request.headers.get("content-type") ?? "";
|
|
2913
|
+
if (!contentType.includes("application/x-www-form-urlencoded") && !contentType.includes("multipart/form-data")) return request;
|
|
2914
|
+
const data = await request.formData();
|
|
2915
|
+
if (data.has("__superform_json")) return data;
|
|
2916
|
+
return formDataToObject(data);
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Return what the route action should hand to `superValidate`: the request
|
|
2920
|
+
* itself when the table has no pickers, the raw FormData when it carries the
|
|
2921
|
+
* enhanced JSON envelope, or a plain object holding the native submission
|
|
2922
|
+
* with each composite pick decoded into its component fields. Returns `null`
|
|
2923
|
+
* for a malformed composite control — wrong arity, invalid percent-encoding,
|
|
2924
|
+
* or an empty-string component — so the action can reject the submission:
|
|
2925
|
+
* letting it fall through to the schema defaults would silently CLEAR an
|
|
2926
|
+
* optional relation instead of reporting the bad value (a required one
|
|
2927
|
+
* already fails validation through the '' defaults).
|
|
2928
|
+
*/
|
|
2929
|
+
async function readFormWithCompositePicks(request, relations) {
|
|
2930
|
+
if (relations.length === 0) return request;
|
|
2931
|
+
const contentType = request.headers.get("content-type") ?? "";
|
|
2932
|
+
if (!contentType.includes("application/x-www-form-urlencoded") && !contentType.includes("multipart/form-data")) return request;
|
|
2933
|
+
const data = await request.formData();
|
|
2934
|
+
if (data.has("__superform_json")) return data;
|
|
2935
|
+
const fields = formDataToObject(data);
|
|
2936
|
+
for (const config of relations) {
|
|
2937
|
+
const keyFields = config.keyFields ?? [config.field];
|
|
2938
|
+
if (keyFields.length < 2) continue;
|
|
2939
|
+
const param = compositeParamName(config.field);
|
|
2940
|
+
const raw = fields[param];
|
|
2941
|
+
if (typeof raw !== "string") continue;
|
|
2942
|
+
delete fields[param];
|
|
2943
|
+
if (raw === "") continue;
|
|
2944
|
+
if (raw === "__clear__") {
|
|
2945
|
+
for (const field of keyFields) delete fields[field];
|
|
2946
|
+
continue;
|
|
2947
|
+
}
|
|
2948
|
+
let components;
|
|
2949
|
+
try {
|
|
2950
|
+
components = raw.split(",").map((part) => decodeURIComponent(part));
|
|
2951
|
+
} catch {
|
|
2952
|
+
return null;
|
|
2953
|
+
}
|
|
2954
|
+
if (components.length !== keyFields.length) return null;
|
|
2955
|
+
if (components.some((part) => part === "")) return null;
|
|
2956
|
+
keyFields.forEach((field, i) => {
|
|
2957
|
+
fields[field] = components[i];
|
|
2958
|
+
});
|
|
2959
|
+
}
|
|
2960
|
+
return fields;
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
export { COMPOSITE_CLEAR_VALUE as C, buildMutationPayload as a, buildArgRelationConfig as b, compositeParamName as c, dbCanSupplyColumn as d, demoteUnpickableRelations as e, readFormWithCompositePicks as f, relationFieldConfigs as g, superForm as h, isPickableOption as i, superValidate as j, zodFromTable as k, promoteCompositeMemberWidgets as p, readActionFormSubmission as r, scalarWidgetForDataType as s, zod as z };
|
|
2964
|
+
//# sourceMappingURL=composite-form-KsMxMbgc.js.map
|