ddd-react 1.3.8 → 1.3.9

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 +84 -84
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { D as c, e as v, a as U, A as g, b as q, h as I, c as $ } from "./h-BbaMkkC7.mjs";
2
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)
@@ -39,17 +39,17 @@ function E(t, e) {
39
39
  }
40
40
  return !1;
41
41
  }
42
- function S(t, e, n, r = null) {
42
+ function w(t, e, n, r = null) {
43
43
  function s(o) {
44
44
  const i = o;
45
45
  r ? e.call(r, i) : e(i);
46
46
  }
47
47
  return n.addEventListener(t, s), s;
48
48
  }
49
- function $(t = {}, e, n = null) {
49
+ function G(t = {}, e, n = null) {
50
50
  const r = {};
51
51
  return Object.entries(t).forEach(([s, o]) => {
52
- r[s] = S(
52
+ r[s] = w(
53
53
  s,
54
54
  o,
55
55
  e,
@@ -57,7 +57,7 @@ function $(t = {}, e, n = null) {
57
57
  );
58
58
  }), r;
59
59
  }
60
- function G(t = {}, e) {
60
+ function W(t = {}, e) {
61
61
  Object.entries(t).forEach(([n, r]) => {
62
62
  e.removeEventListener(n, r);
63
63
  });
@@ -66,15 +66,15 @@ function p(t) {
66
66
  const { type: e } = t;
67
67
  switch (e) {
68
68
  case c.TEXT: {
69
- W(t);
69
+ B(t);
70
70
  break;
71
71
  }
72
72
  case c.ELEMENT: {
73
- B(t);
73
+ X(t);
74
74
  break;
75
75
  }
76
76
  case c.FRAGMENT: {
77
- X(t);
77
+ _(t);
78
78
  break;
79
79
  }
80
80
  case c.COMPONENT: {
@@ -82,7 +82,7 @@ function p(t) {
82
82
  break;
83
83
  }
84
84
  case c.PORTAL: {
85
- _(t);
85
+ J(t);
86
86
  break;
87
87
  }
88
88
  default:
@@ -90,58 +90,58 @@ function p(t) {
90
90
  }
91
91
  delete t.el;
92
92
  }
93
- function W(t) {
93
+ function B(t) {
94
94
  const { el: e } = t;
95
95
  e && e.remove();
96
96
  }
97
- function B(t) {
97
+ function X(t) {
98
98
  const { el: e, children: n, listeners: r, props: s } = t;
99
- s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null), e && e.remove(), n && n.forEach(p), r && e && (G(r, e), delete t.listeners);
99
+ s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null), e && e.remove(), n && n.forEach(p), r && e && (W(r, e), delete t.listeners);
100
100
  }
101
- function X(t) {
101
+ function _(t) {
102
102
  const { children: e } = t;
103
103
  e && e.forEach(p);
104
104
  }
105
- function _(t) {
105
+ function J(t) {
106
106
  const { children: e } = t;
107
107
  e && e.forEach(p);
108
108
  }
109
- function w(t, e, n) {
109
+ function L(t, e, n) {
110
110
  t.style[e] = n.toString();
111
111
  }
112
- function J(t, e) {
112
+ function K(t, e) {
113
113
  t.style[e] = null;
114
114
  }
115
- function K(t, e) {
115
+ function Y(t, e) {
116
116
  const { class: n, style: r, ...s } = e;
117
- n && Y(t, n), r && Object.entries(r).forEach(([o, i]) => {
118
- w(t, o, i);
117
+ n && H(t, n), r && Object.entries(r).forEach(([o, i]) => {
118
+ L(t, o, i);
119
119
  });
120
120
  for (const [o, i] of Object.entries(s))
121
- L(t, o, i);
121
+ j(t, o, i);
122
122
  }
123
- function Y(t, e) {
123
+ function H(t, e) {
124
124
  if (t instanceof SVGElement) {
125
125
  t.removeAttribute("class"), typeof e == "string" ? t.setAttribute("class", e) : Array.isArray(e) && t.classList.add(...e);
126
126
  return;
127
127
  }
128
128
  t.className = "", typeof e == "string" ? t.className = e : Array.isArray(e) && t.classList.add(...e);
129
129
  }
130
- function L(t, e, n) {
131
- n == null ? j(t, e) : t.setAttribute(e, String(n));
130
+ function j(t, e, n) {
131
+ n == null ? x(t, e) : t.setAttribute(e, String(n));
132
132
  }
133
- function j(t, e) {
133
+ function x(t, e) {
134
134
  t[e] = null, t.removeAttribute(e);
135
135
  }
136
136
  let P = !1;
137
137
  const m = [];
138
138
  function y(t) {
139
- m.push(t), H();
140
- }
141
- function H() {
142
- P || (P = !0, queueMicrotask(z));
139
+ m.push(t), z();
143
140
  }
144
141
  function z() {
142
+ P || (P = !0, queueMicrotask(Q));
143
+ }
144
+ function Q() {
145
145
  for (; m.length > 0; ) {
146
146
  const t = m.shift();
147
147
  let e;
@@ -168,56 +168,56 @@ function A(t) {
168
168
  function h(t, e, n = null, r = null) {
169
169
  switch (t.type) {
170
170
  case c.TEXT: {
171
- Q(t, e, n);
171
+ Z(t, e, n);
172
172
  break;
173
173
  }
174
174
  case c.ELEMENT: {
175
- V(t, e, n, r);
175
+ ee(t, e, n, r);
176
176
  break;
177
177
  }
178
178
  case c.FRAGMENT: {
179
- Z(t, e, n, r);
179
+ V(t, e, n, r);
180
180
  break;
181
181
  }
182
182
  case c.COMPONENT: {
183
- te(t, e, n, r);
183
+ ne(t, e, n, r);
184
184
  const s = t.component;
185
185
  s && y(() => s.onMount());
186
186
  break;
187
187
  }
188
188
  case c.PORTAL: {
189
- ne(t, r);
189
+ re(t, r);
190
190
  break;
191
191
  }
192
192
  default:
193
193
  throw new Error(`Can't mount DOM of type: ${t.type}`);
194
194
  }
195
195
  }
196
- function Q(t, e, n) {
196
+ function Z(t, e, n) {
197
197
  const { value: r } = t, s = document.createTextNode(r);
198
- t.el = s, x(s, e, n);
198
+ t.el = s, D(s, e, n);
199
199
  }
200
- function Z(t, e, n, r) {
200
+ function V(t, e, n, r) {
201
201
  const { children: s } = t;
202
202
  t.el = e, s?.forEach((o, i) => {
203
203
  h(o, e, n != null ? n + i : null, r);
204
204
  });
205
205
  }
206
- function V(t, e, n, r) {
206
+ function ee(t, e, n, r) {
207
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) => {
208
+ te(u, t, r), t.el = u, o?.forEach((f) => {
209
209
  h(f, u, null, r);
210
- }), x(u, e, n);
210
+ }), D(u, e, n);
211
211
  }
212
- function ee(t, e, n) {
212
+ function te(t, e, n) {
213
213
  const { props: r, events: s } = A(e);
214
- r.ref && typeof r.ref == "object" && "current" in r.ref && (r.ref.current = t, delete r.ref), e.listeners = $(s, t, n), K(t, r);
214
+ r.ref && typeof r.ref == "object" && "current" in r.ref && (r.ref.current = t, delete r.ref), e.listeners = G(s, t, n), Y(t, r);
215
215
  }
216
- function te(t, e, n, r) {
216
+ function ne(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 x(t, e, n) {
220
+ function D(t, e, n) {
221
221
  if (n == null) {
222
222
  e.append(t);
223
223
  return;
@@ -227,13 +227,13 @@ function x(t, e, n) {
227
227
  const r = e.childNodes;
228
228
  n >= r.length ? e.append(t) : e.insertBefore(t, r[n]);
229
229
  }
230
- function ne(t, e) {
230
+ function re(t, e) {
231
231
  const { children: n, container: r } = t;
232
232
  n?.forEach((s) => {
233
233
  h(s, r, null, e);
234
234
  });
235
235
  }
236
- function D(t, e) {
236
+ function R(t, e) {
237
237
  if (t.type !== e.type)
238
238
  return !1;
239
239
  if (t.type === c.ELEMENT) {
@@ -266,45 +266,45 @@ function T(t, e) {
266
266
  updated: o
267
267
  };
268
268
  }
269
- function re(t) {
269
+ function se(t) {
270
270
  return t !== "";
271
271
  }
272
272
  function N(t) {
273
- return re(t.trim());
273
+ return se(t.trim());
274
274
  }
275
275
  function O(t, e, n, r = null) {
276
- if (!D(t, e)) {
277
- const s = se(n, t.el);
276
+ if (!R(t, e)) {
277
+ const s = oe(n, t.el);
278
278
  return p(t), h(e, n, s, r), e;
279
279
  }
280
280
  switch (e.el = t.el, e.type) {
281
281
  case c.TEXT:
282
- return oe(t, e), e;
282
+ return ie(t, e), e;
283
283
  case c.ELEMENT: {
284
- ie(t, e, r);
284
+ ce(t, e, r);
285
285
  break;
286
286
  }
287
287
  case c.COMPONENT: {
288
- ae(t, e);
288
+ he(t, e);
289
289
  break;
290
290
  }
291
291
  case c.PORTAL: {
292
- he(t, e, r);
292
+ pe(t, e, r);
293
293
  break;
294
294
  }
295
295
  }
296
- return R(t, e, r), e;
296
+ return F(t, e, r), e;
297
297
  }
298
- function se(t, e) {
298
+ function oe(t, e) {
299
299
  if (!e) return null;
300
300
  const n = Array.from(t.childNodes).indexOf(e);
301
301
  return n < 0 ? null : n;
302
302
  }
303
- function oe(t, e) {
303
+ function ie(t, e) {
304
304
  const n = t.el, { value: r } = t, { value: s } = e;
305
305
  r !== s && n && (n.nodeValue = s);
306
306
  }
307
- function ie(t, e, n) {
307
+ function ce(t, e, n) {
308
308
  const r = t.el, {
309
309
  class: s,
310
310
  style: o,
@@ -316,11 +316,11 @@ function ie(t, e, n) {
316
316
  on: a,
317
317
  ...d
318
318
  } = e.props ?? {}, { listeners: b } = t;
319
- ce(r, u, d), le(r, s, f), ue(
319
+ le(r, u, d), ue(r, s, f), fe(
320
320
  r,
321
321
  o,
322
322
  l
323
- ), e.listeners = fe(
323
+ ), e.listeners = ae(
324
324
  r,
325
325
  b,
326
326
  i ?? {},
@@ -328,32 +328,32 @@ function ie(t, e, n) {
328
328
  n
329
329
  );
330
330
  }
331
- function ce(t, e = {}, n = {}) {
331
+ function le(t, e = {}, n = {}) {
332
332
  const r = e.ref, s = n.ref;
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
336
  const { added: u, removed: f, updated: l } = T(o, i);
337
337
  for (const a of f)
338
- j(t, a);
338
+ x(t, a);
339
339
  for (const a of u.concat(l))
340
- L(t, a, i[a]);
340
+ j(t, a, i[a]);
341
341
  }
342
- function le(t, e, n) {
343
- const r = M(e), s = M(n), { added: o, removed: i } = U(r, s);
342
+ function ue(t, e, n) {
343
+ const r = M(e), s = M(n), { added: o, removed: i } = q(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 ue(t, e = {}, n = {}) {
349
+ function fe(t, e = {}, n = {}) {
350
350
  const { added: r, removed: s, updated: o } = T(e, n);
351
351
  for (const i of s)
352
- J(t, i);
352
+ K(t, i);
353
353
  for (const i of r.concat(o))
354
- w(t, i, n[i]);
354
+ L(t, i, n[i]);
355
355
  }
356
- function fe(t, e = {}, n = {}, r = {}, s = null) {
356
+ function ae(t, e = {}, n = {}, r = {}, s = null) {
357
357
  const { removed: o, added: i, updated: u } = T(n, r);
358
358
  for (const l of o.concat(u)) {
359
359
  const a = e?.[l];
@@ -361,7 +361,7 @@ function fe(t, e = {}, n = {}, r = {}, s = null) {
361
361
  }
362
362
  const f = {};
363
363
  for (const l of i.concat(u))
364
- f[l] = S(
364
+ f[l] = w(
365
365
  l,
366
366
  r[l],
367
367
  t,
@@ -369,8 +369,8 @@ function fe(t, e = {}, n = {}, r = {}, s = null) {
369
369
  );
370
370
  return f;
371
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;
372
+ function F(t, e, n) {
373
+ const r = v(t), s = v(e), o = t.el, i = U(r, s, R), u = n?.offset ?? 0;
374
374
  for (const f of i)
375
375
  if (f.op === g.NOOP) {
376
376
  const { originalIndex: l, index: a } = f;
@@ -395,19 +395,19 @@ function R(t, e, n) {
395
395
  }
396
396
  }
397
397
  }
398
- function ae(t, e) {
398
+ function he(t, e) {
399
399
  const { component: n } = t, { props: r } = A(e);
400
400
  n.updateProps(r), e.component = n, e.el = n.firstElement;
401
401
  }
402
- function he(t, e, n) {
402
+ function pe(t, e, n) {
403
403
  if (t.container !== e.container) {
404
404
  p(t), h(e, document.body, null, n);
405
405
  return;
406
406
  }
407
- R(t, e, n);
407
+ F(t, e, n);
408
408
  }
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 {
409
+ const k = (t) => (console.log("isProvider"), console.log("component.constructor.name", t.constructor.name), t.constructor.name.includes("Provider")), C = (t) => (console.log("isConsumer"), console.log("component.constructor.name", t.constructor.name), t.constructor.name.includes("Consumer"));
410
+ class S {
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
  }
@@ -456,7 +456,7 @@ class C {
456
456
  console.log("return");
457
457
  return;
458
458
  }
459
- console.log("isProvider(this as Component)", k(this)), k(this) && this.notify(), this.patch();
459
+ console.log("this.parent", this.parent), console.log("isProvider(this.parent as Component)", k(this.parent)), k(this.parent) && this.notify(), this.patch();
460
460
  }
461
461
  setState(e) {
462
462
  typeof e == "function" ? this.state = {
@@ -467,7 +467,7 @@ class C {
467
467
  mount(e, n = null) {
468
468
  if (this.isMounted)
469
469
  throw new Error("Component is already mounted");
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;
470
+ console.log("this.parent", this.parent), console.log("isConsumer(this as Component)", C(this)), C(this) && !this.subscribedProvider && (console.log(" this.subscribeToProvider()"), 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
473
  this.isMounted && (y(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: e }) => {
@@ -510,13 +510,13 @@ class C {
510
510
  }
511
511
  }
512
512
  function ge(t) {
513
- class e extends C {
513
+ class e extends S {
514
514
  render() {
515
515
  let o = [];
516
- return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], q(o);
516
+ return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], I(o);
517
517
  }
518
518
  }
519
- const r = class r extends C {
519
+ const r = class r extends S {
520
520
  render() {
521
521
  let o = this.props.children;
522
522
  if (Array.isArray(o))
@@ -554,15 +554,15 @@ function Ee(t = null) {
554
554
  }
555
555
  function be(t, e) {
556
556
  const n = Array.isArray(t) ? t : [t];
557
- return I(n, e);
557
+ return $(n, e);
558
558
  }
559
559
  export {
560
- C as Component,
560
+ S as Component,
561
561
  ge as createContext,
562
562
  be as createPortal,
563
563
  Ee as createRef,
564
564
  me as h,
565
- q as hFragment,
565
+ I as hFragment,
566
566
  Oe as hString,
567
567
  ye as render
568
568
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",