cross-state 0.25.2 → 0.27.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.
@@ -1,64 +1,86 @@
1
1
  "use strict";
2
- const require$$0 = require("react");
3
2
  const store = require("./store.cjs");
3
+ const require$$0 = require("react");
4
4
  const jsxRuntime = require("react/jsx-runtime");
5
5
  const hash = require("./hash.cjs");
6
- var withSelector = { exports: {} };
7
- var withSelector_production_min = {};
8
- var shim = { exports: {} };
9
- var useSyncExternalStoreShim_production_min = {};
10
- /**
11
- * @license React
12
- * use-sync-external-store-shim.production.min.js
13
- *
14
- * Copyright (c) Facebook, Inc. and its affiliates.
15
- *
16
- * This source code is licensed under the MIT license found in the
17
- * LICENSE file in the root directory of this source tree.
18
- */
19
- var hasRequiredUseSyncExternalStoreShim_production_min;
20
- function requireUseSyncExternalStoreShim_production_min() {
21
- if (hasRequiredUseSyncExternalStoreShim_production_min)
22
- return useSyncExternalStoreShim_production_min;
23
- hasRequiredUseSyncExternalStoreShim_production_min = 1;
24
- var e = require$$0;
25
- function h(a, b) {
26
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
27
- }
28
- var k = "function" === typeof Object.is ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
29
- function q(a, b) {
30
- var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
31
- n(function() {
32
- c.value = d;
33
- c.getSnapshot = b;
34
- r(c) && g({ inst: c });
35
- }, [a, d, b]);
36
- m(function() {
37
- r(c) && g({ inst: c });
38
- return a(function() {
39
- r(c) && g({ inst: c });
40
- });
41
- }, [a]);
42
- p(d);
43
- return d;
6
+ const unwrapProxySymbol = /* @__PURE__ */ Symbol("unwrapProxy");
7
+ function isPlainObject(value) {
8
+ return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
9
+ }
10
+ function trackingProxy(value, equals = store.deepEqual) {
11
+ if (!isPlainObject(value) && !Array.isArray(value)) {
12
+ return [value, (other) => equals(value, other)];
44
13
  }
45
- function r(a) {
46
- var b = a.getSnapshot;
47
- a = a.value;
48
- try {
49
- var d = b();
50
- return !k(a, d);
51
- } catch (f) {
52
- return true;
14
+ value = value[unwrapProxySymbol] ?? value;
15
+ const deps = new Array();
16
+ const revokations = new Array();
17
+ let revoked = false;
18
+ function trackComplexProp(function_, ...args) {
19
+ const [proxiedValue, equals2, revoke] = trackingProxy(function_(value, ...args));
20
+ deps.push((otherValue) => {
21
+ if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {
22
+ return false;
23
+ }
24
+ return equals2(function_(otherValue, ...args));
25
+ });
26
+ if (revoke) {
27
+ revokations.push(revoke);
53
28
  }
29
+ return proxiedValue;
54
30
  }
55
- function t(a, b) {
56
- return b();
31
+ function trackSimpleProp(function_, ...args) {
32
+ const calculatedValue = function_(value, ...args);
33
+ deps.push((otherValue) => {
34
+ return function_(otherValue, ...args) === calculatedValue;
35
+ });
36
+ return calculatedValue;
57
37
  }
58
- var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
59
- useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
60
- return useSyncExternalStoreShim_production_min;
38
+ const proxy = new Proxy(value, {
39
+ get(target, p, receiver) {
40
+ if (p === unwrapProxySymbol) {
41
+ return value;
42
+ }
43
+ if (revoked) {
44
+ return target[p];
45
+ }
46
+ const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
47
+ if (writable === false && configurable === false) {
48
+ return target[p];
49
+ }
50
+ return trackComplexProp(Reflect.get, p, receiver);
51
+ },
52
+ getOwnPropertyDescriptor(target, p) {
53
+ const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
54
+ if (writable === false && configurable === false) {
55
+ return Reflect.getOwnPropertyDescriptor(target, p);
56
+ }
57
+ return trackComplexProp(Reflect.getOwnPropertyDescriptor, p);
58
+ },
59
+ ownKeys() {
60
+ return trackComplexProp(Reflect.ownKeys);
61
+ },
62
+ getPrototypeOf() {
63
+ return trackSimpleProp(Reflect.getPrototypeOf);
64
+ },
65
+ has(_target, p) {
66
+ return trackSimpleProp(Reflect.has, p);
67
+ },
68
+ isExtensible() {
69
+ return trackSimpleProp(Reflect.isExtensible);
70
+ }
71
+ });
72
+ return [
73
+ proxy,
74
+ (other) => !!other && deps.every((equals2) => equals2(other)),
75
+ () => {
76
+ revoked = true;
77
+ revokations.forEach((revoke) => revoke());
78
+ }
79
+ ];
61
80
  }
81
+ var withSelector = { exports: {} };
82
+ var withSelector_development = {};
83
+ var shim = { exports: {} };
62
84
  var useSyncExternalStoreShim_development = {};
63
85
  /**
64
86
  * @license React
@@ -190,84 +212,71 @@ function requireUseSyncExternalStoreShim_development() {
190
212
  }
191
213
  return useSyncExternalStoreShim_development;
192
214
  }
193
- var hasRequiredShim;
194
- function requireShim() {
195
- if (hasRequiredShim)
196
- return shim.exports;
197
- hasRequiredShim = 1;
198
- if (process.env.NODE_ENV === "production") {
199
- shim.exports = requireUseSyncExternalStoreShim_production_min();
200
- } else {
201
- shim.exports = requireUseSyncExternalStoreShim_development();
202
- }
203
- return shim.exports;
204
- }
215
+ var useSyncExternalStoreShim_production_min = {};
205
216
  /**
206
217
  * @license React
207
- * use-sync-external-store-shim/with-selector.production.min.js
218
+ * use-sync-external-store-shim.production.min.js
208
219
  *
209
220
  * Copyright (c) Facebook, Inc. and its affiliates.
210
221
  *
211
222
  * This source code is licensed under the MIT license found in the
212
223
  * LICENSE file in the root directory of this source tree.
213
224
  */
214
- var hasRequiredWithSelector_production_min;
215
- function requireWithSelector_production_min() {
216
- if (hasRequiredWithSelector_production_min)
217
- return withSelector_production_min;
218
- hasRequiredWithSelector_production_min = 1;
219
- var h = require$$0, n = requireShim();
220
- function p(a, b) {
225
+ var hasRequiredUseSyncExternalStoreShim_production_min;
226
+ function requireUseSyncExternalStoreShim_production_min() {
227
+ if (hasRequiredUseSyncExternalStoreShim_production_min)
228
+ return useSyncExternalStoreShim_production_min;
229
+ hasRequiredUseSyncExternalStoreShim_production_min = 1;
230
+ var e = require$$0;
231
+ function h(a, b) {
221
232
  return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
222
233
  }
223
- var q = "function" === typeof Object.is ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
224
- withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
225
- var c = t(null);
226
- if (null === c.current) {
227
- var f = { hasValue: false, value: null };
228
- c.current = f;
229
- } else
230
- f = c.current;
231
- c = v(function() {
232
- function a2(a3) {
233
- if (!c2) {
234
- c2 = true;
235
- d2 = a3;
236
- a3 = l(a3);
237
- if (void 0 !== g && f.hasValue) {
238
- var b2 = f.value;
239
- if (g(b2, a3))
240
- return k = b2;
241
- }
242
- return k = a3;
243
- }
244
- b2 = k;
245
- if (q(d2, a3))
246
- return b2;
247
- var e2 = l(a3);
248
- if (void 0 !== g && g(b2, e2))
249
- return b2;
250
- d2 = a3;
251
- return k = e2;
252
- }
253
- var c2 = false, d2, k, m = void 0 === e ? null : e;
254
- return [function() {
255
- return a2(b());
256
- }, null === m ? void 0 : function() {
257
- return a2(m());
258
- }];
259
- }, [b, e, l, g]);
260
- var d = r(a, c[0], c[1]);
261
- u(function() {
262
- f.hasValue = true;
263
- f.value = d;
264
- }, [d]);
265
- w(d);
234
+ var k = "function" === typeof Object.is ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
235
+ function q(a, b) {
236
+ var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1];
237
+ n(function() {
238
+ c.value = d;
239
+ c.getSnapshot = b;
240
+ r(c) && g({ inst: c });
241
+ }, [a, d, b]);
242
+ m(function() {
243
+ r(c) && g({ inst: c });
244
+ return a(function() {
245
+ r(c) && g({ inst: c });
246
+ });
247
+ }, [a]);
248
+ p(d);
266
249
  return d;
267
- };
268
- return withSelector_production_min;
250
+ }
251
+ function r(a) {
252
+ var b = a.getSnapshot;
253
+ a = a.value;
254
+ try {
255
+ var d = b();
256
+ return !k(a, d);
257
+ } catch (f) {
258
+ return true;
259
+ }
260
+ }
261
+ function t(a, b) {
262
+ return b();
263
+ }
264
+ var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
265
+ useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
266
+ return useSyncExternalStoreShim_production_min;
267
+ }
268
+ var hasRequiredShim;
269
+ function requireShim() {
270
+ if (hasRequiredShim)
271
+ return shim.exports;
272
+ hasRequiredShim = 1;
273
+ if (process.env.NODE_ENV === "production") {
274
+ shim.exports = requireUseSyncExternalStoreShim_production_min();
275
+ } else {
276
+ shim.exports = requireUseSyncExternalStoreShim_development();
277
+ }
278
+ return shim.exports;
269
279
  }
270
- var withSelector_development = {};
271
280
  /**
272
281
  * @license React
273
282
  * use-sync-external-store-shim/with-selector.development.js
@@ -366,87 +375,78 @@ function requireWithSelector_development() {
366
375
  }
367
376
  return withSelector_development;
368
377
  }
378
+ var withSelector_production_min = {};
379
+ /**
380
+ * @license React
381
+ * use-sync-external-store-shim/with-selector.production.min.js
382
+ *
383
+ * Copyright (c) Facebook, Inc. and its affiliates.
384
+ *
385
+ * This source code is licensed under the MIT license found in the
386
+ * LICENSE file in the root directory of this source tree.
387
+ */
388
+ var hasRequiredWithSelector_production_min;
389
+ function requireWithSelector_production_min() {
390
+ if (hasRequiredWithSelector_production_min)
391
+ return withSelector_production_min;
392
+ hasRequiredWithSelector_production_min = 1;
393
+ var h = require$$0, n = requireShim();
394
+ function p(a, b) {
395
+ return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
396
+ }
397
+ var q = "function" === typeof Object.is ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
398
+ withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
399
+ var c = t(null);
400
+ if (null === c.current) {
401
+ var f = { hasValue: false, value: null };
402
+ c.current = f;
403
+ } else
404
+ f = c.current;
405
+ c = v(function() {
406
+ function a2(a3) {
407
+ if (!c2) {
408
+ c2 = true;
409
+ d2 = a3;
410
+ a3 = l(a3);
411
+ if (void 0 !== g && f.hasValue) {
412
+ var b2 = f.value;
413
+ if (g(b2, a3))
414
+ return k = b2;
415
+ }
416
+ return k = a3;
417
+ }
418
+ b2 = k;
419
+ if (q(d2, a3))
420
+ return b2;
421
+ var e2 = l(a3);
422
+ if (void 0 !== g && g(b2, e2))
423
+ return b2;
424
+ d2 = a3;
425
+ return k = e2;
426
+ }
427
+ var c2 = false, d2, k, m = void 0 === e ? null : e;
428
+ return [function() {
429
+ return a2(b());
430
+ }, null === m ? void 0 : function() {
431
+ return a2(m());
432
+ }];
433
+ }, [b, e, l, g]);
434
+ var d = r(a, c[0], c[1]);
435
+ u(function() {
436
+ f.hasValue = true;
437
+ f.value = d;
438
+ }, [d]);
439
+ w(d);
440
+ return d;
441
+ };
442
+ return withSelector_production_min;
443
+ }
369
444
  if (process.env.NODE_ENV === "production") {
370
445
  withSelector.exports = requireWithSelector_production_min();
371
446
  } else {
372
447
  withSelector.exports = requireWithSelector_development();
373
448
  }
374
449
  var withSelectorExports = withSelector.exports;
375
- const unwrapProxySymbol = /* @__PURE__ */ Symbol("unwrapProxy");
376
- function isPlainObject(value) {
377
- return typeof value === "object" && value !== null && Object.getPrototypeOf(value) === Object.prototype;
378
- }
379
- function trackingProxy(value, equals = store.deepEqual) {
380
- if (!isPlainObject(value) && !Array.isArray(value)) {
381
- return [value, (other) => equals(value, other)];
382
- }
383
- value = value[unwrapProxySymbol] ?? value;
384
- const deps = new Array();
385
- const revokations = new Array();
386
- let revoked = false;
387
- function trackComplexProp(function_, ...args) {
388
- const [proxiedValue, equals2, revoke] = trackingProxy(function_(value, ...args));
389
- deps.push((otherValue) => {
390
- if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {
391
- return false;
392
- }
393
- return equals2(function_(otherValue, ...args));
394
- });
395
- if (revoke) {
396
- revokations.push(revoke);
397
- }
398
- return proxiedValue;
399
- }
400
- function trackSimpleProp(function_, ...args) {
401
- const calculatedValue = function_(value, ...args);
402
- deps.push((otherValue) => {
403
- return function_(otherValue, ...args) === calculatedValue;
404
- });
405
- return calculatedValue;
406
- }
407
- const proxy = new Proxy(value, {
408
- get(target, p, receiver) {
409
- if (p === unwrapProxySymbol) {
410
- return value;
411
- }
412
- if (revoked) {
413
- return target[p];
414
- }
415
- const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
416
- if (writable === false && configurable === false) {
417
- return target[p];
418
- }
419
- return trackComplexProp(Reflect.get, p, receiver);
420
- },
421
- getOwnPropertyDescriptor(target, p) {
422
- const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
423
- if (writable === false && configurable === false) {
424
- return Reflect.getOwnPropertyDescriptor(target, p);
425
- }
426
- return trackComplexProp(Reflect.getOwnPropertyDescriptor, p);
427
- },
428
- ownKeys() {
429
- return trackComplexProp(Reflect.ownKeys);
430
- },
431
- getPrototypeOf() {
432
- return trackSimpleProp(Reflect.getPrototypeOf);
433
- },
434
- has(_target, p) {
435
- return trackSimpleProp(Reflect.has, p);
436
- },
437
- isExtensible() {
438
- return trackSimpleProp(Reflect.isExtensible);
439
- }
440
- });
441
- return [
442
- proxy,
443
- (other) => !!other && deps.every((equals2) => equals2(other)),
444
- () => {
445
- revoked = true;
446
- revokations.forEach((revoke) => revoke());
447
- }
448
- ];
449
- }
450
450
  function useStore(store$1, argument1, argument2) {
451
451
  const selector = store.makeSelector(
452
452
  typeof argument1 === "function" || typeof argument1 === "string" ? argument1 : void 0
@@ -454,6 +454,7 @@ function useStore(store$1, argument1, argument2) {
454
454
  const {
455
455
  disableTrackingProxy = true,
456
456
  equals = store.deepEqual,
457
+ withViewTransition,
457
458
  ...options
458
459
  } = typeof argument1 === "object" ? argument1 : argument2 ?? {};
459
460
  const lastEqualsRef = require$$0.useRef();
@@ -474,7 +475,31 @@ function useStore(store$1, argument1, argument2) {
474
475
  const subOptions = { ...options, runNow: false, passive: false };
475
476
  const subscribe = require$$0.useCallback(
476
477
  (listener) => {
477
- return rootStore.subscribe(listener, subOptions);
478
+ let _listener = listener;
479
+ if (withViewTransition && document.startViewTransition) {
480
+ let lastObservedValue;
481
+ _listener = (value2) => {
482
+ const observedValue = withViewTransition instanceof Function ? withViewTransition(value2) : value2;
483
+ if (equals(lastObservedValue, observedValue)) {
484
+ listener();
485
+ return;
486
+ }
487
+ lastObservedValue = observedValue;
488
+ let hasChanges = false;
489
+ const mutationObserver = new MutationObserver(() => {
490
+ hasChanges = true;
491
+ mutationObserver.disconnect();
492
+ });
493
+ mutationObserver.observe(document.body, { childList: true, subtree: true });
494
+ document.startViewTransition(() => {
495
+ listener();
496
+ if (!hasChanges) {
497
+ throw new Error("no change");
498
+ }
499
+ });
500
+ };
501
+ }
502
+ return rootStore.subscribe(_listener, subOptions);
478
503
  },
479
504
  [rootStore, hash.hash(subOptions)]
480
505
  );
@@ -511,15 +536,20 @@ function useProp(store2, argument1, argument2, argument3) {
511
536
  const value = useStore(store2, options);
512
537
  return [value, store2.set];
513
538
  }
539
+ function boundUseStore(...args) {
540
+ return useStore(this, ...args);
541
+ }
542
+ function boundUseProp(...args) {
543
+ return useProp(this, ...args);
544
+ }
514
545
  const reactMethods = {
515
- useStore(options) {
516
- return useStore(this, options);
517
- },
518
- useProp(options) {
519
- return useProp(this, options);
520
- }
546
+ useStore: boundUseStore,
547
+ useProp: boundUseProp
521
548
  };
522
- function useCache(cache, { passive, updateOnMount, ...options } = {}) {
549
+ function useCache(cache, { passive, updateOnMount, withViewTransition, ...options } = {}) {
550
+ if (withViewTransition === true) {
551
+ withViewTransition = (state) => state.value;
552
+ }
523
553
  const mappedState = require$$0.useMemo(() => {
524
554
  var _a;
525
555
  const rootCache = ((_a = cache.derivedFromCache) == null ? void 0 : _a.cache) ?? cache;
@@ -546,7 +576,7 @@ function useCache(cache, { passive, updateOnMount, ...options } = {}) {
546
576
  cache.invalidate();
547
577
  }
548
578
  }, []);
549
- return useStore(mappedState, options);
579
+ return useStore(mappedState, { ...options, withViewTransition });
550
580
  }
551
581
  function getScopeContext(scope) {
552
582
  scope.context ?? (scope.context = require$$0.createContext(store.createStore(scope.defaultValue)));