ddd-react 1.3.11 → 1.5.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/component.d.ts +1 -1
- package/dist/index.mjs +284 -293
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare abstract class Component<P = {}, S = ComponentState, ContextValue
|
|
|
23
23
|
notify(): void;
|
|
24
24
|
onMount(): void | Promise<void>;
|
|
25
25
|
onUnmount(): void | Promise<void>;
|
|
26
|
-
onUpdate(): void | Promise<void>;
|
|
26
|
+
onUpdate(prevProps: P, prevState: S): void | Promise<void>;
|
|
27
27
|
onWillUnmount(): void | Promise<void>;
|
|
28
28
|
abstract render(): VDOMNode;
|
|
29
29
|
get elements(): HTMLElement[];
|
package/dist/index.mjs
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
import { D as c, e as v, a as
|
|
2
|
-
import { d as
|
|
3
|
-
function
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
6
|
-
if (typeof
|
|
1
|
+
import { D as c, e as v, a as x, A as y, b as F, h as U, c as I } from "./h-BbaMkkC7.mjs";
|
|
2
|
+
import { d as Ot, f as mt } from "./h-BbaMkkC7.mjs";
|
|
3
|
+
function g(e, t) {
|
|
4
|
+
if (e === null || t === null || e === void 0 || t === void 0)
|
|
5
|
+
return e === t;
|
|
6
|
+
if (typeof e != typeof t)
|
|
7
7
|
return !1;
|
|
8
|
-
if (Object.is(
|
|
8
|
+
if (Object.is(e, t))
|
|
9
9
|
return !0;
|
|
10
|
-
if (typeof
|
|
11
|
-
if (
|
|
10
|
+
if (typeof e == "object") {
|
|
11
|
+
if (e.constructor !== t.constructor)
|
|
12
12
|
return !1;
|
|
13
|
-
if (Array.isArray(
|
|
14
|
-
if (
|
|
13
|
+
if (Array.isArray(e)) {
|
|
14
|
+
if (e.length !== t.length)
|
|
15
15
|
return !1;
|
|
16
|
-
for (let r = 0; r <
|
|
17
|
-
if (!
|
|
16
|
+
for (let r = 0; r < e.length; ++r)
|
|
17
|
+
if (!g(e[r], t[r]))
|
|
18
18
|
return !1;
|
|
19
19
|
return !0;
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
25
|
-
if (
|
|
26
|
-
return
|
|
27
|
-
const n = Object.keys(
|
|
28
|
-
if (n.length !== Object.keys(
|
|
21
|
+
if (e.constructor === RegExp)
|
|
22
|
+
return e.source === t.source && e.flags === t.flags;
|
|
23
|
+
if (e.valueOf !== Object.prototype.valueOf)
|
|
24
|
+
return e.valueOf() === t.valueOf();
|
|
25
|
+
if (e.toString !== Object.prototype.toString)
|
|
26
|
+
return e.toString() === t.toString();
|
|
27
|
+
const n = Object.keys(e);
|
|
28
|
+
if (n.length !== Object.keys(t).length)
|
|
29
29
|
return !1;
|
|
30
30
|
for (let r = 0; r < n.length; ++r)
|
|
31
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
31
|
+
if (!Object.prototype.hasOwnProperty.call(t, n[r]))
|
|
32
32
|
return !1;
|
|
33
33
|
for (let r = 0; r < n.length; ++r) {
|
|
34
34
|
const s = n[r];
|
|
35
|
-
if (!(s === "_owner" &&
|
|
35
|
+
if (!(s === "_owner" && e.$$typeof) && !g(e[s], t[s]))
|
|
36
36
|
return !1;
|
|
37
37
|
}
|
|
38
38
|
return !0;
|
|
39
39
|
}
|
|
40
40
|
return !1;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function S(e, t, n, r = null) {
|
|
43
43
|
function s(o) {
|
|
44
44
|
const i = o;
|
|
45
|
-
r ?
|
|
45
|
+
r ? t.call(r, i) : t(i);
|
|
46
46
|
}
|
|
47
|
-
return n.addEventListener(
|
|
47
|
+
return n.addEventListener(e, s), s;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function $(e = {}, t, n = null) {
|
|
50
50
|
const r = {};
|
|
51
|
-
return Object.entries(
|
|
52
|
-
r[s] =
|
|
51
|
+
return Object.entries(e).forEach(([s, o]) => {
|
|
52
|
+
r[s] = S(
|
|
53
53
|
s,
|
|
54
54
|
o,
|
|
55
|
-
|
|
55
|
+
t,
|
|
56
56
|
n
|
|
57
57
|
);
|
|
58
58
|
}), r;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
Object.entries(
|
|
62
|
-
|
|
60
|
+
function q(e = {}, t) {
|
|
61
|
+
Object.entries(e).forEach(([n, r]) => {
|
|
62
|
+
t.removeEventListener(n, r);
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function p(
|
|
66
|
-
const { type:
|
|
67
|
-
switch (
|
|
65
|
+
function p(e) {
|
|
66
|
+
const { type: t } = e;
|
|
67
|
+
switch (t) {
|
|
68
68
|
case c.TEXT: {
|
|
69
|
-
|
|
69
|
+
G(e);
|
|
70
70
|
break;
|
|
71
71
|
}
|
|
72
72
|
case c.ELEMENT: {
|
|
73
|
-
|
|
73
|
+
W(e);
|
|
74
74
|
break;
|
|
75
75
|
}
|
|
76
76
|
case c.FRAGMENT: {
|
|
77
|
-
|
|
77
|
+
B(e);
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
80
|
case c.COMPONENT: {
|
|
81
|
-
|
|
81
|
+
e.component?.unmount();
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
84
84
|
case c.PORTAL: {
|
|
85
|
-
|
|
85
|
+
X(e);
|
|
86
86
|
break;
|
|
87
87
|
}
|
|
88
88
|
default:
|
|
89
|
-
throw new Error(`Can't destroy DOM of type: ${
|
|
89
|
+
throw new Error(`Can't destroy DOM of type: ${t}`);
|
|
90
90
|
}
|
|
91
|
-
delete
|
|
91
|
+
delete e.el;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
const { el:
|
|
95
|
-
|
|
93
|
+
function G(e) {
|
|
94
|
+
const { el: t } = e;
|
|
95
|
+
t && t.remove();
|
|
96
96
|
}
|
|
97
|
-
function
|
|
98
|
-
const { el:
|
|
99
|
-
s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null),
|
|
97
|
+
function W(e) {
|
|
98
|
+
const { el: t, children: n, listeners: r, props: s } = e;
|
|
99
|
+
s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null), t && t.remove(), n && n.forEach(p), r && t && (q(r, t), delete e.listeners);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
const { children:
|
|
103
|
-
|
|
101
|
+
function B(e) {
|
|
102
|
+
const { children: t } = e;
|
|
103
|
+
t && t.forEach(p);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
106
|
-
const { children:
|
|
107
|
-
|
|
105
|
+
function X(e) {
|
|
106
|
+
const { children: t } = e;
|
|
107
|
+
t && t.forEach(p);
|
|
108
108
|
}
|
|
109
|
-
function
|
|
110
|
-
|
|
109
|
+
function C(e, t, n) {
|
|
110
|
+
e.style[t] = n.toString();
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
112
|
+
function _(e, t) {
|
|
113
|
+
e.style[t] = null;
|
|
114
114
|
}
|
|
115
|
-
function
|
|
116
|
-
const { class: n, style: r, ...s } =
|
|
117
|
-
n &&
|
|
118
|
-
|
|
115
|
+
function J(e, t) {
|
|
116
|
+
const { class: n, style: r, ...s } = t;
|
|
117
|
+
n && K(e, n), r && Object.entries(r).forEach(([o, i]) => {
|
|
118
|
+
C(e, o, i);
|
|
119
119
|
});
|
|
120
120
|
for (const [o, i] of Object.entries(s))
|
|
121
|
-
|
|
121
|
+
L(e, o, i);
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
if (
|
|
125
|
-
|
|
123
|
+
function K(e, t) {
|
|
124
|
+
if (e instanceof SVGElement) {
|
|
125
|
+
e.removeAttribute("class"), typeof t == "string" ? e.setAttribute("class", t) : Array.isArray(t) && e.classList.add(...t);
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
e.className = "", typeof t == "string" ? e.className = t : Array.isArray(t) && e.classList.add(...t);
|
|
129
129
|
}
|
|
130
|
-
function
|
|
131
|
-
n == null ?
|
|
130
|
+
function L(e, t, n) {
|
|
131
|
+
n == null ? w(e, t) : e.setAttribute(t, String(n));
|
|
132
132
|
}
|
|
133
|
-
function
|
|
134
|
-
t
|
|
133
|
+
function w(e, t) {
|
|
134
|
+
e[t] = null, e.removeAttribute(t);
|
|
135
135
|
}
|
|
136
136
|
let P = !1;
|
|
137
|
-
const
|
|
138
|
-
function
|
|
139
|
-
|
|
137
|
+
const O = [];
|
|
138
|
+
function E(e) {
|
|
139
|
+
O.push(e), Y();
|
|
140
140
|
}
|
|
141
|
-
function
|
|
142
|
-
P || (P = !0, queueMicrotask(
|
|
141
|
+
function Y() {
|
|
142
|
+
P || (P = !0, queueMicrotask(H));
|
|
143
143
|
}
|
|
144
|
-
function
|
|
145
|
-
for (;
|
|
146
|
-
const
|
|
147
|
-
let
|
|
144
|
+
function H() {
|
|
145
|
+
for (; O.length > 0; ) {
|
|
146
|
+
const e = O.shift();
|
|
147
|
+
let t;
|
|
148
148
|
try {
|
|
149
|
-
|
|
149
|
+
t = e();
|
|
150
150
|
} catch (n) {
|
|
151
151
|
console.error(`[scheduler]: ${n}`);
|
|
152
152
|
continue;
|
|
153
153
|
}
|
|
154
|
-
Promise.resolve(
|
|
154
|
+
Promise.resolve(t).then(
|
|
155
155
|
() => {
|
|
156
156
|
},
|
|
157
157
|
(n) => {
|
|
@@ -161,166 +161,166 @@ function Q() {
|
|
|
161
161
|
}
|
|
162
162
|
P = !1;
|
|
163
163
|
}
|
|
164
|
-
function A(
|
|
165
|
-
const { on:
|
|
166
|
-
return delete n.key, { props: n, events:
|
|
164
|
+
function A(e) {
|
|
165
|
+
const { on: t = {}, ...n } = e.props;
|
|
166
|
+
return delete n.key, { props: n, events: t };
|
|
167
167
|
}
|
|
168
|
-
function h(
|
|
169
|
-
switch (
|
|
168
|
+
function h(e, t, n = null, r = null) {
|
|
169
|
+
switch (e.type) {
|
|
170
170
|
case c.TEXT: {
|
|
171
|
-
|
|
171
|
+
z(e, t, n);
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
174
174
|
case c.ELEMENT: {
|
|
175
|
-
|
|
175
|
+
Z(e, t, n, r);
|
|
176
176
|
break;
|
|
177
177
|
}
|
|
178
178
|
case c.FRAGMENT: {
|
|
179
|
-
|
|
179
|
+
Q(e, t, n, r);
|
|
180
180
|
break;
|
|
181
181
|
}
|
|
182
182
|
case c.COMPONENT: {
|
|
183
|
-
|
|
184
|
-
const s =
|
|
185
|
-
s &&
|
|
183
|
+
tt(e, t, n, r);
|
|
184
|
+
const s = e.component;
|
|
185
|
+
s && E(() => s.onMount());
|
|
186
186
|
break;
|
|
187
187
|
}
|
|
188
188
|
case c.PORTAL: {
|
|
189
|
-
|
|
189
|
+
et(e, r);
|
|
190
190
|
break;
|
|
191
191
|
}
|
|
192
192
|
default:
|
|
193
|
-
throw new Error(`Can't mount DOM of type: ${
|
|
193
|
+
throw new Error(`Can't mount DOM of type: ${e.type}`);
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
function
|
|
197
|
-
const { value: r } =
|
|
198
|
-
|
|
196
|
+
function z(e, t, n) {
|
|
197
|
+
const { value: r } = e, s = document.createTextNode(r);
|
|
198
|
+
e.el = s, j(s, t, n);
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
const { children: s } =
|
|
202
|
-
|
|
203
|
-
h(o,
|
|
200
|
+
function Q(e, t, n, r) {
|
|
201
|
+
const { children: s } = e;
|
|
202
|
+
e.el = t, s?.forEach((o, i) => {
|
|
203
|
+
h(o, t, n != null ? n + i : null, r);
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
-
function
|
|
207
|
-
const { tag: s, children: o } =
|
|
208
|
-
|
|
209
|
-
h(
|
|
210
|
-
}),
|
|
206
|
+
function Z(e, t, n, r) {
|
|
207
|
+
const { tag: s, children: o } = e, f = s === "svg" || t instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
|
|
208
|
+
V(f, e, r), e.el = f, o?.forEach((l) => {
|
|
209
|
+
h(l, f, null, r);
|
|
210
|
+
}), j(f, t, n);
|
|
211
211
|
}
|
|
212
|
-
function
|
|
213
|
-
const { props: r, events: s } = A(
|
|
214
|
-
r.ref && typeof r.ref == "object" && "current" in r.ref && (r.ref.current =
|
|
212
|
+
function V(e, t, n) {
|
|
213
|
+
const { props: r, events: s } = A(t);
|
|
214
|
+
r.ref && typeof r.ref == "object" && "current" in r.ref && (r.ref.current = e, delete r.ref), t.listeners = $(s, e, n), J(e, r);
|
|
215
215
|
}
|
|
216
|
-
function
|
|
217
|
-
const s =
|
|
218
|
-
i.mount(
|
|
216
|
+
function tt(e, t, n, r) {
|
|
217
|
+
const s = e.tag, { props: o } = A(e), i = new s(o, r);
|
|
218
|
+
i.mount(t, n), e.component = i, e.el = i.firstElement || null;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function j(e, t, n) {
|
|
221
221
|
if (n == null) {
|
|
222
|
-
|
|
222
|
+
t.append(e);
|
|
223
223
|
return;
|
|
224
224
|
}
|
|
225
225
|
if (n < 0)
|
|
226
226
|
throw new Error(`Index must be a positive integer, got ${n}`);
|
|
227
|
-
const r =
|
|
228
|
-
n >= r.length ?
|
|
227
|
+
const r = t.childNodes;
|
|
228
|
+
n >= r.length ? t.append(e) : t.insertBefore(e, r[n]);
|
|
229
229
|
}
|
|
230
|
-
function
|
|
231
|
-
const { children: n, container: r } =
|
|
230
|
+
function et(e, t) {
|
|
231
|
+
const { children: n, container: r } = e;
|
|
232
232
|
n?.forEach((s) => {
|
|
233
|
-
h(s, r, null,
|
|
233
|
+
h(s, r, null, t);
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
-
function
|
|
237
|
-
if (
|
|
236
|
+
function D(e, t) {
|
|
237
|
+
if (e.type !== t.type)
|
|
238
238
|
return !1;
|
|
239
|
-
if (
|
|
240
|
-
const n =
|
|
239
|
+
if (e.type === c.ELEMENT) {
|
|
240
|
+
const n = e, r = t, {
|
|
241
241
|
tag: s,
|
|
242
242
|
props: { key: o }
|
|
243
243
|
} = n, {
|
|
244
244
|
tag: i,
|
|
245
|
-
props: { key:
|
|
245
|
+
props: { key: f }
|
|
246
246
|
} = r;
|
|
247
|
-
return s === i && o ===
|
|
247
|
+
return s === i && o === f;
|
|
248
248
|
}
|
|
249
|
-
if (
|
|
250
|
-
const n =
|
|
249
|
+
if (e.type === c.COMPONENT) {
|
|
250
|
+
const n = e, r = t, { tag: s } = n, { tag: o } = r;
|
|
251
251
|
return s === o;
|
|
252
252
|
}
|
|
253
|
-
if (
|
|
254
|
-
const n =
|
|
253
|
+
if (e.type === c.PORTAL) {
|
|
254
|
+
const n = e, r = t;
|
|
255
255
|
return n.container === r.container;
|
|
256
256
|
}
|
|
257
257
|
return !0;
|
|
258
258
|
}
|
|
259
|
-
function T(
|
|
260
|
-
const n = Object.keys(
|
|
259
|
+
function T(e, t) {
|
|
260
|
+
const n = Object.keys(e), r = Object.keys(t), s = [], o = [];
|
|
261
261
|
for (const i of r)
|
|
262
|
-
i in
|
|
262
|
+
i in e ? e[i] !== t[i] && o.push(i) : s.push(i);
|
|
263
263
|
return {
|
|
264
264
|
added: s,
|
|
265
|
-
removed: n.filter((i) => !(i in
|
|
265
|
+
removed: n.filter((i) => !(i in t)),
|
|
266
266
|
updated: o
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
return
|
|
269
|
+
function nt(e) {
|
|
270
|
+
return e !== "";
|
|
271
271
|
}
|
|
272
|
-
function N(
|
|
273
|
-
return
|
|
272
|
+
function N(e) {
|
|
273
|
+
return nt(e.trim());
|
|
274
274
|
}
|
|
275
|
-
function
|
|
276
|
-
if (!
|
|
277
|
-
const s =
|
|
278
|
-
return p(
|
|
275
|
+
function m(e, t, n, r = null) {
|
|
276
|
+
if (!D(e, t)) {
|
|
277
|
+
const s = rt(n, e.el);
|
|
278
|
+
return p(e), h(t, n, s, r), t;
|
|
279
279
|
}
|
|
280
|
-
switch (
|
|
280
|
+
switch (t.el = e.el, t.type) {
|
|
281
281
|
case c.TEXT:
|
|
282
|
-
return
|
|
282
|
+
return st(e, t), t;
|
|
283
283
|
case c.ELEMENT: {
|
|
284
|
-
|
|
284
|
+
ot(e, t, r);
|
|
285
285
|
break;
|
|
286
286
|
}
|
|
287
287
|
case c.COMPONENT: {
|
|
288
|
-
|
|
288
|
+
lt(e, t);
|
|
289
289
|
break;
|
|
290
290
|
}
|
|
291
291
|
case c.PORTAL: {
|
|
292
|
-
|
|
292
|
+
at(e, t, r);
|
|
293
293
|
break;
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
|
-
return
|
|
296
|
+
return R(e, t, r), t;
|
|
297
297
|
}
|
|
298
|
-
function
|
|
299
|
-
if (!
|
|
300
|
-
const n = Array.from(
|
|
298
|
+
function rt(e, t) {
|
|
299
|
+
if (!t) return null;
|
|
300
|
+
const n = Array.from(e.childNodes).indexOf(t);
|
|
301
301
|
return n < 0 ? null : n;
|
|
302
302
|
}
|
|
303
|
-
function
|
|
304
|
-
const n =
|
|
303
|
+
function st(e, t) {
|
|
304
|
+
const n = e.el, { value: r } = e, { value: s } = t;
|
|
305
305
|
r !== s && n && (n.nodeValue = s);
|
|
306
306
|
}
|
|
307
|
-
function
|
|
308
|
-
const r =
|
|
307
|
+
function ot(e, t, n) {
|
|
308
|
+
const r = e.el, {
|
|
309
309
|
class: s,
|
|
310
310
|
style: o,
|
|
311
311
|
on: i,
|
|
312
|
-
...
|
|
313
|
-
} =
|
|
314
|
-
class:
|
|
315
|
-
style:
|
|
312
|
+
...f
|
|
313
|
+
} = e.props ?? {}, {
|
|
314
|
+
class: l,
|
|
315
|
+
style: u,
|
|
316
316
|
on: a,
|
|
317
317
|
...d
|
|
318
|
-
} =
|
|
319
|
-
|
|
318
|
+
} = t.props ?? {}, { listeners: b } = e;
|
|
319
|
+
it(r, f, d), ct(r, s, l), ut(
|
|
320
320
|
r,
|
|
321
321
|
o,
|
|
322
|
-
|
|
323
|
-
),
|
|
322
|
+
u
|
|
323
|
+
), t.listeners = ft(
|
|
324
324
|
r,
|
|
325
325
|
b,
|
|
326
326
|
i ?? {},
|
|
@@ -328,102 +328,99 @@ function ce(t, e, n) {
|
|
|
328
328
|
n
|
|
329
329
|
);
|
|
330
330
|
}
|
|
331
|
-
function
|
|
332
|
-
const r =
|
|
333
|
-
r !== s && (r && typeof r == "object" && "current" in r && (r.current = null), s && typeof s == "object" && "current" in s && (s.current =
|
|
334
|
-
const o = { ...
|
|
331
|
+
function it(e, t = {}, n = {}) {
|
|
332
|
+
const r = t.ref, s = n.ref;
|
|
333
|
+
r !== s && (r && typeof r == "object" && "current" in r && (r.current = null), s && typeof s == "object" && "current" in s && (s.current = e));
|
|
334
|
+
const o = { ...t }, i = { ...n };
|
|
335
335
|
delete o.ref, delete i.ref;
|
|
336
|
-
const { added:
|
|
337
|
-
for (const a of
|
|
338
|
-
|
|
339
|
-
for (const a of
|
|
340
|
-
|
|
336
|
+
const { added: f, removed: l, updated: u } = T(o, i);
|
|
337
|
+
for (const a of l)
|
|
338
|
+
w(e, a);
|
|
339
|
+
for (const a of f.concat(u))
|
|
340
|
+
L(e, a, i[a]);
|
|
341
341
|
}
|
|
342
|
-
function
|
|
343
|
-
const r = M(
|
|
344
|
-
i.length > 0 &&
|
|
342
|
+
function ct(e, t, n) {
|
|
343
|
+
const r = M(t), s = M(n), { added: o, removed: i } = F(r, s);
|
|
344
|
+
i.length > 0 && e.classList.remove(...i), o.length > 0 && e.classList.add(...o);
|
|
345
345
|
}
|
|
346
|
-
function M(
|
|
347
|
-
return Array.isArray(
|
|
346
|
+
function M(e = "") {
|
|
347
|
+
return Array.isArray(e) ? e.filter(N) : String(e).split(/(\s+)/).filter(N);
|
|
348
348
|
}
|
|
349
|
-
function
|
|
350
|
-
const { added: r, removed: s, updated: o } = T(
|
|
349
|
+
function ut(e, t = {}, n = {}) {
|
|
350
|
+
const { added: r, removed: s, updated: o } = T(t, n);
|
|
351
351
|
for (const i of s)
|
|
352
|
-
|
|
352
|
+
_(e, i);
|
|
353
353
|
for (const i of r.concat(o))
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
function
|
|
357
|
-
const { removed: o, added: i, updated:
|
|
358
|
-
for (const
|
|
359
|
-
const a =
|
|
360
|
-
a &&
|
|
361
|
-
}
|
|
362
|
-
const
|
|
363
|
-
for (const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
r[
|
|
367
|
-
|
|
354
|
+
C(e, i, n[i]);
|
|
355
|
+
}
|
|
356
|
+
function ft(e, t = {}, n = {}, r = {}, s = null) {
|
|
357
|
+
const { removed: o, added: i, updated: f } = T(n, r);
|
|
358
|
+
for (const u of o.concat(f)) {
|
|
359
|
+
const a = t?.[u];
|
|
360
|
+
a && e.removeEventListener(u, a);
|
|
361
|
+
}
|
|
362
|
+
const l = {};
|
|
363
|
+
for (const u of i.concat(f))
|
|
364
|
+
l[u] = S(
|
|
365
|
+
u,
|
|
366
|
+
r[u],
|
|
367
|
+
e,
|
|
368
368
|
s
|
|
369
369
|
);
|
|
370
|
-
return
|
|
371
|
-
}
|
|
372
|
-
function
|
|
373
|
-
const r = v(
|
|
374
|
-
for (const
|
|
375
|
-
if (
|
|
376
|
-
const { originalIndex:
|
|
377
|
-
|
|
370
|
+
return l;
|
|
371
|
+
}
|
|
372
|
+
function R(e, t, n) {
|
|
373
|
+
const r = v(e), s = v(t), o = e.el, i = x(r, s, D), f = n?.offset ?? 0;
|
|
374
|
+
for (const l of i)
|
|
375
|
+
if (l.op === y.NOOP) {
|
|
376
|
+
const { originalIndex: u, index: a } = l;
|
|
377
|
+
m(r[u], s[a], o, n);
|
|
378
378
|
}
|
|
379
|
-
for (const
|
|
380
|
-
switch (
|
|
381
|
-
case
|
|
382
|
-
const { from:
|
|
383
|
-
d && (o.insertBefore(d, b),
|
|
379
|
+
for (const l of i)
|
|
380
|
+
switch (l.op) {
|
|
381
|
+
case y.MOVE: {
|
|
382
|
+
const { from: u, index: a } = l, d = r[u].el, b = o.childNodes[a + f];
|
|
383
|
+
d && (o.insertBefore(d, b), m(r[u], s[a], o, n));
|
|
384
384
|
break;
|
|
385
385
|
}
|
|
386
|
-
case
|
|
387
|
-
const { item:
|
|
388
|
-
p(
|
|
386
|
+
case y.REMOVE: {
|
|
387
|
+
const { item: u } = l;
|
|
388
|
+
p(u);
|
|
389
389
|
break;
|
|
390
390
|
}
|
|
391
|
-
case
|
|
392
|
-
const { index:
|
|
393
|
-
h(a, o,
|
|
391
|
+
case y.ADD: {
|
|
392
|
+
const { index: u, item: a } = l;
|
|
393
|
+
h(a, o, u + f, n);
|
|
394
394
|
break;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
-
function
|
|
399
|
-
const { component: n } =
|
|
400
|
-
n.updateProps(r),
|
|
398
|
+
function lt(e, t) {
|
|
399
|
+
const { component: n } = e, { props: r } = A(t);
|
|
400
|
+
n.updateProps(r), t.component = n, t.el = n.firstElement;
|
|
401
401
|
}
|
|
402
|
-
function
|
|
403
|
-
if (
|
|
404
|
-
p(
|
|
402
|
+
function at(e, t, n) {
|
|
403
|
+
if (e.container !== t.container) {
|
|
404
|
+
p(e), h(t, document.body, null, n);
|
|
405
405
|
return;
|
|
406
406
|
}
|
|
407
|
-
|
|
407
|
+
R(e, t, n);
|
|
408
408
|
}
|
|
409
|
-
const
|
|
410
|
-
class
|
|
411
|
-
constructor(
|
|
412
|
-
this.isMounted = !1, this.vdom = null, this.hostEl = null, this.parent = null, this.state = {}, this.context = null, this.dependencies = [], this.subscribedProvider = null, this.isProvider = !1, this.isConsumer = !1, this.props =
|
|
409
|
+
const ht = (e) => e.isProvider, pt = (e) => e.isConsumer;
|
|
410
|
+
class k {
|
|
411
|
+
constructor(t = {}, n) {
|
|
412
|
+
this.isMounted = !1, this.vdom = null, this.hostEl = null, this.parent = null, this.state = {}, this.context = null, this.dependencies = [], this.subscribedProvider = null, this.isProvider = !1, this.isConsumer = !1, this.props = t, this.parent = n;
|
|
413
413
|
}
|
|
414
|
-
addDependency({ consumer:
|
|
415
|
-
this.dependencies.some((n) => n.consumer ===
|
|
414
|
+
addDependency({ consumer: t }) {
|
|
415
|
+
this.dependencies.some((n) => n.consumer === t) || (this.dependencies.push({ consumer: t }), t.subscribedProvider = this);
|
|
416
416
|
}
|
|
417
|
-
removeDependency({ consumer:
|
|
418
|
-
const n = this.dependencies.findIndex((r) => r.consumer ===
|
|
419
|
-
n !== -1 && (this.dependencies.splice(n, 1),
|
|
417
|
+
removeDependency({ consumer: t }) {
|
|
418
|
+
const n = this.dependencies.findIndex((r) => r.consumer === t);
|
|
419
|
+
n !== -1 && (this.dependencies.splice(n, 1), t.subscribedProvider = null);
|
|
420
420
|
}
|
|
421
421
|
notify() {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const n = e.updateContext();
|
|
425
|
-
console.log("changed", n), n && (console.log("consumer.patch"), e.patch());
|
|
426
|
-
}
|
|
422
|
+
this.dependencies.forEach(({ consumer: t }) => {
|
|
423
|
+
t.isMounted && t.updateContext() && t.patch(t.props, t.state);
|
|
427
424
|
});
|
|
428
425
|
}
|
|
429
426
|
onMount() {
|
|
@@ -432,14 +429,14 @@ class S {
|
|
|
432
429
|
onUnmount() {
|
|
433
430
|
return Promise.resolve();
|
|
434
431
|
}
|
|
435
|
-
onUpdate() {
|
|
432
|
+
onUpdate(t, n) {
|
|
436
433
|
return Promise.resolve();
|
|
437
434
|
}
|
|
438
435
|
onWillUnmount() {
|
|
439
436
|
return Promise.resolve();
|
|
440
437
|
}
|
|
441
438
|
get elements() {
|
|
442
|
-
return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? v(this.vdom).flatMap((
|
|
439
|
+
return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? v(this.vdom).flatMap((t) => t.type === c.COMPONENT && t.component ? t.component.elements : t.el ? [t.el] : []) : this.vdom.el ? [this.vdom.el] : [];
|
|
443
440
|
}
|
|
444
441
|
get firstElement() {
|
|
445
442
|
return this.elements[0];
|
|
@@ -447,61 +444,55 @@ class S {
|
|
|
447
444
|
get offset() {
|
|
448
445
|
return this.vdom?.type === c.FRAGMENT && this.hostEl && this.firstElement ? Array.from(this.hostEl.children).indexOf(this.firstElement) : 0;
|
|
449
446
|
}
|
|
450
|
-
updateProps(
|
|
451
|
-
|
|
452
|
-
const n = { ...this.props, ...e }, r = this.props;
|
|
447
|
+
updateProps(t) {
|
|
448
|
+
const n = { ...this.props, ...t }, r = this.props;
|
|
453
449
|
this.props = n;
|
|
454
450
|
let s = this.updateContext();
|
|
455
|
-
|
|
456
|
-
console.log("return");
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
console.log("isProvider(this as Component)", k(this)), k(this) && this.notify(), this.patch();
|
|
451
|
+
g(r, n) && !s || (ht(this) && this.notify(), this.patch(r, this.state));
|
|
460
452
|
}
|
|
461
|
-
setState(
|
|
462
|
-
|
|
453
|
+
setState(t) {
|
|
454
|
+
let n = this.state;
|
|
455
|
+
typeof t == "function" ? this.state = {
|
|
463
456
|
...this.state,
|
|
464
|
-
...
|
|
465
|
-
} : this.state = { ...this.state, ...
|
|
457
|
+
...t(this.state, this.props)
|
|
458
|
+
} : this.state = { ...this.state, ...t }, this.patch(this.props, n);
|
|
466
459
|
}
|
|
467
|
-
mount(
|
|
460
|
+
mount(t, n = null) {
|
|
468
461
|
if (this.isMounted)
|
|
469
462
|
throw new Error("Component is already mounted");
|
|
470
|
-
|
|
463
|
+
pt(this) && !this.subscribedProvider && this.subscribeToProvider(), this.updateContext(), this.vdom = this.render(), h(this.vdom, t, n, this), this.hostEl = t, this.isMounted = !0;
|
|
471
464
|
}
|
|
472
465
|
unmount() {
|
|
473
|
-
this.isMounted && (
|
|
474
|
-
|
|
475
|
-
}), this.dependencies = [], this.vdom && p(this.vdom),
|
|
466
|
+
this.isMounted && (E(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: t }) => {
|
|
467
|
+
t.subscribedProvider = null;
|
|
468
|
+
}), this.dependencies = [], this.vdom && p(this.vdom), E(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
|
|
476
469
|
}
|
|
477
|
-
patch() {
|
|
470
|
+
patch(t, n) {
|
|
478
471
|
if (!this.isMounted || !this.hostEl || !this.vdom)
|
|
479
472
|
return;
|
|
480
|
-
const
|
|
481
|
-
this.vdom =
|
|
473
|
+
const r = this.render();
|
|
474
|
+
this.vdom = m(this.vdom, r, this.hostEl, this), E(() => this.onUpdate(t, n));
|
|
482
475
|
}
|
|
483
476
|
updateContext() {
|
|
484
|
-
|
|
485
|
-
const e = Object.getPrototypeOf(this).constructor.contextType;
|
|
486
|
-
console.log("context", e);
|
|
477
|
+
const t = Object.getPrototypeOf(this).constructor.contextType;
|
|
487
478
|
let n = this.parent;
|
|
488
|
-
if (
|
|
489
|
-
for (
|
|
490
|
-
if (
|
|
491
|
-
return this.context = n.props.value,
|
|
479
|
+
if (t != null) {
|
|
480
|
+
for (; n; ) {
|
|
481
|
+
if (Object.getPrototypeOf(n).constructor === t.Provider)
|
|
482
|
+
return this.context = n.props.value, !0;
|
|
492
483
|
n = n.parent;
|
|
493
484
|
}
|
|
494
|
-
n == null && (
|
|
485
|
+
n == null && (this.context = t.defaultValue);
|
|
495
486
|
}
|
|
496
|
-
return
|
|
487
|
+
return !1;
|
|
497
488
|
}
|
|
498
489
|
subscribeToProvider() {
|
|
499
|
-
const
|
|
500
|
-
if (!
|
|
490
|
+
const t = Object.getPrototypeOf(this).constructor.contextType;
|
|
491
|
+
if (!t)
|
|
501
492
|
return;
|
|
502
493
|
let n = this.parent;
|
|
503
494
|
for (; n; ) {
|
|
504
|
-
if (Object.getPrototypeOf(n).constructor ===
|
|
495
|
+
if (Object.getPrototypeOf(n).constructor === t.Provider) {
|
|
505
496
|
n.addDependency({ consumer: this });
|
|
506
497
|
break;
|
|
507
498
|
}
|
|
@@ -509,17 +500,17 @@ class S {
|
|
|
509
500
|
}
|
|
510
501
|
}
|
|
511
502
|
}
|
|
512
|
-
function
|
|
513
|
-
class
|
|
503
|
+
function yt(e) {
|
|
504
|
+
class t extends k {
|
|
514
505
|
constructor() {
|
|
515
506
|
super(...arguments), this.isProvider = !0;
|
|
516
507
|
}
|
|
517
508
|
render() {
|
|
518
509
|
let o = [];
|
|
519
|
-
return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [],
|
|
510
|
+
return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], U(o);
|
|
520
511
|
}
|
|
521
512
|
}
|
|
522
|
-
const r = class r extends
|
|
513
|
+
const r = class r extends k {
|
|
523
514
|
constructor() {
|
|
524
515
|
super(...arguments), this.isConsumer = !0;
|
|
525
516
|
}
|
|
@@ -538,37 +529,37 @@ function ge(t) {
|
|
|
538
529
|
}
|
|
539
530
|
};
|
|
540
531
|
r.contextType = {
|
|
541
|
-
Provider:
|
|
542
|
-
defaultValue:
|
|
532
|
+
Provider: t,
|
|
533
|
+
defaultValue: e
|
|
543
534
|
};
|
|
544
535
|
let n = r;
|
|
545
536
|
return {
|
|
546
|
-
Provider:
|
|
537
|
+
Provider: t,
|
|
547
538
|
Consumer: n,
|
|
548
|
-
defaultValue:
|
|
539
|
+
defaultValue: e
|
|
549
540
|
};
|
|
550
541
|
}
|
|
551
|
-
function
|
|
552
|
-
if (!
|
|
542
|
+
function Et(e, t) {
|
|
543
|
+
if (!t)
|
|
553
544
|
throw new Error("Container element is not provided for rendering.");
|
|
554
|
-
h(
|
|
545
|
+
h(e, t);
|
|
555
546
|
}
|
|
556
|
-
function
|
|
547
|
+
function bt(e = null) {
|
|
557
548
|
return {
|
|
558
|
-
current:
|
|
549
|
+
current: e
|
|
559
550
|
};
|
|
560
551
|
}
|
|
561
|
-
function
|
|
562
|
-
const n = Array.isArray(
|
|
563
|
-
return
|
|
552
|
+
function vt(e, t) {
|
|
553
|
+
const n = Array.isArray(e) ? e : [e];
|
|
554
|
+
return I(n, t);
|
|
564
555
|
}
|
|
565
556
|
export {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
557
|
+
k as Component,
|
|
558
|
+
yt as createContext,
|
|
559
|
+
vt as createPortal,
|
|
560
|
+
bt as createRef,
|
|
561
|
+
Ot as h,
|
|
562
|
+
U as hFragment,
|
|
563
|
+
mt as hString,
|
|
564
|
+
Et as render
|
|
574
565
|
};
|