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