wrec 0.27.0 → 0.27.1
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.
|
@@ -28,7 +28,7 @@ var r = typeof window < "u" && window.document !== void 0, i = class extends Err
|
|
|
28
28
|
static #e = /* @__PURE__ */ new Map();
|
|
29
29
|
static {
|
|
30
30
|
r && window.addEventListener("beforeunload", () => {
|
|
31
|
-
for (let [e, t] of this.#e.entries()) if (t.#
|
|
31
|
+
for (let [e, t] of this.#e.entries()) if (t.#a) {
|
|
32
32
|
let r = n(t);
|
|
33
33
|
sessionStorage.setItem("wrec-state-" + e, JSON.stringify(r));
|
|
34
34
|
}
|
|
@@ -37,15 +37,16 @@ var r = typeof window < "u" && window.document !== void 0, i = class extends Err
|
|
|
37
37
|
static get(e) {
|
|
38
38
|
return this.#e.get(e);
|
|
39
39
|
}
|
|
40
|
-
#t =
|
|
41
|
-
#n =
|
|
42
|
-
#r;
|
|
40
|
+
#t = [];
|
|
41
|
+
#n = Symbol("objectId");
|
|
42
|
+
#r = [];
|
|
43
43
|
#i;
|
|
44
44
|
#a;
|
|
45
|
+
#o;
|
|
45
46
|
constructor(n, a, o) {
|
|
46
47
|
if (!n) throw new i("name cannot be empty");
|
|
47
48
|
if (e.#e.has(n)) throw new i(`WrecState with name "${n}" already exists`);
|
|
48
|
-
if (this.#
|
|
49
|
+
if (this.#i = n, this.#a = a, this.#o = t({}, this.#s.bind(this)), a && r) {
|
|
49
50
|
let e = sessionStorage.getItem("wrec-state-" + n), t = e ? JSON.parse(e) : void 0;
|
|
50
51
|
t && (o = t);
|
|
51
52
|
}
|
|
@@ -53,36 +54,44 @@ var r = typeof window < "u" && window.document !== void 0, i = class extends Err
|
|
|
53
54
|
e.#e.set(n, this);
|
|
54
55
|
}
|
|
55
56
|
addListener(e, t = {}) {
|
|
56
|
-
let n = this.#
|
|
57
|
+
let n = this.#r.find((t) => t.listenerRef.deref() === e);
|
|
57
58
|
if (n) {
|
|
58
59
|
let { propertyMap: e } = n;
|
|
59
60
|
for (let [n, r] of Object.entries(t)) e[n] = r;
|
|
60
|
-
} else this.#
|
|
61
|
+
} else this.#r.push({
|
|
61
62
|
listenerRef: new WeakRef(e),
|
|
62
63
|
propertyMap: t
|
|
63
64
|
});
|
|
64
65
|
}
|
|
66
|
+
addChangeCallback(e, t = []) {
|
|
67
|
+
if (this.#t.some((t) => t.callback === e)) throw new i("WrecState addChangedCallback was passed a callback that was already added");
|
|
68
|
+
this.#t.push({
|
|
69
|
+
callback: e,
|
|
70
|
+
statePaths: t
|
|
71
|
+
});
|
|
72
|
+
}
|
|
65
73
|
addProperty(e, t) {
|
|
66
74
|
Object.defineProperty(this, e, {
|
|
67
75
|
enumerable: !0,
|
|
68
76
|
get() {
|
|
69
|
-
return this.#
|
|
77
|
+
return this.#o[e];
|
|
70
78
|
},
|
|
71
79
|
set(t) {
|
|
72
|
-
this.#
|
|
80
|
+
this.#o[e] = t;
|
|
73
81
|
}
|
|
74
|
-
}), this.#
|
|
82
|
+
}), this.#o[e] = t;
|
|
75
83
|
}
|
|
76
84
|
get id() {
|
|
77
|
-
return this.#
|
|
85
|
+
return this.#n;
|
|
78
86
|
}
|
|
79
87
|
log() {
|
|
80
|
-
console.log("WrecState:", this.#
|
|
81
|
-
for (let [e, t] of Object.entries(this.#
|
|
88
|
+
console.log("WrecState:", this.#i);
|
|
89
|
+
for (let [e, t] of Object.entries(this.#o)) console.log(` ${e} = ${JSON.stringify(t)}`);
|
|
82
90
|
}
|
|
83
|
-
#
|
|
91
|
+
#s(e, t, n) {
|
|
92
|
+
for (let { callback: r, statePaths: i } of this.#t) (i.length === 0 || i.includes(e)) && r(e, n, t, this);
|
|
84
93
|
let i = /* @__PURE__ */ new Set();
|
|
85
|
-
for (let a of this.#
|
|
94
|
+
for (let a of this.#r) {
|
|
86
95
|
let o = a.listenerRef.deref();
|
|
87
96
|
if (!o) i.add(a);
|
|
88
97
|
else if (r && o instanceof HTMLElement && !o.isConnected) i.add(a);
|
|
@@ -91,10 +100,13 @@ var r = typeof window < "u" && window.document !== void 0, i = class extends Err
|
|
|
91
100
|
(i.length === 0 || i.includes(e)) && o.changed(e, r[e], n, t, this);
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
|
-
this.#
|
|
103
|
+
this.#r = this.#r.filter((e) => !i.has(e));
|
|
104
|
+
}
|
|
105
|
+
removeChangeCallback(e) {
|
|
106
|
+
this.#t = this.#t.filter((t) => t.callback !== e);
|
|
95
107
|
}
|
|
96
108
|
removeListener(e) {
|
|
97
|
-
this.#
|
|
109
|
+
this.#r = this.#r.filter((t) => t.listenerRef.deref() !== e);
|
|
98
110
|
}
|
|
99
111
|
};
|
|
100
112
|
r && process.env.NODE_ENV === "development" && (window.WrecState = a);
|
package/dist/wrec-ssr.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, i as t, n, r, t as i } from "./wrec-
|
|
1
|
+
import { a as e, i as t, n, r, t as i } from "./wrec-TaEXMJIq.js";
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
3
|
var a = Object.defineProperty, o = Object.getOwnPropertyDescriptor, s = Object.getOwnPropertyNames, c = Object.prototype.hasOwnProperty, l = (e, t) => () => (e && (t = e(e = 0)), t), u = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), d = (e, t) => {
|
|
4
4
|
let n = {};
|
package/dist/wrec.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e, i as t, n, r, t as i } from "./wrec-
|
|
1
|
+
import { a as e, i as t, n, r, t as i } from "./wrec-TaEXMJIq.js";
|
|
2
2
|
export { i as Wrec, e as WrecState, n as createElement, r as css, t as html };
|