ddd-react 1.3.6 → 1.3.8

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 +86 -84
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
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";
1
+ import { D as c, e as v, a as F, A as g, b as U, h as q, c as I } from "./h-BbaMkkC7.mjs";
2
+ import { d as me, f as Oe } from "./h-BbaMkkC7.mjs";
3
3
  function E(t, e) {
4
4
  if (t === null || e === null || t === void 0 || e === void 0)
5
5
  return t === e;
@@ -39,7 +39,7 @@ function E(t, e) {
39
39
  }
40
40
  return !1;
41
41
  }
42
- function C(t, e, n, r = null) {
42
+ function S(t, e, n, r = null) {
43
43
  function s(o) {
44
44
  const i = o;
45
45
  r ? e.call(r, i) : e(i);
@@ -49,7 +49,7 @@ function C(t, e, n, r = null) {
49
49
  function $(t = {}, e, n = null) {
50
50
  const r = {};
51
51
  return Object.entries(t).forEach(([s, o]) => {
52
- r[s] = C(
52
+ r[s] = S(
53
53
  s,
54
54
  o,
55
55
  e,
@@ -134,16 +134,16 @@ function j(t, e) {
134
134
  t[e] = null, t.removeAttribute(e);
135
135
  }
136
136
  let P = !1;
137
- const O = [];
138
- function g(t) {
139
- O.push(t), H();
137
+ const m = [];
138
+ function y(t) {
139
+ m.push(t), H();
140
140
  }
141
141
  function H() {
142
142
  P || (P = !0, queueMicrotask(z));
143
143
  }
144
144
  function z() {
145
- for (; O.length > 0; ) {
146
- const t = O.shift();
145
+ for (; m.length > 0; ) {
146
+ const t = m.shift();
147
147
  let e;
148
148
  try {
149
149
  e = t();
@@ -182,7 +182,7 @@ function h(t, e, n = null, r = null) {
182
182
  case c.COMPONENT: {
183
183
  te(t, e, n, r);
184
184
  const s = t.component;
185
- s && g(() => s.onMount());
185
+ s && y(() => s.onMount());
186
186
  break;
187
187
  }
188
188
  case c.PORTAL: {
@@ -195,7 +195,7 @@ function h(t, e, n = null, r = null) {
195
195
  }
196
196
  function Q(t, e, n) {
197
197
  const { value: r } = t, s = document.createTextNode(r);
198
- t.el = s, D(s, e, n);
198
+ t.el = s, x(s, e, n);
199
199
  }
200
200
  function Z(t, e, n, r) {
201
201
  const { children: s } = t;
@@ -204,10 +204,10 @@ function Z(t, e, n, r) {
204
204
  });
205
205
  }
206
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);
207
+ const { tag: s, children: o } = t, u = s === "svg" || e instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
208
+ ee(u, t, r), t.el = u, o?.forEach((f) => {
209
+ h(f, u, null, r);
210
+ }), x(u, e, n);
211
211
  }
212
212
  function ee(t, e, n) {
213
213
  const { props: r, events: s } = A(e);
@@ -217,7 +217,7 @@ function te(t, e, n, r) {
217
217
  const s = t.tag, { props: o } = A(t), i = new s(o, r);
218
218
  i.mount(e, n), t.component = i, t.el = i.firstElement || null;
219
219
  }
220
- function D(t, e, n) {
220
+ function x(t, e, n) {
221
221
  if (n == null) {
222
222
  e.append(t);
223
223
  return;
@@ -233,7 +233,7 @@ function ne(t, e) {
233
233
  h(s, r, null, e);
234
234
  });
235
235
  }
236
- function R(t, e) {
236
+ function D(t, e) {
237
237
  if (t.type !== e.type)
238
238
  return !1;
239
239
  if (t.type === c.ELEMENT) {
@@ -242,9 +242,9 @@ function R(t, e) {
242
242
  props: { key: o }
243
243
  } = n, {
244
244
  tag: i,
245
- props: { key: f }
245
+ props: { key: u }
246
246
  } = r;
247
- return s === i && o === f;
247
+ return s === i && o === u;
248
248
  }
249
249
  if (t.type === c.COMPONENT) {
250
250
  const n = t, r = e, { tag: s } = n, { tag: o } = r;
@@ -272,8 +272,8 @@ function re(t) {
272
272
  function N(t) {
273
273
  return re(t.trim());
274
274
  }
275
- function m(t, e, n, r = null) {
276
- if (!R(t, e)) {
275
+ function O(t, e, n, r = null) {
276
+ if (!D(t, e)) {
277
277
  const s = se(n, t.el);
278
278
  return p(t), h(e, n, s, r), e;
279
279
  }
@@ -293,7 +293,7 @@ function m(t, e, n, r = null) {
293
293
  break;
294
294
  }
295
295
  }
296
- return x(t, e, r), e;
296
+ return R(t, e, r), e;
297
297
  }
298
298
  function se(t, e) {
299
299
  if (!e) return null;
@@ -309,18 +309,18 @@ function ie(t, e, n) {
309
309
  class: s,
310
310
  style: o,
311
311
  on: i,
312
- ...f
312
+ ...u
313
313
  } = t.props ?? {}, {
314
- class: l,
315
- style: u,
314
+ class: f,
315
+ style: l,
316
316
  on: a,
317
317
  ...d
318
318
  } = e.props ?? {}, { listeners: b } = t;
319
- ce(r, f, d), ue(r, s, l), fe(
319
+ ce(r, u, d), le(r, s, f), ue(
320
320
  r,
321
321
  o,
322
- u
323
- ), e.listeners = le(
322
+ l
323
+ ), e.listeners = fe(
324
324
  r,
325
325
  b,
326
326
  i ?? {},
@@ -333,64 +333,64 @@ function ce(t, e = {}, n = {}) {
333
333
  r !== s && (r && typeof r == "object" && "current" in r && (r.current = null), s && typeof s == "object" && "current" in s && (s.current = t));
334
334
  const o = { ...e }, i = { ...n };
335
335
  delete o.ref, delete i.ref;
336
- const { added: f, removed: l, updated: u } = T(o, i);
337
- for (const a of l)
336
+ const { added: u, removed: f, updated: l } = T(o, i);
337
+ for (const a of f)
338
338
  j(t, a);
339
- for (const a of f.concat(u))
339
+ for (const a of u.concat(l))
340
340
  L(t, a, i[a]);
341
341
  }
342
- function ue(t, e, n) {
342
+ function le(t, e, n) {
343
343
  const r = M(e), s = M(n), { added: o, removed: i } = U(r, s);
344
344
  i.length > 0 && t.classList.remove(...i), o.length > 0 && t.classList.add(...o);
345
345
  }
346
346
  function M(t = "") {
347
347
  return Array.isArray(t) ? t.filter(N) : String(t).split(/(\s+)/).filter(N);
348
348
  }
349
- function fe(t, e = {}, n = {}) {
349
+ function ue(t, e = {}, n = {}) {
350
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 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
- }
362
- const l = {};
363
- for (const u of i.concat(f))
364
- l[u] = C(
365
- u,
366
- r[u],
356
+ function fe(t, e = {}, n = {}, r = {}, s = null) {
357
+ const { removed: o, added: i, updated: u } = T(n, r);
358
+ for (const l of o.concat(u)) {
359
+ const a = e?.[l];
360
+ a && t.removeEventListener(l, a);
361
+ }
362
+ const f = {};
363
+ for (const l of i.concat(u))
364
+ f[l] = S(
365
+ l,
366
+ r[l],
367
367
  t,
368
368
  s
369
369
  );
370
- return l;
371
- }
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
- for (const l of i)
375
- if (l.op === y.NOOP) {
376
- const { originalIndex: u, index: a } = l;
377
- m(r[u], s[a], o, n);
370
+ return f;
371
+ }
372
+ function R(t, e, n) {
373
+ const r = v(t), s = v(e), o = t.el, i = F(r, s, D), u = n?.offset ?? 0;
374
+ for (const f of i)
375
+ if (f.op === g.NOOP) {
376
+ const { originalIndex: l, index: a } = f;
377
+ O(r[l], s[a], o, n);
378
378
  }
379
- for (const l of i)
380
- switch (l.op) {
381
- case y.MOVE: {
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));
379
+ for (const f of i)
380
+ switch (f.op) {
381
+ case g.MOVE: {
382
+ const { from: l, index: a } = f, d = r[l].el, b = o.childNodes[a + u];
383
+ d && (o.insertBefore(d, b), O(r[l], s[a], o, n));
384
384
  break;
385
385
  }
386
- case y.REMOVE: {
387
- const { item: u } = l;
388
- p(u);
386
+ case g.REMOVE: {
387
+ const { item: l } = f;
388
+ p(l);
389
389
  break;
390
390
  }
391
- case y.ADD: {
392
- const { index: u, item: a } = l;
393
- h(a, o, u + f, n);
391
+ case g.ADD: {
392
+ const { index: l, item: a } = f;
393
+ h(a, o, l + u, n);
394
394
  break;
395
395
  }
396
396
  }
@@ -404,10 +404,10 @@ function he(t, e, n) {
404
404
  p(t), h(e, document.body, null, n);
405
405
  return;
406
406
  }
407
- x(t, e, n);
407
+ R(t, e, n);
408
408
  }
409
- const k = (t) => t.constructor.name.includes("Provider"), pe = (t) => t.constructor.name.includes("Consumer");
410
- class S {
409
+ const k = (t) => (console.log("isProvider"), console.log("component.constructor.name", t.constructor.name), t.constructor.name.includes("Provider")), pe = (t) => (console.log("isConsumer"), console.log("component.constructor.name", t.constructor.name), t.constructor.name.includes("Consumer"));
410
+ class C {
411
411
  constructor(e = {}, n) {
412
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
  }
@@ -448,7 +448,7 @@ class S {
448
448
  return this.vdom?.type === c.FRAGMENT && this.hostEl && this.firstElement ? Array.from(this.hostEl.children).indexOf(this.firstElement) : 0;
449
449
  }
450
450
  updateProps(e) {
451
- console.log("updateProps");
451
+ console.log("updateProps", this);
452
452
  const n = { ...this.props, ...e }, r = this.props;
453
453
  this.props = n;
454
454
  let s = this.updateContext();
@@ -470,28 +470,30 @@ class S {
470
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;
471
471
  }
472
472
  unmount() {
473
- this.isMounted && (g(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: e }) => {
473
+ this.isMounted && (y(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: e }) => {
474
474
  e.subscribedProvider = null;
475
- }), this.dependencies = [], this.vdom && p(this.vdom), g(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
475
+ }), this.dependencies = [], this.vdom && p(this.vdom), y(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
476
476
  }
477
477
  patch() {
478
478
  if (!this.isMounted || !this.hostEl || !this.vdom)
479
479
  return;
480
480
  const e = this.render();
481
- this.vdom = m(this.vdom, e, this.hostEl, this), g(() => this.onUpdate());
481
+ this.vdom = O(this.vdom, e, this.hostEl, this), y(() => this.onUpdate());
482
482
  }
483
483
  updateContext() {
484
+ console.log("updateContext");
484
485
  const e = Object.getPrototypeOf(this).constructor.contextType;
486
+ console.log("context", e);
485
487
  let n = this.parent;
486
488
  if (e != null) {
487
- for (; n; ) {
488
- if (Object.getPrototypeOf(n).constructor === e.Provider)
489
- return this.context = n.props.value, !0;
489
+ for (console.log(1); n; ) {
490
+ if (console.log(2), Object.getPrototypeOf(n).constructor === e.Provider)
491
+ return this.context = n.props.value, console.log("this.context", this.context), console.log(3), !0;
490
492
  n = n.parent;
491
493
  }
492
- n == null && (this.context = e.defaultValue);
494
+ n == null && (console.log(4), this.context = e.defaultValue);
493
495
  }
494
- return !1;
496
+ return console.log(5), !1;
495
497
  }
496
498
  subscribeToProvider() {
497
499
  const e = Object.getPrototypeOf(this).constructor.contextType;
@@ -507,14 +509,14 @@ class S {
507
509
  }
508
510
  }
509
511
  }
510
- function ye(t) {
511
- class e extends S {
512
+ function ge(t) {
513
+ class e extends C {
512
514
  render() {
513
515
  let o = [];
514
516
  return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], q(o);
515
517
  }
516
518
  }
517
- const r = class r extends S {
519
+ const r = class r extends C {
518
520
  render() {
519
521
  let o = this.props.children;
520
522
  if (Array.isArray(o))
@@ -540,7 +542,7 @@ function ye(t) {
540
542
  defaultValue: t
541
543
  };
542
544
  }
543
- function ge(t, e) {
545
+ function ye(t, e) {
544
546
  if (!e)
545
547
  throw new Error("Container element is not provided for rendering.");
546
548
  h(t, e);
@@ -555,12 +557,12 @@ function be(t, e) {
555
557
  return I(n, e);
556
558
  }
557
559
  export {
558
- S as Component,
559
- ye as createContext,
560
+ C as Component,
561
+ ge as createContext,
560
562
  be as createPortal,
561
563
  Ee as createRef,
562
- Oe as h,
564
+ me as h,
563
565
  q as hFragment,
564
- me as hString,
565
- ge as render
566
+ Oe as hString,
567
+ ye as render
566
568
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",