@ptolemy2002/react-proxy-context 1.0.11 → 1.0.13

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.
Files changed (2) hide show
  1. package/index.js +222 -1
  2. package/package.json +4 -1
package/index.js CHANGED
@@ -207,6 +207,7 @@ var require_react_mount_effects = __commonJS({
207
207
  var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
208
208
  var src_exports2 = {};
209
209
  __export2(src_exports2, {
210
+ useDelayedEffect: () => useDelayedEffect,
210
211
  useMountEffect: () => useMountEffect2,
211
212
  useUnmountEffect: () => useUnmountEffect2
212
213
  });
@@ -220,6 +221,13 @@ var require_react_mount_effects = __commonJS({
220
221
  function useUnmountEffect2(callback) {
221
222
  (0, import_react2.useEffect)(() => callback, []);
222
223
  }
224
+ function useDelayedEffect(callback, deps = [], delay = 0) {
225
+ const changeCount = (0, import_react2.useRef)(0);
226
+ (0, import_react2.useEffect)(() => {
227
+ changeCount.current++;
228
+ if (changeCount.current > delay + 1) callback(changeCount, () => changeCount.current = 0);
229
+ }, deps);
230
+ }
223
231
  }
224
232
  });
225
233
 
@@ -320,6 +328,218 @@ var require_js_utils = __commonJS({
320
328
  }
321
329
  });
322
330
 
331
+ // node_modules/@ptolemy2002/react-hook-result/index.js
332
+ var require_react_hook_result = __commonJS({
333
+ "node_modules/@ptolemy2002/react-hook-result/index.js"(exports, module2) {
334
+ var __create2 = Object.create;
335
+ var __defProp2 = Object.defineProperty;
336
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
337
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
338
+ var __getProtoOf2 = Object.getPrototypeOf;
339
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
340
+ var __commonJS2 = (cb, mod) => function __require() {
341
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
342
+ };
343
+ var __export2 = (target, all) => {
344
+ for (var name in all)
345
+ __defProp2(target, name, { get: all[name], enumerable: true });
346
+ };
347
+ var __copyProps2 = (to, from, except, desc) => {
348
+ if (from && typeof from === "object" || typeof from === "function") {
349
+ for (let key of __getOwnPropNames2(from))
350
+ if (!__hasOwnProp2.call(to, key) && key !== except)
351
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
352
+ }
353
+ return to;
354
+ };
355
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
356
+ // If the importer is in node compatibility mode or this is not an ESM
357
+ // file that has been converted to a CommonJS file using a Babel-
358
+ // compatible transform (i.e. "__esModule" has not been set), then set
359
+ // "default" to the CommonJS "module.exports" for node compatibility.
360
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
361
+ mod
362
+ ));
363
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
364
+ var require_js_utils2 = __commonJS2({
365
+ "node_modules/@ptolemy2002/js-utils/index.js"(exports2, module22) {
366
+ var __defProp22 = Object.defineProperty;
367
+ var __getOwnPropDesc22 = Object.getOwnPropertyDescriptor;
368
+ var __getOwnPropNames22 = Object.getOwnPropertyNames;
369
+ var __hasOwnProp22 = Object.prototype.hasOwnProperty;
370
+ var __export22 = (target, all) => {
371
+ for (var name in all)
372
+ __defProp22(target, name, { get: all[name], enumerable: true });
373
+ };
374
+ var __copyProps22 = (to, from, except, desc) => {
375
+ if (from && typeof from === "object" || typeof from === "function") {
376
+ for (let key of __getOwnPropNames22(from))
377
+ if (!__hasOwnProp22.call(to, key) && key !== except)
378
+ __defProp22(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc22(from, key)) || desc.enumerable });
379
+ }
380
+ return to;
381
+ };
382
+ var __toCommonJS22 = (mod) => __copyProps22(__defProp22({}, "__esModule", { value: true }), mod);
383
+ var src_exports22 = {};
384
+ __export22(src_exports22, {
385
+ Callable: () => Callable,
386
+ ext_getAllProperties: () => ext_getAllProperties,
387
+ ext_hasNestedProperty: () => ext_hasNestedProperty,
388
+ ext_hasOwnNestedProperty: () => ext_hasOwnNestedProperty,
389
+ ext_hasProperty: () => ext_hasProperty2,
390
+ getAllProperties: () => getAllProperties,
391
+ hasNestedProperty: () => hasNestedProperty,
392
+ hasProperty: () => hasProperty,
393
+ isNullOrUndefined: () => isNullOrUndefined2,
394
+ listInPlainEnglish: () => listInPlainEnglish,
395
+ loadExtension: () => loadExtension2,
396
+ unloadExtension: () => unloadExtension
397
+ });
398
+ module22.exports = __toCommonJS22(src_exports22);
399
+ function hasNestedProperty(self, prop = "", hasPropCallback = (o, p) => o.hasOwnProperty(p)) {
400
+ if (typeof prop === "string") prop = prop.split(".");
401
+ if (!Array.isArray(prop)) return hasPropCallback(self, prop);
402
+ let obj = self;
403
+ for (let i = 0; i < prop.length; i++) {
404
+ const p = prop[i];
405
+ if (!obj) return false;
406
+ if (!hasPropCallback(obj, p)) return false;
407
+ obj = obj[p];
408
+ }
409
+ return true;
410
+ }
411
+ function ext_hasOwnNestedProperty(prop = "") {
412
+ return hasNestedProperty(this, prop);
413
+ }
414
+ function getAllProperties(self) {
415
+ let allProps = [], curr = self;
416
+ do {
417
+ let props = Object.getOwnPropertyNames(curr);
418
+ props.forEach(function(prop) {
419
+ if (allProps.indexOf(prop) === -1) {
420
+ allProps.push(prop);
421
+ }
422
+ });
423
+ } while (curr = Object.getPrototypeOf(curr));
424
+ return allProps;
425
+ }
426
+ function ext_getAllProperties() {
427
+ return getAllProperties(this);
428
+ }
429
+ function hasProperty(self, prop) {
430
+ let curr = self;
431
+ do {
432
+ if (curr.hasOwnProperty(prop)) return true;
433
+ } while (curr = Object.getPrototypeOf(curr));
434
+ return false;
435
+ }
436
+ function ext_hasProperty2(prop) {
437
+ return hasProperty(this, prop);
438
+ }
439
+ function ext_hasNestedProperty(prop) {
440
+ return hasNestedProperty(this, prop, (o, p) => hasProperty(o, p));
441
+ }
442
+ function loadExtension2(name, func, base = Object) {
443
+ if (hasProperty(base.prototype, name)) return;
444
+ Object.defineProperty(base.prototype, name, {
445
+ value: func,
446
+ enumerable: false,
447
+ writable: true,
448
+ configurable: true
449
+ });
450
+ }
451
+ function unloadExtension(name, base = Object) {
452
+ delete base.prototype[name];
453
+ }
454
+ function listInPlainEnglish(list, { max = void 0, conjunction = "and" } = {}) {
455
+ if (max === void 0) max = list.length;
456
+ if (list.length === 0) {
457
+ return "";
458
+ }
459
+ if (list.length === 1) {
460
+ return list[0];
461
+ }
462
+ if (list.length === 2) {
463
+ return `${list[0]} ${conjunction} ${list[1]}`;
464
+ }
465
+ list = list.map((v, i) => {
466
+ if (i === list.length - 1) return v;
467
+ if (v.endsWith(`"`)) {
468
+ return v.slice(0, -1) + `," `;
469
+ } else if (v.endsWith(`'`)) {
470
+ return v.slice(0, -1) + `,' `;
471
+ } else {
472
+ return v + ", ";
473
+ }
474
+ });
475
+ if (list.length > max) {
476
+ return `${list.slice(0, max).join("")}${conjunction} ${list.length - max} more`;
477
+ } else {
478
+ return `${list.slice(0, -1).join("")}${conjunction} ${list[list.length - 1]}`;
479
+ }
480
+ }
481
+ function isNullOrUndefined2(v) {
482
+ return v === null || v === void 0;
483
+ }
484
+ var Callable = class extends Function {
485
+ constructor() {
486
+ super("...args", "return this.__self__.__call__(...args)");
487
+ let self = this.bind(this);
488
+ this.__self__ = self;
489
+ return self;
490
+ }
491
+ // This should be overridden by the subclass
492
+ __call__() {
493
+ }
494
+ };
495
+ }
496
+ });
497
+ var src_exports2 = {};
498
+ __export2(src_exports2, {
499
+ default: () => HookResult2
500
+ });
501
+ module2.exports = __toCommonJS2(src_exports2);
502
+ var import_js_utils2 = __toESM2(require_js_utils2());
503
+ (0, import_js_utils2.loadExtension)("hasProperty", import_js_utils2.ext_hasProperty, Object);
504
+ var HookResult2 = class {
505
+ _data = /* @__PURE__ */ new Map();
506
+ constructor(data = {}, order = []) {
507
+ if (typeof Proxy == "undefined") throw new Error("Proxy is not supported in this environment.");
508
+ order.forEach((key) => {
509
+ this._data.set(key, data[key]);
510
+ });
511
+ Object.keys(data).forEach((key) => {
512
+ if (!order.includes(key)) {
513
+ this._data.set(key, data[key]);
514
+ }
515
+ });
516
+ return new Proxy(this, {
517
+ // If the property is not found on the object, get it from the data map
518
+ get: function(target, prop) {
519
+ if (target.hasProperty(prop)) {
520
+ return target[prop];
521
+ } else {
522
+ return target._data.get(prop);
523
+ }
524
+ },
525
+ // If the property is not found on the object, set it in the data map
526
+ set: function(target, prop, value) {
527
+ if (target.hasProperty(prop)) {
528
+ target[prop] = value;
529
+ } else {
530
+ target._data.set(prop, value);
531
+ }
532
+ }
533
+ });
534
+ }
535
+ // This is a generator function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
536
+ *[Symbol.iterator]() {
537
+ yield* this._data.values();
538
+ }
539
+ };
540
+ }
541
+ });
542
+
323
543
  // src/index.js
324
544
  var src_exports = {};
325
545
  __export(src_exports, {
@@ -348,6 +568,7 @@ var import_is_callable = __toESM(require_is_callable());
348
568
  var import_react_force_rerender = __toESM(require_react_force_rerender());
349
569
  var import_react_mount_effects = __toESM(require_react_mount_effects());
350
570
  var import_js_utils = __toESM(require_js_utils());
571
+ var import_react_hook_result = __toESM(require_react_hook_result());
351
572
  function createProxyContext(defaultValue, name) {
352
573
  if (typeof Proxy == "undefined") throw new Error("Proxy is not supported in this environment.");
353
574
  const context = (0, import_react.createContext)(defaultValue);
@@ -436,5 +657,5 @@ function useProxyContext(contextClass, deps, onChange, listenReinit = true) {
436
657
  (0, import_react_mount_effects.useUnmountEffect)(() => {
437
658
  context?.unsubscribe(id.current);
438
659
  });
439
- return [context?.obj, context?.set];
660
+ return new import_react_hook_result.default({ value: context?.obj, set: context?.set }, ["value", "set"]);
440
661
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/react-proxy-context",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js"
@@ -40,5 +40,8 @@
40
40
  "esbuild": "^0.23.0",
41
41
  "is-callable": "^1.2.7",
42
42
  "nanoid": "^5.0.7"
43
+ },
44
+ "dependencies": {
45
+ "@ptolemy2002/react-hook-result": "^1.0.2"
43
46
  }
44
47
  }