@expressive/react 0.71.0 → 0.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter.d.ts +60 -60
- package/dist/adapter.js +122 -106
- package/dist/adapter.js.map +1 -1
- package/dist/esm/adapter.js +66 -87
- package/dist/esm/adapter.js.map +1 -1
- package/dist/esm/chunk-4MR23TOU.js +45 -0
- package/dist/esm/chunk-4MR23TOU.js.map +1 -0
- package/dist/esm/chunk-UIHA4AT6.js +58 -0
- package/dist/esm/chunk-UIHA4AT6.js.map +1 -0
- package/dist/esm/index.js +20 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx-dev-runtime.js +2 -2
- package/dist/esm/jsx-dev-runtime.js.map +1 -1
- package/dist/esm/jsx-runtime.js +14 -24
- package/dist/esm/jsx-runtime.js.map +1 -1
- package/dist/index.d.ts +16 -10
- package/dist/index.js +23 -39
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +9 -36
- package/dist/jsx-runtime.js +71 -34
- package/dist/jsx-runtime.js.map +1 -1
- package/package.json +8 -6
- package/dist/esm/context.js +0 -40
- package/dist/esm/context.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,44 +15,37 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var src_exports = {};
|
|
32
22
|
__export(src_exports, {
|
|
33
23
|
Consumer: () => Consumer,
|
|
34
|
-
Context: () =>
|
|
24
|
+
Context: () => import_mvc2.Context,
|
|
35
25
|
Fragment: () => import_react3.Fragment,
|
|
36
|
-
Model: () => import_mvc2.Model,
|
|
37
26
|
Observable: () => import_mvc2.Observable,
|
|
27
|
+
Pragma: () => import_adapter.Pragma,
|
|
38
28
|
Provider: () => Provider,
|
|
29
|
+
State: () => import_mvc2.State,
|
|
39
30
|
createElement: () => import_react3.createElement,
|
|
40
|
-
default: () =>
|
|
31
|
+
default: () => src_default,
|
|
41
32
|
get: () => import_mvc2.get,
|
|
42
|
-
has: () => import_mvc2.has,
|
|
43
33
|
ref: () => import_mvc2.ref,
|
|
44
34
|
set: () => import_mvc2.set,
|
|
45
35
|
use: () => import_mvc2.use
|
|
46
36
|
});
|
|
47
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
var import_mvc2 = require("@expressive/mvc");
|
|
48
39
|
var import_react2 = require("react");
|
|
49
40
|
var import_adapter = require("./adapter");
|
|
50
41
|
|
|
51
42
|
// src/context.ts
|
|
52
|
-
var import_mvc =
|
|
43
|
+
var import_mvc = require("@expressive/mvc");
|
|
53
44
|
var import_react = require("react");
|
|
54
|
-
var
|
|
45
|
+
var Layers = (0, import_react.createContext)(new import_mvc.Context());
|
|
55
46
|
import_mvc.Context.use = (create) => {
|
|
56
|
-
const ambient = (0, import_react.useContext)(
|
|
57
|
-
return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
|
|
47
|
+
const ambient = (0, import_react.useContext)(Layers);
|
|
48
|
+
return create ? (0, import_react.useMemo)(() => ambient.push(), [ambient]) : ambient;
|
|
58
49
|
};
|
|
59
50
|
function Consumer(props) {
|
|
60
51
|
return props.for.get((i) => props.children(i));
|
|
@@ -62,48 +53,41 @@ function Consumer(props) {
|
|
|
62
53
|
function Provider(props) {
|
|
63
54
|
const context = import_mvc.Context.use(true);
|
|
64
55
|
(0, import_react.useEffect)(() => () => context.pop(), [context]);
|
|
65
|
-
context.
|
|
56
|
+
context.use(props.for, (state) => {
|
|
66
57
|
if (props.forEach) {
|
|
67
|
-
const cleanup = props.forEach(
|
|
68
|
-
if (cleanup)
|
|
69
|
-
model.set(cleanup, null);
|
|
58
|
+
const cleanup = props.forEach(state);
|
|
59
|
+
if (cleanup) state.set(cleanup, null);
|
|
70
60
|
}
|
|
71
61
|
});
|
|
72
|
-
return
|
|
62
|
+
return provide(context, props.children, props.fallback, props.name);
|
|
73
63
|
}
|
|
74
|
-
function
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
function provide(context, children, fallback, name) {
|
|
65
|
+
if (fallback !== void 0)
|
|
66
|
+
children = (0, import_react.createElement)(import_react.Suspense, { fallback, name }, children);
|
|
67
|
+
return (0, import_react.createElement)(Layers.Provider, {
|
|
78
68
|
key: context.id,
|
|
79
69
|
value: context,
|
|
80
70
|
children
|
|
81
71
|
});
|
|
82
|
-
return fallback !== void 0 ? (0, import_react.createElement)(import_react.Suspense, { fallback, name }, element) : element;
|
|
83
72
|
}
|
|
84
73
|
|
|
85
74
|
// src/index.ts
|
|
86
|
-
var import_mvc2 = require("@expressive/mvc");
|
|
87
75
|
var import_react3 = require("react");
|
|
88
|
-
import_adapter.Pragma.
|
|
89
|
-
import_adapter.Pragma.
|
|
90
|
-
import_adapter.Pragma.
|
|
91
|
-
|
|
92
|
-
state[1]((x) => x.bind(null));
|
|
93
|
-
}));
|
|
94
|
-
return state[0];
|
|
95
|
-
};
|
|
76
|
+
import_adapter.Pragma.useEffect = import_react2.useEffect;
|
|
77
|
+
import_adapter.Pragma.useState = import_react2.useState;
|
|
78
|
+
import_adapter.Pragma.createElement = import_react2.createElement;
|
|
79
|
+
var src_default = import_mvc2.State;
|
|
96
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
81
|
0 && (module.exports = {
|
|
98
82
|
Consumer,
|
|
99
83
|
Context,
|
|
100
84
|
Fragment,
|
|
101
|
-
Model,
|
|
102
85
|
Observable,
|
|
86
|
+
Pragma,
|
|
103
87
|
Provider,
|
|
88
|
+
State,
|
|
104
89
|
createElement,
|
|
105
90
|
get,
|
|
106
|
-
has,
|
|
107
91
|
ref,
|
|
108
92
|
set,
|
|
109
93
|
use
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/context.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/context.ts"],"sourcesContent":["import {\n Context,\n Observable,\n State,\n get,\n use,\n ref,\n set\n} from '@expressive/mvc';\nimport { createElement, useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\n\nPragma.useEffect = useEffect;\nPragma.useState = useState;\nPragma.createElement = createElement;\n\nexport default State;\nexport { Context, get, State, Observable, ref, set, use };\nexport { Consumer, Provider } from './context';\nexport { Fragment, createElement } from 'react';\nexport { Pragma };\n","import State, { Context } from '@expressive/mvc';\nimport {\n createContext,\n createElement,\n ReactNode,\n Suspense,\n useContext,\n useEffect,\n useMemo\n} from 'react';\n\nexport const Layers = createContext(new Context());\n\ndeclare module '@expressive/mvc' {\n namespace Context {\n function use(create?: true): Context;\n function use(create: boolean): Context | null | undefined;\n }\n}\n\nContext.use = (create?: boolean) => {\n const ambient = useContext(Layers);\n\n return create ? useMemo(() => ambient.push(), [ambient]) : ambient;\n};\n\ndeclare namespace Consumer {\n type Props<T extends State> = {\n /** Type of controller to fetch from context. */\n for: State.Extends<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `State.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n };\n}\n\nfunction Consumer<T extends State>(props: Consumer.Props<T>) {\n return props.for.get((i) => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends State> {\n /** State or group of States to provide to descendant Consumers. */\n for: Context.Accept<T>;\n\n /**\n * Callback to run for each provided State.\n */\n forEach?: Context.Expect<T>;\n\n /**\n * Children to render within this Provider.\n */\n children?: ReactNode;\n\n /** A fallback tree to show when suspended. */\n fallback?: ReactNode;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n}\n\nfunction Provider<T extends State>(props: Provider.Props<T>) {\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.use(props.for, (state) => {\n if (props.forEach) {\n const cleanup = props.forEach(state);\n\n if (cleanup) state.set(cleanup, null);\n }\n });\n\n return provide(context, props.children, props.fallback, props.name);\n}\n\nfunction provide(\n context: Context,\n children: ReactNode,\n fallback?: ReactNode,\n name?: string | undefined\n): ReactNode {\n if (fallback !== undefined)\n children = createElement(Suspense, { fallback, name }, children);\n\n return createElement(Layers.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, provide };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAQO;AACP,IAAAC,gBAAmD;AAEnD,qBAAuB;;;ACXvB,iBAA+B;AAC/B,mBAQO;AAEA,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AASjD,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aAAS,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,IAAI;AAC7D;AAkBA,SAAS,SAA0B,OAA0B;AAC3D,SAAO,MAAM,IAAI,IAAI,CAAC,MAAM,MAAM,SAAS,CAAC,CAAC;AAC/C;AA4BA,SAAS,SAA0B,OAA0B;AAC3D,QAAM,UAAU,mBAAQ,IAAI,IAAI;AAEhC,8BAAU,MAAM,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC;AAE9C,UAAQ,IAAI,MAAM,KAAK,CAAC,UAAU;AAChC,QAAI,MAAM,SAAS;AACjB,YAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,UAAI,QAAS,OAAM,IAAI,SAAS,IAAI;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO,QAAQ,SAAS,MAAM,UAAU,MAAM,UAAU,MAAM,IAAI;AACpE;AAEA,SAAS,QACP,SACA,UACA,UACA,MACW;AACX,MAAI,aAAa;AACf,mBAAW,4BAAc,uBAAU,EAAE,UAAU,KAAK,GAAG,QAAQ;AAEjE,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;;;ADlFA,IAAAC,gBAAwC;AAPxC,sBAAO,YAAY;AACnB,sBAAO,WAAW;AAClB,sBAAO,gBAAgB;AAEvB,IAAO,cAAQ;","names":["import_mvc","import_react","import_react"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as State from '@expressive/mvc';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
export { Fragment } from 'react';
|
|
4
4
|
export { JSX } from './jsx-runtime';
|
|
5
5
|
|
|
6
|
-
declare const jsxDEV: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements> |
|
|
6
|
+
declare const jsxDEV: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements> | State.State.Class<State.State>, ...args: any[]) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
7
7
|
|
|
8
8
|
export { jsxDEV };
|
package/dist/jsx-dev-runtime.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports = __toCommonJS(jsx_dev_runtime_exports);
|
|
|
37
37
|
var import_jsx_dev_runtime = __toESM(require("react/jsx-dev-runtime"));
|
|
38
38
|
var import_jsx_runtime = require("./jsx-runtime");
|
|
39
39
|
var import_react = require("react");
|
|
40
|
-
var jsxDEV = import_jsx_runtime.
|
|
40
|
+
var jsxDEV = import_jsx_runtime.patch.bind(import_jsx_dev_runtime.default.jsxDEV);
|
|
41
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
42
42
|
0 && (module.exports = {
|
|
43
43
|
Fragment,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/jsx-dev-runtime.ts"],"sourcesContent":["import Runtime from 'react/jsx-dev-runtime';\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/jsx-dev-runtime.ts"],"sourcesContent":["import Runtime from 'react/jsx-dev-runtime';\n\nimport { patch } from './jsx-runtime';\n\nexport const jsxDEV = patch.bind(Runtime.jsxDEV);\n\nexport { type JSX } from './jsx-runtime';\nexport { Fragment } from 'react';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAoB;AAEpB,yBAAsB;AAKtB,mBAAyB;AAHlB,IAAM,SAAS,yBAAM,KAAK,uBAAAA,QAAQ,MAAM;","names":["Runtime"]}
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,40 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { State } from '@expressive/mvc';
|
|
2
2
|
import React__default from 'react';
|
|
3
3
|
export { Fragment } from 'react';
|
|
4
4
|
|
|
5
|
-
declare module "@expressive/mvc" {
|
|
6
|
-
namespace Model {
|
|
7
|
-
/**
|
|
8
|
-
* Use this to define a component which wraps a Model, intended to forward props.
|
|
9
|
-
* This is to be used explicity, in JSDoc types or type annotations.
|
|
10
|
-
* The second type parameter is additional props the component expects to receive.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import { Model } from '@expressive/react';
|
|
15
|
-
*
|
|
16
|
-
* class MyModel extends Model {
|
|
17
|
-
* foo: string;
|
|
18
|
-
* bar: number;
|
|
19
|
-
* }
|
|
20
|
-
*
|
|
21
|
-
* const MyComponent: Model.FC<MyModel, { label: string }> =
|
|
22
|
-
* ({ label, ...rest }) => (
|
|
23
|
-
* <div>
|
|
24
|
-
* <span>{label}</span>
|
|
25
|
-
* <MyModel {...rest} />
|
|
26
|
-
* </div>
|
|
27
|
-
* );
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
type FC<T extends Model, P extends {} = {}> = React__default.FC<Props<T> & P>;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
5
|
declare namespace JSX {
|
|
34
|
-
type ElementType =
|
|
6
|
+
type ElementType = State.Extends<State.AsComponent> | React__default.JSX.ElementType | ((props: {}, ref?: any) => void);
|
|
35
7
|
type LibraryManagedAttributes<C, P> = C extends new (...args: any[]) => {
|
|
36
8
|
props: infer U;
|
|
37
|
-
} ? U : C extends
|
|
9
|
+
} ? U : C extends State.Extends<infer U> ? State.Props<U> : React__default.JSX.LibraryManagedAttributes<C, P>;
|
|
38
10
|
interface Element extends React__default.JSX.Element {
|
|
39
11
|
}
|
|
40
12
|
interface ElementClass extends React__default.JSX.ElementClass {
|
|
@@ -45,13 +17,14 @@ declare namespace JSX {
|
|
|
45
17
|
}
|
|
46
18
|
interface IntrinsicAttributes extends React__default.JSX.IntrinsicAttributes {
|
|
47
19
|
}
|
|
48
|
-
interface IntrinsicClassAttributes<T> extends React__default.JSX
|
|
20
|
+
interface IntrinsicClassAttributes<T> extends React__default.JSX
|
|
21
|
+
.IntrinsicClassAttributes<T> {
|
|
49
22
|
}
|
|
50
23
|
interface IntrinsicElements extends React__default.JSX.IntrinsicElements {
|
|
51
24
|
}
|
|
52
25
|
}
|
|
53
|
-
declare function
|
|
54
|
-
declare const jsx: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> |
|
|
55
|
-
declare const jsxs: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> |
|
|
26
|
+
declare function patch(this: (type: React__default.ElementType, ...args: any[]) => React__default.ReactElement, type: React__default.ElementType | State.Class, ...args: any[]): React__default.ReactElement;
|
|
27
|
+
declare const jsx: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | State.Class<State>, ...args: any[]) => React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>>;
|
|
28
|
+
declare const jsxs: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | State.Class<State>, ...args: any[]) => React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>>;
|
|
56
29
|
|
|
57
|
-
export { JSX,
|
|
30
|
+
export { JSX, jsx, jsxs, patch };
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -31,63 +31,100 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var jsx_runtime_exports = {};
|
|
32
32
|
__export(jsx_runtime_exports, {
|
|
33
33
|
Fragment: () => import_react2.Fragment,
|
|
34
|
-
compat: () => compat,
|
|
35
34
|
jsx: () => jsx,
|
|
36
|
-
jsxs: () => jsxs
|
|
35
|
+
jsxs: () => jsxs,
|
|
36
|
+
patch: () => patch
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(jsx_runtime_exports);
|
|
39
|
-
var
|
|
39
|
+
var import_mvc3 = require("@expressive/mvc");
|
|
40
40
|
var import_jsx_runtime = __toESM(require("react/jsx-runtime"));
|
|
41
41
|
|
|
42
|
+
// src/state.as.ts
|
|
43
|
+
var import_mvc2 = require("@expressive/mvc");
|
|
44
|
+
|
|
42
45
|
// src/context.ts
|
|
43
|
-
var import_mvc =
|
|
46
|
+
var import_mvc = require("@expressive/mvc");
|
|
44
47
|
var import_react = require("react");
|
|
45
|
-
var
|
|
48
|
+
var Layers = (0, import_react.createContext)(new import_mvc.Context());
|
|
46
49
|
import_mvc.Context.use = (create) => {
|
|
47
|
-
const ambient = (0, import_react.useContext)(
|
|
48
|
-
return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
|
|
50
|
+
const ambient = (0, import_react.useContext)(Layers);
|
|
51
|
+
return create ? (0, import_react.useMemo)(() => ambient.push(), [ambient]) : ambient;
|
|
49
52
|
};
|
|
50
|
-
function
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
function provide(context, children, fallback, name) {
|
|
54
|
+
if (fallback !== void 0)
|
|
55
|
+
children = (0, import_react.createElement)(import_react.Suspense, { fallback, name }, children);
|
|
56
|
+
return (0, import_react.createElement)(Layers.Provider, {
|
|
54
57
|
key: context.id,
|
|
55
58
|
value: context,
|
|
56
59
|
children
|
|
57
60
|
});
|
|
58
|
-
return fallback !== void 0 ? (0, import_react.createElement)(import_react.Suspense, { fallback, name }, element) : element;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
// src/
|
|
62
|
-
var
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
// src/state.as.ts
|
|
64
|
+
var import_adapter = require("./adapter");
|
|
65
|
+
import_mvc2.State.as = function(render) {
|
|
66
|
+
const FC = Render.bind(this, { render });
|
|
67
|
+
return Object.assign(FC, {
|
|
68
|
+
displayName: this.name,
|
|
69
|
+
State: this
|
|
68
70
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
71
|
+
};
|
|
72
|
+
function Render(props, props2) {
|
|
73
|
+
const { is, ...rest } = { ...props, ...props2 };
|
|
74
|
+
const ambient = import_mvc2.Context.use();
|
|
75
|
+
const state = import_adapter.Pragma.useState(() => {
|
|
76
|
+
const instance = this.new(rest, is && ((x) => void is(x)));
|
|
77
|
+
const context = ambient.push(instance);
|
|
78
|
+
let ready;
|
|
79
|
+
let active;
|
|
80
|
+
(0, import_mvc2.watch)(instance, (current) => {
|
|
81
|
+
active = current;
|
|
82
|
+
if (ready) state[1]((x) => x.bind(null));
|
|
83
|
+
});
|
|
84
|
+
function didMount() {
|
|
85
|
+
ready = true;
|
|
86
|
+
return () => {
|
|
87
|
+
context.pop();
|
|
88
|
+
instance.set(null);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function Render2(props3) {
|
|
92
|
+
const render = import_mvc2.METHOD.get(active.render) || props3.render || active.render;
|
|
93
|
+
return render ? render.call(active, props3, active) : props3.children;
|
|
94
|
+
}
|
|
95
|
+
return (props3) => {
|
|
96
|
+
ready = false;
|
|
97
|
+
import_adapter.Pragma.useEffect(didMount, []);
|
|
98
|
+
Promise.resolve(instance.set(props3)).finally(() => {
|
|
99
|
+
ready = true;
|
|
100
|
+
});
|
|
101
|
+
return provide(
|
|
102
|
+
context,
|
|
103
|
+
import_adapter.Pragma.createElement(Render2, props3),
|
|
104
|
+
props3.fallback || active.fallback,
|
|
105
|
+
String(instance)
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
return state[0](rest);
|
|
73
110
|
}
|
|
111
|
+
|
|
112
|
+
// src/jsx-runtime.ts
|
|
113
|
+
var import_react2 = require("react");
|
|
74
114
|
var RENDER = /* @__PURE__ */ new WeakMap();
|
|
75
|
-
function
|
|
76
|
-
if (
|
|
77
|
-
if (RENDER.has(type))
|
|
78
|
-
|
|
79
|
-
else if (typeof type == "function")
|
|
80
|
-
RENDER.set(type, type = type.prototype instanceof import_mvc2.Model ? MC.bind(type) : type);
|
|
81
|
-
}
|
|
115
|
+
function patch(type, ...args) {
|
|
116
|
+
if (import_mvc3.State.is(type))
|
|
117
|
+
if (RENDER.has(type)) type = RENDER.get(type);
|
|
118
|
+
else RENDER.set(type, type = Render.bind(type));
|
|
82
119
|
return this(type, ...args);
|
|
83
120
|
}
|
|
84
|
-
var jsx =
|
|
85
|
-
var jsxs =
|
|
121
|
+
var jsx = patch.bind(import_jsx_runtime.default.jsx);
|
|
122
|
+
var jsxs = patch.bind(import_jsx_runtime.default.jsxs);
|
|
86
123
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
124
|
0 && (module.exports = {
|
|
88
125
|
Fragment,
|
|
89
|
-
compat,
|
|
90
126
|
jsx,
|
|
91
|
-
jsxs
|
|
127
|
+
jsxs,
|
|
128
|
+
patch
|
|
92
129
|
});
|
|
93
130
|
//# sourceMappingURL=jsx-runtime.js.map
|
package/dist/jsx-runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { METHOD, Model } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { createProvider } from './context';\n\ndeclare module \"@expressive/mvc\" {\n namespace Model {\n /**\n * Use this to define a component which wraps a Model, intended to forward props.\n * This is to be used explicity, in JSDoc types or type annotations.\n * The second type parameter is additional props the component expects to receive.\n * \n * @example\n * ```tsx\n * import { Model } from '@expressive/react';\n * \n * class MyModel extends Model {\n * foo: string;\n * bar: number;\n * }\n * \n * const MyComponent: Model.FC<MyModel, { label: string }> =\n * ({ label, ...rest }) => (\n * <div>\n * <span>{label}</span>\n * <MyModel {...rest} />\n * </div>\n * );\n * ```\n */\n type FC<T extends Model, P extends {} = {}> = React.FC<Props<T> & P>;\n }\n}\n\nexport declare namespace JSX {\n type ElementType = \n | Model.Type<Model.Compat>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U } ? U :\n C extends Model.Type<infer U> ? Model.Props<U> :\n React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n // This is a hack to make TypeScript happy - React one insists on `props` property existing.\n // I await the \"Find Out\" phase of this experiment in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nfunction MC<T extends Model.Compat>(\n this: Model.Init<T>,\n { is, ...props }: Model.Props<T>\n) {\n const model = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(is)\n is(self);\n });\n\n model.set(props as Model.Assign<T>);\n\n const render = METHOD.get(model.render) || props.render || model.render;\n const children = render\n ? render.call(model, props as Model.HasProps<T>, model)\n : props.children;\n\n return createProvider(model, children, props.fallback || model.fallback, String(model));\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function compat(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | Model.Init, ...args: any[]): React.ReactElement {\n\n if(typeof type == \"function\")\n if(RENDER.has(type))\n type = RENDER.get(type)!;\n else if(typeof type == \"function\")\n RENDER.set(type, type = (\n type.prototype instanceof Model ?\n MC.bind(type as Model.Init) :\n type as React.ComponentType\n ));\n\n return this(type, ...args);\n}\n\nexport const jsx = compat.bind(Runtime.jsx);\nexport const jsxs = compat.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";","import Model, { Context } from '@expressive/mvc';\nimport { createContext, createElement, ReactNode, Suspense, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\n\ndeclare module '@expressive/mvc' {\n namespace Context {\n function use(create?: true): Context;\n function use(create: boolean): Context | null | undefined;\n }\n}\n\nContext.use = (create?: boolean) => {\n const ambient = useContext(Lookup);\n\n return create ?\n useMemo(() => ambient.push(), []) :\n ambient;\n}\n\ndeclare namespace Consumer {\n type Props<T extends Model> = {\n /** Type of controller to fetch from context. */\n for: Model.Type<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `Model.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n }\n}\n\nfunction Consumer<T extends Model>(props: Consumer.Props<T>){\n return props.for.get(i => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends Model> {\n /** Model or group of Models to provide to descendant Consumers. */\n for: Context.Accept<T>;\n\n forEach?: Context.Expect<T>;\n children?: ReactNode;\n\n /** A fallback react tree to show when suspended. */\n fallback?: ReactNode;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n}\n\nfunction Provider<T extends Model>(props: Provider.Props<T>){\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.include(props.for, (model) => {\n if(props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.set(cleanup, null);\n }\n });\n \n return createProvider(context, props.children, props.fallback, props.name);\n}\n\nexport function createProvider(\n context: Context | Model,\n children: ReactNode,\n fallback?: ReactNode,\n name?: string | undefined){\n\n if(context instanceof Model)\n context = Context.get(context)!;\n\n const element = createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n\n return fallback !== undefined ?\n createElement(Suspense, { fallback, name }, element) :\n element;\n}\n\nexport { Consumer, Provider, Context }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA8B;AAE9B,yBAAoB;;;ACFpB,iBAA+B;AAC/B,mBAAkG;AAElG,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAS1C,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aACL,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AA0DO,SAAS,eACd,SACA,UACA,UACA,MAA0B;AAE1B,MAAG,mBAAmB,WAAAC;AACpB,cAAU,mBAAQ,IAAI,OAAO;AAE/B,QAAM,cAAU,4BAAc,OAAO,UAAU;AAAA,IAC7C,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AAED,SAAO,aAAa,aAClB,4BAAc,uBAAU,EAAE,UAAU,KAAK,GAAG,OAAO,IACnD;AACJ;;;ADQA,IAAAC,gBAAyB;AA3CzB,SAAS,GAEP,EAAE,IAAI,GAAG,MAAM,GACf;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG;AACD,SAAG,IAAI;AAAA,EACX,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,mBAAO,IAAI,MAAM,MAAM,KAAK,MAAM,UAAU,MAAM;AACjE,QAAM,WAAW,SACb,OAAO,KAAK,OAAO,OAA4B,KAAK,IACpD,MAAM;AAEV,SAAO,eAAe,OAAO,UAAU,MAAM,YAAY,MAAM,UAAU,OAAO,KAAK,CAAC;AACxF;AAEA,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,OAEd,SAAyC,MAAiC;AAE1E,MAAG,OAAO,QAAQ;AAChB,QAAG,OAAO,IAAI,IAAI;AAChB,aAAO,OAAO,IAAI,IAAI;AAAA,aAChB,OAAO,QAAQ;AACrB,aAAO,IAAI,MAAM,OACf,KAAK,qBAAqB,oBACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,mBAAAC,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,mBAAAA,QAAQ,IAAI;","names":["import_mvc","Model","import_react","Runtime"]}
|
|
1
|
+
{"version":3,"sources":["../src/jsx-runtime.ts","../src/state.as.ts","../src/context.ts"],"sourcesContent":["import { State } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { Render } from './state.as';\n\nexport declare namespace JSX {\n type ElementType =\n | State.Extends<State.AsComponent>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U }\n ? U\n : C extends State.Extends<infer U>\n ? State.Props<U>\n : React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n\n // This is a hack to make TypeScript happy - React's interface insists on `props` property existing.\n // I await the \"Find Out\" phase of this in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute\n extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX\n .IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function patch(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | State.Class,\n ...args: any[]\n): React.ReactElement {\n if (State.is(type))\n if (RENDER.has(type)) type = RENDER.get(type)!;\n else RENDER.set(type, (type = Render.bind(type)));\n\n return this(type, ...args);\n}\n\nexport const jsx = patch.bind(Runtime.jsx);\nexport const jsxs = patch.bind(Runtime.jsxs);\n\nexport { Fragment } from 'react';\n","import { Context, watch, METHOD, State } from '@expressive/mvc';\nimport { FunctionComponent, ReactNode } from 'react';\n\nimport { provide } from './context';\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace State {\n type HasProps<T extends State> = {\n [K in Exclude<keyof T, keyof State>]?: T[K];\n };\n\n type ComponentProps<T extends State> = HasProps<T> & {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void;\n\n /**\n * A fallback react tree to show when suspended.\n * If not provided, `fallback` property of the State will be used.\n */\n fallback?: React.ReactNode;\n };\n\n type Props<T extends State> = T extends {\n render(props: infer P, self: any): any;\n }\n ? ComponentProps<T> & Omit<P, keyof AsComponent>\n : ComponentProps<T> & { children?: React.ReactNode };\n\n /**\n * Props which will not conflict with a State's use as a Component.\n *\n * Built-in properties must be optional, as they will always be omitted.\n */\n type RenderProps<T extends State> = HasProps<T> & {\n is?: never;\n get?: never;\n set?: never;\n };\n\n /** State which is not incompatable as Component in React. */\n interface AsComponent extends State.Valid {\n render?(props: RenderProps<this>, self: this): React.ReactNode;\n fallback?: React.ReactNode;\n }\n\n interface FC<\n T extends State,\n P extends State.Assign<T>\n > extends FunctionComponent<P & State.Props<T>> {\n displayName?: string;\n State: State.Extends<T>;\n }\n\n function as<T extends State, P extends State.Assign<T>>(\n this: State.New<T>,\n render: (props: P, self: T) => ReactNode\n ): FC<T, P>;\n }\n}\n\nState.as = function <T extends State.AsComponent, P extends State.Assign<T>>(\n this: State.Class<T>,\n render: (props: P, self: T) => ReactNode\n): State.FC<T, P> {\n const FC = Render.bind(this as State.Class, { render } as {});\n\n return Object.assign(FC, {\n displayName: this.name,\n State: this\n });\n};\n\nexport function Render<T extends State.AsComponent>(\n this: State.Class<T>,\n props: State.Props<T>,\n props2?: State.Props<T>\n) {\n const { is, ...rest } = { ...props, ...props2 };\n\n const ambient = Context.use();\n const state = Pragma.useState<(props: any) => any>(() => {\n const instance = this.new(rest as {}, is && ((x) => void is(x)));\n const context = ambient.push(instance);\n\n let ready: boolean | undefined;\n let active: T;\n\n watch(instance, (current) => {\n active = current;\n\n if (ready) state[1]((x) => x.bind(null));\n });\n\n function didMount() {\n ready = true;\n return () => {\n context.pop();\n instance.set(null);\n };\n }\n\n function Render(props: State.Props<T>) {\n const render = METHOD.get(active.render) || props.render || active.render;\n\n return render\n ? render.call(active, props as State.HasProps<T>, active)\n : props.children;\n }\n\n return (props: State.RenderProps<T>) => {\n ready = false;\n\n Pragma.useEffect(didMount, []);\n Promise.resolve(instance.set(props as {})).finally(() => {\n ready = true;\n });\n\n return provide(\n context,\n Pragma.createElement(Render, props as any),\n props.fallback || active.fallback,\n String(instance)\n );\n };\n });\n\n return state[0](rest);\n}\n","import State, { Context } from '@expressive/mvc';\nimport {\n createContext,\n createElement,\n ReactNode,\n Suspense,\n useContext,\n useEffect,\n useMemo\n} from 'react';\n\nexport const Layers = createContext(new Context());\n\ndeclare module '@expressive/mvc' {\n namespace Context {\n function use(create?: true): Context;\n function use(create: boolean): Context | null | undefined;\n }\n}\n\nContext.use = (create?: boolean) => {\n const ambient = useContext(Layers);\n\n return create ? useMemo(() => ambient.push(), [ambient]) : ambient;\n};\n\ndeclare namespace Consumer {\n type Props<T extends State> = {\n /** Type of controller to fetch from context. */\n for: State.Extends<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `State.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n };\n}\n\nfunction Consumer<T extends State>(props: Consumer.Props<T>) {\n return props.for.get((i) => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends State> {\n /** State or group of States to provide to descendant Consumers. */\n for: Context.Accept<T>;\n\n /**\n * Callback to run for each provided State.\n */\n forEach?: Context.Expect<T>;\n\n /**\n * Children to render within this Provider.\n */\n children?: ReactNode;\n\n /** A fallback tree to show when suspended. */\n fallback?: ReactNode;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n}\n\nfunction Provider<T extends State>(props: Provider.Props<T>) {\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.use(props.for, (state) => {\n if (props.forEach) {\n const cleanup = props.forEach(state);\n\n if (cleanup) state.set(cleanup, null);\n }\n });\n\n return provide(context, props.children, props.fallback, props.name);\n}\n\nfunction provide(\n context: Context,\n children: ReactNode,\n fallback?: ReactNode,\n name?: string | undefined\n): ReactNode {\n if (fallback !== undefined)\n children = createElement(Suspense, { fallback, name }, children);\n\n return createElement(Layers.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, provide };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAAsB;AAEtB,yBAAoB;;;ACFpB,IAAAC,cAA8C;;;ACA9C,iBAA+B;AAC/B,mBAQO;AAEA,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AASjD,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aAAS,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC,IAAI;AAC7D;AAgEA,SAAS,QACP,SACA,UACA,UACA,MACW;AACX,MAAI,aAAa;AACf,mBAAW,4BAAc,uBAAU,EAAE,UAAU,KAAK,GAAG,QAAQ;AAEjE,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;;;ADlGA,qBAAuB;AA4DvB,kBAAM,KAAK,SAET,QACgB;AAChB,QAAM,KAAK,OAAO,KAAK,MAAqB,EAAE,OAAO,CAAO;AAE5D,SAAO,OAAO,OAAO,IAAI;AAAA,IACvB,aAAa,KAAK;AAAA,IAClB,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,OAEd,OACA,QACA;AACA,QAAM,EAAE,IAAI,GAAG,KAAK,IAAI,EAAE,GAAG,OAAO,GAAG,OAAO;AAE9C,QAAM,UAAU,oBAAQ,IAAI;AAC5B,QAAM,QAAQ,sBAAO,SAA8B,MAAM;AACvD,UAAM,WAAW,KAAK,IAAI,MAAY,OAAO,CAAC,MAAM,KAAK,GAAG,CAAC,EAAE;AAC/D,UAAM,UAAU,QAAQ,KAAK,QAAQ;AAErC,QAAI;AACJ,QAAI;AAEJ,2BAAM,UAAU,CAAC,YAAY;AAC3B,eAAS;AAET,UAAI,MAAO,OAAM,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC;AAAA,IACzC,CAAC;AAED,aAAS,WAAW;AAClB,cAAQ;AACR,aAAO,MAAM;AACX,gBAAQ,IAAI;AACZ,iBAAS,IAAI,IAAI;AAAA,MACnB;AAAA,IACF;AAEA,aAASC,QAAOC,QAAuB;AACrC,YAAM,SAAS,mBAAO,IAAI,OAAO,MAAM,KAAKA,OAAM,UAAU,OAAO;AAEnE,aAAO,SACH,OAAO,KAAK,QAAQA,QAA4B,MAAM,IACtDA,OAAM;AAAA,IACZ;AAEA,WAAO,CAACA,WAAgC;AACtC,cAAQ;AAER,4BAAO,UAAU,UAAU,CAAC,CAAC;AAC7B,cAAQ,QAAQ,SAAS,IAAIA,MAAW,CAAC,EAAE,QAAQ,MAAM;AACvD,gBAAQ;AAAA,MACV,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA,sBAAO,cAAcD,SAAQC,MAAY;AAAA,QACzCA,OAAM,YAAY,OAAO;AAAA,QACzB,OAAO,QAAQ;AAAA,MACjB;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,MAAM,CAAC,EAAE,IAAI;AACtB;;;AD/EA,IAAAC,gBAAyB;AAjBzB,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,MAEd,SACG,MACiB;AACpB,MAAI,kBAAM,GAAG,IAAI;AACf,QAAI,OAAO,IAAI,IAAI,EAAG,QAAO,OAAO,IAAI,IAAI;AAAA,QACvC,QAAO,IAAI,MAAO,OAAO,OAAO,KAAK,IAAI,CAAE;AAElD,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,MAAM,KAAK,mBAAAC,QAAQ,GAAG;AAClC,IAAM,OAAO,MAAM,KAAK,mBAAAA,QAAQ,IAAI;","names":["import_mvc","import_mvc","Render","props","import_react","Runtime"]}
|
package/package.json
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"preversion": "npm run test && npm run build"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@expressive/mvc": "^0.
|
|
52
|
+
"@expressive/mvc": "^0.72.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"react": ">=16.8.0 <20.0.0"
|
|
@@ -60,13 +60,15 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@testing-library/jest-dom": "^6.
|
|
63
|
+
"@testing-library/jest-dom": "^6.8.0",
|
|
64
64
|
"@testing-library/react": "^16.3.0",
|
|
65
|
-
"@types/react": "^
|
|
65
|
+
"@types/react": "^19",
|
|
66
|
+
"@types/react-dom": "^19",
|
|
66
67
|
"jest": "^27.5.1",
|
|
67
|
-
"react": "^
|
|
68
|
+
"react": "^19",
|
|
69
|
+
"react-dom": "^19",
|
|
68
70
|
"tsup": "^8.0.2"
|
|
69
71
|
},
|
|
70
|
-
"version": "0.
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"version": "0.72.0",
|
|
73
|
+
"gitHead": "3661a47db05bd7469cda51b63beed29e76a422cd"
|
|
72
74
|
}
|
package/dist/esm/context.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// src/context.ts
|
|
2
|
-
import Model, { Context } from "@expressive/mvc";
|
|
3
|
-
import { createContext, createElement, Suspense, useContext, useEffect, useMemo } from "react";
|
|
4
|
-
var Lookup = createContext(new Context());
|
|
5
|
-
Context.use = (create) => {
|
|
6
|
-
const ambient = useContext(Lookup);
|
|
7
|
-
return create ? useMemo(() => ambient.push(), []) : ambient;
|
|
8
|
-
};
|
|
9
|
-
function Consumer(props) {
|
|
10
|
-
return props.for.get((i) => props.children(i));
|
|
11
|
-
}
|
|
12
|
-
function Provider(props) {
|
|
13
|
-
const context = Context.use(true);
|
|
14
|
-
useEffect(() => () => context.pop(), [context]);
|
|
15
|
-
context.include(props.for, (model) => {
|
|
16
|
-
if (props.forEach) {
|
|
17
|
-
const cleanup = props.forEach(model);
|
|
18
|
-
if (cleanup)
|
|
19
|
-
model.set(cleanup, null);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return createProvider(context, props.children, props.fallback, props.name);
|
|
23
|
-
}
|
|
24
|
-
function createProvider(context, children, fallback, name) {
|
|
25
|
-
if (context instanceof Model)
|
|
26
|
-
context = Context.get(context);
|
|
27
|
-
const element = createElement(Lookup.Provider, {
|
|
28
|
-
key: context.id,
|
|
29
|
-
value: context,
|
|
30
|
-
children
|
|
31
|
-
});
|
|
32
|
-
return fallback !== void 0 ? createElement(Suspense, { fallback, name }, element) : element;
|
|
33
|
-
}
|
|
34
|
-
export {
|
|
35
|
-
Consumer,
|
|
36
|
-
Context,
|
|
37
|
-
Provider,
|
|
38
|
-
createProvider
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=context.js.map
|
package/dist/esm/context.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context.ts"],"sourcesContent":["import Model, { Context } from '@expressive/mvc';\nimport { createContext, createElement, ReactNode, Suspense, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\n\ndeclare module '@expressive/mvc' {\n namespace Context {\n function use(create?: true): Context;\n function use(create: boolean): Context | null | undefined;\n }\n}\n\nContext.use = (create?: boolean) => {\n const ambient = useContext(Lookup);\n\n return create ?\n useMemo(() => ambient.push(), []) :\n ambient;\n}\n\ndeclare namespace Consumer {\n type Props<T extends Model> = {\n /** Type of controller to fetch from context. */\n for: Model.Type<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `Model.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n }\n}\n\nfunction Consumer<T extends Model>(props: Consumer.Props<T>){\n return props.for.get(i => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends Model> {\n /** Model or group of Models to provide to descendant Consumers. */\n for: Context.Accept<T>;\n\n forEach?: Context.Expect<T>;\n children?: ReactNode;\n\n /** A fallback react tree to show when suspended. */\n fallback?: ReactNode;\n\n /**\n * A name for this Suspense boundary for instrumentation purposes.\n * The name will help identify this boundary in React DevTools.\n */\n name?: string | undefined;\n }\n}\n\nfunction Provider<T extends Model>(props: Provider.Props<T>){\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.include(props.for, (model) => {\n if(props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.set(cleanup, null);\n }\n });\n \n return createProvider(context, props.children, props.fallback, props.name);\n}\n\nexport function createProvider(\n context: Context | Model,\n children: ReactNode,\n fallback?: ReactNode,\n name?: string | undefined){\n\n if(context instanceof Model)\n context = Context.get(context)!;\n\n const element = createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n\n return fallback !== undefined ?\n createElement(Suspense, { fallback, name }, element) :\n element;\n}\n\nexport { Consumer, Provider, Context }\n"],"mappings":";AAAA,OAAO,SAAS,eAAe;AAC/B,SAAS,eAAe,eAA0B,UAAU,YAAY,WAAW,eAAe;AAElG,IAAM,SAAS,cAAc,IAAI,QAAQ,CAAC;AAS1C,QAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,UAAU,WAAW,MAAM;AAEjC,SAAO,SACL,QAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AAkBA,SAAS,SAA0B,OAAyB;AAC1D,SAAO,MAAM,IAAI,IAAI,OAAK,MAAM,SAAS,CAAC,CAAC;AAC7C;AAqBA,SAAS,SAA0B,OAAyB;AAC1D,QAAM,UAAU,QAAQ,IAAI,IAAI;AAEhC,YAAU,MAAM,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC;AAE9C,UAAQ,QAAQ,MAAM,KAAK,CAAC,UAAU;AACpC,QAAG,MAAM,SAAQ;AACf,YAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,UAAG;AACD,cAAM,IAAI,SAAS,IAAI;AAAA,IAC3B;AAAA,EACF,CAAC;AAED,SAAO,eAAe,SAAS,MAAM,UAAU,MAAM,UAAU,MAAM,IAAI;AAC3E;AAEO,SAAS,eACd,SACA,UACA,UACA,MAA0B;AAE1B,MAAG,mBAAmB;AACpB,cAAU,QAAQ,IAAI,OAAO;AAE/B,QAAM,UAAU,cAAc,OAAO,UAAU;AAAA,IAC7C,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AAED,SAAO,aAAa,SAClB,cAAc,UAAU,EAAE,UAAU,KAAK,GAAG,OAAO,IACnD;AACJ;","names":[]}
|