@cleanweb/oore 2.0.0-alpha.21 → 2.0.0-alpha.22

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,19 +1,3 @@
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("./state"), exports);
18
- __exportStar(require("./methods"), exports);
19
- __exportStar(require("./merged-state"), exports);
1
+ export * from './state';
2
+ export * from './methods';
3
+ export * from './merged-state';
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMergedState = void 0;
4
- const react_1 = require("react");
1
+ import { useMemo, useRef, useState } from 'react';
5
2
  class MergedState {
6
3
  static useRefresh() {
7
- [this._values_, this.setState] = (0, react_1.useState)(this.initialState);
4
+ [this._values_, this.setState] = useState(this.initialState);
8
5
  }
9
6
  get put() {
10
7
  return Object.assign({}, this._setters_);
@@ -50,11 +47,10 @@ class MergedState {
50
47
  * Similar to {@link useCleanState},
51
48
  * but uses a single `useState` call for the entire state object.
52
49
  */
53
- const useMergedState = (initialState) => {
54
- const cleanState = (0, react_1.useRef)((0, react_1.useMemo)(() => {
50
+ export const useMergedState = (initialState) => {
51
+ const cleanState = useRef(useMemo(() => {
55
52
  return new MergedState(initialState);
56
53
  }, [])).current;
57
54
  MergedState.useRefresh.call(cleanState);
58
55
  return cleanState;
59
56
  };
60
- exports.useMergedState = useMergedState;
@@ -1,11 +1,8 @@
1
- "use strict";
2
1
  /**
3
2
  * @module ComponentMethods
4
3
  */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useMethods = exports.ComponentMethods = void 0;
7
4
  // Values
8
- const react_1 = require("react");
5
+ import { useMemo, useRef } from 'react';
9
6
  /**
10
7
  * @summary
11
8
  * Base class for a class that holds methods for a function component.
@@ -16,7 +13,7 @@ const react_1 = require("react");
16
13
  *
17
14
  * Call the {@link useMethods} hook inside your function component to instantiate the class.
18
15
  */
19
- class ComponentMethods {
16
+ export class ComponentMethods {
20
17
  constructor() {
21
18
  /**
22
19
  * Persist class members during HMR. {@include ../classy/logic/hrm-preserve-keys.md}
@@ -26,7 +23,6 @@ class ComponentMethods {
26
23
  this._hmrPreserveKeys = []; // @todo Keep undefined. Update to empty array after instantiation in dev env.
27
24
  }
28
25
  }
29
- exports.ComponentMethods = ComponentMethods;
30
26
  ;
31
27
  /**
32
28
  * Returns an instance of the provided class,
@@ -44,8 +40,8 @@ const useMethods = (...args) => {
44
40
  // In production, we only use the latestInstance the first time, and it's ignored every other time.
45
41
  // This means changing the class at runtime will have no effect in production.
46
42
  // latestInstance is only extracted into a separate variable for use in dev mode during HMR.
47
- const latestInstance = (0, react_1.useMemo)(() => new Methods(), [Methods]);
48
- const instanceRef = (0, react_1.useRef)(latestInstance);
43
+ const latestInstance = useMemo(() => new Methods(), [Methods]);
44
+ const instanceRef = useRef(latestInstance);
49
45
  const refreshState = () => {
50
46
  // @ts-expect-error
51
47
  instanceRef.current.props = props;
@@ -76,7 +72,7 @@ const useMethods = (...args) => {
76
72
  refreshState();
77
73
  return instanceRef.current;
78
74
  };
79
- exports.useMethods = useMethods;
75
+ export { useMethods };
80
76
  /** /type_testing: {
81
77
  let a = async () => {
82
78
  const a: object = {b: ''};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CleanState = exports.CleanStateBase = void 0;
4
- const react_1 = require("react");
1
+ import { useState } from 'react';
5
2
  /** @internal */
6
- class CleanStateBase {
3
+ export class CleanStateBase {
7
4
  constructor(initialState) {
8
5
  this._values_ = {};
9
6
  this._setters_ = {};
@@ -100,9 +97,8 @@ class CleanStateBase {
100
97
  return Object.assign({}, this._initialValues_);
101
98
  }
102
99
  }
103
- exports.CleanStateBase = CleanStateBase;
104
100
  CleanStateBase.update = function update() {
105
- if (!(this instanceof exports.CleanState))
101
+ if (!(this instanceof CleanState))
106
102
  throw new Error('CleanState.update must be called with `this` value set to a CleanState instance. Did you forget to use `.call` or `.apply`? Example: CleanState.update.call(cleanState);');
107
103
  /**
108
104
  * Linters complain about the use of a React hook within a loop because:
@@ -113,7 +109,7 @@ CleanStateBase.update = function update() {
113
109
  * and it guarantees that the same useState calls will be made on every render in the exact same order.
114
110
  * Therefore, it is safe to silence the linters, and required for this implementation to work smoothly.
115
111
  */
116
- const retrieveState = react_1.useState;
112
+ const retrieveState = useState;
117
113
  this.valueKeys.forEach((key) => {
118
114
  // @todo Make state updates accessible immediately. Use state.staged to access the scheduled updates.
119
115
  let setter;
@@ -126,4 +122,4 @@ CleanStateBase.update = function update() {
126
122
  };
127
123
  ;
128
124
  /** @internal */
129
- exports.CleanState = (CleanStateBase);
125
+ export const CleanState = (CleanStateBase);
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useCleanState = void 0;
4
- const react_1 = require("react");
5
- const class_1 = require("./class");
1
+ import { useMemo, useRef } from 'react';
2
+ import { CleanState } from './class';
6
3
  /**
7
4
  * Creates a state object, which includes the provided values,
8
5
  * as well as helper methods for updating those values and automatically
@@ -13,18 +10,17 @@ const class_1 = require("./class");
13
10
  *
14
11
  * Discussion: [When to `useCleanState`](https://cleanjsweb.github.io/neat-react/documents/Clean_State.html).
15
12
  */
16
- const useCleanState = (_initialState, ...props) => {
13
+ export const useCleanState = (_initialState, ...props) => {
17
14
  const initialState = typeof _initialState === 'function'
18
- ? (0, react_1.useMemo)(() => _initialState(...props), [])
15
+ ? useMemo(() => _initialState(...props), [])
19
16
  : _initialState;
20
17
  ;
21
- const cleanState = (0, react_1.useRef)((0, react_1.useMemo)(() => {
22
- return new class_1.CleanState(initialState);
18
+ const cleanState = useRef(useMemo(() => {
19
+ return new CleanState(initialState);
23
20
  }, [])).current;
24
- class_1.CleanState.update.call(cleanState);
21
+ CleanState.update.call(cleanState);
25
22
  return cleanState;
26
23
  };
27
- exports.useCleanState = useCleanState;
28
24
  // Should be valid.
29
25
  // useCleanState((a: number) => ({b: a.toString(), q: 1}), 6);
30
26
  // useCleanState((a: boolean) => ({b: a.toString()}), true);
@@ -1,34 +1,6 @@
1
- "use strict";
2
1
  /**
3
2
  * @module CleanState
4
3
  */
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.MergedState = exports.useCleanState = exports.CleanState = void 0;
30
- var class_1 = require("./class");
31
- Object.defineProperty(exports, "CleanState", { enumerable: true, get: function () { return class_1.CleanState; } });
32
- var hooks_1 = require("./hooks");
33
- Object.defineProperty(exports, "useCleanState", { enumerable: true, get: function () { return hooks_1.useCleanState; } });
34
- exports.MergedState = __importStar(require("../../base/merged-state"));
4
+ export { CleanState } from './class';
5
+ export { useCleanState } from './hooks';
6
+ export * as MergedState from '../../base/merged-state';
@@ -1,11 +1,8 @@
1
- "use strict";
2
1
  var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Component = exports.ClassComponent = void 0;
5
- const react_1 = require("react");
6
- const instance_1 = require("../instance");
7
- const function_name_1 = require("./utils/function-name");
8
- const rerender_1 = require("../../helpers/rerender");
2
+ import { useMemo } from 'react';
3
+ import { ComponentInstance, useInstance } from '../instance';
4
+ import { setFunctionName } from './utils/function-name';
5
+ import { useRerender } from '../../helpers/rerender';
9
6
  /**
10
7
  * @summary
11
8
  * A modern class component for React that is fully compatible with
@@ -23,7 +20,7 @@ const rerender_1 = require("../../helpers/rerender");
23
20
  * making it easier to migrate older class components to the newer hooks-based system
24
21
  * with little to no changes to their existing semantics/implementation.
25
22
  */
26
- class ClassComponent extends instance_1.ComponentInstance {
23
+ export class ClassComponent extends ComponentInstance {
27
24
  constructor() {
28
25
  super(...arguments);
29
26
  /**
@@ -70,15 +67,15 @@ class ClassComponent extends instance_1.ComponentInstance {
70
67
  * \`<MyComponent.FC />\`
71
68
  */
72
69
  static _FC(props) {
73
- const instance = (0, instance_1.useInstance)(this, props);
70
+ const instance = useInstance(this, props);
74
71
  const { template, templateContext } = instance;
75
72
  let _forceUpdate;
76
73
  // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
77
- 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`.
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`.
78
75
  );
79
76
  // Add calling component name to template function name in stack traces.
80
- (0, react_1.useMemo)(() => {
81
- (0, function_name_1.setFunctionName)(template, `${this.name}.template`);
77
+ useMemo(() => {
78
+ setFunctionName(template, `${this.name}.template`);
82
79
  }, [template]);
83
80
  return template(templateContext);
84
81
  }
@@ -89,11 +86,9 @@ class ClassComponent extends instance_1.ComponentInstance {
89
86
  return this._BoundFC = this._FC.bind(this);
90
87
  }
91
88
  }
92
- exports.ClassComponent = ClassComponent;
93
- exports.Component = ClassComponent;
94
89
  _a = ClassComponent;
95
90
  (() => {
96
- (0, function_name_1.setFunctionName)(_a._FC, `$${_a.name}$`);
91
+ setFunctionName(_a._FC, `$${_a.name}$`);
97
92
  })();
98
93
  /*************************************
99
94
  * Function Component Extractor *
@@ -133,22 +128,22 @@ ClassComponent.extract = function FC(_Component, properties) {
133
128
  **************************************/
134
129
  /** A class-based, React function component created with `@cleanweb/oore`. {@link ClassComponent} */
135
130
  const Wrapper = (props) => {
136
- const instance = (0, instance_1.useInstance)(Component, props);
131
+ const instance = useInstance(Component, props);
137
132
  const { template, templateContext } = instance;
138
133
  let _forceUpdate;
139
134
  // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
140
- 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`.
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`.
141
136
  );
142
137
  // Add calling component name to template function name in stack traces.
143
- (0, react_1.useMemo)(() => {
144
- (0, function_name_1.setFunctionName)(template, `${Component.name}.template`);
138
+ useMemo(() => {
139
+ setFunctionName(template, `${Component.name}.template`);
145
140
  }, [template]);
146
141
  return template(templateContext);
147
142
  };
148
143
  /**************************************
149
144
  * 👆🏼 End Function Component *
150
145
  **************************************/
151
- (0, function_name_1.setFunctionName)(Wrapper, `$${Component.name}$`);
146
+ setFunctionName(Wrapper, `$${Component.name}$`);
152
147
  return Object.assign(Wrapper, properties);
153
148
  };
154
149
  /**
@@ -157,6 +152,7 @@ ClassComponent.extract = function FC(_Component, properties) {
157
152
  * \`<MyComponent.RC />\`
158
153
  */
159
154
  ClassComponent.RC = _a.extract();
155
+ export { ClassComponent as Component };
160
156
  /** /
161
157
  testing: {
162
158
  const a: object = {b: ''};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setFunctionName = void 0;
4
1
  /** Provide more useful stack traces for otherwise non-specific function names. */
5
- const setFunctionName = (func, newName) => {
2
+ export const setFunctionName = (func, newName) => {
6
3
  try {
7
4
  // Must use try block, as `name` is not configurable on older browsers, and may yield a TypeError.
8
5
  Object.defineProperty(func, 'name', {
@@ -14,4 +11,3 @@ const setFunctionName = (func, newName) => {
14
11
  console.warn(error);
15
12
  }
16
13
  };
17
- exports.setFunctionName = setFunctionName;
@@ -1,19 +1,3 @@
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
+ export * from './logic';
2
+ export * from './instance';
3
+ export * from './class';
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useInstance = exports.ComponentInstance = void 0;
4
- const react_1 = require("react");
5
- const logic_1 = require("../../classy/logic");
6
- const mount_callbacks_1 = require("./mount-callbacks");
7
- const helpers_1 = require("../../helpers");
1
+ import { useEffect } from 'react';
2
+ import { ComponentLogic, useLogic } from '../../classy/logic';
3
+ import { useMountCallbacks } from './mount-callbacks';
4
+ import { noOp } from '../../helpers';
8
5
  /**
9
6
  * A superset of {@link ComponentLogic} that adds support for lifecycle methods.
10
7
  * This provides a declarative API for working with your React function component's lifecycle,
@@ -12,7 +9,7 @@ const helpers_1 = require("../../helpers");
12
9
  *
13
10
  * @see https://github.com/cleanjsweb/neat-react#lifecycle-useinstance
14
11
  */
15
- class ComponentInstance extends logic_1.ComponentLogic {
12
+ export class ComponentInstance extends ComponentLogic {
16
13
  constructor() {
17
14
  super(...arguments);
18
15
  /**
@@ -37,7 +34,7 @@ class ComponentInstance extends logic_1.ComponentLogic {
37
34
  *
38
35
  * Uses `useEffect()` under the hood.
39
36
  */
40
- this.onMount = () => helpers_1.noOp;
37
+ this.onMount = () => noOp;
41
38
  /**
42
39
  * Runs _before_ every render cycle, including the first.
43
40
  * Useful for logic that is involved in determining what to render.
@@ -64,7 +61,7 @@ class ComponentInstance extends logic_1.ComponentLogic {
64
61
  *
65
62
  * @returns A cleanup function.
66
63
  */
67
- this.onRender = () => helpers_1.noOp;
64
+ this.onRender = () => noOp;
68
65
  /**
69
66
  * Runs when the component is unmounted.
70
67
  * It is called _after_ the cleanup function returned by onMount.
@@ -107,7 +104,6 @@ class ComponentInstance extends logic_1.ComponentLogic {
107
104
  return this._templateContext;
108
105
  }
109
106
  }
110
- exports.ComponentInstance = ComponentInstance;
111
107
  ;
112
108
  /**
113
109
  * Enables full separation of concerns between a React component's template
@@ -122,13 +118,13 @@ exports.ComponentInstance = ComponentInstance;
122
118
  *
123
119
  * The provided class should be a subclass of {@link ComponentInstance}.
124
120
  */
125
- const useInstance = (...args) => {
121
+ export const useInstance = (...args) => {
126
122
  var _a;
127
123
  const [Component, props = {}] = args;
128
124
  // useHooks.
129
- const instance = (0, logic_1.useLogic)(Component, props);
125
+ const instance = useLogic(Component, props);
130
126
  // beforeMount, onMount, cleanUp.
131
- (0, mount_callbacks_1.useMountCallbacks)(instance);
127
+ useMountCallbacks(instance);
132
128
  // beforeRender.
133
129
  /**
134
130
  * A proxy variable to allow typechecking of the assignment
@@ -138,7 +134,7 @@ const useInstance = (...args) => {
138
134
  // @ts-expect-error Assigning to a readonly property.
139
135
  instance._templateContext = (_templateContextProxy_ = (_a = instance.beforeRender) === null || _a === void 0 ? void 0 : _a.call(instance));
140
136
  // onRender.
141
- (0, react_1.useEffect)(() => {
137
+ useEffect(() => {
142
138
  var _a;
143
139
  const cleanupAfterRerender = (_a = instance.onRender) === null || _a === void 0 ? void 0 : _a.call(instance);
144
140
  return () => {
@@ -151,7 +147,6 @@ const useInstance = (...args) => {
151
147
  // class FormValues<TValues> extends BrowserMemStore<TValues> {}
152
148
  return instance;
153
149
  };
154
- exports.useInstance = useInstance;
155
150
  /** /
156
151
  testing: {
157
152
  class A extends ComponentInstance<EmptyObject> {
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMountCallbacks = void 0;
4
- const react_1 = require("react");
5
- const mount_state_1 = require("../../helpers/mount-state");
1
+ import { useEffect } from 'react';
2
+ import { useMountState } from '../../helpers/mount-state';
6
3
  /** @internal */
7
- const useMountCallbacks = (instance) => {
4
+ export const useMountCallbacks = (instance) => {
8
5
  var _a;
9
- const isMounted = (0, mount_state_1.useMountState)();
6
+ const isMounted = useMountState();
10
7
  if (!isMounted())
11
8
  (_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
12
- (0, react_1.useEffect)(() => {
9
+ useEffect(() => {
13
10
  var _a;
14
11
  const mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
15
12
  return () => {
@@ -27,4 +24,3 @@ const useMountCallbacks = (instance) => {
27
24
  };
28
25
  }, []);
29
26
  };
30
- exports.useMountCallbacks = useMountCallbacks;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useLogic = exports.ComponentLogic = void 0;
4
- const react_1 = require("react");
5
- const state_1 = require("../../base/state");
1
+ import { useMemo, useRef } from 'react';
2
+ import { useCleanState } from '../../base/state';
6
3
  /**
7
4
  * Base class for a class that holds methods to be used in a function component.
8
5
  *
@@ -16,7 +13,7 @@ const state_1 = require("../../base/state");
16
13
  *
17
14
  * @typeParam TProps - {@include ./types/tprops.md}
18
15
  */
19
- class ComponentLogic {
16
+ export class ComponentLogic {
20
17
  constructor() {
21
18
  /**
22
19
  * Called before each instance of your component is mounted.
@@ -41,7 +38,6 @@ class ComponentLogic {
41
38
  this._hmrPreserveKeys = [];
42
39
  }
43
40
  }
44
- exports.ComponentLogic = ComponentLogic;
45
41
  ;
46
42
  /**
47
43
  * Returns an instance of the provided class, which holds methods for your component and
@@ -51,21 +47,21 @@ exports.ComponentLogic = ComponentLogic;
51
47
  *
52
48
  * @see https://cleanjsweb.github.io/neat-react/functions/API.useLogic.html
53
49
  */
54
- const useLogic = (...args) => {
50
+ export const useLogic = (...args) => {
55
51
  var _a;
56
52
  const [Logic, props = {}] = args;
57
53
  // In production, we only use the latestInstance the first time, and it's ignored every other time.
58
54
  // This means changing the class at runtime will have no effect in production.
59
55
  // latestInstance is only extracted into a separate variable for use in dev mode during HMR.
60
- const latestInstance = (0, react_1.useMemo)(() => new Logic(), [Logic]);
56
+ const latestInstance = useMemo(() => new Logic(), [Logic]);
61
57
  // const latestInstance = useMemo(() => new Logic(), []);
62
- const instanceRef = (0, react_1.useRef)(latestInstance);
58
+ const instanceRef = useRef(latestInstance);
63
59
  const refreshState = () => {
64
60
  var _a;
65
61
  // @ts-expect-error
66
62
  instanceRef.current.props = props;
67
63
  // @ts-expect-error
68
- instanceRef.current.state = (0, state_1.useCleanState)(instanceRef.current.getInitialState, props);
64
+ instanceRef.current.state = useCleanState(instanceRef.current.getInitialState, props);
69
65
  // @ts-expect-error
70
66
  instanceRef.current.hooks = (_a = instanceRef.current.useHooks()) !== null && _a !== void 0 ? _a : {};
71
67
  };
@@ -90,7 +86,6 @@ const useLogic = (...args) => {
90
86
  return instanceRef.current;
91
87
  ;
92
88
  };
93
- exports.useLogic = useLogic;
94
89
  /** /
95
90
  testing: {
96
91
  const a: object = {b: ''};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,9 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComponentInstance = exports.ComponentLogic = exports.ComponentMethods = void 0;
4
- var methods_1 = require("../../base/methods");
5
- Object.defineProperty(exports, "ComponentMethods", { enumerable: true, get: function () { return methods_1.ComponentMethods; } });
6
- var logic_1 = require("../../classy/logic");
7
- Object.defineProperty(exports, "ComponentLogic", { enumerable: true, get: function () { return logic_1.ComponentLogic; } });
8
- var instance_1 = require("../../classy/instance");
9
- Object.defineProperty(exports, "ComponentInstance", { enumerable: true, get: function () { return instance_1.ComponentInstance; } });
1
+ export { ComponentMethods } from '../../base/methods';
2
+ export { ComponentLogic } from '../../classy/logic';
3
+ export { ComponentInstance } from '../../classy/instance';
@@ -1,44 +1,13 @@
1
- "use strict";
2
1
  /**
3
2
  * API Reference
4
3
  * @module API
5
4
  */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || function (mod) {
23
- if (mod && mod.__esModule) return mod;
24
- var result = {};
25
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
- __setModuleDefault(result, mod);
27
- return result;
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.References = exports.Helpers = exports.BaseClasses = exports.ClassComponent = exports.useInstance = exports.useLogic = exports.useMethods = exports.useCleanState = void 0;
31
- var state_1 = require("../../base/state");
32
- Object.defineProperty(exports, "useCleanState", { enumerable: true, get: function () { return state_1.useCleanState; } });
33
- var methods_1 = require("../../base/methods");
34
- Object.defineProperty(exports, "useMethods", { enumerable: true, get: function () { return methods_1.useMethods; } });
35
- var logic_1 = require("../../classy/logic");
36
- Object.defineProperty(exports, "useLogic", { enumerable: true, get: function () { return logic_1.useLogic; } });
37
- var instance_1 = require("../../classy/instance");
38
- Object.defineProperty(exports, "useInstance", { enumerable: true, get: function () { return instance_1.useInstance; } });
39
- var class_1 = require("../../classy/class");
40
- Object.defineProperty(exports, "ClassComponent", { enumerable: true, get: function () { return class_1.ClassComponent; } });
5
+ export { useCleanState } from '../../base/state';
6
+ export { useMethods } from '../../base/methods';
7
+ export { useLogic } from '../../classy/logic';
8
+ export { useInstance } from '../../classy/instance';
9
+ export { ClassComponent } from '../../classy/class';
41
10
  /** @namespace */
42
- exports.BaseClasses = __importStar(require("./base-classes"));
43
- exports.Helpers = __importStar(require("../../helpers"));
44
- exports.References = __importStar(require("./references"));
11
+ export * as BaseClasses from './base-classes';
12
+ export * as Helpers from '../../helpers';
13
+ export * as References from './references';
@@ -1,31 +1,5 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ClassComponent = exports.ComponentInstance = exports.ComponentLogic = exports.$ComponentMethods = exports.$CleanState = void 0;
27
- exports.$CleanState = __importStar(require("../../base/state"));
28
- exports.$ComponentMethods = __importStar(require("../../base/methods"));
29
- exports.ComponentLogic = __importStar(require("../../classy/logic"));
30
- exports.ComponentInstance = __importStar(require("../../classy/instance"));
31
- exports.ClassComponent = __importStar(require("../../classy/class"));
1
+ export * as $CleanState from '../../base/state';
2
+ export * as $ComponentMethods from '../../base/methods';
3
+ export * as ComponentLogic from '../../classy/logic';
4
+ export * as ComponentInstance from '../../classy/instance';
5
+ export * as ClassComponent from '../../classy/class';
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwDevError = void 0;
4
1
  /**
5
2
  * Throw an error with the provided message
6
3
  * only when `NODE_ENV` is *not* 'production'.
@@ -10,7 +7,7 @@ exports.throwDevError = void 0;
10
7
  * Useful for enforcing certain conditions in development
11
8
  * while failing more gracefully in production.
12
9
  */
13
- const throwDevError = (message) => {
10
+ export const throwDevError = (message) => {
14
11
  if (process.env.NODE_ENV === 'production') {
15
12
  console.warn(message);
16
13
  }
@@ -18,4 +15,3 @@ const throwDevError = (message) => {
18
15
  throw new Error(message);
19
16
  }
20
17
  };
21
- exports.throwDevError = throwDevError;
@@ -1,31 +1,13 @@
1
- "use strict";
2
1
  /**
3
2
  * <!-- @ mergeModuleWith API -->
4
3
  * @module Helpers
5
4
  */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.noOp = void 0;
22
- __exportStar(require("./mount-state"), exports);
23
- __exportStar(require("./rerender"), exports);
24
- __exportStar(require("./use-component"), exports);
25
- __exportStar(require("./type-guards"), exports);
5
+ export * from './mount-state';
6
+ export * from './rerender';
7
+ export * from './use-component';
8
+ export * from './type-guards';
26
9
  /**
27
10
  * An empty function.
28
11
  * It returns (void) without performing any operations.
29
12
  */
30
- const noOp = () => { };
31
- exports.noOp = noOp;
13
+ export const noOp = () => { };
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMountState = void 0;
4
- const react_1 = require("react");
1
+ import { useEffect, useRef } from 'react';
5
2
  /**
6
3
  * Returns a value that is false before the component has been mounted,
7
4
  * then true during all subsequent rerenders.
8
5
  */
9
- const useMountState = () => {
6
+ export const useMountState = () => {
10
7
  /**
11
8
  * This must not be a state value. It should not be the cause of a rerender.
12
9
  * It merely provides information about the render count,
13
10
  * without influencing that count itself.
14
11
  * So `mounted` should never be created with `useState`.
15
12
  */
16
- const mounted = (0, react_1.useRef)(false);
17
- (0, react_1.useEffect)(() => {
13
+ const mounted = useRef(false);
14
+ useEffect(() => {
18
15
  mounted.current = true;
19
16
  return () => {
20
17
  mounted.current = false;
@@ -22,4 +19,3 @@ const useMountState = () => {
22
19
  }, []);
23
20
  return () => mounted.current;
24
21
  };
25
- exports.useMountState = useMountState;
@@ -1,19 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useRerender = void 0;
4
- const react_1 = require("react");
5
- const mount_state_1 = require("../helpers/mount-state");
1
+ import { useCallback, useRef, useState } from 'react';
2
+ import { useMountState } from '../helpers/mount-state';
6
3
  ;
7
4
  /**
8
5
  * Returns a function that can be called to manually trigger
9
6
  * a rerender of your component.
10
7
  */
11
- const useRerender = () => {
12
- const isMounted = (0, mount_state_1.useMountState)();
13
- const renderCount = (0, react_1.useRef)(0);
14
- const [, forceRerender] = (0, react_1.useState)(renderCount.current);
8
+ export const useRerender = () => {
9
+ const isMounted = useMountState();
10
+ const renderCount = useRef(0);
11
+ const [, forceRerender] = useState(renderCount.current);
15
12
  renderCount.current++;
16
- const rerender = (0, react_1.useCallback)(() => {
13
+ const rerender = useCallback(() => {
17
14
  let resolve;
18
15
  const promise = new Promise((_r) => resolve = _r);
19
16
  const execute = () => {
@@ -39,4 +36,3 @@ const useRerender = () => {
39
36
  refresher.currentCount = renderCount.current;
40
37
  return refresher;
41
38
  };
42
- exports.useRerender = useRerender;
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canIndex = void 0;
4
- const canIndex = (key, targetObject) => {
1
+ export const canIndex = (key, targetObject) => {
5
2
  const test = typeof key === 'number' ? `${key}` : key;
6
3
  return Reflect.ownKeys(targetObject).includes(test);
7
4
  };
8
- exports.canIndex = canIndex;
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Use = void 0;
4
- const react_1 = require("react");
1
+ import { useEffect } from 'react';
5
2
  /**
6
3
  * A component you can use to consume React hooks
7
4
  * in a {@link Component | React.Component} class.
8
5
  */
9
- const Use = (params) => {
6
+ export const Use = (params) => {
10
7
  const { hook: useGenericHook, argumentsList, onUpdate } = params;
11
8
  const output = useGenericHook(...argumentsList);
12
- (0, react_1.useEffect)(() => {
9
+ useEffect(() => {
13
10
  onUpdate(output);
14
11
  }, [output]);
15
12
  return null;
16
13
  };
17
- exports.Use = Use;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/build/index.js CHANGED
@@ -1,19 +1,3 @@
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("./classy"), exports);
18
- __exportStar(require("./base"), exports);
19
- __exportStar(require("./helpers"), exports);
1
+ export * from './classy';
2
+ export * from './base';
3
+ export * from './helpers';
@@ -1,39 +1,12 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.useSlots = exports.isPortalChild = exports.getComponentSlotName = exports.isElementChild = void 0;
27
- const errors_1 = require("../helpers/errors");
28
- const react_1 = __importStar(require("react"));
29
- const isElementChild = (child) => {
1
+ import { throwDevError } from '../helpers/errors';
2
+ import React, { useMemo } from 'react';
3
+ export const isElementChild = (child) => {
30
4
  if (child && typeof child === 'object' && 'type' in child) {
31
5
  return true;
32
6
  }
33
7
  return false;
34
8
  };
35
- exports.isElementChild = isElementChild;
36
- const getComponentSlotName = (TargetComponent, child) => {
9
+ export const getComponentSlotName = (TargetComponent, child) => {
37
10
  if (child) {
38
11
  const keyTypes = ['string', 'number', 'symbol'];
39
12
  const slotName = child.props['data-slot-name'];
@@ -52,13 +25,11 @@ const getComponentSlotName = (TargetComponent, child) => {
52
25
  }
53
26
  return undefined;
54
27
  };
55
- exports.getComponentSlotName = getComponentSlotName;
56
- const isPortalChild = (child) => {
28
+ export const isPortalChild = (child) => {
57
29
  return (!!child
58
30
  && typeof child === 'object'
59
31
  && 'children' in child);
60
32
  };
61
- exports.isPortalChild = isPortalChild;
62
33
  /**
63
34
  * Groups `children` prop into predefined slots.
64
35
  *
@@ -69,14 +40,14 @@ exports.isPortalChild = isPortalChild;
69
40
  *
70
41
  * @see {@link SlotComponent} for more on how to use the returned slot nodes.
71
42
  */
72
- const useSlots = (children, Caller) => {
73
- const slotsAliasLookup = (0, react_1.useMemo)(() => {
43
+ export const useSlots = (children, Caller) => {
44
+ const slotsAliasLookup = useMemo(() => {
74
45
  const entries = Object.entries(Caller.Slots);
75
46
  const aliasLookup = {};
76
47
  entries.forEach(([alias, RegisteredSlotComponent]) => {
77
- const slotName = (0, exports.getComponentSlotName)(RegisteredSlotComponent);
48
+ const slotName = getComponentSlotName(RegisteredSlotComponent);
78
49
  if (!slotName) {
79
- (0, errors_1.throwDevError)(`A registered slot component did not have a slot name. All components registered as slots must either be a string tag-name or a React component with either "slotName" or "displayName". The affected component was: ${RegisteredSlotComponent}`);
50
+ throwDevError(`A registered slot component did not have a slot name. All components registered as slots must either be a string tag-name or a React component with either "slotName" or "displayName". The affected component was: ${RegisteredSlotComponent}`);
80
51
  return;
81
52
  }
82
53
  aliasLookup[slotName] = alias;
@@ -84,7 +55,7 @@ const useSlots = (children, Caller) => {
84
55
  return aliasLookup;
85
56
  }, [Caller.Slots]);
86
57
  // @todo Expose original source order of `children` with respect to slot aliases.
87
- const result = (0, react_1.useMemo)(() => {
58
+ const result = useMemo(() => {
88
59
  var _a;
89
60
  const slotNodes = {};
90
61
  const unmatchedChildren = [];
@@ -92,27 +63,27 @@ const useSlots = (children, Caller) => {
92
63
  const requiredSlotAliases = [
93
64
  ...((_a = Caller.requiredSlotAliases) !== null && _a !== void 0 ? _a : [])
94
65
  ];
95
- react_1.default.Children.forEach(children, (_child) => {
66
+ React.Children.forEach(children, (_child) => {
96
67
  var _a;
97
68
  const child = _child;
98
69
  if (!child) {
99
70
  invalidChildren.push(child);
100
71
  return;
101
72
  }
102
- if (!react_1.default.isValidElement(child)) {
73
+ if (!React.isValidElement(child)) {
103
74
  console.warn(`Invalid node found in JSX children while parsing slots. Got: "${child}".`);
104
75
  invalidChildren.push(child);
105
76
  return;
106
77
  }
107
78
  ;
108
79
  // @todo Check for fragment
109
- if (!(0, exports.isElementChild)(child)) {
80
+ if (!isElementChild(child)) {
110
81
  unmatchedChildren.push(child);
111
82
  return;
112
83
  }
113
84
  const slotAlias = (() => {
114
85
  var _a;
115
- const slotName = (0, exports.getComponentSlotName)(child.type, child);
86
+ const slotName = getComponentSlotName(child.type, child);
116
87
  return slotName ? (_a = slotsAliasLookup[slotName]) !== null && _a !== void 0 ? _a : null : null;
117
88
  })();
118
89
  if (slotAlias) {
@@ -133,11 +104,10 @@ const useSlots = (children, Caller) => {
133
104
  });
134
105
  requiredSlotAliases.forEach((slotAlias) => {
135
106
  if (!slotNodes[slotAlias]) {
136
- (0, errors_1.throwDevError)(`Missing required slot "${String(slotAlias)}".`);
107
+ throwDevError(`Missing required slot "${String(slotAlias)}".`);
137
108
  }
138
109
  });
139
110
  return [slotNodes, unmatchedChildren, invalidChildren];
140
111
  }, [children]);
141
112
  return result;
142
113
  };
143
- exports.useSlots = useSlots;
@@ -1,17 +1 @@
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("./hook"), exports);
1
+ export * from './hook';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -23,8 +23,8 @@
23
23
  "forceConsistentCasingInFileNames": true,
24
24
  "incremental": false,
25
25
  "esModuleInterop": true,
26
- "module": "nodenext",
27
- "moduleResolution": "nodenext",
26
+ "module": "esnext",
27
+ "moduleResolution": "bundler",
28
28
  "resolveJsonModule": true,
29
29
  "isolatedModules": true,
30
30
  "jsx": "react-jsx",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/oore",
3
- "version": "2.0.0-alpha.21",
3
+ "version": "2.0.0-alpha.22",
4
4
  "description": "A library of helpers for writing cleaner React function components with object-oriented patterns.",
5
5
  "engines": {
6
6
  "node": ">=22"