keits 0.1.0 → 0.1.2
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/dist/dev/forms.js +4 -1
- package/dist/dev/index.js +5 -3
- package/dist/dev/shared/element-Bgf6SNbW.js +21 -0
- package/dist/dev/shared/{hydrate-C8cOsDDH.js → hydrate-g_akkVyT.js} +1 -1
- package/dist/dev/shared/{element-DXwmUAnz.js → insert-DadcXJL8.js} +97 -21
- package/dist/dev/shared/{mount-CDB2HgN5.js → mount-BtpMEhSZ.js} +1 -1
- package/dist/dev/static.js +2 -2
- package/dist/dev/svg.js +2 -2
- package/dist/dev/testing.js +32 -12
- package/dist/prod/forms.js +40 -38
- package/dist/prod/index.js +36 -36
- package/dist/prod/shared/element-B-0tH1YW.js +15 -0
- package/dist/prod/shared/{hydrate-kKnJbkV7.js → hydrate-DhHCtdOz.js} +28 -28
- package/dist/prod/shared/insert-CbcOsYmu.js +192 -0
- package/dist/prod/shared/{mount-DbeKIoyD.js → mount-BEAO35S_.js} +1 -1
- package/dist/prod/static.js +2 -2
- package/dist/prod/svg.js +2 -2
- package/dist/prod/testing.js +35 -18
- package/dist/types/api/client.d.ts +2 -2
- package/dist/types/api/index.d.ts +3 -3
- package/dist/types/async/index.d.ts +2 -2
- package/dist/types/async/lazy.d.ts +1 -1
- package/dist/types/async/render-context.d.ts +2 -2
- package/dist/types/async/resource.d.ts +1 -1
- package/dist/types/async/suspense-context.d.ts +1 -1
- package/dist/types/core/computed.d.ts +1 -1
- package/dist/types/core/signal.d.ts +2 -2
- package/dist/types/dom/element.d.ts +1 -1
- package/dist/types/dom/index.d.ts +6 -6
- package/dist/types/dom/insert.d.ts +1 -1
- package/dist/types/dom/mount.d.ts +1 -1
- package/dist/types/dom/props.d.ts +2 -0
- package/dist/types/dom/tags.d.ts +112 -112
- package/dist/types/flow/catch.d.ts +1 -1
- package/dist/types/flow/dynamic.d.ts +1 -1
- package/dist/types/flow/for.d.ts +2 -2
- package/dist/types/flow/if.d.ts +2 -2
- package/dist/types/flow/index.d.ts +8 -8
- package/dist/types/flow/portal.d.ts +1 -1
- package/dist/types/flow/range.d.ts +1 -1
- package/dist/types/flow/suspense.d.ts +1 -1
- package/dist/types/flow/switch.d.ts +1 -1
- package/dist/types/forms/form.d.ts +3 -3
- package/dist/types/forms/index.d.ts +2 -2
- package/dist/types/index.d.ts +12 -12
- package/dist/types/router/index.d.ts +4 -4
- package/dist/types/router/match.d.ts +1 -1
- package/dist/types/router/router.d.ts +2 -2
- package/dist/types/router/types.d.ts +2 -2
- package/dist/types/static/head.d.ts +2 -2
- package/dist/types/static/hydrate.d.ts +1 -1
- package/dist/types/static/index.d.ts +4 -4
- package/dist/types/static/island.d.ts +1 -1
- package/dist/types/static/render.d.ts +1 -1
- package/dist/types/static/server-dom.d.ts +1 -1
- package/dist/types/svg/element.d.ts +1 -1
- package/dist/types/svg/index.d.ts +3 -3
- package/dist/types/svg/tags.d.ts +63 -63
- package/dist/types/svg/types.d.ts +1 -1
- package/dist/types/testing/index.d.ts +13 -6
- package/dist/types/vite/index.d.ts +1 -1
- package/package.json +8 -8
- package/dist/dev/shared/namespaces-Cz82B0Pr.js +0 -84
- package/dist/prod/shared/element-DCit4-3e.js +0 -129
- package/dist/prod/shared/namespaces-BSRrBJIU.js +0 -71
package/dist/dev/forms.js
CHANGED
|
@@ -95,6 +95,7 @@ function form(options) {
|
|
|
95
95
|
const submitting = signal(false);
|
|
96
96
|
const validating = signal(false);
|
|
97
97
|
let checkId = 0;
|
|
98
|
+
let resets = 0;
|
|
98
99
|
const read = (value) => typeof value === "function" ? value() : value;
|
|
99
100
|
const snapshot = () => structuredClone(unwrap(values));
|
|
100
101
|
const runChecks = () => {
|
|
@@ -282,8 +283,9 @@ function form(options) {
|
|
|
282
283
|
focusFirstError();
|
|
283
284
|
return false;
|
|
284
285
|
}
|
|
286
|
+
const resetsBefore = resets;
|
|
285
287
|
await handler(options.schema ? checked.output : sent);
|
|
286
|
-
baseline.set(() => sent);
|
|
288
|
+
if (resets === resetsBefore) baseline.set(() => sent);
|
|
287
289
|
return true;
|
|
288
290
|
} catch (error) {
|
|
289
291
|
if (result.setErrors(error)) {
|
|
@@ -298,6 +300,7 @@ function form(options) {
|
|
|
298
300
|
},
|
|
299
301
|
reset(next) {
|
|
300
302
|
const start = structuredClone(next ?? untrack(baseline));
|
|
303
|
+
resets++;
|
|
301
304
|
batch(() => {
|
|
302
305
|
setValues((draft) => replaceKeys(draft, structuredClone(start)));
|
|
303
306
|
baseline.set(() => start);
|
package/dist/dev/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { S as untrack, a as deferMounts, f as isStaticRender, i as batch, m as n
|
|
|
5
5
|
import { a as onCleanup, c as runWithOwner, n as createRoot, o as onMount, r as getOwner, s as renderStatic, t as catchError } from "./shared/owner-BuwIoI4j.js";
|
|
6
6
|
import { a as provide, i as createContext, o as useContext } from "./shared/render-context-k2uu_dM_.js";
|
|
7
7
|
import { n as store, r as unwrap, t as reconcile } from "./shared/store-0vEg2bQV.js";
|
|
8
|
-
import { n as html } from "./shared/element-
|
|
9
|
-
import {
|
|
10
|
-
import { t as mount } from "./shared/mount-
|
|
8
|
+
import { n as html } from "./shared/element-Bgf6SNbW.js";
|
|
9
|
+
import { l as withoutClaims, r as restoreSelectValue, s as hooks, t as insert } from "./shared/insert-DadcXJL8.js";
|
|
10
|
+
import { t as mount } from "./shared/mount-BtpMEhSZ.js";
|
|
11
11
|
import { n as SuspenseContext, t as resource } from "./shared/resource-DlgzdtcG.js";
|
|
12
12
|
// src/core/env.ts
|
|
13
13
|
var isServer = typeof window === "undefined";
|
|
@@ -204,6 +204,7 @@ function $for(each, render, options) {
|
|
|
204
204
|
fallback = createRow(options.fallback, null);
|
|
205
205
|
moveRow(parent, fallback, end);
|
|
206
206
|
}
|
|
207
|
+
restoreSelectValue(parent);
|
|
207
208
|
return;
|
|
208
209
|
}
|
|
209
210
|
if (fallback !== null) {
|
|
@@ -240,6 +241,7 @@ function $for(each, render, options) {
|
|
|
240
241
|
anchor = row.first;
|
|
241
242
|
}
|
|
242
243
|
rows = next;
|
|
244
|
+
restoreSelectValue(parent);
|
|
243
245
|
}
|
|
244
246
|
function createItemRow(item, i) {
|
|
245
247
|
let setIndex = () => {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { n as applyProps, s as hooks, t as insert } from "./insert-DadcXJL8.js";
|
|
2
|
+
// src/dom/element.ts
|
|
3
|
+
function html(tag) {
|
|
4
|
+
return createFactory(tag, null);
|
|
5
|
+
}
|
|
6
|
+
function createFactory(tag, namespace) {
|
|
7
|
+
return (first, children) => {
|
|
8
|
+
const element = hooks.element(tag, namespace);
|
|
9
|
+
if (isProps(first)) {
|
|
10
|
+
insert(element, children);
|
|
11
|
+
applyProps(element, first);
|
|
12
|
+
if (typeof first.ref === "function") first.ref(element);
|
|
13
|
+
} else if (first === null || first === void 0) insert(element, children);
|
|
14
|
+
else insert(element, first);
|
|
15
|
+
return element;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function isProps(value) {
|
|
19
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.nodeType !== "number";
|
|
20
|
+
}
|
|
21
|
+
export { html as n, createFactory as t };
|
|
@@ -2,7 +2,7 @@ import { b as stopKeys, c as getOwner, d as insideHydratable, m as nextKey, v as
|
|
|
2
2
|
import { t as renderEffect } from "./render-effect-Uk9dDmuU.js";
|
|
3
3
|
import { a as onCleanup, i as keyedRoot } from "./owner-BuwIoI4j.js";
|
|
4
4
|
import { a as provide, i as createContext, o as useContext, r as setHydratedValue, t as RenderContext } from "./render-context-k2uu_dM_.js";
|
|
5
|
-
import {
|
|
5
|
+
import { a as claimsPaused, c as setHooks, i as SVG_NS, o as defaultHooks, t as insert } from "./insert-DadcXJL8.js";
|
|
6
6
|
// src/static/json.ts
|
|
7
7
|
function scriptJson(value) {
|
|
8
8
|
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
import { a as hooks, n as insert } from "./namespaces-Cz82B0Pr.js";
|
|
2
1
|
import { _ as runWithOwner, c as getOwner, f as isStaticRender, i as batch, u as handleError } from "./graph-SIvYLXSv.js";
|
|
3
2
|
import { t as UNSAFE_KEYS } from "./unsafe-keys-CB1P22No.js";
|
|
4
3
|
import { t as renderEffect } from "./render-effect-Uk9dDmuU.js";
|
|
4
|
+
// src/dom/hooks.ts
|
|
5
|
+
var defaultHooks = {
|
|
6
|
+
element: (tag, namespace) => namespace === null ? document.createElement(tag) : document.createElementNS(namespace, tag),
|
|
7
|
+
text: (value) => document.createTextNode(value),
|
|
8
|
+
marker: () => document.createComment(""),
|
|
9
|
+
fragment: () => document.createDocumentFragment()
|
|
10
|
+
};
|
|
11
|
+
var claimPauses = 0;
|
|
12
|
+
function withoutClaims(fn) {
|
|
13
|
+
claimPauses++;
|
|
14
|
+
try {
|
|
15
|
+
return fn();
|
|
16
|
+
} finally {
|
|
17
|
+
claimPauses--;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function claimsPaused() {
|
|
21
|
+
return claimPauses > 0;
|
|
22
|
+
}
|
|
23
|
+
var hooks = defaultHooks;
|
|
24
|
+
function setHooks(next) {
|
|
25
|
+
const previous = hooks;
|
|
26
|
+
hooks = next;
|
|
27
|
+
return previous;
|
|
28
|
+
}
|
|
5
29
|
// src/dom/events.ts
|
|
6
30
|
function applyEvent(element, key, value) {
|
|
7
31
|
let handler = value;
|
|
@@ -27,6 +51,8 @@ function listen(element, type, handler, options) {
|
|
|
27
51
|
function isPromiseLike(value) {
|
|
28
52
|
return typeof value?.then === "function";
|
|
29
53
|
}
|
|
54
|
+
// src/dom/namespaces.ts
|
|
55
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
30
56
|
// src/dom/props.ts
|
|
31
57
|
var UNSAFE_PROPS = /* @__PURE__ */ new Set([
|
|
32
58
|
"innerhtml",
|
|
@@ -68,10 +94,23 @@ function setProp(element, key, value) {
|
|
|
68
94
|
if (key in element && element.namespaceURI !== "http://www.w3.org/2000/svg") {
|
|
69
95
|
element[key] = value;
|
|
70
96
|
if (isStaticRender()) reflectForStatic(element, key, value);
|
|
97
|
+
else if (key === "value" && element.localName === "select") rememberSelectValue(element, value);
|
|
71
98
|
} else if (key.startsWith("aria-") && typeof value === "boolean") element.setAttribute(key, String(value));
|
|
72
99
|
else if (value === null || value === void 0 || value === false) element.removeAttribute(key);
|
|
73
100
|
else element.setAttribute(key, value === true ? "" : String(value));
|
|
74
101
|
}
|
|
102
|
+
var selectValues = /* @__PURE__ */ new WeakMap();
|
|
103
|
+
function rememberSelectValue(select, value) {
|
|
104
|
+
if (!selectValues.has(select)) select.addEventListener("change", () => selectValues.set(select, select.value));
|
|
105
|
+
selectValues.set(select, value == null ? "" : String(value));
|
|
106
|
+
}
|
|
107
|
+
/** After keits changes the children of `parent`: if it's (in) a <select> given a `value`, select that value again. */
|
|
108
|
+
function restoreSelectValue(parent) {
|
|
109
|
+
let select = parent;
|
|
110
|
+
if (select?.localName === "optgroup") select = select.parentElement;
|
|
111
|
+
const wanted = select && selectValues.get(select);
|
|
112
|
+
if (wanted != null && select.value !== wanted) select.value = wanted;
|
|
113
|
+
}
|
|
75
114
|
function isJavaScriptUrl(url) {
|
|
76
115
|
return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().split(";").some((part) => part.startsWith("javascript:"));
|
|
77
116
|
}
|
|
@@ -154,23 +193,60 @@ function writeStyle(style, name, value) {
|
|
|
154
193
|
if (value === null || value === void 0 || value === "") style.removeProperty(name);
|
|
155
194
|
else style.setProperty(name, String(value));
|
|
156
195
|
}
|
|
157
|
-
// src/dom/
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
196
|
+
// src/dom/insert.ts
|
|
197
|
+
function insert(parent, child, before = null) {
|
|
198
|
+
if (child === null || child === void 0 || typeof child === "boolean") return;
|
|
199
|
+
if (typeof child === "function") return insertDynamic(parent, child, before);
|
|
200
|
+
if (isChildArray(child)) {
|
|
201
|
+
for (const item of child) insert(parent, item, before);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (typeof child === "object") {
|
|
205
|
+
if (!child.nodeType) throw new Error("[keits] A child is a plain object, not text or an element. If it came from an API, check its type (see parse), or write String(value).");
|
|
206
|
+
parent.insertBefore(child, before);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
parent.insertBefore(hooks.text(String(child)), before);
|
|
210
|
+
}
|
|
211
|
+
function isChildArray(value) {
|
|
212
|
+
return Array.isArray(value);
|
|
213
|
+
}
|
|
214
|
+
function isTextValue(value) {
|
|
215
|
+
return value === null || typeof value !== "object" && typeof value !== "function";
|
|
216
|
+
}
|
|
217
|
+
function toText(value) {
|
|
218
|
+
return value === null || value === void 0 || typeof value === "boolean" ? "" : String(value);
|
|
219
|
+
}
|
|
220
|
+
function insertDynamic(parent, fn, before) {
|
|
221
|
+
const text = hooks.text("");
|
|
222
|
+
parent.insertBefore(text, before);
|
|
223
|
+
let start = null;
|
|
224
|
+
let end = null;
|
|
225
|
+
renderEffect(() => {
|
|
226
|
+
const value = fn();
|
|
227
|
+
if (start === null || end === null) {
|
|
228
|
+
if (isTextValue(value)) {
|
|
229
|
+
const next = toText(value);
|
|
230
|
+
if (text.data !== next) text.data = next;
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
start = hooks.marker();
|
|
234
|
+
end = hooks.marker();
|
|
235
|
+
text.before(start);
|
|
236
|
+
text.after(end);
|
|
237
|
+
text.remove();
|
|
238
|
+
}
|
|
239
|
+
clearRange(start, end);
|
|
240
|
+
insert(end.parentNode, value, end);
|
|
241
|
+
restoreSelectValue(end.parentNode);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function clearRange(start, end) {
|
|
245
|
+
let node = start.nextSibling;
|
|
246
|
+
while (node !== null && node !== end) {
|
|
247
|
+
const next = node.nextSibling;
|
|
248
|
+
node.remove();
|
|
249
|
+
node = next;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export { claimsPaused as a, setHooks as c, SVG_NS as i, withoutClaims as l, applyProps as n, defaultHooks as o, restoreSelectValue as r, hooks as s, insert as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as createRoot } from "./owner-BuwIoI4j.js";
|
|
2
|
-
import {
|
|
2
|
+
import { s as hooks, t as insert } from "./insert-DadcXJL8.js";
|
|
3
3
|
// src/dom/mount.ts
|
|
4
4
|
function mount(app, target) {
|
|
5
5
|
if (target === null) throw new Error("[keits] mount(): the target element was not found (null).");
|
package/dist/dev/static.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { i as head, r as renderToString, t as hydrate } from "./shared/hydrate-
|
|
1
|
+
import { i as head, r as renderToString, t as hydrate } from "./shared/hydrate-g_akkVyT.js";
|
|
2
2
|
import { c as getOwner, f as isStaticRender } from "./shared/graph-SIvYLXSv.js";
|
|
3
3
|
import { a as onCleanup, n as createRoot } from "./shared/owner-BuwIoI4j.js";
|
|
4
|
-
import {
|
|
4
|
+
import { s as hooks, t as insert } from "./shared/insert-DadcXJL8.js";
|
|
5
5
|
// src/static/island.ts
|
|
6
6
|
function island(name, component, options = {}) {
|
|
7
7
|
const render = (props) => {
|
package/dist/dev/svg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createFactory } from "./shared/element-
|
|
2
|
-
import {
|
|
1
|
+
import { t as createFactory } from "./shared/element-Bgf6SNbW.js";
|
|
2
|
+
import { i as SVG_NS } from "./shared/insert-DadcXJL8.js";
|
|
3
3
|
// src/svg/element.ts
|
|
4
4
|
function svg(tag) {
|
|
5
5
|
return createFactory(tag, SVG_NS);
|
package/dist/dev/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as mount } from "./shared/mount-
|
|
2
|
-
import { n as resetHydrationData, r as renderToString, t as hydrate } from "./shared/hydrate-
|
|
1
|
+
import { t as mount } from "./shared/mount-BtpMEhSZ.js";
|
|
2
|
+
import { n as resetHydrationData, r as renderToString, t as hydrate } from "./shared/hydrate-g_akkVyT.js";
|
|
3
3
|
// src/testing/index.ts
|
|
4
4
|
/**
|
|
5
5
|
* Testing helpers for keits apps (with Vitest + happy-dom or jsdom). Find things the way a user
|
|
@@ -118,8 +118,8 @@ function asField(element, action) {
|
|
|
118
118
|
/** The queries, scoped to `root`. */
|
|
119
119
|
function within(root) {
|
|
120
120
|
const all = () => [...root.querySelectorAll("*")];
|
|
121
|
-
const byText = (text) => {
|
|
122
|
-
const matching = all().filter((element) => matches(normalize(element.textContent ?? ""), text));
|
|
121
|
+
const byText = (text, options) => {
|
|
122
|
+
const matching = all().filter((element) => matches(normalize(element.textContent ?? ""), text, options));
|
|
123
123
|
return matching.filter((element) => !matching.some((other) => other !== element && element.contains(other)));
|
|
124
124
|
};
|
|
125
125
|
const byRole = (role, options = {}) => all().filter((element) => roleOf(element) === role && (options.name === void 0 || matches(nameOf(element), options.name)));
|
|
@@ -131,10 +131,10 @@ function within(root) {
|
|
|
131
131
|
};
|
|
132
132
|
const roleQuery = (role, options) => `with role "${role}"${options?.name === void 0 ? "" : ` named ${String(options.name)}`}`;
|
|
133
133
|
return {
|
|
134
|
-
getByText: (text) => one(byText(text), `with the text ${String(text)}`),
|
|
135
|
-
queryByText: (text) => byText(text)[0] ?? null,
|
|
136
|
-
getAllByText: (text) => {
|
|
137
|
-
const found = byText(text);
|
|
134
|
+
getByText: (text, options) => one(byText(text, options), `with the text ${String(text)}`),
|
|
135
|
+
queryByText: (text, options) => byText(text, options)[0] ?? null,
|
|
136
|
+
getAllByText: (text, options) => {
|
|
137
|
+
const found = byText(text, options);
|
|
138
138
|
if (found.length === 0) one(found, `with the text ${String(text)}`);
|
|
139
139
|
return found;
|
|
140
140
|
},
|
|
@@ -145,12 +145,12 @@ function within(root) {
|
|
|
145
145
|
if (found.length === 0) one(found, roleQuery(role, options));
|
|
146
146
|
return found;
|
|
147
147
|
},
|
|
148
|
-
getByLabelText: (text) => one(all().filter((element) => isLabelable(element) && labelsOf(element).some((label) => matches(label, text))), `labelled ${String(text)}`),
|
|
148
|
+
getByLabelText: (text, options) => one(all().filter((element) => isLabelable(element) && labelsOf(element).some((label) => matches(label, text, options))), `labelled ${String(text)}`),
|
|
149
149
|
getByTestId: (id) => one(all().filter((element) => element.getAttribute("data-testid") === id), `with data-testid "${id}"`)
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
var normalize = (text) => text.replace(/\s+/g, " ").trim();
|
|
153
|
-
var matches = (value, expected) => typeof expected
|
|
153
|
+
var matches = (value, expected, options) => typeof expected !== "string" ? expected.test(value) : options?.exact === false ? value.toLowerCase().includes(normalize(expected).toLowerCase()) : value === expected;
|
|
154
154
|
var describe = (element) => `<${element.localName}${element.id ? `#${element.id}` : ""}>`;
|
|
155
155
|
var isLabelable = (element) => [
|
|
156
156
|
"input",
|
|
@@ -186,10 +186,11 @@ function roleOf(element) {
|
|
|
186
186
|
return "textbox";
|
|
187
187
|
}
|
|
188
188
|
if (/^h[1-6]$/.test(tag)) return "heading";
|
|
189
|
+
if (tag === "th") return element.getAttribute("scope") === "row" ? "rowheader" : "columnheader";
|
|
190
|
+
if (tag === "select") return element.hasAttribute("multiple") ? "listbox" : "combobox";
|
|
189
191
|
const roles = {
|
|
190
192
|
button: "button",
|
|
191
193
|
textarea: "textbox",
|
|
192
|
-
select: "combobox",
|
|
193
194
|
ul: "list",
|
|
194
195
|
ol: "list",
|
|
195
196
|
li: "listitem",
|
|
@@ -197,18 +198,37 @@ function roleOf(element) {
|
|
|
197
198
|
main: "main",
|
|
198
199
|
form: "form",
|
|
199
200
|
dialog: "dialog",
|
|
201
|
+
option: "option",
|
|
200
202
|
table: "table",
|
|
203
|
+
thead: "rowgroup",
|
|
204
|
+
tbody: "rowgroup",
|
|
205
|
+
tfoot: "rowgroup",
|
|
201
206
|
tr: "row",
|
|
202
|
-
|
|
207
|
+
td: "cell",
|
|
208
|
+
fieldset: "group",
|
|
209
|
+
aside: "complementary",
|
|
210
|
+
progress: "progressbar",
|
|
211
|
+
meter: "meter",
|
|
212
|
+
hr: "separator"
|
|
203
213
|
};
|
|
204
214
|
if (tag === "a") return element.hasAttribute("href") ? "link" : null;
|
|
205
215
|
if (tag === "img") return element.getAttribute("alt") === "" ? "presentation" : "img";
|
|
206
216
|
return roles[tag] ?? null;
|
|
207
217
|
}
|
|
218
|
+
/** Elements named by a child: a table by its <caption>, a fieldset by its <legend>... */
|
|
219
|
+
var CAPTIONS = {
|
|
220
|
+
table: "caption",
|
|
221
|
+
fieldset: "legend",
|
|
222
|
+
figure: "figcaption"
|
|
223
|
+
};
|
|
208
224
|
/** The accessible name, simplified: labels for controls, alt for images, the text for the rest. */
|
|
209
225
|
function nameOf(element) {
|
|
210
226
|
const aria = element.getAttribute("aria-label");
|
|
211
227
|
if (aria !== null) return normalize(aria);
|
|
228
|
+
const labelledBy = element.getAttribute("aria-labelledby");
|
|
229
|
+
if (labelledBy !== null) return normalize(labelledBy.split(/\s+/).map((id) => element.ownerDocument.getElementById(id)?.textContent ?? "").join(" "));
|
|
230
|
+
const caption = CAPTIONS[element.localName];
|
|
231
|
+
if (caption !== void 0) return normalize(element.querySelector(`:scope > ${caption}`)?.textContent ?? "");
|
|
212
232
|
if (isLabelable(element) && element.localName !== "button") return labelsOf(element)[0] ?? normalize(element.getAttribute("placeholder") ?? "");
|
|
213
233
|
if (element.localName === "img") return normalize(element.getAttribute("alt") ?? "");
|
|
214
234
|
return normalize(element.textContent ?? "");
|
package/dist/prod/forms.js
CHANGED
|
@@ -69,8 +69,8 @@ function f(e) {
|
|
|
69
69
|
}
|
|
70
70
|
// src/forms/form.ts
|
|
71
71
|
function p(o) {
|
|
72
|
-
let [p, v] = i(structuredClone(o.initial)), [y, b] = i({}), [x, S] = i({}), [C, w] = i({}), T = r(structuredClone(o.initial), { equals: !1 }), E = r(0), D = r(!1), O = r(!1), k = 0, A = (e) => typeof e == "function" ? e() : e,
|
|
73
|
-
let e =
|
|
72
|
+
let [p, v] = i(structuredClone(o.initial)), [y, b] = i({}), [x, S] = i({}), [C, w] = i({}), T = r(structuredClone(o.initial), { equals: !1 }), E = r(0), D = r(!1), O = r(!1), k = 0, A = 0, j = (e) => typeof e == "function" ? e() : e, M = () => structuredClone(a(p)), N = () => {
|
|
73
|
+
let e = M(), t = [
|
|
74
74
|
{},
|
|
75
75
|
{},
|
|
76
76
|
{}
|
|
@@ -97,36 +97,36 @@ function p(o) {
|
|
|
97
97
|
return n;
|
|
98
98
|
};
|
|
99
99
|
return r.length === 0 ? a() : Promise.all(r).then(a);
|
|
100
|
-
},
|
|
100
|
+
}, P = () => {
|
|
101
101
|
let e = ++k, n = (n) => (e === k && t(() => {
|
|
102
102
|
h(b, n.errors), O.set(!1);
|
|
103
|
-
}), n), r =
|
|
103
|
+
}), n), r = N();
|
|
104
104
|
return _(r) ? (O.set(!0), r.then(n)) : n(r);
|
|
105
|
-
},
|
|
105
|
+
}, F = (e) => {
|
|
106
106
|
S((t) => {
|
|
107
107
|
for (let n of Object.keys(t)) (u(n, e) || u(e, n)) && delete t[n];
|
|
108
|
-
}),
|
|
109
|
-
},
|
|
110
|
-
v((t) => c(t, e, n)),
|
|
111
|
-
}),
|
|
108
|
+
}), P();
|
|
109
|
+
}, I = (e, n) => t(() => {
|
|
110
|
+
v((t) => c(t, e, n)), F(e);
|
|
111
|
+
}), L = (e) => w((t) => void (t[e] = !0)), R = (e, n, r) => t(() => {
|
|
112
112
|
v((t) => {
|
|
113
113
|
Array.isArray(s(t, e)) || c(t, e, []), n(s(t, e));
|
|
114
114
|
}), w((t) => m(t, {
|
|
115
115
|
...d(a(t), e, r),
|
|
116
116
|
[e]: !0
|
|
117
|
-
})), S((t) => m(t, d(a(t), e, r))),
|
|
118
|
-
}),
|
|
117
|
+
})), S((t) => m(t, d(a(t), e, r))), P();
|
|
118
|
+
}), z = () => E() > 0, B = (e) => e === "" ? z() : C[e] === !0 || z(), V = e(() => Object.keys(y).length === 0), H = e(() => !l(p, T())), U = {
|
|
119
119
|
values: p,
|
|
120
|
-
value: (e) => s(p,
|
|
121
|
-
set: (e, t) =>
|
|
120
|
+
value: (e) => s(p, j(e)),
|
|
121
|
+
set: (e, t) => I(e, t),
|
|
122
122
|
update: (e) => t(() => {
|
|
123
|
-
v(e),
|
|
123
|
+
v(e), F("");
|
|
124
124
|
}),
|
|
125
125
|
bind(e, t = {}) {
|
|
126
|
-
let r = () =>
|
|
126
|
+
let r = () => j(e), i = () => s(p, r()), a = {
|
|
127
127
|
name: r,
|
|
128
|
-
onblur: () =>
|
|
129
|
-
"aria-invalid": () =>
|
|
128
|
+
onblur: () => L(r()),
|
|
129
|
+
"aria-invalid": () => U.error(r()) ? "true" : void 0
|
|
130
130
|
}, o = n(i), c = t.value;
|
|
131
131
|
return c !== void 0 && Array.isArray(o) ? {
|
|
132
132
|
...a,
|
|
@@ -135,13 +135,13 @@ function p(o) {
|
|
|
135
135
|
checked: () => i().includes(c),
|
|
136
136
|
onchange: (e) => {
|
|
137
137
|
let t = n(i).filter((e) => e !== c);
|
|
138
|
-
|
|
138
|
+
I(r(), e.currentTarget.checked ? [...t, c] : t);
|
|
139
139
|
}
|
|
140
140
|
} : c === void 0 ? typeof o == "boolean" ? {
|
|
141
141
|
...a,
|
|
142
142
|
type: "checkbox",
|
|
143
143
|
checked: () => i() === !0,
|
|
144
|
-
onchange: (e) =>
|
|
144
|
+
onchange: (e) => I(r(), e.currentTarget.checked)
|
|
145
145
|
} : typeof o == "number" ? {
|
|
146
146
|
...a,
|
|
147
147
|
value: () => {
|
|
@@ -150,37 +150,37 @@ function p(o) {
|
|
|
150
150
|
},
|
|
151
151
|
oninput: (e) => {
|
|
152
152
|
let t = e.currentTarget.value;
|
|
153
|
-
|
|
153
|
+
I(r(), t.trim() === "" ? NaN : Number(t));
|
|
154
154
|
}
|
|
155
155
|
} : {
|
|
156
156
|
...a,
|
|
157
157
|
value: () => String(i() ?? ""),
|
|
158
|
-
oninput: (e) =>
|
|
158
|
+
oninput: (e) => I(r(), e.currentTarget.value)
|
|
159
159
|
} : {
|
|
160
160
|
...a,
|
|
161
161
|
type: "radio",
|
|
162
162
|
value: () => c,
|
|
163
163
|
checked: () => i() === c,
|
|
164
|
-
onchange: () =>
|
|
164
|
+
onchange: () => I(r(), c)
|
|
165
165
|
};
|
|
166
166
|
},
|
|
167
167
|
error(e = "") {
|
|
168
|
-
let t =
|
|
169
|
-
return (
|
|
168
|
+
let t = j(e);
|
|
169
|
+
return (B(t) ? y[t] : void 0) ?? x[t];
|
|
170
170
|
},
|
|
171
|
-
touched: (e) => C[
|
|
172
|
-
touch: (e) =>
|
|
173
|
-
dirty: (e) => e === void 0 ?
|
|
174
|
-
valid: () =>
|
|
171
|
+
touched: (e) => C[j(e)] === !0,
|
|
172
|
+
touch: (e) => L(e),
|
|
173
|
+
dirty: (e) => e === void 0 ? H() : !l(s(p, j(e)), s(T(), j(e))),
|
|
174
|
+
valid: () => V(),
|
|
175
175
|
validating: () => O(),
|
|
176
176
|
submitting: () => D(),
|
|
177
|
-
submitted:
|
|
177
|
+
submitted: z,
|
|
178
178
|
array(e) {
|
|
179
179
|
return {
|
|
180
180
|
items: () => s(p, e) ?? [],
|
|
181
|
-
add: (t, n) =>
|
|
182
|
-
remove: (t) =>
|
|
183
|
-
move: (t, n) =>
|
|
181
|
+
add: (t, n) => R(e, (e) => n === void 0 ? e.push(t) : e.splice(n, 0, t), (e) => n === void 0 || e < n ? e : e + 1),
|
|
182
|
+
remove: (t) => R(e, (e) => e.splice(t, 1), (e) => e === t ? -1 : e > t ? e - 1 : e),
|
|
183
|
+
move: (t, n) => R(e, (e) => e.splice(n, 0, ...e.splice(t, 1)), (e) => e === t ? n : t < n ? e > t && e <= n ? e - 1 : e : e >= n && e < t ? e + 1 : e)
|
|
184
184
|
};
|
|
185
185
|
},
|
|
186
186
|
setErrors(e) {
|
|
@@ -202,10 +202,12 @@ function p(o) {
|
|
|
202
202
|
E.set(n(E) + 1), D.set(!0), S((e) => m(e, {}));
|
|
203
203
|
});
|
|
204
204
|
try {
|
|
205
|
-
let t =
|
|
206
|
-
|
|
205
|
+
let t = M(), n = await P();
|
|
206
|
+
if (Object.keys(n.errors).length > 0) return a(), !1;
|
|
207
|
+
let r = A;
|
|
208
|
+
return await e(o.schema ? n.output : t), A === r && T.set(() => t), !0;
|
|
207
209
|
} catch (e) {
|
|
208
|
-
if (
|
|
210
|
+
if (U.setErrors(e)) return a(), !1;
|
|
209
211
|
throw e;
|
|
210
212
|
} finally {
|
|
211
213
|
D.set(!1);
|
|
@@ -214,12 +216,12 @@ function p(o) {
|
|
|
214
216
|
},
|
|
215
217
|
reset(e) {
|
|
216
218
|
let r = structuredClone(e ?? n(T));
|
|
217
|
-
t(() => {
|
|
218
|
-
v((e) => m(e, structuredClone(r))), T.set(() => r), w((e) => m(e, {})), S((e) => m(e, {})), E.set(0),
|
|
219
|
+
A++, t(() => {
|
|
220
|
+
v((e) => m(e, structuredClone(r))), T.set(() => r), w((e) => m(e, {})), S((e) => m(e, {})), E.set(0), P();
|
|
219
221
|
});
|
|
220
222
|
}
|
|
221
223
|
};
|
|
222
|
-
return
|
|
224
|
+
return P(), U;
|
|
223
225
|
}
|
|
224
226
|
function m(e, t) {
|
|
225
227
|
for (let n of Object.keys(e)) n in t || delete e[n];
|