@expressive/react 0.90.0 → 0.92.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 +31 -23
- package/dist/adapter.d.ts +3 -3
- package/dist/adapter.js +3 -135
- package/dist/{chunk-runtime-Cp1W-hQO.d.ts → chunk-runtime-DNnZ2rnk.d.ts} +3 -49
- package/dist/{chunk-component-BZoZVrRW.js → chunk-state.get-CwOD24xe.js} +110 -14
- package/dist/chunk-state.get-CwOD24xe.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.js +72 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/adapter.js.map +0 -1
- package/dist/chunk-component-BZoZVrRW.js.map +0 -1
- package/dist/chunk-element-CrZVk-LG.js +0 -45
- package/dist/chunk-element-CrZVk-LG.js.map +0 -1
- package/dist/has.d.ts +0 -2
- package/dist/has.js +0 -17
- package/dist/has.js.map +0 -1
- package/dist/map.d.ts +0 -2
- package/dist/map.js +0 -17
- package/dist/map.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,36 +11,44 @@
|
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
The React adapter for [Expressive MVC](https://github.com/gabeklein/expressive-mvc). Define state as a class,
|
|
14
|
+
The React adapter for [Expressive MVC](https://github.com/gabeklein/expressive-mvc). Define state as a class, render it as a component, and reads automatically subscribe - components re-render only when accessed values change.
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
npm install @expressive/mvc @expressive/react
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
`@expressive/mvc` is a peer dependency: import `Model`, `Component` and instructions from it, and import `@expressive/react` once from your entry so the host registers. Provide an instance to a subtree with `<Component for={Model}>` - `Provider` and `Consumer` were removed. The adapter
|
|
20
|
+
`@expressive/mvc` is a peer dependency: import `Model`, `Component` and instructions from it, and import `@expressive/react` once from your entry so the host registers. Provide an instance to a subtree with `<Component for={Model}>` - `Provider` and `Consumer` were removed. The adapter exports nothing for app code.
|
|
21
21
|
|
|
22
22
|
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`.
|
|
23
23
|
|
|
24
24
|
```tsx
|
|
25
|
-
import {
|
|
25
|
+
import { Component } from '@expressive/mvc';
|
|
26
26
|
|
|
27
|
-
class Counter extends
|
|
27
|
+
class Counter extends Component {
|
|
28
28
|
count = 0;
|
|
29
|
-
increment = () => this.count++;
|
|
30
|
-
decrement = () => this.count--;
|
|
31
|
-
}
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
increment() {
|
|
31
|
+
this.count++;
|
|
32
|
+
}
|
|
35
33
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
decrement() {
|
|
35
|
+
this.count--;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
render() {
|
|
39
|
+
const { count, increment, decrement } = this;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div>
|
|
43
|
+
<button onClick={decrement}>-</button>
|
|
44
|
+
<span>{count}</span>
|
|
45
|
+
<button onClick={increment}>+</button>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
43
49
|
}
|
|
50
|
+
|
|
51
|
+
<Counter count={5} />;
|
|
44
52
|
```
|
|
45
53
|
|
|
46
54
|
## Component
|
|
@@ -70,9 +78,9 @@ PascalCase members become their own reactive React components scoped to the live
|
|
|
70
78
|
abstract class Toggle extends Component {
|
|
71
79
|
active = false;
|
|
72
80
|
|
|
73
|
-
toggle
|
|
81
|
+
toggle() {
|
|
74
82
|
this.active = !this.active;
|
|
75
|
-
}
|
|
83
|
+
}
|
|
76
84
|
|
|
77
85
|
Active() { return null; } // subclasses fill these in
|
|
78
86
|
Inactive() { return null; }
|
|
@@ -143,11 +151,12 @@ class Greeting extends Component {
|
|
|
143
151
|
<Greeting name="React" loud />;
|
|
144
152
|
```
|
|
145
153
|
|
|
146
|
-
Every Component also accepts
|
|
154
|
+
Every Component also accepts four special props:
|
|
147
155
|
|
|
148
|
-
- **`is`** - callback handed the instance once, at creation.
|
|
156
|
+
- **`is`** - callback handed the instance once, at creation; an object it returns is assigned to the instance.
|
|
149
157
|
- **`ref`** - standard React ref; set after mount, cleared on unmount.
|
|
150
158
|
- **`fallback`** - Suspense/error UI, overriding the instance's own.
|
|
159
|
+
- **`catch`** - error boundary for this element's children, called `(error, instance)`.
|
|
151
160
|
|
|
152
161
|
### Suspense
|
|
153
162
|
|
|
@@ -171,7 +180,7 @@ class Profile extends Component {
|
|
|
171
180
|
Provide an instance once; descendants read it with `Model.get()` - no props, no selectors.
|
|
172
181
|
|
|
173
182
|
```tsx
|
|
174
|
-
import { Component } from '@expressive/mvc';
|
|
183
|
+
import { Model, Component } from '@expressive/mvc';
|
|
175
184
|
|
|
176
185
|
class Session extends Model {
|
|
177
186
|
user = 'guest';
|
|
@@ -193,10 +202,9 @@ function Profile() {
|
|
|
193
202
|
|
|
194
203
|
**At a glance**
|
|
195
204
|
|
|
196
|
-
- **`
|
|
205
|
+
- **`Component`** - a class that renders: owns its state, lifecycle and boundaries.
|
|
197
206
|
- **`Model.get()`** - read shared state from context, no prop drilling.
|
|
198
207
|
- **`<Component for={Model}>`** - explicit hierarchical dependency injection.
|
|
199
|
-
- **`Component`** - smart widgets and shells whose behavior lives in the tree.
|
|
200
208
|
- **Suspense & error boundaries** - async values suspend; `catch()` handles child errors.
|
|
201
209
|
|
|
202
210
|
Full guide and API reference → **[github.com/gabeklein/expressive-mvc](https://github.com/gabeklein/expressive-mvc)**
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as Runtime } from "./chunk-runtime-
|
|
2
|
-
import { Model
|
|
3
|
-
export { Model, Runtime
|
|
1
|
+
import { t as Runtime } from "./chunk-runtime-DNnZ2rnk.js";
|
|
2
|
+
import { Model } from "@expressive/mvc";
|
|
3
|
+
export { Model, Runtime };
|
package/dist/adapter.js
CHANGED
|
@@ -1,136 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { observer, watch } from "@expressive/mvc/observable";
|
|
1
|
+
import { r as Runtime } from "./chunk-state.get-CwOD24xe.js";
|
|
2
|
+
import { Model } from "@expressive/mvc";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
Model$1.get = function get(argument) {
|
|
7
|
-
const Type = this;
|
|
8
|
-
const [tick, next] = Runtime.useState(0);
|
|
9
|
-
const claim = useSettle(tick);
|
|
10
|
-
const local = Context.get();
|
|
11
|
-
const dispatch = useWeak(next);
|
|
12
|
-
return useFactory(() => {
|
|
13
|
-
let unwatch;
|
|
14
|
-
let mounted = false;
|
|
15
|
-
let pending = false;
|
|
16
|
-
let value;
|
|
17
|
-
let force;
|
|
18
|
-
function update() {
|
|
19
|
-
pending = false;
|
|
20
|
-
dispatch.deref()((x) => x + 1);
|
|
21
|
-
}
|
|
22
|
-
function observed() {
|
|
23
|
-
if (mounted) {
|
|
24
|
-
claim();
|
|
25
|
-
update();
|
|
26
|
-
} else pending = true;
|
|
27
|
-
}
|
|
28
|
-
function refresh(action) {
|
|
29
|
-
if (typeof action == "function") action = action();
|
|
30
|
-
update();
|
|
31
|
-
if (action instanceof Promise) return action.finally(update);
|
|
32
|
-
}
|
|
33
|
-
function release() {
|
|
34
|
-
unsubscribe();
|
|
35
|
-
unwatch?.();
|
|
36
|
-
unwatch = void 0;
|
|
37
|
-
}
|
|
38
|
-
function attach(next) {
|
|
39
|
-
if (local.get(Type, false) !== next) return;
|
|
40
|
-
unwatch?.();
|
|
41
|
-
if (observer(next) === null) {
|
|
42
|
-
value = typeof argument === "function" ? argument.call(next, next, refresh) : next;
|
|
43
|
-
unwatch = () => {};
|
|
44
|
-
return release;
|
|
45
|
-
}
|
|
46
|
-
let first = true;
|
|
47
|
-
unwatch = watch(next, (current) => {
|
|
48
|
-
if (typeof argument === "function") {
|
|
49
|
-
const next = argument.call(current, current, refresh);
|
|
50
|
-
if (next === value) return;
|
|
51
|
-
value = next;
|
|
52
|
-
} else value = current;
|
|
53
|
-
if (!first) observed();
|
|
54
|
-
first = false;
|
|
55
|
-
return (update) => {
|
|
56
|
-
if (update === true) force();
|
|
57
|
-
};
|
|
58
|
-
}, argument === true, Runtime.startTransition);
|
|
59
|
-
if (mounted) {
|
|
60
|
-
pending = true;
|
|
61
|
-
queueMicrotask(() => pending && update());
|
|
62
|
-
}
|
|
63
|
-
return release;
|
|
64
|
-
}
|
|
65
|
-
const unsubscribe = local.get(Type, attach);
|
|
66
|
-
if (!unwatch) {
|
|
67
|
-
unsubscribe();
|
|
68
|
-
if (argument === false) return () => void 0;
|
|
69
|
-
throw new Error(`Could not find ${Type} in context.`);
|
|
70
|
-
}
|
|
71
|
-
if (value === null) {
|
|
72
|
-
release();
|
|
73
|
-
return () => null;
|
|
74
|
-
}
|
|
75
|
-
if (value instanceof Promise) {
|
|
76
|
-
let error;
|
|
77
|
-
release();
|
|
78
|
-
value.then((x) => value = x, (e) => error = e).finally(update);
|
|
79
|
-
value = null;
|
|
80
|
-
return () => {
|
|
81
|
-
if (error) throw error;
|
|
82
|
-
return value === void 0 ? null : value;
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return () => {
|
|
86
|
-
pending = false;
|
|
87
|
-
useSetup((_self, reset) => {
|
|
88
|
-
force = reset;
|
|
89
|
-
return () => {
|
|
90
|
-
mounted = true;
|
|
91
|
-
if (pending) update();
|
|
92
|
-
return release;
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
return value === void 0 ? null : value;
|
|
96
|
-
};
|
|
97
|
-
})();
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region src/state.use.ts
|
|
102
|
-
Model$1.use = function use(...args) {
|
|
103
|
-
const outer = Context.get();
|
|
104
|
-
return useFactory(() => {
|
|
105
|
-
const add = (arg) => typeof arg == "object" && instance.set(arg);
|
|
106
|
-
let use = (...args) => Promise.all(args.flat().map(add));
|
|
107
|
-
const instance = new this((x) => {
|
|
108
|
-
if ("use" in x && typeof x.use == "function") {
|
|
109
|
-
use = x.use.bind(x);
|
|
110
|
-
use(...args);
|
|
111
|
-
} else return args;
|
|
112
|
-
});
|
|
113
|
-
const context = outer.push(instance);
|
|
114
|
-
const teardown = () => {
|
|
115
|
-
context.pop();
|
|
116
|
-
instance.set(null);
|
|
117
|
-
};
|
|
118
|
-
let ready = false;
|
|
119
|
-
return (args) => {
|
|
120
|
-
if (ready) {
|
|
121
|
-
ready = false;
|
|
122
|
-
Promise.resolve(use(...args)).finally(() => {
|
|
123
|
-
ready = true;
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
return useWatch(instance, () => {
|
|
127
|
-
ready = true;
|
|
128
|
-
return instance.mount?.();
|
|
129
|
-
}, teardown);
|
|
130
|
-
};
|
|
131
|
-
})(args);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
//#endregion
|
|
135
|
-
export { Model, Runtime, State };
|
|
136
|
-
//# sourceMappingURL=adapter.js.map
|
|
4
|
+
export { Model, Runtime };
|
|
@@ -38,55 +38,8 @@ declare module '@expressive/mvc' {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
//#endregion
|
|
41
|
-
//#region src/state.use.d.ts
|
|
42
|
-
declare module '@expressive/mvc' {
|
|
43
|
-
interface UseModel extends Model {
|
|
44
|
-
/**
|
|
45
|
-
* Optional hook called when Model.use() is invoked within a React component.
|
|
46
|
-
*
|
|
47
|
-
* This is called *every render* of the component, and will intercept
|
|
48
|
-
* arguments which would otherwise be passed into the Model constructor.
|
|
49
|
-
*
|
|
50
|
-
* @param props Arguments passed to Model.use().
|
|
51
|
-
*/
|
|
52
|
-
use?(...props: any[]): Promise<void> | void;
|
|
53
|
-
/**
|
|
54
|
-
* Optional hook called once the host component commits. Return a function
|
|
55
|
-
* to run when it unmounts.
|
|
56
|
-
*
|
|
57
|
-
* Not called during server render, nor for an instance merely observed or
|
|
58
|
-
* placed: `.get()` and `{instance}` reach one a component does not own, and
|
|
59
|
-
* `Model.new()` has no component at all.
|
|
60
|
-
*
|
|
61
|
-
* Client-only effects belong here - setup which must accompany the instance
|
|
62
|
-
* itself belongs in `new()`.
|
|
63
|
-
*/
|
|
64
|
-
mount?(): (() => void) | void;
|
|
65
|
-
}
|
|
66
|
-
namespace Model {
|
|
67
|
-
type UseArgs<T extends Model> = T extends {
|
|
68
|
-
use(...props: infer P): any;
|
|
69
|
-
} ? P : Model.Args<T>;
|
|
70
|
-
/**
|
|
71
|
-
* Create and manage instance of this Model within React component.
|
|
72
|
-
*
|
|
73
|
-
* @param args Arguments to pass to constructor or `use` method (if defined).
|
|
74
|
-
* @returns Managed instance of this Model.
|
|
75
|
-
*/
|
|
76
|
-
function use<T extends UseModel>(this: Model.Type<T>, ...args: UseArgs<T>): T;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//#endregion
|
|
80
41
|
//#region src/component.d.ts
|
|
81
42
|
declare module '@expressive/mvc' {
|
|
82
|
-
namespace Component {
|
|
83
|
-
/**
|
|
84
|
-
* Not available - a Component is rendered, not a hook.
|
|
85
|
-
* Render it with `<Component />` or `{component}`.
|
|
86
|
-
* For a bare instance use `Component.new()`.
|
|
87
|
-
*/
|
|
88
|
-
const use: never;
|
|
89
|
-
}
|
|
90
43
|
interface Component {
|
|
91
44
|
/**
|
|
92
45
|
* Optional hook called once this Component commits. Return a function to
|
|
@@ -133,10 +86,11 @@ declare const Runtime: {
|
|
|
133
86
|
dedupe?(from: Component, context: Context$1): {
|
|
134
87
|
commit(): void;
|
|
135
88
|
remove(): void;
|
|
136
|
-
}; /**
|
|
89
|
+
}; /** Whether the host is certainly not rendering, so a hook probe would only throw - and may log. `undefined` when the host cannot tell. */
|
|
90
|
+
idle(): boolean | undefined; /** Host error-boundary component, wrapping a Component whose `catch` is set. */
|
|
137
91
|
ErrorBoundary: unknown;
|
|
138
92
|
Suspense: any;
|
|
139
93
|
};
|
|
140
94
|
//#endregion
|
|
141
95
|
export { Runtime as t };
|
|
142
|
-
//# sourceMappingURL=chunk-runtime-
|
|
96
|
+
//# sourceMappingURL=chunk-runtime-DNnZ2rnk.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Component, Context as Context$1, pending, unbind } from "@expressive/mvc";
|
|
2
|
-
import { watch } from "@expressive/mvc/observable";
|
|
1
|
+
import { Component, Context, Context as Context$1, Model, pending, unbind } from "@expressive/mvc";
|
|
2
|
+
import { observer, watch } from "@expressive/mvc/observable";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime.ts
|
|
5
5
|
const Runtime = {};
|
|
@@ -180,7 +180,7 @@ Object.defineProperty(Component, "contextType", {
|
|
|
180
180
|
});
|
|
181
181
|
const _get = Context$1.get;
|
|
182
182
|
Context$1.get = (state) => {
|
|
183
|
-
if (!state) try {
|
|
183
|
+
if (!state && !Runtime.idle()) try {
|
|
184
184
|
return useAmbient();
|
|
185
185
|
} catch {}
|
|
186
186
|
return _get(state);
|
|
@@ -195,12 +195,6 @@ Object.defineProperties(Component.prototype, {
|
|
|
195
195
|
},
|
|
196
196
|
context: { set: bootstrap }
|
|
197
197
|
});
|
|
198
|
-
Object.defineProperty(Component, "use", {
|
|
199
|
-
configurable: true,
|
|
200
|
-
value() {
|
|
201
|
-
throw new Error(`${this} is a Component - render as an element instead of calling use().`);
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
198
|
/**
|
|
205
199
|
* On the root Component, host own-property keys are trapped so each lands as a
|
|
206
200
|
* plain own property (out of observed state); each adapter assigns its own set.
|
|
@@ -224,9 +218,8 @@ Component.on({
|
|
|
224
218
|
subcomponents(self);
|
|
225
219
|
}
|
|
226
220
|
});
|
|
227
|
-
function bootstrap(
|
|
228
|
-
context =
|
|
229
|
-
context.set(this, () => () => this.set(null));
|
|
221
|
+
function bootstrap(parent) {
|
|
222
|
+
const context = parent.push(this, () => this.set(null));
|
|
230
223
|
Object.defineProperties(this, {
|
|
231
224
|
context: {
|
|
232
225
|
get: () => context,
|
|
@@ -318,5 +311,108 @@ function subcomponents(target) {
|
|
|
318
311
|
}
|
|
319
312
|
|
|
320
313
|
//#endregion
|
|
321
|
-
|
|
322
|
-
|
|
314
|
+
//#region src/state.get.ts
|
|
315
|
+
Model.get = function get(argument) {
|
|
316
|
+
const Type = this;
|
|
317
|
+
const [tick, next] = Runtime.useState(0);
|
|
318
|
+
const claim = useSettle(tick);
|
|
319
|
+
const local = Context.get();
|
|
320
|
+
const dispatch = useWeak(next);
|
|
321
|
+
return useFactory(() => {
|
|
322
|
+
let unwatch;
|
|
323
|
+
let mounted = false;
|
|
324
|
+
let pending = false;
|
|
325
|
+
let value;
|
|
326
|
+
let force;
|
|
327
|
+
function update() {
|
|
328
|
+
pending = false;
|
|
329
|
+
dispatch.deref()((x) => x + 1);
|
|
330
|
+
}
|
|
331
|
+
function observed() {
|
|
332
|
+
if (mounted) {
|
|
333
|
+
claim();
|
|
334
|
+
update();
|
|
335
|
+
} else pending = true;
|
|
336
|
+
}
|
|
337
|
+
function refresh(action) {
|
|
338
|
+
if (typeof action == "function") action = action();
|
|
339
|
+
update();
|
|
340
|
+
if (action instanceof Promise) return action.finally(update);
|
|
341
|
+
}
|
|
342
|
+
function release() {
|
|
343
|
+
unfollow();
|
|
344
|
+
unwatch?.();
|
|
345
|
+
unwatch = void 0;
|
|
346
|
+
}
|
|
347
|
+
function attach(next) {
|
|
348
|
+
unwatch?.();
|
|
349
|
+
if (observer(next) === null) {
|
|
350
|
+
value = typeof argument === "function" ? argument.call(next, next, refresh) : next;
|
|
351
|
+
unwatch = () => {};
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
let first = true;
|
|
355
|
+
unwatch = watch(next, (current) => {
|
|
356
|
+
if (typeof argument === "function") {
|
|
357
|
+
const next = argument.call(current, current, refresh);
|
|
358
|
+
if (next === value) return;
|
|
359
|
+
value = next;
|
|
360
|
+
} else value = current;
|
|
361
|
+
if (!first) observed();
|
|
362
|
+
first = false;
|
|
363
|
+
return (update) => {
|
|
364
|
+
if (update === true) force();
|
|
365
|
+
};
|
|
366
|
+
}, argument === true, Runtime.startTransition);
|
|
367
|
+
}
|
|
368
|
+
let found;
|
|
369
|
+
function follow(next) {
|
|
370
|
+
if (next === found) return;
|
|
371
|
+
found = next;
|
|
372
|
+
unwatch?.();
|
|
373
|
+
unwatch = void 0;
|
|
374
|
+
value = void 0;
|
|
375
|
+
if (next) attach(next);
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
const unfollow = watch(local, (ctx) => {
|
|
379
|
+
if (follow(ctx.get(Type, false)) && mounted) observed();
|
|
380
|
+
}, false);
|
|
381
|
+
if (!found && argument !== false) {
|
|
382
|
+
unfollow();
|
|
383
|
+
throw new Error(`Could not find ${Type} in context.`);
|
|
384
|
+
}
|
|
385
|
+
if (value === null) {
|
|
386
|
+
release();
|
|
387
|
+
return () => null;
|
|
388
|
+
}
|
|
389
|
+
if (value instanceof Promise) {
|
|
390
|
+
let error;
|
|
391
|
+
release();
|
|
392
|
+
value.then((x) => value = x, (e) => error = e).finally(update);
|
|
393
|
+
value = null;
|
|
394
|
+
return () => {
|
|
395
|
+
if (error) throw error;
|
|
396
|
+
return value === void 0 ? null : value;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
return () => {
|
|
400
|
+
follow(local.get(Type, false));
|
|
401
|
+
pending = false;
|
|
402
|
+
useSetup((_self, reset) => {
|
|
403
|
+
force = reset;
|
|
404
|
+
return () => {
|
|
405
|
+
mounted = true;
|
|
406
|
+
if (pending) update();
|
|
407
|
+
return release;
|
|
408
|
+
};
|
|
409
|
+
});
|
|
410
|
+
if (found) return value === void 0 ? null : value;
|
|
411
|
+
if (argument !== false) throw new Error(`Could not find ${Type} in context.`);
|
|
412
|
+
};
|
|
413
|
+
})();
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
//#endregion
|
|
417
|
+
export { useWatch as a, useFactory as i, Context$1 as n, weak as o, Runtime as r, createFrame as t };
|
|
418
|
+
//# sourceMappingURL=chunk-state.get-CwOD24xe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-state.get-CwOD24xe.js","names":["Context"],"sources":["../src/runtime.ts","../src/context.ts","../src/component.ts","../src/state.get.ts"],"sourcesContent":["import type { Component } from '@expressive/mvc';\nimport { watch } from '@expressive/mvc/observable';\nimport { pending } from '@expressive/mvc';\nimport type { Context } from './context';\n\ninterface Settle {\n waiting?: (() => void)[];\n claim(): void;\n release(): void;\n}\n\ninterface Setup {\n rendered: number;\n revision: number;\n mounted?: boolean;\n fresh?: boolean;\n getRevision?: () => number;\n lapsed?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | void;\n teardown?: () => void;\n}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: Weak<(next: (previous: number) => number) => void>;\n output: T;\n}\n\ninterface Weak<T> {\n deref(): T | undefined;\n}\n\nexport const Runtime = {} as {\n /** Host own-property keys to trap out of observed state; assigned by each adapter. */\n ignore: string[];\n createElement(type: any, props?: any, ...children: any[]): any;\n createContext<T>(value: T): any;\n useContext(context: any): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n /** Non-urgent bracket a subscriber replays through; absent where the host\n * cannot defer, which keeps normal timing. */\n startTransition?(work: () => void): void;\n /** Consumed for pre-commit revision validation; absent where commits\n * cannot interleave with writes. */\n useSyncExternalStore?(\n subscribe: (notify: () => void) => () => void,\n getSnapshot: () => number,\n getServerSnapshot?: () => number\n ): number;\n /** Per-render-attempt lifecycle; absent where render attempts do not stack. */\n dedupe?(from: Component, context: Context): { commit(): void; remove(): void };\n /** Whether the host is certainly not rendering, so a hook probe would only throw - and may log. `undefined` when the host cannot tell. */\n idle(): boolean | undefined;\n /** Host error-boundary component, wrapping a Component whose `catch` is set. */\n ErrorBoundary: unknown;\n Suspense: any;\n};\n\nconst noop = () => () => {};\n\nexport function useFactory<T extends object>(factory: () => T) {\n const ref = Runtime.useRef<T | null>(null);\n return ref.current || (ref.current = factory());\n}\n\n/**\n * Returns a claim on the update being replayed, held until this hook commits\n * carrying it - or until unmount, where it never will. Keyed on `tick` so an\n * urgent commit in the meantime, which leaves the deferred update queued, does\n * not release it.\n */\nexport function useSettle(tick: number) {\n const ref = Runtime.useRef<Settle | null>(null);\n const settle = ref.current || (ref.current = {\n claim() {\n const held = pending();\n\n if (held) (settle.waiting ||= []).push(held);\n },\n release() {\n const { waiting } = settle;\n\n if (!waiting) return;\n settle.waiting = undefined;\n\n for (const held of waiting) held();\n }\n });\n\n Runtime.useEffect(() => {\n settle.release();\n return settle.release;\n }, [tick]);\n\n return settle.claim;\n}\n\n/**\n * Run `init` once for the life of a hook and clean up when it unmounts, safe\n * under React StrictMode - a remount shares the render counter, so neither the\n * setup nor its cleanup repeats. A cleanup following a render not yet committed\n * - Fast Refresh re-running effects - defers a microtask, and is dropped if the\n * effect runs again. `reset` invalidates the rendered value so in-flight render\n * attempts revalidate.\n *\n * @returns The hook's own record, plus the render counter and its setter.\n */\nexport function useSetup<T extends Setup>(\n init: (self: T, reset: () => void) => () => (() => void) | void,\n teardown?: () => void\n) {\n const { current } = Runtime.useRef({ rendered: 0, revision: 0 } as T);\n\n const [tick, update] = Runtime.useState(() => {\n if (!current.rendered)\n current.commit = init(current, () => {\n current.revision++;\n });\n\n return current.rendered++;\n });\n\n useReap(current, teardown);\n\n const getRevision = (current.getRevision ||= () => current.revision);\n\n current.fresh = true;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.fresh = false;\n });\n\n Runtime.useEffect(() => {\n current.mounted = true;\n current.lapsed = false;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n return () => {\n if (!current.fresh) {\n if (--current.rendered <= 0) release(current);\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) release(current);\n });\n }\n }, []);\n\n return [current, tick, update] as const;\n}\n\nfunction release(setup: Setup) {\n setup.release?.();\n setup.teardown?.();\n}\n\nlet reaper: FinalizationRegistry<Setup> | null | undefined;\n\nfunction useReap(setup: Setup, teardown?: () => void) {\n const token = Runtime.useRef<object | null>(null);\n\n if (!teardown || setup.teardown) return;\n\n setup.teardown = teardown;\n\n if (reaper === undefined)\n reaper = typeof FinalizationRegistry == 'function'\n ? new FinalizationRegistry((setup) => setup.mounted || setup.teardown!())\n : null;\n\n reaper?.register((token.current = {}), setup);\n}\n\nexport function weak<T extends object>(value: T): Weak<T> {\n return typeof WeakRef == 'function' ? new WeakRef(value) : { deref: () => value };\n}\n\nexport function useWeak<T extends object>(value: T) {\n const ref = Runtime.useRef<Weak<T> | null>(null);\n return (ref.current ||= weak(value));\n}\n\n/**\n * Mount-effect with a refreshable return value. Publishing a value before mount\n * defers the update to it, and one published after claims the update being\n * replayed until this hook commits carrying it.\n *\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (\n refresh: (next: T) => void,\n reset: () => void\n ) => () => (() => void) | void,\n teardown?: () => void\n) {\n const [current, tick, update] = useSetup<Hook<T>>((self, reset) => {\n const mount = callback((next) => {\n self.output = next;\n\n if (self.mounted) {\n claim();\n self.update?.deref()!((x) => x + 1);\n }\n else if (self.update) self.queued = true;\n }, reset);\n\n return () => {\n const cleanup = mount();\n\n if (self.queued) {\n self.queued = false;\n self.update!.deref()!((x) => x + 1);\n }\n\n return cleanup;\n };\n }, teardown);\n\n const claim = useSettle(tick);\n\n current.update ||= weak(update);\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | void,\n teardown?: () => void\n) {\n return useHook<T>((refresh, reset) => {\n const release = watch(from, (current) => {\n refresh(current);\n\n return (update) => {\n if (update === true) reset();\n };\n }, undefined, Runtime.startTransition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n if (typeof cleanup == 'function') cleanup();\n };\n };\n }, teardown) ?? from;\n}\n","import { Model, Context, Component } from '@expressive/mvc';\nimport { Runtime } from './runtime';\n\nlet shared: any;\n\n/**\n * Lazily-created context carrying the active {@link Context} down the tree.\n * Lazy because the framework's `createContext` arrives via {@link Runtime},\n * which an adapter's entry populates at load - after this module evaluates.\n */\nfunction Layers() {\n return shared || (shared = Runtime.createContext(Context.root));\n}\n\n/** Read the ambient {@link Context} from the nearest Layers provider. */\nfunction useAmbient() {\n return Runtime.useContext(Layers());\n}\n\n/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */\nfunction createProvider(context: Context, children: any) {\n return Runtime.createElement(Layers().Provider, { value: context, children });\n}\n\n// Class components consume the active Context through the host's `contextType`\nObject.defineProperty(Component, 'contextType', { configurable: true, get: Layers });\n\nconst _get = Context.get;\n\nContext.get = (state?: Model) => {\n if (!state && !Runtime.idle())\n try {\n return useAmbient();\n } catch { }\n\n return _get(state);\n};\n\nexport { 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 interface Component {\n /**\n * Optional hook called once this Component commits. Return a function to\n * run when it unmounts.\n *\n * Not called during server render, nor for an instance placed as\n * `{component}` - a placement does not own what it renders. Client-only\n * effects belong here; setup which must accompany the instance itself\n * belongs in `new()`.\n */\n mount?(): (() => void) | void;\n\n /** @deprecated Only to satisfy host JSX. Use `this.get(Model)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: {};\n /** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */\n setState: (state: any, callback?: () => void) => void;\n /** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */\n forceUpdate: (callback?: () => void) => void;\n }\n}\n\n// Host-agnostic seams: `state` is a read-only values bag; `context`'s setter\n// pushes a child context, registers the instance for teardown, and installs its\n// per-instance render host. Host-specific descriptors stay in each adapter.\nObject.defineProperties(Component.prototype, {\n state: {\n set() {},\n get: Component.prototype.get\n },\n context: {\n set: bootstrap\n }\n});\n\n/**\n * On the root Component, host own-property keys are trapped so each lands as a\n * plain own property (out of observed state); each adapter assigns its own set.\n */\nComponent.on({\n type(type) {\n const render = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (typeof render?.value == 'function')\n Object.defineProperty(type.prototype, 'render', { ...render, configurable: false });\n\n if (type === Component)\n for (const key of Runtime.ignore)\n Object.defineProperty(Component.prototype, key, {\n set(value) {\n Object.defineProperty(this, key, { value, writable: true });\n }\n });\n\n subcomponents(type.prototype);\n },\n setup(self) {\n subcomponents(self);\n }\n});\n\nfunction bootstrap(this: Component, parent: Context){\n const context = parent.push(this, () => this.set(null));\n\n Object.defineProperties(this, {\n context: {\n get: () => context,\n set() {}\n },\n render: {\n value: render(this, context)\n }\n });\n\n this.set(null, () => {\n Object.defineProperty(this, 'props', {\n value: this.props,\n writable: true\n });\n })\n}\n\n/**\n * Wrap a content element in its context provider, a Suspense boundary (unless\n * `fallback` is `false`) and, when `catch` is set, the host error boundary.\n */\nfunction createFrame(from: Component, context: Context, children: unknown) {\n const { createElement } = Runtime;\n\n if(from.fallback !== false)\n children = createElement(\n Runtime.Suspense,\n { fallback: from.fallback, name: String(from) },\n children\n )\n\n children = createProvider(context, children);\n\n return from.props.catch || from.catch\n ? createElement(Runtime.ErrorBoundary, { self: from, children })\n : children;\n}\n\n/**\n * Ownership host for `<Component/>`: React owns the instance, so its render\n * threads the bootstrap-pushed context through `Runtime.dedupe` (React stacks\n * render attempts) and tears that context down - destroying the instance - on\n * unmount.\n */\nfunction render(from: Component, context: Context) {\n const { createElement, dedupe } = Runtime;\n const attempt = dedupe?.(from, context);\n const { is: owner } = from;\n // Read before bootstrap shadows an instance `render` with this host.\n const own = Object.prototype.hasOwnProperty.call(owner, 'render') && owner.render;\n const teardown = () => {\n attempt?.remove();\n context.pop();\n };\n\n const Render = () => (own || Object.getPrototypeOf(owner).render).call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n const release = owner.mount?.();\n\n attempt?.commit();\n\n return release;\n }, teardown);\n\n return createFrame(from, context, createElement(Render));\n };\n\n return () => createElement(Component);\n}\n\n/** Rewrite each own capitalized function on `target` into a subcomponent. */\nfunction subcomponents(target: object) {\n for (const key of Object.getOwnPropertyNames(target)) {\n if (!/^[A-Z]/.test(key)) continue;\n const { value } = Object.getOwnPropertyDescriptor(target, key)!;\n if (typeof value != 'function') continue;\n Object.defineProperty(target, key, {\n configurable: true,\n get(this: Component) {\n const owner = this.is;\n let render = unbind(value);\n const Component = (props: unknown) =>\n render.call(useWatch(owner), props);\n\n Object.defineProperty(owner, key, {\n configurable: true,\n get: () => Component,\n set(fn: Function) {\n render = fn;\n }\n });\n\n return Component;\n },\n set(this: Component, value: unknown) {\n Object.defineProperty(this, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n\n subcomponents(this);\n }\n });\n }\n}\n\nexport { createFrame };\n","import { Model, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { Runtime, useFactory, useSettle, useSetup, useWeak } 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 Model {\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 Model, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends Model> = (\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 Model>(this: Model.Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends Model>(\n this: Model.Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends Model>(\n this: Model.Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends Model, R>(\n this: Model.Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n function get<T extends Model>(\n this: Model.Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nModel.get = function get<T extends Model>(\n this: Model.Extends<T>,\n argument?: boolean | Model.GetFactory<T, unknown>\n) {\n const Type = this;\n const [tick, next] = Runtime.useState(0);\n const claim = useSettle(tick);\n const local = Context.get();\n const dispatch = useWeak(next);\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 dispatch.deref()!((x) => x + 1);\n }\n\n function observed() {\n if (mounted) {\n claim();\n update();\n }\n else pending = true;\n }\n\n function 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 unfollow();\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;\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 Runtime.startTransition\n );\n }\n\n let found: T | undefined;\n\n function follow(next: T | undefined) {\n if (next === found) return;\n\n found = next;\n unwatch?.();\n unwatch = undefined;\n value = undefined;\n\n if (next) attach(next);\n\n return true;\n }\n\n const unfollow = watch(local, (ctx) => {\n if (follow(ctx.get(Type, false)) && mounted) observed();\n }, false);\n\n if (!found && argument !== false) {\n unfollow();\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 follow(local.get(Type, false));\n pending = false;\n useSetup((_self, reset) => {\n force = reset;\n\n return () => {\n mounted = true;\n if (pending) update();\n return release;\n };\n });\n if (found) return value === undefined ? null : value;\n if (argument !== false) throw new Error(`Could not find ${Type} in context.`);\n };\n });\n\n return render();\n};\n"],"mappings":";;;;AAiCA,MAAa,UAAU,EAAE;AA4BzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA6B,SAAkB;CAC7D,MAAM,MAAM,QAAQ,OAAiB,KAAK;AAC1C,QAAO,IAAI,YAAY,IAAI,UAAU,SAAS;;;;;;;;AAShD,SAAgB,UAAU,MAAc;CACtC,MAAM,MAAM,QAAQ,OAAsB,KAAK;CAC/C,MAAM,SAAS,IAAI,YAAY,IAAI,UAAU;EAC3C,QAAQ;GACN,MAAM,OAAO,SAAS;AAEtB,OAAI,KAAM,EAAC,OAAO,YAAY,EAAE,EAAE,KAAK,KAAK;;EAE9C,UAAU;GACR,MAAM,EAAE,YAAY;AAEpB,OAAI,CAAC,QAAS;AACd,UAAO,UAAU;AAEjB,QAAK,MAAM,QAAQ,QAAS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,aAAQ;UAER,SAAQ;AAGV,QAAI,CAAC,MAAO,WAAU;AACtB,YAAQ;AAER,YAAQ,WAAW;AACjB,SAAI,WAAW,KAAM,QAAO;;MAGhC,aAAa,MACb,QAAQ,gBACT;;EAGH,IAAI;EAEJ,SAAS,OAAO,MAAqB;AACnC,OAAI,SAAS,MAAO;AAEpB,WAAQ;AACR,cAAW;AACX,aAAU;AACV,WAAQ;AAER,OAAI,KAAM,QAAO,KAAK;AAEtB,UAAO;;EAGT,MAAM,WAAW,MAAM,QAAQ,QAAQ;AACrC,OAAI,OAAO,IAAI,IAAI,MAAM,MAAM,CAAC,IAAI,QAAS,WAAU;KACtD,MAAM;AAET,MAAI,CAAC,SAAS,aAAa,OAAO;AAChC,aAAU;AACV,SAAM,IAAI,MAAM,kBAAkB,KAAK,cAAc;;AAGvD,MAAI,UAAU,MAAM;AAClB,YAAS;AACT,gBAAa;;AAGf,MAAI,iBAAiB,SAAS;GAC5B,IAAI;AAEJ,YAAS;AAET,SACG,MACE,MAAO,QAAQ,IACf,MAAO,QAAQ,EACjB,CACA,QAAQ,OAAO;AAElB,WAAQ;AAER,gBAAa;AACX,QAAI,MAAO,OAAM;AACjB,WAAO,UAAU,SAAY,OAAO;;;AAIxC,eAAa;AACX,UAAO,MAAM,IAAI,MAAM,MAAM,CAAC;AAC9B,aAAU;AACV,aAAU,OAAO,UAAU;AACzB,YAAQ;AAER,iBAAa;AACX,eAAU;AACV,SAAI,QAAS,SAAQ;AACrB,YAAO;;KAET;AACF,OAAI,MAAO,QAAO,UAAU,SAAY,OAAO;AAC/C,OAAI,aAAa,MAAO,OAAM,IAAI,MAAM,kBAAkB,KAAK,cAAc;;GAE/E,EAEa"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { map } from "./map.js";
|
|
4
|
-
import { Component as Component$1, Context, def, get, pending, ref, set } from "@expressive/mvc";
|
|
5
|
-
import { Component as Component$3, JSX, ReactNode } from "react";
|
|
1
|
+
import { t as Runtime } from "./chunk-runtime-DNnZ2rnk.js";
|
|
2
|
+
import { Component as Component$1, JSX, ReactNode } from "react";
|
|
6
3
|
|
|
7
4
|
//#region src/element.d.ts
|
|
8
5
|
declare module '@expressive/mvc' {
|
|
@@ -22,9 +19,9 @@ declare module '@expressive/mvc/jsx-runtime' {
|
|
|
22
19
|
interface Host {
|
|
23
20
|
node: ReactNode;
|
|
24
21
|
intrinsics: JSX.IntrinsicElements;
|
|
25
|
-
elementClass: Component$
|
|
22
|
+
elementClass: Component$1<any, any>;
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
//#endregion
|
|
29
|
-
export {
|
|
26
|
+
export { type Runtime };
|
|
30
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import "
|
|
4
|
-
import { has } from "./has.js";
|
|
5
|
-
import { map } from "./map.js";
|
|
6
|
-
import { Component, Component as Component$1, Context, def, get, pending, ref, set } from "@expressive/mvc";
|
|
1
|
+
import { a as useWatch, i as useFactory, n as Context$1, o as weak, r as Runtime, t as createFrame } from "./chunk-state.get-CwOD24xe.js";
|
|
2
|
+
import "./adapter.js";
|
|
3
|
+
import { Component } from "@expressive/mvc";
|
|
7
4
|
import * as React$1 from "react";
|
|
8
5
|
import React, { Children, isValidElement } from "react";
|
|
6
|
+
import { elements, host } from "@expressive/mvc/jsx-runtime";
|
|
9
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { host } from "@expressive/mvc/jsx-runtime";
|
|
11
8
|
|
|
9
|
+
//#region src/element.ts
|
|
10
|
+
let template;
|
|
11
|
+
/**
|
|
12
|
+
* Borrow a host element's descriptors so `self` passes as a React element.
|
|
13
|
+
* `props` false keeps the target's own `props` (Component supplies its own);
|
|
14
|
+
* an object installs it as the element's props (collections have none).
|
|
15
|
+
*/
|
|
16
|
+
function seam(self, props, type, key) {
|
|
17
|
+
if (!template) template = Runtime.createElement("template");
|
|
18
|
+
const descriptors = Object.getOwnPropertyDescriptors(template);
|
|
19
|
+
const store = descriptors._store?.value;
|
|
20
|
+
if (props === false) delete descriptors.props;
|
|
21
|
+
if (store) descriptors._store.value = Object.create(Object.getPrototypeOf(store), Object.getOwnPropertyDescriptors(store));
|
|
22
|
+
Object.defineProperties(self, {
|
|
23
|
+
...descriptors,
|
|
24
|
+
$$typeof: { value: template.$$typeof },
|
|
25
|
+
...props ? { props: { value: props } } : void 0,
|
|
26
|
+
key: { value: key },
|
|
27
|
+
type: { value: type }
|
|
28
|
+
});
|
|
29
|
+
return template.$$typeof;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Every class the core declares renderable - `Component`, `has` lists and
|
|
33
|
+
* pools, `map` collections - gets the one getter. `is` resolves a derived view
|
|
34
|
+
* to its instance; a Component renders through its ownership frame, anything
|
|
35
|
+
* else through `render()`.
|
|
36
|
+
*/
|
|
37
|
+
elements((Type) => {
|
|
38
|
+
Object.defineProperty(Type.prototype, "$$typeof", { get() {
|
|
39
|
+
const self = this.is;
|
|
40
|
+
return self instanceof Component ? seam(self, false, Element.bind(self), self.key) : seam(self, {}, Members.bind(self), null);
|
|
41
|
+
} });
|
|
42
|
+
});
|
|
43
|
+
function Element() {
|
|
44
|
+
const outer = Context$1.get();
|
|
45
|
+
return useFactory(() => {
|
|
46
|
+
let from = this;
|
|
47
|
+
const context = outer.push(this);
|
|
48
|
+
const Content = () => from.render(from.props);
|
|
49
|
+
return () => {
|
|
50
|
+
from = useWatch(this, () => () => context.pop());
|
|
51
|
+
return createFrame(from, context, Runtime.createElement(Content));
|
|
52
|
+
};
|
|
53
|
+
})();
|
|
54
|
+
}
|
|
55
|
+
function Members() {
|
|
56
|
+
return useWatch(this).render();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
12
60
|
//#region src/jsx-runtime.ts
|
|
13
61
|
host({
|
|
14
62
|
jsx,
|
|
@@ -86,11 +134,24 @@ var ErrorBoundary = class extends React.Component {
|
|
|
86
134
|
}
|
|
87
135
|
};
|
|
88
136
|
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/idle.ts
|
|
139
|
+
function idle(React) {
|
|
140
|
+
const modern = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
141
|
+
const legacy = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentDispatcher;
|
|
142
|
+
const current = modern && "H" in modern ? () => modern.H : legacy && "current" in legacy ? () => legacy.current : void 0;
|
|
143
|
+
if (!current) return () => void 0;
|
|
144
|
+
return () => {
|
|
145
|
+
const dispatcher = current();
|
|
146
|
+
return !dispatcher || dispatcher.useContext === dispatcher.useState;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
89
150
|
//#endregion
|
|
90
151
|
//#region src/index.ts
|
|
91
|
-
Object.defineProperty(Component
|
|
152
|
+
Object.defineProperty(Component.prototype, "isReactComponent", { value: true });
|
|
92
153
|
const FIBER = /* @__PURE__ */ new WeakMap();
|
|
93
|
-
Object.defineProperty(Component
|
|
154
|
+
Object.defineProperty(Component.prototype, "_reactInternals", {
|
|
94
155
|
get() {
|
|
95
156
|
return FIBER.get(this)?.deref();
|
|
96
157
|
},
|
|
@@ -99,6 +160,7 @@ Object.defineProperty(Component$1.prototype, "_reactInternals", {
|
|
|
99
160
|
}
|
|
100
161
|
});
|
|
101
162
|
Object.assign(Runtime, {
|
|
163
|
+
idle: idle(React$1),
|
|
102
164
|
dedupe,
|
|
103
165
|
ErrorBoundary,
|
|
104
166
|
createElement: React$1.createElement,
|
|
@@ -116,9 +178,7 @@ Object.assign(Runtime, {
|
|
|
116
178
|
"_reactInternalInstance"
|
|
117
179
|
]
|
|
118
180
|
});
|
|
119
|
-
/** @deprecated Import `{ Model }` from `@expressive/mvc`. The default export will be removed. */
|
|
120
|
-
var src_default = Model$1;
|
|
121
181
|
|
|
122
182
|
//#endregion
|
|
123
|
-
export {
|
|
183
|
+
export { };
|
|
124
184
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Component","React","Model"],"sources":["../src/jsx-runtime.ts","../src/boundary.ts","../src/index.ts"],"sourcesContent":["import { Children, isValidElement } from 'react';\nimport { Fragment, jsx, jsxs } from 'react/jsx-runtime';\nimport { host } from '@expressive/mvc/jsx-runtime';\n\nimport type { Component as ReactComponent, JSX as ReactJSX, ReactNode } from 'react';\n\ndeclare module '@expressive/mvc/jsx-runtime' {\n interface Host {\n node: ReactNode;\n intrinsics: ReactJSX.IntrinsicElements;\n elementClass: ReactComponent<any, any>;\n }\n}\n\nhost({\n jsx,\n jsxs,\n Fragment,\n isElement: isValidElement,\n childrenOf: Children.toArray,\n typeOf(node){\n return isValidElement(node) ? node.type : undefined;\n },\n propsOf(node){\n return isValidElement(node) ? node.props as Record<string, unknown> : {};\n }\n});\n","import { Component } from '@expressive/mvc';\nimport React from 'react';\nimport { Context } from './context';\n\ninterface Entry {\n committed?: boolean;\n context: Context;\n commit: () => void;\n remove: () => void;\n};\n\n/** In-flight render attempts by tree position, per ambient context.\n * When one commits, older uncommitted attempts at its slot are provably dead. */\nconst SLOTS = new WeakMap<Context, Map<string, Set<Entry>>>();\n\n/**\n * React's attempt lifecycle: fiber-keyed stacking so a superseded (uncommitted)\n * render attempt at a tree position is discarded when a later one commits.\n */\nexport function dedupe(on: Component, context: Context) {\n let slots = SLOTS.get(context.parent!);\n if (!slots) SLOTS.set(context.parent!, (slots = new Map()));\n\n // key/index path to root: stable across render attempts of this element\n let slot = '';\n for (let f = (on as any)._reactInternals; f; f = f.return)\n slot += (f.key ?? f.index) + '.';\n\n let list = slots.get(slot);\n if (!list) slots.set(slot, (list = new Set()));\n\n const entry: Entry = {\n context,\n commit() {\n entry.committed = true;\n\n for (const e of list) {\n if (e === entry) break;\n if (e.committed) continue;\n e.context.pop();\n list.delete(e);\n }\n },\n remove() {\n list.delete(entry);\n }\n };\n\n list.add(entry);\n return entry;\n};\n\nexport class ErrorBoundary extends React.Component<{\n self: Component;\n children: React.ReactNode;\n}> {\n state = {} as { error?: Error };\n recovering = false;\n\n constructor(props: ErrorBoundary['props']) {\n super(props);\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n const { self } = this.props;\n const { fallback } = self;\n const reset = (error?: Error) => {\n this.recovering = true;\n this.setState({ error });\n };\n\n Promise.resolve((self.props.catch || self.catch)!.call(self, error, self.is))\n .then(() => reset(), reset)\n .finally(() => self.set({ fallback }, true));\n }\n\n componentDidUpdate() {\n this.recovering = false;\n }\n\n render() {\n if (!this.state.error) return this.props.children;\n if (this.recovering) throw this.state.error;\n return this.props.self.fallback;\n }\n};\n","import { Component } from '@expressive/mvc';\nimport { Model } from './adapter';\nimport * as React from 'react';\n\nimport './element';\nimport './jsx-runtime';\n\nimport { Runtime } from './adapter';\nimport { weak } from './runtime';\nimport { ErrorBoundary, dedupe } from './boundary';\n\n// React detects class components by this brand (preact reads `prototype.render`).\nObject.defineProperty(Component.prototype, 'isReactComponent', {\n value: true\n});\n\nconst FIBER = new WeakMap<Component, { deref(): unknown }>();\n\nObject.defineProperty(Component.prototype, '_reactInternals', {\n get(this: Component) {\n return FIBER.get(this)?.deref();\n },\n set(this: Component, fiber: object) {\n FIBER.set(this, weak(fiber));\n }\n});\n\nObject.assign(Runtime, {\n dedupe,\n ErrorBoundary,\n createElement: React.createElement,\n createContext: React.createContext,\n useContext: React.useContext,\n useEffect: React.useEffect,\n useState: React.useState,\n useRef: React.useRef,\n useSyncExternalStore: React.useSyncExternalStore,\n startTransition: React.startTransition,\n Suspense: React.Suspense,\n ignore: [\n 'updater',\n 'refs',\n '_reactInternalInstance'\n ]\n});\n\n/** @deprecated Import `{ Model }` from `@expressive/mvc`. This re-export will be removed. */\nexport { State } from './adapter';\n\n/** @deprecated Import `{ Model }` from `@expressive/mvc`. The default export will be removed. */\nexport default Model;\n\n/** @deprecated Import from `@expressive/mvc`. These re-exports will be removed. */\nexport { Component, Context, def, get, ref, set, pending } from '@expressive/mvc';\n\n/** @deprecated Import `has` from `@expressive/mvc`. This re-export will be removed. */\nexport { has } from './has';\n\n/** @deprecated Import `map` from `@expressive/mvc`. This re-export will be removed. */\nexport { map } from './map';\n"],"mappings":";;;;;;;;;;;;AAcA,KAAK;CACH;CACA;CACA;CACA,WAAW;CACX,YAAY,SAAS;CACrB,OAAO,MAAK;AACV,SAAO,eAAe,KAAK,GAAG,KAAK,OAAO;;CAE5C,QAAQ,MAAK;AACX,SAAO,eAAe,KAAK,GAAG,KAAK,QAAmC,EAAE;;CAE3E,CAAC;;;;;;ACbF,MAAM,wBAAQ,IAAI,SAA2C;;;;;AAM7D,SAAgB,OAAO,IAAe,SAAkB;CACtD,IAAI,QAAQ,MAAM,IAAI,QAAQ,OAAQ;AACtC,KAAI,CAAC,MAAO,OAAM,IAAI,QAAQ,QAAU,wBAAQ,IAAI,KAAK,CAAE;CAG3D,IAAI,OAAO;AACX,MAAK,IAAI,IAAK,GAAW,iBAAiB,GAAG,IAAI,EAAE,OACjD,UAAS,EAAE,OAAO,EAAE,SAAS;CAE/B,IAAI,OAAO,MAAM,IAAI,KAAK;AAC1B,KAAI,CAAC,KAAM,OAAM,IAAI,MAAO,uBAAO,IAAI,KAAK,CAAE;CAE9C,MAAM,QAAe;EACnB;EACA,SAAS;AACP,SAAM,YAAY;AAElB,QAAK,MAAM,KAAK,MAAM;AACpB,QAAI,MAAM,MAAO;AACjB,QAAI,EAAE,UAAW;AACjB,MAAE,QAAQ,KAAK;AACf,SAAK,OAAO,EAAE;;;EAGlB,SAAS;AACP,QAAK,OAAO,MAAM;;EAErB;AAED,MAAK,IAAI,MAAM;AACf,QAAO;;AAGT,IAAa,gBAAb,cAAmC,M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"],"sources":["../src/element.ts","../src/jsx-runtime.ts","../src/boundary.ts","../src/idle.ts","../src/index.ts"],"sourcesContent":["import { Component } from '@expressive/mvc';\nimport { elements } from '@expressive/mvc/jsx-runtime';\nimport type { Renderable } from '@expressive/mvc/jsx-runtime';\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\n/**\n * Every class the core declares renderable - `Component`, `has` lists and\n * pools, `map` collections - gets the one getter. `is` resolves a derived view\n * to its instance; a Component renders through its ownership frame, anything\n * else through `render()`.\n */\nelements((Type) => {\n Object.defineProperty(Type.prototype, '$$typeof', {\n get(this: Renderable) {\n const self = this.is;\n\n return self instanceof Component\n ? seam(self, false, Element.bind(self), self.key)\n : seam(self, {}, Members.bind(self), null);\n }\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\nfunction Members(this: Renderable) {\n return useWatch(this).render();\n}\n","import { Children, isValidElement } from 'react';\nimport { Fragment, jsx, jsxs } from 'react/jsx-runtime';\nimport { host } from '@expressive/mvc/jsx-runtime';\n\nimport type { Component as ReactComponent, JSX as ReactJSX, ReactNode } from 'react';\n\ndeclare module '@expressive/mvc/jsx-runtime' {\n interface Host {\n node: ReactNode;\n intrinsics: ReactJSX.IntrinsicElements;\n elementClass: ReactComponent<any, any>;\n }\n}\n\nhost({\n jsx,\n jsxs,\n Fragment,\n isElement: isValidElement,\n childrenOf: Children.toArray,\n typeOf(node){\n return isValidElement(node) ? node.type : undefined;\n },\n propsOf(node){\n return isValidElement(node) ? node.props as Record<string, unknown> : {};\n }\n});\n","import { Component } from '@expressive/mvc';\nimport React from 'react';\nimport { Context } from './context';\n\ninterface Entry {\n committed?: boolean;\n context: Context;\n commit: () => void;\n remove: () => void;\n};\n\n/** In-flight render attempts by tree position, per ambient context.\n * When one commits, older uncommitted attempts at its slot are provably dead. */\nconst SLOTS = new WeakMap<Context, Map<string, Set<Entry>>>();\n\n/**\n * React's attempt lifecycle: fiber-keyed stacking so a superseded (uncommitted)\n * render attempt at a tree position is discarded when a later one commits.\n */\nexport function dedupe(on: Component, context: Context) {\n let slots = SLOTS.get(context.parent!);\n if (!slots) SLOTS.set(context.parent!, (slots = new Map()));\n\n // key/index path to root: stable across render attempts of this element\n let slot = '';\n for (let f = (on as any)._reactInternals; f; f = f.return)\n slot += (f.key ?? f.index) + '.';\n\n let list = slots.get(slot);\n if (!list) slots.set(slot, (list = new Set()));\n\n const entry: Entry = {\n context,\n commit() {\n entry.committed = true;\n\n for (const e of list) {\n if (e === entry) break;\n if (e.committed) continue;\n e.context.pop();\n list.delete(e);\n }\n },\n remove() {\n list.delete(entry);\n }\n };\n\n list.add(entry);\n return entry;\n};\n\nexport class ErrorBoundary extends React.Component<{\n self: Component;\n children: React.ReactNode;\n}> {\n state = {} as { error?: Error };\n recovering = false;\n\n constructor(props: ErrorBoundary['props']) {\n super(props);\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n const { self } = this.props;\n const { fallback } = self;\n const reset = (error?: Error) => {\n this.recovering = true;\n this.setState({ error });\n };\n\n Promise.resolve((self.props.catch || self.catch)!.call(self, error, self.is))\n .then(() => reset(), reset)\n .finally(() => self.set({ fallback }, true));\n }\n\n componentDidUpdate() {\n this.recovering = false;\n }\n\n render() {\n if (!this.state.error) return this.props.children;\n if (this.recovering) throw this.state.error;\n return this.props.self.fallback;\n }\n};\n","interface Dispatcher {\n useContext: unknown;\n useState: unknown;\n}\n\nexport function idle(React: any): () => boolean | undefined {\n const modern = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;\n const legacy = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentDispatcher;\n\n const current: (() => Dispatcher | null) | undefined =\n modern && 'H' in modern ? () => modern.H :\n legacy && 'current' in legacy ? () => legacy.current :\n undefined;\n\n if (!current) return () => undefined;\n\n return () => {\n const dispatcher = current();\n\n return !dispatcher || dispatcher.useContext === dispatcher.useState;\n };\n}\n","import { Component } from '@expressive/mvc';\nimport * as React from 'react';\n\nimport './element';\nimport './jsx-runtime';\n\nimport { Runtime } from './adapter';\nimport { weak } from './runtime';\nimport { ErrorBoundary, dedupe } from './boundary';\nimport { idle } from './idle';\n\n// React detects class components by this brand (preact reads `prototype.render`).\nObject.defineProperty(Component.prototype, 'isReactComponent', {\n value: true\n});\n\nconst FIBER = new WeakMap<Component, { deref(): unknown }>();\n\nObject.defineProperty(Component.prototype, '_reactInternals', {\n get(this: Component) {\n return FIBER.get(this)?.deref();\n },\n set(this: Component, fiber: object) {\n FIBER.set(this, weak(fiber));\n }\n});\n\nObject.assign(Runtime, {\n idle: idle(React),\n dedupe,\n ErrorBoundary,\n createElement: React.createElement,\n createContext: React.createContext,\n useContext: React.useContext,\n useEffect: React.useEffect,\n useState: React.useState,\n useRef: React.useRef,\n useSyncExternalStore: React.useSyncExternalStore,\n startTransition: React.startTransition,\n Suspense: React.Suspense,\n ignore: [\n 'updater',\n 'refs',\n '_reactInternalInstance'\n ]\n});\n\n// Nothing is exported for app code - `Model`, `Component` and the instructions come\n// from `@expressive/mvc`; `has` and `map` collections are adopted in `element.ts`.\n\n// A type-only export, so this entry's .d.ts stays linked to the adapter's\n// `Model`/`Component` augmentations; the bundler drops a bare import.\nexport type { Runtime } from './adapter';\n"],"mappings":";;;;;;;;;AAcA,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;;;;;;;;AASlB,UAAU,SAAS;AACjB,QAAO,eAAe,KAAK,WAAW,YAAY,EAChD,MAAsB;EACpB,MAAM,OAAO,KAAK;AAElB,SAAO,gBAAgB,YACnB,KAAK,MAAM,OAAO,QAAQ,KAAK,KAAK,EAAE,KAAK,IAAI,GAC/C,KAAK,MAAM,EAAE,EAAE,QAAQ,KAAK,KAAK,EAAE,KAAK;IAE/C,CAAC;EACF;AAEF,SAAS,UAAwB;CAC/B,MAAM,QAAQA,UAAQ,KAAK;AAa3B,QAZe,iBAAiB;EAC9B,IAAI,OAAO;EACX,MAAM,UAA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,YAAYA,QAAM;CAClB,WAAWA,QAAM;CACjB,UAAUA,QAAM;CAChB,QAAQA,QAAM;CACd,sBAAsBA,QAAM;CAC5B,iBAAiBA,QAAM;CACvB,UAAUA,QAAM;CAChB,QAAQ;EACN;EACA;EACA;EACD;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressive/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.92.0",
|
|
4
4
|
"description": "Class-based reactive state for React. Define state and logic as plain classes; components update when the values they read change.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expressive",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"test": "bun run typecheck && bun run coverage"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@expressive/mvc": "^0.
|
|
66
|
+
"@expressive/mvc": "^0.91.0",
|
|
67
67
|
"@testing-library/react": "^16.3.0",
|
|
68
68
|
"@types/react": "^19",
|
|
69
69
|
"@types/react-dom": "^19",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"vite": "^7.3.1"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@expressive/mvc": "^0.
|
|
78
|
+
"@expressive/mvc": "^0.91.0",
|
|
79
79
|
"react": ">=16.14.0 <20.0.0",
|
|
80
80
|
"vite": ">=5"
|
|
81
81
|
},
|
package/dist/adapter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","names":[],"sources":["../src/state.get.ts","../src/state.use.ts"],"sourcesContent":["import { Model, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { Runtime, useFactory, useSettle, useSetup, useWeak } 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 Model {\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 Model, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends Model> = (\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 Model>(this: Model.Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends Model>(\n this: Model.Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends Model>(\n this: Model.Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends Model, R>(\n this: Model.Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n function get<T extends Model>(\n this: Model.Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nModel.get = function get<T extends Model>(\n this: Model.Extends<T>,\n argument?: boolean | Model.GetFactory<T, unknown>\n) {\n const Type = this;\n const [tick, next] = Runtime.useState(0);\n const claim = useSettle(tick);\n const local = Context.get();\n const dispatch = useWeak(next);\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 dispatch.deref()!((x) => x + 1);\n }\n\n function observed() {\n if (mounted) {\n claim();\n update();\n }\n else pending = true;\n }\n\n function 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 Runtime.startTransition\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 useSetup((_self, 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 { Model, Context } from '@expressive/mvc';\nimport type { UseModel } from '@expressive/mvc';\nimport { useFactory, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n interface UseModel extends Model {\n /**\n * Optional hook called when Model.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 Model constructor.\n *\n * @param props Arguments passed to Model.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 * `Model.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 Model {\n type UseArgs<T extends Model> = T extends {\n use(...props: infer P): any;\n }\n ? P\n : Model.Args<T>;\n\n /**\n * Create and manage instance of this Model within React component.\n *\n * @param args Arguments to pass to constructor or `use` method (if defined).\n * @returns Managed instance of this Model.\n */\n function use<T extends UseModel>(\n this: Model.Type<T>,\n ...args: UseArgs<T>\n ): T;\n }\n}\n\nModel.use = function use<T extends Model>(\n this: Model.Type<T>,\n ...args: Model.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 Model.Assign<T>);\n\n let use = (...args: Model.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 const teardown = () => {\n context.pop();\n instance.set(null);\n };\n\n let ready = false;\n\n return (args: Model.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 return (instance as UseModel).mount?.();\n }, teardown);\n };\n });\n\n return render(args);\n};\n"],"mappings":";;;;;AAwEA,QAAM,MAAM,SAAS,IAEnB,UACA;CACA,MAAM,OAAO;CACb,MAAM,CAAC,MAAM,QAAQ,QAAQ,SAAS,EAAE;CACxC,MAAM,QAAQ,UAAU,KAAK;CAC7B,MAAM,QAAQ,QAAQ,KAAK;CAC3B,MAAM,WAAW,QAAQ,KAAK;AA8H9B,QA7He,iBAAiB;EAC9B,IAAI;EACJ,IAAI,UAAU;EACd,IAAI,UAAU;EACd,IAAI;EACJ,IAAI;EAEJ,SAAS,SAAS;AAChB,aAAU;AACV,YAAS,OAAO,EAAG,MAAM,IAAI,EAAE;;EAGjC,SAAS,WAAW;AAClB,OAAI,SAAS;AACX,WAAO;AACP,YAAQ;SAEL,WAAU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AAO,UAAU;AACzB,YAAQ;AAER,iBAAa;AACX,eAAU;AACV,SAAI,QAAS,SAAQ;AACrB,YAAO;;KAET;AACF,UAAO,UAAU,SAAY,OAAO;;GAEtC,EAEa;;;;;AC5JjB,QAAM,MAAM,SAAS,IAEnB,GAAG,MACH;CACA,MAAM,QAAQ,QAAQ,KAAK;AAsC3B,QArCe,iBAAiB;EAC9B,MAAM,OAAO,QACX,OAAO,OAAO,YAAY,SAAS,IAAI,IAAuB;EAEhE,IAAI,OAAO,GAAG,SAAwB,QAAQ,IAAI,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC;EAEvE,MAAM,WAAW,IAAI,MAAM,MAAM;AAC/B,OAAI,SAAS,KAAK,OAAO,EAAE,OAAO,YAAY;AAC5C,UAAM,EAAE,IAAI,KAAK,EAAE;AACnB,QAAI,GAAG,KAAK;SAET,QAAO;IACZ;EAEF,MAAM,UAAU,MAAM,KAAK,SAAS;EACpC,MAAM,iBAAiB;AACrB,WAAQ,KAAK;AACb,YAAS,IAAI,KAAK;;EAGpB,IAAI,QAAQ;AAEZ,UAAQ,SAAwB;AAC9B,OAAI,OAAO;AACT,YAAQ;AACR,YAAQ,QAAQ,IAAI,GAAG,KAAK,CAAC,CAAC,cAAc;AAC1C,aAAQ;MACR;;AAGJ,UAAO,SAAS,gBAAgB;AAC9B,YAAQ;AACR,WAAQ,SAAsB,SAAS;MACtC,SAAS;;GAEd,CAEY,KAAK"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-component-BZoZVrRW.js","names":["Context"],"sources":["../src/runtime.ts","../src/context.ts","../src/component.ts"],"sourcesContent":["import type { Component } from '@expressive/mvc';\nimport { watch } from '@expressive/mvc/observable';\nimport { pending } from '@expressive/mvc';\nimport type { Context } from './context';\n\ninterface Settle {\n waiting?: (() => void)[];\n claim(): void;\n release(): void;\n}\n\ninterface Setup {\n rendered: number;\n revision: number;\n mounted?: boolean;\n fresh?: boolean;\n getRevision?: () => number;\n lapsed?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | void;\n teardown?: () => void;\n}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: Weak<(next: (previous: number) => number) => void>;\n output: T;\n}\n\ninterface Weak<T> {\n deref(): T | undefined;\n}\n\nexport const Runtime = {} as {\n /** Host own-property keys to trap out of observed state; assigned by each adapter. */\n ignore: string[];\n createElement(type: any, props?: any, ...children: any[]): any;\n createContext<T>(value: T): any;\n useContext(context: any): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n /** Non-urgent bracket a subscriber replays through; absent where the host\n * cannot defer, which keeps normal timing. */\n startTransition?(work: () => void): void;\n /** Consumed for pre-commit revision validation; absent where commits\n * cannot interleave with writes. */\n useSyncExternalStore?(\n subscribe: (notify: () => void) => () => void,\n getSnapshot: () => number,\n getServerSnapshot?: () => number\n ): number;\n /** Per-render-attempt lifecycle; absent where render attempts do not stack. */\n dedupe?(from: Component, context: Context): { commit(): void; remove(): void };\n /** Host error-boundary component, wrapping a Component whose `catch` is set. */\n ErrorBoundary: unknown;\n Suspense: any;\n};\n\nconst noop = () => () => {};\n\nexport function useFactory<T extends object>(factory: () => T) {\n const ref = Runtime.useRef<T | null>(null);\n return ref.current || (ref.current = factory());\n}\n\n/**\n * Returns a claim on the update being replayed, held until this hook commits\n * carrying it - or until unmount, where it never will. Keyed on `tick` so an\n * urgent commit in the meantime, which leaves the deferred update queued, does\n * not release it.\n */\nexport function useSettle(tick: number) {\n const ref = Runtime.useRef<Settle | null>(null);\n const settle = ref.current || (ref.current = {\n claim() {\n const held = pending();\n\n if (held) (settle.waiting ||= []).push(held);\n },\n release() {\n const { waiting } = settle;\n\n if (!waiting) return;\n settle.waiting = undefined;\n\n for (const held of waiting) held();\n }\n });\n\n Runtime.useEffect(() => {\n settle.release();\n return settle.release;\n }, [tick]);\n\n return settle.claim;\n}\n\n/**\n * Run `init` once for the life of a hook and clean up when it unmounts, safe\n * under React StrictMode - a remount shares the render counter, so neither the\n * setup nor its cleanup repeats. A cleanup following a render not yet committed\n * - Fast Refresh re-running effects - defers a microtask, and is dropped if the\n * effect runs again. `reset` invalidates the rendered value so in-flight render\n * attempts revalidate.\n *\n * @returns The hook's own record, plus the render counter and its setter.\n */\nexport function useSetup<T extends Setup>(\n init: (self: T, reset: () => void) => () => (() => void) | void,\n teardown?: () => void\n) {\n const { current } = Runtime.useRef({ rendered: 0, revision: 0 } as T);\n\n const [tick, update] = Runtime.useState(() => {\n if (!current.rendered)\n current.commit = init(current, () => {\n current.revision++;\n });\n\n return current.rendered++;\n });\n\n useReap(current, teardown);\n\n const getRevision = (current.getRevision ||= () => current.revision);\n\n current.fresh = true;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.fresh = false;\n });\n\n Runtime.useEffect(() => {\n current.mounted = true;\n current.lapsed = false;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n return () => {\n if (!current.fresh) {\n if (--current.rendered <= 0) release(current);\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) release(current);\n });\n }\n }, []);\n\n return [current, tick, update] as const;\n}\n\nfunction release(setup: Setup) {\n setup.release?.();\n setup.teardown?.();\n}\n\nlet reaper: FinalizationRegistry<Setup> | null | undefined;\n\nfunction useReap(setup: Setup, teardown?: () => void) {\n const token = Runtime.useRef<object | null>(null);\n\n if (!teardown || setup.teardown) return;\n\n setup.teardown = teardown;\n\n if (reaper === undefined)\n reaper = typeof FinalizationRegistry == 'function'\n ? new FinalizationRegistry((setup) => setup.mounted || setup.teardown!())\n : null;\n\n reaper?.register((token.current = {}), setup);\n}\n\nexport function weak<T extends object>(value: T): Weak<T> {\n return typeof WeakRef == 'function' ? new WeakRef(value) : { deref: () => value };\n}\n\nexport function useWeak<T extends object>(value: T) {\n const ref = Runtime.useRef<Weak<T> | null>(null);\n return (ref.current ||= weak(value));\n}\n\n/**\n * Mount-effect with a refreshable return value. Publishing a value before mount\n * defers the update to it, and one published after claims the update being\n * replayed until this hook commits carrying it.\n *\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (\n refresh: (next: T) => void,\n reset: () => void\n ) => () => (() => void) | void,\n teardown?: () => void\n) {\n const [current, tick, update] = useSetup<Hook<T>>((self, reset) => {\n const mount = callback((next) => {\n self.output = next;\n\n if (self.mounted) {\n claim();\n self.update?.deref()!((x) => x + 1);\n }\n else if (self.update) self.queued = true;\n }, reset);\n\n return () => {\n const cleanup = mount();\n\n if (self.queued) {\n self.queued = false;\n self.update!.deref()!((x) => x + 1);\n }\n\n return cleanup;\n };\n }, teardown);\n\n const claim = useSettle(tick);\n\n current.update ||= weak(update);\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | void,\n teardown?: () => void\n) {\n return useHook<T>((refresh, reset) => {\n const release = watch(from, (current) => {\n refresh(current);\n\n return (update) => {\n if (update === true) reset();\n };\n }, undefined, Runtime.startTransition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n if (typeof cleanup == 'function') cleanup();\n };\n };\n }, teardown) ?? from;\n}\n","import { Model, Context, Component } from '@expressive/mvc';\nimport { Runtime } from './runtime';\n\nlet shared: any;\n\n/**\n * Lazily-created context carrying the active {@link Context} down the tree.\n * Lazy because the framework's `createContext` arrives via {@link Runtime},\n * which an adapter's entry populates at load - after this module evaluates.\n */\nfunction Layers() {\n return shared || (shared = Runtime.createContext(Context.root));\n}\n\n/** Read the ambient {@link Context} from the nearest Layers provider. */\nfunction useAmbient() {\n return Runtime.useContext(Layers());\n}\n\n/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */\nfunction createProvider(context: Context, children: any) {\n return Runtime.createElement(Layers().Provider, { value: context, children });\n}\n\n// Class components consume the active Context through the host's `contextType`\nObject.defineProperty(Component, 'contextType', { configurable: true, get: Layers });\n\nconst _get = Context.get;\n\nContext.get = (state?: Model) => {\n if (!state)\n try {\n return useAmbient();\n } catch { }\n\n return _get(state);\n};\n\nexport { 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(Model)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: {};\n /** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */\n setState: (state: any, callback?: () => void) => void;\n /** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */\n forceUpdate: (callback?: () => void) => void;\n }\n}\n\n// Host-agnostic seams: `state` is a read-only values bag; `context`'s setter\n// pushes a child context, registers the instance for teardown, and installs its\n// per-instance render host. Host-specific descriptors stay in each adapter.\nObject.defineProperties(Component.prototype, {\n state: {\n set() {},\n get: Component.prototype.get\n },\n context: {\n set: bootstrap\n }\n});\n\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 * On the root Component, host own-property keys are trapped so each lands as a\n * plain own property (out of observed state); each adapter assigns its own set.\n */\nComponent.on({\n type(type) {\n const render = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (typeof render?.value == 'function')\n Object.defineProperty(type.prototype, 'render', { ...render, configurable: false });\n\n if (type === Component)\n for (const key of Runtime.ignore)\n Object.defineProperty(Component.prototype, key, {\n set(value) {\n Object.defineProperty(this, key, { value, writable: true });\n }\n });\n\n subcomponents(type.prototype);\n },\n setup(self) {\n subcomponents(self);\n }\n});\n\nfunction bootstrap(this: Component, 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.props.catch || from.catch\n ? createElement(Runtime.ErrorBoundary, { self: from, children })\n : children;\n}\n\n/**\n * Ownership host for `<Component/>`: React owns the instance, so its render\n * threads the bootstrap-pushed context through `Runtime.dedupe` (React stacks\n * render attempts) and tears that context down - destroying the instance - on\n * unmount.\n */\nfunction render(from: Component, context: Context) {\n const { createElement, dedupe } = Runtime;\n const attempt = dedupe?.(from, context);\n const { is: owner } = from;\n // Read before bootstrap shadows an instance `render` with this host.\n const own = Object.prototype.hasOwnProperty.call(owner, 'render') && owner.render;\n const teardown = () => {\n attempt?.remove();\n context.pop();\n };\n\n const Render = () => (own || Object.getPrototypeOf(owner).render).call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n const release = owner.mount?.();\n\n attempt?.commit();\n\n return release;\n }, teardown);\n\n return createFrame(from, context, createElement(Render));\n };\n\n return () => createElement(Component);\n}\n\n/** Rewrite each own capitalized function on `target` into a subcomponent. */\nfunction subcomponents(target: object) {\n for (const key of Object.getOwnPropertyNames(target)) {\n if (!/^[A-Z]/.test(key)) continue;\n const { value } = Object.getOwnPropertyDescriptor(target, key)!;\n if (typeof value != 'function') continue;\n Object.defineProperty(target, key, {\n configurable: true,\n get(this: Component) {\n const owner = this.is;\n let render = unbind(value);\n const Component = (props: unknown) =>\n render.call(useWatch(owner), props);\n\n Object.defineProperty(owner, key, {\n configurable: true,\n get: () => Component,\n set(fn: Function) {\n render = fn;\n }\n });\n\n return Component;\n },\n set(this: Component, value: unknown) {\n Object.defineProperty(this, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n\n subcomponents(this);\n }\n });\n }\n}\n\nexport { createFrame };\n"],"mappings":";;;;AAiCA,MAAa,UAAU,EAAE;AA0BzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA6B,SAAkB;CAC7D,MAAM,MAAM,QAAQ,OAAiB,KAAK;AAC1C,QAAO,IAAI,YAAY,IAAI,UAAU,SAAS;;;;;;;;AAShD,SAAgB,UAAU,MAAc;CACtC,MAAM,MAAM,QAAQ,OAAsB,KAAK;CAC/C,MAAM,SAAS,IAAI,YAAY,IAAI,UAAU;EAC3C,QAAQ;GACN,MAAM,OAAO,SAAS;AAEtB,OAAI,KAAM,EAAC,OAAO,YAAY,EAAE,EAAE,KAAK,KAAK;;EAE9C,UAAU;GACR,MAAM,EAAE,YAAY;AAEpB,OAAI,CAAC,QAAS;AACd,UAAO,UAAU;AAEjB,QAAK,MAAM,QAAQ,QAAS,OAAM;;EAErC;AAED,SAAQ,gBAAgB;AACtB,SAAO,SAAS;AAChB,SAAO,OAAO;IACb,CAAC,KAAK,CAAC;AAEV,QAAO,OAAO;;;;;;;;;;;;AAahB,SAAgB,SACd,MACA,UACA;CACA,MAAM,EAAE,YAAY,QAAQ,OAAO;EAAE,UAAU;EAAG,UAAU;EAAG,CAAM;CAErE,MAAM,CAAC,MAAM,UAAU,QAAQ,eAAe;AAC5C,MAAI,CAAC,QAAQ,SACX,SAAQ,SAAS,KAAK,eAAe;AACnC,WAAQ;IACR;AAEJ,SAAO,QAAQ;GACf;AAEF,SAAQ,SAAS,SAAS;CAE1B,MAAM,cA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
-
import { i as useFactory, n as Context$1, r as Runtime, s as useWatch, t as createFrame } from "./chunk-component-BZoZVrRW.js";
|
|
2
|
-
import { Component } from "@expressive/mvc";
|
|
3
|
-
|
|
4
|
-
//#region src/element.ts
|
|
5
|
-
let template;
|
|
6
|
-
/**
|
|
7
|
-
* Borrow a host element's descriptors so `self` passes as a React element.
|
|
8
|
-
* `props` false keeps the target's own `props` (Component supplies its own);
|
|
9
|
-
* an object installs it as the element's props (collections have none).
|
|
10
|
-
*/
|
|
11
|
-
function seam(self, props, type, key) {
|
|
12
|
-
if (!template) template = Runtime.createElement("template");
|
|
13
|
-
const descriptors = Object.getOwnPropertyDescriptors(template);
|
|
14
|
-
const store = descriptors._store?.value;
|
|
15
|
-
if (props === false) delete descriptors.props;
|
|
16
|
-
if (store) descriptors._store.value = Object.create(Object.getPrototypeOf(store), Object.getOwnPropertyDescriptors(store));
|
|
17
|
-
Object.defineProperties(self, {
|
|
18
|
-
...descriptors,
|
|
19
|
-
$$typeof: { value: template.$$typeof },
|
|
20
|
-
...props ? { props: { value: props } } : void 0,
|
|
21
|
-
key: { value: key },
|
|
22
|
-
type: { value: type }
|
|
23
|
-
});
|
|
24
|
-
return template.$$typeof;
|
|
25
|
-
}
|
|
26
|
-
Object.defineProperty(Component.prototype, "$$typeof", { get() {
|
|
27
|
-
const self = this.is;
|
|
28
|
-
return seam(self, false, Element.bind(self), self.key);
|
|
29
|
-
} });
|
|
30
|
-
function Element() {
|
|
31
|
-
const outer = Context$1.get();
|
|
32
|
-
return useFactory(() => {
|
|
33
|
-
let from = this;
|
|
34
|
-
const context = outer.push(this);
|
|
35
|
-
const Content = () => from.render(from.props);
|
|
36
|
-
return () => {
|
|
37
|
-
from = useWatch(this, () => () => context.pop());
|
|
38
|
-
return createFrame(from, context, Runtime.createElement(Content));
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
export { seam as t };
|
|
45
|
-
//# sourceMappingURL=chunk-element-CrZVk-LG.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk-element-CrZVk-LG.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"}
|
package/dist/has.d.ts
DELETED
package/dist/has.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { s as useWatch } from "./chunk-component-BZoZVrRW.js";
|
|
2
|
-
import { t as seam } from "./chunk-element-CrZVk-LG.js";
|
|
3
|
-
import { has } from "@expressive/mvc";
|
|
4
|
-
|
|
5
|
-
//#region src/has.ts
|
|
6
|
-
for (const Collection of [has.List, has.Pool]) Object.defineProperty(Collection.prototype, "$$typeof", { get() {
|
|
7
|
-
let self = this;
|
|
8
|
-
for (let proto = Object.getPrototypeOf(self); proto instanceof has.List || proto instanceof has.Pool; proto = Object.getPrototypeOf(self)) self = proto;
|
|
9
|
-
return seam(self, {}, Members.bind(self), null);
|
|
10
|
-
} });
|
|
11
|
-
function Members() {
|
|
12
|
-
return [...useWatch(this)];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { has };
|
|
17
|
-
//# sourceMappingURL=has.js.map
|
package/dist/has.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"has.js","names":[],"sources":["../src/has.ts"],"sourcesContent":["import { has } from '@expressive/mvc';\nimport { useWatch } from './runtime';\nimport { seam } from './element';\n\nfor (const Collection of [has.List, has.Pool])\n Object.defineProperty(Collection.prototype, '$$typeof', {\n get() {\n let self = this as has.List<unknown> | has.Pool<unknown>;\n\n for (\n let proto = Object.getPrototypeOf(self);\n proto instanceof has.List || proto instanceof has.Pool;\n proto = Object.getPrototypeOf(self)\n )\n self = proto;\n\n return seam(self, {}, Members.bind(self), null);\n }\n });\n\nfunction Members(this: has.List<unknown> | has.Pool<unknown>) {\n return [...useWatch(this)];\n}\n\nexport { has };\n"],"mappings":";;;;;AAIA,KAAK,MAAM,cAAc,CAAC,IAAI,MAAM,IAAI,KAAK,CAC3C,QAAO,eAAe,WAAW,WAAW,YAAY,EACtD,MAAM;CACJ,IAAI,OAAO;AAEX,MACE,IAAI,QAAQ,OAAO,eAAe,KAAK,EACvC,iBAAiB,IAAI,QAAQ,iBAAiB,IAAI,MAClD,QAAQ,OAAO,eAAe,KAAK,CAEnC,QAAO;AAET,QAAO,KAAK,MAAM,EAAE,EAAE,QAAQ,KAAK,KAAK,EAAE,KAAK;GAElD,CAAC;AAEJ,SAAS,UAAqD;AAC5D,QAAO,CAAC,GAAG,SAAS,KAAK,CAAC"}
|
package/dist/map.d.ts
DELETED
package/dist/map.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { s as useWatch } from "./chunk-component-BZoZVrRW.js";
|
|
2
|
-
import { t as seam } from "./chunk-element-CrZVk-LG.js";
|
|
3
|
-
import { map } from "@expressive/mvc";
|
|
4
|
-
|
|
5
|
-
//#region src/map.ts
|
|
6
|
-
Object.defineProperty(map.Managed.prototype, "$$typeof", { get() {
|
|
7
|
-
let self = this;
|
|
8
|
-
for (let proto = Object.getPrototypeOf(self); proto instanceof map.Managed; proto = Object.getPrototypeOf(self)) self = proto;
|
|
9
|
-
return seam(self, {}, Values.bind(self), null);
|
|
10
|
-
} });
|
|
11
|
-
function Values() {
|
|
12
|
-
return [...useWatch(this).values()];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { map };
|
|
17
|
-
//# sourceMappingURL=map.js.map
|
package/dist/map.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","names":[],"sources":["../src/map.ts"],"sourcesContent":["import { map } from '@expressive/mvc';\nimport { useWatch } from './runtime';\nimport { seam } from './element';\n\nObject.defineProperty(map.Managed.prototype, '$$typeof', {\n get() {\n let self = this as map.Managed<unknown, unknown>;\n\n for (\n let proto = Object.getPrototypeOf(self);\n proto instanceof map.Managed;\n proto = Object.getPrototypeOf(self)\n )\n self = proto;\n\n return seam(self, {}, Values.bind(self), null);\n }\n});\n\nfunction Values(this: map.Managed<unknown, unknown>) {\n const self = useWatch(this);\n\n return [...self.values()];\n}\n\nexport { map };\n"],"mappings":";;;;;AAIA,OAAO,eAAe,IAAI,QAAQ,WAAW,YAAY,EACvD,MAAM;CACJ,IAAI,OAAO;AAEX,MACE,IAAI,QAAQ,OAAO,eAAe,KAAK,EACvC,iBAAiB,IAAI,SACrB,QAAQ,OAAO,eAAe,KAAK,CAEnC,QAAO;AAET,QAAO,KAAK,MAAM,EAAE,EAAE,OAAO,KAAK,KAAK,EAAE,KAAK;GAEjD,CAAC;AAEF,SAAS,SAA4C;AAGnD,QAAO,CAAC,GAFK,SAAS,KAAK,CAEX,QAAQ,CAAC"}
|