@cleanweb/oore 2.0.0-alpha.34 → 2.0.0-alpha.36

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.
Files changed (134) hide show
  1. package/build/base/index.d.ts +3 -3
  2. package/build/base/index.js +19 -3
  3. package/build/base/merged-state.d.ts +1 -0
  4. package/build/base/merged-state.js +58 -30
  5. package/build/base/methods.d.ts +6 -5
  6. package/build/base/methods.js +28 -19
  7. package/build/base/state/class-types.d.ts +2 -2
  8. package/build/base/state/class-types.js +2 -1
  9. package/build/base/state/class.d.ts +1 -1
  10. package/build/base/state/class.js +72 -45
  11. package/build/base/state/hook-types.d.ts +1 -1
  12. package/build/base/state/hook-types.js +2 -1
  13. package/build/base/state/hooks.d.ts +1 -1
  14. package/build/base/state/hooks.js +16 -8
  15. package/build/base/state/index.d.ts +6 -5
  16. package/build/base/state/index.js +32 -3
  17. package/build/classy/class/index.d.ts +5 -18
  18. package/build/classy/class/index.js +87 -98
  19. package/build/classy/class/types/extractor.d.ts +1 -1
  20. package/build/classy/class/types/extractor.js +2 -1
  21. package/build/classy/class/utils/function-name.js +5 -1
  22. package/build/classy/index.d.ts +3 -3
  23. package/build/classy/index.js +19 -3
  24. package/build/classy/instance/index.d.ts +4 -4
  25. package/build/classy/instance/index.js +88 -58
  26. package/build/classy/instance/mount-callbacks.d.ts +1 -1
  27. package/build/classy/instance/mount-callbacks.js +12 -8
  28. package/build/classy/instance/types/hook.d.ts +1 -1
  29. package/build/classy/instance/types/hook.js +2 -1
  30. package/build/classy/logic/index.d.ts +2 -2
  31. package/build/classy/logic/index.js +32 -22
  32. package/build/classy/logic/types/hook.d.ts +1 -1
  33. package/build/classy/logic/types/hook.js +2 -1
  34. package/build/docs-src/api/base-classes.d.ts +3 -3
  35. package/build/docs-src/api/base-classes.js +9 -3
  36. package/build/docs-src/api/index.d.ts +8 -8
  37. package/build/docs-src/api/index.js +39 -8
  38. package/build/docs-src/api/references.d.ts +5 -5
  39. package/build/docs-src/api/references.js +31 -5
  40. package/build/globals.d.ts +83 -130
  41. package/build/globals.js +4 -0
  42. package/build/helpers/errors.js +5 -1
  43. package/build/helpers/index.d.ts +4 -7
  44. package/build/helpers/index.js +23 -8
  45. package/build/helpers/mount-state.js +10 -6
  46. package/build/helpers/rerender.js +16 -12
  47. package/build/helpers/type-guards.js +6 -2
  48. package/build/helpers/use-component/index.d.ts +1 -1
  49. package/build/helpers/use-component/index.js +9 -5
  50. package/build/helpers/use-component/types.js +2 -1
  51. package/build/index.d.ts +4 -3
  52. package/build/index.js +19 -3
  53. package/build/slots/hook.d.ts +2 -2
  54. package/build/slots/hook.js +78 -44
  55. package/build/slots/index.d.ts +1 -1
  56. package/build/slots/index.js +17 -1
  57. package/build/slots/types.d.ts +16 -13
  58. package/build/slots/types.js +2 -1
  59. package/build/tsconfig.json +6 -9
  60. package/package.json +11 -31
  61. package/build/_cjs/base/index.d.ts +0 -3
  62. package/build/_cjs/base/index.js +0 -19
  63. package/build/_cjs/base/merged-state.d.ts +0 -19
  64. package/build/_cjs/base/merged-state.js +0 -60
  65. package/build/_cjs/base/methods.d.ts +0 -58
  66. package/build/_cjs/base/methods.js +0 -95
  67. package/build/_cjs/base/state/class-types.d.ts +0 -20
  68. package/build/_cjs/base/state/class-types.js +0 -2
  69. package/build/_cjs/base/state/class.d.ts +0 -69
  70. package/build/_cjs/base/state/class.js +0 -129
  71. package/build/_cjs/base/state/hook-types.d.ts +0 -32
  72. package/build/_cjs/base/state/hook-types.js +0 -2
  73. package/build/_cjs/base/state/hooks.d.ts +0 -12
  74. package/build/_cjs/base/state/hooks.js +0 -41
  75. package/build/_cjs/base/state/index.d.ts +0 -8
  76. package/build/_cjs/base/state/index.js +0 -34
  77. package/build/_cjs/classy/class/index.d.ts +0 -128
  78. package/build/_cjs/classy/class/index.js +0 -176
  79. package/build/_cjs/classy/class/types/extractor.d.ts +0 -5
  80. package/build/_cjs/classy/class/types/extractor.js +0 -2
  81. package/build/_cjs/classy/class/utils/function-name.d.ts +0 -2
  82. package/build/_cjs/classy/class/utils/function-name.js +0 -17
  83. package/build/_cjs/classy/index.d.ts +0 -3
  84. package/build/_cjs/classy/index.js +0 -19
  85. package/build/_cjs/classy/instance/index.d.ts +0 -144
  86. package/build/_cjs/classy/instance/index.js +0 -177
  87. package/build/_cjs/classy/instance/mount-callbacks.d.ts +0 -5
  88. package/build/_cjs/classy/instance/mount-callbacks.js +0 -30
  89. package/build/_cjs/classy/instance/types/hook.d.ts +0 -13
  90. package/build/_cjs/classy/instance/types/hook.js +0 -2
  91. package/build/_cjs/classy/logic/index.d.ts +0 -116
  92. package/build/_cjs/classy/logic/index.js +0 -123
  93. package/build/_cjs/classy/logic/types/hook.d.ts +0 -16
  94. package/build/_cjs/classy/logic/types/hook.js +0 -2
  95. package/build/_cjs/docs-src/api/base-classes.d.ts +0 -3
  96. package/build/_cjs/docs-src/api/base-classes.js +0 -9
  97. package/build/_cjs/docs-src/api/index.d.ts +0 -13
  98. package/build/_cjs/docs-src/api/index.js +0 -44
  99. package/build/_cjs/docs-src/api/references.d.ts +0 -5
  100. package/build/_cjs/docs-src/api/references.js +0 -31
  101. package/build/_cjs/helpers/debounce/index.d.ts +0 -55
  102. package/build/_cjs/helpers/debounce/index.js +0 -111
  103. package/build/_cjs/helpers/debounce/react-state.d.ts +0 -14
  104. package/build/_cjs/helpers/debounce/react-state.js +0 -32
  105. package/build/_cjs/helpers/errors.d.ts +0 -10
  106. package/build/_cjs/helpers/errors.js +0 -21
  107. package/build/_cjs/helpers/index.d.ts +0 -16
  108. package/build/_cjs/helpers/index.js +0 -34
  109. package/build/_cjs/helpers/mount-state.d.ts +0 -5
  110. package/build/_cjs/helpers/mount-state.js +0 -25
  111. package/build/_cjs/helpers/object-gate.d.ts +0 -74
  112. package/build/_cjs/helpers/object-gate.js +0 -67
  113. package/build/_cjs/helpers/rerender.d.ts +0 -24
  114. package/build/_cjs/helpers/rerender.js +0 -42
  115. package/build/_cjs/helpers/type-guards.d.ts +0 -1
  116. package/build/_cjs/helpers/type-guards.js +0 -8
  117. package/build/_cjs/helpers/use-component/index.d.ts +0 -6
  118. package/build/_cjs/helpers/use-component/index.js +0 -17
  119. package/build/_cjs/helpers/use-component/types.d.ts +0 -22
  120. package/build/_cjs/helpers/use-component/types.js +0 -2
  121. package/build/_cjs/index.d.ts +0 -3
  122. package/build/_cjs/index.js +0 -19
  123. package/build/_cjs/slots/hook.d.ts +0 -20
  124. package/build/_cjs/slots/hook.js +0 -147
  125. package/build/_cjs/slots/index.d.ts +0 -1
  126. package/build/_cjs/slots/index.js +0 -17
  127. package/build/_cjs/slots/types.d.ts +0 -128
  128. package/build/_cjs/slots/types.js +0 -2
  129. package/build/helpers/debounce/index.d.ts +0 -55
  130. package/build/helpers/debounce/index.js +0 -107
  131. package/build/helpers/debounce/react-state.d.ts +0 -14
  132. package/build/helpers/debounce/react-state.js +0 -29
  133. package/build/helpers/object-gate.d.ts +0 -74
  134. package/build/helpers/object-gate.js +0 -64
@@ -1,8 +1,25 @@
1
- var _a;
2
- import { useMemo } from 'react';
3
- import { ComponentInstance, useInstance } from '../instance/index.js';
4
- import { setFunctionName } from './utils/function-name.js';
5
- import { useRerender } from '../../helpers/rerender.js';
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Component = exports.ClassComponent = void 0;
19
+ var react_1 = require("react");
20
+ var instance_1 = require("../instance");
21
+ var function_name_1 = require("./utils/function-name");
22
+ var rerender_1 = require("../../helpers/rerender");
6
23
  /**
7
24
  * @summary
8
25
  * A modern class component for React that is fully compatible with
@@ -20,9 +37,10 @@ import { useRerender } from '../../helpers/rerender.js';
20
37
  * making it easier to migrate older class components to the newer hooks-based system
21
38
  * with little to no changes to their existing semantics/implementation.
22
39
  */
23
- export class ClassComponent extends ComponentInstance {
24
- constructor() {
25
- super(...arguments);
40
+ var ClassComponent = /** @class */ (function (_super) {
41
+ __extends(ClassComponent, _super);
42
+ function ClassComponent() {
43
+ var _this = _super !== null && _super.apply(this, arguments) || this;
26
44
  /**
27
45
  * Analogous to {@link React.Component.render}. A function that returns
28
46
  * your component's JSX template.
@@ -59,100 +77,71 @@ export class ClassComponent extends ComponentInstance {
59
77
  * }
60
78
  * ```
61
79
  */
62
- this.template = () => null;
63
- }
64
- /**
65
- * A standard React function component that works like any
66
- * other function component and can be rendered as JSX.
67
- * \`<MyComponent.FC />\`
68
- */
69
- static _FC(props) {
70
- const instance = useInstance(this, props);
71
- const { template, templateContext } = instance;
72
- let _forceUpdate;
73
- // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
74
- instance.forceUpdate = (_forceUpdate = useRerender() // Moved this to separate line to allow TS errors. Use proxy local variable to regain some type checking for the assignment to `instance.forceUpdate`.
75
- );
76
- // Add calling component name to template function name in stack traces.
77
- useMemo(() => {
78
- setFunctionName(template, `${this.name}.template`);
79
- }, [template]);
80
- return template(templateContext);
80
+ _this.template = function () { return null; };
81
+ return _this;
81
82
  }
82
- ;
83
- static get FC() {
84
- if (this._BoundFC)
85
- return this._BoundFC;
86
- return this._BoundFC = this._FC.bind(this);
87
- }
88
- }
89
- _a = ClassComponent;
90
- (() => {
91
- setFunctionName(_a._FC, `$${_a.name}$`);
92
- })();
93
- /*************************************
94
- * Function Component Extractor *
95
- **************************************/
96
- /**
97
- * Extract a Function Component (FC) which can be used to render
98
- * your ClassComponent just like any other React component.
99
- *
100
- * Each JSX reference to the returned component will render with
101
- * a separate instance of your class.
102
- *
103
- * So you only need to call `YourClassComponent.extract()` (or `*.FC()`) once,
104
- * then use the returned function component as many times as you need.
105
- *
106
- * It is recommended to store this returned value as a static member of
107
- * your ClassComponent. While this value may be given any name, the name
108
- * RC (for "React Component") is the recommended convention.
109
- *
110
- * @example <caption>Calling `extract` in your ClassComponent</caption>
111
- * class Button extends ClassComponent {
112
- * static readonly RC = this.extract(); // or this.FC();
113
- * // Because of the static keyword, `this` here refers to the class itself, same as calling `Button.extract()`.
114
- * }
115
- *
116
- * // Render with `<Button.RC />`, or export RC to use the component in other files.
117
- * export default Button.RC;
118
- */
119
- ClassComponent.extract = function FC(_Component, properties) {
120
- const Component = _Component !== null && _Component !== void 0 ? _Component : this;
121
- const isClassComponentType = (Component === _a
122
- || Component.prototype instanceof _a
123
- || _a.isPrototypeOf(Component));
124
- if (!isClassComponentType)
125
- throw new Error('Attempted to initialize `ClassComponent` with an invalid Class type. Either call `extract()` with a class argument that extends ClassComponent (e.g `export default extract(MyComponent);`), or ensure `extract()` is called as a method on a ClassComponent constructor type (e.g `export default MyComponent.extract();`).');
83
+ var _a;
84
+ _a = ClassComponent;
126
85
  /*************************************
127
- * Begin Function Component *
86
+ * Function Component Extractor *
128
87
  **************************************/
129
- /** A class-based, React function component created with `@cleanweb/oore`. {@link ClassComponent} */
130
- const Wrapper = (props) => {
131
- const instance = useInstance(Component, props);
132
- const { template, templateContext } = instance;
133
- let _forceUpdate;
134
- // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
135
- instance.forceUpdate = (_forceUpdate = useRerender() // Moved this to separate line to allow TS errors. Use proxy local variable to regain some type checking for the assignment to `instance.forceUpdate`.
136
- );
137
- // Add calling component name to template function name in stack traces.
138
- useMemo(() => {
139
- setFunctionName(template, `${Component.name}.template`);
140
- }, [template]);
141
- return template(templateContext);
88
+ /**
89
+ * Extract a Function Component (FC) which can be used to render
90
+ * your ClassComponent just like any other React component.
91
+ *
92
+ * Each JSX reference to the returned component will render with
93
+ * a separate instance of your class.
94
+ *
95
+ * So you only need to call `YourClassComponent.extract()` (or `*.FC()`) once,
96
+ * then use the returned function component as many times as you need.
97
+ *
98
+ * It is recommended to store this returned value as a static member of
99
+ * your ClassComponent. While this value may be given any name, the name
100
+ * RC (for "React Component") is the recommended convention.
101
+ *
102
+ * @example <caption>Calling `extract` in your ClassComponent</caption>
103
+ * class Button extends ClassComponent {
104
+ * static readonly RC = this.extract(); // or this.FC();
105
+ * // Because of the static keyword, `this` here refers to the class itself, same as calling `Button.extract()`.
106
+ * }
107
+ *
108
+ * // Render with `<Button.RC />`, or export RC to use the component in other files.
109
+ * export default Button.RC;
110
+ */
111
+ ClassComponent.extract = function FC(_Component, properties) {
112
+ var Component = _Component !== null && _Component !== void 0 ? _Component : this;
113
+ var isClassComponentType = Component.prototype instanceof _a;
114
+ if (!isClassComponentType)
115
+ throw new Error('Attempted to initialize ClassComponent with invalid Class type. Either pass, as an argument to FC(), a class that extends ClassComponent (e.g `export FC(MyComponent);`), or ensure FC() is called as a method on a ClassComponent constructor type (e.g `export MyComponent.FC()`).');
116
+ /*************************************
117
+ * Begin Function Component *
118
+ **************************************/
119
+ /** A class-based, React function component created with `@cleanweb/oore`. {@link ClassComponent} */
120
+ var Wrapper = function (props) {
121
+ var instance = (0, instance_1.useInstance)(Component, props);
122
+ var template = instance.template, templateContext = instance.templateContext;
123
+ var _forceUpdate;
124
+ // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
125
+ instance.forceUpdate = (_forceUpdate = (0, rerender_1.useRerender)() // Moved this to separate line to allow TS errors. Use proxy local variable to regain some type checking for the assignment to `instance.forceUpdate`.
126
+ );
127
+ // Add calling component name to template function name in stack traces.
128
+ (0, react_1.useMemo)(function () {
129
+ (0, function_name_1.setFunctionName)(template, "".concat(Component.name, ".template"));
130
+ }, [template]);
131
+ return template(templateContext);
132
+ };
133
+ /**************************************
134
+ * 👆🏼 End Function Component *
135
+ **************************************/
136
+ (0, function_name_1.setFunctionName)(Wrapper, "$".concat(Component.name, "$"));
137
+ return Object.assign(Wrapper, properties);
142
138
  };
143
- /**************************************
144
- * 👆🏼 End Function Component *
145
- **************************************/
146
- setFunctionName(Wrapper, `$${Component.name}$`);
147
- return Object.assign(Wrapper, properties);
148
- };
149
- /**
150
- * A standard React function component that works like any
151
- * other function component and can be rendered as JSX.
152
- * \`<MyComponent.RC />\`
153
- */
154
- ClassComponent.RC = _a.extract();
155
- export { ClassComponent as Component };
139
+ /** @see {@link ClassComponent.extract} */
140
+ ClassComponent.FC = _a.extract;
141
+ return ClassComponent;
142
+ }(instance_1.ComponentInstance));
143
+ exports.ClassComponent = ClassComponent;
144
+ exports.Component = ClassComponent;
156
145
  /** /
157
146
  testing: {
158
147
  const a: object = {b: ''};
@@ -1,5 +1,5 @@
1
1
  import type { VoidFunctionComponent } from 'react';
2
- import type { ClassComponent } from '../index.js';
2
+ import type { ClassComponent } from '..';
3
3
  type BaseCCConstructor = typeof ClassComponent<object>;
4
4
  export type Extractor = <TComponentClass extends BaseCCConstructor, TProperties extends {} = {}>(this: TComponentClass, Component?: TComponentClass | null, properties?: TProperties) => NonNullable<TProperties> & VoidFunctionComponent<InstanceType<TComponentClass>['props']>;
5
5
  export {};
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setFunctionName = void 0;
1
4
  /** Provide more useful stack traces for otherwise non-specific function names. */
2
- export const setFunctionName = (func, newName) => {
5
+ var setFunctionName = function (func, newName) {
3
6
  try {
4
7
  // Must use try block, as `name` is not configurable on older browsers, and may yield a TypeError.
5
8
  Object.defineProperty(func, 'name', {
@@ -11,3 +14,4 @@ export const setFunctionName = (func, newName) => {
11
14
  console.warn(error);
12
15
  }
13
16
  };
17
+ exports.setFunctionName = setFunctionName;
@@ -1,3 +1,3 @@
1
- export * from './logic/index.js';
2
- export * from './instance/index.js';
3
- export * from './class/index.js';
1
+ export * from './logic';
2
+ export * from './instance';
3
+ export * from './class';
@@ -1,3 +1,19 @@
1
- export * from './logic/index.js';
2
- export * from './instance/index.js';
3
- export * from './class/index.js';
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./logic"), exports);
18
+ __exportStar(require("./instance"), exports);
19
+ __exportStar(require("./class"), exports);
@@ -1,7 +1,7 @@
1
- import type { UseInstance } from './types/hook.js';
2
- import type { TPropsBase } from '../../classy/logic/index.js';
3
- import { ComponentLogic } from '../../classy/logic/index.js';
4
- type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction | void>;
1
+ import type { UseInstance } from './types/hook';
2
+ import type { TPropsBase } from '../../classy/logic';
3
+ import { ComponentLogic } from '../../classy/logic';
4
+ type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
5
5
  /**
6
6
  * A superset of {@link ComponentLogic} that adds support for lifecycle methods.
7
7
  * This provides a declarative API for working with your React function component's lifecycle,
@@ -1,7 +1,25 @@
1
- import { useEffect } from 'react';
2
- import { ComponentLogic, useLogic } from '../../classy/logic/index.js';
3
- import { useMountCallbacks } from './mount-callbacks.js';
4
- import { noOp } from '../../helpers/index.js';
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.useInstance = exports.ComponentInstance = void 0;
19
+ var react_1 = require("react");
20
+ var logic_1 = require("../../classy/logic");
21
+ var mount_callbacks_1 = require("./mount-callbacks");
22
+ var helpers_1 = require("../../helpers");
5
23
  /**
6
24
  * A superset of {@link ComponentLogic} that adds support for lifecycle methods.
7
25
  * This provides a declarative API for working with your React function component's lifecycle,
@@ -9,9 +27,10 @@ import { noOp } from '../../helpers/index.js';
9
27
  *
10
28
  * @see https://github.com/cleanjsweb/neat-react#lifecycle-useinstance
11
29
  */
12
- export class ComponentInstance extends ComponentLogic {
13
- constructor() {
14
- super(...arguments);
30
+ var ComponentInstance = /** @class */ (function (_super) {
31
+ __extends(ComponentInstance, _super);
32
+ function ComponentInstance() {
33
+ var _this = _super !== null && _super.apply(this, arguments) || this;
15
34
  /**
16
35
  * Runs only _before_ the first render,
17
36
  * i.e before the component instance is mounted.
@@ -22,7 +41,7 @@ export class ComponentInstance extends ComponentLogic {
22
41
  * PS: You can conditionally update state from here, but with certain caveats.
23
42
  * {@link https://react.dev/reference/react/useState#storing-information-from-previous-renders | See the React docs for details}.
24
43
  */
25
- this.beforeMount = () => { };
44
+ _this.beforeMount = function () { };
26
45
  /**
27
46
  * Runs only **_after_** the first render, i.e after the component instance is mounted.
28
47
  * It is ignored on subsequent rerenders.
@@ -34,7 +53,7 @@ export class ComponentInstance extends ComponentLogic {
34
53
  *
35
54
  * Uses `useEffect()` under the hood.
36
55
  */
37
- this.onMount = () => noOp;
56
+ _this.onMount = function () { return helpers_1.noOp; };
38
57
  /**
39
58
  * Runs _before_ every render cycle, including the first.
40
59
  * Useful for logic that is involved in determining what to render.
@@ -50,7 +69,7 @@ export class ComponentInstance extends ComponentLogic {
50
69
  * PS: You can conditionally update state from here, but with certain caveats.
51
70
  * {@link https://react.dev/reference/react/useState#storing-information-from-previous-renders | See the React docs for details}.
52
71
  */
53
- this.beforeRender = () => ({});
72
+ _this.beforeRender = function () { return ({}); };
54
73
  /**
55
74
  * Runs **_after_** every render cycle, including the first.
56
75
  *
@@ -61,49 +80,56 @@ export class ComponentInstance extends ComponentLogic {
61
80
  *
62
81
  * @returns A cleanup function.
63
82
  */
64
- this.onRender = () => noOp;
83
+ _this.onRender = function () { return helpers_1.noOp; };
65
84
  /**
66
85
  * Runs when the component is unmounted.
67
86
  * It is called _after_ the cleanup function returned by onMount.
68
87
  */
69
- this.cleanUp = () => { };
88
+ _this.cleanUp = function () { };
89
+ return _this;
70
90
  }
71
- /**
72
- * Exposes the object returned by {@link beforeRender}.
73
- *
74
- * This is useful when you need to render some state or props
75
- * in a transformed format. Put the transformation logic
76
- * in {@link beforeRender} to the keep the main
77
- * function component body clean.
78
- *
79
- * ******
80
- *
81
- * @example <caption>Using `templateContext`.</caption>
82
- *
83
- * ```tsx
84
- * class MyComponentLogic extends ComponentInstance {
85
- * beforeRender = () => {
86
- * const title = `My Site | ${this.props.title}`;
87
- * return { title };
88
- * }
89
- * }
90
- * const MyComponent = (props) => {
91
- * const self = useInstance(MyComponentLogic, props);
92
- * const { templateContext: ctx, state } = self;
93
- *
94
- * return (
95
- * <h1>
96
- * {ctx.title}
97
- * </h1>
98
- * <p>{props.description}</p>
99
- * );
100
- * }
101
- * ```
102
- */
103
- get templateContext() {
104
- return this._templateContext;
105
- }
106
- }
91
+ Object.defineProperty(ComponentInstance.prototype, "templateContext", {
92
+ /**
93
+ * Exposes the object returned by {@link beforeRender}.
94
+ *
95
+ * This is useful when you need to render some state or props
96
+ * in a transformed format. Put the transformation logic
97
+ * in {@link beforeRender} to the keep the main
98
+ * function component body clean.
99
+ *
100
+ * ******
101
+ *
102
+ * @example <caption>Using `templateContext`.</caption>
103
+ *
104
+ * ```tsx
105
+ * class MyComponentLogic extends ComponentInstance {
106
+ * beforeRender = () => {
107
+ * const title = `My Site | ${this.props.title}`;
108
+ * return { title };
109
+ * }
110
+ * }
111
+ * const MyComponent = (props) => {
112
+ * const self = useInstance(MyComponentLogic, props);
113
+ * const { templateContext: ctx, state } = self;
114
+ *
115
+ * return (
116
+ * <h1>
117
+ * {ctx.title}
118
+ * </h1>
119
+ * <p>{props.description}</p>
120
+ * );
121
+ * }
122
+ * ```
123
+ */
124
+ get: function () {
125
+ return this._templateContext;
126
+ },
127
+ enumerable: false,
128
+ configurable: true
129
+ });
130
+ return ComponentInstance;
131
+ }(logic_1.ComponentLogic));
132
+ exports.ComponentInstance = ComponentInstance;
107
133
  ;
108
134
  /**
109
135
  * Enables full separation of concerns between a React component's template
@@ -118,35 +144,39 @@ export class ComponentInstance extends ComponentLogic {
118
144
  *
119
145
  * The provided class should be a subclass of {@link ComponentInstance}.
120
146
  */
121
- export const useInstance = (...args) => {
147
+ var useInstance = function () {
122
148
  var _a;
123
- const [Component, props = {}] = args;
149
+ var args = [];
150
+ for (var _i = 0; _i < arguments.length; _i++) {
151
+ args[_i] = arguments[_i];
152
+ }
153
+ var Component = args[0], _b = args[1], props = _b === void 0 ? {} : _b;
124
154
  // useHooks.
125
- const instance = useLogic(Component, props);
155
+ var instance = (0, logic_1.useLogic)(Component, props);
126
156
  // beforeMount, onMount, cleanUp.
127
- useMountCallbacks(instance);
157
+ (0, mount_callbacks_1.useMountCallbacks)(instance);
128
158
  // beforeRender.
129
159
  /**
130
160
  * A proxy variable to allow typechecking of the assignment
131
161
  * to `self.templateContext` despite the need for "readonly" error suppression.
132
162
  */
133
- let _templateContextProxy_;
163
+ var _templateContextProxy_;
134
164
  // @ts-expect-error Assigning to a readonly property.
135
165
  instance._templateContext = (_templateContextProxy_ = (_a = instance.beforeRender) === null || _a === void 0 ? void 0 : _a.call(instance));
136
166
  // onRender.
137
- useEffect(() => {
167
+ (0, react_1.useEffect)(function () {
138
168
  var _a;
139
- const cleanupAfterRerender = (_a = instance.onRender) === null || _a === void 0 ? void 0 : _a.call(instance);
140
- return () => {
169
+ var cleanupAfterRerender = (_a = instance.onRender) === null || _a === void 0 ? void 0 : _a.call(instance);
170
+ return function () {
141
171
  if (typeof cleanupAfterRerender === 'function')
142
172
  cleanupAfterRerender();
143
173
  else
144
- cleanupAfterRerender === null || cleanupAfterRerender === void 0 ? void 0 : cleanupAfterRerender.then((cleanUp) => cleanUp === null || cleanUp === void 0 ? void 0 : cleanUp());
174
+ cleanupAfterRerender === null || cleanupAfterRerender === void 0 ? void 0 : cleanupAfterRerender.then(function (cleanUp) { return cleanUp === null || cleanUp === void 0 ? void 0 : cleanUp(); });
145
175
  };
146
176
  });
147
- // class FormValues<TValues> extends BrowserMemStore<TValues> {}
148
177
  return instance;
149
178
  };
179
+ exports.useInstance = useInstance;
150
180
  /** /
151
181
  testing: {
152
182
  class A extends ComponentInstance<EmptyObject> {
@@ -1,4 +1,4 @@
1
- import { ComponentInstance } from './index.js';
1
+ import { ComponentInstance } from '.';
2
2
  type UseMountCallbacks = <TInstance extends ComponentInstance>(instance: TInstance) => void;
3
3
  /** @internal */
4
4
  export declare const useMountCallbacks: UseMountCallbacks;
@@ -1,16 +1,19 @@
1
- import { useEffect } from 'react';
2
- import { useMountState } from '../../helpers/mount-state.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMountCallbacks = void 0;
4
+ var react_1 = require("react");
5
+ var mount_state_1 = require("../../helpers/mount-state");
3
6
  /** @internal */
4
- export const useMountCallbacks = (instance) => {
7
+ var useMountCallbacks = function (instance) {
5
8
  var _a;
6
- const isMounted = useMountState();
9
+ var isMounted = (0, mount_state_1.useMountState)();
7
10
  if (!isMounted())
8
11
  (_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
9
- useEffect(() => {
12
+ (0, react_1.useEffect)(function () {
10
13
  var _a;
11
- const mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
12
- return () => {
13
- const doCleanUp = (runMountCleaners) => {
14
+ var mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
15
+ return function () {
16
+ var doCleanUp = function (runMountCleaners) {
14
17
  var _a;
15
18
  runMountCleaners === null || runMountCleaners === void 0 ? void 0 : runMountCleaners();
16
19
  (_a = instance.cleanUp) === null || _a === void 0 ? void 0 : _a.call(instance);
@@ -24,3 +27,4 @@ export const useMountCallbacks = (instance) => {
24
27
  };
25
28
  }, []);
26
29
  };
30
+ exports.useMountCallbacks = useMountCallbacks;
@@ -1,4 +1,4 @@
1
- import { ComponentInstance } from '../index.js';
1
+ import { ComponentInstance } from '..';
2
2
  type UIClassParam = typeof ComponentInstance<NonNullable<any>>;
3
3
  type UIProplessClassParam = typeof ComponentInstance<null>;
4
4
  export type UseInstance = {
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
- import type { TCleanState } from '../../base/state/index.js';
2
- import type { UseLogic } from './types/hook.js';
1
+ import type { TCleanState } from '../../base/state';
2
+ import type { UseLogic } from './types/hook';
3
3
  /**
4
4
  * The base type for the `props` type argument.
5
5
  *