@expressive/react 0.58.3 → 0.58.4

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 +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 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: 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 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 Render<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Assign<T>\n){\n const { is, ...rest } = props;\n\n return jsx(Provider, {\n for: this,\n forEach: is,\n children: jsx(() => {\n const self = this.get();\n const { render } = self;\n \n for(const key in rest)\n if(key in self)\n (self as any)[key] = rest[key];\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;AAsJzB,SAAS,gBAAgB;AAtEzB,SAAS,OAEP,OACD;AACC,QAAM,EAAE,IAAI,GAAG,KAAK,IAAI;AAExB,SAAO,IAAI,UAAU;AAAA,IACnB,KAAK;AAAA,IACL,SAAS;AAAA,IACT,UAAU,IAAI,MAAM;AAClB,YAAM,OAAO,KAAK,IAAI;AACtB,YAAM,EAAE,OAAO,IAAI;AAEnB,iBAAU,OAAO;AACf,YAAG,OAAO;AACR,UAAC,KAAa,GAAG,IAAI,KAAK,GAAG;AAEjC,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"]}
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 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: 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, self: any): 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 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 Render<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Assign<T>\n){\n const { is, ...rest } = props;\n\n return jsx(Provider, {\n for: this,\n forEach: is,\n children: jsx(() => {\n const self = this.get();\n const { render } = self;\n \n for(const key in rest)\n if(key in self)\n (self as any)[key] = rest[key];\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;AAsJzB,SAAS,gBAAgB;AAtEzB,SAAS,OAEP,OACD;AACC,QAAM,EAAE,IAAI,GAAG,KAAK,IAAI;AAExB,SAAO,IAAI,UAAU;AAAA,IACnB,KAAK;AAAA,IACL,SAAS;AAAA,IACT,UAAU,IAAI,MAAM;AAClB,YAAM,OAAO,KAAK,IAAI;AACtB,YAAM,EAAE,OAAO,IAAI;AAEnB,iBAAU,OAAO;AACf,YAAG,OAAO;AACR,UAAC,KAAa,GAAG,IAAI,KAAK,GAAG;AAEjC,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"]}
@@ -39,7 +39,7 @@ declare module '@expressive/mvc' {
39
39
  children?: React.ReactNode;
40
40
  }
41
41
  type Props<T extends Model> = T extends {
42
- render(props: infer P): any;
42
+ render(props: infer P, self: any): any;
43
43
  } ? Partial<Pick<T, Exclude<keyof T, keyof Model | "render">>> & P : Partial<Pick<T, Exclude<keyof T, keyof Model>>> & {
44
44
  children?: React.ReactNode | Render<T>;
45
45
  } & {
@@ -1 +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 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: 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 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 Render<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Assign<T>\n){\n const { is, ...rest } = props;\n\n return jsx(Provider, {\n for: this,\n forEach: is,\n children: jsx(() => {\n const self = this.get();\n const { render } = self;\n \n for(const key in rest)\n if(key in self)\n (self as any)[key] = rest[key];\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 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 ambient = useContext(Lookup);\n const context = useMemo(() => ambient.push(), [ambient]);\n\n useEffect(() => () => context.pop(), [ambient]);\n \n context.include(props.for, (model) => {\n // TODO: remove next minor release\n if(\"set\" in props)\n throw new Error(`The \\`set\\` prop is deprecated. Use \\`forEach\\` or <${model.constructor} {...props} /> instead.`);\n\n if(props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.set(null, cleanup);\n }\n });\n\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context\n }, props.children);\n}\n\nexport { Consumer, Provider, Lookup 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;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,CAAC,UAAU;AAEpC,QAAG,SAAS;AACV,YAAM,IAAI,MAAM,uDAAuD,MAAM,WAAW,yBAAyB;AAEnH,QAAG,MAAM,SAAQ;AACf,YAAM,UAAU,MAAM,QAAQ,KAAK;AAEnC,UAAG;AACD,cAAM,IAAI,MAAM,OAAO;AAAA,IAC3B;AAAA,E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O,KAAK,uBAAI;","names":["import_mvc","import_react","self"]}
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 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: 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, self: any): 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 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 Render<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Assign<T>\n){\n const { is, ...rest } = props;\n\n return jsx(Provider, {\n for: this,\n forEach: is,\n children: jsx(() => {\n const self = this.get();\n const { render } = self;\n \n for(const key in rest)\n if(key in self)\n (self as any)[key] = rest[key];\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 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 ambient = useContext(Lookup);\n const context = useMemo(() => ambient.push(), [ambient]);\n\n useEffect(() => () => context.pop(), [ambient]);\n \n context.include(props.for, (model) => {\n // TODO: remove next minor release\n if(\"set\" in props)\n throw new Error(`The \\`set\\` prop is deprecated. Use \\`forEach\\` or <${model.constructor} {...props} /> instead.`);\n\n if(props.forEach){\n const cleanup = props.forEach(model);\n\n if(cleanup)\n model.set(null, cleanup);\n }\n });\n\n return createElement(Lookup.Provider, {\n key: context.id,\n value: context\n }, props.children);\n}\n\nexport { Consumer, Provider, Lookup 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;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,CAAC,UAAU;AAEpC,QAAG,SAAS;AACV,YAAM,IAAI,MAAM,uDAAuD,MAAM,WAAW,yBAAyB;AAEnH,QAAG,MAAM,SAAQ;AACf,YA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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
@@ -67,6 +67,6 @@
67
67
  "react-test-renderer": "^18.2.0",
68
68
  "tsup": "^8.0.2"
69
69
  },
70
- "version": "0.58.3",
71
- "gitHead": "4db8f8f95f3416dc8f28094b3ff77f72d1920c6b"
70
+ "version": "0.58.4",
71
+ "gitHead": "614b3b4980892b0776e420e68b30d97ddae61ae7"
72
72
  }