@expressive/react 0.60.3 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter.js +13 -6
- package/dist/adapter.js.map +1 -1
- package/dist/esm/adapter.js +7 -7
- package/dist/esm/adapter.js.map +1 -1
- package/dist/esm/context.js +8 -4
- package/dist/esm/context.js.map +1 -1
- package/dist/esm/jsx-runtime.js +16 -35
- package/dist/esm/jsx-runtime.js.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +2 -2
- package/dist/jsx-runtime.js +23 -35
- package/dist/jsx-runtime.js.map +1 -1
- package/package.json +3 -3
package/dist/adapter.js
CHANGED
|
@@ -26,7 +26,6 @@ module.exports = __toCommonJS(adapter_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/model.as.ts
|
|
28
28
|
var import_mvc2 = require("@expressive/mvc");
|
|
29
|
-
var import_react2 = require("react");
|
|
30
29
|
|
|
31
30
|
// src/context.ts
|
|
32
31
|
var import_mvc = require("@expressive/mvc");
|
|
@@ -36,18 +35,26 @@ import_mvc.Context.use = (create) => {
|
|
|
36
35
|
const ambient = (0, import_react.useContext)(Lookup);
|
|
37
36
|
return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
|
|
38
37
|
};
|
|
38
|
+
function createProvider(context, children) {
|
|
39
|
+
return (0, import_react.createElement)(Lookup.Provider, {
|
|
40
|
+
key: context.id,
|
|
41
|
+
value: context,
|
|
42
|
+
children
|
|
43
|
+
});
|
|
44
|
+
}
|
|
39
45
|
|
|
40
46
|
// src/model.as.ts
|
|
41
47
|
import_mvc2.Model.as = function(render) {
|
|
42
48
|
if (this === import_mvc2.Model)
|
|
43
49
|
throw new Error("Cannot create component from base Model.");
|
|
44
50
|
const Component = (props) => {
|
|
45
|
-
const local = this.use(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
children: render(props, local)
|
|
51
|
+
const local = this.use((self) => {
|
|
52
|
+
self.set(props);
|
|
53
|
+
if (props.is)
|
|
54
|
+
return props.is(self);
|
|
50
55
|
});
|
|
56
|
+
local.set(props);
|
|
57
|
+
return createProvider(import_mvc.Context.get(local), render(props, local));
|
|
51
58
|
};
|
|
52
59
|
Component.Model = this;
|
|
53
60
|
Component.displayName = this.name;
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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\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, { createElement, FunctionComponent } from 'react';\n\nimport { Context, Lookup } from './context';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> extends FunctionComponent<P & Component.Props<T>> {\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n namespace Component {\n type Props<T extends Model> = \n & Partial<Pick<T, Exclude<keyof T, keyof Model>>>\n & {\n is?: (instance: T) => void | (() => void);\n }\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, 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(props.is);\n\n local.set(props);\n\n return createElement(Lookup.Provider, {\n value: Context.get(local)!,\n children: render(props, 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 { ReactNode, createContext, createElement, 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 for: Context.Accept<T>;\n forEach?: Context.Expect<T>;\n children?: ReactNode;\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(null, cleanup);\n }\n });\n\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context\n }, props.children);\n}\n\nexport { Consumer, Provider, Lookup, Context }\n","import { Model, Context } 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 enabled: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n\n context.include(instance);\n \n const unwatch = instance.get(current => {\n local = current;\n\n if(enabled) \n refresh();\n });\n\n function didMount(){\n enabled = 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(enabled && repeat && props){\n enabled = 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(() => enabled = true);\n else\n enabled = 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 function forceUpdate(): void;\n function forceUpdate<T>(action: Promise<T> | (() => Promise<T>)): Promise<T>;\n function forceUpdate<T>(action?: Promise<T> | (() => Promise<T>)){\n if(typeof action == \"function\")\n action = action();\n\n refresh();\n\n if(action)\n return action.finally(refresh);\n }\n\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 unwatch: (() => void) | undefined;\n let value: any;\n\n unwatch = createEffect(instance, current => {\n if(typeof argument === \"function\"){\n const next = argument.call(current, current, forceUpdate);\n\n if(next === value)\n return;\n\n value = next;\n }\n else\n value = current;\n\n if(unwatch)\n refresh();\n }, argument === true);\n\n if(value instanceof Promise){\n let error: Error | undefined;\n\n unwatch();\n\n // TODO: ignore update if resolves to undefined or null\n value.then(x => value = x).catch(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 return () => {\n Pragma.useLifecycle(() => unwatch);\n return value === undefined ? null : value;\n }\n });\n\n return render() as R;\n}"],"mappings":"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","names":["Pragma","import_mvc","import_react","import_mvc","import_mvc","import_adapter","Pragma"]}
|
|
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\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 { Context, 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 & Component.Props<T>> {\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n namespace Component {\n type Props<T extends Model> = \n & Partial<Pick<T, Exclude<keyof T, keyof Model>>>\n & {\n is?: (instance: T) => void | (() => void);\n }\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, 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(Context.get(local)!, render(props, local));\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, 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 for: Context.Accept<T>;\n forEach?: Context.Expect<T>;\n children?: ReactNode;\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(null, cleanup);\n }\n });\n\n return createProvider(context, props.children);\n}\n\nexport function createProvider(context: Context, children: ReactNode){\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, Context }\n","import { Model, Context } 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 enabled: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n\n context.include(instance);\n \n const unwatch = instance.get(current => {\n local = current;\n\n if(enabled) \n refresh();\n });\n\n function didMount(){\n enabled = 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(enabled && repeat && props){\n enabled = 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(() => enabled = true);\n else\n enabled = 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 function forceUpdate(): void;\n function forceUpdate<T>(action: Promise<T> | (() => Promise<T>)): Promise<T>;\n function forceUpdate<T>(action?: Promise<T> | (() => Promise<T>)){\n if(typeof action == \"function\")\n action = action();\n\n refresh();\n\n if(action)\n return action.finally(refresh);\n }\n\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 unwatch: (() => void) | undefined;\n let value: any;\n\n unwatch = createEffect(instance, current => {\n if(typeof argument === \"function\"){\n const next = argument.call(current, current, forceUpdate);\n\n if(next === value)\n return;\n\n value = next;\n }\n else\n value = current;\n\n if(unwatch)\n refresh();\n }, argument === true);\n\n if(value instanceof Promise){\n let error: Error | undefined;\n\n unwatch();\n\n // TODO: ignore update if resolves to undefined or null\n value.then(x => value = x).catch(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 return () => {\n Pragma.useLifecycle(() => unwatch);\n return value === undefined ? null : value;\n }\n });\n\n return render() as R;\n}"],"mappings":"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","names":["Pragma","import_mvc","import_mvc","import_mvc","import_adapter","Pragma"]}
|
package/dist/esm/adapter.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// src/model.as.ts
|
|
2
2
|
import { Model } from "@expressive/mvc";
|
|
3
|
-
import {
|
|
4
|
-
import { Context, Lookup } from "./context";
|
|
3
|
+
import { Context, createProvider } from "./context";
|
|
5
4
|
Model.as = function(render) {
|
|
6
5
|
if (this === Model)
|
|
7
6
|
throw new Error("Cannot create component from base Model.");
|
|
8
7
|
const Component = (props) => {
|
|
9
|
-
const local = this.use(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
children: render(props, local)
|
|
8
|
+
const local = this.use((self) => {
|
|
9
|
+
self.set(props);
|
|
10
|
+
if (props.is)
|
|
11
|
+
return props.is(self);
|
|
14
12
|
});
|
|
13
|
+
local.set(props);
|
|
14
|
+
return createProvider(Context.get(local), render(props, local));
|
|
15
15
|
};
|
|
16
16
|
Component.Model = this;
|
|
17
17
|
Component.displayName = this.name;
|
package/dist/esm/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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, {
|
|
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 { Context, 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 & Component.Props<T>> {\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n namespace Component {\n type Props<T extends Model> = \n & Partial<Pick<T, Exclude<keyof T, keyof Model>>>\n & {\n is?: (instance: T) => void | (() => void);\n }\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, 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(Context.get(local)!, render(props, local));\n }\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import { Model, Context } 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 enabled: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n\n context.include(instance);\n \n const unwatch = instance.get(current => {\n local = current;\n\n if(enabled) \n refresh();\n });\n\n function didMount(){\n enabled = 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(enabled && repeat && props){\n enabled = 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(() => enabled = true);\n else\n enabled = 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 function forceUpdate(): void;\n function forceUpdate<T>(action: Promise<T> | (() => Promise<T>)): Promise<T>;\n function forceUpdate<T>(action?: Promise<T> | (() => Promise<T>)){\n if(typeof action == \"function\")\n action = action();\n\n refresh();\n\n if(action)\n return action.finally(refresh);\n }\n\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 unwatch: (() => void) | undefined;\n let value: any;\n\n unwatch = createEffect(instance, current => {\n if(typeof argument === \"function\"){\n const next = argument.call(current, current, forceUpdate);\n\n if(next === value)\n return;\n\n value = next;\n }\n else\n value = current;\n\n if(unwatch)\n refresh();\n }, argument === true);\n\n if(value instanceof Promise){\n let error: Error | undefined;\n\n unwatch();\n\n // TODO: ignore update if resolves to undefined or null\n value.then(x => value = x).catch(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 return () => {\n Pragma.useLifecycle(() => unwatch);\n return value === undefined ? null : value;\n }\n });\n\n return render() as R;\n}","import { Context } from '@expressive/mvc';\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","Context","Model","Pragma","Pragma"]}
|
package/dist/esm/context.js
CHANGED
|
@@ -19,15 +19,19 @@ function Provider(props) {
|
|
|
19
19
|
model.set(null, cleanup);
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
+
return createProvider(context, props.children);
|
|
23
|
+
}
|
|
24
|
+
function createProvider(context, children) {
|
|
22
25
|
return createElement(Lookup.Provider, {
|
|
23
26
|
key: context.id,
|
|
24
|
-
value: context
|
|
25
|
-
|
|
27
|
+
value: context,
|
|
28
|
+
children
|
|
29
|
+
});
|
|
26
30
|
}
|
|
27
31
|
export {
|
|
28
32
|
Consumer,
|
|
29
33
|
Context,
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
Provider,
|
|
35
|
+
createProvider
|
|
32
36
|
};
|
|
33
37
|
//# sourceMappingURL=context.js.map
|
package/dist/esm/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context.ts"],"sourcesContent":["import Model, { Context } from '@expressive/mvc';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/context.ts"],"sourcesContent":["import Model, { Context } from '@expressive/mvc';\nimport { createContext, createElement, ReactNode, 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 for: Context.Accept<T>;\n forEach?: Context.Expect<T>;\n children?: ReactNode;\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(null, cleanup);\n }\n });\n\n return createProvider(context, props.children);\n}\n\nexport function createProvider(context: Context, children: ReactNode){\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, Context }\n"],"mappings":";AAAA,SAAgB,eAAe;AAC/B,SAAS,eAAe,eAA0B,YAAY,WAAW,eAAe;AAExF,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;AAUA,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,MAAM,OAAO;AAAA,IAC3B;AAAA,EACF,CAAC;AAED,SAAO,eAAe,SAAS,MAAM,QAAQ;AAC/C;AAEO,SAAS,eAAe,SAAkB,UAAoB;AACnE,SAAO,cAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/esm/jsx-runtime.js
CHANGED
|
@@ -1,39 +1,20 @@
|
|
|
1
1
|
// src/jsx-runtime.ts
|
|
2
|
-
import { Model } from "@expressive/mvc";
|
|
3
|
-
import { isValidElement } from "react";
|
|
2
|
+
import { Context, Model } from "@expressive/mvc";
|
|
4
3
|
import Runtime from "react/jsx-runtime";
|
|
5
|
-
import {
|
|
4
|
+
import { createProvider } from "./context";
|
|
6
5
|
import { Fragment } from "react";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (children === void 0)
|
|
20
|
-
children = Children;
|
|
21
|
-
if (Ambient && (Array.isArray(children) || isValidElement(children) && children.type !== Lookup.Provider))
|
|
22
|
-
children = jsx(Lookup.Provider, { value: Ambient, children });
|
|
23
|
-
Ambient = void 0;
|
|
24
|
-
return children;
|
|
25
|
-
}
|
|
26
|
-
function Component({ is, render, ...rest }) {
|
|
27
|
-
Ambient = Children = null;
|
|
28
|
-
const local = this.use(is);
|
|
29
|
-
if (!render)
|
|
30
|
-
render = local.render;
|
|
31
|
-
local.set(rest);
|
|
32
|
-
return provider(render ? render(rest, local) : rest.children);
|
|
33
|
-
}
|
|
34
|
-
function FC(props, ref) {
|
|
35
|
-
Ambient = Children = null;
|
|
36
|
-
return provider(this(props, ref));
|
|
6
|
+
function MC(props) {
|
|
7
|
+
const local = this.use((self) => {
|
|
8
|
+
self.set(props);
|
|
9
|
+
if (props.is)
|
|
10
|
+
return props.is(self);
|
|
11
|
+
});
|
|
12
|
+
local.set(props);
|
|
13
|
+
const render = local.render || props.render;
|
|
14
|
+
return createProvider(
|
|
15
|
+
Context.get(local),
|
|
16
|
+
render ? render(props, local) : props.children
|
|
17
|
+
);
|
|
37
18
|
}
|
|
38
19
|
var RENDER = /* @__PURE__ */ new WeakMap();
|
|
39
20
|
function compat(type, ...args) {
|
|
@@ -41,9 +22,9 @@ function compat(type, ...args) {
|
|
|
41
22
|
if (RENDER.has(type))
|
|
42
23
|
type = RENDER.get(type);
|
|
43
24
|
else if (typeof type == "function")
|
|
44
|
-
RENDER.set(type, type = type.prototype instanceof Model ?
|
|
25
|
+
RENDER.set(type, type = type.prototype instanceof Model ? MC.bind(type) : type);
|
|
45
26
|
}
|
|
46
|
-
return
|
|
27
|
+
return this(type, ...args);
|
|
47
28
|
}
|
|
48
29
|
var jsx = compat.bind(Runtime.jsx);
|
|
49
30
|
var jsxs = compat.bind(Runtime.jsxs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport React
|
|
1
|
+
{"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { Context, 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 namespace FC {\n type Extends<T extends Model, P extends {} = {}> = Props<T> & P;\n\n export { Extends as Props };\n }\n\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<FC.Props<T, P>>;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: HasProps<this>, self: this): 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 | (() => void);\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n }\n\n type HasProps<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>>;\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & P\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\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 props: Model.Props<T>\n) {\n const local = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props as Model.Assign<T>);\n\n const render = local.render || props.render;\n\n return createProvider(\n Context.get(local)!,\n render ? render(props as Model.HasProps<T>, local) : props.children\n );\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,SAAS,aAAa;AAE/B,OAAO,aAAa;AAEpB,SAAS,sBAAsB;AA8H/B,SAAS,gBAAgB;AA3CzB,SAAS,GAEP,OACA;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG,MAAM;AACP,aAAO,MAAM,GAAG,IAAI;AAAA,EACxB,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,MAAM,UAAU,MAAM;AAErC,SAAO;AAAA,IACL,QAAQ,IAAI,KAAK;AAAA,IACjB,SAAS,OAAO,OAA4B,KAAK,IAAI,MAAM;AAAA,EAC7D;AACF;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.js
CHANGED
|
@@ -58,10 +58,14 @@ function Provider(props) {
|
|
|
58
58
|
model.set(null, cleanup);
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
+
return createProvider(context, props.children);
|
|
62
|
+
}
|
|
63
|
+
function createProvider(context, children) {
|
|
61
64
|
return (0, import_react.createElement)(Lookup.Provider, {
|
|
62
65
|
key: context.id,
|
|
63
|
-
value: context
|
|
64
|
-
|
|
66
|
+
value: context,
|
|
67
|
+
children
|
|
68
|
+
});
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// src/index.ts
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 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 {
|
|
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 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, 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 for: Context.Accept<T>;\n forEach?: Context.Expect<T>;\n children?: ReactNode;\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(null, cleanup);\n }\n });\n\n return createProvider(context, props.children);\n}\n\nexport function createProvider(context: Context, children: ReactNode){\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\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,IAAAA,gBAAoC;AAEpC,qBAAuB;;;ACFvB,iBAA+B;AAC/B,mBAAwF;AAExF,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;AAUA,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,MAAM,OAAO;AAAA,IAC3B;AAAA,EACF,CAAC;AAED,SAAO,eAAe,SAAS,MAAM,QAAQ;AAC/C;AAEO,SAAS,eAAe,SAAkB,UAAoB;AACnE,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;;;ADtDA,IAAAC,cAGO;AAGP,IAAAC,gBAAwC;AAlBxC,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","import_mvc","import_react"]}
|
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ declare namespace JSX {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
declare function compat(this: (type: React__default.ElementType, ...args: any[]) => React__default.ReactElement, type: React__default.ElementType | Model.Init, ...args: any[]): React__default.ReactElement;
|
|
76
|
-
declare const jsx: (type:
|
|
77
|
-
declare const jsxs: (type:
|
|
76
|
+
declare const jsx: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
|
|
77
|
+
declare const jsxs: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
|
|
78
78
|
|
|
79
79
|
export { JSX, compat, jsx, jsxs };
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -30,14 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/jsx-runtime.ts
|
|
31
31
|
var jsx_runtime_exports = {};
|
|
32
32
|
__export(jsx_runtime_exports, {
|
|
33
|
-
Fragment: () =>
|
|
33
|
+
Fragment: () => import_react2.Fragment,
|
|
34
34
|
compat: () => compat,
|
|
35
35
|
jsx: () => jsx,
|
|
36
36
|
jsxs: () => jsxs
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(jsx_runtime_exports);
|
|
39
39
|
var import_mvc2 = require("@expressive/mvc");
|
|
40
|
-
var import_react2 = require("react");
|
|
41
40
|
var import_jsx_runtime = __toESM(require("react/jsx-runtime"));
|
|
42
41
|
|
|
43
42
|
// src/context.ts
|
|
@@ -48,39 +47,28 @@ import_mvc.Context.use = (create) => {
|
|
|
48
47
|
const ambient = (0, import_react.useContext)(Lookup);
|
|
49
48
|
return create ? (0, import_react.useMemo)(() => ambient.push(), []) : ambient;
|
|
50
49
|
};
|
|
50
|
+
function createProvider(context, children) {
|
|
51
|
+
return (0, import_react.createElement)(Lookup.Provider, {
|
|
52
|
+
key: context.id,
|
|
53
|
+
value: context,
|
|
54
|
+
children
|
|
55
|
+
});
|
|
56
|
+
}
|
|
51
57
|
|
|
52
58
|
// src/jsx-runtime.ts
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (children === void 0)
|
|
67
|
-
children = Children;
|
|
68
|
-
if (Ambient && (Array.isArray(children) || (0, import_react2.isValidElement)(children) && children.type !== Lookup.Provider))
|
|
69
|
-
children = jsx(Lookup.Provider, { value: Ambient, children });
|
|
70
|
-
Ambient = void 0;
|
|
71
|
-
return children;
|
|
72
|
-
}
|
|
73
|
-
function Component({ is, render, ...rest }) {
|
|
74
|
-
Ambient = Children = null;
|
|
75
|
-
const local = this.use(is);
|
|
76
|
-
if (!render)
|
|
77
|
-
render = local.render;
|
|
78
|
-
local.set(rest);
|
|
79
|
-
return provider(render ? render(rest, local) : rest.children);
|
|
80
|
-
}
|
|
81
|
-
function FC(props, ref) {
|
|
82
|
-
Ambient = Children = null;
|
|
83
|
-
return provider(this(props, ref));
|
|
59
|
+
var import_react2 = require("react");
|
|
60
|
+
function MC(props) {
|
|
61
|
+
const local = this.use((self) => {
|
|
62
|
+
self.set(props);
|
|
63
|
+
if (props.is)
|
|
64
|
+
return props.is(self);
|
|
65
|
+
});
|
|
66
|
+
local.set(props);
|
|
67
|
+
const render = local.render || props.render;
|
|
68
|
+
return createProvider(
|
|
69
|
+
import_mvc2.Context.get(local),
|
|
70
|
+
render ? render(props, local) : props.children
|
|
71
|
+
);
|
|
84
72
|
}
|
|
85
73
|
var RENDER = /* @__PURE__ */ new WeakMap();
|
|
86
74
|
function compat(type, ...args) {
|
|
@@ -88,9 +76,9 @@ function compat(type, ...args) {
|
|
|
88
76
|
if (RENDER.has(type))
|
|
89
77
|
type = RENDER.get(type);
|
|
90
78
|
else if (typeof type == "function")
|
|
91
|
-
RENDER.set(type, type = type.prototype instanceof import_mvc2.Model ?
|
|
79
|
+
RENDER.set(type, type = type.prototype instanceof import_mvc2.Model ? MC.bind(type) : type);
|
|
92
80
|
}
|
|
93
|
-
return
|
|
81
|
+
return this(type, ...args);
|
|
94
82
|
}
|
|
95
83
|
var jsx = compat.bind(import_jsx_runtime.default.jsx);
|
|
96
84
|
var jsxs = compat.bind(import_jsx_runtime.default.jsxs);
|
package/dist/jsx-runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport React
|
|
1
|
+
{"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { Context, 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 namespace FC {\n type Extends<T extends Model, P extends {} = {}> = Props<T> & P;\n\n export { Extends as Props };\n }\n\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<FC.Props<T, P>>;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: HasProps<this>, self: this): 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 | (() => void);\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n }\n\n type HasProps<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>>;\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & P\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\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 props: Model.Props<T>\n) {\n const local = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props as Model.Assign<T>);\n\n const render = local.render || props.render;\n\n return createProvider(\n Context.get(local)!,\n render ? render(props as Model.HasProps<T>, local) : props.children\n );\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, 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 for: Context.Accept<T>;\n forEach?: Context.Expect<T>;\n children?: ReactNode;\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(null, cleanup);\n }\n });\n\n return createProvider(context, props.children);\n}\n\nexport function createProvider(context: Context, children: ReactNode){\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, Context }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA+B;AAE/B,yBAAoB;;;ACFpB,iBAA+B;AAC/B,mBAAwF;AAExF,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;AA+CO,SAAS,eAAe,SAAkB,UAAoB;AACnE,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;;;AD2DA,IAAAC,gBAAyB;AA3CzB,SAAS,GAEP,OACA;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG,MAAM;AACP,aAAO,MAAM,GAAG,IAAI;AAAA,EACxB,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,MAAM,UAAU,MAAM;AAErC,SAAO;AAAA,IACL,oBAAQ,IAAI,KAAK;AAAA,IACjB,SAAS,OAAO,OAA4B,KAAK,IAAI,MAAM;AAAA,EAC7D;AACF;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","import_react","Runtime"]}
|
package/package.json
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"preversion": "npm run test && npm run build"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@expressive/mvc": "^0.
|
|
52
|
+
"@expressive/mvc": "^0.62.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"react": ">=16.8.0 <19.0.0"
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"react": "^18.2.0",
|
|
67
67
|
"tsup": "^8.0.2"
|
|
68
68
|
},
|
|
69
|
-
"version": "0.
|
|
70
|
-
"gitHead": "
|
|
69
|
+
"version": "0.62.0",
|
|
70
|
+
"gitHead": "f6fb91c11b934386e8eab41e61477f77e84b24c6"
|
|
71
71
|
}
|