chizu 0.2.25 → 0.2.27
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 +223 -220
- package/dist/chizu.umd.cjs +1 -1
- package/dist/controller/types.d.ts +2 -2
- package/dist/module/renderer/actions/types.d.ts +2 -0
- package/dist/module/renderer/dispatchers/types.d.ts +0 -2
- package/dist/module/renderer/props/index.d.ts +3 -0
- package/dist/module/renderer/props/types.d.ts +7 -0
- package/dist/types/index.d.ts +0 -7
- package/dist/view/types.d.ts +1 -0
- package/package.json +1 -1
- package/dist/module/renderer/queue/index.d.ts +0 -2
- package/dist/module/renderer/queue/types.d.ts +0 -2
package/dist/chizu.js
CHANGED
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var k = (t) => {
|
|
3
|
+
throw TypeError(t);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var x = (
|
|
8
|
-
import { jsx as
|
|
9
|
-
import * as
|
|
10
|
-
import { useRef as
|
|
11
|
-
import
|
|
12
|
-
import { Immer as
|
|
5
|
+
var G = (t, e, n) => e in t ? q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
6
|
+
var w = (t, e, n) => G(t, typeof e != "symbol" ? e + "" : e, n), N = (t, e, n) => e.has(t) || k("Cannot " + n);
|
|
7
|
+
var x = (t, e, n) => (N(t, e, "read from private field"), n ? n.call(t) : e.get(t)), R = (t, e, n) => e.has(t) ? k("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), S = (t, e, n, r) => (N(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
|
|
8
|
+
import { jsx as M } from "react/jsx-runtime";
|
|
9
|
+
import * as u from "react";
|
|
10
|
+
import { useRef as O } from "react";
|
|
11
|
+
import U from "eventemitter3";
|
|
12
|
+
import { Immer as K, enablePatches as Q } from "immer";
|
|
13
13
|
import m from "lodash/get";
|
|
14
|
-
import
|
|
14
|
+
import j from "traverse";
|
|
15
15
|
class H {
|
|
16
|
-
constructor(
|
|
17
|
-
this.value =
|
|
16
|
+
constructor(e) {
|
|
17
|
+
this.value = e;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
class V {
|
|
21
|
-
static Draft(
|
|
22
|
-
return new H(
|
|
21
|
+
static Draft(e) {
|
|
22
|
+
return new H(e);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
w(V, "Op", {
|
|
26
26
|
Add: 1,
|
|
27
27
|
Remove: 2,
|
|
28
28
|
Update: 4,
|
|
29
29
|
Move: 8,
|
|
30
30
|
Replace: 16
|
|
31
31
|
});
|
|
32
|
-
var h = /* @__PURE__ */ ((
|
|
33
|
-
function X(
|
|
34
|
-
return new Promise((
|
|
32
|
+
var h = /* @__PURE__ */ ((t) => (t.Mount = "lifecycle/mount", t.Node = "lifecycle/node", t.Derive = "lifecycle/derive", t.Error = "lifecycle/error", t.Unmount = "lifecycle/unmount", t))(h || {}), _ = /* @__PURE__ */ ((t) => (t[t.Default = 0] = "Default", t[t.Error = 1] = "Error", t))(_ || {});
|
|
33
|
+
function X(t) {
|
|
34
|
+
return new Promise((e) => setTimeout(e, t));
|
|
35
35
|
}
|
|
36
|
-
function Y(
|
|
37
|
-
return
|
|
36
|
+
function Y(t) {
|
|
37
|
+
return t ? !!(t && typeof t != "symbol") : Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
return JSON.stringify(
|
|
39
|
+
function b(t) {
|
|
40
|
+
return JSON.stringify(t);
|
|
41
41
|
}
|
|
42
|
-
const E = Symbol("meta"),
|
|
42
|
+
const E = Symbol("meta"), wt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
43
43
|
__proto__: null,
|
|
44
|
-
hash:
|
|
44
|
+
hash: b,
|
|
45
45
|
meta: E,
|
|
46
46
|
pk: Y,
|
|
47
47
|
sleep: X
|
|
48
48
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
49
|
-
function f(
|
|
50
|
-
const n =
|
|
51
|
-
return
|
|
52
|
-
const s =
|
|
49
|
+
function f(t, e) {
|
|
50
|
+
const n = u.useRef(null), r = u.useRef(null);
|
|
51
|
+
return u.useMemo(() => {
|
|
52
|
+
const s = b(e);
|
|
53
53
|
if (r.current !== s) {
|
|
54
54
|
r.current = s;
|
|
55
|
-
const o =
|
|
55
|
+
const o = t();
|
|
56
56
|
return n.current = o, o;
|
|
57
57
|
}
|
|
58
58
|
return n.current;
|
|
59
|
-
},
|
|
59
|
+
}, e);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
const n =
|
|
63
|
-
|
|
64
|
-
const r =
|
|
61
|
+
function D(t, e) {
|
|
62
|
+
const n = u.useRef(null);
|
|
63
|
+
u.useEffect(() => {
|
|
64
|
+
const r = b(e);
|
|
65
65
|
if (n.current !== r)
|
|
66
|
-
return n.current = r,
|
|
67
|
-
},
|
|
66
|
+
return n.current = r, t();
|
|
67
|
+
}, e);
|
|
68
68
|
}
|
|
69
|
-
const T =
|
|
70
|
-
instance: new
|
|
69
|
+
const T = u.createContext({
|
|
70
|
+
instance: new U()
|
|
71
71
|
});
|
|
72
72
|
function $() {
|
|
73
|
-
return
|
|
73
|
+
return u.useContext(T);
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
const
|
|
75
|
+
function xt({ children: t }) {
|
|
76
|
+
const e = f(
|
|
77
77
|
() => ({
|
|
78
|
-
instance: new
|
|
78
|
+
instance: new U()
|
|
79
79
|
}),
|
|
80
80
|
[]
|
|
81
81
|
);
|
|
82
|
-
return /* @__PURE__ */
|
|
82
|
+
return /* @__PURE__ */ M(T.Provider, { value: e, children: t });
|
|
83
83
|
}
|
|
84
84
|
const l = {
|
|
85
|
-
immer: new
|
|
85
|
+
immer: new K(),
|
|
86
86
|
annotations: Symbol("annotations")
|
|
87
87
|
};
|
|
88
|
-
|
|
88
|
+
Q();
|
|
89
89
|
l.immer.setAutoFreeze(!1);
|
|
90
|
-
class
|
|
91
|
-
constructor(
|
|
92
|
-
|
|
93
|
-
this.value =
|
|
90
|
+
class C {
|
|
91
|
+
constructor(e, n, r = null) {
|
|
92
|
+
w(this, "process");
|
|
93
|
+
this.value = e, this.operations = n, this.field = r, this.process = null;
|
|
94
94
|
}
|
|
95
|
-
attach(
|
|
96
|
-
return this.process =
|
|
95
|
+
attach(e) {
|
|
96
|
+
return this.process = e, this;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
function Z(
|
|
100
|
-
return new
|
|
99
|
+
function Z(t, e = []) {
|
|
100
|
+
return new C(t, e);
|
|
101
101
|
}
|
|
102
|
-
class
|
|
103
|
-
constructor(
|
|
104
|
-
this.stateless =
|
|
102
|
+
class A {
|
|
103
|
+
constructor(e, n = e) {
|
|
104
|
+
this.stateless = e, this.stateful = n;
|
|
105
105
|
}
|
|
106
106
|
get validatable() {
|
|
107
107
|
return z(this.stateful);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function z(
|
|
111
|
-
return new Proxy(
|
|
110
|
+
function z(t, e = []) {
|
|
111
|
+
return new Proxy(t, {
|
|
112
112
|
get(n, r) {
|
|
113
113
|
switch (r) {
|
|
114
114
|
case "is":
|
|
115
115
|
return (s) => {
|
|
116
|
-
const o = P(
|
|
116
|
+
const o = P(t, e);
|
|
117
117
|
if (!o) return !1;
|
|
118
|
-
const
|
|
118
|
+
const c = new Set(
|
|
119
119
|
o.flatMap((d) => d.operations)
|
|
120
120
|
);
|
|
121
|
-
return !!(Array.from(
|
|
121
|
+
return !!(Array.from(c).reduce(
|
|
122
122
|
(d, a) => d | (a ?? 0),
|
|
123
123
|
0
|
|
124
124
|
) & s);
|
|
125
125
|
};
|
|
126
126
|
case "pending":
|
|
127
|
-
return () => !!P(
|
|
127
|
+
return () => !!P(t, e);
|
|
128
128
|
case "draft":
|
|
129
129
|
return () => {
|
|
130
|
-
const s = P(
|
|
131
|
-
if (!s) return m(
|
|
132
|
-
const o = s.flatMap((
|
|
133
|
-
return o ? o.value : m(
|
|
130
|
+
const s = P(t, e);
|
|
131
|
+
if (!s) return m(t, e);
|
|
132
|
+
const o = s.flatMap((c) => c.operations).find((c) => c instanceof H);
|
|
133
|
+
return o ? o.value : m(t, e);
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
return z(
|
|
136
|
+
return z(t, [...e, String(r)]);
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
-
function P(
|
|
141
|
-
const r = typeof m(
|
|
140
|
+
function P(t, e) {
|
|
141
|
+
const r = typeof m(t, e) == "object" ? e : e.slice(0, -1), s = r.length === 0 ? t : m(t, r), o = (s == null ? void 0 : s[l.annotations]) ?? [];
|
|
142
142
|
return o.length > 0 ? o : null;
|
|
143
143
|
}
|
|
144
|
-
function
|
|
145
|
-
function r(
|
|
146
|
-
return
|
|
144
|
+
function I(t, e, n) {
|
|
145
|
+
function r(c) {
|
|
146
|
+
return j(c).forEach(function() {
|
|
147
147
|
if (this.key === l.annotations) {
|
|
148
148
|
this.block();
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
|
-
this.node instanceof
|
|
151
|
+
this.node instanceof C && this.update(this.node.value);
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
function s(
|
|
155
|
-
return
|
|
154
|
+
function s(c) {
|
|
155
|
+
return j(c).forEach(function() {
|
|
156
156
|
if (this.key === l.annotations) {
|
|
157
157
|
this.block();
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
|
-
if (this.node instanceof
|
|
160
|
+
if (this.node instanceof C) {
|
|
161
161
|
const i = typeof this.node.value == "object", d = [
|
|
162
162
|
...i ? this.path : this.path.slice(0, -1),
|
|
163
163
|
l.annotations
|
|
164
|
-
], a = m(
|
|
164
|
+
], a = m(t.stateful, d) ?? [], g = this.node.attach(e);
|
|
165
165
|
i ? this.update(
|
|
166
166
|
{
|
|
167
167
|
...this.node.value,
|
|
168
|
-
[l.annotations]: [
|
|
168
|
+
[l.annotations]: [g, ...a]
|
|
169
169
|
},
|
|
170
170
|
!0
|
|
171
|
-
) : (this.parent && (this.parent.node[l.annotations] = [
|
|
171
|
+
) : (this.parent && (this.parent.node[l.annotations] = [g, ...a]), this.update(this.node.value, !0));
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
}
|
|
175
|
-
const o = (
|
|
176
|
-
return new
|
|
177
|
-
r(l.immer.produce(
|
|
178
|
-
s(l.immer.produce(
|
|
175
|
+
const o = (c) => n(c, c[E]);
|
|
176
|
+
return new A(
|
|
177
|
+
r(l.immer.produce(t.stateless, o)),
|
|
178
|
+
s(l.immer.produce(t.stateful, o))
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
|
-
function
|
|
182
|
-
const n =
|
|
181
|
+
function y(t, e) {
|
|
182
|
+
const n = j(t.stateful).forEach(function() {
|
|
183
183
|
if (this.key === l.annotations) {
|
|
184
184
|
this.block();
|
|
185
185
|
return;
|
|
@@ -190,42 +190,44 @@ function b(e, t) {
|
|
|
190
190
|
{
|
|
191
191
|
...this.node,
|
|
192
192
|
[l.annotations]: r.filter(
|
|
193
|
-
(s) => s.process !==
|
|
193
|
+
(s) => s.process !== e
|
|
194
194
|
)
|
|
195
195
|
},
|
|
196
196
|
!0
|
|
197
197
|
);
|
|
198
198
|
}
|
|
199
199
|
});
|
|
200
|
-
return new
|
|
200
|
+
return new A(t.stateless, n);
|
|
201
201
|
}
|
|
202
|
-
function L(
|
|
202
|
+
function L(t) {
|
|
203
203
|
return f(
|
|
204
204
|
() => ({
|
|
205
205
|
controller: {
|
|
206
206
|
get model() {
|
|
207
|
-
return
|
|
207
|
+
return t.model.current.stateless;
|
|
208
|
+
},
|
|
209
|
+
get props() {
|
|
210
|
+
return t.props.current;
|
|
208
211
|
},
|
|
209
|
-
queue: [],
|
|
210
212
|
actions: {
|
|
211
|
-
annotate(
|
|
212
|
-
return Z(
|
|
213
|
+
annotate(e, n) {
|
|
214
|
+
return Z(e, n);
|
|
213
215
|
},
|
|
214
|
-
produce(
|
|
215
|
-
return (n, r) =>
|
|
216
|
+
produce(e) {
|
|
217
|
+
return (n, r) => I(n, r, e);
|
|
216
218
|
},
|
|
217
|
-
dispatch([
|
|
218
|
-
if (
|
|
219
|
+
dispatch([e, ...n]) {
|
|
220
|
+
if (e == null) return Promise.reject();
|
|
219
221
|
const r = Promise.withResolvers();
|
|
220
|
-
return
|
|
222
|
+
return t.dispatchers.dispatch(e, n, r), r.promise;
|
|
221
223
|
},
|
|
222
|
-
context(
|
|
223
|
-
const n = Object.keys(
|
|
224
|
-
return
|
|
224
|
+
context(e) {
|
|
225
|
+
const n = Object.keys(e);
|
|
226
|
+
return t.context.use.current = e, t.context.update(), n.reduce(
|
|
225
227
|
(r, s) => ({
|
|
226
228
|
...r,
|
|
227
229
|
get [s]() {
|
|
228
|
-
return
|
|
230
|
+
return t.context.values.current[s];
|
|
229
231
|
}
|
|
230
232
|
}),
|
|
231
233
|
{}
|
|
@@ -235,21 +237,24 @@ function L(e) {
|
|
|
235
237
|
},
|
|
236
238
|
view: {
|
|
237
239
|
get model() {
|
|
238
|
-
return
|
|
240
|
+
return t.model.current.stateless;
|
|
241
|
+
},
|
|
242
|
+
get props() {
|
|
243
|
+
return t.props.current;
|
|
239
244
|
},
|
|
240
245
|
get validate() {
|
|
241
|
-
return
|
|
246
|
+
return t.model.current.validatable;
|
|
242
247
|
},
|
|
243
248
|
boundary: {
|
|
244
|
-
is(
|
|
245
|
-
return
|
|
249
|
+
is(e) {
|
|
250
|
+
return t.model.current.stateless[E].boundary === e;
|
|
246
251
|
}
|
|
247
252
|
},
|
|
248
253
|
actions: {
|
|
249
|
-
dispatch([
|
|
250
|
-
if (
|
|
254
|
+
dispatch([e, ...n]) {
|
|
255
|
+
if (e == null) return Promise.reject();
|
|
251
256
|
const r = Promise.withResolvers();
|
|
252
|
-
return
|
|
257
|
+
return t.dispatchers.dispatch(e, n, r), r.promise;
|
|
253
258
|
}
|
|
254
259
|
}
|
|
255
260
|
}
|
|
@@ -257,191 +262,189 @@ function L(e) {
|
|
|
257
262
|
[]
|
|
258
263
|
);
|
|
259
264
|
}
|
|
260
|
-
function
|
|
261
|
-
const
|
|
262
|
-
return
|
|
263
|
-
if (
|
|
264
|
-
return Object.entries(
|
|
265
|
+
function tt(t) {
|
|
266
|
+
const e = O(null);
|
|
267
|
+
return e.current == null && (e.current = t.options.using.actions(t.actions.controller)), f(() => {
|
|
268
|
+
if (e.current)
|
|
269
|
+
return Object.entries(e.current).forEach(([r, s]) => t.dispatchers.attach(r, s)), e.current;
|
|
265
270
|
}, []);
|
|
266
271
|
}
|
|
267
|
-
function
|
|
268
|
-
return
|
|
272
|
+
function B(t) {
|
|
273
|
+
return t.startsWith("distributed");
|
|
269
274
|
}
|
|
270
|
-
function
|
|
271
|
-
return
|
|
275
|
+
function Rt(t) {
|
|
276
|
+
return t instanceof J;
|
|
272
277
|
}
|
|
273
|
-
function
|
|
274
|
-
return
|
|
278
|
+
function F(t) {
|
|
279
|
+
return t instanceof J || t instanceof Error ? t : new Error("Unknown error", { cause: t });
|
|
275
280
|
}
|
|
276
|
-
var
|
|
277
|
-
class
|
|
281
|
+
var p, v;
|
|
282
|
+
class J extends Error {
|
|
278
283
|
constructor(n, r = null) {
|
|
279
284
|
super(String(r));
|
|
280
|
-
R(this, v);
|
|
281
285
|
R(this, p);
|
|
282
|
-
|
|
286
|
+
R(this, v);
|
|
287
|
+
S(this, p, n), S(this, v, r);
|
|
283
288
|
}
|
|
284
289
|
get type() {
|
|
285
|
-
return x(this,
|
|
290
|
+
return x(this, p);
|
|
286
291
|
}
|
|
287
292
|
get message() {
|
|
288
|
-
return x(this,
|
|
293
|
+
return x(this, v) || "";
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
|
-
|
|
292
|
-
function
|
|
293
|
-
children:
|
|
296
|
+
p = new WeakMap(), v = new WeakMap();
|
|
297
|
+
function et({
|
|
298
|
+
children: t
|
|
294
299
|
}) {
|
|
295
|
-
return
|
|
300
|
+
return t();
|
|
296
301
|
}
|
|
297
|
-
function
|
|
298
|
-
return (
|
|
302
|
+
function nt(t) {
|
|
303
|
+
return (e, n) => async (r = Promise.withResolvers(), s) => {
|
|
299
304
|
if (typeof n != "function") return void r.resolve();
|
|
300
|
-
const o = Symbol("process"),
|
|
305
|
+
const o = Symbol("process"), c = n(...s);
|
|
301
306
|
try {
|
|
302
|
-
if (
|
|
303
|
-
if (typeof
|
|
304
|
-
const i =
|
|
305
|
-
return
|
|
307
|
+
if (c == null) return void r.resolve();
|
|
308
|
+
if (typeof c == "function") {
|
|
309
|
+
const i = c(t.model.current, o);
|
|
310
|
+
return t.model.current = y(i, o), t.update.rerender(), void r.resolve();
|
|
306
311
|
}
|
|
307
312
|
for (; ; ) {
|
|
308
|
-
if (
|
|
309
|
-
const a = await
|
|
313
|
+
if (c instanceof Promise) {
|
|
314
|
+
const a = await c;
|
|
310
315
|
if (a == null) return void r.resolve();
|
|
311
|
-
const
|
|
312
|
-
return
|
|
316
|
+
const g = a(t.model.current, o);
|
|
317
|
+
return t.model.current = y(g, o), t.update.rerender(), void r.resolve();
|
|
313
318
|
}
|
|
314
|
-
const { value: i, done: d } = await
|
|
319
|
+
const { value: i, done: d } = await c.next();
|
|
315
320
|
if (d) {
|
|
316
|
-
const a = i(
|
|
317
|
-
return
|
|
321
|
+
const a = i(t.model.current, o);
|
|
322
|
+
return t.model.current = y(a, o), t.update.rerender(), void r.resolve();
|
|
318
323
|
}
|
|
319
|
-
|
|
324
|
+
t.model.current = i(t.model.current, o), t.update.rerender();
|
|
320
325
|
}
|
|
321
326
|
} catch (i) {
|
|
322
|
-
|
|
327
|
+
y(t.model.current, o), t.update.rerender(), t.unicast.emit(h.Error, r, [F(i)]);
|
|
323
328
|
}
|
|
324
329
|
};
|
|
325
330
|
}
|
|
326
|
-
function
|
|
327
|
-
const
|
|
331
|
+
function rt(t) {
|
|
332
|
+
const e = $(), n = f(() => new U(), []), r = nt({ ...t, unicast: n });
|
|
328
333
|
return f(() => ({
|
|
329
334
|
attach(s, o) {
|
|
330
|
-
const
|
|
331
|
-
|
|
335
|
+
const c = String(s);
|
|
336
|
+
B(c) ? e.instance.on(c, r(s, o)) : n.on(c, r(s, o));
|
|
332
337
|
},
|
|
333
|
-
dispatch(s, o,
|
|
338
|
+
dispatch(s, o, c) {
|
|
334
339
|
const i = String(s);
|
|
335
|
-
|
|
340
|
+
B(i) ? e.instance.emit(i, c, o) : n.emit(i, c, o);
|
|
336
341
|
}
|
|
337
342
|
}), []);
|
|
338
343
|
}
|
|
339
|
-
function
|
|
340
|
-
const
|
|
341
|
-
return f(() => ({ customElement:
|
|
344
|
+
function st() {
|
|
345
|
+
const t = u.useRef(null);
|
|
346
|
+
return f(() => ({ customElement: t }), []);
|
|
342
347
|
}
|
|
343
|
-
function
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}, [
|
|
347
|
-
|
|
348
|
-
]), () =>
|
|
348
|
+
function ot(t) {
|
|
349
|
+
D(() => {
|
|
350
|
+
t.dispatchers.dispatch(h.Derive, []);
|
|
351
|
+
}, [t.options.using.props]), D(() => (t.dispatchers.dispatch(h.Mount, []), t.dispatchers.dispatch(h.Node, [
|
|
352
|
+
t.elements.customElement.current
|
|
353
|
+
]), () => t.dispatchers.dispatch(h.Unmount, [])), []);
|
|
349
354
|
}
|
|
350
|
-
function
|
|
351
|
-
const
|
|
352
|
-
return
|
|
355
|
+
function ct(t) {
|
|
356
|
+
const e = f(() => ({ ...t.options.using.model ?? {}, [E]: { boundary: _.Default } }), []);
|
|
357
|
+
return u.useRef(new A(e, e));
|
|
353
358
|
}
|
|
354
|
-
function
|
|
355
|
-
|
|
359
|
+
function ut() {
|
|
360
|
+
const [t, e] = u.useReducer((n) => n + 1, 0);
|
|
361
|
+
return f(() => ({ hash: t, rerender: e }), [t]);
|
|
356
362
|
}
|
|
357
|
-
|
|
358
|
-
const [e, t] = c.useReducer((n) => n + 1, 0);
|
|
359
|
-
return f(() => ({ hash: e, rerender: t }), [e]);
|
|
360
|
-
}
|
|
361
|
-
const ae = {
|
|
363
|
+
const it = {
|
|
362
364
|
elementName: "x-chizu"
|
|
363
|
-
},
|
|
365
|
+
}, W = u.createContext(
|
|
364
366
|
null
|
|
365
367
|
);
|
|
366
|
-
function
|
|
367
|
-
const
|
|
368
|
-
if (!
|
|
368
|
+
function St() {
|
|
369
|
+
const t = u.useContext(W);
|
|
370
|
+
if (!t)
|
|
369
371
|
throw new Error("useScoped is not being used within a scoped module.");
|
|
370
|
-
return
|
|
372
|
+
return t;
|
|
371
373
|
}
|
|
372
|
-
class
|
|
373
|
-
constructor(
|
|
374
|
-
super(
|
|
374
|
+
class at extends u.Component {
|
|
375
|
+
constructor(e) {
|
|
376
|
+
super(e), this.state = { error: null };
|
|
375
377
|
}
|
|
376
|
-
componentDidCatch(
|
|
377
|
-
const n = Symbol("process"), r =
|
|
378
|
-
o.boundary =
|
|
378
|
+
componentDidCatch(e) {
|
|
379
|
+
const n = Symbol("process"), r = I(this.props.model.current, n, (s, o) => {
|
|
380
|
+
o.boundary = _.Error;
|
|
379
381
|
});
|
|
380
|
-
this.props.model.current = r, this.props.update.rerender(), this.props.dispatchers.dispatch(h.Error, [
|
|
382
|
+
this.props.model.current = r, this.props.update.rerender(), this.props.dispatchers.dispatch(h.Error, [F(e)]);
|
|
381
383
|
}
|
|
382
384
|
render() {
|
|
383
|
-
return /* @__PURE__ */
|
|
385
|
+
return /* @__PURE__ */ M(et, { children: this.props.children });
|
|
384
386
|
}
|
|
385
387
|
}
|
|
386
|
-
function
|
|
387
|
-
const
|
|
388
|
+
function lt() {
|
|
389
|
+
const t = u.useRef({}), e = u.useRef({});
|
|
388
390
|
function n() {
|
|
389
|
-
|
|
390
|
-
Object.entries(
|
|
391
|
+
e.current = Object.fromEntries(
|
|
392
|
+
Object.entries(t.current).map(([r, s]) => [r, u.use(s)])
|
|
391
393
|
);
|
|
392
394
|
}
|
|
393
|
-
return n(), f(() => ({ use:
|
|
395
|
+
return n(), f(() => ({ use: t, values: e, update: n }), []);
|
|
396
|
+
}
|
|
397
|
+
function dt() {
|
|
398
|
+
return O(0);
|
|
394
399
|
}
|
|
395
|
-
function
|
|
396
|
-
|
|
400
|
+
function ft(t) {
|
|
401
|
+
const e = O(t.options.using.props);
|
|
402
|
+
return D(() => {
|
|
403
|
+
e.current = t.options.using.props;
|
|
404
|
+
}, [t.options.using.props]), e;
|
|
397
405
|
}
|
|
398
|
-
function
|
|
399
|
-
options:
|
|
406
|
+
function ht({
|
|
407
|
+
options: t
|
|
400
408
|
}) {
|
|
401
|
-
const
|
|
402
|
-
broadcast: o,
|
|
403
|
-
options: e,
|
|
404
|
-
update: t,
|
|
405
|
-
model: i,
|
|
406
|
-
queue: n
|
|
407
|
-
}), a = L({
|
|
409
|
+
const e = ut(), n = dt(), r = st(), s = $(), o = lt(), c = ft({ options: t }), i = ct({ options: t }), d = rt({ broadcast: s, options: t, update: e, model: i }), a = L({
|
|
408
410
|
model: i,
|
|
409
411
|
dispatchers: d,
|
|
410
|
-
context:
|
|
412
|
+
context: o,
|
|
413
|
+
props: c
|
|
411
414
|
});
|
|
412
|
-
return
|
|
415
|
+
return tt({ options: t, dispatchers: d, actions: a }), ot({ options: t, dispatchers: d, elements: r }), f(() => u.createElement(at, {
|
|
413
416
|
model: i,
|
|
414
417
|
dispatchers: d,
|
|
415
|
-
update:
|
|
418
|
+
update: e,
|
|
416
419
|
module: a.view,
|
|
417
420
|
children() {
|
|
418
|
-
return
|
|
421
|
+
return u.createElement(W.Provider, {
|
|
419
422
|
value: a.view,
|
|
420
423
|
// eslint-disable-next-line react/no-children-prop
|
|
421
|
-
children:
|
|
422
|
-
ref:
|
|
424
|
+
children: u.createElement(it.elementName, {
|
|
425
|
+
ref: r.customElement,
|
|
423
426
|
style: { display: "contents" },
|
|
424
|
-
children:
|
|
427
|
+
children: t.children(a.view)
|
|
425
428
|
})
|
|
426
429
|
});
|
|
427
430
|
}
|
|
428
431
|
}), [
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
+
e.hash,
|
|
433
|
+
b(t.using.props),
|
|
434
|
+
t.passive ? n.current++ : 0
|
|
432
435
|
]);
|
|
433
436
|
}
|
|
434
|
-
function
|
|
435
|
-
return /* @__PURE__ */
|
|
437
|
+
function Pt(t) {
|
|
438
|
+
return /* @__PURE__ */ M(ht, { options: t });
|
|
436
439
|
}
|
|
437
440
|
export {
|
|
438
|
-
|
|
439
|
-
|
|
441
|
+
_ as Boundary,
|
|
442
|
+
xt as Broadcaster,
|
|
440
443
|
h as Lifecycle,
|
|
441
|
-
|
|
444
|
+
Pt as Scope,
|
|
442
445
|
V as State,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
446
|
+
J as TypedError,
|
|
447
|
+
Rt as isTypedError,
|
|
448
|
+
St as useScoped,
|
|
449
|
+
wt as utils
|
|
447
450
|
};
|
package/dist/chizu.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react"),require("eventemitter3"),require("immer"),require("lodash/get"),require("traverse")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","eventemitter3","immer","lodash/get","traverse"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.Chizu={},s.jsxRuntime,s.React,s.EventEmitter3,s.Immer,s.get,s.Traverse))})(this,function(s,c,
|
|
1
|
+
(function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react"),require("eventemitter3"),require("immer"),require("lodash/get"),require("traverse")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","eventemitter3","immer","lodash/get","traverse"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.Chizu={},s.jsxRuntime,s.React,s.EventEmitter3,s.Immer,s.get,s.Traverse))})(this,function(s,c,a,y,A,b,O){"use strict";var be=Object.defineProperty;var G=s=>{throw TypeError(s)};var ge=(s,c,a)=>c in s?be(s,c,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[c]=a;var _=(s,c,a)=>ge(s,typeof c!="symbol"?c+"":c,a),K=(s,c,a)=>c.has(s)||G("Cannot "+a);var U=(s,c,a)=>(K(s,c,"read from private field"),a?a.call(s):c.get(s)),k=(s,c,a)=>c.has(s)?G("Cannot add the same private member more than once"):c instanceof WeakSet?c.add(s):c.set(s,a),q=(s,c,a,y)=>(K(s,c,"write to private field"),y?y.call(s,a):c.set(s,a),a);var g,w;function Q(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const l=Q(a);class B{constructor(t){this.value=t}}class N{static Draft(t){return new B(t)}}_(N,"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="lifecycle/error",e.Unmount="lifecycle/unmount",e))(p||{}),E=(e=>(e[e.Default=0]="Default",e[e.Error=1]="Error",e))(E||{});function V(e){return new Promise(t=>setTimeout(t,e))}function X(e){return e?!!(e&&typeof e!="symbol"):Symbol(`pk.${Date.now()}.${crypto.randomUUID()}`)}function S(e){return JSON.stringify(e)}const j=Symbol("meta"),Y=Object.freeze(Object.defineProperty({__proto__:null,hash:S,meta:j,pk:X,sleep:V},Symbol.toStringTag,{value:"Module"}));function v(e,t){const r=l.useRef(null),n=l.useRef(null);return l.useMemo(()=>{const o=S(t);if(n.current!==o){n.current=o;const u=e();return r.current=u,u}return r.current},t)}function R(e,t){const r=l.useRef(null);l.useEffect(()=>{const n=S(t);if(r.current!==n)return r.current=n,e()},t)}const z=l.createContext({instance:new y});function H(){return l.useContext(z)}function Z({children:e}){const t=v(()=>({instance:new y}),[]);return c.jsx(z.Provider,{value:t,children:e})}const h={immer:new A.Immer,annotations:Symbol("annotations")};A.enablePatches(),h.immer.setAutoFreeze(!1);class D{constructor(t,r,n=null){_(this,"process");this.value=t,this.operations=r,this.field=n,this.process=null}attach(t){return this.process=t,this}}function L(e,t=[]){return new D(e,t)}class C{constructor(t,r=t){this.stateless=t,this.stateful=r}get validatable(){return $(this.stateful)}}function $(e,t=[]){return new Proxy(e,{get(r,n){switch(n){case"is":return o=>{const u=M(e,t);if(!u)return!1;const i=new Set(u.flatMap(m=>m.operations));return!!(Array.from(i).reduce((m,f)=>m|(f??0),0)&o)};case"pending":return()=>!!M(e,t);case"draft":return()=>{const o=M(e,t);if(!o)return b(e,t);const u=o.flatMap(i=>i.operations).find(i=>i instanceof B);return u?u.value:b(e,t)}}return $(e,[...t,String(n)])}})}function M(e,t){const n=typeof b(e,t)=="object"?t:t.slice(0,-1),o=n.length===0?e:b(e,n),u=(o==null?void 0:o[h.annotations])??[];return u.length>0?u:null}function I(e,t,r){function n(i){return O(i).forEach(function(){if(this.key===h.annotations){this.block();return}this.node instanceof D&&this.update(this.node.value)})}function o(i){return O(i).forEach(function(){if(this.key===h.annotations){this.block();return}if(this.node instanceof D){const d=typeof this.node.value=="object",m=[...d?this.path:this.path.slice(0,-1),h.annotations],f=b(e.stateful,m)??[],P=this.node.attach(t);d?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))}})}const u=i=>r(i,i[j]);return new C(n(h.immer.produce(e.stateless,u)),o(h.immer.produce(e.stateful,u)))}function x(e,t){const r=O(e.stateful).forEach(function(){if(this.key===h.annotations){this.block();return}if(this.node&&this.node[h.annotations]){const n=this.node[h.annotations];this.update({...this.node,[h.annotations]:n.filter(o=>o.process!==t)},!0)}});return new C(e.stateless,r)}function ee(e){return v(()=>({controller:{get model(){return e.model.current.stateless},get props(){return e.props.current},actions:{annotate(t,r){return L(t,r)},produce(t){return(r,n)=>I(r,n,t)},dispatch([t,...r]){if(t==null)return Promise.reject();const n=Promise.withResolvers();return e.dispatchers.dispatch(t,r,n),n.promise},context(t){const r=Object.keys(t);return e.context.use.current=t,e.context.update(),r.reduce((n,o)=>({...n,get[o](){return e.context.values.current[o]}}),{})}}},view:{get model(){return e.model.current.stateless},get props(){return e.props.current},get validate(){return e.model.current.validatable},boundary:{is(t){return e.model.current.stateless[j].boundary===t}},actions:{dispatch([t,...r]){if(t==null)return Promise.reject();const n=Promise.withResolvers();return e.dispatchers.dispatch(t,r,n),n.promise}}}}),[])}function te(e){const t=a.useRef(null);return t.current==null&&(t.current=e.options.using.actions(e.actions.controller)),v(()=>{if(t.current)return Object.entries(t.current).forEach(([n,o])=>e.dispatchers.attach(n,o)),t.current},[])}function F(e){return e.startsWith("distributed")}function ne(e){return e instanceof T}function J(e){return e instanceof T||e instanceof Error?e:new Error("Unknown error",{cause:e})}class T extends Error{constructor(r,n=null){super(String(n));k(this,g);k(this,w);q(this,g,r),q(this,w,n)}get type(){return U(this,g)}get message(){return U(this,w)||""}}g=new WeakMap,w=new WeakMap;function re({children:e}){return e()}function se(e){return(t,r)=>async(n=Promise.withResolvers(),o)=>{if(typeof r!="function")return void n.resolve();const u=Symbol("process"),i=r(...o);try{if(i==null)return void n.resolve();if(typeof i=="function"){const d=i(e.model.current,u);return e.model.current=x(d,u),e.update.rerender(),void n.resolve()}for(;;){if(i instanceof Promise){const f=await i;if(f==null)return void n.resolve();const P=f(e.model.current,u);return e.model.current=x(P,u),e.update.rerender(),void n.resolve()}const{value:d,done:m}=await i.next();if(m){const f=d(e.model.current,u);return e.model.current=x(f,u),e.update.rerender(),void n.resolve()}e.model.current=d(e.model.current,u),e.update.rerender()}}catch(d){x(e.model.current,u),e.update.rerender(),e.unicast.emit(p.Error,n,[J(d)])}}}function oe(e){const t=H(),r=v(()=>new y,[]),n=se({...e,unicast:r});return v(()=>({attach(o,u){const i=String(o);F(i)?t.instance.on(i,n(o,u)):r.on(i,n(o,u))},dispatch(o,u,i){const d=String(o);F(d)?t.instance.emit(d,i,u):r.emit(d,i,u)}}),[])}function ue(){const e=l.useRef(null);return v(()=>({customElement:e}),[])}function ce(e){R(()=>{e.dispatchers.dispatch(p.Derive,[])},[e.options.using.props]),R(()=>(e.dispatchers.dispatch(p.Mount,[]),e.dispatchers.dispatch(p.Node,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(p.Unmount,[])),[])}function ie(e){const t=v(()=>({...e.options.using.model??{},[j]:{boundary:E.Default}}),[]);return l.useRef(new C(t,t))}function ae(){const[e,t]=l.useReducer(r=>r+1,0);return v(()=>({hash:e,rerender:t}),[e])}const le={elementName:"x-chizu"},W=l.createContext(null);function de(){const e=l.useContext(W);if(!e)throw new Error("useScoped is not being used within a scoped module.");return e}class fe extends l.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){const r=Symbol("process"),n=I(this.props.model.current,r,(o,u)=>{u.boundary=E.Error});this.props.model.current=n,this.props.update.rerender(),this.props.dispatchers.dispatch(p.Error,[J(t)])}render(){return c.jsx(re,{children:this.props.children})}}function he(){const e=l.useRef({}),t=l.useRef({});function r(){t.current=Object.fromEntries(Object.entries(e.current).map(([n,o])=>[n,l.use(o)]))}return r(),v(()=>({use:e,values:t,update:r}),[])}function me(){return a.useRef(0)}function ve(e){const t=a.useRef(e.options.using.props);return R(()=>{t.current=e.options.using.props},[e.options.using.props]),t}function pe({options:e}){const t=ae(),r=me(),n=ue(),o=H(),u=he(),i=ve({options:e}),d=ie({options:e}),m=oe({broadcast:o,options:e,update:t,model:d}),f=ee({model:d,dispatchers:m,context:u,props:i});return te({options:e,dispatchers:m,actions:f}),ce({options:e,dispatchers:m,elements:n}),v(()=>l.createElement(fe,{model:d,dispatchers:m,update:t,module:f.view,children(){return l.createElement(W.Provider,{value:f.view,children:l.createElement(le.elementName,{ref:n.customElement,style:{display:"contents"},children:e.children(f.view)})})}}),[t.hash,S(e.using.props),e.passive?r.current++:0])}function ye(e){return c.jsx(pe,{options:e})}s.Boundary=E,s.Broadcaster=Z,s.Lifecycle=p,s.Scope=ye,s.State=N,s.TypedError=T,s.isTypedError=ne,s.useScoped=de,s.utils=Y,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedError } from '../errors/utils.ts';
|
|
2
2
|
import { Models } from '../module/renderer/model/utils.ts';
|
|
3
3
|
import { Head } from '../module/renderer/types.ts';
|
|
4
|
-
import { Actions, Context, ContextTypes, Draft, Lifecycle, Meta, ModuleDefinition, Op
|
|
4
|
+
import { Actions, Context, ContextTypes, Draft, Lifecycle, Meta, ModuleDefinition, Op } from '../types/index.ts';
|
|
5
5
|
export type ControllerActions<M extends ModuleDefinition> = {
|
|
6
6
|
annotate<T>(value: T, operations?: (Op | Draft<T>)[]): T;
|
|
7
7
|
produce(ƒ: (model: M["Model"], meta: Meta) => void): (models: Models<M["Model"]>, process: symbol) => Models<M["Model"]>;
|
|
@@ -10,7 +10,7 @@ export type ControllerActions<M extends ModuleDefinition> = {
|
|
|
10
10
|
};
|
|
11
11
|
export type ControllerArgs<M extends ModuleDefinition> = Readonly<{
|
|
12
12
|
model: Readonly<M["Model"]>;
|
|
13
|
-
|
|
13
|
+
props: Readonly<M["Props"]>;
|
|
14
14
|
actions: Readonly<ControllerActions<M>>;
|
|
15
15
|
}>;
|
|
16
16
|
export type ActionEvent<M extends ModuleDefinition> = (...args: M["Actions"][number]) => ActionGenerator<M>;
|
|
@@ -6,12 +6,14 @@ import { ViewArgs } from '../../../view/types.ts';
|
|
|
6
6
|
import { UseOptions } from '../../types.ts';
|
|
7
7
|
import { UseDispatchers } from '../dispatchers/types.ts';
|
|
8
8
|
import { UseModel } from '../model/types.ts';
|
|
9
|
+
import { UseProps } from '../props/types.ts';
|
|
9
10
|
export type Props<M extends ModuleDefinition> = {
|
|
10
11
|
broadcast: UseBroadcast;
|
|
11
12
|
options: UseOptions<M>;
|
|
12
13
|
model: UseModel;
|
|
13
14
|
dispatchers: UseDispatchers;
|
|
14
15
|
context: UseContext;
|
|
16
|
+
props: UseProps;
|
|
15
17
|
};
|
|
16
18
|
export type UseActions<M extends ModuleDefinition> = {
|
|
17
19
|
controller: ControllerArgs<M>;
|
|
@@ -3,7 +3,6 @@ import { UseBroadcast } from '../../../broadcast/types.ts';
|
|
|
3
3
|
import { ModuleDefinition } from '../../../types/index.ts';
|
|
4
4
|
import { UseOptions } from '../../types.ts';
|
|
5
5
|
import { UseModel } from '../model/types.ts';
|
|
6
|
-
import { UseQueue } from '../queue/types.ts';
|
|
7
6
|
import { UseUpdate } from '../update/types.ts';
|
|
8
7
|
import { default as useDispatchers } from './index.ts';
|
|
9
8
|
export type Props<M extends ModuleDefinition> = {
|
|
@@ -11,7 +10,6 @@ export type Props<M extends ModuleDefinition> = {
|
|
|
11
10
|
options: UseOptions<M>;
|
|
12
11
|
update: UseUpdate;
|
|
13
12
|
model: UseModel;
|
|
14
|
-
queue: UseQueue;
|
|
15
13
|
};
|
|
16
14
|
export type UseDispatchers = ReturnType<typeof useDispatchers>;
|
|
17
15
|
export type UseDispatchHandlerProps<M extends ModuleDefinition> = Props<M> & {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ModuleDefinition } from '../../../types/index.ts';
|
|
2
|
+
import { UseOptions } from '../../types.ts';
|
|
3
|
+
import { default as useProps } from './index.ts';
|
|
4
|
+
export type Props<M extends ModuleDefinition> = {
|
|
5
|
+
options: UseOptions<M>;
|
|
6
|
+
};
|
|
7
|
+
export type UseProps = ReturnType<typeof useProps>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Head } from '../module/renderer/types.ts';
|
|
2
1
|
export declare enum Transmit {
|
|
3
2
|
Unicast = "unicast",
|
|
4
3
|
Multicast = "multicast",
|
|
@@ -42,12 +41,6 @@ export type ModuleDefinition = {
|
|
|
42
41
|
Props: Props;
|
|
43
42
|
};
|
|
44
43
|
export type Pk<T> = undefined | symbol | T;
|
|
45
|
-
export type Queue<A extends ModuleDefinition["Actions"]> = {
|
|
46
|
-
name: Head<A>;
|
|
47
|
-
actions: {
|
|
48
|
-
abort: AbortController["abort"];
|
|
49
|
-
};
|
|
50
|
-
}[];
|
|
51
44
|
export type Task = PromiseWithResolvers<void>;
|
|
52
45
|
export type Process = symbol;
|
|
53
46
|
export type Op = number;
|
package/dist/view/types.d.ts
CHANGED
package/package.json
CHANGED