@zag-js/store 1.47.0 → 1.48.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/dist/clone.d.mts CHANGED
@@ -1,3 +1 @@
1
- declare function clone<T>(x: T): T;
2
-
3
- export { clone };
1
+ export declare function clone<T>(x: T): T;
package/dist/clone.d.ts CHANGED
@@ -1,3 +1 @@
1
- declare function clone<T>(x: T): T;
2
-
3
- export { clone };
1
+ export declare function clone<T>(x: T): T;
package/dist/clone.js CHANGED
@@ -1,77 +1,42 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/clone.ts
21
- var clone_exports = {};
22
- __export(clone_exports, {
23
- clone: () => clone
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
24
4
  });
25
- module.exports = __toCommonJS(clone_exports);
26
- var import_utils = require("./utils.js");
5
+ const require_utils = require("./utils.js");
6
+ // src/clone.ts
27
7
  function set(obj, key, val) {
28
- if (typeof val.value === "object" && !(0, import_utils.canProxy)(val.value)) val.value = clone(val.value);
29
- if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") {
30
- Object.defineProperty(obj, key, val);
31
- } else obj[key] = val.value;
8
+ if (typeof val.value === "object" && !require_utils.canProxy(val.value)) val.value = clone(val.value);
9
+ if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") Object.defineProperty(obj, key, val);
10
+ else obj[key] = val.value;
32
11
  }
33
12
  function clone(x) {
34
- if (typeof x !== "object") return x;
35
- let i = 0, k, list, tmp, str = Object.prototype.toString.call(x);
36
- if (str === "[object Object]") {
37
- tmp = Object.create(Object.getPrototypeOf(x) || null);
38
- } else if (str === "[object Array]") {
39
- tmp = Array(x.length);
40
- } else if (str === "[object Set]") {
41
- tmp = /* @__PURE__ */ new Set();
42
- x.forEach(function(val) {
43
- tmp.add(clone(val));
44
- });
45
- } else if (str === "[object Map]") {
46
- tmp = /* @__PURE__ */ new Map();
47
- x.forEach(function(val, key) {
48
- tmp.set(clone(key), clone(val));
49
- });
50
- } else if (str === "[object Date]") {
51
- tmp = /* @__PURE__ */ new Date(+x);
52
- } else if (str === "[object RegExp]") {
53
- tmp = new RegExp(x.source, x.flags);
54
- } else if (str === "[object DataView]") {
55
- tmp = new x.constructor(clone(x.buffer));
56
- } else if (str === "[object ArrayBuffer]") {
57
- tmp = x.slice(0);
58
- } else if (str === "[object Blob]") {
59
- tmp = x.slice();
60
- } else if (str.slice(-6) === "Array]") {
61
- tmp = new x.constructor(x);
62
- }
63
- if (tmp) {
64
- for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {
65
- set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
66
- }
67
- for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
68
- if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
69
- set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
70
- }
71
- }
72
- return tmp || x;
13
+ if (typeof x !== "object") return x;
14
+ let i = 0, k, list, tmp, str = Object.prototype.toString.call(x);
15
+ if (str === "[object Object]") tmp = Object.create(Object.getPrototypeOf(x) || null);
16
+ else if (str === "[object Array]") tmp = Array(x.length);
17
+ else if (str === "[object Set]") {
18
+ tmp = /* @__PURE__ */ new Set();
19
+ x.forEach(function(val) {
20
+ tmp.add(clone(val));
21
+ });
22
+ } else if (str === "[object Map]") {
23
+ tmp = /* @__PURE__ */ new Map();
24
+ x.forEach(function(val, key) {
25
+ tmp.set(clone(key), clone(val));
26
+ });
27
+ } else if (str === "[object Date]") tmp = /* @__PURE__ */ new Date(+x);
28
+ else if (str === "[object RegExp]") tmp = new RegExp(x.source, x.flags);
29
+ else if (str === "[object DataView]") tmp = new x.constructor(clone(x.buffer));
30
+ else if (str === "[object ArrayBuffer]") tmp = x.slice(0);
31
+ else if (str === "[object Blob]") tmp = x.slice();
32
+ else if (str.slice(-6) === "Array]") tmp = new x.constructor(x);
33
+ if (tmp) {
34
+ for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
35
+ for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
36
+ if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
37
+ set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
38
+ }
39
+ }
40
+ return tmp || x;
73
41
  }
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {
76
- clone
77
- });
42
+ exports.clone = clone;
package/dist/clone.mjs CHANGED
@@ -1,52 +1,38 @@
1
- // src/clone.ts
2
1
  import { canProxy } from "./utils.mjs";
2
+ // src/clone.ts
3
3
  function set(obj, key, val) {
4
- if (typeof val.value === "object" && !canProxy(val.value)) val.value = clone(val.value);
5
- if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") {
6
- Object.defineProperty(obj, key, val);
7
- } else obj[key] = val.value;
4
+ if (typeof val.value === "object" && !canProxy(val.value)) val.value = clone(val.value);
5
+ if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") Object.defineProperty(obj, key, val);
6
+ else obj[key] = val.value;
8
7
  }
9
8
  function clone(x) {
10
- if (typeof x !== "object") return x;
11
- let i = 0, k, list, tmp, str = Object.prototype.toString.call(x);
12
- if (str === "[object Object]") {
13
- tmp = Object.create(Object.getPrototypeOf(x) || null);
14
- } else if (str === "[object Array]") {
15
- tmp = Array(x.length);
16
- } else if (str === "[object Set]") {
17
- tmp = /* @__PURE__ */ new Set();
18
- x.forEach(function(val) {
19
- tmp.add(clone(val));
20
- });
21
- } else if (str === "[object Map]") {
22
- tmp = /* @__PURE__ */ new Map();
23
- x.forEach(function(val, key) {
24
- tmp.set(clone(key), clone(val));
25
- });
26
- } else if (str === "[object Date]") {
27
- tmp = /* @__PURE__ */ new Date(+x);
28
- } else if (str === "[object RegExp]") {
29
- tmp = new RegExp(x.source, x.flags);
30
- } else if (str === "[object DataView]") {
31
- tmp = new x.constructor(clone(x.buffer));
32
- } else if (str === "[object ArrayBuffer]") {
33
- tmp = x.slice(0);
34
- } else if (str === "[object Blob]") {
35
- tmp = x.slice();
36
- } else if (str.slice(-6) === "Array]") {
37
- tmp = new x.constructor(x);
38
- }
39
- if (tmp) {
40
- for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {
41
- set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
42
- }
43
- for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
44
- if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
45
- set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
46
- }
47
- }
48
- return tmp || x;
9
+ if (typeof x !== "object") return x;
10
+ let i = 0, k, list, tmp, str = Object.prototype.toString.call(x);
11
+ if (str === "[object Object]") tmp = Object.create(Object.getPrototypeOf(x) || null);
12
+ else if (str === "[object Array]") tmp = Array(x.length);
13
+ else if (str === "[object Set]") {
14
+ tmp = /* @__PURE__ */ new Set();
15
+ x.forEach(function(val) {
16
+ tmp.add(clone(val));
17
+ });
18
+ } else if (str === "[object Map]") {
19
+ tmp = /* @__PURE__ */ new Map();
20
+ x.forEach(function(val, key) {
21
+ tmp.set(clone(key), clone(val));
22
+ });
23
+ } else if (str === "[object Date]") tmp = /* @__PURE__ */ new Date(+x);
24
+ else if (str === "[object RegExp]") tmp = new RegExp(x.source, x.flags);
25
+ else if (str === "[object DataView]") tmp = new x.constructor(clone(x.buffer));
26
+ else if (str === "[object ArrayBuffer]") tmp = x.slice(0);
27
+ else if (str === "[object Blob]") tmp = x.slice();
28
+ else if (str.slice(-6) === "Array]") tmp = new x.constructor(x);
29
+ if (tmp) {
30
+ for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
31
+ for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
32
+ if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
33
+ set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
34
+ }
35
+ }
36
+ return tmp || x;
49
37
  }
50
- export {
51
- clone
52
- };
38
+ export { clone };
package/dist/global.d.mts CHANGED
@@ -1,4 +1,2 @@
1
- declare function globalRef<T>(key: string, value: () => T): T;
2
- declare const refSet: WeakSet<WeakKey>;
3
-
4
- export { globalRef, refSet };
1
+ export declare function globalRef<T>(key: string, value: () => T): T;
2
+ export declare const refSet: WeakSet<WeakKey>;
package/dist/global.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- declare function globalRef<T>(key: string, value: () => T): T;
2
- declare const refSet: WeakSet<WeakKey>;
3
-
4
- export { globalRef, refSet };
1
+ export declare function globalRef<T>(key: string, value: () => T): T;
2
+ export declare const refSet: WeakSet<WeakKey>;
package/dist/global.js CHANGED
@@ -1,44 +1,20 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/global.ts
21
- var global_exports = {};
22
- __export(global_exports, {
23
- globalRef: () => globalRef,
24
- refSet: () => refSet
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
25
4
  });
26
- module.exports = __toCommonJS(global_exports);
5
+ // src/global.ts
27
6
  function glob() {
28
- if (typeof globalThis !== "undefined") return globalThis;
29
- if (typeof self !== "undefined") return self;
30
- if (typeof window !== "undefined") return window;
31
- if (typeof global !== "undefined") return global;
7
+ if (typeof globalThis !== "undefined") return globalThis;
8
+ if (typeof self !== "undefined") return self;
9
+ if (typeof window !== "undefined") return window;
10
+ if (typeof global !== "undefined") return global;
32
11
  }
33
12
  function globalRef(key, value) {
34
- const g = glob();
35
- if (!g) return value();
36
- g[key] || (g[key] = value());
37
- return g[key];
13
+ const g = glob();
14
+ if (!g) return value();
15
+ g[key] || (g[key] = value());
16
+ return g[key];
38
17
  }
39
- var refSet = globalRef("__zag__refSet", () => /* @__PURE__ */ new WeakSet());
40
- // Annotate the CommonJS export names for ESM import in node:
41
- 0 && (module.exports = {
42
- globalRef,
43
- refSet
44
- });
18
+ const refSet = globalRef("__zag__refSet", () => /* @__PURE__ */ new WeakSet());
19
+ exports.globalRef = globalRef;
20
+ exports.refSet = refSet;
package/dist/global.mjs CHANGED
@@ -1,18 +1,15 @@
1
1
  // src/global.ts
2
2
  function glob() {
3
- if (typeof globalThis !== "undefined") return globalThis;
4
- if (typeof self !== "undefined") return self;
5
- if (typeof window !== "undefined") return window;
6
- if (typeof global !== "undefined") return global;
3
+ if (typeof globalThis !== "undefined") return globalThis;
4
+ if (typeof self !== "undefined") return self;
5
+ if (typeof window !== "undefined") return window;
6
+ if (typeof global !== "undefined") return global;
7
7
  }
8
8
  function globalRef(key, value) {
9
- const g = glob();
10
- if (!g) return value();
11
- g[key] || (g[key] = value());
12
- return g[key];
9
+ const g = glob();
10
+ if (!g) return value();
11
+ g[key] || (g[key] = value());
12
+ return g[key];
13
13
  }
14
- var refSet = globalRef("__zag__refSet", () => /* @__PURE__ */ new WeakSet());
15
- export {
16
- globalRef,
17
- refSet
18
- };
14
+ const refSet = globalRef("__zag__refSet", () => /* @__PURE__ */ new WeakSet());
15
+ export { globalRef, refSet };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- export { clone } from './clone.mjs';
2
- export { globalRef } from './global.mjs';
3
- export { Ref, Snapshot, proxy, ref, snapshot, subscribe } from './proxy.mjs';
4
- export { proxyWithComputed } from './proxy-computed.mjs';
1
+ import { clone } from "./clone.mjs";
2
+ import { globalRef } from "./global.mjs";
3
+ import { Ref, Snapshot, proxy, ref, snapshot, subscribe } from "./proxy.mjs";
4
+ import { proxyWithComputed } from "./proxy-computed.mjs";
5
+ export { type Ref, type Snapshot, clone, globalRef, proxy, proxyWithComputed, ref, snapshot, subscribe };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { clone } from './clone.js';
2
- export { globalRef } from './global.js';
3
- export { Ref, Snapshot, proxy, ref, snapshot, subscribe } from './proxy.js';
4
- export { proxyWithComputed } from './proxy-computed.js';
1
+ import { clone } from "./clone.js";
2
+ import { globalRef } from "./global.js";
3
+ import { Ref, Snapshot, proxy, ref, snapshot, subscribe } from "./proxy.js";
4
+ import { proxyWithComputed } from "./proxy-computed.js";
5
+ export { type Ref, type Snapshot, clone, globalRef, proxy, proxyWithComputed, ref, snapshot, subscribe };
package/dist/index.js CHANGED
@@ -1,45 +1,15 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- clone: () => import_clone.clone,
24
- globalRef: () => import_global.globalRef,
25
- proxy: () => import_proxy.proxy,
26
- proxyWithComputed: () => import_proxy_computed.proxyWithComputed,
27
- ref: () => import_proxy.ref,
28
- snapshot: () => import_proxy.snapshot,
29
- subscribe: () => import_proxy.subscribe
30
- });
31
- module.exports = __toCommonJS(index_exports);
32
- var import_clone = require("./clone.js");
33
- var import_global = require("./global.js");
34
- var import_proxy = require("./proxy.js");
35
- var import_proxy_computed = require("./proxy-computed.js");
36
- // Annotate the CommonJS export names for ESM import in node:
37
- 0 && (module.exports = {
38
- clone,
39
- globalRef,
40
- proxy,
41
- proxyWithComputed,
42
- ref,
43
- snapshot,
44
- subscribe
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
45
4
  });
5
+ const require_clone = require("./clone.js");
6
+ const require_global = require("./global.js");
7
+ const require_proxy = require("./proxy.js");
8
+ const require_proxy_computed = require("./proxy-computed.js");
9
+ exports.clone = require_clone.clone;
10
+ exports.globalRef = require_global.globalRef;
11
+ exports.proxy = require_proxy.proxy;
12
+ exports.proxyWithComputed = require_proxy_computed.proxyWithComputed;
13
+ exports.ref = require_proxy.ref;
14
+ exports.snapshot = require_proxy.snapshot;
15
+ exports.subscribe = require_proxy.subscribe;
package/dist/index.mjs CHANGED
@@ -1,14 +1,5 @@
1
- // src/index.ts
2
1
  import { clone } from "./clone.mjs";
3
2
  import { globalRef } from "./global.mjs";
4
3
  import { proxy, ref, snapshot, subscribe } from "./proxy.mjs";
5
4
  import { proxyWithComputed } from "./proxy-computed.mjs";
6
- export {
7
- clone,
8
- globalRef,
9
- proxy,
10
- proxyWithComputed,
11
- ref,
12
- snapshot,
13
- subscribe
14
- };
5
+ export { clone, globalRef, proxy, proxyWithComputed, ref, snapshot, subscribe };
@@ -1,10 +1,5 @@
1
- import { Snapshot } from './proxy.mjs';
2
-
3
- declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: {
4
- [K in keyof U]: ((snap: Snapshot<T>) => U[K]) | {
5
- get: (snap: Snapshot<T>) => U[K];
6
- set?: ((state: T, newValue: U[K]) => void) | undefined;
7
- };
8
- }): T & U;
9
-
10
- export { proxyWithComputed };
1
+ import { Snapshot } from "./proxy.mjs";
2
+ export declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: { [K in keyof U]: ((snap: Snapshot<T>) => U[K]) | {
3
+ get: (snap: Snapshot<T>) => U[K];
4
+ set?: ((state: T, newValue: U[K]) => void) | undefined;
5
+ }; }): T & U;
@@ -1,10 +1,5 @@
1
- import { Snapshot } from './proxy.js';
2
-
3
- declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: {
4
- [K in keyof U]: ((snap: Snapshot<T>) => U[K]) | {
5
- get: (snap: Snapshot<T>) => U[K];
6
- set?: ((state: T, newValue: U[K]) => void) | undefined;
7
- };
8
- }): T & U;
9
-
10
- export { proxyWithComputed };
1
+ import { Snapshot } from "./proxy.js";
2
+ export declare function proxyWithComputed<T extends object, U extends object>(initialObject: T, computedFns: { [K in keyof U]: ((snap: Snapshot<T>) => U[K]) | {
3
+ get: (snap: Snapshot<T>) => U[K];
4
+ set?: ((state: T, newValue: U[K]) => void) | undefined;
5
+ }; }): T & U;
@@ -1,48 +1,20 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/proxy-computed.ts
21
- var proxy_computed_exports = {};
22
- __export(proxy_computed_exports, {
23
- proxyWithComputed: () => proxyWithComputed
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
24
4
  });
25
- module.exports = __toCommonJS(proxy_computed_exports);
26
- var import_proxy = require("./proxy.js");
5
+ const require_proxy = require("./proxy.js");
6
+ // src/proxy-computed.ts
27
7
  function proxyWithComputed(initialObject, computedFns) {
28
- const keys = Object.keys(computedFns);
29
- keys.forEach((key) => {
30
- if (Object.getOwnPropertyDescriptor(initialObject, key)) {
31
- throw new Error("object property already defined");
32
- }
33
- const computedFn = computedFns[key];
34
- const { get, set } = typeof computedFn === "function" ? { get: computedFn } : computedFn;
35
- const desc = {};
36
- desc.get = () => get((0, import_proxy.snapshot)(proxyObject));
37
- if (set) {
38
- desc.set = (newValue) => set(proxyObject, newValue);
39
- }
40
- Object.defineProperty(initialObject, key, desc);
41
- });
42
- const proxyObject = (0, import_proxy.proxy)(initialObject);
43
- return proxyObject;
8
+ Object.keys(computedFns).forEach((key) => {
9
+ if (Object.getOwnPropertyDescriptor(initialObject, key)) throw new Error("object property already defined");
10
+ const computedFn = computedFns[key];
11
+ const { get, set } = typeof computedFn === "function" ? { get: computedFn } : computedFn;
12
+ const desc = {};
13
+ desc.get = () => get(require_proxy.snapshot(proxyObject));
14
+ if (set) desc.set = (newValue) => set(proxyObject, newValue);
15
+ Object.defineProperty(initialObject, key, desc);
16
+ });
17
+ const proxyObject = require_proxy.proxy(initialObject);
18
+ return proxyObject;
44
19
  }
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- proxyWithComputed
48
- });
20
+ exports.proxyWithComputed = proxyWithComputed;
@@ -1,23 +1,16 @@
1
- // src/proxy-computed.ts
2
1
  import { proxy, snapshot } from "./proxy.mjs";
2
+ // src/proxy-computed.ts
3
3
  function proxyWithComputed(initialObject, computedFns) {
4
- const keys = Object.keys(computedFns);
5
- keys.forEach((key) => {
6
- if (Object.getOwnPropertyDescriptor(initialObject, key)) {
7
- throw new Error("object property already defined");
8
- }
9
- const computedFn = computedFns[key];
10
- const { get, set } = typeof computedFn === "function" ? { get: computedFn } : computedFn;
11
- const desc = {};
12
- desc.get = () => get(snapshot(proxyObject));
13
- if (set) {
14
- desc.set = (newValue) => set(proxyObject, newValue);
15
- }
16
- Object.defineProperty(initialObject, key, desc);
17
- });
18
- const proxyObject = proxy(initialObject);
19
- return proxyObject;
4
+ Object.keys(computedFns).forEach((key) => {
5
+ if (Object.getOwnPropertyDescriptor(initialObject, key)) throw new Error("object property already defined");
6
+ const computedFn = computedFns[key];
7
+ const { get, set } = typeof computedFn === "function" ? { get: computedFn } : computedFn;
8
+ const desc = {};
9
+ desc.get = () => get(snapshot(proxyObject));
10
+ if (set) desc.set = (newValue) => set(proxyObject, newValue);
11
+ Object.defineProperty(initialObject, key, desc);
12
+ });
13
+ const proxyObject = proxy(initialObject);
14
+ return proxyObject;
20
15
  }
21
- export {
22
- proxyWithComputed
23
- };
16
+ export { proxyWithComputed };
package/dist/proxy.d.mts CHANGED
@@ -1,14 +1,13 @@
1
1
  type AsRef = {
2
- $$valtioRef: true;
2
+ $$valtioRef: true;
3
3
  };
4
4
  type Path = (string | symbol)[];
5
5
  type Op = [op: "set", path: Path, value: unknown, prevValue: unknown] | [op: "delete", path: Path, prevValue: unknown];
6
- type Snapshot<T> = T;
7
- declare function proxy<T extends object>(initialObject?: T): T;
8
- declare function getVersion(proxyObject: unknown): number | undefined;
9
- declare function subscribe<T extends object>(proxyObject: T, callback: (ops: Op[]) => void, notifyInSync?: boolean): () => void;
10
- declare function snapshot<T extends object>(proxyObject: T): T;
11
- declare function ref<T extends object>(obj: T): Ref<T>;
12
- type Ref<T> = T & AsRef;
13
-
14
- export { type Ref, type Snapshot, getVersion, proxy, ref, snapshot, subscribe };
6
+ export type Snapshot<T> = T;
7
+ export declare function proxy<T extends object>(initialObject?: T): T;
8
+ export declare function getVersion(proxyObject: unknown): number | undefined;
9
+ export declare function subscribe<T extends object>(proxyObject: T, callback: (ops: Op[]) => void, notifyInSync?: boolean): () => void;
10
+ export declare function snapshot<T extends object>(proxyObject: T): T;
11
+ export declare function ref<T extends object>(obj: T): Ref<T>;
12
+ export type Ref<T> = T & AsRef;
13
+ export {};
package/dist/proxy.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  type AsRef = {
2
- $$valtioRef: true;
2
+ $$valtioRef: true;
3
3
  };
4
4
  type Path = (string | symbol)[];
5
5
  type Op = [op: "set", path: Path, value: unknown, prevValue: unknown] | [op: "delete", path: Path, prevValue: unknown];
6
- type Snapshot<T> = T;
7
- declare function proxy<T extends object>(initialObject?: T): T;
8
- declare function getVersion(proxyObject: unknown): number | undefined;
9
- declare function subscribe<T extends object>(proxyObject: T, callback: (ops: Op[]) => void, notifyInSync?: boolean): () => void;
10
- declare function snapshot<T extends object>(proxyObject: T): T;
11
- declare function ref<T extends object>(obj: T): Ref<T>;
12
- type Ref<T> = T & AsRef;
13
-
14
- export { type Ref, type Snapshot, getVersion, proxy, ref, snapshot, subscribe };
6
+ export type Snapshot<T> = T;
7
+ export declare function proxy<T extends object>(initialObject?: T): T;
8
+ export declare function getVersion(proxyObject: unknown): number | undefined;
9
+ export declare function subscribe<T extends object>(proxyObject: T, callback: (ops: Op[]) => void, notifyInSync?: boolean): () => void;
10
+ export declare function snapshot<T extends object>(proxyObject: T): T;
11
+ export declare function ref<T extends object>(obj: T): Ref<T>;
12
+ export type Ref<T> = T & AsRef;
13
+ export {};