ddd-react 1.10.0 → 1.10.2

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.
@@ -45,4 +45,6 @@ export declare abstract class Component<P = {}, S = {}, C = null> {
45
45
  getDefaultProps(): P;
46
46
  private handleError;
47
47
  private getComponentStack;
48
+ private findClosestErrorBoundary;
49
+ isErrorBoundary(): boolean;
48
50
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
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) {
1
+ import { D as c, e as b, a as x, A as v, b as F, h as U, c as B } from "./h-BbaMkkC7.mjs";
2
+ import { d as Pt, f as Ot } from "./h-BbaMkkC7.mjs";
3
+ function m(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 P(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 (!P(e[n], t[n]))
17
+ if (!m(e[n], t[n]))
18
18
  return !1;
19
19
  return !0;
20
20
  }
@@ -32,24 +32,24 @@ function P(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) && !P(e[s], t[s]))
35
+ if (!(s === "_owner" && e.$$typeof) && !m(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, r, n = null) {
42
+ function N(e, t, r, n = null) {
43
43
  function s(i) {
44
44
  const o = i;
45
45
  n ? t.call(n, o) : t(o);
46
46
  }
47
47
  return r.addEventListener(e, s), s;
48
48
  }
49
- function $(e = {}, t, r = null) {
49
+ function I(e = {}, t, r = null) {
50
50
  const n = {};
51
51
  return Object.entries(e).forEach(([s, i]) => {
52
- n[s] = S(
52
+ n[s] = N(
53
53
  s,
54
54
  i,
55
55
  t,
@@ -57,7 +57,7 @@ function $(e = {}, t, r = null) {
57
57
  );
58
58
  }), n;
59
59
  }
60
- function q(e = {}, t) {
60
+ function $(e = {}, t) {
61
61
  Object.entries(e).forEach(([r, n]) => {
62
62
  t.removeEventListener(r, n);
63
63
  });
@@ -66,15 +66,15 @@ function p(e) {
66
66
  const { type: t } = e;
67
67
  switch (t) {
68
68
  case c.TEXT: {
69
- G(e);
69
+ q(e);
70
70
  break;
71
71
  }
72
72
  case c.ELEMENT: {
73
- _(e);
73
+ G(e);
74
74
  break;
75
75
  }
76
76
  case c.FRAGMENT: {
77
- B(e);
77
+ _(e);
78
78
  break;
79
79
  }
80
80
  case c.COMPONENT: {
@@ -90,15 +90,15 @@ function p(e) {
90
90
  }
91
91
  delete e.el;
92
92
  }
93
- function G(e) {
93
+ function q(e) {
94
94
  const { el: t } = e;
95
95
  t && t.remove();
96
96
  }
97
- function _(e) {
97
+ function G(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(p), n && t && (q(n, t), delete e.listeners);
99
+ s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null), t && t.remove(), r && r.forEach(p), n && t && ($(n, t), delete e.listeners);
100
100
  }
101
- function B(e) {
101
+ function _(e) {
102
102
  const { children: t } = e;
103
103
  t && t.forEach(p);
104
104
  }
@@ -106,7 +106,7 @@ function X(e) {
106
106
  const { children: t } = e;
107
107
  t && t.forEach(p);
108
108
  }
109
- function C(e, t, r) {
109
+ function M(e, t, r) {
110
110
  e.style[t] = r.toString();
111
111
  }
112
112
  function J(e, t) {
@@ -115,7 +115,7 @@ function J(e, t) {
115
115
  function K(e, t) {
116
116
  const { class: r, style: n, ...s } = t;
117
117
  r && W(e, r), n && Object.entries(n).forEach(([i, o]) => {
118
- C(e, i, o);
118
+ M(e, i, o);
119
119
  });
120
120
  for (const [i, o] of Object.entries(s))
121
121
  w(e, i, o);
@@ -133,13 +133,13 @@ function w(e, t, r) {
133
133
  function D(e, t) {
134
134
  e[t] = null, e.removeAttribute(t);
135
135
  }
136
- let m = !1;
136
+ let P = !1;
137
137
  const O = [];
138
138
  function d(e) {
139
139
  O.push(e), Y();
140
140
  }
141
141
  function Y() {
142
- m || (m = !0, queueMicrotask(H));
142
+ P || (P = !0, queueMicrotask(H));
143
143
  }
144
144
  function H() {
145
145
  for (; O.length > 0; ) {
@@ -159,7 +159,7 @@ function H() {
159
159
  }
160
160
  );
161
161
  }
162
- m = !1;
162
+ P = !1;
163
163
  }
164
164
  function A(e) {
165
165
  const { on: t = {}, ...r } = e.props;
@@ -204,14 +204,14 @@ function Q(e, t, r, n) {
204
204
  });
205
205
  }
206
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
- }), L(f, t, r);
207
+ const { tag: s, children: i } = e, a = s === "svg" || t instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
208
+ V(a, e, n), e.el = a, i?.forEach((f) => {
209
+ h(f, a, null, n);
210
+ }), L(a, t, r);
211
211
  }
212
212
  function V(e, t, r) {
213
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), K(e, n);
214
+ n.ref && typeof n.ref == "object" && "current" in n.ref && (n.ref.current = e, delete n.ref), t.listeners = I(s, e, r), K(e, n);
215
215
  }
216
216
  function tt(e, t, r, n) {
217
217
  const s = e.tag, { props: i } = A(e), o = new s(i, n);
@@ -242,9 +242,9 @@ function j(e, t) {
242
242
  props: { key: i }
243
243
  } = r, {
244
244
  tag: o,
245
- props: { key: f }
245
+ props: { key: a }
246
246
  } = n;
247
- return s === o && i === f;
247
+ return s === o && i === a;
248
248
  }
249
249
  if (e.type === c.COMPONENT) {
250
250
  const r = e, n = t, { tag: s } = r, { tag: i } = n;
@@ -256,7 +256,7 @@ function j(e, t) {
256
256
  }
257
257
  return !0;
258
258
  }
259
- function T(e, t) {
259
+ function S(e, t) {
260
260
  const r = Object.keys(e), n = Object.keys(t), s = [], i = [];
261
261
  for (const o of n)
262
262
  o in e ? e[o] !== t[o] && i.push(o) : s.push(o);
@@ -269,10 +269,10 @@ function T(e, t) {
269
269
  function rt(e) {
270
270
  return e !== "";
271
271
  }
272
- function N(e) {
272
+ function T(e) {
273
273
  return rt(e.trim());
274
274
  }
275
- function v(e, t, r, n = null) {
275
+ function y(e, t, r, n = null) {
276
276
  if (!j(e, t)) {
277
277
  const s = nt(r, e.el);
278
278
  return p(e), h(t, r, s, n), t;
@@ -285,7 +285,7 @@ function v(e, t, r, n = null) {
285
285
  break;
286
286
  }
287
287
  case c.COMPONENT: {
288
- at(e, t);
288
+ ft(e, t);
289
289
  break;
290
290
  }
291
291
  case c.PORTAL: {
@@ -309,18 +309,18 @@ function ot(e, t, r) {
309
309
  class: s,
310
310
  style: i,
311
311
  on: o,
312
- ...f
312
+ ...a
313
313
  } = e.props ?? {}, {
314
- class: a,
314
+ class: f,
315
315
  style: u,
316
316
  on: l,
317
- ...y
317
+ ...E
318
318
  } = t.props ?? {}, { listeners: g } = e;
319
- it(n, f, y), ct(n, s, a), ut(
319
+ it(n, a, E), ct(n, s, f), ut(
320
320
  n,
321
321
  i,
322
322
  u
323
- ), t.listeners = ft(
323
+ ), t.listeners = at(
324
324
  n,
325
325
  g,
326
326
  o ?? {},
@@ -333,69 +333,69 @@ 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: a, updated: u } = T(i, o);
337
- for (const l of a)
336
+ const { added: a, removed: f, updated: u } = S(i, o);
337
+ for (const l of f)
338
338
  D(e, l);
339
- for (const l of f.concat(u))
339
+ for (const l of a.concat(u))
340
340
  w(e, l, o[l]);
341
341
  }
342
342
  function ct(e, t, r) {
343
- const n = k(t), s = k(r), { added: i, removed: o } = U(n, s);
343
+ const n = k(t), s = k(r), { added: i, removed: o } = F(n, s);
344
344
  o.length > 0 && e.classList.remove(...o), i.length > 0 && e.classList.add(...i);
345
345
  }
346
346
  function k(e = "") {
347
- return Array.isArray(e) ? e.filter(N) : String(e).split(/(\s+)/).filter(N);
347
+ return Array.isArray(e) ? e.filter(T) : String(e).split(/(\s+)/).filter(T);
348
348
  }
349
349
  function ut(e, t = {}, r = {}) {
350
- const { added: n, removed: s, updated: i } = T(t, r);
350
+ const { added: n, removed: s, updated: i } = S(t, r);
351
351
  for (const o of s)
352
352
  J(e, o);
353
353
  for (const o of n.concat(i))
354
- C(e, o, r[o]);
354
+ M(e, o, r[o]);
355
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)) {
356
+ function at(e, t = {}, r = {}, n = {}, s = null) {
357
+ const { removed: i, added: o, updated: a } = S(r, n);
358
+ for (const u of i.concat(a)) {
359
359
  const l = t?.[u];
360
360
  l && e.removeEventListener(u, l);
361
361
  }
362
- const a = {};
363
- for (const u of o.concat(f))
364
- a[u] = S(
362
+ const f = {};
363
+ for (const u of o.concat(a))
364
+ f[u] = N(
365
365
  u,
366
366
  n[u],
367
367
  e,
368
368
  s
369
369
  );
370
- return a;
370
+ return f;
371
371
  }
372
372
  function R(e, t, r) {
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);
373
+ const n = b(e), s = b(t), i = e.el, o = x(n, s, j), a = r?.offset ?? 0;
374
+ for (const f of o)
375
+ if (f.op === v.NOOP) {
376
+ const { originalIndex: u, index: l } = f;
377
+ y(n[u], s[l], i, r);
378
378
  }
379
- for (const a of o)
380
- switch (a.op) {
381
- case E.MOVE: {
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));
379
+ for (const f of o)
380
+ switch (f.op) {
381
+ case v.MOVE: {
382
+ const { from: u, index: l } = f, E = n[u].el, g = i.childNodes[l + a];
383
+ E && (i.insertBefore(E, g), y(n[u], s[l], i, r));
384
384
  break;
385
385
  }
386
- case E.REMOVE: {
387
- const { item: u } = a;
386
+ case v.REMOVE: {
387
+ const { item: u } = f;
388
388
  p(u);
389
389
  break;
390
390
  }
391
- case E.ADD: {
392
- const { index: u, item: l } = a;
393
- h(l, i, u + f, r);
391
+ case v.ADD: {
392
+ const { index: u, item: l } = f;
393
+ h(l, i, u + a, r);
394
394
  break;
395
395
  }
396
396
  }
397
397
  }
398
- function at(e, t) {
398
+ function ft(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
  }
@@ -407,7 +407,7 @@ function lt(e, t, r) {
407
407
  R(e, t, r);
408
408
  }
409
409
  const ht = (e) => e.isProvider, dt = (e) => e.isConsumer;
410
- class M {
410
+ class C {
411
411
  isMounted = !1;
412
412
  vdom = null;
413
413
  hostEl = null;
@@ -458,7 +458,7 @@ class M {
458
458
  return console.error("Uncaught error:", t, r), this.error = t, Promise.resolve();
459
459
  }
460
460
  shouldComponentUpdate(t, r) {
461
- return P(t, r);
461
+ return m(t, r);
462
462
  }
463
463
  get elements() {
464
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] : [];
@@ -500,7 +500,7 @@ class M {
500
500
  d(() => this.willUpdate(this.props, this.state));
501
501
  try {
502
502
  const n = this.render();
503
- this.vdom = v(this.vdom, n, this.hostEl, this), d(() => this.didUpdate(t, r));
503
+ this.vdom = y(this.vdom, n, this.hostEl, this), d(() => this.didUpdate(t, r));
504
504
  } catch (n) {
505
505
  this.handleError(n, "patch");
506
506
  }
@@ -536,10 +536,32 @@ class M {
536
536
  return this.constructor.defaultProps || {};
537
537
  }
538
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 };
539
+ const n = this.findClosestErrorBoundary();
540
+ if (n && n.isMounted) {
541
+ const i = n.constructor;
542
+ if (i.getDerivedStateFromError) {
543
+ const o = i.getDerivedStateFromError(t);
544
+ n.state = { ...n.state, ...o };
545
+ }
546
+ if (n.didCatch(t, {
547
+ phase: r,
548
+ failedComponent: this.constructor.name,
549
+ componentStack: this.getComponentStack()
550
+ }), n.hostEl && n.vdom)
551
+ try {
552
+ const o = n.render();
553
+ if (o) {
554
+ y(n.vdom, o, n.hostEl, n);
555
+ return;
556
+ }
557
+ } catch (o) {
558
+ console.error("Error during ErrorBoundary recovery:", o);
559
+ }
560
+ }
561
+ const s = this.constructor;
562
+ if (s.getDerivedStateFromError) {
563
+ const i = s.getDerivedStateFromError(t);
564
+ this.state = { ...this.state, ...i };
543
565
  }
544
566
  d(() => {
545
567
  if (this.didCatch(t, {
@@ -547,10 +569,10 @@ class M {
547
569
  componentStack: this.getComponentStack()
548
570
  }), this.hostEl && this.isMounted)
549
571
  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);
572
+ const i = this.render();
573
+ i && y(this.vdom, i, this.hostEl, this);
574
+ } catch (i) {
575
+ console.error("Error during error recovery render:", i);
554
576
  }
555
577
  });
556
578
  }
@@ -561,16 +583,28 @@ class M {
561
583
  t.push(r.constructor.name), r = r.parent;
562
584
  return t.reverse();
563
585
  }
586
+ findClosestErrorBoundary() {
587
+ let t = this.parent;
588
+ for (; t; ) {
589
+ if (t.isErrorBoundary())
590
+ return t;
591
+ t = t.parent;
592
+ }
593
+ return null;
594
+ }
595
+ isErrorBoundary() {
596
+ return this.constructor.getDerivedStateFromError !== void 0;
597
+ }
564
598
  }
565
599
  function yt(e) {
566
- class t extends M {
600
+ class t extends C {
567
601
  isProvider = !0;
568
602
  render() {
569
603
  let s = [];
570
- return Array.isArray(this.props.children) ? s = this.props.children : this.props.children ? s = [this.props.children] : s = [], F(s);
604
+ return Array.isArray(this.props.children) ? s = this.props.children : this.props.children ? s = [this.props.children] : s = [], U(s);
571
605
  }
572
606
  }
573
- class r extends M {
607
+ class r extends C {
574
608
  static contextType = {
575
609
  Provider: t,
576
610
  defaultValue: e
@@ -608,15 +642,15 @@ function vt(e = null) {
608
642
  }
609
643
  function gt(e, t) {
610
644
  const r = Array.isArray(e) ? e : [e];
611
- return I(r, t);
645
+ return B(r, t);
612
646
  }
613
647
  export {
614
- M as Component,
648
+ C as Component,
615
649
  yt as createContext,
616
650
  gt as createPortal,
617
651
  vt as createRef,
618
- mt as h,
619
- F as hFragment,
652
+ Pt as h,
653
+ U as hFragment,
620
654
  Ot as hString,
621
655
  Et as render
622
656
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",