@expressive/react 0.71.0 → 0.72.1-canary.14

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/package.json CHANGED
@@ -7,27 +7,31 @@
7
7
  "url": "https://github.com/gabeklein"
8
8
  },
9
9
  "license": "MIT",
10
- "repository": "https://github.com/gabeklein/expressive-mvc",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/gabeklein/expressive-state.git"
13
+ },
11
14
  "publishConfig": {
12
15
  "access": "public"
13
16
  },
14
17
  "keywords": [
15
18
  "expressive",
16
19
  "react",
17
- "mvc"
20
+ "state"
18
21
  ],
19
22
  "main": "dist/index.js",
20
23
  "types": "dist/index.d.ts",
24
+ "type": "module",
21
25
  "exports": {
22
26
  ".": {
23
27
  "types": "./dist/index.d.ts",
24
28
  "require": "./dist/index.js",
25
29
  "import": "./dist/esm/index.js"
26
30
  },
27
- "./adapter": {
28
- "types": "./dist/adapter.d.ts",
29
- "require": "./dist/adapter.js",
30
- "import": "./dist/esm/adapter.js"
31
+ "./state": {
32
+ "types": "./dist/state.d.ts",
33
+ "require": "./dist/state.js",
34
+ "import": "./dist/esm/state.js"
31
35
  },
32
36
  "./jsx-runtime": {
33
37
  "types": "./dist/jsx-runtime.d.ts",
@@ -44,12 +48,12 @@
44
48
  "dist"
45
49
  ],
46
50
  "scripts": {
47
- "build": "tsup",
48
- "test": "tsc --noEmit && jest --collectCoverage",
51
+ "build": "tsdown",
52
+ "test": "tsc --noEmit && vitest run --coverage",
49
53
  "preversion": "npm run test && npm run build"
50
54
  },
51
55
  "dependencies": {
52
- "@expressive/mvc": "^0.71.0"
56
+ "@expressive/state": "^0.72.1-canary.14+f89c0af8"
53
57
  },
54
58
  "peerDependencies": {
55
59
  "react": ">=16.8.0 <20.0.0"
@@ -60,13 +64,16 @@
60
64
  }
61
65
  },
62
66
  "devDependencies": {
63
- "@testing-library/jest-dom": "^6.6.4",
64
67
  "@testing-library/react": "^16.3.0",
65
- "@types/react": "^18.2.14",
66
- "jest": "^27.5.1",
67
- "react": "^18.2.0",
68
- "tsup": "^8.0.2"
68
+ "@types/react": "^19",
69
+ "@types/react-dom": "^19",
70
+ "@vitest/browser": "^4.0.18",
71
+ "react": "^19",
72
+ "react-dom": "^19",
73
+ "tsdown": "^0.20.1",
74
+ "tsup": "^8.0.2",
75
+ "vitest": "^4.0.18"
69
76
  },
70
- "version": "0.71.0",
71
- "gitHead": "4d1f02e2c64ae6a993d6fa1384d385bd58a26e37"
77
+ "version": "0.72.1-canary.14+f89c0af8",
78
+ "gitHead": "f89c0af893d0f5ae24f28f42ef5c1af1d37be9bf"
72
79
  }
package/dist/adapter.d.ts DELETED
@@ -1,105 +0,0 @@
1
- import { Context } from '@expressive/mvc';
2
- import React__default, { FunctionComponent } from 'react';
3
-
4
- declare module '@expressive/mvc' {
5
- namespace Model {
6
- interface Component<T extends Model, P extends Model.Assign<T>> extends FunctionComponent<P & Model.Props<T>> {
7
- displayName?: string;
8
- Model: Model.Type<T>;
9
- }
10
- function as<T extends Model, P extends Model.Assign<T>>(this: Model.Init<T>, render: (props: P, self: T) => React__default.ReactNode): Component<T, P>;
11
- }
12
- }
13
-
14
- declare module '@expressive/mvc' {
15
- namespace Model {
16
- function use<T extends Model>(this: Model.Init<T>, apply?: Model.Assign<T>, repeat?: boolean): T;
17
- function use<T extends Model>(this: Model.Init<T>, callback?: Model.Callback<T>, repeat?: boolean): T;
18
- }
19
- }
20
-
21
- /** Type may not be undefined - instead will be null. */
22
- type NoVoid<T> = T extends undefined | void ? null : T;
23
- type ForceRefresh = {
24
- /** Request a refresh for current component. */
25
- (): void;
26
- /**
27
- * Request a refresh and again after promise either resolves or rejects.
28
- *
29
- * @param waitFor Promise to wait for.
30
- * @returns Promise which resolves, after refresh, to same value as `waitFor`.
31
- */
32
- <T = void>(waitFor: Promise<T>): Promise<T>;
33
- /**
34
- * Request refresh before and after async function.
35
- * A refresh will occur both before and after the given function.
36
- *
37
- * **Note:** Any actions performed before first `await` will occur prior to refresh.
38
- *
39
- * @param invoke Async function to invoke.
40
- * @returns Promise which resolves returned value after refresh.
41
- */
42
- <T = void>(invoke: () => Promise<T>): Promise<T>;
43
- };
44
- declare module '@expressive/mvc' {
45
- namespace Model {
46
- type GetFactory<T extends Model, R> = (this: T, current: T, refresh: ForceRefresh) => R;
47
- type GetEffect<T extends Model> = (this: T, current: T, refresh: ForceRefresh) => null;
48
- /** Fetch instance of this class from context. */
49
- function get<T extends Model>(this: Model.Type<T>): T;
50
- /** Fetch instance of this class optionally. */
51
- function get<T extends Model>(this: Model.Type<T>, required: false): T | undefined;
52
- /** Fetch instance of this class from context. */
53
- function get<T extends Model>(this: Model.Type<T>, requireValues: true): Required<T>;
54
- function get<T extends Model, R>(this: Model.Type<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;
55
- function get<T extends Model>(this: Model.Type<T>, factory: GetEffect<T>): null;
56
- }
57
- }
58
-
59
- declare module '@expressive/mvc' {
60
- namespace Model {
61
- type HasProps<T extends Model> = {
62
- [K in Exclude<keyof T, keyof Model>]?: T[K];
63
- };
64
- /**
65
- * Props which will not conflict with a Model's use as a Component.
66
- *
67
- * Built-in properties must be optional, as they will always be omitted.
68
- */
69
- type RenderProps<T extends Model> = HasProps<T> & {
70
- is?: undefined;
71
- get?: undefined;
72
- set?: undefined;
73
- };
74
- /** Model which is not incompatable as Component in React. */
75
- interface Compat extends Model {
76
- render?(props: RenderProps<this>, self: this): React.ReactNode;
77
- fallback?: React.ReactNode;
78
- }
79
- interface BaseProps<T extends Model> {
80
- /**
81
- * Callback for newly created instance. Only called once.
82
- * @returns Callback to run when instance is destroyed.
83
- */
84
- is?: (instance: T) => void;
85
- render?(props: HasProps<T>, self: T): React.ReactNode;
86
- /**
87
- * A fallback react tree to show when suspended.
88
- * If not provided, `fallback` property of the Model will be used.
89
- */
90
- fallback?: React.ReactNode;
91
- }
92
- type Props<T extends Model> = T extends {
93
- render(props: infer P, self: any): any;
94
- } ? BaseProps<T> & HasProps<T> & Omit<P, keyof Model> : BaseProps<T> & HasProps<T> & {
95
- children?: React.ReactNode;
96
- };
97
- }
98
- }
99
- declare const Pragma: {
100
- useContext(): Context;
101
- useFactory<T extends Function>(factory: (refresh: () => void) => T): T;
102
- useLifecycle(callback: () => () => void): void;
103
- };
104
-
105
- export { Pragma };
package/dist/adapter.js DELETED
@@ -1,191 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
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
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/adapter.ts
31
- var adapter_exports = {};
32
- __export(adapter_exports, {
33
- Pragma: () => Pragma3
34
- });
35
- module.exports = __toCommonJS(adapter_exports);
36
-
37
- // src/model.as.ts
38
- var import_mvc2 = require("@expressive/mvc");
39
-
40
- // src/context.ts
41
- var import_mvc = __toESM(require("@expressive/mvc"));
42
- var import_react = require("react");
43
- var Lookup = (0, import_react.createContext)(new import_mvc.Context());
44
- import_mvc.Context.use = (create) => {
45
- const ambient = (0, import_react.useContext)(Lookup);
46
- return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
47
- };
48
- function createProvider(context, children, fallback, name) {
49
- if (context instanceof import_mvc.default)
50
- context = import_mvc.Context.get(context);
51
- const element = (0, import_react.createElement)(Lookup.Provider, {
52
- key: context.id,
53
- value: context,
54
- children
55
- });
56
- return fallback !== void 0 ? (0, import_react.createElement)(import_react.Suspense, { fallback, name }, element) : element;
57
- }
58
-
59
- // src/model.as.ts
60
- import_mvc2.Model.as = function(render) {
61
- if (this === import_mvc2.Model)
62
- throw new Error("Cannot create component from base Model.");
63
- const Component = (props) => {
64
- const local = this.use((self) => {
65
- self.set(props);
66
- if (props.is)
67
- return props.is(self);
68
- });
69
- local.set(props);
70
- return createProvider(
71
- local,
72
- render(props, local),
73
- props.fallback || local.fallback,
74
- String(local)
75
- );
76
- };
77
- Component.Model = this;
78
- Component.displayName = this.name;
79
- return Component;
80
- };
81
-
82
- // src/model.use.ts
83
- var import_mvc3 = require("@expressive/mvc");
84
- var import_adapter = require("./adapter");
85
- import_mvc3.Model.use = function(argument, repeat) {
86
- const context = import_mvc3.Context.use(true);
87
- const render = import_adapter.Pragma.useFactory((refresh) => {
88
- let ready;
89
- let local;
90
- const instance = new this(argument);
91
- context.include(instance);
92
- const unwatch = (0, import_mvc3.createEffect)(instance, (current) => {
93
- local = current;
94
- if (ready)
95
- refresh();
96
- });
97
- function didMount() {
98
- ready = true;
99
- return () => {
100
- unwatch();
101
- context.pop();
102
- instance.set(null);
103
- };
104
- }
105
- return (props) => {
106
- import_adapter.Pragma.useLifecycle(didMount);
107
- if (ready && repeat && props) {
108
- ready = false;
109
- if (typeof props == "function") {
110
- props.call(instance, instance);
111
- props = void 0;
112
- }
113
- const update = instance.set(props);
114
- if (update)
115
- update.then(() => ready = true);
116
- else
117
- ready = true;
118
- }
119
- return local;
120
- };
121
- });
122
- return render(argument);
123
- };
124
-
125
- // src/model.get.ts
126
- var import_mvc4 = require("@expressive/mvc");
127
- var import_adapter2 = require("./adapter");
128
- import_mvc4.Model.get = function(argument) {
129
- const context = import_adapter2.Pragma.useContext();
130
- const render = import_adapter2.Pragma.useFactory((refresh) => {
131
- const instance = context.get(this);
132
- if (!instance)
133
- if (argument === false)
134
- return () => void 0;
135
- else
136
- throw new Error(`Could not find ${this} in context.`);
137
- let ready;
138
- let value;
139
- const unwatch = (0, import_mvc4.createEffect)(instance, (current) => {
140
- if (typeof argument === "function") {
141
- const next = argument.call(current, current, update);
142
- if (next === value)
143
- return;
144
- value = next;
145
- } else
146
- value = current;
147
- if (ready)
148
- refresh();
149
- }, argument === true);
150
- if (value instanceof Promise) {
151
- let error;
152
- unwatch();
153
- value.then((x) => value = x, (e) => error = e).finally(refresh);
154
- value = null;
155
- return () => {
156
- if (error)
157
- throw error;
158
- return value === void 0 ? null : value;
159
- };
160
- }
161
- if (value === null) {
162
- unwatch();
163
- return () => null;
164
- }
165
- ;
166
- function update(action) {
167
- if (typeof action == "function")
168
- action = action();
169
- refresh();
170
- if (action)
171
- return action.finally(refresh);
172
- }
173
- function didMount() {
174
- ready = true;
175
- return unwatch;
176
- }
177
- return () => {
178
- import_adapter2.Pragma.useLifecycle(didMount);
179
- return value === void 0 ? null : value;
180
- };
181
- });
182
- return render();
183
- };
184
-
185
- // src/adapter.ts
186
- var Pragma3 = {};
187
- // Annotate the CommonJS export names for ESM import in node:
188
- 0 && (module.exports = {
189
- Pragma
190
- });
191
- //# sourceMappingURL=adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/adapter.ts","../src/model.as.ts","../src/context.ts","../src/model.use.ts","../src/model.get.ts"],"sourcesContent":["import { Context } from '@expressive/mvc';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type HasProps<T extends Model> = {\n [K in Exclude<keyof T, keyof Model>]?: T[K];\n }\n\n /**\n * Props which will not conflict with a Model'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 Model> = HasProps<T> & {\n is?: undefined;\n get?: undefined;\n set?: undefined;\n };\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: RenderProps<this>, self: this): React.ReactNode;\n fallback?: React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\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 render?(props: HasProps<T>, self: T): React.ReactNode;\n\n /**\n * A fallback react tree to show when suspended.\n * If not provided, `fallback` property of the Model will be used.\n */\n fallback?: React.ReactNode;\n }\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & Omit<P, keyof Model>\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nconst Pragma = {} as {\n useContext(): Context;\n\n useFactory<T extends Function>(\n factory: (refresh: () => void) => T\n ): T;\n\n useLifecycle(callback: () => () => void): void;\n};\n\nexport { Pragma };\n\nimport \"./model.as\";\nimport './model.use';\nimport './model.get';","import { Model } from '@expressive/mvc';\nimport React, { FunctionComponent } from 'react';\n\nimport { createProvider } from './context';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> extends FunctionComponent<P & Model.Props<T>> {\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (props: P, self: T) => React.ReactNode\n ): Component<T, P>;\n }\n}\n\nModel.as = function <T extends Model.Compat, P extends Model.Assign<T>> (\n this: Model.Init<T>,\n render: (props: P, self: T) => React.ReactNode\n){\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component: Model.Component<T, P> = (props) => {\n const local = this.use((self) => {\n self.set(props);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props);\n\n return createProvider(\n local,\n render(props, local),\n props.fallback || local.fallback,\n String(local)\n );\n }\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","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","import { Model, Context, createEffect } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n function use <T extends Model> (\n this: Model.Init<T>,\n apply?: Model.Assign<T>,\n repeat?: boolean\n ): T;\n\n function use <T extends Model> (\n this: Model.Init<T>,\n callback?: Model.Callback<T>,\n repeat?: boolean\n ): T;\n }\n}\n\nModel.use = function <T extends Model> (\n this: Model.Init<T>,\n argument?: Model.Assign<T> | Model.Callback<T>,\n repeat?: boolean){\n\n const context = Context.use(true);\n const render = Pragma.useFactory((refresh) => {\n let ready: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n\n context.include(instance);\n \n const unwatch = createEffect(instance, current => {\n local = current;\n\n if(ready) \n refresh();\n });\n\n function didMount(){\n ready = true;\n return () => {\n unwatch();\n context.pop()\n instance.set(null);\n }\n }\n\n return (props?: Model.Assign<T> | Model.Callback<T>) => {\n Pragma.useLifecycle(didMount);\n\n if(ready && repeat && props){\n ready = false;\n\n if(typeof props == \"function\"){\n props.call(instance, instance);\n props = undefined\n }\n\n const update = instance.set(props);\n\n if(update)\n update.then(() => ready = true);\n else\n ready = true;\n }\n\n return local; \n };\n });\n\n return render(argument);\n}","import { createEffect, Model } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\ntype 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\ndeclare module '@expressive/mvc' {\n namespace Model {\n type GetFactory<T extends Model, R> =\n (this: T, current: T, refresh: ForceRefresh) => R;\n\n type GetEffect<T extends Model> =\n (this: T, current: T, refresh: ForceRefresh) => null;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>): T;\n \n /** Fetch instance of this class optionally. */\n function get <T extends Model> (this: Model.Type<T>, required: false): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>, requireValues: true): Required<T>\n \n function get <T extends Model, R> (this: Model.Type<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;\n \n // TODO: eagerly metch this so any nulls are caught - would prevent updates.\n function get <T extends Model> (this: Model.Type<T>, factory: GetEffect<T>): null;\n }\n}\n\nModel.get = function <T extends Model, R> (\n this: Model.Type<T>,\n argument?: boolean | Model.GetFactory<T, unknown>\n){\n const context = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n const instance = context.get(this);\n\n if(!instance)\n if(argument === false)\n return () => undefined;\n else\n throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n const unwatch = createEffect(instance, current => {\n if(typeof argument === \"function\"){\n const next = argument.call(current, current, update);\n\n if(next === value)\n return;\n\n value = next;\n }\n else\n value = current;\n\n if(ready)\n refresh();\n }, argument === true);\n\n if(value instanceof Promise){\n let error: Error | undefined;\n\n unwatch();\n\n value.then(x => value = x, e => error = e).finally(refresh);\n value = null;\n\n return () => {\n if(error)\n throw error;\n\n return value === undefined ? null : value;\n }\n }\n\n if(value === null){\n unwatch();\n return () => null;\n };\n\n function update<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if(typeof action == \"function\")\n action = action();\n\n refresh();\n\n if(action)\n return action.finally(refresh);\n }\n\n function didMount(){\n ready = true;\n return unwatch;\n }\n\n return () => {\n Pragma.useLifecycle(didMount);\n return value === undefined ? null : value;\n }\n });\n\n return render() as R;\n}"],"mappings":"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","names":["Pragma","import_mvc","Model","import_mvc","import_mvc","import_adapter","Pragma"]}
@@ -1,134 +0,0 @@
1
- // src/model.as.ts
2
- import { Model } from "@expressive/mvc";
3
- import { createProvider } from "./context";
4
- Model.as = function(render) {
5
- if (this === Model)
6
- throw new Error("Cannot create component from base Model.");
7
- const Component = (props) => {
8
- const local = this.use((self) => {
9
- self.set(props);
10
- if (props.is)
11
- return props.is(self);
12
- });
13
- local.set(props);
14
- return createProvider(
15
- local,
16
- render(props, local),
17
- props.fallback || local.fallback,
18
- String(local)
19
- );
20
- };
21
- Component.Model = this;
22
- Component.displayName = this.name;
23
- return Component;
24
- };
25
-
26
- // src/model.use.ts
27
- import { Model as Model2, Context, createEffect } from "@expressive/mvc";
28
- import { Pragma } from "./adapter";
29
- Model2.use = function(argument, repeat) {
30
- const context = Context.use(true);
31
- const render = Pragma.useFactory((refresh) => {
32
- let ready;
33
- let local;
34
- const instance = new this(argument);
35
- context.include(instance);
36
- const unwatch = createEffect(instance, (current) => {
37
- local = current;
38
- if (ready)
39
- refresh();
40
- });
41
- function didMount() {
42
- ready = true;
43
- return () => {
44
- unwatch();
45
- context.pop();
46
- instance.set(null);
47
- };
48
- }
49
- return (props) => {
50
- Pragma.useLifecycle(didMount);
51
- if (ready && repeat && props) {
52
- ready = false;
53
- if (typeof props == "function") {
54
- props.call(instance, instance);
55
- props = void 0;
56
- }
57
- const update = instance.set(props);
58
- if (update)
59
- update.then(() => ready = true);
60
- else
61
- ready = true;
62
- }
63
- return local;
64
- };
65
- });
66
- return render(argument);
67
- };
68
-
69
- // src/model.get.ts
70
- import { createEffect as createEffect2, Model as Model3 } from "@expressive/mvc";
71
- import { Pragma as Pragma2 } from "./adapter";
72
- Model3.get = function(argument) {
73
- const context = Pragma2.useContext();
74
- const render = Pragma2.useFactory((refresh) => {
75
- const instance = context.get(this);
76
- if (!instance)
77
- if (argument === false)
78
- return () => void 0;
79
- else
80
- throw new Error(`Could not find ${this} in context.`);
81
- let ready;
82
- let value;
83
- const unwatch = createEffect2(instance, (current) => {
84
- if (typeof argument === "function") {
85
- const next = argument.call(current, current, update);
86
- if (next === value)
87
- return;
88
- value = next;
89
- } else
90
- value = current;
91
- if (ready)
92
- refresh();
93
- }, argument === true);
94
- if (value instanceof Promise) {
95
- let error;
96
- unwatch();
97
- value.then((x) => value = x, (e) => error = e).finally(refresh);
98
- value = null;
99
- return () => {
100
- if (error)
101
- throw error;
102
- return value === void 0 ? null : value;
103
- };
104
- }
105
- if (value === null) {
106
- unwatch();
107
- return () => null;
108
- }
109
- ;
110
- function update(action) {
111
- if (typeof action == "function")
112
- action = action();
113
- refresh();
114
- if (action)
115
- return action.finally(refresh);
116
- }
117
- function didMount() {
118
- ready = true;
119
- return unwatch;
120
- }
121
- return () => {
122
- Pragma2.useLifecycle(didMount);
123
- return value === void 0 ? null : value;
124
- };
125
- });
126
- return render();
127
- };
128
-
129
- // src/adapter.ts
130
- var Pragma3 = {};
131
- export {
132
- Pragma3 as Pragma
133
- };
134
- //# sourceMappingURL=adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/model.as.ts","../../src/model.use.ts","../../src/model.get.ts","../../src/adapter.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport React, { FunctionComponent } from 'react';\n\nimport { createProvider } from './context';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> extends FunctionComponent<P & Model.Props<T>> {\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (props: P, self: T) => React.ReactNode\n ): Component<T, P>;\n }\n}\n\nModel.as = function <T extends Model.Compat, P extends Model.Assign<T>> (\n this: Model.Init<T>,\n render: (props: P, self: T) => React.ReactNode\n){\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component: Model.Component<T, P> = (props) => {\n const local = this.use((self) => {\n self.set(props);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props);\n\n return createProvider(\n local,\n render(props, local),\n props.fallback || local.fallback,\n String(local)\n );\n }\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import { Model, Context, createEffect } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n function use <T extends Model> (\n this: Model.Init<T>,\n apply?: Model.Assign<T>,\n repeat?: boolean\n ): T;\n\n function use <T extends Model> (\n this: Model.Init<T>,\n callback?: Model.Callback<T>,\n repeat?: boolean\n ): T;\n }\n}\n\nModel.use = function <T extends Model> (\n this: Model.Init<T>,\n argument?: Model.Assign<T> | Model.Callback<T>,\n repeat?: boolean){\n\n const context = Context.use(true);\n const render = Pragma.useFactory((refresh) => {\n let ready: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n\n context.include(instance);\n \n const unwatch = createEffect(instance, current => {\n local = current;\n\n if(ready) \n refresh();\n });\n\n function didMount(){\n ready = true;\n return () => {\n unwatch();\n context.pop()\n instance.set(null);\n }\n }\n\n return (props?: Model.Assign<T> | Model.Callback<T>) => {\n Pragma.useLifecycle(didMount);\n\n if(ready && repeat && props){\n ready = false;\n\n if(typeof props == \"function\"){\n props.call(instance, instance);\n props = undefined\n }\n\n const update = instance.set(props);\n\n if(update)\n update.then(() => ready = true);\n else\n ready = true;\n }\n\n return local; \n };\n });\n\n return render(argument);\n}","import { createEffect, Model } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\n/** Type may not be undefined - instead will be null. */\ntype NoVoid<T> = T extends undefined | void ? null : T;\n\ntype 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\ndeclare module '@expressive/mvc' {\n namespace Model {\n type GetFactory<T extends Model, R> =\n (this: T, current: T, refresh: ForceRefresh) => R;\n\n type GetEffect<T extends Model> =\n (this: T, current: T, refresh: ForceRefresh) => null;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>): T;\n \n /** Fetch instance of this class optionally. */\n function get <T extends Model> (this: Model.Type<T>, required: false): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get <T extends Model> (this: Model.Type<T>, requireValues: true): Required<T>\n \n function get <T extends Model, R> (this: Model.Type<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;\n \n // TODO: eagerly metch this so any nulls are caught - would prevent updates.\n function get <T extends Model> (this: Model.Type<T>, factory: GetEffect<T>): null;\n }\n}\n\nModel.get = function <T extends Model, R> (\n this: Model.Type<T>,\n argument?: boolean | Model.GetFactory<T, unknown>\n){\n const context = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n const instance = context.get(this);\n\n if(!instance)\n if(argument === false)\n return () => undefined;\n else\n throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n const unwatch = createEffect(instance, current => {\n if(typeof argument === \"function\"){\n const next = argument.call(current, current, update);\n\n if(next === value)\n return;\n\n value = next;\n }\n else\n value = current;\n\n if(ready)\n refresh();\n }, argument === true);\n\n if(value instanceof Promise){\n let error: Error | undefined;\n\n unwatch();\n\n value.then(x => value = x, e => error = e).finally(refresh);\n value = null;\n\n return () => {\n if(error)\n throw error;\n\n return value === undefined ? null : value;\n }\n }\n\n if(value === null){\n unwatch();\n return () => null;\n };\n\n function update<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if(typeof action == \"function\")\n action = action();\n\n refresh();\n\n if(action)\n return action.finally(refresh);\n }\n\n function didMount(){\n ready = true;\n return unwatch;\n }\n\n return () => {\n Pragma.useLifecycle(didMount);\n return value === undefined ? null : value;\n }\n });\n\n return render() as R;\n}","import { Context } from '@expressive/mvc';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type HasProps<T extends Model> = {\n [K in Exclude<keyof T, keyof Model>]?: T[K];\n }\n\n /**\n * Props which will not conflict with a Model'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 Model> = HasProps<T> & {\n is?: undefined;\n get?: undefined;\n set?: undefined;\n };\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: RenderProps<this>, self: this): React.ReactNode;\n fallback?: React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\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 render?(props: HasProps<T>, self: T): React.ReactNode;\n\n /**\n * A fallback react tree to show when suspended.\n * If not provided, `fallback` property of the Model will be used.\n */\n fallback?: React.ReactNode;\n }\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & Omit<P, keyof Model>\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nconst Pragma = {} as {\n useContext(): Context;\n\n useFactory<T extends Function>(\n factory: (refresh: () => void) => T\n ): T;\n\n useLifecycle(callback: () => () => void): void;\n};\n\nexport { Pragma };\n\nimport \"./model.as\";\nimport './model.use';\nimport './model.get';"],"mappings":"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","names":["Model","createEffect","Model","Pragma","Pragma"]}
@@ -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
@@ -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":[]}
package/dist/esm/index.js DELETED
@@ -1,40 +0,0 @@
1
- // src/index.ts
2
- import { useEffect, useState } from "react";
3
- import { Pragma } from "./adapter";
4
- import { Context } from "./context";
5
- import {
6
- Observable,
7
- Model,
8
- Model as Model2,
9
- get,
10
- use,
11
- ref,
12
- set,
13
- has
14
- } from "@expressive/mvc";
15
- import { Consumer, Context as Context2, Provider } from "./context";
16
- import { Fragment, createElement } from "react";
17
- Pragma.useContext = () => Context.use();
18
- Pragma.useLifecycle = (callback) => useEffect(() => callback(), []);
19
- Pragma.useFactory = (factory) => {
20
- const state = useState(() => factory(() => {
21
- state[1]((x) => x.bind(null));
22
- }));
23
- return state[0];
24
- };
25
- export {
26
- Consumer,
27
- Context2 as Context,
28
- Fragment,
29
- Model,
30
- Observable,
31
- Provider,
32
- createElement,
33
- Model2 as default,
34
- get,
35
- has,
36
- ref,
37
- set,
38
- use
39
- };
40
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\nimport { Context } from './context';\n\nPragma.useContext = () => Context.use();\n\nPragma.useLifecycle = (callback) => useEffect(() => callback(), []);\n\nPragma.useFactory = (factory) => {\n const state = useState(() => factory(() => {\n state[1](x => x.bind(null) as any);\n }));\n\n return state[0];\n}\n\nexport {\n Observable,\n Model, Model as default,\n get, use, ref, set, has\n} from '@expressive/mvc';\n\nexport { Consumer, Context, Provider } from './context';\nexport { Fragment, createElement } from 'react';\nexport { type Pragma };\n"],"mappings":";AAAA,SAAS,WAAW,gBAAgB;AAEpC,SAAS,cAAc;AACvB,SAAS,eAAe;AAcxB;AAAA,EACE;AAAA,EACA;AAAA,EAAgB,SAATA;AAAA,EACP;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,OACf;AAEP,SAAS,UAAU,WAAAC,UAAS,gBAAgB;AAC5C,SAAS,UAAU,qBAAqB;AAnBxC,OAAO,aAAa,MAAM,QAAQ,IAAI;AAEtC,OAAO,eAAe,CAAC,aAAa,UAAU,MAAM,SAAS,GAAG,CAAC,CAAC;AAElE,OAAO,aAAa,CAAC,YAAY;AAC/B,QAAM,QAAQ,SAAS,MAAM,QAAQ,MAAM;AACzC,UAAM,CAAC,EAAE,OAAK,EAAE,KAAK,IAAI,CAAQ;AAAA,EACnC,CAAC,CAAC;AAEF,SAAO,MAAM,CAAC;AAChB;","names":["Model","Context"]}
@@ -1,10 +0,0 @@
1
- // src/jsx-dev-runtime.ts
2
- import Runtime from "react/jsx-dev-runtime";
3
- import { compat } from "./jsx-runtime";
4
- import { Fragment } from "react";
5
- var jsxDEV = compat.bind(Runtime.jsxDEV);
6
- export {
7
- Fragment,
8
- jsxDEV
9
- };
10
- //# sourceMappingURL=jsx-dev-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/jsx-dev-runtime.ts"],"sourcesContent":["import Runtime from 'react/jsx-dev-runtime';\n\nimport { compat } from './jsx-runtime';\n\nexport const jsxDEV = compat.bind(Runtime.jsxDEV);\n\nexport { type JSX } from './jsx-runtime';\nexport { Fragment } from \"react\";\n"],"mappings":";AAAA,OAAO,aAAa;AAEpB,SAAS,cAAc;AAKvB,SAAS,gBAAgB;AAHlB,IAAM,SAAS,OAAO,KAAK,QAAQ,MAAM;","names":[]}
@@ -1,35 +0,0 @@
1
- // src/jsx-runtime.ts
2
- import { METHOD, Model } from "@expressive/mvc";
3
- import Runtime from "react/jsx-runtime";
4
- import { createProvider } from "./context";
5
- import { Fragment } from "react";
6
- function MC({ is, ...props }) {
7
- const model = this.use((self) => {
8
- self.set(props);
9
- if (is)
10
- is(self);
11
- });
12
- model.set(props);
13
- const render = METHOD.get(model.render) || props.render || model.render;
14
- const children = render ? render.call(model, props, model) : props.children;
15
- return createProvider(model, children, props.fallback || model.fallback, String(model));
16
- }
17
- var RENDER = /* @__PURE__ */ new WeakMap();
18
- function compat(type, ...args) {
19
- if (typeof type == "function") {
20
- if (RENDER.has(type))
21
- type = RENDER.get(type);
22
- else if (typeof type == "function")
23
- RENDER.set(type, type = type.prototype instanceof Model ? MC.bind(type) : type);
24
- }
25
- return this(type, ...args);
26
- }
27
- var jsx = compat.bind(Runtime.jsx);
28
- var jsxs = compat.bind(Runtime.jsxs);
29
- export {
30
- Fragment,
31
- compat,
32
- jsx,
33
- jsxs
34
- };
35
- //# sourceMappingURL=jsx-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/jsx-runtime.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\";"],"mappings":";AAAA,SAAS,QAAQ,aAAa;AAE9B,OAAO,aAAa;AAEpB,SAAS,sBAAsB;AAkG/B,SAAS,gBAAgB;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,OAAO,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,QACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,QAAQ,IAAI;","names":[]}
package/dist/index.d.ts DELETED
@@ -1,46 +0,0 @@
1
- export { Pragma } from './adapter';
2
- import Model__default, { Context } from '@expressive/mvc';
3
- export { Context, Model, Observable, Model as default, get, has, ref, set, use } from '@expressive/mvc';
4
- import * as React from 'react';
5
- import { ReactNode } from 'react';
6
- export { Fragment, createElement } from 'react';
7
-
8
- declare module '@expressive/mvc' {
9
- namespace Context {
10
- function use(create?: true): Context;
11
- function use(create: boolean): Context | null | undefined;
12
- }
13
- }
14
- declare namespace Consumer {
15
- type Props<T extends Model__default> = {
16
- /** Type of controller to fetch from context. */
17
- for: Model__default.Type<T>;
18
- /**
19
- * Render function, will receive instance of desired controller.
20
- *
21
- * Called every render of parent component.
22
- * Similar to `Model.get()`, updates to properties accessed in
23
- * this function will cause a refresh when they change.
24
- */
25
- children: (value: T) => ReactNode | void;
26
- };
27
- }
28
- declare function Consumer<T extends Model__default>(props: Consumer.Props<T>): string | number | bigint | boolean | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal | null;
29
- declare namespace Provider {
30
- interface Props<T extends Model__default> {
31
- /** Model or group of Models to provide to descendant Consumers. */
32
- for: Context.Accept<T>;
33
- forEach?: Context.Expect<T>;
34
- children?: ReactNode;
35
- /** A fallback react tree to show when suspended. */
36
- fallback?: ReactNode;
37
- /**
38
- * A name for this Suspense boundary for instrumentation purposes.
39
- * The name will help identify this boundary in React DevTools.
40
- */
41
- name?: string | undefined;
42
- }
43
- }
44
- declare function Provider<T extends Model__default>(props: Provider.Props<T>): React.FunctionComponentElement<React.ProviderProps<Context>> | React.FunctionComponentElement<React.SuspenseProps>;
45
-
46
- export { Consumer, Provider };
package/dist/index.js DELETED
@@ -1,111 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
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
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- Consumer: () => Consumer,
34
- Context: () => import_mvc.Context,
35
- Fragment: () => import_react3.Fragment,
36
- Model: () => import_mvc2.Model,
37
- Observable: () => import_mvc2.Observable,
38
- Provider: () => Provider,
39
- createElement: () => import_react3.createElement,
40
- default: () => import_mvc2.Model,
41
- get: () => import_mvc2.get,
42
- has: () => import_mvc2.has,
43
- ref: () => import_mvc2.ref,
44
- set: () => import_mvc2.set,
45
- use: () => import_mvc2.use
46
- });
47
- module.exports = __toCommonJS(src_exports);
48
- var import_react2 = require("react");
49
- var import_adapter = require("./adapter");
50
-
51
- // src/context.ts
52
- var import_mvc = __toESM(require("@expressive/mvc"));
53
- var import_react = require("react");
54
- var Lookup = (0, import_react.createContext)(new import_mvc.Context());
55
- import_mvc.Context.use = (create) => {
56
- const ambient = (0, import_react.useContext)(Lookup);
57
- return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
58
- };
59
- function Consumer(props) {
60
- return props.for.get((i) => props.children(i));
61
- }
62
- function Provider(props) {
63
- const context = import_mvc.Context.use(true);
64
- (0, import_react.useEffect)(() => () => context.pop(), [context]);
65
- context.include(props.for, (model) => {
66
- if (props.forEach) {
67
- const cleanup = props.forEach(model);
68
- if (cleanup)
69
- model.set(cleanup, null);
70
- }
71
- });
72
- return createProvider(context, props.children, props.fallback, props.name);
73
- }
74
- function createProvider(context, children, fallback, name) {
75
- if (context instanceof import_mvc.default)
76
- context = import_mvc.Context.get(context);
77
- const element = (0, import_react.createElement)(Lookup.Provider, {
78
- key: context.id,
79
- value: context,
80
- children
81
- });
82
- return fallback !== void 0 ? (0, import_react.createElement)(import_react.Suspense, { fallback, name }, element) : element;
83
- }
84
-
85
- // src/index.ts
86
- var import_mvc2 = require("@expressive/mvc");
87
- var import_react3 = require("react");
88
- import_adapter.Pragma.useContext = () => import_mvc.Context.use();
89
- import_adapter.Pragma.useLifecycle = (callback) => (0, import_react2.useEffect)(() => callback(), []);
90
- import_adapter.Pragma.useFactory = (factory) => {
91
- const state = (0, import_react2.useState)(() => factory(() => {
92
- state[1]((x) => x.bind(null));
93
- }));
94
- return state[0];
95
- };
96
- // Annotate the CommonJS export names for ESM import in node:
97
- 0 && (module.exports = {
98
- Consumer,
99
- Context,
100
- Fragment,
101
- Model,
102
- Observable,
103
- Provider,
104
- createElement,
105
- get,
106
- has,
107
- ref,
108
- set,
109
- use
110
- });
111
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/context.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\nimport { Context } from './context';\n\nPragma.useContext = () => Context.use();\n\nPragma.useLifecycle = (callback) => useEffect(() => callback(), []);\n\nPragma.useFactory = (factory) => {\n const state = useState(() => factory(() => {\n state[1](x => x.bind(null) as any);\n }));\n\n return state[0];\n}\n\nexport {\n Observable,\n Model, Model as default,\n get, use, ref, set, has\n} from '@expressive/mvc';\n\nexport { Consumer, Context, Provider } from './context';\nexport { Fragment, createElement } from 'react';\nexport { type Pragma };\n","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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAoC;AAEpC,qBAAuB;;;ACFvB,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;AAkBA,SAAS,SAA0B,OAAyB;AAC1D,SAAO,MAAM,IAAI,IAAI,OAAK,MAAM,SAAS,CAAC,CAAC;AAC7C;AAqBA,SAAS,SAA0B,OAAyB;AAC1D,QAAM,UAAU,mBAAQ,IAAI,IAAI;AAEhC,8BAAU,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,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;;;AD7EA,IAAAC,cAIO;AAGP,IAAAC,gBAAwC;AAnBxC,sBAAO,aAAa,MAAM,mBAAQ,IAAI;AAEtC,sBAAO,eAAe,CAAC,iBAAa,yBAAU,MAAM,SAAS,GAAG,CAAC,CAAC;AAElE,sBAAO,aAAa,CAAC,YAAY;AAC/B,QAAM,YAAQ,wBAAS,MAAM,QAAQ,MAAM;AACzC,UAAM,CAAC,EAAE,OAAK,EAAE,KAAK,IAAI,CAAQ;AAAA,EACnC,CAAC,CAAC;AAEF,SAAO,MAAM,CAAC;AAChB;","names":["import_react","Model","import_mvc","import_react"]}
@@ -1,8 +0,0 @@
1
- import * as Model from '@expressive/mvc';
2
- import * as React from 'react';
3
- export { Fragment } from 'react';
4
- export { JSX } from './jsx-runtime';
5
-
6
- declare const jsxDEV: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements> | Model.Model.Init<Model.Model>, ...args: any[]) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
7
-
8
- export { jsxDEV };
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
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
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/jsx-dev-runtime.ts
31
- var jsx_dev_runtime_exports = {};
32
- __export(jsx_dev_runtime_exports, {
33
- Fragment: () => import_react.Fragment,
34
- jsxDEV: () => jsxDEV
35
- });
36
- module.exports = __toCommonJS(jsx_dev_runtime_exports);
37
- var import_jsx_dev_runtime = __toESM(require("react/jsx-dev-runtime"));
38
- var import_jsx_runtime = require("./jsx-runtime");
39
- var import_react = require("react");
40
- var jsxDEV = import_jsx_runtime.compat.bind(import_jsx_dev_runtime.default.jsxDEV);
41
- // Annotate the CommonJS export names for ESM import in node:
42
- 0 && (module.exports = {
43
- Fragment,
44
- jsxDEV
45
- });
46
- //# sourceMappingURL=jsx-dev-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/jsx-dev-runtime.ts"],"sourcesContent":["import Runtime from 'react/jsx-dev-runtime';\n\nimport { compat } from './jsx-runtime';\n\nexport const jsxDEV = compat.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,yBAAuB;AAKvB,mBAAyB;AAHlB,IAAM,SAAS,0BAAO,KAAK,uBAAAA,QAAQ,MAAM;","names":["Runtime"]}
@@ -1,57 +0,0 @@
1
- import { Model } from '@expressive/mvc';
2
- import React__default from 'react';
3
- export { Fragment } from 'react';
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
- declare namespace JSX {
34
- type ElementType = Model.Type<Model.Compat> | React__default.JSX.ElementType | ((props: {}, ref?: any) => void);
35
- type LibraryManagedAttributes<C, P> = C extends new (...args: any[]) => {
36
- props: infer U;
37
- } ? U : C extends Model.Type<infer U> ? Model.Props<U> : React__default.JSX.LibraryManagedAttributes<C, P>;
38
- interface Element extends React__default.JSX.Element {
39
- }
40
- interface ElementClass extends React__default.JSX.ElementClass {
41
- }
42
- interface ElementAttributesProperty {
43
- }
44
- interface ElementChildrenAttribute extends React__default.JSX.ElementChildrenAttribute {
45
- }
46
- interface IntrinsicAttributes extends React__default.JSX.IntrinsicAttributes {
47
- }
48
- interface IntrinsicClassAttributes<T> extends React__default.JSX.IntrinsicClassAttributes<T> {
49
- }
50
- interface IntrinsicElements extends React__default.JSX.IntrinsicElements {
51
- }
52
- }
53
- declare function compat(this: (type: React__default.ElementType, ...args: any[]) => React__default.ReactElement, type: React__default.ElementType | Model.Init, ...args: any[]): React__default.ReactElement;
54
- declare const jsx: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>>;
55
- declare const jsxs: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<unknown, string | React__default.JSXElementConstructor<any>>;
56
-
57
- export { JSX, compat, jsx, jsxs };
@@ -1,93 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
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
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/jsx-runtime.ts
31
- var jsx_runtime_exports = {};
32
- __export(jsx_runtime_exports, {
33
- Fragment: () => import_react2.Fragment,
34
- compat: () => compat,
35
- jsx: () => jsx,
36
- jsxs: () => jsxs
37
- });
38
- module.exports = __toCommonJS(jsx_runtime_exports);
39
- var import_mvc2 = require("@expressive/mvc");
40
- var import_jsx_runtime = __toESM(require("react/jsx-runtime"));
41
-
42
- // src/context.ts
43
- var import_mvc = __toESM(require("@expressive/mvc"));
44
- var import_react = require("react");
45
- var Lookup = (0, import_react.createContext)(new import_mvc.Context());
46
- import_mvc.Context.use = (create) => {
47
- const ambient = (0, import_react.useContext)(Lookup);
48
- return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
49
- };
50
- function createProvider(context, children, fallback, name) {
51
- if (context instanceof import_mvc.default)
52
- context = import_mvc.Context.get(context);
53
- const element = (0, import_react.createElement)(Lookup.Provider, {
54
- key: context.id,
55
- value: context,
56
- children
57
- });
58
- return fallback !== void 0 ? (0, import_react.createElement)(import_react.Suspense, { fallback, name }, element) : element;
59
- }
60
-
61
- // src/jsx-runtime.ts
62
- var import_react2 = require("react");
63
- function MC({ is, ...props }) {
64
- const model = this.use((self) => {
65
- self.set(props);
66
- if (is)
67
- is(self);
68
- });
69
- model.set(props);
70
- const render = import_mvc2.METHOD.get(model.render) || props.render || model.render;
71
- const children = render ? render.call(model, props, model) : props.children;
72
- return createProvider(model, children, props.fallback || model.fallback, String(model));
73
- }
74
- var RENDER = /* @__PURE__ */ new WeakMap();
75
- function compat(type, ...args) {
76
- if (typeof type == "function") {
77
- if (RENDER.has(type))
78
- type = RENDER.get(type);
79
- else if (typeof type == "function")
80
- RENDER.set(type, type = type.prototype instanceof import_mvc2.Model ? MC.bind(type) : type);
81
- }
82
- return this(type, ...args);
83
- }
84
- var jsx = compat.bind(import_jsx_runtime.default.jsx);
85
- var jsxs = compat.bind(import_jsx_runtime.default.jsxs);
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- Fragment,
89
- compat,
90
- jsx,
91
- jsxs
92
- });
93
- //# sourceMappingURL=jsx-runtime.js.map
@@ -1 +0,0 @@
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"]}