@expressive/react 0.56.0 → 0.57.1

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.
@@ -10,14 +10,12 @@ function Provider(props) {
10
10
  const context = useMemo(() => ambient.push(), [ambient]);
11
11
  useEffect(() => () => context.pop(), [ambient]);
12
12
  context.include(props.for, (model) => {
13
- if ("forEach" in props && props.forEach) {
13
+ if ("set" in props)
14
+ throw new Error(`The \`set\` prop is deprecated. Use \`forEach\` or <${model.constructor} {...props} /> instead.`);
15
+ if (props.forEach) {
14
16
  const cleanup = props.forEach(model);
15
17
  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];
18
+ model.set(null, cleanup);
21
19
  }
22
20
  });
23
21
  return createElement(Lookup.Provider, {
@@ -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 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":[]}
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 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,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;AAUA,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;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,EACF,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 CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  has
13
13
  } from "@expressive/mvc";
14
14
  import { Consumer, Provider } from "./context";
15
+ import { Fragment, createElement } from "react";
15
16
  Pragma.useContext = () => useContext(Context);
16
17
  Pragma.useLifecycle = (callback) => useEffect(() => callback(), []);
17
18
  Pragma.useFactory = (factory) => {
@@ -22,8 +23,10 @@ Pragma.useFactory = (factory) => {
22
23
  };
23
24
  export {
24
25
  Consumer,
26
+ Fragment,
25
27
  Model,
26
28
  Provider,
29
+ createElement,
27
30
  Model2 as default,
28
31
  get,
29
32
  has,
@@ -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 };\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"]}
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 { Fragment, createElement } from 'react';\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;AACnC,SAAS,UAAU,qBAAqB;AAlBxC,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"]}
@@ -4,13 +4,16 @@ import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { Provider } from "./context";
5
5
  import { Fragment } from "react";
6
6
  function Render(props) {
7
+ const { is, ...rest } = props;
7
8
  return jsx(Provider, {
8
9
  for: this,
9
- set: props,
10
- forEach: props.is,
10
+ forEach: is,
11
11
  children: jsx(() => {
12
12
  const self = this.get();
13
13
  const { render } = self;
14
+ for (const key in rest)
15
+ if (key in self)
16
+ self[key] = rest[key];
14
17
  if (render)
15
18
  return jsx(() => {
16
19
  const self2 = this.get();
@@ -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 /** 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"]}
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 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;AAuHzB,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"]}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import Model, { Context } from '@expressive/mvc';
3
3
  export { Model, Model as default, get, has, ref, set, use } from '@expressive/mvc';
4
4
  import * as react from 'react';
5
5
  import { ReactNode } from 'react';
6
+ export { Fragment, createElement } from 'react';
6
7
 
7
8
  declare namespace Consumer {
8
9
  type Props<T extends Model> = {
@@ -20,18 +21,11 @@ declare namespace Consumer {
20
21
  }
21
22
  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
23
  declare namespace Provider {
23
- interface SetProps<T extends Model> {
24
+ interface Props<T extends Model> {
24
25
  for: Context.Accept<T>;
25
- /** @deprecated May be removed in future versions. Use component Models instead. */
26
- set?: Model.Assign<T>;
26
+ forEach?: Context.Expect<T>;
27
27
  children?: ReactNode;
28
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>;
35
29
  }
36
30
  declare function Provider<T extends Model>(props: Provider.Props<T>): react.FunctionComponentElement<react.ProviderProps<Context>>;
37
31
 
package/dist/index.js CHANGED
@@ -21,8 +21,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  Consumer: () => Consumer,
24
+ Fragment: () => import_react3.Fragment,
24
25
  Model: () => import_mvc2.Model,
25
26
  Provider: () => Provider,
27
+ createElement: () => import_react3.createElement,
26
28
  default: () => import_mvc2.Model,
27
29
  get: () => import_mvc2.get,
28
30
  has: () => import_mvc2.has,
@@ -46,14 +48,12 @@ function Provider(props) {
46
48
  const context = (0, import_react.useMemo)(() => ambient.push(), [ambient]);
47
49
  (0, import_react.useEffect)(() => () => context.pop(), [ambient]);
48
50
  context.include(props.for, (model) => {
49
- if ("forEach" in props && props.forEach) {
51
+ if ("set" in props)
52
+ throw new Error(`The \`set\` prop is deprecated. Use \`forEach\` or <${model.constructor} {...props} /> instead.`);
53
+ if (props.forEach) {
50
54
  const cleanup = props.forEach(model);
51
55
  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];
56
+ model.set(null, cleanup);
57
57
  }
58
58
  });
59
59
  return (0, import_react.createElement)(Lookup.Provider, {
@@ -64,6 +64,7 @@ function Provider(props) {
64
64
 
65
65
  // src/index.ts
66
66
  var import_mvc2 = require("@expressive/mvc");
67
+ var import_react3 = require("react");
67
68
  import_adapter.Pragma.useContext = () => (0, import_react2.useContext)(Lookup);
68
69
  import_adapter.Pragma.useLifecycle = (callback) => (0, import_react2.useEffect)(() => callback(), []);
69
70
  import_adapter.Pragma.useFactory = (factory) => {
@@ -75,8 +76,10 @@ import_adapter.Pragma.useFactory = (factory) => {
75
76
  // Annotate the CommonJS export names for ESM import in node:
76
77
  0 && (module.exports = {
77
78
  Consumer,
79
+ Fragment,
78
80
  Model,
79
81
  Provider,
82
+ createElement,
80
83
  get,
81
84
  has,
82
85
  ref,
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 };\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"]}
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 { Fragment, createElement } from 'react';\nexport { type Pragma };\n","import Model, { Context } from '@expressive/mvc';\nimport { ReactNode, createContext, createElement, useContext, useEffect, useMemo } from 'react';\n\nconst Lookup = createContext(new Context());\n\ndeclare namespace Consumer {\n type Props<T extends Model> = {\n /** Type of controller to fetch from context. */\n for: Model.Type<T>;\n\n /**\n * Render function, will receive instance of desired controller.\n *\n * Called every render of parent component.\n * Similar to `Model.get()`, updates to properties accessed in\n * this function will cause a refresh when they change.\n */\n children: (value: T) => ReactNode | void;\n }\n}\n\nfunction Consumer<T extends Model>(props: Consumer.Props<T>){\n return props.for.get(i => props.children(i));\n}\n\ndeclare namespace Provider {\n interface Props<T extends Model> {\n for: Context.Accept<T>;\n 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAgD;AAEhD,qBAAuB;;;ACFvB,iBAA+B;AAC/B,mBAAwF;AAExF,IAAM,aAAS,4BAAc,IAAI,mBAAQ,CAAC;AAkB1C,SAAS,SAA0B,OAAyB;AAC1D,SAAO,MAAM,IAAI,IAAI,OAAK,MAAM,SAAS,CAAC,CAAC;AAC7C;AAUA,SAAS,SAA0B,OAAyB;AAC1D,QAAM,cAAU,yBAAW,MAAM;AACjC,QAAM,cAAU,sBAAQ,MAAM,QAAQ,KAAK,GAAG,CAAC,OAAO,CAAC;AAEvD,8BAAU,MAAM,MAAM,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC;AAE9C,UAAQ,QAAQ,MAAM,KAAK,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,EACF,CAAC;AAED,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,EACT,GAAG,MAAM,QAAQ;AACnB;;;ADvCA,IAAAC,cAGO;AAGP,IAAAC,gBAAwC;AAlBxC,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","import_react"]}
@@ -38,14 +38,12 @@ function Provider(props) {
38
38
  const context = (0, import_react.useMemo)(() => ambient.push(), [ambient]);
39
39
  (0, import_react.useEffect)(() => () => context.pop(), [ambient]);
40
40
  context.include(props.for, (model) => {
41
- if ("forEach" in props && props.forEach) {
41
+ if ("set" in props)
42
+ throw new Error(`The \`set\` prop is deprecated. Use \`forEach\` or <${model.constructor} {...props} /> instead.`);
43
+ if (props.forEach) {
42
44
  const cleanup = props.forEach(model);
43
45
  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];
46
+ model.set(null, cleanup);
49
47
  }
50
48
  });
51
49
  return (0, import_react.createElement)(Lookup.Provider, {
@@ -57,13 +55,16 @@ function Provider(props) {
57
55
  // src/jsx-runtime.ts
58
56
  var import_react2 = require("react");
59
57
  function Render(props) {
58
+ const { is, ...rest } = props;
60
59
  return (0, import_jsx_runtime.jsx)(Provider, {
61
60
  for: this,
62
- set: props,
63
- forEach: props.is,
61
+ forEach: is,
64
62
  children: (0, import_jsx_runtime.jsx)(() => {
65
63
  const self = this.get();
66
64
  const { render } = self;
65
+ for (const key in rest)
66
+ if (key in self)
67
+ self[key] = rest[key];
67
68
  if (render)
68
69
  return (0, import_jsx_runtime.jsx)(() => {
69
70
  const self2 = this.get();
@@ -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 /** 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,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;;;ADmDA,IAAAC,gBAAyB;AAjEzB,SAAS,OAEP,OACD;AACC,aAAO,wBAAI,UAAU;AAAA,IACnB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,SAAS,MAAM;AAAA,IACf,cAAU,wBAAI,MAAM;AAClB,YAAM,OAAO,KAAK,IAAI;AACtB,YAAM,EAAE,OAAO,IAAI;AAEnB,UAAG;AACD,mBAAO,wBAAI,MAAM;AACf,gBAAMC,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,iBAAO,wBAAI,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,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"]}
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 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,EACF,CAAC;AAED,aAAO,4BAAc,OAAO,UAAU;AAAA,IACpC,KAAK,QAAQ;AAAA,IACb,OAAO;AAAA,EACT,GAAG,MAAM,QAAQ;AACnB;;;ADkEA,IAAAC,gBAAyB;AAtEzB,SAAS,OAEP,OACD;AACC,QAAM,EAAE,IAAI,GAAG,KAAK,IAAI;AAExB,aAAO,wBAAI,UAAU;AAAA,IACnB,KAAK;AAAA,IACL,SAAS;AAAA,IACT,cAAU,wBAAI,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,mBAAO,wBAAI,MAAM;AACf,gBAAMC,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,iBAAO,wBAAI,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,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
@@ -49,7 +49,7 @@
49
49
  "preversion": "npm run test && npm run build"
50
50
  },
51
51
  "dependencies": {
52
- "@expressive/mvc": "^0.56.0"
52
+ "@expressive/mvc": "^0.57.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": ">=16.8.0 <19.0.0"
@@ -67,6 +67,6 @@
67
67
  "react-test-renderer": "^18.2.0",
68
68
  "tsup": "^8.0.2"
69
69
  },
70
- "version": "0.56.0",
71
- "gitHead": "c53df17507eeb1859d2003a92f739971b8017133"
70
+ "version": "0.57.1",
71
+ "gitHead": "122175f8932a22dce31cc63f9ce8328200d44ab1"
72
72
  }