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