chizu 0.2.7 → 0.2.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.
- package/dist/chizu.js +195 -172
- package/dist/chizu.umd.cjs +1 -1
- package/dist/controller/types.d.ts +1 -1
- package/dist/hooks/index.d.ts +16 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/module/renderer/decorate/index.d.ts +0 -1
package/dist/chizu.js
CHANGED
|
@@ -1,45 +1,28 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var J = Object.defineProperty;
|
|
2
|
+
var D = (t) => {
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
import { jsx as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import * as
|
|
15
|
-
const A = i.createContext({
|
|
16
|
-
appEmitter: new x()
|
|
17
|
-
});
|
|
18
|
-
function U() {
|
|
19
|
-
return i.useContext(A);
|
|
20
|
-
}
|
|
21
|
-
function F(t) {
|
|
22
|
-
return () => {
|
|
23
|
-
const e = i.useMemo(
|
|
24
|
-
() => ({
|
|
25
|
-
appEmitter: new x()
|
|
26
|
-
}),
|
|
27
|
-
[]
|
|
28
|
-
);
|
|
29
|
-
return /* @__PURE__ */ h(A.Provider, { value: e, children: /* @__PURE__ */ h(t, {}) });
|
|
30
|
-
};
|
|
31
|
-
}
|
|
5
|
+
var q = (t, e, n) => e in t ? J(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
6
|
+
var w = (t, e, n) => q(t, typeof e != "symbol" ? e + "" : e, n), k = (t, e, n) => e.has(t) || D("Cannot " + n);
|
|
7
|
+
var E = (t, e, n) => (k(t, e, "read from private field"), n ? n.call(t) : e.get(t)), R = (t, e, n) => e.has(t) ? D("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), b = (t, e, n, r) => (k(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
|
|
8
|
+
import { jsx as p, Fragment as z } from "react/jsx-runtime";
|
|
9
|
+
import { Immer as F } from "immer";
|
|
10
|
+
import v from "lodash/get";
|
|
11
|
+
import x from "traverse";
|
|
12
|
+
import * as a from "react";
|
|
13
|
+
import P from "eventemitter3";
|
|
14
|
+
import * as h from "react-router-dom";
|
|
32
15
|
class _ {
|
|
33
16
|
constructor(e) {
|
|
34
17
|
this.value = e;
|
|
35
18
|
}
|
|
36
19
|
}
|
|
37
|
-
class
|
|
20
|
+
class T {
|
|
38
21
|
static Draft(e) {
|
|
39
22
|
return new _(e);
|
|
40
23
|
}
|
|
41
24
|
}
|
|
42
|
-
|
|
25
|
+
w(T, "Op", {
|
|
43
26
|
Add: 1,
|
|
44
27
|
Remove: 2,
|
|
45
28
|
Update: 4,
|
|
@@ -48,23 +31,23 @@ y(J, "Op", {
|
|
|
48
31
|
});
|
|
49
32
|
var m = /* @__PURE__ */ ((t) => (t.Mount = "lifecycle/mount", t.Node = "lifecycle/node", t.Derive = "lifecycle/derive", t.Error = "distributed/lifecycle/error", t.Unmount = "lifecycle/unmount", t))(m || {});
|
|
50
33
|
const l = {
|
|
51
|
-
immer: new
|
|
34
|
+
immer: new F(),
|
|
52
35
|
annotations: Symbol("annotations")
|
|
53
36
|
};
|
|
54
37
|
l.immer.setAutoFreeze(!1);
|
|
55
|
-
class
|
|
38
|
+
class M {
|
|
56
39
|
constructor(e, n, r = null) {
|
|
57
|
-
|
|
40
|
+
w(this, "process");
|
|
58
41
|
this.value = e, this.operations = n, this.field = r, this.process = null;
|
|
59
42
|
}
|
|
60
43
|
attach(e) {
|
|
61
44
|
return this.process = e, this;
|
|
62
45
|
}
|
|
63
46
|
}
|
|
64
|
-
function
|
|
65
|
-
return new
|
|
47
|
+
function $(t, e = []) {
|
|
48
|
+
return new M(t, e);
|
|
66
49
|
}
|
|
67
|
-
class
|
|
50
|
+
class O {
|
|
68
51
|
constructor(e, n = e) {
|
|
69
52
|
this.stateless = e, this.stateful = n;
|
|
70
53
|
}
|
|
@@ -78,72 +61,72 @@ function C(t, e = []) {
|
|
|
78
61
|
switch (r) {
|
|
79
62
|
case "is":
|
|
80
63
|
return (s) => {
|
|
81
|
-
const o =
|
|
64
|
+
const o = S(t, e);
|
|
82
65
|
if (!o) return !1;
|
|
83
66
|
const u = new Set(
|
|
84
67
|
o.flatMap((c) => c.operations)
|
|
85
68
|
);
|
|
86
69
|
return !!(Array.from(u).reduce(
|
|
87
|
-
(c,
|
|
70
|
+
(c, d) => c | (d ?? 0),
|
|
88
71
|
0
|
|
89
72
|
) & s);
|
|
90
73
|
};
|
|
91
74
|
case "pending":
|
|
92
|
-
return () => !!
|
|
75
|
+
return () => !!S(t, e);
|
|
93
76
|
case "draft":
|
|
94
77
|
return () => {
|
|
95
|
-
const s =
|
|
96
|
-
if (!s) return
|
|
78
|
+
const s = S(t, e);
|
|
79
|
+
if (!s) return v(t, e);
|
|
97
80
|
const o = s.flatMap((u) => u.operations).find((u) => u instanceof _);
|
|
98
|
-
return o ? o.value :
|
|
81
|
+
return o ? o.value : v(t, e);
|
|
99
82
|
};
|
|
100
83
|
}
|
|
101
84
|
return C(t, [...e, String(r)]);
|
|
102
85
|
}
|
|
103
86
|
});
|
|
104
87
|
}
|
|
105
|
-
function
|
|
106
|
-
const r = typeof
|
|
88
|
+
function S(t, e) {
|
|
89
|
+
const r = typeof v(t, e) == "object" ? e : e.slice(0, -1), s = r.length === 0 ? t : v(t, r), o = (s == null ? void 0 : s[l.annotations]) ?? [];
|
|
107
90
|
return o.length > 0 ? o : null;
|
|
108
91
|
}
|
|
109
|
-
function
|
|
92
|
+
function Q(t, e, n) {
|
|
110
93
|
function r(o) {
|
|
111
|
-
return
|
|
94
|
+
return x(o).forEach(function() {
|
|
112
95
|
if (this.key === l.annotations) {
|
|
113
96
|
this.block();
|
|
114
97
|
return;
|
|
115
98
|
}
|
|
116
|
-
this.node instanceof
|
|
99
|
+
this.node instanceof M && this.update(this.node.value);
|
|
117
100
|
});
|
|
118
101
|
}
|
|
119
102
|
function s(o) {
|
|
120
|
-
return
|
|
103
|
+
return x(o).forEach(function() {
|
|
121
104
|
if (this.key === l.annotations) {
|
|
122
105
|
this.block();
|
|
123
106
|
return;
|
|
124
107
|
}
|
|
125
|
-
if (this.node instanceof
|
|
126
|
-
const u = typeof this.node.value == "object",
|
|
108
|
+
if (this.node instanceof M) {
|
|
109
|
+
const u = typeof this.node.value == "object", i = [
|
|
127
110
|
...u ? this.path : this.path.slice(0, -1),
|
|
128
111
|
l.annotations
|
|
129
|
-
], c =
|
|
112
|
+
], c = v(t.stateful, i) ?? [], d = this.node.attach(e);
|
|
130
113
|
u ? this.update(
|
|
131
114
|
{
|
|
132
115
|
...this.node.value,
|
|
133
|
-
[l.annotations]: [
|
|
116
|
+
[l.annotations]: [d, ...c]
|
|
134
117
|
},
|
|
135
118
|
!0
|
|
136
|
-
) : (this.parent && (this.parent.node[l.annotations] = [
|
|
119
|
+
) : (this.parent && (this.parent.node[l.annotations] = [d, ...c]), this.update(this.node.value, !0));
|
|
137
120
|
}
|
|
138
121
|
});
|
|
139
122
|
}
|
|
140
|
-
return new
|
|
123
|
+
return new O(
|
|
141
124
|
r(l.immer.produce(t.stateless, n)),
|
|
142
125
|
s(l.immer.produce(t.stateful, n))
|
|
143
126
|
);
|
|
144
127
|
}
|
|
145
|
-
function
|
|
146
|
-
const n =
|
|
128
|
+
function A(t, e) {
|
|
129
|
+
const n = x(t.stateful).forEach(function() {
|
|
147
130
|
if (this.key === l.annotations) {
|
|
148
131
|
this.block();
|
|
149
132
|
return;
|
|
@@ -161,10 +144,108 @@ function D(t, e) {
|
|
|
161
144
|
);
|
|
162
145
|
}
|
|
163
146
|
});
|
|
164
|
-
return new
|
|
147
|
+
return new O(t.stateless, n);
|
|
148
|
+
}
|
|
149
|
+
function W(t) {
|
|
150
|
+
return (e, n) => async (r = Promise.withResolvers(), s) => {
|
|
151
|
+
if (typeof n != "function") return;
|
|
152
|
+
const o = Symbol("process"), u = n(...s);
|
|
153
|
+
if (u == null)
|
|
154
|
+
return void r.resolve();
|
|
155
|
+
if (typeof u == "function") {
|
|
156
|
+
const i = u(t.model.current, o);
|
|
157
|
+
return t.model.current = A(i, o), t.update.rerender(), void r.resolve();
|
|
158
|
+
}
|
|
159
|
+
for (; ; ) {
|
|
160
|
+
const { value: i, done: c } = await u.next();
|
|
161
|
+
if (c) {
|
|
162
|
+
const H = i(t.model.current, o);
|
|
163
|
+
t.model.current = A(H, o), t.update.rerender();
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
const d = i;
|
|
167
|
+
t.model.current = d(t.model.current, o), t.update.rerender();
|
|
168
|
+
}
|
|
169
|
+
r.resolve();
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function N(t) {
|
|
173
|
+
return t.startsWith("distributed");
|
|
174
|
+
}
|
|
175
|
+
var g, y;
|
|
176
|
+
class G extends Error {
|
|
177
|
+
constructor(n, r = null) {
|
|
178
|
+
super(String(r));
|
|
179
|
+
R(this, g);
|
|
180
|
+
R(this, y);
|
|
181
|
+
b(this, g, n), b(this, y, r);
|
|
182
|
+
}
|
|
183
|
+
get type() {
|
|
184
|
+
return E(this, g);
|
|
185
|
+
}
|
|
186
|
+
get message() {
|
|
187
|
+
return E(this, y) || "";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
g = new WeakMap(), y = new WeakMap();
|
|
191
|
+
function K(t) {
|
|
192
|
+
return new Promise((e) => setTimeout(e, t));
|
|
193
|
+
}
|
|
194
|
+
function V(t) {
|
|
195
|
+
return t ? !!(t && typeof t != "symbol") : Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`);
|
|
196
|
+
}
|
|
197
|
+
function X(t) {
|
|
198
|
+
return t instanceof G;
|
|
199
|
+
}
|
|
200
|
+
function j(t) {
|
|
201
|
+
return JSON.stringify(t);
|
|
202
|
+
}
|
|
203
|
+
const gt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
204
|
+
__proto__: null,
|
|
205
|
+
hash: j,
|
|
206
|
+
isEventError: X,
|
|
207
|
+
pk: V,
|
|
208
|
+
sleep: K
|
|
209
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
210
|
+
function f(t, e) {
|
|
211
|
+
const n = a.useRef(null), r = a.useRef(null);
|
|
212
|
+
return a.useMemo(() => {
|
|
213
|
+
const s = j(e);
|
|
214
|
+
if (r.current !== s) {
|
|
215
|
+
r.current = s;
|
|
216
|
+
const o = t();
|
|
217
|
+
return n.current = o, o;
|
|
218
|
+
}
|
|
219
|
+
return n.current;
|
|
220
|
+
}, e);
|
|
165
221
|
}
|
|
166
|
-
function
|
|
167
|
-
|
|
222
|
+
function U(t, e) {
|
|
223
|
+
const n = a.useRef(null);
|
|
224
|
+
a.useEffect(() => {
|
|
225
|
+
const r = j(e);
|
|
226
|
+
if (n.current !== r)
|
|
227
|
+
return n.current = r, t();
|
|
228
|
+
}, e);
|
|
229
|
+
}
|
|
230
|
+
const I = a.createContext({
|
|
231
|
+
appEmitter: new P()
|
|
232
|
+
});
|
|
233
|
+
function B() {
|
|
234
|
+
return a.useContext(I);
|
|
235
|
+
}
|
|
236
|
+
function Y(t) {
|
|
237
|
+
return () => {
|
|
238
|
+
const e = f(
|
|
239
|
+
() => ({
|
|
240
|
+
appEmitter: new P()
|
|
241
|
+
}),
|
|
242
|
+
[]
|
|
243
|
+
);
|
|
244
|
+
return /* @__PURE__ */ p(I.Provider, { value: e, children: /* @__PURE__ */ p(t, {}) });
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function Z(t) {
|
|
248
|
+
return f(
|
|
168
249
|
() => ({
|
|
169
250
|
controller: {
|
|
170
251
|
get model() {
|
|
@@ -177,10 +258,10 @@ function Q(t) {
|
|
|
177
258
|
props: t.options.props,
|
|
178
259
|
actions: {
|
|
179
260
|
annotate(e, n) {
|
|
180
|
-
return
|
|
261
|
+
return $(e, n);
|
|
181
262
|
},
|
|
182
263
|
produce(e) {
|
|
183
|
-
return (n, r) =>
|
|
264
|
+
return (n, r) => Q(n, r, e);
|
|
184
265
|
},
|
|
185
266
|
dispatch([e, ...n]) {
|
|
186
267
|
if (e == null) return Promise.reject();
|
|
@@ -209,128 +290,84 @@ function Q(t) {
|
|
|
209
290
|
[]
|
|
210
291
|
);
|
|
211
292
|
}
|
|
212
|
-
function
|
|
213
|
-
return
|
|
293
|
+
function L(t) {
|
|
294
|
+
return f(() => {
|
|
214
295
|
var r, s;
|
|
215
296
|
const e = (s = (r = t.options).controller) == null ? void 0 : s.call(r, t.actions.controller);
|
|
216
297
|
return e ? (Object.entries(e).forEach(([o, u]) => t.dispatchers.attach(o, u)), e) : void 0;
|
|
217
298
|
}, []);
|
|
218
299
|
}
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
if (typeof u == "function") {
|
|
224
|
-
const a = u(t.model.current, o);
|
|
225
|
-
return t.model.current = D(a, o), t.update.rerender(), void r.resolve();
|
|
226
|
-
}
|
|
227
|
-
for (; ; ) {
|
|
228
|
-
const { value: a, done: c } = await u.next();
|
|
229
|
-
if (c) {
|
|
230
|
-
const I = a(t.model.current, o);
|
|
231
|
-
t.model.current = D(I, o), t.update.rerender();
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
const f = a;
|
|
235
|
-
t.model.current = f(t.model.current, o), t.update.rerender();
|
|
236
|
-
}
|
|
237
|
-
r.resolve();
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function O(t) {
|
|
241
|
-
return t.startsWith("distributed");
|
|
242
|
-
}
|
|
243
|
-
var v, g;
|
|
244
|
-
class H extends Error {
|
|
245
|
-
constructor(n, r = null) {
|
|
246
|
-
super(String(r));
|
|
247
|
-
E(this, v);
|
|
248
|
-
E(this, g);
|
|
249
|
-
b(this, v, n), b(this, g, r);
|
|
250
|
-
}
|
|
251
|
-
get type() {
|
|
252
|
-
return w(this, v);
|
|
253
|
-
}
|
|
254
|
-
get message() {
|
|
255
|
-
return w(this, g) || "";
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
v = new WeakMap(), g = new WeakMap();
|
|
259
|
-
function K(t) {
|
|
260
|
-
const e = U(), n = G(t);
|
|
261
|
-
return i.useMemo(() => {
|
|
262
|
-
const r = new x(), s = e.appEmitter;
|
|
300
|
+
function tt(t) {
|
|
301
|
+
const e = B(), n = W(t);
|
|
302
|
+
return f(() => {
|
|
303
|
+
const r = new P(), s = e.appEmitter;
|
|
263
304
|
return {
|
|
264
305
|
attach(o, u) {
|
|
265
|
-
const
|
|
266
|
-
|
|
306
|
+
const i = String(o);
|
|
307
|
+
N(i) ? s.on(i, n(o, u)) : r.on(i, n(o, u));
|
|
267
308
|
},
|
|
268
|
-
dispatch(o, u,
|
|
309
|
+
dispatch(o, u, i) {
|
|
269
310
|
const c = String(o);
|
|
270
|
-
|
|
311
|
+
N(c) ? s.emit(c, i, u) : r.emit(c, i, u);
|
|
271
312
|
}
|
|
272
313
|
};
|
|
273
314
|
}, []);
|
|
274
315
|
}
|
|
275
|
-
function
|
|
276
|
-
const t =
|
|
277
|
-
return
|
|
316
|
+
function et() {
|
|
317
|
+
const t = a.useRef(null);
|
|
318
|
+
return f(() => ({ customElement: t }), []);
|
|
278
319
|
}
|
|
279
|
-
function
|
|
280
|
-
var n, r, s
|
|
281
|
-
|
|
282
|
-
i.useLayoutEffect(() => {
|
|
320
|
+
function nt(t) {
|
|
321
|
+
var e, n, r, s;
|
|
322
|
+
U(() => {
|
|
283
323
|
t.dispatchers.dispatch(m.Derive, []);
|
|
284
324
|
}, [
|
|
285
325
|
t.options.props,
|
|
286
|
-
(
|
|
287
|
-
(
|
|
288
|
-
(
|
|
289
|
-
]),
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
t.elements.customElement.current
|
|
293
|
-
]), () => t.dispatchers.dispatch(m.Unmount, []);
|
|
294
|
-
}, []);
|
|
326
|
+
(e = t.router.current) == null ? void 0 : e.location,
|
|
327
|
+
(n = t.router.current) == null ? void 0 : n.params,
|
|
328
|
+
(s = (r = t.router.current) == null ? void 0 : r.search) == null ? void 0 : s[0]
|
|
329
|
+
]), U(() => (t.dispatchers.dispatch(m.Mount, []), t.dispatchers.dispatch(m.Node, [
|
|
330
|
+
t.elements.customElement.current
|
|
331
|
+
]), () => t.dispatchers.dispatch(m.Unmount, [])), []);
|
|
295
332
|
}
|
|
296
|
-
function
|
|
297
|
-
const e =
|
|
298
|
-
return
|
|
333
|
+
function rt(t) {
|
|
334
|
+
const e = f(() => t.options.model ?? {}, []);
|
|
335
|
+
return a.useRef(new O(e, e));
|
|
299
336
|
}
|
|
300
|
-
function
|
|
301
|
-
return
|
|
337
|
+
function ot() {
|
|
338
|
+
return a.useRef(/* @__PURE__ */ new Set());
|
|
302
339
|
}
|
|
303
|
-
function
|
|
304
|
-
return
|
|
340
|
+
function st() {
|
|
341
|
+
return a.useRef(null);
|
|
305
342
|
}
|
|
306
|
-
function
|
|
307
|
-
return
|
|
343
|
+
function ut({ using: t, children: e }) {
|
|
344
|
+
return h.useInRouterContext() ? /* @__PURE__ */ p(it, { using: t, children: e }) : e();
|
|
308
345
|
}
|
|
309
|
-
function
|
|
346
|
+
function it({ using: t, children: e }) {
|
|
310
347
|
return t.current = {
|
|
311
|
-
navigate:
|
|
312
|
-
location:
|
|
313
|
-
params:
|
|
314
|
-
search:
|
|
315
|
-
}, /* @__PURE__ */
|
|
348
|
+
navigate: h.useNavigate(),
|
|
349
|
+
location: h.useLocation(),
|
|
350
|
+
params: h.useParams(),
|
|
351
|
+
search: h.useSearchParams()
|
|
352
|
+
}, /* @__PURE__ */ p(z, { children: e() });
|
|
316
353
|
}
|
|
317
|
-
function
|
|
318
|
-
const [t, e] =
|
|
319
|
-
return
|
|
354
|
+
function ct() {
|
|
355
|
+
const [t, e] = a.useReducer((n) => n + 1, 0);
|
|
356
|
+
return f(() => ({ hash: t, rerender: e }), [t]);
|
|
320
357
|
}
|
|
321
|
-
function
|
|
358
|
+
function at({
|
|
322
359
|
options: t
|
|
323
360
|
}) {
|
|
324
|
-
const e =
|
|
325
|
-
return
|
|
361
|
+
const e = B(), n = ct(), r = ot(), s = et(), o = st(), u = rt({ options: t }), i = tt({ app: e, options: t, update: n, model: u, queue: r }), c = Z({ app: e, options: t, model: u, dispatchers: i, router: o });
|
|
362
|
+
return L({ options: t, dispatchers: i, actions: c }), nt({ options: t, dispatchers: i, elements: s, router: o }), f(() => a.createElement(t.name, {
|
|
326
363
|
ref: s.customElement,
|
|
327
364
|
style: { display: "contents" },
|
|
328
|
-
children: /* @__PURE__ */
|
|
365
|
+
children: /* @__PURE__ */ p(ut, { using: o, children: () => t.view(c.view) })
|
|
329
366
|
}), [n.hash]);
|
|
330
367
|
}
|
|
331
|
-
function
|
|
332
|
-
return (e) =>
|
|
333
|
-
(n) =>
|
|
368
|
+
function lt(t) {
|
|
369
|
+
return (e) => a.memo(
|
|
370
|
+
(n) => at({
|
|
334
371
|
options: {
|
|
335
372
|
...e,
|
|
336
373
|
name: t.join(""),
|
|
@@ -340,25 +377,11 @@ function ot(t) {
|
|
|
340
377
|
(n, r) => JSON.stringify(n) === JSON.stringify(r)
|
|
341
378
|
);
|
|
342
379
|
}
|
|
343
|
-
|
|
344
|
-
return new Promise((e) => setTimeout(e, t));
|
|
345
|
-
}
|
|
346
|
-
function ut(t) {
|
|
347
|
-
return t ? !!(t && typeof t != "symbol") : Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`);
|
|
348
|
-
}
|
|
349
|
-
function it(t) {
|
|
350
|
-
return t instanceof H;
|
|
351
|
-
}
|
|
352
|
-
const ht = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
353
|
-
__proto__: null,
|
|
354
|
-
isEventError: it,
|
|
355
|
-
pk: ut,
|
|
356
|
-
sleep: st
|
|
357
|
-
}, Symbol.toStringTag, { value: "Module" })), pt = { app: F, module: ot };
|
|
380
|
+
const yt = { app: Y, module: lt };
|
|
358
381
|
export {
|
|
359
|
-
|
|
382
|
+
G as EventError,
|
|
360
383
|
m as Lifecycle,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
384
|
+
T as State,
|
|
385
|
+
yt as create,
|
|
386
|
+
gt as utils
|
|
364
387
|
};
|
package/dist/chizu.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("react/jsx-runtime"),require("immer"),require("lodash/get"),require("traverse"),require("react"),require("eventemitter3"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","immer","lodash/get","traverse","react","eventemitter3","react-router-dom"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.Chizu={},s.jsxRuntime,s.Immer,s.get,s.Traverse,s.React,s.EventEmitter3,s.ReactRouterDOM))})(this,function(s,u,l,m,S,F,E,$){"use strict";var me=Object.defineProperty;var H=s=>{throw TypeError(s)};var pe=(s,u,l)=>u in s?me(s,u,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[u]=l;var P=(s,u,l)=>pe(s,typeof u!="symbol"?u+"":u,l),J=(s,u,l)=>u.has(s)||H("Cannot "+l);var D=(s,u,l)=>(J(s,u,"read from private field"),l?l.call(s):u.get(s)),_=(s,u,l)=>u.has(s)?H("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(s):u.set(s,l),x=(s,u,l,m)=>(J(s,u,"write to private field"),m?m.call(s,l):u.set(s,l),l);var w,b;function k(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const d=k(F),g=k($);class q{constructor(t){this.value=t}}class N{static Draft(t){return new q(t)}}P(N,"Op",{Add:1,Remove:2,Update:4,Move:8,Replace:16});var v=(e=>(e.Mount="lifecycle/mount",e.Node="lifecycle/node",e.Derive="lifecycle/derive",e.Error="distributed/lifecycle/error",e.Unmount="lifecycle/unmount",e))(v||{});const h={immer:new l.Immer,annotations:Symbol("annotations")};h.immer.setAutoFreeze(!1);class R{constructor(t,n,r=null){P(this,"process");this.value=t,this.operations=n,this.field=r,this.process=null}attach(t){return this.process=t,this}}function Q(e,t=[]){return new R(e,t)}class j{constructor(t,n=t){this.stateless=t,this.stateful=n}get validatable(){return T(this.stateful)}}function T(e,t=[]){return new Proxy(e,{get(n,r){switch(r){case"is":return c=>{const o=O(e,t);if(!o)return!1;const i=new Set(o.flatMap(f=>f.operations));return!!(Array.from(i).reduce((f,y)=>f|(y??0),0)&c)};case"pending":return()=>!!O(e,t);case"draft":return()=>{const c=O(e,t);if(!c)return m(e,t);const o=c.flatMap(i=>i.operations).find(i=>i instanceof q);return o?o.value:m(e,t)}}return T(e,[...t,String(r)])}})}function O(e,t){const r=typeof m(e,t)=="object"?t:t.slice(0,-1),c=r.length===0?e:m(e,r),o=(c==null?void 0:c[h.annotations])??[];return o.length>0?o:null}function W(e,t,n){function r(o){return S(o).forEach(function(){if(this.key===h.annotations){this.block();return}this.node instanceof R&&this.update(this.node.value)})}function c(o){return S(o).forEach(function(){if(this.key===h.annotations){this.block();return}if(this.node instanceof R){const i=typeof this.node.value=="object",a=[...i?this.path:this.path.slice(0,-1),h.annotations],f=m(e.stateful,a)??[],y=this.node.attach(t);i?this.update({...this.node.value,[h.annotations]:[y,...f]},!0):(this.parent&&(this.parent.node[h.annotations]=[y,...f]),this.update(this.node.value,!0))}})}return new j(r(h.immer.produce(e.stateless,n)),c(h.immer.produce(e.stateful,n)))}function A(e,t){const n=S(e.stateful).forEach(function(){if(this.key===h.annotations){this.block();return}if(this.node&&this.node[h.annotations]){const r=this.node[h.annotations];this.update({...this.node,[h.annotations]:r.filter(c=>c.process!==t)},!0)}});return new j(e.stateless,n)}function G(e){return(t,n)=>async(r=Promise.withResolvers(),c)=>{if(typeof n!="function")return;const o=Symbol("process"),i=n(...c);if(i==null)return void r.resolve();if(typeof i=="function"){const a=i(e.model.current,o);return e.model.current=A(a,o),e.update.rerender(),void r.resolve()}for(;;){const{value:a,done:f}=await i.next();if(f){const he=a(e.model.current,o);e.model.current=A(he,o),e.update.rerender();break}const y=a;e.model.current=y(e.model.current,o),e.update.rerender()}r.resolve()}}function C(e){return e.startsWith("distributed")}class I extends Error{constructor(n,r=null){super(String(r));_(this,w);_(this,b);x(this,w,n),x(this,b,r)}get type(){return D(this,w)}get message(){return D(this,b)||""}}w=new WeakMap,b=new WeakMap;function K(e){return new Promise(t=>setTimeout(t,e))}function V(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function X(e){return e instanceof I}function M(e){return JSON.stringify(e)}const Y=Object.freeze(Object.defineProperty({__proto__:null,hash:M,isEventError:X,pk:V,sleep:K},Symbol.toStringTag,{value:"Module"}));function p(e,t){const n=d.useRef(null),r=d.useRef(null);return d.useMemo(()=>{const c=M(t);if(r.current!==c){r.current=c;const o=e();return n.current=o,o}return n.current},t)}function U(e,t){const n=d.useRef(null);d.useEffect(()=>{const r=M(t);if(n.current!==r)return n.current=r,e()},t)}const z=d.createContext({appEmitter:new E});function B(){return d.useContext(z)}function Z(e){return()=>{const t=p(()=>({appEmitter:new E}),[]);return u.jsx(z.Provider,{value:t,children:u.jsx(e,{})})}}function L(e){return p(()=>({controller:{get model(){return e.model.current.stateful},get router(){return e.router.current},queue:[],props:e.options.props,actions:{annotate(t,n){return Q(t,n)},produce(t){return(n,r)=>W(n,r,t)},dispatch([t,...n]){if(t==null)return Promise.reject();const r=Promise.withResolvers();return e.dispatchers.dispatch(t,n,r),r.promise}}},view:{get model(){return e.model.current.stateless},get validate(){return e.model.current.validatable},props:e.options.props,actions:{dispatch([t,...n]){if(t==null)return Promise.reject();const r=Promise.withResolvers();return e.dispatchers.dispatch(t,n,r),r.promise}}}}),[])}function ee(e){return p(()=>{var r,c;const t=(c=(r=e.options).controller)==null?void 0:c.call(r,e.actions.controller);return t?(Object.entries(t).forEach(([o,i])=>e.dispatchers.attach(o,i)),t):void 0},[])}function te(e){const t=B(),n=G(e);return p(()=>{const r=new E,c=t.appEmitter;return{attach(o,i){const a=String(o);C(a)?c.on(a,n(o,i)):r.on(a,n(o,i))},dispatch(o,i,a){const f=String(o);C(f)?c.emit(f,a,i):r.emit(f,a,i)}}},[])}function ne(){const e=d.useRef(null);return p(()=>({customElement:e}),[])}function re(e){var t,n,r,c;U(()=>{e.dispatchers.dispatch(v.Derive,[])},[e.options.props,(t=e.router.current)==null?void 0:t.location,(n=e.router.current)==null?void 0:n.params,(c=(r=e.router.current)==null?void 0:r.search)==null?void 0:c[0]]),U(()=>(e.dispatchers.dispatch(v.Mount,[]),e.dispatchers.dispatch(v.Node,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(v.Unmount,[])),[])}function se(e){const t=p(()=>e.options.model??{},[]);return d.useRef(new j(t,t))}function oe(){return d.useRef(new Set)}function ue(){return d.useRef(null)}function ce({using:e,children:t}){return g.useInRouterContext()?u.jsx(ie,{using:e,children:t}):t()}function ie({using:e,children:t}){return e.current={navigate:g.useNavigate(),location:g.useLocation(),params:g.useParams(),search:g.useSearchParams()},u.jsx(u.Fragment,{children:t()})}function ae(){const[e,t]=d.useReducer(n=>n+1,0);return p(()=>({hash:e,rerender:t}),[e])}function le({options:e}){const t=B(),n=ae(),r=oe(),c=ne(),o=ue(),i=se({options:e}),a=te({app:t,options:e,update:n,model:i,queue:r}),f=L({app:t,options:e,model:i,dispatchers:a,router:o});return ee({options:e,dispatchers:a,actions:f}),re({options:e,dispatchers:a,elements:c,router:o}),p(()=>d.createElement(e.name,{ref:c.customElement,style:{display:"contents"},children:u.jsx(ce,{using:o,children:()=>e.view(f.view)})}),[n.hash])}function fe(e){return t=>d.memo(n=>le({options:{...t,name:e.join(""),props:n}}),(n,r)=>JSON.stringify(n)===JSON.stringify(r))}const de={app:Z,module:fe};s.EventError=I,s.Lifecycle=v,s.State=N,s.create=de,s.utils=Y,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -19,7 +19,7 @@ export type ActionEvent<M extends ModuleDefinition> = (...args: M["Actions"][num
|
|
|
19
19
|
type ActionEvents<M extends ModuleDefinition> = {
|
|
20
20
|
[K in Head<M["Actions"]>]: (payload: Payload<M["Actions"], K>) => ActionGenerator<M>;
|
|
21
21
|
};
|
|
22
|
-
export type ActionGenerator<M extends ModuleDefinition> = ((models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>) | AsyncGenerator<(models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>, (models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>, unknown>;
|
|
22
|
+
export type ActionGenerator<M extends ModuleDefinition> = void | ((models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>) | AsyncGenerator<(models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>, (models: Models<M["Model"]>, process: Symbol) => Models<M["Model"]>, unknown>;
|
|
23
23
|
export type ControllerDefinition<M extends ModuleDefinition> = (controller: ControllerArgs<M>) => ControllerInstance<M>;
|
|
24
24
|
export type ControllerInstance<M extends ModuleDefinition> = {
|
|
25
25
|
[Lifecycle.Mount]?(): ActionGenerator<M>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Optimises the memoisation of a value based on its dependencies.
|
|
4
|
+
*
|
|
5
|
+
* @param factory {() => T}
|
|
6
|
+
* @param dependencies {React.DependencyList}
|
|
7
|
+
* @returns {T}
|
|
8
|
+
*/
|
|
9
|
+
export declare function useOptimisedMemo<T>(factory: () => T, dependencies: React.DependencyList): T;
|
|
10
|
+
/**
|
|
11
|
+
* Optimises the execution of an effect based on its dependencies.
|
|
12
|
+
*
|
|
13
|
+
* @param effect {React.EffectCallback}
|
|
14
|
+
* @param dependencies {React.DependencyList}
|
|
15
|
+
*/
|
|
16
|
+
export declare function useOptimisedEffect(effect: React.EffectCallback, dependencies: React.DependencyList): void;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { default as sleep } from './sleep/index.ts';
|
|
|
4
4
|
export declare function pk<T>(): Symbol;
|
|
5
5
|
export declare function pk<T>(id: Pk<T>): boolean;
|
|
6
6
|
export declare function isEventError(error: Error | EventError): error is EventError;
|
|
7
|
+
export declare function hash<T>(x: T): string;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|