@expressive/react 0.60.0 → 0.60.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,27 +1,30 @@
1
1
  // src/jsx-runtime.ts
2
2
  import { Model } from "@expressive/mvc";
3
- import React, { isValidElement } from "react";
3
+ import { isValidElement } from "react";
4
4
  import Runtime from "react/jsx-runtime";
5
5
  import { Context, Lookup } from "./context";
6
6
  import { Fragment } from "react";
7
7
  var Ambient = void 0;
8
+ var Children = null;
8
9
  var useContext = Context.use;
9
10
  Context.use = (create) => {
10
11
  if (Ambient || create === false)
11
12
  return Ambient;
12
13
  const context = useContext(create);
13
- if (Ambient === null)
14
+ if (Ambient === null && create)
14
15
  Ambient = context;
15
16
  return context;
16
17
  };
17
18
  function provider(children) {
19
+ if (children === void 0)
20
+ children = Children;
18
21
  if (Ambient && (Array.isArray(children) || isValidElement(children) && children.type !== Lookup.Provider))
19
22
  children = jsx(Lookup.Provider, { value: Ambient, children });
20
23
  Ambient = void 0;
21
24
  return children;
22
25
  }
23
26
  function Component(props) {
24
- Ambient = null;
27
+ Ambient = Children = null;
25
28
  const local = this.use(props.is);
26
29
  const render = props.render || local.render;
27
30
  for (const key in local)
@@ -30,7 +33,7 @@ function Component(props) {
30
33
  return provider(render ? render(props, local) : props.children);
31
34
  }
32
35
  function FC(props, ref) {
33
- Ambient = null;
36
+ Ambient = Children = null;
34
37
  return provider(this(props, ref));
35
38
  }
36
39
  var RENDER = /* @__PURE__ */ new WeakMap();
@@ -39,9 +42,9 @@ function compat(type, ...args) {
39
42
  if (RENDER.has(type))
40
43
  type = RENDER.get(type);
41
44
  else if (typeof type == "function")
42
- RENDER.set(type, type = type.prototype instanceof Model ? Component.bind(type) : type.prototype instanceof React.Component ? type : FC.bind(type));
45
+ RENDER.set(type, type = type.prototype instanceof Model ? Component.bind(type) : type.prototype ? type : FC.bind(type));
43
46
  }
44
- return this(type, ...args);
47
+ return Children = this(type, ...args);
45
48
  }
46
49
  var jsx = compat.bind(Runtime.jsx);
47
50
  var jsxs = compat.bind(Runtime.jsxs);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/jsx-runtime.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport React, { isValidElement } from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { Context, Lookup } 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 = 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\nlet Ambient: Context | null | undefined = undefined;\n\nconst useContext = Context.use;\n\nContext.use = (create?: boolean): any => {\n if(Ambient || create === false)\n return Ambient;\n\n const context = useContext(create);\n\n if(Ambient === null)\n Ambient = context;\n\n return context;\n}\n\nfunction provider(children: React.ReactNode) {\n if(Ambient && (Array.isArray(children) || isValidElement(children) && children.type !== Lookup.Provider))\n children = jsx(Lookup.Provider, { value: Ambient, children });\n\n Ambient = undefined;\n\n return children;\n}\n\nfunction Component<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n Ambient = null;\n const local = this.use(props.is);\n const render = props.render || local.render;\n\n for(const key in local)\n if(key in props)\n local[key] = (props as any)[key];\n\n return provider(render ? render(props, local) : props.children);\n}\n\nfunction FC<T extends {}>(this: React.FC<T>, props: T, ref: any) {\n Ambient = null;\n return provider(this(props, ref));\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 Component.bind(type as Model.Init) :\n type.prototype instanceof React.Component ? \n type as React.ComponentClass :\n FC.bind(type as React.FC)\n ));\n\n return this(type, ...args);\n}\n\nexport const jsx = compat.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3B;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 { Model } from '@expressive/mvc';\nimport React, { isValidElement } from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { Context, Lookup } 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\nlet Ambient: Context | null | undefined = undefined;\nlet Children: React.ReactNode | null = null;\n\nconst useContext = Context.use;\n\nContext.use = (create?: boolean): any => {\n if(Ambient || create === false)\n return Ambient;\n\n const context = useContext(create);\n\n if(Ambient === null && create)\n Ambient = context;\n\n return context;\n}\n\nfunction provider(children: React.ReactNode) {\n if(children === undefined)\n children = Children;\n\n if(Ambient && (Array.isArray(children) || isValidElement(children) && children.type !== Lookup.Provider))\n children = jsx(Lookup.Provider, { value: Ambient, children });\n\n Ambient = undefined;\n\n return children;\n}\n\nfunction Component<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n Ambient = Children = null;\n\n const local = this.use(props.is);\n const render = props.render || local.render;\n\n for(const key in local)\n if(key in props)\n local[key] = (props as any)[key];\n\n return provider(render ? render(props, local) : props.children);\n}\n\nfunction FC<T extends {}>(this: React.FC<T>, props: T, ref: any) {\n Ambient = Children = null;\n return provider(this(props, ref));\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 Component.bind(type as Model.Init) :\n type.prototype ? \n type as React.ComponentType :\n FC.bind(type as React.FC)\n ));\n\n return Children = 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,aAAa;AACtB,SAAgB,sBAAsB;AACtC,OAAO,aAAa;AAEpB,SAAS,SAAS,cAAc;AA6JhC,SAAS,gBAAgB;AA1EzB,IAAI,UAAsC;AAC1C,IAAI,WAAmC;AAEvC,IAAM,aAAa,QAAQ;AAE3B,QAAQ,MAAM,CAAC,WAA0B;AACvC,MAAG,WAAW,WAAW;AACvB,WAAO;AAET,QAAM,UAAU,WAAW,MAAM;AAEjC,MAAG,YAAY,QAAQ;AACrB,cAAU;AAEZ,SAAO;AACT;AAEA,SAAS,SAAS,UAA2B;AAC3C,MAAG,aAAa;AACd,eAAW;AAEb,MAAG,YAAY,MAAM,QAAQ,QAAQ,KAAK,eAAe,QAAQ,KAAK,SAAS,SAAS,OAAO;AAC7F,eAAW,IAAI,OAAO,UAAU,EAAE,OAAO,SAAS,SAAS,CAAC;AAE9D,YAAU;AAEV,SAAO;AACT;AAEA,SAAS,UAEP,OACA;AACA,YAAU,WAAW;AAErB,QAAM,QAAQ,KAAK,IAAI,MAAM,EAAE;AAC/B,QAAM,SAAS,MAAM,UAAU,MAAM;AAErC,aAAU,OAAO;AACf,QAAG,OAAO;AACR,YAAM,GAAG,IAAK,MAAc,GAAG;AAEnC,SAAO,SAAS,SAAS,OAAO,OAAO,KAAK,IAAI,MAAM,QAAQ;AAChE;AAEA,SAAS,GAAoC,OAAU,KAAU;AAC/D,YAAU,WAAW;AACrB,SAAO,SAAS,KAAK,OAAO,GAAG,CAAC;AAClC;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,UAAU,KAAK,IAAkB,IACnC,KAAK,YACH,OACA,GAAG,KAAK,IAAgB,CAC3B;AAAA;AAEL,SAAO,WAAW,KAAK,MAAM,GAAG,IAAI;AACtC;AAEO,IAAM,MAAM,OAAO,KAAK,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,QAAQ,IAAI;","names":[]}
@@ -53,7 +53,7 @@ declare module "@expressive/mvc" {
53
53
  }
54
54
  }
55
55
  declare namespace JSX {
56
- type ElementType = Model.Type<Model.Compat> | React__default.JSX.ElementType;
56
+ type ElementType = Model.Type<Model.Compat> | React__default.JSX.ElementType | ((props: {}, ref?: any) => void);
57
57
  type LibraryManagedAttributes<C, P> = C extends new (...args: any[]) => {
58
58
  props: infer U;
59
59
  } ? U : C extends Model.Type<infer U> ? Model.Props<U> : React__default.JSX.LibraryManagedAttributes<C, P>;
@@ -73,7 +73,7 @@ declare namespace JSX {
73
73
  }
74
74
  }
75
75
  declare function compat(this: (type: React__default.ElementType, ...args: any[]) => React__default.ReactElement, type: React__default.ElementType | Model.Init, ...args: any[]): React__default.ReactElement;
76
- declare const jsx: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
77
- declare const jsxs: (type: React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements> | Model.Init<Model>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
76
+ declare const jsx: (type: Model.Init<Model> | React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
77
+ declare const jsxs: (type: Model.Init<Model> | React__default.ElementType<any, keyof React__default.JSX.IntrinsicElements>, ...args: any[]) => React__default.ReactElement<any, string | React__default.JSXElementConstructor<any>>;
78
78
 
79
79
  export { JSX, compat, jsx, jsxs };
@@ -37,7 +37,7 @@ __export(jsx_runtime_exports, {
37
37
  });
38
38
  module.exports = __toCommonJS(jsx_runtime_exports);
39
39
  var import_mvc2 = require("@expressive/mvc");
40
- var import_react2 = __toESM(require("react"));
40
+ var import_react2 = require("react");
41
41
  var import_jsx_runtime = __toESM(require("react/jsx-runtime"));
42
42
 
43
43
  // src/context.ts
@@ -52,23 +52,26 @@ import_mvc.Context.use = (create) => {
52
52
  // src/jsx-runtime.ts
53
53
  var import_react3 = require("react");
54
54
  var Ambient = void 0;
55
+ var Children = null;
55
56
  var useContext2 = import_mvc.Context.use;
56
57
  import_mvc.Context.use = (create) => {
57
58
  if (Ambient || create === false)
58
59
  return Ambient;
59
60
  const context = useContext2(create);
60
- if (Ambient === null)
61
+ if (Ambient === null && create)
61
62
  Ambient = context;
62
63
  return context;
63
64
  };
64
65
  function provider(children) {
66
+ if (children === void 0)
67
+ children = Children;
65
68
  if (Ambient && (Array.isArray(children) || (0, import_react2.isValidElement)(children) && children.type !== Lookup.Provider))
66
69
  children = jsx(Lookup.Provider, { value: Ambient, children });
67
70
  Ambient = void 0;
68
71
  return children;
69
72
  }
70
73
  function Component(props) {
71
- Ambient = null;
74
+ Ambient = Children = null;
72
75
  const local = this.use(props.is);
73
76
  const render = props.render || local.render;
74
77
  for (const key in local)
@@ -77,7 +80,7 @@ function Component(props) {
77
80
  return provider(render ? render(props, local) : props.children);
78
81
  }
79
82
  function FC(props, ref) {
80
- Ambient = null;
83
+ Ambient = Children = null;
81
84
  return provider(this(props, ref));
82
85
  }
83
86
  var RENDER = /* @__PURE__ */ new WeakMap();
@@ -86,9 +89,9 @@ function compat(type, ...args) {
86
89
  if (RENDER.has(type))
87
90
  type = RENDER.get(type);
88
91
  else if (typeof type == "function")
89
- RENDER.set(type, type = type.prototype instanceof import_mvc2.Model ? Component.bind(type) : type.prototype instanceof import_react2.default.Component ? type : FC.bind(type));
92
+ RENDER.set(type, type = type.prototype instanceof import_mvc2.Model ? Component.bind(type) : type.prototype ? type : FC.bind(type));
90
93
  }
91
- return this(type, ...args);
94
+ return Children = this(type, ...args);
92
95
  }
93
96
  var jsx = compat.bind(import_jsx_runtime.default.jsx);
94
97
  var jsxs = compat.bind(import_jsx_runtime.default.jsxs);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport React, { isValidElement } from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { Context, Lookup } 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 = 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\nlet Ambient: Context | null | undefined = undefined;\n\nconst useContext = Context.use;\n\nContext.use = (create?: boolean): any => {\n if(Ambient || create === false)\n return Ambient;\n\n const context = useContext(create);\n\n if(Ambient === null)\n Ambient = context;\n\n return context;\n}\n\nfunction provider(children: React.ReactNode) {\n if(Ambient && (Array.isArray(children) || isValidElement(children) && children.type !== Lookup.Provider))\n children = jsx(Lookup.Provider, { value: Ambient, children });\n\n Ambient = undefined;\n\n return children;\n}\n\nfunction Component<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n Ambient = null;\n const local = this.use(props.is);\n const render = props.render || local.render;\n\n for(const key in local)\n if(key in props)\n local[key] = (props as any)[key];\n\n return provider(render ? render(props, local) : props.children);\n}\n\nfunction FC<T extends {}>(this: React.FC<T>, props: T, ref: any) {\n Ambient = null;\n return provider(this(props, ref));\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 Component.bind(type as Model.Init) :\n type.prototype instanceof React.Component ? \n type as React.ComponentClass :\n FC.bind(type as React.FC)\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 { ReactNode, createContext, createElement, 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 createElement(Lookup.Provider, {\n key: context.id,\n value: context\n }, props.children);\n}\n\nexport { Consumer, Provider, Lookup, Context }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,cAAsB;AACtB,IAAAC,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,oBACxB,UAAU,KAAK,IAAkB,IACnC,KAAK,qBAAqB,cAAAC,QAAM,YAC9B,OACA,GAAG,KAAK,IAAgB,CAC3B;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","import_react","useContext","React","Runtime"]}
1
+ {"version":3,"sources":["../src/jsx-runtime.ts","../src/context.ts"],"sourcesContent":["import { Model } from '@expressive/mvc';\nimport React, { isValidElement } from 'react';\nimport Runtime from 'react/jsx-runtime';\n\nimport { Context, Lookup } 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\nlet Ambient: Context | null | undefined = undefined;\nlet Children: React.ReactNode | null = null;\n\nconst useContext = Context.use;\n\nContext.use = (create?: boolean): any => {\n if(Ambient || create === false)\n return Ambient;\n\n const context = useContext(create);\n\n if(Ambient === null && create)\n Ambient = context;\n\n return context;\n}\n\nfunction provider(children: React.ReactNode) {\n if(children === undefined)\n children = Children;\n\n if(Ambient && (Array.isArray(children) || isValidElement(children) && children.type !== Lookup.Provider))\n children = jsx(Lookup.Provider, { value: Ambient, children });\n\n Ambient = undefined;\n\n return children;\n}\n\nfunction Component<T extends Model.Compat>(\n this: Model.Init<T>,\n props: Model.Props<T>\n) {\n Ambient = Children = null;\n\n const local = this.use(props.is);\n const render = props.render || local.render;\n\n for(const key in local)\n if(key in props)\n local[key] = (props as any)[key];\n\n return provider(render ? render(props, local) : props.children);\n}\n\nfunction FC<T extends {}>(this: React.FC<T>, props: T, ref: any) {\n Ambient = Children = null;\n return provider(this(props, ref));\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 Component.bind(type as Model.Init) :\n type.prototype ? \n type as React.ComponentType :\n FC.bind(type as React.FC)\n ));\n\n return Children = 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 { ReactNode, createContext, createElement, 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 createElement(Lookup.Provider, {\n key: context.id,\n value: context\n }, props.children);\n}\n\nexport { Consumer, Provider, Lookup, Context }\n"],"m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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,UAAU,KAAK,IAAkB,IACnC,KAAK,YACH,OACA,GAAG,KAAK,IAAgB,CAC3B;AAAA;AAEL,SAAO,WAAW,KAAK,MAAM,GAAG,IAAI;AACtC;AAEO,IAAM,MAAM,OAAO,KAAK,mBAAAC,QAAQ,GAAG;AACnC,IAAM,OAAO,OAAO,KAAK,mBAAAA,QAAQ,IAAI;","names":["import_mvc","import_react","import_react","useContext","Runtime"]}
package/package.json CHANGED
@@ -66,6 +66,6 @@
66
66
  "react": "^18.2.0",
67
67
  "tsup": "^8.0.2"
68
68
  },
69
- "version": "0.60.0",
70
- "gitHead": "a147241b0028524bc6807f233185bda26ae8f969"
69
+ "version": "0.60.2",
70
+ "gitHead": "0dd94a0b662a1a49a9741b6bfcaf076a97bd3184"
71
71
  }