@ptolemy2002/react-proxy-context 1.0.13 → 1.0.15
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/index.js +190 -2
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -540,6 +540,193 @@ var require_react_hook_result = __commonJS({
|
|
|
540
540
|
}
|
|
541
541
|
});
|
|
542
542
|
|
|
543
|
+
// node_modules/@ptolemy2002/react-utils/index.js
|
|
544
|
+
var require_react_utils = __commonJS({
|
|
545
|
+
"node_modules/@ptolemy2002/react-utils/index.js"(exports, module2) {
|
|
546
|
+
var __create2 = Object.create;
|
|
547
|
+
var __defProp2 = Object.defineProperty;
|
|
548
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
549
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
550
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
551
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
552
|
+
var __commonJS2 = (cb, mod) => function __require() {
|
|
553
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
554
|
+
};
|
|
555
|
+
var __export2 = (target, all) => {
|
|
556
|
+
for (var name in all)
|
|
557
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
558
|
+
};
|
|
559
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
560
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
561
|
+
for (let key of __getOwnPropNames2(from))
|
|
562
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
563
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
564
|
+
}
|
|
565
|
+
return to;
|
|
566
|
+
};
|
|
567
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
|
|
568
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
569
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
570
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
571
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
572
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
|
|
573
|
+
mod
|
|
574
|
+
));
|
|
575
|
+
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
576
|
+
var require_is_callable2 = __commonJS2({
|
|
577
|
+
"node_modules/is-callable/index.js"(exports2, module22) {
|
|
578
|
+
"use strict";
|
|
579
|
+
var fnToStr = Function.prototype.toString;
|
|
580
|
+
var reflectApply = typeof Reflect === "object" && Reflect !== null && Reflect.apply;
|
|
581
|
+
var badArrayLike;
|
|
582
|
+
var isCallableMarker;
|
|
583
|
+
if (typeof reflectApply === "function" && typeof Object.defineProperty === "function") {
|
|
584
|
+
try {
|
|
585
|
+
badArrayLike = Object.defineProperty({}, "length", {
|
|
586
|
+
get: function() {
|
|
587
|
+
throw isCallableMarker;
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
isCallableMarker = {};
|
|
591
|
+
reflectApply(function() {
|
|
592
|
+
throw 42;
|
|
593
|
+
}, null, badArrayLike);
|
|
594
|
+
} catch (_) {
|
|
595
|
+
if (_ !== isCallableMarker) {
|
|
596
|
+
reflectApply = null;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
reflectApply = null;
|
|
601
|
+
}
|
|
602
|
+
var constructorRegex = /^\s*class\b/;
|
|
603
|
+
var isES6ClassFn = function isES6ClassFunction(value) {
|
|
604
|
+
try {
|
|
605
|
+
var fnStr = fnToStr.call(value);
|
|
606
|
+
return constructorRegex.test(fnStr);
|
|
607
|
+
} catch (e) {
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var tryFunctionObject = function tryFunctionToStr(value) {
|
|
612
|
+
try {
|
|
613
|
+
if (isES6ClassFn(value)) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
fnToStr.call(value);
|
|
617
|
+
return true;
|
|
618
|
+
} catch (e) {
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
var toStr = Object.prototype.toString;
|
|
623
|
+
var objectClass = "[object Object]";
|
|
624
|
+
var fnClass = "[object Function]";
|
|
625
|
+
var genClass = "[object GeneratorFunction]";
|
|
626
|
+
var ddaClass = "[object HTMLAllCollection]";
|
|
627
|
+
var ddaClass2 = "[object HTML document.all class]";
|
|
628
|
+
var ddaClass3 = "[object HTMLCollection]";
|
|
629
|
+
var hasToStringTag = typeof Symbol === "function" && !!Symbol.toStringTag;
|
|
630
|
+
var isIE68 = !(0 in [,]);
|
|
631
|
+
var isDDA = function isDocumentDotAll() {
|
|
632
|
+
return false;
|
|
633
|
+
};
|
|
634
|
+
if (typeof document === "object") {
|
|
635
|
+
all = document.all;
|
|
636
|
+
if (toStr.call(all) === toStr.call(document.all)) {
|
|
637
|
+
isDDA = function isDocumentDotAll(value) {
|
|
638
|
+
if ((isIE68 || !value) && (typeof value === "undefined" || typeof value === "object")) {
|
|
639
|
+
try {
|
|
640
|
+
var str = toStr.call(value);
|
|
641
|
+
return (str === ddaClass || str === ddaClass2 || str === ddaClass3 || str === objectClass) && value("") == null;
|
|
642
|
+
} catch (e) {
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return false;
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
var all;
|
|
650
|
+
module22.exports = reflectApply ? function isCallable2(value) {
|
|
651
|
+
if (isDDA(value)) {
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
if (!value) {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
if (typeof value !== "function" && typeof value !== "object") {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
try {
|
|
661
|
+
reflectApply(value, null, badArrayLike);
|
|
662
|
+
} catch (e) {
|
|
663
|
+
if (e !== isCallableMarker) {
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return !isES6ClassFn(value) && tryFunctionObject(value);
|
|
668
|
+
} : function isCallable2(value) {
|
|
669
|
+
if (isDDA(value)) {
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
if (!value) {
|
|
673
|
+
return false;
|
|
674
|
+
}
|
|
675
|
+
if (typeof value !== "function" && typeof value !== "object") {
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
if (hasToStringTag) {
|
|
679
|
+
return tryFunctionObject(value);
|
|
680
|
+
}
|
|
681
|
+
if (isES6ClassFn(value)) {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
var strClass = toStr.call(value);
|
|
685
|
+
if (strClass !== fnClass && strClass !== genClass && !/^\[object HTML/.test(strClass)) {
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
return tryFunctionObject(value);
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
var src_exports2 = {};
|
|
693
|
+
__export2(src_exports2, {
|
|
694
|
+
Spacer: () => Spacer,
|
|
695
|
+
partialMemo: () => partialMemo2
|
|
696
|
+
});
|
|
697
|
+
module2.exports = __toCommonJS2(src_exports2);
|
|
698
|
+
var import_react2 = __toESM2(require("react"));
|
|
699
|
+
function r(e) {
|
|
700
|
+
var t, f, n = "";
|
|
701
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
702
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
703
|
+
var o = e.length;
|
|
704
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
705
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
706
|
+
return n;
|
|
707
|
+
}
|
|
708
|
+
function clsx() {
|
|
709
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
710
|
+
return n;
|
|
711
|
+
}
|
|
712
|
+
var clsx_default = clsx;
|
|
713
|
+
var import_is_callable2 = __toESM2(require_is_callable2());
|
|
714
|
+
var partialMemo2 = (component, deps = []) => {
|
|
715
|
+
return (0, import_react2.memo)(component, (prevProps, nextProps) => {
|
|
716
|
+
if (deps.length === 0) return true;
|
|
717
|
+
return deps.every((dep) => {
|
|
718
|
+
if ((0, import_is_callable2.default)(dep)) return dep(prevProps, nextProps);
|
|
719
|
+
return prevProps[dep] === nextProps[dep];
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
var Spacer = (0, import_react2.memo)(function({ size = "1rem", horizontal = false, style = {}, className = null, ...props } = {}) {
|
|
724
|
+
const keyName = horizontal ? "width" : "height";
|
|
725
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", { className: clsx_default("spacer", className), style: { ...style, [keyName]: size }, ...props });
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
|
|
543
730
|
// src/index.js
|
|
544
731
|
var src_exports = {};
|
|
545
732
|
__export(src_exports, {
|
|
@@ -569,13 +756,14 @@ var import_react_force_rerender = __toESM(require_react_force_rerender());
|
|
|
569
756
|
var import_react_mount_effects = __toESM(require_react_mount_effects());
|
|
570
757
|
var import_js_utils = __toESM(require_js_utils());
|
|
571
758
|
var import_react_hook_result = __toESM(require_react_hook_result());
|
|
759
|
+
var import_react_utils = __toESM(require_react_utils());
|
|
572
760
|
function createProxyContext(defaultValue, name) {
|
|
573
761
|
if (typeof Proxy == "undefined") throw new Error("Proxy is not supported in this environment.");
|
|
574
762
|
const context = (0, import_react.createContext)(defaultValue);
|
|
575
763
|
context.name = name;
|
|
576
764
|
return context;
|
|
577
765
|
}
|
|
578
|
-
|
|
766
|
+
var ProxyContextProvider = (0, import_react_utils.partialMemo)(function ProxyContextProvider2({ contextClass, children, value, onChange, proxyRef }) {
|
|
579
767
|
const changeSubscribers = (0, import_react.useRef)({});
|
|
580
768
|
const objRef = (0, import_react.useRef)();
|
|
581
769
|
const contextRef = (0, import_react.useRef)({});
|
|
@@ -639,7 +827,7 @@ function ProxyContextProvider({ contextClass, children, value, onChange, proxyRe
|
|
|
639
827
|
contextRef.current.subscribe = subscribe;
|
|
640
828
|
contextRef.current.unsubscribe = unsubscribe;
|
|
641
829
|
return /* @__PURE__ */ import_react.default.createElement(contextClass.Provider, { value: contextRef.current }, children);
|
|
642
|
-
}
|
|
830
|
+
}, ["children", "onChange", "proxyRef"]);
|
|
643
831
|
function useProxyContext(contextClass, deps, onChange, listenReinit = true) {
|
|
644
832
|
const context = (0, import_react.useContext)(contextClass);
|
|
645
833
|
const forceRerender = (0, import_react_force_rerender.default)();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ptolemy2002/react-proxy-context",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"index.js"
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"nanoid": "^5.0.7"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ptolemy2002/react-hook-result": "^1.0.2"
|
|
45
|
+
"@ptolemy2002/react-hook-result": "^1.0.2",
|
|
46
|
+
"@ptolemy2002/react-utils": "^1.1.0"
|
|
46
47
|
}
|
|
47
48
|
}
|