ddd-react 1.4.0 → 1.6.0

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.
@@ -10,7 +10,9 @@ export declare abstract class Component<P = {}, S = ComponentState, ContextValue
10
10
  dependencies: {
11
11
  consumer: Component;
12
12
  }[];
13
- subscribedProvider: Component | null;
13
+ subscribedProvider: Component<{
14
+ value: any;
15
+ }> | null;
14
16
  isProvider: boolean;
15
17
  isConsumer: boolean;
16
18
  constructor(props: P, parentComponent: Component | null);
@@ -23,7 +25,7 @@ export declare abstract class Component<P = {}, S = ComponentState, ContextValue
23
25
  notify(): void;
24
26
  onMount(): void | Promise<void>;
25
27
  onUnmount(): void | Promise<void>;
26
- onUpdate(): void | Promise<void>;
28
+ onUpdate(prevProps: P, prevState: S): void | Promise<void>;
27
29
  onWillUnmount(): void | Promise<void>;
28
30
  abstract render(): VDOMNode;
29
31
  get elements(): HTMLElement[];
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { D as c, e as g, a as x, A as y, b as F, h as U, c as I } from "./h-BbaMkkC7.mjs";
1
+ import { D as c, e as v, a as x, A as y, b as F, h as U, c as I } from "./h-BbaMkkC7.mjs";
2
2
  import { d as Ot, f as mt } from "./h-BbaMkkC7.mjs";
3
- function v(e, t) {
3
+ function g(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)
@@ -13,8 +13,8 @@ function v(e, t) {
13
13
  if (Array.isArray(e)) {
14
14
  if (e.length !== t.length)
15
15
  return !1;
16
- for (let r = 0; r < e.length; ++r)
17
- if (!v(e[r], t[r]))
16
+ for (let n = 0; n < e.length; ++n)
17
+ if (!g(e[n], t[n]))
18
18
  return !1;
19
19
  return !0;
20
20
  }
@@ -24,42 +24,42 @@ function v(e, t) {
24
24
  return e.valueOf() === t.valueOf();
25
25
  if (e.toString !== Object.prototype.toString)
26
26
  return e.toString() === t.toString();
27
- const n = Object.keys(e);
28
- if (n.length !== Object.keys(t).length)
27
+ const r = Object.keys(e);
28
+ if (r.length !== Object.keys(t).length)
29
29
  return !1;
30
- for (let r = 0; r < n.length; ++r)
31
- if (!Object.prototype.hasOwnProperty.call(t, n[r]))
30
+ for (let n = 0; n < r.length; ++n)
31
+ if (!Object.prototype.hasOwnProperty.call(t, r[n]))
32
32
  return !1;
33
- for (let r = 0; r < n.length; ++r) {
34
- const s = n[r];
35
- if (!(s === "_owner" && e.$$typeof) && !v(e[s], t[s]))
33
+ for (let n = 0; n < r.length; ++n) {
34
+ const s = r[n];
35
+ if (!(s === "_owner" && e.$$typeof) && !g(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, n, r = null) {
43
- function s(o) {
44
- const i = o;
45
- r ? t.call(r, i) : t(i);
42
+ function S(e, t, r, n = null) {
43
+ function s(i) {
44
+ const o = i;
45
+ n ? t.call(n, o) : t(o);
46
46
  }
47
- return n.addEventListener(e, s), s;
47
+ return r.addEventListener(e, s), s;
48
48
  }
49
- function $(e = {}, t, n = null) {
50
- const r = {};
51
- return Object.entries(e).forEach(([s, o]) => {
52
- r[s] = S(
49
+ function $(e = {}, t, r = null) {
50
+ const n = {};
51
+ return Object.entries(e).forEach(([s, i]) => {
52
+ n[s] = S(
53
53
  s,
54
- o,
54
+ i,
55
55
  t,
56
- n
56
+ r
57
57
  );
58
- }), r;
58
+ }), n;
59
59
  }
60
60
  function q(e = {}, t) {
61
- Object.entries(e).forEach(([n, r]) => {
62
- t.removeEventListener(n, r);
61
+ Object.entries(e).forEach(([r, n]) => {
62
+ t.removeEventListener(r, n);
63
63
  });
64
64
  }
65
65
  function p(e) {
@@ -95,8 +95,8 @@ function G(e) {
95
95
  t && t.remove();
96
96
  }
97
97
  function W(e) {
98
- const { el: t, children: n, listeners: r, props: s } = e;
99
- s?.ref && typeof s.ref == "object" && "current" in s.ref && (s.ref.current = null), t && t.remove(), n && n.forEach(p), r && t && (q(r, t), delete e.listeners);
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);
100
100
  }
101
101
  function B(e) {
102
102
  const { children: t } = e;
@@ -106,19 +106,19 @@ function X(e) {
106
106
  const { children: t } = e;
107
107
  t && t.forEach(p);
108
108
  }
109
- function C(e, t, n) {
110
- e.style[t] = n.toString();
109
+ function C(e, t, r) {
110
+ e.style[t] = r.toString();
111
111
  }
112
112
  function _(e, t) {
113
113
  e.style[t] = null;
114
114
  }
115
115
  function J(e, t) {
116
- const { class: n, style: r, ...s } = t;
117
- n && K(e, n), r && Object.entries(r).forEach(([o, i]) => {
118
- C(e, o, i);
116
+ const { class: r, style: n, ...s } = t;
117
+ r && K(e, r), n && Object.entries(n).forEach(([i, o]) => {
118
+ C(e, i, o);
119
119
  });
120
- for (const [o, i] of Object.entries(s))
121
- L(e, o, i);
120
+ for (const [i, o] of Object.entries(s))
121
+ L(e, i, o);
122
122
  }
123
123
  function K(e, t) {
124
124
  if (e instanceof SVGElement) {
@@ -127,8 +127,8 @@ function K(e, t) {
127
127
  }
128
128
  e.className = "", typeof t == "string" ? e.className = t : Array.isArray(t) && e.classList.add(...t);
129
129
  }
130
- function L(e, t, n) {
131
- n == null ? w(e, t) : e.setAttribute(t, String(n));
130
+ function L(e, t, r) {
131
+ r == null ? w(e, t) : e.setAttribute(t, String(r));
132
132
  }
133
133
  function w(e, t) {
134
134
  e[t] = null, e.removeAttribute(t);
@@ -147,280 +147,280 @@ function H() {
147
147
  let t;
148
148
  try {
149
149
  t = e();
150
- } catch (n) {
151
- console.error(`[scheduler]: ${n}`);
150
+ } catch (r) {
151
+ console.error(`[scheduler]: ${r}`);
152
152
  continue;
153
153
  }
154
154
  Promise.resolve(t).then(
155
155
  () => {
156
156
  },
157
- (n) => {
158
- console.error(`[scheduler]: ${n}`);
157
+ (r) => {
158
+ console.error(`[scheduler]: ${r}`);
159
159
  }
160
160
  );
161
161
  }
162
162
  P = !1;
163
163
  }
164
164
  function A(e) {
165
- const { on: t = {}, ...n } = e.props;
166
- return delete n.key, { props: n, events: t };
165
+ const { on: t = {}, ...r } = e.props;
166
+ return delete r.key, { props: r, events: t };
167
167
  }
168
- function h(e, t, n = null, r = null) {
168
+ function h(e, t, r = null, n = null) {
169
169
  switch (e.type) {
170
170
  case c.TEXT: {
171
- z(e, t, n);
171
+ z(e, t, r);
172
172
  break;
173
173
  }
174
174
  case c.ELEMENT: {
175
- Z(e, t, n, r);
175
+ Z(e, t, r, n);
176
176
  break;
177
177
  }
178
178
  case c.FRAGMENT: {
179
- Q(e, t, n, r);
179
+ Q(e, t, r, n);
180
180
  break;
181
181
  }
182
182
  case c.COMPONENT: {
183
- tt(e, t, n, r);
183
+ tt(e, t, r, n);
184
184
  const s = e.component;
185
185
  s && E(() => s.onMount());
186
186
  break;
187
187
  }
188
188
  case c.PORTAL: {
189
- et(e, r);
189
+ et(e, n);
190
190
  break;
191
191
  }
192
192
  default:
193
193
  throw new Error(`Can't mount DOM of type: ${e.type}`);
194
194
  }
195
195
  }
196
- function z(e, t, n) {
197
- const { value: r } = e, s = document.createTextNode(r);
198
- e.el = s, j(s, t, n);
196
+ function z(e, t, r) {
197
+ const { value: n } = e, s = document.createTextNode(n);
198
+ e.el = s, j(s, t, r);
199
199
  }
200
- function Q(e, t, n, r) {
200
+ function Q(e, t, r, n) {
201
201
  const { children: s } = e;
202
- e.el = t, s?.forEach((o, i) => {
203
- h(o, t, n != null ? n + i : null, r);
202
+ e.el = t, s?.forEach((i, o) => {
203
+ h(i, t, r != null ? r + o : null, n);
204
204
  });
205
205
  }
206
- function Z(e, t, n, r) {
207
- const { tag: s, children: o } = e, f = s === "svg" || t instanceof SVGElement ? document.createElementNS("http://www.w3.org/2000/svg", s) : document.createElement(s);
208
- V(f, e, r), e.el = f, o?.forEach((l) => {
209
- h(l, f, null, r);
210
- }), j(f, t, n);
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
+ }), j(f, t, r);
211
211
  }
212
- function V(e, t, n) {
213
- const { props: r, events: s } = A(t);
214
- r.ref && typeof r.ref == "object" && "current" in r.ref && (r.ref.current = e, delete r.ref), t.listeners = $(s, e, n), J(e, r);
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 = $(s, e, r), J(e, n);
215
215
  }
216
- function tt(e, t, n, r) {
217
- const s = e.tag, { props: o } = A(e), i = new s(o, r);
218
- i.mount(t, n), e.component = i, e.el = i.firstElement || null;
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;
219
219
  }
220
- function j(e, t, n) {
221
- if (n == null) {
220
+ function j(e, t, r) {
221
+ if (r == null) {
222
222
  t.append(e);
223
223
  return;
224
224
  }
225
- if (n < 0)
226
- throw new Error(`Index must be a positive integer, got ${n}`);
227
- const r = t.childNodes;
228
- n >= r.length ? t.append(e) : t.insertBefore(e, r[n]);
225
+ if (r < 0)
226
+ throw new Error(`Index must be a positive integer, got ${r}`);
227
+ const n = t.childNodes;
228
+ r >= n.length ? t.append(e) : t.insertBefore(e, n[r]);
229
229
  }
230
230
  function et(e, t) {
231
- const { children: n, container: r } = e;
232
- n?.forEach((s) => {
233
- h(s, r, null, t);
231
+ const { children: r, container: n } = e;
232
+ r?.forEach((s) => {
233
+ h(s, n, null, t);
234
234
  });
235
235
  }
236
236
  function D(e, t) {
237
237
  if (e.type !== t.type)
238
238
  return !1;
239
239
  if (e.type === c.ELEMENT) {
240
- const n = e, r = t, {
240
+ const r = e, n = t, {
241
241
  tag: s,
242
- props: { key: o }
243
- } = n, {
244
- tag: i,
242
+ props: { key: i }
243
+ } = r, {
244
+ tag: o,
245
245
  props: { key: f }
246
- } = r;
247
- return s === i && o === f;
246
+ } = n;
247
+ return s === o && i === f;
248
248
  }
249
249
  if (e.type === c.COMPONENT) {
250
- const n = e, r = t, { tag: s } = n, { tag: o } = r;
251
- return s === o;
250
+ const r = e, n = t, { tag: s } = r, { tag: i } = n;
251
+ return s === i;
252
252
  }
253
253
  if (e.type === c.PORTAL) {
254
- const n = e, r = t;
255
- return n.container === r.container;
254
+ const r = e, n = t;
255
+ return r.container === n.container;
256
256
  }
257
257
  return !0;
258
258
  }
259
259
  function T(e, t) {
260
- const n = Object.keys(e), r = Object.keys(t), s = [], o = [];
261
- for (const i of r)
262
- i in e ? e[i] !== t[i] && o.push(i) : s.push(i);
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
263
  return {
264
264
  added: s,
265
- removed: n.filter((i) => !(i in t)),
266
- updated: o
265
+ removed: r.filter((o) => !(o in t)),
266
+ updated: i
267
267
  };
268
268
  }
269
- function nt(e) {
269
+ function rt(e) {
270
270
  return e !== "";
271
271
  }
272
272
  function N(e) {
273
- return nt(e.trim());
273
+ return rt(e.trim());
274
274
  }
275
- function m(e, t, n, r = null) {
275
+ function m(e, t, r, n = null) {
276
276
  if (!D(e, t)) {
277
- const s = rt(n, e.el);
278
- return p(e), h(t, n, s, r), t;
277
+ const s = nt(r, e.el);
278
+ return p(e), h(t, r, s, n), t;
279
279
  }
280
280
  switch (t.el = e.el, t.type) {
281
281
  case c.TEXT:
282
282
  return st(e, t), t;
283
283
  case c.ELEMENT: {
284
- ot(e, t, r);
284
+ it(e, t, n);
285
285
  break;
286
286
  }
287
287
  case c.COMPONENT: {
288
- lt(e, t);
288
+ at(e, t);
289
289
  break;
290
290
  }
291
291
  case c.PORTAL: {
292
- at(e, t, r);
292
+ lt(e, t, n);
293
293
  break;
294
294
  }
295
295
  }
296
- return R(e, t, r), t;
296
+ return R(e, t, n), t;
297
297
  }
298
- function rt(e, t) {
298
+ function nt(e, t) {
299
299
  if (!t) return null;
300
- const n = Array.from(e.childNodes).indexOf(t);
301
- return n < 0 ? null : n;
300
+ const r = Array.from(e.childNodes).indexOf(t);
301
+ return r < 0 ? null : r;
302
302
  }
303
303
  function st(e, t) {
304
- const n = e.el, { value: r } = e, { value: s } = t;
305
- r !== s && n && (n.nodeValue = s);
304
+ const r = e.el, { value: n } = e, { value: s } = t;
305
+ n !== s && r && (r.nodeValue = s);
306
306
  }
307
- function ot(e, t, n) {
308
- const r = e.el, {
307
+ function it(e, t, r) {
308
+ const n = e.el, {
309
309
  class: s,
310
- style: o,
311
- on: i,
310
+ style: i,
311
+ on: o,
312
312
  ...f
313
313
  } = e.props ?? {}, {
314
- class: l,
314
+ class: a,
315
315
  style: u,
316
- on: a,
316
+ on: l,
317
317
  ...d
318
318
  } = t.props ?? {}, { listeners: b } = e;
319
- it(r, f, d), ct(r, s, l), ut(
320
- r,
321
- o,
319
+ ot(n, f, d), ct(n, s, a), ut(
320
+ n,
321
+ i,
322
322
  u
323
323
  ), t.listeners = ft(
324
- r,
324
+ n,
325
325
  b,
326
- i ?? {},
327
- a ?? {},
328
- n
326
+ o ?? {},
327
+ l ?? {},
328
+ r
329
329
  );
330
330
  }
331
- function it(e, t = {}, n = {}) {
332
- const r = t.ref, s = n.ref;
333
- r !== s && (r && typeof r == "object" && "current" in r && (r.current = null), s && typeof s == "object" && "current" in s && (s.current = e));
334
- const o = { ...t }, i = { ...n };
335
- delete o.ref, delete i.ref;
336
- const { added: f, removed: l, updated: u } = T(o, i);
337
- for (const a of l)
338
- w(e, a);
339
- for (const a of f.concat(u))
340
- L(e, a, i[a]);
341
- }
342
- function ct(e, t, n) {
343
- const r = M(t), s = M(n), { added: o, removed: i } = F(r, s);
344
- i.length > 0 && e.classList.remove(...i), o.length > 0 && e.classList.add(...o);
331
+ function ot(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: f, removed: a, updated: u } = T(i, o);
337
+ for (const l of a)
338
+ w(e, l);
339
+ for (const l of f.concat(u))
340
+ L(e, l, o[l]);
341
+ }
342
+ function ct(e, t, r) {
343
+ const n = M(t), s = M(r), { added: i, removed: o } = F(n, s);
344
+ o.length > 0 && e.classList.remove(...o), i.length > 0 && e.classList.add(...i);
345
345
  }
346
346
  function M(e = "") {
347
347
  return Array.isArray(e) ? e.filter(N) : String(e).split(/(\s+)/).filter(N);
348
348
  }
349
- function ut(e, t = {}, n = {}) {
350
- const { added: r, removed: s, updated: o } = T(t, n);
351
- for (const i of s)
352
- _(e, i);
353
- for (const i of r.concat(o))
354
- C(e, i, n[i]);
355
- }
356
- function ft(e, t = {}, 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 = t?.[u];
360
- a && e.removeEventListener(u, a);
361
- }
362
- const l = {};
363
- for (const u of i.concat(f))
364
- l[u] = S(
349
+ function ut(e, t = {}, r = {}) {
350
+ const { added: n, removed: s, updated: i } = T(t, r);
351
+ for (const o of s)
352
+ _(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)) {
359
+ const l = t?.[u];
360
+ l && e.removeEventListener(u, l);
361
+ }
362
+ const a = {};
363
+ for (const u of o.concat(f))
364
+ a[u] = S(
365
365
  u,
366
- r[u],
366
+ n[u],
367
367
  e,
368
368
  s
369
369
  );
370
- return l;
371
- }
372
- function R(e, t, n) {
373
- const r = g(e), s = g(t), o = e.el, i = x(r, s, D), 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 a;
371
+ }
372
+ function R(e, t, r) {
373
+ const n = v(e), s = v(t), i = e.el, o = x(n, s, D), f = r?.offset ?? 0;
374
+ for (const a of o)
375
+ if (a.op === y.NOOP) {
376
+ const { originalIndex: u, index: l } = a;
377
+ m(n[u], s[l], i, r);
378
378
  }
379
- for (const l of i)
380
- switch (l.op) {
379
+ for (const a of o)
380
+ switch (a.op) {
381
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));
382
+ const { from: u, index: l } = a, d = n[u].el, b = i.childNodes[l + f];
383
+ d && (i.insertBefore(d, b), m(n[u], s[l], i, r));
384
384
  break;
385
385
  }
386
386
  case y.REMOVE: {
387
- const { item: u } = l;
387
+ const { item: u } = a;
388
388
  p(u);
389
389
  break;
390
390
  }
391
391
  case y.ADD: {
392
- const { index: u, item: a } = l;
393
- h(a, o, u + f, n);
392
+ const { index: u, item: l } = a;
393
+ h(l, i, u + f, r);
394
394
  break;
395
395
  }
396
396
  }
397
397
  }
398
- function lt(e, t) {
399
- const { component: n } = e, { props: r } = A(t);
400
- n.updateProps(r), t.component = n, t.el = n.firstElement;
398
+ function at(e, t) {
399
+ const { component: r } = e, { props: n } = A(t);
400
+ r.updateProps(n), t.component = r, t.el = r.firstElement;
401
401
  }
402
- function at(e, t, n) {
402
+ function lt(e, t, r) {
403
403
  if (e.container !== t.container) {
404
- p(e), h(t, document.body, null, n);
404
+ p(e), h(t, document.body, null, r);
405
405
  return;
406
406
  }
407
- R(e, t, n);
407
+ R(e, t, r);
408
408
  }
409
409
  const ht = (e) => e.isProvider, pt = (e) => e.isConsumer;
410
410
  class k {
411
- constructor(t = {}, n) {
412
- this.isMounted = !1, this.vdom = null, this.hostEl = null, this.parent = null, this.state = {}, this.context = null, this.dependencies = [], this.subscribedProvider = null, this.isProvider = !1, this.isConsumer = !1, this.props = t, this.parent = n;
411
+ constructor(t = {}, r) {
412
+ this.isMounted = !1, this.vdom = null, this.hostEl = null, this.parent = null, this.state = {}, this.context = null, this.dependencies = [], this.subscribedProvider = null, this.isProvider = !1, this.isConsumer = !1, this.props = t, this.parent = r;
413
413
  }
414
414
  addDependency({ consumer: t }) {
415
- this.dependencies.some((n) => n.consumer === t) || (this.dependencies.push({ consumer: t }), t.subscribedProvider = this);
415
+ this.dependencies.some((r) => r.consumer === t) || (this.dependencies.push({ consumer: t }), t.subscribedProvider = this);
416
416
  }
417
417
  removeDependency({ consumer: t }) {
418
- const n = this.dependencies.findIndex((r) => r.consumer === t);
419
- n !== -1 && (this.dependencies.splice(n, 1), t.subscribedProvider = null);
418
+ const r = this.dependencies.findIndex((n) => n.consumer === t);
419
+ r !== -1 && (this.dependencies.splice(r, 1), t.subscribedProvider = null);
420
420
  }
421
421
  notify() {
422
422
  this.dependencies.forEach(({ consumer: t }) => {
423
- t.isMounted && t.updateContext() && t.patch();
423
+ t.isMounted && t.updateContext() && t.patch(t.props, t.state);
424
424
  });
425
425
  }
426
426
  onMount() {
@@ -429,14 +429,14 @@ class k {
429
429
  onUnmount() {
430
430
  return Promise.resolve();
431
431
  }
432
- onUpdate() {
432
+ onUpdate(t, r) {
433
433
  return Promise.resolve();
434
434
  }
435
435
  onWillUnmount() {
436
436
  return Promise.resolve();
437
437
  }
438
438
  get elements() {
439
- return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? g(this.vdom).flatMap((t) => t.type === c.COMPONENT && t.component ? t.component.elements : t.el ? [t.el] : []) : this.vdom.el ? [this.vdom.el] : [];
439
+ return this.vdom == null ? [] : this.vdom.type === c.FRAGMENT ? v(this.vdom).flatMap((t) => t.type === c.COMPONENT && t.component ? t.component.elements : t.el ? [t.el] : []) : this.vdom.el ? [this.vdom.el] : [];
440
440
  }
441
441
  get firstElement() {
442
442
  return this.elements[0];
@@ -445,57 +445,48 @@ class k {
445
445
  return this.vdom?.type === c.FRAGMENT && this.hostEl && this.firstElement ? Array.from(this.hostEl.children).indexOf(this.firstElement) : 0;
446
446
  }
447
447
  updateProps(t) {
448
- const n = { ...this.props, ...t }, r = this.props;
449
- this.props = n;
448
+ const r = { ...this.props, ...t }, n = this.props;
449
+ this.props = r;
450
450
  let s = this.updateContext();
451
- v(r, n) && !s || (ht(this) && this.notify(), this.patch());
451
+ g(n, r) && !s || (ht(this) && this.notify(), this.patch(n, this.state));
452
452
  }
453
453
  setState(t) {
454
+ let r = this.state;
454
455
  typeof t == "function" ? this.state = {
455
456
  ...this.state,
456
457
  ...t(this.state, this.props)
457
- } : this.state = { ...this.state, ...t }, this.patch();
458
+ } : this.state = { ...this.state, ...t }, this.patch(this.props, r);
458
459
  }
459
- mount(t, n = null) {
460
+ mount(t, r = null) {
460
461
  if (this.isMounted)
461
462
  throw new Error("Component is already mounted");
462
- pt(this) && !this.subscribedProvider && this.subscribeToProvider(), this.updateContext(), this.vdom = this.render(), h(this.vdom, t, n, this), this.hostEl = t, this.isMounted = !0;
463
+ pt(this) && !this.subscribedProvider && this.subscribeToProvider(), this.updateContext(), this.vdom = this.render(), h(this.vdom, t, r, this), this.hostEl = t, this.isMounted = !0;
463
464
  }
464
465
  unmount() {
465
466
  this.isMounted && (E(() => this.onWillUnmount()), this.subscribedProvider && this.subscribedProvider.removeDependency({ consumer: this }), this.dependencies.forEach(({ consumer: t }) => {
466
467
  t.subscribedProvider = null;
467
468
  }), this.dependencies = [], this.vdom && p(this.vdom), E(() => this.onUnmount()), this.vdom = null, this.hostEl = null, this.isMounted = !1);
468
469
  }
469
- patch() {
470
+ patch(t, r) {
470
471
  if (!this.isMounted || !this.hostEl || !this.vdom)
471
472
  return;
472
- const t = this.render();
473
- this.vdom = m(this.vdom, t, this.hostEl, this), E(() => this.onUpdate());
473
+ const n = this.render();
474
+ this.vdom = m(this.vdom, n, this.hostEl, this), E(() => this.onUpdate(t, r));
474
475
  }
475
476
  updateContext() {
476
- const t = Object.getPrototypeOf(this).constructor.contextType;
477
- let n = this.parent;
478
- if (t != null) {
479
- for (; n; ) {
480
- if (Object.getPrototypeOf(n).constructor === t.Provider)
481
- return this.context = n.props.value, !0;
482
- n = n.parent;
483
- }
484
- n == null && (this.context = t.defaultValue);
485
- }
486
- return !1;
477
+ return this.subscribedProvider ? (this.context = this.subscribedProvider.props.value, !0) : !1;
487
478
  }
488
479
  subscribeToProvider() {
489
480
  const t = Object.getPrototypeOf(this).constructor.contextType;
490
481
  if (!t)
491
482
  return;
492
- let n = this.parent;
493
- for (; n; ) {
494
- if (Object.getPrototypeOf(n).constructor === t.Provider) {
495
- n.addDependency({ consumer: this });
483
+ let r = this.parent;
484
+ for (; r; ) {
485
+ if (Object.getPrototypeOf(r).constructor === t.Provider) {
486
+ r.addDependency({ consumer: this });
496
487
  break;
497
488
  }
498
- n = n.parent;
489
+ r = r.parent;
499
490
  }
500
491
  }
501
492
  }
@@ -505,36 +496,36 @@ function yt(e) {
505
496
  super(...arguments), this.isProvider = !0;
506
497
  }
507
498
  render() {
508
- let o = [];
509
- return Array.isArray(this.props.children) ? o = this.props.children : this.props.children ? o = [this.props.children] : o = [], U(o);
499
+ let i = [];
500
+ return Array.isArray(this.props.children) ? i = this.props.children : this.props.children ? i = [this.props.children] : i = [], U(i);
510
501
  }
511
502
  }
512
- const r = class r extends k {
503
+ const n = class n extends k {
513
504
  constructor() {
514
505
  super(...arguments), this.isConsumer = !0;
515
506
  }
516
507
  render() {
517
- let o = this.props.children;
518
- if (Array.isArray(o))
519
- if (o.length === 1 && typeof o[0] == "function")
520
- o = o[0];
508
+ let i = this.props.children;
509
+ if (Array.isArray(i))
510
+ if (i.length === 1 && typeof i[0] == "function")
511
+ i = i[0];
521
512
  else
522
513
  throw new Error(
523
514
  "Consumer: expected single function child, got array"
524
515
  );
525
- if (typeof o != "function")
516
+ if (typeof i != "function")
526
517
  throw new Error("Consumer: children is not a function");
527
- return o(this.context);
518
+ return i(this.context);
528
519
  }
529
520
  };
530
- r.contextType = {
521
+ n.contextType = {
531
522
  Provider: t,
532
523
  defaultValue: e
533
524
  };
534
- let n = r;
525
+ let r = n;
535
526
  return {
536
527
  Provider: t,
537
- Consumer: n,
528
+ Consumer: r,
538
529
  defaultValue: e
539
530
  };
540
531
  }
@@ -548,14 +539,14 @@ function bt(e = null) {
548
539
  current: e
549
540
  };
550
541
  }
551
- function gt(e, t) {
552
- const n = Array.isArray(e) ? e : [e];
553
- return I(n, t);
542
+ function vt(e, t) {
543
+ const r = Array.isArray(e) ? e : [e];
544
+ return I(r, t);
554
545
  }
555
546
  export {
556
547
  k as Component,
557
548
  yt as createContext,
558
- gt as createPortal,
549
+ vt as createPortal,
559
550
  bt as createRef,
560
551
  Ot as h,
561
552
  U as hFragment,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-react",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1",
6
6
  "type-check": "tsc --noEmit",