@expressive/react 0.84.1 → 0.85.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/README.md +2 -0
- package/dist/adapter.d.ts +3 -191
- package/dist/adapter.js +5 -3
- package/dist/adapter.js.map +1 -1
- package/dist/{chunk-component-D-gCYZt4.js → chunk-component-BCcu60Qc.js} +10 -1
- package/dist/{chunk-component-D-gCYZt4.js.map → chunk-component-BCcu60Qc.js.map} +1 -1
- package/dist/{chunk-element-DaopgGAg.js → chunk-element-Cs4wcriz.js} +2 -2
- package/dist/{chunk-element-DaopgGAg.js.map → chunk-element-Cs4wcriz.js.map} +1 -1
- package/dist/chunk-runtime-C-yxuYAq.d.ts +191 -0
- package/dist/has.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -4
- package/dist/map.js +2 -2
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -17,6 +17,8 @@ The React adapter for [Expressive MVC](https://github.com/gabeklein/expressive-m
|
|
|
17
17
|
npm install @expressive/react
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
Works on React DOM, and on React Native and Expo - the adapter imports only `react` and `react/jsx-runtime`, so there is nothing renderer-specific to port. Exercised on an iOS simulator and an Android emulator in both Debug and Release builds, and gated per release on Metro resolution and a Hermes build (Expo SDK 57, React Native 0.86). Under Jest, add `@expressive` to `transformIgnorePatterns`.
|
|
21
|
+
|
|
20
22
|
```tsx
|
|
21
23
|
import State from '@expressive/react';
|
|
22
24
|
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,191 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
//#region src/state.get.d.ts
|
|
5
|
-
/** Type may not be undefined - instead will be null. */
|
|
6
|
-
type NoVoid<T> = T extends undefined | void ? null : T;
|
|
7
|
-
declare module '@expressive/mvc' {
|
|
8
|
-
namespace State {
|
|
9
|
-
type ForceRefresh = {
|
|
10
|
-
/** Request a refresh for current component. */(): void;
|
|
11
|
-
/**
|
|
12
|
-
* Request a refresh and again after promise either resolves or rejects.
|
|
13
|
-
*
|
|
14
|
-
* @param waitFor Promise to wait for.
|
|
15
|
-
* @returns Promise which resolves, after refresh, to same value as `waitFor`.
|
|
16
|
-
*/
|
|
17
|
-
<T = void>(waitFor: Promise<T>): Promise<T>;
|
|
18
|
-
/**
|
|
19
|
-
* Request refresh before and after async function.
|
|
20
|
-
* A refresh will occur both before and after the given function.
|
|
21
|
-
*
|
|
22
|
-
* **Note:** Any actions performed before first `await` will occur prior to refresh.
|
|
23
|
-
*
|
|
24
|
-
* @param invoke Async function to invoke.
|
|
25
|
-
* @returns Promise which resolves returned value after refresh.
|
|
26
|
-
*/
|
|
27
|
-
<T = void>(invoke: () => Promise<T>): Promise<T>;
|
|
28
|
-
};
|
|
29
|
-
type GetFactory<T extends State, R> = (this: T, current: T, refresh: ForceRefresh) => R;
|
|
30
|
-
type GetEffect<T extends State> = (this: T, current: T, refresh: ForceRefresh) => null;
|
|
31
|
-
/** Fetch instance of this class from context. */
|
|
32
|
-
function get<T extends State>(this: State.Extends<T>): T;
|
|
33
|
-
/** Fetch instance of this class optionally. */
|
|
34
|
-
function get<T extends State>(this: State.Extends<T>, required: false): T | undefined;
|
|
35
|
-
/** Fetch instance of this class from context. */
|
|
36
|
-
function get<T extends State>(this: State.Extends<T>, requireValues: true): Required<T>;
|
|
37
|
-
function get<T extends State, R>(this: State.Extends<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;
|
|
38
|
-
function get<T extends State>(this: State.Extends<T>, factory: GetEffect<T>): null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/state.use.d.ts
|
|
43
|
-
declare module '@expressive/mvc' {
|
|
44
|
-
interface UseState extends State {
|
|
45
|
-
/**
|
|
46
|
-
* Optional hook called when State.use() is invoked within a React component.
|
|
47
|
-
*
|
|
48
|
-
* This is called *every render* of the component, and will intercept
|
|
49
|
-
* arguments which would otherwise be passed into the State constructor.
|
|
50
|
-
*
|
|
51
|
-
* @param props Arguments passed to State.use().
|
|
52
|
-
*/
|
|
53
|
-
use?(...props: any[]): Promise<void> | void;
|
|
54
|
-
/**
|
|
55
|
-
* Optional hook called once the host component commits. Return a function
|
|
56
|
-
* to run when it unmounts.
|
|
57
|
-
*
|
|
58
|
-
* Not called during server render, nor for an instance merely observed or
|
|
59
|
-
* placed: `.get()` and `{instance}` reach one a component does not own, and
|
|
60
|
-
* `State.new()` has no component at all.
|
|
61
|
-
*
|
|
62
|
-
* Client-only effects belong here - setup which must accompany the instance
|
|
63
|
-
* itself belongs in `new()`.
|
|
64
|
-
*/
|
|
65
|
-
mount?(): (() => void) | void;
|
|
66
|
-
}
|
|
67
|
-
namespace State {
|
|
68
|
-
type UseArgs<T extends State> = T extends {
|
|
69
|
-
use(...props: infer P): any;
|
|
70
|
-
} ? P : State.Args<T>;
|
|
71
|
-
/**
|
|
72
|
-
* Create and manage instance of this State within React component.
|
|
73
|
-
*
|
|
74
|
-
* @param args Arguments to pass to constructor or `use` method (if defined).
|
|
75
|
-
* @returns Managed instance of this State.
|
|
76
|
-
*/
|
|
77
|
-
function use<T extends UseState>(this: State.Type<T>, ...args: UseArgs<T>): T;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/context.d.ts
|
|
82
|
-
declare namespace Consumer {
|
|
83
|
-
type Props<T extends State$2> = {
|
|
84
|
-
/** Type of controller to fetch from context. */for: State$2.Extends<T>;
|
|
85
|
-
/**
|
|
86
|
-
* Render function, will receive instance of desired controller.
|
|
87
|
-
*
|
|
88
|
-
* Called every render of parent component.
|
|
89
|
-
* Similar to `State.get()`, updates to properties accessed in
|
|
90
|
-
* this function will cause a refresh when they change.
|
|
91
|
-
*/
|
|
92
|
-
children: (value: T) => Component.Node | void;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
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;
|
|
96
|
-
declare namespace Provider {
|
|
97
|
-
/**
|
|
98
|
-
* Runs for each State registered by this Provider. Return value is ignored -
|
|
99
|
-
* to run teardown with a State, use `state.set(null, callback)`.
|
|
100
|
-
*/
|
|
101
|
-
type ForEach<T> = (state: T) => void;
|
|
102
|
-
interface SharedProps {
|
|
103
|
-
/**
|
|
104
|
-
* Children to render within this Provider.
|
|
105
|
-
*/
|
|
106
|
-
children?: Component.Node;
|
|
107
|
-
/** A fallback tree to show when suspended. */
|
|
108
|
-
fallback?: Component.Node;
|
|
109
|
-
/**
|
|
110
|
-
* A name for this Suspense boundary for instrumentation purposes.
|
|
111
|
-
* The name will help identify this boundary in React DevTools.
|
|
112
|
-
*/
|
|
113
|
-
name?: string | undefined;
|
|
114
|
-
}
|
|
115
|
-
type ForSingleProps<T extends State$2> = SharedProps & {
|
|
116
|
-
for: T | State$2.Type<T>;
|
|
117
|
-
is: (instance: T) => void;
|
|
118
|
-
} & { [K in State$2.Field<T>]?: T[K] };
|
|
119
|
-
type ForMultipleProps<T extends State$2> = SharedProps & {
|
|
120
|
-
for: Context$1.Accept<T>;
|
|
121
|
-
is?: ForEach<T>;
|
|
122
|
-
};
|
|
123
|
-
type Props<T extends State$2 = State$2> = ForSingleProps<T> | ForMultipleProps<T>;
|
|
124
|
-
}
|
|
125
|
-
declare function Provider<T extends State$2>({
|
|
126
|
-
children,
|
|
127
|
-
fallback,
|
|
128
|
-
name,
|
|
129
|
-
...props
|
|
130
|
-
}: Provider.Props<T>): any;
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/component.d.ts
|
|
133
|
-
declare module '@expressive/mvc' {
|
|
134
|
-
namespace Component {
|
|
135
|
-
/**
|
|
136
|
-
* Not available - a Component is rendered, not a hook.
|
|
137
|
-
* Render it with `<Component />` or `{component}`.
|
|
138
|
-
* For a bare instance use `Component.new()`.
|
|
139
|
-
*/
|
|
140
|
-
const use: never;
|
|
141
|
-
}
|
|
142
|
-
interface Component {
|
|
143
|
-
/**
|
|
144
|
-
* Optional hook called once this Component commits. Return a function to
|
|
145
|
-
* run when it unmounts.
|
|
146
|
-
*
|
|
147
|
-
* Not called during server render, nor for an instance placed as
|
|
148
|
-
* `{component}` - a placement does not own what it renders. Client-only
|
|
149
|
-
* effects belong here; setup which must accompany the instance itself
|
|
150
|
-
* belongs in `new()`.
|
|
151
|
-
*/
|
|
152
|
-
mount?(): (() => void) | void;
|
|
153
|
-
/** @deprecated Only to satisfy host JSX. Use `this.get(State)` instead. */
|
|
154
|
-
readonly context: Context$1;
|
|
155
|
-
/** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */
|
|
156
|
-
readonly state: State.Values<this>;
|
|
157
|
-
/** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */
|
|
158
|
-
setState: (state: any, callback?: () => void) => void;
|
|
159
|
-
/** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */
|
|
160
|
-
forceUpdate: (callback?: () => void) => void;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Wrap a content element in its context provider, a Suspense boundary (unless
|
|
165
|
-
* `fallback` is `false`) and, when `catch` is set, the host error boundary.
|
|
166
|
-
*/
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/runtime.d.ts
|
|
169
|
-
declare const Runtime: {
|
|
170
|
-
/** Host own-property keys to trap out of observed state; assigned by each adapter. */ignore: string[];
|
|
171
|
-
createElement(type: any, props?: any, ...children: any[]): any;
|
|
172
|
-
createContext<T>(value: T): any;
|
|
173
|
-
useContext(context: any): any;
|
|
174
|
-
useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];
|
|
175
|
-
useEffect(effect: () => (() => void) | void, deps?: any[]): void;
|
|
176
|
-
useRef<T>(initial: T): {
|
|
177
|
-
current: T;
|
|
178
|
-
};
|
|
179
|
-
/** Consumed for pre-commit revision validation; absent where commits
|
|
180
|
-
* cannot interleave with writes. */
|
|
181
|
-
useSyncExternalStore?(subscribe: (notify: () => void) => () => void, getSnapshot: () => number, getServerSnapshot?: () => number): number; /** Per-render-attempt lifecycle, set by each adapter (React stacks attempts; others no-op). */
|
|
182
|
-
dedupe(from: Component, context: Context$1): {
|
|
183
|
-
commit(): void;
|
|
184
|
-
remove(): void;
|
|
185
|
-
}; /** Host error-boundary component, wrapping a Component whose `catch` is set. */
|
|
186
|
-
ErrorBoundary: unknown;
|
|
187
|
-
Suspense: any;
|
|
188
|
-
};
|
|
189
|
-
//#endregion
|
|
190
|
-
export { Consumer, Provider, Runtime, State$1 as State };
|
|
191
|
-
//# sourceMappingURL=adapter.d.ts.map
|
|
1
|
+
import { n as Consumer, r as Provider, t as Runtime } from "./chunk-runtime-C-yxuYAq.js";
|
|
2
|
+
import { State } from "@expressive/mvc";
|
|
3
|
+
export { Consumer, Provider, Runtime, State };
|
package/dist/adapter.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { a as Runtime, c as useWatch, i as Provider, n as Consumer, o as useFactory, s as useHook } from "./chunk-component-
|
|
1
|
+
import { a as Runtime, c as useWatch, i as Provider, n as Consumer, o as useFactory, s as useHook } from "./chunk-component-BCcu60Qc.js";
|
|
2
2
|
import { Context, State, State as State$1 } from "@expressive/mvc";
|
|
3
3
|
import { observer, watch } from "@expressive/mvc/observable";
|
|
4
4
|
|
|
5
5
|
//#region src/state.get.ts
|
|
6
6
|
State$1.get = function get(argument) {
|
|
7
|
+
const Type = this;
|
|
7
8
|
const next = Runtime.useState(0)[1];
|
|
8
9
|
const local = Context.get();
|
|
9
10
|
return useFactory(() => {
|
|
@@ -31,6 +32,7 @@ State$1.get = function get(argument) {
|
|
|
31
32
|
unwatch = void 0;
|
|
32
33
|
}
|
|
33
34
|
function attach(next) {
|
|
35
|
+
if (local.get(Type, false) !== next) return;
|
|
34
36
|
unwatch?.();
|
|
35
37
|
if (observer(next) === null) {
|
|
36
38
|
value = typeof argument === "function" ? argument.call(next, next, refresh) : next;
|
|
@@ -56,11 +58,11 @@ State$1.get = function get(argument) {
|
|
|
56
58
|
}
|
|
57
59
|
return release;
|
|
58
60
|
}
|
|
59
|
-
const unsubscribe = local.get(
|
|
61
|
+
const unsubscribe = local.get(Type, attach);
|
|
60
62
|
if (!unwatch) {
|
|
61
63
|
unsubscribe();
|
|
62
64
|
if (argument === false) return () => void 0;
|
|
63
|
-
throw new Error(`Could not find ${
|
|
65
|
+
throw new Error(`Could not find ${Type} in context.`);
|
|
64
66
|
}
|
|
65
67
|
if (value === null) {
|
|
66
68
|
release();
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","names":[],"sources":["../src/state.get.ts","../src/state.use.ts"],"sourcesContent":["import { State, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { Runtime, useFactory, useHook } from './runtime';\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\ndeclare module '@expressive/mvc' {\n namespace State {\n type ForceRefresh = {\n /** Request a refresh for current component. */\n (): void;\n\n /**\n * Request a refresh and again after promise either resolves or rejects.\n *\n * @param waitFor Promise to wait for.\n * @returns Promise which resolves, after refresh, to same value as `waitFor`.\n */\n <T = void>(waitFor: Promise<T>): Promise<T>;\n\n /**\n * Request refresh before and after async function.\n * A refresh will occur both before and after the given function.\n *\n * **Note:** Any actions performed before first `await` will occur prior to refresh.\n *\n * @param invoke Async function to invoke.\n * @returns Promise which resolves returned value after refresh.\n */\n <T = void>(invoke: () => Promise<T>): Promise<T>;\n };\n\n type GetFactory<T extends State, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends State> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => null;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(this: State.Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends State>(\n this: State.Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(\n this: State.Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends State, R>(\n this: State.Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n function get<T extends State>(\n this: State.Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nState.get = function get<T extends State>(\n this: State.Extends<T>,\n argument?: boolean | State.GetFactory<T, unknown>\n) {\n const next = Runtime.useState(0)[1];\n const local = Context.get();\n const render = useFactory(() => {\n let unwatch: (() => void) | undefined;\n let mounted = false;\n let pending = false;\n let value: any;\n let force!: () => void;\n\n function update() {\n pending = false;\n next((x) => x + 1);\n }\n\n function observed() {\n if (mounted) update();\n else pending = true;\n }\n\n function refresh<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if (typeof action == 'function') action = action();\n update();\n if (action instanceof Promise) return action.finally(update);\n }\n\n function release() {\n unsubscribe();\n unwatch?.();\n unwatch = undefined;\n }\n\n function attach(next: T) {\n unwatch?.();\n\n if (observer(next) === null) {\n value = typeof argument === 'function'\n ? argument.call(next, next, refresh)\n : next;\n unwatch = () => {};\n return release;\n }\n\n let first = true;\n\n unwatch = watch(\n next,\n (current) => {\n if (typeof argument === 'function') {\n const next = argument.call(current, current, refresh);\n if (next === value) return;\n value = next;\n } else {\n value = current;\n }\n\n if (!first) observed();\n first = false;\n\n return (update) => {\n if (update === true) force();\n };\n },\n argument === true\n );\n\n if (mounted) {\n pending = true;\n queueMicrotask(() => pending && update());\n }\n\n return release;\n }\n\n const unsubscribe = local.get(this, attach);\n\n if (!unwatch) {\n unsubscribe();\n if (argument === false) return () => undefined;\n throw new Error(`Could not find ${this} in context.`);\n }\n\n if (value === null) {\n release();\n return () => null;\n }\n\n if (value instanceof Promise) {\n let error: Error | undefined;\n\n release();\n\n value\n .then(\n (x) => (value = x),\n (e) => (error = e)\n )\n .finally(update);\n\n value = null;\n\n return () => {\n if (error) throw error;\n return value === undefined ? null : value;\n };\n }\n\n return () => {\n pending = false;\n useHook((_refresh, reset) => {\n force = reset;\n\n return () => {\n mounted = true;\n if (pending) update();\n return release;\n };\n });\n return value === undefined ? null : value;\n };\n });\n\n return render();\n};\n","import { State, Context } from '@expressive/mvc';\nimport type { UseState } from '@expressive/mvc';\nimport { useFactory, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n interface UseState extends State {\n /**\n * Optional hook called when State.use() is invoked within a React component.\n *\n * This is called *every render* of the component, and will intercept\n * arguments which would otherwise be passed into the State constructor.\n *\n * @param props Arguments passed to State.use().\n */\n use?(...props: any[]): Promise<void> | void;\n\n /**\n * Optional hook called once the host component commits. Return a function\n * to run when it unmounts.\n *\n * Not called during server render, nor for an instance merely observed or\n * placed: `.get()` and `{instance}` reach one a component does not own, and\n * `State.new()` has no component at all.\n *\n * Client-only effects belong here - setup which must accompany the instance\n * itself belongs in `new()`.\n */\n mount?(): (() => void) | void;\n }\n\n namespace State {\n type UseArgs<T extends State> = T extends {\n use(...props: infer P): any;\n }\n ? P\n : State.Args<T>;\n\n /**\n * Create and manage instance of this State within React component.\n *\n * @param args Arguments to pass to constructor or `use` method (if defined).\n * @returns Managed instance of this State.\n */\n function use<T extends UseState>(\n this: State.Type<T>,\n ...args: UseArgs<T>\n ): T;\n }\n}\n\nState.use = function use<T extends State>(\n this: State.Type<T>,\n ...args: State.UseArgs<T>\n) {\n const outer = Context.get();\n const render = useFactory(() => {\n const add = (arg: unknown) =>\n typeof arg == 'object' && instance.set(arg as State.Assign<T>);\n\n let use = (...args: State.Args<T>) => Promise.all(args.flat().map(add));\n\n const instance = new this((x) => {\n if ('use' in x && typeof x.use == 'function') {\n use = x.use.bind(x);\n use(...args);\n }\n else return args;\n });\n\n const context = outer.push(instance);\n\n let ready = false;\n\n return (args: State.Args<T>) => {\n if (ready) {\n ready = false;\n Promise.resolve(use(...args)).finally(() => {\n ready = true;\n });\n }\n\n return useWatch(instance, () => {\n ready = true;\n\n const release = (instance as UseState).mount?.();\n\n return () => {\n if (typeof release == 'function') release();\n context.pop();\n instance.set(null);\n };\n });\n };\n });\n\n return render(args);\n};\n"],"mappings":";;;;;AAwEA,QAAM,MAAM,SAAS,IAEnB,UACA;CACA,MAAM,OAAO,QAAQ,SAAS,EAAE,CAAC;CACjC,MAAM,QAAQ,QAAQ,KAAK;AAwH3B,QAvHe,iBAAiB;EAC9B,IAAI;EACJ,IAAI,UAAU;EACd,IAAI,UAAU;EACd,IAAI;EACJ,IAAI;EAEJ,SAAS,SAAS;AAChB,aAAU;AACV,SAAM,MAAM,IAAI,EAAE;;EAGpB,SAAS,WAAW;AAClB,OAAI,QAAS,SAAQ;OAChB,WAAU;;EAGjB,SAAS,QAAW,QAA+C;AACjE,OAAI,OAAO,UAAU,WAAY,UAAS,QAAQ;AAClD,WAAQ;AACR,OAAI,kBAAkB,QAAS,QAAO,OAAO,QAAQ,OAAO;;EAG9D,SAAS,UAAU;AACjB,gBAAa;AACb,cAAW;AACX,aAAU;;EAGZ,SAAS,OAAO,MAAS;AACvB,cAAW;AAEX,OAAI,SAAS,KAAK,KAAK,MAAM;AAC3B,YAAQ,OAAO,aAAa,aACxB,SAAS,KAAK,MAAM,MAAM,QAAQ,GAClC;AACJ,oBAAgB;AAChB,WAAO;;GAGT,IAAI,QAAQ;AAEZ,aAAU,MACR,OACC,YAAY;AACX,QAAI,OAAO,aAAa,YAAY;KAClC,MAAM,OAAO,SAAS,KAAK,SAAS,SAAS,QAAQ;AACrD,SAAI,SAAS,MAAO;AACpB,aAAQ;UAER,SAAQ;AAGV,QAAI,CAAC,MAAO,WAAU;AACtB,YAAQ;AAER,YAAQ,WAAW;AACjB,SAAI,WAAW,KAAM,QAAO;;MAGhC,aAAa,KACd;AAED,OAAI,SAAS;AACX,cAAU;AACV,yBAAqB,WAAW,QAAQ,CAAC;;AAG3C,UAAO;;EAGT,MAAM,cAAc,MAAM,IAAI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a;AACX,SAAI,OAAO,WAAW,WAAY,UAAS;AAC3C,aAAQ,KAAK;AACb,cAAS,IAAI,KAAK;;KAEpB;;GAEJ,CAEY,KAAK"}
|
|
1
|
+
{"version":3,"file":"adapter.js","names":[],"sources":["../src/state.get.ts","../src/state.use.ts"],"sourcesContent":["import { State, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { Runtime, useFactory, useHook } from './runtime';\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\ndeclare module '@expressive/mvc' {\n namespace State {\n type ForceRefresh = {\n /** Request a refresh for current component. */\n (): void;\n\n /**\n * Request a refresh and again after promise either resolves or rejects.\n *\n * @param waitFor Promise to wait for.\n * @returns Promise which resolves, after refresh, to same value as `waitFor`.\n */\n <T = void>(waitFor: Promise<T>): Promise<T>;\n\n /**\n * Request refresh before and after async function.\n * A refresh will occur both before and after the given function.\n *\n * **Note:** Any actions performed before first `await` will occur prior to refresh.\n *\n * @param invoke Async function to invoke.\n * @returns Promise which resolves returned value after refresh.\n */\n <T = void>(invoke: () => Promise<T>): Promise<T>;\n };\n\n type GetFactory<T extends State, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends State> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => null;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(this: State.Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends State>(\n this: State.Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(\n this: State.Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends State, R>(\n this: State.Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n function get<T extends State>(\n this: State.Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nState.get = function get<T extends State>(\n this: State.Extends<T>,\n argument?: boolean | State.GetFactory<T, unknown>\n) {\n const Type = this;\n const next = Runtime.useState(0)[1];\n const local = Context.get();\n const render = useFactory(() => {\n let unwatch: (() => void) | undefined;\n let mounted = false;\n let pending = false;\n let value: any;\n let force!: () => void;\n\n function update() {\n pending = false;\n next((x) => x + 1);\n }\n\n function observed() {\n if (mounted) update();\n else pending = true;\n }\n\n function refresh<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if (typeof action == 'function') action = action();\n update();\n if (action instanceof Promise) return action.finally(update);\n }\n\n function release() {\n unsubscribe();\n unwatch?.();\n unwatch = undefined;\n }\n\n function attach(next: T) {\n if (local.get(Type, false) !== next) return;\n\n unwatch?.();\n\n if (observer(next) === null) {\n value = typeof argument === 'function'\n ? argument.call(next, next, refresh)\n : next;\n unwatch = () => {};\n return release;\n }\n\n let first = true;\n\n unwatch = watch(\n next,\n (current) => {\n if (typeof argument === 'function') {\n const next = argument.call(current, current, refresh);\n if (next === value) return;\n value = next;\n } else {\n value = current;\n }\n\n if (!first) observed();\n first = false;\n\n return (update) => {\n if (update === true) force();\n };\n },\n argument === true\n );\n\n if (mounted) {\n pending = true;\n queueMicrotask(() => pending && update());\n }\n\n return release;\n }\n\n const unsubscribe = local.get(Type, attach);\n\n if (!unwatch) {\n unsubscribe();\n if (argument === false) return () => undefined;\n throw new Error(`Could not find ${Type} in context.`);\n }\n\n if (value === null) {\n release();\n return () => null;\n }\n\n if (value instanceof Promise) {\n let error: Error | undefined;\n\n release();\n\n value\n .then(\n (x) => (value = x),\n (e) => (error = e)\n )\n .finally(update);\n\n value = null;\n\n return () => {\n if (error) throw error;\n return value === undefined ? null : value;\n };\n }\n\n return () => {\n pending = false;\n useHook((_refresh, reset) => {\n force = reset;\n\n return () => {\n mounted = true;\n if (pending) update();\n return release;\n };\n });\n return value === undefined ? null : value;\n };\n });\n\n return render();\n};\n","import { State, Context } from '@expressive/mvc';\nimport type { UseState } from '@expressive/mvc';\nimport { useFactory, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n interface UseState extends State {\n /**\n * Optional hook called when State.use() is invoked within a React component.\n *\n * This is called *every render* of the component, and will intercept\n * arguments which would otherwise be passed into the State constructor.\n *\n * @param props Arguments passed to State.use().\n */\n use?(...props: any[]): Promise<void> | void;\n\n /**\n * Optional hook called once the host component commits. Return a function\n * to run when it unmounts.\n *\n * Not called during server render, nor for an instance merely observed or\n * placed: `.get()` and `{instance}` reach one a component does not own, and\n * `State.new()` has no component at all.\n *\n * Client-only effects belong here - setup which must accompany the instance\n * itself belongs in `new()`.\n */\n mount?(): (() => void) | void;\n }\n\n namespace State {\n type UseArgs<T extends State> = T extends {\n use(...props: infer P): any;\n }\n ? P\n : State.Args<T>;\n\n /**\n * Create and manage instance of this State within React component.\n *\n * @param args Arguments to pass to constructor or `use` method (if defined).\n * @returns Managed instance of this State.\n */\n function use<T extends UseState>(\n this: State.Type<T>,\n ...args: UseArgs<T>\n ): T;\n }\n}\n\nState.use = function use<T extends State>(\n this: State.Type<T>,\n ...args: State.UseArgs<T>\n) {\n const outer = Context.get();\n const render = useFactory(() => {\n const add = (arg: unknown) =>\n typeof arg == 'object' && instance.set(arg as State.Assign<T>);\n\n let use = (...args: State.Args<T>) => Promise.all(args.flat().map(add));\n\n const instance = new this((x) => {\n if ('use' in x && typeof x.use == 'function') {\n use = x.use.bind(x);\n use(...args);\n }\n else return args;\n });\n\n const context = outer.push(instance);\n\n let ready = false;\n\n return (args: State.Args<T>) => {\n if (ready) {\n ready = false;\n Promise.resolve(use(...args)).finally(() => {\n ready = true;\n });\n }\n\n return useWatch(instance, () => {\n ready = true;\n\n const release = (instance as UseState).mount?.();\n\n return () => {\n if (typeof release == 'function') release();\n context.pop();\n instance.set(null);\n };\n });\n };\n });\n\n return render(args);\n};\n"],"mappings":";;;;;AAwEA,QAAM,MAAM,SAAS,IAEnB,UACA;CACA,MAAM,OAAO;CACb,MAAM,OAAO,QAAQ,SAAS,EAAE,CAAC;CACjC,MAAM,QAAQ,QAAQ,KAAK;AA0H3B,QAzHe,iBAAiB;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267
|
+
Object.defineProperty(this, key, {
|
|
268
|
+
value,
|
|
269
|
+
writable: true,
|
|
270
|
+
enumerable: true,
|
|
271
|
+
configurable: true
|
|
272
|
+
});
|
|
273
|
+
subcomponents(this, true);
|
|
265
274
|
}
|
|
266
275
|
});
|
|
267
276
|
}
|
|
@@ -269,4 +278,4 @@ function subcomponents(target, configurable) {
|
|
|
269
278
|
|
|
270
279
|
//#endregion
|
|
271
280
|
export { Runtime as a, useWatch as c, Provider as i, Consumer as n, useFactory as o, Context$1 as r, useHook as s, createFrame as t };
|
|
272
|
-
//# sourceMappingURL=chunk-component-
|
|
281
|
+
//# sourceMappingURL=chunk-component-BCcu60Qc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-component-D-gCYZt4.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 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 /** 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 * Mount-effect with a refreshable return value, safe under React StrictMode.\n *\n * @param callback Setup handler, run on creation; receives a setter, plus a\n * reset which invalidates the rendered value so in-flight render attempts\n * revalidate, and returns a mount handler, which in turn returns a cleanup.\n * All share this hook's render counter, so a StrictMode remount repeats\n * none of them.\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 } = Runtime.useRef(\n { rendered: 0, revision: 0 } as {\n rendered: number;\n revision: number;\n mounted?: boolean;\n pending?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | 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.commit = callback(\n (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 current.revision++;\n }\n );\n\n return current.rendered++;\n })[1];\n\n const getRevision = () => current.revision;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.mounted = true;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n if (current.pending) {\n current.pending = false;\n current.update!((x) => x + 1);\n }\n\n return () => {\n if (--current.rendered <= 0) current.release?.();\n }\n }, []);\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 });\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\n const self = from;\n const content = from.render;\n const Render = () => content.call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n const release = self.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 });\n }\n}\n\nexport { createFrame };\n"],"mappings":";;;;AAIA,MAAa,UAAU,EAAE;AAuBzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA+B,SAAkB;CAC/D,MAAM,MAAM,QAAQ,OAAiB,KAAK;AAC1C,QAAO,IAAI,YAAY,IAAI,UAAU,SAAS;;;;;;;;;;;;AAahD,SAAgB,QACd,UAIA;CACA,MAAM,EAAE,YAAY,QAAQ,OAC1B;EAAE,UAAU;EAAG,UAAU;EAAG,CAU7B;AAED,SAAQ,SAAS,QAAQ,eAAe;AACtC,MAAI,CAAC,QAAQ,SACX,SAAQ,SAAS,UACd,SAAS;AACR,WAAQ,SAAS;AACjB,OAAI,QAAQ,QAAS,SAAQ,UAAU,MAAM,IAAI,EAAE;YAC1C,QAAQ,OAAQ,SAAQ,UAAU;WAEvC;AACJ,WAAQ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AAG1D,cAAa,cAAc,UAAU;;;AAIvC,SAAS,cAAc,QAAgB,cAAwB;AAC7D,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;GACA,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;;GAEV,CAAC"}
|
|
1
|
+
{"version":3,"file":"chunk-component-BCcu60Qc.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 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 /** 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 * Mount-effect with a refreshable return value, safe under React StrictMode.\n *\n * @param callback Setup handler, run on creation; receives a setter, plus a\n * reset which invalidates the rendered value so in-flight render attempts\n * revalidate, and returns a mount handler, which in turn returns a cleanup.\n * All share this hook's render counter, so a StrictMode remount repeats\n * none of them.\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 } = Runtime.useRef(\n { rendered: 0, revision: 0 } as {\n rendered: number;\n revision: number;\n mounted?: boolean;\n pending?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | 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.commit = callback(\n (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 current.revision++;\n }\n );\n\n return current.rendered++;\n })[1];\n\n const getRevision = () => current.revision;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.mounted = true;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n if (current.pending) {\n current.pending = false;\n current.update!((x) => x + 1);\n }\n\n return () => {\n if (--current.rendered <= 0) current.release?.();\n }\n }, []);\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 });\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\n const self = from;\n const content = from.render;\n const Render = () => content.call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n const release = self.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":";;;;AAIA,MAAa,UAAU,EAAE;AAuBzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA+B,SAAkB;CAC/D,MAAM,MAAM,QAAQ,OAAiB,KAAK;AAC1C,QAAO,IAAI,YAAY,IAAI,UAAU,SAAS;;;;;;;;;;;;AAahD,SAAgB,QACd,UAIA;CACA,MAAM,EAAE,YAAY,QAAQ,OAC1B;EAAE,UAAU;EAAG,UAAU;EAAG,CAU7B;AAED,SAAQ,SAAS,QAAQ,eAAe;AACtC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1B,MAAM,UAAU,KAAK,SAAS;AAE9B,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,cAAwB;AAC7D,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;GACA,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,MAAM,KAAK;;GAE5B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Runtime, c as useWatch, o as useFactory, r as Context$1, t as createFrame } from "./chunk-component-
|
|
1
|
+
import { a as Runtime, c as useWatch, o as useFactory, r as Context$1, t as createFrame } from "./chunk-component-BCcu60Qc.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-Cs4wcriz.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-element-
|
|
1
|
+
{"version":3,"file":"chunk-element-Cs4wcriz.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"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { Component, Context as Context$1, State as State$1 } from "@expressive/mvc";
|
|
2
|
+
import * as react from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/state.get.d.ts
|
|
5
|
+
/** Type may not be undefined - instead will be null. */
|
|
6
|
+
type NoVoid<T> = T extends undefined | void ? null : T;
|
|
7
|
+
declare module '@expressive/mvc' {
|
|
8
|
+
namespace State {
|
|
9
|
+
type ForceRefresh = {
|
|
10
|
+
/** Request a refresh for current component. */(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Request a refresh and again after promise either resolves or rejects.
|
|
13
|
+
*
|
|
14
|
+
* @param waitFor Promise to wait for.
|
|
15
|
+
* @returns Promise which resolves, after refresh, to same value as `waitFor`.
|
|
16
|
+
*/
|
|
17
|
+
<T = void>(waitFor: Promise<T>): Promise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Request refresh before and after async function.
|
|
20
|
+
* A refresh will occur both before and after the given function.
|
|
21
|
+
*
|
|
22
|
+
* **Note:** Any actions performed before first `await` will occur prior to refresh.
|
|
23
|
+
*
|
|
24
|
+
* @param invoke Async function to invoke.
|
|
25
|
+
* @returns Promise which resolves returned value after refresh.
|
|
26
|
+
*/
|
|
27
|
+
<T = void>(invoke: () => Promise<T>): Promise<T>;
|
|
28
|
+
};
|
|
29
|
+
type GetFactory<T extends State, R> = (this: T, current: T, refresh: ForceRefresh) => R;
|
|
30
|
+
type GetEffect<T extends State> = (this: T, current: T, refresh: ForceRefresh) => null;
|
|
31
|
+
/** Fetch instance of this class from context. */
|
|
32
|
+
function get<T extends State>(this: State.Extends<T>): T;
|
|
33
|
+
/** Fetch instance of this class optionally. */
|
|
34
|
+
function get<T extends State>(this: State.Extends<T>, required: false): T | undefined;
|
|
35
|
+
/** Fetch instance of this class from context. */
|
|
36
|
+
function get<T extends State>(this: State.Extends<T>, requireValues: true): Required<T>;
|
|
37
|
+
function get<T extends State, R>(this: State.Extends<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;
|
|
38
|
+
function get<T extends State>(this: State.Extends<T>, factory: GetEffect<T>): null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/state.use.d.ts
|
|
43
|
+
declare module '@expressive/mvc' {
|
|
44
|
+
interface UseState extends State {
|
|
45
|
+
/**
|
|
46
|
+
* Optional hook called when State.use() is invoked within a React component.
|
|
47
|
+
*
|
|
48
|
+
* This is called *every render* of the component, and will intercept
|
|
49
|
+
* arguments which would otherwise be passed into the State constructor.
|
|
50
|
+
*
|
|
51
|
+
* @param props Arguments passed to State.use().
|
|
52
|
+
*/
|
|
53
|
+
use?(...props: any[]): Promise<void> | void;
|
|
54
|
+
/**
|
|
55
|
+
* Optional hook called once the host component commits. Return a function
|
|
56
|
+
* to run when it unmounts.
|
|
57
|
+
*
|
|
58
|
+
* Not called during server render, nor for an instance merely observed or
|
|
59
|
+
* placed: `.get()` and `{instance}` reach one a component does not own, and
|
|
60
|
+
* `State.new()` has no component at all.
|
|
61
|
+
*
|
|
62
|
+
* Client-only effects belong here - setup which must accompany the instance
|
|
63
|
+
* itself belongs in `new()`.
|
|
64
|
+
*/
|
|
65
|
+
mount?(): (() => void) | void;
|
|
66
|
+
}
|
|
67
|
+
namespace State {
|
|
68
|
+
type UseArgs<T extends State> = T extends {
|
|
69
|
+
use(...props: infer P): any;
|
|
70
|
+
} ? P : State.Args<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Create and manage instance of this State within React component.
|
|
73
|
+
*
|
|
74
|
+
* @param args Arguments to pass to constructor or `use` method (if defined).
|
|
75
|
+
* @returns Managed instance of this State.
|
|
76
|
+
*/
|
|
77
|
+
function use<T extends UseState>(this: State.Type<T>, ...args: UseArgs<T>): T;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/context.d.ts
|
|
82
|
+
declare namespace Consumer {
|
|
83
|
+
type Props<T extends State$1> = {
|
|
84
|
+
/** Type of controller to fetch from context. */for: State$1.Extends<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Render function, will receive instance of desired controller.
|
|
87
|
+
*
|
|
88
|
+
* Called every render of parent component.
|
|
89
|
+
* Similar to `State.get()`, updates to properties accessed in
|
|
90
|
+
* this function will cause a refresh when they change.
|
|
91
|
+
*/
|
|
92
|
+
children: (value: T) => Component.Node | void;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
declare function Consumer<T extends State$1>(props: Consumer.Props<T>): string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | react.ReactPortal | null;
|
|
96
|
+
declare namespace Provider {
|
|
97
|
+
/**
|
|
98
|
+
* Runs for each State registered by this Provider. Return value is ignored -
|
|
99
|
+
* to run teardown with a State, use `state.set(null, callback)`.
|
|
100
|
+
*/
|
|
101
|
+
type ForEach<T> = (state: T) => void;
|
|
102
|
+
interface SharedProps {
|
|
103
|
+
/**
|
|
104
|
+
* Children to render within this Provider.
|
|
105
|
+
*/
|
|
106
|
+
children?: Component.Node;
|
|
107
|
+
/** A fallback tree to show when suspended. */
|
|
108
|
+
fallback?: Component.Node;
|
|
109
|
+
/**
|
|
110
|
+
* A name for this Suspense boundary for instrumentation purposes.
|
|
111
|
+
* The name will help identify this boundary in React DevTools.
|
|
112
|
+
*/
|
|
113
|
+
name?: string | undefined;
|
|
114
|
+
}
|
|
115
|
+
type ForSingleProps<T extends State$1> = SharedProps & {
|
|
116
|
+
for: T | State$1.Type<T>;
|
|
117
|
+
is: (instance: T) => void;
|
|
118
|
+
} & { [K in State$1.Field<T>]?: T[K] };
|
|
119
|
+
type ForMultipleProps<T extends State$1> = SharedProps & {
|
|
120
|
+
for: Context$1.Accept<T>;
|
|
121
|
+
is?: ForEach<T>;
|
|
122
|
+
};
|
|
123
|
+
type Props<T extends State$1 = State$1> = ForSingleProps<T> | ForMultipleProps<T>;
|
|
124
|
+
}
|
|
125
|
+
declare function Provider<T extends State$1>({
|
|
126
|
+
children,
|
|
127
|
+
fallback,
|
|
128
|
+
name,
|
|
129
|
+
...props
|
|
130
|
+
}: Provider.Props<T>): any;
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/component.d.ts
|
|
133
|
+
declare module '@expressive/mvc' {
|
|
134
|
+
namespace Component {
|
|
135
|
+
/**
|
|
136
|
+
* Not available - a Component is rendered, not a hook.
|
|
137
|
+
* Render it with `<Component />` or `{component}`.
|
|
138
|
+
* For a bare instance use `Component.new()`.
|
|
139
|
+
*/
|
|
140
|
+
const use: never;
|
|
141
|
+
}
|
|
142
|
+
interface Component {
|
|
143
|
+
/**
|
|
144
|
+
* Optional hook called once this Component commits. Return a function to
|
|
145
|
+
* run when it unmounts.
|
|
146
|
+
*
|
|
147
|
+
* Not called during server render, nor for an instance placed as
|
|
148
|
+
* `{component}` - a placement does not own what it renders. Client-only
|
|
149
|
+
* effects belong here; setup which must accompany the instance itself
|
|
150
|
+
* belongs in `new()`.
|
|
151
|
+
*/
|
|
152
|
+
mount?(): (() => void) | void;
|
|
153
|
+
/** @deprecated Only to satisfy host JSX. Use `this.get(State)` instead. */
|
|
154
|
+
readonly context: Context$1;
|
|
155
|
+
/** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */
|
|
156
|
+
readonly state: State.Values<this>;
|
|
157
|
+
/** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */
|
|
158
|
+
setState: (state: any, callback?: () => void) => void;
|
|
159
|
+
/** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */
|
|
160
|
+
forceUpdate: (callback?: () => void) => void;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Wrap a content element in its context provider, a Suspense boundary (unless
|
|
165
|
+
* `fallback` is `false`) and, when `catch` is set, the host error boundary.
|
|
166
|
+
*/
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/runtime.d.ts
|
|
169
|
+
declare const Runtime: {
|
|
170
|
+
/** Host own-property keys to trap out of observed state; assigned by each adapter. */ignore: string[];
|
|
171
|
+
createElement(type: any, props?: any, ...children: any[]): any;
|
|
172
|
+
createContext<T>(value: T): any;
|
|
173
|
+
useContext(context: any): any;
|
|
174
|
+
useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];
|
|
175
|
+
useEffect(effect: () => (() => void) | void, deps?: any[]): void;
|
|
176
|
+
useRef<T>(initial: T): {
|
|
177
|
+
current: T;
|
|
178
|
+
};
|
|
179
|
+
/** Consumed for pre-commit revision validation; absent where commits
|
|
180
|
+
* cannot interleave with writes. */
|
|
181
|
+
useSyncExternalStore?(subscribe: (notify: () => void) => () => void, getSnapshot: () => number, getServerSnapshot?: () => number): number; /** Per-render-attempt lifecycle, set by each adapter (React stacks attempts; others no-op). */
|
|
182
|
+
dedupe(from: Component, context: Context$1): {
|
|
183
|
+
commit(): void;
|
|
184
|
+
remove(): void;
|
|
185
|
+
}; /** Host error-boundary component, wrapping a Component whose `catch` is set. */
|
|
186
|
+
ErrorBoundary: unknown;
|
|
187
|
+
Suspense: any;
|
|
188
|
+
};
|
|
189
|
+
//#endregion
|
|
190
|
+
export { Consumer as n, Provider as r, Runtime as t };
|
|
191
|
+
//# sourceMappingURL=chunk-runtime-C-yxuYAq.d.ts.map
|
package/dist/has.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as useWatch } from "./chunk-component-
|
|
2
|
-
import { t as seam } from "./chunk-element-
|
|
1
|
+
import { c as useWatch } from "./chunk-component-BCcu60Qc.js";
|
|
2
|
+
import { t as seam } from "./chunk-element-Cs4wcriz.js";
|
|
3
3
|
import { has } from "@expressive/mvc";
|
|
4
4
|
|
|
5
5
|
//#region src/has.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { n as Consumer, r as Provider } from "./chunk-runtime-C-yxuYAq.js";
|
|
2
|
+
import { State } from "./adapter.js";
|
|
1
3
|
import { has } from "./has.js";
|
|
2
4
|
import { map } from "./map.js";
|
|
3
5
|
import { Component as Component$1, Context, def, get, ref, set, transition } from "@expressive/mvc";
|
|
4
6
|
import { JSX, ReactNode } from "react";
|
|
5
|
-
import { Consumer, Provider, State, State as adapter_default } from "./adapter";
|
|
6
7
|
|
|
7
8
|
//#region src/element.d.ts
|
|
8
9
|
declare module '@expressive/mvc' {
|
|
@@ -25,5 +26,5 @@ declare module '@expressive/mvc/runtime' {
|
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
//#endregion
|
|
28
|
-
export { Component$1 as Component, Consumer, Context, Provider, State,
|
|
29
|
+
export { Component$1 as Component, Consumer, Context, Provider, State, State as default, def, get, has, map, ref, set, transition };
|
|
29
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import "./chunk-component-
|
|
2
|
-
import "./chunk-element-
|
|
1
|
+
import { a as Runtime, i as Provider, n as Consumer } from "./chunk-component-BCcu60Qc.js";
|
|
2
|
+
import "./chunk-element-Cs4wcriz.js";
|
|
3
|
+
import { State } from "./adapter.js";
|
|
3
4
|
import { has } from "./has.js";
|
|
4
5
|
import { map } from "./map.js";
|
|
5
6
|
import { Component, Component as Component$1, Context, def, get, ref, set, transition } from "@expressive/mvc";
|
|
6
7
|
import React, { Children, Suspense, createContext, createElement, isValidElement, useContext, useEffect, useRef, useState } from "react";
|
|
7
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { host } from "@expressive/mvc/runtime";
|
|
9
|
-
import { Consumer, Provider, Runtime, State, State as adapter_default } from "./adapter";
|
|
10
10
|
|
|
11
11
|
//#region src/jsx-runtime.ts
|
|
12
12
|
host({
|
|
@@ -109,5 +109,5 @@ Object.assign(Runtime, {
|
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
//#endregion
|
|
112
|
-
export { Component, Consumer, Context, Provider, State,
|
|
112
|
+
export { Component, Consumer, Context, Provider, State, State as default, def, get, has, map, ref, set, transition };
|
|
113
113
|
//# sourceMappingURL=index.js.map
|
package/dist/map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as useWatch } from "./chunk-component-
|
|
2
|
-
import { t as seam } from "./chunk-element-
|
|
1
|
+
import { c as useWatch } from "./chunk-component-BCcu60Qc.js";
|
|
2
|
+
import { t as seam } from "./chunk-element-Cs4wcriz.js";
|
|
3
3
|
import { map } from "@expressive/mvc";
|
|
4
4
|
|
|
5
5
|
//#region src/map.ts
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressive/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.85.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",
|
|
7
7
|
"mvc",
|
|
8
8
|
"react",
|
|
9
|
+
"react-native",
|
|
10
|
+
"expo",
|
|
9
11
|
"state",
|
|
10
12
|
"state-management",
|
|
11
13
|
"reactive",
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
"test": "tsc --noEmit && vitest run --coverage"
|
|
56
58
|
},
|
|
57
59
|
"dependencies": {
|
|
58
|
-
"@expressive/mvc": "^0.
|
|
60
|
+
"@expressive/mvc": "^0.84.0"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
|
61
63
|
"@testing-library/react": "^16.3.0",
|
|
@@ -66,6 +68,6 @@
|
|
|
66
68
|
"tsdown": "^0.20.1"
|
|
67
69
|
},
|
|
68
70
|
"peerDependencies": {
|
|
69
|
-
"react": ">=16.
|
|
71
|
+
"react": ">=16.14.0 <20.0.0"
|
|
70
72
|
}
|
|
71
73
|
}
|