@expressive/react 0.54.3 → 0.56.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/context.js +11 -1
- package/dist/esm/context.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 +51 -0
- package/dist/esm/jsx-runtime.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +11 -1
- 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 +50 -0
- package/dist/jsx-runtime.js +105 -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,U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5C,aAAS,YAAe,QAAyC;AAC/D,UAAG,OAAO,UAAU;AAClB,iBAAS,OAAO;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;AA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9,7 +9,17 @@ function Provider(props) {
|
|
|
9
9
|
const ambient = useContext(Lookup);
|
|
10
10
|
const context = useMemo(() => ambient.push(), [ambient]);
|
|
11
11
|
useEffect(() => () => context.pop(), [ambient]);
|
|
12
|
-
context.include(props.for,
|
|
12
|
+
context.include(props.for, (model) => {
|
|
13
|
+
if ("forEach" in props && props.forEach) {
|
|
14
|
+
const cleanup = props.forEach(model);
|
|
15
|
+
if (cleanup)
|
|
16
|
+
model.get(null, cleanup);
|
|
17
|
+
} else if ("set" in props && props.set) {
|
|
18
|
+
for (const key in props.set)
|
|
19
|
+
if (key in model)
|
|
20
|
+
model[key] = props.set[key];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
13
23
|
return createElement(Lookup.Provider, {
|
|
14
24
|
key: context.id,
|
|
15
25
|
value: context
|
package/dist/esm/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context.ts"],"sourcesContent":["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
|
|
1
|
+
{"version":3,"sources":["../../src/context.ts"],"sourcesContent":["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 SetProps<T extends Model> {\n for: Context.Accept<T>;\n /** @deprecated May be removed in future versions. Use component Models instead. */\n set?: Model.Assign<T>;\n children?: ReactNode;\n }\n\n interface NewProps<T extends Model> {\n for: Context.Accept<T>;\n forEach?: Context.Expect;\n children?: ReactNode;\n }\n\n type Props<T extends Model> = SetProps<T> | NewProps<T>;\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 // TODO: Replace with Context.ForEach instead.\n context.include(props.for, (model) => {\n if(\"forEach\" in props && props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.get(null, cleanup);\n }\n else if(\"set\" in props && props.set)\n for(const key in props.set)\n if(key in model)\n (model as any)[key] = props.set[key];\n });\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,SAAgB,eAAe;AAC/B,SAAoB,eAAe,eAAe,YAAY,WAAW,eAAe;AAExF,IAAM,SAAS,cAAc,IAAI,QAAQ,CAAC;AAkB1C,SAAS,SAA0B,OAAyB;AAC1D,SAAO,MAAM,IAAI,IAAI,OAAK,MAAM,SAAS,CAAC,CAAC;AAC7C;AAmBA,SAAS,SAA0B,OAAyB;AAC1D,QAAM,UAAU,WAAW,MAAM;AACjC,QAAM,UAAU,QAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC;AAEvD,YAAU,MAAM,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC;AAG9C,UAAQ,QAAQ,MAAM,KAAK,CAAC,UAAU;AACpC,QAAG,aAAa,SAAS,MAAM,SAAQ;AACrC,YAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,UAAG;AACD,cAAM,IAAI,MAAM,OAAO;AAAA,IAC3B,WACQ,SAAS,SAAS,MAAM;AAC9B,iBAAU,OAAO,MAAM;AACrB,YAAG,OAAO;AACR,UAAC,MAAc,GAAG,IAAI,MAAM,IAAI,GAAG;AAAA;AAAA,EAC3C,CAAC;AAED,SAAO,cAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,EACT,GAAG,MAAM,QAAQ;AACnB;","names":[]}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 }
|
|
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 { create } from "./jsx-runtime";
|
|
4
|
+
import { Fragment } from "react";
|
|
5
|
+
var jsxDEV2 = create.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 { create } from './jsx-runtime';\n\nexport const jsxDEV = create.bind(Runtime.jsxDEV);\n\nexport { type JSX } from './jsx-runtime';\nexport { Fragment } from \"react\";"],"mappings":";AAAA,YAAY,aAAa;AACzB,SAAS,cAAc;AAKvB,SAAS,gBAAgB;AAHlB,IAAMA,UAAS,OAAO,KAAa,cAAM;","names":["jsxDEV"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/jsx-runtime.ts
|
|
2
|
+
import { Model } from "@expressive/mvc";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Provider } from "./context";
|
|
5
|
+
import { Fragment } from "react";
|
|
6
|
+
function Render(props) {
|
|
7
|
+
return jsx(Provider, {
|
|
8
|
+
for: this,
|
|
9
|
+
set: props,
|
|
10
|
+
forEach: props.is,
|
|
11
|
+
children: jsx(() => {
|
|
12
|
+
const self = this.get();
|
|
13
|
+
const { render } = self;
|
|
14
|
+
if (render)
|
|
15
|
+
return jsx(() => {
|
|
16
|
+
const self2 = this.get();
|
|
17
|
+
return render.call(self2, props, self2);
|
|
18
|
+
}, {});
|
|
19
|
+
const { children } = self;
|
|
20
|
+
if (children)
|
|
21
|
+
return children;
|
|
22
|
+
const fn = props.children;
|
|
23
|
+
if (typeof fn != "function")
|
|
24
|
+
return fn;
|
|
25
|
+
return jsx(() => {
|
|
26
|
+
const self2 = this.get();
|
|
27
|
+
return fn.call(self2, self2);
|
|
28
|
+
}, {});
|
|
29
|
+
}, {})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
var RENDER = /* @__PURE__ */ new WeakMap();
|
|
33
|
+
function create(type, props, key, ...args) {
|
|
34
|
+
if (Model.is(type)) {
|
|
35
|
+
const bound = RENDER.get(type);
|
|
36
|
+
if (bound)
|
|
37
|
+
type = bound;
|
|
38
|
+
else
|
|
39
|
+
RENDER.set(type, type = Render.bind(type));
|
|
40
|
+
}
|
|
41
|
+
return this(type, props, key, ...args);
|
|
42
|
+
}
|
|
43
|
+
var jsx2 = create.bind(jsx);
|
|
44
|
+
var jsxs2 = create.bind(jsxs);
|
|
45
|
+
export {
|
|
46
|
+
Fragment,
|
|
47
|
+
create,
|
|
48
|
+
jsx2 as jsx,
|
|
49
|
+
jsxs2 as jsxs
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=jsx-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport { jsx, jsxs } from 'react/jsx-runtime';\n\nimport { Provider } from './context';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type Render<T extends Model> = (this: T, self: T) => React.ReactNode;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: Model.Assign<this>, self: this): React.ReactNode;\n children?: React.ReactNode;\n }\n\n type Props<T extends Model> = \n & T extends { render(props: infer P): any }\n ? Partial<Pick<T, Exclude<keyof T, keyof Model | \"render\">>> & P\n : Partial<Pick<T, Exclude<keyof T, keyof Model>>> & {\n children?: React.ReactNode | Render<T>;\n }\n & {\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 }\n}\n\nexport declare namespace JSX {\n type ElementType = Model.Type<Model.Compat> | 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 Render<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Assign<T>\n){\n return jsx(Provider, {\n for: this,\n set: props,\n forEach: props.is,\n children: jsx(() => {\n const self = this.get();\n const { render } = self;\n\n if(render)\n return jsx(() => {\n const self = this.get();\n return render.call(self, props, self);\n }, {});\n\n const { children } = self;\n\n if(children)\n return children;\n\n const fn = props.children as React.ReactNode | Model.Render<T>;\n\n if(typeof fn != \"function\")\n return fn;\n\n return jsx(() => {\n const self = this.get();\n return fn.call(self, self);\n }, {});\n }, {})\n });\n}\n\nconst RENDER = new WeakMap<typeof Model, React.FC>();\n\nexport function create(\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 bound = RENDER.get(type);\n\n if(bound)\n type = bound;\n else\n RENDER.set(type, type = Render.bind(type as Model.Init));\n }\n \n return this(type, props, key, ...args);\n}\n\nconst jsx2 = create.bind(jsx);\nconst jsxs2 = create.bind(jsxs);\n\nexport { Fragment } from \"react\";\nexport {\n jsx2 as jsx,\n jsxs2 as jsxs\n}"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,KAAK,YAAY;AAE1B,SAAS,gBAAgB;AAkHzB,SAAS,gBAAgB;AAjEzB,SAAS,OAEP,OACD;AACC,SAAO,IAAI,UAAU;AAAA,IACnB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,SAAS,MAAM;AAAA,IACf,UAAU,IAAI,MAAM;AAClB,YAAM,OAAO,KAAK,IAAI;AACtB,YAAM,EAAE,OAAO,IAAI;AAEnB,UAAG;AACD,eAAO,IAAI,MAAM;AACf,gBAAMA,QAAO,KAAK,IAAI;AACtB,iBAAO,OAAO,KAAKA,OAAM,OAAOA,KAAI;AAAA,QACtC,GAAG,CAAC,CAAC;AAEP,YAAM,EAAE,SAAS,IAAI;AAErB,UAAG;AACD,eAAO;AAET,YAAM,KAAK,MAAM;AAEjB,UAAG,OAAO,MAAM;AACd,eAAO;AAET,aAAO,IAAI,MAAM;AACf,cAAMA,QAAO,KAAK,IAAI;AACtB,eAAO,GAAG,KAAKA,OAAMA,KAAI;AAAA,MAC3B,GAAG,CAAC,CAAC;AAAA,IACP,GAAG,CAAC,CAAC;AAAA,EACP,CAAC;AACH;AAEA,IAAM,SAAS,oBAAI,QAAgC;AAE5C,SAAS,OAOd,MACA,OACA,QACG,MAAY;AAEf,MAAG,MAAM,GAAG,IAAI,GAAE;AAChB,UAAM,QAAQ,OAAO,IAAI,IAAI;AAE7B,QAAG;AACD,aAAO;AAAA;AAEP,aAAO,IAAI,MAAM,OAAO,OAAO,KAAK,IAAkB,CAAC;AAAA,EAC3D;AAEA,SAAO,KAAK,MAAM,OAAO,KAAK,GAAG,IAAI;AACvC;AAEA,IAAM,OAAO,OAAO,KAAK,GAAG;AAC5B,IAAM,QAAQ,OAAO,KAAK,IAAI;","names":["self"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -20,11 +20,18 @@ declare namespace Consumer {
|
|
|
20
20
|
}
|
|
21
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
|
-
interface
|
|
23
|
+
interface SetProps<T extends Model> {
|
|
24
24
|
for: Context.Accept<T>;
|
|
25
|
+
/** @deprecated May be removed in future versions. Use component Models instead. */
|
|
25
26
|
set?: Model.Assign<T>;
|
|
26
27
|
children?: ReactNode;
|
|
27
28
|
}
|
|
29
|
+
interface NewProps<T extends Model> {
|
|
30
|
+
for: Context.Accept<T>;
|
|
31
|
+
forEach?: Context.Expect;
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
}
|
|
34
|
+
type Props<T extends Model> = SetProps<T> | NewProps<T>;
|
|
28
35
|
}
|
|
29
36
|
declare function Provider<T extends Model>(props: Provider.Props<T>): react.FunctionComponentElement<react.ProviderProps<Context>>;
|
|
30
37
|
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,17 @@ function Provider(props) {
|
|
|
45
45
|
const ambient = (0, import_react.useContext)(Lookup);
|
|
46
46
|
const context = (0, import_react.useMemo)(() => ambient.push(), [ambient]);
|
|
47
47
|
(0, import_react.useEffect)(() => () => context.pop(), [ambient]);
|
|
48
|
-
context.include(props.for,
|
|
48
|
+
context.include(props.for, (model) => {
|
|
49
|
+
if ("forEach" in props && props.forEach) {
|
|
50
|
+
const cleanup = props.forEach(model);
|
|
51
|
+
if (cleanup)
|
|
52
|
+
model.get(null, cleanup);
|
|
53
|
+
} else if ("set" in props && props.set) {
|
|
54
|
+
for (const key in props.set)
|
|
55
|
+
if (key in model)
|
|
56
|
+
model[key] = props.set[key];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
49
59
|
return (0, import_react.createElement)(Lookup.Provider, {
|
|
50
60
|
key: context.id,
|
|
51
61
|
value: context
|
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 SetProps<T extends Model> {\n for: Context.Accept<T>;\n /** @deprecated May be removed in future versions. Use component Models instead. */\n set?: Model.Assign<T>;\n children?: ReactNode;\n }\n\n interface NewProps<T extends Model> {\n for: Context.Accept<T>;\n forEach?: Context.Expect;\n children?: ReactNode;\n }\n\n type Props<T extends Model> = SetProps<T> | NewProps<T>;\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 // TODO: Replace with Context.ForEach instead.\n context.include(props.for, (model) => {\n if(\"forEach\" in props && props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.get(null, cleanup);\n }\n else if(\"set\" in props && props.set)\n for(const key in props.set)\n if(key in model)\n (model as any)[key] = props.set[key];\n });\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;AAmBA,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;AAG9C,UAAQ,QAAQ,MAAM,KAAK,CAAC,UAAU;AACpC,QAAG,aAAa,SAAS,MAAM,SAAQ;AACrC,YAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,UAAG;AACD,cAAM,IAAI,MAAM,OAAO;AAAA,IAC3B,WACQ,SAAS,SAAS,MAAM;AAC9B,iBAAU,OAAO,MAAM;AACrB,YAAG,OAAO;AACR,UAAC,MAAc,GAAG,IAAI,MAAM,IAAI,GAAG;AAAA;AAAA,EAC3C,CAAC;AAED,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,EACT,GAAG,MAAM,QAAQ;AACnB;;;ADjDA,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.create.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 { create } from './jsx-runtime';\n\nexport const jsxDEV = create.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,yBAAuB;AAKvB,mBAAyB;AAHlB,IAAMA,UAAS,0BAAO,KAAa,cAAM;","names":["jsxDEV"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
export { Fragment } from 'react';
|
|
3
|
+
import { Model } from '@expressive/mvc';
|
|
4
|
+
|
|
5
|
+
declare module '@expressive/mvc' {
|
|
6
|
+
namespace Model {
|
|
7
|
+
type Render<T extends Model> = (this: T, self: T) => React.ReactNode;
|
|
8
|
+
/** Model which is not incompatable as Component in React. */
|
|
9
|
+
interface Compat extends Model {
|
|
10
|
+
render?(props: Model.Assign<this>, self: this): React.ReactNode;
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
type Props<T extends Model> = T extends {
|
|
14
|
+
render(props: infer P): any;
|
|
15
|
+
} ? Partial<Pick<T, Exclude<keyof T, keyof Model | "render">>> & P : Partial<Pick<T, Exclude<keyof T, keyof Model>>> & {
|
|
16
|
+
children?: React.ReactNode | Render<T>;
|
|
17
|
+
} & {
|
|
18
|
+
/**
|
|
19
|
+
* Callback for newly created instance. Only called once.
|
|
20
|
+
* @returns Callback to run when instance is destroyed.
|
|
21
|
+
*/
|
|
22
|
+
is?: (instance: T) => void | (() => void);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
declare namespace JSX {
|
|
27
|
+
type ElementType = Model.Type<Model.Compat> | React.JSX.ElementType;
|
|
28
|
+
type LibraryManagedAttributes<C, P> = C extends new (...args: any[]) => {
|
|
29
|
+
props: infer U;
|
|
30
|
+
} ? U : C extends Model.Type<infer U> ? Model.Props<U> : React.JSX.LibraryManagedAttributes<C, P>;
|
|
31
|
+
interface Element extends React.JSX.Element {
|
|
32
|
+
}
|
|
33
|
+
interface ElementClass extends React.JSX.ElementClass {
|
|
34
|
+
}
|
|
35
|
+
interface ElementAttributesProperty {
|
|
36
|
+
}
|
|
37
|
+
interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {
|
|
38
|
+
}
|
|
39
|
+
interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {
|
|
40
|
+
}
|
|
41
|
+
interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {
|
|
42
|
+
}
|
|
43
|
+
interface IntrinsicElements extends React.JSX.IntrinsicElements {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
declare function create(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>>;
|
|
47
|
+
declare const jsx2: (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>>;
|
|
48
|
+
declare const jsxs2: (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>>;
|
|
49
|
+
|
|
50
|
+
export { JSX, create, jsx2 as jsx, jsxs2 as jsxs };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/jsx-runtime.ts
|
|
21
|
+
var jsx_runtime_exports = {};
|
|
22
|
+
__export(jsx_runtime_exports, {
|
|
23
|
+
Fragment: () => import_react2.Fragment,
|
|
24
|
+
create: () => create,
|
|
25
|
+
jsx: () => jsx2,
|
|
26
|
+
jsxs: () => jsxs2
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(jsx_runtime_exports);
|
|
29
|
+
var import_mvc2 = require("@expressive/mvc");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
|
|
32
|
+
// src/context.ts
|
|
33
|
+
var import_mvc = require("@expressive/mvc");
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var Lookup = (0, import_react.createContext)(new import_mvc.Context());
|
|
36
|
+
function Provider(props) {
|
|
37
|
+
const ambient = (0, import_react.useContext)(Lookup);
|
|
38
|
+
const context = (0, import_react.useMemo)(() => ambient.push(), [ambient]);
|
|
39
|
+
(0, import_react.useEffect)(() => () => context.pop(), [ambient]);
|
|
40
|
+
context.include(props.for, (model) => {
|
|
41
|
+
if ("forEach" in props && props.forEach) {
|
|
42
|
+
const cleanup = props.forEach(model);
|
|
43
|
+
if (cleanup)
|
|
44
|
+
model.get(null, cleanup);
|
|
45
|
+
} else if ("set" in props && props.set) {
|
|
46
|
+
for (const key in props.set)
|
|
47
|
+
if (key in model)
|
|
48
|
+
model[key] = props.set[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return (0, import_react.createElement)(Lookup.Provider, {
|
|
52
|
+
key: context.id,
|
|
53
|
+
value: context
|
|
54
|
+
}, props.children);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/jsx-runtime.ts
|
|
58
|
+
var import_react2 = require("react");
|
|
59
|
+
function Render(props) {
|
|
60
|
+
return (0, import_jsx_runtime.jsx)(Provider, {
|
|
61
|
+
for: this,
|
|
62
|
+
set: props,
|
|
63
|
+
forEach: props.is,
|
|
64
|
+
children: (0, import_jsx_runtime.jsx)(() => {
|
|
65
|
+
const self = this.get();
|
|
66
|
+
const { render } = self;
|
|
67
|
+
if (render)
|
|
68
|
+
return (0, import_jsx_runtime.jsx)(() => {
|
|
69
|
+
const self2 = this.get();
|
|
70
|
+
return render.call(self2, props, self2);
|
|
71
|
+
}, {});
|
|
72
|
+
const { children } = self;
|
|
73
|
+
if (children)
|
|
74
|
+
return children;
|
|
75
|
+
const fn = props.children;
|
|
76
|
+
if (typeof fn != "function")
|
|
77
|
+
return fn;
|
|
78
|
+
return (0, import_jsx_runtime.jsx)(() => {
|
|
79
|
+
const self2 = this.get();
|
|
80
|
+
return fn.call(self2, self2);
|
|
81
|
+
}, {});
|
|
82
|
+
}, {})
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
var RENDER = /* @__PURE__ */ new WeakMap();
|
|
86
|
+
function create(type, props, key, ...args) {
|
|
87
|
+
if (import_mvc2.Model.is(type)) {
|
|
88
|
+
const bound = RENDER.get(type);
|
|
89
|
+
if (bound)
|
|
90
|
+
type = bound;
|
|
91
|
+
else
|
|
92
|
+
RENDER.set(type, type = Render.bind(type));
|
|
93
|
+
}
|
|
94
|
+
return this(type, props, key, ...args);
|
|
95
|
+
}
|
|
96
|
+
var jsx2 = create.bind(import_jsx_runtime.jsx);
|
|
97
|
+
var jsxs2 = create.bind(import_jsx_runtime.jsxs);
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
Fragment,
|
|
101
|
+
create,
|
|
102
|
+
jsx,
|
|
103
|
+
jsxs
|
|
104
|
+
});
|
|
105
|
+
//# 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 { jsx, jsxs } from 'react/jsx-runtime';\n\nimport { Provider } from './context';\n\ndeclare module '@expressive/mvc' {\n namespace Model {\n type Render<T extends Model> = (this: T, self: T) => React.ReactNode;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: Model.Assign<this>, self: this): React.ReactNode;\n children?: React.ReactNode;\n }\n\n type Props<T extends Model> = \n & T extends { render(props: infer P): any }\n ? Partial<Pick<T, Exclude<keyof T, keyof Model | \"render\">>> & P\n : Partial<Pick<T, Exclude<keyof T, keyof Model>>> & {\n children?: React.ReactNode | Render<T>;\n }\n & {\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 }\n}\n\nexport declare namespace JSX {\n type ElementType = Model.Type<Model.Compat> | 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 Render<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Assign<T>\n){\n return jsx(Provider, {\n for: this,\n set: props,\n forEach: props.is,\n children: jsx(() => {\n const self = this.get();\n const { render } = self;\n\n if(render)\n return jsx(() => {\n const self = this.get();\n return render.call(self, props, self);\n }, {});\n\n const { children } = self;\n\n if(children)\n return children;\n\n const fn = props.children as React.ReactNode | Model.Render<T>;\n\n if(typeof fn != \"function\")\n return fn;\n\n return jsx(() => {\n const self = this.get();\n return fn.call(self, self);\n }, {});\n }, {})\n });\n}\n\nconst RENDER = new WeakMap<typeof Model, React.FC>();\n\nexport function create(\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 bound = RENDER.get(type);\n\n if(bound)\n type = bound;\n else\n RENDER.set(type, type = Render.bind(type as Model.Init));\n }\n \n return this(type, props, key, ...args);\n}\n\nconst jsx2 = create.bind(jsx);\nconst jsxs2 = create.bind(jsxs);\n\nexport { Fragment } from \"react\";\nexport {\n jsx2 as jsx,\n jsxs2 as jsxs\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 SetProps<T extends Model> {\n for: Context.Accept<T>;\n /** @deprecated May be removed in future versions. Use component Models instead. */\n set?: Model.Assign<T>;\n children?: ReactNode;\n }\n\n interface NewProps<T extends Model> {\n for: Context.Accept<T>;\n forEach?: Context.Expect;\n children?: ReactNode;\n }\n\n type Props<T extends Model> = SetProps<T> | NewProps<T>;\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 // TODO: Replace with Context.ForEach instead.\n context.include(props.for, (model) => {\n if(\"forEach\" in props && props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.get(null, cleanup);\n }\n else if(\"set\" in props && props.set)\n for(const key in props.set)\n if(key in model)\n (model as any)[key] = props.set[key];\n });\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,IAAAA,cAAsB;AACtB,yBAA0B;;;ACD1B,iBAA+B;AAC/B,mBAAwF;AAExF,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAuC1C,SAAS,SAA0B,OAAyB;AAC1D,QAAM,cAAU,yBAAW,MAAM;AACjC,QAAM,cAAU,sBAAQ,MAAM,QAAQ,KAAK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ACG,MAAY;AAEf,MAAG,kBAAM,GAAG,IAAI,GAAE;AAChB,UAAM,QAAQ,OAAO,IAAI,IAAI;AAE7B,QAAG;AACD,aAAO;AAAA;AAEP,aAAO,IAAI,MAAM,OAAO,OAAO,KAAK,IAAkB,CAAC;AAAA,EAC3D;AAEA,SAAO,KAAK,MAAM,OAAO,KAAK,GAAG,IAAI;AACvC;AAEA,IAAM,OAAO,OAAO,KAAK,sBAAG;AAC5B,IAAM,QAAQ,OAAO,KAAK,uBAAI;","names":["import_mvc","import_react","self"]}
|
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.56.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.56.0",
|
|
71
|
+
"gitHead": "c53df17507eeb1859d2003a92f739971b8017133"
|
|
62
72
|
}
|