@expressive/react 0.72.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.72.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,15 +64,16 @@
60
64
  }
61
65
  },
62
66
  "devDependencies": {
63
- "@testing-library/jest-dom": "^6.8.0",
64
67
  "@testing-library/react": "^16.3.0",
65
68
  "@types/react": "^19",
66
69
  "@types/react-dom": "^19",
67
- "jest": "^27.5.1",
70
+ "@vitest/browser": "^4.0.18",
68
71
  "react": "^19",
69
72
  "react-dom": "^19",
70
- "tsup": "^8.0.2"
73
+ "tsdown": "^0.20.1",
74
+ "tsup": "^8.0.2",
75
+ "vitest": "^4.0.18"
71
76
  },
72
- "version": "0.72.0",
73
- "gitHead": "3661a47db05bd7469cda51b63beed29e76a422cd"
77
+ "version": "0.72.1-canary.14+f89c0af8",
78
+ "gitHead": "f89c0af893d0f5ae24f28f42ef5c1af1d37be9bf"
74
79
  }
package/dist/adapter.d.ts DELETED
@@ -1,105 +0,0 @@
1
- import { FunctionComponent, ReactNode } from 'react';
2
-
3
- declare module '@expressive/mvc' {
4
- namespace State {
5
- type HasProps<T extends State> = {
6
- [K in Exclude<keyof T, keyof State>]?: T[K];
7
- };
8
- type ComponentProps<T extends State> = HasProps<T> & {
9
- /**
10
- * Callback for newly created instance. Only called once.
11
- * @returns Callback to run when instance is destroyed.
12
- */
13
- is?: (instance: T) => void;
14
- /**
15
- * A fallback react tree to show when suspended.
16
- * If not provided, `fallback` property of the State will be used.
17
- */
18
- fallback?: React.ReactNode;
19
- };
20
- type Props<T extends State> = T extends {
21
- render(props: infer P, self: any): any;
22
- } ? ComponentProps<T> & Omit<P, keyof AsComponent> : ComponentProps<T> & {
23
- children?: React.ReactNode;
24
- };
25
- /**
26
- * Props which will not conflict with a State's use as a Component.
27
- *
28
- * Built-in properties must be optional, as they will always be omitted.
29
- */
30
- type RenderProps<T extends State> = HasProps<T> & {
31
- is?: never;
32
- get?: never;
33
- set?: never;
34
- };
35
- /** State which is not incompatable as Component in React. */
36
- interface AsComponent extends State.Valid {
37
- render?(props: RenderProps<this>, self: this): React.ReactNode;
38
- fallback?: React.ReactNode;
39
- }
40
- interface FC<T extends State, P extends State.Assign<T>> extends FunctionComponent<P & State.Props<T>> {
41
- displayName?: string;
42
- State: State.Extends<T>;
43
- }
44
- function as<T extends State, P extends State.Assign<T>>(this: State.New<T>, render: (props: P, self: T) => ReactNode): FC<T, P>;
45
- }
46
- }
47
-
48
- declare module '@expressive/mvc' {
49
- namespace State {
50
- interface Valid {
51
- use?(...props: any[]): Promise<void> | void;
52
- }
53
- type UseArgs<T extends State> = T extends {
54
- use(...props: infer P): any;
55
- } ? P : State.Args<T>;
56
- function use<T extends State>(this: New<T>, ...args: UseArgs<T>): T;
57
- }
58
- }
59
-
60
- /** Type may not be undefined - instead will be null. */
61
- type NoVoid<T> = T extends undefined | void ? null : T;
62
- type ForceRefresh = {
63
- /** Request a refresh for current component. */
64
- (): void;
65
- /**
66
- * Request a refresh and again after promise either resolves or rejects.
67
- *
68
- * @param waitFor Promise to wait for.
69
- * @returns Promise which resolves, after refresh, to same value as `waitFor`.
70
- */
71
- <T = void>(waitFor: Promise<T>): Promise<T>;
72
- /**
73
- * Request refresh before and after async function.
74
- * A refresh will occur both before and after the given function.
75
- *
76
- * **Note:** Any actions performed before first `await` will occur prior to refresh.
77
- *
78
- * @param invoke Async function to invoke.
79
- * @returns Promise which resolves returned value after refresh.
80
- */
81
- <T = void>(invoke: () => Promise<T>): Promise<T>;
82
- };
83
- declare module '@expressive/mvc' {
84
- namespace State {
85
- type GetFactory<T extends State, R> = (this: T, current: T, refresh: ForceRefresh) => R;
86
- type GetEffect<T extends State> = (this: T, current: T, refresh: ForceRefresh) => null;
87
- /** Fetch instance of this class from context. */
88
- function get<T extends State>(this: Extends<T>): T;
89
- /** Fetch instance of this class optionally. */
90
- function get<T extends State>(this: Extends<T>, required: false): T | undefined;
91
- /** Fetch instance of this class from context. */
92
- function get<T extends State>(this: Extends<T>, requireValues: true): Required<T>;
93
- function get<T extends State, R>(this: Extends<T>, factory: GetFactory<T, Promise<R> | R>): NoVoid<R>;
94
- function get<T extends State>(this: Extends<T>, factory: GetEffect<T>): null;
95
- }
96
- }
97
-
98
- declare namespace Pragma { }
99
- declare const Pragma: {
100
- useState<S>(initial: () => S): [S, (next: (previous: S) => S) => void];
101
- useEffect(effect: () => () => void, deps?: any[]): void;
102
- createElement(type: any, props?: any, ...children: any[]): any;
103
- };
104
-
105
- export { Pragma };
package/dist/adapter.js DELETED
@@ -1,207 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/adapter.ts
21
- var adapter_exports = {};
22
- __export(adapter_exports, {
23
- Pragma: () => Pragma4
24
- });
25
- module.exports = __toCommonJS(adapter_exports);
26
-
27
- // src/state.as.ts
28
- var import_mvc2 = require("@expressive/mvc");
29
-
30
- // src/context.ts
31
- var import_mvc = require("@expressive/mvc");
32
- var import_react = require("react");
33
- var Layers = (0, import_react.createContext)(new import_mvc.Context());
34
- import_mvc.Context.use = (create) => {
35
- const ambient = (0, import_react.useContext)(Layers);
36
- return create ? (0, import_react.useMemo)(() => ambient.push(), [ambient]) : ambient;
37
- };
38
- function provide(context, children, fallback, name) {
39
- if (fallback !== void 0)
40
- children = (0, import_react.createElement)(import_react.Suspense, { fallback, name }, children);
41
- return (0, import_react.createElement)(Layers.Provider, {
42
- key: context.id,
43
- value: context,
44
- children
45
- });
46
- }
47
-
48
- // src/state.as.ts
49
- var import_adapter = require("./adapter");
50
- import_mvc2.State.as = function(render) {
51
- const FC = Render.bind(this, { render });
52
- return Object.assign(FC, {
53
- displayName: this.name,
54
- State: this
55
- });
56
- };
57
- function Render(props, props2) {
58
- const { is, ...rest } = { ...props, ...props2 };
59
- const ambient = import_mvc2.Context.use();
60
- const state = import_adapter.Pragma.useState(() => {
61
- const instance = this.new(rest, is && ((x) => void is(x)));
62
- const context = ambient.push(instance);
63
- let ready;
64
- let active;
65
- (0, import_mvc2.watch)(instance, (current) => {
66
- active = current;
67
- if (ready) state[1]((x) => x.bind(null));
68
- });
69
- function didMount() {
70
- ready = true;
71
- return () => {
72
- context.pop();
73
- instance.set(null);
74
- };
75
- }
76
- function Render2(props3) {
77
- const render = import_mvc2.METHOD.get(active.render) || props3.render || active.render;
78
- return render ? render.call(active, props3, active) : props3.children;
79
- }
80
- return (props3) => {
81
- ready = false;
82
- import_adapter.Pragma.useEffect(didMount, []);
83
- Promise.resolve(instance.set(props3)).finally(() => {
84
- ready = true;
85
- });
86
- return provide(
87
- context,
88
- import_adapter.Pragma.createElement(Render2, props3),
89
- props3.fallback || active.fallback,
90
- String(instance)
91
- );
92
- };
93
- });
94
- return state[0](rest);
95
- }
96
-
97
- // src/state.use.ts
98
- var import_mvc3 = require("@expressive/mvc");
99
- var import_adapter2 = require("./adapter");
100
- import_mvc3.State.use = function(...args) {
101
- const ambient = import_mvc3.Context.use();
102
- const state = import_adapter2.Pragma.useState(() => {
103
- let ready;
104
- let active;
105
- const instance = this.new(
106
- (x) => x.use ? Promise.resolve(x.use(...args)) : args
107
- );
108
- const context = ambient.push(instance);
109
- (0, import_mvc3.watch)(instance, (current) => {
110
- active = current;
111
- if (ready) state[1]((x) => x.bind(null));
112
- });
113
- function didMount() {
114
- ready = true;
115
- return () => {
116
- context.pop();
117
- instance.set(null);
118
- };
119
- }
120
- return (...args2) => {
121
- import_adapter2.Pragma.useEffect(didMount, []);
122
- if (ready) {
123
- ready = false;
124
- Promise.resolve(
125
- instance.use ? instance.use(...args2) : Promise.all(
126
- args2.flat().map(
127
- (arg) => typeof arg == "object" && instance.set(arg)
128
- )
129
- )
130
- ).finally(() => {
131
- ready = true;
132
- });
133
- }
134
- return active;
135
- };
136
- });
137
- return state[0](...args);
138
- };
139
-
140
- // src/state.get.ts
141
- var import_mvc4 = require("@expressive/mvc");
142
- var import_adapter3 = require("./adapter");
143
- import_mvc4.State.get = function(argument) {
144
- const context = import_mvc4.Context.use();
145
- const state = import_adapter3.Pragma.useState(() => {
146
- const instance = context.get(this);
147
- if (!instance)
148
- if (argument === false) return () => void 0;
149
- else throw new Error(`Could not find ${this} in context.`);
150
- let ready;
151
- let value;
152
- function render() {
153
- state[1]((x) => x.bind(null));
154
- }
155
- function refresh(action) {
156
- if (typeof action == "function") action = action();
157
- render();
158
- if (action) return action.finally(render);
159
- }
160
- function onMount() {
161
- ready = true;
162
- return unwatch;
163
- }
164
- const unwatch = (0, import_mvc4.watch)(
165
- instance,
166
- (current) => {
167
- if (typeof argument === "function") {
168
- const next = argument.call(current, current, refresh);
169
- if (next === value) return;
170
- value = next;
171
- } else value = current;
172
- if (ready) render();
173
- },
174
- argument === true
175
- );
176
- if (value instanceof Promise) {
177
- let error;
178
- unwatch();
179
- value.then(
180
- (x) => value = x,
181
- (e) => error = e
182
- ).finally(render);
183
- value = null;
184
- return () => {
185
- if (error) throw error;
186
- return value === void 0 ? null : value;
187
- };
188
- }
189
- if (value === null) {
190
- unwatch();
191
- return () => null;
192
- }
193
- return () => {
194
- import_adapter3.Pragma.useEffect(onMount, []);
195
- return value === void 0 ? null : value;
196
- };
197
- });
198
- return state[0]();
199
- };
200
-
201
- // src/adapter.ts
202
- var Pragma4 = {};
203
- // Annotate the CommonJS export names for ESM import in node:
204
- 0 && (module.exports = {
205
- Pragma
206
- });
207
- //# sourceMappingURL=adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/adapter.ts","../src/state.as.ts","../src/context.ts","../src/state.use.ts","../src/state.get.ts"],"sourcesContent":["namespace Pragma {}\n\nconst Pragma = {} as {\n useState<S>(initial: () => S): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => () => void, deps?: any[]): void;\n createElement(type: any, props?: any, ...children: any[]): any;\n};\n\nexport { Pragma };\n\nimport './state.as';\nimport './state.use';\nimport './state.get';\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","import { State, Context, watch } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace State {\n interface Valid {\n use?(...props: any[]): Promise<void> | void;\n }\n\n type UseArgs<T extends State> = T extends {\n use(...props: infer P): any;\n }\n ? P\n : State.Args<T>;\n\n function use<T extends State>(this: New<T>, ...args: UseArgs<T>): T;\n }\n}\n\nState.use = function <T extends State.Valid>(\n this: State.New<T>,\n ...args: any[]\n) {\n const ambient = Context.use();\n const state = Pragma.useState(() => {\n let ready: boolean | undefined;\n let active: T;\n\n const instance = this.new((x) =>\n x.use ? Promise.resolve(x.use(...args)) : args\n );\n const context = ambient.push(instance);\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 return (...args: State.Args<T>) => {\n Pragma.useEffect(didMount, []);\n\n if (ready) {\n ready = false;\n\n Promise.resolve(\n instance.use\n ? instance.use(...args)\n : Promise.all(\n args\n .flat()\n .map(\n (arg) =>\n typeof arg == 'object' &&\n instance.set(arg as State.Assign<T>)\n )\n )\n ).finally(() => {\n ready = true;\n });\n }\n\n return active;\n };\n });\n\n return state[0](...args);\n};\n","import { Context, watch, State } 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 State {\n type GetFactory<T extends State, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends State> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => null;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(this: Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends State>(\n this: Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(\n this: Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends State, R>(\n this: Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n // TODO: eagerly match this so any nulls are caught - would prevent updates.\n function get<T extends State>(\n this: Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nState.get = function <T extends State, R>(\n this: State.Extends<T>,\n argument?: boolean | State.GetFactory<T, unknown>\n) {\n const context = Context.use();\n const state = Pragma.useState(() => {\n const instance = context.get(this);\n\n if (!instance)\n if (argument === false) return () => undefined;\n else throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n function render() {\n state[1]((x) => x.bind(null));\n }\n\n function refresh<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if (typeof action == 'function') action = action();\n\n render();\n\n if (action) return action.finally(render);\n }\n\n function onMount() {\n ready = true;\n return unwatch;\n }\n\n const unwatch = watch(\n instance,\n (current) => {\n if (typeof argument === 'function') {\n const next = argument.call(current, current, refresh);\n\n if (next === value) return;\n\n value = next;\n } else value = current;\n\n if (ready) render();\n },\n argument === true\n );\n\n if (value instanceof Promise) {\n let error: Error | undefined;\n\n unwatch();\n\n value\n .then(\n (x) => (value = x),\n (e) => (error = e)\n )\n .finally(render);\n\n value = null;\n\n return () => {\n if (error) throw error;\n\n return value === undefined ? null : value;\n };\n }\n\n if (value === null) {\n unwatch();\n return () => null;\n }\n\n return () => {\n Pragma.useEffect(onMount, []);\n return value === undefined ? null : value;\n };\n });\n\n return state[0]() as R;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gBAAAA;AAAA;AAAA;;;ACAA,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,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./chunk-UIHA4AT6.js";
2
- import "./chunk-4MR23TOU.js";
3
-
4
- // src/state.use.ts
5
- import { State, Context, watch } from "@expressive/mvc";
6
- import { Pragma } from "./adapter";
7
- State.use = function(...args) {
8
- const ambient = Context.use();
9
- const state = Pragma.useState(() => {
10
- let ready;
11
- let active;
12
- const instance = this.new(
13
- (x) => x.use ? Promise.resolve(x.use(...args)) : args
14
- );
15
- const context = ambient.push(instance);
16
- watch(instance, (current) => {
17
- active = current;
18
- if (ready) state[1]((x) => x.bind(null));
19
- });
20
- function didMount() {
21
- ready = true;
22
- return () => {
23
- context.pop();
24
- instance.set(null);
25
- };
26
- }
27
- return (...args2) => {
28
- Pragma.useEffect(didMount, []);
29
- if (ready) {
30
- ready = false;
31
- Promise.resolve(
32
- instance.use ? instance.use(...args2) : Promise.all(
33
- args2.flat().map(
34
- (arg) => typeof arg == "object" && instance.set(arg)
35
- )
36
- )
37
- ).finally(() => {
38
- ready = true;
39
- });
40
- }
41
- return active;
42
- };
43
- });
44
- return state[0](...args);
45
- };
46
-
47
- // src/state.get.ts
48
- import { Context as Context2, watch as watch2, State as State2 } from "@expressive/mvc";
49
- import { Pragma as Pragma2 } from "./adapter";
50
- State2.get = function(argument) {
51
- const context = Context2.use();
52
- const state = Pragma2.useState(() => {
53
- const instance = context.get(this);
54
- if (!instance)
55
- if (argument === false) return () => void 0;
56
- else throw new Error(`Could not find ${this} in context.`);
57
- let ready;
58
- let value;
59
- function render() {
60
- state[1]((x) => x.bind(null));
61
- }
62
- function refresh(action) {
63
- if (typeof action == "function") action = action();
64
- render();
65
- if (action) return action.finally(render);
66
- }
67
- function onMount() {
68
- ready = true;
69
- return unwatch;
70
- }
71
- const unwatch = watch2(
72
- instance,
73
- (current) => {
74
- if (typeof argument === "function") {
75
- const next = argument.call(current, current, refresh);
76
- if (next === value) return;
77
- value = next;
78
- } else value = current;
79
- if (ready) render();
80
- },
81
- argument === true
82
- );
83
- if (value instanceof Promise) {
84
- let error;
85
- unwatch();
86
- value.then(
87
- (x) => value = x,
88
- (e) => error = e
89
- ).finally(render);
90
- value = null;
91
- return () => {
92
- if (error) throw error;
93
- return value === void 0 ? null : value;
94
- };
95
- }
96
- if (value === null) {
97
- unwatch();
98
- return () => null;
99
- }
100
- return () => {
101
- Pragma2.useEffect(onMount, []);
102
- return value === void 0 ? null : value;
103
- };
104
- });
105
- return state[0]();
106
- };
107
-
108
- // src/adapter.ts
109
- var Pragma3 = {};
110
- export {
111
- Pragma3 as Pragma
112
- };
113
- //# sourceMappingURL=adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/state.use.ts","../../src/state.get.ts","../../src/adapter.ts"],"sourcesContent":["import { State, Context, watch } from '@expressive/mvc';\n\nimport { Pragma } from './adapter';\n\ndeclare module '@expressive/mvc' {\n namespace State {\n interface Valid {\n use?(...props: any[]): Promise<void> | void;\n }\n\n type UseArgs<T extends State> = T extends {\n use(...props: infer P): any;\n }\n ? P\n : State.Args<T>;\n\n function use<T extends State>(this: New<T>, ...args: UseArgs<T>): T;\n }\n}\n\nState.use = function <T extends State.Valid>(\n this: State.New<T>,\n ...args: any[]\n) {\n const ambient = Context.use();\n const state = Pragma.useState(() => {\n let ready: boolean | undefined;\n let active: T;\n\n const instance = this.new((x) =>\n x.use ? Promise.resolve(x.use(...args)) : args\n );\n const context = ambient.push(instance);\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 return (...args: State.Args<T>) => {\n Pragma.useEffect(didMount, []);\n\n if (ready) {\n ready = false;\n\n Promise.resolve(\n instance.use\n ? instance.use(...args)\n : Promise.all(\n args\n .flat()\n .map(\n (arg) =>\n typeof arg == 'object' &&\n instance.set(arg as State.Assign<T>)\n )\n )\n ).finally(() => {\n ready = true;\n });\n }\n\n return active;\n };\n });\n\n return state[0](...args);\n};\n","import { Context, watch, State } 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 State {\n type GetFactory<T extends State, R> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => R;\n\n type GetEffect<T extends State> = (\n this: T,\n current: T,\n refresh: ForceRefresh\n ) => null;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(this: Extends<T>): T;\n\n /** Fetch instance of this class optionally. */\n function get<T extends State>(\n this: Extends<T>,\n required: false\n ): T | undefined;\n\n /** Fetch instance of this class from context. */\n function get<T extends State>(\n this: Extends<T>,\n requireValues: true\n ): Required<T>;\n\n function get<T extends State, R>(\n this: Extends<T>,\n factory: GetFactory<T, Promise<R> | R>\n ): NoVoid<R>;\n\n // TODO: eagerly match this so any nulls are caught - would prevent updates.\n function get<T extends State>(\n this: Extends<T>,\n factory: GetEffect<T>\n ): null;\n }\n}\n\nState.get = function <T extends State, R>(\n this: State.Extends<T>,\n argument?: boolean | State.GetFactory<T, unknown>\n) {\n const context = Context.use();\n const state = Pragma.useState(() => {\n const instance = context.get(this);\n\n if (!instance)\n if (argument === false) return () => undefined;\n else throw new Error(`Could not find ${this} in context.`);\n\n let ready: boolean | undefined;\n let value: any;\n\n function render() {\n state[1]((x) => x.bind(null));\n }\n\n function refresh<T>(action?: Promise<T> | (() => Promise<T>)): any {\n if (typeof action == 'function') action = action();\n\n render();\n\n if (action) return action.finally(render);\n }\n\n function onMount() {\n ready = true;\n return unwatch;\n }\n\n const unwatch = watch(\n instance,\n (current) => {\n if (typeof argument === 'function') {\n const next = argument.call(current, current, refresh);\n\n if (next === value) return;\n\n value = next;\n } else value = current;\n\n if (ready) render();\n },\n argument === true\n );\n\n if (value instanceof Promise) {\n let error: Error | undefined;\n\n unwatch();\n\n value\n .then(\n (x) => (value = x),\n (e) => (error = e)\n )\n .finally(render);\n\n value = null;\n\n return () => {\n if (error) throw error;\n\n return value === undefined ? null : value;\n };\n }\n\n if (value === null) {\n unwatch();\n return () => null;\n }\n\n return () => {\n Pragma.useEffect(onMount, []);\n return value === undefined ? null : value;\n };\n });\n\n return state[0]() as R;\n};\n","namespace Pragma {}\n\nconst Pragma = {} as {\n useState<S>(initial: () => S): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => () => void, deps?: any[]): void;\n createElement(type: any, props?: any, ...children: any[]): any;\n};\n\nexport { Pragma };\n\nimport './state.as';\nimport './state.use';\nimport './state.get';\n"],"mappings":";;;;AAAA,SAAS,OAAO,SAAS,aAAa;AAEtC,SAAS,cAAc;AAkBvB,MAAM,MAAM,YAEP,MACH;AACA,QAAM,UAAU,QAAQ,IAAI;AAC5B,QAAM,QAAQ,OAAO,SAAS,MAAM;AAClC,QAAI;AACJ,QAAI;AAEJ,UAAM,WAAW,KAAK;AAAA,MAAI,CAAC,MACzB,EAAE,MAAM,QAAQ,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC,IAAI;AAAA,IAC5C;AACA,UAAM,UAAU,QAAQ,KAAK,QAAQ;AAErC,UAAM,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,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AAEpB,kBAAQ;AAAA,QACV,MAAO,SAAQ;AAEf,YAAI,MAAO,QAAO;AAAA,MACpB;AAAA,MACA,aAAa;AAAA,IACf;AAEA,QAAI,iBAAiB,SAAS;AAC5B,UAAI;AAEJ,cAAQ;AAER,YACG;AAAA,QACC,CAAC,MAAO,QAAQ;AAAA,QAChB,CAAC,MAAO,QAAQ;AAAA,MAClB,EACC,QAAQ,MAAM;AAEjB,cAAQ;AAER,aAAO,MAAM;AACX,YAAI,MAAO,OAAM;AAEjB,eAAO,UAAU,SAAY,OAAO;AAAA,MACtC;AAAA,IACF;AAEA,QAAI,UAAU,MAAM;AAClB,cAAQ;AACR,aAAO,MAAM;AAAA,IACf;AAEA,WAAO,MAAM;AACX,MAAAE,QAAO,UAAU,SAAS,CAAC,CAAC;AAC5B,aAAO,UAAU,SAAY,OAAO;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO,MAAM,CAAC,EAAE;AAClB;;;ACxJA,IAAMC,UAAS,CAAC;","names":["args","Context","watch","State","Pragma","Pragma"]}
@@ -1,45 +0,0 @@
1
- // src/context.ts
2
- import { Context } from "@expressive/mvc";
3
- import {
4
- createContext,
5
- createElement,
6
- Suspense,
7
- useContext,
8
- useEffect,
9
- useMemo
10
- } from "react";
11
- var Layers = createContext(new Context());
12
- Context.use = (create) => {
13
- const ambient = useContext(Layers);
14
- return create ? useMemo(() => ambient.push(), [ambient]) : ambient;
15
- };
16
- function Consumer(props) {
17
- return props.for.get((i) => props.children(i));
18
- }
19
- function Provider(props) {
20
- const context = Context.use(true);
21
- useEffect(() => () => context.pop(), [context]);
22
- context.use(props.for, (state) => {
23
- if (props.forEach) {
24
- const cleanup = props.forEach(state);
25
- if (cleanup) state.set(cleanup, null);
26
- }
27
- });
28
- return provide(context, props.children, props.fallback, props.name);
29
- }
30
- function provide(context, children, fallback, name) {
31
- if (fallback !== void 0)
32
- children = createElement(Suspense, { fallback, name }, children);
33
- return createElement(Layers.Provider, {
34
- key: context.id,
35
- value: context,
36
- children
37
- });
38
- }
39
-
40
- export {
41
- Consumer,
42
- Provider,
43
- provide
44
- };
45
- //# sourceMappingURL=chunk-4MR23TOU.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/context.ts"],"sourcesContent":["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,SAAgB,eAAe;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,SAAS,cAAc,IAAI,QAAQ,CAAC;AASjD,QAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,UAAU,WAAW,MAAM;AAEjC,SAAO,SAAS,QAAQ,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,QAAQ,IAAI,IAAI;AAEhC,YAAU,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,eAAW,cAAc,UAAU,EAAE,UAAU,KAAK,GAAG,QAAQ;AAEjE,SAAO,cAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,58 +0,0 @@
1
- import {
2
- provide
3
- } from "./chunk-4MR23TOU.js";
4
-
5
- // src/state.as.ts
6
- import { Context, watch, METHOD, State } from "@expressive/mvc";
7
- import { Pragma } from "./adapter";
8
- State.as = function(render) {
9
- const FC = Render.bind(this, { render });
10
- return Object.assign(FC, {
11
- displayName: this.name,
12
- State: this
13
- });
14
- };
15
- function Render(props, props2) {
16
- const { is, ...rest } = { ...props, ...props2 };
17
- const ambient = Context.use();
18
- const state = Pragma.useState(() => {
19
- const instance = this.new(rest, is && ((x) => void is(x)));
20
- const context = ambient.push(instance);
21
- let ready;
22
- let active;
23
- watch(instance, (current) => {
24
- active = current;
25
- if (ready) state[1]((x) => x.bind(null));
26
- });
27
- function didMount() {
28
- ready = true;
29
- return () => {
30
- context.pop();
31
- instance.set(null);
32
- };
33
- }
34
- function Render2(props3) {
35
- const render = METHOD.get(active.render) || props3.render || active.render;
36
- return render ? render.call(active, props3, active) : props3.children;
37
- }
38
- return (props3) => {
39
- ready = false;
40
- Pragma.useEffect(didMount, []);
41
- Promise.resolve(instance.set(props3)).finally(() => {
42
- ready = true;
43
- });
44
- return provide(
45
- context,
46
- Pragma.createElement(Render2, props3),
47
- props3.fallback || active.fallback,
48
- String(instance)
49
- );
50
- };
51
- });
52
- return state[0](rest);
53
- }
54
-
55
- export {
56
- Render
57
- };
58
- //# sourceMappingURL=chunk-UIHA4AT6.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/state.as.ts"],"sourcesContent":["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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AAA,QACL;AAAA,QACA,OAAO,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;","names":["Render","props"]}
package/dist/esm/index.js DELETED
@@ -1,38 +0,0 @@
1
- import {
2
- Consumer,
3
- Provider
4
- } from "./chunk-4MR23TOU.js";
5
-
6
- // src/index.ts
7
- import {
8
- Context,
9
- Observable,
10
- State,
11
- get,
12
- use,
13
- ref,
14
- set
15
- } from "@expressive/mvc";
16
- import { createElement, useEffect, useState } from "react";
17
- import { Pragma } from "./adapter";
18
- import { Fragment, createElement as createElement2 } from "react";
19
- Pragma.useEffect = useEffect;
20
- Pragma.useState = useState;
21
- Pragma.createElement = createElement;
22
- var src_default = State;
23
- export {
24
- Consumer,
25
- Context,
26
- Fragment,
27
- Observable,
28
- Pragma,
29
- Provider,
30
- State,
31
- createElement2 as createElement,
32
- src_default as default,
33
- get,
34
- ref,
35
- set,
36
- use
37
- };
38
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.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"],"mappings":";;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,WAAW,gBAAgB;AAEnD,SAAS,cAAc;AASvB,SAAS,UAAU,iBAAAA,sBAAqB;AAPxC,OAAO,YAAY;AACnB,OAAO,WAAW;AAClB,OAAO,gBAAgB;AAEvB,IAAO,cAAQ;","names":["createElement"]}
@@ -1,10 +0,0 @@
1
- // src/jsx-dev-runtime.ts
2
- import Runtime from "react/jsx-dev-runtime";
3
- import { patch } from "./jsx-runtime";
4
- import { Fragment } from "react";
5
- var jsxDEV = patch.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 { 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,OAAO,aAAa;AAEpB,SAAS,aAAa;AAKtB,SAAS,gBAAgB;AAHlB,IAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;","names":[]}
@@ -1,25 +0,0 @@
1
- import {
2
- Render
3
- } from "./chunk-UIHA4AT6.js";
4
- import "./chunk-4MR23TOU.js";
5
-
6
- // src/jsx-runtime.ts
7
- import { State } from "@expressive/mvc";
8
- import Runtime from "react/jsx-runtime";
9
- import { Fragment } from "react";
10
- var RENDER = /* @__PURE__ */ new WeakMap();
11
- function patch(type, ...args) {
12
- if (State.is(type))
13
- if (RENDER.has(type)) type = RENDER.get(type);
14
- else RENDER.set(type, type = Render.bind(type));
15
- return this(type, ...args);
16
- }
17
- var jsx = patch.bind(Runtime.jsx);
18
- var jsxs = patch.bind(Runtime.jsxs);
19
- export {
20
- Fragment,
21
- jsx,
22
- jsxs,
23
- patch
24
- };
25
- //# sourceMappingURL=jsx-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/jsx-runtime.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"],"mappings":";;;;;;AAAA,SAAS,aAAa;AAEtB,OAAO,aAAa;AAkDpB,SAAS,gBAAgB;AAjBzB,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,MAEd,SACG,MACiB;AACpB,MAAI,MAAM,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,QAAQ,GAAG;AAClC,IAAM,OAAO,MAAM,KAAK,QAAQ,IAAI;","names":[]}
package/dist/index.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import State__default, { Context, State } from '@expressive/mvc';
2
- export { Context, Observable, State, State as default, get, ref, set, use } from '@expressive/mvc';
3
- export { Pragma } from './adapter';
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 State__default> = {
16
- /** Type of controller to fetch from context. */
17
- for: State__default.Extends<T>;
18
- /**
19
- * Render function, will receive instance of desired controller.
20
- *
21
- * Called every render of parent component.
22
- * Similar to `State.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 State__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 State__default> {
31
- /** State or group of States to provide to descendant Consumers. */
32
- for: Context.Accept<T>;
33
- /**
34
- * Callback to run for each provided State.
35
- */
36
- forEach?: Context.Expect<T>;
37
- /**
38
- * Children to render within this Provider.
39
- */
40
- children?: ReactNode;
41
- /** A fallback tree to show when suspended. */
42
- fallback?: ReactNode;
43
- /**
44
- * A name for this Suspense boundary for instrumentation purposes.
45
- * The name will help identify this boundary in React DevTools.
46
- */
47
- name?: string | undefined;
48
- }
49
- }
50
- declare function Provider<T extends State__default>(props: Provider.Props<T>): ReactNode;
51
-
52
- export { Consumer, Provider };
package/dist/index.js DELETED
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- Consumer: () => Consumer,
24
- Context: () => import_mvc2.Context,
25
- Fragment: () => import_react3.Fragment,
26
- Observable: () => import_mvc2.Observable,
27
- Pragma: () => import_adapter.Pragma,
28
- Provider: () => Provider,
29
- State: () => import_mvc2.State,
30
- createElement: () => import_react3.createElement,
31
- default: () => src_default,
32
- get: () => import_mvc2.get,
33
- ref: () => import_mvc2.ref,
34
- set: () => import_mvc2.set,
35
- use: () => import_mvc2.use
36
- });
37
- module.exports = __toCommonJS(src_exports);
38
- var import_mvc2 = require("@expressive/mvc");
39
- var import_react2 = require("react");
40
- var import_adapter = require("./adapter");
41
-
42
- // src/context.ts
43
- var import_mvc = require("@expressive/mvc");
44
- var import_react = require("react");
45
- var Layers = (0, import_react.createContext)(new import_mvc.Context());
46
- import_mvc.Context.use = (create) => {
47
- const ambient = (0, import_react.useContext)(Layers);
48
- return create ? (0, import_react.useMemo)(() => ambient.push(), [ambient]) : ambient;
49
- };
50
- function Consumer(props) {
51
- return props.for.get((i) => props.children(i));
52
- }
53
- function Provider(props) {
54
- const context = import_mvc.Context.use(true);
55
- (0, import_react.useEffect)(() => () => context.pop(), [context]);
56
- context.use(props.for, (state) => {
57
- if (props.forEach) {
58
- const cleanup = props.forEach(state);
59
- if (cleanup) state.set(cleanup, null);
60
- }
61
- });
62
- return provide(context, props.children, props.fallback, props.name);
63
- }
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, {
68
- key: context.id,
69
- value: context,
70
- children
71
- });
72
- }
73
-
74
- // src/index.ts
75
- var import_react3 = require("react");
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;
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- Consumer,
83
- Context,
84
- Fragment,
85
- Observable,
86
- Pragma,
87
- Provider,
88
- State,
89
- createElement,
90
- get,
91
- ref,
92
- set,
93
- use
94
- });
95
- //# 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 {\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 +0,0 @@
1
- import * as State 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> | State.State.Class<State.State>, ...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.patch.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 { 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"]}
@@ -1,30 +0,0 @@
1
- import { State } from '@expressive/mvc';
2
- import React__default from 'react';
3
- export { Fragment } from 'react';
4
-
5
- declare namespace JSX {
6
- type ElementType = State.Extends<State.AsComponent> | React__default.JSX.ElementType | ((props: {}, ref?: any) => void);
7
- type LibraryManagedAttributes<C, P> = C extends new (...args: any[]) => {
8
- props: infer U;
9
- } ? U : C extends State.Extends<infer U> ? State.Props<U> : React__default.JSX.LibraryManagedAttributes<C, P>;
10
- interface Element extends React__default.JSX.Element {
11
- }
12
- interface ElementClass extends React__default.JSX.ElementClass {
13
- }
14
- interface ElementAttributesProperty {
15
- }
16
- interface ElementChildrenAttribute extends React__default.JSX.ElementChildrenAttribute {
17
- }
18
- interface IntrinsicAttributes extends React__default.JSX.IntrinsicAttributes {
19
- }
20
- interface IntrinsicClassAttributes<T> extends React__default.JSX
21
- .IntrinsicClassAttributes<T> {
22
- }
23
- interface IntrinsicElements extends React__default.JSX.IntrinsicElements {
24
- }
25
- }
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>>;
29
-
30
- export { JSX, jsx, jsxs, patch };
@@ -1,130 +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
- jsx: () => jsx,
35
- jsxs: () => jsxs,
36
- patch: () => patch
37
- });
38
- module.exports = __toCommonJS(jsx_runtime_exports);
39
- var import_mvc3 = require("@expressive/mvc");
40
- var import_jsx_runtime = __toESM(require("react/jsx-runtime"));
41
-
42
- // src/state.as.ts
43
- var import_mvc2 = require("@expressive/mvc");
44
-
45
- // src/context.ts
46
- var import_mvc = require("@expressive/mvc");
47
- var import_react = require("react");
48
- var Layers = (0, import_react.createContext)(new import_mvc.Context());
49
- import_mvc.Context.use = (create) => {
50
- const ambient = (0, import_react.useContext)(Layers);
51
- return create ? (0, import_react.useMemo)(() => ambient.push(), [ambient]) : ambient;
52
- };
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, {
57
- key: context.id,
58
- value: context,
59
- children
60
- });
61
- }
62
-
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
70
- });
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);
110
- }
111
-
112
- // src/jsx-runtime.ts
113
- var import_react2 = require("react");
114
- var RENDER = /* @__PURE__ */ new WeakMap();
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));
119
- return this(type, ...args);
120
- }
121
- var jsx = patch.bind(import_jsx_runtime.default.jsx);
122
- var jsxs = patch.bind(import_jsx_runtime.default.jsxs);
123
- // Annotate the CommonJS export names for ESM import in node:
124
- 0 && (module.exports = {
125
- Fragment,
126
- jsx,
127
- jsxs,
128
- patch
129
- });
130
- //# sourceMappingURL=jsx-runtime.js.map
@@ -1 +0,0 @@
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,K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