@expressive/react 0.93.0 → 0.94.1

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/adapter.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { t as Runtime } from "./chunk-runtime-BPVaN7sv.js";
1
+ import { t as Runtime } from "./chunk-runtime-BVFmTU_r.js";
2
2
  import { Model } from "@expressive/mvc";
3
3
  export { Model, Runtime };
package/dist/adapter.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as Runtime } from "./chunk-state.get-rQCeG3MQ.js";
1
+ import { r as Runtime } from "./chunk-state.get-Buie72pM.js";
2
2
  import { Model } from "@expressive/mvc";
3
3
 
4
4
  export { Model, Runtime };
@@ -3,16 +3,6 @@ import { Component, Context } from "@expressive/mvc";
3
3
  //#region src/component.d.ts
4
4
  declare module '@expressive/mvc' {
5
5
  interface Component {
6
- /**
7
- * Optional hook called once this Component commits. Return a function to
8
- * run when it unmounts.
9
- *
10
- * Not called during server render, nor for an instance placed as
11
- * `{component}` - a placement does not own what it renders. Client-only
12
- * effects belong here; setup which must accompany the instance itself
13
- * belongs in `new()`.
14
- */
15
- mount?(): (() => void) | void;
16
6
  /** @deprecated Only to satisfy host JSX. Use `this.get(Model)` instead. */
17
7
  readonly context: Context;
18
8
  /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */
@@ -55,4 +45,4 @@ declare const Runtime: {
55
45
  };
56
46
  //#endregion
57
47
  export { Runtime as t };
58
- //# sourceMappingURL=chunk-runtime-BPVaN7sv.d.ts.map
48
+ //# sourceMappingURL=chunk-runtime-BVFmTU_r.d.ts.map
@@ -182,6 +182,7 @@ Object.defineProperty(Component, "contextType", {
182
182
 
183
183
  //#endregion
184
184
  //#region src/component.ts
185
+ const PLACING = /* @__PURE__ */ new WeakMap();
185
186
  Object.defineProperties(Component.prototype, {
186
187
  state: {
187
188
  set() {},
@@ -210,9 +211,13 @@ Component.on({
210
211
  },
211
212
  setup(self) {
212
213
  subcomponents(self);
214
+ return PLACING.get(self)?.placed;
213
215
  }
214
216
  });
215
217
  function bootstrap(parent) {
218
+ const placing = {};
219
+ placing.placed = new Promise((resolve) => placing.place = resolve);
220
+ PLACING.set(this, placing);
216
221
  const context = parent.push(this, () => this.set(null));
217
222
  Object.defineProperties(this, {
218
223
  context: {
@@ -262,9 +267,8 @@ function render(from, context) {
262
267
  const Render = () => (own || Object.getPrototypeOf(owner).render).call(from, from.props);
263
268
  const Component = () => {
264
269
  from = useWatch(from, () => {
265
- const release = owner.mount?.();
270
+ PLACING.get(owner).place();
266
271
  attempt?.commit();
267
- return release;
268
272
  }, teardown);
269
273
  return createFrame(from, context, createElement(Render));
270
274
  };
@@ -398,4 +402,4 @@ function use(local, compute) {
398
402
 
399
403
  //#endregion
400
404
  export { useWatch as a, useFactory as i, useAmbient as n, weak as o, Runtime as r, createFrame as t };
401
- //# sourceMappingURL=chunk-state.get-rQCeG3MQ.js.map
405
+ //# sourceMappingURL=chunk-state.get-Buie72pM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chunk-state.get-Buie72pM.js","names":[],"sources":["../src/runtime.ts","../src/context.ts","../src/component.ts","../src/state.get.ts"],"sourcesContent":["import type { Component } from '@expressive/mvc';\nimport { watch } from '@expressive/mvc/observable';\nimport { pending } from '@expressive/mvc';\nimport type { Context } from './context';\n\ninterface Settle {\n waiting?: (() => void)[];\n claim(): void;\n release(): void;\n}\n\ninterface Setup {\n rendered: number;\n revision: number;\n mounted?: boolean;\n fresh?: boolean;\n getRevision?: () => number;\n lapsed?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | void;\n teardown?: () => void;\n}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: Weak<(next: (previous: number) => number) => void>;\n output: T;\n}\n\ninterface Weak<T> {\n deref(): T | undefined;\n}\n\nexport const Runtime = {} as {\n /** Host own-property keys to trap out of observed state; assigned by each adapter. */\n ignore: string[];\n createElement(type: any, props?: any, ...children: any[]): any;\n createContext<T>(value: T): any;\n useContext(context: any): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n /** Non-urgent bracket a subscriber replays through; absent where the host\n * cannot defer, which keeps normal timing. */\n startTransition?(work: () => void): void;\n /** Consumed for pre-commit revision validation; absent where commits\n * cannot interleave with writes. */\n useSyncExternalStore?(\n subscribe: (notify: () => void) => () => void,\n getSnapshot: () => number,\n getServerSnapshot?: () => number\n ): number;\n /** Per-render-attempt lifecycle; absent where render attempts do not stack. */\n dedupe?(from: Component, context: Context): { commit(): void; remove(): void };\n /** Whether the host is certainly not rendering, so a hook probe would only throw - and may log. `undefined` when the host cannot tell. */\n idle(): boolean | undefined;\n /** Host error-boundary component, wrapping a Component whose `catch` is set. */\n ErrorBoundary: unknown;\n Suspense: any;\n};\n\nconst noop = () => () => {};\n\nexport function useFactory<T extends object>(factory: () => T) {\n const ref = Runtime.useRef<T | null>(null);\n return ref.current || (ref.current = factory());\n}\n\n/**\n * Returns a claim on the update being replayed, held until this hook commits\n * carrying it - or until unmount, where it never will. Keyed on `tick` so an\n * urgent commit in the meantime, which leaves the deferred update queued, does\n * not release it.\n */\nexport function useSettle(tick: number) {\n const ref = Runtime.useRef<Settle | null>(null);\n const settle = ref.current || (ref.current = {\n claim() {\n const held = pending();\n\n if (held) (settle.waiting ||= []).push(held);\n },\n release() {\n const { waiting } = settle;\n\n if (!waiting) return;\n settle.waiting = undefined;\n\n for (const held of waiting) held();\n }\n });\n\n Runtime.useEffect(() => {\n settle.release();\n return settle.release;\n }, [tick]);\n\n return settle.claim;\n}\n\n/**\n * Run `init` once for the life of a hook and clean up when it unmounts, safe\n * under React StrictMode - a remount shares the render counter, so neither the\n * setup nor its cleanup repeats. A cleanup following a render not yet committed\n * - Fast Refresh re-running effects - defers a microtask, and is dropped if the\n * effect runs again. `reset` invalidates the rendered value so in-flight render\n * attempts revalidate.\n *\n * @returns The hook's own record, plus the render counter and its setter.\n */\nexport function useSetup<T extends Setup>(\n init: (self: T, reset: () => void) => () => (() => void) | void,\n teardown?: () => void\n) {\n const { current } = Runtime.useRef({ rendered: 0, revision: 0 } as T);\n\n const [tick, update] = Runtime.useState(() => {\n if (!current.rendered)\n current.commit = init(current, () => {\n current.revision++;\n });\n\n return current.rendered++;\n });\n\n useReap(current, teardown);\n\n const getRevision = (current.getRevision ||= () => current.revision);\n\n current.fresh = true;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.fresh = false;\n });\n\n Runtime.useEffect(() => {\n current.mounted = true;\n current.lapsed = false;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n return () => {\n if (!current.fresh) {\n if (--current.rendered <= 0) release(current);\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) release(current);\n });\n }\n }, []);\n\n return [current, tick, update] as const;\n}\n\nfunction release(setup: Setup) {\n setup.release?.();\n setup.teardown?.();\n}\n\nlet reaper: FinalizationRegistry<Setup> | null | undefined;\n\nfunction useReap(setup: Setup, teardown?: () => void) {\n const token = Runtime.useRef<object | null>(null);\n\n if (!teardown || setup.teardown) return;\n\n setup.teardown = teardown;\n\n if (reaper === undefined)\n reaper = typeof FinalizationRegistry == 'function'\n ? new FinalizationRegistry((setup) => setup.mounted || setup.teardown!())\n : null;\n\n reaper?.register((token.current = {}), setup);\n}\n\nexport function weak<T extends object>(value: T): Weak<T> {\n return typeof WeakRef == 'function' ? new WeakRef(value) : { deref: () => value };\n}\n\nexport function useWeak<T extends object>(value: T) {\n const ref = Runtime.useRef<Weak<T> | null>(null);\n return (ref.current ||= weak(value));\n}\n\n/**\n * Mount-effect with a refreshable return value. Publishing a value before mount\n * defers the update to it, and one published after claims the update being\n * replayed until this hook commits carrying it.\n *\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (\n refresh: (next: T) => void,\n reset: () => void\n ) => () => (() => void) | void,\n teardown?: () => void\n) {\n const [current, tick, update] = useSetup<Hook<T>>((self, reset) => {\n const mount = callback((next) => {\n self.output = next;\n\n if (self.mounted) {\n claim();\n self.update?.deref()!((x) => x + 1);\n }\n else if (self.update) self.queued = true;\n }, reset);\n\n return () => {\n const cleanup = mount();\n\n if (self.queued) {\n self.queued = false;\n self.update!.deref()!((x) => x + 1);\n }\n\n return cleanup;\n };\n }, teardown);\n\n const claim = useSettle(tick);\n\n current.update ||= weak(update);\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | void,\n teardown?: () => void\n) {\n return useHook<T>((refresh, reset) => {\n const release = watch(from, (current) => {\n refresh(current);\n\n return (update) => {\n if (update === true) reset();\n };\n }, undefined, Runtime.startTransition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n if (typeof cleanup == 'function') cleanup();\n };\n };\n }, teardown) ?? from;\n}\n","import { Context, Component } from '@expressive/mvc';\nimport { Runtime } from './runtime';\n\nlet shared: any;\n\n/**\n * Lazily-created context carrying the active {@link Context} down the tree.\n * Lazy because the framework's `createContext` arrives via {@link Runtime},\n * which an adapter's entry populates at load - after this module evaluates.\n */\nfunction Layers() {\n return shared || (shared = Runtime.createContext(Context.root));\n}\n\n/** Read the ambient {@link Context} from the nearest Layers provider. */\nfunction useAmbient() {\n return Runtime.useContext(Layers());\n}\n\n/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */\nfunction createProvider(context: Context, children: any) {\n return Runtime.createElement(Layers().Provider, { value: context, children });\n}\n\n// Class components consume the active Context through the host's `contextType`\nObject.defineProperty(Component, 'contextType', { configurable: true, get: Layers });\n\nexport { Context, createProvider, useAmbient };\n","import { Component, unbind } from '@expressive/mvc';\nimport { createProvider, type Context } from './context';\nimport { Runtime, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n interface Component {\n /** @deprecated Only to satisfy host JSX. Use `this.get(Model)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: {};\n /** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */\n setState: (state: any, callback?: () => void) => void;\n /** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */\n forceUpdate: (callback?: () => void) => void;\n }\n}\n\n// Host-agnostic seams: `state` is a read-only values bag; `context`'s setter\n// pushes a child context, registers the instance for teardown, and installs its\n// per-instance render host. Host-specific descriptors stay in each adapter.\nconst PLACING = new WeakMap<Component, { placed: Promise<void>; place(): void }>();\n\nObject.defineProperties(Component.prototype, {\n state: {\n set() {},\n get: Component.prototype.get\n },\n context: {\n set: bootstrap\n }\n});\n\n/**\n * On the root Component, host own-property keys are trapped so each lands as a\n * plain own property (out of observed state); each adapter assigns its own set.\n */\nComponent.on({\n type(type) {\n const render = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (typeof render?.value == 'function')\n Object.defineProperty(type.prototype, 'render', { ...render, configurable: false });\n\n if (type === Component)\n for (const key of Runtime.ignore)\n Object.defineProperty(Component.prototype, key, {\n set(value) {\n Object.defineProperty(this, key, { value, writable: true });\n }\n });\n\n subcomponents(type.prototype);\n },\n setup(self) {\n subcomponents(self);\n return PLACING.get(self)?.placed;\n }\n});\n\nfunction bootstrap(this: Component, parent: Context){\n const placing = {} as { placed: Promise<void>; place(): void };\n\n placing.placed = new Promise((resolve) => (placing.place = resolve));\n PLACING.set(this, placing);\n\n const context = parent.push(this, () => this.set(null));\n\n Object.defineProperties(this, {\n context: {\n get: () => context,\n set() {}\n },\n render: {\n value: render(this, context)\n }\n });\n\n this.set(null, () => {\n Object.defineProperty(this, 'props', {\n value: this.props,\n writable: true\n });\n })\n}\n\n/**\n * Wrap a content element in its context provider, a Suspense boundary (unless\n * `fallback` is `false`) and, when `catch` is set, the host error boundary.\n */\nfunction createFrame(from: Component, context: Context, children: unknown) {\n const { createElement } = Runtime;\n\n if(from.fallback !== false)\n children = createElement(\n Runtime.Suspense,\n { fallback: from.fallback, name: String(from) },\n children\n )\n\n children = createProvider(context, children);\n\n return from.props.catch || from.catch\n ? createElement(Runtime.ErrorBoundary, { self: from, children })\n : children;\n}\n\n/**\n * Ownership host for `<Component/>`: React owns the instance, so its render\n * threads the bootstrap-pushed context through `Runtime.dedupe` (React stacks\n * render attempts) and tears that context down - destroying the instance - on\n * unmount.\n */\nfunction render(from: Component, context: Context) {\n const { createElement, dedupe } = Runtime;\n const attempt = dedupe?.(from, context);\n const { is: owner } = from;\n // Read before bootstrap shadows an instance `render` with this host.\n const own = Object.prototype.hasOwnProperty.call(owner, 'render') && owner.render;\n const teardown = () => {\n attempt?.remove();\n context.pop();\n };\n\n const Render = () => (own || Object.getPrototypeOf(owner).render).call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n PLACING.get(owner)!.place();\n attempt?.commit();\n }, teardown);\n\n return createFrame(from, context, createElement(Render));\n };\n\n return () => createElement(Component);\n}\n\n/** Rewrite each own capitalized function on `target` into a subcomponent. */\nfunction subcomponents(target: object) {\n for (const key of Object.getOwnPropertyNames(target)) {\n if (!/^[A-Z]/.test(key)) continue;\n const { value } = Object.getOwnPropertyDescriptor(target, key)!;\n if (typeof value != 'function') continue;\n Object.defineProperty(target, key, {\n configurable: true,\n get(this: Component) {\n const owner = this.is;\n let render = unbind(value);\n const Component = (props: unknown) =>\n render.call(useWatch(owner), props);\n\n Object.defineProperty(owner, key, {\n configurable: true,\n get: () => Component,\n set(fn: Function) {\n render = fn;\n }\n });\n\n return Component;\n },\n set(this: Component, value: unknown) {\n Object.defineProperty(this, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n\n subcomponents(this);\n }\n });\n }\n}\n\nexport { createFrame };\n","import { Model, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { resolver } from '@expressive/mvc/jsx-runtime';\nimport { useAmbient } from './context';\nimport { Runtime, useFactory, useSettle, useSetup, useWeak } from './runtime';\n\nconst normal = resolver((Type, compute) => {\n const idle = Runtime.idle();\n\n if (idle) return normal(Type, compute);\n\n let ambient: Context;\n\n if (idle === undefined)\n try {\n ambient = useAmbient();\n } catch {\n return normal(Type, compute);\n }\n else ambient = useAmbient();\n\n return Type ? use(ambient, compute) : compute(ambient);\n});\n\nfunction use(local: Context, compute: (context: Context) => unknown) {\n const [tick, next] = Runtime.useState(0);\n const claim = useSettle(tick);\n const dispatch = useWeak(next);\n const render = useFactory(() => {\n let latest = compute;\n let mounted = false;\n let pending = false;\n let force!: () => void;\n let target: unknown;\n let value: unknown;\n let unwatch: (() => void) | undefined;\n let thrown: [unknown] | undefined;\n\n function update() {\n pending = false;\n dispatch.deref()!((x) => x + 1);\n }\n\n function observed() {\n if (mounted) {\n claim();\n update();\n }\n else pending = true;\n }\n\n function follow(found: unknown) {\n if (found === target) return;\n\n unwatch?.();\n unwatch = undefined;\n target = value = found;\n\n if (found instanceof Model && observer(found) !== null) {\n let first = true;\n\n unwatch = watch(\n found,\n (current) => {\n value = current;\n\n if (!first) observed();\n first = false;\n\n return (update) => {\n if (update === true) force();\n };\n },\n false,\n Runtime.startTransition\n );\n }\n\n return true;\n }\n\n function release() {\n unfollow();\n unwatch?.();\n unwatch = target = undefined;\n }\n\n let first = true;\n\n const unfollow = watch(local, (ctx) => {\n try {\n if (follow(latest(ctx)) && !first) observed();\n } catch (error) {\n thrown = [error];\n if (!first) observed();\n }\n }, false);\n\n first = false;\n\n if (thrown) {\n unfollow();\n throw thrown[0];\n }\n\n let fresh = true;\n\n return (next: typeof compute) => {\n pending = false;\n useSetup((_self, reset) => {\n force = reset;\n\n return () => {\n mounted = true;\n if (pending) update();\n return release;\n };\n });\n\n if (!fresh) follow((latest = next)(local));\n\n fresh = false;\n\n return value;\n };\n });\n\n return render(compute);\n}\n"],"mappings":";;;;;AAiCA,MAAa,UAAU,EAAE;AA4BzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA6B,SAAkB;CAC7D,MAAM,MAAM,QAAQ,OAAiB,K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,IAAI;EACJ,IAAI;EAEJ,SAAS,SAAS;AAChB,aAAU;AACV,YAAS,OAAO,EAAG,MAAM,IAAI,EAAE;;EAGjC,SAAS,WAAW;AAClB,OAAI,SAAS;AACX,WAAO;AACP,YAAQ;SAEL,WAAU;;EAGjB,SAAS,OAAO,OAAgB;AAC9B,OAAI,UAAU,OAAQ;AAEtB,cAAW;AACX,aAAU;AACV,YAAS,QAAQ;AAEjB,OAAI,iBAAiB,SAAS,SAAS,MAAM,KAAK,MAAM;IACtD,IAAI,QAAQ;AAEZ,cAAU,MACR,QACC,YAAY;AACX,aAAQ;AAER,SAAI,CAAC,MAAO,WAAU;AACtB,aAAQ;AAER,aAAQ,WAAW;AACjB,UAAI,WAAW,KAAM,QAAO;;OAGhC,OACA,QAAQ,gBACT;;AAGH,UAAO;;EAGT,SAAS,UAAU;AACjB,aAAU;AACV,cAAW;AACX,aAAU,SAAS;;EAGrB,IAAI,QAAQ;EAEZ,MAAM,WAAW,MAAM,QAAQ,QAAQ;AACrC,OAAI;AACF,QAAI,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,MAAO,WAAU;YACtC,OAAO;AACd,aAAS,CAAC,MAAM;AAChB,QAAI,CAAC,MAAO,WAAU;;KAEvB,MAAM;AAET,UAAQ;AAER,MAAI,QAAQ;AACV,aAAU;AACV,SAAM,OAAO;;EAGf,IAAI,QAAQ;AAEZ,UAAQ,SAAyB;AAC/B,aAAU;AACV,aAAU,OAAO,UAAU;AACzB,YAAQ;AAER,iBAAa;AACX,eAAU;AACV,SAAI,QAAS,SAAQ;AACrB,YAAO;;KAET;AAEF,OAAI,CAAC,MAAO,SAAQ,SAAS,MAAM,MAAM,CAAC;AAE1C,WAAQ;AAER,UAAO;;GAET,CAEY,QAAQ"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as Runtime } from "./chunk-runtime-BPVaN7sv.js";
1
+ import { t as Runtime } from "./chunk-runtime-BVFmTU_r.js";
2
2
  import { Component as Component$1, JSX, ReactNode } from "react";
3
3
 
4
4
  //#region src/element.d.ts
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as useWatch, i as useFactory, n as useAmbient, o as weak, r as Runtime, t as createFrame } from "./chunk-state.get-rQCeG3MQ.js";
1
+ import { a as useWatch, i as useFactory, n as useAmbient, o as weak, r as Runtime, t as createFrame } from "./chunk-state.get-Buie72pM.js";
2
2
  import "./adapter.js";
3
3
  import { Component } from "@expressive/mvc";
4
4
  import * as React$1 from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressive/react",
3
- "version": "0.93.0",
3
+ "version": "0.94.1",
4
4
  "description": "Class-based reactive state for React. Define state and logic as plain classes; components update when the values they read change.",
5
5
  "keywords": [
6
6
  "expressive",
@@ -63,7 +63,7 @@
63
63
  "test": "bun run typecheck && bun run coverage"
64
64
  },
65
65
  "devDependencies": {
66
- "@expressive/mvc": "^0.92.0",
66
+ "@expressive/mvc": "^0.94.0",
67
67
  "@testing-library/react": "^16.3.0",
68
68
  "@types/react": "^19",
69
69
  "@types/react-dom": "^19",
@@ -75,7 +75,7 @@
75
75
  "vite": "^7.3.1"
76
76
  },
77
77
  "peerDependencies": {
78
- "@expressive/mvc": "^0.92.0",
78
+ "@expressive/mvc": "^0.94.0",
79
79
  "react": ">=16.14.0 <20.0.0",
80
80
  "vite": ">=5"
81
81
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunk-state.get-rQCeG3MQ.js","names":[],"sources":["../src/runtime.ts","../src/context.ts","../src/component.ts","../src/state.get.ts"],"sourcesContent":["import type { Component } from '@expressive/mvc';\nimport { watch } from '@expressive/mvc/observable';\nimport { pending } from '@expressive/mvc';\nimport type { Context } from './context';\n\ninterface Settle {\n waiting?: (() => void)[];\n claim(): void;\n release(): void;\n}\n\ninterface Setup {\n rendered: number;\n revision: number;\n mounted?: boolean;\n fresh?: boolean;\n getRevision?: () => number;\n lapsed?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | void;\n teardown?: () => void;\n}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: Weak<(next: (previous: number) => number) => void>;\n output: T;\n}\n\ninterface Weak<T> {\n deref(): T | undefined;\n}\n\nexport const Runtime = {} as {\n /** Host own-property keys to trap out of observed state; assigned by each adapter. */\n ignore: string[];\n createElement(type: any, props?: any, ...children: any[]): any;\n createContext<T>(value: T): any;\n useContext(context: any): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n /** Non-urgent bracket a subscriber replays through; absent where the host\n * cannot defer, which keeps normal timing. */\n startTransition?(work: () => void): void;\n /** Consumed for pre-commit revision validation; absent where commits\n * cannot interleave with writes. */\n useSyncExternalStore?(\n subscribe: (notify: () => void) => () => void,\n getSnapshot: () => number,\n getServerSnapshot?: () => number\n ): number;\n /** Per-render-attempt lifecycle; absent where render attempts do not stack. */\n dedupe?(from: Component, context: Context): { commit(): void; remove(): void };\n /** Whether the host is certainly not rendering, so a hook probe would only throw - and may log. `undefined` when the host cannot tell. */\n idle(): boolean | undefined;\n /** Host error-boundary component, wrapping a Component whose `catch` is set. */\n ErrorBoundary: unknown;\n Suspense: any;\n};\n\nconst noop = () => () => {};\n\nexport function useFactory<T extends object>(factory: () => T) {\n const ref = Runtime.useRef<T | null>(null);\n return ref.current || (ref.current = factory());\n}\n\n/**\n * Returns a claim on the update being replayed, held until this hook commits\n * carrying it - or until unmount, where it never will. Keyed on `tick` so an\n * urgent commit in the meantime, which leaves the deferred update queued, does\n * not release it.\n */\nexport function useSettle(tick: number) {\n const ref = Runtime.useRef<Settle | null>(null);\n const settle = ref.current || (ref.current = {\n claim() {\n const held = pending();\n\n if (held) (settle.waiting ||= []).push(held);\n },\n release() {\n const { waiting } = settle;\n\n if (!waiting) return;\n settle.waiting = undefined;\n\n for (const held of waiting) held();\n }\n });\n\n Runtime.useEffect(() => {\n settle.release();\n return settle.release;\n }, [tick]);\n\n return settle.claim;\n}\n\n/**\n * Run `init` once for the life of a hook and clean up when it unmounts, safe\n * under React StrictMode - a remount shares the render counter, so neither the\n * setup nor its cleanup repeats. A cleanup following a render not yet committed\n * - Fast Refresh re-running effects - defers a microtask, and is dropped if the\n * effect runs again. `reset` invalidates the rendered value so in-flight render\n * attempts revalidate.\n *\n * @returns The hook's own record, plus the render counter and its setter.\n */\nexport function useSetup<T extends Setup>(\n init: (self: T, reset: () => void) => () => (() => void) | void,\n teardown?: () => void\n) {\n const { current } = Runtime.useRef({ rendered: 0, revision: 0 } as T);\n\n const [tick, update] = Runtime.useState(() => {\n if (!current.rendered)\n current.commit = init(current, () => {\n current.revision++;\n });\n\n return current.rendered++;\n });\n\n useReap(current, teardown);\n\n const getRevision = (current.getRevision ||= () => current.revision);\n\n current.fresh = true;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.fresh = false;\n });\n\n Runtime.useEffect(() => {\n current.mounted = true;\n current.lapsed = false;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n return () => {\n if (!current.fresh) {\n if (--current.rendered <= 0) release(current);\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) release(current);\n });\n }\n }, []);\n\n return [current, tick, update] as const;\n}\n\nfunction release(setup: Setup) {\n setup.release?.();\n setup.teardown?.();\n}\n\nlet reaper: FinalizationRegistry<Setup> | null | undefined;\n\nfunction useReap(setup: Setup, teardown?: () => void) {\n const token = Runtime.useRef<object | null>(null);\n\n if (!teardown || setup.teardown) return;\n\n setup.teardown = teardown;\n\n if (reaper === undefined)\n reaper = typeof FinalizationRegistry == 'function'\n ? new FinalizationRegistry((setup) => setup.mounted || setup.teardown!())\n : null;\n\n reaper?.register((token.current = {}), setup);\n}\n\nexport function weak<T extends object>(value: T): Weak<T> {\n return typeof WeakRef == 'function' ? new WeakRef(value) : { deref: () => value };\n}\n\nexport function useWeak<T extends object>(value: T) {\n const ref = Runtime.useRef<Weak<T> | null>(null);\n return (ref.current ||= weak(value));\n}\n\n/**\n * Mount-effect with a refreshable return value. Publishing a value before mount\n * defers the update to it, and one published after claims the update being\n * replayed until this hook commits carrying it.\n *\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (\n refresh: (next: T) => void,\n reset: () => void\n ) => () => (() => void) | void,\n teardown?: () => void\n) {\n const [current, tick, update] = useSetup<Hook<T>>((self, reset) => {\n const mount = callback((next) => {\n self.output = next;\n\n if (self.mounted) {\n claim();\n self.update?.deref()!((x) => x + 1);\n }\n else if (self.update) self.queued = true;\n }, reset);\n\n return () => {\n const cleanup = mount();\n\n if (self.queued) {\n self.queued = false;\n self.update!.deref()!((x) => x + 1);\n }\n\n return cleanup;\n };\n }, teardown);\n\n const claim = useSettle(tick);\n\n current.update ||= weak(update);\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | void,\n teardown?: () => void\n) {\n return useHook<T>((refresh, reset) => {\n const release = watch(from, (current) => {\n refresh(current);\n\n return (update) => {\n if (update === true) reset();\n };\n }, undefined, Runtime.startTransition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n if (typeof cleanup == 'function') cleanup();\n };\n };\n }, teardown) ?? from;\n}\n","import { Context, Component } from '@expressive/mvc';\nimport { Runtime } from './runtime';\n\nlet shared: any;\n\n/**\n * Lazily-created context carrying the active {@link Context} down the tree.\n * Lazy because the framework's `createContext` arrives via {@link Runtime},\n * which an adapter's entry populates at load - after this module evaluates.\n */\nfunction Layers() {\n return shared || (shared = Runtime.createContext(Context.root));\n}\n\n/** Read the ambient {@link Context} from the nearest Layers provider. */\nfunction useAmbient() {\n return Runtime.useContext(Layers());\n}\n\n/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */\nfunction createProvider(context: Context, children: any) {\n return Runtime.createElement(Layers().Provider, { value: context, children });\n}\n\n// Class components consume the active Context through the host's `contextType`\nObject.defineProperty(Component, 'contextType', { configurable: true, get: Layers });\n\nexport { Context, createProvider, useAmbient };\n","import { Component, unbind } from '@expressive/mvc';\nimport { createProvider, type Context } from './context';\nimport { Runtime, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n interface Component {\n /**\n * Optional hook called once this Component commits. Return a function to\n * run when it unmounts.\n *\n * Not called during server render, nor for an instance placed as\n * `{component}` - a placement does not own what it renders. Client-only\n * effects belong here; setup which must accompany the instance itself\n * belongs in `new()`.\n */\n mount?(): (() => void) | void;\n\n /** @deprecated Only to satisfy host JSX. Use `this.get(Model)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: {};\n /** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */\n setState: (state: any, callback?: () => void) => void;\n /** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */\n forceUpdate: (callback?: () => void) => void;\n }\n}\n\n// Host-agnostic seams: `state` is a read-only values bag; `context`'s setter\n// pushes a child context, registers the instance for teardown, and installs its\n// per-instance render host. Host-specific descriptors stay in each adapter.\nObject.defineProperties(Component.prototype, {\n state: {\n set() {},\n get: Component.prototype.get\n },\n context: {\n set: bootstrap\n }\n});\n\n/**\n * On the root Component, host own-property keys are trapped so each lands as a\n * plain own property (out of observed state); each adapter assigns its own set.\n */\nComponent.on({\n type(type) {\n const render = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (typeof render?.value == 'function')\n Object.defineProperty(type.prototype, 'render', { ...render, configurable: false });\n\n if (type === Component)\n for (const key of Runtime.ignore)\n Object.defineProperty(Component.prototype, key, {\n set(value) {\n Object.defineProperty(this, key, { value, writable: true });\n }\n });\n\n subcomponents(type.prototype);\n },\n setup(self) {\n subcomponents(self);\n }\n});\n\nfunction bootstrap(this: Component, parent: Context){\n const context = parent.push(this, () => this.set(null));\n\n Object.defineProperties(this, {\n context: {\n get: () => context,\n set() {}\n },\n render: {\n value: render(this, context)\n }\n });\n\n this.set(null, () => {\n Object.defineProperty(this, 'props', {\n value: this.props,\n writable: true\n });\n })\n}\n\n/**\n * Wrap a content element in its context provider, a Suspense boundary (unless\n * `fallback` is `false`) and, when `catch` is set, the host error boundary.\n */\nfunction createFrame(from: Component, context: Context, children: unknown) {\n const { createElement } = Runtime;\n\n if(from.fallback !== false)\n children = createElement(\n Runtime.Suspense,\n { fallback: from.fallback, name: String(from) },\n children\n )\n\n children = createProvider(context, children);\n\n return from.props.catch || from.catch\n ? createElement(Runtime.ErrorBoundary, { self: from, children })\n : children;\n}\n\n/**\n * Ownership host for `<Component/>`: React owns the instance, so its render\n * threads the bootstrap-pushed context through `Runtime.dedupe` (React stacks\n * render attempts) and tears that context down - destroying the instance - on\n * unmount.\n */\nfunction render(from: Component, context: Context) {\n const { createElement, dedupe } = Runtime;\n const attempt = dedupe?.(from, context);\n const { is: owner } = from;\n // Read before bootstrap shadows an instance `render` with this host.\n const own = Object.prototype.hasOwnProperty.call(owner, 'render') && owner.render;\n const teardown = () => {\n attempt?.remove();\n context.pop();\n };\n\n const Render = () => (own || Object.getPrototypeOf(owner).render).call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n const release = owner.mount?.();\n\n attempt?.commit();\n\n return release;\n }, teardown);\n\n return createFrame(from, context, createElement(Render));\n };\n\n return () => createElement(Component);\n}\n\n/** Rewrite each own capitalized function on `target` into a subcomponent. */\nfunction subcomponents(target: object) {\n for (const key of Object.getOwnPropertyNames(target)) {\n if (!/^[A-Z]/.test(key)) continue;\n const { value } = Object.getOwnPropertyDescriptor(target, key)!;\n if (typeof value != 'function') continue;\n Object.defineProperty(target, key, {\n configurable: true,\n get(this: Component) {\n const owner = this.is;\n let render = unbind(value);\n const Component = (props: unknown) =>\n render.call(useWatch(owner), props);\n\n Object.defineProperty(owner, key, {\n configurable: true,\n get: () => Component,\n set(fn: Function) {\n render = fn;\n }\n });\n\n return Component;\n },\n set(this: Component, value: unknown) {\n Object.defineProperty(this, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n\n subcomponents(this);\n }\n });\n }\n}\n\nexport { createFrame };\n","import { Model, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { resolver } from '@expressive/mvc/jsx-runtime';\nimport { useAmbient } from './context';\nimport { Runtime, useFactory, useSettle, useSetup, useWeak } from './runtime';\n\nconst normal = resolver((Type, compute) => {\n const idle = Runtime.idle();\n\n if (idle) return normal(Type, compute);\n\n let ambient: Context;\n\n if (idle === undefined)\n try {\n ambient = useAmbient();\n } catch {\n return normal(Type, compute);\n }\n else ambient = useAmbient();\n\n return Type ? use(ambient, compute) : compute(ambient);\n});\n\nfunction use(local: Context, compute: (context: Context) => unknown) {\n const [tick, next] = Runtime.useState(0);\n const claim = useSettle(tick);\n const dispatch = useWeak(next);\n const render = useFactory(() => {\n let latest = compute;\n let mounted = false;\n let pending = false;\n let force!: () => void;\n let target: unknown;\n let value: unknown;\n let unwatch: (() => void) | undefined;\n let thrown: [unknown] | undefined;\n\n function update() {\n pending = false;\n dispatch.deref()!((x) => x + 1);\n }\n\n function observed() {\n if (mounted) {\n claim();\n update();\n }\n else pending = true;\n }\n\n function follow(found: unknown) {\n if (found === target) return;\n\n unwatch?.();\n unwatch = undefined;\n target = value = found;\n\n if (found instanceof Model && observer(found) !== null) {\n let first = true;\n\n unwatch = watch(\n found,\n (current) => {\n value = current;\n\n if (!first) observed();\n first = false;\n\n return (update) => {\n if (update === true) force();\n };\n },\n false,\n Runtime.startTransition\n );\n }\n\n return true;\n }\n\n function release() {\n unfollow();\n unwatch?.();\n unwatch = target = undefined;\n }\n\n let first = true;\n\n const unfollow = watch(local, (ctx) => {\n try {\n if (follow(latest(ctx)) && !first) observed();\n } catch (error) {\n thrown = [error];\n if (!first) observed();\n }\n }, false);\n\n first = false;\n\n if (thrown) {\n unfollow();\n throw thrown[0];\n }\n\n let fresh = true;\n\n return (next: typeof compute) => {\n pending = false;\n useSetup((_self, reset) => {\n force = reset;\n\n return () => {\n mounted = true;\n if (pending) update();\n return release;\n };\n });\n\n if (!fresh) follow((latest = next)(local));\n\n fresh = false;\n\n return value;\n };\n });\n\n return render(compute);\n}\n"],"mappings":";;;;;AAiCA,MAAa,UAAU,EAAE;AA4BzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA6B,SAAkB;CAC7D,MAAM,MAAM,QAAQ,OAAiB,KAAK;AAC1C,QAAO,IAAI,YAAY,IAAI,UAAU,SAAS;;;;;;;;AAShD,SAAgB,UAAU,MAAc;CACtC,MAAM,MAAM,QAAQ,OAAsB,KAAK;CAC/C,MAAM,SAAS,IAAI,YAAY,IAAI,UAAU;EAC3C,QAAQ;GACN,MAAM,OAAO,SAAS;AAEtB,OAAI,KAAM,EAAC,OAAO,YAAY,EAAE,EAAE,KAAK,KAAK;;EAE9C,UAAU;GACR,MAAM,EAAE,YAAY;AAEpB,OAAI,CAAC,QAAS;AACd,UAAO,UAAU;AAEjB,QAAK,MAAM,QAAQ,QAAS,OAAM;;EAErC;AAED,SAAQ,gBAAgB;AACtB,SAAO,SAAS;AAChB,SAAO,OAAO;IACb,CAAC,KAAK,CAAC;AAEV,QAAO,OAAO;;;;;;;;;;;;AAahB,SAAgB,SACd,MACA,UACA;CACA,MAAM,EAAE,YAAY,QAAQ,OAAO;EAAE,UAAU;EAAG,UAAU;EAAG,CAAM;CAErE,MAAM,CAAC,MAAM,UAAU,QAAQ,eAAe;AAC5C,MAAI,CAAC,QAAQ,SACX,SAAQ,SAAS,KAAK,eAAe;AACnC,WAAQ;IACR;AAEJ,SAAO,QAAQ;GACf;AAEF,SAAQ,SAAS,SAAS;CAE1B,MAAM,cAAe,QAAQ,sBAAsB,QAAQ;AAE3D,SAAQ,QAAQ;AAEhB,SAAQ,uBAAuB,MAAM,aAAa,YAAY;AAE9D,SAAQ,gBAAgB;AACtB,UAAQ,QAAQ;GAChB;AAEF,SAAQ,gBAAgB;AACtB,UAAQ,UAAU;AAClB,UAAQ,SAAS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