@vertz/ui 0.2.24 → 0.2.26
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/shared/{chunk-2eh4p2n7.js → chunk-09ntccdx.js} +1 -1
- package/dist/shared/{chunk-4gen306a.js → chunk-1jgws7rs.js} +4 -109
- package/dist/shared/{chunk-2wag9c7v.js → chunk-2krx4aqe.js} +5 -5
- package/dist/shared/{chunk-f4d5nphq.js → chunk-7nr2ebrf.js} +1 -1
- package/dist/shared/{chunk-mbnda3pv.js → chunk-djvarb8r.js} +123 -76
- package/dist/shared/{chunk-jtma4sh4.js → chunk-e09mdqcx.js} +2 -2
- package/dist/shared/{chunk-4gmtsf6v.js → chunk-h2sjma78.js} +110 -1
- package/dist/shared/{chunk-t3rnfxc0.js → chunk-j1a7t906.js} +2 -2
- package/dist/shared/{chunk-656n0x6y.js → chunk-ppr06jgn.js} +8 -2
- package/dist/shared/{chunk-ge2e6y2s.js → chunk-svvqjmyy.js} +1 -1
- package/dist/shared/{chunk-da2w7j7w.js → chunk-xs5s8gqe.js} +1 -1
- package/dist/shared/{chunk-18frwfc4.js → chunk-ymc3wwam.js} +8 -2
- package/dist/src/auth/public.js +4 -4
- package/dist/src/components/index.d.ts +2 -1
- package/dist/src/components/index.js +5 -0
- package/dist/src/css/public.js +3 -4
- package/dist/src/form/public.d.ts +11 -0
- package/dist/src/form/public.js +2 -2
- package/dist/src/index.d.ts +37 -44
- package/dist/src/index.js +17 -202
- package/dist/src/internals.d.ts +51 -5
- package/dist/src/internals.js +284 -74
- package/dist/src/query/public.d.ts +1 -32
- package/dist/src/query/public.js +5 -8
- package/dist/src/router/public.js +7 -8
- package/dist/src/test/index.js +3 -3
- package/package.json +3 -3
- package/dist/shared/chunk-2y9f9j62.js +0 -40
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isNavPrefetchActive
|
|
3
3
|
} from "./chunk-jrtrk5z4.js";
|
|
4
|
-
import {
|
|
5
|
-
getAdapter,
|
|
6
|
-
isRenderNode
|
|
7
|
-
} from "./chunk-2y9f9j62.js";
|
|
8
4
|
import {
|
|
9
5
|
registerActiveQuery
|
|
10
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-09ntccdx.js";
|
|
11
7
|
import {
|
|
12
8
|
isBrowser
|
|
13
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-xs5s8gqe.js";
|
|
14
10
|
import {
|
|
15
11
|
_tryOnCleanup,
|
|
16
12
|
batch,
|
|
17
13
|
computed,
|
|
18
|
-
domEffect,
|
|
19
14
|
getSSRContext,
|
|
20
15
|
lifecycleEffect,
|
|
21
|
-
popScope,
|
|
22
|
-
pushScope,
|
|
23
|
-
runCleanups,
|
|
24
16
|
setReadValueCallback,
|
|
25
17
|
signal,
|
|
26
18
|
untrack
|
|
27
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-ppr06jgn.js";
|
|
28
20
|
|
|
29
21
|
// src/query/cache.ts
|
|
30
22
|
class MemoryCache {
|
|
@@ -1380,101 +1372,4 @@ function splitRefKey(key) {
|
|
|
1380
1372
|
return [key.slice(0, idx), key.slice(idx + 1)];
|
|
1381
1373
|
}
|
|
1382
1374
|
|
|
1383
|
-
|
|
1384
|
-
var cache = new WeakMap;
|
|
1385
|
-
function queryMatch(queryResult, handlers) {
|
|
1386
|
-
const key = queryResult;
|
|
1387
|
-
const existing = cache.get(key);
|
|
1388
|
-
if (existing && !existing.disposed) {
|
|
1389
|
-
existing.handlers = handlers;
|
|
1390
|
-
return existing.wrapper;
|
|
1391
|
-
}
|
|
1392
|
-
if (existing) {
|
|
1393
|
-
cache.delete(key);
|
|
1394
|
-
}
|
|
1395
|
-
const wrapper = getAdapter().createElement("span");
|
|
1396
|
-
wrapper.style.display = "contents";
|
|
1397
|
-
const entry = { wrapper, handlers, disposed: false };
|
|
1398
|
-
cache.set(key, entry);
|
|
1399
|
-
let currentBranch = null;
|
|
1400
|
-
let branchCleanups = [];
|
|
1401
|
-
const outerScope = pushScope();
|
|
1402
|
-
domEffect(() => {
|
|
1403
|
-
const isLoading = queryResult.loading.value;
|
|
1404
|
-
const err = queryResult.error.value;
|
|
1405
|
-
const dataValue = queryResult.data.value;
|
|
1406
|
-
let branch;
|
|
1407
|
-
if (isLoading || err === undefined && dataValue === undefined) {
|
|
1408
|
-
branch = "loading";
|
|
1409
|
-
} else if (err !== undefined) {
|
|
1410
|
-
branch = "error";
|
|
1411
|
-
} else {
|
|
1412
|
-
branch = "data";
|
|
1413
|
-
}
|
|
1414
|
-
if (branch === currentBranch) {
|
|
1415
|
-
return;
|
|
1416
|
-
}
|
|
1417
|
-
runCleanups(branchCleanups);
|
|
1418
|
-
while (wrapper.firstChild) {
|
|
1419
|
-
wrapper.removeChild(wrapper.firstChild);
|
|
1420
|
-
}
|
|
1421
|
-
currentBranch = branch;
|
|
1422
|
-
const scope = pushScope();
|
|
1423
|
-
let branchResult = null;
|
|
1424
|
-
if (branch === "loading") {
|
|
1425
|
-
branchResult = entry.handlers.loading();
|
|
1426
|
-
} else if (branch === "error") {
|
|
1427
|
-
branchResult = entry.handlers.error(err);
|
|
1428
|
-
} else {
|
|
1429
|
-
const dataSignal = queryResult.data;
|
|
1430
|
-
const dataProxy = new Proxy({}, {
|
|
1431
|
-
get(_target, prop, receiver) {
|
|
1432
|
-
const current = dataSignal.value;
|
|
1433
|
-
if (current == null)
|
|
1434
|
-
return;
|
|
1435
|
-
const value = Reflect.get(current, prop, receiver);
|
|
1436
|
-
if (typeof value === "function") {
|
|
1437
|
-
return value.bind(current);
|
|
1438
|
-
}
|
|
1439
|
-
return value;
|
|
1440
|
-
},
|
|
1441
|
-
has(_target, prop) {
|
|
1442
|
-
const current = dataSignal.value;
|
|
1443
|
-
if (current == null)
|
|
1444
|
-
return false;
|
|
1445
|
-
return Reflect.has(current, prop);
|
|
1446
|
-
},
|
|
1447
|
-
ownKeys() {
|
|
1448
|
-
const current = dataSignal.value;
|
|
1449
|
-
if (current == null)
|
|
1450
|
-
return [];
|
|
1451
|
-
return Reflect.ownKeys(current);
|
|
1452
|
-
},
|
|
1453
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
1454
|
-
const current = dataSignal.value;
|
|
1455
|
-
if (current == null)
|
|
1456
|
-
return;
|
|
1457
|
-
return Reflect.getOwnPropertyDescriptor(current, prop);
|
|
1458
|
-
}
|
|
1459
|
-
});
|
|
1460
|
-
branchResult = entry.handlers.data(dataProxy);
|
|
1461
|
-
}
|
|
1462
|
-
popScope();
|
|
1463
|
-
branchCleanups = scope;
|
|
1464
|
-
if (branchResult != null && isRenderNode(branchResult)) {
|
|
1465
|
-
wrapper.appendChild(branchResult);
|
|
1466
|
-
}
|
|
1467
|
-
});
|
|
1468
|
-
popScope();
|
|
1469
|
-
const dispose = () => {
|
|
1470
|
-
entry.disposed = true;
|
|
1471
|
-
runCleanups(branchCleanups);
|
|
1472
|
-
runCleanups(outerScope);
|
|
1473
|
-
cache.delete(key);
|
|
1474
|
-
};
|
|
1475
|
-
wrapper.dispose = dispose;
|
|
1476
|
-
_tryOnCleanup(dispose);
|
|
1477
|
-
return wrapper;
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
export { MemoryCache, deriveKey, FieldSelectionTracker, registerRelationSchema, getRelationSchema, resetRelationSchemas_TEST_ONLY, EntityStore, QueryEnvelopeStore, getEntityStore, getQueryEnvelopeStore, getMutationEventBus, query, queryMatch };
|
|
1375
|
+
export { MemoryCache, deriveKey, FieldSelectionTracker, registerRelationSchema, getRelationSchema, resetRelationSchemas_TEST_ONLY, EntityStore, QueryEnvelopeStore, getEntityStore, getQueryEnvelopeStore, getMutationEventBus, query };
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
beginDeferringMounts,
|
|
4
4
|
discardDeferredMounts,
|
|
5
5
|
flushDeferredMounts
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-svvqjmyy.js";
|
|
7
7
|
import {
|
|
8
8
|
__append,
|
|
9
9
|
__classList,
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
__enterChildren,
|
|
12
12
|
__exitChildren,
|
|
13
13
|
__staticText
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-djvarb8r.js";
|
|
15
15
|
import {
|
|
16
16
|
RouterContext
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-7nr2ebrf.js";
|
|
18
18
|
import {
|
|
19
19
|
isBrowser
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-xs5s8gqe.js";
|
|
21
21
|
import {
|
|
22
22
|
_tryOnCleanup,
|
|
23
23
|
createContext,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
startHydration,
|
|
33
33
|
untrack,
|
|
34
34
|
useContext
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-ppr06jgn.js";
|
|
36
36
|
|
|
37
37
|
// src/component/error-boundary-context.ts
|
|
38
38
|
var handlerStack = [];
|
|
@@ -5,10 +5,7 @@ import {
|
|
|
5
5
|
styleObjectToString
|
|
6
6
|
} from "./chunk-h1fsr8kv.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
isRenderNode
|
|
10
|
-
} from "./chunk-2y9f9j62.js";
|
|
11
|
-
import {
|
|
8
|
+
claimComment,
|
|
12
9
|
claimElement,
|
|
13
10
|
claimText,
|
|
14
11
|
deferredDomEffect,
|
|
@@ -16,39 +13,51 @@ import {
|
|
|
16
13
|
enterChildren,
|
|
17
14
|
exitChildren,
|
|
18
15
|
getIsHydrating,
|
|
16
|
+
getSSRContext,
|
|
19
17
|
pauseHydration,
|
|
20
18
|
popScope,
|
|
21
19
|
pushScope,
|
|
22
20
|
resumeHydration,
|
|
23
21
|
runCleanups
|
|
24
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ppr06jgn.js";
|
|
25
23
|
|
|
26
|
-
// src/dom/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
// src/dom/dom-adapter.ts
|
|
25
|
+
function createDOMAdapter() {
|
|
26
|
+
return {
|
|
27
|
+
createElement: (tag) => document.createElement(tag),
|
|
28
|
+
createElementNS: (ns, tag) => document.createElementNS(ns, tag),
|
|
29
|
+
createTextNode: (text) => document.createTextNode(text),
|
|
30
|
+
createComment: (text) => document.createComment(text),
|
|
31
|
+
createDocumentFragment: () => document.createDocumentFragment(),
|
|
32
|
+
isNode: (value) => typeof Node !== "undefined" && value instanceof Node
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/dom/adapter.ts
|
|
37
|
+
var RENDER_NODE_BRAND = Symbol.for("vertz:render-node");
|
|
38
|
+
function isRenderNode(value) {
|
|
39
|
+
if (value == null || typeof value !== "object")
|
|
40
|
+
return false;
|
|
41
|
+
if (RENDER_NODE_BRAND in value)
|
|
42
|
+
return true;
|
|
43
|
+
return typeof Node !== "undefined" && value instanceof Node;
|
|
44
|
+
}
|
|
45
|
+
var currentAdapter = null;
|
|
46
|
+
function getAdapter() {
|
|
47
|
+
const ctx = getSSRContext();
|
|
48
|
+
if (ctx)
|
|
49
|
+
return ctx.adapter;
|
|
50
|
+
if (!currentAdapter) {
|
|
51
|
+
currentAdapter = createDOMAdapter();
|
|
48
52
|
}
|
|
49
|
-
|
|
50
|
-
parent.appendChild(getAdapter().createTextNode(text));
|
|
53
|
+
return currentAdapter;
|
|
51
54
|
}
|
|
55
|
+
function setAdapter(adapter) {
|
|
56
|
+
currentAdapter = adapter;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/dom/element.ts
|
|
60
|
+
var MAX_THUNK_DEPTH = 100;
|
|
52
61
|
function __text(fn) {
|
|
53
62
|
if (getIsHydrating()) {
|
|
54
63
|
const claimed = claimText();
|
|
@@ -66,74 +75,112 @@ function __text(fn) {
|
|
|
66
75
|
});
|
|
67
76
|
return node;
|
|
68
77
|
}
|
|
78
|
+
function resolveAndInsertAfter(anchor, value, managed, depth = 0) {
|
|
79
|
+
if (depth >= MAX_THUNK_DEPTH) {
|
|
80
|
+
throw new Error("resolveAndInsertAfter: max recursion depth exceeded — possible circular thunk");
|
|
81
|
+
}
|
|
82
|
+
if (value == null || typeof value === "boolean")
|
|
83
|
+
return;
|
|
84
|
+
if (typeof value === "function") {
|
|
85
|
+
resolveAndInsertAfter(anchor, value(), managed, depth + 1);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
for (const item of value) {
|
|
90
|
+
resolveAndInsertAfter(anchor, item, managed, depth);
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const node = isRenderNode(value) ? value : getAdapter().createTextNode(typeof value === "string" ? value : String(value));
|
|
95
|
+
if (node.nodeType === 11) {
|
|
96
|
+
const children = Array.from(node.childNodes);
|
|
97
|
+
for (const child of children) {
|
|
98
|
+
const insertAfter2 = managed.length > 0 ? managed[managed.length - 1] : anchor;
|
|
99
|
+
insertAfter2.parentNode.insertBefore(child, insertAfter2.nextSibling);
|
|
100
|
+
managed.push(child);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const insertAfter = managed.length > 0 ? managed[managed.length - 1] : anchor;
|
|
105
|
+
insertAfter.parentNode.insertBefore(node, insertAfter.nextSibling);
|
|
106
|
+
managed.push(node);
|
|
107
|
+
}
|
|
108
|
+
function childEffect(anchor, fn, managed, childCleanups) {
|
|
109
|
+
return domEffect(() => {
|
|
110
|
+
runCleanups(childCleanups.value);
|
|
111
|
+
const scope = pushScope();
|
|
112
|
+
const value = fn();
|
|
113
|
+
popScope();
|
|
114
|
+
childCleanups.value = scope;
|
|
115
|
+
if (managed.length === 1 && isRenderNode(value) && managed[0] === value) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (managed.length === 1 && managed[0].nodeType === 3 && !isRenderNode(value) && value != null && typeof value !== "boolean" && typeof value !== "function") {
|
|
119
|
+
const text = typeof value === "string" ? value : String(value);
|
|
120
|
+
managed[0].data = text;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
for (const node of managed) {
|
|
124
|
+
node.parentNode?.removeChild(node);
|
|
125
|
+
}
|
|
126
|
+
managed.length = 0;
|
|
127
|
+
resolveAndInsertAfter(anchor, value, managed);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
69
130
|
function __child(fn) {
|
|
70
|
-
let wrapper;
|
|
71
131
|
if (getIsHydrating()) {
|
|
72
|
-
const claimed =
|
|
132
|
+
const claimed = claimComment();
|
|
73
133
|
if (claimed) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
134
|
+
const anchor2 = claimed;
|
|
135
|
+
const managed2 = [];
|
|
136
|
+
const childCleanups2 = { value: [] };
|
|
137
|
+
let sibling = anchor2.nextSibling;
|
|
138
|
+
while (sibling) {
|
|
139
|
+
if (sibling.nodeType === 8 && sibling.data.trim() === "child") {
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
const next = sibling.nextSibling;
|
|
143
|
+
sibling.parentNode?.removeChild(sibling);
|
|
144
|
+
sibling = next;
|
|
77
145
|
}
|
|
78
146
|
pauseHydration();
|
|
79
147
|
try {
|
|
80
|
-
|
|
81
|
-
wrapper.dispose = domEffect(() => {
|
|
82
|
-
runCleanups(childCleanups2);
|
|
148
|
+
const dispose2 = childEffect(anchor2, ((originalFn) => () => {
|
|
83
149
|
const needsPause = getIsHydrating();
|
|
84
150
|
if (needsPause)
|
|
85
151
|
pauseHydration();
|
|
86
152
|
try {
|
|
87
|
-
|
|
88
|
-
const value = fn();
|
|
89
|
-
popScope();
|
|
90
|
-
childCleanups2 = scope;
|
|
91
|
-
if (isRenderNode(value) && wrapper.childNodes.length === 1 && wrapper.firstChild === value) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (!isRenderNode(value) && value != null && typeof value !== "boolean" && wrapper.childNodes.length === 1 && wrapper.firstChild.nodeType === 3) {
|
|
95
|
-
const text = typeof value === "string" ? value : String(value);
|
|
96
|
-
wrapper.firstChild.data = text;
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
while (wrapper.firstChild) {
|
|
100
|
-
wrapper.removeChild(wrapper.firstChild);
|
|
101
|
-
}
|
|
102
|
-
resolveAndAppend(wrapper, value);
|
|
153
|
+
return originalFn();
|
|
103
154
|
} finally {
|
|
104
155
|
if (needsPause)
|
|
105
156
|
resumeHydration();
|
|
106
157
|
}
|
|
158
|
+
})(fn), managed2, childCleanups2);
|
|
159
|
+
const result2 = Object.assign(anchor2, {
|
|
160
|
+
dispose: () => {
|
|
161
|
+
runCleanups(childCleanups2.value);
|
|
162
|
+
dispose2();
|
|
163
|
+
}
|
|
107
164
|
});
|
|
165
|
+
return result2;
|
|
108
166
|
} finally {
|
|
109
167
|
resumeHydration();
|
|
110
168
|
}
|
|
111
|
-
return wrapper;
|
|
112
169
|
}
|
|
113
170
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (!isRenderNode(value) && value != null && typeof value !== "boolean" && typeof value !== "function" && wrapper.childNodes.length === 1 && wrapper.firstChild.nodeType === 3) {
|
|
127
|
-
const text = typeof value === "string" ? value : String(value);
|
|
128
|
-
wrapper.firstChild.data = text;
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
while (wrapper.firstChild) {
|
|
132
|
-
wrapper.removeChild(wrapper.firstChild);
|
|
171
|
+
const anchor = getAdapter().createComment("child");
|
|
172
|
+
const fragment = getAdapter().createDocumentFragment();
|
|
173
|
+
fragment.appendChild(anchor);
|
|
174
|
+
const managed = [];
|
|
175
|
+
const childCleanups = { value: [] };
|
|
176
|
+
const dispose = childEffect(anchor, fn, managed, childCleanups);
|
|
177
|
+
const result = Object.assign(fragment, {
|
|
178
|
+
dispose: () => {
|
|
179
|
+
runCleanups(childCleanups.value);
|
|
180
|
+
dispose();
|
|
133
181
|
}
|
|
134
|
-
resolveAndAppend(wrapper, value);
|
|
135
182
|
});
|
|
136
|
-
return
|
|
183
|
+
return result;
|
|
137
184
|
}
|
|
138
185
|
function resolveAndInsert(parent, value, depth = 0) {
|
|
139
186
|
if (depth >= MAX_THUNK_DEPTH) {
|
|
@@ -283,4 +330,4 @@ function __classList(el, classMap) {
|
|
|
283
330
|
};
|
|
284
331
|
}
|
|
285
332
|
|
|
286
|
-
export { __text, __child, __insert, __element, __append, __staticText, __enterChildren, __exitChildren, __attr, __prop, __show, __classList };
|
|
333
|
+
export { createDOMAdapter, RENDER_NODE_BRAND, isRenderNode, getAdapter, setAdapter, __text, __child, __insert, __element, __append, __staticText, __enterChildren, __exitChildren, __attr, __prop, __show, __classList };
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
} from "./chunk-jrtrk5z4.js";
|
|
8
8
|
import {
|
|
9
9
|
isBrowser
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-xs5s8gqe.js";
|
|
11
11
|
import {
|
|
12
12
|
getSSRContext,
|
|
13
13
|
signal
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-ppr06jgn.js";
|
|
15
15
|
|
|
16
16
|
// src/router/view-transitions.ts
|
|
17
17
|
var transitionGen = 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
computed,
|
|
3
3
|
signal
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ppr06jgn.js";
|
|
5
5
|
|
|
6
6
|
// src/form/field-state.ts
|
|
7
7
|
function createFieldState(_name, initialValue) {
|
|
@@ -103,6 +103,74 @@ function validate(schema, data) {
|
|
|
103
103
|
}
|
|
104
104
|
return { success: false, data: undefined, errors: { _form: "Validation failed" } };
|
|
105
105
|
}
|
|
106
|
+
function isSchemaLike(value) {
|
|
107
|
+
return value !== null && typeof value === "object" && "parse" in value && typeof value.parse === "function";
|
|
108
|
+
}
|
|
109
|
+
function resolveFieldSchema(schema, fieldPath) {
|
|
110
|
+
const shape = schema.shape;
|
|
111
|
+
if (!shape || typeof shape !== "object")
|
|
112
|
+
return;
|
|
113
|
+
const segments = fieldPath.split(".");
|
|
114
|
+
let current = shape;
|
|
115
|
+
for (let i = 0;i < segments.length; i++) {
|
|
116
|
+
if (!current || typeof current !== "object")
|
|
117
|
+
return;
|
|
118
|
+
const segment = segments[i];
|
|
119
|
+
let fieldSchema = current[segment];
|
|
120
|
+
if (i < segments.length - 1) {
|
|
121
|
+
let unwrapCount = 0;
|
|
122
|
+
while (fieldSchema && typeof fieldSchema === "object" && "unwrap" in fieldSchema && typeof fieldSchema.unwrap === "function" && !fieldSchema.shape && unwrapCount < 10) {
|
|
123
|
+
fieldSchema = fieldSchema.unwrap();
|
|
124
|
+
unwrapCount++;
|
|
125
|
+
}
|
|
126
|
+
if (fieldSchema && typeof fieldSchema === "object" && "shape" in fieldSchema && typeof fieldSchema.shape === "object") {
|
|
127
|
+
current = fieldSchema.shape;
|
|
128
|
+
} else {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
if (isSchemaLike(fieldSchema)) {
|
|
133
|
+
return fieldSchema;
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
function extractErrorFromParseResult(result) {
|
|
141
|
+
const err = result.error;
|
|
142
|
+
if (err instanceof Error) {
|
|
143
|
+
const issues = err.issues;
|
|
144
|
+
if (Array.isArray(issues) && issues.length > 0) {
|
|
145
|
+
return issues[0].message ?? "Validation failed";
|
|
146
|
+
}
|
|
147
|
+
return err.message;
|
|
148
|
+
}
|
|
149
|
+
return "Validation failed";
|
|
150
|
+
}
|
|
151
|
+
function validateField(schema, fieldName, value, formData) {
|
|
152
|
+
const fieldSchema = resolveFieldSchema(schema, fieldName);
|
|
153
|
+
if (fieldSchema) {
|
|
154
|
+
const result = fieldSchema.parse(value);
|
|
155
|
+
if (result.ok) {
|
|
156
|
+
return { valid: true, error: undefined };
|
|
157
|
+
}
|
|
158
|
+
const error = extractErrorFromParseResult(result);
|
|
159
|
+
return { valid: false, error };
|
|
160
|
+
}
|
|
161
|
+
if (formData) {
|
|
162
|
+
const result = validate(schema, formData);
|
|
163
|
+
if (result.success) {
|
|
164
|
+
return { valid: true, error: undefined };
|
|
165
|
+
}
|
|
166
|
+
const fieldError = result.errors[fieldName];
|
|
167
|
+
if (fieldError) {
|
|
168
|
+
return { valid: false, error: fieldError };
|
|
169
|
+
}
|
|
170
|
+
return { valid: true, error: undefined };
|
|
171
|
+
}
|
|
172
|
+
return { valid: true, error: undefined };
|
|
173
|
+
}
|
|
106
174
|
|
|
107
175
|
// src/form/form.ts
|
|
108
176
|
var FIELD_STATE_SIGNALS = new Set(["error", "dirty", "touched", "value"]);
|
|
@@ -112,6 +180,8 @@ function form(sdkMethod, options) {
|
|
|
112
180
|
const chainProxyCache = new Map;
|
|
113
181
|
const submitting = signal(false);
|
|
114
182
|
const fieldGeneration = signal(0);
|
|
183
|
+
const revalidateOn = options?.revalidateOn ?? "blur";
|
|
184
|
+
let hasSubmitted = false;
|
|
115
185
|
const dirty = computed(() => {
|
|
116
186
|
fieldGeneration.value;
|
|
117
187
|
for (const field of fieldCache.values()) {
|
|
@@ -178,6 +248,7 @@ function form(sdkMethod, options) {
|
|
|
178
248
|
}
|
|
179
249
|
const resolvedSchema = options?.schema ?? sdkMethod.meta?.bodySchema;
|
|
180
250
|
async function submitPipeline(formData) {
|
|
251
|
+
hasSubmitted = true;
|
|
181
252
|
const data = formDataToObject(formData, { nested: true });
|
|
182
253
|
if (resolvedSchema) {
|
|
183
254
|
const result2 = validate(resolvedSchema, data);
|
|
@@ -209,10 +280,42 @@ function form(sdkMethod, options) {
|
|
|
209
280
|
}
|
|
210
281
|
let boundElement;
|
|
211
282
|
function resetForm() {
|
|
283
|
+
hasSubmitted = false;
|
|
212
284
|
for (const field of fieldCache.values()) {
|
|
213
285
|
field.reset();
|
|
214
286
|
}
|
|
215
287
|
}
|
|
288
|
+
function assembleFormData() {
|
|
289
|
+
const result = {};
|
|
290
|
+
for (const [name, f] of fieldCache) {
|
|
291
|
+
const value = f.value.peek();
|
|
292
|
+
if (!name.includes(".")) {
|
|
293
|
+
result[name] = value;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const segments = name.split(".");
|
|
297
|
+
let current = result;
|
|
298
|
+
for (let i = 0;i < segments.length - 1; i++) {
|
|
299
|
+
const seg = segments[i];
|
|
300
|
+
if (!(seg in current) || typeof current[seg] !== "object" || current[seg] === null) {
|
|
301
|
+
current[seg] = {};
|
|
302
|
+
}
|
|
303
|
+
current = current[seg];
|
|
304
|
+
}
|
|
305
|
+
current[segments[segments.length - 1]] = value;
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
function revalidateFieldIfNeeded(fieldName) {
|
|
310
|
+
if (!hasSubmitted || revalidateOn === "submit" || !resolvedSchema)
|
|
311
|
+
return;
|
|
312
|
+
const field = fieldCache.get(fieldName);
|
|
313
|
+
if (!field || field.error.peek() === undefined)
|
|
314
|
+
return;
|
|
315
|
+
const formData = assembleFormData();
|
|
316
|
+
const result = validateField(resolvedSchema, fieldName, field.value.peek(), formData);
|
|
317
|
+
field.error.value = result.valid ? undefined : result.error;
|
|
318
|
+
}
|
|
216
319
|
async function submitPipelineWithReset(formData) {
|
|
217
320
|
await submitPipeline(formData);
|
|
218
321
|
if (options?.resetOnSuccess && !submitting.peek() && boundElement) {
|
|
@@ -228,6 +331,9 @@ function form(sdkMethod, options) {
|
|
|
228
331
|
return;
|
|
229
332
|
const field = getOrCreateField(target.name);
|
|
230
333
|
field.setValue(target.value);
|
|
334
|
+
if (revalidateOn === "change") {
|
|
335
|
+
revalidateFieldIfNeeded(target.name);
|
|
336
|
+
}
|
|
231
337
|
}
|
|
232
338
|
function handleFocusout(e) {
|
|
233
339
|
const target = e.target;
|
|
@@ -235,6 +341,9 @@ function form(sdkMethod, options) {
|
|
|
235
341
|
return;
|
|
236
342
|
const field = getOrCreateField(target.name);
|
|
237
343
|
field.touched.value = true;
|
|
344
|
+
if (revalidateOn === "blur") {
|
|
345
|
+
revalidateFieldIfNeeded(target.name);
|
|
346
|
+
}
|
|
238
347
|
}
|
|
239
348
|
const baseProperties = {
|
|
240
349
|
action: sdkMethod.url,
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
__element,
|
|
5
5
|
__enterChildren,
|
|
6
6
|
__exitChildren
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-djvarb8r.js";
|
|
8
8
|
import {
|
|
9
9
|
getSSRContext
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ppr06jgn.js";
|
|
11
11
|
|
|
12
12
|
// src/component/children.ts
|
|
13
13
|
var MAX_RESOLVE_DEPTH = 100;
|
|
@@ -411,7 +411,7 @@ function claimText() {
|
|
|
411
411
|
currentNode = text.nextSibling;
|
|
412
412
|
return text;
|
|
413
413
|
}
|
|
414
|
-
if (currentNode.nodeType === Node.ELEMENT_NODE) {
|
|
414
|
+
if (currentNode.nodeType === Node.ELEMENT_NODE || currentNode.nodeType === Node.COMMENT_NODE) {
|
|
415
415
|
break;
|
|
416
416
|
}
|
|
417
417
|
currentNode = currentNode.nextSibling;
|
|
@@ -466,8 +466,14 @@ function findUnclaimedNodes(root, claimed) {
|
|
|
466
466
|
continue;
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
|
-
if (child.nodeType === Node.
|
|
469
|
+
if (child.nodeType === Node.COMMENT_NODE && claimed.has(child) && child.data.trim() === "child") {
|
|
470
470
|
child = child.nextSibling;
|
|
471
|
+
while (child) {
|
|
472
|
+
if (child.nodeType === Node.COMMENT_NODE && child.data.trim() === "child") {
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
child = child.nextSibling;
|
|
476
|
+
}
|
|
471
477
|
continue;
|
|
472
478
|
}
|
|
473
479
|
if (!claimed.has(child)) {
|