@expressive/react 0.76.0 → 0.78.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 +228 -0
- package/dist/context-B-HNZeaN.d.ts +49 -0
- package/dist/context-BfeYQmAX.js +59 -0
- package/dist/context-BfeYQmAX.js.map +1 -0
- package/dist/index.d.ts +10 -130
- package/dist/index.js +74 -269
- package/dist/index.js.map +1 -1
- package/dist/{state.d.ts → runtime.d.ts} +73 -34
- package/dist/runtime.js +74 -0
- package/dist/runtime.js.map +1 -0
- package/package.json +21 -17
- package/LICENSE +0 -21
- package/dist/esm/component.js +0 -195
- package/dist/esm/component.js.map +0 -1
- package/dist/esm/context.js +0 -40
- package/dist/esm/context.js.map +0 -1
- package/dist/esm/index.js +0 -15
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/state.js +0 -138
- package/dist/esm/state.js.map +0 -1
- package/dist/state.js +0 -142
- package/dist/state.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
<h1 align="center">@expressive/react</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
React adapter for Expressive MVC - class-based reactive state.
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@expressive/react"><img alt="NPM" src="https://badge.fury.io/js/%40expressive%2Freact.svg"></a>
|
|
9
|
+
<img src="https://img.shields.io/badge/Coverage-100%25-brightgreen.svg">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
The React adapter for [Expressive MVC](https://github.com/gabeklein/expressive-mvc). Define state as a class, use it in a component, and reads automatically subscribe - components re-render only when accessed values change.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @expressive/react react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { State } from '@expressive/react';
|
|
22
|
+
|
|
23
|
+
class Counter extends State {
|
|
24
|
+
count = 0;
|
|
25
|
+
increment = () => this.count++;
|
|
26
|
+
decrement = () => this.count--;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function CounterWidget() {
|
|
30
|
+
const { count, increment, decrement } = Counter.use();
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div>
|
|
34
|
+
<button onClick={decrement}>-</button>
|
|
35
|
+
<span>{count}</span>
|
|
36
|
+
<button onClick={increment}>+</button>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Component
|
|
43
|
+
|
|
44
|
+
`Component` is a `State` that owns its own rendering - a persistent class instance with lifecycle, context, suspense, and error handling baked in. Reach for it when state is intrinsic to a rendered unit: form controls, layout shells, route controllers, media players.
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { Component } from '@expressive/react';
|
|
48
|
+
|
|
49
|
+
class Counter extends Component {
|
|
50
|
+
count = 0;
|
|
51
|
+
render() {
|
|
52
|
+
return <button onClick={() => this.count++}>{this.count}</button>;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
<Counter />;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Anything read through `this` in `render()` is reactive; the instance survives across renders, so refs, sockets, and Maps held on `this` persist. State fields also become optional JSX props (`<Counter count={5} />`).
|
|
60
|
+
|
|
61
|
+
### Render composition
|
|
62
|
+
|
|
63
|
+
When a subclass overrides `render()`, it **composes** with its base rather than replacing it - no `super.render()`. Each `render()` up the prototype chain wraps the one below, base-outermost, with the inner output arriving as `props.children`.
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
class Frame extends Component {
|
|
67
|
+
render(props = {} as { children?: React.ReactNode }) {
|
|
68
|
+
return (
|
|
69
|
+
<section className="frame">
|
|
70
|
+
<header>Frame</header>
|
|
71
|
+
{props.children}
|
|
72
|
+
</section>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
class Page extends Frame {
|
|
78
|
+
body = 'Hello';
|
|
79
|
+
render() {
|
|
80
|
+
return <p>{this.body}</p>;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// <Page /> -> <section class="frame"><header>Frame</header><p>Hello</p></section>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Every layer binds to the same live instance, so all read the same reactive `this`. A base that wraps must declare a `props` parameter and render `props.children` - a layer that ignores it silently drops everything below. (A base can also choose to *defer* to a subclass's render, e.g. a leaf `<a>` that's overridable; the base detects the subclass content by identity and returns it as-is.)
|
|
88
|
+
|
|
89
|
+
### Subcomponents
|
|
90
|
+
|
|
91
|
+
PascalCase members become their own reactive React components scoped to the live instance. They read the parent's reactive `this` directly - no props plumbing - yet each is an isolated component with its own hooks and boundary. Subclasses override them to customize pieces without touching behavior.
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
abstract class Toggle extends Component {
|
|
95
|
+
active = false;
|
|
96
|
+
|
|
97
|
+
toggle = () => {
|
|
98
|
+
this.active = !this.active;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
Active() { return null; } // subclasses fill these in
|
|
102
|
+
Inactive() { return null; }
|
|
103
|
+
|
|
104
|
+
render() {
|
|
105
|
+
return (
|
|
106
|
+
<div onClick={this.toggle}>
|
|
107
|
+
{this.active ? <this.Active /> : <this.Inactive />}
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class DarkModeSwitch extends Toggle {
|
|
114
|
+
Active() { return <span>Dark</span>; }
|
|
115
|
+
Inactive() { return <span>Light</span>; }
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The base owns behavior and structure; subclasses author only the rendering. Override a subcomponent as a **method** when it takes no props, or as an **arrow field** when you want its props type inferred from the base - which is how `@expressive/router`'s [`NavLinks`](https://github.com/gabeklein/expressive-mvc/blob/main/packages/router/README.md#generated-navigation) exposes its overridable `Item` / `List` / `Group` members.
|
|
120
|
+
|
|
121
|
+
### Self-providing context
|
|
122
|
+
|
|
123
|
+
A `Component` provides *itself* to context automatically - no `Provider` needed. Both its own render output and any `children` passed in can read it with `get()`.
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
class Tabs extends Component {
|
|
127
|
+
active = 0;
|
|
128
|
+
render(props = {} as { children?: React.ReactNode }) {
|
|
129
|
+
return <div className="tabs">{props.children}</div>;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function Tab({ index, label }: { index: number; label: string }) {
|
|
134
|
+
const tabs = Tabs.get(); // reads the enclosing Tabs instance
|
|
135
|
+
return (
|
|
136
|
+
<button
|
|
137
|
+
className={tabs.active === index ? 'on' : undefined}
|
|
138
|
+
onClick={() => (tabs.active = index)}>
|
|
139
|
+
{label}
|
|
140
|
+
</button>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
<Tabs>
|
|
145
|
+
<Tab index={0} label="One" />
|
|
146
|
+
<Tab index={1} label="Two" />
|
|
147
|
+
</Tabs>;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
It works the same whether the consumer is part of the Component's own render or is passed in as `children` - both sit under the instance's context. A render-less `Component` still self-provides, which is what makes it useful purely as a context/boundary placement.
|
|
151
|
+
|
|
152
|
+
### Props
|
|
153
|
+
|
|
154
|
+
State fields become optional JSX props, **merged onto the instance every render** - passing `count={5}` is the same as assigning `this.count = 5`. Extra props beyond fields are read through a parameter on `render`:
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
class Greeting extends Component {
|
|
158
|
+
name = 'World'; // -> optional `name` prop
|
|
159
|
+
|
|
160
|
+
render(props = {} as { loud?: boolean }) { // extra render prop
|
|
161
|
+
return <h1>Hello {this.name}{props.loud && '!!!'}</h1>;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
<Greeting name="React" loud />;
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Every Component also accepts three special props:
|
|
169
|
+
|
|
170
|
+
- **`is`** - callback handed the instance once, at creation.
|
|
171
|
+
- **`ref`** - standard React ref; set after mount, cleared on unmount.
|
|
172
|
+
- **`fallback`** - Suspense/error UI, overriding the instance's own.
|
|
173
|
+
|
|
174
|
+
### Suspense
|
|
175
|
+
|
|
176
|
+
A value that isn't ready yet suspends the render; `fallback` shows in the meantime.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { Component, set } from '@expressive/react';
|
|
180
|
+
|
|
181
|
+
class Profile extends Component {
|
|
182
|
+
user = set<User>(); // undefined until set - suspends render
|
|
183
|
+
fallback = <Spinner />;
|
|
184
|
+
|
|
185
|
+
render() {
|
|
186
|
+
return <span>{this.user.name}</span>;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Shared state via context
|
|
192
|
+
|
|
193
|
+
Provide a model once; descendants read it with `State.get()` - no props, no selectors.
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
import { Provider } from '@expressive/react';
|
|
197
|
+
|
|
198
|
+
class Session extends State {
|
|
199
|
+
user = 'guest';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function App() {
|
|
203
|
+
return (
|
|
204
|
+
<Provider for={Session}>
|
|
205
|
+
<Profile />
|
|
206
|
+
</Provider>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function Profile() {
|
|
211
|
+
const { user } = Session.get(); // nearest Session in context
|
|
212
|
+
return <p>Signed in as {user}</p>;
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**At a glance**
|
|
217
|
+
|
|
218
|
+
- **`State.use()`** - create an instance bound to a component's lifecycle.
|
|
219
|
+
- **`State.get()`** - read shared state from context, no prop drilling.
|
|
220
|
+
- **`Provider` / `Consumer`** - explicit hierarchical dependency injection.
|
|
221
|
+
- **`Component`** - smart controls and shells whose behavior lives in the tree.
|
|
222
|
+
- **Suspense & error boundaries** - async values suspend; `catch()` handles child errors.
|
|
223
|
+
|
|
224
|
+
Full guide and API reference → **[github.com/gabeklein/expressive-mvc](https://github.com/gabeklein/expressive-mvc)**
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
MIT
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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/index.d.ts
CHANGED
|
@@ -1,135 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import { r as Provider, t as Consumer } from "./context-B-HNZeaN.js";
|
|
2
|
+
import { Component, Context, Observer, def, get, hot, ref, set } from "@expressive/mvc";
|
|
3
|
+
import { JSX, ReactNode } from "react";
|
|
4
|
+
import { State, State as runtime_default, use } from "./runtime";
|
|
5
5
|
|
|
6
|
-
//#region src/
|
|
7
|
-
declare
|
|
8
|
-
|
|
9
|
-
|
|
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) => ReactNode | void;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
declare function Consumer<T extends State$2>(props: Consumer.Props<T>): string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<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?: ReactNode;
|
|
28
|
-
/** A fallback tree to show when suspended. */
|
|
29
|
-
fallback?: ReactNode;
|
|
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$2> = SharedProps & {
|
|
37
|
-
for: T | State$2.Type<T>;
|
|
38
|
-
is: (instance: T) => void;
|
|
39
|
-
} & { [K in State$2.Field<T>]?: T[K] };
|
|
40
|
-
type ForMultipleProps<T extends State$2> = SharedProps & {
|
|
41
|
-
for: Context$1.Accept<T>;
|
|
42
|
-
is?: ForEach<T>;
|
|
43
|
-
};
|
|
44
|
-
type Props<T extends State$2 = State$2> = ForSingleProps<T> | ForMultipleProps<T>;
|
|
45
|
-
}
|
|
46
|
-
declare function Provider<T extends State$2>(props: Provider.Props<T>): react.FunctionComponentElement<react.ProviderProps<Context$1>>;
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/component.d.ts
|
|
49
|
-
type StateProps<T extends State$1> = { [K in Exclude<keyof T, keyof Component>]?: T[K] };
|
|
50
|
-
type RenderProps<T> = T extends {
|
|
51
|
-
render(props: infer P): any;
|
|
52
|
-
} ? {} extends P ? {
|
|
53
|
-
children?: ReactNode;
|
|
54
|
-
} : P : {
|
|
55
|
-
children?: ReactNode;
|
|
56
|
-
};
|
|
57
|
-
interface ComponentProps<T extends Component> {
|
|
58
|
-
/** Callback for newly created instance. Only called once. */
|
|
59
|
-
is?: (instance: T) => void;
|
|
60
|
-
/** Fallback to show when suspended or in error recovery. */
|
|
61
|
-
fallback?: ReactNode;
|
|
62
|
-
}
|
|
63
|
-
type Props<T extends Component> = StateProps<T> & ComponentProps<T> & RenderProps<T>;
|
|
64
|
-
declare module '@expressive/state' {
|
|
65
|
-
namespace State {
|
|
66
|
-
export type { Component, Props };
|
|
6
|
+
//#region src/jsx-runtime.d.ts
|
|
7
|
+
declare module '@expressive/mvc/jsx-runtime' {
|
|
8
|
+
interface Host {
|
|
9
|
+
node: ReactNode;
|
|
10
|
+
intrinsics: JSX.IntrinsicElements;
|
|
67
11
|
}
|
|
68
12
|
}
|
|
69
|
-
declare class Component extends State$1 {
|
|
70
|
-
static contextType: React.Context<Context$1>;
|
|
71
|
-
/**
|
|
72
|
-
* All JSX attributes passed to this component.
|
|
73
|
-
* Includes state-derived props, render props, and built-in props like `is` and `fallback`.
|
|
74
|
-
*
|
|
75
|
-
* Will incorperate extra props you declare as props parameter in `render` method.
|
|
76
|
-
*/
|
|
77
|
-
readonly props: Props<this>;
|
|
78
|
-
/** @deprecated Only to satisfy React JSX. Use `this.get(State)` instead. */
|
|
79
|
-
readonly context: Context$1;
|
|
80
|
-
/** @deprecated Only to satisfy React JSX. Use `this.get()` instead. */
|
|
81
|
-
readonly state: State$1.Values<this>;
|
|
82
|
-
/** @deprecated Only to satisfy React JSX. Not implemented. */
|
|
83
|
-
setState: (state: any, callback?: () => void) => void;
|
|
84
|
-
/** @deprecated Only to satisfy React JSX. Not implemented. */
|
|
85
|
-
forceUpdate: (callback?: () => void) => void;
|
|
86
|
-
/**
|
|
87
|
-
* Content to display while this component or its children are suspended.
|
|
88
|
-
* Will cover suspense by pending properties in `this.render` as well.
|
|
89
|
-
* Can be set as a class property or overridden via the `fallback` JSX prop.
|
|
90
|
-
*
|
|
91
|
-
* Defaults to null - nothing will be rendered.
|
|
92
|
-
*/
|
|
93
|
-
fallback: ReactNode;
|
|
94
|
-
constructor(nextProps: any, ...rest: any[]);
|
|
95
|
-
/**
|
|
96
|
-
* Output for this component. Override to define custom JSX.
|
|
97
|
-
*
|
|
98
|
-
* Properties accessed via `this` are reactive and will trigger a render when , in addition to props.
|
|
99
|
-
*
|
|
100
|
-
* Accepts optional parameter to receive extra props
|
|
101
|
-
* from JSX, beyond those merged to state properties.
|
|
102
|
-
*
|
|
103
|
-
* To declare extra props use `props = {} as { ... }` with expected shape.
|
|
104
|
-
* A default is required to satisfy TypeScript but safely ignored.
|
|
105
|
-
*
|
|
106
|
-
* ```ts
|
|
107
|
-
* render(props = {} as { label: string }) {
|
|
108
|
-
* return <span>{props.label}</span>;
|
|
109
|
-
* }
|
|
110
|
-
* ```
|
|
111
|
-
* Usable as:
|
|
112
|
-
* ```tsx
|
|
113
|
-
* <MyComponent label="Hello" />
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
* These must be compatible with State-derived properties, or be unused.
|
|
117
|
-
* Props you declare as not-optional will be required by the JSX element.
|
|
118
|
-
*
|
|
119
|
-
* Without a parameter, children are accepted by default and passed through provider.
|
|
120
|
-
*/
|
|
121
|
-
render(props?: {}): ReactNode;
|
|
122
|
-
/**
|
|
123
|
-
* Called when a child component throws during render.
|
|
124
|
-
* While this is pending, `fallback` is displayed.
|
|
125
|
-
* When resolved, the error boundary resets and `render` is called again.
|
|
126
|
-
*
|
|
127
|
-
* Override to handle errors - set `this.fallback` for error-specific UI,
|
|
128
|
-
* await async recovery, or await user interaction before retrying. If you
|
|
129
|
-
* assign a fallback within catch, it will be reverted after resolved.
|
|
130
|
-
*/
|
|
131
|
-
catch?(error: Error): Promise<void> | void;
|
|
132
|
-
}
|
|
133
13
|
//#endregion
|
|
134
|
-
export { Component, Consumer, Context,
|
|
14
|
+
export { Component, Consumer, Context, Observer, Provider, State, def, runtime_default as default, get, hot, ref, set, use };
|
|
135
15
|
//# sourceMappingURL=index.d.ts.map
|