@ptolemy2002/react-proxy-context 2.1.3 → 2.3.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.
package/README.md CHANGED
@@ -20,9 +20,9 @@ type OnChangeReinitCallback<T> =
20
20
  (current: T, prev?: T) => void
21
21
  ;
22
22
 
23
- type Dependency<T> = keyof T | (
23
+ type Dependency<_T, T=Exclude<_T, null | undefined>> = keyof T | (
24
24
  <K extends keyof T>(prop: K, current: T[K], prev: T[K], obj: T) => boolean
25
- ) | null | undefined | false;
25
+ ) | null | undefined | false | [keyof T, ...PropertyKey[]];
26
26
 
27
27
  type ProxyContext<T> = ContextWithName<ProxyContextValue<T> | undefined>;
28
28
 
@@ -54,9 +54,19 @@ type UseProxyContextResult<T> = HookResultData<{
54
54
  ## Functions
55
55
  The following functions are available in the library:
56
56
 
57
+ ### evaluateDependency<T>
58
+ #### Description
59
+ Given a dependency, if it is an array instance, converts it to the equivalent function that will test for equality of a nested property. If it is not an array instance, returns the dependency as is.
60
+
61
+ #### Parameters
62
+ - `dependency` (`Dependency<T>`): The dependency to evaluate.
63
+
64
+ #### Returns
65
+ `Dependency<T>` - The evaluated dependency. If the dependency is an array, it will be converted to a function that tests for equality of a nested property.
66
+
57
67
  ### createProxyContext<T>
58
68
  #### Description
59
- Creates a new instance of the ProxyContext, essentially to be used as the context type, with the specified name. This is effectively just the normal React createContext function, but with a check to ensure that the browser supports Proxies. `T` represents the type of the object that will be stored in the context.
69
+ Creates a new instance of the ProxyContext, essentially to be used as the context type, with the specified name. This is effectively just the normal React `createContext` function, but with a check to ensure that the browser supports Proxies. `T` represents the type of the object that will be stored in the context.
60
70
 
61
71
  #### Parameters
62
72
  - `name` (String): The name of the context. This is used for debugging purposes.
@@ -88,7 +98,7 @@ A hook that uses the context provided by the `ProxyContextProvider` component. T
88
98
 
89
99
  #### Parameters
90
100
  - `contextClass` (`ProxyContext<T>`): The context class that was created using `createProxyContext`.
91
- - `deps` (`Dependency<T>[] | null`): An array of dependencies to listen to. If any of these properties on the context change, the hook will re-render. If this is falsy, any mutation will trigger a re-render. You can also specify a function that returns a boolean to determine whether to re-render. If this is null, the hook will re-render on any mutation. By default, this is an empty array.
101
+ - `deps` (`Dependency<T>[] | null`): An array of dependencies to listen to. If any of these properties on the context change, the hook will re-render. If this is falsy, any mutation will trigger a re-render. If a dependency is an array, it represents a nested property dependency. You can also specify a function that returns a boolean to determine whether to re-render. By default, this is an empty array.
92
102
  - `onChangeProp` (`OnChangePropCallback<T> | undefined`): A function that is called whenever a property of the context is changed. The first parameter is the property that was changed, the second parameter is the current value of the property, and the third parameter is the previous value of the property. This is useful for listening to changes in the provider's parent component.
93
103
  - `onChangeReinit` (`OnChangeReinitCallback<T> | undefined`): A function that is called whenever the context is reinitialized. The first parameter is the current value of the context, and the second parameter is the previous value of the context. This is useful for listening to changes in the provider's parent component.
94
104
  - `listenReinit` (`boolean`): Whether to listen to full reassignments of the context. If this is true, the hook will re-render whenever the context is reinitialized. By default, this is true.
package/dist/main.d.ts CHANGED
@@ -12,7 +12,8 @@ export type ProxyContextValue<T> = {
12
12
  unsubscribe: (id: string) => void;
13
13
  };
14
14
  export declare function createProxyContext<T>(name: string): ProxyContext<T>;
15
- export type Dependency<T> = keyof T | (<K extends keyof T>(prop: K, current: T[K], prev: T[K], obj: T) => boolean) | null | undefined | false;
15
+ export type Dependency<T> = keyof T | (<K extends keyof T>(prop: K, current: T[K], prev: T[K], obj: T) => boolean) | null | undefined | false | [keyof T, ...PropertyKey[]];
16
+ export declare function evaluateDependency<T>(dep: Dependency<T>): Exclude<Dependency<T>, any[]> | keyof T;
16
17
  export type ProxyContext<T> = ContextWithName<ProxyContextValue<T> | undefined>;
17
18
  export type ProxyContextProviderProps<T> = {
18
19
  children: ReactNode;
package/dist/main.js CHANGED
@@ -1,10 +1,10 @@
1
- import Ae, { useEffect as Ie, createContext as br, useRef as H, useImperativeHandle as yr, useCallback as ie, useContext as mr } from "react";
1
+ import $e, { useEffect as We, createContext as br, useRef as Z, useImperativeHandle as yr, useCallback as se, useContext as mr } from "react";
2
2
  import { nanoid as Rr } from "nanoid";
3
- import L from "is-callable";
4
- import $e from "@ptolemy2002/react-force-rerender";
3
+ import Y from "is-callable";
4
+ import Ye from "@ptolemy2002/react-force-rerender";
5
5
  import gr from "@ptolemy2002/react-hook-result";
6
6
  import { partialMemo as hr } from "@ptolemy2002/react-utils";
7
- var ue = { exports: {} }, N = {};
7
+ var ce = { exports: {} }, N = {};
8
8
  /**
9
9
  * @license React
10
10
  * react-jsx-runtime.production.min.js
@@ -14,19 +14,19 @@ var ue = { exports: {} }, N = {};
14
14
  * This source code is licensed under the MIT license found in the
15
15
  * LICENSE file in the root directory of this source tree.
16
16
  */
17
- var De;
17
+ var Fe;
18
18
  function Er() {
19
- if (De) return N;
20
- De = 1;
21
- var y = Ae, _ = Symbol.for("react.element"), k = Symbol.for("react.fragment"), h = Object.prototype.hasOwnProperty, x = y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, R = { key: !0, ref: !0, __self: !0, __source: !0 };
22
- function E(c, s, T) {
23
- var v, S = {}, O = null, b = null;
24
- T !== void 0 && (O = "" + T), s.key !== void 0 && (O = "" + s.key), s.ref !== void 0 && (b = s.ref);
25
- for (v in s) h.call(s, v) && !R.hasOwnProperty(v) && (S[v] = s[v]);
26
- if (c && c.defaultProps) for (v in s = c.defaultProps, s) S[v] === void 0 && (S[v] = s[v]);
27
- return { $$typeof: _, type: c, key: O, ref: b, props: S, _owner: x.current };
19
+ if (Fe) return N;
20
+ Fe = 1;
21
+ var v = $e, E = Symbol.for("react.element"), w = Symbol.for("react.fragment"), g = Object.prototype.hasOwnProperty, T = v.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, m = { key: !0, ref: !0, __self: !0, __source: !0 };
22
+ function p(i, s, P) {
23
+ var b, x = {}, O = null, R = null;
24
+ P !== void 0 && (O = "" + P), s.key !== void 0 && (O = "" + s.key), s.ref !== void 0 && (R = s.ref);
25
+ for (b in s) g.call(s, b) && !m.hasOwnProperty(b) && (x[b] = s[b]);
26
+ if (i && i.defaultProps) for (b in s = i.defaultProps, s) x[b] === void 0 && (x[b] = s[b]);
27
+ return { $$typeof: E, type: i, key: O, ref: R, props: x, _owner: T.current };
28
28
  }
29
- return N.Fragment = k, N.jsx = E, N.jsxs = E, N;
29
+ return N.Fragment = w, N.jsx = p, N.jsxs = p, N;
30
30
  }
31
31
  var B = {};
32
32
  /**
@@ -38,17 +38,17 @@ var B = {};
38
38
  * This source code is licensed under the MIT license found in the
39
39
  * LICENSE file in the root directory of this source tree.
40
40
  */
41
- var Fe;
41
+ var Ie;
42
42
  function _r() {
43
- return Fe || (Fe = 1, process.env.NODE_ENV !== "production" && function() {
44
- var y = Ae, _ = Symbol.for("react.element"), k = Symbol.for("react.portal"), h = Symbol.for("react.fragment"), x = Symbol.for("react.strict_mode"), R = Symbol.for("react.profiler"), E = Symbol.for("react.provider"), c = Symbol.for("react.context"), s = Symbol.for("react.forward_ref"), T = Symbol.for("react.suspense"), v = Symbol.for("react.suspense_list"), S = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), b = Symbol.for("react.offscreen"), D = Symbol.iterator, C = "@@iterator";
45
- function j(e) {
43
+ return Ie || (Ie = 1, process.env.NODE_ENV !== "production" && function() {
44
+ var v = $e, E = Symbol.for("react.element"), w = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), T = Symbol.for("react.strict_mode"), m = Symbol.for("react.profiler"), p = Symbol.for("react.provider"), i = Symbol.for("react.context"), s = Symbol.for("react.forward_ref"), P = Symbol.for("react.suspense"), b = Symbol.for("react.suspense_list"), x = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), R = Symbol.for("react.offscreen"), D = Symbol.iterator, C = "@@iterator";
45
+ function k(e) {
46
46
  if (e === null || typeof e != "object")
47
47
  return null;
48
48
  var r = D && e[D] || e[C];
49
49
  return typeof r == "function" ? r : null;
50
50
  }
51
- var p = y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
51
+ var y = v.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
52
52
  function f(e) {
53
53
  {
54
54
  for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
@@ -58,34 +58,34 @@ function _r() {
58
58
  }
59
59
  function I(e, r, t) {
60
60
  {
61
- var n = p.ReactDebugCurrentFrame, i = n.getStackAddendum();
62
- i !== "" && (r += "%s", t = t.concat([i]));
63
- var u = t.map(function(o) {
61
+ var n = y.ReactDebugCurrentFrame, u = n.getStackAddendum();
62
+ u !== "" && (r += "%s", t = t.concat([u]));
63
+ var c = t.map(function(o) {
64
64
  return String(o);
65
65
  });
66
- u.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, u);
66
+ c.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, c);
67
67
  }
68
68
  }
69
- var $ = !1, J = !1, We = !1, Ye = !1, Le = !1, se;
70
- se = Symbol.for("react.module.reference");
69
+ var J = !1, L = !1, q = !1, K = !1, Le = !1, fe;
70
+ fe = Symbol.for("react.module.reference");
71
71
  function Ve(e) {
72
- return !!(typeof e == "string" || typeof e == "function" || e === h || e === R || Le || e === x || e === T || e === v || Ye || e === b || $ || J || We || typeof e == "object" && e !== null && (e.$$typeof === O || e.$$typeof === S || e.$$typeof === E || e.$$typeof === c || e.$$typeof === s || // This needs to include all possible module reference object
72
+ return !!(typeof e == "string" || typeof e == "function" || e === g || e === m || Le || e === T || e === P || e === b || K || e === R || J || L || q || typeof e == "object" && e !== null && (e.$$typeof === O || e.$$typeof === x || e.$$typeof === p || e.$$typeof === i || e.$$typeof === s || // This needs to include all possible module reference object
73
73
  // types supported by any Flight configuration anywhere since
74
74
  // we don't know which Flight build this will end up being used
75
75
  // with.
76
- e.$$typeof === se || e.getModuleId !== void 0));
76
+ e.$$typeof === fe || e.getModuleId !== void 0));
77
77
  }
78
78
  function Me(e, r, t) {
79
79
  var n = e.displayName;
80
80
  if (n)
81
81
  return n;
82
- var i = r.displayName || r.name || "";
83
- return i !== "" ? t + "(" + i + ")" : t;
82
+ var u = r.displayName || r.name || "";
83
+ return u !== "" ? t + "(" + u + ")" : t;
84
84
  }
85
- function ce(e) {
85
+ function le(e) {
86
86
  return e.displayName || "Context";
87
87
  }
88
- function w(e) {
88
+ function j(e) {
89
89
  if (e == null)
90
90
  return null;
91
91
  if (typeof e.tag == "number" && f("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
@@ -93,36 +93,36 @@ function _r() {
93
93
  if (typeof e == "string")
94
94
  return e;
95
95
  switch (e) {
96
- case h:
96
+ case g:
97
97
  return "Fragment";
98
- case k:
98
+ case w:
99
99
  return "Portal";
100
- case R:
100
+ case m:
101
101
  return "Profiler";
102
- case x:
103
- return "StrictMode";
104
102
  case T:
103
+ return "StrictMode";
104
+ case P:
105
105
  return "Suspense";
106
- case v:
106
+ case b:
107
107
  return "SuspenseList";
108
108
  }
109
109
  if (typeof e == "object")
110
110
  switch (e.$$typeof) {
111
- case c:
111
+ case i:
112
112
  var r = e;
113
- return ce(r) + ".Consumer";
114
- case E:
113
+ return le(r) + ".Consumer";
114
+ case p:
115
115
  var t = e;
116
- return ce(t._context) + ".Provider";
116
+ return le(t._context) + ".Provider";
117
117
  case s:
118
118
  return Me(e, e.render, "ForwardRef");
119
- case S:
119
+ case x:
120
120
  var n = e.displayName || null;
121
- return n !== null ? n : w(e.type) || "Memo";
121
+ return n !== null ? n : j(e.type) || "Memo";
122
122
  case O: {
123
- var i = e, u = i._payload, o = i._init;
123
+ var u = e, c = u._payload, o = u._init;
124
124
  try {
125
- return w(o(u));
125
+ return j(o(c));
126
126
  } catch {
127
127
  return null;
128
128
  }
@@ -130,18 +130,18 @@ function _r() {
130
130
  }
131
131
  return null;
132
132
  }
133
- var F = Object.assign, V = 0, fe, le, de, ve, pe, be, ye;
134
- function me() {
133
+ var A = Object.assign, V = 0, de, ve, pe, be, ye, me, Re;
134
+ function ge() {
135
135
  }
136
- me.__reactDisabledLog = !0;
136
+ ge.__reactDisabledLog = !0;
137
137
  function Ue() {
138
138
  {
139
139
  if (V === 0) {
140
- fe = console.log, le = console.info, de = console.warn, ve = console.error, pe = console.group, be = console.groupCollapsed, ye = console.groupEnd;
140
+ de = console.log, ve = console.info, pe = console.warn, be = console.error, ye = console.group, me = console.groupCollapsed, Re = console.groupEnd;
141
141
  var e = {
142
142
  configurable: !0,
143
143
  enumerable: !0,
144
- value: me,
144
+ value: ge,
145
145
  writable: !0
146
146
  };
147
147
  Object.defineProperties(console, {
@@ -166,65 +166,65 @@ function _r() {
166
166
  writable: !0
167
167
  };
168
168
  Object.defineProperties(console, {
169
- log: F({}, e, {
170
- value: fe
171
- }),
172
- info: F({}, e, {
173
- value: le
174
- }),
175
- warn: F({}, e, {
169
+ log: A({}, e, {
176
170
  value: de
177
171
  }),
178
- error: F({}, e, {
172
+ info: A({}, e, {
179
173
  value: ve
180
174
  }),
181
- group: F({}, e, {
175
+ warn: A({}, e, {
182
176
  value: pe
183
177
  }),
184
- groupCollapsed: F({}, e, {
178
+ error: A({}, e, {
185
179
  value: be
186
180
  }),
187
- groupEnd: F({}, e, {
181
+ group: A({}, e, {
188
182
  value: ye
183
+ }),
184
+ groupCollapsed: A({}, e, {
185
+ value: me
186
+ }),
187
+ groupEnd: A({}, e, {
188
+ value: Re
189
189
  })
190
190
  });
191
191
  }
192
192
  V < 0 && f("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
193
193
  }
194
194
  }
195
- var X = p.ReactCurrentDispatcher, Z;
196
- function q(e, r, t) {
195
+ var Q = y.ReactCurrentDispatcher, ee;
196
+ function G(e, r, t) {
197
197
  {
198
- if (Z === void 0)
198
+ if (ee === void 0)
199
199
  try {
200
200
  throw Error();
201
- } catch (i) {
202
- var n = i.stack.trim().match(/\n( *(at )?)/);
203
- Z = n && n[1] || "";
201
+ } catch (u) {
202
+ var n = u.stack.trim().match(/\n( *(at )?)/);
203
+ ee = n && n[1] || "";
204
204
  }
205
205
  return `
206
- ` + Z + e;
206
+ ` + ee + e;
207
207
  }
208
208
  }
209
- var Q = !1, K;
209
+ var re = !1, z;
210
210
  {
211
211
  var Be = typeof WeakMap == "function" ? WeakMap : Map;
212
- K = new Be();
212
+ z = new Be();
213
213
  }
214
- function Re(e, r) {
215
- if (!e || Q)
214
+ function he(e, r) {
215
+ if (!e || re)
216
216
  return "";
217
217
  {
218
- var t = K.get(e);
218
+ var t = z.get(e);
219
219
  if (t !== void 0)
220
220
  return t;
221
221
  }
222
222
  var n;
223
- Q = !0;
224
- var i = Error.prepareStackTrace;
223
+ re = !0;
224
+ var u = Error.prepareStackTrace;
225
225
  Error.prepareStackTrace = void 0;
226
- var u;
227
- u = X.current, X.current = null, Ue();
226
+ var c;
227
+ c = Q.current, Q.current = null, Ue();
228
228
  try {
229
229
  if (r) {
230
230
  var o = function() {
@@ -237,116 +237,116 @@ function _r() {
237
237
  }), typeof Reflect == "object" && Reflect.construct) {
238
238
  try {
239
239
  Reflect.construct(o, []);
240
- } catch (g) {
241
- n = g;
240
+ } catch (_) {
241
+ n = _;
242
242
  }
243
243
  Reflect.construct(e, [], o);
244
244
  } else {
245
245
  try {
246
246
  o.call();
247
- } catch (g) {
248
- n = g;
247
+ } catch (_) {
248
+ n = _;
249
249
  }
250
250
  e.call(o.prototype);
251
251
  }
252
252
  } else {
253
253
  try {
254
254
  throw Error();
255
- } catch (g) {
256
- n = g;
255
+ } catch (_) {
256
+ n = _;
257
257
  }
258
258
  e();
259
259
  }
260
- } catch (g) {
261
- if (g && n && typeof g.stack == "string") {
262
- for (var a = g.stack.split(`
263
- `), m = n.stack.split(`
264
- `), l = a.length - 1, d = m.length - 1; l >= 1 && d >= 0 && a[l] !== m[d]; )
260
+ } catch (_) {
261
+ if (_ && n && typeof _.stack == "string") {
262
+ for (var a = _.stack.split(`
263
+ `), h = n.stack.split(`
264
+ `), l = a.length - 1, d = h.length - 1; l >= 1 && d >= 0 && a[l] !== h[d]; )
265
265
  d--;
266
266
  for (; l >= 1 && d >= 0; l--, d--)
267
- if (a[l] !== m[d]) {
267
+ if (a[l] !== h[d]) {
268
268
  if (l !== 1 || d !== 1)
269
269
  do
270
- if (l--, d--, d < 0 || a[l] !== m[d]) {
271
- var P = `
270
+ if (l--, d--, d < 0 || a[l] !== h[d]) {
271
+ var S = `
272
272
  ` + a[l].replace(" at new ", " at ");
273
- return e.displayName && P.includes("<anonymous>") && (P = P.replace("<anonymous>", e.displayName)), typeof e == "function" && K.set(e, P), P;
273
+ return e.displayName && S.includes("<anonymous>") && (S = S.replace("<anonymous>", e.displayName)), typeof e == "function" && z.set(e, S), S;
274
274
  }
275
275
  while (l >= 1 && d >= 0);
276
276
  break;
277
277
  }
278
278
  }
279
279
  } finally {
280
- Q = !1, X.current = u, Ne(), Error.prepareStackTrace = i;
280
+ re = !1, Q.current = c, Ne(), Error.prepareStackTrace = u;
281
281
  }
282
- var Y = e ? e.displayName || e.name : "", A = Y ? q(Y) : "";
283
- return typeof e == "function" && K.set(e, A), A;
282
+ var W = e ? e.displayName || e.name : "", F = W ? G(W) : "";
283
+ return typeof e == "function" && z.set(e, F), F;
284
284
  }
285
285
  function Je(e, r, t) {
286
- return Re(e, !1);
286
+ return he(e, !1);
287
287
  }
288
288
  function qe(e) {
289
289
  var r = e.prototype;
290
290
  return !!(r && r.isReactComponent);
291
291
  }
292
- function G(e, r, t) {
292
+ function H(e, r, t) {
293
293
  if (e == null)
294
294
  return "";
295
295
  if (typeof e == "function")
296
- return Re(e, qe(e));
296
+ return he(e, qe(e));
297
297
  if (typeof e == "string")
298
- return q(e);
298
+ return G(e);
299
299
  switch (e) {
300
- case T:
301
- return q("Suspense");
302
- case v:
303
- return q("SuspenseList");
300
+ case P:
301
+ return G("Suspense");
302
+ case b:
303
+ return G("SuspenseList");
304
304
  }
305
305
  if (typeof e == "object")
306
306
  switch (e.$$typeof) {
307
307
  case s:
308
308
  return Je(e.render);
309
- case S:
310
- return G(e.type, r, t);
309
+ case x:
310
+ return H(e.type, r, t);
311
311
  case O: {
312
- var n = e, i = n._payload, u = n._init;
312
+ var n = e, u = n._payload, c = n._init;
313
313
  try {
314
- return G(u(i), r, t);
314
+ return H(c(u), r, t);
315
315
  } catch {
316
316
  }
317
317
  }
318
318
  }
319
319
  return "";
320
320
  }
321
- var M = Object.prototype.hasOwnProperty, ge = {}, he = p.ReactDebugCurrentFrame;
322
- function z(e) {
321
+ var M = Object.prototype.hasOwnProperty, Ee = {}, _e = y.ReactDebugCurrentFrame;
322
+ function X(e) {
323
323
  if (e) {
324
- var r = e._owner, t = G(e.type, e._source, r ? r.type : null);
325
- he.setExtraStackFrame(t);
324
+ var r = e._owner, t = H(e.type, e._source, r ? r.type : null);
325
+ _e.setExtraStackFrame(t);
326
326
  } else
327
- he.setExtraStackFrame(null);
327
+ _e.setExtraStackFrame(null);
328
328
  }
329
- function Ke(e, r, t, n, i) {
329
+ function Ke(e, r, t, n, u) {
330
330
  {
331
- var u = Function.call.bind(M);
331
+ var c = Function.call.bind(M);
332
332
  for (var o in e)
333
- if (u(e, o)) {
333
+ if (c(e, o)) {
334
334
  var a = void 0;
335
335
  try {
336
336
  if (typeof e[o] != "function") {
337
- var m = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
338
- throw m.name = "Invariant Violation", m;
337
+ var h = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
338
+ throw h.name = "Invariant Violation", h;
339
339
  }
340
340
  a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
341
341
  } catch (l) {
342
342
  a = l;
343
343
  }
344
- a && !(a instanceof Error) && (z(i), f("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, o, typeof a), z(null)), a instanceof Error && !(a.message in ge) && (ge[a.message] = !0, z(i), f("Failed %s type: %s", t, a.message), z(null));
344
+ a && !(a instanceof Error) && (X(u), f("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, o, typeof a), X(null)), a instanceof Error && !(a.message in Ee) && (Ee[a.message] = !0, X(u), f("Failed %s type: %s", t, a.message), X(null));
345
345
  }
346
346
  }
347
347
  }
348
348
  var Ge = Array.isArray;
349
- function ee(e) {
349
+ function te(e) {
350
350
  return Ge(e);
351
351
  }
352
352
  function ze(e) {
@@ -357,25 +357,25 @@ function _r() {
357
357
  }
358
358
  function He(e) {
359
359
  try {
360
- return Ee(e), !1;
360
+ return Te(e), !1;
361
361
  } catch {
362
362
  return !0;
363
363
  }
364
364
  }
365
- function Ee(e) {
365
+ function Te(e) {
366
366
  return "" + e;
367
367
  }
368
- function _e(e) {
368
+ function Pe(e) {
369
369
  if (He(e))
370
- return f("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ze(e)), Ee(e);
370
+ return f("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ze(e)), Te(e);
371
371
  }
372
- var U = p.ReactCurrentOwner, Xe = {
372
+ var U = y.ReactCurrentOwner, Xe = {
373
373
  key: !0,
374
374
  ref: !0,
375
375
  __self: !0,
376
376
  __source: !0
377
- }, Te, Pe, re;
378
- re = {};
377
+ }, Se, xe, ne;
378
+ ne = {};
379
379
  function Ze(e) {
380
380
  if (M.call(e, "ref")) {
381
381
  var r = Object.getOwnPropertyDescriptor(e, "ref").get;
@@ -394,14 +394,14 @@ function _r() {
394
394
  }
395
395
  function er(e, r) {
396
396
  if (typeof e.ref == "string" && U.current && r && U.current.stateNode !== r) {
397
- var t = w(U.current.type);
398
- re[t] || (f('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', w(U.current.type), e.ref), re[t] = !0);
397
+ var t = j(U.current.type);
398
+ ne[t] || (f('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', j(U.current.type), e.ref), ne[t] = !0);
399
399
  }
400
400
  }
401
401
  function rr(e, r) {
402
402
  {
403
403
  var t = function() {
404
- Te || (Te = !0, f("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
404
+ Se || (Se = !0, f("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
405
405
  };
406
406
  t.isReactWarning = !0, Object.defineProperty(e, "key", {
407
407
  get: t,
@@ -412,7 +412,7 @@ function _r() {
412
412
  function tr(e, r) {
413
413
  {
414
414
  var t = function() {
415
- Pe || (Pe = !0, f("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
415
+ xe || (xe = !0, f("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
416
416
  };
417
417
  t.isReactWarning = !0, Object.defineProperty(e, "ref", {
418
418
  get: t,
@@ -420,17 +420,17 @@ function _r() {
420
420
  });
421
421
  }
422
422
  }
423
- var nr = function(e, r, t, n, i, u, o) {
423
+ var nr = function(e, r, t, n, u, c, o) {
424
424
  var a = {
425
425
  // This tag allows us to uniquely identify this as a React Element
426
- $$typeof: _,
426
+ $$typeof: E,
427
427
  // Built-in properties that belong on the element
428
428
  type: e,
429
429
  key: r,
430
430
  ref: t,
431
431
  props: o,
432
432
  // Record the component responsible for creating this element.
433
- _owner: u
433
+ _owner: c
434
434
  };
435
435
  return a._store = {}, Object.defineProperty(a._store, "validated", {
436
436
  configurable: !1,
@@ -446,44 +446,44 @@ function _r() {
446
446
  configurable: !1,
447
447
  enumerable: !1,
448
448
  writable: !1,
449
- value: i
449
+ value: u
450
450
  }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
451
451
  };
452
- function ar(e, r, t, n, i) {
452
+ function ar(e, r, t, n, u) {
453
453
  {
454
- var u, o = {}, a = null, m = null;
455
- t !== void 0 && (_e(t), a = "" + t), Qe(r) && (_e(r.key), a = "" + r.key), Ze(r) && (m = r.ref, er(r, i));
456
- for (u in r)
457
- M.call(r, u) && !Xe.hasOwnProperty(u) && (o[u] = r[u]);
454
+ var c, o = {}, a = null, h = null;
455
+ t !== void 0 && (Pe(t), a = "" + t), Qe(r) && (Pe(r.key), a = "" + r.key), Ze(r) && (h = r.ref, er(r, u));
456
+ for (c in r)
457
+ M.call(r, c) && !Xe.hasOwnProperty(c) && (o[c] = r[c]);
458
458
  if (e && e.defaultProps) {
459
459
  var l = e.defaultProps;
460
- for (u in l)
461
- o[u] === void 0 && (o[u] = l[u]);
460
+ for (c in l)
461
+ o[c] === void 0 && (o[c] = l[c]);
462
462
  }
463
- if (a || m) {
463
+ if (a || h) {
464
464
  var d = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
465
- a && rr(o, d), m && tr(o, d);
465
+ a && rr(o, d), h && tr(o, d);
466
466
  }
467
- return nr(e, a, m, i, n, U.current, o);
467
+ return nr(e, a, h, u, n, U.current, o);
468
468
  }
469
469
  }
470
- var te = p.ReactCurrentOwner, Se = p.ReactDebugCurrentFrame;
471
- function W(e) {
470
+ var ae = y.ReactCurrentOwner, Ce = y.ReactDebugCurrentFrame;
471
+ function $(e) {
472
472
  if (e) {
473
- var r = e._owner, t = G(e.type, e._source, r ? r.type : null);
474
- Se.setExtraStackFrame(t);
473
+ var r = e._owner, t = H(e.type, e._source, r ? r.type : null);
474
+ Ce.setExtraStackFrame(t);
475
475
  } else
476
- Se.setExtraStackFrame(null);
476
+ Ce.setExtraStackFrame(null);
477
477
  }
478
- var ne;
479
- ne = !1;
480
- function ae(e) {
481
- return typeof e == "object" && e !== null && e.$$typeof === _;
478
+ var oe;
479
+ oe = !1;
480
+ function ie(e) {
481
+ return typeof e == "object" && e !== null && e.$$typeof === E;
482
482
  }
483
- function Ce() {
483
+ function we() {
484
484
  {
485
- if (te.current) {
486
- var e = w(te.current.type);
485
+ if (ae.current) {
486
+ var e = j(ae.current.type);
487
487
  if (e)
488
488
  return `
489
489
 
@@ -495,10 +495,10 @@ Check the render method of \`` + e + "`.";
495
495
  function or(e) {
496
496
  return "";
497
497
  }
498
- var xe = {};
498
+ var Oe = {};
499
499
  function ir(e) {
500
500
  {
501
- var r = Ce();
501
+ var r = we();
502
502
  if (!r) {
503
503
  var t = typeof e == "string" ? e : e.displayName || e.name;
504
504
  t && (r = `
@@ -508,35 +508,35 @@ Check the top-level render call using <` + t + ">.");
508
508
  return r;
509
509
  }
510
510
  }
511
- function Oe(e, r) {
511
+ function je(e, r) {
512
512
  {
513
513
  if (!e._store || e._store.validated || e.key != null)
514
514
  return;
515
515
  e._store.validated = !0;
516
516
  var t = ir(r);
517
- if (xe[t])
517
+ if (Oe[t])
518
518
  return;
519
- xe[t] = !0;
519
+ Oe[t] = !0;
520
520
  var n = "";
521
- e && e._owner && e._owner !== te.current && (n = " It was passed a child from " + w(e._owner.type) + "."), W(e), f('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), W(null);
521
+ e && e._owner && e._owner !== ae.current && (n = " It was passed a child from " + j(e._owner.type) + "."), $(e), f('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), $(null);
522
522
  }
523
523
  }
524
- function we(e, r) {
524
+ function ke(e, r) {
525
525
  {
526
526
  if (typeof e != "object")
527
527
  return;
528
- if (ee(e))
528
+ if (te(e))
529
529
  for (var t = 0; t < e.length; t++) {
530
530
  var n = e[t];
531
- ae(n) && Oe(n, r);
531
+ ie(n) && je(n, r);
532
532
  }
533
- else if (ae(e))
533
+ else if (ie(e))
534
534
  e._store && (e._store.validated = !0);
535
535
  else if (e) {
536
- var i = j(e);
537
- if (typeof i == "function" && i !== e.entries)
538
- for (var u = i.call(e), o; !(o = u.next()).done; )
539
- ae(o.value) && Oe(o.value, r);
536
+ var u = k(e);
537
+ if (typeof u == "function" && u !== e.entries)
538
+ for (var c = u.call(e), o; !(o = c.next()).done; )
539
+ ie(o.value) && je(o.value, r);
540
540
  }
541
541
  }
542
542
  }
@@ -550,17 +550,17 @@ Check the top-level render call using <` + t + ">.");
550
550
  t = r.propTypes;
551
551
  else if (typeof r == "object" && (r.$$typeof === s || // Note: Memo only checks outer props here.
552
552
  // Inner props are checked in the reconciler.
553
- r.$$typeof === S))
553
+ r.$$typeof === x))
554
554
  t = r.propTypes;
555
555
  else
556
556
  return;
557
557
  if (t) {
558
- var n = w(r);
558
+ var n = j(r);
559
559
  Ke(t, e.props, "prop", n, e);
560
- } else if (r.PropTypes !== void 0 && !ne) {
561
- ne = !0;
562
- var i = w(r);
563
- f("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown");
560
+ } else if (r.PropTypes !== void 0 && !oe) {
561
+ oe = !0;
562
+ var u = j(r);
563
+ f("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
564
564
  }
565
565
  typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && f("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
566
566
  }
@@ -570,155 +570,173 @@ Check the top-level render call using <` + t + ">.");
570
570
  for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
571
571
  var n = r[t];
572
572
  if (n !== "children" && n !== "key") {
573
- W(e), f("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), W(null);
573
+ $(e), f("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), $(null);
574
574
  break;
575
575
  }
576
576
  }
577
- e.ref !== null && (W(e), f("Invalid attribute `ref` supplied to `React.Fragment`."), W(null));
577
+ e.ref !== null && ($(e), f("Invalid attribute `ref` supplied to `React.Fragment`."), $(null));
578
578
  }
579
579
  }
580
- var je = {};
581
- function ke(e, r, t, n, i, u) {
580
+ var De = {};
581
+ function Ae(e, r, t, n, u, c) {
582
582
  {
583
583
  var o = Ve(e);
584
584
  if (!o) {
585
585
  var a = "";
586
586
  (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
587
- var m = or();
588
- m ? a += m : a += Ce();
587
+ var h = or();
588
+ h ? a += h : a += we();
589
589
  var l;
590
- e === null ? l = "null" : ee(e) ? l = "array" : e !== void 0 && e.$$typeof === _ ? (l = "<" + (w(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : l = typeof e, f("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", l, a);
590
+ e === null ? l = "null" : te(e) ? l = "array" : e !== void 0 && e.$$typeof === E ? (l = "<" + (j(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : l = typeof e, f("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", l, a);
591
591
  }
592
- var d = ar(e, r, t, i, u);
592
+ var d = ar(e, r, t, u, c);
593
593
  if (d == null)
594
594
  return d;
595
595
  if (o) {
596
- var P = r.children;
597
- if (P !== void 0)
596
+ var S = r.children;
597
+ if (S !== void 0)
598
598
  if (n)
599
- if (ee(P)) {
600
- for (var Y = 0; Y < P.length; Y++)
601
- we(P[Y], e);
602
- Object.freeze && Object.freeze(P);
599
+ if (te(S)) {
600
+ for (var W = 0; W < S.length; W++)
601
+ ke(S[W], e);
602
+ Object.freeze && Object.freeze(S);
603
603
  } else
604
604
  f("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
605
605
  else
606
- we(P, e);
606
+ ke(S, e);
607
607
  }
608
608
  if (M.call(r, "key")) {
609
- var A = w(e), g = Object.keys(r).filter(function(pr) {
609
+ var F = j(e), _ = Object.keys(r).filter(function(pr) {
610
610
  return pr !== "key";
611
- }), oe = g.length > 0 ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}";
612
- if (!je[A + oe]) {
613
- var vr = g.length > 0 ? "{" + g.join(": ..., ") + ": ...}" : "{}";
611
+ }), ue = _.length > 0 ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}";
612
+ if (!De[F + ue]) {
613
+ var vr = _.length > 0 ? "{" + _.join(": ..., ") + ": ...}" : "{}";
614
614
  f(`A props object containing a "key" prop is being spread into JSX:
615
615
  let props = %s;
616
616
  <%s {...props} />
617
617
  React keys must be passed directly to JSX without using spread:
618
618
  let props = %s;
619
- <%s key={someKey} {...props} />`, oe, A, vr, A), je[A + oe] = !0;
619
+ <%s key={someKey} {...props} />`, ue, F, vr, F), De[F + ue] = !0;
620
620
  }
621
621
  }
622
- return e === h ? sr(d) : ur(d), d;
622
+ return e === g ? sr(d) : ur(d), d;
623
623
  }
624
624
  }
625
625
  function cr(e, r, t) {
626
- return ke(e, r, t, !0);
626
+ return Ae(e, r, t, !0);
627
627
  }
628
628
  function fr(e, r, t) {
629
- return ke(e, r, t, !1);
629
+ return Ae(e, r, t, !1);
630
630
  }
631
631
  var lr = fr, dr = cr;
632
- B.Fragment = h, B.jsx = lr, B.jsxs = dr;
632
+ B.Fragment = g, B.jsx = lr, B.jsxs = dr;
633
633
  }()), B;
634
634
  }
635
- process.env.NODE_ENV === "production" ? ue.exports = Er() : ue.exports = _r();
636
- var Tr = ue.exports;
637
- function Pr(y) {
638
- Ie(() => {
639
- y();
635
+ process.env.NODE_ENV === "production" ? ce.exports = Er() : ce.exports = _r();
636
+ var Tr = ce.exports;
637
+ function Pr(v) {
638
+ We(() => {
639
+ v();
640
640
  }, []);
641
641
  }
642
- function Sr(y) {
643
- Ie(() => y, []);
642
+ function Sr(v) {
643
+ We(() => v, []);
644
644
  }
645
- function Dr(y) {
645
+ function Ar(v) {
646
646
  if (typeof Proxy > "u") throw new Error("Proxy is not supported in this environment.");
647
- const _ = br(
647
+ const E = br(
648
648
  void 0
649
649
  );
650
- return _.name = y, _;
650
+ return E.name = v, E;
651
+ }
652
+ function xr(v) {
653
+ if (Array.isArray(v)) {
654
+ const [E, ...w] = v;
655
+ return (g, T, m) => {
656
+ if (g !== E) return !1;
657
+ let p = T, i = m;
658
+ for (const s of w)
659
+ p = p == null ? void 0 : p[s], i = i == null ? void 0 : i[s];
660
+ return p !== i;
661
+ };
662
+ }
663
+ return v;
651
664
  }
652
- function Fr(y) {
665
+ function Fr(v) {
653
666
  return hr(
654
667
  ({
655
- children: _,
656
- value: k,
657
- onChangeProp: h,
658
- onChangeReinit: x,
659
- proxyRef: R
668
+ children: E,
669
+ value: w,
670
+ onChangeProp: g,
671
+ onChangeReinit: T,
672
+ proxyRef: m
660
673
  }) => {
661
- const E = H({}), c = H(), s = H({}), T = $e();
662
- yr(R, () => c.current, [c.current]);
663
- const v = ie((b, D, C) => {
664
- const j = Rr();
665
- return E.current[j] = {
666
- id: j,
674
+ const p = Z({}), i = Z(), s = Z({}), P = Ye();
675
+ yr(m, () => i.current, [i.current]);
676
+ const b = se((R, D, C) => {
677
+ const k = Rr();
678
+ return p.current[k] = {
679
+ id: k,
667
680
  deps: C,
668
- propCallback: b,
681
+ propCallback: R,
669
682
  reinitCallback: D
670
- }, j;
671
- }, []), S = ie((b) => {
672
- delete E.current[b];
673
- }, []), O = ie((b) => {
674
- if (b !== c.current) {
675
- const D = c.current;
676
- b !== null ? c.current = new Proxy(b, {
677
- get: function(C, j) {
678
- const p = Reflect.get(C, j, b);
679
- return L(p) ? p.bind(c.current) : p;
683
+ }, k;
684
+ }, []), x = se((R) => {
685
+ delete p.current[R];
686
+ }, []), O = se((R) => {
687
+ if (R !== i.current) {
688
+ const D = i.current;
689
+ R !== null ? i.current = new Proxy(R, {
690
+ get: function(C, k) {
691
+ const y = Reflect.get(C, k, R);
692
+ return Y(y) ? y.bind(i.current) : y;
680
693
  },
681
- set: function(C, j, p) {
682
- const f = j, I = C[f];
683
- return Reflect.set(C, f, p, b), p = C[f], Object.values(E.current).forEach(($) => {
684
- (!$.deps || $.deps.includes(f) && I !== p || $.deps.some((J) => L(J) && J(f, p, I, b))) && $.propCallback(f, p, I);
685
- }), L(h) && h(f, p, I), !0;
694
+ set: function(C, k, y) {
695
+ const f = k, I = C[f];
696
+ return Reflect.set(C, f, y, R), y = C[f], Object.values(p.current).forEach((J) => {
697
+ var q;
698
+ const L = (q = J.deps) == null ? void 0 : q.map(xr);
699
+ (!L || L.includes(f) && I !== y || L.some(
700
+ (K) => Y(K) && K(f, y, I, R)
701
+ )) && J.propCallback(f, y, I);
702
+ }), Y(g) && g(f, y, I), !0;
686
703
  }
687
- }) : c.current = b, Object.values(E.current).forEach((C) => {
688
- C.reinitCallback(c.current, D);
689
- }), L(x) && x(c.current, D), T();
704
+ }) : i.current = R, Object.values(p.current).forEach((C) => {
705
+ C.reinitCallback(i.current, D);
706
+ }), Y(T) && T(i.current, D), P();
690
707
  }
691
- return s.current.obj = c.current, c.current;
692
- }, [h, x]);
693
- return c.current === void 0 && (c.current = O(k)), s.current.obj = c.current, s.current.set = O, s.current.subscribe = v, s.current.unsubscribe = S, /* @__PURE__ */ Tr.jsx(y.Provider, { value: s.current, children: _ });
708
+ return s.current.obj = i.current, i.current;
709
+ }, [g, T]);
710
+ return i.current === void 0 && (i.current = O(w)), s.current.obj = i.current, s.current.set = O, s.current.subscribe = b, s.current.unsubscribe = x, /* @__PURE__ */ Tr.jsx(v.Provider, { value: s.current, children: E });
694
711
  },
695
712
  ["children", "onChangeProp", "onChangeReinit", "proxyRef"],
696
- y.name + ".Provider"
713
+ v.name + ".Provider"
697
714
  );
698
715
  }
699
- function Ar(y, _ = [], k, h, x = !0) {
700
- const R = mr(y), E = $e(), c = H(null);
701
- if (R === void 0)
702
- throw new Error(`No ${y.name} provider found.`);
716
+ function Ir(v, E = [], w, g, T = !0) {
717
+ const m = mr(v), p = Ye(), i = Z(null);
718
+ if (m === void 0)
719
+ throw new Error(`No ${v.name} provider found.`);
703
720
  return Pr(() => {
704
- c.current = R == null ? void 0 : R.subscribe(
705
- (s, T, v) => {
706
- E(), L(k) && k(s, T, v);
721
+ i.current = m == null ? void 0 : m.subscribe(
722
+ (s, P, b) => {
723
+ p(), Y(w) && w(s, P, b);
707
724
  },
708
- (s, T) => {
709
- x && E(), L(h) && h(s, T);
725
+ (s, P) => {
726
+ T && p(), Y(g) && g(s, P);
710
727
  },
711
- _
728
+ E
712
729
  );
713
730
  }), Sr(() => {
714
- R.unsubscribe(c.current);
731
+ m.unsubscribe(i.current);
715
732
  }), new gr(
716
- { value: R.obj, set: R.set },
733
+ { value: m.obj, set: m.set },
717
734
  ["value", "set"]
718
735
  );
719
736
  }
720
737
  export {
721
- Dr as createProxyContext,
738
+ Ar as createProxyContext,
722
739
  Fr as createProxyContextProvider,
723
- Ar as useProxyContext
740
+ xr as evaluateDependency,
741
+ Ir as useProxyContext
724
742
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ptolemy2002/react-proxy-context",
3
3
  "private": false,
4
- "version": "2.1.3",
4
+ "version": "2.3.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",