@expressive/react 0.87.0 → 0.88.0
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 +1 -1
- package/dist/adapter.js +1 -1
- package/dist/{chunk-component-fgmNhcNc.js → chunk-component-Bu6E8zDP.js} +7 -7
- package/dist/chunk-component-Bu6E8zDP.js.map +1 -0
- package/dist/{chunk-element-DJUrjtdY.js → chunk-element-BwZN13A8.js} +2 -2
- package/dist/{chunk-element-DJUrjtdY.js.map → chunk-element-BwZN13A8.js.map} +1 -1
- package/dist/{chunk-runtime-BAiKyBJZ.d.ts → chunk-runtime-Cn_ynxAT.d.ts} +2 -2
- package/dist/has.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/map.js +2 -2
- package/dist/vite.d.ts +8 -0
- package/dist/vite.js +137 -0
- package/dist/vite.js.map +1 -0
- package/package.json +16 -5
- package/dist/chunk-component-fgmNhcNc.js.map +0 -1
package/dist/adapter.d.ts
CHANGED
package/dist/adapter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Runtime, c as useSetup, i as Provider, l as useWatch, n as Consumer, o as useFactory, s as useSettle } from "./chunk-component-
|
|
1
|
+
import { a as Runtime, c as useSetup, i as Provider, l as useWatch, n as Consumer, o as useFactory, s as useSettle } from "./chunk-component-Bu6E8zDP.js";
|
|
2
2
|
import { Context, State, State as State$1 } from "@expressive/mvc";
|
|
3
3
|
import { observer, watch } from "@expressive/mvc/observable";
|
|
4
4
|
|
|
@@ -223,8 +223,8 @@ Object.defineProperty(Component, "use", {
|
|
|
223
223
|
*
|
|
224
224
|
* - On the root Component, host own-property keys are trapped so each lands as a
|
|
225
225
|
* plain own property (out of observed state); each adapter assigns its own set.
|
|
226
|
-
* - capitalized methods are rewritten into subcomponents as
|
|
227
|
-
*
|
|
226
|
+
* - capitalized methods are rewritten into subcomponents as get/set accessors,
|
|
227
|
+
* so bootstrap skips them too.
|
|
228
228
|
*
|
|
229
229
|
* (Sealing `render` as the content-render seam is handled by core itself.)
|
|
230
230
|
*
|
|
@@ -243,7 +243,7 @@ Component.on({
|
|
|
243
243
|
subcomponents(type.prototype);
|
|
244
244
|
},
|
|
245
245
|
before(self) {
|
|
246
|
-
subcomponents(self
|
|
246
|
+
subcomponents(self);
|
|
247
247
|
}
|
|
248
248
|
});
|
|
249
249
|
function bootstrap(context) {
|
|
@@ -305,13 +305,13 @@ function render(from, context) {
|
|
|
305
305
|
return () => createElement(Component);
|
|
306
306
|
}
|
|
307
307
|
/** Rewrite each own capitalized function on `target` into a subcomponent. */
|
|
308
|
-
function subcomponents(target
|
|
308
|
+
function subcomponents(target) {
|
|
309
309
|
for (const key of Object.getOwnPropertyNames(target)) {
|
|
310
310
|
if (!/^[A-Z]/.test(key)) continue;
|
|
311
311
|
const { value } = Object.getOwnPropertyDescriptor(target, key);
|
|
312
312
|
if (typeof value != "function") continue;
|
|
313
313
|
Object.defineProperty(target, key, {
|
|
314
|
-
configurable,
|
|
314
|
+
configurable: true,
|
|
315
315
|
get() {
|
|
316
316
|
const owner = this.is;
|
|
317
317
|
let render = unbind(value);
|
|
@@ -332,7 +332,7 @@ function subcomponents(target, configurable) {
|
|
|
332
332
|
enumerable: true,
|
|
333
333
|
configurable: true
|
|
334
334
|
});
|
|
335
|
-
subcomponents(this
|
|
335
|
+
subcomponents(this);
|
|
336
336
|
}
|
|
337
337
|
});
|
|
338
338
|
}
|
|
@@ -340,4 +340,4 @@ function subcomponents(target, configurable) {
|
|
|
340
340
|
|
|
341
341
|
//#endregion
|
|
342
342
|
export { Runtime as a, useSetup as c, Provider as i, useWatch as l, Consumer as n, useFactory as o, Context$1 as r, useSettle as s, createFrame as t };
|
|
343
|
-
//# sourceMappingURL=chunk-component-
|
|
343
|
+
//# sourceMappingURL=chunk-component-Bu6E8zDP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-component-Bu6E8zDP.js","names":["Context"],"sources":["../src/runtime.ts","../src/context.ts","../src/component.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}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: (next: (previous: number) => number) => void;\n output: T;\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 transition?(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, set by each adapter (React stacks attempts; others no-op). */\n dedupe(from: Component, context: Context): { commit(): void; remove(): void };\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 Function>(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) {\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 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) current.release?.();\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) current.release?.();\n });\n }\n }, []);\n\n return [current, tick, update] as const;\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) {\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?.((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!((x) => x + 1);\n }\n\n return cleanup;\n };\n });\n\n const claim = useSettle(tick);\n\n current.update = update;\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | 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.transition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n cleanup?.();\n };\n };\n }) ?? from;\n}\n","import { State, Context, Component } from '@expressive/mvc';\nimport type { UseState } from '@expressive/mvc';\nimport { Runtime, useHook } 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\nconst _get = Context.get;\n\nContext.get = (state?: State) => {\n if (!state)\n try {\n return useAmbient();\n } catch { }\n\n return _get(state);\n};\n\ndeclare namespace Consumer {\n type Props<T extends State> = {\n /** Type of controller to fetch from context. */\n for: State.Extends<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `State.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => Component.Node | void;\n };\n}\n\nfunction Consumer<T extends State>(props: Consumer.Props<T>) {\n return props.for.get((i) => props.children(i));\n}\n\ndeclare namespace Provider {\n /**\n * Runs for each State registered by this Provider. Return value is ignored -\n * to run teardown with a State, use `state.set(null, callback)`.\n */\n type ForEach<T> = (state: T) => void;\n\n interface SharedProps {\n /**\n * Children to render within this Provider.\n */\n children?: Component.Node;\n\n /** A fallback tree to show when suspended. */\n fallback?: Component.Node;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n\n type ForSingleProps<T extends State> = SharedProps & {\n for: T | State.Type<T>;\n is: (instance: T) => void;\n } & { [K in State.Property<T>]?: T[K] };\n\n type ForMultipleProps<T extends State> = SharedProps & {\n for: Context.Accept<T>;\n is?: ForEach<T>;\n };\n\n type Props<T extends State = State> = ForSingleProps<T> | ForMultipleProps<T>;\n}\n\ntype Digest<T extends State> = (props: Provider.Props<T>) => Context;\n\nfunction Provider<T extends State>({\n children,\n fallback,\n name,\n ...props\n}: Provider.Props<T>) {\n const ambient = useAmbient();\n const digest: Digest<T> = useHook((returns) => {\n const context = new Context(ambient);\n const fresh: State[] = [];\n\n let applied: Context.Accept<T> | undefined;\n let solo: State | undefined;\n\n returns(({ is, for: input, ...rest }) => {\n if (input !== applied) {\n const single = State.is(input) || input instanceof State;\n\n applied = input;\n solo = undefined;\n\n context.set(input, (state, owned) => {\n if (single) solo = state;\n if (owned) fresh.push(state);\n if (is) is(state);\n });\n }\n\n if (solo && Object.keys(rest).length) solo.set(rest);\n\n return context;\n });\n\n return () => {\n const release = fresh.map((state) => (state as UseState).mount?.());\n\n return () => {\n for (const done of release) if (typeof done == 'function') done();\n context.pop();\n };\n };\n });\n\n return createProvider(\n digest(props),\n fallback !== undefined\n ? Runtime.createElement(Runtime.Suspense, { fallback, name }, children)\n : children\n );\n}\n\nexport { Consumer, Provider, Context, createProvider };\n","import { Component, unbind } from '@expressive/mvc';\nimport { createProvider, type Context } from './context';\nimport { Runtime, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n namespace Component {\n /**\n * Not available - a Component is rendered, not a hook.\n * Render it with `<Component />` or `{component}`.\n * For a bare instance use `Component.new()`.\n */\n const use: never;\n }\n\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(State)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: State.Values<this>;\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\nObject.defineProperty(Component, 'use', {\n configurable: true,\n value() {\n throw new Error(\n `${this} is a Component - render as an element instead of calling use().`\n );\n }\n});\n\n/**\n * `State.on` handler that prepares a Component's prototype at bootstrap, before\n * mvc classifies its members:\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 * - capitalized methods are rewritten into subcomponents as get/set accessors,\n * so bootstrap skips them too.\n *\n * (Sealing `render` as the content-render seam is handled by core itself.)\n *\n * `before` covers the per-instance case: a capitalized function assigned as an\n * instance field (e.g. `Sidebar = Sidebar` to inject or override one), promoted\n * before `observe` so it is not mistaken for reactive state.\n */\nComponent.on({\n type(type) {\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 // capitalized methods into subcomponents\n subcomponents(type.prototype);\n },\n before(self){\n // capitalized instance fields into subcomponents\n subcomponents(self);\n }\n});\n\nfunction bootstrap(this: Component, context: Context){\n context = context.push();\n context.set(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.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 } = Runtime;\n const { commit, remove } = Runtime.dedupe(from, context);\n const { is: owner, render } = from;\n\n const Render = () => render.call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n const release = owner.mount?.();\n\n commit();\n\n return () => {\n if (typeof release == 'function') release();\n remove();\n context.pop();\n };\n });\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"],"mappings":";;;;AA4BA,MAAa,UAAU,EAAE;AA0BzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA+B,SAAkB;CAC/D,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;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;CAEF,MAAM,cAAe,QAAQ,sBAAsB,QAAQ;AAE3D,SAAQ,QAAQ;AAEhB,SAAQ,uBAAuB,MAAM,aAAa,YAAY;AAE9D,SAAQ,gBAAgB;AACtB,UAAQ,QAAQ;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9D;;;;;;;;AASN,SAAS,OAAO,MAAiB,SAAkB;CACjD,MAAM,EAAE,kBAAkB;CAC1B,MAAM,EAAE,QAAQ,WAAW,QAAQ,OAAO,MAAM,QAAQ;CACxD,MAAM,EAAE,IAAI,OAAO,WAAW;CAE9B,MAAM,eAAe,OAAO,KAAK,MAAM,KAAK,MAAM;CAClD,MAAM,kBAAkB;AACtB,SAAO,SAAS,YAAY;GAC1B,MAAM,UAAU,MAAM,SAAS;AAE/B,WAAQ;AAER,gBAAa;AACX,QAAI,OAAO,WAAW,WAAY,UAAS;AAC3C,YAAQ;AACR,YAAQ,KAAK;;IAEf;AAEF,SAAO,YAAY,MAAM,SAAS,cAAc,OAAO,CAAC;;AAG1D,cAAa,cAAc,UAAU;;;AAIvC,SAAS,cAAc,QAAgB;AACrC,MAAK,MAAM,OAAO,OAAO,oBAAoB,OAAO,EAAE;AACpD,MAAI,CAAC,SAAS,KAAK,IAAI,CAAE;EACzB,MAAM,EAAE,UAAU,OAAO,yBAAyB,QAAQ,IAAI;AAC9D,MAAI,OAAO,SAAS,WAAY;AAChC,SAAO,eAAe,QAAQ,KAAK;GACjC,cAAc;GACd,MAAqB;IACnB,MAAM,QAAQ,KAAK;IACnB,IAAI,SAAS,OAAO,MAAM;IAC1B,MAAM,aAAa,UACjB,OAAO,KAAK,SAAS,MAAM,EAAE,MAAM;AAErC,WAAO,eAAe,OAAO,KAAK;KAChC,cAAc;KACd,WAAW;KACX,IAAI,IAAc;AAChB,eAAS;;KAEZ,CAAC;AAEF,WAAO;;GAET,IAAqB,OAAgB;AACnC,WAAO,eAAe,MAAM,KAAK;KAC/B;KACA,UAAU;KACV,YAAY;KACZ,cAAc;KACf,CAAC;AAEF,kBAAc,KAAK;;GAEtB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Runtime, l as useWatch, o as useFactory, r as Context$1, t as createFrame } from "./chunk-component-
|
|
1
|
+
import { a as Runtime, l as useWatch, o as useFactory, r as Context$1, t as createFrame } from "./chunk-component-Bu6E8zDP.js";
|
|
2
2
|
import { Component } from "@expressive/mvc";
|
|
3
3
|
|
|
4
4
|
//#region src/element.ts
|
|
@@ -42,4 +42,4 @@ function Element() {
|
|
|
42
42
|
|
|
43
43
|
//#endregion
|
|
44
44
|
export { seam as t };
|
|
45
|
-
//# sourceMappingURL=chunk-element-
|
|
45
|
+
//# sourceMappingURL=chunk-element-BwZN13A8.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-element-
|
|
1
|
+
{"version":3,"file":"chunk-element-BwZN13A8.js","names":["Context"],"sources":["../src/element.ts"],"sourcesContent":["import { Component } from '@expressive/mvc';\nimport { Context } from './context';\nimport { Runtime, useFactory, useWatch } from './runtime';\nimport { createFrame } from './component';\n\ndeclare module '@expressive/mvc' {\n interface Component {\n /** @deprecated Only to satisfy host JSX. */\n readonly type: typeof Component;\n }\n}\n\nlet template: any;\n\n/**\n * Borrow a host element's descriptors so `self` passes as a React element.\n * `props` false keeps the target's own `props` (Component supplies its own);\n * an object installs it as the element's props (collections have none).\n */\nexport function seam(\n self: object,\n props: object | false,\n type: Function,\n key: unknown\n) {\n if (!template) template = Runtime.createElement('template');\n\n const descriptors = Object.getOwnPropertyDescriptors(template);\n const store = descriptors._store?.value;\n\n if (props === false) delete (descriptors as any).props;\n\n if (store)\n descriptors._store.value = Object.create(\n Object.getPrototypeOf(store),\n Object.getOwnPropertyDescriptors(store)\n );\n\n Object.defineProperties(self, {\n ...descriptors,\n $$typeof: { value: template.$$typeof },\n ...(props ? { props: { value: props } } : undefined),\n key: { value: key },\n type: { value: type }\n });\n\n return template.$$typeof;\n}\n\nObject.defineProperty(Component.prototype, '$$typeof', {\n get(this: Component) {\n const self = this.is;\n return seam(self, false, Element.bind(self), self.key);\n }\n});\n\nfunction Element(this: Component){\n const outer = Context.get();\n const render = useFactory(() => {\n let from = this;\n const context = outer.push(this);\n const Content = () => from.render(from.props);\n\n return () => {\n from = useWatch(this, () => () => context.pop());\n\n return createFrame(from, context, Runtime.createElement(Content));\n };\n });\n\n return render();\n}\n"],"mappings":";;;;AAYA,IAAI;;;;;;AAOJ,SAAgB,KACd,MACA,OACA,MACA,KACA;AACA,KAAI,CAAC,SAAU,YAAW,QAAQ,cAAc,WAAW;CAE3D,MAAM,cAAc,OAAO,0BAA0B,SAAS;CAC9D,MAAM,QAAQ,YAAY,QAAQ;AAElC,KAAI,UAAU,MAAO,QAAQ,YAAoB;AAEjD,KAAI,MACF,aAAY,OAAO,QAAQ,OAAO,OAChC,OAAO,eAAe,MAAM,EAC5B,OAAO,0BAA0B,MAAM,CACxC;AAEH,QAAO,iBAAiB,MAAM;EAC5B,GAAG;EACH,UAAU,EAAE,OAAO,SAAS,UAAU;EACtC,GAAI,QAAQ,EAAE,OAAO,EAAE,OAAO,OAAO,EAAE,GAAG;EAC1C,KAAK,EAAE,OAAO,KAAK;EACnB,MAAM,EAAE,OAAO,MAAM;EACtB,CAAC;AAEF,QAAO,SAAS;;AAGlB,OAAO,eAAe,UAAU,WAAW,YAAY,EACrD,MAAqB;CACnB,MAAM,OAAO,KAAK;AAClB,QAAO,KAAK,MAAM,OAAO,QAAQ,KAAK,KAAK,EAAE,KAAK,IAAI;GAEzD,CAAC;AAEF,SAAS,UAAwB;CAC/B,MAAM,QAAQA,UAAQ,KAAK;AAa3B,QAZe,iBAAiB;EAC9B,IAAI,OAAO;EACX,MAAM,UAAU,MAAM,KAAK,KAAK;EAChC,MAAM,gBAAgB,KAAK,OAAO,KAAK,MAAM;AAE7C,eAAa;AACX,UAAO,SAAS,kBAAkB,QAAQ,KAAK,CAAC;AAEhD,UAAO,YAAY,MAAM,SAAS,QAAQ,cAAc,QAAQ,CAAC;;GAEnE,EAEa"}
|
|
@@ -115,7 +115,7 @@ declare namespace Provider {
|
|
|
115
115
|
type ForSingleProps<T extends State$1> = SharedProps & {
|
|
116
116
|
for: T | State$1.Type<T>;
|
|
117
117
|
is: (instance: T) => void;
|
|
118
|
-
} & { [K in State$1.
|
|
118
|
+
} & { [K in State$1.Property<T>]?: T[K] };
|
|
119
119
|
type ForMultipleProps<T extends State$1> = SharedProps & {
|
|
120
120
|
for: Context$1.Accept<T>;
|
|
121
121
|
is?: ForEach<T>;
|
|
@@ -191,4 +191,4 @@ declare const Runtime: {
|
|
|
191
191
|
};
|
|
192
192
|
//#endregion
|
|
193
193
|
export { Consumer as n, Provider as r, Runtime as t };
|
|
194
|
-
//# sourceMappingURL=chunk-runtime-
|
|
194
|
+
//# sourceMappingURL=chunk-runtime-Cn_ynxAT.d.ts.map
|
package/dist/has.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as useWatch } from "./chunk-component-
|
|
2
|
-
import { t as seam } from "./chunk-element-
|
|
1
|
+
import { l as useWatch } from "./chunk-component-Bu6E8zDP.js";
|
|
2
|
+
import { t as seam } from "./chunk-element-BwZN13A8.js";
|
|
3
3
|
import { has } from "@expressive/mvc";
|
|
4
4
|
|
|
5
5
|
//#region src/has.ts
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as Runtime, i as Provider, n as Consumer } from "./chunk-component-
|
|
1
|
+
import { a as Runtime, i as Provider, n as Consumer } from "./chunk-component-Bu6E8zDP.js";
|
|
2
2
|
import { State } from "./adapter.js";
|
|
3
|
-
import "./chunk-element-
|
|
3
|
+
import "./chunk-element-BwZN13A8.js";
|
|
4
4
|
import { has } from "./has.js";
|
|
5
5
|
import { map } from "./map.js";
|
|
6
6
|
import { Component, Component as Component$1, Context, def, get, pending, ref, set } from "@expressive/mvc";
|
package/dist/map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as useWatch } from "./chunk-component-
|
|
2
|
-
import { t as seam } from "./chunk-element-
|
|
1
|
+
import { l as useWatch } from "./chunk-component-Bu6E8zDP.js";
|
|
2
|
+
import { t as seam } from "./chunk-element-BwZN13A8.js";
|
|
3
3
|
import { map } from "@expressive/mvc";
|
|
4
4
|
|
|
5
5
|
//#region src/map.ts
|
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
|
|
3
|
+
//#region src/vite.ts
|
|
4
|
+
const SOURCE = /\.[cm]?[jt]sx?$/;
|
|
5
|
+
/**
|
|
6
|
+
* Top-level classes a module can reassign, those declaring private members,
|
|
7
|
+
* and its exports by local binding.
|
|
8
|
+
*/
|
|
9
|
+
function scan(body) {
|
|
10
|
+
const classes = [];
|
|
11
|
+
const hidden = [];
|
|
12
|
+
const exports = {};
|
|
13
|
+
function add(name, node) {
|
|
14
|
+
classes.push(name);
|
|
15
|
+
if (node.body.body.some((member) => member.key?.type == "PrivateIdentifier")) hidden.push(name);
|
|
16
|
+
}
|
|
17
|
+
function collect(node) {
|
|
18
|
+
if (node.type == "ClassDeclaration" && node.id) add(node.id.name, node);
|
|
19
|
+
else if (node.type == "VariableDeclaration" && node.kind != "const") {
|
|
20
|
+
for (const { id, init } of node.declarations) if (id.type == "Identifier" && init?.type == "ClassExpression") add(id.name, init);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function names(node) {
|
|
24
|
+
if (node.type == "VariableDeclaration") return node.declarations.flatMap(({ id }) => id.type == "Identifier" ? [id.name] : []);
|
|
25
|
+
return [node.id.name];
|
|
26
|
+
}
|
|
27
|
+
for (const node of body) if (node.type == "ExportNamedDeclaration") {
|
|
28
|
+
if (node.declaration) {
|
|
29
|
+
collect(node.declaration);
|
|
30
|
+
for (const name of names(node.declaration)) exports[name] = name;
|
|
31
|
+
} else if (!node.source) for (const { local, exported } of node.specifiers) exports[exported.name ?? exported.value] = local.name;
|
|
32
|
+
} else if (node.type == "ExportDefaultDeclaration") {
|
|
33
|
+
const { declaration } = node;
|
|
34
|
+
collect(declaration);
|
|
35
|
+
if (declaration.id) exports.default = declaration.id.name;
|
|
36
|
+
} else collect(node);
|
|
37
|
+
return {
|
|
38
|
+
classes,
|
|
39
|
+
hidden,
|
|
40
|
+
exports
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Bind a module's classes to `hot.accept`. A State class it could not patch
|
|
45
|
+
* reloads the page; after an update, a changed component is left to React
|
|
46
|
+
* Refresh and any other changed export invalidates importers.
|
|
47
|
+
*/
|
|
48
|
+
function inject(id, body, ssr = false) {
|
|
49
|
+
const { classes, hidden, exports } = scan(body);
|
|
50
|
+
if (!classes.length) return "";
|
|
51
|
+
const list = classes.join(", ");
|
|
52
|
+
const record = Object.entries(exports).map(([name, local]) => `${JSON.stringify(name)}: ${local}`);
|
|
53
|
+
const effect = ssr ? "replace it instead of patching" : "will trigger a full reload";
|
|
54
|
+
const notes = hidden.map((name) => `${JSON.stringify(name)}: ${JSON.stringify(`[expressive] ${name} (${id}) declares #private members, so edits to its module ${effect}. Use _ properties instead to keep HMR.`)}`);
|
|
55
|
+
const replace = ssr ? ` const __notes = { ${notes.join(", ")} };
|
|
56
|
+
const __before = import.meta.hot.data.expressive;
|
|
57
|
+
const __classes = (import.meta.hot.data.expressive = { ${list} });
|
|
58
|
+
const __warned = (import.meta.hot.data.warned ||= {});
|
|
59
|
+
for (const key in __notes)
|
|
60
|
+
if (__before && __classes[key] !== __before[key] && !__warned[key]) {
|
|
61
|
+
__warned[key] = true;
|
|
62
|
+
console.warn(__notes[key]);
|
|
63
|
+
}
|
|
64
|
+
` : ` const __notes = { ${notes.join(", ")} };
|
|
65
|
+
const __flag = (key) => 'expressive:private:' + ${JSON.stringify(id)} + ':' + key;
|
|
66
|
+
for (const key in __notes)
|
|
67
|
+
try {
|
|
68
|
+
if (sessionStorage.getItem(__flag(key)) == 'due') {
|
|
69
|
+
console.warn(__notes[key]);
|
|
70
|
+
sessionStorage.setItem(__flag(key), 'shown');
|
|
71
|
+
}
|
|
72
|
+
} catch {}
|
|
73
|
+
const __before = import.meta.hot.data.expressive;
|
|
74
|
+
const __classes = (import.meta.hot.data.expressive = { ${list} });
|
|
75
|
+
for (const key in __before)
|
|
76
|
+
if (__classes[key] !== __before[key] && __classes[key]?.prototype instanceof __State) {
|
|
77
|
+
const note = __notes[key];
|
|
78
|
+
if (note)
|
|
79
|
+
try {
|
|
80
|
+
if (!sessionStorage.getItem(__flag(key))) sessionStorage.setItem(__flag(key), 'due');
|
|
81
|
+
} catch {
|
|
82
|
+
console.warn(note);
|
|
83
|
+
}
|
|
84
|
+
dispatchEvent(new CustomEvent('expressive:reload', { detail: { module: ${JSON.stringify(id)}, class: key, reason: note ? 'private members' : 'class changed shape' } }));
|
|
85
|
+
location.reload();
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
return `
|
|
90
|
+
import { hot as __expressive } from '@expressive/mvc/runtime';
|
|
91
|
+
import { State as __State } from '@expressive/mvc';
|
|
92
|
+
{
|
|
93
|
+
const __hot = __expressive.accept(${JSON.stringify(id)}, { ${list} });
|
|
94
|
+
${classes.map((name) => `${name} = __hot.${name};`).join("\n ")}
|
|
95
|
+
}
|
|
96
|
+
if (import.meta.hot) {
|
|
97
|
+
${replace} const __exports = { ${record.join(", ")} };
|
|
98
|
+
import.meta.hot.accept((next) => {
|
|
99
|
+
if (!next) return;
|
|
100
|
+
for (const key in __exports) {
|
|
101
|
+
const after = next[key];
|
|
102
|
+
if (after !== __exports[key] && !(after?.prototype instanceof __State) && (typeof after != 'function' || !/^[A-Z]/.test(after.name)))
|
|
103
|
+
return import.meta.hot.invalidate(\`"\${key}" export cannot be hot-patched.\`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
}
|
|
109
|
+
/** Hot-patch State and Component classes in place during `vite` dev. */
|
|
110
|
+
function expressive() {
|
|
111
|
+
let root = "";
|
|
112
|
+
let runtime;
|
|
113
|
+
return {
|
|
114
|
+
name: "@expressive/react:hot",
|
|
115
|
+
apply: "serve",
|
|
116
|
+
enforce: "post",
|
|
117
|
+
configResolved(config) {
|
|
118
|
+
root = config.root;
|
|
119
|
+
},
|
|
120
|
+
async transform(code, id, options) {
|
|
121
|
+
const [file] = id.split("?");
|
|
122
|
+
if (!SOURCE.test(file) || file.includes("/node_modules/") || !code.includes("class")) return;
|
|
123
|
+
runtime ||= this.resolve("@expressive/mvc/runtime").then((found) => found && dirname(found.id));
|
|
124
|
+
const own = await runtime;
|
|
125
|
+
if (own && file.startsWith(own)) return;
|
|
126
|
+
const output = inject(file.startsWith(root + "/") ? file.slice(root.length) : file, this.parse(code).body, options?.ssr);
|
|
127
|
+
if (output) return {
|
|
128
|
+
code: code + output,
|
|
129
|
+
map: null
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { expressive as default };
|
|
137
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { dirname } from 'node:path';\nimport type { Plugin } from 'vite';\n\ntype Node = { type: string; [key: string]: any };\n\nconst SOURCE = /\\.[cm]?[jt]sx?$/;\n\n/**\n * Top-level classes a module can reassign, those declaring private members,\n * and its exports by local binding.\n */\nfunction scan(body: Node[]) {\n const classes: string[] = [];\n const hidden: string[] = [];\n const exports: Record<string, string> = {};\n\n function add(name: string, node: Node) {\n classes.push(name);\n\n if (node.body.body.some((member: Node) => member.key?.type == 'PrivateIdentifier')) hidden.push(name);\n }\n\n function collect(node: Node) {\n if (node.type == 'ClassDeclaration' && node.id) add(node.id.name, node);\n else if (node.type == 'VariableDeclaration' && node.kind != 'const')\n for (const { id, init } of node.declarations)\n if (id.type == 'Identifier' && init?.type == 'ClassExpression') add(id.name, init);\n }\n\n function names(node: Node): string[] {\n if (node.type == 'VariableDeclaration')\n return node.declarations.flatMap(({ id }: Node) => (id.type == 'Identifier' ? [id.name] : []));\n\n return [node.id.name];\n }\n\n for (const node of body) {\n if (node.type == 'ExportNamedDeclaration') {\n if (node.declaration) {\n collect(node.declaration);\n for (const name of names(node.declaration)) exports[name] = name;\n } else if (!node.source)\n for (const { local, exported } of node.specifiers)\n exports[exported.name ?? exported.value] = local.name;\n } else if (node.type == 'ExportDefaultDeclaration') {\n const { declaration } = node;\n\n collect(declaration);\n\n if (declaration.id) exports.default = declaration.id.name;\n } else collect(node);\n }\n\n return { classes, hidden, exports };\n}\n\n/**\n * Bind a module's classes to `hot.accept`. A State class it could not patch\n * reloads the page; after an update, a changed component is left to React\n * Refresh and any other changed export invalidates importers.\n */\nfunction inject(id: string, body: Node[], ssr = false) {\n const { classes, hidden, exports } = scan(body);\n\n if (!classes.length) return '';\n\n const list = classes.join(', ');\n const record = Object.entries(exports).map(([name, local]) => `${JSON.stringify(name)}: ${local}`);\n const effect = ssr ? 'replace it instead of patching' : 'will trigger a full reload';\n const notes = hidden.map(\n (name) =>\n `${JSON.stringify(name)}: ${JSON.stringify(`[expressive] ${name} (${id}) declares #private members, so edits to its module ${effect}. Use _ properties instead to keep HMR.`)}`\n );\n const replace = ssr\n ? ` const __notes = { ${notes.join(', ')} };\n const __before = import.meta.hot.data.expressive;\n const __classes = (import.meta.hot.data.expressive = { ${list} });\n const __warned = (import.meta.hot.data.warned ||= {});\n for (const key in __notes)\n if (__before && __classes[key] !== __before[key] && !__warned[key]) {\n __warned[key] = true;\n console.warn(__notes[key]);\n }\n`\n : ` const __notes = { ${notes.join(', ')} };\n const __flag = (key) => 'expressive:private:' + ${JSON.stringify(id)} + ':' + key;\n for (const key in __notes)\n try {\n if (sessionStorage.getItem(__flag(key)) == 'due') {\n console.warn(__notes[key]);\n sessionStorage.setItem(__flag(key), 'shown');\n }\n } catch {}\n const __before = import.meta.hot.data.expressive;\n const __classes = (import.meta.hot.data.expressive = { ${list} });\n for (const key in __before)\n if (__classes[key] !== __before[key] && __classes[key]?.prototype instanceof __State) {\n const note = __notes[key];\n if (note)\n try {\n if (!sessionStorage.getItem(__flag(key))) sessionStorage.setItem(__flag(key), 'due');\n } catch {\n console.warn(note);\n }\n dispatchEvent(new CustomEvent('expressive:reload', { detail: { module: ${JSON.stringify(id)}, class: key, reason: note ? 'private members' : 'class changed shape' } }));\n location.reload();\n break;\n }\n`;\n\n return `\nimport { hot as __expressive } from '@expressive/mvc/runtime';\nimport { State as __State } from '@expressive/mvc';\n{\n const __hot = __expressive.accept(${JSON.stringify(id)}, { ${list} });\n ${classes.map((name) => `${name} = __hot.${name};`).join('\\n ')}\n}\nif (import.meta.hot) {\n${replace} const __exports = { ${record.join(', ')} };\n import.meta.hot.accept((next) => {\n if (!next) return;\n for (const key in __exports) {\n const after = next[key];\n if (after !== __exports[key] && !(after?.prototype instanceof __State) && (typeof after != 'function' || !/^[A-Z]/.test(after.name)))\n return import.meta.hot.invalidate(\\`\"\\${key}\" export cannot be hot-patched.\\`);\n }\n });\n}\n`;\n}\n\n/** Hot-patch State and Component classes in place during `vite` dev. */\nexport default function expressive(): Plugin {\n let root = '';\n let runtime: Promise<string | null | undefined> | undefined;\n\n return {\n name: '@expressive/react:hot',\n apply: 'serve',\n enforce: 'post',\n configResolved(config) {\n root = config.root;\n },\n async transform(code, id, options) {\n const [file] = id.split('?');\n\n if (!SOURCE.test(file) || file.includes('/node_modules/') || !code.includes('class'))\n return;\n\n runtime ||= this.resolve('@expressive/mvc/runtime').then((found) => found && dirname(found.id));\n\n const own = await runtime;\n\n if (own && file.startsWith(own)) return;\n\n const output = inject(file.startsWith(root + '/') ? file.slice(root.length) : file, this.parse(code).body as Node[], options?.ssr);\n\n if (output) return { code: code + output, map: null };\n }\n };\n}\n"],"mappings":";;;AAKA,MAAM,SAAS;;;;;AAMf,SAAS,KAAK,MAAc;CAC1B,MAAM,UAAoB,EAAE;CAC5B,MAAM,SAAmB,EAAE;CAC3B,MAAM,UAAkC,EAAE;CAE1C,SAAS,IAAI,MAAc,MAAY;AACrC,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,MAAM,KAAK,MAAM,KAAK,CAAC,MAAgB,SAAS,IAAI;AAElI,OAAI,OAAQ,QAAO;IAAE,MAAM,OAAO;IAAQ,KAAK;IAAM;;EAExD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressive/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.88.0",
|
|
4
4
|
"description": "Class-based reactive state for React. Define models as plain classes; components update when the values they read change.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expressive",
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"./adapter": {
|
|
45
45
|
"types": "./dist/adapter.d.ts",
|
|
46
46
|
"default": "./dist/adapter.js"
|
|
47
|
+
},
|
|
48
|
+
"./vite": {
|
|
49
|
+
"types": "./dist/vite.d.ts",
|
|
50
|
+
"default": "./dist/vite.js"
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
53
|
"engines": {
|
|
@@ -57,7 +61,7 @@
|
|
|
57
61
|
"test": "tsc --noEmit && vitest run --coverage"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
|
-
"@expressive/mvc": "^0.
|
|
64
|
+
"@expressive/mvc": "^0.87.0",
|
|
61
65
|
"@testing-library/react": "^16.3.0",
|
|
62
66
|
"@types/react": "^19",
|
|
63
67
|
"@types/react-dom": "^19",
|
|
@@ -65,10 +69,17 @@
|
|
|
65
69
|
"react": "^19",
|
|
66
70
|
"react-dom": "^19",
|
|
67
71
|
"react-refresh": "^0.18.0",
|
|
68
|
-
"tsdown": "^0.20.1"
|
|
72
|
+
"tsdown": "^0.20.1",
|
|
73
|
+
"vite": "^7.3.1"
|
|
69
74
|
},
|
|
70
75
|
"peerDependencies": {
|
|
71
|
-
"@expressive/mvc": "^0.
|
|
72
|
-
"react": ">=16.14.0 <20.0.0"
|
|
76
|
+
"@expressive/mvc": "^0.87.0",
|
|
77
|
+
"react": ">=16.14.0 <20.0.0",
|
|
78
|
+
"vite": ">=5"
|
|
79
|
+
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"vite": {
|
|
82
|
+
"optional": true
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
85
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-component-fgmNhcNc.js","names":["Context"],"sources":["../src/runtime.ts","../src/context.ts","../src/component.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}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: (next: (previous: number) => number) => void;\n output: T;\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 transition?(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, set by each adapter (React stacks attempts; others no-op). */\n dedupe(from: Component, context: Context): { commit(): void; remove(): void };\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 Function>(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) {\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 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) current.release?.();\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) current.release?.();\n });\n }\n }, []);\n\n return [current, tick, update] as const;\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) {\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?.((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!((x) => x + 1);\n }\n\n return cleanup;\n };\n });\n\n const claim = useSettle(tick);\n\n current.update = update;\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | 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.transition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n cleanup?.();\n };\n };\n }) ?? from;\n}\n","import { State, Context, Component } from '@expressive/mvc';\nimport type { UseState } from '@expressive/mvc';\nimport { Runtime, useHook } 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\nconst _get = Context.get;\n\nContext.get = (state?: State) => {\n if (!state)\n try {\n return useAmbient();\n } catch { }\n\n return _get(state);\n};\n\ndeclare namespace Consumer {\n type Props<T extends State> = {\n /** Type of controller to fetch from context. */\n for: State.Extends<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `State.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => Component.Node | void;\n };\n}\n\nfunction Consumer<T extends State>(props: Consumer.Props<T>) {\n return props.for.get((i) => props.children(i));\n}\n\ndeclare namespace Provider {\n /**\n * Runs for each State registered by this Provider. Return value is ignored -\n * to run teardown with a State, use `state.set(null, callback)`.\n */\n type ForEach<T> = (state: T) => void;\n\n interface SharedProps {\n /**\n * Children to render within this Provider.\n */\n children?: Component.Node;\n\n /** A fallback tree to show when suspended. */\n fallback?: Component.Node;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n\n type ForSingleProps<T extends State> = SharedProps & {\n for: T | State.Type<T>;\n is: (instance: T) => void;\n } & { [K in State.Field<T>]?: T[K] };\n\n type ForMultipleProps<T extends State> = SharedProps & {\n for: Context.Accept<T>;\n is?: ForEach<T>;\n };\n\n type Props<T extends State = State> = ForSingleProps<T> | ForMultipleProps<T>;\n}\n\ntype Digest<T extends State> = (props: Provider.Props<T>) => Context;\n\nfunction Provider<T extends State>({\n children,\n fallback,\n name,\n ...props\n}: Provider.Props<T>) {\n const ambient = useAmbient();\n const digest: Digest<T> = useHook((returns) => {\n const context = new Context(ambient);\n const fresh: State[] = [];\n\n let applied: Context.Accept<T> | undefined;\n let solo: State | undefined;\n\n returns(({ is, for: input, ...rest }) => {\n if (input !== applied) {\n const single = State.is(input) || input instanceof State;\n\n applied = input;\n solo = undefined;\n\n context.set(input, (state, owned) => {\n if (single) solo = state;\n if (owned) fresh.push(state);\n if (is) is(state);\n });\n }\n\n if (solo && Object.keys(rest).length) solo.set(rest);\n\n return context;\n });\n\n return () => {\n const release = fresh.map((state) => (state as UseState).mount?.());\n\n return () => {\n for (const done of release) if (typeof done == 'function') done();\n context.pop();\n };\n };\n });\n\n return createProvider(\n digest(props),\n fallback !== undefined\n ? Runtime.createElement(Runtime.Suspense, { fallback, name }, children)\n : children\n );\n}\n\nexport { Consumer, Provider, Context, createProvider };\n","import { Component, unbind } from '@expressive/mvc';\nimport { createProvider, type Context } from './context';\nimport { Runtime, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n namespace Component {\n /**\n * Not available - a Component is rendered, not a hook.\n * Render it with `<Component />` or `{component}`.\n * For a bare instance use `Component.new()`.\n */\n const use: never;\n }\n\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(State)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: State.Values<this>;\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\nObject.defineProperty(Component, 'use', {\n configurable: true,\n value() {\n throw new Error(\n `${this} is a Component - render as an element instead of calling use().`\n );\n }\n});\n\n/**\n * `State.on` handler that prepares a Component's prototype at bootstrap, before\n * mvc classifies its members:\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 * - capitalized methods are rewritten into subcomponents as non-configurable\n * getters, so bootstrap skips them too.\n *\n * (Sealing `render` as the content-render seam is handled by core itself.)\n *\n * `before` covers the per-instance case: a capitalized function assigned as an\n * instance field (e.g. `Sidebar = Sidebar` to inject or override one), promoted\n * before `observe` so it is not mistaken for reactive state.\n */\nComponent.on({\n type(type) {\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 // capitalized methods into subcomponents\n subcomponents(type.prototype);\n },\n before(self){\n // capitalized instance fields into subcomponents\n subcomponents(self, true);\n }\n});\n\nfunction bootstrap(this: Component, context: Context){\n context = context.push();\n context.set(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.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 } = Runtime;\n const { commit, remove } = Runtime.dedupe(from, context);\n const { is: owner, render } = from;\n\n const Render = () => render.call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n const release = owner.mount?.();\n\n commit();\n\n return () => {\n if (typeof release == 'function') release();\n remove();\n context.pop();\n };\n });\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, configurable?: boolean) {\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,\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, true);\n }\n });\n }\n}\n\nexport { createFrame };\n"],"mappings":";;;;AA4BA,MAAa,UAAU,EAAE;AA0BzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA+B,SAAkB;CAC/D,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;CACA,MAAM,EAAE,YAAY,QAAQ,OAAO;EAAE,UAAU;EAAG,UAAU;EAAG,CAAM;CAErE,MAAM,CAAC,MAAM,UAAU,QAAQ,eAAe;AAC5C,MAAI,CAAC,QAAQ,S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