@askrjs/askr 0.3.0 → 0.4.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/CHANGELOG.md +874 -0
- package/README.md +61 -29
- package/capabilities.json +19 -9
- package/dist/actions/index.js +56 -12
- package/dist/benchmark.js +10 -15
- package/dist/boot/index.d.ts +3 -2
- package/dist/boot/index.js +1 -1
- package/dist/boot-DaoTYoCw.js +3989 -0
- package/dist/browser-activity-CB8e-V4f.js +220 -0
- package/dist/components/index.d.ts +8 -1
- package/dist/components/index.js +1 -43
- package/dist/{aria-hKjThHcp.js → compose-ref-DWzdbxsD.js} +41 -4
- package/dist/control/index.d.ts +2 -0
- package/dist/control/index.js +1 -1
- package/dist/control-nfpT2fbK.js +209 -0
- package/dist/core.d.ts +5 -9
- package/dist/csp-nonce-DwGw1A6Q.js +35 -0
- package/dist/data/index.js +3 -3
- package/dist/{data-2edW0jhF.js → data-BCwClJiF.js} +283 -94
- package/dist/data-runtime-C1bFAlba.js +242 -0
- package/dist/{deferred-CbgNhf67.js → deferred-bEEHHvic.js} +42 -20
- package/dist/domains/actions.d.ts +8 -3
- package/dist/domains/component.d.ts +1 -107
- package/dist/domains/context.d.ts +0 -15
- package/dist/domains/control.d.ts +36 -249
- package/dist/domains/data.d.ts +31 -13
- package/dist/domains/diagnostics.d.ts +1 -2
- package/dist/domains/lifecycle.d.ts +2 -5
- package/dist/domains/refs.d.ts +0 -2
- package/dist/domains/routing.d.ts +43 -8
- package/dist/domains/scheduler.d.ts +1 -76
- package/dist/domains/server.d.ts +5 -2
- package/dist/domains/state.d.ts +2 -5
- package/dist/domains/telemetry.d.ts +0 -2
- package/dist/elements.d.ts +214 -51
- package/dist/error-boundary-Bpwofwps.js +293 -0
- package/dist/foundations/icon/index.d.ts +0 -58
- package/dist/foundations/icon/index.js +2 -2
- package/dist/foundations/index.js +2 -1
- package/dist/foundations/interactions/index.js +1 -1
- package/dist/foundations/state/index.d.ts +3 -3
- package/dist/foundations/state/index.js +5 -3
- package/dist/foundations/structures/index.js +2 -1
- package/dist/foundations/utilities/index.d.ts +2 -0
- package/dist/foundations/utilities/index.js +1 -2
- package/dist/fx/index.d.ts +31 -58
- package/dist/fx/index.js +313 -195
- package/dist/hooks-BimKStr4.js +202 -0
- package/dist/index.d.ts +11 -74
- package/dist/index.js +8 -447
- package/dist/instance-BAnfmXOR.js +988 -0
- package/dist/{interactions-CTeACdT_.js → interactions-D2BoREb-.js} +3 -2
- package/dist/jsx-dev-runtime.d.ts +41 -18
- package/dist/jsx-dev-runtime.js +1 -6
- package/dist/{jsx-runtime-CPJXAOBF.js → jsx-runtime-C4idqHY0.js} +18 -7
- package/dist/jsx-runtime.js +1 -1
- package/dist/jsx.d.ts +61 -37
- package/dist/{manifest-D1P3UNWV.js → manifest-CW9gyNBY.js} +3 -3
- package/dist/{navigate-prC5V8XV.js → navigate-CP_0Zy5U.js} +454 -87
- package/dist/navigation.d.ts +12 -3
- package/dist/peer-types.d.ts +8 -0
- package/dist/portal-DuOKfnLa.js +349 -0
- package/dist/promise-Dz8iIHAm.js +16 -0
- package/dist/query-registry-WMCN0BJL.js +320 -0
- package/dist/readable-DFWOsTac.js +21 -0
- package/dist/{render-context-B7ohlh6t.js → render-context-DGHnEveC.js} +27 -11
- package/dist/render-sync-IC5lMFpq.js +1240 -0
- package/dist/resolution-Cx82-xjW.js +1244 -0
- package/dist/resource-CLjB7RBQ.js +377 -0
- package/dist/resources/index.d.ts +21 -11
- package/dist/resources/index.js +45 -244
- package/dist/router/index.d.ts +14 -5
- package/dist/router/index.js +22 -53
- package/dist/scope-CwpVSHVf.js +55 -0
- package/dist/{shared-kU8yvryp.js → shared-O2ZnmYAf.js} +1 -7
- package/dist/{snapshot-source-An4iKajG.js → snapshot-Cjx4N988.js} +6 -1
- package/dist/ssg/index.d.ts +1 -2
- package/dist/ssg/index.js +5 -13
- package/dist/ssr/index.d.ts +26 -28
- package/dist/ssr/index.js +4 -4
- package/dist/{ssr-CiNm6Vzl.js → ssr-BJ8ug7zH.js} +133 -122
- package/dist/ssr-DoV-vJ-5.js +229 -0
- package/dist/state-DWO1KzkX.js +232 -0
- package/dist/structures-D4dDMqHX.js +231 -0
- package/dist/testing/index.d.ts +8 -4
- package/dist/testing/index.js +29 -34
- package/dist/url-CnbfpX0K.js +185 -0
- package/dist/utilities.d.ts +48 -2
- package/dist/verify-hydration-DpVaDnqz.js +152 -0
- package/package.json +19 -9
- package/dist/access-CEA2pOry.js +0 -1046
- package/dist/activity-oy2YFTFF.js +0 -201
- package/dist/boot-BMBMWUGI.js +0 -1084
- package/dist/capabilities-Bbf0mlp9.js +0 -42
- package/dist/compose-ref-v0qGlHoN.js +0 -26
- package/dist/control-BR_mrX__.js +0 -173
- package/dist/control-C-ApnFs1.js +0 -20
- package/dist/csp-nonce-BfFWcd0w.js +0 -173
- package/dist/data-runtime-CxoY98lX.js +0 -149
- package/dist/default-portal-runtime-DvMvWJVp.js +0 -20
- package/dist/dom-renderer.d.ts +0 -77
- package/dist/domains/renderer.d.ts +0 -127
- package/dist/eager-control.d.ts +0 -8
- package/dist/effect-C3Zsc1k6.js +0 -292
- package/dist/for-state-BDykeOJL.js +0 -1753
- package/dist/instance-VAFYVJOa.js +0 -1027
- package/dist/notify-DxxuDPeY.js +0 -266
- package/dist/portal-w3oQ6oQU.js +0 -29
- package/dist/query-registry-LrYpQsDJ.js +0 -83
- package/dist/render-resolved-BC0W7_5b.js +0 -1123
- package/dist/renderer-CT0HeY58.js +0 -8623
- package/dist/resolution-3DskUkjG.js +0 -577
- package/dist/resource-18-sFRl9.js +0 -344
- package/dist/route-matching-CUzZ31gT.js +0 -551
- package/dist/router-internal-7nuNEHfG.js +0 -36
- package/dist/scope-Cq_iYbTR.js +0 -403
- package/dist/selector-BSPVkjKP.js +0 -311
- package/dist/ssr-EPjwJH5R.js +0 -29
- package/dist/state-BXJfudq1.js +0 -91
- package/dist/structures-CjEzfj4h.js +0 -654
- package/dist/timer-C7uqnJVt.js +0 -85
- package/dist/verify-hydration-ikaxotf7.js +0 -27
- package/dist/vnode-D24p6IW2.js +0 -7
|
@@ -1,654 +0,0 @@
|
|
|
1
|
-
import { i as getRuntimeCleanup } from "./access-CEA2pOry.js";
|
|
2
|
-
import { O as ownCleanup, f as getCurrentComponentInstance, p as getCurrentPortalScope } from "./scope-Cq_iYbTR.js";
|
|
3
|
-
import { c as registerCommitEffect, s as getCurrentCommitTransaction, t as notifyReadableSource, v as recordReadableRead } from "./notify-DxxuDPeY.js";
|
|
4
|
-
import { n as Fragment, t as ELEMENT_TYPE } from "./jsx-DRS-qjiN.js";
|
|
5
|
-
import { n as getActiveRenderContext } from "./render-context-B7ohlh6t.js";
|
|
6
|
-
import { i as createSSRPortalHostToken, n as SSR_PORTAL_HOST, r as createSSRPortalAnchorToken, t as SSR_PORTAL_ANCHOR } from "./portal-w3oQ6oQU.js";
|
|
7
|
-
import { i as registerDefaultPortalRuntime } from "./default-portal-runtime-DvMvWJVp.js";
|
|
8
|
-
//#region src/jsx/utils.ts
|
|
9
|
-
/** Check whether `value` is a JSX element vnode. */
|
|
10
|
-
function isElement(value) {
|
|
11
|
-
return typeof value === "object" && value !== null && value.$$typeof === ELEMENT_TYPE;
|
|
12
|
-
}
|
|
13
|
-
/** Clone a JSX element, shallow-merging `props` over its existing props. */
|
|
14
|
-
function cloneElement(element, props) {
|
|
15
|
-
return {
|
|
16
|
-
$$typeof: element.$$typeof,
|
|
17
|
-
type: element.type,
|
|
18
|
-
key: element.key,
|
|
19
|
-
props: {
|
|
20
|
-
...element.props,
|
|
21
|
-
...props
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/foundations/structures/layout.tsx
|
|
27
|
-
/**
|
|
28
|
-
* Wrap a {@link LayoutComponent} so it can be invoked as `(children, props)`,
|
|
29
|
-
* matching route layout conventions.
|
|
30
|
-
*/
|
|
31
|
-
function layout(Layout) {
|
|
32
|
-
return (children, props) => {
|
|
33
|
-
return Layout({
|
|
34
|
-
...props,
|
|
35
|
-
children
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/foundations/structures/slot.tsx
|
|
41
|
-
/**
|
|
42
|
-
* Slot
|
|
43
|
-
*
|
|
44
|
-
* Structural primitive for prop forwarding patterns.
|
|
45
|
-
*
|
|
46
|
-
* POLICY DECISIONS (LOCKED):
|
|
47
|
-
*
|
|
48
|
-
* 1. asChild Pattern
|
|
49
|
-
* When asChild=true, merges props into the single child element.
|
|
50
|
-
* Child must be a valid JSXElement; non-element children return null.
|
|
51
|
-
* **Slot props override child props** (injection pattern).
|
|
52
|
-
*
|
|
53
|
-
* 2. Fallback Behavior
|
|
54
|
-
* When asChild=false, returns a Fragment (structural no-op).
|
|
55
|
-
* No DOM element is introduced.
|
|
56
|
-
*
|
|
57
|
-
* 3. Type Safety
|
|
58
|
-
* asChild=true requires exactly one JSXElement child (enforced by type).
|
|
59
|
-
* Runtime validates with isElement() check.
|
|
60
|
-
*/
|
|
61
|
-
function Slot(props) {
|
|
62
|
-
if (props.asChild) {
|
|
63
|
-
const { children, asChild: _asChild, ...rest } = props;
|
|
64
|
-
if (isElement(children)) return cloneElement(children, rest);
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
$$typeof: ELEMENT_TYPE,
|
|
69
|
-
type: Fragment,
|
|
70
|
-
props: { children: props.children },
|
|
71
|
-
key: null
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/foundations/structures/presence.ts
|
|
76
|
-
/**
|
|
77
|
-
* Presence
|
|
78
|
-
*
|
|
79
|
-
* Structural policy primitive for conditional mount/unmount.
|
|
80
|
-
* - No timers
|
|
81
|
-
* - No animation coupling
|
|
82
|
-
* - No DOM side-effects
|
|
83
|
-
*
|
|
84
|
-
* POLICY DECISIONS (LOCKED):
|
|
85
|
-
*
|
|
86
|
-
* 1. Present as Function
|
|
87
|
-
* Accepts boolean OR function to support lazy evaluation patterns.
|
|
88
|
-
* Function is called once per render. Use boolean form for static values.
|
|
89
|
-
*
|
|
90
|
-
* 2. Children Type
|
|
91
|
-
* Presence forwards normal renderable child content only.
|
|
92
|
-
* Imperative DOM nodes are not part of the public contract.
|
|
93
|
-
*
|
|
94
|
-
* 3. Immediate Mount/Unmount
|
|
95
|
-
* No exit animations or transitions. When `present` becomes false,
|
|
96
|
-
* children are removed immediately. Animation must be layered above
|
|
97
|
-
* this primitive.
|
|
98
|
-
*/
|
|
99
|
-
function Presence({ present, children }) {
|
|
100
|
-
if (!(typeof present === "function" ? present() : Boolean(present))) return null;
|
|
101
|
-
return {
|
|
102
|
-
$$typeof: ELEMENT_TYPE,
|
|
103
|
-
type: Fragment,
|
|
104
|
-
props: { children },
|
|
105
|
-
key: null
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/runtime/portal/ssr.ts
|
|
110
|
-
const DEFAULT_SSR_PORTAL_KEY = {};
|
|
111
|
-
function getSSRPortalSlot(key) {
|
|
112
|
-
const context = getActiveRenderContext();
|
|
113
|
-
if (context?.mode !== "ssr") return null;
|
|
114
|
-
let slot = context.ssrPortals.slots.get(key);
|
|
115
|
-
if (!slot) {
|
|
116
|
-
slot = {
|
|
117
|
-
hasValue: false,
|
|
118
|
-
value: void 0,
|
|
119
|
-
hosts: []
|
|
120
|
-
};
|
|
121
|
-
context.ssrPortals.slots.set(key, slot);
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
context,
|
|
125
|
-
slot
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
function createSSRPortalHost(key, automatic) {
|
|
129
|
-
const current = getSSRPortalSlot(key);
|
|
130
|
-
if (!current) return null;
|
|
131
|
-
const token = createSSRPortalHostToken(current.context.ssrPortals.nextHostId++);
|
|
132
|
-
current.slot.hosts.push({
|
|
133
|
-
token,
|
|
134
|
-
automatic
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
$$typeof: ELEMENT_TYPE,
|
|
138
|
-
type: SSR_PORTAL_HOST,
|
|
139
|
-
props: { token }
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function writeSSRPortal(key, children) {
|
|
143
|
-
const current = getSSRPortalSlot(key);
|
|
144
|
-
if (!current) return false;
|
|
145
|
-
current.slot.hasValue = true;
|
|
146
|
-
current.slot.value = children;
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
function createSSRPortalAnchor() {
|
|
150
|
-
const context = getActiveRenderContext();
|
|
151
|
-
if (context?.mode !== "ssr") return null;
|
|
152
|
-
const token = createSSRPortalAnchorToken(context.ssrPortals.nextHostId++);
|
|
153
|
-
return {
|
|
154
|
-
$$typeof: ELEMENT_TYPE,
|
|
155
|
-
type: SSR_PORTAL_ANCHOR,
|
|
156
|
-
props: { token }
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region src/runtime/portal/lifetime.ts
|
|
161
|
-
function setPortalErrorParent(host, owner) {
|
|
162
|
-
if (!host) return;
|
|
163
|
-
if (owner && owner.instance.owner.identity === owner.generation && owner.instance.notifyUpdate !== null) {
|
|
164
|
-
host._portalErrorParent = owner.instance;
|
|
165
|
-
host._portalErrorParentGeneration = owner.generation;
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
host._portalErrorParent = null;
|
|
169
|
-
host._portalErrorParentGeneration = void 0;
|
|
170
|
-
}
|
|
171
|
-
function createPortalSlot() {
|
|
172
|
-
let currentValue;
|
|
173
|
-
let currentOwner = null;
|
|
174
|
-
const source = (() => {
|
|
175
|
-
recordReadableRead(source);
|
|
176
|
-
return currentValue;
|
|
177
|
-
});
|
|
178
|
-
return {
|
|
179
|
-
read() {
|
|
180
|
-
return source();
|
|
181
|
-
},
|
|
182
|
-
write(value, owner) {
|
|
183
|
-
const ownerChanged = currentOwner?.instance !== owner?.instance || currentOwner?.generation !== owner?.generation;
|
|
184
|
-
currentOwner = owner;
|
|
185
|
-
if (Object.is(currentValue, value) && !ownerChanged) return;
|
|
186
|
-
currentValue = value;
|
|
187
|
-
notifyReadableSource(source);
|
|
188
|
-
},
|
|
189
|
-
getOwner() {
|
|
190
|
-
return currentOwner;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
//#endregion
|
|
195
|
-
//#region src/runtime/portal/explicit.ts
|
|
196
|
-
/** Create a new named {@link Portal} channel with its own host and content. */
|
|
197
|
-
function definePortal() {
|
|
198
|
-
const ssrPortalKey = {};
|
|
199
|
-
if (typeof createPortalSlot === "function") {
|
|
200
|
-
const slot = createPortalSlot();
|
|
201
|
-
function PortalHost() {
|
|
202
|
-
const serverHost = createSSRPortalHost(ssrPortalKey, false);
|
|
203
|
-
if (serverHost) return serverHost;
|
|
204
|
-
const host = getCurrentComponentInstance();
|
|
205
|
-
if (host?.fn === PortalHost) setPortalErrorParent(host, slot.getOwner());
|
|
206
|
-
return slot.read();
|
|
207
|
-
}
|
|
208
|
-
PortalHost.render = function PortalRender(props) {
|
|
209
|
-
if (writeSSRPortal(ssrPortalKey, props.children)) return null;
|
|
210
|
-
const owner = getCurrentComponentInstance();
|
|
211
|
-
slot.write(props.children, owner ? {
|
|
212
|
-
instance: owner,
|
|
213
|
-
generation: owner.owner.identity
|
|
214
|
-
} : null);
|
|
215
|
-
return null;
|
|
216
|
-
};
|
|
217
|
-
return PortalHost;
|
|
218
|
-
}
|
|
219
|
-
let mounted = false;
|
|
220
|
-
let value;
|
|
221
|
-
function PortalHostFallback() {
|
|
222
|
-
mounted = true;
|
|
223
|
-
return value;
|
|
224
|
-
}
|
|
225
|
-
PortalHostFallback.render = function PortalRenderFallback(props) {
|
|
226
|
-
if (!mounted) return null;
|
|
227
|
-
value = props.children;
|
|
228
|
-
return null;
|
|
229
|
-
};
|
|
230
|
-
return PortalHostFallback;
|
|
231
|
-
}
|
|
232
|
-
//#endregion
|
|
233
|
-
//#region src/runtime/portal/portal.ts
|
|
234
|
-
let _defaultPortalStates = /* @__PURE__ */ new Map();
|
|
235
|
-
let _hasPendingDefaultPortalValue = false;
|
|
236
|
-
let _pendingDefaultPortalValue = void 0;
|
|
237
|
-
let _pendingDefaultPortalWrites = /* @__PURE__ */ new WeakMap();
|
|
238
|
-
const _batchPortalWrites = /* @__PURE__ */ new WeakMap();
|
|
239
|
-
function trackBatchPortalWrite(batch, state, transaction) {
|
|
240
|
-
let current = batch;
|
|
241
|
-
while (current) {
|
|
242
|
-
let writes = _batchPortalWrites.get(current);
|
|
243
|
-
if (!writes) {
|
|
244
|
-
writes = /* @__PURE__ */ new Map();
|
|
245
|
-
_batchPortalWrites.set(current, writes);
|
|
246
|
-
}
|
|
247
|
-
if (!writes.has(state)) writes.set(state, transaction);
|
|
248
|
-
current = current.parent;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function clearTrackedBatchPortalWrite(transaction) {
|
|
252
|
-
let batch = transaction.batch ?? null;
|
|
253
|
-
while (batch) {
|
|
254
|
-
const writes = _batchPortalWrites.get(batch);
|
|
255
|
-
if (writes?.get(transaction.state) === transaction) writes.delete(transaction.state);
|
|
256
|
-
batch = batch.parent;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function createPortalStateSource(readCount) {
|
|
260
|
-
let source = (() => {
|
|
261
|
-
recordReadableRead(source);
|
|
262
|
-
return readCount();
|
|
263
|
-
});
|
|
264
|
-
return source;
|
|
265
|
-
}
|
|
266
|
-
function readExplicitDefaultPortalHosts(state) {
|
|
267
|
-
return state.explicitHostSource();
|
|
268
|
-
}
|
|
269
|
-
function notifyExplicitDefaultPortalHostReaders(state) {
|
|
270
|
-
notifyReadableSource(state.explicitHostSource);
|
|
271
|
-
}
|
|
272
|
-
function setDefaultPortalOwner(state, owner) {
|
|
273
|
-
if (state.owner?.instance === owner?.instance && state.owner?.generation === owner?.generation) return;
|
|
274
|
-
state.owner = owner;
|
|
275
|
-
state.ownerVersion += 1;
|
|
276
|
-
notifyReadableSource(state.ownerSource);
|
|
277
|
-
}
|
|
278
|
-
function createDefaultPortalState() {
|
|
279
|
-
const state = {
|
|
280
|
-
portal: definePortal(),
|
|
281
|
-
owner: null,
|
|
282
|
-
host: null,
|
|
283
|
-
cleanupOwners: /* @__PURE__ */ new WeakSet(),
|
|
284
|
-
explicitHostOwners: /* @__PURE__ */ new Map(),
|
|
285
|
-
explicitHostCleanupOwners: /* @__PURE__ */ new WeakSet(),
|
|
286
|
-
explicitHostSource: (() => 0),
|
|
287
|
-
ownerVersion: 0,
|
|
288
|
-
ownerSource: (() => 0)
|
|
289
|
-
};
|
|
290
|
-
state.explicitHostSource = createPortalStateSource(() => state.explicitHostOwners.size);
|
|
291
|
-
state.ownerSource = createPortalStateSource(() => state.ownerVersion);
|
|
292
|
-
return state;
|
|
293
|
-
}
|
|
294
|
-
function disposeDefaultPortalScope(scope) {
|
|
295
|
-
if (!scope) return;
|
|
296
|
-
const state = _defaultPortalStates.get(scope);
|
|
297
|
-
if (state) state.portal.render({ children: void 0 });
|
|
298
|
-
_defaultPortalStates.delete(scope);
|
|
299
|
-
}
|
|
300
|
-
function isComponentPortalScope(scope) {
|
|
301
|
-
return "lifecycleGeneration" in scope && "evaluationGeneration" in scope && "parentInstance" in scope;
|
|
302
|
-
}
|
|
303
|
-
function isEmptyPortalValue(value) {
|
|
304
|
-
return value === null || value === void 0 || value === false;
|
|
305
|
-
}
|
|
306
|
-
function detachDefaultPortalHostOutput(state) {
|
|
307
|
-
if (state.host) getRuntimeCleanup().detachPortalHostOutput(state.host.instance);
|
|
308
|
-
}
|
|
309
|
-
function applyDefaultPortalWrite(state, children, owner) {
|
|
310
|
-
state.portal.render({ children });
|
|
311
|
-
setDefaultPortalOwner(state, owner);
|
|
312
|
-
if (isEmptyPortalValue(children)) detachDefaultPortalHostOutput(state);
|
|
313
|
-
}
|
|
314
|
-
function isStaleDefaultPortalScope(scope) {
|
|
315
|
-
if (!isComponentPortalScope(scope)) return false;
|
|
316
|
-
if (getRuntimeCleanup().isComponentHostDetached(scope)) return true;
|
|
317
|
-
return scope.owner.mounted === false;
|
|
318
|
-
}
|
|
319
|
-
function pruneStaleDefaultPortalScopes() {
|
|
320
|
-
if (_defaultPortalStates.size === 0) return;
|
|
321
|
-
for (const scope of Array.from(_defaultPortalStates.keys())) if (isStaleDefaultPortalScope(scope)) disposeDefaultPortalScope(scope);
|
|
322
|
-
}
|
|
323
|
-
function getSingleDefaultPortalScope() {
|
|
324
|
-
pruneStaleDefaultPortalScopes();
|
|
325
|
-
if (_defaultPortalStates.size !== 1) return null;
|
|
326
|
-
return _defaultPortalStates.keys().next().value ?? null;
|
|
327
|
-
}
|
|
328
|
-
function getDefaultPortalState(scope) {
|
|
329
|
-
let state = _defaultPortalStates.get(scope);
|
|
330
|
-
if (!state) {
|
|
331
|
-
state = createDefaultPortalState();
|
|
332
|
-
_defaultPortalStates.set(scope, state);
|
|
333
|
-
}
|
|
334
|
-
return state;
|
|
335
|
-
}
|
|
336
|
-
function resolveDefaultPortalScope(owner) {
|
|
337
|
-
return owner?.portalScope ?? getCurrentPortalScope() ?? getSingleDefaultPortalScope();
|
|
338
|
-
}
|
|
339
|
-
function writeDefaultPortal(props, owner) {
|
|
340
|
-
const scope = resolveDefaultPortalScope(owner);
|
|
341
|
-
if (!scope) {
|
|
342
|
-
if (_defaultPortalStates.size !== 0) return;
|
|
343
|
-
_hasPendingDefaultPortalValue = true;
|
|
344
|
-
_pendingDefaultPortalValue = props.children;
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
const state = getDefaultPortalState(scope);
|
|
348
|
-
const capturedOwner = owner ? {
|
|
349
|
-
instance: owner,
|
|
350
|
-
generation: owner.owner.identity
|
|
351
|
-
} : null;
|
|
352
|
-
const batch = getCurrentCommitTransaction();
|
|
353
|
-
if (batch) {
|
|
354
|
-
let writes = _batchPortalWrites.get(batch);
|
|
355
|
-
if (!writes) {
|
|
356
|
-
writes = /* @__PURE__ */ new Map();
|
|
357
|
-
_batchPortalWrites.set(batch, writes);
|
|
358
|
-
}
|
|
359
|
-
const existing = writes.get(state);
|
|
360
|
-
if (existing) {
|
|
361
|
-
existing.owner = capturedOwner;
|
|
362
|
-
existing.children = props.children;
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
const transaction = {
|
|
366
|
-
state,
|
|
367
|
-
owner: capturedOwner,
|
|
368
|
-
children: props.children,
|
|
369
|
-
batch
|
|
370
|
-
};
|
|
371
|
-
if (registerCommitEffect(state, () => {
|
|
372
|
-
if (_batchPortalWrites.get(batch)?.get(state) !== transaction) return;
|
|
373
|
-
clearTrackedBatchPortalWrite(transaction);
|
|
374
|
-
applyDefaultPortalWrite(state, transaction.children, transaction.owner);
|
|
375
|
-
}, () => {
|
|
376
|
-
clearTrackedBatchPortalWrite(transaction);
|
|
377
|
-
}, () => {
|
|
378
|
-
const parentBatch = batch.parent;
|
|
379
|
-
const parentWrite = parentBatch ? _batchPortalWrites.get(parentBatch)?.get(state) : void 0;
|
|
380
|
-
if (parentWrite && parentWrite !== transaction) {
|
|
381
|
-
parentWrite.owner = transaction.owner;
|
|
382
|
-
parentWrite.children = transaction.children;
|
|
383
|
-
}
|
|
384
|
-
clearTrackedBatchPortalWrite(transaction);
|
|
385
|
-
})) {
|
|
386
|
-
trackBatchPortalWrite(batch, state, transaction);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
const pending = _pendingDefaultPortalWrites.get(state);
|
|
391
|
-
if (pending) {
|
|
392
|
-
pending.owner = capturedOwner;
|
|
393
|
-
pending.children = props.children;
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
const transaction = {
|
|
397
|
-
state,
|
|
398
|
-
owner: capturedOwner,
|
|
399
|
-
children: props.children
|
|
400
|
-
};
|
|
401
|
-
if (registerCommitEffect(transaction, () => {
|
|
402
|
-
if (_pendingDefaultPortalWrites.get(state) !== transaction) return;
|
|
403
|
-
_pendingDefaultPortalWrites.delete(state);
|
|
404
|
-
_hasPendingDefaultPortalValue = false;
|
|
405
|
-
_pendingDefaultPortalValue = void 0;
|
|
406
|
-
applyDefaultPortalWrite(state, transaction.children, transaction.owner);
|
|
407
|
-
}, () => {
|
|
408
|
-
if (_pendingDefaultPortalWrites.get(state) === transaction) _pendingDefaultPortalWrites.delete(state);
|
|
409
|
-
})) {
|
|
410
|
-
_pendingDefaultPortalWrites.set(state, transaction);
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
_hasPendingDefaultPortalValue = false;
|
|
414
|
-
_pendingDefaultPortalValue = void 0;
|
|
415
|
-
applyDefaultPortalWrite(state, props.children, capturedOwner);
|
|
416
|
-
}
|
|
417
|
-
function applyPendingDefaultPortalValue(scope) {
|
|
418
|
-
if (!_hasPendingDefaultPortalValue) return;
|
|
419
|
-
const state = getDefaultPortalState(scope);
|
|
420
|
-
state.portal.render({ children: _pendingDefaultPortalValue });
|
|
421
|
-
setDefaultPortalOwner(state, null);
|
|
422
|
-
_hasPendingDefaultPortalValue = false;
|
|
423
|
-
_pendingDefaultPortalValue = void 0;
|
|
424
|
-
}
|
|
425
|
-
function getPendingDefaultPortalWrite(state) {
|
|
426
|
-
let batch = getCurrentCommitTransaction();
|
|
427
|
-
while (batch) {
|
|
428
|
-
const pending = _batchPortalWrites.get(batch)?.get(state);
|
|
429
|
-
if (pending) return pending;
|
|
430
|
-
batch = batch.parent;
|
|
431
|
-
}
|
|
432
|
-
return _pendingDefaultPortalWrites.get(state);
|
|
433
|
-
}
|
|
434
|
-
function hasPendingReplacementPortalOwner(state, owner, generation) {
|
|
435
|
-
const pendingOwner = getPendingDefaultPortalWrite(state)?.owner;
|
|
436
|
-
return Boolean(pendingOwner && (pendingOwner.instance !== owner || pendingOwner.generation !== generation));
|
|
437
|
-
}
|
|
438
|
-
function registerDefaultPortalOwner(owner) {
|
|
439
|
-
const scope = resolveDefaultPortalScope(owner);
|
|
440
|
-
if (!scope) return;
|
|
441
|
-
const state = getDefaultPortalState(scope);
|
|
442
|
-
const generation = owner.owner.identity;
|
|
443
|
-
if (state.cleanupOwners.has(generation)) return;
|
|
444
|
-
state.cleanupOwners.add(generation);
|
|
445
|
-
ownCleanup(owner.owner, () => {
|
|
446
|
-
const currentState = _defaultPortalStates.get(scope);
|
|
447
|
-
if (!currentState) return;
|
|
448
|
-
if (currentState.owner?.instance === owner && currentState.owner.generation === generation && !hasPendingReplacementPortalOwner(currentState, owner, generation)) applyDefaultPortalWrite(currentState, void 0, null);
|
|
449
|
-
if (currentState.cleanupOwners.delete(generation)) {}
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
function registerExplicitDefaultPortalHost(scope, state, owner) {
|
|
453
|
-
if (!owner) return;
|
|
454
|
-
const generation = owner.owner.identity;
|
|
455
|
-
if (!state.explicitHostOwners.has(generation)) {
|
|
456
|
-
state.explicitHostOwners.set(generation, owner);
|
|
457
|
-
notifyExplicitDefaultPortalHostReaders(state);
|
|
458
|
-
}
|
|
459
|
-
if (!state.explicitHostCleanupOwners.has(generation)) {
|
|
460
|
-
state.explicitHostCleanupOwners.add(generation);
|
|
461
|
-
ownCleanup(owner.owner, () => {
|
|
462
|
-
if (_defaultPortalStates.get(scope) !== state) return;
|
|
463
|
-
state.explicitHostCleanupOwners.delete(generation);
|
|
464
|
-
if (state.explicitHostOwners.get(generation) === owner && state.explicitHostOwners.delete(generation)) notifyExplicitDefaultPortalHostReaders(state);
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
function clearDefaultPortalForInstance(instance) {
|
|
469
|
-
const scope = instance.portalScope;
|
|
470
|
-
if (!scope) return;
|
|
471
|
-
const state = _defaultPortalStates.get(scope);
|
|
472
|
-
if (!state) return;
|
|
473
|
-
_hasPendingDefaultPortalValue = false;
|
|
474
|
-
_pendingDefaultPortalValue = void 0;
|
|
475
|
-
state.portal.render({ children: void 0 });
|
|
476
|
-
setDefaultPortalOwner(state, null);
|
|
477
|
-
detachDefaultPortalHostOutput(state);
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* The implicit portal channel that {@link Portal} writes to and that any
|
|
481
|
-
* host rendered without an explicit portal falls back to.
|
|
482
|
-
*/
|
|
483
|
-
const DefaultPortal = (() => {
|
|
484
|
-
function Host(props) {
|
|
485
|
-
const serverHost = createSSRPortalHost(DEFAULT_SSR_PORTAL_KEY, props?.__askrAutoDefaultPortal === true);
|
|
486
|
-
if (serverHost) return serverHost;
|
|
487
|
-
const owner = getCurrentComponentInstance();
|
|
488
|
-
const scope = resolveDefaultPortalScope(owner);
|
|
489
|
-
if (!scope) return null;
|
|
490
|
-
const state = getDefaultPortalState(scope);
|
|
491
|
-
state.host = owner ? {
|
|
492
|
-
instance: owner,
|
|
493
|
-
generation: owner.owner.identity
|
|
494
|
-
} : null;
|
|
495
|
-
if (!(props?.__askrAutoDefaultPortal === true)) registerExplicitDefaultPortalHost(scope, state, owner);
|
|
496
|
-
else if (readExplicitDefaultPortalHosts(state) > 0) return null;
|
|
497
|
-
applyPendingDefaultPortalValue(scope);
|
|
498
|
-
state.ownerSource();
|
|
499
|
-
setPortalErrorParent(owner, state.owner);
|
|
500
|
-
const value = state.portal();
|
|
501
|
-
return value === void 0 ? null : value;
|
|
502
|
-
}
|
|
503
|
-
Host.render = function Render(props) {
|
|
504
|
-
if (writeSSRPortal(DEFAULT_SSR_PORTAL_KEY, props.children)) return null;
|
|
505
|
-
writeDefaultPortal(props, getCurrentComponentInstance());
|
|
506
|
-
return null;
|
|
507
|
-
};
|
|
508
|
-
return Host;
|
|
509
|
-
})();
|
|
510
|
-
/** Write children to the {@link DefaultPortal} host wherever it is rendered. */
|
|
511
|
-
function Portal(props) {
|
|
512
|
-
if (writeSSRPortal(DEFAULT_SSR_PORTAL_KEY, props.children)) return createSSRPortalAnchor();
|
|
513
|
-
const owner = getCurrentComponentInstance();
|
|
514
|
-
if (owner) registerDefaultPortalOwner(owner);
|
|
515
|
-
writeDefaultPortal(props, owner);
|
|
516
|
-
return null;
|
|
517
|
-
}
|
|
518
|
-
registerDefaultPortalRuntime({
|
|
519
|
-
host: DefaultPortal,
|
|
520
|
-
clearForInstance(instance) {
|
|
521
|
-
clearDefaultPortalForInstance(instance);
|
|
522
|
-
},
|
|
523
|
-
disposeScope: disposeDefaultPortalScope
|
|
524
|
-
});
|
|
525
|
-
//#endregion
|
|
526
|
-
//#region src/foundations/structures/collection.ts
|
|
527
|
-
/** Create an empty, insertion-ordered {@link Collection} registry. */
|
|
528
|
-
function createCollection() {
|
|
529
|
-
const registry = /* @__PURE__ */ new Map();
|
|
530
|
-
function register(node, metadata) {
|
|
531
|
-
const item = {
|
|
532
|
-
node,
|
|
533
|
-
metadata
|
|
534
|
-
};
|
|
535
|
-
registry.set(node, item);
|
|
536
|
-
return () => {
|
|
537
|
-
registry.delete(node);
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
function items() {
|
|
541
|
-
return Array.from(registry.values());
|
|
542
|
-
}
|
|
543
|
-
function clear() {
|
|
544
|
-
registry.clear();
|
|
545
|
-
}
|
|
546
|
-
function size() {
|
|
547
|
-
return registry.size;
|
|
548
|
-
}
|
|
549
|
-
return {
|
|
550
|
-
register,
|
|
551
|
-
items,
|
|
552
|
-
clear,
|
|
553
|
-
size
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* USAGE EXAMPLE:
|
|
558
|
-
*
|
|
559
|
-
* // Create a collection for menu items
|
|
560
|
-
* const menuItems = createCollection<HTMLElement, { disabled: boolean }>();
|
|
561
|
-
*
|
|
562
|
-
* // Register items
|
|
563
|
-
* const unregister1 = menuItems.register(element1, { disabled: false });
|
|
564
|
-
* const unregister2 = menuItems.register(element2, { disabled: true });
|
|
565
|
-
*
|
|
566
|
-
* // Query items
|
|
567
|
-
* const allItems = menuItems.items();
|
|
568
|
-
* const enabledItems = allItems.filter(item => !item.metadata.disabled);
|
|
569
|
-
*
|
|
570
|
-
* // Cleanup
|
|
571
|
-
* unregister1();
|
|
572
|
-
* unregister2();
|
|
573
|
-
*/
|
|
574
|
-
//#endregion
|
|
575
|
-
//#region src/foundations/structures/layer.ts
|
|
576
|
-
/** Create a new, empty {@link LayerManager} for coordinating overlay stacking. */
|
|
577
|
-
function createLayer() {
|
|
578
|
-
const stack = [];
|
|
579
|
-
let nextId = 1;
|
|
580
|
-
function register(options) {
|
|
581
|
-
const id = nextId++;
|
|
582
|
-
const entry = {
|
|
583
|
-
id,
|
|
584
|
-
options
|
|
585
|
-
};
|
|
586
|
-
stack.push(entry);
|
|
587
|
-
function isTop() {
|
|
588
|
-
return stack[stack.length - 1]?.id === id;
|
|
589
|
-
}
|
|
590
|
-
function unregister() {
|
|
591
|
-
const index = stack.findIndex((e) => e.id === id);
|
|
592
|
-
if (index !== -1) stack.splice(index, 1);
|
|
593
|
-
}
|
|
594
|
-
return {
|
|
595
|
-
id,
|
|
596
|
-
isTop,
|
|
597
|
-
unregister
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
function layers() {
|
|
601
|
-
return stack.map((entry) => ({
|
|
602
|
-
id: entry.id,
|
|
603
|
-
isTop: () => stack[stack.length - 1]?.id === entry.id,
|
|
604
|
-
unregister: () => {
|
|
605
|
-
const index = stack.findIndex((e) => e.id === entry.id);
|
|
606
|
-
if (index !== -1) stack.splice(index, 1);
|
|
607
|
-
}
|
|
608
|
-
}));
|
|
609
|
-
}
|
|
610
|
-
function handleEscape() {
|
|
611
|
-
const top = stack[stack.length - 1];
|
|
612
|
-
if (top) top.options.onEscape?.();
|
|
613
|
-
}
|
|
614
|
-
function handleOutsidePointer(e) {
|
|
615
|
-
const top = stack[stack.length - 1];
|
|
616
|
-
if (!top) return;
|
|
617
|
-
const node = top.options.node;
|
|
618
|
-
if (node && e.target instanceof Node) {
|
|
619
|
-
if (!node.contains(e.target)) top.options.onOutsidePointer?.(e);
|
|
620
|
-
} else top.options.onOutsidePointer?.(e);
|
|
621
|
-
}
|
|
622
|
-
return {
|
|
623
|
-
register,
|
|
624
|
-
layers,
|
|
625
|
-
handleEscape,
|
|
626
|
-
handleOutsidePointer
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
/**
|
|
630
|
-
* USAGE EXAMPLE:
|
|
631
|
-
*
|
|
632
|
-
* const layerManager = createLayer();
|
|
633
|
-
*
|
|
634
|
-
* function Modal({ onClose }) {
|
|
635
|
-
* const modalRef = ref<HTMLDivElement>();
|
|
636
|
-
*
|
|
637
|
-
* const layer = layerManager.register({
|
|
638
|
-
* node: modalRef.current,
|
|
639
|
-
* onEscape: onClose,
|
|
640
|
-
* onOutsidePointer: onClose,
|
|
641
|
-
* });
|
|
642
|
-
*
|
|
643
|
-
* onUnmount(() => layer.unregister());
|
|
644
|
-
*
|
|
645
|
-
* return (
|
|
646
|
-
* <div ref={modalRef}>
|
|
647
|
-
* <h1>Modal</h1>
|
|
648
|
-
* {layer.isTop() && <p>I am on top!</p>}
|
|
649
|
-
* </div>
|
|
650
|
-
* );
|
|
651
|
-
* }
|
|
652
|
-
*/
|
|
653
|
-
//#endregion
|
|
654
|
-
export { definePortal as a, layout as c, Portal as i, cloneElement as l, createCollection as n, Presence as o, DefaultPortal as r, Slot as s, createLayer as t, isElement as u };
|