chizu 0.2.13 → 0.2.14
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/broadcast/index.d.ts +4 -0
- package/dist/{context → broadcast}/types.d.ts +3 -3
- package/dist/chizu.js +122 -115
- package/dist/chizu.umd.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/module/renderer/actions/types.d.ts +2 -2
- package/dist/module/renderer/dispatchers/types.d.ts +2 -2
- package/package.json +18 -18
- package/dist/context/index.d.ts +0 -4
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { default as EventEmitter } from 'eventemitter3';
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
export type
|
|
4
|
-
export type
|
|
3
|
+
export type BroadcastOptions = React.ComponentType;
|
|
4
|
+
export type BroadcastContext = {
|
|
5
5
|
appEmitter: EventEmitter;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type UseBroadcast = BroadcastContext;
|
|
8
8
|
export type Props = {
|
|
9
9
|
children: React.ReactNode;
|
|
10
10
|
};
|
package/dist/chizu.js
CHANGED
|
@@ -4,24 +4,24 @@ var j = (t) => {
|
|
|
4
4
|
};
|
|
5
5
|
var z = (t, e, n) => e in t ? T(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
6
6
|
var y = (t, e, n) => z(t, typeof e != "symbol" ? e + "" : e, n), k = (t, e, n) => e.has(t) || j("Cannot " + n);
|
|
7
|
-
var
|
|
7
|
+
var E = (t, e, n) => (k(t, e, "read from private field"), n ? n.call(t) : e.get(t)), w = (t, e, n) => e.has(t) ? j("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
8
|
import { Immer as N } from "immer";
|
|
9
9
|
import p from "lodash/get";
|
|
10
|
-
import
|
|
10
|
+
import x from "traverse";
|
|
11
11
|
import { jsx as $ } from "react/jsx-runtime";
|
|
12
|
-
import * as
|
|
12
|
+
import * as c from "react";
|
|
13
13
|
import M from "eventemitter3";
|
|
14
|
-
class
|
|
14
|
+
class U {
|
|
15
15
|
constructor(e) {
|
|
16
16
|
this.value = e;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
class
|
|
19
|
+
class I {
|
|
20
20
|
static Draft(e) {
|
|
21
|
-
return new
|
|
21
|
+
return new U(e);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
y(
|
|
24
|
+
y(I, "Op", {
|
|
25
25
|
Add: 1,
|
|
26
26
|
Remove: 2,
|
|
27
27
|
Update: 4,
|
|
@@ -29,11 +29,11 @@ y(q, "Op", {
|
|
|
29
29
|
Replace: 16
|
|
30
30
|
});
|
|
31
31
|
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 || {});
|
|
32
|
-
const
|
|
32
|
+
const u = {
|
|
33
33
|
immer: new N(),
|
|
34
34
|
annotations: Symbol("annotations")
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
u.immer.setAutoFreeze(!1);
|
|
37
37
|
class S {
|
|
38
38
|
constructor(e, n, r = null) {
|
|
39
39
|
y(this, "process");
|
|
@@ -43,7 +43,7 @@ class S {
|
|
|
43
43
|
return this.process = e, this;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function q(t, e = []) {
|
|
47
47
|
return new S(t, e);
|
|
48
48
|
}
|
|
49
49
|
class P {
|
|
@@ -51,92 +51,92 @@ class P {
|
|
|
51
51
|
this.stateless = e, this.stateful = n;
|
|
52
52
|
}
|
|
53
53
|
get validatable() {
|
|
54
|
-
return
|
|
54
|
+
return _(this.stateful);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
function
|
|
57
|
+
function _(t, e = []) {
|
|
58
58
|
return new Proxy(t, {
|
|
59
59
|
get(n, r) {
|
|
60
60
|
switch (r) {
|
|
61
61
|
case "is":
|
|
62
|
-
return (
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
65
|
-
const
|
|
66
|
-
|
|
62
|
+
return (s) => {
|
|
63
|
+
const o = R(t, e);
|
|
64
|
+
if (!o) return !1;
|
|
65
|
+
const i = new Set(
|
|
66
|
+
o.flatMap((l) => l.operations)
|
|
67
67
|
);
|
|
68
|
-
return !!(Array.from(
|
|
69
|
-
(l,
|
|
68
|
+
return !!(Array.from(i).reduce(
|
|
69
|
+
(l, f) => l | (f ?? 0),
|
|
70
70
|
0
|
|
71
|
-
) &
|
|
71
|
+
) & s);
|
|
72
72
|
};
|
|
73
73
|
case "pending":
|
|
74
|
-
return () => !!
|
|
74
|
+
return () => !!R(t, e);
|
|
75
75
|
case "draft":
|
|
76
76
|
return () => {
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
const
|
|
80
|
-
return
|
|
77
|
+
const s = R(t, e);
|
|
78
|
+
if (!s) return p(t, e);
|
|
79
|
+
const o = s.flatMap((i) => i.operations).find((i) => i instanceof U);
|
|
80
|
+
return o ? o.value : p(t, e);
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
return
|
|
83
|
+
return _(t, [...e, String(r)]);
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
const r = typeof p(t, e) == "object" ? e : e.slice(0, -1),
|
|
89
|
-
return
|
|
87
|
+
function R(t, e) {
|
|
88
|
+
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[u.annotations]) ?? [];
|
|
89
|
+
return o.length > 0 ? o : null;
|
|
90
90
|
}
|
|
91
91
|
function F(t, e, n) {
|
|
92
|
-
function r(
|
|
93
|
-
return
|
|
94
|
-
if (this.key ===
|
|
92
|
+
function r(o) {
|
|
93
|
+
return x(o).forEach(function() {
|
|
94
|
+
if (this.key === u.annotations) {
|
|
95
95
|
this.block();
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
this.node instanceof S && this.update(this.node.value);
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
function o
|
|
102
|
-
return
|
|
103
|
-
if (this.key ===
|
|
101
|
+
function s(o) {
|
|
102
|
+
return x(o).forEach(function() {
|
|
103
|
+
if (this.key === u.annotations) {
|
|
104
104
|
this.block();
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
if (this.node instanceof S) {
|
|
108
|
-
const
|
|
109
|
-
...
|
|
110
|
-
|
|
111
|
-
], l = p(t.stateful,
|
|
112
|
-
|
|
108
|
+
const i = typeof this.node.value == "object", a = [
|
|
109
|
+
...i ? this.path : this.path.slice(0, -1),
|
|
110
|
+
u.annotations
|
|
111
|
+
], l = p(t.stateful, a) ?? [], f = this.node.attach(e);
|
|
112
|
+
i ? this.update(
|
|
113
113
|
{
|
|
114
114
|
...this.node.value,
|
|
115
|
-
[
|
|
115
|
+
[u.annotations]: [f, ...l]
|
|
116
116
|
},
|
|
117
117
|
!0
|
|
118
|
-
) : (this.parent && (this.parent.node[
|
|
118
|
+
) : (this.parent && (this.parent.node[u.annotations] = [f, ...l]), this.update(this.node.value, !0));
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
return new P(
|
|
123
|
-
r(
|
|
124
|
-
|
|
123
|
+
r(u.immer.produce(t.stateless, n)),
|
|
124
|
+
s(u.immer.produce(t.stateful, n))
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
function D(t, e) {
|
|
128
|
-
const n =
|
|
129
|
-
if (this.key ===
|
|
128
|
+
const n = x(t.stateful).forEach(function() {
|
|
129
|
+
if (this.key === u.annotations) {
|
|
130
130
|
this.block();
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
|
-
if (this.node && this.node[
|
|
134
|
-
const r = this.node[
|
|
133
|
+
if (this.node && this.node[u.annotations]) {
|
|
134
|
+
const r = this.node[u.annotations];
|
|
135
135
|
this.update(
|
|
136
136
|
{
|
|
137
137
|
...this.node,
|
|
138
|
-
[
|
|
139
|
-
(
|
|
138
|
+
[u.annotations]: r.filter(
|
|
139
|
+
(s) => s.process !== e
|
|
140
140
|
)
|
|
141
141
|
},
|
|
142
142
|
!0
|
|
@@ -146,44 +146,44 @@ function D(t, e) {
|
|
|
146
146
|
return new P(t.stateless, n);
|
|
147
147
|
}
|
|
148
148
|
function J(t) {
|
|
149
|
-
return (e, n) => async (r = Promise.withResolvers(),
|
|
149
|
+
return (e, n) => async (r = Promise.withResolvers(), s) => {
|
|
150
150
|
if (typeof n != "function") return;
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
151
|
+
const o = Symbol("process"), i = n(...s);
|
|
152
|
+
if (i == null)
|
|
153
153
|
return void r.resolve();
|
|
154
|
-
if (typeof
|
|
155
|
-
const
|
|
156
|
-
return t.model.current = D(
|
|
154
|
+
if (typeof i == "function") {
|
|
155
|
+
const a = i(t.model.current, o);
|
|
156
|
+
return t.model.current = D(a, o), t.update.rerender(), void r.resolve();
|
|
157
157
|
}
|
|
158
158
|
for (; ; ) {
|
|
159
|
-
const { value:
|
|
159
|
+
const { value: a, done: l } = await i.next();
|
|
160
160
|
if (l) {
|
|
161
|
-
const H =
|
|
162
|
-
t.model.current = D(H,
|
|
161
|
+
const H = a(t.model.current, o);
|
|
162
|
+
t.model.current = D(H, o), t.update.rerender();
|
|
163
163
|
break;
|
|
164
164
|
}
|
|
165
|
-
const
|
|
166
|
-
t.model.current =
|
|
165
|
+
const f = a;
|
|
166
|
+
t.model.current = f(t.model.current, o), t.update.rerender();
|
|
167
167
|
}
|
|
168
168
|
r.resolve();
|
|
169
169
|
};
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function O(t) {
|
|
172
172
|
return t.startsWith("distributed");
|
|
173
173
|
}
|
|
174
174
|
var v, g;
|
|
175
175
|
class Q extends Error {
|
|
176
176
|
constructor(n, r = null) {
|
|
177
177
|
super(String(r));
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
w(this, v);
|
|
179
|
+
w(this, g);
|
|
180
180
|
b(this, v, n), b(this, g, r);
|
|
181
181
|
}
|
|
182
182
|
get type() {
|
|
183
|
-
return
|
|
183
|
+
return E(this, v);
|
|
184
184
|
}
|
|
185
185
|
get message() {
|
|
186
|
-
return
|
|
186
|
+
return E(this, g) || "";
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
v = new WeakMap(), g = new WeakMap();
|
|
@@ -199,52 +199,52 @@ function K(t) {
|
|
|
199
199
|
function h(t) {
|
|
200
200
|
return JSON.stringify(t);
|
|
201
201
|
}
|
|
202
|
-
const
|
|
202
|
+
const dt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
203
203
|
__proto__: null,
|
|
204
204
|
hash: h,
|
|
205
205
|
isEventError: K,
|
|
206
206
|
pk: G,
|
|
207
207
|
sleep: W
|
|
208
208
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
209
|
-
function
|
|
210
|
-
const n =
|
|
211
|
-
return
|
|
212
|
-
const
|
|
213
|
-
if (r.current !==
|
|
214
|
-
r.current =
|
|
215
|
-
const
|
|
216
|
-
return n.current =
|
|
209
|
+
function d(t, e) {
|
|
210
|
+
const n = c.useRef(null), r = c.useRef(null);
|
|
211
|
+
return c.useMemo(() => {
|
|
212
|
+
const s = h(e);
|
|
213
|
+
if (r.current !== s) {
|
|
214
|
+
r.current = s;
|
|
215
|
+
const o = t();
|
|
216
|
+
return n.current = o, o;
|
|
217
217
|
}
|
|
218
218
|
return n.current;
|
|
219
219
|
}, e);
|
|
220
220
|
}
|
|
221
|
-
function
|
|
222
|
-
const n =
|
|
223
|
-
|
|
221
|
+
function B(t, e) {
|
|
222
|
+
const n = c.useRef(null);
|
|
223
|
+
c.useEffect(() => {
|
|
224
224
|
const r = h(e);
|
|
225
225
|
if (n.current !== r)
|
|
226
226
|
return n.current = r, t();
|
|
227
227
|
}, e);
|
|
228
228
|
}
|
|
229
|
-
const
|
|
229
|
+
const A = c.createContext({
|
|
230
230
|
appEmitter: new M()
|
|
231
231
|
});
|
|
232
|
-
function
|
|
233
|
-
return
|
|
232
|
+
function C() {
|
|
233
|
+
return c.useContext(A);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function ft({ children: t }) {
|
|
236
236
|
return () => {
|
|
237
|
-
const e =
|
|
237
|
+
const e = d(
|
|
238
238
|
() => ({
|
|
239
239
|
appEmitter: new M()
|
|
240
240
|
}),
|
|
241
241
|
[]
|
|
242
242
|
);
|
|
243
|
-
return /* @__PURE__ */ $(
|
|
243
|
+
return /* @__PURE__ */ $(A.Provider, { value: e, children: t });
|
|
244
244
|
};
|
|
245
245
|
}
|
|
246
246
|
function V(t) {
|
|
247
|
-
return
|
|
247
|
+
return d(
|
|
248
248
|
() => ({
|
|
249
249
|
controller: {
|
|
250
250
|
get model() {
|
|
@@ -253,7 +253,7 @@ function V(t) {
|
|
|
253
253
|
queue: [],
|
|
254
254
|
actions: {
|
|
255
255
|
annotate(e, n) {
|
|
256
|
-
return
|
|
256
|
+
return q(e, n);
|
|
257
257
|
},
|
|
258
258
|
produce(e) {
|
|
259
259
|
return (n, r) => F(n, r, e);
|
|
@@ -285,69 +285,76 @@ function V(t) {
|
|
|
285
285
|
);
|
|
286
286
|
}
|
|
287
287
|
function X(t) {
|
|
288
|
-
return
|
|
288
|
+
return d(() => {
|
|
289
289
|
const e = t.options.using.actions(t.actions.controller);
|
|
290
|
-
return Object.entries(e).forEach(([r,
|
|
290
|
+
return Object.entries(e).forEach(([r, s]) => t.dispatchers.attach(r, s)), e;
|
|
291
291
|
}, []);
|
|
292
292
|
}
|
|
293
293
|
function Y(t) {
|
|
294
|
-
const e =
|
|
295
|
-
return
|
|
296
|
-
const r = new M()
|
|
294
|
+
const e = C(), n = J(t);
|
|
295
|
+
return d(() => {
|
|
296
|
+
const r = new M();
|
|
297
297
|
return {
|
|
298
|
-
attach(s,
|
|
298
|
+
attach(s, o) {
|
|
299
299
|
const i = String(s);
|
|
300
|
-
|
|
300
|
+
O(i) ? e.appEmitter.on(i, n(s, o)) : r.on(i, n(s, o));
|
|
301
301
|
},
|
|
302
|
-
dispatch(s,
|
|
303
|
-
const
|
|
304
|
-
|
|
302
|
+
dispatch(s, o, i) {
|
|
303
|
+
const a = String(s);
|
|
304
|
+
O(a) ? e.appEmitter.emit(a, i, o) : r.emit(a, i, o);
|
|
305
305
|
}
|
|
306
306
|
};
|
|
307
307
|
}, []);
|
|
308
308
|
}
|
|
309
309
|
function Z() {
|
|
310
|
-
const t =
|
|
311
|
-
return
|
|
310
|
+
const t = c.useRef(null);
|
|
311
|
+
return d(() => ({ customElement: t }), []);
|
|
312
312
|
}
|
|
313
313
|
function L(t) {
|
|
314
|
-
|
|
314
|
+
B(() => {
|
|
315
315
|
t.dispatchers.dispatch(m.Derive, []);
|
|
316
|
-
}, [t.options.using.props]),
|
|
316
|
+
}, [t.options.using.props]), B(() => (t.dispatchers.dispatch(m.Mount, []), t.dispatchers.dispatch(m.Node, [
|
|
317
317
|
t.elements.customElement.current
|
|
318
318
|
]), () => t.dispatchers.dispatch(m.Unmount, [])), []);
|
|
319
319
|
}
|
|
320
320
|
function tt(t) {
|
|
321
|
-
const e =
|
|
322
|
-
return
|
|
321
|
+
const e = d(() => t.options.using.model ?? {}, []);
|
|
322
|
+
return c.useRef(new P(e, e));
|
|
323
323
|
}
|
|
324
324
|
function et() {
|
|
325
|
-
return
|
|
325
|
+
return c.useRef(/* @__PURE__ */ new Set());
|
|
326
326
|
}
|
|
327
327
|
function nt() {
|
|
328
|
-
const [t, e] =
|
|
329
|
-
return
|
|
328
|
+
const [t, e] = c.useReducer((n) => n + 1, 0);
|
|
329
|
+
return d(() => ({ hash: t, rerender: e }), [t]);
|
|
330
330
|
}
|
|
331
331
|
function rt({
|
|
332
332
|
options: t
|
|
333
333
|
}) {
|
|
334
|
-
const e =
|
|
335
|
-
|
|
336
|
-
|
|
334
|
+
const e = nt();
|
|
335
|
+
et();
|
|
336
|
+
const n = Z();
|
|
337
|
+
C();
|
|
338
|
+
const r = tt({ options: t }), s = Y({
|
|
339
|
+
update: e,
|
|
340
|
+
model: r
|
|
341
|
+
}), o = V({ model: r, dispatchers: s });
|
|
342
|
+
return X({ options: t, dispatchers: s, actions: o }), L({ options: t, dispatchers: s, elements: n }), d(() => c.createElement("x-chizu", {
|
|
343
|
+
ref: n.customElement,
|
|
337
344
|
style: { display: "contents" },
|
|
338
|
-
children: t.children(
|
|
339
|
-
}), [
|
|
345
|
+
children: t.children(o.view)
|
|
346
|
+
}), [e.hash, h(t.using.props)]);
|
|
340
347
|
}
|
|
341
348
|
function st(t) {
|
|
342
349
|
return rt({ options: t });
|
|
343
350
|
}
|
|
344
|
-
const ht =
|
|
351
|
+
const ht = c.memo(st, (t, e) => h(t) === h(e));
|
|
345
352
|
export {
|
|
346
|
-
|
|
353
|
+
ft as BroadcastProvider,
|
|
347
354
|
Q as EventError,
|
|
348
355
|
m as Lifecycle,
|
|
349
|
-
|
|
356
|
+
I as State,
|
|
350
357
|
ht as Tree,
|
|
351
|
-
|
|
352
|
-
|
|
358
|
+
C as useBroadcast,
|
|
359
|
+
dt as utils
|
|
353
360
|
};
|
package/dist/chizu.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("immer"),require("lodash/get"),require("traverse"),require("react/jsx-runtime"),require("react"),require("eventemitter3")):typeof define=="function"&&define.amd?define(["exports","immer","lodash/get","traverse","react/jsx-runtime","react","eventemitter3"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.Chizu={},s.Immer,s.get,s.Traverse,s.jsxRuntime,s.React,s.EventEmitter3))})(this,function(s,u,
|
|
1
|
+
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("immer"),require("lodash/get"),require("traverse"),require("react/jsx-runtime"),require("react"),require("eventemitter3")):typeof define=="function"&&define.amd?define(["exports","immer","lodash/get","traverse","react/jsx-runtime","react","eventemitter3"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.Chizu={},s.Immer,s.get,s.Traverse,s.jsxRuntime,s.React,s.EventEmitter3))})(this,function(s,u,c,v,N,I,E){"use strict";var ae=Object.defineProperty;var C=s=>{throw TypeError(s)};var le=(s,u,c)=>u in s?ae(s,u,{enumerable:!0,configurable:!0,writable:!0,value:c}):s[u]=c;var O=(s,u,c)=>le(s,typeof u!="symbol"?u+"":u,c),H=(s,u,c)=>u.has(s)||C("Cannot "+c);var M=(s,u,c)=>(H(s,u,"read from private field"),c?c.call(s):u.get(s)),x=(s,u,c)=>u.has(s)?C("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(s):u.set(s,c),D=(s,u,c,v)=>(H(s,u,"write to private field"),v?v.call(s,c):u.set(s,c),c);var g,w;function $(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 l=$(I);class k{constructor(t){this.value=t}}class T{static Draft(t){return new k(t)}}O(T,"Op",{Add:1,Remove:2,Update:4,Move:8,Replace:16});var p=(e=>(e.Mount="lifecycle/mount",e.Node="lifecycle/node",e.Derive="lifecycle/derive",e.Error="distributed/lifecycle/error",e.Unmount="lifecycle/unmount",e))(p||{});const d={immer:new u.Immer,annotations:Symbol("annotations")};d.immer.setAutoFreeze(!1);class j{constructor(t,n,r=null){O(this,"process");this.value=t,this.operations=n,this.field=r,this.process=null}attach(t){return this.process=t,this}}function F(e,t=[]){return new j(e,t)}class S{constructor(t,n=t){this.stateless=t,this.stateful=n}get validatable(){return _(this.stateful)}}function _(e,t=[]){return new Proxy(e,{get(n,r){switch(r){case"is":return o=>{const i=R(e,t);if(!i)return!1;const a=new Set(i.flatMap(m=>m.operations));return!!(Array.from(a).reduce((m,b)=>m|(b??0),0)&o)};case"pending":return()=>!!R(e,t);case"draft":return()=>{const o=R(e,t);if(!o)return c(e,t);const i=o.flatMap(a=>a.operations).find(a=>a instanceof k);return i?i.value:c(e,t)}}return _(e,[...t,String(r)])}})}function R(e,t){const r=typeof c(e,t)=="object"?t:t.slice(0,-1),o=r.length===0?e:c(e,r),i=(o==null?void 0:o[d.annotations])??[];return i.length>0?i:null}function J(e,t,n){function r(i){return v(i).forEach(function(){if(this.key===d.annotations){this.block();return}this.node instanceof j&&this.update(this.node.value)})}function o(i){return v(i).forEach(function(){if(this.key===d.annotations){this.block();return}if(this.node instanceof j){const a=typeof this.node.value=="object",f=[...a?this.path:this.path.slice(0,-1),d.annotations],m=c(e.stateful,f)??[],b=this.node.attach(t);a?this.update({...this.node.value,[d.annotations]:[b,...m]},!0):(this.parent&&(this.parent.node[d.annotations]=[b,...m]),this.update(this.node.value,!0))}})}return new S(r(d.immer.produce(e.stateless,n)),o(d.immer.produce(e.stateful,n)))}function B(e,t){const n=v(e.stateful).forEach(function(){if(this.key===d.annotations){this.block();return}if(this.node&&this.node[d.annotations]){const r=this.node[d.annotations];this.update({...this.node,[d.annotations]:r.filter(o=>o.process!==t)},!0)}});return new S(e.stateless,n)}function Q(e){return(t,n)=>async(r=Promise.withResolvers(),o)=>{if(typeof n!="function")return;const i=Symbol("process"),a=n(...o);if(a==null)return void r.resolve();if(typeof a=="function"){const f=a(e.model.current,i);return e.model.current=B(f,i),e.update.rerender(),void r.resolve()}for(;;){const{value:f,done:m}=await a.next();if(m){const ce=f(e.model.current,i);e.model.current=B(ce,i),e.update.rerender();break}const b=f;e.model.current=b(e.model.current,i),e.update.rerender()}r.resolve()}}function q(e){return e.startsWith("distributed")}class U extends Error{constructor(n,r=null){super(String(r));x(this,g);x(this,w);D(this,g,n),D(this,w,r)}get type(){return M(this,g)}get message(){return M(this,w)||""}}g=new WeakMap,w=new WeakMap;function W(e){return new Promise(t=>setTimeout(t,e))}function G(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function K(e){return e instanceof U}function y(e){return JSON.stringify(e)}const V=Object.freeze(Object.defineProperty({__proto__:null,hash:y,isEventError:K,pk:G,sleep:W},Symbol.toStringTag,{value:"Module"}));function h(e,t){const n=l.useRef(null),r=l.useRef(null);return l.useMemo(()=>{const o=y(t);if(r.current!==o){r.current=o;const i=e();return n.current=i,i}return n.current},t)}function z(e,t){const n=l.useRef(null);l.useEffect(()=>{const r=y(t);if(n.current!==r)return n.current=r,e()},t)}const A=l.createContext({appEmitter:new E});function P(){return l.useContext(A)}function X({children:e}){return()=>{const t=h(()=>({appEmitter:new E}),[]);return N.jsx(A.Provider,{value:t,children:e})}}function Y(e){return h(()=>({controller:{get model(){return e.model.current.stateful},queue:[],actions:{annotate(t,n){return F(t,n)},produce(t){return(n,r)=>J(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},actions:{dispatch([t,...n]){if(t==null)return Promise.reject();const r=Promise.withResolvers();return e.dispatchers.dispatch(t,n,r),r.promise}}}}),[])}function Z(e){return h(()=>{const t=e.options.using.actions(e.actions.controller);return Object.entries(t).forEach(([r,o])=>e.dispatchers.attach(r,o)),t},[])}function L(e){const t=P(),n=Q(e);return h(()=>{const r=new E;return{attach(o,i){const a=String(o);q(a)?t.appEmitter.on(a,n(o,i)):r.on(a,n(o,i))},dispatch(o,i,a){const f=String(o);q(f)?t.appEmitter.emit(f,a,i):r.emit(f,a,i)}}},[])}function ee(){const e=l.useRef(null);return h(()=>({customElement:e}),[])}function te(e){z(()=>{e.dispatchers.dispatch(p.Derive,[])},[e.options.using.props]),z(()=>(e.dispatchers.dispatch(p.Mount,[]),e.dispatchers.dispatch(p.Node,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(p.Unmount,[])),[])}function ne(e){const t=h(()=>e.options.using.model??{},[]);return l.useRef(new S(t,t))}function re(){return l.useRef(new Set)}function se(){const[e,t]=l.useReducer(n=>n+1,0);return h(()=>({hash:e,rerender:t}),[e])}function oe({options:e}){const t=se();re();const n=ee();P();const r=ne({options:e}),o=L({update:t,model:r}),i=Y({model:r,dispatchers:o});return Z({options:e,dispatchers:o,actions:i}),te({options:e,dispatchers:o,elements:n}),h(()=>l.createElement("x-chizu",{ref:n.customElement,style:{display:"contents"},children:e.children(i.view)}),[t.hash,y(e.using.props)])}function ie(e){return oe({options:e})}const ue=l.memo(ie,(e,t)=>y(e)===y(t));s.BroadcastProvider=X,s.EventError=U,s.Lifecycle=p,s.State=T,s.Tree=ue,s.useBroadcast=P,s.utils=V,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { Lifecycle, State } from './types/index.ts';
|
|
|
4
4
|
export * as utils from './utils/index.ts';
|
|
5
5
|
export { EventError } from './module/renderer/dispatchers/utils.ts';
|
|
6
6
|
export { default as Tree } from './module/index.tsx';
|
|
7
|
-
export {
|
|
7
|
+
export { BroadcastProvider, useBroadcast } from './broadcast/index.tsx';
|
|
8
8
|
export type * as Typed from './types/index.ts';
|
|
9
9
|
export type { Pk } from './types/index.ts';
|
|
10
10
|
export type { ViewDefinition as View };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseBroadcast } from '../../../broadcast/types.ts';
|
|
2
2
|
import { ControllerArgs } from '../../../controller/types.ts';
|
|
3
3
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
4
4
|
import { ViewArgs } from '../../../view/types.ts';
|
|
@@ -6,7 +6,7 @@ import { UseOptions } from '../../types.ts';
|
|
|
6
6
|
import { UseDispatchers } from '../dispatchers/types.ts';
|
|
7
7
|
import { UseModel } from '../model/types.ts';
|
|
8
8
|
export type Props<M extends ModuleDefinition> = {
|
|
9
|
-
|
|
9
|
+
broadcast: UseBroadcast;
|
|
10
10
|
options: UseOptions<M>;
|
|
11
11
|
model: UseModel;
|
|
12
12
|
dispatchers: UseDispatchers;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UseBroadcast } from '../../../broadcast/types.ts';
|
|
2
2
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
3
3
|
import { UseOptions } from '../../types.ts';
|
|
4
4
|
import { UseModel } from '../model/types.ts';
|
|
@@ -6,7 +6,7 @@ import { UseQueue } from '../queue/types.ts';
|
|
|
6
6
|
import { UseUpdate } from '../update/types.ts';
|
|
7
7
|
import { default as useDispatchers } from './index.ts';
|
|
8
8
|
export type Props<M extends ModuleDefinition> = {
|
|
9
|
-
|
|
9
|
+
broadcast: UseBroadcast;
|
|
10
10
|
options: UseOptions<M>;
|
|
11
11
|
update: UseUpdate;
|
|
12
12
|
model: UseModel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chizu",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/chizu.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -15,42 +15,42 @@
|
|
|
15
15
|
"eventemitter3": "^5.0.1",
|
|
16
16
|
"immer": "^10.1.1",
|
|
17
17
|
"lodash": "^4.17.21",
|
|
18
|
-
"react": "^19.
|
|
19
|
-
"react-router-dom": "^7.6.0",
|
|
18
|
+
"react": "^19.1.0",
|
|
20
19
|
"traverse": "0.6.8"
|
|
21
20
|
},
|
|
22
21
|
"files": [
|
|
23
22
|
"dist"
|
|
24
23
|
],
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"@babel/preset-env": "^7.
|
|
27
|
-
"@babel/preset-react": "^7.
|
|
28
|
-
"@babel/preset-typescript": "^7.
|
|
25
|
+
"@babel/preset-env": "^7.27.2",
|
|
26
|
+
"@babel/preset-react": "^7.27.1",
|
|
27
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
29
28
|
"@emotion/css": "^11.13.5",
|
|
30
|
-
"@jest/globals": "^
|
|
29
|
+
"@jest/globals": "^30.0.0-beta.3",
|
|
31
30
|
"@testing-library/dom": "^10.4.0",
|
|
32
31
|
"@testing-library/jest-dom": "^6.6.3",
|
|
33
|
-
"@testing-library/react": "^16.
|
|
32
|
+
"@testing-library/react": "^16.3.0",
|
|
34
33
|
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|
|
35
|
-
"@types/lodash": "^4.17.
|
|
36
|
-
"@types/react": "^19.
|
|
37
|
-
"@types/react-dom": "^19.
|
|
34
|
+
"@types/lodash": "^4.17.17",
|
|
35
|
+
"@types/react": "^19.1.6",
|
|
36
|
+
"@types/react-dom": "^19.1.5",
|
|
38
37
|
"@types/traverse": "^0.6.37",
|
|
39
38
|
"commit-and-tag-version": "^12.5.1",
|
|
40
39
|
"dayjs": "^1.11.13",
|
|
41
40
|
"dexie": "^4.0.11",
|
|
42
41
|
"get-port-cli": "^3.0.0",
|
|
43
42
|
"jest": "^29.7.0",
|
|
44
|
-
"jest-environment-jsdom": "^
|
|
45
|
-
"lucide-react": "^0.
|
|
43
|
+
"jest-environment-jsdom": "^30.0.0-beta.3",
|
|
44
|
+
"lucide-react": "^0.511.0",
|
|
46
45
|
"prettier": "^3.5.3",
|
|
47
|
-
"react-dom": "^19.
|
|
48
|
-
"react-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
46
|
+
"react-dom": "^19.1.0",
|
|
47
|
+
"react-router-dom": "^7.6.1",
|
|
48
|
+
"react-test-renderer": "^19.1.0",
|
|
49
|
+
"rollup-plugin-visualizer": "^6.0.1",
|
|
50
|
+
"ts-jest": "^29.3.4",
|
|
51
51
|
"ts-node": "^10.9.2",
|
|
52
52
|
"typescript": "^5.8.3",
|
|
53
|
-
"vite": "^6.
|
|
53
|
+
"vite": "^6.3.5",
|
|
54
54
|
"vite-plugin-dts": "^4.5.4",
|
|
55
55
|
"wait-on": "^8.0.3"
|
|
56
56
|
}
|
package/dist/context/index.d.ts
DELETED