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