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