ddd-react 1.10.4 → 1.10.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.
Files changed (2) hide show
  1. package/dist/index.mjs +156 -146
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { D as c, e as m, a as F, A as g, b as x, h as U, c as B } from "./h-BbaMkkC7.mjs";
1
+ import { D as c, e as m, a as R, A as g, b as x, h as B, c as U } from "./h-BbaMkkC7.mjs";
2
2
  import { d as Pt, f as Ot } from "./h-BbaMkkC7.mjs";
3
3
  function b(e, t) {
4
4
  if (e === null || t === null || e === void 0 || t === void 0)
@@ -31,8 +31,8 @@ function b(e, t) {
31
31
  if (!Object.prototype.hasOwnProperty.call(t, r[n]))
32
32
  return !1;
33
33
  for (let n = 0; n < r.length; ++n) {
34
- const s = r[n];
35
- if (!(s === "_owner" && e.$$typeof) && !b(e[s], t[s]))
34
+ const o = r[n];
35
+ if (!(o === "_owner" && e.$$typeof) && !b(e[o], t[o]))
36
36
  return !1;
37
37
  }
38
38
  return !0;
@@ -40,17 +40,17 @@ function b(e, t) {
40
40
  return !1;
41
41
  }
42
42
  function N(e, t, r, n = null) {
43
- function s(i) {
44
- const o = i;
45
- n ? t.call(n, o) : t(o);
43
+ function o(i) {
44
+ const s = i;
45
+ n ? t.call(n, s) : t(s);
46
46
  }
47
- return r.addEventListener(e, s), s;
47
+ return r.addEventListener(e, o), o;
48
48
  }
49
49
  function I(e = {}, t, r = null) {
50
50
  const n = {};
51
- return Object.entries(e).forEach(([s, i]) => {
52
- n[s] = N(
53
- s,
51
+ return Object.entries(e).forEach(([o, i]) => {
52
+ n[o] = N(
53
+ o,
54
54
  i,
55
55
  t,
56
56
  r
@@ -95,8 +95,8 @@ function q(e) {
95
95
  t && t.remove();
96
96
  }
97
97
  function G(e) {
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 && ($(n, t), delete e.listeners);
98
+ const { el: t, children: r, listeners: n, props: o } = e;
99
+ o?.ref && typeof o.ref == "object" && "current" in o.ref && (o.ref.current = null), t && t.remove(), r && r.forEach(p), n && t && ($(n, t), delete e.listeners);
100
100
  }
101
101
  function _(e) {
102
102
  const { children: t } = e;
@@ -113,12 +113,12 @@ function J(e, t) {
113
113
  e.style[t] = null;
114
114
  }
115
115
  function K(e, t) {
116
- const { class: r, style: n, ...s } = t;
117
- r && W(e, r), n && Object.entries(n).forEach(([i, o]) => {
118
- M(e, i, o);
116
+ const { class: r, style: n, ...o } = t;
117
+ r && W(e, r), n && Object.entries(n).forEach(([i, s]) => {
118
+ M(e, i, s);
119
119
  });
120
- for (const [i, o] of Object.entries(s))
121
- w(e, i, o);
120
+ for (const [i, s] of Object.entries(o))
121
+ w(e, i, s);
122
122
  }
123
123
  function W(e, t) {
124
124
  if (e instanceof SVGElement) {
@@ -181,8 +181,8 @@ function h(e, t, r = null, n = null) {
181
181
  }
182
182
  case c.COMPONENT: {
183
183
  tt(e, t, r, n);
184
- const s = e.component;
185
- s && d(() => s.didMount());
184
+ const o = e.component;
185
+ o && d(() => o.didMount());
186
186
  break;
187
187
  }
188
188
  case c.PORTAL: {
@@ -194,28 +194,32 @@ function h(e, t, r = null, n = null) {
194
194
  }
195
195
  }
196
196
  function z(e, t, r) {
197
- const { value: n } = e, s = document.createTextNode(n);
198
- e.el = s, L(s, t, r);
197
+ const { value: n } = e, o = document.createTextNode(n);
198
+ e.el = o, L(o, t, r);
199
199
  }
200
200
  function Q(e, t, r, n) {
201
- const { children: s } = e;
202
- e.el = t, s?.forEach((i, o) => {
203
- h(i, t, r != null ? r + o : null, n);
201
+ const { children: o } = e;
202
+ e.el = t, o?.forEach((i, s) => {
203
+ h(i, t, r != null ? r + s : null, n);
204
204
  });
205
205
  }
206
206
  function Z(e, t, r, n) {
207
- const { tag: s, children: i } = e, l = s === "svg" || t instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
208
- V(l, e, n), e.el = l, i?.forEach((a) => {
209
- h(a, l, null, n);
210
- }), L(l, t, r);
207
+ const { tag: o, children: i } = e, u = o === "svg" || t instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", o) : document.createElement(o);
208
+ V(u, e, n), e.el = u, i?.forEach((a) => {
209
+ h(a, u, null, n);
210
+ }), L(u, t, r);
211
211
  }
212
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 = I(s, e, r), K(e, n);
213
+ const { props: n, events: o } = A(t);
214
+ n.ref && typeof n.ref == "object" && "current" in n.ref && (n.ref.current = e, delete n.ref), t.listeners = I(o, 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 o = e.tag, { props: i } = A(e), s = new o(i, n);
218
+ try {
219
+ s.mount(t, r), e.component = s, e.el = s.firstElement || null;
220
+ } catch {
221
+ s.vdom && (e.component = s);
222
+ }
219
223
  }
220
224
  function L(e, t, r) {
221
225
  if (r == null) {
@@ -229,8 +233,8 @@ function L(e, t, r) {
229
233
  }
230
234
  function et(e, t) {
231
235
  const { children: r, container: n } = e;
232
- r?.forEach((s) => {
233
- h(s, n, null, t);
236
+ r?.forEach((o) => {
237
+ h(o, n, null, t);
234
238
  });
235
239
  }
236
240
  function j(e, t) {
@@ -238,17 +242,17 @@ function j(e, t) {
238
242
  return !1;
239
243
  if (e.type === c.ELEMENT) {
240
244
  const r = e, n = t, {
241
- tag: s,
245
+ tag: o,
242
246
  props: { key: i }
243
247
  } = r, {
244
- tag: o,
245
- props: { key: l }
248
+ tag: s,
249
+ props: { key: u }
246
250
  } = n;
247
- return s === o && i === l;
251
+ return o === s && i === u;
248
252
  }
249
253
  if (e.type === c.COMPONENT) {
250
- const r = e, n = t, { tag: s } = r, { tag: i } = n;
251
- return s === i;
254
+ const r = e, n = t, { tag: o } = r, { tag: i } = n;
255
+ return o === i;
252
256
  }
253
257
  if (e.type === c.PORTAL) {
254
258
  const r = e, n = t;
@@ -256,32 +260,32 @@ function j(e, t) {
256
260
  }
257
261
  return !0;
258
262
  }
259
- function S(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);
263
+ function C(e, t) {
264
+ const r = Object.keys(e), n = Object.keys(t), o = [], i = [];
265
+ for (const s of n)
266
+ s in e ? e[s] !== t[s] && i.push(s) : o.push(s);
263
267
  return {
264
- added: s,
265
- removed: r.filter((o) => !(o in t)),
268
+ added: o,
269
+ removed: r.filter((s) => !(s in t)),
266
270
  updated: i
267
271
  };
268
272
  }
269
273
  function rt(e) {
270
274
  return e !== "";
271
275
  }
272
- function C(e) {
276
+ function S(e) {
273
277
  return rt(e.trim());
274
278
  }
275
279
  function y(e, t, r, n = null) {
276
280
  if (!j(e, t)) {
277
- const s = nt(r, e.el);
278
- return p(e), h(t, r, s, n), t;
281
+ const o = nt(r, e.el);
282
+ return p(e), h(t, r, o, n), t;
279
283
  }
280
284
  switch (t.el = e.el, t.type) {
281
285
  case c.TEXT:
282
- return st(e, t), t;
286
+ return ot(e, t), t;
283
287
  case c.ELEMENT: {
284
- ot(e, t, n);
288
+ st(e, t, n);
285
289
  break;
286
290
  }
287
291
  case c.COMPONENT: {
@@ -293,104 +297,104 @@ function y(e, t, r, n = null) {
293
297
  break;
294
298
  }
295
299
  }
296
- return R(e, t, n), t;
300
+ return F(e, t, n), t;
297
301
  }
298
302
  function nt(e, t) {
299
303
  if (!t) return null;
300
304
  const r = Array.from(e.childNodes).indexOf(t);
301
305
  return r < 0 ? null : r;
302
306
  }
303
- function st(e, t) {
304
- const r = e.el, { value: n } = e, { value: s } = t;
305
- n !== s && r && (r.nodeValue = s);
307
+ function ot(e, t) {
308
+ const r = e.el, { value: n } = e, { value: o } = t;
309
+ n !== o && r && (r.nodeValue = o);
306
310
  }
307
- function ot(e, t, r) {
311
+ function st(e, t, r) {
308
312
  const n = e.el, {
309
- class: s,
313
+ class: o,
310
314
  style: i,
311
- on: o,
312
- ...l
315
+ on: s,
316
+ ...u
313
317
  } = e.props ?? {}, {
314
318
  class: a,
315
- style: u,
319
+ style: l,
316
320
  on: f,
317
321
  ...E
318
322
  } = t.props ?? {}, { listeners: v } = e;
319
- it(n, l, E), ct(n, s, a), ut(
323
+ it(n, u, E), ct(n, o, a), ut(
320
324
  n,
321
325
  i,
322
- u
326
+ l
323
327
  ), t.listeners = lt(
324
328
  n,
325
329
  v,
326
- o ?? {},
330
+ s ?? {},
327
331
  f ?? {},
328
332
  r
329
333
  );
330
334
  }
331
335
  function it(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: l, removed: a, updated: u } = S(i, o);
336
+ const n = t.ref, o = r.ref;
337
+ n !== o && (n && typeof n == "object" && "current" in n && (n.current = null), o && typeof o == "object" && "current" in o && (o.current = e));
338
+ const i = { ...t }, s = { ...r };
339
+ delete i.ref, delete s.ref;
340
+ const { added: u, removed: a, updated: l } = C(i, s);
337
341
  for (const f of a)
338
342
  D(e, f);
339
- for (const f of l.concat(u))
340
- w(e, f, o[f]);
343
+ for (const f of u.concat(l))
344
+ w(e, f, s[f]);
341
345
  }
342
346
  function ct(e, t, r) {
343
- const n = T(t), s = T(r), { added: i, removed: o } = x(n, s);
344
- o.length > 0 && e.classList.remove(...o), i.length > 0 && e.classList.add(...i);
347
+ const n = k(t), o = k(r), { added: i, removed: s } = x(n, o);
348
+ s.length > 0 && e.classList.remove(...s), i.length > 0 && e.classList.add(...i);
345
349
  }
346
- function T(e = "") {
347
- return Array.isArray(e) ? e.filter(C) : String(e).split(/(\s+)/).filter(C);
350
+ function k(e = "") {
351
+ return Array.isArray(e) ? e.filter(S) : String(e).split(/(\s+)/).filter(S);
348
352
  }
349
353
  function ut(e, t = {}, r = {}) {
350
- const { added: n, removed: s, updated: i } = S(t, r);
351
- for (const o of s)
352
- J(e, o);
353
- for (const o of n.concat(i))
354
- M(e, o, r[o]);
355
- }
356
- function lt(e, t = {}, r = {}, n = {}, s = null) {
357
- const { removed: i, added: o, updated: l } = S(r, n);
358
- for (const u of i.concat(l)) {
359
- const f = t?.[u];
360
- f && e.removeEventListener(u, f);
354
+ const { added: n, removed: o, updated: i } = C(t, r);
355
+ for (const s of o)
356
+ J(e, s);
357
+ for (const s of n.concat(i))
358
+ M(e, s, r[s]);
359
+ }
360
+ function lt(e, t = {}, r = {}, n = {}, o = null) {
361
+ const { removed: i, added: s, updated: u } = C(r, n);
362
+ for (const l of i.concat(u)) {
363
+ const f = t?.[l];
364
+ f && e.removeEventListener(l, f);
361
365
  }
362
366
  const a = {};
363
- for (const u of o.concat(l))
364
- a[u] = N(
365
- u,
366
- n[u],
367
+ for (const l of s.concat(u))
368
+ a[l] = N(
369
+ l,
370
+ n[l],
367
371
  e,
368
- s
372
+ o
369
373
  );
370
374
  return a;
371
375
  }
372
- function R(e, t, r) {
373
- const n = m(e), s = m(t), i = e.el, o = F(n, s, j), l = r?.offset ?? 0;
374
- for (const a of o)
376
+ function F(e, t, r) {
377
+ const n = m(e), o = m(t), i = e.el, s = R(n, o, j), u = r?.offset ?? 0;
378
+ for (const a of s)
375
379
  if (a.op === g.NOOP) {
376
- const { originalIndex: u, index: f } = a;
377
- y(n[u], s[f], i, r);
380
+ const { originalIndex: l, index: f } = a;
381
+ y(n[l], o[f], i, r);
378
382
  }
379
- for (const a of o)
383
+ for (const a of s)
380
384
  switch (a.op) {
381
385
  case g.MOVE: {
382
- const { from: u, index: f } = a, E = n[u].el, v = i.childNodes[f + l];
383
- E && (i.insertBefore(E, v), y(n[u], s[f], i, r));
386
+ const { from: l, index: f } = a, E = n[l].el, v = i.childNodes[f + u];
387
+ E && (i.insertBefore(E, v), y(n[l], o[f], i, r));
384
388
  break;
385
389
  }
386
390
  case g.REMOVE: {
387
- const { item: u } = a;
388
- p(u);
391
+ const { item: l } = a;
392
+ p(l);
389
393
  break;
390
394
  }
391
395
  case g.ADD: {
392
- const { index: u, item: f } = a;
393
- h(f, i, u + l, r);
396
+ const { index: l, item: f } = a;
397
+ h(f, i, l + u, r);
394
398
  break;
395
399
  }
396
400
  }
@@ -404,10 +408,10 @@ function ft(e, t, r) {
404
408
  p(e), h(t, document.body, null, r);
405
409
  return;
406
410
  }
407
- R(e, t, r);
411
+ F(e, t, r);
408
412
  }
409
413
  const ht = (e) => e.isProvider, dt = (e) => e.isConsumer;
410
- class k {
414
+ class T {
411
415
  isMounted = !1;
412
416
  vdom = null;
413
417
  hostEl = null;
@@ -470,8 +474,8 @@ class k {
470
474
  return this.vdom?.type === c.FRAGMENT && this.hostEl && this.firstElement ? Array.from(this.hostEl.children).indexOf(this.firstElement) : 0;
471
475
  }
472
476
  updateProps(t) {
473
- const n = { ...this.getDefaultProps(), ...this.props, ...t }, s = this.props;
474
- this.props = n, !this.shouldComponentUpdate(s, n) && (ht(this) && this.notify(), this.patch(s, this.state));
477
+ const n = { ...this.getDefaultProps(), ...this.props, ...t }, o = this.props;
478
+ this.props = n, !this.shouldComponentUpdate(o, n) && (ht(this) && this.notify(), this.patch(o, this.state));
475
479
  }
476
480
  setState(t) {
477
481
  const r = this.state;
@@ -485,7 +489,7 @@ class k {
485
489
  throw new Error("Component is already mounted");
486
490
  dt(this) && !this.subscribedProvider && this.subscribeToProvider(), this.updateContext();
487
491
  try {
488
- this.vdom = this.render(), h(this.vdom, t, r, this), this.hostEl = t, this.isMounted = !0;
492
+ this.vdom = this.render(), this.hostEl = t, h(this.vdom, t, r, this), this.isMounted = !0;
489
493
  } catch (n) {
490
494
  this.handleError(n, "mount");
491
495
  }
@@ -538,36 +542,42 @@ class k {
538
542
  handleError(t, r) {
539
543
  console.log("handleError");
540
544
  const n = this.findClosestErrorBoundary();
541
- if (console.log("errorBoundary", n), console.log(1), n) {
542
- if (console.log(2), n.isMounted) {
543
- console.log(3);
544
- const i = n.constructor;
545
- if (i.getDerivedStateFromError) {
546
- console.log(4);
547
- const o = i.getDerivedStateFromError(t);
548
- n.state = { ...n.state, ...o };
549
- }
550
- if (n.didCatch(t, {
551
- phase: r,
552
- failedComponent: this.constructor.name,
553
- componentStack: this.getComponentStack()
554
- }), n.hostEl && n.vdom) {
555
- console.log(5);
556
- try {
557
- console.log(6);
558
- const o = n.render();
559
- o && (console.log(7), y(n.vdom, o, n.hostEl, n));
560
- } catch (o) {
561
- console.log(8), console.error("Error during ErrorBoundary recovery:", o);
562
- }
545
+ if (console.log("errorBoundary", n), n) {
546
+ console.log("Found error boundary");
547
+ const i = n.constructor;
548
+ if (i.getDerivedStateFromError) {
549
+ console.log("Calling getDerivedStateFromError");
550
+ const s = i.getDerivedStateFromError(t);
551
+ n.state = { ...n.state, ...s };
552
+ }
553
+ if ((r === "patch" || n.isMounted) && (console.log("Calling componentDidCatch"), n.didCatch(t, {
554
+ phase: r,
555
+ failedComponent: this.constructor.name,
556
+ componentStack: this.getComponentStack()
557
+ })), n.hostEl) {
558
+ console.log("Rendering fallback UI");
559
+ try {
560
+ const s = n.render();
561
+ if (s)
562
+ if (n.vdom)
563
+ console.log("Patching ErrorBoundary"), y(n.vdom, s, n.hostEl, n);
564
+ else {
565
+ console.log("Mounting ErrorBoundary fallback");
566
+ const u = n.parent?.offset || 0;
567
+ n.hostEl && n.hostEl.children.length > 0 && Array.from(n.hostEl.children).forEach((a) => {
568
+ a.remove();
569
+ }), h(s, n.hostEl, u, n.parent), n.vdom = s, n.isMounted = !0;
570
+ }
571
+ } catch (s) {
572
+ console.error("Error during ErrorBoundary recovery:", s), n.parent && n.parent.handleError(s, r);
563
573
  }
564
574
  }
565
575
  return;
566
576
  }
567
- console.log(9);
568
- const s = this.constructor;
569
- if (s.getDerivedStateFromError) {
570
- const i = s.getDerivedStateFromError(t);
577
+ console.log("No error boundary found, handling locally");
578
+ const o = this.constructor;
579
+ if (o.getDerivedStateFromError) {
580
+ const i = o.getDerivedStateFromError(t);
571
581
  this.state = { ...this.state, ...i };
572
582
  }
573
583
  d(() => {
@@ -604,31 +614,31 @@ class k {
604
614
  }
605
615
  }
606
616
  function yt(e) {
607
- class t extends k {
617
+ class t extends T {
608
618
  isProvider = !0;
609
619
  render() {
610
- let s = [];
611
- return Array.isArray(this.props.children) ? s = this.props.children : this.props.children ? s = [this.props.children] : s = [], U(s);
620
+ let o = [];
621
+ return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], B(o);
612
622
  }
613
623
  }
614
- class r extends k {
624
+ class r extends T {
615
625
  static contextType = {
616
626
  Provider: t,
617
627
  defaultValue: e
618
628
  };
619
629
  isConsumer = !0;
620
630
  render() {
621
- let s = this.props.children;
622
- if (Array.isArray(s))
623
- if (s.length === 1 && typeof s[0] == "function")
624
- s = s[0];
631
+ let o = this.props.children;
632
+ if (Array.isArray(o))
633
+ if (o.length === 1 && typeof o[0] == "function")
634
+ o = o[0];
625
635
  else
626
636
  throw new Error(
627
637
  "Consumer: expected single function child, got array"
628
638
  );
629
- if (typeof s != "function")
639
+ if (typeof o != "function")
630
640
  throw new Error("Consumer: children is not a function");
631
- return s(this.context);
641
+ return o(this.context);
632
642
  }
633
643
  }
634
644
  return {
@@ -649,15 +659,15 @@ function gt(e = null) {
649
659
  }
650
660
  function vt(e, t) {
651
661
  const r = Array.isArray(e) ? e : [e];
652
- return B(r, t);
662
+ return U(r, t);
653
663
  }
654
664
  export {
655
- k as Component,
665
+ T as Component,
656
666
  yt as createContext,
657
667
  vt as createPortal,
658
668
  gt as createRef,
659
669
  Pt as h,
660
- U as hFragment,
670
+ B as hFragment,
661
671
  Ot as hString,
662
672
  Et as render
663
673
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.10.4",
3
+ "version": "1.10.6",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",