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/solid.cjs CHANGED
@@ -1,1027 +1,35 @@
1
1
  'use strict';
2
2
 
3
- let taskIdCounter = 1,
4
- isCallbackScheduled = false,
5
- isPerformingWork = false,
6
- taskQueue = [],
7
- currentTask = null,
8
- shouldYieldToHost = null,
9
- yieldInterval = 5,
10
- deadline = 0,
11
- maxYieldInterval = 300,
12
- scheduleCallback = null,
13
- scheduledCallback = null;
14
- const maxSigned31BitInt = 1073741823;
15
- function setupScheduler() {
16
- const channel = new MessageChannel(),
17
- port = channel.port2;
18
- scheduleCallback = () => port.postMessage(null);
19
- channel.port1.onmessage = () => {
20
- if (scheduledCallback !== null) {
21
- const currentTime = performance.now();
22
- deadline = currentTime + yieldInterval;
23
- const hasTimeRemaining = true;
24
- try {
25
- const hasMoreWork = scheduledCallback(hasTimeRemaining, currentTime);
26
- if (!hasMoreWork) {
27
- scheduledCallback = null;
28
- } else port.postMessage(null);
29
- } catch (error) {
30
- port.postMessage(null);
31
- throw error;
32
- }
33
- }
34
- };
35
- if (navigator && navigator.scheduling && navigator.scheduling.isInputPending) {
36
- const scheduling = navigator.scheduling;
37
- shouldYieldToHost = () => {
38
- const currentTime = performance.now();
39
- if (currentTime >= deadline) {
40
- if (scheduling.isInputPending()) {
41
- return true;
42
- }
43
- return currentTime >= maxYieldInterval;
44
- } else {
45
- return false;
46
- }
47
- };
48
- } else {
49
- shouldYieldToHost = () => performance.now() >= deadline;
50
- }
51
- }
52
- function enqueue(taskQueue, task) {
53
- function findIndex() {
54
- let m = 0;
55
- let n = taskQueue.length - 1;
56
- while (m <= n) {
57
- const k = n + m >> 1;
58
- const cmp = task.expirationTime - taskQueue[k].expirationTime;
59
- if (cmp > 0) m = k + 1;else if (cmp < 0) n = k - 1;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
- }
3
+ var signals = require('@solidjs/signals');
118
4
 
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
- }
146
-
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
- function createRoot(fn, detachedOwner) {
175
- const listener = Listener,
176
- owner = Owner,
177
- unowned = fn.length === 0,
178
- current = detachedOwner === undefined ? owner : detachedOwner,
179
- root = unowned ? UNOWNED : {
180
- owned: null,
181
- cleanups: null,
182
- context: current ? current.context : null,
183
- owner: current
184
- },
185
- updateFn = unowned ? fn : () => fn(() => untrack(() => cleanNode(root)));
186
- Owner = root;
187
- Listener = null;
188
- try {
189
- return runUpdates(updateFn, true);
190
- } finally {
191
- Listener = listener;
192
- Owner = owner;
193
- }
194
- }
195
- function createSignal(value, options) {
196
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
197
- const s = {
198
- value,
199
- observers: null,
200
- observerSlots: null,
201
- comparator: options.equals || undefined
202
- };
203
- const setter = value => {
204
- if (typeof value === "function") {
205
- if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue);else value = value(s.value);
206
- }
207
- return writeSignal(s, value);
208
- };
209
- return [readSignal.bind(s), setter];
210
- }
211
- function createComputed(fn, value, options) {
212
- const c = createComputation(fn, value, true, STALE);
213
- if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
214
- }
215
- function createRenderEffect(fn, value, options) {
216
- const c = createComputation(fn, value, false, STALE);
217
- if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c);
218
- }
219
- function createEffect(fn, value, options) {
220
- runEffects = runUserEffects;
221
- const c = createComputation(fn, value, false, STALE),
222
- s = SuspenseContext && useContext(SuspenseContext);
223
- if (s) c.suspense = s;
224
- if (!options || !options.render) c.user = true;
225
- Effects ? Effects.push(c) : updateComputation(c);
226
- }
227
- function createReaction(onInvalidate, options) {
228
- let fn;
229
- const c = createComputation(() => {
230
- fn ? fn() : untrack(onInvalidate);
231
- fn = undefined;
232
- }, undefined, false, 0),
233
- s = SuspenseContext && useContext(SuspenseContext);
234
- if (s) c.suspense = s;
235
- c.user = true;
236
- return tracking => {
237
- fn = tracking;
238
- updateComputation(c);
239
- };
240
- }
241
- function createMemo(fn, value, options) {
242
- options = options ? Object.assign({}, signalOptions, options) : signalOptions;
243
- const c = createComputation(fn, value, true, 0);
244
- c.observers = null;
245
- c.observerSlots = null;
246
- c.comparator = options.equals || undefined;
247
- if (Scheduler && Transition && Transition.running) {
248
- c.tState = STALE;
249
- Updates.push(c);
250
- } else updateComputation(c);
251
- return readSignal.bind(c);
252
- }
253
- function isPromise(v) {
254
- return v && typeof v === "object" && "then" in v;
255
- }
256
- function createResource(pSource, pFetcher, pOptions) {
257
- let source;
258
- let fetcher;
259
- let options;
260
- if (arguments.length === 2 && typeof pFetcher === "object" || arguments.length === 1) {
261
- source = true;
262
- fetcher = pSource;
263
- options = pFetcher || {};
264
- } else {
265
- source = pSource;
266
- fetcher = pFetcher;
267
- options = pOptions || {};
268
- }
269
- let pr = null,
270
- initP = NO_INIT,
271
- id = null,
272
- loadedUnderTransition = false,
273
- scheduled = false,
274
- resolved = "initialValue" in options,
275
- dynamic = typeof source === "function" && createMemo(source);
276
- const contexts = new Set(),
277
- [value, setValue] = (options.storage || createSignal)(options.initialValue),
278
- [error, setError] = createSignal(undefined),
279
- [track, trigger] = createSignal(undefined, {
280
- equals: false
281
- }),
282
- [state, setState] = createSignal(resolved ? "ready" : "unresolved");
283
- if (sharedConfig.context) {
284
- id = sharedConfig.getNextContextId();
285
- if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id);
286
- }
287
- function loadEnd(p, v, error, key) {
288
- if (pr === p) {
289
- pr = null;
290
- key !== undefined && (resolved = true);
291
- if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, {
292
- value: v
293
- }));
294
- initP = NO_INIT;
295
- if (Transition && p && loadedUnderTransition) {
296
- Transition.promises.delete(p);
297
- loadedUnderTransition = false;
298
- runUpdates(() => {
299
- Transition.running = true;
300
- completeLoad(v, error);
301
- }, false);
302
- } else completeLoad(v, error);
303
- }
304
- return v;
305
- }
306
- function completeLoad(v, err) {
307
- runUpdates(() => {
308
- if (err === undefined) setValue(() => v);
309
- setState(err !== undefined ? "errored" : resolved ? "ready" : "unresolved");
310
- setError(err);
311
- for (const c of contexts.keys()) c.decrement();
312
- contexts.clear();
313
- }, false);
314
- }
315
- function read() {
316
- const c = SuspenseContext && useContext(SuspenseContext),
317
- v = value(),
318
- err = error();
319
- if (err !== undefined && !pr) throw err;
320
- if (Listener && !Listener.user && c) {
321
- createComputed(() => {
322
- track();
323
- if (pr) {
324
- if (c.resolved && Transition && loadedUnderTransition) Transition.promises.add(pr);else if (!contexts.has(c)) {
325
- c.increment();
326
- contexts.add(c);
327
- }
328
- }
329
- });
330
- }
331
- return v;
332
- }
333
- function load(refetching = true) {
334
- if (refetching !== false && scheduled) return;
335
- scheduled = false;
336
- const lookup = dynamic ? dynamic() : source;
337
- loadedUnderTransition = Transition && Transition.running;
338
- if (lookup == null || lookup === false) {
339
- loadEnd(pr, untrack(value));
340
- return;
341
- }
342
- if (Transition && pr) Transition.promises.delete(pr);
343
- const p = initP !== NO_INIT ? initP : untrack(() => fetcher(lookup, {
344
- value: value(),
345
- refetching
346
- }));
347
- if (!isPromise(p)) {
348
- loadEnd(pr, p, undefined, lookup);
349
- return p;
350
- }
351
- pr = p;
352
- if ("value" in p) {
353
- if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, castError(p.value), lookup);
354
- return p;
355
- }
356
- scheduled = true;
357
- queueMicrotask(() => scheduled = false);
358
- runUpdates(() => {
359
- setState(resolved ? "refreshing" : "pending");
360
- trigger();
361
- }, false);
362
- return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, undefined, castError(e), lookup));
363
- }
364
- Object.defineProperties(read, {
365
- state: {
366
- get: () => state()
367
- },
368
- error: {
369
- get: () => error()
370
- },
371
- loading: {
372
- get() {
373
- const s = state();
374
- return s === "pending" || s === "refreshing";
375
- }
376
- },
377
- latest: {
378
- get() {
379
- if (!resolved) return read();
380
- const err = error();
381
- if (err && !pr) throw err;
382
- return value();
383
- }
384
- }
385
- });
386
- if (dynamic) createComputed(() => load(false));else load(false);
387
- return [read, {
388
- refetch: load,
389
- mutate: setValue
390
- }];
391
- }
392
- function createDeferred(source, options) {
393
- let t,
394
- timeout = options ? options.timeoutMs : undefined;
395
- const node = createComputation(() => {
396
- if (!t || !t.fn) t = requestCallback(() => setDeferred(() => node.value), timeout !== undefined ? {
397
- timeout
398
- } : undefined);
399
- return source();
400
- }, undefined, true);
401
- const [deferred, setDeferred] = createSignal(Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, options);
402
- updateComputation(node);
403
- setDeferred(() => Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value);
404
- return deferred;
405
- }
406
- function createSelector(source, fn = equalFn, options) {
407
- const subs = new Map();
408
- const node = createComputation(p => {
409
- const v = source();
410
- for (const [key, val] of subs.entries()) if (fn(key, v) !== fn(key, p)) {
411
- for (const c of val.values()) {
412
- c.state = STALE;
413
- if (c.pure) Updates.push(c);else Effects.push(c);
414
- }
415
- }
416
- return v;
417
- }, undefined, true, STALE);
418
- updateComputation(node);
419
- return key => {
420
- const listener = Listener;
421
- if (listener) {
422
- let l;
423
- if (l = subs.get(key)) l.add(listener);else subs.set(key, l = new Set([listener]));
424
- onCleanup(() => {
425
- l.delete(listener);
426
- !l.size && subs.delete(key);
427
- });
428
- }
429
- return fn(key, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value);
430
- };
431
- }
432
- function batch(fn) {
433
- return runUpdates(fn, false);
434
- }
435
- function untrack(fn) {
436
- if (!ExternalSourceConfig && Listener === null) return fn();
437
- const listener = Listener;
438
- Listener = null;
439
- try {
440
- if (ExternalSourceConfig) return ExternalSourceConfig.untrack(fn);
441
- return fn();
442
- } finally {
443
- Listener = listener;
444
- }
445
- }
446
- function on(deps, fn, options) {
447
- const isArray = Array.isArray(deps);
448
- let prevInput;
449
- let defer = options && options.defer;
450
- return prevValue => {
451
- let input;
452
- if (isArray) {
453
- input = Array(deps.length);
454
- for (let i = 0; i < deps.length; i++) input[i] = deps[i]();
455
- } else input = deps();
456
- if (defer) {
457
- defer = false;
458
- return prevValue;
459
- }
460
- const result = untrack(() => fn(input, prevInput, prevValue));
461
- prevInput = input;
462
- return result;
463
- };
464
- }
5
+ const $DEVCOMP = Symbol(0);
465
6
  function onMount(fn) {
466
- createEffect(() => untrack(fn));
467
- }
468
- function onCleanup(fn) {
469
- if (Owner === null) ;else if (Owner.cleanups === null) Owner.cleanups = [fn];else Owner.cleanups.push(fn);
470
- return fn;
471
- }
472
- function catchError(fn, handler) {
473
- ERROR || (ERROR = Symbol("error"));
474
- Owner = createComputation(undefined, undefined, true);
475
- Owner.context = {
476
- ...Owner.context,
477
- [ERROR]: [handler]
478
- };
479
- if (Transition && Transition.running) Transition.sources.add(Owner);
480
- try {
481
- return fn();
482
- } catch (err) {
483
- handleError(err);
484
- } finally {
485
- Owner = Owner.owner;
486
- }
487
- }
488
- function getListener() {
489
- return Listener;
490
- }
491
- function getOwner() {
492
- return Owner;
493
- }
494
- function runWithOwner(o, fn) {
495
- const prev = Owner;
496
- const prevListener = Listener;
497
- Owner = o;
498
- Listener = null;
499
- try {
500
- return runUpdates(fn, true);
501
- } catch (err) {
502
- handleError(err);
503
- } finally {
504
- Owner = prev;
505
- Listener = prevListener;
506
- }
507
- }
508
- function enableScheduling(scheduler = requestCallback) {
509
- Scheduler = scheduler;
510
- }
511
- function startTransition(fn) {
512
- if (Transition && Transition.running) {
513
- fn();
514
- return Transition.done;
515
- }
516
- const l = Listener;
517
- const o = Owner;
518
- return Promise.resolve().then(() => {
519
- Listener = l;
520
- Owner = o;
521
- let t;
522
- if (Scheduler || SuspenseContext) {
523
- t = Transition || (Transition = {
524
- sources: new Set(),
525
- effects: [],
526
- promises: new Set(),
527
- disposed: new Set(),
528
- queue: new Set(),
529
- running: true
530
- });
531
- t.done || (t.done = new Promise(res => t.resolve = res));
532
- t.running = true;
533
- }
534
- runUpdates(fn, false);
535
- Listener = Owner = null;
536
- return t ? t.done : undefined;
537
- });
538
- }
539
- const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
540
- function useTransition() {
541
- return [transPending, startTransition];
542
- }
543
- function resumeEffects(e) {
544
- Effects.push.apply(Effects, e);
545
- e.length = 0;
7
+ signals.createEffect(() => null, fn);
546
8
  }
547
9
  function createContext(defaultValue, options) {
548
- const id = Symbol("context");
549
- return {
550
- id,
551
- Provider: createProvider(id),
552
- defaultValue
553
- };
10
+ const id = Symbol(options && options.name || "");
11
+ function provider(props) {
12
+ return signals.createMemo(() => {
13
+ signals.setContext(provider, signals.untrack(() => props.value));
14
+ return children(() => props.children);
15
+ });
16
+ }
17
+ provider.id = id;
18
+ provider.defaultValue = defaultValue;
19
+ return provider;
554
20
  }
555
21
  function useContext(context) {
556
- let value;
557
- return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined ? value : context.defaultValue;
22
+ return signals.getContext(context);
558
23
  }
559
24
  function children(fn) {
560
- const children = createMemo(fn);
561
- const memo = createMemo(() => resolveChildren(children()));
25
+ const children = signals.createMemo(fn);
26
+ const memo = signals.createMemo(() => signals.flatten(children()));
562
27
  memo.toArray = () => {
563
28
  const c = memo();
564
29
  return Array.isArray(c) ? c : c != null ? [c] : [];
565
30
  };
566
31
  return memo;
567
32
  }
568
- let SuspenseContext;
569
- function getSuspenseContext() {
570
- return SuspenseContext || (SuspenseContext = createContext());
571
- }
572
- function enableExternalSource(factory, untrack = fn => fn()) {
573
- if (ExternalSourceConfig) {
574
- const {
575
- factory: oldFactory,
576
- untrack: oldUntrack
577
- } = ExternalSourceConfig;
578
- ExternalSourceConfig = {
579
- factory: (fn, trigger) => {
580
- const oldSource = oldFactory(fn, trigger);
581
- const source = factory(x => oldSource.track(x), trigger);
582
- return {
583
- track: x => source.track(x),
584
- dispose() {
585
- source.dispose();
586
- oldSource.dispose();
587
- }
588
- };
589
- },
590
- untrack: fn => oldUntrack(() => untrack(fn))
591
- };
592
- } else {
593
- ExternalSourceConfig = {
594
- factory,
595
- untrack
596
- };
597
- }
598
- }
599
- function readSignal() {
600
- const runningTransition = Transition && Transition.running;
601
- if (this.sources && (runningTransition ? this.tState : this.state)) {
602
- if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this);else {
603
- const updates = Updates;
604
- Updates = null;
605
- runUpdates(() => lookUpstream(this), false);
606
- Updates = updates;
607
- }
608
- }
609
- if (Listener) {
610
- const sSlot = this.observers ? this.observers.length : 0;
611
- if (!Listener.sources) {
612
- Listener.sources = [this];
613
- Listener.sourceSlots = [sSlot];
614
- } else {
615
- Listener.sources.push(this);
616
- Listener.sourceSlots.push(sSlot);
617
- }
618
- if (!this.observers) {
619
- this.observers = [Listener];
620
- this.observerSlots = [Listener.sources.length - 1];
621
- } else {
622
- this.observers.push(Listener);
623
- this.observerSlots.push(Listener.sources.length - 1);
624
- }
625
- }
626
- if (runningTransition && Transition.sources.has(this)) return this.tValue;
627
- return this.value;
628
- }
629
- function writeSignal(node, value, isComp) {
630
- let current = Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value;
631
- if (!node.comparator || !node.comparator(current, value)) {
632
- if (Transition) {
633
- const TransitionRunning = Transition.running;
634
- if (TransitionRunning || !isComp && Transition.sources.has(node)) {
635
- Transition.sources.add(node);
636
- node.tValue = value;
637
- }
638
- if (!TransitionRunning) node.value = value;
639
- } else node.value = value;
640
- if (node.observers && node.observers.length) {
641
- runUpdates(() => {
642
- for (let i = 0; i < node.observers.length; i += 1) {
643
- const o = node.observers[i];
644
- const TransitionRunning = Transition && Transition.running;
645
- if (TransitionRunning && Transition.disposed.has(o)) continue;
646
- if (TransitionRunning ? !o.tState : !o.state) {
647
- if (o.pure) Updates.push(o);else Effects.push(o);
648
- if (o.observers) markDownstream(o);
649
- }
650
- if (!TransitionRunning) o.state = STALE;else o.tState = STALE;
651
- }
652
- if (Updates.length > 10e5) {
653
- Updates = [];
654
- if (false) ;
655
- throw new Error();
656
- }
657
- }, false);
658
- }
659
- }
660
- return value;
661
- }
662
- function updateComputation(node) {
663
- if (!node.fn) return;
664
- cleanNode(node);
665
- const time = ExecCount;
666
- runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time);
667
- if (Transition && !Transition.running && Transition.sources.has(node)) {
668
- queueMicrotask(() => {
669
- runUpdates(() => {
670
- Transition && (Transition.running = true);
671
- Listener = Owner = node;
672
- runComputation(node, node.tValue, time);
673
- Listener = Owner = null;
674
- }, false);
675
- });
676
- }
677
- }
678
- function runComputation(node, value, time) {
679
- let nextValue;
680
- const owner = Owner,
681
- listener = Listener;
682
- Listener = Owner = node;
683
- try {
684
- nextValue = node.fn(value);
685
- } catch (err) {
686
- if (node.pure) {
687
- if (Transition && Transition.running) {
688
- node.tState = STALE;
689
- node.tOwned && node.tOwned.forEach(cleanNode);
690
- node.tOwned = undefined;
691
- } else {
692
- node.state = STALE;
693
- node.owned && node.owned.forEach(cleanNode);
694
- node.owned = null;
695
- }
696
- }
697
- node.updatedAt = time + 1;
698
- return handleError(err);
699
- } finally {
700
- Listener = listener;
701
- Owner = owner;
702
- }
703
- if (!node.updatedAt || node.updatedAt <= time) {
704
- if (node.updatedAt != null && "observers" in node) {
705
- writeSignal(node, nextValue, true);
706
- } else if (Transition && Transition.running && node.pure) {
707
- Transition.sources.add(node);
708
- node.tValue = nextValue;
709
- } else node.value = nextValue;
710
- node.updatedAt = time;
711
- }
712
- }
713
- function createComputation(fn, init, pure, state = STALE, options) {
714
- const c = {
715
- fn,
716
- state: state,
717
- updatedAt: null,
718
- owned: null,
719
- sources: null,
720
- sourceSlots: null,
721
- cleanups: null,
722
- value: init,
723
- owner: Owner,
724
- context: Owner ? Owner.context : null,
725
- pure
726
- };
727
- if (Transition && Transition.running) {
728
- c.state = 0;
729
- c.tState = state;
730
- }
731
- if (Owner === null) ;else if (Owner !== UNOWNED) {
732
- if (Transition && Transition.running && Owner.pure) {
733
- if (!Owner.tOwned) Owner.tOwned = [c];else Owner.tOwned.push(c);
734
- } else {
735
- if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c);
736
- }
737
- }
738
- if (ExternalSourceConfig && c.fn) {
739
- const [track, trigger] = createSignal(undefined, {
740
- equals: false
741
- });
742
- const ordinary = ExternalSourceConfig.factory(c.fn, trigger);
743
- onCleanup(() => ordinary.dispose());
744
- const triggerInTransition = () => startTransition(trigger).then(() => inTransition.dispose());
745
- const inTransition = ExternalSourceConfig.factory(c.fn, triggerInTransition);
746
- c.fn = x => {
747
- track();
748
- return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
749
- };
750
- }
751
- return c;
752
- }
753
- function runTop(node) {
754
- const runningTransition = Transition && Transition.running;
755
- if ((runningTransition ? node.tState : node.state) === 0) return;
756
- if ((runningTransition ? node.tState : node.state) === PENDING) return lookUpstream(node);
757
- if (node.suspense && untrack(node.suspense.inFallback)) return node.suspense.effects.push(node);
758
- const ancestors = [node];
759
- while ((node = node.owner) && (!node.updatedAt || node.updatedAt < ExecCount)) {
760
- if (runningTransition && Transition.disposed.has(node)) return;
761
- if (runningTransition ? node.tState : node.state) ancestors.push(node);
762
- }
763
- for (let i = ancestors.length - 1; i >= 0; i--) {
764
- node = ancestors[i];
765
- if (runningTransition) {
766
- let top = node,
767
- prev = ancestors[i + 1];
768
- while ((top = top.owner) && top !== prev) {
769
- if (Transition.disposed.has(top)) return;
770
- }
771
- }
772
- if ((runningTransition ? node.tState : node.state) === STALE) {
773
- updateComputation(node);
774
- } else if ((runningTransition ? node.tState : node.state) === PENDING) {
775
- const updates = Updates;
776
- Updates = null;
777
- runUpdates(() => lookUpstream(node, ancestors[0]), false);
778
- Updates = updates;
779
- }
780
- }
781
- }
782
- function runUpdates(fn, init) {
783
- if (Updates) return fn();
784
- let wait = false;
785
- if (!init) Updates = [];
786
- if (Effects) wait = true;else Effects = [];
787
- ExecCount++;
788
- try {
789
- const res = fn();
790
- completeUpdates(wait);
791
- return res;
792
- } catch (err) {
793
- if (!wait) Effects = null;
794
- Updates = null;
795
- handleError(err);
796
- }
797
- }
798
- function completeUpdates(wait) {
799
- if (Updates) {
800
- if (Scheduler && Transition && Transition.running) scheduleQueue(Updates);else runQueue(Updates);
801
- Updates = null;
802
- }
803
- if (wait) return;
804
- let res;
805
- if (Transition) {
806
- if (!Transition.promises.size && !Transition.queue.size) {
807
- const sources = Transition.sources;
808
- const disposed = Transition.disposed;
809
- Effects.push.apply(Effects, Transition.effects);
810
- res = Transition.resolve;
811
- for (const e of Effects) {
812
- "tState" in e && (e.state = e.tState);
813
- delete e.tState;
814
- }
815
- Transition = null;
816
- runUpdates(() => {
817
- for (const d of disposed) cleanNode(d);
818
- for (const v of sources) {
819
- v.value = v.tValue;
820
- if (v.owned) {
821
- for (let i = 0, len = v.owned.length; i < len; i++) cleanNode(v.owned[i]);
822
- }
823
- if (v.tOwned) v.owned = v.tOwned;
824
- delete v.tValue;
825
- delete v.tOwned;
826
- v.tState = 0;
827
- }
828
- setTransPending(false);
829
- }, false);
830
- } else if (Transition.running) {
831
- Transition.running = false;
832
- Transition.effects.push.apply(Transition.effects, Effects);
833
- Effects = null;
834
- setTransPending(true);
835
- return;
836
- }
837
- }
838
- const e = Effects;
839
- Effects = null;
840
- if (e.length) runUpdates(() => runEffects(e), false);
841
- if (res) res();
842
- }
843
- function runQueue(queue) {
844
- for (let i = 0; i < queue.length; i++) runTop(queue[i]);
845
- }
846
- function scheduleQueue(queue) {
847
- for (let i = 0; i < queue.length; i++) {
848
- const item = queue[i];
849
- const tasks = Transition.queue;
850
- if (!tasks.has(item)) {
851
- tasks.add(item);
852
- Scheduler(() => {
853
- tasks.delete(item);
854
- runUpdates(() => {
855
- Transition.running = true;
856
- runTop(item);
857
- }, false);
858
- Transition && (Transition.running = false);
859
- });
860
- }
861
- }
862
- }
863
- function runUserEffects(queue) {
864
- let i,
865
- userLength = 0;
866
- for (i = 0; i < queue.length; i++) {
867
- const e = queue[i];
868
- if (!e.user) runTop(e);else queue[userLength++] = e;
869
- }
870
- if (sharedConfig.context) {
871
- if (sharedConfig.count) {
872
- sharedConfig.effects || (sharedConfig.effects = []);
873
- sharedConfig.effects.push(...queue.slice(0, userLength));
874
- return;
875
- }
876
- setHydrateContext();
877
- }
878
- if (sharedConfig.effects && (sharedConfig.done || !sharedConfig.count)) {
879
- queue = [...sharedConfig.effects, ...queue];
880
- userLength += sharedConfig.effects.length;
881
- delete sharedConfig.effects;
882
- }
883
- for (i = 0; i < userLength; i++) runTop(queue[i]);
884
- }
885
- function lookUpstream(node, ignore) {
886
- const runningTransition = Transition && Transition.running;
887
- if (runningTransition) node.tState = 0;else node.state = 0;
888
- for (let i = 0; i < node.sources.length; i += 1) {
889
- const source = node.sources[i];
890
- if (source.sources) {
891
- const state = runningTransition ? source.tState : source.state;
892
- if (state === STALE) {
893
- if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) runTop(source);
894
- } else if (state === PENDING) lookUpstream(source, ignore);
895
- }
896
- }
897
- }
898
- function markDownstream(node) {
899
- const runningTransition = Transition && Transition.running;
900
- for (let i = 0; i < node.observers.length; i += 1) {
901
- const o = node.observers[i];
902
- if (runningTransition ? !o.tState : !o.state) {
903
- if (runningTransition) o.tState = PENDING;else o.state = PENDING;
904
- if (o.pure) Updates.push(o);else Effects.push(o);
905
- o.observers && markDownstream(o);
906
- }
907
- }
908
- }
909
- function cleanNode(node) {
910
- let i;
911
- if (node.sources) {
912
- while (node.sources.length) {
913
- const source = node.sources.pop(),
914
- index = node.sourceSlots.pop(),
915
- obs = source.observers;
916
- if (obs && obs.length) {
917
- const n = obs.pop(),
918
- s = source.observerSlots.pop();
919
- if (index < obs.length) {
920
- n.sourceSlots[s] = index;
921
- obs[index] = n;
922
- source.observerSlots[index] = s;
923
- }
924
- }
925
- }
926
- }
927
- if (node.tOwned) {
928
- for (i = node.tOwned.length - 1; i >= 0; i--) cleanNode(node.tOwned[i]);
929
- delete node.tOwned;
930
- }
931
- if (Transition && Transition.running && node.pure) {
932
- reset(node, true);
933
- } else if (node.owned) {
934
- for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]);
935
- node.owned = null;
936
- }
937
- if (node.cleanups) {
938
- for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i]();
939
- node.cleanups = null;
940
- }
941
- if (Transition && Transition.running) node.tState = 0;else node.state = 0;
942
- }
943
- function reset(node, top) {
944
- if (!top) {
945
- node.tState = 0;
946
- Transition.disposed.add(node);
947
- }
948
- if (node.owned) {
949
- for (let i = 0; i < node.owned.length; i++) reset(node.owned[i]);
950
- }
951
- }
952
- function castError(err) {
953
- if (err instanceof Error) return err;
954
- return new Error(typeof err === "string" ? err : "Unknown error", {
955
- cause: err
956
- });
957
- }
958
- function runErrors(err, fns, owner) {
959
- try {
960
- for (const f of fns) f(err);
961
- } catch (e) {
962
- handleError(e, owner && owner.owner || null);
963
- }
964
- }
965
- function handleError(err, owner = Owner) {
966
- const fns = ERROR && owner && owner.context && owner.context[ERROR];
967
- const error = castError(err);
968
- if (!fns) throw error;
969
- if (Effects) Effects.push({
970
- fn() {
971
- runErrors(error, fns, owner);
972
- },
973
- state: STALE
974
- });else runErrors(error, fns, owner);
975
- }
976
- function resolveChildren(children) {
977
- if (typeof children === "function" && !children.length) return resolveChildren(children());
978
- if (Array.isArray(children)) {
979
- const results = [];
980
- for (let i = 0; i < children.length; i++) {
981
- const result = resolveChildren(children[i]);
982
- Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
983
- }
984
- return results;
985
- }
986
- return children;
987
- }
988
- function createProvider(id, options) {
989
- return function provider(props) {
990
- let res;
991
- createRenderEffect(() => res = untrack(() => {
992
- Owner.context = {
993
- ...Owner.context,
994
- [id]: props.value
995
- };
996
- return children(() => props.children);
997
- }), undefined);
998
- return res;
999
- };
1000
- }
1001
- function onError(fn) {
1002
- ERROR || (ERROR = Symbol("error"));
1003
- if (Owner === null) ;else if (Owner.context === null || !Owner.context[ERROR]) {
1004
- Owner.context = {
1005
- ...Owner.context,
1006
- [ERROR]: [fn]
1007
- };
1008
- mutateContext(Owner, ERROR, [fn]);
1009
- } else Owner.context[ERROR].push(fn);
1010
- }
1011
- function mutateContext(o, key, value) {
1012
- if (o.owned) {
1013
- for (let i = 0; i < o.owned.length; i++) {
1014
- if (o.owned[i].context === o.context) mutateContext(o.owned[i], key, value);
1015
- if (!o.owned[i].context) {
1016
- o.owned[i].context = o.context;
1017
- mutateContext(o.owned[i], key, value);
1018
- } else if (!o.owned[i].context[key]) {
1019
- o.owned[i].context[key] = value;
1020
- mutateContext(o.owned[i], key, value);
1021
- }
1022
- }
1023
- }
1024
- }
1025
33
 
1026
34
  function observable(input) {
1027
35
  return {
@@ -1035,14 +43,13 @@ function observable(input) {
1035
43
  unsubscribe() {}
1036
44
  };
1037
45
  }
1038
- const dispose = createRoot(disposer => {
1039
- createEffect(() => {
1040
- const v = input();
1041
- untrack(() => handler(v));
46
+ const dispose = signals.createRoot(disposer => {
47
+ signals.createEffect(() => input(), v => {
48
+ handler(v);
1042
49
  });
1043
50
  return disposer;
1044
51
  });
1045
- if (getOwner()) onCleanup(dispose);
52
+ if (signals.getOwner()) signals.onCleanup(dispose);
1046
53
  return {
1047
54
  unsubscribe() {
1048
55
  dispose();
@@ -1055,177 +62,43 @@ function observable(input) {
1055
62
  };
1056
63
  }
1057
64
  function from(producer) {
1058
- const [s, set] = createSignal(undefined, {
65
+ const [s, set] = signals.createSignal(undefined, {
1059
66
  equals: false
1060
67
  });
1061
68
  if ("subscribe" in producer) {
1062
69
  const unsub = producer.subscribe(v => set(() => v));
1063
- onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
70
+ signals.onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
1064
71
  } else {
1065
72
  const clean = producer(set);
1066
- onCleanup(clean);
73
+ signals.onCleanup(clean);
1067
74
  }
1068
75
  return s;
1069
76
  }
1070
77
 
1071
- const FALLBACK = Symbol("fallback");
1072
- function dispose(d) {
1073
- for (let i = 0; i < d.length; i++) d[i]();
78
+ const sharedConfig = {
79
+ context: undefined,
80
+ registry: undefined,
81
+ done: false,
82
+ getContextId() {
83
+ return getContextId(this.context.count);
84
+ },
85
+ getNextContextId() {
86
+ return getContextId(this.context.count++);
87
+ }
88
+ };
89
+ function getContextId(count) {
90
+ const num = String(count),
91
+ len = num.length - 1;
92
+ return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
1074
93
  }
1075
- function mapArray(list, mapFn, options = {}) {
1076
- let items = [],
1077
- mapped = [],
1078
- disposers = [],
1079
- len = 0,
1080
- indexes = mapFn.length > 1 ? [] : null;
1081
- onCleanup(() => dispose(disposers));
1082
- return () => {
1083
- let newItems = list() || [],
1084
- newLen = newItems.length,
1085
- i,
1086
- j;
1087
- newItems[$TRACK];
1088
- return untrack(() => {
1089
- let newIndices, newIndicesNext, temp, tempdisposers, tempIndexes, start, end, newEnd, item;
1090
- if (newLen === 0) {
1091
- if (len !== 0) {
1092
- dispose(disposers);
1093
- disposers = [];
1094
- items = [];
1095
- mapped = [];
1096
- len = 0;
1097
- indexes && (indexes = []);
1098
- }
1099
- if (options.fallback) {
1100
- items = [FALLBACK];
1101
- mapped[0] = createRoot(disposer => {
1102
- disposers[0] = disposer;
1103
- return options.fallback();
1104
- });
1105
- len = 1;
1106
- }
1107
- }
1108
- else if (len === 0) {
1109
- mapped = new Array(newLen);
1110
- for (j = 0; j < newLen; j++) {
1111
- items[j] = newItems[j];
1112
- mapped[j] = createRoot(mapper);
1113
- }
1114
- len = newLen;
1115
- } else {
1116
- temp = new Array(newLen);
1117
- tempdisposers = new Array(newLen);
1118
- indexes && (tempIndexes = new Array(newLen));
1119
- for (start = 0, end = Math.min(len, newLen); start < end && items[start] === newItems[start]; start++);
1120
- for (end = len - 1, newEnd = newLen - 1; end >= start && newEnd >= start && items[end] === newItems[newEnd]; end--, newEnd--) {
1121
- temp[newEnd] = mapped[end];
1122
- tempdisposers[newEnd] = disposers[end];
1123
- indexes && (tempIndexes[newEnd] = indexes[end]);
1124
- }
1125
- newIndices = new Map();
1126
- newIndicesNext = new Array(newEnd + 1);
1127
- for (j = newEnd; j >= start; j--) {
1128
- item = newItems[j];
1129
- i = newIndices.get(item);
1130
- newIndicesNext[j] = i === undefined ? -1 : i;
1131
- newIndices.set(item, j);
1132
- }
1133
- for (i = start; i <= end; i++) {
1134
- item = items[i];
1135
- j = newIndices.get(item);
1136
- if (j !== undefined && j !== -1) {
1137
- temp[j] = mapped[i];
1138
- tempdisposers[j] = disposers[i];
1139
- indexes && (tempIndexes[j] = indexes[i]);
1140
- j = newIndicesNext[j];
1141
- newIndices.set(item, j);
1142
- } else disposers[i]();
1143
- }
1144
- for (j = start; j < newLen; j++) {
1145
- if (j in temp) {
1146
- mapped[j] = temp[j];
1147
- disposers[j] = tempdisposers[j];
1148
- if (indexes) {
1149
- indexes[j] = tempIndexes[j];
1150
- indexes[j](j);
1151
- }
1152
- } else mapped[j] = createRoot(mapper);
1153
- }
1154
- mapped = mapped.slice(0, len = newLen);
1155
- items = newItems.slice(0);
1156
- }
1157
- return mapped;
1158
- });
1159
- function mapper(disposer) {
1160
- disposers[j] = disposer;
1161
- if (indexes) {
1162
- const [s, set] = createSignal(j);
1163
- indexes[j] = set;
1164
- return mapFn(newItems[j], s);
1165
- }
1166
- return mapFn(newItems[j]);
1167
- }
1168
- };
94
+ function setHydrateContext(context) {
95
+ sharedConfig.context = context;
1169
96
  }
1170
- function indexArray(list, mapFn, options = {}) {
1171
- let items = [],
1172
- mapped = [],
1173
- disposers = [],
1174
- signals = [],
1175
- len = 0,
1176
- i;
1177
- onCleanup(() => dispose(disposers));
1178
- return () => {
1179
- const newItems = list() || [],
1180
- newLen = newItems.length;
1181
- newItems[$TRACK];
1182
- return untrack(() => {
1183
- if (newLen === 0) {
1184
- if (len !== 0) {
1185
- dispose(disposers);
1186
- disposers = [];
1187
- items = [];
1188
- mapped = [];
1189
- len = 0;
1190
- signals = [];
1191
- }
1192
- if (options.fallback) {
1193
- items = [FALLBACK];
1194
- mapped[0] = createRoot(disposer => {
1195
- disposers[0] = disposer;
1196
- return options.fallback();
1197
- });
1198
- len = 1;
1199
- }
1200
- return mapped;
1201
- }
1202
- if (items[0] === FALLBACK) {
1203
- disposers[0]();
1204
- disposers = [];
1205
- items = [];
1206
- mapped = [];
1207
- len = 0;
1208
- }
1209
- for (i = 0; i < newLen; i++) {
1210
- if (i < items.length && items[i] !== newItems[i]) {
1211
- signals[i](() => newItems[i]);
1212
- } else if (i >= items.length) {
1213
- mapped[i] = createRoot(mapper);
1214
- }
1215
- }
1216
- for (; i < items.length; i++) {
1217
- disposers[i]();
1218
- }
1219
- len = signals.length = disposers.length = newLen;
1220
- items = newItems.slice(0);
1221
- return mapped = mapped.slice(0, len);
1222
- });
1223
- function mapper(disposer) {
1224
- disposers[i] = disposer;
1225
- const [s, set] = createSignal(newItems[i]);
1226
- signals[i] = set;
1227
- return mapFn(s, i);
1228
- }
97
+ function nextHydrateContext() {
98
+ return {
99
+ ...sharedConfig.context,
100
+ id: sharedConfig.getNextContextId(),
101
+ count: 0
1229
102
  };
1230
103
  }
1231
104
 
@@ -1238,160 +111,12 @@ function createComponent(Comp, props) {
1238
111
  if (sharedConfig.context) {
1239
112
  const c = sharedConfig.context;
1240
113
  setHydrateContext(nextHydrateContext());
1241
- const r = untrack(() => Comp(props || {}));
114
+ const r = signals.untrack(() => Comp(props || {}));
1242
115
  setHydrateContext(c);
1243
116
  return r;
1244
117
  }
1245
118
  }
1246
- return untrack(() => Comp(props || {}));
1247
- }
1248
- function trueFn() {
1249
- return true;
1250
- }
1251
- const propTraps = {
1252
- get(_, property, receiver) {
1253
- if (property === $PROXY) return receiver;
1254
- return _.get(property);
1255
- },
1256
- has(_, property) {
1257
- if (property === $PROXY) return true;
1258
- return _.has(property);
1259
- },
1260
- set: trueFn,
1261
- deleteProperty: trueFn,
1262
- getOwnPropertyDescriptor(_, property) {
1263
- return {
1264
- configurable: true,
1265
- enumerable: true,
1266
- get() {
1267
- return _.get(property);
1268
- },
1269
- set: trueFn,
1270
- deleteProperty: trueFn
1271
- };
1272
- },
1273
- ownKeys(_) {
1274
- return _.keys();
1275
- }
1276
- };
1277
- function resolveSource(s) {
1278
- return !(s = typeof s === "function" ? s() : s) ? {} : s;
1279
- }
1280
- function resolveSources() {
1281
- for (let i = 0, length = this.length; i < length; ++i) {
1282
- const v = this[i]();
1283
- if (v !== undefined) return v;
1284
- }
1285
- }
1286
- function mergeProps(...sources) {
1287
- let proxy = false;
1288
- for (let i = 0; i < sources.length; i++) {
1289
- const s = sources[i];
1290
- proxy = proxy || !!s && $PROXY in s;
1291
- sources[i] = typeof s === "function" ? (proxy = true, createMemo(s)) : s;
1292
- }
1293
- if (SUPPORTS_PROXY && proxy) {
1294
- return new Proxy({
1295
- get(property) {
1296
- for (let i = sources.length - 1; i >= 0; i--) {
1297
- const v = resolveSource(sources[i])[property];
1298
- if (v !== undefined) return v;
1299
- }
1300
- },
1301
- has(property) {
1302
- for (let i = sources.length - 1; i >= 0; i--) {
1303
- if (property in resolveSource(sources[i])) return true;
1304
- }
1305
- return false;
1306
- },
1307
- keys() {
1308
- const keys = [];
1309
- for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i])));
1310
- return [...new Set(keys)];
1311
- }
1312
- }, propTraps);
1313
- }
1314
- const sourcesMap = {};
1315
- const defined = Object.create(null);
1316
- for (let i = sources.length - 1; i >= 0; i--) {
1317
- const source = sources[i];
1318
- if (!source) continue;
1319
- const sourceKeys = Object.getOwnPropertyNames(source);
1320
- for (let i = sourceKeys.length - 1; i >= 0; i--) {
1321
- const key = sourceKeys[i];
1322
- if (key === "__proto__" || key === "constructor") continue;
1323
- const desc = Object.getOwnPropertyDescriptor(source, key);
1324
- if (!defined[key]) {
1325
- defined[key] = desc.get ? {
1326
- enumerable: true,
1327
- configurable: true,
1328
- get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)])
1329
- } : desc.value !== undefined ? desc : undefined;
1330
- } else {
1331
- const sources = sourcesMap[key];
1332
- if (sources) {
1333
- if (desc.get) sources.push(desc.get.bind(source));else if (desc.value !== undefined) sources.push(() => desc.value);
1334
- }
1335
- }
1336
- }
1337
- }
1338
- const target = {};
1339
- const definedKeys = Object.keys(defined);
1340
- for (let i = definedKeys.length - 1; i >= 0; i--) {
1341
- const key = definedKeys[i],
1342
- desc = defined[key];
1343
- if (desc && desc.get) Object.defineProperty(target, key, desc);else target[key] = desc ? desc.value : undefined;
1344
- }
1345
- return target;
1346
- }
1347
- function splitProps(props, ...keys) {
1348
- if (SUPPORTS_PROXY && $PROXY in props) {
1349
- const blocked = new Set(keys.length > 1 ? keys.flat() : keys[0]);
1350
- const res = keys.map(k => {
1351
- return new Proxy({
1352
- get(property) {
1353
- return k.includes(property) ? props[property] : undefined;
1354
- },
1355
- has(property) {
1356
- return k.includes(property) && property in props;
1357
- },
1358
- keys() {
1359
- return k.filter(property => property in props);
1360
- }
1361
- }, propTraps);
1362
- });
1363
- res.push(new Proxy({
1364
- get(property) {
1365
- return blocked.has(property) ? undefined : props[property];
1366
- },
1367
- has(property) {
1368
- return blocked.has(property) ? false : property in props;
1369
- },
1370
- keys() {
1371
- return Object.keys(props).filter(k => !blocked.has(k));
1372
- }
1373
- }, propTraps));
1374
- return res;
1375
- }
1376
- const otherObject = {};
1377
- const objects = keys.map(() => ({}));
1378
- for (const propName of Object.getOwnPropertyNames(props)) {
1379
- const desc = Object.getOwnPropertyDescriptor(props, propName);
1380
- const isDefaultDesc = !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable;
1381
- let blocked = false;
1382
- let objectIndex = 0;
1383
- for (const k of keys) {
1384
- if (k.includes(propName)) {
1385
- blocked = true;
1386
- isDefaultDesc ? objects[objectIndex][propName] = desc.value : Object.defineProperty(objects[objectIndex], propName, desc);
1387
- }
1388
- ++objectIndex;
1389
- }
1390
- if (!blocked) {
1391
- isDefaultDesc ? otherObject[propName] = desc.value : Object.defineProperty(otherObject, propName, desc);
1392
- }
1393
- }
1394
- return [...objects, otherObject];
119
+ return signals.untrack(() => Comp(props || {}));
1395
120
  }
1396
121
  function lazy(fn) {
1397
122
  let comp;
@@ -1399,7 +124,7 @@ function lazy(fn) {
1399
124
  const wrap = props => {
1400
125
  const ctx = sharedConfig.context;
1401
126
  if (ctx) {
1402
- const [s, set] = createSignal();
127
+ const [s, set] = signals.createSignal();
1403
128
  sharedConfig.count || (sharedConfig.count = 0);
1404
129
  sharedConfig.count++;
1405
130
  (p || (p = fn())).then(mod => {
@@ -1410,12 +135,11 @@ function lazy(fn) {
1410
135
  });
1411
136
  comp = s;
1412
137
  } else if (!comp) {
1413
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
138
+ const s = signals.createAsync(() => (p || (p = fn())).then(mod => mod.default));
1414
139
  comp = s;
1415
140
  }
1416
141
  let Comp;
1417
- return createMemo(() => (Comp = comp()) ? untrack(() => {
1418
- if (false) ;
142
+ return signals.createMemo(() => (Comp = comp()) ? signals.untrack(() => {
1419
143
  if (!ctx || sharedConfig.done) return Comp(props);
1420
144
  const c = sharedConfig.context;
1421
145
  setHydrateContext(ctx);
@@ -1435,29 +159,32 @@ function createUniqueId() {
1435
159
 
1436
160
  const narrowedError = name => `Stale read from <${name}>.`;
1437
161
  function For(props) {
1438
- const fallback = "fallback" in props && {
162
+ const options = "fallback" in props ? {
163
+ keyed: props.keyed,
1439
164
  fallback: () => props.fallback
165
+ } : {
166
+ keyed: props.keyed
1440
167
  };
1441
- return createMemo(mapArray(() => props.each, props.children, fallback || undefined));
168
+ return signals.createMemo(signals.mapArray(() => props.each, props.children, options));
1442
169
  }
1443
- function Index(props) {
1444
- const fallback = "fallback" in props && {
170
+ function Repeat(props) {
171
+ const options = "fallback" in props ? {
1445
172
  fallback: () => props.fallback
1446
- };
1447
- return createMemo(indexArray(() => props.each, props.children, fallback || undefined));
173
+ } : {};
174
+ return signals.createMemo(signals.repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options));
1448
175
  }
1449
176
  function Show(props) {
1450
177
  const keyed = props.keyed;
1451
- const condition = createMemo(() => props.when, undefined, {
178
+ const condition = signals.createMemo(() => props.when, undefined, {
1452
179
  equals: (a, b) => keyed ? a === b : !a === !b
1453
180
  });
1454
- return createMemo(() => {
181
+ return signals.createMemo(() => {
1455
182
  const c = condition();
1456
183
  if (c) {
1457
184
  const child = props.children;
1458
185
  const fn = typeof child === "function" && child.length > 0;
1459
- return fn ? untrack(() => child(keyed ? c : () => {
1460
- if (!untrack(condition)) throw narrowedError("Show");
186
+ return fn ? signals.untrack(() => child(() => {
187
+ if (!signals.untrack(condition)) throw narrowedError("Show");
1461
188
  return props.when;
1462
189
  })) : child;
1463
190
  }
@@ -1468,7 +195,7 @@ function Switch(props) {
1468
195
  let keyed = false;
1469
196
  const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
1470
197
  const conditions = children(() => props.children),
1471
- evalConditions = createMemo(() => {
198
+ evalConditions = signals.createMemo(() => {
1472
199
  let conds = conditions();
1473
200
  if (!Array.isArray(conds)) conds = [conds];
1474
201
  for (let i = 0; i < conds.length; i++) {
@@ -1482,13 +209,13 @@ function Switch(props) {
1482
209
  }, undefined, {
1483
210
  equals
1484
211
  });
1485
- return createMemo(() => {
212
+ return signals.createMemo(() => {
1486
213
  const [index, when, cond] = evalConditions();
1487
214
  if (index < 0) return props.fallback;
1488
215
  const c = cond.children;
1489
216
  const fn = typeof c === "function" && c.length > 0;
1490
- return fn ? untrack(() => c(keyed ? when : () => {
1491
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
217
+ return fn ? signals.untrack(() => c(() => {
218
+ if (signals.untrack(evalConditions)[0] !== index) throw narrowedError("Match");
1492
219
  return cond.when;
1493
220
  })) : c;
1494
221
  }, undefined, undefined);
@@ -1496,248 +223,159 @@ function Switch(props) {
1496
223
  function Match(props) {
1497
224
  return props;
1498
225
  }
1499
- let Errors;
1500
- function resetErrorBoundaries() {
1501
- Errors && [...Errors].forEach(fn => fn());
1502
- }
1503
226
  function ErrorBoundary(props) {
1504
- let err;
1505
- if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.getContextId());
1506
- const [errored, setErrored] = createSignal(err, undefined);
1507
- Errors || (Errors = new Set());
1508
- Errors.add(setErrored);
1509
- onCleanup(() => Errors.delete(setErrored));
1510
- return createMemo(() => {
1511
- let e;
1512
- if (e = errored()) {
1513
- const f = props.fallback;
1514
- return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f;
1515
- }
1516
- return catchError(() => props.children, setErrored);
1517
- }, undefined, undefined);
1518
- }
1519
-
1520
- const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback;
1521
- const SuspenseListContext = /* #__PURE__ */createContext();
1522
- function SuspenseList(props) {
1523
- let [wrapper, setWrapper] = createSignal(() => ({
1524
- inFallback: false
1525
- })),
1526
- show;
1527
- const listContext = useContext(SuspenseListContext);
1528
- const [registry, setRegistry] = createSignal([]);
1529
- if (listContext) {
1530
- show = listContext.register(createMemo(() => wrapper()().inFallback));
1531
- }
1532
- const resolved = createMemo(prev => {
1533
- const reveal = props.revealOrder,
1534
- tail = props.tail,
1535
- {
1536
- showContent = true,
1537
- showFallback = true
1538
- } = show ? show() : {},
1539
- reg = registry(),
1540
- reverse = reveal === "backwards";
1541
- if (reveal === "together") {
1542
- const all = reg.every(inFallback => !inFallback());
1543
- const res = reg.map(() => ({
1544
- showContent: all && showContent,
1545
- showFallback
1546
- }));
1547
- res.inFallback = !all;
1548
- return res;
1549
- }
1550
- let stop = false;
1551
- let inFallback = prev.inFallback;
1552
- const res = [];
1553
- for (let i = 0, len = reg.length; i < len; i++) {
1554
- const n = reverse ? len - i - 1 : i,
1555
- s = reg[n]();
1556
- if (!stop && !s) {
1557
- res[n] = {
1558
- showContent,
1559
- showFallback
1560
- };
1561
- } else {
1562
- const next = !stop;
1563
- if (next) inFallback = true;
1564
- res[n] = {
1565
- showContent: next,
1566
- showFallback: !tail || next && tail === "collapsed" ? showFallback : false
1567
- };
1568
- stop = true;
1569
- }
1570
- }
1571
- if (!stop) inFallback = false;
1572
- res.inFallback = inFallback;
1573
- return res;
1574
- }, {
1575
- inFallback: false
1576
- });
1577
- setWrapper(() => resolved);
1578
- return createComponent(SuspenseListContext.Provider, {
1579
- value: {
1580
- register: inFallback => {
1581
- let index;
1582
- setRegistry(registry => {
1583
- index = registry.length;
1584
- return [...registry, inFallback];
1585
- });
1586
- return createMemo(() => resolved()[index], undefined, {
1587
- equals: suspenseListEquals
1588
- });
1589
- }
1590
- },
1591
- get children() {
1592
- return props.children;
1593
- }
227
+ return signals.createErrorBoundary(() => props.children, (err, reset) => {
228
+ const f = props.fallback;
229
+ return typeof f === "function" && f.length ? f(err, reset) : f;
1594
230
  });
1595
231
  }
1596
232
  function Suspense(props) {
1597
- let counter = 0,
1598
- show,
1599
- ctx,
1600
- p,
1601
- flicker,
1602
- error;
1603
- const [inFallback, setFallback] = createSignal(false),
1604
- SuspenseContext = getSuspenseContext(),
1605
- store = {
1606
- increment: () => {
1607
- if (++counter === 1) setFallback(true);
1608
- },
1609
- decrement: () => {
1610
- if (--counter === 0) setFallback(false);
1611
- },
1612
- inFallback,
1613
- effects: [],
1614
- resolved: false
1615
- },
1616
- owner = getOwner();
1617
- if (sharedConfig.context && sharedConfig.load) {
1618
- const key = sharedConfig.getContextId();
1619
- let ref = sharedConfig.load(key);
1620
- if (ref) {
1621
- if (typeof ref !== "object" || ref.status !== "success") p = ref;else sharedConfig.gather(key);
1622
- }
1623
- if (p && p !== "$$f") {
1624
- const [s, set] = createSignal(undefined, {
1625
- equals: false
1626
- });
1627
- flicker = s;
1628
- p.then(() => {
1629
- if (sharedConfig.done) return set();
1630
- sharedConfig.gather(key);
1631
- setHydrateContext(ctx);
1632
- set();
1633
- setHydrateContext();
1634
- }, err => {
1635
- error = err;
1636
- set();
1637
- });
1638
- }
1639
- }
1640
- const listContext = useContext(SuspenseListContext);
1641
- if (listContext) show = listContext.register(store.inFallback);
1642
- let dispose;
1643
- onCleanup(() => dispose && dispose());
1644
- return createComponent(SuspenseContext.Provider, {
1645
- value: store,
1646
- get children() {
1647
- return createMemo(() => {
1648
- if (error) throw error;
1649
- ctx = sharedConfig.context;
1650
- if (flicker) {
1651
- flicker();
1652
- return flicker = undefined;
1653
- }
1654
- if (ctx && p === "$$f") setHydrateContext();
1655
- const rendered = createMemo(() => props.children);
1656
- return createMemo(prev => {
1657
- const inFallback = store.inFallback(),
1658
- {
1659
- showContent = true,
1660
- showFallback = true
1661
- } = show ? show() : {};
1662
- if ((!inFallback || p && p !== "$$f") && showContent) {
1663
- store.resolved = true;
1664
- dispose && dispose();
1665
- dispose = ctx = p = undefined;
1666
- resumeEffects(store.effects);
1667
- return rendered();
1668
- }
1669
- if (!showFallback) return;
1670
- if (dispose) return prev;
1671
- return createRoot(disposer => {
1672
- dispose = disposer;
1673
- if (ctx) {
1674
- setHydrateContext({
1675
- id: ctx.id + "F",
1676
- count: 0
1677
- });
1678
- ctx = undefined;
1679
- }
1680
- return props.fallback;
1681
- }, owner);
1682
- });
1683
- });
1684
- }
1685
- });
233
+ return signals.createSuspense(() => props.children, () => props.fallback);
1686
234
  }
1687
235
 
1688
236
  const DEV = undefined;
1689
237
 
238
+ Object.defineProperty(exports, "$PROXY", {
239
+ enumerable: true,
240
+ get: function () { return signals.$PROXY; }
241
+ });
242
+ Object.defineProperty(exports, "$RAW", {
243
+ enumerable: true,
244
+ get: function () { return signals.$RAW; }
245
+ });
246
+ Object.defineProperty(exports, "$TRACK", {
247
+ enumerable: true,
248
+ get: function () { return signals.$TRACK; }
249
+ });
250
+ Object.defineProperty(exports, "catchError", {
251
+ enumerable: true,
252
+ get: function () { return signals.catchError; }
253
+ });
254
+ Object.defineProperty(exports, "createAsync", {
255
+ enumerable: true,
256
+ get: function () { return signals.createAsync; }
257
+ });
258
+ Object.defineProperty(exports, "createEffect", {
259
+ enumerable: true,
260
+ get: function () { return signals.createEffect; }
261
+ });
262
+ Object.defineProperty(exports, "createMemo", {
263
+ enumerable: true,
264
+ get: function () { return signals.createMemo; }
265
+ });
266
+ Object.defineProperty(exports, "createProjection", {
267
+ enumerable: true,
268
+ get: function () { return signals.createProjection; }
269
+ });
270
+ Object.defineProperty(exports, "createReaction", {
271
+ enumerable: true,
272
+ get: function () { return signals.createReaction; }
273
+ });
274
+ Object.defineProperty(exports, "createRenderEffect", {
275
+ enumerable: true,
276
+ get: function () { return signals.createRenderEffect; }
277
+ });
278
+ Object.defineProperty(exports, "createRoot", {
279
+ enumerable: true,
280
+ get: function () { return signals.createRoot; }
281
+ });
282
+ Object.defineProperty(exports, "createSignal", {
283
+ enumerable: true,
284
+ get: function () { return signals.createSignal; }
285
+ });
286
+ Object.defineProperty(exports, "createStore", {
287
+ enumerable: true,
288
+ get: function () { return signals.createStore; }
289
+ });
290
+ Object.defineProperty(exports, "flatten", {
291
+ enumerable: true,
292
+ get: function () { return signals.flatten; }
293
+ });
294
+ Object.defineProperty(exports, "flushSync", {
295
+ enumerable: true,
296
+ get: function () { return signals.flushSync; }
297
+ });
298
+ Object.defineProperty(exports, "getObserver", {
299
+ enumerable: true,
300
+ get: function () { return signals.getObserver; }
301
+ });
302
+ Object.defineProperty(exports, "getOwner", {
303
+ enumerable: true,
304
+ get: function () { return signals.getOwner; }
305
+ });
306
+ Object.defineProperty(exports, "isEqual", {
307
+ enumerable: true,
308
+ get: function () { return signals.isEqual; }
309
+ });
310
+ Object.defineProperty(exports, "isStale", {
311
+ enumerable: true,
312
+ get: function () { return signals.isStale; }
313
+ });
314
+ Object.defineProperty(exports, "isWrappable", {
315
+ enumerable: true,
316
+ get: function () { return signals.isWrappable; }
317
+ });
318
+ Object.defineProperty(exports, "latest", {
319
+ enumerable: true,
320
+ get: function () { return signals.latest; }
321
+ });
322
+ Object.defineProperty(exports, "mapArray", {
323
+ enumerable: true,
324
+ get: function () { return signals.mapArray; }
325
+ });
326
+ Object.defineProperty(exports, "merge", {
327
+ enumerable: true,
328
+ get: function () { return signals.merge; }
329
+ });
330
+ Object.defineProperty(exports, "omit", {
331
+ enumerable: true,
332
+ get: function () { return signals.omit; }
333
+ });
334
+ Object.defineProperty(exports, "onCleanup", {
335
+ enumerable: true,
336
+ get: function () { return signals.onCleanup; }
337
+ });
338
+ Object.defineProperty(exports, "reconcile", {
339
+ enumerable: true,
340
+ get: function () { return signals.reconcile; }
341
+ });
342
+ Object.defineProperty(exports, "repeat", {
343
+ enumerable: true,
344
+ get: function () { return signals.repeat; }
345
+ });
346
+ Object.defineProperty(exports, "resolve", {
347
+ enumerable: true,
348
+ get: function () { return signals.resolve; }
349
+ });
350
+ Object.defineProperty(exports, "runWithOwner", {
351
+ enumerable: true,
352
+ get: function () { return signals.runWithOwner; }
353
+ });
354
+ Object.defineProperty(exports, "untrack", {
355
+ enumerable: true,
356
+ get: function () { return signals.untrack; }
357
+ });
358
+ Object.defineProperty(exports, "unwrap", {
359
+ enumerable: true,
360
+ get: function () { return signals.unwrap; }
361
+ });
1690
362
  exports.$DEVCOMP = $DEVCOMP;
1691
- exports.$PROXY = $PROXY;
1692
- exports.$TRACK = $TRACK;
1693
363
  exports.DEV = DEV;
1694
364
  exports.ErrorBoundary = ErrorBoundary;
1695
365
  exports.For = For;
1696
- exports.Index = Index;
1697
366
  exports.Match = Match;
367
+ exports.Repeat = Repeat;
1698
368
  exports.Show = Show;
1699
369
  exports.Suspense = Suspense;
1700
- exports.SuspenseList = SuspenseList;
1701
370
  exports.Switch = Switch;
1702
- exports.batch = batch;
1703
- exports.cancelCallback = cancelCallback;
1704
- exports.catchError = catchError;
1705
371
  exports.children = children;
1706
372
  exports.createComponent = createComponent;
1707
- exports.createComputed = createComputed;
1708
373
  exports.createContext = createContext;
1709
- exports.createDeferred = createDeferred;
1710
- exports.createEffect = createEffect;
1711
- exports.createMemo = createMemo;
1712
- exports.createReaction = createReaction;
1713
- exports.createRenderEffect = createRenderEffect;
1714
- exports.createResource = createResource;
1715
- exports.createRoot = createRoot;
1716
- exports.createSelector = createSelector;
1717
- exports.createSignal = createSignal;
1718
374
  exports.createUniqueId = createUniqueId;
1719
- exports.enableExternalSource = enableExternalSource;
1720
375
  exports.enableHydration = enableHydration;
1721
- exports.enableScheduling = enableScheduling;
1722
- exports.equalFn = equalFn;
1723
376
  exports.from = from;
1724
- exports.getListener = getListener;
1725
- exports.getOwner = getOwner;
1726
- exports.indexArray = indexArray;
1727
377
  exports.lazy = lazy;
1728
- exports.mapArray = mapArray;
1729
- exports.mergeProps = mergeProps;
1730
378
  exports.observable = observable;
1731
- exports.on = on;
1732
- exports.onCleanup = onCleanup;
1733
- exports.onError = onError;
1734
379
  exports.onMount = onMount;
1735
- exports.requestCallback = requestCallback;
1736
- exports.resetErrorBoundaries = resetErrorBoundaries;
1737
- exports.runWithOwner = runWithOwner;
1738
380
  exports.sharedConfig = sharedConfig;
1739
- exports.splitProps = splitProps;
1740
- exports.startTransition = startTransition;
1741
- exports.untrack = untrack;
1742
381
  exports.useContext = useContext;
1743
- exports.useTransition = useTransition;