bippy 0.3.26 → 0.3.28
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/README.md +3 -3
- package/dist/experiments/inspect.cjs +4 -5
- package/dist/experiments/inspect.js +2 -3
- package/dist/index.cjs +16 -13
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.iife.js +1 -1
- package/dist/index.js +2 -3
- package/dist/{source-DApL4zD4.js → source-BfkxIx1q.js} +67 -77
- package/dist/{source-CTbJ4jWB.cjs → source-CD5HO-_u.cjs} +69 -109
- package/dist/source.cjs +2 -8
- package/dist/source.d.cts +2 -19
- package/dist/source.d.ts +3 -20
- package/dist/source.js +3 -4
- package/dist/{src--kkhuH0q.js → src-CqIv1vpl.js} +259 -2
- package/dist/{src-BIDabo17.cjs → src-nBpvAkYD.cjs} +360 -12
- package/package.json +1 -11
- package/dist/override.cjs +0 -123
- package/dist/override.d.cts +0 -14
- package/dist/override.d.ts +0 -14
- package/dist/override.js +0 -120
- package/dist/rdt-hook-BraYbuNA.js +0 -162
- package/dist/rdt-hook-CR3KoPkF.cjs +0 -228
- /package/dist/{types-CeFOA1ZM.d.ts → types-Bud6qf-i.d.ts} +0 -0
|
@@ -6,8 +6,160 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
const require_rdt_hook = require('./rdt-hook-CR3KoPkF.cjs');
|
|
10
9
|
|
|
10
|
+
//#region src/rdt-hook.ts
|
|
11
|
+
const version = "0.3.28";
|
|
12
|
+
const BIPPY_INSTRUMENTATION_STRING = `bippy-${version}`;
|
|
13
|
+
const objectDefineProperty = Object.defineProperty;
|
|
14
|
+
const objectHasOwnProperty = Object.prototype.hasOwnProperty;
|
|
15
|
+
const NO_OP = () => {};
|
|
16
|
+
const checkDCE = (fn) => {
|
|
17
|
+
try {
|
|
18
|
+
const code = Function.prototype.toString.call(fn);
|
|
19
|
+
if (code.indexOf("^_^") > -1) setTimeout(() => {
|
|
20
|
+
throw new Error("React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://reactjs.org/link/perf-use-production-build");
|
|
21
|
+
});
|
|
22
|
+
} catch {}
|
|
23
|
+
};
|
|
24
|
+
const isRealReactDevtools = (rdtHook = getRDTHook()) => {
|
|
25
|
+
return "getFiberRoots" in rdtHook;
|
|
26
|
+
};
|
|
27
|
+
let isReactRefreshOverride = false;
|
|
28
|
+
let injectFnStr = void 0;
|
|
29
|
+
const isReactRefresh = (rdtHook = getRDTHook()) => {
|
|
30
|
+
if (isReactRefreshOverride) return true;
|
|
31
|
+
if (typeof rdtHook.inject === "function") injectFnStr = rdtHook.inject.toString();
|
|
32
|
+
return Boolean(injectFnStr?.includes("(injected)"));
|
|
33
|
+
};
|
|
34
|
+
const onActiveListeners = new Set();
|
|
35
|
+
const _renderers = new Set();
|
|
36
|
+
const installRDTHook = (onActive) => {
|
|
37
|
+
const renderers = new Map();
|
|
38
|
+
let i = 0;
|
|
39
|
+
let rdtHook = {
|
|
40
|
+
checkDCE,
|
|
41
|
+
supportsFiber: true,
|
|
42
|
+
supportsFlight: true,
|
|
43
|
+
hasUnsupportedRendererAttached: false,
|
|
44
|
+
renderers,
|
|
45
|
+
onCommitFiberRoot: NO_OP,
|
|
46
|
+
onCommitFiberUnmount: NO_OP,
|
|
47
|
+
onPostCommitFiberRoot: NO_OP,
|
|
48
|
+
on: NO_OP,
|
|
49
|
+
inject(renderer) {
|
|
50
|
+
const nextID = ++i;
|
|
51
|
+
renderers.set(nextID, renderer);
|
|
52
|
+
_renderers.add(renderer);
|
|
53
|
+
if (!rdtHook._instrumentationIsActive) {
|
|
54
|
+
rdtHook._instrumentationIsActive = true;
|
|
55
|
+
onActiveListeners.forEach((listener) => listener());
|
|
56
|
+
}
|
|
57
|
+
return nextID;
|
|
58
|
+
},
|
|
59
|
+
_instrumentationSource: BIPPY_INSTRUMENTATION_STRING,
|
|
60
|
+
_instrumentationIsActive: false
|
|
61
|
+
};
|
|
62
|
+
try {
|
|
63
|
+
objectDefineProperty(globalThis, "__REACT_DEVTOOLS_GLOBAL_HOOK__", {
|
|
64
|
+
get() {
|
|
65
|
+
return rdtHook;
|
|
66
|
+
},
|
|
67
|
+
set(newHook) {
|
|
68
|
+
if (newHook && typeof newHook === "object") {
|
|
69
|
+
const ourRenderers = rdtHook.renderers;
|
|
70
|
+
rdtHook = newHook;
|
|
71
|
+
if (ourRenderers.size > 0) {
|
|
72
|
+
ourRenderers.forEach((renderer, id) => {
|
|
73
|
+
_renderers.add(renderer);
|
|
74
|
+
newHook.renderers.set(id, renderer);
|
|
75
|
+
});
|
|
76
|
+
patchRDTHook(onActive);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
configurable: true,
|
|
81
|
+
enumerable: true
|
|
82
|
+
});
|
|
83
|
+
const originalWindowHasOwnProperty = window.hasOwnProperty;
|
|
84
|
+
let hasRanHack = false;
|
|
85
|
+
objectDefineProperty(window, "hasOwnProperty", {
|
|
86
|
+
value: function() {
|
|
87
|
+
try {
|
|
88
|
+
if (!hasRanHack && arguments[0] === "__REACT_DEVTOOLS_GLOBAL_HOOK__") {
|
|
89
|
+
globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__ = void 0;
|
|
90
|
+
hasRanHack = true;
|
|
91
|
+
return -0;
|
|
92
|
+
}
|
|
93
|
+
} catch {}
|
|
94
|
+
return originalWindowHasOwnProperty.apply(this, arguments);
|
|
95
|
+
},
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true
|
|
98
|
+
});
|
|
99
|
+
} catch {
|
|
100
|
+
patchRDTHook(onActive);
|
|
101
|
+
}
|
|
102
|
+
return rdtHook;
|
|
103
|
+
};
|
|
104
|
+
const patchRDTHook = (onActive) => {
|
|
105
|
+
if (onActive) onActiveListeners.add(onActive);
|
|
106
|
+
try {
|
|
107
|
+
const rdtHook = globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
108
|
+
if (!rdtHook) return;
|
|
109
|
+
if (!rdtHook._instrumentationSource) {
|
|
110
|
+
rdtHook.checkDCE = checkDCE;
|
|
111
|
+
rdtHook.supportsFiber = true;
|
|
112
|
+
rdtHook.supportsFlight = true;
|
|
113
|
+
rdtHook.hasUnsupportedRendererAttached = false;
|
|
114
|
+
rdtHook._instrumentationSource = BIPPY_INSTRUMENTATION_STRING;
|
|
115
|
+
rdtHook._instrumentationIsActive = false;
|
|
116
|
+
rdtHook.on = NO_OP;
|
|
117
|
+
if (rdtHook.renderers.size) {
|
|
118
|
+
rdtHook._instrumentationIsActive = true;
|
|
119
|
+
onActiveListeners.forEach((listener) => listener());
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const prevInject = rdtHook.inject;
|
|
123
|
+
if (isReactRefresh(rdtHook) && !isRealReactDevtools()) {
|
|
124
|
+
isReactRefreshOverride = true;
|
|
125
|
+
const nextID = rdtHook.inject({ scheduleRefresh() {} });
|
|
126
|
+
if (nextID) rdtHook._instrumentationIsActive = true;
|
|
127
|
+
}
|
|
128
|
+
rdtHook.inject = (renderer) => {
|
|
129
|
+
const id = prevInject(renderer);
|
|
130
|
+
_renderers.add(renderer);
|
|
131
|
+
rdtHook._instrumentationIsActive = true;
|
|
132
|
+
onActiveListeners.forEach((listener) => listener());
|
|
133
|
+
return id;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (rdtHook.renderers.size || rdtHook._instrumentationIsActive || isReactRefresh()) onActive?.();
|
|
137
|
+
} catch {}
|
|
138
|
+
};
|
|
139
|
+
const hasRDTHook = () => {
|
|
140
|
+
return objectHasOwnProperty.call(globalThis, "__REACT_DEVTOOLS_GLOBAL_HOOK__");
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Returns the current React DevTools global hook.
|
|
144
|
+
*/
|
|
145
|
+
const getRDTHook = (onActive) => {
|
|
146
|
+
if (!hasRDTHook()) return installRDTHook(onActive);
|
|
147
|
+
patchRDTHook(onActive);
|
|
148
|
+
return globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
149
|
+
};
|
|
150
|
+
const isClientEnvironment = () => {
|
|
151
|
+
return Boolean(typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"));
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Usually used purely for side effect
|
|
155
|
+
*/
|
|
156
|
+
const safelyInstallRDTHook = () => {
|
|
157
|
+
try {
|
|
158
|
+
if (isClientEnvironment()) getRDTHook();
|
|
159
|
+
} catch {}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
//#endregion
|
|
11
163
|
//#region src/core.ts
|
|
12
164
|
const FunctionComponentTag = 0;
|
|
13
165
|
const ClassComponentTag = 1;
|
|
@@ -333,8 +485,8 @@ const detectReactBuildType = (renderer) => {
|
|
|
333
485
|
* Returns `true` if bippy's instrumentation is active.
|
|
334
486
|
*/
|
|
335
487
|
const isInstrumentationActive = () => {
|
|
336
|
-
const rdtHook =
|
|
337
|
-
return Boolean(rdtHook._instrumentationIsActive) ||
|
|
488
|
+
const rdtHook = getRDTHook();
|
|
489
|
+
return Boolean(rdtHook._instrumentationIsActive) || isRealReactDevtools() || isReactRefresh();
|
|
338
490
|
};
|
|
339
491
|
/**
|
|
340
492
|
* Returns the latest fiber (since it may be double-buffered).
|
|
@@ -480,6 +632,112 @@ const createFiberVisitor = ({ onRender }) => {
|
|
|
480
632
|
traverseRenderedFibers(root, onRender);
|
|
481
633
|
};
|
|
482
634
|
};
|
|
635
|
+
let _overrideProps = null;
|
|
636
|
+
let _overrideHookState = null;
|
|
637
|
+
let _overrideContext = null;
|
|
638
|
+
const injectOverrideMethods = () => {
|
|
639
|
+
if (!hasRDTHook()) return null;
|
|
640
|
+
const rdtHook = getRDTHook();
|
|
641
|
+
if (!rdtHook?.renderers) return null;
|
|
642
|
+
if (_overrideProps || _overrideHookState || _overrideContext) return {
|
|
643
|
+
overrideProps: _overrideProps,
|
|
644
|
+
overrideHookState: _overrideHookState,
|
|
645
|
+
overrideContext: _overrideContext
|
|
646
|
+
};
|
|
647
|
+
for (const [_, renderer] of Array.from(rdtHook.renderers)) try {
|
|
648
|
+
if (_overrideHookState) {
|
|
649
|
+
const prevOverrideHookState = _overrideHookState;
|
|
650
|
+
_overrideHookState = (fiber, id, path, value) => {
|
|
651
|
+
let current = fiber.memoizedState;
|
|
652
|
+
for (let i = 0; i < Number(id); i++) {
|
|
653
|
+
if (!current?.next) break;
|
|
654
|
+
current = current.next;
|
|
655
|
+
}
|
|
656
|
+
if (current?.queue) {
|
|
657
|
+
const queue = current.queue;
|
|
658
|
+
if (isPOJO(queue) && "dispatch" in queue) {
|
|
659
|
+
const dispatch = queue.dispatch;
|
|
660
|
+
dispatch(value);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
prevOverrideHookState(fiber, id, path, value);
|
|
665
|
+
renderer.overrideHookState?.(fiber, id, path, value);
|
|
666
|
+
};
|
|
667
|
+
} else if (renderer.overrideHookState) _overrideHookState = renderer.overrideHookState;
|
|
668
|
+
if (_overrideProps) {
|
|
669
|
+
const prevOverrideProps = _overrideProps;
|
|
670
|
+
_overrideProps = (fiber, path, value) => {
|
|
671
|
+
prevOverrideProps(fiber, path, value);
|
|
672
|
+
renderer.overrideProps?.(fiber, path, value);
|
|
673
|
+
};
|
|
674
|
+
} else if (renderer.overrideProps) _overrideProps = renderer.overrideProps;
|
|
675
|
+
_overrideContext = (fiber, contextType, path, value) => {
|
|
676
|
+
let current = fiber;
|
|
677
|
+
while (current) {
|
|
678
|
+
const type = current.type;
|
|
679
|
+
if (type === contextType || type?.Provider === contextType) {
|
|
680
|
+
if (_overrideProps) {
|
|
681
|
+
_overrideProps(current, ["value", ...path], value);
|
|
682
|
+
if (current.alternate) _overrideProps(current.alternate, ["value", ...path], value);
|
|
683
|
+
}
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
current = current.return;
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
} catch {}
|
|
690
|
+
};
|
|
691
|
+
const isPOJO = (maybePOJO) => {
|
|
692
|
+
return Object.prototype.toString.call(maybePOJO) === "[object Object]" && (Object.getPrototypeOf(maybePOJO) === Object.prototype || Object.getPrototypeOf(maybePOJO) === null);
|
|
693
|
+
};
|
|
694
|
+
const buildPathsFromValue = (maybePOJO, basePath = []) => {
|
|
695
|
+
if (!isPOJO(maybePOJO)) return [{
|
|
696
|
+
path: basePath,
|
|
697
|
+
value: maybePOJO
|
|
698
|
+
}];
|
|
699
|
+
const paths = [];
|
|
700
|
+
for (const key in maybePOJO) {
|
|
701
|
+
const value = maybePOJO[key];
|
|
702
|
+
const path = basePath.concat(key);
|
|
703
|
+
if (isPOJO(value)) paths.push(...buildPathsFromValue(value, path));
|
|
704
|
+
else paths.push({
|
|
705
|
+
path,
|
|
706
|
+
value
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
return paths;
|
|
710
|
+
};
|
|
711
|
+
const overrideProps = (fiber, partialValue) => {
|
|
712
|
+
injectOverrideMethods();
|
|
713
|
+
const paths = buildPathsFromValue(partialValue);
|
|
714
|
+
for (const { path, value } of paths) try {
|
|
715
|
+
_overrideProps?.(fiber, path, value);
|
|
716
|
+
} catch {}
|
|
717
|
+
};
|
|
718
|
+
const overrideHookState = (fiber, id, partialValue) => {
|
|
719
|
+
injectOverrideMethods();
|
|
720
|
+
const hookId = String(id);
|
|
721
|
+
if (isPOJO(partialValue)) {
|
|
722
|
+
const paths = buildPathsFromValue(partialValue);
|
|
723
|
+
for (const { path, value } of paths) try {
|
|
724
|
+
_overrideHookState?.(fiber, hookId, path, value);
|
|
725
|
+
} catch {}
|
|
726
|
+
} else try {
|
|
727
|
+
_overrideHookState?.(fiber, hookId, [], partialValue);
|
|
728
|
+
} catch {}
|
|
729
|
+
};
|
|
730
|
+
const overrideContext = (fiber, contextType, partialValue) => {
|
|
731
|
+
injectOverrideMethods();
|
|
732
|
+
if (isPOJO(partialValue)) {
|
|
733
|
+
const paths = buildPathsFromValue(partialValue);
|
|
734
|
+
for (const { path, value } of paths) try {
|
|
735
|
+
_overrideContext?.(fiber, contextType, path, value);
|
|
736
|
+
} catch {}
|
|
737
|
+
} else try {
|
|
738
|
+
_overrideContext?.(fiber, contextType, [], partialValue);
|
|
739
|
+
} catch {}
|
|
740
|
+
};
|
|
483
741
|
/**
|
|
484
742
|
* Instruments the DevTools hook.
|
|
485
743
|
* @example
|
|
@@ -493,10 +751,10 @@ const createFiberVisitor = ({ onRender }) => {
|
|
|
493
751
|
* });
|
|
494
752
|
*/
|
|
495
753
|
const instrument = (options) => {
|
|
496
|
-
return
|
|
497
|
-
const rdtHook =
|
|
754
|
+
return getRDTHook(() => {
|
|
755
|
+
const rdtHook = getRDTHook();
|
|
498
756
|
options.onActive?.();
|
|
499
|
-
rdtHook._instrumentationSource = options.name ??
|
|
757
|
+
rdtHook._instrumentationSource = options.name ?? BIPPY_INSTRUMENTATION_STRING;
|
|
500
758
|
const prevOnCommitFiberRoot = rdtHook.onCommitFiberRoot;
|
|
501
759
|
if (options.onCommitFiberRoot) rdtHook.onCommitFiberRoot = (rendererID, root, priority) => {
|
|
502
760
|
if (prevOnCommitFiberRoot) prevOnCommitFiberRoot(rendererID, root, priority);
|
|
@@ -515,7 +773,7 @@ const instrument = (options) => {
|
|
|
515
773
|
});
|
|
516
774
|
};
|
|
517
775
|
const getFiberFromHostInstance = (hostInstance) => {
|
|
518
|
-
const rdtHook =
|
|
776
|
+
const rdtHook = getRDTHook();
|
|
519
777
|
for (const renderer of rdtHook.renderers.values()) try {
|
|
520
778
|
const fiber = renderer.findFiberByHostInstance?.(hostInstance);
|
|
521
779
|
if (fiber) return fiber;
|
|
@@ -530,16 +788,16 @@ const INSTALL_ERROR = new Error();
|
|
|
530
788
|
const _fiberRoots = new Set();
|
|
531
789
|
const secure = (options, secureOptions = {}) => {
|
|
532
790
|
const onActive = options.onActive;
|
|
533
|
-
const isRDTHookInstalled =
|
|
534
|
-
const isUsingRealReactDevtools =
|
|
535
|
-
const isUsingReactRefresh =
|
|
791
|
+
const isRDTHookInstalled = hasRDTHook();
|
|
792
|
+
const isUsingRealReactDevtools = isRealReactDevtools();
|
|
793
|
+
const isUsingReactRefresh = isReactRefresh();
|
|
536
794
|
let timeout;
|
|
537
795
|
let isDevelopment = !secureOptions.isProduction;
|
|
538
796
|
options.onActive = () => {
|
|
539
797
|
clearTimeout(timeout);
|
|
540
798
|
let isSecure = true;
|
|
541
799
|
try {
|
|
542
|
-
const rdtHook =
|
|
800
|
+
const rdtHook = getRDTHook();
|
|
543
801
|
for (const renderer of rdtHook.renderers.values()) {
|
|
544
802
|
const [majorVersion] = renderer.version.split(".");
|
|
545
803
|
if (Number(majorVersion) < (secureOptions.minReactMajorVersion ?? 17)) isSecure = false;
|
|
@@ -610,7 +868,7 @@ const onCommitFiberRoot = (handler) => {
|
|
|
610
868
|
|
|
611
869
|
//#endregion
|
|
612
870
|
//#region src/index.ts
|
|
613
|
-
|
|
871
|
+
safelyInstallRDTHook();
|
|
614
872
|
|
|
615
873
|
//#endregion
|
|
616
874
|
Object.defineProperty(exports, 'ActivityComponentTag', {
|
|
@@ -619,6 +877,12 @@ Object.defineProperty(exports, 'ActivityComponentTag', {
|
|
|
619
877
|
return ActivityComponentTag;
|
|
620
878
|
}
|
|
621
879
|
});
|
|
880
|
+
Object.defineProperty(exports, 'BIPPY_INSTRUMENTATION_STRING', {
|
|
881
|
+
enumerable: true,
|
|
882
|
+
get: function () {
|
|
883
|
+
return BIPPY_INSTRUMENTATION_STRING;
|
|
884
|
+
}
|
|
885
|
+
});
|
|
622
886
|
Object.defineProperty(exports, 'CONCURRENT_MODE_NUMBER', {
|
|
623
887
|
enumerable: true,
|
|
624
888
|
get: function () {
|
|
@@ -775,6 +1039,12 @@ Object.defineProperty(exports, '_fiberRoots', {
|
|
|
775
1039
|
return _fiberRoots;
|
|
776
1040
|
}
|
|
777
1041
|
});
|
|
1042
|
+
Object.defineProperty(exports, '_renderers', {
|
|
1043
|
+
enumerable: true,
|
|
1044
|
+
get: function () {
|
|
1045
|
+
return _renderers;
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
778
1048
|
Object.defineProperty(exports, 'areFiberEqual', {
|
|
779
1049
|
enumerable: true,
|
|
780
1050
|
get: function () {
|
|
@@ -859,6 +1129,12 @@ Object.defineProperty(exports, 'getNearestHostFibers', {
|
|
|
859
1129
|
return getNearestHostFibers;
|
|
860
1130
|
}
|
|
861
1131
|
});
|
|
1132
|
+
Object.defineProperty(exports, 'getRDTHook', {
|
|
1133
|
+
enumerable: true,
|
|
1134
|
+
get: function () {
|
|
1135
|
+
return getRDTHook;
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
862
1138
|
Object.defineProperty(exports, 'getTimings', {
|
|
863
1139
|
enumerable: true,
|
|
864
1140
|
get: function () {
|
|
@@ -877,12 +1153,36 @@ Object.defineProperty(exports, 'hasMemoCache', {
|
|
|
877
1153
|
return hasMemoCache;
|
|
878
1154
|
}
|
|
879
1155
|
});
|
|
1156
|
+
Object.defineProperty(exports, 'hasRDTHook', {
|
|
1157
|
+
enumerable: true,
|
|
1158
|
+
get: function () {
|
|
1159
|
+
return hasRDTHook;
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
Object.defineProperty(exports, 'injectOverrideMethods', {
|
|
1163
|
+
enumerable: true,
|
|
1164
|
+
get: function () {
|
|
1165
|
+
return injectOverrideMethods;
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
Object.defineProperty(exports, 'installRDTHook', {
|
|
1169
|
+
enumerable: true,
|
|
1170
|
+
get: function () {
|
|
1171
|
+
return installRDTHook;
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
880
1174
|
Object.defineProperty(exports, 'instrument', {
|
|
881
1175
|
enumerable: true,
|
|
882
1176
|
get: function () {
|
|
883
1177
|
return instrument;
|
|
884
1178
|
}
|
|
885
1179
|
});
|
|
1180
|
+
Object.defineProperty(exports, 'isClientEnvironment', {
|
|
1181
|
+
enumerable: true,
|
|
1182
|
+
get: function () {
|
|
1183
|
+
return isClientEnvironment;
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
886
1186
|
Object.defineProperty(exports, 'isCompositeFiber', {
|
|
887
1187
|
enumerable: true,
|
|
888
1188
|
get: function () {
|
|
@@ -901,6 +1201,18 @@ Object.defineProperty(exports, 'isInstrumentationActive', {
|
|
|
901
1201
|
return isInstrumentationActive;
|
|
902
1202
|
}
|
|
903
1203
|
});
|
|
1204
|
+
Object.defineProperty(exports, 'isReactRefresh', {
|
|
1205
|
+
enumerable: true,
|
|
1206
|
+
get: function () {
|
|
1207
|
+
return isReactRefresh;
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
Object.defineProperty(exports, 'isRealReactDevtools', {
|
|
1211
|
+
enumerable: true,
|
|
1212
|
+
get: function () {
|
|
1213
|
+
return isRealReactDevtools;
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
904
1216
|
Object.defineProperty(exports, 'isValidElement', {
|
|
905
1217
|
enumerable: true,
|
|
906
1218
|
get: function () {
|
|
@@ -925,6 +1237,36 @@ Object.defineProperty(exports, 'onCommitFiberRoot', {
|
|
|
925
1237
|
return onCommitFiberRoot;
|
|
926
1238
|
}
|
|
927
1239
|
});
|
|
1240
|
+
Object.defineProperty(exports, 'overrideContext', {
|
|
1241
|
+
enumerable: true,
|
|
1242
|
+
get: function () {
|
|
1243
|
+
return overrideContext;
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
Object.defineProperty(exports, 'overrideHookState', {
|
|
1247
|
+
enumerable: true,
|
|
1248
|
+
get: function () {
|
|
1249
|
+
return overrideHookState;
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
Object.defineProperty(exports, 'overrideProps', {
|
|
1253
|
+
enumerable: true,
|
|
1254
|
+
get: function () {
|
|
1255
|
+
return overrideProps;
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
Object.defineProperty(exports, 'patchRDTHook', {
|
|
1259
|
+
enumerable: true,
|
|
1260
|
+
get: function () {
|
|
1261
|
+
return patchRDTHook;
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
Object.defineProperty(exports, 'safelyInstallRDTHook', {
|
|
1265
|
+
enumerable: true,
|
|
1266
|
+
get: function () {
|
|
1267
|
+
return safelyInstallRDTHook;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
928
1270
|
Object.defineProperty(exports, 'secure', {
|
|
929
1271
|
enumerable: true,
|
|
930
1272
|
get: function () {
|
|
@@ -1002,4 +1344,10 @@ Object.defineProperty(exports, 'updateFiberRecursively', {
|
|
|
1002
1344
|
get: function () {
|
|
1003
1345
|
return updateFiberRecursively;
|
|
1004
1346
|
}
|
|
1347
|
+
});
|
|
1348
|
+
Object.defineProperty(exports, 'version', {
|
|
1349
|
+
enumerable: true,
|
|
1350
|
+
get: function () {
|
|
1351
|
+
return version;
|
|
1352
|
+
}
|
|
1005
1353
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bippy",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.28",
|
|
4
4
|
"description": "hack into react internals",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -60,16 +60,6 @@
|
|
|
60
60
|
"default": "./dist/source.cjs"
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
|
-
"./override": {
|
|
64
|
-
"import": {
|
|
65
|
-
"types": "./dist/override.d.ts",
|
|
66
|
-
"default": "./dist/override.js"
|
|
67
|
-
},
|
|
68
|
-
"require": {
|
|
69
|
-
"types": "./dist/override.d.cts",
|
|
70
|
-
"default": "./dist/override.cjs"
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
63
|
"./experiments/inspect": {
|
|
74
64
|
"import": {
|
|
75
65
|
"types": "./dist/experiments/inspect.d.ts",
|
package/dist/override.cjs
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license bippy
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Aiden Bai
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*/
|
|
9
|
-
const require_rdt_hook = require('./rdt-hook-CR3KoPkF.cjs');
|
|
10
|
-
|
|
11
|
-
//#region src/override.ts
|
|
12
|
-
let _overrideProps = null;
|
|
13
|
-
let _overrideHookState = null;
|
|
14
|
-
let _overrideContext = null;
|
|
15
|
-
const injectOverrideMethods = () => {
|
|
16
|
-
if (!require_rdt_hook.hasRDTHook()) return null;
|
|
17
|
-
const rdtHook = require_rdt_hook.getRDTHook();
|
|
18
|
-
if (!rdtHook?.renderers) return null;
|
|
19
|
-
if (_overrideProps || _overrideHookState || _overrideContext) return {
|
|
20
|
-
overrideProps: _overrideProps,
|
|
21
|
-
overrideHookState: _overrideHookState,
|
|
22
|
-
overrideContext: _overrideContext
|
|
23
|
-
};
|
|
24
|
-
for (const [_, renderer] of Array.from(rdtHook.renderers)) try {
|
|
25
|
-
if (_overrideHookState) {
|
|
26
|
-
const prevOverrideHookState = _overrideHookState;
|
|
27
|
-
_overrideHookState = (fiber, id, path, value) => {
|
|
28
|
-
let current = fiber.memoizedState;
|
|
29
|
-
for (let i = 0; i < Number(id); i++) {
|
|
30
|
-
if (!current?.next) break;
|
|
31
|
-
current = current.next;
|
|
32
|
-
}
|
|
33
|
-
if (current?.queue) {
|
|
34
|
-
const queue = current.queue;
|
|
35
|
-
if (isPOJO(queue) && "dispatch" in queue) {
|
|
36
|
-
const dispatch = queue.dispatch;
|
|
37
|
-
dispatch(value);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
prevOverrideHookState(fiber, id, path, value);
|
|
42
|
-
renderer.overrideHookState?.(fiber, id, path, value);
|
|
43
|
-
};
|
|
44
|
-
} else if (renderer.overrideHookState) _overrideHookState = renderer.overrideHookState;
|
|
45
|
-
if (_overrideProps) {
|
|
46
|
-
const prevOverrideProps = _overrideProps;
|
|
47
|
-
_overrideProps = (fiber, path, value) => {
|
|
48
|
-
prevOverrideProps(fiber, path, value);
|
|
49
|
-
renderer.overrideProps?.(fiber, path, value);
|
|
50
|
-
};
|
|
51
|
-
} else if (renderer.overrideProps) _overrideProps = renderer.overrideProps;
|
|
52
|
-
_overrideContext = (fiber, contextType, path, value) => {
|
|
53
|
-
let current = fiber;
|
|
54
|
-
while (current) {
|
|
55
|
-
const type = current.type;
|
|
56
|
-
if (type === contextType || type?.Provider === contextType) {
|
|
57
|
-
if (_overrideProps) {
|
|
58
|
-
_overrideProps(current, ["value", ...path], value);
|
|
59
|
-
if (current.alternate) _overrideProps(current.alternate, ["value", ...path], value);
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
current = current.return;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
} catch {}
|
|
67
|
-
};
|
|
68
|
-
const isPOJO = (maybePOJO) => {
|
|
69
|
-
return Object.prototype.toString.call(maybePOJO) === "[object Object]" && (Object.getPrototypeOf(maybePOJO) === Object.prototype || Object.getPrototypeOf(maybePOJO) === null);
|
|
70
|
-
};
|
|
71
|
-
const buildPathsFromValue = (maybePOJO, basePath = []) => {
|
|
72
|
-
if (!isPOJO(maybePOJO)) return [{
|
|
73
|
-
path: basePath,
|
|
74
|
-
value: maybePOJO
|
|
75
|
-
}];
|
|
76
|
-
const paths = [];
|
|
77
|
-
for (const key in maybePOJO) {
|
|
78
|
-
const value = maybePOJO[key];
|
|
79
|
-
const path = basePath.concat(key);
|
|
80
|
-
if (isPOJO(value)) paths.push(...buildPathsFromValue(value, path));
|
|
81
|
-
else paths.push({
|
|
82
|
-
path,
|
|
83
|
-
value
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return paths;
|
|
87
|
-
};
|
|
88
|
-
const overrideProps = (fiber, partialValue) => {
|
|
89
|
-
injectOverrideMethods();
|
|
90
|
-
const paths = buildPathsFromValue(partialValue);
|
|
91
|
-
for (const { path, value } of paths) try {
|
|
92
|
-
_overrideProps?.(fiber, path, value);
|
|
93
|
-
} catch {}
|
|
94
|
-
};
|
|
95
|
-
const overrideHookState = (fiber, id, partialValue) => {
|
|
96
|
-
injectOverrideMethods();
|
|
97
|
-
const hookId = String(id);
|
|
98
|
-
if (isPOJO(partialValue)) {
|
|
99
|
-
const paths = buildPathsFromValue(partialValue);
|
|
100
|
-
for (const { path, value } of paths) try {
|
|
101
|
-
_overrideHookState?.(fiber, hookId, path, value);
|
|
102
|
-
} catch {}
|
|
103
|
-
} else try {
|
|
104
|
-
_overrideHookState?.(fiber, hookId, [], partialValue);
|
|
105
|
-
} catch {}
|
|
106
|
-
};
|
|
107
|
-
const overrideContext = (fiber, contextType, partialValue) => {
|
|
108
|
-
injectOverrideMethods();
|
|
109
|
-
if (isPOJO(partialValue)) {
|
|
110
|
-
const paths = buildPathsFromValue(partialValue);
|
|
111
|
-
for (const { path, value } of paths) try {
|
|
112
|
-
_overrideContext?.(fiber, contextType, path, value);
|
|
113
|
-
} catch {}
|
|
114
|
-
} else try {
|
|
115
|
-
_overrideContext?.(fiber, contextType, [], partialValue);
|
|
116
|
-
} catch {}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
exports.injectOverrideMethods = injectOverrideMethods;
|
|
121
|
-
exports.overrideContext = overrideContext;
|
|
122
|
-
exports.overrideHookState = overrideHookState;
|
|
123
|
-
exports.overrideProps = overrideProps;
|
package/dist/override.d.cts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Fiber } from "./types-CmdVtE8u.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/override.d.ts
|
|
4
|
-
declare const injectOverrideMethods: () => {
|
|
5
|
-
overrideProps: ((fiber: Fiber, path: string[], value: unknown) => void) | null | undefined;
|
|
6
|
-
overrideHookState: ((fiber: Fiber, id: string, path: string[], value: unknown) => void) | null | undefined;
|
|
7
|
-
overrideContext: ((fiber: Fiber, contextType: unknown, path: string[], value: unknown) => void) | null | undefined;
|
|
8
|
-
} | null | undefined;
|
|
9
|
-
declare const overrideProps: (fiber: Fiber, partialValue: Record<string, unknown>) => void;
|
|
10
|
-
declare const overrideHookState: (fiber: Fiber, id: number, partialValue: Record<string, unknown> | unknown) => void;
|
|
11
|
-
declare const overrideContext: (fiber: Fiber, contextType: unknown, partialValue: Record<string, unknown> | unknown) => void;
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { injectOverrideMethods, overrideContext, overrideHookState, overrideProps };
|
package/dist/override.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Fiber } from "./types-CeFOA1ZM.js";
|
|
2
|
-
|
|
3
|
-
//#region src/override.d.ts
|
|
4
|
-
declare const injectOverrideMethods: () => {
|
|
5
|
-
overrideProps: ((fiber: Fiber, path: string[], value: unknown) => void) | null | undefined;
|
|
6
|
-
overrideHookState: ((fiber: Fiber, id: string, path: string[], value: unknown) => void) | null | undefined;
|
|
7
|
-
overrideContext: ((fiber: Fiber, contextType: unknown, path: string[], value: unknown) => void) | null | undefined;
|
|
8
|
-
} | null | undefined;
|
|
9
|
-
declare const overrideProps: (fiber: Fiber, partialValue: Record<string, unknown>) => void;
|
|
10
|
-
declare const overrideHookState: (fiber: Fiber, id: number, partialValue: Record<string, unknown> | unknown) => void;
|
|
11
|
-
declare const overrideContext: (fiber: Fiber, contextType: unknown, partialValue: Record<string, unknown> | unknown) => void;
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { injectOverrideMethods, overrideContext, overrideHookState, overrideProps };
|