react-state-basis 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -31,64 +31,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  BasisProvider: () => BasisProvider,
34
- Children: () => Children2,
35
- Component: () => Component2,
36
- Fragment: () => Fragment2,
37
- Profiler: () => Profiler2,
38
- PureComponent: () => PureComponent2,
39
- React: () => ReactNamespace,
40
- StrictMode: () => StrictMode2,
41
- Suspense: () => Suspense2,
42
- __testEngine__: () => __testEngine__,
43
- __test__: () => __test__,
44
34
  basis: () => basis,
45
- beginEffectTracking: () => beginEffectTracking,
46
- cloneElement: () => cloneElement2,
47
- config: () => config,
48
35
  configureBasis: () => configureBasis,
49
- createContext: () => createContext2,
50
- createElement: () => createElement2,
51
- createPortal: () => createPortal,
52
- createRef: () => createRef2,
53
- currentTickBatch: () => currentTickBatch,
54
- default: () => index_default,
55
- endEffectTracking: () => endEffectTracking,
56
- flushSync: () => flushSync,
57
- forwardRef: () => forwardRef2,
58
- history: () => history,
59
- isValidElement: () => isValidElement2,
60
- lazy: () => lazy2,
61
- memo: () => memo2,
62
36
  printBasisHealthReport: () => printBasisHealthReport,
63
- recordUpdate: () => recordUpdate,
64
- registerVariable: () => registerVariable,
65
- startTransition: () => startTransition2,
66
- unregisterVariable: () => unregisterVariable,
67
- unstable_batchedUpdates: () => unstable_batchedUpdates,
68
37
  use: () => use,
69
38
  useActionState: () => useActionState2,
70
39
  useBasisConfig: () => useBasisConfig,
71
40
  useCallback: () => useCallback,
72
- useContext: () => useContext2,
73
41
  useDebugValue: () => useDebugValue2,
74
42
  useDeferredValue: () => useDeferredValue,
75
- useEffect: () => useEffect2,
43
+ useEffect: () => useEffect,
76
44
  useId: () => useId2,
77
45
  useImperativeHandle: () => useImperativeHandle2,
78
46
  useInsertionEffect: () => useInsertionEffect2,
79
- useLayoutEffect: () => useLayoutEffect2,
47
+ useLayoutEffect: () => useLayoutEffect,
80
48
  useMemo: () => useMemo,
81
49
  useOptimistic: () => useOptimistic2,
82
50
  useReducer: () => useReducer,
83
- useRef: () => useRef2,
84
- useState: () => useState2,
51
+ useRef: () => useRef,
52
+ useState: () => useState,
85
53
  useSyncExternalStore: () => useSyncExternalStore,
86
- useTransition: () => useTransition,
87
- version: () => version2
54
+ useTransition: () => useTransition
88
55
  });
89
56
  module.exports = __toCommonJS(index_exports);
90
- var ReactNamespace = __toESM(require("react"));
91
- var ReactDOMNamespace = __toESM(require("react-dom"));
57
+
58
+ // src/hooks.ts
59
+ var React = __toESM(require("react"));
60
+ var import_react = require("react");
92
61
 
93
62
  // src/core/logger.ts
94
63
  var isWeb = typeof window !== "undefined" && typeof window.document !== "undefined";
@@ -429,11 +398,134 @@ var __testEngine__ = {
429
398
  endEffectTracking
430
399
  };
431
400
 
401
+ // src/hooks.ts
402
+ function useState(initialState, label) {
403
+ const [val, setVal] = (0, import_react.useState)(initialState);
404
+ const effectiveLabel = label || "anonymous_state";
405
+ (0, import_react.useEffect)(() => {
406
+ registerVariable(effectiveLabel);
407
+ return () => unregisterVariable(effectiveLabel);
408
+ }, [effectiveLabel]);
409
+ const setter = (0, import_react.useCallback)((newValue) => {
410
+ if (recordUpdate(effectiveLabel)) setVal(newValue);
411
+ }, [effectiveLabel, setVal]);
412
+ return [val, setter];
413
+ }
414
+ function useRef(initialValue, _label) {
415
+ return (0, import_react.useRef)(initialValue);
416
+ }
417
+ function useReducer(reducer, initialArg, init, label) {
418
+ const effectiveLabel = typeof init === "string" ? init : label || "anonymous_reducer";
419
+ const reactInit = typeof init === "function" ? init : void 0;
420
+ const [state, dispatch] = (0, import_react.useReducer)(reducer, initialArg, reactInit);
421
+ (0, import_react.useEffect)(() => {
422
+ registerVariable(effectiveLabel);
423
+ return () => unregisterVariable(effectiveLabel);
424
+ }, [effectiveLabel]);
425
+ const basisDispatch = (0, import_react.useCallback)((action) => {
426
+ if (recordUpdate(effectiveLabel)) dispatch(action);
427
+ }, [effectiveLabel, dispatch]);
428
+ return [state, basisDispatch];
429
+ }
430
+ function useMemo(factory, deps, label) {
431
+ const effectiveLabel = label || "anonymous_projection";
432
+ (0, import_react.useEffect)(() => {
433
+ if (config.debug) console.log(`%c [Basis] Valid Projection: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
434
+ }, [effectiveLabel]);
435
+ return (0, import_react.useMemo)(factory, deps || []);
436
+ }
437
+ function useCallback(callback, deps, label) {
438
+ const effectiveLabel = label || "anonymous_callback";
439
+ (0, import_react.useEffect)(() => {
440
+ if (config.debug) console.log(`%c [Basis] Stable Callback: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
441
+ }, [effectiveLabel]);
442
+ return (0, import_react.useCallback)(callback, deps);
443
+ }
444
+ function useEffect(effect, deps, label) {
445
+ const effectiveLabel = label || "anonymous_effect";
446
+ (0, import_react.useEffect)(() => {
447
+ beginEffectTracking(effectiveLabel);
448
+ const cleanup = effect();
449
+ endEffectTracking();
450
+ return cleanup;
451
+ }, deps);
452
+ }
453
+ function useLayoutEffect(effect, deps, label) {
454
+ const effectiveLabel = label || "anonymous_layout_effect";
455
+ (0, import_react.useLayoutEffect)(() => {
456
+ beginEffectTracking(effectiveLabel);
457
+ const cleanup = effect();
458
+ endEffectTracking();
459
+ return cleanup;
460
+ }, deps);
461
+ }
462
+ function useTransition(_label) {
463
+ const [isPending, startTransition] = (0, import_react.useTransition)();
464
+ const effectiveLabel = _label || "anonymous_transition";
465
+ const basisStartTransition = (callback) => {
466
+ if (config.debug) console.log(`%c [Basis] Transition Started: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
467
+ startTransition(callback);
468
+ };
469
+ return [isPending, basisStartTransition];
470
+ }
471
+ function useDeferredValue(value, initialValueOrLabel, label) {
472
+ const isLabelAsSecondArg = typeof initialValueOrLabel === "string" && label === void 0;
473
+ const actualInitialValue = isLabelAsSecondArg ? void 0 : initialValueOrLabel;
474
+ const effectiveLabel = isLabelAsSecondArg ? initialValueOrLabel : label || "anonymous_deferred";
475
+ const deferredValue = (0, import_react.useDeferredValue)(value, actualInitialValue);
476
+ (0, import_react.useEffect)(() => {
477
+ if (config.debug && value !== deferredValue) console.log(`%c [Basis] Value Deferred: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
478
+ }, [value, deferredValue, effectiveLabel]);
479
+ return deferredValue;
480
+ }
481
+ var useId2 = (label) => React.useId();
482
+ var useDebugValue2 = React.useDebugValue;
483
+ var useImperativeHandle2 = React.useImperativeHandle;
484
+ var useInsertionEffect2 = React.useInsertionEffect;
485
+ var useSyncExternalStore = import_react.useSyncExternalStore;
486
+ function use(usable) {
487
+ return (0, import_react.use)(usable);
488
+ }
489
+ function useOptimistic2(passthrough, reducer, label) {
490
+ const effectiveLabel = label || "anonymous_optimistic";
491
+ (0, import_react.useEffect)(() => {
492
+ registerVariable(effectiveLabel);
493
+ return () => unregisterVariable(effectiveLabel);
494
+ }, [effectiveLabel]);
495
+ const [state, reactAddOptimistic] = React.useOptimistic(passthrough, reducer);
496
+ const addOptimistic = (0, import_react.useCallback)((payload) => {
497
+ if (recordUpdate(effectiveLabel)) {
498
+ reactAddOptimistic(payload);
499
+ }
500
+ }, [effectiveLabel, reactAddOptimistic]);
501
+ return [state, addOptimistic];
502
+ }
503
+ function useActionState2(action, initialState, permalink, label) {
504
+ const isLabelAsThirdArg = typeof permalink === "string" && label === void 0;
505
+ const actualPermalink = isLabelAsThirdArg ? void 0 : permalink;
506
+ const effectiveLabel = isLabelAsThirdArg ? permalink : label || "anonymous_action_state";
507
+ const [state, reactDispatch, isPending] = React.useActionState(
508
+ action,
509
+ initialState,
510
+ actualPermalink
511
+ );
512
+ (0, import_react.useEffect)(() => {
513
+ registerVariable(effectiveLabel);
514
+ return () => unregisterVariable(effectiveLabel);
515
+ }, [effectiveLabel]);
516
+ const basisDispatch = (0, import_react.useCallback)((payload) => {
517
+ if (recordUpdate(effectiveLabel)) {
518
+ reactDispatch(payload);
519
+ }
520
+ }, [effectiveLabel, reactDispatch]);
521
+ return [state, basisDispatch, isPending];
522
+ }
523
+
432
524
  // src/context.tsx
433
- var import_react2 = require("react");
525
+ var import_react3 = require("react");
434
526
 
435
527
  // src/ui/BasisHUD.tsx
436
- var import_react = require("react");
528
+ var import_react2 = require("react");
437
529
 
438
530
  // src/ui/config.ts
439
531
  var HUD_DIMENSIONS = {
@@ -475,9 +567,9 @@ var getHUDContainerStyle = (isExpanded) => ({
475
567
  // src/ui/BasisHUD.tsx
476
568
  var import_jsx_runtime = require("react/jsx-runtime");
477
569
  var BasisHUD = () => {
478
- const [isExpanded, setIsExpanded] = (0, import_react.useState)(false);
479
- const canvasRef = (0, import_react.useRef)(null);
480
- (0, import_react.useEffect)(() => {
570
+ const [isExpanded, setIsExpanded] = (0, import_react2.useState)(false);
571
+ const canvasRef = (0, import_react2.useRef)(null);
572
+ (0, import_react2.useEffect)(() => {
481
573
  if (!isExpanded) return;
482
574
  let animationFrame;
483
575
  const draw = () => {
@@ -583,10 +675,10 @@ var HUDFooter = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { styl
583
675
 
584
676
  // src/context.tsx
585
677
  var import_jsx_runtime2 = require("react/jsx-runtime");
586
- var BasisContext = (0, import_react2.createContext)({ debug: false });
678
+ var BasisContext = (0, import_react3.createContext)({ debug: false });
587
679
  var isWeb2 = typeof window !== "undefined" && typeof window.document !== "undefined";
588
680
  var BasisProvider = ({ children, debug = true }) => {
589
- (0, import_react2.useLayoutEffect)(() => {
681
+ (0, import_react3.useLayoutEffect)(() => {
590
682
  configureBasis({ debug });
591
683
  if (isWeb2) {
592
684
  window._basis_debug = debug;
@@ -597,227 +689,31 @@ var BasisProvider = ({ children, debug = true }) => {
597
689
  debug && isWeb2 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BasisHUD, {})
598
690
  ] });
599
691
  };
600
- var useBasisConfig = () => (0, import_react2.useContext)(BasisContext);
601
-
602
- // src/hooks.ts
603
- var React3 = __toESM(require("react"));
604
- var import_react3 = require("react");
605
- function useState2(initialState, label) {
606
- const [val, setVal] = (0, import_react3.useState)(initialState);
607
- const effectiveLabel = label || "anonymous_state";
608
- (0, import_react3.useEffect)(() => {
609
- registerVariable(effectiveLabel);
610
- return () => unregisterVariable(effectiveLabel);
611
- }, [effectiveLabel]);
612
- const setter = (0, import_react3.useCallback)((newValue) => {
613
- if (recordUpdate(effectiveLabel)) setVal(newValue);
614
- }, [effectiveLabel, setVal]);
615
- return [val, setter];
616
- }
617
- function useRef2(initialValue, _label) {
618
- return (0, import_react3.useRef)(initialValue);
619
- }
620
- function useReducer(reducer, initialArg, init, label) {
621
- const effectiveLabel = typeof init === "string" ? init : label || "anonymous_reducer";
622
- const reactInit = typeof init === "function" ? init : void 0;
623
- const [state, dispatch] = (0, import_react3.useReducer)(reducer, initialArg, reactInit);
624
- (0, import_react3.useEffect)(() => {
625
- registerVariable(effectiveLabel);
626
- return () => unregisterVariable(effectiveLabel);
627
- }, [effectiveLabel]);
628
- const basisDispatch = (0, import_react3.useCallback)((action) => {
629
- if (recordUpdate(effectiveLabel)) dispatch(action);
630
- }, [effectiveLabel, dispatch]);
631
- return [state, basisDispatch];
632
- }
633
- function useMemo(factory, deps, label) {
634
- const effectiveLabel = label || "anonymous_projection";
635
- (0, import_react3.useEffect)(() => {
636
- if (config.debug) console.log(`%c [Basis] Valid Projection: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
637
- }, [effectiveLabel]);
638
- return (0, import_react3.useMemo)(factory, deps || []);
639
- }
640
- function useCallback(callback, deps, label) {
641
- const effectiveLabel = label || "anonymous_callback";
642
- (0, import_react3.useEffect)(() => {
643
- if (config.debug) console.log(`%c [Basis] Stable Callback: "${effectiveLabel}" `, "color: #2ecc71; font-weight: bold;");
644
- }, [effectiveLabel]);
645
- return (0, import_react3.useCallback)(callback, deps);
646
- }
647
- function useEffect2(effect, deps, label) {
648
- const effectiveLabel = label || "anonymous_effect";
649
- (0, import_react3.useEffect)(() => {
650
- beginEffectTracking(effectiveLabel);
651
- const cleanup = effect();
652
- endEffectTracking();
653
- return cleanup;
654
- }, deps);
655
- }
656
- function useLayoutEffect2(effect, deps, label) {
657
- const effectiveLabel = label || "anonymous_layout_effect";
658
- (0, import_react3.useLayoutEffect)(() => {
659
- beginEffectTracking(effectiveLabel);
660
- const cleanup = effect();
661
- endEffectTracking();
662
- return cleanup;
663
- }, deps);
664
- }
665
- function useTransition(_label) {
666
- const [isPending, startTransition3] = (0, import_react3.useTransition)();
667
- const effectiveLabel = _label || "anonymous_transition";
668
- const basisStartTransition = (callback) => {
669
- if (config.debug) console.log(`%c [Basis] Transition Started: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
670
- startTransition3(callback);
671
- };
672
- return [isPending, basisStartTransition];
673
- }
674
- function useDeferredValue(value, initialValueOrLabel, label) {
675
- const isLabelAsSecondArg = typeof initialValueOrLabel === "string" && label === void 0;
676
- const actualInitialValue = isLabelAsSecondArg ? void 0 : initialValueOrLabel;
677
- const effectiveLabel = isLabelAsSecondArg ? initialValueOrLabel : label || "anonymous_deferred";
678
- const deferredValue = (0, import_react3.useDeferredValue)(value, actualInitialValue);
679
- (0, import_react3.useEffect)(() => {
680
- if (config.debug && value !== deferredValue) console.log(`%c [Basis] Value Deferred: "${effectiveLabel}" `, "color: #e67e22; font-weight: bold;");
681
- }, [value, deferredValue, effectiveLabel]);
682
- return deferredValue;
683
- }
684
- function createContext2(defaultValue, label) {
685
- const context = (0, import_react3.createContext)(defaultValue);
686
- if (label) context._basis_label = label;
687
- return context;
688
- }
689
- var useContext2 = import_react3.useContext;
690
- var useId2 = (label) => React3.useId();
691
- var useDebugValue2 = React3.useDebugValue;
692
- var useImperativeHandle2 = React3.useImperativeHandle;
693
- var useInsertionEffect2 = React3.useInsertionEffect;
694
- var useSyncExternalStore = import_react3.useSyncExternalStore;
695
- function use(usable) {
696
- return (0, import_react3.use)(usable);
697
- }
698
- function useOptimistic2(passthrough, reducer, label) {
699
- const effectiveLabel = label || "anonymous_optimistic";
700
- (0, import_react3.useEffect)(() => {
701
- registerVariable(effectiveLabel);
702
- return () => unregisterVariable(effectiveLabel);
703
- }, [effectiveLabel]);
704
- const [state, reactAddOptimistic] = React3.useOptimistic(passthrough, reducer);
705
- const addOptimistic = (0, import_react3.useCallback)((payload) => {
706
- if (recordUpdate(effectiveLabel)) {
707
- reactAddOptimistic(payload);
708
- }
709
- }, [effectiveLabel, reactAddOptimistic]);
710
- return [state, addOptimistic];
711
- }
712
- function useActionState2(action, initialState, permalink, label) {
713
- const isLabelAsThirdArg = typeof permalink === "string" && label === void 0;
714
- const actualPermalink = isLabelAsThirdArg ? void 0 : permalink;
715
- const effectiveLabel = isLabelAsThirdArg ? permalink : label || "anonymous_action_state";
716
- const [state, reactDispatch, isPending] = React3.useActionState(
717
- action,
718
- initialState,
719
- actualPermalink
720
- );
721
- (0, import_react3.useEffect)(() => {
722
- registerVariable(effectiveLabel);
723
- return () => unregisterVariable(effectiveLabel);
724
- }, [effectiveLabel]);
725
- const basisDispatch = (0, import_react3.useCallback)((payload) => {
726
- if (recordUpdate(effectiveLabel)) {
727
- reactDispatch(payload);
728
- }
729
- }, [effectiveLabel, reactDispatch]);
730
- return [state, basisDispatch, isPending];
731
- }
732
- var __test__ = { registerVariable, unregisterVariable, recordUpdate, beginEffectTracking, endEffectTracking, history, currentTickBatch };
692
+ var useBasisConfig = () => (0, import_react3.useContext)(BasisContext);
733
693
 
734
694
  // src/vite-plugin.ts
735
695
  function basis() {
736
696
  return {
737
697
  name: "vite-plugin-react-state-basis",
738
- enforce: "pre",
739
- resolveId(source, importer) {
740
- if (source === "react" || source === "react-dom" || source === "react-dom/client") {
741
- const isLibraryCore = importer && ((importer.includes("react-state-basis/src") || importer.includes("react-state-basis/dist")) && !importer.includes("react-state-basis/example"));
742
- const isYalc = importer && importer.includes(".yalc");
743
- if (isLibraryCore || isYalc) {
744
- return null;
698
+ config() {
699
+ return {
700
+ optimizeDeps: {
701
+ exclude: ["react-state-basis"]
745
702
  }
746
- const mapping = {
747
- "react": "react-state-basis",
748
- "react-dom": "react-state-basis",
749
- "react-dom/client": "react-state-basis/client"
750
- };
751
- return this.resolve(mapping[source], importer, { skipSelf: true });
752
- }
753
- return null;
703
+ };
754
704
  }
755
705
  };
756
706
  }
757
-
758
- // src/index.ts
759
- var Children2 = ReactNamespace.Children;
760
- var Component2 = ReactNamespace.Component;
761
- var Fragment2 = ReactNamespace.Fragment;
762
- var Profiler2 = ReactNamespace.Profiler;
763
- var PureComponent2 = ReactNamespace.PureComponent;
764
- var StrictMode2 = ReactNamespace.StrictMode;
765
- var Suspense2 = ReactNamespace.Suspense;
766
- var cloneElement2 = ReactNamespace.cloneElement;
767
- var createElement2 = ReactNamespace.createElement;
768
- var createRef2 = ReactNamespace.createRef;
769
- var forwardRef2 = ReactNamespace.forwardRef;
770
- var isValidElement2 = ReactNamespace.isValidElement;
771
- var lazy2 = ReactNamespace.lazy;
772
- var memo2 = ReactNamespace.memo;
773
- var startTransition2 = ReactNamespace.startTransition;
774
- var version2 = ReactNamespace.version;
775
- var RD = ReactDOMNamespace;
776
- var createPortal = RD.createPortal;
777
- var flushSync = RD.flushSync;
778
- var unstable_batchedUpdates = RD.unstable_batchedUpdates;
779
- var index_default = ReactNamespace;
780
707
  // Annotate the CommonJS export names for ESM import in node:
781
708
  0 && (module.exports = {
782
709
  BasisProvider,
783
- Children,
784
- Component,
785
- Fragment,
786
- Profiler,
787
- PureComponent,
788
- React,
789
- StrictMode,
790
- Suspense,
791
- __testEngine__,
792
- __test__,
793
710
  basis,
794
- beginEffectTracking,
795
- cloneElement,
796
- config,
797
711
  configureBasis,
798
- createContext,
799
- createElement,
800
- createPortal,
801
- createRef,
802
- currentTickBatch,
803
- endEffectTracking,
804
- flushSync,
805
- forwardRef,
806
- history,
807
- isValidElement,
808
- lazy,
809
- memo,
810
712
  printBasisHealthReport,
811
- recordUpdate,
812
- registerVariable,
813
- startTransition,
814
- unregisterVariable,
815
- unstable_batchedUpdates,
816
713
  use,
817
714
  useActionState,
818
715
  useBasisConfig,
819
716
  useCallback,
820
- useContext,
821
717
  useDebugValue,
822
718
  useDeferredValue,
823
719
  useEffect,
@@ -831,7 +727,6 @@ var index_default = ReactNamespace;
831
727
  useRef,
832
728
  useState,
833
729
  useSyncExternalStore,
834
- useTransition,
835
- version
730
+ useTransition
836
731
  });
837
732
  //# sourceMappingURL=index.js.map