@expressive/react 0.54.3 → 0.55.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 +2 -1
- package/dist/adapter.js.map +1 -1
- package/dist/esm/adapter.js +2 -1
- package/dist/esm/adapter.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx-dev-runtime.js +10 -0
- package/dist/esm/jsx-dev-runtime.js.map +1 -0
- package/dist/esm/jsx-runtime.js +34 -0
- package/dist/esm/jsx-runtime.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +7 -0
- package/dist/jsx-dev-runtime.js +46 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +38 -0
- package/dist/jsx-runtime.js +88 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/package.json +13 -3
package/dist/adapter.js
CHANGED
|
@@ -50,7 +50,7 @@ import_mvc2.Model.use = function(argument, repeat) {
|
|
|
50
50
|
let enabled;
|
|
51
51
|
let local;
|
|
52
52
|
const instance = new this(argument);
|
|
53
|
-
const context = ambient.push(
|
|
53
|
+
const context = ambient.push();
|
|
54
54
|
const unwatch = instance.get((current) => {
|
|
55
55
|
local = current;
|
|
56
56
|
if (enabled)
|
|
@@ -66,6 +66,7 @@ import_mvc2.Model.use = function(argument, repeat) {
|
|
|
66
66
|
}
|
|
67
67
|
return (props) => {
|
|
68
68
|
import_adapter.Pragma.useLifecycle(didMount);
|
|
69
|
+
context.include({ instance });
|
|
69
70
|
if (repeat && enabled && props) {
|
|
70
71
|
enabled = false;
|
|
71
72
|
if (typeof props == "function")
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts","../src/model.as.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 () => unknown>(\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';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> {\n (props: P): JSX.Element | null;\n\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n /**\n * Creates a component which reflects this Model. All managed properties may be assigned using props.\n * \n * @param render Function which renders component. This function receives all Model state merged with props. Normal subscription behavior still applies.\n */\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null\n ): Component<T, P & Model.Assign<T>>;\n }\n}\n\nModel.as = function <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null){\n\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component = ((inputProps: P) => {\n const props = this.use(inputProps, true) as T & P;\n\n for(const key in inputProps)\n if(!(key in props))\n Object.defineProperty(props, key, { value: inputProps[key] });\n\n return render(props);\n }) as Model.Component<T, P>;\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import { Model } 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 ambient = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n let enabled: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n const context = ambient.push(
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts","../src/model.as.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 () => unknown>(\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';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> {\n (props: P): JSX.Element | null;\n\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n /**\n * Creates a component which reflects this Model. All managed properties may be assigned using props.\n * \n * @param render Function which renders component. This function receives all Model state merged with props. Normal subscription behavior still applies.\n */\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null\n ): Component<T, P & Model.Assign<T>>;\n }\n}\n\nModel.as = function <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null){\n\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component = ((inputProps: P) => {\n const props = this.use(inputProps, true) as T & P;\n\n for(const key in inputProps)\n if(!(key in props))\n Object.defineProperty(props, key, { value: inputProps[key] });\n\n return render(props);\n }) as Model.Component<T, P>;\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import { Model } 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 ambient = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n let enabled: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n const context = ambient.push();\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 instance.set(null);\n context.pop()\n }\n }\n\n return (props?: Model.Assign<T> | Model.Callback<T>) => {\n Pragma.useLifecycle(didMount);\n context.include({ instance });\n\n if(repeat && enabled && props){\n enabled = false;\n\n if(typeof props == \"function\")\n props.call(instance, instance);\n else if(typeof props == \"object\")\n instance.set(props);\n\n const update = instance.set();\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gBAAAA;AAAA;AAAA;;;ACAA,iBAAsB;AAsBtB,iBAAM,KAAK,SACY,QAAyC;AAE9D,MAAG,SAAS;AACV,UAAM,IAAI,MAAM,0CAA0C;AAE5D,QAAM,YAAa,CAAC,eAAkB;AACpC,UAAM,QAAQ,KAAK,IAAI,YAAY,IAAI;AAEvC,eAAU,OAAO;AACf,UAAG,EAAE,OAAO;AACV,eAAO,eAAe,OAAO,KAAK,EAAE,OAAO,WAAW,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AO;AAElB,cAAQ;AAER,UAAG;AACD,eAAO,OAAO,QAAQ,OAAO;AAAA,IACjC;AAEA,UAAM,WAAW,QAAQ,IAAI,IAAI;AAEjC,QAAG,CAAC;AACF,UAAG,aAAa;AACd,eAAO,MAAM;AAAA;AAEb,cAAM,IAAI,MAAM,kBAAkB,IAAI,cAAc;AAExD,QAAI;AACJ,QAAI;AAEJ,kBAAU,0BAAa,UAAU,aAAW;AAC1C,UAAG,OAAO,aAAa,YAAW;AAChC,cAAM,OAAO,SAAS,KAAK,SAAS,SAAS,WAAW;AAExD,YAAG,SAAS;AACV;AAEF,gBAAQ;AAAA,MACV;AAEE,gBAAQ;AAEV,UAAG;AACD,gBAAQ;AAAA,IACZ,GAAG,aAAa,IAAI;AAEpB,QAAG,iBAAiB,SAAQ;AAC1B,UAAI;AAEJ,cAAQ;AAGR,YAAM,KAAK,OAAK,QAAQ,CAAC,EAAE,MAAM,OAAK,QAAQ,CAAC,EAAE,QAAQ,OAAO;AAChE,cAAQ;AAER,aAAO,MAAM;AACX,YAAG;AACD,gBAAM;AAER,eAAO,UAAU,SAAY,OAAO;AAAA,MACtC;AAAA,IACF;AAEA,QAAG,UAAU,MAAK;AAChB,cAAQ;AACR,aAAO,MAAM;AAAA,IACf;AAEA,WAAO,MAAM;AACX,6BAAO,aAAa,MAAM,OAAO;AACjC,aAAO,UAAU,SAAY,OAAO;AAAA,IACtC;AAAA,EACF,CAAC;AAED,SAAO,OAAO;AAChB;;;AH/HA,IAAMC,UAAS,CAAC;","names":["Pragma","import_mvc","import_mvc","import_adapter","Pragma"]}
|
package/dist/esm/adapter.js
CHANGED
|
@@ -24,7 +24,7 @@ Model2.use = function(argument, repeat) {
|
|
|
24
24
|
let enabled;
|
|
25
25
|
let local;
|
|
26
26
|
const instance = new this(argument);
|
|
27
|
-
const context = ambient.push(
|
|
27
|
+
const context = ambient.push();
|
|
28
28
|
const unwatch = instance.get((current) => {
|
|
29
29
|
local = current;
|
|
30
30
|
if (enabled)
|
|
@@ -40,6 +40,7 @@ Model2.use = function(argument, repeat) {
|
|
|
40
40
|
}
|
|
41
41
|
return (props) => {
|
|
42
42
|
Pragma.useLifecycle(didMount);
|
|
43
|
+
context.include({ instance });
|
|
43
44
|
if (repeat && enabled && props) {
|
|
44
45
|
enabled = false;
|
|
45
46
|
if (typeof props == "function")
|
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';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> {\n (props: P): JSX.Element | null;\n\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n /**\n * Creates a component which reflects this Model. All managed properties may be assigned using props.\n * \n * @param render Function which renders component. This function receives all Model state merged with props. Normal subscription behavior still applies.\n */\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null\n ): Component<T, P & Model.Assign<T>>;\n }\n}\n\nModel.as = function <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null){\n\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component = ((inputProps: P) => {\n const props = this.use(inputProps, true) as T & P;\n\n for(const key in inputProps)\n if(!(key in props))\n Object.defineProperty(props, key, { value: inputProps[key] });\n\n return render(props);\n }) as Model.Component<T, P>;\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import { Model } 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 ambient = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n let enabled: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n const context = ambient.push(
|
|
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';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n interface Component<T extends Model, P extends Model.Assign<T>> {\n (props: P): JSX.Element | null;\n\n displayName?: string;\n Model: Model.Type<T>;\n }\n\n /**\n * Creates a component which reflects this Model. All managed properties may be assigned using props.\n * \n * @param render Function which renders component. This function receives all Model state merged with props. Normal subscription behavior still applies.\n */\n function as <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null\n ): Component<T, P & Model.Assign<T>>;\n }\n}\n\nModel.as = function <T extends Model, P extends Model.Assign<T>> (\n this: Model.Init<T>, render: (using: P) => JSX.Element | null){\n\n if(this === Model)\n throw new Error(\"Cannot create component from base Model.\");\n\n const Component = ((inputProps: P) => {\n const props = this.use(inputProps, true) as T & P;\n\n for(const key in inputProps)\n if(!(key in props))\n Object.defineProperty(props, key, { value: inputProps[key] });\n\n return render(props);\n }) as Model.Component<T, P>;\n\n Component.Model = this;\n Component.displayName = this.name;\n \n return Component;\n}","import { Model } 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 ambient = Pragma.useContext();\n const render = Pragma.useFactory((refresh) => {\n let enabled: boolean | undefined;\n let local: T;\n\n const instance = new this(argument);\n const context = ambient.push();\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 instance.set(null);\n context.pop()\n }\n }\n\n return (props?: Model.Assign<T> | Model.Callback<T>) => {\n Pragma.useLifecycle(didMount);\n context.include({ instance });\n\n if(repeat && enabled && props){\n enabled = false;\n\n if(typeof props == \"function\")\n props.call(instance, instance);\n else if(typeof props == \"object\")\n instance.set(props);\n\n const update = instance.set();\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 () => unknown>(\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":";AAAA,SAAS,aAAa;AAsBtB,MAAM,KAAK,SACY,QAAyC;AAE9D,MAAG,SAAS;AACV,UAAM,IAAI,MAAM,0CAA0C;AAE5D,QAAM,YA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{ useContext, useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\nimport { Context } from './context';\n\nPragma.useContext = () => useContext(Context);\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, Provider } from './context';\nexport { type Pragma }
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import { useContext, useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\nimport { Context } from './context';\n\nPragma.useContext = () => useContext(Context);\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, Provider } from './context';\nexport { type Pragma };\n"],"mappings":";AAAA,SAAS,YAAY,WAAW,gBAAgB;AAEhD,SAAS,cAAc;AACvB,SAAS,eAAe;AAcxB;AAAA,EACE;AAAA,EAAgB,SAATA;AAAA,EACP;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,OACf;AAEP,SAAS,UAAU,gBAAgB;AAjBnC,OAAO,aAAa,MAAM,WAAW,OAAO;AAE5C,OAAO,eAAe,CAAC,aAAa,UAAU,MAAM,SAAS,GAAG,CAAC,CAAC;AAElE,OAAO,aAAa,CAAC,YAAY;AAC/B,QAAM,QAAQ,SAAS,MAAM,QAAQ,MAAM;AACzC,UAAM,CAAC,EAAE,OAAK,EAAE,KAAK,IAAI,CAAQ;AAAA,EACnC,CAAC,CAAC;AAEF,SAAO,MAAM,CAAC;AAChB;","names":["Model"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/jsx-dev-runtime.ts
|
|
2
|
+
import * as Runtime from "react/jsx-dev-runtime";
|
|
3
|
+
import { createElement } from "./jsx-runtime";
|
|
4
|
+
import { Fragment } from "react";
|
|
5
|
+
var jsxDEV2 = createElement.bind(Runtime.jsxDEV);
|
|
6
|
+
export {
|
|
7
|
+
Fragment,
|
|
8
|
+
jsxDEV2 as jsxDEV
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=jsx-dev-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jsx-dev-runtime.ts"],"sourcesContent":["import * as Runtime from 'react/jsx-dev-runtime';\nimport { createElement } from './jsx-runtime';\n\nexport const jsxDEV = createElement.bind(Runtime.jsxDEV);\n\nexport { type JSX } from './jsx-runtime';\nexport { Fragment } from \"react\";"],"mappings":";AAAA,YAAY,aAAa;AACzB,SAAS,qBAAqB;AAK9B,SAAS,gBAAgB;AAHlB,IAAMA,UAAS,cAAc,KAAa,cAAM;","names":["jsxDEV"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/jsx-runtime.ts
|
|
2
|
+
import { Model } from "@expressive/mvc";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as Runtime from "react/jsx-runtime";
|
|
5
|
+
import { Provider } from "./context";
|
|
6
|
+
import { Fragment } from "react";
|
|
7
|
+
function component(child, key) {
|
|
8
|
+
if (typeof child == "function")
|
|
9
|
+
return React.createElement(() => {
|
|
10
|
+
const self = this.get();
|
|
11
|
+
return child.call(self, self);
|
|
12
|
+
}, { key });
|
|
13
|
+
return child;
|
|
14
|
+
}
|
|
15
|
+
function createElement2(type, props, key, ...args) {
|
|
16
|
+
if (Model.is(type)) {
|
|
17
|
+
const { children, ...rest } = props;
|
|
18
|
+
return this(Provider, {
|
|
19
|
+
for: type,
|
|
20
|
+
set: rest,
|
|
21
|
+
children: Array.isArray(children) ? children.map(component, type) : component.call(type, children, 0)
|
|
22
|
+
}, key, ...args);
|
|
23
|
+
}
|
|
24
|
+
return this(type, props, key, ...args);
|
|
25
|
+
}
|
|
26
|
+
var jsx2 = createElement2.bind(Runtime.jsx);
|
|
27
|
+
var jsxs2 = createElement2.bind(Runtime.jsxs);
|
|
28
|
+
export {
|
|
29
|
+
Fragment,
|
|
30
|
+
createElement2 as createElement,
|
|
31
|
+
jsx2 as jsx,
|
|
32
|
+
jsxs2 as jsxs
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=jsx-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport * as React from 'react';\nimport * as Runtime from 'react/jsx-runtime';\n\nimport { Provider } from './context';\n\ntype MaybeArray<T> = T | T[];\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type Render<T extends Model> = (this: T, self: T) => React.ReactNode | null;\n\n type Props<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>> & {\n children?: MaybeArray<React.ReactNode | Render<T>>;\n }\n }\n}\n\nexport declare namespace JSX {\n type ElementType = Model.Type | React.JSX.ElementType;\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 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 component<T extends Model>(\n this: Model.Type<T>,\n child: React.ReactNode | Model.Render<T>,\n key: number){\n\n if(typeof child == 'function')\n return React.createElement(() => {\n const self = this.get();\n return child.call(self, self);\n }, { key });\n\n return child;\n}\n\nexport function createElement(\n this: (\n type: React.ElementType,\n props: Record<string, any>,\n key?: React.Key,\n ...rest: any[]\n ) => React.ReactElement,\n type: React.ElementType,\n props: Record<string, any>,\n key?: React.Key,\n ...args: any[]){\n\n if(Model.is(type)){\n const { children, ...rest } = props;\n\n return this(Provider, {\n for: type,\n set: rest,\n children: Array.isArray(children) ?\n children.map(component, type) :\n component.call(type, children, 0)\n }, key, ...args);\n }\n\n return this(type, props, key, ...args);\n}\n\nexport const jsx = createElement.bind(Runtime.jsx);\nexport const jsxs = createElement.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";"],"mappings":";AAAA,SAAS,aAAa;AACtB,YAAY,WAAW;AACvB,YAAY,aAAa;AAEzB,SAAS,gBAAgB;AA+EzB,SAAS,gBAAgB;AA5CzB,SAAS,UAEP,OACA,KAAY;AAEZ,MAAG,OAAO,SAAS;AACjB,WAAa,oBAAc,MAAM;AAC/B,YAAM,OAAO,KAAK,IAAI;AACtB,aAAO,MAAM,KAAK,MAAM,IAAI;AAAA,IAC9B,GAAG,EAAE,IAAI,CAAC;AAEZ,SAAO;AACT;AAEO,SAASA,eAOd,MACA,OACA,QACG,MAAY;AAEf,MAAG,MAAM,GAAG,IAAI,GAAE;AAChB,UAAM,EAAE,UAAU,GAAG,KAAK,IAAI;AAE9B,WAAO,KAAK,UAAU;AAAA,MACpB,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAAU,MAAM,QAAQ,QAAQ,IAC9B,SAAS,IAAI,WAAW,IAAI,IAC5B,UAAU,KAAK,MAAM,UAAU,CAAC;AAAA,IACpC,GAAG,KAAK,GAAG,IAAI;AAAA,EACjB;AAEA,SAAO,KAAK,MAAM,OAAO,KAAK,GAAG,IAAI;AACvC;AAEO,IAAMC,OAAMD,eAAc,KAAa,WAAG;AAC1C,IAAME,QAAOF,eAAc,KAAa,YAAI;","names":["createElement","jsx","jsxs"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Pragma } from './adapter';
|
|
2
2
|
import Model, { Context } from '@expressive/mvc';
|
|
3
3
|
export { Model, Model as default, get, has, ref, set, use } from '@expressive/mvc';
|
|
4
|
-
import * as
|
|
4
|
+
import * as React from 'react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
6
6
|
|
|
7
7
|
declare namespace Consumer {
|
|
@@ -18,7 +18,7 @@ declare namespace Consumer {
|
|
|
18
18
|
children: (value: T) => ReactNode | void;
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
declare function Consumer<T extends Model>(props: Consumer.Props<T>): string | number | boolean |
|
|
21
|
+
declare function Consumer<T extends Model>(props: Consumer.Props<T>): string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<ReactNode> | React.ReactPortal | null;
|
|
22
22
|
declare namespace Provider {
|
|
23
23
|
interface Props<T extends Model> {
|
|
24
24
|
for: Context.Accept<T>;
|
|
@@ -26,6 +26,6 @@ declare namespace Provider {
|
|
|
26
26
|
children?: ReactNode;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
declare function Provider<T extends Model>(props: Provider.Props<T>):
|
|
29
|
+
declare function Provider<T extends Model>(props: Provider.Props<T>): React.FunctionComponentElement<React.ProviderProps<Context>>;
|
|
30
30
|
|
|
31
31
|
export { Consumer, Provider };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/context.ts"],"sourcesContent":["import { useContext, useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\nimport { Context } from './context';\n\nPragma.useContext = () => useContext(Context);\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, Provider } from './context';\nexport { type Pragma }
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/context.ts"],"sourcesContent":["import { useContext, useEffect, useState } from 'react';\n\nimport { Pragma } from './adapter';\nimport { Context } from './context';\n\nPragma.useContext = () => useContext(Context);\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, Provider } from './context';\nexport { type Pragma };\n","import Model, { Context } from '@expressive/mvc';\nimport { ReactNode, createContext, createElement, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\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 set?: Model.Assign<T>;\n children?: ReactNode;\n }\n}\n\nfunction Provider<T extends Model>(props: Provider.Props<T>){\n const ambient = useContext(Lookup);\n const context = useMemo(() => ambient.push(), [ambient]);\n\n useEffect(() => () => context.pop(), [ambient]);\n \n context.include(props.for, props.set);\n\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context\n }, props.children);\n}\n\nexport { Consumer, Provider, Lookup as Context }"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAgD;AAEhD,qBAAuB;;;ACFvB,iBAA+B;AAC/B,mBAAwF;AAExF,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAkB1C,SAAS,SAA0B,OAAyB;AAC1D,SAAO,MAAM,IAAI,IAAI,OAAK,MAAM,SAAS,CAAC,CAAC;AAC7C;AAUA,SAAS,SAA0B,OAAyB;AAC1D,QAAM,cAAU,yBAAW,MAAM;AACjC,QAAM,cAAU,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC;AAEvD,8BAAU,MAAM,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC;AAE9C,UAAQ,QAAQ,MAAM,KAAK,MAAM,GAAG;AAEpC,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,EACT,GAAG,MAAM,QAAQ;AACnB;;;AD5BA,IAAAC,cAGO;AAfP,sBAAO,aAAa,UAAM,0BAAW,MAAO;AAE5C,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"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export { Fragment } from 'react';
|
|
3
|
+
export { JSX } from './jsx-runtime';
|
|
4
|
+
|
|
5
|
+
declare const jsxDEV: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements>, props: Record<string, any>, key?: React.Key | undefined, ...args: any[]) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
6
|
+
|
|
7
|
+
export { jsxDEV };
|
|
@@ -0,0 +1,46 @@
|
|
|
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: () => jsxDEV2
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(jsx_dev_runtime_exports);
|
|
37
|
+
var Runtime = __toESM(require("react/jsx-dev-runtime"));
|
|
38
|
+
var import_jsx_runtime = require("./jsx-runtime");
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var jsxDEV2 = import_jsx_runtime.createElement.bind(Runtime.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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/jsx-dev-runtime.ts"],"sourcesContent":["import * as Runtime from 'react/jsx-dev-runtime';\nimport { createElement } from './jsx-runtime';\n\nexport const jsxDEV = createElement.bind(Runtime.jsxDEV);\n\nexport { type JSX } from './jsx-runtime';\nexport { Fragment } from \"react\";"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,gBAAAA;AAAA;AAAA;AAAA,cAAyB;AACzB,yBAA8B;AAK9B,mBAAyB;AAHlB,IAAMA,UAAS,iCAAc,KAAa,cAAM;","names":["jsxDEV"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Model } from '@expressive/mvc';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export { Fragment } from 'react';
|
|
4
|
+
|
|
5
|
+
type MaybeArray<T> = T | T[];
|
|
6
|
+
declare module '@expressive/mvc' {
|
|
7
|
+
namespace Model {
|
|
8
|
+
type Render<T extends Model> = (this: T, self: T) => React.ReactNode | null;
|
|
9
|
+
type Props<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>> & {
|
|
10
|
+
children?: MaybeArray<React.ReactNode | Render<T>>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare namespace JSX {
|
|
15
|
+
type ElementType = Model.Type | React.JSX.ElementType;
|
|
16
|
+
type LibraryManagedAttributes<C, P> = C extends new (...args: any[]) => {
|
|
17
|
+
props: infer U;
|
|
18
|
+
} ? U : C extends Model.Type<infer U> ? Model.Props<U> : React.JSX.LibraryManagedAttributes<C, P>;
|
|
19
|
+
interface Element extends React.JSX.Element {
|
|
20
|
+
}
|
|
21
|
+
interface ElementClass extends React.JSX.ElementClass {
|
|
22
|
+
}
|
|
23
|
+
interface ElementAttributesProperty {
|
|
24
|
+
}
|
|
25
|
+
interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {
|
|
26
|
+
}
|
|
27
|
+
interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {
|
|
28
|
+
}
|
|
29
|
+
interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {
|
|
30
|
+
}
|
|
31
|
+
interface IntrinsicElements extends React.JSX.IntrinsicElements {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
declare function createElement(this: (type: React.ElementType, props: Record<string, any>, key?: React.Key, ...rest: any[]) => React.ReactElement, type: React.ElementType, props: Record<string, any>, key?: React.Key, ...args: any[]): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
35
|
+
declare const jsx: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements>, props: Record<string, any>, key?: React.Key | undefined, ...args: any[]) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
36
|
+
declare const jsxs: (type: React.ElementType<any, keyof React.JSX.IntrinsicElements>, props: Record<string, any>, key?: React.Key | undefined, ...args: any[]) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
|
|
37
|
+
|
|
38
|
+
export { JSX, createElement, jsx, jsxs };
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
createElement: () => createElement3,
|
|
35
|
+
jsx: () => jsx2,
|
|
36
|
+
jsxs: () => jsxs2
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(jsx_runtime_exports);
|
|
39
|
+
var import_mvc2 = require("@expressive/mvc");
|
|
40
|
+
var React = __toESM(require("react"));
|
|
41
|
+
var Runtime = __toESM(require("react/jsx-runtime"));
|
|
42
|
+
|
|
43
|
+
// src/context.ts
|
|
44
|
+
var import_mvc = require("@expressive/mvc");
|
|
45
|
+
var import_react = require("react");
|
|
46
|
+
var Lookup = (0, import_react.createContext)(new import_mvc.Context());
|
|
47
|
+
function Provider(props) {
|
|
48
|
+
const ambient = (0, import_react.useContext)(Lookup);
|
|
49
|
+
const context = (0, import_react.useMemo)(() => ambient.push(), [ambient]);
|
|
50
|
+
(0, import_react.useEffect)(() => () => context.pop(), [ambient]);
|
|
51
|
+
context.include(props.for, props.set);
|
|
52
|
+
return (0, import_react.createElement)(Lookup.Provider, {
|
|
53
|
+
key: context.id,
|
|
54
|
+
value: context
|
|
55
|
+
}, props.children);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/jsx-runtime.ts
|
|
59
|
+
var import_react2 = require("react");
|
|
60
|
+
function component(child, key) {
|
|
61
|
+
if (typeof child == "function")
|
|
62
|
+
return React.createElement(() => {
|
|
63
|
+
const self = this.get();
|
|
64
|
+
return child.call(self, self);
|
|
65
|
+
}, { key });
|
|
66
|
+
return child;
|
|
67
|
+
}
|
|
68
|
+
function createElement3(type, props, key, ...args) {
|
|
69
|
+
if (import_mvc2.Model.is(type)) {
|
|
70
|
+
const { children, ...rest } = props;
|
|
71
|
+
return this(Provider, {
|
|
72
|
+
for: type,
|
|
73
|
+
set: rest,
|
|
74
|
+
children: Array.isArray(children) ? children.map(component, type) : component.call(type, children, 0)
|
|
75
|
+
}, key, ...args);
|
|
76
|
+
}
|
|
77
|
+
return this(type, props, key, ...args);
|
|
78
|
+
}
|
|
79
|
+
var jsx2 = createElement3.bind(Runtime.jsx);
|
|
80
|
+
var jsxs2 = createElement3.bind(Runtime.jsxs);
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
Fragment,
|
|
84
|
+
createElement,
|
|
85
|
+
jsx,
|
|
86
|
+
jsxs
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=jsx-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport * as React from 'react';\nimport * as Runtime from 'react/jsx-runtime';\n\nimport { Provider } from './context';\n\ntype MaybeArray<T> = T | T[];\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type Render<T extends Model> = (this: T, self: T) => React.ReactNode | null;\n\n type Props<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>> & {\n children?: MaybeArray<React.ReactNode | Render<T>>;\n }\n }\n}\n\nexport declare namespace JSX {\n type ElementType = Model.Type | React.JSX.ElementType;\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 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 component<T extends Model>(\n this: Model.Type<T>,\n child: React.ReactNode | Model.Render<T>,\n key: number){\n\n if(typeof child == 'function')\n return React.createElement(() => {\n const self = this.get();\n return child.call(self, self);\n }, { key });\n\n return child;\n}\n\nexport function createElement(\n this: (\n type: React.ElementType,\n props: Record<string, any>,\n key?: React.Key,\n ...rest: any[]\n ) => React.ReactElement,\n type: React.ElementType,\n props: Record<string, any>,\n key?: React.Key,\n ...args: any[]){\n\n if(Model.is(type)){\n const { children, ...rest } = props;\n\n return this(Provider, {\n for: type,\n set: rest,\n children: Array.isArray(children) ?\n children.map(component, type) :\n component.call(type, children, 0)\n }, key, ...args);\n }\n\n return this(type, props, key, ...args);\n}\n\nexport const jsx = createElement.bind(Runtime.jsx);\nexport const jsxs = createElement.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";","import Model, { Context } from '@expressive/mvc';\nimport { ReactNode, createContext, createElement, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\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 set?: Model.Assign<T>;\n children?: ReactNode;\n }\n}\n\nfunction Provider<T extends Model>(props: Provider.Props<T>){\n const ambient = useContext(Lookup);\n const context = useMemo(() => ambient.push(), [ambient]);\n\n useEffect(() => () => context.pop(), [ambient]);\n \n context.include(props.for, props.set);\n\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context\n }, props.children);\n}\n\nexport { Consumer, Provider, Lookup as Context }"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,uBAAAA;AAAA,EAAA,WAAAC;AAAA,EAAA,YAAAC;AAAA;AAAA;AAAA,IAAAC,cAAsB;AACtB,YAAuB;AACvB,cAAyB;;;ACFzB,iBAA+B;AAC/B,mBAAwF;AAExF,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AA8B1C,SAAS,SAA0B,OAAyB;AAC1D,QAAM,cAAU,yBAAW,MAAM;AACjC,QAAM,cAAU,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC;AAEvD,8BAAU,MAAM,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC;AAE9C,UAAQ,QAAQ,MAAM,KAAK,MAAM,GAAG;AAEpC,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,EACT,GAAG,MAAM,QAAQ;AACnB;;;ADsCA,IAAAC,gBAAyB;AA5CzB,SAAS,UAEP,OACA,KAAY;AAEZ,MAAG,OAAO,SAAS;AACjB,WAAa,oBAAc,MAAM;AAC/B,YAAM,OAAO,KAAK,IAAI;AACtB,aAAO,MAAM,KAAK,MAAM,IAAI;AAAA,IAC9B,GAAG,EAAE,IAAI,CAAC;AAEZ,SAAO;AACT;AAEO,SAASC,eAOd,MACA,OACA,QACG,MAAY;AAEf,MAAG,kBAAM,GAAG,IAAI,GAAE;AAChB,UAAM,EAAE,UAAU,GAAG,KAAK,IAAI;AAE9B,WAAO,KAAK,UAAU;AAAA,MACpB,KAAK;AAAA,MACL,KAAK;AAAA,MACL,UAAU,MAAM,QAAQ,QAAQ,IAC9B,SAAS,IAAI,WAAW,IAAI,IAC5B,UAAU,KAAK,MAAM,UAAU,CAAC;AAAA,IACpC,GAAG,KAAK,GAAG,IAAI;AAAA,EACjB;AAEA,SAAO,KAAK,MAAM,OAAO,KAAK,GAAG,IAAI;AACvC;AAEO,IAAMC,OAAMD,eAAc,KAAa,WAAG;AAC1C,IAAME,QAAOF,eAAc,KAAa,YAAI;","names":["createElement","jsx","jsxs","import_mvc","import_react","createElement","jsx","jsxs"]}
|
package/package.json
CHANGED
|
@@ -28,6 +28,16 @@
|
|
|
28
28
|
"types": "./dist/adapter.d.ts",
|
|
29
29
|
"require": "./dist/adapter.js",
|
|
30
30
|
"import": "./dist/esm/adapter.js"
|
|
31
|
+
},
|
|
32
|
+
"./jsx-runtime": {
|
|
33
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
34
|
+
"require": "./dist/jsx-runtime.js",
|
|
35
|
+
"import": "./dist/esm/jsx-runtime.js"
|
|
36
|
+
},
|
|
37
|
+
"./jsx-dev-runtime": {
|
|
38
|
+
"types": "./dist/jsx-dev-runtime.d.ts",
|
|
39
|
+
"require": "./dist/jsx-dev-runtime.js",
|
|
40
|
+
"import": "./dist/esm/jsx-dev-runtime.js"
|
|
31
41
|
}
|
|
32
42
|
},
|
|
33
43
|
"files": [
|
|
@@ -39,7 +49,7 @@
|
|
|
39
49
|
"preversion": "npm run test && npm run build"
|
|
40
50
|
},
|
|
41
51
|
"dependencies": {
|
|
42
|
-
"@expressive/mvc": "^0.
|
|
52
|
+
"@expressive/mvc": "^0.55.0"
|
|
43
53
|
},
|
|
44
54
|
"peerDependencies": {
|
|
45
55
|
"react": ">=16.8.0 <19.0.0"
|
|
@@ -57,6 +67,6 @@
|
|
|
57
67
|
"react-test-renderer": "^18.2.0",
|
|
58
68
|
"tsup": "^8.0.2"
|
|
59
69
|
},
|
|
60
|
-
"version": "0.
|
|
61
|
-
"gitHead": "
|
|
70
|
+
"version": "0.55.0",
|
|
71
|
+
"gitHead": "286c709fc8238f010f5e5ac32b4dbd709bdc79dc"
|
|
62
72
|
}
|