keits 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -79
- package/dist/dev/api.js +275 -0
- package/dist/dev/forms.js +330 -0
- package/dist/dev/index.js +26 -326
- package/dist/dev/router.js +24 -5
- package/dist/dev/shared/computed-DrF8O8b4.js +40 -0
- package/dist/dev/shared/{element-C4DfKtZW.js → element-DXwmUAnz.js} +32 -111
- package/dist/dev/shared/{graph-D6-x_CWC.js → graph-SIvYLXSv.js} +62 -3
- package/dist/dev/shared/hydrate-C8cOsDDH.js +588 -0
- package/dist/dev/shared/mount-CDB2HgN5.js +23 -0
- package/dist/dev/shared/namespaces-Cz82B0Pr.js +84 -0
- package/dist/dev/shared/owner-BuwIoI4j.js +72 -0
- package/dist/dev/shared/render-context-k2uu_dM_.js +34 -0
- package/dist/dev/shared/render-effect-Uk9dDmuU.js +32 -0
- package/dist/dev/shared/resource-DlgzdtcG.js +145 -0
- package/dist/dev/shared/signal-B3xOKbVm.js +24 -0
- package/dist/dev/shared/store-0vEg2bQV.js +152 -0
- package/dist/dev/shared/unsafe-keys-CB1P22No.js +8 -0
- package/dist/dev/static.js +76 -0
- package/dist/dev/svg.js +2 -1
- package/dist/dev/testing.js +216 -0
- package/dist/dev/vite.js +141 -0
- package/dist/prod/api.js +215 -0
- package/dist/prod/forms.js +240 -0
- package/dist/prod/index.js +110 -327
- package/dist/prod/router.js +83 -68
- package/dist/prod/shared/computed-BjqJ6Pps.js +33 -0
- package/dist/prod/shared/element-DCit4-3e.js +129 -0
- package/dist/prod/shared/{graph-C_aA46c6.js → graph-CR2WKbwr.js} +107 -63
- package/dist/prod/shared/hydrate-kKnJbkV7.js +480 -0
- package/dist/prod/shared/mount-DbeKIoyD.js +18 -0
- package/dist/prod/shared/namespaces-BSRrBJIU.js +71 -0
- package/dist/prod/shared/owner-DBi3odT4.js +67 -0
- package/dist/prod/shared/render-context-DF8lr1uu.js +30 -0
- package/dist/prod/shared/render-effect-UFDi2Pfh.js +25 -0
- package/dist/prod/shared/resource-Ch5tVseZ.js +91 -0
- package/dist/prod/shared/signal-BDMlfa0Z.js +16 -0
- package/dist/prod/shared/store-CvW0DbmK.js +110 -0
- package/dist/prod/shared/unsafe-keys-C5PMlerl.js +7 -0
- package/dist/prod/static.js +48 -0
- package/dist/prod/svg.js +3 -2
- package/dist/prod/testing.js +144 -0
- package/dist/prod/vite.js +106 -0
- package/dist/types/api/cache.d.ts +16 -0
- package/dist/types/api/client.d.ts +42 -0
- package/dist/types/api/error.d.ts +16 -0
- package/dist/types/api/index.d.ts +3 -0
- package/dist/types/api/url.d.ts +5 -0
- package/dist/types/async/render-context.d.ts +10 -0
- package/dist/types/core/effect.d.ts +1 -0
- package/dist/types/core/graph.d.ts +11 -0
- package/dist/types/core/owner.d.ts +1 -0
- package/dist/types/core/unsafe-keys.d.ts +2 -0
- package/dist/types/dom/hooks.d.ts +4 -0
- package/dist/types/dom/types.d.ts +5 -0
- package/dist/types/forms/form.d.ts +55 -0
- package/dist/types/forms/index.d.ts +2 -0
- package/dist/types/forms/paths.d.ts +6 -0
- package/dist/types/forms/types.d.ts +38 -0
- package/dist/types/router/index.d.ts +1 -0
- package/dist/types/router/match.d.ts +1 -0
- package/dist/types/router/types.d.ts +1 -0
- package/dist/types/static/head.d.ts +36 -0
- package/dist/types/static/hydrate.d.ts +3 -0
- package/dist/types/static/index.d.ts +4 -0
- package/dist/types/static/island.d.ts +14 -0
- package/dist/types/static/json.d.ts +1 -0
- package/dist/types/static/render.d.ts +11 -0
- package/dist/types/static/server-dom.d.ts +100 -0
- package/dist/types/testing/index.d.ts +62 -0
- package/dist/types/vite/index.d.ts +24 -0
- package/package.json +46 -5
- package/dist/dev/shared/owner-DlUsXKXE.js +0 -122
- package/dist/prod/shared/element-DUtXb3px.js +0 -187
- package/dist/prod/shared/owner-DgJNPM0P.js +0 -104
|
@@ -1,87 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const node = {
|
|
6
|
-
kind: 1,
|
|
7
|
-
fn,
|
|
8
|
-
state: 0,
|
|
9
|
-
sources: [],
|
|
10
|
-
flushId: 0,
|
|
11
|
-
flushRuns: 0,
|
|
12
|
-
owner: null,
|
|
13
|
-
children: null,
|
|
14
|
-
cleanups: null,
|
|
15
|
-
disposed: false
|
|
16
|
-
};
|
|
17
|
-
if (options?.name !== void 0) node.name = options.name;
|
|
18
|
-
adopt(node);
|
|
19
|
-
batch(() => runEffect(node));
|
|
20
|
-
}
|
|
21
|
-
var hooks = {
|
|
22
|
-
element: (tag, namespace) => namespace === null ? document.createElement(tag) : document.createElementNS(namespace, tag),
|
|
23
|
-
text: (value) => document.createTextNode(value),
|
|
24
|
-
marker: () => document.createComment("")
|
|
25
|
-
};
|
|
26
|
-
// src/dom/render-effect.ts
|
|
27
|
-
function renderEffect(fn) {
|
|
28
|
-
if (isStaticRender()) fn();
|
|
29
|
-
else effect(fn);
|
|
30
|
-
}
|
|
31
|
-
// src/dom/insert.ts
|
|
32
|
-
function insert(parent, child, before = null) {
|
|
33
|
-
if (child === null || child === void 0 || typeof child === "boolean") return;
|
|
34
|
-
if (typeof child === "function") return insertDynamic(parent, child, before);
|
|
35
|
-
if (isChildArray(child)) {
|
|
36
|
-
for (const item of child) insert(parent, item, before);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (typeof child === "object") {
|
|
40
|
-
parent.insertBefore(child, before);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
parent.insertBefore(hooks.text(String(child)), before);
|
|
44
|
-
}
|
|
45
|
-
function isChildArray(value) {
|
|
46
|
-
return Array.isArray(value);
|
|
47
|
-
}
|
|
48
|
-
function isTextValue(value) {
|
|
49
|
-
return value === null || typeof value !== "object" && typeof value !== "function";
|
|
50
|
-
}
|
|
51
|
-
function toText(value) {
|
|
52
|
-
return value === null || value === void 0 || typeof value === "boolean" ? "" : String(value);
|
|
53
|
-
}
|
|
54
|
-
function insertDynamic(parent, fn, before) {
|
|
55
|
-
const text = hooks.text("");
|
|
56
|
-
parent.insertBefore(text, before);
|
|
57
|
-
let start = null;
|
|
58
|
-
let end = null;
|
|
59
|
-
renderEffect(() => {
|
|
60
|
-
const value = fn();
|
|
61
|
-
if (start === null || end === null) {
|
|
62
|
-
if (isTextValue(value)) {
|
|
63
|
-
const next = toText(value);
|
|
64
|
-
if (text.data !== next) text.data = next;
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
start = hooks.marker();
|
|
68
|
-
end = hooks.marker();
|
|
69
|
-
text.before(start);
|
|
70
|
-
text.after(end);
|
|
71
|
-
text.remove();
|
|
72
|
-
}
|
|
73
|
-
clearRange(start, end);
|
|
74
|
-
insert(end.parentNode, value, end);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
function clearRange(start, end) {
|
|
78
|
-
let node = start.nextSibling;
|
|
79
|
-
while (node !== null && node !== end) {
|
|
80
|
-
const next = node.nextSibling;
|
|
81
|
-
node.remove();
|
|
82
|
-
node = next;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
1
|
+
import { a as hooks, n as insert } from "./namespaces-Cz82B0Pr.js";
|
|
2
|
+
import { _ as runWithOwner, c as getOwner, f as isStaticRender, i as batch, u as handleError } from "./graph-SIvYLXSv.js";
|
|
3
|
+
import { t as UNSAFE_KEYS } from "./unsafe-keys-CB1P22No.js";
|
|
4
|
+
import { t as renderEffect } from "./render-effect-Uk9dDmuU.js";
|
|
85
5
|
// src/dom/events.ts
|
|
86
6
|
function applyEvent(element, key, value) {
|
|
87
7
|
let handler = value;
|
|
@@ -107,24 +27,24 @@ function listen(element, type, handler, options) {
|
|
|
107
27
|
function isPromiseLike(value) {
|
|
108
28
|
return typeof value?.then === "function";
|
|
109
29
|
}
|
|
110
|
-
// src/dom/namespaces.ts
|
|
111
|
-
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
112
30
|
// src/dom/props.ts
|
|
113
31
|
var UNSAFE_PROPS = /* @__PURE__ */ new Set([
|
|
114
|
-
"
|
|
115
|
-
"
|
|
32
|
+
"innerhtml",
|
|
33
|
+
"outerhtml",
|
|
116
34
|
"srcdoc"
|
|
117
35
|
]);
|
|
118
36
|
var URL_PROPS = /* @__PURE__ */ new Set([
|
|
119
37
|
"href",
|
|
120
38
|
"src",
|
|
121
39
|
"action",
|
|
122
|
-
"formAction",
|
|
123
40
|
"formaction",
|
|
124
41
|
"poster",
|
|
125
42
|
"cite",
|
|
126
43
|
"data",
|
|
127
|
-
"xlink:href"
|
|
44
|
+
"xlink:href",
|
|
45
|
+
"to",
|
|
46
|
+
"from",
|
|
47
|
+
"values"
|
|
128
48
|
]);
|
|
129
49
|
var BLOCKED_URL = "about:invalid#keits-blocked";
|
|
130
50
|
function applyProps(element, props) {
|
|
@@ -133,43 +53,54 @@ function applyProps(element, props) {
|
|
|
133
53
|
if (key === "ref") continue;
|
|
134
54
|
if (key === "class") applyClass(element, value);
|
|
135
55
|
else if (key === "style") applyStyle(element, value);
|
|
136
|
-
else if (key.startsWith("on")) applyEvent(element, key, value);
|
|
56
|
+
else if (key.toLowerCase().startsWith("on")) applyEvent(element, key, value);
|
|
137
57
|
else if (typeof value === "function") renderEffect(() => setProp(element, key, value()));
|
|
138
58
|
else setProp(element, key, value);
|
|
139
59
|
}
|
|
140
60
|
}
|
|
141
61
|
function setProp(element, key, value) {
|
|
142
|
-
|
|
143
|
-
if (
|
|
62
|
+
const name = key.toLowerCase();
|
|
63
|
+
if (UNSAFE_PROPS.has(name) || UNSAFE_KEYS.has(key) || name.startsWith("on") && typeof value === "string") throw new Error(`[keits] "${key}" is not allowed as a prop: it would allow HTML injection.`);
|
|
64
|
+
if (URL_PROPS.has(name) && value != null && value !== false && isJavaScriptUrl(String(value))) {
|
|
144
65
|
console.warn(`[keits] Blocked a javascript: URL in "${key}".`);
|
|
145
66
|
value = BLOCKED_URL;
|
|
146
67
|
}
|
|
147
68
|
if (key in element && element.namespaceURI !== "http://www.w3.org/2000/svg") {
|
|
148
69
|
element[key] = value;
|
|
149
70
|
if (isStaticRender()) reflectForStatic(element, key, value);
|
|
150
|
-
} else if (
|
|
71
|
+
} else if (key.startsWith("aria-") && typeof value === "boolean") element.setAttribute(key, String(value));
|
|
72
|
+
else if (value === null || value === void 0 || value === false) element.removeAttribute(key);
|
|
151
73
|
else element.setAttribute(key, value === true ? "" : String(value));
|
|
152
74
|
}
|
|
153
75
|
function isJavaScriptUrl(url) {
|
|
154
|
-
return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().startsWith("javascript");
|
|
76
|
+
return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().split(";").some((part) => part.startsWith("javascript:"));
|
|
155
77
|
}
|
|
156
78
|
function reflectForStatic(element, key, value) {
|
|
157
79
|
if (key === "value") {
|
|
158
80
|
if (element.localName === "textarea") element.textContent = value == null ? "" : String(value);
|
|
81
|
+
else if (element.localName === "select") selectOption(element, value == null ? "" : String(value));
|
|
159
82
|
else if (value == null) element.removeAttribute("value");
|
|
160
83
|
else element.setAttribute("value", String(value));
|
|
161
84
|
} else if (key === "checked" || key === "selected") element.toggleAttribute(key, value === true);
|
|
162
85
|
}
|
|
86
|
+
function selectOption(node, value) {
|
|
87
|
+
for (let child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
88
|
+
if (child.nodeType !== 1) continue;
|
|
89
|
+
const element = child;
|
|
90
|
+
if (element.localName === "option") element.toggleAttribute("selected", (element.getAttribute("value") ?? element.textContent) === value);
|
|
91
|
+
else selectOption(element, value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
163
94
|
function applyClass(element, value) {
|
|
164
95
|
if (typeof value === "function") {
|
|
165
96
|
renderEffect(() => writeClass(element, toClassString(value())));
|
|
166
97
|
return;
|
|
167
98
|
}
|
|
168
99
|
const fixed = [];
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
});
|
|
100
|
+
const reactive = [];
|
|
101
|
+
collectClasses(value, fixed, (name, on) => reactive.push([name, on]));
|
|
172
102
|
if (fixed.length > 0) element.classList.add(...fixed);
|
|
103
|
+
for (const [name, on] of reactive) renderEffect(() => element.classList.toggle(name, on()));
|
|
173
104
|
}
|
|
174
105
|
function writeClass(element, className) {
|
|
175
106
|
if (className === "") element.removeAttribute("class");
|
|
@@ -225,24 +156,14 @@ function writeStyle(style, name, value) {
|
|
|
225
156
|
}
|
|
226
157
|
// src/dom/element.ts
|
|
227
158
|
function html(tag) {
|
|
228
|
-
|
|
229
|
-
const element = hooks.element(tag, null);
|
|
230
|
-
if (isProps(first)) {
|
|
231
|
-
applyProps(element, first);
|
|
232
|
-
insert(element, children);
|
|
233
|
-
if (typeof first.ref === "function") first.ref(element);
|
|
234
|
-
} else if (first === null || first === void 0) insert(element, children);
|
|
235
|
-
else insert(element, first);
|
|
236
|
-
return element;
|
|
237
|
-
};
|
|
238
|
-
return factory;
|
|
159
|
+
return createFactory(tag, null);
|
|
239
160
|
}
|
|
240
161
|
function createFactory(tag, namespace) {
|
|
241
162
|
return (first, children) => {
|
|
242
163
|
const element = hooks.element(tag, namespace);
|
|
243
164
|
if (isProps(first)) {
|
|
244
|
-
applyProps(element, first);
|
|
245
165
|
insert(element, children);
|
|
166
|
+
applyProps(element, first);
|
|
246
167
|
if (typeof first.ref === "function") first.ref(element);
|
|
247
168
|
} else if (first === null || first === void 0) insert(element, children);
|
|
248
169
|
else insert(element, first);
|
|
@@ -252,4 +173,4 @@ function createFactory(tag, namespace) {
|
|
|
252
173
|
function isProps(value) {
|
|
253
174
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.nodeType !== "number";
|
|
254
175
|
}
|
|
255
|
-
export {
|
|
176
|
+
export { html as n, createFactory as t };
|
|
@@ -12,6 +12,7 @@ var mounts = [];
|
|
|
12
12
|
var lastWritten = null;
|
|
13
13
|
var unhandledErrors = [];
|
|
14
14
|
var staticDepth = 0;
|
|
15
|
+
var staticRoots = 0;
|
|
15
16
|
function track(source) {
|
|
16
17
|
const observer = currentObserver;
|
|
17
18
|
if (observer === null || source.seenBy === currentRunId) return;
|
|
@@ -26,6 +27,9 @@ function track(source) {
|
|
|
26
27
|
function isTracking() {
|
|
27
28
|
return currentObserver !== null;
|
|
28
29
|
}
|
|
30
|
+
function getObserver() {
|
|
31
|
+
return currentObserver;
|
|
32
|
+
}
|
|
29
33
|
function notify(source) {
|
|
30
34
|
if (source.observers.length === 0) return;
|
|
31
35
|
lastWritten = source;
|
|
@@ -213,6 +217,32 @@ function adopt(node) {
|
|
|
213
217
|
const owner = currentOwner;
|
|
214
218
|
node.owner = owner;
|
|
215
219
|
if (owner !== null) (owner.children ??= []).push(node);
|
|
220
|
+
giveKey(node);
|
|
221
|
+
}
|
|
222
|
+
var keying = 0;
|
|
223
|
+
function startKeys() {
|
|
224
|
+
keying++;
|
|
225
|
+
}
|
|
226
|
+
function stopKeys() {
|
|
227
|
+
keying--;
|
|
228
|
+
}
|
|
229
|
+
function nextKey() {
|
|
230
|
+
const owner = currentOwner;
|
|
231
|
+
if (keying === 0 || owner === null || owner.key === void 0) return null;
|
|
232
|
+
const index = owner.keyCount ?? 0;
|
|
233
|
+
owner.keyCount = index + 1;
|
|
234
|
+
return `${owner.key}.${index}`;
|
|
235
|
+
}
|
|
236
|
+
function giveKey(node) {
|
|
237
|
+
const key = nextKey();
|
|
238
|
+
if (key !== null) {
|
|
239
|
+
node.key = key;
|
|
240
|
+
node.keyCount = 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function insideHydratable(from = currentOwner) {
|
|
244
|
+
for (let owner = from; owner !== null; owner = owner.owner) if (owner.kind === 3 && owner.hydratable) return true;
|
|
245
|
+
return false;
|
|
216
246
|
}
|
|
217
247
|
function getOwner() {
|
|
218
248
|
return currentOwner;
|
|
@@ -235,7 +265,7 @@ function addCleanup(fn) {
|
|
|
235
265
|
return true;
|
|
236
266
|
}
|
|
237
267
|
function addMount(fn) {
|
|
238
|
-
if (
|
|
268
|
+
if (isStaticRender()) return;
|
|
239
269
|
queueMount(currentOwner, fn);
|
|
240
270
|
}
|
|
241
271
|
function queueMount(owner, fn) {
|
|
@@ -279,6 +309,7 @@ function cleanNode(node) {
|
|
|
279
309
|
const cleanups = node.cleanups;
|
|
280
310
|
node.children = null;
|
|
281
311
|
node.cleanups = null;
|
|
312
|
+
if (node.key !== void 0) node.keyCount = 0;
|
|
282
313
|
if (children !== null) for (let i = children.length - 1; i >= 0; i--) dispose(children[i]);
|
|
283
314
|
if (cleanups !== null) for (let i = cleanups.length - 1; i >= 0; i--) try {
|
|
284
315
|
cleanups[i]();
|
|
@@ -311,7 +342,35 @@ function handleError(error, owner) {
|
|
|
311
342
|
unhandledErrors.push(error);
|
|
312
343
|
}
|
|
313
344
|
function isStaticRender() {
|
|
314
|
-
|
|
345
|
+
if (staticDepth > 0) return true;
|
|
346
|
+
if (staticRoots === 0) return false;
|
|
347
|
+
for (let owner = currentOwner; owner !== null; owner = owner.owner) if (owner.kind === 3 && owner.static) return true;
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
function staticRoot(fn) {
|
|
351
|
+
const root = {
|
|
352
|
+
kind: 3,
|
|
353
|
+
owner: null,
|
|
354
|
+
children: null,
|
|
355
|
+
cleanups: null,
|
|
356
|
+
disposed: false,
|
|
357
|
+
handler: null,
|
|
358
|
+
static: true
|
|
359
|
+
};
|
|
360
|
+
staticRoots++;
|
|
361
|
+
let ended = false;
|
|
362
|
+
const end = () => {
|
|
363
|
+
if (ended) return;
|
|
364
|
+
ended = true;
|
|
365
|
+
staticRoots--;
|
|
366
|
+
batch(() => dispose(root));
|
|
367
|
+
};
|
|
368
|
+
try {
|
|
369
|
+
return batch(() => runWithOwner(root, () => fn(end)));
|
|
370
|
+
} catch (error) {
|
|
371
|
+
end();
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
315
374
|
}
|
|
316
375
|
function withStaticRender(fn) {
|
|
317
376
|
staticDepth++;
|
|
@@ -321,4 +380,4 @@ function withStaticRender(fn) {
|
|
|
321
380
|
staticDepth--;
|
|
322
381
|
}
|
|
323
382
|
}
|
|
324
|
-
export {
|
|
383
|
+
export { updateIfNeeded as C, untrack as S, runWithOwner as _, deferMounts as a, stopKeys as b, getOwner as c, insideHydratable as d, isStaticRender as f, runEffect as g, notify as h, batch as i, giveKey as l, nextKey as m, addMount as n, dispose as o, isTracking as p, adopt as r, getObserver as s, addCleanup as t, handleError as u, startKeys as v, withStaticRender as w, track as x, staticRoot as y };
|