@atom.io/spa 0.0.8 → 0.0.9
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 +169 -25
- package/README.mdx +62 -15
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +1 -1
- package/dist/astro-client.d.ts.map +1 -1
- package/dist/astro-client.js +5 -4
- package/dist/astro-client.js.map +1 -1
- package/dist/astro-resumability-client.d.ts +1 -1
- package/dist/astro-server.js +4 -4
- package/dist/astro-server.js.map +1 -1
- package/dist/{astro-shared-83hxw7-M.js → astro-shared-DBwINQav.js} +2 -2
- package/dist/{astro-shared-83hxw7-M.js.map → astro-shared-DBwINQav.js.map} +1 -1
- package/dist/{astro-shared-DZp1x8RQ.d.ts → astro-shared-KxK9OUSj.d.ts} +2 -2
- package/dist/{astro-shared-DZp1x8RQ.d.ts.map → astro-shared-KxK9OUSj.d.ts.map} +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/{capabilities-DNcnGRv_.d.ts → capabilities-ChgSs6bp.d.ts} +34 -6
- package/dist/capabilities-ChgSs6bp.d.ts.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/core-DD2giR6E.js +451 -0
- package/dist/core-DD2giR6E.js.map +1 -0
- package/dist/development/astro-client.js +5 -4
- package/dist/development/astro-client.js.map +1 -1
- package/dist/development/astro-server.js +4 -4
- package/dist/development/astro-server.js.map +1 -1
- package/dist/development/{astro-shared-83hxw7-M.js → astro-shared-DBwINQav.js} +2 -2
- package/dist/development/{astro-shared-83hxw7-M.js.map → astro-shared-DBwINQav.js.map} +1 -1
- package/dist/development/astro.js +1 -1
- package/dist/development/core-DrUd8x25.js +465 -0
- package/dist/development/core-DrUd8x25.js.map +1 -0
- package/dist/development/{dom-DQ0M3rLL.js → dom-BRFv7FP_.js} +150 -35
- package/dist/development/dom-BRFv7FP_.js.map +1 -0
- package/dist/development/floating.js +2 -6
- package/dist/development/floating.js.map +1 -1
- package/dist/development/hot.js +164 -0
- package/dist/development/hot.js.map +1 -0
- package/dist/development/identity-DwB8MTM1.js +121 -0
- package/dist/development/identity-DwB8MTM1.js.map +1 -0
- package/dist/development/index.js +5 -5
- package/dist/development/jsx-runtime-BGDPK50B.js +49 -0
- package/dist/development/jsx-runtime-BGDPK50B.js.map +1 -0
- package/dist/development/jsx-runtime.js +1 -25
- package/dist/development/konva.js +12 -5
- package/dist/development/konva.js.map +1 -1
- package/dist/development/motion.js +3 -20
- package/dist/development/motion.js.map +1 -1
- package/dist/development/renderer.js +41 -40
- package/dist/development/renderer.js.map +1 -1
- package/dist/development/{server-renderer-DCLoMdOX.js → server-renderer-u1-c5PGd.js} +8 -18
- package/dist/development/server-renderer-u1-c5PGd.js.map +1 -0
- package/dist/development/server.js +1 -1
- package/dist/{src-Bme1kz2b.js → development/src-CB7ruwRs.js} +3 -3
- package/dist/development/src-CB7ruwRs.js.map +1 -0
- package/dist/development/three.js +20 -19
- package/dist/development/three.js.map +1 -1
- package/dist/development/vite-WUiz1ju6.js +545 -0
- package/dist/development/vite-WUiz1ju6.js.map +1 -0
- package/dist/development/vite.js +1 -1
- package/dist/{dom-D8g3roX9.js → dom--HZvmgqd.js} +139 -32
- package/dist/dom--HZvmgqd.js.map +1 -0
- package/dist/floating.d.ts +1 -1
- package/dist/floating.d.ts.map +1 -1
- package/dist/floating.js +2 -6
- package/dist/floating.js.map +1 -1
- package/dist/hot.d.ts +15 -0
- package/dist/hot.d.ts.map +1 -0
- package/dist/hot.js +19 -0
- package/dist/hot.js.map +1 -0
- package/dist/identity-oFU5p-Qj.js +121 -0
- package/dist/identity-oFU5p-Qj.js.map +1 -0
- package/dist/{index-BFnXIfOj.d.ts → index-DdA39aMv.d.ts} +4 -4
- package/dist/{index-BFnXIfOj.d.ts.map → index-DdA39aMv.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/jsx-runtime-BGDPK50B.js +49 -0
- package/dist/jsx-runtime-BGDPK50B.js.map +1 -0
- package/dist/{jsx-runtime-DQnpyT_g.d.ts → jsx-runtime-CCvcEosg.d.ts} +14 -9
- package/dist/jsx-runtime-CCvcEosg.d.ts.map +1 -0
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +1 -25
- package/dist/konva.d.ts +46 -9
- package/dist/konva.d.ts.map +1 -1
- package/dist/konva.js +12 -5
- package/dist/konva.js.map +1 -1
- package/dist/motion.d.ts +1 -1
- package/dist/motion.js +3 -20
- package/dist/motion.js.map +1 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +39 -40
- package/dist/renderer.js.map +1 -1
- package/dist/{server-renderer-D0rsFL_-.js → server-renderer-BYFDmqnM.js} +8 -18
- package/dist/server-renderer-BYFDmqnM.js.map +1 -0
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/size.json +12 -12
- package/dist/{development/src-DoQgCX-O.js → src-B2W_TA_X.js} +3 -3
- package/dist/src-B2W_TA_X.js.map +1 -0
- package/dist/three.d.ts +3 -3
- package/dist/three.d.ts.map +1 -1
- package/dist/three.js +20 -19
- package/dist/three.js.map +1 -1
- package/dist/vite-WUiz1ju6.js +545 -0
- package/dist/vite-WUiz1ju6.js.map +1 -0
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +1 -1
- package/package.json +16 -9
- package/src/astro-client.ts +3 -2
- package/src/astro-server.ts +2 -2
- package/src/capabilities.ts +48 -21
- package/src/compiler-hmr.ts +297 -0
- package/src/compiler.ts +127 -25
- package/src/core.ts +282 -33
- package/src/dom-forms.ts +127 -0
- package/src/dom.ts +116 -52
- package/src/floating.ts +2 -6
- package/src/hot.ts +190 -0
- package/src/identity.ts +39 -0
- package/src/index.ts +2 -0
- package/src/jsx-runtime.ts +6 -26
- package/src/jsx-types.d.ts +8 -3
- package/src/konva.ts +66 -10
- package/src/presence.ts +11 -23
- package/src/props.ts +55 -0
- package/src/renderer.ts +91 -71
- package/src/server-renderer.ts +18 -13
- package/src/three.ts +23 -24
- package/src/use-loadable.ts +2 -2
- package/src/vite.ts +44 -4
- package/dist/capabilities-DNcnGRv_.d.ts.map +0 -1
- package/dist/capabilities-nOIitQ-_.js +0 -65
- package/dist/capabilities-nOIitQ-_.js.map +0 -1
- package/dist/core-B4rJ0xdc.js +0 -268
- package/dist/core-B4rJ0xdc.js.map +0 -1
- package/dist/development/capabilities-nOIitQ-_.js +0 -65
- package/dist/development/capabilities-nOIitQ-_.js.map +0 -1
- package/dist/development/core-BHA7I1nf.js +0 -271
- package/dist/development/core-BHA7I1nf.js.map +0 -1
- package/dist/development/dom-DQ0M3rLL.js.map +0 -1
- package/dist/development/jsx-runtime.js.map +0 -1
- package/dist/development/server-renderer-DCLoMdOX.js.map +0 -1
- package/dist/development/src-DoQgCX-O.js.map +0 -1
- package/dist/development/vite-Bmyb6P5w.js +0 -265
- package/dist/development/vite-Bmyb6P5w.js.map +0 -1
- package/dist/dom-D8g3roX9.js.map +0 -1
- package/dist/jsx-runtime-DQnpyT_g.d.ts.map +0 -1
- package/dist/jsx-runtime.js.map +0 -1
- package/dist/server-renderer-D0rsFL_-.js.map +0 -1
- package/dist/src-Bme1kz2b.js.map +0 -1
- package/dist/vite-Bmyb6P5w.js +0 -265
- package/dist/vite-Bmyb6P5w.js.map +0 -1
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { IMPLICIT, actUponStore, clearTimelineInStore, disposeFromStore, findInStore, findTimelineInStore, getFromStore, getTimelineTransactionAtHead, setIntoStore, subscribeToState, subscribeToTimeline, timeTravel, timeTravelTransactionGroupInStore, withdraw } from "atom.io/internal";
|
|
2
|
+
// src/core.ts
|
|
3
|
+
let owner;
|
|
4
|
+
let tracking;
|
|
5
|
+
let serial = 0;
|
|
6
|
+
let setupOrder = 0;
|
|
7
|
+
function scopedErrorHandler(scope, error) {
|
|
8
|
+
const failure = scope._root._failure;
|
|
9
|
+
return failure && Object.is(failure.error, error) ? failure.report : scope._options?.onError;
|
|
10
|
+
}
|
|
11
|
+
function throwScopedError(scope, error, report = scopedErrorHandler(scope, error)) {
|
|
12
|
+
if (report) scope._root._failure = {
|
|
13
|
+
error,
|
|
14
|
+
report
|
|
15
|
+
};
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
function within(scope, run) {
|
|
19
|
+
const previous = owner;
|
|
20
|
+
owner = scope;
|
|
21
|
+
try {
|
|
22
|
+
return run();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throwScopedError(scope, error);
|
|
25
|
+
} finally {
|
|
26
|
+
owner = previous;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function untrack(run) {
|
|
30
|
+
const previous = tracking;
|
|
31
|
+
tracking = void 0;
|
|
32
|
+
try {
|
|
33
|
+
return run();
|
|
34
|
+
} finally {
|
|
35
|
+
tracking = previous;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function createScope(parent) {
|
|
39
|
+
const child = {
|
|
40
|
+
_root: parent?._root,
|
|
41
|
+
_parent: parent,
|
|
42
|
+
_options: parent?._options,
|
|
43
|
+
_setupOrder: setupOrder++,
|
|
44
|
+
_cleanups: /* @__PURE__ */ new Set(),
|
|
45
|
+
_updates: [],
|
|
46
|
+
_dead: false
|
|
47
|
+
};
|
|
48
|
+
parent?._cleanups.add(child);
|
|
49
|
+
return child;
|
|
50
|
+
}
|
|
51
|
+
function fail(scope, error) {
|
|
52
|
+
const report = scopedErrorHandler(scope, error);
|
|
53
|
+
try {
|
|
54
|
+
dispose(scope);
|
|
55
|
+
} catch (cleanup) {
|
|
56
|
+
throwScopedError(scope, new AggregateError([error, cleanup]), report);
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
function dispose(scope) {
|
|
61
|
+
if (scope._dead) return;
|
|
62
|
+
scope._dead = true;
|
|
63
|
+
const errors = [];
|
|
64
|
+
let report;
|
|
65
|
+
const record = (error) => {
|
|
66
|
+
errors.push(error);
|
|
67
|
+
report ??= scopedErrorHandler(scope, error);
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
scope._root._presence?.forget(scope);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
record(error);
|
|
73
|
+
}
|
|
74
|
+
for (const cleanup of [...scope._cleanups].reverse()) try {
|
|
75
|
+
typeof cleanup === `function` ? cleanup() : dispose(cleanup);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
record(error);
|
|
78
|
+
}
|
|
79
|
+
scope._parent?._cleanups.delete(scope);
|
|
80
|
+
scope._cleanups.clear();
|
|
81
|
+
scope._targets?.clear();
|
|
82
|
+
scope._updates.length = 0;
|
|
83
|
+
if (errors.length) throwScopedError(scope, new AggregateError(errors), report);
|
|
84
|
+
}
|
|
85
|
+
function invalidate(scope) {
|
|
86
|
+
for (const run of scope._updates) enqueue(scope, run);
|
|
87
|
+
for (const child of scope._cleanups) if (typeof child !== `function`) invalidate(child);
|
|
88
|
+
}
|
|
89
|
+
function enqueue(scope, run) {
|
|
90
|
+
if (!isPresent(scope)) return;
|
|
91
|
+
const root = scope._root;
|
|
92
|
+
if (!root._queue.size && !root._flushing) queueMicrotask(() => {
|
|
93
|
+
try {
|
|
94
|
+
root.flush();
|
|
95
|
+
} catch (error) {
|
|
96
|
+
const report = scopedErrorHandler(root, error) ?? root.error;
|
|
97
|
+
root._failure = void 0;
|
|
98
|
+
report(error);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
root._queue.add(run);
|
|
102
|
+
}
|
|
103
|
+
function runCommits(root, pending) {
|
|
104
|
+
const top = {
|
|
105
|
+
order: root._setupOrder,
|
|
106
|
+
children: [],
|
|
107
|
+
jobs: []
|
|
108
|
+
};
|
|
109
|
+
const groups = /* @__PURE__ */ new Map([[root, top]]);
|
|
110
|
+
const groupFor = (scope) => {
|
|
111
|
+
let group = groups.get(scope);
|
|
112
|
+
if (!group) {
|
|
113
|
+
group = {
|
|
114
|
+
order: scope._setupOrder,
|
|
115
|
+
children: [],
|
|
116
|
+
jobs: []
|
|
117
|
+
};
|
|
118
|
+
groups.set(scope, group);
|
|
119
|
+
groupFor(scope._parent).children.push(group);
|
|
120
|
+
}
|
|
121
|
+
return group;
|
|
122
|
+
};
|
|
123
|
+
for (const job of [...pending].sort((a, b) => a.order - b.order)) groupFor(job.scope).jobs.push(job);
|
|
124
|
+
const visit = (group) => {
|
|
125
|
+
for (const child of group.children.sort((a, b) => a.order - b.order)) visit(child);
|
|
126
|
+
for (const job of group.jobs) if (pending.delete(job) && isPresent(job.scope)) job.run();
|
|
127
|
+
};
|
|
128
|
+
visit(top);
|
|
129
|
+
}
|
|
130
|
+
function capabilityMap(list) {
|
|
131
|
+
const capabilities = /* @__PURE__ */ new Map();
|
|
132
|
+
for (const capability of list ?? []) {
|
|
133
|
+
if (capabilities.has(capability.namespace)) throw new Error(`spa: duplicate capability ${capability.namespace}`);
|
|
134
|
+
capabilities.set(capability.namespace, capability);
|
|
135
|
+
}
|
|
136
|
+
return capabilities;
|
|
137
|
+
}
|
|
138
|
+
function registerPresence(root, capability, shared = false) {
|
|
139
|
+
const create = capability.presence;
|
|
140
|
+
if (!create) return;
|
|
141
|
+
if (root._presence) {
|
|
142
|
+
if (!shared || root._presenceFactory !== create) throw new Error(`spa: multiple presence coordinators`);
|
|
143
|
+
} else {
|
|
144
|
+
root._presence = create(root);
|
|
145
|
+
root._presenceFactory = create;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function scopeCapabilities(scope) {
|
|
149
|
+
return scope._options?._capabilities ?? scope._root._capabilities;
|
|
150
|
+
}
|
|
151
|
+
function reportScopeError(scope, error) {
|
|
152
|
+
const report = scopedErrorHandler(scope, error) ?? scope._root.error;
|
|
153
|
+
try {
|
|
154
|
+
fail(scope._root, error);
|
|
155
|
+
} catch (failure) {
|
|
156
|
+
scope._root._failure = void 0;
|
|
157
|
+
report(failure);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Override root options for these children while sharing their parent's ownership. */
|
|
161
|
+
function RootBoundary(props) {
|
|
162
|
+
const scope = owner;
|
|
163
|
+
const { store, idPrefix, onError, capabilities } = props;
|
|
164
|
+
const options = { ...scope._options };
|
|
165
|
+
if (store !== void 0) options.store = store;
|
|
166
|
+
if (idPrefix !== void 0) options.idPrefix = idPrefix;
|
|
167
|
+
if (onError !== void 0) options.onError = onError;
|
|
168
|
+
if (capabilities !== void 0) {
|
|
169
|
+
options._capabilities = capabilityMap(capabilities);
|
|
170
|
+
const root = scope._root;
|
|
171
|
+
const active = root._boundaryCapabilities ??= /* @__PURE__ */ new Map();
|
|
172
|
+
for (const capability of options._capabilities.values()) {
|
|
173
|
+
registerPresence(root, capability, true);
|
|
174
|
+
active.set(capability, (active.get(capability) ?? 0) + 1);
|
|
175
|
+
scope._cleanups.add(() => {
|
|
176
|
+
const remaining = active.get(capability) - 1;
|
|
177
|
+
if (remaining) active.set(capability, remaining);
|
|
178
|
+
else active.delete(capability);
|
|
179
|
+
});
|
|
180
|
+
root._prepareCapability?.(capability);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
scope._options = options;
|
|
184
|
+
return () => props.children;
|
|
185
|
+
}
|
|
186
|
+
function createRoot(options = {}, server = false) {
|
|
187
|
+
const capabilities = capabilityMap(options.capabilities);
|
|
188
|
+
const root = {
|
|
189
|
+
_capabilities: capabilities,
|
|
190
|
+
_store: options.store ?? IMPLICIT.STORE,
|
|
191
|
+
_prefix: options.idPrefix ?? `w${serial++}`,
|
|
192
|
+
_id: 0,
|
|
193
|
+
...createScope(),
|
|
194
|
+
_queue: /* @__PURE__ */ new Set(),
|
|
195
|
+
_mounts: server ? void 0 : []
|
|
196
|
+
};
|
|
197
|
+
root._root = root;
|
|
198
|
+
root.error = options.onError ?? ((error) => {
|
|
199
|
+
throw error;
|
|
200
|
+
});
|
|
201
|
+
for (const capability of capabilities.values()) registerPresence(root, capability);
|
|
202
|
+
const hasWrites = () => root._queue.size || root._mounts.length;
|
|
203
|
+
const hasWork = () => hasWrites() || root._commits?.size;
|
|
204
|
+
let flushPendingWrites;
|
|
205
|
+
root.flush = () => {
|
|
206
|
+
const nested = root._flushing;
|
|
207
|
+
if (!(nested ? hasWrites() : hasWork()) && !root._forms?.size) return;
|
|
208
|
+
root._flushing = true;
|
|
209
|
+
try {
|
|
210
|
+
if (nested) {
|
|
211
|
+
flushPendingWrites?.();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
root._failure = void 0;
|
|
215
|
+
let lastCommit;
|
|
216
|
+
const runWriteBatch = () => {
|
|
217
|
+
const commits = /* @__PURE__ */ new Map();
|
|
218
|
+
const prepare = (capability) => {
|
|
219
|
+
if (!commits.has(capability)) commits.set(capability, capability.beforeUpdate?.(root));
|
|
220
|
+
};
|
|
221
|
+
const previous = root._prepareCapability;
|
|
222
|
+
root._prepareCapability = prepare;
|
|
223
|
+
let formsReady = true;
|
|
224
|
+
try {
|
|
225
|
+
for (const capability of capabilities.values()) prepare(capability);
|
|
226
|
+
for (const capability of root._boundaryCapabilities?.keys() ?? []) prepare(capability);
|
|
227
|
+
while (hasWrites()) {
|
|
228
|
+
for (const run of [...root._queue]) if (root._queue.delete(run)) run();
|
|
229
|
+
for (const run of root._mounts.splice(0)) run();
|
|
230
|
+
}
|
|
231
|
+
for (const restore of root._forms ?? []) if (!untrack(restore)) formsReady = false;
|
|
232
|
+
} finally {
|
|
233
|
+
root._prepareCapability = previous;
|
|
234
|
+
for (const commit of commits.values()) commit?.();
|
|
235
|
+
}
|
|
236
|
+
return formsReady;
|
|
237
|
+
};
|
|
238
|
+
do {
|
|
239
|
+
flushPendingWrites = runWriteBatch;
|
|
240
|
+
const formsReady = runWriteBatch();
|
|
241
|
+
flushPendingWrites = void 0;
|
|
242
|
+
if (!hasWrites()) {
|
|
243
|
+
if (!formsReady || !root._commits?.size) break;
|
|
244
|
+
lastCommit = runCommits(root, root._commits) ?? lastCommit;
|
|
245
|
+
}
|
|
246
|
+
} while (hasWork());
|
|
247
|
+
root._failure = void 0;
|
|
248
|
+
} catch (error) {
|
|
249
|
+
flushPendingWrites = void 0;
|
|
250
|
+
fail(root, error);
|
|
251
|
+
} finally {
|
|
252
|
+
if (!nested) root._flushing = false;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
return root;
|
|
256
|
+
}
|
|
257
|
+
/** Return the atom.io store selected by the current owner. */
|
|
258
|
+
function useStore() {
|
|
259
|
+
return owner._options?.store ?? owner._root._store;
|
|
260
|
+
}
|
|
261
|
+
/** Return atom.io disposal bound to the current root's store. */
|
|
262
|
+
function useDisposal() {
|
|
263
|
+
return disposeFromStore.bind(null, useStore());
|
|
264
|
+
}
|
|
265
|
+
function onCleanup(cleanup) {
|
|
266
|
+
owner._cleanups.add(cleanup);
|
|
267
|
+
}
|
|
268
|
+
function onMount(run) {
|
|
269
|
+
const scope = owner;
|
|
270
|
+
scope._root._mounts?.push(() => {
|
|
271
|
+
if (!scope._dead) within(scope, () => {
|
|
272
|
+
untrack(run);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
/** Observe state during setup and apply changes after the root's writes. */
|
|
277
|
+
function onCommit(read, apply) {
|
|
278
|
+
const scope = owner;
|
|
279
|
+
const root = scope._root;
|
|
280
|
+
if (!root._mounts) return;
|
|
281
|
+
const pending = root._commits ??= /* @__PURE__ */ new Set();
|
|
282
|
+
let ran = false;
|
|
283
|
+
let next;
|
|
284
|
+
let previous;
|
|
285
|
+
let cleanup;
|
|
286
|
+
const clear = () => {
|
|
287
|
+
const release = cleanup;
|
|
288
|
+
cleanup = void 0;
|
|
289
|
+
if (release) untrack(release);
|
|
290
|
+
};
|
|
291
|
+
const job = {
|
|
292
|
+
scope,
|
|
293
|
+
order: setupOrder++,
|
|
294
|
+
loopError: void 0,
|
|
295
|
+
run() {
|
|
296
|
+
within(scope, () => {
|
|
297
|
+
untrack(() => {
|
|
298
|
+
clear();
|
|
299
|
+
if (!isPresent(scope)) return;
|
|
300
|
+
const old = previous;
|
|
301
|
+
previous = next;
|
|
302
|
+
ran = true;
|
|
303
|
+
cleanup = apply(next, old);
|
|
304
|
+
if (scope._dead) clear();
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
scope._cleanups.add(() => {
|
|
310
|
+
pending.delete(job);
|
|
311
|
+
clear();
|
|
312
|
+
});
|
|
313
|
+
observe(scope, read, (value) => {
|
|
314
|
+
next = value;
|
|
315
|
+
if (!ran || !Object.is(value, previous)) pending.add(job);
|
|
316
|
+
else pending.delete(job);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
function useId() {
|
|
320
|
+
const root = owner._root;
|
|
321
|
+
return `${owner._options?.idPrefix ?? root._prefix}-${root._id++}`;
|
|
322
|
+
}
|
|
323
|
+
function observe(scope, read, apply) {
|
|
324
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
325
|
+
const run = () => {
|
|
326
|
+
if (!isPresent(scope)) return;
|
|
327
|
+
const used = /* @__PURE__ */ new Set();
|
|
328
|
+
const previous = tracking;
|
|
329
|
+
tracking = (subscribe) => {
|
|
330
|
+
used.add(subscribe);
|
|
331
|
+
if (!subscriptions.has(subscribe)) subscriptions.set(subscribe, subscribe(() => {
|
|
332
|
+
enqueue(scope, run);
|
|
333
|
+
}));
|
|
334
|
+
};
|
|
335
|
+
let value;
|
|
336
|
+
try {
|
|
337
|
+
value = within(scope, read);
|
|
338
|
+
} finally {
|
|
339
|
+
tracking = previous;
|
|
340
|
+
for (const [subscribe, unsubscribe] of subscriptions) if (!used.has(subscribe)) {
|
|
341
|
+
unsubscribe();
|
|
342
|
+
subscriptions.delete(subscribe);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
within(scope, () => {
|
|
346
|
+
untrack(() => {
|
|
347
|
+
apply(value);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
};
|
|
351
|
+
scope._updates.push(run);
|
|
352
|
+
scope._cleanups.add(() => {
|
|
353
|
+
scope._root._queue.delete(run);
|
|
354
|
+
for (const unsubscribe of subscriptions.values()) unsubscribe();
|
|
355
|
+
});
|
|
356
|
+
run();
|
|
357
|
+
}
|
|
358
|
+
/** Resolve a fixed family key in the current owner's store. */
|
|
359
|
+
function resolveStateToken(token, key) {
|
|
360
|
+
const store = useStore();
|
|
361
|
+
return token.type.endsWith(`_family`) ? findInStore(store, token, key) : token;
|
|
362
|
+
}
|
|
363
|
+
function useGetter(token, key) {
|
|
364
|
+
token = resolveStateToken(token, key);
|
|
365
|
+
const root = owner._root;
|
|
366
|
+
const store = useStore();
|
|
367
|
+
const subscribe = (notify) => subscribeToState(store, token, `spa:${serial++}`, notify);
|
|
368
|
+
return () => {
|
|
369
|
+
const value = getFromStore(store, token);
|
|
370
|
+
root._onRead?.(value, token, store);
|
|
371
|
+
tracking?.(subscribe);
|
|
372
|
+
return value;
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function useSetter(token, key) {
|
|
376
|
+
token = resolveStateToken(token, key);
|
|
377
|
+
const store = useStore();
|
|
378
|
+
return (value) => {
|
|
379
|
+
setIntoStore(store, token, value);
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function useTransaction(token) {
|
|
383
|
+
return actUponStore(useStore(), token, `spa:${serial++}`);
|
|
384
|
+
}
|
|
385
|
+
const refs = /* @__PURE__ */ new WeakMap();
|
|
386
|
+
function useRef(token, key) {
|
|
387
|
+
token = resolveStateToken(token, key);
|
|
388
|
+
const store = useStore();
|
|
389
|
+
const owners = refs.get(store) ?? /* @__PURE__ */ new Map();
|
|
390
|
+
refs.set(store, owners);
|
|
391
|
+
const identity = {};
|
|
392
|
+
let held = null;
|
|
393
|
+
return (element) => {
|
|
394
|
+
if (element) {
|
|
395
|
+
held = element;
|
|
396
|
+
owners.set(token.key, identity);
|
|
397
|
+
setIntoStore(store, token, element);
|
|
398
|
+
} else if (owners.get(token.key) === identity) {
|
|
399
|
+
owners.delete(token.key);
|
|
400
|
+
if (getFromStore(store, token) === held) setIntoStore(store, token, null);
|
|
401
|
+
held = null;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function useTimeline(token, key) {
|
|
406
|
+
const store = useStore();
|
|
407
|
+
const selected = token.type === `timeline_family` ? findTimelineInStore(store, token, key) : token;
|
|
408
|
+
const subscribe = (notify) => subscribeToTimeline(store, selected, `spa:${serial++}`, notify);
|
|
409
|
+
const read = () => {
|
|
410
|
+
const timeline = withdraw(store, selected);
|
|
411
|
+
tracking?.(subscribe);
|
|
412
|
+
return timeline;
|
|
413
|
+
};
|
|
414
|
+
return {
|
|
415
|
+
getCursor: () => read().at,
|
|
416
|
+
getLength: () => read().history.length,
|
|
417
|
+
undo: () => {
|
|
418
|
+
timeTravel(store, `undo`, selected);
|
|
419
|
+
},
|
|
420
|
+
redo: () => {
|
|
421
|
+
timeTravel(store, `redo`, selected);
|
|
422
|
+
},
|
|
423
|
+
clear: () => {
|
|
424
|
+
clearTimelineInStore(store, selected);
|
|
425
|
+
},
|
|
426
|
+
getTransaction: () => {
|
|
427
|
+
const timeline = read();
|
|
428
|
+
const controls = {};
|
|
429
|
+
for (const direction of [`undo`, `redo`]) {
|
|
430
|
+
const group = getTimelineTransactionAtHead(timeline, direction);
|
|
431
|
+
if (group) controls[direction] = () => {
|
|
432
|
+
timeTravelTransactionGroupInStore(store, direction, group);
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
return controls;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function plain(value) {
|
|
440
|
+
if (typeof value === `function`) return plain(value());
|
|
441
|
+
if (Array.isArray(value)) return value.map(plain).join(``);
|
|
442
|
+
if (value == null || typeof value === `boolean`) return ``;
|
|
443
|
+
return String(value);
|
|
444
|
+
}
|
|
445
|
+
function isPresent(scope) {
|
|
446
|
+
for (let at = scope; at; at = at._parent) if (at._dead || at._exiting) return false;
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
export { useSetter as C, within as D, useTransaction as E, useRef as S, useTimeline as T, scopeCapabilities as _, enqueue as a, useGetter as b, isPresent as c, onCommit as d, onMount as f, resolveStateToken as g, reportScopeError as h, dispose as i, observe as l, plain as m, createRoot as n, fail as o, owner as p, createScope as r, invalidate as s, RootBoundary as t, onCleanup as u, untrack as v, useStore as w, useId as x, useDisposal as y };
|
|
450
|
+
|
|
451
|
+
//# sourceMappingURL=core-DD2giR6E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-DD2giR6E.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import type {\n\tdisposeState,\n\tReadableFamilyToken,\n\tReadableToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSetter,\n\tTimelineFamilyToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tViewOf,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/foundations/canonical\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tclearTimelineInStore,\n\tdisposeFromStore,\n\tfindInStore,\n\tfindTimelineInStore,\n\tgetFromStore,\n\tgetTimelineTransactionAtHead,\n\tIMPLICIT,\n\tsetIntoStore,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\ttimeTravel,\n\ttimeTravelTransactionGroupInStore,\n\twithdraw,\n} from \"atom.io/internal\"\n\nimport type { Capability } from \"./capabilities.ts\"\nimport type {\n\tExitParticipant,\n\tPresenceCoordinator,\n\tPresenceTarget,\n} from \"./presence.ts\"\n\nexport type Cleanup = () => void\n// A callable interface permits the recursive Children union. A type alias does not.\n/* oxlint-disable typescript/prefer-function-type -- A callable interface is required for recursive Children. */\nexport interface Accessor<T> {\n\t(): T\n}\n/* oxlint-enable typescript/prefer-function-type */\nexport type Component<P = any> = (props: P) => Children\n/** A JSX descriptor for an intrinsic tag, component, or fragment. */\nexport interface SpaElement {\n\ttype: string | Component | null\n\tprops: Record<string, any>\n}\n/** Renderable content, including nested groups and reactive accessors. */\nexport type Children =\n\t| SpaElement\n\t| string\n\t| number\n\t| bigint\n\t| boolean\n\t| null\n\t| undefined\n\t| readonly Children[]\n\t| Accessor<Children>\nexport interface RootOptions {\n\tcapabilities?: readonly Capability[]\n\tstore?: RootStore\n\tidPrefix?: string\n\tonError?: (error: unknown) => void\n}\ninterface BoundaryOptions extends Omit<RootOptions, `capabilities`> {\n\t_capabilities?: Map<string, Capability>\n}\nexport interface Scope {\n\t_exiting?: boolean\n\t_exits?: Set<ExitParticipant>\n\t_targets?: Set<PresenceTarget>\n\t_root: Root\n\t_parent?: Scope | undefined\n\t_options?: BoundaryOptions | undefined\n\t_setupOrder: number\n\t_cleanups: Set<Cleanup | Scope>\n\t_updates: Cleanup[]\n\t_dead: boolean\n}\nexport interface Root extends Scope {\n\t_onRead?:\n\t\t| ((value: unknown, token: ReadableToken<unknown>, store: RootStore) => void)\n\t\t| undefined\n\t_presence?: PresenceCoordinator\n\t_presenceFactory?: Capability[`presence`]\n\t_capabilities: Map<string, Capability>\n\t_boundaryCapabilities?: Map<Capability, number>\n\t_prepareCapability?: ((capability: Capability) => void) | undefined\n\t_failure?: { error: unknown; report: Root[`error`] } | undefined\n\t_store: RootStore\n\t_prefix: string\n\t_id: number\n\t_queue: Set<Cleanup>\n\t_enqueueCount?: number\n\t_mounts: Cleanup[] | undefined\n\t_commits?: Set<CommitJob>\n\t_flushing?: boolean\n\t_forms?: Set<() => boolean>\n\t_host?: Element\n\tflush: Cleanup\n\terror: (error: unknown) => void\n}\n\ninterface CommitJob {\n\tscope: Scope\n\torder: number\n\trun: Cleanup\n\tloopError: Error | undefined\n}\ninterface CommitGroup {\n\torder: number\n\tchildren: CommitGroup[]\n\tjobs: CommitJob[]\n}\n\nexport let owner: Scope | undefined\ntype Subscribe = (notify: Cleanup) => Cleanup\nlet tracking: ((subscribe: Subscribe) => void) | undefined\nlet serial = 0\nlet setupOrder = 0\n\nfunction scopedErrorHandler(\n\tscope: Scope,\n\terror: unknown,\n): Root[`error`] | undefined {\n\tconst failure = scope._root._failure\n\treturn failure && Object.is(failure.error, error)\n\t\t? failure.report\n\t\t: scope._options?.onError\n}\nfunction throwScopedError(\n\tscope: Scope,\n\terror: unknown,\n\treport = scopedErrorHandler(scope, error),\n): never {\n\tif (report) scope._root._failure = { error, report }\n\tthrow error\n}\nexport function within<T>(scope: Scope, run: () => T): T {\n\tconst previous = owner\n\towner = scope\n\ttry {\n\t\treturn run()\n\t} catch (error) {\n\t\tthrowScopedError(scope, error)\n\t} finally {\n\t\towner = previous\n\t}\n}\nexport function untrack<T>(run: () => T): T {\n\tconst previous = tracking\n\ttracking = undefined\n\ttry {\n\t\treturn run()\n\t} finally {\n\t\ttracking = previous\n\t}\n}\nexport function createScope(parent?: Scope): Scope {\n\tconst child: Scope = {\n\t\t_root: parent?._root as Root,\n\t\t_parent: parent,\n\t\t_options: parent?._options,\n\t\t_setupOrder: setupOrder++,\n\t\t_cleanups: new Set(),\n\t\t_updates: [],\n\t\t_dead: false,\n\t}\n\tparent?._cleanups.add(child)\n\treturn child\n}\nexport function fail(scope: Scope, error: unknown): never {\n\tconst report = scopedErrorHandler(scope, error)\n\ttry {\n\t\tdispose(scope)\n\t} catch (cleanup) {\n\t\tthrowScopedError(scope, new AggregateError([error, cleanup]), report)\n\t}\n\tthrow error\n}\nexport function dispose(scope: Scope): void {\n\tif (scope._dead) return\n\tscope._dead = true\n\tconst errors: unknown[] = []\n\tlet report: Root[`error`] | undefined\n\tconst record = (error: unknown) => {\n\t\terrors.push(error)\n\t\t// Keep the first boundary handler as nested disposal wraps its errors.\n\t\treport ??= scopedErrorHandler(scope, error)\n\t}\n\ttry {\n\t\tscope._root._presence?.forget(scope)\n\t} catch (error) {\n\t\trecord(error)\n\t}\n\tfor (const cleanup of [...scope._cleanups].reverse()) {\n\t\ttry {\n\t\t\ttypeof cleanup === `function` ? cleanup() : dispose(cleanup)\n\t\t} catch (error) {\n\t\t\trecord(error)\n\t\t}\n\t}\n\tscope._parent?._cleanups.delete(scope)\n\tscope._cleanups.clear()\n\tscope._targets?.clear()\n\tscope._updates.length = 0\n\tif (errors.length) throwScopedError(scope, new AggregateError(errors), report)\n}\nexport function invalidate(scope: Scope): void {\n\tfor (const run of scope._updates) enqueue(scope, run)\n\tfor (const child of scope._cleanups)\n\t\tif (typeof child !== `function`) invalidate(child)\n}\nexport function enqueue(scope: Scope, run: Cleanup): void {\n\tif (!isPresent(scope)) return\n\tconst root = scope._root\n\tif (!root._queue.size && !root._flushing)\n\t\tqueueMicrotask(() => {\n\t\t\ttry {\n\t\t\t\troot.flush()\n\t\t\t} catch (error) {\n\t\t\t\tconst report = scopedErrorHandler(root, error) ?? root.error\n\t\t\t\troot._failure = undefined\n\t\t\t\treport(error)\n\t\t\t}\n\t\t})\n\t// A write can invalidate an observer that is already pending.\n\tif (import.meta.env.DEV) root._enqueueCount = (root._enqueueCount ?? 0) + 1\n\troot._queue.add(run)\n}\n\nfunction runCommits(root: Root, pending: Set<CommitJob>): CommitJob | undefined {\n\tconst top: CommitGroup = { order: root._setupOrder, children: [], jobs: [] }\n\tconst groups = new Map<Scope, CommitGroup>([[root, top]])\n\t// Keep only branches with pending work. Visit siblings in setup order.\n\tconst groupFor = (scope: Scope): CommitGroup => {\n\t\tlet group = groups.get(scope)\n\t\tif (!group) {\n\t\t\tgroup = { order: scope._setupOrder, children: [], jobs: [] }\n\t\t\tgroups.set(scope, group)\n\t\t\tgroupFor(scope._parent!).children.push(group)\n\t\t}\n\t\treturn group\n\t}\n\tfor (const job of [...pending].sort((a, b) => a.order - b.order))\n\t\tgroupFor(job.scope).jobs.push(job)\n\tlet last: CommitJob | undefined\n\tconst visit = (group: CommitGroup) => {\n\t\tfor (const child of group.children.sort((a, b) => a.order - b.order))\n\t\t\tvisit(child)\n\t\tfor (const job of group.jobs) {\n\t\t\tif (pending.delete(job) && isPresent(job.scope)) {\n\t\t\t\tconst enqueueCount = import.meta.env.DEV ? root._enqueueCount : undefined\n\t\t\t\tjob.run()\n\t\t\t\tif (import.meta.env.DEV && root._enqueueCount !== enqueueCount)\n\t\t\t\t\tlast = job\n\t\t\t}\n\t\t}\n\t}\n\tvisit(top)\n\treturn last\n}\n\nfunction capabilityMap(list: readonly Capability[] | undefined) {\n\tconst capabilities = new Map<string, Capability>()\n\tfor (const capability of list ?? []) {\n\t\tif (capabilities.has(capability.namespace))\n\t\t\tthrow new Error(`spa: duplicate capability ${capability.namespace}`)\n\t\tcapabilities.set(capability.namespace, capability)\n\t}\n\treturn capabilities\n}\nfunction registerPresence(\n\troot: Root,\n\tcapability: Capability,\n\tshared = false,\n): void {\n\tconst create = capability.presence\n\tif (!create) return\n\tif (root._presence) {\n\t\tif (!shared || root._presenceFactory !== create)\n\t\t\tthrow new Error(`spa: multiple presence coordinators`)\n\t} else {\n\t\troot._presence = create(root)\n\t\troot._presenceFactory = create\n\t}\n}\nexport function scopeCapabilities(scope: Scope): Map<string, Capability> {\n\treturn scope._options?._capabilities ?? scope._root._capabilities\n}\nexport function reportScopeError(scope: Scope, error: unknown): void {\n\tconst report = scopedErrorHandler(scope, error) ?? scope._root.error\n\ttry {\n\t\tfail(scope._root, error)\n\t} catch (failure) {\n\t\tscope._root._failure = undefined\n\t\treport(failure)\n\t}\n}\n\n/** Override root options for these children while sharing their parent's ownership. */\nexport function RootBoundary(\n\tprops: RootOptions & { children?: Children },\n): Children {\n\tconst scope = owner!\n\tconst { store, idPrefix, onError, capabilities } = props\n\tconst options = { ...scope._options }\n\tif (store !== undefined) options.store = store\n\tif (idPrefix !== undefined) options.idPrefix = idPrefix\n\tif (onError !== undefined) options.onError = onError\n\tif (capabilities !== undefined) {\n\t\toptions._capabilities = capabilityMap(capabilities)\n\t\tconst root = scope._root\n\t\tconst active = (root._boundaryCapabilities ??= new Map())\n\t\tfor (const capability of options._capabilities.values()) {\n\t\t\tregisterPresence(root, capability, true)\n\t\t\tactive.set(capability, (active.get(capability) ?? 0) + 1)\n\t\t\tscope._cleanups.add(() => {\n\t\t\t\tconst remaining = active.get(capability)! - 1\n\t\t\t\tif (remaining) active.set(capability, remaining)\n\t\t\t\telse active.delete(capability)\n\t\t\t})\n\t\t\troot._prepareCapability?.(capability)\n\t\t}\n\t}\n\tscope._options = options\n\treturn () => props.children\n}\n\nexport function createRoot(options: RootOptions = {}, server = false): Root {\n\tconst capabilities = capabilityMap(options.capabilities)\n\tconst root = {\n\t\t_capabilities: capabilities,\n\t\t_store: options.store ?? IMPLICIT.STORE,\n\t\t_prefix: options.idPrefix ?? `w${serial++}`,\n\t\t_id: 0,\n\t\t...createScope(),\n\t\t_queue: new Set(),\n\t\t_mounts: server ? undefined : [],\n\t} as unknown as Root\n\troot._root = root\n\troot.error =\n\t\toptions.onError ??\n\t\t((error) => {\n\t\t\tthrow error\n\t\t})\n\tfor (const capability of capabilities.values())\n\t\tregisterPresence(root, capability)\n\tconst hasWrites = () => root._queue.size || root._mounts!.length\n\tconst hasWork = () => hasWrites() || root._commits?.size\n\tlet flushPendingWrites: Cleanup | undefined\n\troot.flush = () => {\n\t\tconst nested = root._flushing\n\t\tif (!(nested ? hasWrites() : hasWork()) && !root._forms?.size) return\n\t\troot._flushing = true\n\t\ttry {\n\t\t\tif (nested) {\n\t\t\t\t// The outer flush owns commit dispatch. Mount callbacks can drain writes.\n\t\t\t\tflushPendingWrites?.()\n\t\t\t\treturn\n\t\t\t}\n\t\t\troot._failure = undefined\n\t\t\tlet passes = 0\n\t\t\tlet lastCommit: CommitJob | undefined\n\t\t\tconst checkLoop = () => {\n\t\t\t\tif (import.meta.env.DEV && ++passes > 100)\n\t\t\t\t\tthrow lastCommit?.loopError ?? new Error(`spa: update loop`)\n\t\t\t}\n\t\t\tconst runWriteBatch = () => {\n\t\t\t\tconst commits = new Map<Capability, Cleanup | undefined>()\n\t\t\t\tconst prepare = (capability: Capability) => {\n\t\t\t\t\tif (!commits.has(capability))\n\t\t\t\t\t\tcommits.set(capability, capability.beforeUpdate?.(root))\n\t\t\t\t}\n\t\t\t\tconst previous = root._prepareCapability\n\t\t\t\troot._prepareCapability = prepare\n\t\t\t\tlet formsReady = true\n\t\t\t\ttry {\n\t\t\t\t\tfor (const capability of capabilities.values()) prepare(capability)\n\t\t\t\t\tfor (const capability of root._boundaryCapabilities?.keys() ?? [])\n\t\t\t\t\t\tprepare(capability)\n\t\t\t\t\twhile (hasWrites()) {\n\t\t\t\t\t\tcheckLoop()\n\t\t\t\t\t\tfor (const run of [...root._queue])\n\t\t\t\t\t\t\tif (root._queue.delete(run)) run()\n\t\t\t\t\t\tfor (const run of root._mounts!.splice(0)) run()\n\t\t\t\t\t}\n\t\t\t\t\tfor (const restore of root._forms ?? [])\n\t\t\t\t\t\tif (!untrack(restore)) formsReady = false\n\t\t\t\t} finally {\n\t\t\t\t\troot._prepareCapability = previous\n\t\t\t\t\tfor (const commit of commits.values()) commit?.()\n\t\t\t\t}\n\t\t\t\treturn formsReady\n\t\t\t}\n\t\t\tdo {\n\t\t\t\tflushPendingWrites = runWriteBatch\n\t\t\t\tconst formsReady = runWriteBatch()\n\t\t\t\tflushPendingWrites = undefined\n\t\t\t\tif (!hasWrites()) {\n\t\t\t\t\t// Form event completion schedules a flush to restore the controls.\n\t\t\t\t\tif (!formsReady || !root._commits?.size) break\n\t\t\t\t\tcheckLoop()\n\t\t\t\t\tlastCommit = runCommits(root, root._commits) ?? lastCommit\n\t\t\t\t}\n\t\t\t} while (hasWork())\n\t\t\troot._failure = undefined\n\t\t} catch (error) {\n\t\t\tflushPendingWrites = undefined\n\t\t\tfail(root, error)\n\t\t} finally {\n\t\t\tif (!nested) root._flushing = false\n\t\t}\n\t}\n\treturn root\n}\n/** Return the atom.io store selected by the current owner. */\nexport function useStore(): RootStore {\n\treturn owner!._options?.store ?? owner!._root._store\n}\n/** Return atom.io disposal bound to the current root's store. */\nexport function useDisposal(): typeof disposeState {\n\treturn disposeFromStore.bind(null, useStore()) as typeof disposeState\n}\nexport function onCleanup(cleanup: Cleanup): void {\n\towner!._cleanups.add(cleanup)\n}\nexport function onMount(run: Cleanup): void {\n\tconst scope = owner!\n\tscope._root._mounts?.push(() => {\n\t\tif (!scope._dead)\n\t\t\twithin(scope, () => {\n\t\t\t\tuntrack(run)\n\t\t\t})\n\t})\n}\n/** Observe state during setup and apply changes after the root's writes. */\nexport function onCommit<T>(\n\tread: Accessor<T>,\n\tapply: (value: T, previous: T | undefined) => void | Cleanup,\n): void {\n\tconst scope = owner!\n\tconst root = scope._root\n\tif (!root._mounts) return\n\tconst pending = (root._commits ??= new Set())\n\tlet ran = false\n\tlet next: T\n\tlet previous: T | undefined\n\tlet cleanup: Cleanup | void\n\tconst clear = () => {\n\t\tconst release = cleanup\n\t\tcleanup = undefined\n\t\tif (release) untrack(release)\n\t}\n\tconst job: CommitJob = {\n\t\tscope,\n\t\torder: setupOrder++,\n\t\t// The registration stack identifies the component in a feedback loop.\n\t\tloopError: import.meta.env.DEV\n\t\t\t? new Error(`spa: onCommit update loop`)\n\t\t\t: undefined,\n\t\trun() {\n\t\t\twithin(scope, () => {\n\t\t\t\tuntrack(() => {\n\t\t\t\t\tclear()\n\t\t\t\t\tif (!isPresent(scope)) return\n\t\t\t\t\tconst old = previous\n\t\t\t\t\tprevious = next\n\t\t\t\t\tran = true\n\t\t\t\t\tcleanup = apply(next, old)\n\t\t\t\t\tif (scope._dead) clear()\n\t\t\t\t})\n\t\t\t})\n\t\t},\n\t}\n\tscope._cleanups.add(() => {\n\t\tpending.delete(job)\n\t\tclear()\n\t})\n\tobserve(scope, read, (value) => {\n\t\tnext = value\n\t\tif (!ran || !Object.is(value, previous)) pending.add(job)\n\t\telse pending.delete(job)\n\t})\n}\nexport function useId(): string {\n\tconst root = owner!._root\n\treturn `${owner!._options?.idPrefix ?? root._prefix}-${root._id++}`\n}\n\nexport function observe<T>(\n\tscope: Scope,\n\tread: Accessor<T>,\n\tapply: (value: T) => void,\n): void {\n\tconst subscriptions = new Map<Subscribe, Cleanup>()\n\tconst run = () => {\n\t\tif (!isPresent(scope)) return\n\t\tconst used = new Set<Subscribe>()\n\t\tconst previous = tracking\n\t\ttracking = (subscribe) => {\n\t\t\tused.add(subscribe)\n\t\t\tif (!subscriptions.has(subscribe))\n\t\t\t\tsubscriptions.set(\n\t\t\t\t\tsubscribe,\n\t\t\t\t\tsubscribe(() => {\n\t\t\t\t\t\tenqueue(scope, run)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t}\n\t\tlet value: T\n\t\ttry {\n\t\t\tvalue = within(scope, read)\n\t\t} finally {\n\t\t\ttracking = previous\n\t\t\tfor (const [subscribe, unsubscribe] of subscriptions)\n\t\t\t\tif (!used.has(subscribe)) {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tsubscriptions.delete(subscribe)\n\t\t\t\t}\n\t\t}\n\t\twithin(scope, () => {\n\t\t\tuntrack(() => {\n\t\t\t\tapply(value)\n\t\t\t})\n\t\t})\n\t}\n\tscope._updates.push(run)\n\tscope._cleanups.add(() => {\n\t\tscope._root._queue.delete(run)\n\t\tfor (const unsubscribe of subscriptions.values()) unsubscribe()\n\t})\n\trun()\n}\n\n/** Resolve a fixed family key in the current owner's store. */\nexport function resolveStateToken(token: any, key?: Canonical): any {\n\tconst store = useStore()\n\treturn token.type.endsWith(`_family`) ? findInStore(store, token, key!) : token\n}\n\n/** Capture a token for this instance. Change the component key to change its token. */\nexport function useGetter<T, E = never>(\n\ttoken: ReadableToken<T, any, E>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter<T, K extends Canonical, E = never>(\n\tfamily: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): Accessor<ViewOf<T | E>>\nexport function useGetter(token: any, key?: Canonical): Accessor<any> {\n\ttoken = resolveStateToken(token, key)\n\tconst root = owner!._root\n\tconst store = useStore()\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToState(store, token, `spa:${serial++}`, notify)\n\treturn () => {\n\t\tconst value = getFromStore(store, token)\n\t\troot._onRead?.(value, token, store)\n\t\ttracking?.(subscribe)\n\t\treturn value\n\t}\n}\nexport function useSetter<T>(\n\ttoken: WritableToken<T, any, any>,\n): (value: T | Setter<T>) => void\nexport function useSetter<T, K extends Canonical>(\n\tfamily: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n): (value: T | Setter<T>) => void\nexport function useSetter(token: any, key?: Canonical): (value: any) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = useStore()\n\treturn (value) => {\n\t\tsetIntoStore(store, token, value)\n\t}\n}\nexport function useTransaction<F extends (...args: any[]) => any>(\n\ttoken: TransactionToken<F>,\n): (...args: Parameters<F>) => ReturnType<F> {\n\treturn actUponStore(useStore(), token, `spa:${serial++}`)\n}\n\nconst refs = new WeakMap<RootStore, Map<string, object>>()\nexport function useRef<E extends Element>(\n\ttoken: RegularAtomToken<E | null>,\n): (element: E | null) => void\nexport function useRef<E extends Element, K extends Canonical>(\n\tfamily: RegularAtomFamilyToken<E | null, K>,\n\tkey: NoInfer<K>,\n): (element: E | null) => void\nexport function useRef<E extends Element>(\n\ttoken: any,\n\tkey?: Canonical,\n): (element: E | null) => void {\n\ttoken = resolveStateToken(token, key)\n\tconst store = useStore()\n\tconst owners = refs.get(store) ?? new Map<string, object>()\n\trefs.set(store, owners)\n\tconst identity = {}\n\tlet held: E | null = null\n\treturn (element) => {\n\t\tif (element) {\n\t\t\theld = element\n\t\t\towners.set(token.key, identity)\n\t\t\tsetIntoStore(store, token, element)\n\t\t} else if (owners.get(token.key) === identity) {\n\t\t\towners.delete(token.key)\n\t\t\tif (getFromStore(store, token) === held) setIntoStore(store, token, null)\n\t\t\theld = null\n\t\t}\n\t}\n}\nexport interface TimelineControls {\n\tgetCursor(): number\n\tgetLength(): number\n\tundo(): void\n\tredo(): void\n\tclear(): void\n\tgetTransaction(): { undo?: Cleanup; redo?: Cleanup }\n}\nexport function useTimeline<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n): TimelineControls\nexport function useTimeline<K extends Canonical, M extends TimelineManageable>(\n\tfamily: TimelineFamilyToken<K, M>,\n\tkey: NoInfer<K>,\n): TimelineControls\nexport function useTimeline(token: any, key?: Canonical): TimelineControls {\n\tconst store = useStore()\n\tconst selected: TimelineToken<any> =\n\t\ttoken.type === `timeline_family`\n\t\t\t? findTimelineInStore(store, token, key!)\n\t\t\t: token\n\tconst subscribe: Subscribe = (notify) =>\n\t\tsubscribeToTimeline(store, selected, `spa:${serial++}`, notify)\n\tconst read = () => {\n\t\tconst timeline = withdraw(store, selected)\n\t\ttracking?.(subscribe)\n\t\treturn timeline\n\t}\n\treturn {\n\t\tgetCursor: () => read().at,\n\t\tgetLength: () => read().history.length,\n\t\tundo: () => {\n\t\t\ttimeTravel(store, `undo`, selected)\n\t\t},\n\t\tredo: () => {\n\t\t\ttimeTravel(store, `redo`, selected)\n\t\t},\n\t\tclear: () => {\n\t\t\tclearTimelineInStore(store, selected)\n\t\t},\n\t\tgetTransaction: () => {\n\t\t\tconst timeline = read()\n\t\t\tconst controls: ReturnType<TimelineControls[`getTransaction`]> = {}\n\t\t\tfor (const direction of [`undo`, `redo`] as const) {\n\t\t\t\tconst group = getTimelineTransactionAtHead(timeline, direction)\n\t\t\t\tif (group)\n\t\t\t\t\tcontrols[direction] = () => {\n\t\t\t\t\t\ttimeTravelTransactionGroupInStore(store, direction, group)\n\t\t\t\t\t}\n\t\t\t}\n\t\t\treturn controls\n\t\t},\n\t}\n}\n\nexport function plain(value: Children): string {\n\tif (typeof value === `function`) return plain(value())\n\tif (Array.isArray(value)) return value.map(plain).join(``)\n\tif (value == null || typeof value === `boolean`) return ``\n\tif (import.meta.env.DEV && typeof value === `object`)\n\t\tthrow new Error(`spa: text required`)\n\t// oxlint-disable-next-line typescript/no-base-to-string -- Valid text children are primitives here; development rejects malformed object children.\n\treturn String(value)\n}\n\nexport function isPresent(scope: Scope): boolean {\n\tfor (let at: Scope | undefined = scope; at; at = at._parent)\n\t\tif (at._dead || at._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WACL,MAAM,SAAS,oBACZ,oBAAoB,OAAO,OAAO,GAAI,IACtC;CACJ,MAAM,aAAwB,WAC7B,oBAAoB,OAAO,UAAU,OAAO,YAAY,MAAM;CAC/D,MAAM,aAAa;EAClB,MAAM,WAAW,SAAS,OAAO,QAAQ;EACzC,WAAW,SAAS;EACpB,OAAO;CACR;CACA,OAAO;EACN,iBAAiB,KAAK,CAAC,CAAC;EACxB,iBAAiB,KAAK,CAAC,CAAC,QAAQ;EAChC,YAAY;GACX,WAAW,OAAO,QAAQ,QAAQ;EACnC;EACA,YAAY;GACX,WAAW,OAAO,QAAQ,QAAQ;EACnC;EACA,aAAa;GACZ,qBAAqB,OAAO,QAAQ;EACrC;EACA,sBAAsB;GACrB,MAAM,WAAW,KAAK;GACtB,MAAM,WAA2D,CAAC;GAClE,KAAK,MAAM,aAAa,CAAC,QAAQ,MAAM,GAAY;IAClD,MAAM,QAAQ,6BAA6B,UAAU,SAAS;IAC9D,IAAI,OACH,SAAS,mBAAmB;KAC3B,kCAAkC,OAAO,WAAW,KAAK;IAC1D;GACF;GACA,OAAO;EACR;CACD;AACD;AAEA,SAAgB,MAAM,OAAyB;CAC9C,IAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAAC;CACrD,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE;CACzD,IAAI,SAAS,QAAQ,OAAO,UAAU,WAAW,OAAO;CAIxD,OAAO,OAAO,KAAK;AACpB;AAEA,SAAgB,UAAU,OAAuB;CAChD,KAAK,IAAI,KAAwB,OAAO,IAAI,KAAK,GAAG,SACnD,IAAI,GAAG,SAAS,GAAG,UAAU,OAAO;CACrC,OAAO;AACR"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { browserApplication } from "./astro-application.js";
|
|
2
2
|
import { n as failPreparation, r as storeContext } from "./astro-context-OdlexHR4.js";
|
|
3
|
-
import { n as islandStore, t as island } from "./astro-shared-
|
|
4
|
-
import {
|
|
5
|
-
import { n as render, t as hydrate } from "./dom-
|
|
3
|
+
import { n as islandStore, t as island } from "./astro-shared-DBwINQav.js";
|
|
4
|
+
import { b as useGetter } from "./core-DrUd8x25.js";
|
|
5
|
+
import { n as render, t as hydrate } from "./dom-BRFv7FP_.js";
|
|
6
|
+
import { onRootDispose } from "./hot.js";
|
|
6
7
|
import { IMPLICIT, createRegularAtomFamily, disposeFromStore, findInStore, getFromStore, setIntoStore } from "atom.io/internal";
|
|
7
8
|
// src/astro-client.ts
|
|
8
9
|
const roots = /* @__PURE__ */ new WeakMap();
|
|
@@ -60,7 +61,7 @@ const createHydrator = (prepare) => (element) => async (component, props, slots,
|
|
|
60
61
|
disposeFromStore(store, state);
|
|
61
62
|
});
|
|
62
63
|
const mount = () => {
|
|
63
|
-
|
|
64
|
+
onRootDispose(dispose);
|
|
64
65
|
const getState = useGetter(state);
|
|
65
66
|
return () => island(component, getState().props, getState().slots);
|
|
66
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-client.js","names":[],"sources":["../../src/astro-client.ts"],"sourcesContent":["import type { ReadableToken, RegularAtomFamilyToken } from \"atom.io\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tcreateRegularAtomFamily,\n\tdisposeFromStore,\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport type { AstroStorePreparation, Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport {
|
|
1
|
+
{"version":3,"file":"astro-client.js","names":[],"sources":["../../src/astro-client.ts"],"sourcesContent":["import type { ReadableToken, RegularAtomFamilyToken } from \"atom.io\"\nimport type { RootStore } from \"atom.io/internal\"\nimport {\n\tcreateRegularAtomFamily,\n\tdisposeFromStore,\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\n\nimport { browserApplication } from \"./astro-application.ts\"\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport type { AstroStorePreparation, Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { useGetter } from \"./core.ts\"\nimport { hydrate, render } from \"./dom.ts\"\nimport { onRootDispose } from \"./hot.ts\"\n\ntype Props = Record<string, any>\ntype Slots = Record<string, string>\ntype Hydrator = (\n\tcomponent: Island,\n\tprops: Props,\n\tslots: Slots,\n\tmetadata: { client: string },\n) => Promise<void>\nconst roots = new WeakMap<\n\tElement,\n\t{\n\t\tcomponent: Island\n\t\tready: Promise<void>\n\t\tupdate(props: Props, slots: Slots): void\n\t\tdispose(): void\n\t}\n>()\ntype State = { props: Props; slots: Slots }\nconst states = new WeakMap<RootStore, RegularAtomFamilyToken<State, number>>()\nlet serial = 0\n\nexport const createHydrator =\n\t(prepare?: AstroStorePreparation) =>\n\t(element: HTMLElement): Hydrator =>\n\tasync (component, props, slots, { client }) => {\n\t\tconst previous = roots.get(element)\n\t\tif (previous?.component === component) {\n\t\t\tprevious.update(props, slots)\n\t\t\treturn previous.ready\n\t\t}\n\t\tprevious?.dispose()\n\t\tconst shared = !component.createStore && !component.isolate\n\t\tconst application = shared\n\t\t\t? browserApplication(element.ownerDocument)\n\t\t\t: undefined\n\t\tif (application && client === `only`) application.canResume = false\n\t\tconst lifetime = storeContext(element, application)\n\t\tconst initial = { props, slots }\n\t\tlet current = initial\n\t\tlet update: ((value: State) => void) | undefined\n\t\tlet disposed = false\n\t\tconst dispose = () => {\n\t\t\tif (disposed) return\n\t\t\tdisposed = true\n\t\t\telement.removeEventListener(`astro:unmount`, dispose)\n\t\t\troots.delete(element)\n\t\t\tlifetime.dispose()\n\t\t}\n\t\t// Publish the pending owner before invoking user code. Repeated hydration\n\t\t// calls update its props and share its preparation rather than racing stores.\n\t\tconst ready = Promise.resolve().then(async () => {\n\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\tlet mounting = false\n\t\t\ttry {\n\t\t\t\tconst store = await Promise.race([\n\t\t\t\t\tislandStore(\n\t\t\t\t\t\tcomponent,\n\t\t\t\t\t\tprops,\n\t\t\t\t\t\tlifetime.context,\n\t\t\t\t\t\tshared ? IMPLICIT.STORE : undefined,\n\t\t\t\t\t\tprepare,\n\t\t\t\t\t),\n\t\t\t\t\tlifetime.cancelled,\n\t\t\t\t])\n\t\t\t\tif (lifetime.context.signal.aborted) return\n\t\t\t\tmounting = true\n\t\t\t\tconst replace =\n\t\t\t\t\tclient === `only` ||\n\t\t\t\t\tprevious !== undefined ||\n\t\t\t\t\tapplication?.canResume === false ||\n\t\t\t\t\t// Server-settled state without a synchronous browser seed needs a\n\t\t\t\t\t// fresh view, whose loading state can differ from the SSR markup.\n\t\t\t\t\t(\n\t\t\t\t\t\tJSON.parse(\n\t\t\t\t\t\t\telement.getAttribute(`data-spa-reads`) ?? `[]`,\n\t\t\t\t\t\t) as ReadableToken<unknown>[]\n\t\t\t\t\t).some((token) => getFromStore(store!, token) instanceof Promise)\n\t\t\t\t// Astro leaves this sentinel on islands inserted by ClientRouter.\n\t\t\t\tconst sentinel = element.lastChild\n\t\t\t\tif (sentinel?.nodeType === 8 && sentinel.nodeValue === `astro:end`)\n\t\t\t\t\tsentinel.remove()\n\t\t\t\tlet family = states.get(store!)\n\t\t\t\tif (!family) {\n\t\t\t\t\tfamily = createRegularAtomFamily<State, number, never>(store!, {\n\t\t\t\t\t\tkey: `🔍 spa islands`,\n\t\t\t\t\t\tdefault: { props: {}, slots: {} },\n\t\t\t\t\t})\n\t\t\t\t\tstates.set(store!, family)\n\t\t\t\t}\n\t\t\t\tconst state = findInStore(store!, family, serial++)\n\t\t\t\tsetIntoStore(store!, state, replace ? current : initial)\n\t\t\t\tlifetime.context.onCleanup(() => {\n\t\t\t\t\tdisposeFromStore(store!, state)\n\t\t\t\t})\n\t\t\t\tconst mount = () => {\n\t\t\t\t\tonRootDispose(dispose)\n\t\t\t\t\tconst getState = useGetter(state)\n\t\t\t\t\treturn () => island(component, getState().props, getState().slots)\n\t\t\t\t}\n\t\t\t\tif (replace) element.replaceChildren()\n\t\t\t\tconst root = (replace ? render : hydrate)(mount, element, {\n\t\t\t\t\tstore: store!,\n\t\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t\t})\n\t\t\t\tlifetime.context.onCleanup(root.dispose)\n\t\t\t\tupdate = (next) => {\n\t\t\t\t\tsetIntoStore(store!, state, next)\n\t\t\t\t\troot.flush()\n\t\t\t\t}\n\t\t\t\t// Match the existing SSR tree before applying a structural prop update\n\t\t\t\t// that arrived while its store was still being prepared.\n\t\t\t\tif (!replace && current !== initial) update(current)\n\t\t\t} catch (error) {\n\t\t\t\tif (lifetime.context.signal.aborted && !mounting) return\n\t\t\t\tfailPreparation(error, dispose)\n\t\t\t}\n\t\t})\n\t\troots.set(element, {\n\t\t\tcomponent,\n\t\t\tready,\n\t\t\tupdate(nextProps, nextSlots) {\n\t\t\t\tcurrent = { props: nextProps, slots: nextSlots }\n\t\t\t\tupdate?.(current)\n\t\t\t},\n\t\t\tdispose,\n\t\t})\n\t\telement.addEventListener(`astro:unmount`, dispose, { once: true })\n\t\tlifetime.context.onCleanup(dispose)\n\t\treturn ready\n\t}\n\nexport default createHydrator()\n"],"mappings":";;;;;;;;AA2BA,MAAM,wBAAQ,IAAI,QAQhB;AAEF,MAAM,yBAAS,IAAI,QAA0D;AAC7E,IAAI,SAAS;AAEb,MAAa,kBACX,aACA,YACD,OAAO,WAAW,OAAO,OAAO,EAAE,aAAa;CAC9C,MAAM,WAAW,MAAM,IAAI,OAAO;CAClC,IAAI,UAAU,cAAc,WAAW;EACtC,SAAS,OAAO,OAAO,KAAK;EAC5B,OAAO,SAAS;CACjB;CACA,UAAU,QAAQ;CAClB,MAAM,SAAS,CAAC,UAAU,eAAe,CAAC,UAAU;CACpD,MAAM,cAAc,SACjB,mBAAmB,QAAQ,aAAa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,cAAc;IACnB,cAAc,OAAO;IACrB,MAAM,WAAW,UAAU,KAAK;IAChC,aAAa,OAAO,WAAW,SAAS,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,KAAK;GAClE;GACA,IAAI,SAAS,QAAQ,gBAAgB;GACrC,MAAM,QAAQ,UAAU,SAAS,QAAA,CAAS,OAAO,SAAS;IAClD;IACP,cAAc,UAAU,gBAAgB,CAAC;GAC1C,CAAC;GACD,SAAS,QAAQ,UAAU,KAAK,OAAO;GACvC,UAAU,SAAS;IAClB,aAAa,OAAQ,OAAO,IAAI;IAChC,KAAK,MAAM;GACZ;GAGA,IAAI,CAAC,WAAW,YAAY,SAAS,OAAO,OAAO;EACpD,SAAS,OAAO;GACf,IAAI,SAAS,QAAQ,OAAO,WAAW,CAAC,UAAU;GAClD,gBAAgB,OAAO,OAAO;EAC/B;CACD,CAAC;CACD,MAAM,IAAI,SAAS;EAClB;EACA;EACA,OAAO,WAAW,WAAW;GAC5B,UAAU;IAAE,OAAO;IAAW,OAAO;GAAU;GAC/C,SAAS,OAAO;EACjB;EACA;CACD,CAAC;CACD,QAAQ,iBAAiB,iBAAiB,SAAS,EAAE,MAAM,KAAK,CAAC;CACjE,SAAS,QAAQ,UAAU,OAAO;CAClC,OAAO;AACR;AAED,IAAA,uBAAe,eAAe"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as failPreparation, r as storeContext } from "./astro-context-OdlexHR4.js";
|
|
2
2
|
import { t as requestApplication } from "./astro-request-DRKvDjsO.js";
|
|
3
|
-
import { n as islandStore, t as island } from "./astro-shared-
|
|
4
|
-
import { t as renderToStringWithReads } from "./server-renderer-
|
|
3
|
+
import { n as islandStore, t as island } from "./astro-shared-DBwINQav.js";
|
|
4
|
+
import { t as renderToStringWithReads } from "./server-renderer-u1-c5PGd.js";
|
|
5
5
|
// src/astro-server.ts
|
|
6
6
|
const createRenderer = (awaitState = false) => ({
|
|
7
7
|
name: `spa`,
|
|
@@ -27,8 +27,8 @@ const createRenderer = (awaitState = false) => ({
|
|
|
27
27
|
lifetime.context.signal.throwIfAborted();
|
|
28
28
|
const reads = /* @__PURE__ */ new Map();
|
|
29
29
|
const pending = /* @__PURE__ */ new Set();
|
|
30
|
-
const html = renderToStringWithReads(() => () => island(component, props, slots), options, awaitState ? (value, token) => {
|
|
31
|
-
reads.set(token.key, token);
|
|
30
|
+
const html = renderToStringWithReads(() => () => island(component, props, slots), options, awaitState ? (value, token, readStore) => {
|
|
31
|
+
if (readStore === store) reads.set(token.key, token);
|
|
32
32
|
if (value instanceof Promise) pending.add(value);
|
|
33
33
|
} : void 0);
|
|
34
34
|
if (!pending.size) return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-server.js","names":[],"sources":["../../src/astro-server.ts"],"sourcesContent":["/* oxlint-disable typescript/require-await -- Astro requires async renderer callbacks, even for synchronous rendering. */\nimport type { NamedSSRLoadedRendererValue } from \"astro\"\nimport type { ReadableToken } from \"atom.io\"\n\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport { requestApplication } from \"./astro-request.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { renderToStringWithReads } from \"./server-renderer.ts\"\n\nexport const createRenderer = (\n\tawaitState = false,\n): NamedSSRLoadedRendererValue => ({\n\tname: `spa`,\n\tasync check(component: Island) {\n\t\treturn component?.spa === true\n\t},\n\tasync renderToStaticMarkup(component: Island, props, slots) {\n\t\tconst request = (this as unknown as { result?: { request: Request } }).result\n\t\t\t?.request\n\t\tconst requestOwner = request ? requestApplication(request) : undefined\n\t\tconst shared =\n\t\t\t!component.createStore && !component.isolate ? requestOwner : undefined\n\t\tconst lifetime = storeContext(undefined, shared?.application)\n\t\tif (requestOwner && !shared) {\n\t\t\tlifetime.context.onCleanup(\n\t\t\t\trequestOwner.application.onCleanup(lifetime.dispose),\n\t\t\t)\n\t\t}\n\t\ttry {\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst store = await Promise.race([\n\t\t\t\tislandStore(component, props, lifetime.context, shared?.store),\n\t\t\t\tlifetime.cancelled,\n\t\t\t])\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst options = {\n\t\t\t\tstore: store!,\n\t\t\t\tidPrefix: crypto.randomUUID(),\n\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t}\n\t\t\t// Retry only after reads made by this view settle. Each discarded render\n\t\t\t// releases its scopes; conditional branches can discover more async state.\n\t\t\tfor (;;) {\n\t\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\t\tconst reads = new Map<string, ReadableToken<unknown>>()\n\t\t\t\tconst pending = new Set<Promise<unknown>>()\n\t\t\t\tconst html = renderToStringWithReads(\n\t\t\t\t\t() => () => island(component, props, slots),\n\t\t\t\t\toptions,\n\t\t\t\t\tawaitState\n\t\t\t\t\t\t? (value, token) => {\n\t\t\t\t\t\t\t\
|
|
1
|
+
{"version":3,"file":"astro-server.js","names":[],"sources":["../../src/astro-server.ts"],"sourcesContent":["/* oxlint-disable typescript/require-await -- Astro requires async renderer callbacks, even for synchronous rendering. */\nimport type { NamedSSRLoadedRendererValue } from \"astro\"\nimport type { ReadableToken } from \"atom.io\"\n\nimport { failPreparation, storeContext } from \"./astro-context.ts\"\nimport { requestApplication } from \"./astro-request.ts\"\nimport type { Island } from \"./astro-shared.ts\"\nimport { island, islandStore } from \"./astro-shared.ts\"\nimport { renderToStringWithReads } from \"./server-renderer.ts\"\n\nexport const createRenderer = (\n\tawaitState = false,\n): NamedSSRLoadedRendererValue => ({\n\tname: `spa`,\n\tasync check(component: Island) {\n\t\treturn component?.spa === true\n\t},\n\tasync renderToStaticMarkup(component: Island, props, slots) {\n\t\tconst request = (this as unknown as { result?: { request: Request } }).result\n\t\t\t?.request\n\t\tconst requestOwner = request ? requestApplication(request) : undefined\n\t\tconst shared =\n\t\t\t!component.createStore && !component.isolate ? requestOwner : undefined\n\t\tconst lifetime = storeContext(undefined, shared?.application)\n\t\tif (requestOwner && !shared) {\n\t\t\tlifetime.context.onCleanup(\n\t\t\t\trequestOwner.application.onCleanup(lifetime.dispose),\n\t\t\t)\n\t\t}\n\t\ttry {\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst store = await Promise.race([\n\t\t\t\tislandStore(component, props, lifetime.context, shared?.store),\n\t\t\t\tlifetime.cancelled,\n\t\t\t])\n\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\tconst options = {\n\t\t\t\tstore: store!,\n\t\t\t\tidPrefix: crypto.randomUUID(),\n\t\t\t\tcapabilities: component.capabilities ?? [],\n\t\t\t}\n\t\t\t// Retry only after reads made by this view settle. Each discarded render\n\t\t\t// releases its scopes; conditional branches can discover more async state.\n\t\t\tfor (;;) {\n\t\t\t\tlifetime.context.signal.throwIfAborted()\n\t\t\t\tconst reads = new Map<string, ReadableToken<unknown>>()\n\t\t\t\tconst pending = new Set<Promise<unknown>>()\n\t\t\t\tconst html = renderToStringWithReads(\n\t\t\t\t\t() => () => island(component, props, slots),\n\t\t\t\t\toptions,\n\t\t\t\t\tawaitState\n\t\t\t\t\t\t? (value, token, readStore) => {\n\t\t\t\t\t\t\t\tif (readStore === store) reads.set(token.key, token)\n\t\t\t\t\t\t\t\tif (value instanceof Promise) {\n\t\t\t\t\t\t\t\t\tpending.add(value)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined,\n\t\t\t\t)\n\t\t\t\tif (!pending.size)\n\t\t\t\t\treturn {\n\t\t\t\t\t\thtml,\n\t\t\t\t\t\t// Even a cached synchronous server read can be async in the browser.\n\t\t\t\t\t\t...(reads.size\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tattrs: {\n\t\t\t\t\t\t\t\t\t\t\"data-spa-reads\": JSON.stringify([...reads.values()]),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t}\n\t\t\t\t// Caught producer errors resolve as state values. An uncaught failure\n\t\t\t\t// must reject this render with its original error.\n\t\t\t\tawait Promise.race([Promise.all(pending), lifetime.cancelled])\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailPreparation(error, lifetime.dispose)\n\t\t} finally {\n\t\t\tlifetime.dispose()\n\t\t}\n\t},\n})\nexport default createRenderer()\n"],"mappings":";;;;;AAUA,MAAa,kBACZ,aAAa,WACqB;CAClC,MAAM;CACN,MAAM,MAAM,WAAmB;EAC9B,OAAO,WAAW,QAAQ;CAC3B;CACA,MAAM,qBAAqB,WAAmB,OAAO,OAAO;EAC3D,MAAM,UAAW,KAAsD,QACpE;EACH,MAAM,eAAe,UAAU,mBAAmB,OAAO,IAAI,KAAA;EAC7D,MAAM,SACL,CAAC,UAAU,eAAe,CAAC,UAAU,UAAU,eAAe,KAAA;EAC/D,MAAM,WAAW,aAAa,KAAA,GAAW,QAAQ,WAAW;EAC5D,IAAI,gBAAgB,CAAC,QACpB,SAAS,QAAQ,UAChB,aAAa,YAAY,UAAU,SAAS,OAAO,CACpD;EAED,IAAI;GACH,SAAS,QAAQ,OAAO,eAAe;GACvC,MAAM,QAAQ,MAAM,QAAQ,KAAK,CAChC,YAAY,WAAW,OAAO,SAAS,SAAS,QAAQ,KAAK,GAC7D,SAAS,SACV,CAAC;GACD,SAAS,QAAQ,OAAO,eAAe;GACvC,MAAM,UAAU;IACR;IACP,UAAU,OAAO,WAAW;IAC5B,cAAc,UAAU,gBAAgB,CAAC;GAC1C;GAGA,SAAS;IACR,SAAS,QAAQ,OAAO,eAAe;IACvC,MAAM,wBAAQ,IAAI,IAAoC;IACtD,MAAM,0BAAU,IAAI,IAAsB;IAC1C,MAAM,OAAO,oCACA,OAAO,WAAW,OAAO,KAAK,GAC1C,SACA,cACI,OAAO,OAAO,cAAc;KAC7B,IAAI,cAAc,OAAO,MAAM,IAAI,MAAM,KAAK,KAAK;KACnD,IAAI,iBAAiB,SACpB,QAAQ,IAAI,KAAK;IAEnB,IACC,KAAA,CACJ;IACA,IAAI,CAAC,QAAQ,MACZ,OAAO;KACN;KAEA,GAAI,MAAM,OACP,EACA,OAAO,EACN,kBAAkB,KAAK,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,EACrD,EACD,IACC,CAAC;IACL;IAGD,MAAM,QAAQ,KAAK,CAAC,QAAQ,IAAI,OAAO,GAAG,SAAS,SAAS,CAAC;GAC9D;EACD,SAAS,OAAO;GACf,gBAAgB,OAAO,SAAS,OAAO;EACxC,UAAU;GACT,SAAS,QAAQ;EAClB;CACD;AACD;AACA,IAAA,uBAAe,eAAe"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx } from "./jsx-runtime.js";
|
|
1
|
+
import { n as jsx } from "./jsx-runtime-BGDPK50B.js";
|
|
2
2
|
import { IMPLICIT, Store } from "atom.io/internal";
|
|
3
3
|
// src/astro-shared.ts
|
|
4
4
|
async function islandStore(component, props, context, shared, prepare) {
|
|
@@ -28,4 +28,4 @@ function island(component, props, slots) {
|
|
|
28
28
|
}
|
|
29
29
|
export { islandStore as n, island as t };
|
|
30
30
|
|
|
31
|
-
//# sourceMappingURL=astro-shared-
|
|
31
|
+
//# sourceMappingURL=astro-shared-DBwINQav.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"astro-shared-
|
|
1
|
+
{"version":3,"file":"astro-shared-DBwINQav.js","names":[],"sources":["../../src/astro-shared.ts"],"sourcesContent":["import type { RootStore } from \"atom.io/internal\"\nimport { IMPLICIT, Store } from \"atom.io/internal\"\n\nimport type { Capability } from \"./capabilities.ts\"\nimport type { Component, SpaElement } from \"./core.ts\"\nimport { jsx } from \"./jsx-runtime.ts\"\n\nexport interface AstroApplicationContext {\n\t/** Whether the application still represents its initial server snapshot. */\n\treadonly canResume: boolean\n\treadonly signal: AbortSignal\n\tonCleanup(cleanup: () => void): void\n\t/** Initialize a resource once for this application lifetime. */\n\tget<T>(key: unknown, initialize: () => T): T\n}\nexport interface AstroStoreContext {\n\t/** Shared across default islands; private for explicitly isolated islands. */\n\tapplication: AstroApplicationContext\n\t/** The browser island host; undefined during server rendering. */\n\telement: HTMLElement | undefined\n\t/** Aborted when preparation is cancelled or the island is released. */\n\tsignal: AbortSignal\n\t/** Release resources even if preparation or rendering fails. */\n\tonCleanup(cleanup: () => void): void\n}\nexport type AstroStoreFactory<P = Record<string, any>> = (\n\tprops: P,\n\tcontext: AstroStoreContext,\n) => RootStore | Promise<RootStore>\nexport type AstroStorePreparation<P = Record<string, any>> = (\n\tstore: RootStore,\n\tprops: P,\n\tcontext: AstroStoreContext,\n) => void | Promise<void>\nexport type Island<P = any> = Component<P> & {\n\tspa?: boolean\n\t/** Capabilities are scoped to this island root on the server and client. */\n\tcapabilities?: readonly Capability[]\n\t/** Opt into a private island store instead of the shared application store. */\n\tisolate?: boolean\n\tcreateStore?: AstroStoreFactory<P>\n\tprepareStore?: AstroStorePreparation<P>\n}\nexport async function islandStore(\n\tcomponent: Island,\n\tprops: Record<string, any>,\n\tcontext: AstroStoreContext,\n\tshared?: RootStore,\n\tprepare?: AstroStorePreparation,\n): Promise<RootStore> {\n\tconst store = await (component.createStore?.(props, context) ??\n\t\tshared ??\n\t\t(new Store(\n\t\t\t{ name: `spa-island`, lifespan: `ephemeral`, isProduction: true },\n\t\t\tIMPLICIT.STORE,\n\t\t) as RootStore))\n\tcontext.signal.throwIfAborted()\n\tawait prepare?.(store, props, context)\n\tcontext.signal.throwIfAborted()\n\tawait component.prepareStore?.(store, props, context)\n\tcontext.signal.throwIfAborted()\n\treturn store\n}\nexport function island(\n\tcomponent: Island,\n\tprops: Record<string, any>,\n\tslots: Record<string, string>,\n): SpaElement {\n\tconst children = Object.fromEntries(\n\t\tObject.entries(slots).map(([name, html]) => [\n\t\t\tname,\n\t\t\tjsx(`astro-slot`, {\n\t\t\t\tkey: html,\n\t\t\t\tname: name === `default` ? undefined : name,\n\t\t\t\tinnerHTML: html,\n\t\t\t}),\n\t\t]),\n\t)\n\treturn jsx(component, {\n\t\t...props,\n\t\tslots: children,\n\t\tchildren: children[`default`],\n\t})\n}\n"],"mappings":";;;AA2CA,eAAsB,YACrB,WACA,OACA,SACA,QACA,SACqB;CACrB,MAAM,QAAQ,OAAO,UAAU,cAAc,OAAO,OAAO,KAC1D,UACC,IAAI,MACJ;EAAE,MAAM;EAAc,UAAU;EAAa,cAAc;CAAK,GAChE,SAAS,KACV;CACD,QAAQ,OAAO,eAAe;CAC9B,MAAM,UAAU,OAAO,OAAO,OAAO;CACrC,QAAQ,OAAO,eAAe;CAC9B,MAAM,UAAU,eAAe,OAAO,OAAO,OAAO;CACpD,QAAQ,OAAO,eAAe;CAC9B,OAAO;AACR;AACA,SAAgB,OACf,WACA,OACA,OACa;CACb,MAAM,WAAW,OAAO,YACvB,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,UAAU,CAC3C,MACA,IAAI,cAAc;EACjB,KAAK;EACL,MAAM,SAAS,YAAY,KAAA,IAAY;EACvC,WAAW;CACZ,CAAC,CACF,CAAC,CACF;CACA,OAAO,IAAI,WAAW;EACrB,GAAG;EACH,OAAO;EACP,UAAU,SAAS;CACpB,CAAC;AACF"}
|