solid-js 1.9.11 → 2.0.0-beta.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/dist/dev.cjs +733 -1678
- package/dist/dev.js +598 -1643
- package/dist/server.cjs +769 -703
- package/dist/server.js +682 -670
- package/dist/solid.cjs +699 -1618
- package/dist/solid.js +563 -1582
- package/package.json +7 -151
- package/types/{render → client}/component.d.ts +1 -38
- package/types/client/core.d.ts +65 -0
- package/types/client/flow.d.ts +100 -0
- package/types/client/hydration.d.ts +76 -0
- package/types/index.d.ts +11 -14
- package/types/jsx.d.ts +1508 -1633
- package/types/server/component.d.ts +66 -0
- package/types/server/core.d.ts +44 -0
- package/types/server/flow.d.ts +60 -0
- package/types/server/hydration.d.ts +21 -0
- package/types/server/index.d.ts +12 -3
- package/types/server/shared.d.ts +45 -0
- package/types/server/signals.d.ts +60 -0
- package/h/dist/h.cjs +0 -115
- package/h/dist/h.js +0 -113
- package/h/jsx-dev-runtime/package.json +0 -8
- package/h/jsx-runtime/dist/jsx.cjs +0 -15
- package/h/jsx-runtime/dist/jsx.js +0 -10
- package/h/jsx-runtime/package.json +0 -8
- package/h/jsx-runtime/types/index.d.ts +0 -11
- package/h/jsx-runtime/types/jsx.d.ts +0 -4242
- package/h/package.json +0 -8
- package/h/types/hyperscript.d.ts +0 -20
- package/h/types/index.d.ts +0 -3
- package/html/dist/html.cjs +0 -583
- package/html/dist/html.js +0 -581
- package/html/package.json +0 -8
- package/html/types/index.d.ts +0 -3
- package/html/types/lit.d.ts +0 -41
- package/store/dist/dev.cjs +0 -458
- package/store/dist/dev.js +0 -449
- package/store/dist/server.cjs +0 -126
- package/store/dist/server.js +0 -114
- package/store/dist/store.cjs +0 -438
- package/store/dist/store.js +0 -429
- package/store/package.json +0 -46
- package/store/types/index.d.ts +0 -12
- package/store/types/modifiers.d.ts +0 -6
- package/store/types/mutable.d.ts +0 -5
- package/store/types/server.d.ts +0 -17
- package/store/types/store.d.ts +0 -107
- package/types/reactive/array.d.ts +0 -44
- package/types/reactive/observable.d.ts +0 -36
- package/types/reactive/scheduler.d.ts +0 -10
- package/types/reactive/signal.d.ts +0 -577
- package/types/render/Suspense.d.ts +0 -26
- package/types/render/flow.d.ts +0 -118
- package/types/render/hydration.d.ts +0 -24
- package/types/render/index.d.ts +0 -4
- package/types/server/reactive.d.ts +0 -98
- package/types/server/rendering.d.ts +0 -159
- package/universal/dist/dev.cjs +0 -245
- package/universal/dist/dev.js +0 -243
- package/universal/dist/universal.cjs +0 -245
- package/universal/dist/universal.js +0 -243
- package/universal/package.json +0 -20
- package/universal/types/index.d.ts +0 -3
- package/universal/types/universal.d.ts +0 -30
- package/web/dist/dev.cjs +0 -894
- package/web/dist/dev.js +0 -782
- package/web/dist/server.cjs +0 -892
- package/web/dist/server.js +0 -782
- package/web/dist/web.cjs +0 -883
- package/web/dist/web.js +0 -771
- package/web/package.json +0 -46
- package/web/storage/dist/storage.cjs +0 -12
- package/web/storage/dist/storage.js +0 -10
- package/web/storage/package.json +0 -15
- package/web/storage/types/index.d.ts +0 -2
- package/web/types/client.d.ts +0 -79
- package/web/types/core.d.ts +0 -2
- package/web/types/index.d.ts +0 -50
- package/web/types/jsx.d.ts +0 -1
- package/web/types/server-mock.d.ts +0 -65
- package/web/types/server.d.ts +0 -177
package/dist/server.js
CHANGED
|
@@ -1,759 +1,771 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return new Error(typeof err === "string" ? err : "Unknown error", {
|
|
10
|
-
cause: err
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function handleError(err, owner = Owner) {
|
|
14
|
-
const fns = owner && owner.context && owner.context[ERROR];
|
|
15
|
-
const error = castError(err);
|
|
16
|
-
if (!fns) throw error;
|
|
17
|
-
try {
|
|
18
|
-
for (const f of fns) f(error);
|
|
19
|
-
} catch (e) {
|
|
20
|
-
handleError(e, owner && owner.owner || null);
|
|
1
|
+
import { getOwner, getNextChildId, createOwner, runWithOwner, onCleanup, NotReadyError, isWrappable, setContext, getContext, flatten, createRoot } from '@solidjs/signals';
|
|
2
|
+
export { $PROXY, $TRACK, NotReadyError, createOwner, createRoot, flatten, getNextChildId, getOwner, isEqual, isWrappable, merge, omit, onCleanup, runWithOwner, snapshot, storePath } from '@solidjs/signals';
|
|
3
|
+
|
|
4
|
+
const sharedConfig = {
|
|
5
|
+
getNextContextId() {
|
|
6
|
+
const o = getOwner();
|
|
7
|
+
if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
|
|
8
|
+
return getNextChildId(o);
|
|
21
9
|
}
|
|
22
|
-
}
|
|
23
|
-
const UNOWNED = {
|
|
24
|
-
context: null,
|
|
25
|
-
owner: null,
|
|
26
|
-
owned: null,
|
|
27
|
-
cleanups: null
|
|
28
10
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
owned: null,
|
|
35
|
-
cleanups: null
|
|
36
|
-
};
|
|
37
|
-
if (Owner) {
|
|
38
|
-
if (!Owner.owned) Owner.owned = [o];else Owner.owned.push(o);
|
|
39
|
-
}
|
|
40
|
-
return o;
|
|
41
|
-
}
|
|
42
|
-
function createRoot(fn, detachedOwner) {
|
|
43
|
-
const owner = Owner,
|
|
44
|
-
current = detachedOwner === undefined ? owner : detachedOwner,
|
|
45
|
-
root = fn.length === 0 ? UNOWNED : {
|
|
46
|
-
context: current ? current.context : null,
|
|
47
|
-
owner: current,
|
|
48
|
-
owned: null,
|
|
49
|
-
cleanups: null
|
|
50
|
-
};
|
|
51
|
-
Owner = root;
|
|
52
|
-
let result;
|
|
11
|
+
|
|
12
|
+
let Observer = null;
|
|
13
|
+
function runWithObserver(comp, fn) {
|
|
14
|
+
const prev = Observer;
|
|
15
|
+
Observer = comp;
|
|
53
16
|
try {
|
|
54
|
-
|
|
55
|
-
} catch (err) {
|
|
56
|
-
handleError(err);
|
|
17
|
+
return fn();
|
|
57
18
|
} finally {
|
|
58
|
-
|
|
19
|
+
Observer = prev;
|
|
59
20
|
}
|
|
60
|
-
return result;
|
|
61
21
|
}
|
|
62
|
-
function
|
|
63
|
-
return
|
|
64
|
-
return value = typeof v === "function" ? v(value) : v;
|
|
65
|
-
}];
|
|
22
|
+
function getObserver() {
|
|
23
|
+
return Observer;
|
|
66
24
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
25
|
+
function createSignal(first, second, third) {
|
|
26
|
+
if (typeof first === "function") {
|
|
27
|
+
const ssrSource = third?.ssrSource;
|
|
28
|
+
if (ssrSource === "initial" || ssrSource === "client") {
|
|
29
|
+
createOwner();
|
|
30
|
+
let value = second;
|
|
31
|
+
return [() => value, v => {
|
|
32
|
+
return value = typeof v === "function" ? v(value) : v;
|
|
33
|
+
}];
|
|
34
|
+
}
|
|
35
|
+
const memoOpts = third?.deferStream || ssrSource ? {
|
|
36
|
+
deferStream: third?.deferStream,
|
|
37
|
+
ssrSource
|
|
38
|
+
} : undefined;
|
|
39
|
+
const memo = createMemo(p => {
|
|
40
|
+
let value = first(p ? p[0]() : second);
|
|
41
|
+
return [() => value, v => {
|
|
42
|
+
return value = typeof v === "function" ? v(value) : v;
|
|
43
|
+
}];
|
|
44
|
+
}, undefined, memoOpts);
|
|
45
|
+
return [() => memo()[0](), v => memo()[1](v)];
|
|
46
|
+
}
|
|
47
|
+
return [() => first, v => {
|
|
48
|
+
return first = typeof v === "function" ? v(first) : v;
|
|
49
|
+
}];
|
|
76
50
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
51
|
+
function createMemo(compute, value, options) {
|
|
52
|
+
const ctx = sharedConfig.context;
|
|
53
|
+
const owner = createOwner();
|
|
54
|
+
const comp = {
|
|
55
|
+
owner,
|
|
56
|
+
value: value,
|
|
57
|
+
compute: compute,
|
|
58
|
+
error: undefined,
|
|
59
|
+
computed: false,
|
|
60
|
+
disposed: false
|
|
82
61
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
62
|
+
runWithOwner(owner, () => onCleanup(() => {
|
|
63
|
+
comp.disposed = true;
|
|
64
|
+
}));
|
|
65
|
+
function update() {
|
|
66
|
+
if (comp.disposed) return;
|
|
67
|
+
try {
|
|
68
|
+
comp.error = undefined;
|
|
69
|
+
const result = runWithOwner(owner, () => runWithObserver(comp, () => comp.compute(comp.value)));
|
|
70
|
+
comp.computed = true;
|
|
71
|
+
processResult(comp, result, owner, ctx, options?.deferStream, options?.ssrSource);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
if (err instanceof NotReadyError) {
|
|
74
|
+
err.source?.then(() => update());
|
|
75
|
+
}
|
|
76
|
+
comp.error = err;
|
|
77
|
+
comp.computed = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const ssrSource = options?.ssrSource;
|
|
81
|
+
if (ssrSource === "initial" || ssrSource === "client") {
|
|
82
|
+
comp.computed = true;
|
|
83
|
+
} else if (!options?.lazy) {
|
|
84
|
+
update();
|
|
93
85
|
}
|
|
94
|
-
return () => v;
|
|
95
|
-
}
|
|
96
|
-
function createDeferred(source) {
|
|
97
|
-
return source;
|
|
98
|
-
}
|
|
99
|
-
function createSelector(source, fn = equalFn) {
|
|
100
|
-
return k => fn(k, source());
|
|
101
|
-
}
|
|
102
|
-
function batch(fn) {
|
|
103
|
-
return fn();
|
|
104
|
-
}
|
|
105
|
-
const untrack = batch;
|
|
106
|
-
function on(deps, fn, options = {}) {
|
|
107
|
-
const isArray = Array.isArray(deps);
|
|
108
|
-
const defer = options.defer;
|
|
109
86
|
return () => {
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
return
|
|
87
|
+
if (!comp.computed) {
|
|
88
|
+
update();
|
|
89
|
+
}
|
|
90
|
+
if (comp.error) {
|
|
91
|
+
throw comp.error;
|
|
92
|
+
}
|
|
93
|
+
return comp.value;
|
|
117
94
|
};
|
|
118
95
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
96
|
+
function createDeepProxy(target, patches, basePath = []) {
|
|
97
|
+
const childProxies = new Map();
|
|
98
|
+
const handler = {
|
|
99
|
+
get(obj, key, receiver) {
|
|
100
|
+
if (Array.isArray(obj)) {
|
|
101
|
+
if (key === "shift") {
|
|
102
|
+
return function () {
|
|
103
|
+
if (obj.length === 0) return undefined;
|
|
104
|
+
const removed = obj[0];
|
|
105
|
+
Array.prototype.shift.call(obj);
|
|
106
|
+
childProxies.clear();
|
|
107
|
+
patches.push([[...basePath, 0]]);
|
|
108
|
+
return removed;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (key === "unshift") {
|
|
112
|
+
return function (...items) {
|
|
113
|
+
const result = Array.prototype.unshift.apply(obj, items);
|
|
114
|
+
childProxies.clear();
|
|
115
|
+
for (let i = 0; i < items.length; i++) {
|
|
116
|
+
patches.push([[...basePath, i], items[i], 1]);
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (key === "splice") {
|
|
122
|
+
return function (start, deleteCount, ...items) {
|
|
123
|
+
const len = obj.length;
|
|
124
|
+
const s = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
|
|
125
|
+
const d = deleteCount === undefined ? len - s : Math.min(Math.max(deleteCount, 0), len - s);
|
|
126
|
+
const removed = Array.prototype.splice.apply(obj, [s, d, ...items]);
|
|
127
|
+
childProxies.clear();
|
|
128
|
+
for (let i = 0; i < d; i++) patches.push([[...basePath, s]]);
|
|
129
|
+
for (let i = 0; i < items.length; i++) patches.push([[...basePath, s + i], items[i], 1]);
|
|
130
|
+
return removed;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const value = Reflect.get(obj, key, receiver);
|
|
135
|
+
if (value !== null && typeof value === "object" && typeof key !== "symbol") {
|
|
136
|
+
if (!childProxies.has(key)) {
|
|
137
|
+
childProxies.set(key, createDeepProxy(value, patches, [...basePath, key]));
|
|
138
|
+
}
|
|
139
|
+
return childProxies.get(key);
|
|
140
|
+
}
|
|
141
|
+
return value;
|
|
142
|
+
},
|
|
143
|
+
set(obj, key, value) {
|
|
144
|
+
childProxies.delete(key);
|
|
145
|
+
patches.push([[...basePath, key], value]);
|
|
146
|
+
return Reflect.set(obj, key, value);
|
|
147
|
+
},
|
|
148
|
+
deleteProperty(obj, key) {
|
|
149
|
+
childProxies.delete(key);
|
|
150
|
+
patches.push([[...basePath, key]]);
|
|
151
|
+
return Reflect.deleteProperty(obj, key);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
return new Proxy(target, handler);
|
|
155
|
+
}
|
|
156
|
+
function processResult(comp, result, owner, ctx, deferStream, ssrSource) {
|
|
157
|
+
if (comp.disposed) return;
|
|
158
|
+
const id = owner.id;
|
|
159
|
+
const uninitialized = comp.value === undefined;
|
|
160
|
+
if (result instanceof Promise) {
|
|
161
|
+
result.then(v => {
|
|
162
|
+
result.s = 1;
|
|
163
|
+
result.v = v;
|
|
164
|
+
if (comp.disposed) return;
|
|
165
|
+
comp.value = v;
|
|
166
|
+
comp.error = undefined;
|
|
167
|
+
}, () => {});
|
|
168
|
+
if (ctx?.async && ctx.serialize && id) ctx.serialize(id, result, deferStream);
|
|
169
|
+
if (uninitialized) {
|
|
170
|
+
comp.error = new NotReadyError(result);
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const iterator = result?.[Symbol.asyncIterator];
|
|
175
|
+
if (typeof iterator === "function") {
|
|
176
|
+
const iter = iterator.call(result);
|
|
177
|
+
if (ssrSource === "hybrid") {
|
|
178
|
+
const promise = iter.next().then(v => {
|
|
179
|
+
promise.s = 1;
|
|
180
|
+
promise.v = v.value;
|
|
181
|
+
if (comp.disposed) return;
|
|
182
|
+
comp.value = v.value;
|
|
183
|
+
comp.error = undefined;
|
|
184
|
+
}, () => {});
|
|
185
|
+
if (ctx?.async && ctx.serialize && id) ctx.serialize(id, promise, deferStream);
|
|
186
|
+
if (uninitialized) {
|
|
187
|
+
comp.error = new NotReadyError(promise);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
const firstNext = iter.next();
|
|
191
|
+
const firstReady = firstNext.then(r => {
|
|
192
|
+
if (comp.disposed) return;
|
|
193
|
+
if (!r.done) {
|
|
194
|
+
comp.value = r.value;
|
|
195
|
+
comp.error = undefined;
|
|
196
|
+
}
|
|
197
|
+
}, () => {});
|
|
198
|
+
let servedFirst = false;
|
|
199
|
+
const tapped = {
|
|
200
|
+
[Symbol.asyncIterator]: () => ({
|
|
201
|
+
next() {
|
|
202
|
+
if (!servedFirst) {
|
|
203
|
+
servedFirst = true;
|
|
204
|
+
return firstNext.then(r => {
|
|
205
|
+
if (!r.done && !comp.disposed) comp.value = r.value;
|
|
206
|
+
return r;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return iter.next().then(r => r);
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
};
|
|
213
|
+
if (ctx?.async && ctx.serialize && id) ctx.serialize(id, tapped, deferStream);
|
|
214
|
+
if (uninitialized) {
|
|
215
|
+
comp.error = new NotReadyError(firstReady);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
123
219
|
}
|
|
124
|
-
|
|
220
|
+
comp.value = result;
|
|
125
221
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
222
|
+
function serverEffect(compute, effectFn, value, options) {
|
|
223
|
+
const ssrSource = options?.ssrSource;
|
|
224
|
+
if (ssrSource === "client" || ssrSource === "initial") {
|
|
225
|
+
createOwner();
|
|
226
|
+
return;
|
|
130
227
|
}
|
|
131
|
-
|
|
132
|
-
for (let i = 0; i < node.cleanups.length; i++) node.cleanups[i]();
|
|
133
|
-
node.cleanups = null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function catchError(fn, handler) {
|
|
228
|
+
const ctx = sharedConfig.context;
|
|
137
229
|
const owner = createOwner();
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
230
|
+
const comp = {
|
|
231
|
+
owner,
|
|
232
|
+
value: value,
|
|
233
|
+
compute: compute,
|
|
234
|
+
error: undefined,
|
|
235
|
+
computed: true,
|
|
236
|
+
disposed: false
|
|
141
237
|
};
|
|
142
|
-
|
|
238
|
+
if (ssrSource) {
|
|
239
|
+
runWithOwner(owner, () => onCleanup(() => {
|
|
240
|
+
comp.disposed = true;
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
143
243
|
try {
|
|
144
|
-
|
|
244
|
+
const result = runWithOwner(owner, () => runWithObserver(comp, () => compute(value)));
|
|
245
|
+
if (ssrSource) {
|
|
246
|
+
processResult(comp, result, owner, ctx, options?.deferStream, ssrSource);
|
|
247
|
+
}
|
|
248
|
+
effectFn?.(ssrSource ? comp.value ?? result : result, value);
|
|
145
249
|
} catch (err) {
|
|
146
|
-
handleError(err);
|
|
147
|
-
} finally {
|
|
148
|
-
Owner = Owner.owner;
|
|
149
250
|
}
|
|
150
251
|
}
|
|
151
|
-
function
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
function createContext(defaultValue) {
|
|
155
|
-
const id = Symbol("context");
|
|
156
|
-
return {
|
|
157
|
-
id,
|
|
158
|
-
Provider: createProvider(id),
|
|
159
|
-
defaultValue
|
|
160
|
-
};
|
|
252
|
+
function createEffect(compute, effect, value, options) {
|
|
253
|
+
serverEffect(compute, undefined, value, options);
|
|
161
254
|
}
|
|
162
|
-
function
|
|
163
|
-
|
|
255
|
+
function createRenderEffect(compute, effectFn, value, options) {
|
|
256
|
+
serverEffect(compute, effectFn, value, options);
|
|
164
257
|
}
|
|
165
|
-
function
|
|
166
|
-
|
|
258
|
+
function createTrackedEffect(compute, options) {
|
|
259
|
+
const o = getOwner();
|
|
260
|
+
if (o?.id != null) getNextChildId(o);
|
|
167
261
|
}
|
|
168
|
-
function
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const c = memo();
|
|
172
|
-
return Array.isArray(c) ? c : c != null ? [c] : [];
|
|
262
|
+
function createReaction(effectFn, options) {
|
|
263
|
+
return tracking => {
|
|
264
|
+
tracking();
|
|
173
265
|
};
|
|
174
|
-
return memo;
|
|
175
|
-
}
|
|
176
|
-
function runWithOwner(o, fn) {
|
|
177
|
-
const prev = Owner;
|
|
178
|
-
Owner = o;
|
|
179
|
-
try {
|
|
180
|
-
return fn();
|
|
181
|
-
} catch (err) {
|
|
182
|
-
handleError(err);
|
|
183
|
-
} finally {
|
|
184
|
-
Owner = prev;
|
|
185
|
-
}
|
|
186
266
|
}
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
267
|
+
function createOptimistic(first, second, third) {
|
|
268
|
+
return createSignal(first, second, third);
|
|
269
|
+
}
|
|
270
|
+
function setProperty(state, property, value) {
|
|
271
|
+
if (state[property] === value) return;
|
|
272
|
+
if (value === undefined) {
|
|
273
|
+
delete state[property];
|
|
274
|
+
} else state[property] = value;
|
|
275
|
+
}
|
|
276
|
+
function createStore(first, second) {
|
|
277
|
+
if (typeof first === "function") {
|
|
278
|
+
const store = createProjection(first, second ?? {});
|
|
279
|
+
return [store, fn => fn(store)];
|
|
280
|
+
}
|
|
281
|
+
const state = first;
|
|
282
|
+
return [state, fn => fn(state)];
|
|
283
|
+
}
|
|
284
|
+
const createOptimisticStore = createStore;
|
|
285
|
+
function createPendingProxy(state, source) {
|
|
286
|
+
let pending = true;
|
|
287
|
+
let readTarget = state;
|
|
288
|
+
const proxy = new Proxy(state, {
|
|
289
|
+
get(obj, key, receiver) {
|
|
290
|
+
if (pending && typeof key !== "symbol") {
|
|
291
|
+
throw new NotReadyError(source);
|
|
292
|
+
}
|
|
293
|
+
return Reflect.get(readTarget, key);
|
|
194
294
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
295
|
+
});
|
|
296
|
+
return [proxy, frozen => {
|
|
297
|
+
if (frozen) readTarget = frozen;
|
|
298
|
+
pending = false;
|
|
299
|
+
}];
|
|
198
300
|
}
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
301
|
+
function createProjection(fn, initialValue = {}, options) {
|
|
302
|
+
const ctx = sharedConfig.context;
|
|
303
|
+
const owner = createOwner();
|
|
304
|
+
const [state] = createStore(initialValue);
|
|
305
|
+
if (options?.ssrSource === "initial" || options?.ssrSource === "client") {
|
|
306
|
+
return state;
|
|
307
|
+
}
|
|
308
|
+
let disposed = false;
|
|
309
|
+
runWithOwner(owner, () => onCleanup(() => {
|
|
310
|
+
disposed = true;
|
|
311
|
+
}));
|
|
312
|
+
const ssrSource = options?.ssrSource;
|
|
313
|
+
const useProxy = ssrSource !== "hybrid";
|
|
314
|
+
const patches = [];
|
|
315
|
+
const draft = useProxy ? createDeepProxy(state, patches) : state;
|
|
316
|
+
const result = runWithOwner(owner, () => fn(draft));
|
|
317
|
+
const iteratorFn = result?.[Symbol.asyncIterator];
|
|
318
|
+
if (typeof iteratorFn === "function") {
|
|
319
|
+
const iter = iteratorFn.call(result);
|
|
320
|
+
if (ssrSource === "hybrid") {
|
|
321
|
+
const promise = iter.next().then(r => {
|
|
322
|
+
promise.s = 1;
|
|
323
|
+
if (disposed) {
|
|
324
|
+
promise.v = state;
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (r.value !== undefined && r.value !== state) {
|
|
328
|
+
Object.assign(state, r.value);
|
|
329
|
+
}
|
|
330
|
+
promise.v = state;
|
|
331
|
+
markReady();
|
|
332
|
+
}, () => {});
|
|
333
|
+
if (ctx?.async && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, promise, options?.deferStream);
|
|
334
|
+
const [pending, markReady] = createPendingProxy(state, promise);
|
|
335
|
+
return pending;
|
|
336
|
+
} else {
|
|
337
|
+
const firstNext = iter.next();
|
|
338
|
+
const firstReady = firstNext.then(r => {
|
|
339
|
+
if (disposed) return;
|
|
340
|
+
patches.length = 0;
|
|
341
|
+
if (!r.done) {
|
|
342
|
+
if (r.value !== undefined && r.value !== draft) {
|
|
343
|
+
Object.assign(state, r.value);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
markReady(JSON.parse(JSON.stringify(state)));
|
|
347
|
+
}, () => {
|
|
348
|
+
markReady();
|
|
349
|
+
});
|
|
350
|
+
let servedFirst = false;
|
|
351
|
+
const tapped = {
|
|
352
|
+
[Symbol.asyncIterator]: () => ({
|
|
353
|
+
next() {
|
|
354
|
+
if (!servedFirst) {
|
|
355
|
+
servedFirst = true;
|
|
356
|
+
return firstNext.then(r => {
|
|
357
|
+
if (!r.done && !disposed) return {
|
|
358
|
+
done: false,
|
|
359
|
+
value: state
|
|
360
|
+
};
|
|
361
|
+
return {
|
|
362
|
+
done: r.done,
|
|
363
|
+
value: undefined
|
|
364
|
+
};
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
return iter.next().then(r => {
|
|
368
|
+
if (disposed) return {
|
|
369
|
+
done: true,
|
|
370
|
+
value: undefined
|
|
371
|
+
};
|
|
372
|
+
const flushed = patches.splice(0);
|
|
373
|
+
if (!r.done) {
|
|
374
|
+
if (r.value !== undefined && r.value !== draft) {
|
|
375
|
+
Object.assign(state, r.value);
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
done: false,
|
|
379
|
+
value: flushed
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
done: true,
|
|
384
|
+
value: undefined
|
|
385
|
+
};
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
})
|
|
205
389
|
};
|
|
206
|
-
|
|
207
|
-
|
|
390
|
+
if (ctx?.async && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, tapped, options?.deferStream);
|
|
391
|
+
const [pending, markReady] = createPendingProxy(state, firstReady);
|
|
392
|
+
return pending;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (result instanceof Promise) {
|
|
396
|
+
const promise = result.then(v => {
|
|
397
|
+
promise.s = 1;
|
|
398
|
+
if (disposed) {
|
|
399
|
+
promise.v = state;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (v !== undefined && v !== state) {
|
|
403
|
+
Object.assign(state, v);
|
|
404
|
+
}
|
|
405
|
+
promise.v = state;
|
|
406
|
+
markReady();
|
|
407
|
+
}, () => {});
|
|
408
|
+
if (ctx?.async && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, promise, options?.deferStream);
|
|
409
|
+
const [pending, markReady] = createPendingProxy(state, promise);
|
|
410
|
+
return pending;
|
|
411
|
+
}
|
|
412
|
+
if (result !== undefined && result !== state && result !== draft) {
|
|
413
|
+
Object.assign(state, result);
|
|
414
|
+
}
|
|
415
|
+
return state;
|
|
416
|
+
}
|
|
417
|
+
function reconcile(value) {
|
|
418
|
+
return state => {
|
|
419
|
+
if (!isWrappable(state) || !isWrappable(value)) return value;
|
|
420
|
+
const targetKeys = Object.keys(value);
|
|
421
|
+
const previousKeys = Object.keys(state);
|
|
422
|
+
for (let i = 0, len = targetKeys.length; i < len; i++) {
|
|
423
|
+
const key = targetKeys[i];
|
|
424
|
+
setProperty(state, key, value[key]);
|
|
425
|
+
}
|
|
426
|
+
for (let i = 0, len = previousKeys.length; i < len; i++) {
|
|
427
|
+
if (value[previousKeys[i]] === undefined) setProperty(state, previousKeys[i], undefined);
|
|
428
|
+
}
|
|
429
|
+
return state;
|
|
208
430
|
};
|
|
209
431
|
}
|
|
210
|
-
function
|
|
211
|
-
return
|
|
212
|
-
id: 0,
|
|
213
|
-
fn: () => {},
|
|
214
|
-
startTime: 0,
|
|
215
|
-
expirationTime: 0
|
|
216
|
-
};
|
|
432
|
+
function deep(store) {
|
|
433
|
+
return store;
|
|
217
434
|
}
|
|
218
435
|
function mapArray(list, mapFn, options = {}) {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
let s = [];
|
|
229
|
-
if (items && items.length) {
|
|
230
|
-
for (let i = 0, len = items.length; i < len; i++) s.push(mapFn(() => items[i], i));
|
|
231
|
-
} else if (options.fallback) s = [options.fallback()];
|
|
232
|
-
return () => s;
|
|
233
|
-
}
|
|
234
|
-
function observable(input) {
|
|
235
|
-
return {
|
|
236
|
-
subscribe(observer) {
|
|
237
|
-
if (!(observer instanceof Object) || observer == null) {
|
|
238
|
-
throw new TypeError("Expected the observer to be an object.");
|
|
239
|
-
}
|
|
240
|
-
const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
|
|
241
|
-
if (!handler) {
|
|
242
|
-
return {
|
|
243
|
-
unsubscribe() {}
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
const dispose = createRoot(disposer => {
|
|
247
|
-
createEffect(() => {
|
|
248
|
-
const v = input();
|
|
249
|
-
untrack(() => handler(v));
|
|
436
|
+
const root = getOwner();
|
|
437
|
+
const id = getNextChildId(root);
|
|
438
|
+
return () => {
|
|
439
|
+
const items = list();
|
|
440
|
+
let s = [];
|
|
441
|
+
if (items && items.length) {
|
|
442
|
+
for (let i = 0, len = items.length; i < len; i++) {
|
|
443
|
+
const o = createOwner({
|
|
444
|
+
id: id + i
|
|
250
445
|
});
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
unsubscribe() {
|
|
256
|
-
dispose();
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
},
|
|
260
|
-
[Symbol.observable || "@@observable"]() {
|
|
261
|
-
return this;
|
|
262
|
-
}
|
|
446
|
+
s.push(runWithOwner(o, () => mapFn(() => items[i], () => i)));
|
|
447
|
+
}
|
|
448
|
+
} else if (options.fallback) s = [options.fallback()];
|
|
449
|
+
return s;
|
|
263
450
|
};
|
|
264
451
|
}
|
|
265
|
-
function
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
function enableExternalSource(factory) {}
|
|
277
|
-
function onError(fn) {
|
|
278
|
-
if (Owner) {
|
|
279
|
-
if (Owner.context === null || !Owner.context[ERROR]) {
|
|
280
|
-
Owner.context = {
|
|
281
|
-
...Owner.context,
|
|
282
|
-
[ERROR]: [fn]
|
|
283
|
-
};
|
|
284
|
-
mutateContext(Owner, ERROR, [fn]);
|
|
285
|
-
} else Owner.context[ERROR].push(fn);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
function mutateContext(o, key, value) {
|
|
289
|
-
if (o.owned) {
|
|
290
|
-
for (let i = 0; i < o.owned.length; i++) {
|
|
291
|
-
if (o.owned[i].context === o.context) mutateContext(o.owned[i], key, value);
|
|
292
|
-
if (!o.owned[i].context) {
|
|
293
|
-
o.owned[i].context = o.context;
|
|
294
|
-
mutateContext(o.owned[i], key, value);
|
|
295
|
-
} else if (!o.owned[i].context[key]) {
|
|
296
|
-
o.owned[i].context[key] = value;
|
|
297
|
-
mutateContext(o.owned[i], key, value);
|
|
452
|
+
function repeat(count, mapFn, options = {}) {
|
|
453
|
+
const owner = createOwner();
|
|
454
|
+
const len = count();
|
|
455
|
+
const offset = options.from?.() || 0;
|
|
456
|
+
let s = [];
|
|
457
|
+
if (len) {
|
|
458
|
+
runWithOwner(owner, () => {
|
|
459
|
+
for (let i = 0; i < len; i++) {
|
|
460
|
+
const itemOwner = createOwner();
|
|
461
|
+
s.push(runWithOwner(itemOwner, () => mapFn(i + offset)));
|
|
298
462
|
}
|
|
299
|
-
}
|
|
463
|
+
});
|
|
464
|
+
} else if (options.fallback) {
|
|
465
|
+
s = [runWithOwner(owner, () => {
|
|
466
|
+
const fo = createOwner();
|
|
467
|
+
return runWithOwner(fo, () => options.fallback());
|
|
468
|
+
})];
|
|
300
469
|
}
|
|
470
|
+
return () => s;
|
|
301
471
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
out += escDelim;
|
|
324
|
-
left = iDelim + 1;
|
|
325
|
-
iDelim = s.indexOf(delim, left);
|
|
326
|
-
} else {
|
|
327
|
-
if (left < iAmp) out += s.substring(left, iAmp);
|
|
328
|
-
out += "&";
|
|
329
|
-
left = iAmp + 1;
|
|
330
|
-
iAmp = s.indexOf("&", left);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
if (iDelim >= 0) {
|
|
334
|
-
do {
|
|
335
|
-
if (left < iDelim) out += s.substring(left, iDelim);
|
|
336
|
-
out += escDelim;
|
|
337
|
-
left = iDelim + 1;
|
|
338
|
-
iDelim = s.indexOf(delim, left);
|
|
339
|
-
} while (iDelim >= 0);
|
|
340
|
-
} else while (iAmp >= 0) {
|
|
341
|
-
if (left < iAmp) out += s.substring(left, iAmp);
|
|
342
|
-
out += "&";
|
|
343
|
-
left = iAmp + 1;
|
|
344
|
-
iAmp = s.indexOf("&", left);
|
|
345
|
-
}
|
|
346
|
-
return left < s.length ? out + s.substring(left) : out;
|
|
347
|
-
}
|
|
348
|
-
function resolveSSRNode(node) {
|
|
349
|
-
const t = typeof node;
|
|
350
|
-
if (t === "string") return node;
|
|
351
|
-
if (node == null || t === "boolean") return "";
|
|
352
|
-
if (Array.isArray(node)) {
|
|
353
|
-
let prev = {};
|
|
354
|
-
let mapped = "";
|
|
355
|
-
for (let i = 0, len = node.length; i < len; i++) {
|
|
356
|
-
if (typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`;
|
|
357
|
-
mapped += resolveSSRNode(prev = node[i]);
|
|
472
|
+
const ErrorContext = {
|
|
473
|
+
id: Symbol("ErrorContext"),
|
|
474
|
+
defaultValue: null
|
|
475
|
+
};
|
|
476
|
+
function createErrorBoundary(fn, fallback) {
|
|
477
|
+
const ctx = sharedConfig.context;
|
|
478
|
+
const owner = createOwner();
|
|
479
|
+
const parent = getOwner();
|
|
480
|
+
if (parent?.id != null) getNextChildId(parent);
|
|
481
|
+
owner.id = owner.id + "0";
|
|
482
|
+
return runWithOwner(owner, () => {
|
|
483
|
+
let result;
|
|
484
|
+
setContext(ErrorContext, err => {
|
|
485
|
+
if (ctx && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, err);
|
|
486
|
+
result = fallback(err, () => {});
|
|
487
|
+
});
|
|
488
|
+
try {
|
|
489
|
+
result = fn();
|
|
490
|
+
} catch (err) {
|
|
491
|
+
if (ctx && !ctx.noHydrate && owner.id) ctx.serialize(owner.id, err);
|
|
492
|
+
result = fallback(err, () => {});
|
|
358
493
|
}
|
|
359
|
-
return
|
|
360
|
-
}
|
|
361
|
-
if (t === "object") return node.t;
|
|
362
|
-
if (t === "function") return resolveSSRNode(node());
|
|
363
|
-
return String(node);
|
|
494
|
+
return () => result;
|
|
495
|
+
});
|
|
364
496
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
497
|
+
function createLoadBoundary(fn, fallback) {
|
|
498
|
+
try {
|
|
499
|
+
const result = fn();
|
|
500
|
+
return () => result;
|
|
501
|
+
} catch (err) {
|
|
502
|
+
if (err instanceof NotReadyError) {
|
|
503
|
+
return () => fallback();
|
|
504
|
+
}
|
|
505
|
+
throw err;
|
|
374
506
|
}
|
|
375
|
-
};
|
|
376
|
-
function getContextId(count) {
|
|
377
|
-
const num = String(count),
|
|
378
|
-
len = num.length - 1;
|
|
379
|
-
return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
|
|
380
507
|
}
|
|
381
|
-
function
|
|
382
|
-
|
|
508
|
+
function untrack(fn) {
|
|
509
|
+
return fn();
|
|
383
510
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
id: sharedConfig.getNextContextId(),
|
|
388
|
-
count: 0
|
|
389
|
-
} : undefined;
|
|
511
|
+
function flush() {}
|
|
512
|
+
function resolve(fn) {
|
|
513
|
+
throw new Error("resolve is not implemented on the server");
|
|
390
514
|
}
|
|
391
|
-
function
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const r = Comp(props || {});
|
|
399
|
-
setHydrateContext(c);
|
|
400
|
-
return r;
|
|
401
|
-
}
|
|
402
|
-
return Comp(props || {});
|
|
403
|
-
}
|
|
404
|
-
function mergeProps(...sources) {
|
|
405
|
-
const target = {};
|
|
406
|
-
for (let i = 0; i < sources.length; i++) {
|
|
407
|
-
let source = sources[i];
|
|
408
|
-
if (typeof source === "function") source = source();
|
|
409
|
-
if (source) {
|
|
410
|
-
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
411
|
-
for (const key in descriptors) {
|
|
412
|
-
if (key in target) continue;
|
|
413
|
-
Object.defineProperty(target, key, {
|
|
414
|
-
enumerable: true,
|
|
415
|
-
get() {
|
|
416
|
-
for (let i = sources.length - 1; i >= 0; i--) {
|
|
417
|
-
let v,
|
|
418
|
-
s = sources[i];
|
|
419
|
-
if (typeof s === "function") s = s();
|
|
420
|
-
v = (s || {})[key];
|
|
421
|
-
if (v !== undefined) return v;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
}
|
|
515
|
+
function isPending(fn, fallback) {
|
|
516
|
+
try {
|
|
517
|
+
fn();
|
|
518
|
+
return false;
|
|
519
|
+
} catch (err) {
|
|
520
|
+
if (err instanceof NotReadyError && arguments.length > 1) {
|
|
521
|
+
return fallback;
|
|
426
522
|
}
|
|
523
|
+
throw err;
|
|
427
524
|
}
|
|
428
|
-
return target;
|
|
429
|
-
}
|
|
430
|
-
function splitProps(props, ...keys) {
|
|
431
|
-
const descriptors = Object.getOwnPropertyDescriptors(props),
|
|
432
|
-
split = k => {
|
|
433
|
-
const clone = {};
|
|
434
|
-
for (let i = 0; i < k.length; i++) {
|
|
435
|
-
const key = k[i];
|
|
436
|
-
if (descriptors[key]) {
|
|
437
|
-
Object.defineProperty(clone, key, descriptors[key]);
|
|
438
|
-
delete descriptors[key];
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
return clone;
|
|
442
|
-
};
|
|
443
|
-
return keys.map(split).concat(split(Object.keys(descriptors)));
|
|
444
|
-
}
|
|
445
|
-
function simpleMap(props, wrap) {
|
|
446
|
-
const list = props.each || [],
|
|
447
|
-
len = list.length,
|
|
448
|
-
fn = props.children;
|
|
449
|
-
if (len) {
|
|
450
|
-
let mapped = Array(len);
|
|
451
|
-
for (let i = 0; i < len; i++) mapped[i] = wrap(fn, list[i], i);
|
|
452
|
-
return mapped;
|
|
453
|
-
}
|
|
454
|
-
return props.fallback;
|
|
455
525
|
}
|
|
456
|
-
function
|
|
457
|
-
return
|
|
526
|
+
function latest(fn) {
|
|
527
|
+
return fn();
|
|
458
528
|
}
|
|
459
|
-
function
|
|
460
|
-
return
|
|
529
|
+
function isRefreshing() {
|
|
530
|
+
return false;
|
|
461
531
|
}
|
|
462
|
-
function
|
|
463
|
-
|
|
464
|
-
return props.when ? typeof (c = props.children) === "function" ? c(props.keyed ? props.when : () => props.when) : c : props.fallback || "";
|
|
532
|
+
function refresh(fn) {
|
|
533
|
+
return fn();
|
|
465
534
|
}
|
|
466
|
-
function
|
|
467
|
-
|
|
468
|
-
Array.isArray(conditions) || (conditions = [conditions]);
|
|
469
|
-
for (let i = 0; i < conditions.length; i++) {
|
|
470
|
-
const w = conditions[i].when;
|
|
471
|
-
if (w) {
|
|
472
|
-
const c = conditions[i].children;
|
|
473
|
-
return typeof c === "function" ? c(conditions[i].keyed ? w : () => w) : c;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
return props.fallback || "";
|
|
535
|
+
function action(fn) {
|
|
536
|
+
return fn;
|
|
477
537
|
}
|
|
478
|
-
function
|
|
479
|
-
|
|
538
|
+
function onSettled(callback) {
|
|
539
|
+
const o = getOwner();
|
|
540
|
+
if (o?.id != null) getNextChildId(o);
|
|
480
541
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
function displayFallback() {
|
|
490
|
-
cleanNode(clean);
|
|
491
|
-
ctx.serialize(id, error);
|
|
492
|
-
setHydrateContext({
|
|
493
|
-
...ctx,
|
|
494
|
-
count: 0
|
|
542
|
+
|
|
543
|
+
const $DEVCOMP = Symbol("solid-dev-component");
|
|
544
|
+
function createContext(defaultValue, options) {
|
|
545
|
+
const id = Symbol(options && options.name || "");
|
|
546
|
+
function provider(props) {
|
|
547
|
+
return createRoot(() => {
|
|
548
|
+
setContext(provider, props.value);
|
|
549
|
+
return children(() => props.children);
|
|
495
550
|
});
|
|
496
|
-
const f = props.fallback;
|
|
497
|
-
return typeof f === "function" && f.length ? f(error, () => {}) : f;
|
|
498
551
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
552
|
+
provider.id = id;
|
|
553
|
+
provider.defaultValue = defaultValue;
|
|
554
|
+
return provider;
|
|
555
|
+
}
|
|
556
|
+
function useContext(context) {
|
|
557
|
+
return getContext(context);
|
|
558
|
+
}
|
|
559
|
+
function children(fn) {
|
|
560
|
+
const c = createMemo(fn, undefined, {
|
|
561
|
+
lazy: true
|
|
506
562
|
});
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
563
|
+
const memo = createMemo(() => flatten(c()), undefined, {
|
|
564
|
+
lazy: true
|
|
565
|
+
});
|
|
566
|
+
memo.toArray = () => {
|
|
567
|
+
const v = memo();
|
|
568
|
+
return Array.isArray(v) ? v : v != null ? [v] : [];
|
|
511
569
|
};
|
|
570
|
+
return memo;
|
|
512
571
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
const contexts = new Set();
|
|
522
|
-
const id = sharedConfig.getNextContextId();
|
|
523
|
-
let resource = {};
|
|
524
|
-
let value = options.storage ? options.storage(options.initialValue)[0]() : options.initialValue;
|
|
525
|
-
let p;
|
|
526
|
-
let error;
|
|
527
|
-
if (sharedConfig.context.async && options.ssrLoadFrom !== "initial") {
|
|
528
|
-
resource = sharedConfig.context.resources[id] || (sharedConfig.context.resources[id] = {});
|
|
529
|
-
if (resource.ref) {
|
|
530
|
-
if (!resource.data && !resource.ref[0]._loading && !resource.ref[0].error) resource.ref[1].refetch();
|
|
531
|
-
return resource.ref;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
const prepareResource = () => {
|
|
535
|
-
if (error) throw error;
|
|
536
|
-
const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id];
|
|
537
|
-
if (!resolved && resourceContext) resourceContext.push(id);
|
|
538
|
-
if (!resolved && read._loading) {
|
|
539
|
-
const ctx = useContext(SuspenseContext);
|
|
540
|
-
if (ctx) {
|
|
541
|
-
ctx.resources.set(id, read);
|
|
542
|
-
contexts.add(ctx);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
return resolved;
|
|
546
|
-
};
|
|
547
|
-
const read = () => {
|
|
548
|
-
return prepareResource() ? sharedConfig.context.resources[id].data : value;
|
|
549
|
-
};
|
|
550
|
-
const loading = () => {
|
|
551
|
-
prepareResource();
|
|
552
|
-
return read._loading;
|
|
553
|
-
};
|
|
554
|
-
read._loading = false;
|
|
555
|
-
read.error = undefined;
|
|
556
|
-
read.state = "initialValue" in options ? "ready" : "unresolved";
|
|
557
|
-
Object.defineProperties(read, {
|
|
558
|
-
latest: {
|
|
559
|
-
get() {
|
|
560
|
-
return read();
|
|
561
|
-
}
|
|
562
|
-
},
|
|
563
|
-
loading: {
|
|
564
|
-
get() {
|
|
565
|
-
return loading();
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
function load() {
|
|
570
|
-
const ctx = sharedConfig.context;
|
|
571
|
-
if (!ctx.async) return read._loading = !!(typeof source === "function" ? source() : source);
|
|
572
|
-
if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) {
|
|
573
|
-
value = ctx.resources[id].data;
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
let lookup;
|
|
577
|
-
try {
|
|
578
|
-
resourceContext = [];
|
|
579
|
-
lookup = typeof source === "function" ? source() : source;
|
|
580
|
-
if (resourceContext.length) return;
|
|
581
|
-
} finally {
|
|
582
|
-
resourceContext = null;
|
|
583
|
-
}
|
|
584
|
-
if (!p) {
|
|
585
|
-
if (lookup == null || lookup === false) return;
|
|
586
|
-
p = fetcher(lookup, {
|
|
587
|
-
value
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
if (p != undefined && typeof p === "object" && "then" in p) {
|
|
591
|
-
read._loading = true;
|
|
592
|
-
read.state = "pending";
|
|
593
|
-
p = p.then(res => {
|
|
594
|
-
read._loading = false;
|
|
595
|
-
read.state = "ready";
|
|
596
|
-
ctx.resources[id].data = res;
|
|
597
|
-
p = null;
|
|
598
|
-
notifySuspense(contexts);
|
|
599
|
-
return res;
|
|
600
|
-
}).catch(err => {
|
|
601
|
-
read._loading = false;
|
|
602
|
-
read.state = "errored";
|
|
603
|
-
read.error = error = castError(err);
|
|
604
|
-
p = null;
|
|
605
|
-
notifySuspense(contexts);
|
|
606
|
-
throw error;
|
|
607
|
-
});
|
|
608
|
-
if (ctx.serialize) ctx.serialize(id, p, options.deferStream);
|
|
609
|
-
return p;
|
|
610
|
-
}
|
|
611
|
-
ctx.resources[id].data = p;
|
|
612
|
-
if (ctx.serialize) ctx.serialize(id, p);
|
|
613
|
-
p = null;
|
|
614
|
-
return ctx.resources[id].data;
|
|
615
|
-
}
|
|
616
|
-
if (options.ssrLoadFrom !== "initial") load();
|
|
617
|
-
const ref = [read, {
|
|
618
|
-
refetch: load,
|
|
619
|
-
mutate: v => value = v
|
|
620
|
-
}];
|
|
621
|
-
if (p) resource.ref = ref;
|
|
622
|
-
return ref;
|
|
572
|
+
function ssrRunInScope(fn) {
|
|
573
|
+
return fn;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function enableHydration() {}
|
|
577
|
+
function createComponent(Comp, props) {
|
|
578
|
+
return Comp(props || {});
|
|
623
579
|
}
|
|
624
|
-
function lazy(fn) {
|
|
580
|
+
function lazy(fn, moduleUrl) {
|
|
625
581
|
let p;
|
|
626
|
-
let load =
|
|
582
|
+
let load = () => {
|
|
627
583
|
if (!p) {
|
|
628
584
|
p = fn();
|
|
629
|
-
p.then(mod =>
|
|
630
|
-
|
|
585
|
+
p.then(mod => {
|
|
586
|
+
p.v = mod.default;
|
|
587
|
+
});
|
|
631
588
|
}
|
|
632
589
|
return p;
|
|
633
590
|
};
|
|
634
|
-
const contexts = new Set();
|
|
635
591
|
const wrap = props => {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
if (
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
592
|
+
if (!moduleUrl) {
|
|
593
|
+
throw new Error("lazy() used in SSR without a moduleUrl. " + "All lazy() components require a moduleUrl for correct hydration. " + "This is typically injected by the bundler plugin.");
|
|
594
|
+
}
|
|
595
|
+
if (!sharedConfig.context?.resolveAssets) {
|
|
596
|
+
throw new Error(`lazy() called with moduleUrl "${moduleUrl}" but no asset manifest is set. ` + "Pass a manifest option to renderToStream/renderToString.");
|
|
597
|
+
}
|
|
598
|
+
load();
|
|
599
|
+
const ctx = sharedConfig.context;
|
|
600
|
+
if (!ctx?.registerAsset || !ctx.resolveAssets) return;
|
|
601
|
+
const assets = ctx.resolveAssets(moduleUrl);
|
|
602
|
+
if (assets) {
|
|
603
|
+
for (let i = 0; i < assets.css.length; i++) ctx.registerAsset("style", assets.css[i]);
|
|
604
|
+
for (let i = 0; i < assets.js.length; i++) ctx.registerAsset("module", assets.js[i]);
|
|
605
|
+
ctx.registerModule?.(moduleUrl, assets.js[0]);
|
|
648
606
|
}
|
|
649
|
-
if (
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
notifySuspense(contexts);
|
|
607
|
+
if (ctx?.async) {
|
|
608
|
+
ctx.block(p.then(() => {
|
|
609
|
+
p.s = "success";
|
|
653
610
|
}));
|
|
654
611
|
}
|
|
655
|
-
return
|
|
612
|
+
return createMemo(() => {
|
|
613
|
+
if (!p.v) throw new NotReadyError(p);
|
|
614
|
+
return p.v(props);
|
|
615
|
+
});
|
|
656
616
|
};
|
|
657
617
|
wrap.preload = load;
|
|
658
618
|
return wrap;
|
|
659
619
|
}
|
|
660
|
-
function
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
620
|
+
function createUniqueId() {
|
|
621
|
+
return sharedConfig.getNextContextId();
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function For(props) {
|
|
625
|
+
const options = "fallback" in props ? {
|
|
626
|
+
keyed: props.keyed,
|
|
627
|
+
fallback: () => props.fallback
|
|
628
|
+
} : {
|
|
629
|
+
keyed: props.keyed
|
|
630
|
+
};
|
|
631
|
+
return createMemo(mapArray(() => props.each, props.children, options));
|
|
665
632
|
}
|
|
666
|
-
function
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
633
|
+
function Repeat(props) {
|
|
634
|
+
const options = "fallback" in props ? {
|
|
635
|
+
fallback: () => props.fallback
|
|
636
|
+
} : {};
|
|
637
|
+
options.from = () => props.from;
|
|
638
|
+
return repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options);
|
|
639
|
+
}
|
|
640
|
+
function Show(props) {
|
|
641
|
+
const o = getOwner();
|
|
642
|
+
if (o?.id != null) {
|
|
643
|
+
getNextChildId(o);
|
|
644
|
+
if (!props.keyed) getNextChildId(o);
|
|
645
|
+
}
|
|
646
|
+
return createMemo(() => {
|
|
647
|
+
const when = props.when;
|
|
648
|
+
if (when) {
|
|
649
|
+
const child = props.children;
|
|
650
|
+
if (typeof child === "function" && child.length > 0) {
|
|
651
|
+
return child(() => when);
|
|
652
|
+
}
|
|
653
|
+
return child;
|
|
670
654
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
}
|
|
655
|
+
return props.fallback;
|
|
656
|
+
});
|
|
674
657
|
}
|
|
675
|
-
function
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
658
|
+
function Switch(props) {
|
|
659
|
+
const chs = children(() => props.children);
|
|
660
|
+
const o = getOwner();
|
|
661
|
+
if (o?.id != null) getNextChildId(o);
|
|
662
|
+
return createMemo(() => {
|
|
663
|
+
let conds = chs();
|
|
664
|
+
if (!Array.isArray(conds)) conds = [conds];
|
|
665
|
+
for (let i = 0; i < conds.length; i++) {
|
|
666
|
+
const w = conds[i].when;
|
|
667
|
+
if (w) {
|
|
668
|
+
const c = conds[i].children;
|
|
669
|
+
return typeof c === "function" && c.length > 0 ? c(() => w) : c;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return props.fallback;
|
|
673
|
+
});
|
|
679
674
|
}
|
|
680
|
-
function
|
|
681
|
-
return
|
|
682
|
-
fn();
|
|
683
|
-
}];
|
|
675
|
+
function Match(props) {
|
|
676
|
+
return props;
|
|
684
677
|
}
|
|
685
|
-
function
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
678
|
+
function Errored(props) {
|
|
679
|
+
return createErrorBoundary(() => props.children, (err, reset) => {
|
|
680
|
+
const f = props.fallback;
|
|
681
|
+
return typeof f === "function" && f.length ? f(err, reset) : f;
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function ssrHandleError(err) {
|
|
686
|
+
if (err instanceof NotReadyError) {
|
|
687
|
+
return err.source;
|
|
692
688
|
}
|
|
693
|
-
|
|
689
|
+
const handler = getContext(ErrorContext);
|
|
690
|
+
if (handler) {
|
|
691
|
+
handler(err);
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
throw err;
|
|
694
695
|
}
|
|
695
|
-
function
|
|
696
|
-
let done;
|
|
696
|
+
function Loading(props) {
|
|
697
697
|
const ctx = sharedConfig.context;
|
|
698
|
-
|
|
698
|
+
if (!ctx) {
|
|
699
|
+
return createLoadBoundary(() => props.children, () => props.fallback);
|
|
700
|
+
}
|
|
699
701
|
const o = createOwner();
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
702
|
+
const id = o.id;
|
|
703
|
+
o.id = id + "00";
|
|
704
|
+
let runPromise;
|
|
705
|
+
let serializeBuffer = [];
|
|
706
|
+
const origSerialize = ctx.serialize;
|
|
707
|
+
function runInitially() {
|
|
708
|
+
o.dispose(false);
|
|
709
|
+
serializeBuffer = [];
|
|
710
|
+
ctx.serialize = (id, p, deferStream) => {
|
|
711
|
+
serializeBuffer.push([id, p, deferStream]);
|
|
712
|
+
};
|
|
713
|
+
const prevBoundary = ctx._currentBoundaryId;
|
|
714
|
+
ctx._currentBoundaryId = id;
|
|
715
|
+
const result = runWithOwner(o, () => {
|
|
716
|
+
try {
|
|
717
|
+
return ctx.resolve(props.children);
|
|
718
|
+
} catch (err) {
|
|
719
|
+
runPromise = ssrHandleError(err);
|
|
706
720
|
}
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
function suspenseError(err) {
|
|
710
|
-
if (!done || !done(undefined, err)) {
|
|
711
|
-
runWithOwner(o.owner, () => {
|
|
712
|
-
throw err;
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
function runSuspense() {
|
|
717
|
-
setHydrateContext({
|
|
718
|
-
...ctx,
|
|
719
|
-
count: 0
|
|
720
721
|
});
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
get children() {
|
|
725
|
-
return catchError(() => props.children, suspenseError);
|
|
726
|
-
}
|
|
727
|
-
}));
|
|
722
|
+
ctx._currentBoundaryId = prevBoundary;
|
|
723
|
+
ctx.serialize = origSerialize;
|
|
724
|
+
return result;
|
|
728
725
|
}
|
|
729
|
-
|
|
730
|
-
if (
|
|
731
|
-
|
|
732
|
-
|
|
726
|
+
let ret = runInitially();
|
|
727
|
+
if (!(runPromise || ret?.p?.length)) {
|
|
728
|
+
for (const args of serializeBuffer) origSerialize(args[0], args[1], args[2]);
|
|
729
|
+
serializeBuffer = [];
|
|
730
|
+
const modules = ctx.getBoundaryModules?.(id);
|
|
731
|
+
if (modules) ctx.serialize(id + "_assets", modules);
|
|
732
|
+
return ret;
|
|
733
733
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
734
|
+
const fallbackOwner = createOwner({
|
|
735
|
+
id
|
|
736
|
+
});
|
|
737
|
+
getNextChildId(fallbackOwner);
|
|
738
|
+
if (ctx.async) {
|
|
739
|
+
const done = ctx.registerFragment(id);
|
|
740
|
+
(async () => {
|
|
741
|
+
try {
|
|
742
|
+
while (runPromise) {
|
|
743
|
+
o.dispose(false);
|
|
744
|
+
await runPromise;
|
|
745
|
+
runPromise = undefined;
|
|
746
|
+
ret = runInitially();
|
|
747
|
+
}
|
|
748
|
+
for (const args of serializeBuffer) origSerialize(args[0], args[1], args[2]);
|
|
749
|
+
serializeBuffer = [];
|
|
750
|
+
while (ret.p.length) {
|
|
751
|
+
await Promise.all(ret.p);
|
|
752
|
+
ret = runWithOwner(o, () => ctx.ssr(ret.t, ...ret.h));
|
|
753
|
+
}
|
|
754
|
+
done(ret.t[0]);
|
|
755
|
+
} catch (err) {
|
|
756
|
+
done(undefined, err);
|
|
757
|
+
}
|
|
758
|
+
})();
|
|
759
|
+
return runWithOwner(fallbackOwner, () => ctx.ssr([`<template id="pl-${id}"></template>`, `<!--pl-${id}-->`], ctx.escape(props.fallback)));
|
|
760
|
+
}
|
|
761
|
+
for (const args of serializeBuffer) origSerialize(args[0], args[1], args[2]);
|
|
762
|
+
serializeBuffer = [];
|
|
763
|
+
const modules = ctx.getBoundaryModules?.(id);
|
|
764
|
+
if (modules) ctx.serialize(id + "_assets", modules);
|
|
765
|
+
ctx.serialize(id, "$$f");
|
|
766
|
+
return runWithOwner(fallbackOwner, () => props.fallback);
|
|
757
767
|
}
|
|
758
768
|
|
|
759
|
-
|
|
769
|
+
const DEV = undefined;
|
|
770
|
+
|
|
771
|
+
export { $DEVCOMP, DEV, Errored, For, Loading, Match, Repeat, Show, Switch, action, children, createComponent, createContext, createDeepProxy, createEffect, createMemo, createOptimistic, createOptimisticStore, createProjection, createReaction, createRenderEffect, createSignal, createStore, createTrackedEffect, createUniqueId, deep, enableHydration, flush, getObserver, isPending, isRefreshing, latest, lazy, mapArray, onSettled, reconcile, refresh, repeat, resolve, sharedConfig, ssrHandleError, ssrRunInScope, untrack, useContext };
|