@expressive/react 0.63.0 → 0.63.2

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.
@@ -1,5 +1,5 @@
1
1
  // src/jsx-runtime.ts
2
- import { Context, Model } from "@expressive/mvc";
2
+ import { Context, METHOD, Model } from "@expressive/mvc";
3
3
  import Runtime from "react/jsx-runtime";
4
4
  import { createProvider } from "./context";
5
5
  import { Fragment } from "react";
@@ -10,10 +10,10 @@ function MC(props) {
10
10
  return props.is(self);
11
11
  });
12
12
  local.set(props);
13
- const render = local.render || props.render;
13
+ const render = METHOD.get(local.render) || props.render;
14
14
  return createProvider(
15
15
  Context.get(local),
16
- render ? render(props, local) : props.children
16
+ render ? render.call(local, props, local) : props.children
17
17
  );
18
18
  }
19
19
  var RENDER = /* @__PURE__ */ new WeakMap();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { Context, Model } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { createProvider } from './context';\n\ndeclare module \"@expressive/mvc\" {\n namespace Model {\n namespace FC {\n type Extends<T extends Model, P extends {} = {}> = Props<T> & P;\n\n export { Extends as Props };\n }\n\n /**\n * Use this to define a component which wraps a Model, intended to forward props.\n * This is to be used explicity, in JSDoc types or type annotations.\n * The second type parameter is additional props the component expects to receive.\n * \n * @example\n * ```tsx\n * import { Model } from '@expressive/react';\n * \n * class MyModel extends Model {\n * foo: string;\n * bar: number;\n * }\n * \n * const MyComponent: Model.FC<MyModel, { label: string }> =\n * ({ label, ...rest }) => (\n * <div>\n * <span>{label}</span>\n * <MyModel {...rest} />\n * </div>\n * );\n * ```\n */\n type FC<T extends Model, P extends {} = {}> = React.FC<FC.Props<T, P>>;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: HasProps<this>, self: this): React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void | (() => void);\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n }\n\n type HasProps<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>>;\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & P\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nexport declare namespace JSX {\n type ElementType = \n | Model.Type<Model.Compat>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U } ? U :\n C extends Model.Type<infer U> ? Model.Props<U> :\n React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n // This is a hack to make TypeScript happy - React one insists on `props` property existing.\n // I await the \"Find Out\" phase of this experiment in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nfunction MC<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n const local = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props as Model.Assign<T>);\n\n const render = local.render || props.render;\n\n return createProvider(\n Context.get(local)!,\n render ? render(props as Model.HasProps<T>, local) : props.children\n );\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function compat(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | Model.Init, ...args: any[]): React.ReactElement {\n\n if(typeof type == \"function\")\n if(RENDER.has(type))\n type = RENDER.get(type)!;\n else if(typeof type == \"function\")\n RENDER.set(type, type = (\n type.prototype instanceof Model ?\n MC.bind(type as Model.Init) :\n type as React.ComponentType\n ));\n\n return this(type, ...args);\n}\n\nexport const jsx = compat.bind(Runtime.jsx);\nexport const jsxs = compat.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";"],"mappings":";AAAA,SAAS,SAAS,aAAa;AAE/B,OAAO,aAAa;AAEpB,SAAS,sBAAsB;AA8H/B,SAAS,gBAAgB;AA3CzB,SAAS,GAEP,OACA;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG,MAAM;AACP,aAAO,MAAM,GAAG,IAAI;AAAA,EACxB,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,MAAM,UAAU,MAAM;AAErC,SAAO;AAAA,IACL,QAAQ,IAAI,KAAK;AAAA,IACjB,SAAS,OAAO,OAA4B,KAAK,IAAI,MAAM;AAAA,EAC7D;AACF;AAEA,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,OAEd,SAAyC,MAAiC;AAE1E,MAAG,OAAO,QAAQ;AAChB,QAAG,OAAO,IAAI,IAAI;AAChB,aAAO,OAAO,IAAI,IAAI;AAAA,aAChB,OAAO,QAAQ;AACrB,aAAO,IAAI,MAAM,OACf,KAAK,qBAAqB,QACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,QAAQ,IAAI;","names":[]}
1
+ {"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { Context, METHOD, Model } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { createProvider } from './context';\n\ndeclare module \"@expressive/mvc\" {\n namespace Model {\n namespace FC {\n type Extends<T extends Model, P extends {} = {}> = Props<T> & P;\n\n export { Extends as Props };\n }\n\n /**\n * Use this to define a component which wraps a Model, intended to forward props.\n * This is to be used explicity, in JSDoc types or type annotations.\n * The second type parameter is additional props the component expects to receive.\n * \n * @example\n * ```tsx\n * import { Model } from '@expressive/react';\n * \n * class MyModel extends Model {\n * foo: string;\n * bar: number;\n * }\n * \n * const MyComponent: Model.FC<MyModel, { label: string }> =\n * ({ label, ...rest }) => (\n * <div>\n * <span>{label}</span>\n * <MyModel {...rest} />\n * </div>\n * );\n * ```\n */\n type FC<T extends Model, P extends {} = {}> = React.FC<FC.Props<T, P>>;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: HasProps<this>, self: this): React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void | (() => void);\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n }\n\n type HasProps<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>>;\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & P\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nexport declare namespace JSX {\n type ElementType = \n | Model.Type<Model.Compat>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U } ? U :\n C extends Model.Type<infer U> ? Model.Props<U> :\n React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n // This is a hack to make TypeScript happy - React one insists on `props` property existing.\n // I await the \"Find Out\" phase of this experiment in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nfunction MC<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n const local = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props as Model.Assign<T>);\n\n const render = METHOD.get(local.render) || props.render;\n\n return createProvider(\n Context.get(local)!,\n render ? render.call(local, props as Model.HasProps<T>, local) : props.children\n );\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function compat(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | Model.Init, ...args: any[]): React.ReactElement {\n\n if(typeof type == \"function\")\n if(RENDER.has(type))\n type = RENDER.get(type)!;\n else if(typeof type == \"function\")\n RENDER.set(type, type = (\n type.prototype instanceof Model ?\n MC.bind(type as Model.Init) :\n type as React.ComponentType\n ));\n\n return this(type, ...args);\n}\n\nexport const jsx = compat.bind(Runtime.jsx);\nexport const jsxs = compat.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";"],"mappings":";AAAA,SAAS,SAAS,QAAQ,aAAa;AAEvC,OAAO,aAAa;AAEpB,SAAS,sBAAsB;AA8H/B,SAAS,gBAAgB;AA3CzB,SAAS,GAEP,OACA;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG,MAAM;AACP,aAAO,MAAM,GAAG,IAAI;AAAA,EACxB,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,OAAO,IAAI,MAAM,MAAM,KAAK,MAAM;AAEjD,SAAO;AAAA,IACL,QAAQ,IAAI,KAAK;AAAA,IACjB,SAAS,OAAO,KAAK,OAAO,OAA4B,KAAK,IAAI,MAAM;AAAA,EACzE;AACF;AAEA,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,OAEd,SAAyC,MAAiC;AAE1E,MAAG,OAAO,QAAQ;AAChB,QAAG,OAAO,IAAI,IAAI;AAChB,aAAO,OAAO,IAAI,IAAI;AAAA,aAChB,OAAO,QAAQ;AACrB,aAAO,IAAI,MAAM,OACf,KAAK,qBAAqB,QACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,QAAQ,IAAI;","names":[]}
@@ -64,10 +64,10 @@ function MC(props) {
64
64
  return props.is(self);
65
65
  });
66
66
  local.set(props);
67
- const render = local.render || props.render;
67
+ const render = import_mvc2.METHOD.get(local.render) || props.render;
68
68
  return createProvider(
69
69
  import_mvc2.Context.get(local),
70
- render ? render(props, local) : props.children
70
+ render ? render.call(local, props, local) : props.children
71
71
  );
72
72
  }
73
73
  var RENDER = /* @__PURE__ */ new WeakMap();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { Context, Model } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { createProvider } from './context';\n\ndeclare module \"@expressive/mvc\" {\n namespace Model {\n namespace FC {\n type Extends<T extends Model, P extends {} = {}> = Props<T> & P;\n\n export { Extends as Props };\n }\n\n /**\n * Use this to define a component which wraps a Model, intended to forward props.\n * This is to be used explicity, in JSDoc types or type annotations.\n * The second type parameter is additional props the component expects to receive.\n * \n * @example\n * ```tsx\n * import { Model } from '@expressive/react';\n * \n * class MyModel extends Model {\n * foo: string;\n * bar: number;\n * }\n * \n * const MyComponent: Model.FC<MyModel, { label: string }> =\n * ({ label, ...rest }) => (\n * <div>\n * <span>{label}</span>\n * <MyModel {...rest} />\n * </div>\n * );\n * ```\n */\n type FC<T extends Model, P extends {} = {}> = React.FC<FC.Props<T, P>>;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: HasProps<this>, self: this): React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void | (() => void);\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n }\n\n type HasProps<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>>;\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & P\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nexport declare namespace JSX {\n type ElementType = \n | Model.Type<Model.Compat>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U } ? U :\n C extends Model.Type<infer U> ? Model.Props<U> :\n React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n // This is a hack to make TypeScript happy - React one insists on `props` property existing.\n // I await the \"Find Out\" phase of this experiment in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nfunction MC<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n const local = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props as Model.Assign<T>);\n\n const render = local.render || props.render;\n\n return createProvider(\n Context.get(local)!,\n render ? render(props as Model.HasProps<T>, local) : props.children\n );\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function compat(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | Model.Init, ...args: any[]): React.ReactElement {\n\n if(typeof type == \"function\")\n if(RENDER.has(type))\n type = RENDER.get(type)!;\n else if(typeof type == \"function\")\n RENDER.set(type, type = (\n type.prototype instanceof Model ?\n MC.bind(type as Model.Init) :\n type as React.ComponentType\n ));\n\n return this(type, ...args);\n}\n\nexport const jsx = compat.bind(Runtime.jsx);\nexport const jsxs = compat.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";","import Model, { Context } from '@expressive/mvc';\nimport { createContext, createElement, ReactNode, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\n\ndeclare module '@expressive/mvc' {\n namespace Context {\n function use(create?: true): Context;\n function use(create: boolean): Context | null | undefined;\n }\n}\n\nContext.use = (create?: boolean) => {\n const ambient = useContext(Lookup);\n\n return create ?\n useMemo(() => ambient.push(), []) :\n ambient;\n}\n\ndeclare namespace Consumer {\n type Props<T extends Model> = {\n /** Type of controller to fetch from context. */\n for: Model.Type<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `Model.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n }\n}\n\nfunction Consumer<T extends Model>(props: Consumer.Props<T>){\n return props.for.get(i => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends Model> {\n for: Context.Accept<T>;\n forEach?: Context.Expect<T>;\n children?: ReactNode;\n }\n}\n\nfunction Provider<T extends Model>(props: Provider.Props<T>){\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.include(props.for, (model) => {\n if(props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.set(null, cleanup);\n }\n });\n\n return createProvider(context, props.children);\n}\n\nexport function createProvider(context: Context, children: ReactNode){\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, Context }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAA+B;AAE/B,yBAAoB;;;ACFpB,iBAA+B;AAC/B,mBAAwF;AAExF,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAS1C,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aACL,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AA+CO,SAAS,eAAe,SAAkB,UAAoB;AACnE,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;;;AD2DA,IAAAC,gBAAyB;AA3CzB,SAAS,GAEP,OACA;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG,MAAM;AACP,aAAO,MAAM,GAAG,IAAI;AAAA,EACxB,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,MAAM,UAAU,MAAM;AAErC,SAAO;AAAA,IACL,oBAAQ,IAAI,KAAK;AAAA,IACjB,SAAS,OAAO,OAA4B,KAAK,IAAI,MAAM;AAAA,EAC7D;AACF;AAEA,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,OAEd,SAAyC,MAAiC;AAE1E,MAAG,OAAO,QAAQ;AAChB,QAAG,OAAO,IAAI,IAAI;AAChB,aAAO,OAAO,IAAI,IAAI;AAAA,aAChB,OAAO,QAAQ;AACrB,aAAO,IAAI,MAAM,OACf,KAAK,qBAAqB,oBACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,mBAAAC,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,mBAAAA,QAAQ,IAAI;","names":["import_mvc","import_react","Runtime"]}
1
+ {"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { Context, METHOD, Model } from '@expressive/mvc';\nimport React from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { createProvider } from './context';\n\ndeclare module \"@expressive/mvc\" {\n namespace Model {\n namespace FC {\n type Extends<T extends Model, P extends {} = {}> = Props<T> & P;\n\n export { Extends as Props };\n }\n\n /**\n * Use this to define a component which wraps a Model, intended to forward props.\n * This is to be used explicity, in JSDoc types or type annotations.\n * The second type parameter is additional props the component expects to receive.\n * \n * @example\n * ```tsx\n * import { Model } from '@expressive/react';\n * \n * class MyModel extends Model {\n * foo: string;\n * bar: number;\n * }\n * \n * const MyComponent: Model.FC<MyModel, { label: string }> =\n * ({ label, ...rest }) => (\n * <div>\n * <span>{label}</span>\n * <MyModel {...rest} />\n * </div>\n * );\n * ```\n */\n type FC<T extends Model, P extends {} = {}> = React.FC<FC.Props<T, P>>;\n\n /** Model which is not incompatable as Component in React. */\n interface Compat extends Model {\n render?(props: HasProps<this>, self: this): React.ReactNode;\n }\n\n interface BaseProps<T extends Model> {\n /**\n * Callback for newly created instance. Only called once.\n * @returns Callback to run when instance is destroyed.\n */\n is?: (instance: T) => void | (() => void);\n\n render?(props: HasProps<T>, self: T): React.ReactNode;\n }\n\n type HasProps<T extends Model> = Partial<Pick<T, Exclude<keyof T, keyof Model>>>;\n\n type Props<T extends Model> = \n T extends { render(props: infer P, self: any): any }\n ? BaseProps<T> & HasProps<T> & P\n : BaseProps<T> & HasProps<T> & { children?: React.ReactNode };\n }\n}\n\nexport declare namespace JSX {\n type ElementType = \n | Model.Type<Model.Compat>\n | React.JSX.ElementType\n | ((props: {}, ref?: any) => void);\n\n type LibraryManagedAttributes<C, P> =\n // For normal class components, pull from props property explicitly because we dorked up ElementAttributesProperty.\n C extends new (...args: any[]) => { props: infer U } ? U :\n C extends Model.Type<infer U> ? Model.Props<U> :\n React.JSX.LibraryManagedAttributes<C, P>;\n\n interface Element extends React.JSX.Element {}\n interface ElementClass extends React.JSX.ElementClass {}\n // This is a hack to make TypeScript happy - React one insists on `props` property existing.\n // I await the \"Find Out\" phase of this experiment in git issues.\n interface ElementAttributesProperty {}\n interface ElementChildrenAttribute extends React.JSX.ElementChildrenAttribute {}\n\n interface IntrinsicAttributes extends React.JSX.IntrinsicAttributes {}\n interface IntrinsicClassAttributes<T> extends React.JSX.IntrinsicClassAttributes<T> {}\n interface IntrinsicElements extends React.JSX.IntrinsicElements {}\n}\n\nfunction MC<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n const local = this.use((self) => {\n self.set(props as Model.Assign<T>);\n\n if(props.is)\n return props.is(self);\n });\n\n local.set(props as Model.Assign<T>);\n\n const render = METHOD.get(local.render) || props.render;\n\n return createProvider(\n Context.get(local)!,\n render ? render.call(local, props as Model.HasProps<T>, local) : props.children\n );\n}\n\nconst RENDER = new WeakMap<Function, React.ComponentType>();\n\nexport function compat(\n this: (type: React.ElementType, ...args: any[]) => React.ReactElement,\n type: React.ElementType | Model.Init, ...args: any[]): React.ReactElement {\n\n if(typeof type == \"function\")\n if(RENDER.has(type))\n type = RENDER.get(type)!;\n else if(typeof type == \"function\")\n RENDER.set(type, type = (\n type.prototype instanceof Model ?\n MC.bind(type as Model.Init) :\n type as React.ComponentType\n ));\n\n return this(type, ...args);\n}\n\nexport const jsx = compat.bind(Runtime.jsx);\nexport const jsxs = compat.bind(Runtime.jsxs);\n\nexport { Fragment } from \"react\";","import Model, { Context } from '@expressive/mvc';\nimport { createContext, createElement, ReactNode, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\n\ndeclare module '@expressive/mvc' {\n namespace Context {\n function use(create?: true): Context;\n function use(create: boolean): Context | null | undefined;\n }\n}\n\nContext.use = (create?: boolean) => {\n const ambient = useContext(Lookup);\n\n return create ?\n useMemo(() => ambient.push(), []) :\n ambient;\n}\n\ndeclare namespace Consumer {\n type Props<T extends Model> = {\n /** Type of controller to fetch from context. */\n for: Model.Type<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `Model.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n }\n}\n\nfunction Consumer<T extends Model>(props: Consumer.Props<T>){\n return props.for.get(i => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends Model> {\n for: Context.Accept<T>;\n forEach?: Context.Expect<T>;\n children?: ReactNode;\n }\n}\n\nfunction Provider<T extends Model>(props: Provider.Props<T>){\n const context = Context.use(true);\n\n useEffect(() => () => context.pop(), [context]);\n\n context.include(props.for, (model) => {\n if(props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.set(null, cleanup);\n }\n });\n\n return createProvider(context, props.children);\n}\n\nexport function createProvider(context: Context, children: ReactNode){\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context,\n children\n });\n}\n\nexport { Consumer, Provider, Context }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAAuC;AAEvC,yBAAoB;;;ACFpB,iBAA+B;AAC/B,mBAAwF;AAExF,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAS1C,mBAAQ,MAAM,CAAC,WAAqB;AAClC,QAAM,cAAU,yBAAW,MAAM;AAEjC,SAAO,aACL,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,CAAC,IAChC;AACJ;AA+CO,SAAS,eAAe,SAAkB,UAAoB;AACnE,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,IACP;AAAA,EACF,CAAC;AACH;;;AD2DA,IAAAC,gBAAyB;AA3CzB,SAAS,GAEP,OACA;AACA,QAAM,QAAQ,KAAK,IAAI,CAAC,SAAS;AAC/B,SAAK,IAAI,KAAwB;AAEjC,QAAG,MAAM;AACP,aAAO,MAAM,GAAG,IAAI;AAAA,EACxB,CAAC;AAED,QAAM,IAAI,KAAwB;AAElC,QAAM,SAAS,mBAAO,IAAI,MAAM,MAAM,KAAK,MAAM;AAEjD,SAAO;AAAA,IACL,oBAAQ,IAAI,KAAK;AAAA,IACjB,SAAS,OAAO,KAAK,OAAO,OAA4B,KAAK,IAAI,MAAM;AAAA,EACzE;AACF;AAEA,IAAM,SAAS,oBAAI,QAAuC;AAEnD,SAAS,OAEd,SAAyC,MAAiC;AAE1E,MAAG,OAAO,QAAQ;AAChB,QAAG,OAAO,IAAI,IAAI;AAChB,aAAO,OAAO,IAAI,IAAI;AAAA,aAChB,OAAO,QAAQ;AACrB,aAAO,IAAI,MAAM,OACf,KAAK,qBAAqB,oBACxB,GAAG,KAAK,IAAkB,IAC5B,IACD;AAAA;AAEL,SAAO,KAAK,MAAM,GAAG,IAAI;AAC3B;AAEO,IAAM,MAAM,OAAO,KAAK,mBAAAC,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,mBAAAA,QAAQ,IAAI;","names":["import_mvc","import_react","Runtime"]}
package/package.json CHANGED
@@ -49,7 +49,7 @@
49
49
  "preversion": "npm run test && npm run build"
50
50
  },
51
51
  "dependencies": {
52
- "@expressive/mvc": "^0.63.0"
52
+ "@expressive/mvc": "^0.63.2"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": ">=16.8.0 <19.0.0"
@@ -66,6 +66,6 @@
66
66
  "react": "^18.2.0",
67
67
  "tsup": "^8.0.2"
68
68
  },
69
- "version": "0.63.0",
70
- "gitHead": "d80f3cb88d855a34a706c3b3b524c2806ed7f3e8"
69
+ "version": "0.63.2",
70
+ "gitHead": "1e9ec97032ec59d5b93f9db4772149458bf7d11e"
71
71
  }