ddd-react 1.9.0 → 1.10.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 +6 -1
- package/dist/index.mjs +123 -84
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export declare abstract class Component<P = {}, S = {}, C = null> {
|
|
|
4
4
|
vdom: VDOMNode | null;
|
|
5
5
|
private hostEl;
|
|
6
6
|
parent: Component | null;
|
|
7
|
+
private error;
|
|
7
8
|
static defaultProps: any;
|
|
9
|
+
static getDerivedStateFromError?(error: Error): any;
|
|
8
10
|
props: P & WithChildrenProps;
|
|
9
11
|
state: S;
|
|
10
12
|
context: C;
|
|
@@ -27,7 +29,8 @@ export declare abstract class Component<P = {}, S = {}, C = null> {
|
|
|
27
29
|
didUpdate(prevProps: P, prevState: S): void | Promise<void>;
|
|
28
30
|
willUnmount(): void | Promise<void>;
|
|
29
31
|
didUnmount(): void | Promise<void>;
|
|
30
|
-
|
|
32
|
+
didCatch(error: Error, errorInfo: any): void | Promise<void>;
|
|
33
|
+
shouldComponentUpdate(prevProps: P, nextProps: P): boolean;
|
|
31
34
|
abstract render(): VDOMNode;
|
|
32
35
|
get elements(): HTMLElement[];
|
|
33
36
|
get firstElement(): HTMLElement | undefined;
|
|
@@ -40,4 +43,6 @@ export declare abstract class Component<P = {}, S = {}, C = null> {
|
|
|
40
43
|
private updateContext;
|
|
41
44
|
private subscribeToProvider;
|
|
42
45
|
getDefaultProps(): P;
|
|
46
|
+
private handleError;
|
|
47
|
+
private getComponentStack;
|
|
43
48
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as c, e as
|
|
2
|
-
import { d as
|
|
3
|
-
function
|
|
1
|
+
import { D as c, e as b, a as x, A as E, b as U, h as F, c as I } from "./h-BbaMkkC7.mjs";
|
|
2
|
+
import { d as mt, f as Ot } from "./h-BbaMkkC7.mjs";
|
|
3
|
+
function P(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)
|
|
@@ -14,7 +14,7 @@ function g(e, t) {
|
|
|
14
14
|
if (e.length !== t.length)
|
|
15
15
|
return !1;
|
|
16
16
|
for (let n = 0; n < e.length; ++n)
|
|
17
|
-
if (!
|
|
17
|
+
if (!P(e[n], t[n]))
|
|
18
18
|
return !1;
|
|
19
19
|
return !0;
|
|
20
20
|
}
|
|
@@ -32,7 +32,7 @@ function g(e, t) {
|
|
|
32
32
|
return !1;
|
|
33
33
|
for (let n = 0; n < r.length; ++n) {
|
|
34
34
|
const s = r[n];
|
|
35
|
-
if (!(s === "_owner" && e.$$typeof) && !
|
|
35
|
+
if (!(s === "_owner" && e.$$typeof) && !P(e[s], t[s]))
|
|
36
36
|
return !1;
|
|
37
37
|
}
|
|
38
38
|
return !0;
|
|
@@ -62,7 +62,7 @@ function q(e = {}, t) {
|
|
|
62
62
|
t.removeEventListener(r, n);
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function p(e) {
|
|
66
66
|
const { type: t } = e;
|
|
67
67
|
switch (t) {
|
|
68
68
|
case c.TEXT: {
|
|
@@ -96,15 +96,15 @@ function G(e) {
|
|
|
96
96
|
}
|
|
97
97
|
function _(e) {
|
|
98
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(
|
|
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;
|
|
103
|
-
t && t.forEach(
|
|
103
|
+
t && t.forEach(p);
|
|
104
104
|
}
|
|
105
105
|
function X(e) {
|
|
106
106
|
const { children: t } = e;
|
|
107
|
-
t && t.forEach(
|
|
107
|
+
t && t.forEach(p);
|
|
108
108
|
}
|
|
109
109
|
function C(e, t, r) {
|
|
110
110
|
e.style[t] = r.toString();
|
|
@@ -128,18 +128,18 @@ function W(e, t) {
|
|
|
128
128
|
e.className = "", typeof t == "string" ? e.className = t : Array.isArray(t) && e.classList.add(...t);
|
|
129
129
|
}
|
|
130
130
|
function w(e, t, r) {
|
|
131
|
-
r == null ?
|
|
131
|
+
r == null ? D(e, t) : e.setAttribute(t, String(r));
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function D(e, t) {
|
|
134
134
|
e[t] = null, e.removeAttribute(t);
|
|
135
135
|
}
|
|
136
|
-
let
|
|
136
|
+
let m = !1;
|
|
137
137
|
const O = [];
|
|
138
138
|
function d(e) {
|
|
139
139
|
O.push(e), Y();
|
|
140
140
|
}
|
|
141
141
|
function Y() {
|
|
142
|
-
|
|
142
|
+
m || (m = !0, queueMicrotask(H));
|
|
143
143
|
}
|
|
144
144
|
function H() {
|
|
145
145
|
for (; O.length > 0; ) {
|
|
@@ -159,13 +159,13 @@ function H() {
|
|
|
159
159
|
}
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
m = !1;
|
|
163
163
|
}
|
|
164
164
|
function A(e) {
|
|
165
165
|
const { on: t = {}, ...r } = e.props;
|
|
166
166
|
return delete r.key, { props: r, events: t };
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function h(e, t, r = null, n = null) {
|
|
169
169
|
switch (e.type) {
|
|
170
170
|
case c.TEXT: {
|
|
171
171
|
z(e, t, r);
|
|
@@ -195,19 +195,19 @@ function p(e, t, r = null, n = null) {
|
|
|
195
195
|
}
|
|
196
196
|
function z(e, t, r) {
|
|
197
197
|
const { value: n } = e, s = document.createTextNode(n);
|
|
198
|
-
e.el = s,
|
|
198
|
+
e.el = s, L(s, t, r);
|
|
199
199
|
}
|
|
200
200
|
function Q(e, t, r, n) {
|
|
201
201
|
const { children: s } = e;
|
|
202
202
|
e.el = t, s?.forEach((i, o) => {
|
|
203
|
-
|
|
203
|
+
h(i, t, r != null ? r + o : null, n);
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
function Z(e, t, r, n) {
|
|
207
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((
|
|
209
|
-
|
|
210
|
-
}),
|
|
208
|
+
V(f, e, n), e.el = f, i?.forEach((a) => {
|
|
209
|
+
h(a, f, null, n);
|
|
210
|
+
}), L(f, t, r);
|
|
211
211
|
}
|
|
212
212
|
function V(e, t, r) {
|
|
213
213
|
const { props: n, events: s } = A(t);
|
|
@@ -217,7 +217,7 @@ function tt(e, t, r, n) {
|
|
|
217
217
|
const s = e.tag, { props: i } = A(e), o = new s(i, n);
|
|
218
218
|
o.mount(t, r), e.component = o, e.el = o.firstElement || null;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function L(e, t, r) {
|
|
221
221
|
if (r == null) {
|
|
222
222
|
t.append(e);
|
|
223
223
|
return;
|
|
@@ -230,10 +230,10 @@ function j(e, t, r) {
|
|
|
230
230
|
function et(e, t) {
|
|
231
231
|
const { children: r, container: n } = e;
|
|
232
232
|
r?.forEach((s) => {
|
|
233
|
-
|
|
233
|
+
h(s, n, null, t);
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
-
function
|
|
236
|
+
function j(e, t) {
|
|
237
237
|
if (e.type !== t.type)
|
|
238
238
|
return !1;
|
|
239
239
|
if (e.type === c.ELEMENT) {
|
|
@@ -272,10 +272,10 @@ function rt(e) {
|
|
|
272
272
|
function N(e) {
|
|
273
273
|
return rt(e.trim());
|
|
274
274
|
}
|
|
275
|
-
function
|
|
276
|
-
if (!
|
|
275
|
+
function v(e, t, r, n = null) {
|
|
276
|
+
if (!j(e, t)) {
|
|
277
277
|
const s = nt(r, e.el);
|
|
278
|
-
return
|
|
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:
|
|
@@ -285,11 +285,11 @@ function m(e, t, r, n = null) {
|
|
|
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
|
}
|
|
@@ -311,20 +311,20 @@ function ot(e, t, r) {
|
|
|
311
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
|
...y
|
|
318
|
-
} = t.props ?? {}, { listeners:
|
|
319
|
-
it(n, f, y), ct(n, s,
|
|
318
|
+
} = t.props ?? {}, { listeners: g } = e;
|
|
319
|
+
it(n, f, y), ct(n, s, a), ut(
|
|
320
320
|
n,
|
|
321
321
|
i,
|
|
322
322
|
u
|
|
323
323
|
), t.listeners = ft(
|
|
324
324
|
n,
|
|
325
|
-
|
|
325
|
+
g,
|
|
326
326
|
o ?? {},
|
|
327
|
-
|
|
327
|
+
l ?? {},
|
|
328
328
|
r
|
|
329
329
|
);
|
|
330
330
|
}
|
|
@@ -333,17 +333,17 @@ function it(e, t = {}, r = {}) {
|
|
|
333
333
|
n !== s && (n && typeof n == "object" && "current" in n && (n.current = null), s && typeof s == "object" && "current" in s && (s.current = e));
|
|
334
334
|
const i = { ...t }, o = { ...r };
|
|
335
335
|
delete i.ref, delete o.ref;
|
|
336
|
-
const { added: f, removed:
|
|
337
|
-
for (const
|
|
338
|
-
|
|
339
|
-
for (const
|
|
340
|
-
w(e,
|
|
336
|
+
const { added: f, removed: a, updated: u } = T(i, o);
|
|
337
|
+
for (const l of a)
|
|
338
|
+
D(e, l);
|
|
339
|
+
for (const l of f.concat(u))
|
|
340
|
+
w(e, l, o[l]);
|
|
341
341
|
}
|
|
342
342
|
function ct(e, t, r) {
|
|
343
|
-
const n =
|
|
343
|
+
const n = k(t), s = k(r), { added: i, removed: o } = U(n, s);
|
|
344
344
|
o.length > 0 && e.classList.remove(...o), i.length > 0 && e.classList.add(...i);
|
|
345
345
|
}
|
|
346
|
-
function
|
|
346
|
+
function k(e = "") {
|
|
347
347
|
return Array.isArray(e) ? e.filter(N) : String(e).split(/(\s+)/).filter(N);
|
|
348
348
|
}
|
|
349
349
|
function ut(e, t = {}, r = {}) {
|
|
@@ -356,62 +356,63 @@ function ut(e, t = {}, r = {}) {
|
|
|
356
356
|
function ft(e, t = {}, r = {}, n = {}, s = null) {
|
|
357
357
|
const { removed: i, added: o, updated: f } = T(r, n);
|
|
358
358
|
for (const u of i.concat(f)) {
|
|
359
|
-
const
|
|
360
|
-
|
|
359
|
+
const l = t?.[u];
|
|
360
|
+
l && e.removeEventListener(u, l);
|
|
361
361
|
}
|
|
362
|
-
const
|
|
362
|
+
const a = {};
|
|
363
363
|
for (const u of o.concat(f))
|
|
364
|
-
|
|
364
|
+
a[u] = S(
|
|
365
365
|
u,
|
|
366
366
|
n[u],
|
|
367
367
|
e,
|
|
368
368
|
s
|
|
369
369
|
);
|
|
370
|
-
return
|
|
370
|
+
return a;
|
|
371
371
|
}
|
|
372
372
|
function R(e, t, r) {
|
|
373
|
-
const n =
|
|
374
|
-
for (const
|
|
375
|
-
if (
|
|
376
|
-
const { originalIndex: u, index:
|
|
377
|
-
|
|
373
|
+
const n = b(e), s = b(t), i = e.el, o = x(n, s, j), f = r?.offset ?? 0;
|
|
374
|
+
for (const a of o)
|
|
375
|
+
if (a.op === E.NOOP) {
|
|
376
|
+
const { originalIndex: u, index: l } = a;
|
|
377
|
+
v(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 E.MOVE: {
|
|
382
|
-
const { from: u, index:
|
|
383
|
-
y && (i.insertBefore(y,
|
|
382
|
+
const { from: u, index: l } = a, y = n[u].el, g = i.childNodes[l + f];
|
|
383
|
+
y && (i.insertBefore(y, g), v(n[u], s[l], i, r));
|
|
384
384
|
break;
|
|
385
385
|
}
|
|
386
386
|
case E.REMOVE: {
|
|
387
|
-
const { item: u } =
|
|
388
|
-
|
|
387
|
+
const { item: u } = a;
|
|
388
|
+
p(u);
|
|
389
389
|
break;
|
|
390
390
|
}
|
|
391
391
|
case E.ADD: {
|
|
392
|
-
const { index: u, item:
|
|
393
|
-
|
|
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
|
|
398
|
+
function at(e, t) {
|
|
399
399
|
const { component: r } = e, { props: n } = A(t);
|
|
400
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
|
-
|
|
404
|
+
p(e), h(t, document.body, null, r);
|
|
405
405
|
return;
|
|
406
406
|
}
|
|
407
407
|
R(e, t, r);
|
|
408
408
|
}
|
|
409
|
-
const
|
|
410
|
-
class
|
|
409
|
+
const ht = (e) => e.isProvider, dt = (e) => e.isConsumer;
|
|
410
|
+
class M {
|
|
411
411
|
isMounted = !1;
|
|
412
412
|
vdom = null;
|
|
413
413
|
hostEl = null;
|
|
414
414
|
parent = null;
|
|
415
|
+
error = null;
|
|
415
416
|
static defaultProps = {};
|
|
416
417
|
props;
|
|
417
418
|
state = {};
|
|
@@ -453,11 +454,14 @@ class k {
|
|
|
453
454
|
didUnmount() {
|
|
454
455
|
return Promise.resolve();
|
|
455
456
|
}
|
|
457
|
+
didCatch(t, r) {
|
|
458
|
+
return console.error("Uncaught error:", t, r), this.error = t, Promise.resolve();
|
|
459
|
+
}
|
|
456
460
|
shouldComponentUpdate(t, r) {
|
|
457
|
-
return
|
|
461
|
+
return P(t, r);
|
|
458
462
|
}
|
|
459
463
|
get elements() {
|
|
460
|
-
return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ?
|
|
464
|
+
return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? b(this.vdom).flatMap((t) => t.type === c.COMPONENT && t.component ? t.component.elements : t.el ? [t.el] : []) : this.vdom.el ? [this.vdom.el] : [];
|
|
461
465
|
}
|
|
462
466
|
get firstElement() {
|
|
463
467
|
return this.elements[0];
|
|
@@ -467,7 +471,7 @@ class k {
|
|
|
467
471
|
}
|
|
468
472
|
updateProps(t) {
|
|
469
473
|
const n = { ...this.getDefaultProps(), ...this.props, ...t }, s = this.props;
|
|
470
|
-
this.props = n, !this.shouldComponentUpdate(s, n) && (
|
|
474
|
+
this.props = n, !this.shouldComponentUpdate(s, n) && (ht(this) && this.notify(), this.patch(s, this.state));
|
|
471
475
|
}
|
|
472
476
|
setState(t) {
|
|
473
477
|
const r = this.state;
|
|
@@ -479,19 +483,28 @@ class k {
|
|
|
479
483
|
mount(t, r = null) {
|
|
480
484
|
if (this.isMounted)
|
|
481
485
|
throw new Error("Component is already mounted");
|
|
482
|
-
|
|
486
|
+
dt(this) && !this.subscribedProvider && this.subscribeToProvider(), this.updateContext();
|
|
487
|
+
try {
|
|
488
|
+
this.vdom = this.render(), h(this.vdom, t, r, this), this.hostEl = t, this.isMounted = !0;
|
|
489
|
+
} catch (n) {
|
|
490
|
+
this.handleError(n, "mount");
|
|
491
|
+
}
|
|
483
492
|
}
|
|
484
493
|
unmount() {
|
|
485
494
|
this.isMounted && (d(() => this.willUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: t }) => {
|
|
486
495
|
t.subscribedProvider = null;
|
|
487
|
-
}), this.dependencies = [], this.vdom &&
|
|
496
|
+
}), this.dependencies = [], this.vdom && p(this.vdom), d(() => this.didUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1, this.error = null);
|
|
488
497
|
}
|
|
489
498
|
patch(t, r) {
|
|
490
|
-
if (!this.isMounted || !this.hostEl || !this.vdom)
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
499
|
+
if (!(!this.isMounted || !this.hostEl || !this.vdom) && !this.error) {
|
|
500
|
+
d(() => this.willUpdate(this.props, this.state));
|
|
501
|
+
try {
|
|
502
|
+
const n = this.render();
|
|
503
|
+
this.vdom = v(this.vdom, n, this.hostEl, this), d(() => this.didUpdate(t, r));
|
|
504
|
+
} catch (n) {
|
|
505
|
+
this.handleError(n, "patch");
|
|
506
|
+
}
|
|
507
|
+
}
|
|
495
508
|
}
|
|
496
509
|
updateContext() {
|
|
497
510
|
const t = Object.getPrototypeOf(this).constructor.contextType;
|
|
@@ -522,16 +535,42 @@ class k {
|
|
|
522
535
|
getDefaultProps() {
|
|
523
536
|
return this.constructor.defaultProps || {};
|
|
524
537
|
}
|
|
538
|
+
handleError(t, r) {
|
|
539
|
+
const n = this.constructor;
|
|
540
|
+
if (n.getDerivedStateFromError) {
|
|
541
|
+
const s = n.getDerivedStateFromError(t);
|
|
542
|
+
this.state = { ...this.state, ...s };
|
|
543
|
+
}
|
|
544
|
+
d(() => {
|
|
545
|
+
if (this.didCatch(t, {
|
|
546
|
+
phase: r,
|
|
547
|
+
componentStack: this.getComponentStack()
|
|
548
|
+
}), this.hostEl && this.isMounted)
|
|
549
|
+
try {
|
|
550
|
+
const s = this.render();
|
|
551
|
+
s && v(this.vdom, s, this.hostEl, this);
|
|
552
|
+
} catch (s) {
|
|
553
|
+
console.error("Error during error recovery render:", s);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
getComponentStack() {
|
|
558
|
+
const t = [this.constructor.name];
|
|
559
|
+
let r = this.parent;
|
|
560
|
+
for (; r; )
|
|
561
|
+
t.push(r.constructor.name), r = r.parent;
|
|
562
|
+
return t.reverse();
|
|
563
|
+
}
|
|
525
564
|
}
|
|
526
565
|
function yt(e) {
|
|
527
|
-
class t extends
|
|
566
|
+
class t extends M {
|
|
528
567
|
isProvider = !0;
|
|
529
568
|
render() {
|
|
530
569
|
let s = [];
|
|
531
570
|
return Array.isArray(this.props.children) ? s = this.props.children : this.props.children ? s = [this.props.children] : s = [], F(s);
|
|
532
571
|
}
|
|
533
572
|
}
|
|
534
|
-
class r extends
|
|
573
|
+
class r extends M {
|
|
535
574
|
static contextType = {
|
|
536
575
|
Provider: t,
|
|
537
576
|
defaultValue: e
|
|
@@ -560,24 +599,24 @@ function yt(e) {
|
|
|
560
599
|
function Et(e, t) {
|
|
561
600
|
if (!t)
|
|
562
601
|
throw new Error("Container element is not provided for rendering.");
|
|
563
|
-
|
|
602
|
+
h(e, t);
|
|
564
603
|
}
|
|
565
|
-
function
|
|
604
|
+
function vt(e = null) {
|
|
566
605
|
return {
|
|
567
606
|
current: e
|
|
568
607
|
};
|
|
569
608
|
}
|
|
570
|
-
function
|
|
609
|
+
function gt(e, t) {
|
|
571
610
|
const r = Array.isArray(e) ? e : [e];
|
|
572
611
|
return I(r, t);
|
|
573
612
|
}
|
|
574
613
|
export {
|
|
575
|
-
|
|
614
|
+
M as Component,
|
|
576
615
|
yt as createContext,
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
616
|
+
gt as createPortal,
|
|
617
|
+
vt as createRef,
|
|
618
|
+
mt as h,
|
|
580
619
|
F as hFragment,
|
|
581
|
-
|
|
620
|
+
Ot as hString,
|
|
582
621
|
Et as render
|
|
583
622
|
};
|