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.
@@ -0,0 +1,4 @@
1
+ import { BroadcastContext, Props } from './types.ts';
2
+ import * as React from "react";
3
+ export declare function useBroadcast(): BroadcastContext;
4
+ export declare function BroadcastProvider({ children }: Props): React.ComponentType;
@@ -1,10 +1,10 @@
1
1
  import { default as EventEmitter } from 'eventemitter3';
2
2
  import * as React from "react";
3
- export type AppOptions = React.ComponentType;
4
- export type AppContext = {
3
+ export type BroadcastOptions = React.ComponentType;
4
+ export type BroadcastContext = {
5
5
  appEmitter: EventEmitter;
6
6
  };
7
- export type UseApp = AppContext;
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 w = (t, e, n) => (k(t, e, "read from private field"), n ? n.call(t) : e.get(t)), E = (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);
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 R from "traverse";
10
+ import x from "traverse";
11
11
  import { jsx as $ } from "react/jsx-runtime";
12
- import * as a from "react";
12
+ import * as c from "react";
13
13
  import M from "eventemitter3";
14
- class O {
14
+ class U {
15
15
  constructor(e) {
16
16
  this.value = e;
17
17
  }
18
18
  }
19
- class q {
19
+ class I {
20
20
  static Draft(e) {
21
- return new O(e);
21
+ return new U(e);
22
22
  }
23
23
  }
24
- y(q, "Op", {
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 c = {
32
+ const u = {
33
33
  immer: new N(),
34
34
  annotations: Symbol("annotations")
35
35
  };
36
- c.immer.setAutoFreeze(!1);
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 I(t, e = []) {
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 U(this.stateful);
54
+ return _(this.stateful);
55
55
  }
56
56
  }
57
- function U(t, e = []) {
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 (o) => {
63
- const s = x(t, e);
64
- if (!s) return !1;
65
- const u = new Set(
66
- s.flatMap((l) => l.operations)
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(u).reduce(
69
- (l, d) => l | (d ?? 0),
68
+ return !!(Array.from(i).reduce(
69
+ (l, f) => l | (f ?? 0),
70
70
  0
71
- ) & o);
71
+ ) & s);
72
72
  };
73
73
  case "pending":
74
- return () => !!x(t, e);
74
+ return () => !!R(t, e);
75
75
  case "draft":
76
76
  return () => {
77
- const o = x(t, e);
78
- if (!o) return p(t, e);
79
- const s = o.flatMap((u) => u.operations).find((u) => u instanceof O);
80
- return s ? s.value : p(t, e);
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 U(t, [...e, String(r)]);
83
+ return _(t, [...e, String(r)]);
84
84
  }
85
85
  });
86
86
  }
87
- function x(t, e) {
88
- const r = typeof p(t, e) == "object" ? e : e.slice(0, -1), o = r.length === 0 ? t : p(t, r), s = (o == null ? void 0 : o[c.annotations]) ?? [];
89
- return s.length > 0 ? s : null;
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(s) {
93
- return R(s).forEach(function() {
94
- if (this.key === c.annotations) {
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(s) {
102
- return R(s).forEach(function() {
103
- if (this.key === c.annotations) {
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 u = typeof this.node.value == "object", i = [
109
- ...u ? this.path : this.path.slice(0, -1),
110
- c.annotations
111
- ], l = p(t.stateful, i) ?? [], d = this.node.attach(e);
112
- u ? this.update(
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
- [c.annotations]: [d, ...l]
115
+ [u.annotations]: [f, ...l]
116
116
  },
117
117
  !0
118
- ) : (this.parent && (this.parent.node[c.annotations] = [d, ...l]), this.update(this.node.value, !0));
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(c.immer.produce(t.stateless, n)),
124
- o(c.immer.produce(t.stateful, n))
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 = R(t.stateful).forEach(function() {
129
- if (this.key === c.annotations) {
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[c.annotations]) {
134
- const r = this.node[c.annotations];
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
- [c.annotations]: r.filter(
139
- (o) => o.process !== e
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(), o) => {
149
+ return (e, n) => async (r = Promise.withResolvers(), s) => {
150
150
  if (typeof n != "function") return;
151
- const s = Symbol("process"), u = n(...o);
152
- if (u == null)
151
+ const o = Symbol("process"), i = n(...s);
152
+ if (i == null)
153
153
  return void r.resolve();
154
- if (typeof u == "function") {
155
- const i = u(t.model.current, s);
156
- return t.model.current = D(i, s), t.update.rerender(), void r.resolve();
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: i, done: l } = await u.next();
159
+ const { value: a, done: l } = await i.next();
160
160
  if (l) {
161
- const H = i(t.model.current, s);
162
- t.model.current = D(H, s), t.update.rerender();
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 d = i;
166
- t.model.current = d(t.model.current, s), t.update.rerender();
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 A(t) {
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
- E(this, v);
179
- E(this, g);
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 w(this, v);
183
+ return E(this, v);
184
184
  }
185
185
  get message() {
186
- return w(this, g) || "";
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 ft = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
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 f(t, e) {
210
- const n = a.useRef(null), r = a.useRef(null);
211
- return a.useMemo(() => {
212
- const o = h(e);
213
- if (r.current !== o) {
214
- r.current = o;
215
- const s = t();
216
- return n.current = s, s;
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 C(t, e) {
222
- const n = a.useRef(null);
223
- a.useEffect(() => {
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 _ = a.createContext({
229
+ const A = c.createContext({
230
230
  appEmitter: new M()
231
231
  });
232
- function B() {
233
- return a.useContext(_);
232
+ function C() {
233
+ return c.useContext(A);
234
234
  }
235
- function dt({ children: t }) {
235
+ function ft({ children: t }) {
236
236
  return () => {
237
- const e = f(
237
+ const e = d(
238
238
  () => ({
239
239
  appEmitter: new M()
240
240
  }),
241
241
  []
242
242
  );
243
- return /* @__PURE__ */ $(_.Provider, { value: e, children: t });
243
+ return /* @__PURE__ */ $(A.Provider, { value: e, children: t });
244
244
  };
245
245
  }
246
246
  function V(t) {
247
- return f(
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 I(e, n);
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 f(() => {
288
+ return d(() => {
289
289
  const e = t.options.using.actions(t.actions.controller);
290
- return Object.entries(e).forEach(([r, o]) => t.dispatchers.attach(r, o)), e;
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 = B(), n = J(t);
295
- return f(() => {
296
- const r = new M(), o = e.appEmitter;
294
+ const e = C(), n = J(t);
295
+ return d(() => {
296
+ const r = new M();
297
297
  return {
298
- attach(s, u) {
298
+ attach(s, o) {
299
299
  const i = String(s);
300
- A(i) ? o.on(i, n(s, u)) : r.on(i, n(s, u));
300
+ O(i) ? e.appEmitter.on(i, n(s, o)) : r.on(i, n(s, o));
301
301
  },
302
- dispatch(s, u, i) {
303
- const l = String(s);
304
- A(l) ? o.emit(l, i, u) : r.emit(l, i, u);
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 = a.useRef(null);
311
- return f(() => ({ customElement: t }), []);
310
+ const t = c.useRef(null);
311
+ return d(() => ({ customElement: t }), []);
312
312
  }
313
313
  function L(t) {
314
- C(() => {
314
+ B(() => {
315
315
  t.dispatchers.dispatch(m.Derive, []);
316
- }, [t.options.using.props]), C(() => (t.dispatchers.dispatch(m.Mount, []), t.dispatchers.dispatch(m.Node, [
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 = f(() => t.options.using.model ?? {}, []);
322
- return a.useRef(new P(e, e));
321
+ const e = d(() => t.options.using.model ?? {}, []);
322
+ return c.useRef(new P(e, e));
323
323
  }
324
324
  function et() {
325
- return a.useRef(/* @__PURE__ */ new Set());
325
+ return c.useRef(/* @__PURE__ */ new Set());
326
326
  }
327
327
  function nt() {
328
- const [t, e] = a.useReducer((n) => n + 1, 0);
329
- return f(() => ({ hash: t, rerender: e }), [t]);
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 = B(), n = nt(), r = et(), o = Z(), s = tt({ options: t }), u = Y({ app: e, options: t, update: n, model: s, queue: r }), i = V({ app: e, options: t, model: s, dispatchers: u });
335
- return X({ options: t, dispatchers: u, actions: i }), L({ options: t, dispatchers: u, elements: o, update: n }), f(() => a.createElement("x-chizu", {
336
- ref: o.customElement,
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(i.view)
339
- }), [n.hash, h(t.using.props)]);
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 = a.memo(st, (t, e) => h(t) === h(e));
351
+ const ht = c.memo(st, (t, e) => h(t) === h(e));
345
352
  export {
346
- dt as Context,
353
+ ft as BroadcastProvider,
347
354
  Q as EventError,
348
355
  m as Lifecycle,
349
- q as State,
356
+ I as State,
350
357
  ht as Tree,
351
- B as useContext,
352
- ft as utils
358
+ C as useBroadcast,
359
+ dt as utils
353
360
  };
@@ -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,a,p,N,I,E){"use strict";var ae=Object.defineProperty;var B=s=>{throw TypeError(s)};var le=(s,u,a)=>u in s?ae(s,u,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[u]=a;var O=(s,u,a)=>le(s,typeof u!="symbol"?u+"":u,a),H=(s,u,a)=>u.has(s)||B("Cannot "+a);var M=(s,u,a)=>(H(s,u,"read from private field"),a?a.call(s):u.get(s)),P=(s,u,a)=>u.has(s)?B("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(s):u.set(s,a),D=(s,u,a,p)=>(H(s,u,"write to private field"),p?p.call(s,a):u.set(s,a),a);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 f=$(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 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 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 i=>{const o=R(e,t);if(!o)return!1;const c=new Set(o.flatMap(h=>h.operations));return!!(Array.from(c).reduce((h,b)=>h|(b??0),0)&i)};case"pending":return()=>!!R(e,t);case"draft":return()=>{const i=R(e,t);if(!i)return a(e,t);const o=i.flatMap(c=>c.operations).find(c=>c instanceof k);return o?o.value:a(e,t)}}return _(e,[...t,String(r)])}})}function R(e,t){const r=typeof a(e,t)=="object"?t:t.slice(0,-1),i=r.length===0?e:a(e,r),o=(i==null?void 0:i[d.annotations])??[];return o.length>0?o:null}function J(e,t,n){function r(o){return p(o).forEach(function(){if(this.key===d.annotations){this.block();return}this.node instanceof j&&this.update(this.node.value)})}function i(o){return p(o).forEach(function(){if(this.key===d.annotations){this.block();return}if(this.node instanceof j){const c=typeof this.node.value=="object",l=[...c?this.path:this.path.slice(0,-1),d.annotations],h=a(e.stateful,l)??[],b=this.node.attach(t);c?this.update({...this.node.value,[d.annotations]:[b,...h]},!0):(this.parent&&(this.parent.node[d.annotations]=[b,...h]),this.update(this.node.value,!0))}})}return new S(r(d.immer.produce(e.stateless,n)),i(d.immer.produce(e.stateful,n)))}function q(e,t){const n=p(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(i=>i.process!==t)},!0)}});return new S(e.stateless,n)}function Q(e){return(t,n)=>async(r=Promise.withResolvers(),i)=>{if(typeof n!="function")return;const o=Symbol("process"),c=n(...i);if(c==null)return void r.resolve();if(typeof c=="function"){const l=c(e.model.current,o);return e.model.current=q(l,o),e.update.rerender(),void r.resolve()}for(;;){const{value:l,done:h}=await c.next();if(h){const ce=l(e.model.current,o);e.model.current=q(ce,o),e.update.rerender();break}const b=l;e.model.current=b(e.model.current,o),e.update.rerender()}r.resolve()}}function C(e){return e.startsWith("distributed")}class A extends Error{constructor(n,r=null){super(String(r));P(this,g);P(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 A}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 m(e,t){const n=f.useRef(null),r=f.useRef(null);return f.useMemo(()=>{const i=y(t);if(r.current!==i){r.current=i;const o=e();return n.current=o,o}return n.current},t)}function U(e,t){const n=f.useRef(null);f.useEffect(()=>{const r=y(t);if(n.current!==r)return n.current=r,e()},t)}const z=f.createContext({appEmitter:new E});function x(){return f.useContext(z)}function X({children:e}){return()=>{const t=m(()=>({appEmitter:new E}),[]);return N.jsx(z.Provider,{value:t,children:e})}}function Y(e){return m(()=>({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 m(()=>{const t=e.options.using.actions(e.actions.controller);return Object.entries(t).forEach(([r,i])=>e.dispatchers.attach(r,i)),t},[])}function L(e){const t=x(),n=Q(e);return m(()=>{const r=new E,i=t.appEmitter;return{attach(o,c){const l=String(o);C(l)?i.on(l,n(o,c)):r.on(l,n(o,c))},dispatch(o,c,l){const h=String(o);C(h)?i.emit(h,l,c):r.emit(h,l,c)}}},[])}function ee(){const e=f.useRef(null);return m(()=>({customElement:e}),[])}function te(e){U(()=>{e.dispatchers.dispatch(v.Derive,[])},[e.options.using.props]),U(()=>(e.dispatchers.dispatch(v.Mount,[]),e.dispatchers.dispatch(v.Node,[e.elements.customElement.current]),()=>e.dispatchers.dispatch(v.Unmount,[])),[])}function ne(e){const t=m(()=>e.options.using.model??{},[]);return f.useRef(new S(t,t))}function re(){return f.useRef(new Set)}function se(){const[e,t]=f.useReducer(n=>n+1,0);return m(()=>({hash:e,rerender:t}),[e])}function oe({options:e}){const t=x(),n=se(),r=re(),i=ee(),o=ne({options:e}),c=L({app:t,options:e,update:n,model:o,queue:r}),l=Y({app:t,options:e,model:o,dispatchers:c});return Z({options:e,dispatchers:c,actions:l}),te({options:e,dispatchers:c,elements:i,update:n}),m(()=>f.createElement("x-chizu",{ref:i.customElement,style:{display:"contents"},children:e.children(l.view)}),[n.hash,y(e.using.props)])}function ue(e){return oe({options:e})}const ie=f.memo(ue,(e,t)=>y(e)===y(t));s.Context=X,s.EventError=A,s.Lifecycle=v,s.State=T,s.Tree=ie,s.useContext=x,s.utils=V,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
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 { AppContext as Context, useApp as useContext, } from './context/index.tsx';
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 { UseApp } from '../../../context/types.ts';
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
- app: UseApp;
9
+ broadcast: UseBroadcast;
10
10
  options: UseOptions<M>;
11
11
  model: UseModel;
12
12
  dispatchers: UseDispatchers;
@@ -1,4 +1,4 @@
1
- import { UseApp } from '../../../context/types.ts';
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
- app: UseApp;
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.13",
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.0.0",
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.26.0",
27
- "@babel/preset-react": "^7.26.3",
28
- "@babel/preset-typescript": "^7.26.0",
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.7.0",
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.2.0",
32
+ "@testing-library/react": "^16.3.0",
34
33
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
35
- "@types/lodash": "^4.17.16",
36
- "@types/react": "^19.0.8",
37
- "@types/react-dom": "^19.0.3",
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": "^29.7.0",
45
- "lucide-react": "^0.503.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.0.0",
48
- "react-test-renderer": "^19.0.0",
49
- "rollup-plugin-visualizer": "^5.14.0",
50
- "ts-jest": "^29.2.6",
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.0.5",
53
+ "vite": "^6.3.5",
54
54
  "vite-plugin-dts": "^4.5.4",
55
55
  "wait-on": "^8.0.3"
56
56
  }
@@ -1,4 +0,0 @@
1
- import { AppContext, Props } from './types.ts';
2
- import * as React from "react";
3
- export declare function useApp(): AppContext;
4
- export declare function AppContext({ children }: Props): React.ComponentType;