solid-js 1.9.3 → 2.0.0-experimental.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.
Files changed (76) hide show
  1. package/dist/dev.cjs +213 -1603
  2. package/dist/dev.js +159 -1749
  3. package/dist/server.cjs +88 -11
  4. package/dist/server.js +91 -11
  5. package/dist/solid.cjs +196 -1558
  6. package/dist/solid.js +139 -1682
  7. package/package.json +8 -154
  8. package/types/{render → client}/component.d.ts +0 -61
  9. package/types/client/core.d.ts +75 -0
  10. package/types/client/flow.d.ts +114 -0
  11. package/types/{render → client}/hydration.d.ts +0 -2
  12. package/types/{reactive → client}/observable.d.ts +1 -1
  13. package/types/index.d.ts +44 -55
  14. package/types/jsx.d.ts +1944 -174
  15. package/types/server/index.d.ts +1 -1
  16. package/types/server/reactive.d.ts +6 -1
  17. package/types/server/store.d.ts +6 -0
  18. package/h/dist/h.cjs +0 -115
  19. package/h/dist/h.js +0 -144
  20. package/h/jsx-dev-runtime/package.json +0 -8
  21. package/h/jsx-runtime/dist/jsx.cjs +0 -15
  22. package/h/jsx-runtime/dist/jsx.js +0 -10
  23. package/h/jsx-runtime/package.json +0 -8
  24. package/h/jsx-runtime/types/index.d.ts +0 -14
  25. package/h/jsx-runtime/types/jsx.d.ts +0 -2276
  26. package/h/package.json +0 -8
  27. package/h/types/hyperscript.d.ts +0 -20
  28. package/h/types/index.d.ts +0 -3
  29. package/html/dist/html.cjs +0 -583
  30. package/html/dist/html.js +0 -706
  31. package/html/package.json +0 -8
  32. package/html/types/index.d.ts +0 -3
  33. package/html/types/lit.d.ts +0 -60
  34. package/store/dist/dev.cjs +0 -454
  35. package/store/dist/dev.js +0 -525
  36. package/store/dist/server.cjs +0 -126
  37. package/store/dist/server.js +0 -126
  38. package/store/dist/store.cjs +0 -434
  39. package/store/dist/store.js +0 -499
  40. package/store/package.json +0 -46
  41. package/store/types/index.d.ts +0 -26
  42. package/store/types/modifiers.d.ts +0 -9
  43. package/store/types/mutable.d.ts +0 -8
  44. package/store/types/server.d.ts +0 -37
  45. package/store/types/store.d.ts +0 -263
  46. package/types/reactive/array.d.ts +0 -52
  47. package/types/reactive/scheduler.d.ts +0 -13
  48. package/types/reactive/signal.d.ts +0 -664
  49. package/types/render/Suspense.d.ts +0 -26
  50. package/types/render/flow.d.ts +0 -130
  51. package/types/render/index.d.ts +0 -4
  52. package/universal/dist/dev.cjs +0 -243
  53. package/universal/dist/dev.js +0 -257
  54. package/universal/dist/universal.cjs +0 -243
  55. package/universal/dist/universal.js +0 -257
  56. package/universal/package.json +0 -20
  57. package/universal/types/index.d.ts +0 -4
  58. package/universal/types/universal.d.ts +0 -29
  59. package/web/dist/dev.cjs +0 -804
  60. package/web/dist/dev.js +0 -1241
  61. package/web/dist/server.cjs +0 -793
  62. package/web/dist/server.js +0 -1214
  63. package/web/dist/web.cjs +0 -793
  64. package/web/dist/web.js +0 -1220
  65. package/web/package.json +0 -46
  66. package/web/storage/dist/storage.cjs +0 -12
  67. package/web/storage/dist/storage.js +0 -10
  68. package/web/storage/package.json +0 -15
  69. package/web/storage/types/index.d.ts +0 -2
  70. package/web/storage/types/index.js +0 -13
  71. package/web/types/client.d.ts +0 -79
  72. package/web/types/core.d.ts +0 -10
  73. package/web/types/index.d.ts +0 -54
  74. package/web/types/jsx.d.ts +0 -1
  75. package/web/types/server-mock.d.ts +0 -80
  76. package/web/types/server.d.ts +0 -177
package/dist/dev.js CHANGED
@@ -1,675 +1,79 @@
1
- let taskIdCounter = 1,
2
- isCallbackScheduled = false,
3
- isPerformingWork = false,
4
- taskQueue = [],
5
- currentTask = null,
6
- shouldYieldToHost = null,
7
- yieldInterval = 5,
8
- deadline = 0,
9
- maxYieldInterval = 300,
10
- scheduleCallback = null,
11
- scheduledCallback = null;
12
- const maxSigned31BitInt = 1073741823;
13
- function setupScheduler() {
14
- const channel = new MessageChannel(),
15
- port = channel.port2;
16
- scheduleCallback = () => port.postMessage(null);
17
- channel.port1.onmessage = () => {
18
- if (scheduledCallback !== null) {
19
- const currentTime = performance.now();
20
- deadline = currentTime + yieldInterval;
21
- const hasTimeRemaining = true;
22
- try {
23
- const hasMoreWork = scheduledCallback(hasTimeRemaining, currentTime);
24
- if (!hasMoreWork) {
25
- scheduledCallback = null;
26
- } else port.postMessage(null);
27
- } catch (error) {
28
- port.postMessage(null);
29
- throw error;
30
- }
31
- }
32
- };
33
- if (navigator && navigator.scheduling && navigator.scheduling.isInputPending) {
34
- const scheduling = navigator.scheduling;
35
- shouldYieldToHost = () => {
36
- const currentTime = performance.now();
37
- if (currentTime >= deadline) {
38
- if (scheduling.isInputPending()) {
39
- return true;
40
- }
41
- return currentTime >= maxYieldInterval;
42
- } else {
43
- return false;
44
- }
45
- };
46
- } else {
47
- shouldYieldToHost = () => performance.now() >= deadline;
48
- }
49
- }
50
- function enqueue(taskQueue, task) {
51
- function findIndex() {
52
- let m = 0;
53
- let n = taskQueue.length - 1;
54
- while (m <= n) {
55
- const k = (n + m) >> 1;
56
- const cmp = task.expirationTime - taskQueue[k].expirationTime;
57
- if (cmp > 0) m = k + 1;
58
- else if (cmp < 0) n = k - 1;
59
- else return k;
60
- }
61
- return m;
62
- }
63
- taskQueue.splice(findIndex(), 0, task);
64
- }
65
- function requestCallback(fn, options) {
66
- if (!scheduleCallback) setupScheduler();
67
- let startTime = performance.now(),
68
- timeout = maxSigned31BitInt;
69
- if (options && options.timeout) timeout = options.timeout;
70
- const newTask = {
71
- id: taskIdCounter++,
72
- fn,
73
- startTime,
74
- expirationTime: startTime + timeout
75
- };
76
- enqueue(taskQueue, newTask);
77
- if (!isCallbackScheduled && !isPerformingWork) {
78
- isCallbackScheduled = true;
79
- scheduledCallback = flushWork;
80
- scheduleCallback();
81
- }
82
- return newTask;
83
- }
84
- function cancelCallback(task) {
85
- task.fn = null;
86
- }
87
- function flushWork(hasTimeRemaining, initialTime) {
88
- isCallbackScheduled = false;
89
- isPerformingWork = true;
90
- try {
91
- return workLoop(hasTimeRemaining, initialTime);
92
- } finally {
93
- currentTask = null;
94
- isPerformingWork = false;
95
- }
96
- }
97
- function workLoop(hasTimeRemaining, initialTime) {
98
- let currentTime = initialTime;
99
- currentTask = taskQueue[0] || null;
100
- while (currentTask !== null) {
101
- if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) {
102
- break;
103
- }
104
- const callback = currentTask.fn;
105
- if (callback !== null) {
106
- currentTask.fn = null;
107
- const didUserCallbackTimeout = currentTask.expirationTime <= currentTime;
108
- callback(didUserCallbackTimeout);
109
- currentTime = performance.now();
110
- if (currentTask === taskQueue[0]) {
111
- taskQueue.shift();
112
- }
113
- } else taskQueue.shift();
114
- currentTask = taskQueue[0] || null;
115
- }
116
- return currentTask !== null;
117
- }
118
-
119
- const sharedConfig = {
120
- context: undefined,
121
- registry: undefined,
122
- effects: undefined,
123
- done: false,
124
- getContextId() {
125
- return getContextId(this.context.count);
126
- },
127
- getNextContextId() {
128
- return getContextId(this.context.count++);
129
- }
130
- };
131
- function getContextId(count) {
132
- const num = String(count),
133
- len = num.length - 1;
134
- return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
135
- }
136
- function setHydrateContext(context) {
137
- sharedConfig.context = context;
138
- }
139
- function nextHydrateContext() {
140
- return {
141
- ...sharedConfig.context,
142
- id: sharedConfig.getNextContextId(),
143
- count: 0
144
- };
145
- }
1
+ import {
2
+ createEffect,
3
+ getContext,
4
+ createMemo,
5
+ flatten,
6
+ setContext,
7
+ untrack,
8
+ createRoot,
9
+ getOwner,
10
+ onCleanup,
11
+ createSignal,
12
+ createAsync,
13
+ mapArray,
14
+ repeat,
15
+ createErrorBoundary,
16
+ createSuspense
17
+ } from "@solidjs/signals";
18
+ export {
19
+ $PROXY,
20
+ $RAW,
21
+ $TRACK,
22
+ catchError,
23
+ createAsync,
24
+ createEffect,
25
+ createMemo,
26
+ createProjection,
27
+ createReaction,
28
+ createRenderEffect,
29
+ createRoot,
30
+ createSignal,
31
+ createStore,
32
+ flatten,
33
+ flushSync,
34
+ getObserver,
35
+ getOwner,
36
+ isEqual,
37
+ isStale,
38
+ isWrappable,
39
+ latest,
40
+ mapArray,
41
+ merge,
42
+ omit,
43
+ onCleanup,
44
+ reconcile,
45
+ repeat,
46
+ resolve,
47
+ runWithOwner,
48
+ untrack,
49
+ unwrap
50
+ } from "@solidjs/signals";
146
51
 
147
- const equalFn = (a, b) => a === b;
148
- const $PROXY = Symbol("solid-proxy");
149
- const SUPPORTS_PROXY = typeof Proxy === "function";
150
- const $TRACK = Symbol("solid-track");
151
- const $DEVCOMP = Symbol("solid-dev-component");
152
- const signalOptions = {
153
- equals: equalFn
154
- };
155
- let ERROR = null;
156
- let runEffects = runQueue;
157
- const STALE = 1;
158
- const PENDING = 2;
159
- const UNOWNED = {
160
- owned: null,
161
- cleanups: null,
162
- context: null,
163
- owner: null
164
- };
165
- const NO_INIT = {};
166
- var Owner = null;
167
- let Transition = null;
168
- let Scheduler = null;
169
- let ExternalSourceConfig = null;
170
- let Listener = null;
171
- let Updates = null;
172
- let Effects = null;
173
- let ExecCount = 0;
174
- const DevHooks = {
175
- afterUpdate: null,
176
- afterCreateOwner: null,
177
- afterCreateSignal: null
178
- };
179
- function createRoot(fn, detachedOwner) {
180
- const listener = Listener,
181
- owner = Owner,
182
- unowned = fn.length === 0,
183
- current = detachedOwner === undefined ? owner : detachedOwner,
184
- root = unowned
185
- ? {
186
- owned: null,
187
- cleanups: null,
188
- context: null,
189
- owner: null
190
- }
191
- : {
192
- owned: null,
193
- cleanups: null,
194
- context: current ? current.context : null,
195
- owner: current
196
- },
197
- updateFn = unowned
198
- ? () =>
199
- fn(() => {
200
- throw new Error("Dispose method must be an explicit argument to createRoot function");
201
- })
202
- : () => fn(() => untrack(() => cleanNode(root)));
203
- DevHooks.afterCreateOwner && DevHooks.afterCreateOwner(root);
204
- Owner = root;
205
- Listener = null;
206
- try {
207
- return runUpdates(updateFn, true);
208
- } finally {
209
- Listener = listener;
210
- Owner = owner;
211
- }
212
- }
213
- function createSignal(value, options) {
214
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
215
- const s = {
216
- value,
217
- observers: null,
218
- observerSlots: null,
219
- comparator: options.equals || undefined
220
- };
221
- {
222
- if (options.name) s.name = options.name;
223
- if (DevHooks.afterCreateSignal) DevHooks.afterCreateSignal(s);
224
- if (!options.internal) registerGraph(s);
225
- }
226
- const setter = value => {
227
- if (typeof value === "function") {
228
- if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue);
229
- else value = value(s.value);
230
- }
231
- return writeSignal(s, value);
232
- };
233
- return [readSignal.bind(s), setter];
234
- }
235
- function createComputed(fn, value, options) {
236
- const c = createComputation(fn, value, true, STALE, options);
237
- if (Scheduler && Transition && Transition.running) Updates.push(c);
238
- else updateComputation(c);
239
- }
240
- function createRenderEffect(fn, value, options) {
241
- const c = createComputation(fn, value, false, STALE, options);
242
- if (Scheduler && Transition && Transition.running) Updates.push(c);
243
- else updateComputation(c);
244
- }
245
- function createEffect(fn, value, options) {
246
- runEffects = runUserEffects;
247
- const c = createComputation(fn, value, false, STALE, options),
248
- s = SuspenseContext && useContext(SuspenseContext);
249
- if (s) c.suspense = s;
250
- if (!options || !options.render) c.user = true;
251
- Effects ? Effects.push(c) : updateComputation(c);
252
- }
253
- function createReaction(onInvalidate, options) {
254
- let fn;
255
- const c = createComputation(
256
- () => {
257
- fn ? fn() : untrack(onInvalidate);
258
- fn = undefined;
259
- },
260
- undefined,
261
- false,
262
- 0,
263
- options
264
- ),
265
- s = SuspenseContext && useContext(SuspenseContext);
266
- if (s) c.suspense = s;
267
- c.user = true;
268
- return tracking => {
269
- fn = tracking;
270
- updateComputation(c);
271
- };
272
- }
273
- function createMemo(fn, value, options) {
274
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
275
- const c = createComputation(fn, value, true, 0, options);
276
- c.observers = null;
277
- c.observerSlots = null;
278
- c.comparator = options.equals || undefined;
279
- if (Scheduler && Transition && Transition.running) {
280
- c.tState = STALE;
281
- Updates.push(c);
282
- } else updateComputation(c);
283
- return readSignal.bind(c);
284
- }
285
- function isPromise(v) {
286
- return v && typeof v === "object" && "then" in v;
287
- }
288
- function createResource(pSource, pFetcher, pOptions) {
289
- let source;
290
- let fetcher;
291
- let options;
292
- if ((arguments.length === 2 && typeof pFetcher === "object") || arguments.length === 1) {
293
- source = true;
294
- fetcher = pSource;
295
- options = pFetcher || {};
296
- } else {
297
- source = pSource;
298
- fetcher = pFetcher;
299
- options = pOptions || {};
300
- }
301
- let pr = null,
302
- initP = NO_INIT,
303
- id = null,
304
- loadedUnderTransition = false,
305
- scheduled = false,
306
- resolved = "initialValue" in options,
307
- dynamic = typeof source === "function" && createMemo(source);
308
- const contexts = new Set(),
309
- [value, setValue] = (options.storage || createSignal)(options.initialValue),
310
- [error, setError] = createSignal(undefined),
311
- [track, trigger] = createSignal(undefined, {
312
- equals: false
313
- }),
314
- [state, setState] = createSignal(resolved ? "ready" : "unresolved");
315
- if (sharedConfig.context) {
316
- id = sharedConfig.getNextContextId();
317
- if (options.ssrLoadFrom === "initial") initP = options.initialValue;
318
- else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id);
319
- }
320
- function loadEnd(p, v, error, key) {
321
- if (pr === p) {
322
- pr = null;
323
- key !== undefined && (resolved = true);
324
- if ((p === initP || v === initP) && options.onHydrated)
325
- queueMicrotask(() =>
326
- options.onHydrated(key, {
327
- value: v
328
- })
329
- );
330
- initP = NO_INIT;
331
- if (Transition && p && loadedUnderTransition) {
332
- Transition.promises.delete(p);
333
- loadedUnderTransition = false;
334
- runUpdates(() => {
335
- Transition.running = true;
336
- completeLoad(v, error);
337
- }, false);
338
- } else completeLoad(v, error);
339
- }
340
- return v;
341
- }
342
- function completeLoad(v, err) {
343
- runUpdates(() => {
344
- if (err === undefined) setValue(() => v);
345
- setState(err !== undefined ? "errored" : resolved ? "ready" : "unresolved");
346
- setError(err);
347
- for (const c of contexts.keys()) c.decrement();
348
- contexts.clear();
349
- }, false);
350
- }
351
- function read() {
352
- const c = SuspenseContext && useContext(SuspenseContext),
353
- v = value(),
354
- err = error();
355
- if (err !== undefined && !pr) throw err;
356
- if (Listener && !Listener.user && c) {
357
- createComputed(() => {
358
- track();
359
- if (pr) {
360
- if (c.resolved && Transition && loadedUnderTransition) Transition.promises.add(pr);
361
- else if (!contexts.has(c)) {
362
- c.increment();
363
- contexts.add(c);
364
- }
365
- }
366
- });
367
- }
368
- return v;
369
- }
370
- function load(refetching = true) {
371
- if (refetching !== false && scheduled) return;
372
- scheduled = false;
373
- const lookup = dynamic ? dynamic() : source;
374
- loadedUnderTransition = Transition && Transition.running;
375
- if (lookup == null || lookup === false) {
376
- loadEnd(pr, untrack(value));
377
- return;
378
- }
379
- if (Transition && pr) Transition.promises.delete(pr);
380
- const p =
381
- initP !== NO_INIT
382
- ? initP
383
- : untrack(() =>
384
- fetcher(lookup, {
385
- value: value(),
386
- refetching
387
- })
388
- );
389
- if (!isPromise(p)) {
390
- loadEnd(pr, p, undefined, lookup);
391
- return p;
392
- }
393
- pr = p;
394
- if ("value" in p) {
395
- if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);
396
- else loadEnd(pr, undefined, castError(p.value), lookup);
397
- return p;
398
- }
399
- scheduled = true;
400
- queueMicrotask(() => (scheduled = false));
401
- runUpdates(() => {
402
- setState(resolved ? "refreshing" : "pending");
403
- trigger();
404
- }, false);
405
- return p.then(
406
- v => loadEnd(p, v, undefined, lookup),
407
- e => loadEnd(p, undefined, castError(e), lookup)
408
- );
409
- }
410
- Object.defineProperties(read, {
411
- state: {
412
- get: () => state()
413
- },
414
- error: {
415
- get: () => error()
416
- },
417
- loading: {
418
- get() {
419
- const s = state();
420
- return s === "pending" || s === "refreshing";
421
- }
422
- },
423
- latest: {
424
- get() {
425
- if (!resolved) return read();
426
- const err = error();
427
- if (err && !pr) throw err;
428
- return value();
429
- }
430
- }
431
- });
432
- if (dynamic) createComputed(() => load(false));
433
- else load(false);
434
- return [
435
- read,
436
- {
437
- refetch: load,
438
- mutate: setValue
439
- }
440
- ];
441
- }
442
- function createDeferred(source, options) {
443
- let t,
444
- timeout = options ? options.timeoutMs : undefined;
445
- const node = createComputation(
446
- () => {
447
- if (!t || !t.fn)
448
- t = requestCallback(
449
- () => setDeferred(() => node.value),
450
- timeout !== undefined
451
- ? {
452
- timeout
453
- }
454
- : undefined
455
- );
456
- return source();
457
- },
458
- undefined,
459
- true
460
- );
461
- const [deferred, setDeferred] = createSignal(
462
- Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value,
463
- options
464
- );
465
- updateComputation(node);
466
- setDeferred(() =>
467
- Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value
468
- );
469
- return deferred;
470
- }
471
- function createSelector(source, fn = equalFn, options) {
472
- const subs = new Map();
473
- const node = createComputation(
474
- p => {
475
- const v = source();
476
- for (const [key, val] of subs.entries())
477
- if (fn(key, v) !== fn(key, p)) {
478
- for (const c of val.values()) {
479
- c.state = STALE;
480
- if (c.pure) Updates.push(c);
481
- else Effects.push(c);
482
- }
483
- }
484
- return v;
485
- },
486
- undefined,
487
- true,
488
- STALE,
489
- options
490
- );
491
- updateComputation(node);
492
- return key => {
493
- const listener = Listener;
494
- if (listener) {
495
- let l;
496
- if ((l = subs.get(key))) l.add(listener);
497
- else subs.set(key, (l = new Set([listener])));
498
- onCleanup(() => {
499
- l.delete(listener);
500
- !l.size && subs.delete(key);
501
- });
502
- }
503
- return fn(
504
- key,
505
- Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value
506
- );
507
- };
508
- }
509
- function batch(fn) {
510
- return runUpdates(fn, false);
511
- }
512
- function untrack(fn) {
513
- if (!ExternalSourceConfig && Listener === null) return fn();
514
- const listener = Listener;
515
- Listener = null;
516
- try {
517
- if (ExternalSourceConfig) return ExternalSourceConfig.untrack(fn);
518
- return fn();
519
- } finally {
520
- Listener = listener;
521
- }
522
- }
523
- function on(deps, fn, options) {
524
- const isArray = Array.isArray(deps);
525
- let prevInput;
526
- let defer = options && options.defer;
527
- return prevValue => {
528
- let input;
529
- if (isArray) {
530
- input = Array(deps.length);
531
- for (let i = 0; i < deps.length; i++) input[i] = deps[i]();
532
- } else input = deps();
533
- if (defer) {
534
- defer = false;
535
- return prevValue;
536
- }
537
- const result = untrack(() => fn(input, prevInput, prevValue));
538
- prevInput = input;
539
- return result;
540
- };
541
- }
52
+ const $DEVCOMP = Symbol("COMPONENT_DEV");
542
53
  function onMount(fn) {
543
- createEffect(() => untrack(fn));
544
- }
545
- function onCleanup(fn) {
546
- if (Owner === null)
547
- console.warn("cleanups created outside a `createRoot` or `render` will never be run");
548
- else if (Owner.cleanups === null) Owner.cleanups = [fn];
549
- else Owner.cleanups.push(fn);
550
- return fn;
551
- }
552
- function catchError(fn, handler) {
553
- ERROR || (ERROR = Symbol("error"));
554
- Owner = createComputation(undefined, undefined, true);
555
- Owner.context = {
556
- ...Owner.context,
557
- [ERROR]: [handler]
558
- };
559
- if (Transition && Transition.running) Transition.sources.add(Owner);
560
- try {
561
- return fn();
562
- } catch (err) {
563
- handleError(err);
564
- } finally {
565
- Owner = Owner.owner;
566
- }
567
- }
568
- function getListener() {
569
- return Listener;
570
- }
571
- function getOwner() {
572
- return Owner;
573
- }
574
- function runWithOwner(o, fn) {
575
- const prev = Owner;
576
- const prevListener = Listener;
577
- Owner = o;
578
- Listener = null;
579
- try {
580
- return runUpdates(fn, true);
581
- } catch (err) {
582
- handleError(err);
583
- } finally {
584
- Owner = prev;
585
- Listener = prevListener;
586
- }
587
- }
588
- function enableScheduling(scheduler = requestCallback) {
589
- Scheduler = scheduler;
590
- }
591
- function startTransition(fn) {
592
- if (Transition && Transition.running) {
593
- fn();
594
- return Transition.done;
595
- }
596
- const l = Listener;
597
- const o = Owner;
598
- return Promise.resolve().then(() => {
599
- Listener = l;
600
- Owner = o;
601
- let t;
602
- if (Scheduler || SuspenseContext) {
603
- t =
604
- Transition ||
605
- (Transition = {
606
- sources: new Set(),
607
- effects: [],
608
- promises: new Set(),
609
- disposed: new Set(),
610
- queue: new Set(),
611
- running: true
612
- });
613
- t.done || (t.done = new Promise(res => (t.resolve = res)));
614
- t.running = true;
615
- }
616
- runUpdates(fn, false);
617
- Listener = Owner = null;
618
- return t ? t.done : undefined;
619
- });
620
- }
621
- const [transPending, setTransPending] = /*@__PURE__*/ createSignal(false);
622
- function useTransition() {
623
- return [transPending, startTransition];
624
- }
625
- function resumeEffects(e) {
626
- Effects.push.apply(Effects, e);
627
- e.length = 0;
628
- }
629
- function devComponent(Comp, props) {
630
- const c = createComputation(
631
- () =>
632
- untrack(() => {
633
- Object.assign(Comp, {
634
- [$DEVCOMP]: true
635
- });
636
- return Comp(props);
637
- }),
638
- undefined,
639
- true,
640
- 0
641
- );
642
- c.props = props;
643
- c.observers = null;
644
- c.observerSlots = null;
645
- c.name = Comp.name;
646
- c.component = Comp;
647
- updateComputation(c);
648
- return c.tValue !== undefined ? c.tValue : c.value;
649
- }
650
- function registerGraph(value) {
651
- if (!Owner) return;
652
- if (Owner.sourceMap) Owner.sourceMap.push(value);
653
- else Owner.sourceMap = [value];
654
- value.graph = Owner;
54
+ createEffect(() => null, fn);
655
55
  }
656
56
  function createContext(defaultValue, options) {
657
- const id = Symbol("context");
658
- return {
659
- id,
660
- Provider: createProvider(id, options),
661
- defaultValue
662
- };
57
+ const id = Symbol((options && options.name) || "");
58
+ function provider(props) {
59
+ return createMemo(() => {
60
+ setContext(
61
+ provider,
62
+ untrack(() => props.value)
63
+ );
64
+ return children(() => props.children);
65
+ });
66
+ }
67
+ provider.id = id;
68
+ provider.defaultValue = defaultValue;
69
+ return provider;
663
70
  }
664
71
  function useContext(context) {
665
- let value;
666
- return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined
667
- ? value
668
- : context.defaultValue;
72
+ return getContext(context);
669
73
  }
670
74
  function children(fn) {
671
75
  const children = createMemo(fn);
672
- const memo = createMemo(() => resolveChildren(children()), undefined, {
76
+ const memo = createMemo(() => flatten(children()), undefined, {
673
77
  name: "children"
674
78
  });
675
79
  memo.toArray = () => {
@@ -678,492 +82,26 @@ function children(fn) {
678
82
  };
679
83
  return memo;
680
84
  }
681
- let SuspenseContext;
682
- function getSuspenseContext() {
683
- return SuspenseContext || (SuspenseContext = createContext());
684
- }
685
- function enableExternalSource(factory, untrack = fn => fn()) {
686
- if (ExternalSourceConfig) {
687
- const { factory: oldFactory, untrack: oldUntrack } = ExternalSourceConfig;
688
- ExternalSourceConfig = {
689
- factory: (fn, trigger) => {
690
- const oldSource = oldFactory(fn, trigger);
691
- const source = factory(x => oldSource.track(x), trigger);
692
- return {
693
- track: x => source.track(x),
694
- dispose() {
695
- source.dispose();
696
- oldSource.dispose();
697
- }
698
- };
699
- },
700
- untrack: fn => oldUntrack(() => untrack(fn))
701
- };
702
- } else {
703
- ExternalSourceConfig = {
704
- factory,
705
- untrack
706
- };
707
- }
708
- }
709
- function readSignal() {
710
- const runningTransition = Transition && Transition.running;
711
- if (this.sources && (runningTransition ? this.tState : this.state)) {
712
- if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this);
713
- else {
714
- const updates = Updates;
715
- Updates = null;
716
- runUpdates(() => lookUpstream(this), false);
717
- Updates = updates;
718
- }
719
- }
720
- if (Listener) {
721
- const sSlot = this.observers ? this.observers.length : 0;
722
- if (!Listener.sources) {
723
- Listener.sources = [this];
724
- Listener.sourceSlots = [sSlot];
725
- } else {
726
- Listener.sources.push(this);
727
- Listener.sourceSlots.push(sSlot);
728
- }
729
- if (!this.observers) {
730
- this.observers = [Listener];
731
- this.observerSlots = [Listener.sources.length - 1];
732
- } else {
733
- this.observers.push(Listener);
734
- this.observerSlots.push(Listener.sources.length - 1);
735
- }
736
- }
737
- if (runningTransition && Transition.sources.has(this)) return this.tValue;
738
- return this.value;
739
- }
740
- function writeSignal(node, value, isComp) {
741
- let current =
742
- Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value;
743
- if (!node.comparator || !node.comparator(current, value)) {
744
- if (Transition) {
745
- const TransitionRunning = Transition.running;
746
- if (TransitionRunning || (!isComp && Transition.sources.has(node))) {
747
- Transition.sources.add(node);
748
- node.tValue = value;
749
- }
750
- if (!TransitionRunning) node.value = value;
751
- } else node.value = value;
752
- if (node.observers && node.observers.length) {
753
- runUpdates(() => {
754
- for (let i = 0; i < node.observers.length; i += 1) {
755
- const o = node.observers[i];
756
- const TransitionRunning = Transition && Transition.running;
757
- if (TransitionRunning && Transition.disposed.has(o)) continue;
758
- if (TransitionRunning ? !o.tState : !o.state) {
759
- if (o.pure) Updates.push(o);
760
- else Effects.push(o);
761
- if (o.observers) markDownstream(o);
762
- }
763
- if (!TransitionRunning) o.state = STALE;
764
- else o.tState = STALE;
765
- }
766
- if (Updates.length > 10e5) {
767
- Updates = [];
768
- if (true) throw new Error("Potential Infinite Loop Detected.");
769
- throw new Error();
770
- }
771
- }, false);
772
- }
773
- }
774
- return value;
775
- }
776
- function updateComputation(node) {
777
- if (!node.fn) return;
778
- cleanNode(node);
779
- const time = ExecCount;
780
- runComputation(
781
- node,
782
- Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value,
783
- time
784
- );
785
- if (Transition && !Transition.running && Transition.sources.has(node)) {
786
- queueMicrotask(() => {
787
- runUpdates(() => {
788
- Transition && (Transition.running = true);
789
- Listener = Owner = node;
790
- runComputation(node, node.tValue, time);
791
- Listener = Owner = null;
792
- }, false);
793
- });
794
- }
795
- }
796
- function runComputation(node, value, time) {
797
- let nextValue;
798
- const owner = Owner,
799
- listener = Listener;
800
- Listener = Owner = node;
801
- try {
802
- nextValue = node.fn(value);
803
- } catch (err) {
804
- if (node.pure) {
805
- if (Transition && Transition.running) {
806
- node.tState = STALE;
807
- node.tOwned && node.tOwned.forEach(cleanNode);
808
- node.tOwned = undefined;
809
- } else {
810
- node.state = STALE;
811
- node.owned && node.owned.forEach(cleanNode);
812
- node.owned = null;
813
- }
814
- }
815
- node.updatedAt = time + 1;
816
- return handleError(err);
817
- } finally {
818
- Listener = listener;
819
- Owner = owner;
820
- }
821
- if (!node.updatedAt || node.updatedAt <= time) {
822
- if (node.updatedAt != null && "observers" in node) {
823
- writeSignal(node, nextValue, true);
824
- } else if (Transition && Transition.running && node.pure) {
825
- Transition.sources.add(node);
826
- node.tValue = nextValue;
827
- } else node.value = nextValue;
828
- node.updatedAt = time;
829
- }
830
- }
831
- function createComputation(fn, init, pure, state = STALE, options) {
832
- const c = {
833
- fn,
834
- state: state,
835
- updatedAt: null,
836
- owned: null,
837
- sources: null,
838
- sourceSlots: null,
839
- cleanups: null,
840
- value: init,
841
- owner: Owner,
842
- context: Owner ? Owner.context : null,
843
- pure
844
- };
845
- if (Transition && Transition.running) {
846
- c.state = 0;
847
- c.tState = state;
848
- }
849
- if (Owner === null)
850
- console.warn("computations created outside a `createRoot` or `render` will never be disposed");
851
- else if (Owner !== UNOWNED) {
852
- if (Transition && Transition.running && Owner.pure) {
853
- if (!Owner.tOwned) Owner.tOwned = [c];
854
- else Owner.tOwned.push(c);
855
- } else {
856
- if (!Owner.owned) Owner.owned = [c];
857
- else Owner.owned.push(c);
858
- }
859
- }
860
- if (options && options.name) c.name = options.name;
861
- if (ExternalSourceConfig && c.fn) {
862
- const [track, trigger] = createSignal(undefined, {
863
- equals: false
864
- });
865
- const ordinary = ExternalSourceConfig.factory(c.fn, trigger);
866
- onCleanup(() => ordinary.dispose());
867
- const triggerInTransition = () => startTransition(trigger).then(() => inTransition.dispose());
868
- const inTransition = ExternalSourceConfig.factory(c.fn, triggerInTransition);
869
- c.fn = x => {
870
- track();
871
- return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
872
- };
873
- }
874
- DevHooks.afterCreateOwner && DevHooks.afterCreateOwner(c);
875
- return c;
876
- }
877
- function runTop(node) {
878
- const runningTransition = Transition && Transition.running;
879
- if ((runningTransition ? node.tState : node.state) === 0) return;
880
- if ((runningTransition ? node.tState : node.state) === PENDING) return lookUpstream(node);
881
- if (node.suspense && untrack(node.suspense.inFallback)) return node.suspense.effects.push(node);
882
- const ancestors = [node];
883
- while ((node = node.owner) && (!node.updatedAt || node.updatedAt < ExecCount)) {
884
- if (runningTransition && Transition.disposed.has(node)) return;
885
- if (runningTransition ? node.tState : node.state) ancestors.push(node);
886
- }
887
- for (let i = ancestors.length - 1; i >= 0; i--) {
888
- node = ancestors[i];
889
- if (runningTransition) {
890
- let top = node,
891
- prev = ancestors[i + 1];
892
- while ((top = top.owner) && top !== prev) {
893
- if (Transition.disposed.has(top)) return;
894
- }
895
- }
896
- if ((runningTransition ? node.tState : node.state) === STALE) {
897
- updateComputation(node);
898
- } else if ((runningTransition ? node.tState : node.state) === PENDING) {
899
- const updates = Updates;
900
- Updates = null;
901
- runUpdates(() => lookUpstream(node, ancestors[0]), false);
902
- Updates = updates;
903
- }
904
- }
905
- }
906
- function runUpdates(fn, init) {
907
- if (Updates) return fn();
908
- let wait = false;
909
- if (!init) Updates = [];
910
- if (Effects) wait = true;
911
- else Effects = [];
912
- ExecCount++;
913
- try {
914
- const res = fn();
915
- completeUpdates(wait);
916
- return res;
917
- } catch (err) {
918
- if (!wait) Effects = null;
919
- Updates = null;
920
- handleError(err);
921
- }
922
- }
923
- function completeUpdates(wait) {
924
- if (Updates) {
925
- if (Scheduler && Transition && Transition.running) scheduleQueue(Updates);
926
- else runQueue(Updates);
927
- Updates = null;
928
- }
929
- if (wait) return;
930
- let res;
931
- if (Transition) {
932
- if (!Transition.promises.size && !Transition.queue.size) {
933
- const sources = Transition.sources;
934
- const disposed = Transition.disposed;
935
- Effects.push.apply(Effects, Transition.effects);
936
- res = Transition.resolve;
937
- for (const e of Effects) {
938
- "tState" in e && (e.state = e.tState);
939
- delete e.tState;
940
- }
941
- Transition = null;
942
- runUpdates(() => {
943
- for (const d of disposed) cleanNode(d);
944
- for (const v of sources) {
945
- v.value = v.tValue;
946
- if (v.owned) {
947
- for (let i = 0, len = v.owned.length; i < len; i++) cleanNode(v.owned[i]);
948
- }
949
- if (v.tOwned) v.owned = v.tOwned;
950
- delete v.tValue;
951
- delete v.tOwned;
952
- v.tState = 0;
953
- }
954
- setTransPending(false);
955
- }, false);
956
- } else if (Transition.running) {
957
- Transition.running = false;
958
- Transition.effects.push.apply(Transition.effects, Effects);
959
- Effects = null;
960
- setTransPending(true);
961
- return;
962
- }
963
- }
964
- const e = Effects;
965
- Effects = null;
966
- if (e.length) runUpdates(() => runEffects(e), false);
967
- else DevHooks.afterUpdate && DevHooks.afterUpdate();
968
- if (res) res();
969
- }
970
- function runQueue(queue) {
971
- for (let i = 0; i < queue.length; i++) runTop(queue[i]);
972
- }
973
- function scheduleQueue(queue) {
974
- for (let i = 0; i < queue.length; i++) {
975
- const item = queue[i];
976
- const tasks = Transition.queue;
977
- if (!tasks.has(item)) {
978
- tasks.add(item);
979
- Scheduler(() => {
980
- tasks.delete(item);
981
- runUpdates(() => {
982
- Transition.running = true;
983
- runTop(item);
984
- }, false);
985
- Transition && (Transition.running = false);
85
+ function devComponent(Comp, props) {
86
+ return createRoot(() => {
87
+ const owner = getOwner();
88
+ owner._props = props;
89
+ owner._name = Comp.name;
90
+ owner._component = Comp;
91
+ return untrack(() => {
92
+ Object.assign(Comp, {
93
+ [$DEVCOMP]: true
986
94
  });
987
- }
988
- }
989
- }
990
- function runUserEffects(queue) {
991
- let i,
992
- userLength = 0;
993
- for (i = 0; i < queue.length; i++) {
994
- const e = queue[i];
995
- if (!e.user) runTop(e);
996
- else queue[userLength++] = e;
997
- }
998
- if (sharedConfig.context) {
999
- if (sharedConfig.count) {
1000
- sharedConfig.effects || (sharedConfig.effects = []);
1001
- sharedConfig.effects.push(...queue.slice(0, userLength));
1002
- return;
1003
- }
1004
- setHydrateContext();
1005
- }
1006
- if (sharedConfig.effects && (sharedConfig.done || !sharedConfig.count)) {
1007
- queue = [...sharedConfig.effects, ...queue];
1008
- userLength += sharedConfig.effects.length;
1009
- delete sharedConfig.effects;
1010
- }
1011
- for (i = 0; i < userLength; i++) runTop(queue[i]);
1012
- }
1013
- function lookUpstream(node, ignore) {
1014
- const runningTransition = Transition && Transition.running;
1015
- if (runningTransition) node.tState = 0;
1016
- else node.state = 0;
1017
- for (let i = 0; i < node.sources.length; i += 1) {
1018
- const source = node.sources[i];
1019
- if (source.sources) {
1020
- const state = runningTransition ? source.tState : source.state;
1021
- if (state === STALE) {
1022
- if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount))
1023
- runTop(source);
1024
- } else if (state === PENDING) lookUpstream(source, ignore);
1025
- }
1026
- }
1027
- }
1028
- function markDownstream(node) {
1029
- const runningTransition = Transition && Transition.running;
1030
- for (let i = 0; i < node.observers.length; i += 1) {
1031
- const o = node.observers[i];
1032
- if (runningTransition ? !o.tState : !o.state) {
1033
- if (runningTransition) o.tState = PENDING;
1034
- else o.state = PENDING;
1035
- if (o.pure) Updates.push(o);
1036
- else Effects.push(o);
1037
- o.observers && markDownstream(o);
1038
- }
1039
- }
1040
- }
1041
- function cleanNode(node) {
1042
- let i;
1043
- if (node.sources) {
1044
- while (node.sources.length) {
1045
- const source = node.sources.pop(),
1046
- index = node.sourceSlots.pop(),
1047
- obs = source.observers;
1048
- if (obs && obs.length) {
1049
- const n = obs.pop(),
1050
- s = source.observerSlots.pop();
1051
- if (index < obs.length) {
1052
- n.sourceSlots[s] = index;
1053
- obs[index] = n;
1054
- source.observerSlots[index] = s;
1055
- }
1056
- }
1057
- }
1058
- }
1059
- if (node.tOwned) {
1060
- for (i = node.tOwned.length - 1; i >= 0; i--) cleanNode(node.tOwned[i]);
1061
- delete node.tOwned;
1062
- }
1063
- if (Transition && Transition.running && node.pure) {
1064
- reset(node, true);
1065
- } else if (node.owned) {
1066
- for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]);
1067
- node.owned = null;
1068
- }
1069
- if (node.cleanups) {
1070
- for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i]();
1071
- node.cleanups = null;
1072
- }
1073
- if (Transition && Transition.running) node.tState = 0;
1074
- else node.state = 0;
1075
- delete node.sourceMap;
1076
- }
1077
- function reset(node, top) {
1078
- if (!top) {
1079
- node.tState = 0;
1080
- Transition.disposed.add(node);
1081
- }
1082
- if (node.owned) {
1083
- for (let i = 0; i < node.owned.length; i++) reset(node.owned[i]);
1084
- }
1085
- }
1086
- function castError(err) {
1087
- if (err instanceof Error) return err;
1088
- return new Error(typeof err === "string" ? err : "Unknown error", {
1089
- cause: err
1090
- });
1091
- }
1092
- function runErrors(err, fns, owner) {
1093
- try {
1094
- for (const f of fns) f(err);
1095
- } catch (e) {
1096
- handleError(e, (owner && owner.owner) || null);
1097
- }
1098
- }
1099
- function handleError(err, owner = Owner) {
1100
- const fns = ERROR && owner && owner.context && owner.context[ERROR];
1101
- const error = castError(err);
1102
- if (!fns) throw error;
1103
- if (Effects)
1104
- Effects.push({
1105
- fn() {
1106
- runErrors(error, fns, owner);
1107
- },
1108
- state: STALE
95
+ return Comp(props);
1109
96
  });
1110
- else runErrors(error, fns, owner);
1111
- }
1112
- function resolveChildren(children) {
1113
- if (typeof children === "function" && !children.length) return resolveChildren(children());
1114
- if (Array.isArray(children)) {
1115
- const results = [];
1116
- for (let i = 0; i < children.length; i++) {
1117
- const result = resolveChildren(children[i]);
1118
- Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
1119
- }
1120
- return results;
1121
- }
1122
- return children;
1123
- }
1124
- function createProvider(id, options) {
1125
- return function provider(props) {
1126
- let res;
1127
- createRenderEffect(
1128
- () =>
1129
- (res = untrack(() => {
1130
- Owner.context = {
1131
- ...Owner.context,
1132
- [id]: props.value
1133
- };
1134
- return children(() => props.children);
1135
- })),
1136
- undefined,
1137
- options
1138
- );
1139
- return res;
1140
- };
1141
- }
1142
- function onError(fn) {
1143
- ERROR || (ERROR = Symbol("error"));
1144
- if (Owner === null)
1145
- console.warn("error handlers created outside a `createRoot` or `render` will never be run");
1146
- else if (Owner.context === null || !Owner.context[ERROR]) {
1147
- Owner.context = {
1148
- ...Owner.context,
1149
- [ERROR]: [fn]
1150
- };
1151
- mutateContext(Owner, ERROR, [fn]);
1152
- } else Owner.context[ERROR].push(fn);
97
+ });
1153
98
  }
1154
- function mutateContext(o, key, value) {
1155
- if (o.owned) {
1156
- for (let i = 0; i < o.owned.length; i++) {
1157
- if (o.owned[i].context === o.context) mutateContext(o.owned[i], key, value);
1158
- if (!o.owned[i].context) {
1159
- o.owned[i].context = o.context;
1160
- mutateContext(o.owned[i], key, value);
1161
- } else if (!o.owned[i].context[key]) {
1162
- o.owned[i].context[key] = value;
1163
- mutateContext(o.owned[i], key, value);
1164
- }
1165
- }
1166
- }
99
+ function registerGraph(value) {
100
+ const owner = getOwner();
101
+ if (!owner) return;
102
+ if (owner.sourceMap) owner.sourceMap.push(value);
103
+ else owner.sourceMap = [value];
104
+ value.graph = owner;
1167
105
  }
1168
106
 
1169
107
  function observable(input) {
@@ -1180,10 +118,12 @@ function observable(input) {
1180
118
  };
1181
119
  }
1182
120
  const dispose = createRoot(disposer => {
1183
- createEffect(() => {
1184
- const v = input();
1185
- untrack(() => handler(v));
1186
- });
121
+ createEffect(
122
+ () => input(),
123
+ v => {
124
+ handler(v);
125
+ }
126
+ );
1187
127
  return disposer;
1188
128
  });
1189
129
  if (getOwner()) onCleanup(dispose);
@@ -1212,175 +152,30 @@ function from(producer) {
1212
152
  return s;
1213
153
  }
1214
154
 
1215
- const FALLBACK = Symbol("fallback");
1216
- function dispose(d) {
1217
- for (let i = 0; i < d.length; i++) d[i]();
155
+ const sharedConfig = {
156
+ context: undefined,
157
+ registry: undefined,
158
+ done: false,
159
+ getContextId() {
160
+ return getContextId(this.context.count);
161
+ },
162
+ getNextContextId() {
163
+ return getContextId(this.context.count++);
164
+ }
165
+ };
166
+ function getContextId(count) {
167
+ const num = String(count),
168
+ len = num.length - 1;
169
+ return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
1218
170
  }
1219
- function mapArray(list, mapFn, options = {}) {
1220
- let items = [],
1221
- mapped = [],
1222
- disposers = [],
1223
- len = 0,
1224
- indexes = mapFn.length > 1 ? [] : null;
1225
- onCleanup(() => dispose(disposers));
1226
- return () => {
1227
- let newItems = list() || [],
1228
- newLen = newItems.length,
1229
- i,
1230
- j;
1231
- newItems[$TRACK];
1232
- return untrack(() => {
1233
- let newIndices, newIndicesNext, temp, tempdisposers, tempIndexes, start, end, newEnd, item;
1234
- if (newLen === 0) {
1235
- if (len !== 0) {
1236
- dispose(disposers);
1237
- disposers = [];
1238
- items = [];
1239
- mapped = [];
1240
- len = 0;
1241
- indexes && (indexes = []);
1242
- }
1243
- if (options.fallback) {
1244
- items = [FALLBACK];
1245
- mapped[0] = createRoot(disposer => {
1246
- disposers[0] = disposer;
1247
- return options.fallback();
1248
- });
1249
- len = 1;
1250
- }
1251
- } else if (len === 0) {
1252
- mapped = new Array(newLen);
1253
- for (j = 0; j < newLen; j++) {
1254
- items[j] = newItems[j];
1255
- mapped[j] = createRoot(mapper);
1256
- }
1257
- len = newLen;
1258
- } else {
1259
- temp = new Array(newLen);
1260
- tempdisposers = new Array(newLen);
1261
- indexes && (tempIndexes = new Array(newLen));
1262
- for (
1263
- start = 0, end = Math.min(len, newLen);
1264
- start < end && items[start] === newItems[start];
1265
- start++
1266
- );
1267
- for (
1268
- end = len - 1, newEnd = newLen - 1;
1269
- end >= start && newEnd >= start && items[end] === newItems[newEnd];
1270
- end--, newEnd--
1271
- ) {
1272
- temp[newEnd] = mapped[end];
1273
- tempdisposers[newEnd] = disposers[end];
1274
- indexes && (tempIndexes[newEnd] = indexes[end]);
1275
- }
1276
- newIndices = new Map();
1277
- newIndicesNext = new Array(newEnd + 1);
1278
- for (j = newEnd; j >= start; j--) {
1279
- item = newItems[j];
1280
- i = newIndices.get(item);
1281
- newIndicesNext[j] = i === undefined ? -1 : i;
1282
- newIndices.set(item, j);
1283
- }
1284
- for (i = start; i <= end; i++) {
1285
- item = items[i];
1286
- j = newIndices.get(item);
1287
- if (j !== undefined && j !== -1) {
1288
- temp[j] = mapped[i];
1289
- tempdisposers[j] = disposers[i];
1290
- indexes && (tempIndexes[j] = indexes[i]);
1291
- j = newIndicesNext[j];
1292
- newIndices.set(item, j);
1293
- } else disposers[i]();
1294
- }
1295
- for (j = start; j < newLen; j++) {
1296
- if (j in temp) {
1297
- mapped[j] = temp[j];
1298
- disposers[j] = tempdisposers[j];
1299
- if (indexes) {
1300
- indexes[j] = tempIndexes[j];
1301
- indexes[j](j);
1302
- }
1303
- } else mapped[j] = createRoot(mapper);
1304
- }
1305
- mapped = mapped.slice(0, (len = newLen));
1306
- items = newItems.slice(0);
1307
- }
1308
- return mapped;
1309
- });
1310
- function mapper(disposer) {
1311
- disposers[j] = disposer;
1312
- if (indexes) {
1313
- const [s, set] = createSignal(j, {
1314
- name: "index"
1315
- });
1316
- indexes[j] = set;
1317
- return mapFn(newItems[j], s);
1318
- }
1319
- return mapFn(newItems[j]);
1320
- }
1321
- };
171
+ function setHydrateContext(context) {
172
+ sharedConfig.context = context;
1322
173
  }
1323
- function indexArray(list, mapFn, options = {}) {
1324
- let items = [],
1325
- mapped = [],
1326
- disposers = [],
1327
- signals = [],
1328
- len = 0,
1329
- i;
1330
- onCleanup(() => dispose(disposers));
1331
- return () => {
1332
- const newItems = list() || [],
1333
- newLen = newItems.length;
1334
- newItems[$TRACK];
1335
- return untrack(() => {
1336
- if (newLen === 0) {
1337
- if (len !== 0) {
1338
- dispose(disposers);
1339
- disposers = [];
1340
- items = [];
1341
- mapped = [];
1342
- len = 0;
1343
- signals = [];
1344
- }
1345
- if (options.fallback) {
1346
- items = [FALLBACK];
1347
- mapped[0] = createRoot(disposer => {
1348
- disposers[0] = disposer;
1349
- return options.fallback();
1350
- });
1351
- len = 1;
1352
- }
1353
- return mapped;
1354
- }
1355
- if (items[0] === FALLBACK) {
1356
- disposers[0]();
1357
- disposers = [];
1358
- items = [];
1359
- mapped = [];
1360
- len = 0;
1361
- }
1362
- for (i = 0; i < newLen; i++) {
1363
- if (i < items.length && items[i] !== newItems[i]) {
1364
- signals[i](() => newItems[i]);
1365
- } else if (i >= items.length) {
1366
- mapped[i] = createRoot(mapper);
1367
- }
1368
- }
1369
- for (; i < items.length; i++) {
1370
- disposers[i]();
1371
- }
1372
- len = signals.length = disposers.length = newLen;
1373
- items = newItems.slice(0);
1374
- return (mapped = mapped.slice(0, len));
1375
- });
1376
- function mapper(disposer) {
1377
- disposers[i] = disposer;
1378
- const [s, set] = createSignal(newItems[i], {
1379
- name: "value"
1380
- });
1381
- signals[i] = set;
1382
- return mapFn(s, i);
1383
- }
174
+ function nextHydrateContext() {
175
+ return {
176
+ ...sharedConfig.context,
177
+ id: sharedConfig.getNextContextId(),
178
+ count: 0
1384
179
  };
1385
180
  }
1386
181
 
@@ -1400,177 +195,6 @@ function createComponent(Comp, props) {
1400
195
  }
1401
196
  return devComponent(Comp, props || {});
1402
197
  }
1403
- function trueFn() {
1404
- return true;
1405
- }
1406
- const propTraps = {
1407
- get(_, property, receiver) {
1408
- if (property === $PROXY) return receiver;
1409
- return _.get(property);
1410
- },
1411
- has(_, property) {
1412
- if (property === $PROXY) return true;
1413
- return _.has(property);
1414
- },
1415
- set: trueFn,
1416
- deleteProperty: trueFn,
1417
- getOwnPropertyDescriptor(_, property) {
1418
- return {
1419
- configurable: true,
1420
- enumerable: true,
1421
- get() {
1422
- return _.get(property);
1423
- },
1424
- set: trueFn,
1425
- deleteProperty: trueFn
1426
- };
1427
- },
1428
- ownKeys(_) {
1429
- return _.keys();
1430
- }
1431
- };
1432
- function resolveSource(s) {
1433
- return !(s = typeof s === "function" ? s() : s) ? {} : s;
1434
- }
1435
- function resolveSources() {
1436
- for (let i = 0, length = this.length; i < length; ++i) {
1437
- const v = this[i]();
1438
- if (v !== undefined) return v;
1439
- }
1440
- }
1441
- function mergeProps(...sources) {
1442
- let proxy = false;
1443
- for (let i = 0; i < sources.length; i++) {
1444
- const s = sources[i];
1445
- proxy = proxy || (!!s && $PROXY in s);
1446
- sources[i] = typeof s === "function" ? ((proxy = true), createMemo(s)) : s;
1447
- }
1448
- if (SUPPORTS_PROXY && proxy) {
1449
- return new Proxy(
1450
- {
1451
- get(property) {
1452
- for (let i = sources.length - 1; i >= 0; i--) {
1453
- const v = resolveSource(sources[i])[property];
1454
- if (v !== undefined) return v;
1455
- }
1456
- },
1457
- has(property) {
1458
- for (let i = sources.length - 1; i >= 0; i--) {
1459
- if (property in resolveSource(sources[i])) return true;
1460
- }
1461
- return false;
1462
- },
1463
- keys() {
1464
- const keys = [];
1465
- for (let i = 0; i < sources.length; i++)
1466
- keys.push(...Object.keys(resolveSource(sources[i])));
1467
- return [...new Set(keys)];
1468
- }
1469
- },
1470
- propTraps
1471
- );
1472
- }
1473
- const sourcesMap = {};
1474
- const defined = Object.create(null);
1475
- for (let i = sources.length - 1; i >= 0; i--) {
1476
- const source = sources[i];
1477
- if (!source) continue;
1478
- const sourceKeys = Object.getOwnPropertyNames(source);
1479
- for (let i = sourceKeys.length - 1; i >= 0; i--) {
1480
- const key = sourceKeys[i];
1481
- if (key === "__proto__" || key === "constructor") continue;
1482
- const desc = Object.getOwnPropertyDescriptor(source, key);
1483
- if (!defined[key]) {
1484
- defined[key] = desc.get
1485
- ? {
1486
- enumerable: true,
1487
- configurable: true,
1488
- get: resolveSources.bind((sourcesMap[key] = [desc.get.bind(source)]))
1489
- }
1490
- : desc.value !== undefined
1491
- ? desc
1492
- : undefined;
1493
- } else {
1494
- const sources = sourcesMap[key];
1495
- if (sources) {
1496
- if (desc.get) sources.push(desc.get.bind(source));
1497
- else if (desc.value !== undefined) sources.push(() => desc.value);
1498
- }
1499
- }
1500
- }
1501
- }
1502
- const target = {};
1503
- const definedKeys = Object.keys(defined);
1504
- for (let i = definedKeys.length - 1; i >= 0; i--) {
1505
- const key = definedKeys[i],
1506
- desc = defined[key];
1507
- if (desc && desc.get) Object.defineProperty(target, key, desc);
1508
- else target[key] = desc ? desc.value : undefined;
1509
- }
1510
- return target;
1511
- }
1512
- function splitProps(props, ...keys) {
1513
- if (SUPPORTS_PROXY && $PROXY in props) {
1514
- const blocked = new Set(keys.length > 1 ? keys.flat() : keys[0]);
1515
- const res = keys.map(k => {
1516
- return new Proxy(
1517
- {
1518
- get(property) {
1519
- return k.includes(property) ? props[property] : undefined;
1520
- },
1521
- has(property) {
1522
- return k.includes(property) && property in props;
1523
- },
1524
- keys() {
1525
- return k.filter(property => property in props);
1526
- }
1527
- },
1528
- propTraps
1529
- );
1530
- });
1531
- res.push(
1532
- new Proxy(
1533
- {
1534
- get(property) {
1535
- return blocked.has(property) ? undefined : props[property];
1536
- },
1537
- has(property) {
1538
- return blocked.has(property) ? false : property in props;
1539
- },
1540
- keys() {
1541
- return Object.keys(props).filter(k => !blocked.has(k));
1542
- }
1543
- },
1544
- propTraps
1545
- )
1546
- );
1547
- return res;
1548
- }
1549
- const otherObject = {};
1550
- const objects = keys.map(() => ({}));
1551
- for (const propName of Object.getOwnPropertyNames(props)) {
1552
- const desc = Object.getOwnPropertyDescriptor(props, propName);
1553
- const isDefaultDesc =
1554
- !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable;
1555
- let blocked = false;
1556
- let objectIndex = 0;
1557
- for (const k of keys) {
1558
- if (k.includes(propName)) {
1559
- blocked = true;
1560
- isDefaultDesc
1561
- ? (objects[objectIndex][propName] = desc.value)
1562
- : Object.defineProperty(objects[objectIndex], propName, desc);
1563
- }
1564
- ++objectIndex;
1565
- }
1566
- if (!blocked) {
1567
- isDefaultDesc
1568
- ? (otherObject[propName] = desc.value)
1569
- : Object.defineProperty(otherObject, propName, desc);
1570
- }
1571
- }
1572
- return [...objects, otherObject];
1573
- }
1574
198
  function lazy(fn) {
1575
199
  let comp;
1576
200
  let p;
@@ -1588,17 +212,16 @@ function lazy(fn) {
1588
212
  });
1589
213
  comp = s;
1590
214
  } else if (!comp) {
1591
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
215
+ const s = createAsync(() => (p || (p = fn())).then(mod => mod.default));
1592
216
  comp = s;
1593
217
  }
1594
218
  let Comp;
1595
219
  return createMemo(() =>
1596
220
  (Comp = comp())
1597
221
  ? untrack(() => {
1598
- if (true)
1599
- Object.assign(Comp, {
1600
- [$DEVCOMP]: true
1601
- });
222
+ Object.assign(Comp, {
223
+ [$DEVCOMP]: true
224
+ });
1602
225
  if (!ctx || sharedConfig.done) return Comp(props);
1603
226
  const c = sharedConfig.context;
1604
227
  setHydrateContext(ctx);
@@ -1621,23 +244,36 @@ function createUniqueId() {
1621
244
  const narrowedError = name =>
1622
245
  `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.`;
1623
246
  function For(props) {
1624
- const fallback = "fallback" in props && {
1625
- fallback: () => props.fallback
1626
- };
247
+ const options =
248
+ "fallback" in props
249
+ ? {
250
+ keyed: props.keyed,
251
+ fallback: () => props.fallback
252
+ }
253
+ : {
254
+ keyed: props.keyed
255
+ };
1627
256
  return createMemo(
1628
- mapArray(() => props.each, props.children, fallback || undefined),
257
+ mapArray(() => props.each, props.children, options),
1629
258
  undefined,
1630
259
  {
1631
260
  name: "value"
1632
261
  }
1633
262
  );
1634
263
  }
1635
- function Index(props) {
1636
- const fallback = "fallback" in props && {
1637
- fallback: () => props.fallback
1638
- };
264
+ function Repeat(props) {
265
+ const options =
266
+ "fallback" in props
267
+ ? {
268
+ fallback: () => props.fallback
269
+ }
270
+ : {};
1639
271
  return createMemo(
1640
- indexArray(() => props.each, props.children, fallback || undefined),
272
+ repeat(
273
+ () => props.count,
274
+ index => (typeof props.children === "function" ? props.children(index) : props.children),
275
+ options
276
+ ),
1641
277
  undefined,
1642
278
  {
1643
279
  name: "value"
@@ -1658,14 +294,10 @@ function Show(props) {
1658
294
  const fn = typeof child === "function" && child.length > 0;
1659
295
  return fn
1660
296
  ? untrack(() =>
1661
- child(
1662
- keyed
1663
- ? c
1664
- : () => {
1665
- if (!untrack(condition)) throw narrowedError("Show");
1666
- return props.when;
1667
- }
1668
- )
297
+ child(() => {
298
+ if (!untrack(condition)) throw narrowedError("Show");
299
+ return props.when;
300
+ })
1669
301
  )
1670
302
  : child;
1671
303
  }
@@ -1708,14 +340,10 @@ function Switch(props) {
1708
340
  const fn = typeof c === "function" && c.length > 0;
1709
341
  return fn
1710
342
  ? untrack(() =>
1711
- c(
1712
- keyed
1713
- ? when
1714
- : () => {
1715
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
1716
- return cond.when;
1717
- }
1718
- )
343
+ c(() => {
344
+ if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
345
+ return cond.when;
346
+ })
1719
347
  )
1720
348
  : c;
1721
349
  },
@@ -1728,210 +356,26 @@ function Switch(props) {
1728
356
  function Match(props) {
1729
357
  return props;
1730
358
  }
1731
- let Errors;
1732
- function resetErrorBoundaries() {
1733
- Errors && [...Errors].forEach(fn => fn());
1734
- }
1735
359
  function ErrorBoundary(props) {
1736
- let err;
1737
- if (sharedConfig.context && sharedConfig.load)
1738
- err = sharedConfig.load(sharedConfig.getContextId());
1739
- const [errored, setErrored] = createSignal(err, {
1740
- name: "errored"
1741
- });
1742
- Errors || (Errors = new Set());
1743
- Errors.add(setErrored);
1744
- onCleanup(() => Errors.delete(setErrored));
1745
- return createMemo(
1746
- () => {
1747
- let e;
1748
- if ((e = errored())) {
1749
- const f = props.fallback;
1750
- if (typeof f !== "function" || f.length == 0) console.error(e);
1751
- return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f;
1752
- }
1753
- return catchError(() => props.children, setErrored);
1754
- },
1755
- undefined,
1756
- {
1757
- name: "value"
1758
- }
1759
- );
1760
- }
1761
-
1762
- const suspenseListEquals = (a, b) =>
1763
- a.showContent === b.showContent && a.showFallback === b.showFallback;
1764
- const SuspenseListContext = /* #__PURE__ */ createContext();
1765
- function SuspenseList(props) {
1766
- let [wrapper, setWrapper] = createSignal(() => ({
1767
- inFallback: false
1768
- })),
1769
- show;
1770
- const listContext = useContext(SuspenseListContext);
1771
- const [registry, setRegistry] = createSignal([]);
1772
- if (listContext) {
1773
- show = listContext.register(createMemo(() => wrapper()().inFallback));
1774
- }
1775
- const resolved = createMemo(
1776
- prev => {
1777
- const reveal = props.revealOrder,
1778
- tail = props.tail,
1779
- { showContent = true, showFallback = true } = show ? show() : {},
1780
- reg = registry(),
1781
- reverse = reveal === "backwards";
1782
- if (reveal === "together") {
1783
- const all = reg.every(inFallback => !inFallback());
1784
- const res = reg.map(() => ({
1785
- showContent: all && showContent,
1786
- showFallback
1787
- }));
1788
- res.inFallback = !all;
1789
- return res;
1790
- }
1791
- let stop = false;
1792
- let inFallback = prev.inFallback;
1793
- const res = [];
1794
- for (let i = 0, len = reg.length; i < len; i++) {
1795
- const n = reverse ? len - i - 1 : i,
1796
- s = reg[n]();
1797
- if (!stop && !s) {
1798
- res[n] = {
1799
- showContent,
1800
- showFallback
1801
- };
1802
- } else {
1803
- const next = !stop;
1804
- if (next) inFallback = true;
1805
- res[n] = {
1806
- showContent: next,
1807
- showFallback: !tail || (next && tail === "collapsed") ? showFallback : false
1808
- };
1809
- stop = true;
1810
- }
1811
- }
1812
- if (!stop) inFallback = false;
1813
- res.inFallback = inFallback;
1814
- return res;
1815
- },
1816
- {
1817
- inFallback: false
360
+ return createErrorBoundary(
361
+ () => props.children,
362
+ (err, reset) => {
363
+ const f = props.fallback;
364
+ if (typeof f !== "function" || f.length == 0) console.error(err);
365
+ return typeof f === "function" && f.length ? f(err, reset) : f;
1818
366
  }
1819
367
  );
1820
- setWrapper(() => resolved);
1821
- return createComponent(SuspenseListContext.Provider, {
1822
- value: {
1823
- register: inFallback => {
1824
- let index;
1825
- setRegistry(registry => {
1826
- index = registry.length;
1827
- return [...registry, inFallback];
1828
- });
1829
- return createMemo(() => resolved()[index], undefined, {
1830
- equals: suspenseListEquals
1831
- });
1832
- }
1833
- },
1834
- get children() {
1835
- return props.children;
1836
- }
1837
- });
1838
368
  }
1839
369
  function Suspense(props) {
1840
- let counter = 0,
1841
- show,
1842
- ctx,
1843
- p,
1844
- flicker,
1845
- error;
1846
- const [inFallback, setFallback] = createSignal(false),
1847
- SuspenseContext = getSuspenseContext(),
1848
- store = {
1849
- increment: () => {
1850
- if (++counter === 1) setFallback(true);
1851
- },
1852
- decrement: () => {
1853
- if (--counter === 0) setFallback(false);
1854
- },
1855
- inFallback,
1856
- effects: [],
1857
- resolved: false
1858
- },
1859
- owner = getOwner();
1860
- if (sharedConfig.context && sharedConfig.load) {
1861
- const key = sharedConfig.getContextId();
1862
- let ref = sharedConfig.load(key);
1863
- if (ref) {
1864
- if (typeof ref !== "object" || ref.status !== "success") p = ref;
1865
- else sharedConfig.gather(key);
1866
- }
1867
- if (p && p !== "$$f") {
1868
- const [s, set] = createSignal(undefined, {
1869
- equals: false
1870
- });
1871
- flicker = s;
1872
- p.then(
1873
- () => {
1874
- if (sharedConfig.done) return set();
1875
- sharedConfig.gather(key);
1876
- setHydrateContext(ctx);
1877
- set();
1878
- setHydrateContext();
1879
- },
1880
- err => {
1881
- error = err;
1882
- set();
1883
- }
1884
- );
1885
- }
1886
- }
1887
- const listContext = useContext(SuspenseListContext);
1888
- if (listContext) show = listContext.register(store.inFallback);
1889
- let dispose;
1890
- onCleanup(() => dispose && dispose());
1891
- return createComponent(SuspenseContext.Provider, {
1892
- value: store,
1893
- get children() {
1894
- return createMemo(() => {
1895
- if (error) throw error;
1896
- ctx = sharedConfig.context;
1897
- if (flicker) {
1898
- flicker();
1899
- return (flicker = undefined);
1900
- }
1901
- if (ctx && p === "$$f") setHydrateContext();
1902
- const rendered = createMemo(() => props.children);
1903
- return createMemo(prev => {
1904
- const inFallback = store.inFallback(),
1905
- { showContent = true, showFallback = true } = show ? show() : {};
1906
- if ((!inFallback || (p && p !== "$$f")) && showContent) {
1907
- store.resolved = true;
1908
- dispose && dispose();
1909
- dispose = ctx = p = undefined;
1910
- resumeEffects(store.effects);
1911
- return rendered();
1912
- }
1913
- if (!showFallback) return;
1914
- if (dispose) return prev;
1915
- return createRoot(disposer => {
1916
- dispose = disposer;
1917
- if (ctx) {
1918
- setHydrateContext({
1919
- id: ctx.id + "F",
1920
- count: 0
1921
- });
1922
- ctx = undefined;
1923
- }
1924
- return props.fallback;
1925
- }, owner);
1926
- });
1927
- });
1928
- }
1929
- });
370
+ return createSuspense(
371
+ () => props.children,
372
+ () => props.fallback
373
+ );
1930
374
  }
1931
375
 
376
+ const DevHooks = {};
1932
377
  const DEV = {
1933
378
  hooks: DevHooks,
1934
- writeSignal,
1935
379
  registerGraph
1936
380
  };
1937
381
  if (globalThis) {
@@ -1944,57 +388,23 @@ if (globalThis) {
1944
388
 
1945
389
  export {
1946
390
  $DEVCOMP,
1947
- $PROXY,
1948
- $TRACK,
1949
391
  DEV,
1950
392
  ErrorBoundary,
1951
393
  For,
1952
- Index,
1953
394
  Match,
395
+ Repeat,
1954
396
  Show,
1955
397
  Suspense,
1956
- SuspenseList,
1957
398
  Switch,
1958
- batch,
1959
- cancelCallback,
1960
- catchError,
1961
399
  children,
1962
400
  createComponent,
1963
- createComputed,
1964
401
  createContext,
1965
- createDeferred,
1966
- createEffect,
1967
- createMemo,
1968
- createReaction,
1969
- createRenderEffect,
1970
- createResource,
1971
- createRoot,
1972
- createSelector,
1973
- createSignal,
1974
402
  createUniqueId,
1975
- enableExternalSource,
1976
403
  enableHydration,
1977
- enableScheduling,
1978
- equalFn,
1979
404
  from,
1980
- getListener,
1981
- getOwner,
1982
- indexArray,
1983
405
  lazy,
1984
- mapArray,
1985
- mergeProps,
1986
406
  observable,
1987
- on,
1988
- onCleanup,
1989
- onError,
1990
407
  onMount,
1991
- requestCallback,
1992
- resetErrorBoundaries,
1993
- runWithOwner,
1994
408
  sharedConfig,
1995
- splitProps,
1996
- startTransition,
1997
- untrack,
1998
- useContext,
1999
- useTransition
409
+ useContext
2000
410
  };