ddd-react 1.10.0 → 1.10.1

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 E, 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,32 +32,32 @@ 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) {
43
- function s(i) {
44
- const o = i;
45
- n ? t.call(n, o) : t(o);
42
+ function N(e, t, r, n = null) {
43
+ function s(o) {
44
+ const i = o;
45
+ n ? t.call(n, i) : t(i);
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
- return Object.entries(e).forEach(([s, i]) => {
52
- n[s] = S(
51
+ return Object.entries(e).forEach(([s, o]) => {
52
+ n[s] = N(
53
53
  s,
54
- i,
54
+ o,
55
55
  t,
56
56
  r
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) {
@@ -114,11 +114,11 @@ function J(e, t) {
114
114
  }
115
115
  function K(e, t) {
116
116
  const { class: r, style: n, ...s } = t;
117
- r && W(e, r), n && Object.entries(n).forEach(([i, o]) => {
118
- C(e, i, o);
117
+ r && W(e, r), n && Object.entries(n).forEach(([o, i]) => {
118
+ M(e, o, i);
119
119
  });
120
- for (const [i, o] of Object.entries(s))
121
- w(e, i, o);
120
+ for (const [o, i] of Object.entries(s))
121
+ w(e, o, i);
122
122
  }
123
123
  function W(e, t) {
124
124
  if (e instanceof SVGElement) {
@@ -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;
@@ -199,23 +199,23 @@ function z(e, t, r) {
199
199
  }
200
200
  function Q(e, t, r, n) {
201
201
  const { children: s } = e;
202
- e.el = t, s?.forEach((i, o) => {
203
- h(i, t, r != null ? r + o : null, n);
202
+ e.el = t, s?.forEach((o, i) => {
203
+ h(o, t, r != null ? r + i : null, 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: o } = 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, o?.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
- 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;
217
+ const s = e.tag, { props: o } = A(e), i = new s(o, n);
218
+ i.mount(t, r), e.component = i, e.el = i.firstElement || null;
219
219
  }
220
220
  function L(e, t, r) {
221
221
  if (r == null) {
@@ -239,16 +239,16 @@ function j(e, t) {
239
239
  if (e.type === c.ELEMENT) {
240
240
  const r = e, n = t, {
241
241
  tag: s,
242
- props: { key: i }
242
+ props: { key: o }
243
243
  } = r, {
244
- tag: o,
245
- props: { key: f }
244
+ tag: i,
245
+ props: { key: a }
246
246
  } = n;
247
- return s === o && i === f;
247
+ return s === i && o === a;
248
248
  }
249
249
  if (e.type === c.COMPONENT) {
250
- const r = e, n = t, { tag: s } = r, { tag: i } = n;
251
- return s === i;
250
+ const r = e, n = t, { tag: s } = r, { tag: o } = n;
251
+ return s === o;
252
252
  }
253
253
  if (e.type === c.PORTAL) {
254
254
  const r = e, n = t;
@@ -256,20 +256,20 @@ function j(e, t) {
256
256
  }
257
257
  return !0;
258
258
  }
259
- function T(e, t) {
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);
259
+ function S(e, t) {
260
+ const r = Object.keys(e), n = Object.keys(t), s = [], o = [];
261
+ for (const i of n)
262
+ i in e ? e[i] !== t[i] && o.push(i) : s.push(i);
263
263
  return {
264
264
  added: s,
265
- removed: r.filter((o) => !(o in t)),
266
- updated: i
265
+ removed: r.filter((i) => !(i in t)),
266
+ updated: o
267
267
  };
268
268
  }
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
275
  function v(e, t, r, n = null) {
@@ -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: {
@@ -307,23 +307,23 @@ function st(e, t) {
307
307
  function ot(e, t, r) {
308
308
  const n = e.el, {
309
309
  class: s,
310
- style: i,
311
- on: o,
312
- ...f
310
+ style: o,
311
+ on: i,
312
+ ...a
313
313
  } = e.props ?? {}, {
314
- class: a,
314
+ class: f,
315
315
  style: u,
316
316
  on: l,
317
317
  ...y
318
318
  } = t.props ?? {}, { listeners: g } = e;
319
- it(n, f, y), ct(n, s, a), ut(
319
+ it(n, a, y), ct(n, s, f), ut(
320
320
  n,
321
- i,
321
+ o,
322
322
  u
323
- ), t.listeners = ft(
323
+ ), t.listeners = at(
324
324
  n,
325
325
  g,
326
- o ?? {},
326
+ i ?? {},
327
327
  l ?? {},
328
328
  r
329
329
  );
@@ -331,71 +331,71 @@ function ot(e, t, r) {
331
331
  function it(e, t = {}, r = {}) {
332
332
  const n = t.ref, s = r.ref;
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
- 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)
334
+ const o = { ...t }, i = { ...r };
335
+ delete o.ref, delete i.ref;
336
+ const { added: a, removed: f, updated: u } = S(o, i);
337
+ for (const l of f)
338
338
  D(e, l);
339
- for (const l of f.concat(u))
340
- w(e, l, o[l]);
339
+ for (const l of a.concat(u))
340
+ w(e, l, i[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);
344
- o.length > 0 && e.classList.remove(...o), i.length > 0 && e.classList.add(...i);
343
+ const n = k(t), s = k(r), { added: o, removed: i } = F(n, s);
344
+ i.length > 0 && e.classList.remove(...i), o.length > 0 && e.classList.add(...o);
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);
351
- for (const o of s)
352
- J(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)) {
350
+ const { added: n, removed: s, updated: o } = S(t, r);
351
+ for (const i of s)
352
+ J(e, i);
353
+ for (const i of n.concat(o))
354
+ M(e, i, r[i]);
355
+ }
356
+ function at(e, t = {}, r = {}, n = {}, s = null) {
357
+ const { removed: o, added: i, updated: a } = S(r, n);
358
+ for (const u of o.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 i.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), o = e.el, i = x(n, s, j), a = r?.offset ?? 0;
374
+ for (const f of i)
375
+ if (f.op === E.NOOP) {
376
+ const { originalIndex: u, index: l } = f;
377
+ v(n[u], s[l], o, r);
378
378
  }
379
- for (const a of o)
380
- switch (a.op) {
379
+ for (const f of i)
380
+ switch (f.op) {
381
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));
382
+ const { from: u, index: l } = f, y = n[u].el, g = o.childNodes[l + a];
383
+ y && (o.insertBefore(y, g), v(n[u], s[l], o, r));
384
384
  break;
385
385
  }
386
386
  case E.REMOVE: {
387
- const { item: u } = a;
387
+ const { item: u } = f;
388
388
  p(u);
389
389
  break;
390
390
  }
391
391
  case E.ADD: {
392
- const { index: u, item: l } = a;
393
- h(l, i, u + f, r);
392
+ const { index: u, item: l } = f;
393
+ h(l, o, 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] : [];
@@ -536,10 +536,29 @@ 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 o = n.constructor;
542
+ if (o.getDerivedStateFromError) {
543
+ const i = o.getDerivedStateFromError(t);
544
+ n.state = { ...n.state, ...i };
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
+ if (n.render())
553
+ return;
554
+ } catch (i) {
555
+ console.error("Error during ErrorBoundary recovery:", i);
556
+ }
557
+ }
558
+ const s = this.constructor;
559
+ if (s.getDerivedStateFromError) {
560
+ const o = s.getDerivedStateFromError(t);
561
+ this.state = { ...this.state, ...o };
543
562
  }
544
563
  d(() => {
545
564
  if (this.didCatch(t, {
@@ -547,10 +566,10 @@ class M {
547
566
  componentStack: this.getComponentStack()
548
567
  }), this.hostEl && this.isMounted)
549
568
  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);
569
+ const o = this.render();
570
+ o && v(this.vdom, o, this.hostEl, this);
571
+ } catch (o) {
572
+ console.error("Error during error recovery render:", o);
554
573
  }
555
574
  });
556
575
  }
@@ -561,16 +580,28 @@ class M {
561
580
  t.push(r.constructor.name), r = r.parent;
562
581
  return t.reverse();
563
582
  }
583
+ findClosestErrorBoundary() {
584
+ let t = this.parent;
585
+ for (; t; ) {
586
+ if (t.isErrorBoundary())
587
+ return t;
588
+ t = t.parent;
589
+ }
590
+ return null;
591
+ }
592
+ isErrorBoundary() {
593
+ return this.constructor.getDerivedStateFromError !== void 0;
594
+ }
564
595
  }
565
596
  function yt(e) {
566
- class t extends M {
597
+ class t extends C {
567
598
  isProvider = !0;
568
599
  render() {
569
600
  let s = [];
570
- return Array.isArray(this.props.children) ? s = this.props.children : this.props.children ? s = [this.props.children] : s = [], F(s);
601
+ return Array.isArray(this.props.children) ? s = this.props.children : this.props.children ? s = [this.props.children] : s = [], U(s);
571
602
  }
572
603
  }
573
- class r extends M {
604
+ class r extends C {
574
605
  static contextType = {
575
606
  Provider: t,
576
607
  defaultValue: e
@@ -608,15 +639,15 @@ function vt(e = null) {
608
639
  }
609
640
  function gt(e, t) {
610
641
  const r = Array.isArray(e) ? e : [e];
611
- return I(r, t);
642
+ return B(r, t);
612
643
  }
613
644
  export {
614
- M as Component,
645
+ C as Component,
615
646
  yt as createContext,
616
647
  gt as createPortal,
617
648
  vt as createRef,
618
- mt as h,
619
- F as hFragment,
649
+ Pt as h,
650
+ U as hFragment,
620
651
  Ot as hString,
621
652
  Et as render
622
653
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",