@expressive/react 0.78.0 → 0.79.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/{runtime.d.ts → adapter.d.ts} +60 -27
- package/dist/{runtime.js → adapter.js} +57 -11
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
- package/dist/context-B-HNZeaN.d.ts +0 -49
- package/dist/context-BfeYQmAX.js +0 -59
- package/dist/context-BfeYQmAX.js.map +0 -1
- package/dist/runtime.js.map +0 -1
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Component, Context, State as State$1, State as State$2 } from "@expressive/mvc";
|
|
2
|
+
import * as react from "react";
|
|
3
3
|
|
|
4
|
-
//#region src/component.d.ts
|
|
5
|
-
declare module '@expressive/mvc' {
|
|
6
|
-
interface Component {
|
|
7
|
-
/** @deprecated Only to satisfy host JSX. Use `this.get(State)` instead. */
|
|
8
|
-
readonly context: Context;
|
|
9
|
-
/** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */
|
|
10
|
-
readonly state: State.Values<this>;
|
|
11
|
-
/** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */
|
|
12
|
-
setState: (state: any, callback?: () => void) => void;
|
|
13
|
-
/** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */
|
|
14
|
-
forceUpdate: (callback?: () => void) => void;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
4
|
//#region src/state.get.d.ts
|
|
19
5
|
/** Type may not be undefined - instead will be null. */
|
|
20
6
|
type NoVoid<T> = T extends undefined | void ? null : T;
|
|
@@ -80,6 +66,62 @@ declare module '@expressive/mvc' {
|
|
|
80
66
|
}
|
|
81
67
|
}
|
|
82
68
|
//#endregion
|
|
69
|
+
//#region src/context.d.ts
|
|
70
|
+
declare namespace Consumer {
|
|
71
|
+
type Props<T extends State$2> = {
|
|
72
|
+
/** Type of controller to fetch from context. */for: State$2.Extends<T>;
|
|
73
|
+
/**
|
|
74
|
+
* Render function, will receive instance of desired controller.
|
|
75
|
+
*
|
|
76
|
+
* Called every render of parent component.
|
|
77
|
+
* Similar to `State.get()`, updates to properties accessed in
|
|
78
|
+
* this function will cause a refresh when they change.
|
|
79
|
+
*/
|
|
80
|
+
children: (value: T) => Component.Node | void;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
declare function Consumer<T extends State$2>(props: Consumer.Props<T>): string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | react.ReactPortal | null;
|
|
84
|
+
declare namespace Provider {
|
|
85
|
+
type ForEach<T> = (state: T) => void | (() => void);
|
|
86
|
+
interface SharedProps {
|
|
87
|
+
/**
|
|
88
|
+
* Children to render within this Provider.
|
|
89
|
+
*/
|
|
90
|
+
children?: Component.Node;
|
|
91
|
+
/** A fallback tree to show when suspended. */
|
|
92
|
+
fallback?: Component.Node;
|
|
93
|
+
/**
|
|
94
|
+
* A name for this Suspense boundary for instrumentation purposes.
|
|
95
|
+
* The name will help identify this boundary in React DevTools.
|
|
96
|
+
*/
|
|
97
|
+
name?: string | undefined;
|
|
98
|
+
}
|
|
99
|
+
type ForSingleProps<T extends State$2> = SharedProps & {
|
|
100
|
+
for: T | State$2.Type<T>;
|
|
101
|
+
is: (instance: T) => void;
|
|
102
|
+
} & { [K in State$2.Field<T>]?: T[K] };
|
|
103
|
+
type ForMultipleProps<T extends State$2> = SharedProps & {
|
|
104
|
+
for: Context.Accept<T>;
|
|
105
|
+
is?: ForEach<T>;
|
|
106
|
+
};
|
|
107
|
+
type Props<T extends State$2 = State$2> = ForSingleProps<T> | ForMultipleProps<T>;
|
|
108
|
+
}
|
|
109
|
+
declare function Provider<T extends State$2>(props: Provider.Props<T>): any;
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/component.d.ts
|
|
112
|
+
declare module '@expressive/mvc' {
|
|
113
|
+
interface Component {
|
|
114
|
+
/** @deprecated Only to satisfy host JSX. Use `this.get(State)` instead. */
|
|
115
|
+
readonly context: Context;
|
|
116
|
+
/** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */
|
|
117
|
+
readonly state: State.Values<this>;
|
|
118
|
+
/** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */
|
|
119
|
+
setState: (state: any, callback?: () => void) => void;
|
|
120
|
+
/** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */
|
|
121
|
+
forceUpdate: (callback?: () => void) => void;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
83
125
|
//#region src/runtime.d.ts
|
|
84
126
|
declare const Runtime: {
|
|
85
127
|
/** Host own-property keys to trap out of observed state; assigned by each adapter. */ignore: string[];
|
|
@@ -98,17 +140,8 @@ declare const Runtime: {
|
|
|
98
140
|
ErrorBoundary: unknown;
|
|
99
141
|
Suspense: any;
|
|
100
142
|
};
|
|
101
|
-
declare function useFactory<T extends Function>(factory: () => T): T;
|
|
102
|
-
declare function useReady<T>(callback: () => void): void;
|
|
103
|
-
/**
|
|
104
|
-
* Mount-effect with a refreshable return value, safe under React StrictMode.
|
|
105
|
-
*
|
|
106
|
-
* @param callback Setup handler; receives a setter, must return a cleanup.
|
|
107
|
-
* @returns Latest value published via the setter (`undefined` until set).
|
|
108
|
-
*/
|
|
109
|
-
declare function useHook<T = void>(callback: (refresh: (next: T) => void) => () => void): T;
|
|
110
143
|
/** Subscribe to an existing observable instance within a component. */
|
|
111
144
|
declare function use<T extends object>(subject: T): T;
|
|
112
145
|
//#endregion
|
|
113
|
-
export { Consumer,
|
|
114
|
-
//# sourceMappingURL=
|
|
146
|
+
export { Consumer, Provider, Runtime, State$1 as State, use };
|
|
147
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { State, event, observer, watch } from "@expressive/mvc";
|
|
1
|
+
import { Component, Context, State, State as State$1, event, observer, watch } from "@expressive/mvc";
|
|
3
2
|
|
|
4
3
|
//#region src/runtime.ts
|
|
5
4
|
const Runtime = {};
|
|
6
|
-
function useFactory(factory) {
|
|
7
|
-
const ref = Runtime.useRef(null);
|
|
8
|
-
return ref.current || (ref.current = factory());
|
|
9
|
-
}
|
|
10
|
-
function useReady(callback) {
|
|
11
|
-
return Runtime.useEffect(() => void callback(), []);
|
|
12
|
-
}
|
|
13
5
|
/**
|
|
14
6
|
* Mount-effect with a refreshable return value, safe under React StrictMode.
|
|
15
7
|
*
|
|
@@ -70,5 +62,59 @@ function use(subject) {
|
|
|
70
62
|
}
|
|
71
63
|
|
|
72
64
|
//#endregion
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
//#region src/context.ts
|
|
66
|
+
let shared;
|
|
67
|
+
/**
|
|
68
|
+
* Lazily-created context carrying the active {@link Context} down the tree.
|
|
69
|
+
* Lazy because the framework's `createContext` arrives via {@link Runtime},
|
|
70
|
+
* which an adapter's entry populates at load - after this module evaluates.
|
|
71
|
+
*/
|
|
72
|
+
function Layers() {
|
|
73
|
+
return shared || (shared = Runtime.createContext(Context.root));
|
|
74
|
+
}
|
|
75
|
+
/** Read the ambient {@link Context} from the nearest Layers provider. */
|
|
76
|
+
function useAmbient() {
|
|
77
|
+
return Runtime.useContext(Layers());
|
|
78
|
+
}
|
|
79
|
+
/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */
|
|
80
|
+
function provide(context, children) {
|
|
81
|
+
return Runtime.createElement(Layers().Provider, {
|
|
82
|
+
value: context,
|
|
83
|
+
children
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
Object.defineProperty(Component, "contextType", {
|
|
87
|
+
configurable: true,
|
|
88
|
+
get: Layers
|
|
89
|
+
});
|
|
90
|
+
const _get = Context.get;
|
|
91
|
+
Context.get = (state) => {
|
|
92
|
+
if (!state) try {
|
|
93
|
+
return useAmbient();
|
|
94
|
+
} catch {}
|
|
95
|
+
return _get(state);
|
|
96
|
+
};
|
|
97
|
+
function Consumer(props) {
|
|
98
|
+
return props.for.get((i) => props.children(i));
|
|
99
|
+
}
|
|
100
|
+
function Provider(props) {
|
|
101
|
+
const { for: input, children, fallback, name, is, ...rest } = props;
|
|
102
|
+
const ambient = useAmbient();
|
|
103
|
+
const context = useHook((set) => {
|
|
104
|
+
set(new Context(ambient));
|
|
105
|
+
return () => context.pop();
|
|
106
|
+
});
|
|
107
|
+
context.set(input, is);
|
|
108
|
+
if (Object.keys(rest).length) {
|
|
109
|
+
const i = State$1.is(input) ? context.get(input) : input;
|
|
110
|
+
if (i instanceof State$1) i.set(rest);
|
|
111
|
+
}
|
|
112
|
+
return provide(context, fallback !== void 0 ? Runtime.createElement(Runtime.Suspense, {
|
|
113
|
+
fallback,
|
|
114
|
+
name
|
|
115
|
+
}, children) : children);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { Consumer, Provider, Runtime, State, use };
|
|
120
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","names":["State"],"sources":["../src/runtime.ts","../src/context.ts"],"sourcesContent":["import { event, watch, observer } from '@expressive/mvc';\nimport type { Component } from '@expressive/mvc';\nimport type { Context } from './context';\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 /** 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\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\nexport function useReady<T>(callback: () => void) {\n return Runtime.useEffect(() => void callback(), []);\n}\n\n/**\n * Mount-effect with a refreshable return value, safe under React StrictMode.\n *\n * @param callback Setup handler; receives a setter, must return a cleanup.\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (refresh: (next: T) => void) => () => void\n) {\n const { current } = Runtime.useRef(\n { rendered: 0 } as {\n rendered: number;\n mounted?: boolean;\n pending?: boolean;\n unmount: () => void;\n update?: (next: (previous: number) => number) => void;\n output: T;\n }\n );\n\n current.update = Runtime.useState(() => {\n if (!current.rendered)\n current.unmount = callback((next) => {\n current.output = next;\n if (current.mounted) current.update?.((x) => x + 1);\n else if (current.update) current.pending = true;\n });\n\n return current.rendered++;\n })[1];\n\n Runtime.useEffect(() => {\n current.mounted = true;\n if (current.pending) {\n current.pending = false;\n current.update!((x) => x + 1);\n }\n return () => {\n if (--current.rendered < 1) current.unmount();\n }\n }, []);\n\n return current.output;\n}\n\n/** Subscribe to an existing observable instance within a component. */\nexport function use<T extends object>(subject: T) {\n const { current } = Runtime.useRef<{\n proxy: T;\n source?: T;\n mounted: number;\n unwatch?: () => void;\n }>({ mounted: 0, proxy: subject });\n\n const update = Runtime.useState(() => current.mounted++)[1];\n\n if (current.source !== subject) {\n const status = observer(subject);\n\n if (status === undefined)\n throw new Error('Provided object is not observable.');\n\n current.unwatch?.();\n current.source = subject;\n\n if (status === null) {\n current.unwatch = undefined;\n current.proxy = subject;\n } else {\n if (!status.ready) event(subject);\n\n let init = true;\n\n current.unwatch = watch(subject, (next, changed) => {\n current.proxy = next;\n if (changed.length && !init)\n update((x) => x + 1);\n });\n\n init = false;\n }\n }\n\n Runtime.useEffect(() => () => {\n if (--current.mounted < 1) current.unwatch?.();\n }, []);\n\n return current.proxy;\n}\n","import { State, Context, Component } 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 provide(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 type ForEach<T> = (state: T) => void | (() => 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\nfunction Provider<T extends State>(props: Provider.Props<T>) {\n const {\n for: input,\n children,\n fallback,\n name,\n is,\n ...rest\n } = props as Provider.ForSingleProps<T> & Provider.ForMultipleProps<T>;\n\n const ambient = useAmbient();\n const context = useHook<Context>((set) => {\n set(new Context(ambient));\n return () => context.pop();\n });\n\n context.set(input, is);\n\n if (Object.keys(rest).length) {\n const i = State.is(input) ? context.get(input) : input;\n if (i instanceof State) i.set(rest);\n }\n\n return provide(context,\n fallback !== undefined\n ? Runtime.createElement(Runtime.Suspense, { fallback, name }, children)\n : children\n );\n}\n\nexport { Consumer, Provider, Context, provide };\n"],"mappings":";;;AAIA,MAAa,UAAU,EAAE;;;;;;;AA+BzB,SAAgB,QACd,UACA;CACA,MAAM,EAAE,YAAY,QAAQ,OAC1B,EAAE,UAAU,GAAG,CAQhB;AAED,SAAQ,SAAS,QAAQ,eAAe;AACtC,MAAI,CAAC,QAAQ,SACX,SAAQ,UAAU,UAAU,SAAS;AACnC,WAAQ,SAAS;AACjB,OAAI,QAAQ,QAAS,SAAQ,UAAU,MAAM,IAAI,EAAE;YAC1C,QAAQ,OAAQ,SAAQ,UAAU;IAC3C;AAEJ,SAAO,QAAQ;GACf,CAAC;AAEH,SAAQ,gBAAgB;AACtB,UAAQ,UAAU;AAClB,MAAI,QAAQ,SAAS;AACnB,WAAQ,UAAU;AAClB,WAAQ,QAAS,MAAM,IAAI,EAAE;;AAE/B,eAAa;AACX,OAAI,EAAE,QAAQ,WAAW,EAAG,SAAQ,SAAS;;IAE9C,EAAE,CAAC;AAEN,QAAO,QAAQ;;;AAIjB,SAAgB,IAAsB,SAAY;CAChD,MAAM,EAAE,YAAY,QAAQ,OAKzB;EAAE,SAAS;EAAG,OAAO;EAAS,CAAC;CAElC,MAAM,SAAS,QAAQ,eAAe,QAAQ,UAAU,CAAC;AAEzD,KAAI,QAAQ,WAAW,SAAS;EAC9B,MAAM,SAAS,SAAS,QAAQ;AAEhC,MAAI,WAAW,OACb,OAAM,IAAI,MAAM,qCAAqC;AAEvD,UAAQ,WAAW;AACnB,UAAQ,SAAS;AAEjB,MAAI,WAAW,MAAM;AACnB,WAAQ,UAAU;AAClB,WAAQ,QAAQ;SACX;AACL,OAAI,CAAC,OAAO,MAAO,OAAM,QAAQ;GAEjC,IAAI,OAAO;AAEX,WAAQ,UAAU,MAAM,UAAU,MAAM,YAAY;AAClD,YAAQ,QAAQ;AAChB,QAAI,QAAQ,UAAU,CAAC,KACrB,SAAQ,MAAM,IAAI,EAAE;KACtB;AAEF,UAAO;;;AAIX,SAAQ,sBAAsB;AAC5B,MAAI,EAAE,QAAQ,UAAU,EAAG,SAAQ,WAAW;IAC7C,EAAE,CAAC;AAEN,QAAO,QAAQ;;;;;ACjHjB,IAAI;;;;;;AAOJ,SAAS,SAAS;AAChB,QAAO,WAAW,SAAS,QAAQ,cAAc,QAAQ,KAAK;;;AAIhE,SAAS,aAAa;AACpB,QAAO,QAAQ,WAAW,QAAQ,CAAC;;;AAIrC,SAAS,QAAQ,SAAkB,UAAe;AAChD,QAAO,QAAQ,cAAc,QAAQ,CAAC,UAAU;EAAE,OAAO;EAAS;EAAU,CAAC;;AAI/E,OAAO,eAAe,WAAW,eAAe;CAAE,cAAc;CAAM,KAAK;CAAQ,CAAC;AAEpF,MAAM,OAAO,QAAQ;AAErB,QAAQ,OAAO,UAAkB;AAC/B,KAAI,CAAC,MACH,KAAI;AACF,SAAO,YAAY;SACb;AAEV,QAAO,KAAK,MAAM;;AAmBpB,SAAS,SAA0B,OAA0B;AAC3D,QAAO,MAAM,IAAI,KAAK,MAAM,MAAM,SAAS,EAAE,CAAC;;AAmChD,SAAS,SAA0B,OAA0B;CAC3D,MAAM,EACJ,KAAK,OACL,UACA,UACA,MACA,IACA,GAAG,SACD;CAEJ,MAAM,UAAU,YAAY;CAC5B,MAAM,UAAU,SAAkB,QAAQ;AACxC,MAAI,IAAI,QAAQ,QAAQ,CAAC;AACzB,eAAa,QAAQ,KAAK;GAC1B;AAEF,SAAQ,IAAI,OAAO,GAAG;AAEtB,KAAI,OAAO,KAAK,KAAK,CAAC,QAAQ;EAC5B,MAAM,IAAIA,QAAM,GAAG,MAAM,GAAG,QAAQ,IAAI,MAAM,GAAG;AACjD,MAAI,aAAaA,QAAO,GAAE,IAAI,KAAK;;AAGrC,QAAO,QAAQ,SACb,aAAa,SACT,QAAQ,cAAc,QAAQ,UAAU;EAAE;EAAU;EAAM,EAAE,SAAS,GACrE,SACL"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { r as Provider, t as Consumer } from "./context-B-HNZeaN.js";
|
|
2
1
|
import { Component, Context, Observer, def, get, hot, ref, set } from "@expressive/mvc";
|
|
3
2
|
import { JSX, ReactNode } from "react";
|
|
4
|
-
import { State, State as
|
|
3
|
+
import { Consumer, Provider, State, State as adapter_default, use } from "./adapter";
|
|
5
4
|
|
|
6
5
|
//#region src/jsx-runtime.d.ts
|
|
7
6
|
declare module '@expressive/mvc/jsx-runtime' {
|
|
@@ -11,5 +10,5 @@ declare module '@expressive/mvc/jsx-runtime' {
|
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
//#endregion
|
|
14
|
-
export { Component, Consumer, Context, Observer, Provider, State, def,
|
|
13
|
+
export { Component, Consumer, Context, Observer, Provider, State, def, adapter_default as default, get, hot, ref, set, use };
|
|
15
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { r as Provider, t as Consumer } from "./context-BfeYQmAX.js";
|
|
2
1
|
import { Component, Component as Component$1, Context, Observer, def, get, hot, ref, set } from "@expressive/mvc";
|
|
3
2
|
import React, { Children, Suspense, createContext, createElement, isValidElement, useContext, useEffect, useRef, useState } from "react";
|
|
4
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
4
|
import { host } from "@expressive/mvc/jsx-runtime";
|
|
6
|
-
import { Runtime, State, State as
|
|
5
|
+
import { Consumer, Provider, Runtime, State, State as adapter_default, use } from "./adapter";
|
|
7
6
|
|
|
8
7
|
//#region src/jsx-runtime.ts
|
|
9
8
|
host({
|
|
@@ -106,5 +105,5 @@ Object.assign(Runtime, {
|
|
|
106
105
|
});
|
|
107
106
|
|
|
108
107
|
//#endregion
|
|
109
|
-
export { Component, Consumer, Context, Observer, Provider, State, def,
|
|
108
|
+
export { Component, Consumer, Context, Observer, Provider, State, def, adapter_default as default, get, hot, ref, set, use };
|
|
110
109
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Component"],"sources":["../src/jsx-runtime.ts","../src/boundary.ts","../src/index.ts"],"sourcesContent":["import { Children, isValidElement } from 'react';\nimport { Fragment, jsx, jsxs } from 'react/jsx-runtime';\nimport { host } from '@expressive/mvc/jsx-runtime';\n\nimport type { Component } from '@expressive/mvc';\nimport type { JSX as ReactJSX, ReactNode } from 'react';\n\ndeclare module '@expressive/mvc/jsx-runtime' {\n interface Host {\n node: ReactNode;\n intrinsics: ReactJSX.IntrinsicElements;\n }\n}\n\nhost({\n jsx,\n jsxs,\n Fragment,\n isElement: isValidElement,\n childrenOf(children): Component.Node[] {\n return Children.toArray(children as React.ReactNode);\n },\n typeOf(node){\n return isValidElement(node) ? node.type : undefined;\n },\n propsOf(node){\n return isValidElement(node) ? node.props as Record<string, unknown> : {};\n }\n});\n","import { Component } from '@expressive/mvc';\nimport React from 'react';\nimport { Context } from './context';\n\ninterface Entry {\n committed?: boolean;\n context: Context;\n commit: () => void;\n remove: () => void;\n};\n\n/** In-flight render attempts by tree position, per ambient context.\n * When one commits, older uncommitted attempts at its slot are provably dead. */\nconst SLOTS = new WeakMap<Context, Map<string, Set<Entry>>>();\n\n/**\n * React's attempt lifecycle: fiber-keyed stacking so a superseded (uncommitted)\n * render attempt at a tree position is discarded when a later one commits.\n */\nexport function dedupe(on: Component, context: Context) {\n let slots = SLOTS.get(context.parent!);\n if (!slots) SLOTS.set(context.parent!, (slots = new Map()));\n\n // key/index path to root: stable across render attempts of this element\n let slot = '';\n for (let f = (on as any)._reactInternals; f; f = f.return)\n slot += (f.key ?? f.index) + '.';\n\n let list = slots.get(slot);\n if (!list) slots.set(slot, (list = new Set()));\n\n const entry: Entry = {\n context,\n commit() {\n entry.committed = true;\n\n for (const e of list) {\n if (e === entry) break;\n if (e.committed) continue;\n e.context.pop();\n list.delete(e);\n }\n },\n remove() {\n list.delete(entry);\n }\n };\n\n list.add(entry);\n return entry;\n};\n\nexport class ErrorBoundary extends React.Component<{\n self: Component;\n children: React.ReactNode;\n}> {\n state = {} as { error?: Error };\n recovering = false;\n\n constructor(props: ErrorBoundary['props']) {\n super(props);\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n const { self } = this.props;\n const { fallback } = self;\n const reset = (error?: Error) => {\n this.recovering = true;\n this.setState({ error });\n };\n\n Promise.resolve(self.catch!(error))\n .then(() => reset(), reset)\n .finally(() => self.set({ fallback }, true));\n }\n\n componentDidUpdate() {\n this.recovering = false;\n }\n\n render() {\n if (!this.state.error) return this.props.children;\n if (this.recovering) throw this.state.error;\n return this.props.self.fallback;\n }\n};\n","import { Component } from '@expressive/mvc';\nimport {\n createContext,\n createElement,\n Suspense,\n useContext,\n useEffect,\n useRef,\n useState\n} from 'react';\n\nimport './jsx-runtime';\nimport { Runtime } from './
|
|
1
|
+
{"version":3,"file":"index.js","names":["Component"],"sources":["../src/jsx-runtime.ts","../src/boundary.ts","../src/index.ts"],"sourcesContent":["import { Children, isValidElement } from 'react';\nimport { Fragment, jsx, jsxs } from 'react/jsx-runtime';\nimport { host } from '@expressive/mvc/jsx-runtime';\n\nimport type { Component } from '@expressive/mvc';\nimport type { JSX as ReactJSX, ReactNode } from 'react';\n\ndeclare module '@expressive/mvc/jsx-runtime' {\n interface Host {\n node: ReactNode;\n intrinsics: ReactJSX.IntrinsicElements;\n }\n}\n\nhost({\n jsx,\n jsxs,\n Fragment,\n isElement: isValidElement,\n childrenOf(children): Component.Node[] {\n return Children.toArray(children as React.ReactNode);\n },\n typeOf(node){\n return isValidElement(node) ? node.type : undefined;\n },\n propsOf(node){\n return isValidElement(node) ? node.props as Record<string, unknown> : {};\n }\n});\n","import { Component } from '@expressive/mvc';\nimport React from 'react';\nimport { Context } from './context';\n\ninterface Entry {\n committed?: boolean;\n context: Context;\n commit: () => void;\n remove: () => void;\n};\n\n/** In-flight render attempts by tree position, per ambient context.\n * When one commits, older uncommitted attempts at its slot are provably dead. */\nconst SLOTS = new WeakMap<Context, Map<string, Set<Entry>>>();\n\n/**\n * React's attempt lifecycle: fiber-keyed stacking so a superseded (uncommitted)\n * render attempt at a tree position is discarded when a later one commits.\n */\nexport function dedupe(on: Component, context: Context) {\n let slots = SLOTS.get(context.parent!);\n if (!slots) SLOTS.set(context.parent!, (slots = new Map()));\n\n // key/index path to root: stable across render attempts of this element\n let slot = '';\n for (let f = (on as any)._reactInternals; f; f = f.return)\n slot += (f.key ?? f.index) + '.';\n\n let list = slots.get(slot);\n if (!list) slots.set(slot, (list = new Set()));\n\n const entry: Entry = {\n context,\n commit() {\n entry.committed = true;\n\n for (const e of list) {\n if (e === entry) break;\n if (e.committed) continue;\n e.context.pop();\n list.delete(e);\n }\n },\n remove() {\n list.delete(entry);\n }\n };\n\n list.add(entry);\n return entry;\n};\n\nexport class ErrorBoundary extends React.Component<{\n self: Component;\n children: React.ReactNode;\n}> {\n state = {} as { error?: Error };\n recovering = false;\n\n constructor(props: ErrorBoundary['props']) {\n super(props);\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n const { self } = this.props;\n const { fallback } = self;\n const reset = (error?: Error) => {\n this.recovering = true;\n this.setState({ error });\n };\n\n Promise.resolve(self.catch!(error))\n .then(() => reset(), reset)\n .finally(() => self.set({ fallback }, true));\n }\n\n componentDidUpdate() {\n this.recovering = false;\n }\n\n render() {\n if (!this.state.error) return this.props.children;\n if (this.recovering) throw this.state.error;\n return this.props.self.fallback;\n }\n};\n","import { Component } from '@expressive/mvc';\nimport {\n createContext,\n createElement,\n Suspense,\n useContext,\n useEffect,\n useRef,\n useState\n} from 'react';\n\nimport './jsx-runtime';\nimport { Runtime } from './adapter';\nimport { ErrorBoundary, dedupe } from './boundary';\n\n// React detects class components by this brand (preact reads `prototype.render`).\nObject.defineProperty(Component.prototype, 'isReactComponent', {\n value: true\n});\n\nObject.assign(Runtime, {\n dedupe,\n ErrorBoundary,\n createElement,\n createContext,\n useContext,\n useEffect,\n useState,\n useRef,\n Suspense,\n ignore: [\n 'updater',\n 'refs',\n '_reactInternals',\n '_reactInternalInstance'\n ]\n});\n\nexport { State, State as default, use, Consumer, Provider } from './adapter';\nexport { Component, Context, Observer, def, get, ref, set, hot } from '@expressive/mvc';\n"],"mappings":";;;;;;;AAcA,KAAK;CACH;CACA;CACA;CACA,WAAW;CACX,WAAW,UAA4B;AACrC,SAAO,SAAS,QAAQ,SAA4B;;CAEtD,OAAO,MAAK;AACV,SAAO,eAAe,KAAK,GAAG,KAAK,OAAO;;CAE5C,QAAQ,MAAK;AACX,SAAO,eAAe,KAAK,GAAG,KAAK,QAAmC,EAAE;;CAE3E,CAAC;;;;;;ACfF,MAAM,wBAAQ,IAAI,SAA2C;;;;;AAM7D,SAAgB,OAAO,IAAe,SAAkB;CACtD,IAAI,QAAQ,MAAM,IAAI,QAAQ,OAAQ;AACtC,KAAI,CAAC,MAAO,OAAM,IAAI,QAAQ,QAAU,wBAAQ,IAAI,KAAK,CAAE;CAG3D,IAAI,OAAO;AACX,MAAK,IAAI,IAAK,GAAW,iBAAiB,GAAG,IAAI,EAAE,OACjD,UAAS,EAAE,OAAO,EAAE,SAAS;CAE/B,IAAI,OAAO,MAAM,IAAI,KAAK;AAC1B,KAAI,CAAC,KAAM,OAAM,IAAI,MAAO,uBAAO,IAAI,KAAK,CAAE;CAE9C,MAAM,QAAe;EACnB;EACA,SAAS;AACP,SAAM,YAAY;AAElB,QAAK,MAAM,KAAK,MAAM;AACpB,QAAI,MAAM,MAAO;AACjB,QAAI,EAAE,UAAW;AACjB,MAAE,QAAQ,KAAK;AACf,SAAK,OAAO,EAAE;;;EAGlB,SAAS;AACP,QAAK,OAAO,MAAM;;EAErB;AAED,MAAK,IAAI,MAAM;AACf,QAAO;;AAGT,IAAa,gBAAb,cAAmC,MAAM,UAGtC;CAID,YAAY,OAA+B;AACzC,QAAM,MAAM;eAJN,EAAE;oBACG;;CAMb,OAAO,yBAAyB,OAAc;AAC5C,SAAO,EAAE,OAAO;;CAGlB,kBAAkB,OAAc;EAC9B,MAAM,EAAE,SAAS,KAAK;EACtB,MAAM,EAAE,aAAa;EACrB,MAAM,SAAS,UAAkB;AAC/B,QAAK,aAAa;AAClB,QAAK,SAAS,EAAE,OAAO,CAAC;;AAG1B,UAAQ,QAAQ,KAAK,MAAO,MAAM,CAAC,CAChC,WAAW,OAAO,EAAE,MAAM,CAC1B,cAAc,KAAK,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC;;CAGhD,qBAAqB;AACnB,OAAK,aAAa;;CAGpB,SAAS;AACP,MAAI,CAAC,KAAK,MAAM,MAAO,QAAO,KAAK,MAAM;AACzC,MAAI,KAAK,WAAY,OAAM,KAAK,MAAM;AACtC,SAAO,KAAK,MAAM,KAAK;;;;;;ACvE3B,OAAO,eAAeA,YAAU,WAAW,oBAAoB,EAC7D,OAAO,MACR,CAAC;AAEF,OAAO,OAAO,SAAS;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,QAAQ;EACN;EACA;EACA;EACA;EACD;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressive/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.79.0",
|
|
4
4
|
"description": "Use classes to define state in React!",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expressive",
|
|
@@ -23,10 +23,7 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"sideEffects": [
|
|
25
25
|
"./dist/index.js",
|
|
26
|
-
"./dist/
|
|
27
|
-
"./dist/component.js",
|
|
28
|
-
"./dist/state.get.js",
|
|
29
|
-
"./dist/state.use.js",
|
|
26
|
+
"./dist/adapter.js",
|
|
30
27
|
"./src/jsx-runtime.ts"
|
|
31
28
|
],
|
|
32
29
|
"main": "dist/index.js",
|
|
@@ -36,9 +33,9 @@
|
|
|
36
33
|
"types": "./dist/index.d.ts",
|
|
37
34
|
"default": "./dist/index.js"
|
|
38
35
|
},
|
|
39
|
-
"./
|
|
40
|
-
"types": "./dist/
|
|
41
|
-
"default": "./dist/
|
|
36
|
+
"./adapter": {
|
|
37
|
+
"types": "./dist/adapter.d.ts",
|
|
38
|
+
"default": "./dist/adapter.js"
|
|
42
39
|
}
|
|
43
40
|
},
|
|
44
41
|
"engines": {
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Component, Context, State } from "@expressive/mvc";
|
|
2
|
-
import * as react from "react";
|
|
3
|
-
|
|
4
|
-
//#region src/context.d.ts
|
|
5
|
-
/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */
|
|
6
|
-
declare function provide(context: Context, children: any): any;
|
|
7
|
-
declare namespace Consumer {
|
|
8
|
-
type Props<T extends State> = {
|
|
9
|
-
/** Type of controller to fetch from context. */for: State.Extends<T>;
|
|
10
|
-
/**
|
|
11
|
-
* Render function, will receive instance of desired controller.
|
|
12
|
-
*
|
|
13
|
-
* Called every render of parent component.
|
|
14
|
-
* Similar to `State.get()`, updates to properties accessed in
|
|
15
|
-
* this function will cause a refresh when they change.
|
|
16
|
-
*/
|
|
17
|
-
children: (value: T) => Component.Node | void;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
declare function Consumer<T extends State>(props: Consumer.Props<T>): string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | react.ReactPortal | null;
|
|
21
|
-
declare namespace Provider {
|
|
22
|
-
type ForEach<T> = (state: T) => void | (() => void);
|
|
23
|
-
interface SharedProps {
|
|
24
|
-
/**
|
|
25
|
-
* Children to render within this Provider.
|
|
26
|
-
*/
|
|
27
|
-
children?: Component.Node;
|
|
28
|
-
/** A fallback tree to show when suspended. */
|
|
29
|
-
fallback?: Component.Node;
|
|
30
|
-
/**
|
|
31
|
-
* A name for this Suspense boundary for instrumentation purposes.
|
|
32
|
-
* The name will help identify this boundary in React DevTools.
|
|
33
|
-
*/
|
|
34
|
-
name?: string | undefined;
|
|
35
|
-
}
|
|
36
|
-
type ForSingleProps<T extends State> = SharedProps & {
|
|
37
|
-
for: T | State.Type<T>;
|
|
38
|
-
is: (instance: T) => void;
|
|
39
|
-
} & { [K in State.Field<T>]?: T[K] };
|
|
40
|
-
type ForMultipleProps<T extends State> = SharedProps & {
|
|
41
|
-
for: Context.Accept<T>;
|
|
42
|
-
is?: ForEach<T>;
|
|
43
|
-
};
|
|
44
|
-
type Props<T extends State = State> = ForSingleProps<T> | ForMultipleProps<T>;
|
|
45
|
-
}
|
|
46
|
-
declare function Provider<T extends State>(props: Provider.Props<T>): any;
|
|
47
|
-
//#endregion
|
|
48
|
-
export { provide as i, Context as n, Provider as r, Consumer as t };
|
|
49
|
-
//# sourceMappingURL=context-B-HNZeaN.d.ts.map
|
package/dist/context-BfeYQmAX.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Component, Context, State } from "@expressive/mvc";
|
|
2
|
-
import { Runtime, useHook } from "./runtime";
|
|
3
|
-
|
|
4
|
-
//#region src/context.ts
|
|
5
|
-
let shared;
|
|
6
|
-
/**
|
|
7
|
-
* Lazily-created context carrying the active {@link Context} down the tree.
|
|
8
|
-
* Lazy because the framework's `createContext` arrives via {@link Runtime},
|
|
9
|
-
* which an adapter's entry populates at load - after this module evaluates.
|
|
10
|
-
*/
|
|
11
|
-
function Layers() {
|
|
12
|
-
return shared || (shared = Runtime.createContext(Context.root));
|
|
13
|
-
}
|
|
14
|
-
/** Read the ambient {@link Context} from the nearest Layers provider. */
|
|
15
|
-
function useAmbient() {
|
|
16
|
-
return Runtime.useContext(Layers());
|
|
17
|
-
}
|
|
18
|
-
/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */
|
|
19
|
-
function provide(context, children) {
|
|
20
|
-
return Runtime.createElement(Layers().Provider, {
|
|
21
|
-
value: context,
|
|
22
|
-
children
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(Component, "contextType", {
|
|
26
|
-
configurable: true,
|
|
27
|
-
get: Layers
|
|
28
|
-
});
|
|
29
|
-
const _get = Context.get;
|
|
30
|
-
Context.get = (state) => {
|
|
31
|
-
if (!state) try {
|
|
32
|
-
return useAmbient();
|
|
33
|
-
} catch {}
|
|
34
|
-
return _get(state);
|
|
35
|
-
};
|
|
36
|
-
function Consumer(props) {
|
|
37
|
-
return props.for.get((i) => props.children(i));
|
|
38
|
-
}
|
|
39
|
-
function Provider(props) {
|
|
40
|
-
const { for: input, children, fallback, name, is, ...rest } = props;
|
|
41
|
-
const ambient = useAmbient();
|
|
42
|
-
const context = useHook((set) => {
|
|
43
|
-
set(new Context(ambient));
|
|
44
|
-
return () => context.pop();
|
|
45
|
-
});
|
|
46
|
-
context.set(input, is);
|
|
47
|
-
if (Object.keys(rest).length) {
|
|
48
|
-
const i = State.is(input) ? context.get(input) : input;
|
|
49
|
-
if (i instanceof State) i.set(rest);
|
|
50
|
-
}
|
|
51
|
-
return provide(context, fallback !== void 0 ? Runtime.createElement(Runtime.Suspense, {
|
|
52
|
-
fallback,
|
|
53
|
-
name
|
|
54
|
-
}, children) : children);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
export { provide as i, Context as n, Provider as r, Consumer as t };
|
|
59
|
-
//# sourceMappingURL=context-BfeYQmAX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-BfeYQmAX.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { State, Context, Component } 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 provide(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 type ForEach<T> = (state: T) => void | (() => 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\nfunction Provider<T extends State>(props: Provider.Props<T>) {\n const {\n for: input,\n children,\n fallback,\n name,\n is,\n ...rest\n } = props as Provider.ForSingleProps<T> & Provider.ForMultipleProps<T>;\n\n const ambient = useAmbient();\n const context = useHook<Context>((set) => {\n set(new Context(ambient));\n return () => context.pop();\n });\n\n context.set(input, is);\n\n if (Object.keys(rest).length) {\n const i = State.is(input) ? context.get(input) : input;\n if (i instanceof State) i.set(rest);\n }\n\n return provide(context,\n fallback !== undefined\n ? Runtime.createElement(Runtime.Suspense, { fallback, name }, children)\n : children\n );\n}\n\nexport { Consumer, Provider, Context, provide };\n"],"mappings":";;;;AAGA,IAAI;;;;;;AAOJ,SAAS,SAAS;AAChB,QAAO,WAAW,SAAS,QAAQ,cAAc,QAAQ,KAAK;;;AAIhE,SAAS,aAAa;AACpB,QAAO,QAAQ,WAAW,QAAQ,CAAC;;;AAIrC,SAAS,QAAQ,SAAkB,UAAe;AAChD,QAAO,QAAQ,cAAc,QAAQ,CAAC,UAAU;EAAE,OAAO;EAAS;EAAU,CAAC;;AAI/E,OAAO,eAAe,WAAW,eAAe;CAAE,cAAc;CAAM,KAAK;CAAQ,CAAC;AAEpF,MAAM,OAAO,QAAQ;AAErB,QAAQ,OAAO,UAAkB;AAC/B,KAAI,CAAC,MACH,KAAI;AACF,SAAO,YAAY;SACb;AAEV,QAAO,KAAK,MAAM;;AAmBpB,SAAS,SAA0B,OAA0B;AAC3D,QAAO,MAAM,IAAI,KAAK,MAAM,MAAM,SAAS,EAAE,CAAC;;AAmChD,SAAS,SAA0B,OAA0B;CAC3D,MAAM,EACJ,KAAK,OACL,UACA,UACA,MACA,IACA,GAAG,SACD;CAEJ,MAAM,UAAU,YAAY;CAC5B,MAAM,UAAU,SAAkB,QAAQ;AACxC,MAAI,IAAI,QAAQ,QAAQ,CAAC;AACzB,eAAa,QAAQ,KAAK;GAC1B;AAEF,SAAQ,IAAI,OAAO,GAAG;AAEtB,KAAI,OAAO,KAAK,KAAK,CAAC,QAAQ;EAC5B,MAAM,IAAI,MAAM,GAAG,MAAM,GAAG,QAAQ,IAAI,MAAM,GAAG;AACjD,MAAI,aAAa,MAAO,GAAE,IAAI,KAAK;;AAGrC,QAAO,QAAQ,SACb,aAAa,SACT,QAAQ,cAAc,QAAQ,UAAU;EAAE;EAAU;EAAM,EAAE,SAAS,GACrE,SACL"}
|
package/dist/runtime.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import { event, watch, observer } from '@expressive/mvc';\nimport type { Component } from '@expressive/mvc';\nimport type { Context } from './context';\nimport './component';\nimport './state.get';\nimport './state.use';\n\nexport { State } from '@expressive/mvc';\nexport { Consumer, Provider, Context, provide } from './context';\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 /** 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\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\nexport function useReady<T>(callback: () => void) {\n return Runtime.useEffect(() => void callback(), []);\n}\n\n/**\n * Mount-effect with a refreshable return value, safe under React StrictMode.\n *\n * @param callback Setup handler; receives a setter, must return a cleanup.\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (refresh: (next: T) => void) => () => void\n) {\n const { current } = Runtime.useRef(\n { rendered: 0 } as {\n rendered: number;\n mounted?: boolean;\n pending?: boolean;\n unmount: () => void;\n update?: (next: (previous: number) => number) => void;\n output: T;\n }\n );\n\n current.update = Runtime.useState(() => {\n if (!current.rendered)\n current.unmount = callback((next) => {\n current.output = next;\n if (current.mounted) current.update?.((x) => x + 1);\n else if (current.update) current.pending = true;\n });\n\n return current.rendered++;\n })[1];\n\n Runtime.useEffect(() => {\n current.mounted = true;\n if (current.pending) {\n current.pending = false;\n current.update!((x) => x + 1);\n }\n return () => {\n if (--current.rendered < 1) current.unmount();\n }\n }, []);\n\n return current.output;\n}\n\n/** Subscribe to an existing observable instance within a component. */\nexport function use<T extends object>(subject: T) {\n const { current } = Runtime.useRef<{\n proxy: T;\n source?: T;\n mounted: number;\n unwatch?: () => void;\n }>({ mounted: 0, proxy: subject });\n\n const update = Runtime.useState(() => current.mounted++)[1];\n\n if (current.source !== subject) {\n const status = observer(subject);\n\n if (status === undefined)\n throw new Error('Provided object is not observable.');\n\n current.unwatch?.();\n current.source = subject;\n\n if (status === null) {\n current.unwatch = undefined;\n current.proxy = subject;\n } else {\n if (!status.ready) event(subject);\n\n let init = true;\n\n current.unwatch = watch(subject, (next, changed) => {\n current.proxy = next;\n if (changed.length && !init)\n update((x) => x + 1);\n });\n\n init = false;\n }\n }\n\n Runtime.useEffect(() => () => {\n if (--current.mounted < 1) current.unwatch?.();\n }, []);\n\n return current.proxy;\n}\n"],"mappings":";;;;AAUA,MAAa,UAAU,EAAE;AAgBzB,SAAgB,WAA+B,SAAkB;CAC/D,MAAM,MAAM,QAAQ,OAAiB,KAAK;AAC1C,QAAO,IAAI,YAAY,IAAI,UAAU,SAAS;;AAGhD,SAAgB,SAAY,UAAsB;AAChD,QAAO,QAAQ,gBAAgB,KAAK,UAAU,EAAE,EAAE,CAAC;;;;;;;;AASrD,SAAgB,QACd,UACA;CACA,MAAM,EAAE,YAAY,QAAQ,OAC1B,EAAE,UAAU,GAAG,CAQhB;AAED,SAAQ,SAAS,QAAQ,eAAe;AACtC,MAAI,CAAC,QAAQ,SACX,SAAQ,UAAU,UAAU,SAAS;AACnC,WAAQ,SAAS;AACjB,OAAI,QAAQ,QAAS,SAAQ,UAAU,MAAM,IAAI,EAAE;YAC1C,QAAQ,OAAQ,SAAQ,UAAU;IAC3C;AAEJ,SAAO,QAAQ;GACf,CAAC;AAEH,SAAQ,gBAAgB;AACtB,UAAQ,UAAU;AAClB,MAAI,QAAQ,SAAS;AACnB,WAAQ,UAAU;AAClB,WAAQ,QAAS,MAAM,IAAI,EAAE;;AAE/B,eAAa;AACX,OAAI,EAAE,QAAQ,WAAW,EAAG,SAAQ,SAAS;;IAE9C,EAAE,CAAC;AAEN,QAAO,QAAQ;;;AAIjB,SAAgB,IAAsB,SAAY;CAChD,MAAM,EAAE,YAAY,QAAQ,OAKzB;EAAE,SAAS;EAAG,OAAO;EAAS,CAAC;CAElC,MAAM,SAAS,QAAQ,eAAe,QAAQ,UAAU,CAAC;AAEzD,KAAI,QAAQ,WAAW,SAAS;EAC9B,MAAM,SAAS,SAAS,QAAQ;AAEhC,MAAI,WAAW,OACb,OAAM,IAAI,MAAM,qCAAqC;AAEvD,UAAQ,WAAW;AACnB,UAAQ,SAAS;AAEjB,MAAI,WAAW,MAAM;AACnB,WAAQ,UAAU;AAClB,WAAQ,QAAQ;SACX;AACL,OAAI,CAAC,OAAO,MAAO,OAAM,QAAQ;GAEjC,IAAI,OAAO;AAEX,WAAQ,UAAU,MAAM,UAAU,MAAM,YAAY;AAClD,YAAQ,QAAQ;AAChB,QAAI,QAAQ,UAAU,CAAC,KACrB,SAAQ,MAAM,IAAI,EAAE;KACtB;AAEF,UAAO;;;AAIX,SAAQ,sBAAsB;AAC5B,MAAI,EAAE,QAAQ,UAAU,EAAG,SAAQ,WAAW;IAC7C,EAAE,CAAC;AAEN,QAAO,QAAQ"}
|