@cleanweb/oore 2.0.0-alpha.14 → 2.0.0-alpha.16
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.
- package/build/base/index.js +3 -19
- package/build/base/merged-state.js +5 -9
- package/build/base/methods.d.ts +2 -3
- package/build/base/methods.js +5 -8
- package/build/base/state/class-types.js +1 -2
- package/build/base/state/class.js +5 -8
- package/build/base/state/hook-types.js +1 -2
- package/build/base/state/hooks.js +7 -11
- package/build/base/state/index.js +4 -32
- package/build/classy/class/index.d.ts +15 -2
- package/build/classy/class/index.js +50 -17
- package/build/classy/class/types/extractor.js +1 -2
- package/build/classy/class/utils/function-name.js +1 -5
- package/build/classy/index.js +3 -19
- package/build/classy/instance/index.d.ts +2 -2
- package/build/classy/instance/index.js +14 -17
- package/build/classy/instance/mount-callbacks.js +5 -9
- package/build/classy/instance/types/hook.js +1 -2
- package/build/classy/logic/index.js +7 -11
- package/build/classy/logic/types/hook.js +1 -2
- package/build/docs-src/api/base-classes.js +3 -9
- package/build/docs-src/api/index.js +8 -39
- package/build/docs-src/api/references.js +5 -31
- package/build/globals.js +1 -2
- package/build/helpers/errors.js +1 -5
- package/build/helpers/index.js +5 -23
- package/build/helpers/mount-state.js +4 -8
- package/build/helpers/rerender.js +7 -11
- package/build/helpers/type-guards.js +1 -5
- package/build/helpers/use-component/index.js +3 -7
- package/build/helpers/use-component/types.js +1 -2
- package/build/index.js +3 -19
- package/build/slots/hook.js +15 -45
- package/build/slots/index.js +1 -17
- package/build/slots/types.js +1 -2
- package/build/tsconfig.json +2 -2
- package/package.json +2 -1
package/build/base/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __assign = (this && this.__assign) || function () {
|
|
3
2
|
__assign = Object.assign || function(t) {
|
|
4
3
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -10,10 +9,8 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
9
|
};
|
|
11
10
|
return __assign.apply(this, arguments);
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
require("../globals");
|
|
16
|
-
var react_1 = require("react");
|
|
12
|
+
import '../globals';
|
|
13
|
+
import { useMemo, useRef, useState } from 'react';
|
|
17
14
|
var MergedState = /** @class */ (function () {
|
|
18
15
|
function MergedState(initialState) {
|
|
19
16
|
var _this = this;
|
|
@@ -52,7 +49,7 @@ var MergedState = /** @class */ (function () {
|
|
|
52
49
|
}
|
|
53
50
|
MergedState.useRefresh = function () {
|
|
54
51
|
var _a;
|
|
55
|
-
_a =
|
|
52
|
+
_a = useState(this.initialState), this._values_ = _a[0], this.setState = _a[1];
|
|
56
53
|
};
|
|
57
54
|
Object.defineProperty(MergedState.prototype, "put", {
|
|
58
55
|
get: function () {
|
|
@@ -74,11 +71,10 @@ var MergedState = /** @class */ (function () {
|
|
|
74
71
|
* Similar to {@link useCleanState},
|
|
75
72
|
* but uses a single `useState` call for the entire state object.
|
|
76
73
|
*/
|
|
77
|
-
var useMergedState = function (initialState) {
|
|
78
|
-
var cleanState =
|
|
74
|
+
export var useMergedState = function (initialState) {
|
|
75
|
+
var cleanState = useRef(useMemo(function () {
|
|
79
76
|
return new MergedState(initialState);
|
|
80
77
|
}, [])).current;
|
|
81
78
|
MergedState.useRefresh.call(cleanState);
|
|
82
79
|
return cleanState;
|
|
83
80
|
};
|
|
84
|
-
exports.useMergedState = useMergedState;
|
package/build/base/methods.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module ComponentMethods
|
|
3
3
|
*/
|
|
4
|
-
import type { TCleanState, TStateData } from './state';
|
|
5
4
|
/**
|
|
6
5
|
* @summary
|
|
7
6
|
* Base class for a class that holds methods for a function component.
|
|
@@ -12,9 +11,9 @@ import type { TCleanState, TStateData } from './state';
|
|
|
12
11
|
*
|
|
13
12
|
* Call the {@link useMethods} hook inside your function component to instantiate the class.
|
|
14
13
|
*/
|
|
15
|
-
export declare class ComponentMethods<TProps extends object = {}, TState extends
|
|
14
|
+
export declare class ComponentMethods<TProps extends object = {}, TState extends object | null = null> {
|
|
16
15
|
readonly props: TProps;
|
|
17
|
-
readonly state: TState
|
|
16
|
+
readonly state: TState;
|
|
18
17
|
/**
|
|
19
18
|
* Persist class members during HMR. {@include ../classy/logic/hrm-preserve-keys.md}
|
|
20
19
|
* @privateRemarks
|
package/build/base/methods.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
@@ -27,7 +24,7 @@ var ComponentMethods = /** @class */ (function () {
|
|
|
27
24
|
}
|
|
28
25
|
return ComponentMethods;
|
|
29
26
|
}());
|
|
30
|
-
|
|
27
|
+
export { ComponentMethods };
|
|
31
28
|
;
|
|
32
29
|
/**
|
|
33
30
|
* Returns an instance of the provided class,
|
|
@@ -49,8 +46,8 @@ var useMethods = function () {
|
|
|
49
46
|
// In production, we only use the latestInstance the first time, and it's ignored every other time.
|
|
50
47
|
// This means changing the class at runtime will have no effect in production.
|
|
51
48
|
// latestInstance is only extracted into a separate variable for use in dev mode during HMR.
|
|
52
|
-
var latestInstance =
|
|
53
|
-
var instanceRef =
|
|
49
|
+
var latestInstance = useMemo(function () { return new Methods(); }, [Methods]);
|
|
50
|
+
var instanceRef = useRef(latestInstance);
|
|
54
51
|
var refreshState = function () {
|
|
55
52
|
// @ts-expect-error
|
|
56
53
|
instanceRef.current.props = props;
|
|
@@ -81,7 +78,7 @@ var useMethods = function () {
|
|
|
81
78
|
refreshState();
|
|
82
79
|
return instanceRef.current;
|
|
83
80
|
};
|
|
84
|
-
|
|
81
|
+
export { useMethods };
|
|
85
82
|
/** /type_testing: {
|
|
86
83
|
let a = async () => {
|
|
87
84
|
const a: object = {b: ''};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __assign = (this && this.__assign) || function () {
|
|
3
2
|
__assign = Object.assign || function(t) {
|
|
4
3
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -10,9 +9,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
9
|
};
|
|
11
10
|
return __assign.apply(this, arguments);
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
exports.CleanState = exports.CleanStateBase = void 0;
|
|
15
|
-
var react_1 = require("react");
|
|
12
|
+
import { useState } from 'react';
|
|
16
13
|
/** @internal */
|
|
17
14
|
var CleanStateBase = /** @class */ (function () {
|
|
18
15
|
function CleanStateBase(initialState) {
|
|
@@ -121,7 +118,7 @@ var CleanStateBase = /** @class */ (function () {
|
|
|
121
118
|
});
|
|
122
119
|
CleanStateBase.update = function update() {
|
|
123
120
|
var _this = this;
|
|
124
|
-
if (!(this instanceof
|
|
121
|
+
if (!(this instanceof CleanState))
|
|
125
122
|
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);');
|
|
126
123
|
/**
|
|
127
124
|
* Linters complain about the use of a React hook within a loop because:
|
|
@@ -132,7 +129,7 @@ var CleanStateBase = /** @class */ (function () {
|
|
|
132
129
|
* and it guarantees that the same useState calls will be made on every render in the exact same order.
|
|
133
130
|
* Therefore, it is safe to silence the linters, and required for this implementation to work smoothly.
|
|
134
131
|
*/
|
|
135
|
-
var retrieveState =
|
|
132
|
+
var retrieveState = useState;
|
|
136
133
|
this.valueKeys.forEach(function (key) {
|
|
137
134
|
var _a;
|
|
138
135
|
// @todo Make state updates accessible immediately. Use state.staged to access the scheduled updates.
|
|
@@ -146,7 +143,7 @@ var CleanStateBase = /** @class */ (function () {
|
|
|
146
143
|
};
|
|
147
144
|
return CleanStateBase;
|
|
148
145
|
}());
|
|
149
|
-
|
|
146
|
+
export { CleanStateBase };
|
|
150
147
|
;
|
|
151
148
|
/** @internal */
|
|
152
|
-
|
|
149
|
+
export var CleanState = (CleanStateBase);
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useCleanState = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
var 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,22 +10,21 @@ var 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
|
-
var useCleanState = function (_initialState) {
|
|
13
|
+
export var useCleanState = function (_initialState) {
|
|
17
14
|
var props = [];
|
|
18
15
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
19
16
|
props[_i - 1] = arguments[_i];
|
|
20
17
|
}
|
|
21
18
|
var initialState = typeof _initialState === 'function'
|
|
22
|
-
?
|
|
19
|
+
? useMemo(function () { return _initialState.apply(void 0, props); }, [])
|
|
23
20
|
: _initialState;
|
|
24
21
|
;
|
|
25
|
-
var cleanState =
|
|
26
|
-
return new
|
|
22
|
+
var cleanState = useRef(useMemo(function () {
|
|
23
|
+
return new CleanState(initialState);
|
|
27
24
|
}, [])).current;
|
|
28
|
-
|
|
25
|
+
CleanState.update.call(cleanState);
|
|
29
26
|
return cleanState;
|
|
30
27
|
};
|
|
31
|
-
exports.useCleanState = useCleanState;
|
|
32
28
|
// Should be valid.
|
|
33
29
|
// useCleanState((a: number) => ({b: a.toString(), q: 1}), 6);
|
|
34
30
|
// useCleanState((a: boolean) => ({b: a.toString()}), true);
|
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @module CleanState
|
|
4
3
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
require("../../globals");
|
|
31
|
-
var class_1 = require("./class");
|
|
32
|
-
Object.defineProperty(exports, "CleanState", { enumerable: true, get: function () { return class_1.CleanState; } });
|
|
33
|
-
var hooks_1 = require("./hooks");
|
|
34
|
-
Object.defineProperty(exports, "useCleanState", { enumerable: true, get: function () { return hooks_1.useCleanState; } });
|
|
35
|
-
exports.MergedState = __importStar(require("../../base/merged-state"));
|
|
4
|
+
import '../../globals';
|
|
5
|
+
export { CleanState } from './class';
|
|
6
|
+
export { useCleanState } from './hooks';
|
|
7
|
+
export * as MergedState from '../../base/merged-state';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
1
2
|
import type { TPropsBase } from '../logic';
|
|
2
3
|
import type { Extractor } from './types/extractor';
|
|
3
4
|
import { ComponentInstance } from '../instance';
|
|
@@ -65,6 +66,14 @@ export declare class ClassComponent<TProps extends TPropsBase = null> extends Co
|
|
|
65
66
|
* Note that the callback argument is currently not supported.
|
|
66
67
|
*/
|
|
67
68
|
readonly forceUpdate: VoidFunction;
|
|
69
|
+
/**
|
|
70
|
+
* A standard React function component that works like any
|
|
71
|
+
* other function component and can be rendered as JSX.
|
|
72
|
+
* \`<MyComponent.FC />\`
|
|
73
|
+
*/
|
|
74
|
+
static _FC<T extends typeof ClassComponent>(this: T, props: InstanceType<T>['props']): JSX.Element | null;
|
|
75
|
+
static _BoundFC: typeof this._FC | undefined;
|
|
76
|
+
static get FC(): typeof ClassComponent._FC;
|
|
68
77
|
/*************************************
|
|
69
78
|
* Function Component Extractor *
|
|
70
79
|
**************************************/
|
|
@@ -92,8 +101,12 @@ export declare class ClassComponent<TProps extends TPropsBase = null> extends Co
|
|
|
92
101
|
* export default Button.RC;
|
|
93
102
|
*/
|
|
94
103
|
static readonly extract: Extractor;
|
|
95
|
-
/**
|
|
96
|
-
|
|
104
|
+
/**
|
|
105
|
+
* A standard React function component that works like any
|
|
106
|
+
* other function component and can be rendered as JSX.
|
|
107
|
+
* \`<MyComponent.RC />\`
|
|
108
|
+
*/
|
|
109
|
+
static readonly RC: React.VoidFunctionComponent<object | EmptyObject>;
|
|
97
110
|
}
|
|
98
111
|
export { ClassComponent as Component };
|
|
99
112
|
/** /
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __extends = (this && this.__extends) || (function () {
|
|
3
2
|
var extendStatics = function (d, b) {
|
|
4
3
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -14,12 +13,10 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
14
|
};
|
|
16
15
|
})();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var function_name_1 = require("./utils/function-name");
|
|
22
|
-
var rerender_1 = require("../../helpers/rerender");
|
|
16
|
+
import { useMemo } from 'react';
|
|
17
|
+
import { ComponentInstance, useInstance } from '../instance';
|
|
18
|
+
import { setFunctionName } from './utils/function-name';
|
|
19
|
+
import { useRerender } from '../../helpers/rerender';
|
|
23
20
|
/**
|
|
24
21
|
* @summary
|
|
25
22
|
* A modern class component for React that is fully compatible with
|
|
@@ -80,8 +77,40 @@ var ClassComponent = /** @class */ (function (_super) {
|
|
|
80
77
|
_this.template = function () { return null; };
|
|
81
78
|
return _this;
|
|
82
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* A standard React function component that works like any
|
|
82
|
+
* other function component and can be rendered as JSX.
|
|
83
|
+
* \`<MyComponent.FC />\`
|
|
84
|
+
*/
|
|
85
|
+
ClassComponent._FC = function (props) {
|
|
86
|
+
var _this = this;
|
|
87
|
+
var instance = useInstance(this, props);
|
|
88
|
+
var template = instance.template, templateContext = instance.templateContext;
|
|
89
|
+
var _forceUpdate;
|
|
90
|
+
// @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
|
|
91
|
+
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`.
|
|
92
|
+
);
|
|
93
|
+
// Add calling component name to template function name in stack traces.
|
|
94
|
+
useMemo(function () {
|
|
95
|
+
setFunctionName(template, "".concat(_this.name, ".template"));
|
|
96
|
+
}, [template]);
|
|
97
|
+
return template(templateContext);
|
|
98
|
+
};
|
|
99
|
+
;
|
|
100
|
+
Object.defineProperty(ClassComponent, "FC", {
|
|
101
|
+
get: function () {
|
|
102
|
+
if (this._BoundFC)
|
|
103
|
+
return this._BoundFC;
|
|
104
|
+
return this._BoundFC = this._FC.bind(this);
|
|
105
|
+
},
|
|
106
|
+
enumerable: false,
|
|
107
|
+
configurable: true
|
|
108
|
+
});
|
|
83
109
|
var _a;
|
|
84
110
|
_a = ClassComponent;
|
|
111
|
+
(function () {
|
|
112
|
+
setFunctionName(_a._FC, "$".concat(_a.name, "$"));
|
|
113
|
+
})();
|
|
85
114
|
/*************************************
|
|
86
115
|
* Function Component Extractor *
|
|
87
116
|
**************************************/
|
|
@@ -118,30 +147,34 @@ var ClassComponent = /** @class */ (function (_super) {
|
|
|
118
147
|
**************************************/
|
|
119
148
|
/** A class-based, React function component created with `@cleanweb/oore`. {@link ClassComponent} */
|
|
120
149
|
var Wrapper = function (props) {
|
|
121
|
-
var instance =
|
|
150
|
+
var instance = useInstance(Component, props);
|
|
122
151
|
var template = instance.template, templateContext = instance.templateContext;
|
|
123
152
|
var _forceUpdate;
|
|
124
153
|
// @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
|
|
125
|
-
instance.forceUpdate = (_forceUpdate =
|
|
154
|
+
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`.
|
|
126
155
|
);
|
|
127
156
|
// Add calling component name to template function name in stack traces.
|
|
128
|
-
|
|
129
|
-
|
|
157
|
+
useMemo(function () {
|
|
158
|
+
setFunctionName(template, "".concat(Component.name, ".template"));
|
|
130
159
|
}, [template]);
|
|
131
160
|
return template(templateContext);
|
|
132
161
|
};
|
|
133
162
|
/**************************************
|
|
134
163
|
* 👆🏼 End Function Component *
|
|
135
164
|
**************************************/
|
|
136
|
-
|
|
165
|
+
setFunctionName(Wrapper, "$".concat(Component.name, "$"));
|
|
137
166
|
return Object.assign(Wrapper, properties);
|
|
138
167
|
};
|
|
139
|
-
/**
|
|
140
|
-
|
|
168
|
+
/**
|
|
169
|
+
* A standard React function component that works like any
|
|
170
|
+
* other function component and can be rendered as JSX.
|
|
171
|
+
* \`<MyComponent.RC />\`
|
|
172
|
+
*/
|
|
173
|
+
ClassComponent.RC = _a.extract();
|
|
141
174
|
return ClassComponent;
|
|
142
|
-
}(
|
|
143
|
-
|
|
144
|
-
|
|
175
|
+
}(ComponentInstance));
|
|
176
|
+
export { ClassComponent };
|
|
177
|
+
export { ClassComponent as Component };
|
|
145
178
|
/** /
|
|
146
179
|
testing: {
|
|
147
180
|
const a: object = {b: ''};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
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
|
-
var setFunctionName = function (func, newName) {
|
|
2
|
+
export var setFunctionName = function (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 @@ var setFunctionName = function (func, newName) {
|
|
|
14
11
|
console.warn(error);
|
|
15
12
|
}
|
|
16
13
|
};
|
|
17
|
-
exports.setFunctionName = setFunctionName;
|
package/build/classy/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import type { UseInstance } from './types/hook';
|
|
2
2
|
import type { TPropsBase } from '../../classy/logic';
|
|
3
3
|
import { ComponentLogic } from '../../classy/logic';
|
|
4
|
-
type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
|
|
4
|
+
type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction | void>;
|
|
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,
|
|
@@ -86,7 +86,7 @@ export declare class ComponentInstance<TProps extends TPropsBase = null> extends
|
|
|
86
86
|
* PS: You can conditionally update state from here, but with certain caveats.
|
|
87
87
|
* {@link https://react.dev/reference/react/useState#storing-information-from-previous-renders | See the React docs for details}.
|
|
88
88
|
*/
|
|
89
|
-
beforeRender: () =>
|
|
89
|
+
beforeRender: () => any;
|
|
90
90
|
/**
|
|
91
91
|
* Runs **_after_** every render cycle, including the first.
|
|
92
92
|
*
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __extends = (this && this.__extends) || (function () {
|
|
3
2
|
var extendStatics = function (d, b) {
|
|
4
3
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -14,12 +13,10 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
14
|
};
|
|
16
15
|
})();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var mount_callbacks_1 = require("./mount-callbacks");
|
|
22
|
-
var helpers_1 = require("../../helpers");
|
|
16
|
+
import { useEffect } from 'react';
|
|
17
|
+
import { ComponentLogic, useLogic } from '../../classy/logic';
|
|
18
|
+
import { useMountCallbacks } from './mount-callbacks';
|
|
19
|
+
import { noOp } from '../../helpers';
|
|
23
20
|
/**
|
|
24
21
|
* A superset of {@link ComponentLogic} that adds support for lifecycle methods.
|
|
25
22
|
* This provides a declarative API for working with your React function component's lifecycle,
|
|
@@ -53,7 +50,7 @@ var ComponentInstance = /** @class */ (function (_super) {
|
|
|
53
50
|
*
|
|
54
51
|
* Uses `useEffect()` under the hood.
|
|
55
52
|
*/
|
|
56
|
-
_this.onMount = function () { return
|
|
53
|
+
_this.onMount = function () { return noOp; };
|
|
57
54
|
/**
|
|
58
55
|
* Runs _before_ every render cycle, including the first.
|
|
59
56
|
* Useful for logic that is involved in determining what to render.
|
|
@@ -69,7 +66,7 @@ var ComponentInstance = /** @class */ (function (_super) {
|
|
|
69
66
|
* PS: You can conditionally update state from here, but with certain caveats.
|
|
70
67
|
* {@link https://react.dev/reference/react/useState#storing-information-from-previous-renders | See the React docs for details}.
|
|
71
68
|
*/
|
|
72
|
-
_this.beforeRender = function () { };
|
|
69
|
+
_this.beforeRender = function () { return ({}); };
|
|
73
70
|
/**
|
|
74
71
|
* Runs **_after_** every render cycle, including the first.
|
|
75
72
|
*
|
|
@@ -80,7 +77,7 @@ var ComponentInstance = /** @class */ (function (_super) {
|
|
|
80
77
|
*
|
|
81
78
|
* @returns A cleanup function.
|
|
82
79
|
*/
|
|
83
|
-
_this.onRender = function () { return
|
|
80
|
+
_this.onRender = function () { return noOp; };
|
|
84
81
|
/**
|
|
85
82
|
* Runs when the component is unmounted.
|
|
86
83
|
* It is called _after_ the cleanup function returned by onMount.
|
|
@@ -128,8 +125,8 @@ var ComponentInstance = /** @class */ (function (_super) {
|
|
|
128
125
|
configurable: true
|
|
129
126
|
});
|
|
130
127
|
return ComponentInstance;
|
|
131
|
-
}(
|
|
132
|
-
|
|
128
|
+
}(ComponentLogic));
|
|
129
|
+
export { ComponentInstance };
|
|
133
130
|
;
|
|
134
131
|
/**
|
|
135
132
|
* Enables full separation of concerns between a React component's template
|
|
@@ -144,7 +141,7 @@ exports.ComponentInstance = ComponentInstance;
|
|
|
144
141
|
*
|
|
145
142
|
* The provided class should be a subclass of {@link ComponentInstance}.
|
|
146
143
|
*/
|
|
147
|
-
var useInstance = function () {
|
|
144
|
+
export var useInstance = function () {
|
|
148
145
|
var _a;
|
|
149
146
|
var args = [];
|
|
150
147
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -152,9 +149,9 @@ var useInstance = function () {
|
|
|
152
149
|
}
|
|
153
150
|
var Component = args[0], _b = args[1], props = _b === void 0 ? {} : _b;
|
|
154
151
|
// useHooks.
|
|
155
|
-
var instance =
|
|
152
|
+
var instance = useLogic(Component, props);
|
|
156
153
|
// beforeMount, onMount, cleanUp.
|
|
157
|
-
|
|
154
|
+
useMountCallbacks(instance);
|
|
158
155
|
// beforeRender.
|
|
159
156
|
/**
|
|
160
157
|
* A proxy variable to allow typechecking of the assignment
|
|
@@ -164,7 +161,7 @@ var useInstance = function () {
|
|
|
164
161
|
// @ts-expect-error Assigning to a readonly property.
|
|
165
162
|
instance._templateContext = (_templateContextProxy_ = (_a = instance.beforeRender) === null || _a === void 0 ? void 0 : _a.call(instance));
|
|
166
163
|
// onRender.
|
|
167
|
-
|
|
164
|
+
useEffect(function () {
|
|
168
165
|
var _a;
|
|
169
166
|
var cleanupAfterRerender = (_a = instance.onRender) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
170
167
|
return function () {
|
|
@@ -174,9 +171,9 @@ var useInstance = function () {
|
|
|
174
171
|
cleanupAfterRerender === null || cleanupAfterRerender === void 0 ? void 0 : cleanupAfterRerender.then(function (cleanUp) { return cleanUp === null || cleanUp === void 0 ? void 0 : cleanUp(); });
|
|
175
172
|
};
|
|
176
173
|
});
|
|
174
|
+
// class FormValues<TValues> extends BrowserMemStore<TValues> {}
|
|
177
175
|
return instance;
|
|
178
176
|
};
|
|
179
|
-
exports.useInstance = useInstance;
|
|
180
177
|
/** /
|
|
181
178
|
testing: {
|
|
182
179
|
class A extends ComponentInstance<EmptyObject> {
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useMountCallbacks = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
var mount_state_1 = require("../../helpers/mount-state");
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useMountState } from '../../helpers/mount-state';
|
|
6
3
|
/** @internal */
|
|
7
|
-
var useMountCallbacks = function (instance) {
|
|
4
|
+
export var useMountCallbacks = function (instance) {
|
|
8
5
|
var _a;
|
|
9
|
-
var isMounted =
|
|
6
|
+
var isMounted = useMountState();
|
|
10
7
|
if (!isMounted())
|
|
11
8
|
(_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
12
|
-
|
|
9
|
+
useEffect(function () {
|
|
13
10
|
var _a;
|
|
14
11
|
var mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
15
12
|
return function () {
|
|
@@ -27,4 +24,3 @@ var useMountCallbacks = function (instance) {
|
|
|
27
24
|
};
|
|
28
25
|
}, []);
|
|
29
26
|
};
|
|
30
|
-
exports.useMountCallbacks = useMountCallbacks;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useLogic = exports.ComponentLogic = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
var 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
|
*
|
|
@@ -42,7 +39,7 @@ var ComponentLogic = /** @class */ (function () {
|
|
|
42
39
|
}
|
|
43
40
|
return ComponentLogic;
|
|
44
41
|
}());
|
|
45
|
-
|
|
42
|
+
export { ComponentLogic };
|
|
46
43
|
;
|
|
47
44
|
/**
|
|
48
45
|
* Returns an instance of the provided class, which holds methods for your component and
|
|
@@ -52,7 +49,7 @@ exports.ComponentLogic = ComponentLogic;
|
|
|
52
49
|
*
|
|
53
50
|
* @see https://cleanjsweb.github.io/neat-react/functions/API.useLogic.html
|
|
54
51
|
*/
|
|
55
|
-
var useLogic = function () {
|
|
52
|
+
export var useLogic = function () {
|
|
56
53
|
var _a;
|
|
57
54
|
var args = [];
|
|
58
55
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -62,15 +59,15 @@ var useLogic = function () {
|
|
|
62
59
|
// In production, we only use the latestInstance the first time, and it's ignored every other time.
|
|
63
60
|
// This means changing the class at runtime will have no effect in production.
|
|
64
61
|
// latestInstance is only extracted into a separate variable for use in dev mode during HMR.
|
|
65
|
-
var latestInstance =
|
|
62
|
+
var latestInstance = useMemo(function () { return new Logic(); }, [Logic]);
|
|
66
63
|
// const latestInstance = useMemo(() => new Logic(), []);
|
|
67
|
-
var instanceRef =
|
|
64
|
+
var instanceRef = useRef(latestInstance);
|
|
68
65
|
var refreshState = function () {
|
|
69
66
|
var _a;
|
|
70
67
|
// @ts-expect-error
|
|
71
68
|
instanceRef.current.props = props;
|
|
72
69
|
// @ts-expect-error
|
|
73
|
-
instanceRef.current.state =
|
|
70
|
+
instanceRef.current.state = useCleanState(instanceRef.current.getInitialState, props);
|
|
74
71
|
// @ts-expect-error
|
|
75
72
|
instanceRef.current.hooks = (_a = instanceRef.current.useHooks()) !== null && _a !== void 0 ? _a : {};
|
|
76
73
|
};
|
|
@@ -95,7 +92,6 @@ var useLogic = function () {
|
|
|
95
92
|
return instanceRef.current;
|
|
96
93
|
;
|
|
97
94
|
};
|
|
98
|
-
exports.useLogic = useLogic;
|
|
99
95
|
/** /
|
|
100
96
|
testing: {
|
|
101
97
|
const a: object = {b: ''};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
export * as BaseClasses from './base-classes';
|
|
12
|
+
export * as Helpers from '../../helpers';
|
|
13
|
+
export * as References from './references';
|
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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';
|
package/build/globals.js
CHANGED
package/build/helpers/errors.js
CHANGED
|
@@ -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
|
-
var throwDevError = function (message) {
|
|
10
|
+
export var throwDevError = function (message) {
|
|
14
11
|
if (process.env.NODE_ENV === 'production') {
|
|
15
12
|
console.warn(message);
|
|
16
13
|
}
|
|
@@ -18,4 +15,3 @@ var throwDevError = function (message) {
|
|
|
18
15
|
throw new Error(message);
|
|
19
16
|
}
|
|
20
17
|
};
|
|
21
|
-
exports.throwDevError = throwDevError;
|
package/build/helpers/index.js
CHANGED
|
@@ -1,31 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* <!-- @ mergeModuleWith API -->
|
|
4
3
|
* @module Helpers
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
var noOp = function () { };
|
|
31
|
-
exports.noOp = noOp;
|
|
13
|
+
export var noOp = function () { };
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useMountState = void 0;
|
|
4
|
-
var 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
|
-
var useMountState = function () {
|
|
6
|
+
export var useMountState = function () {
|
|
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
|
-
var mounted =
|
|
17
|
-
|
|
13
|
+
var mounted = useRef(false);
|
|
14
|
+
useEffect(function () {
|
|
18
15
|
mounted.current = true;
|
|
19
16
|
return function () {
|
|
20
17
|
mounted.current = false;
|
|
@@ -22,4 +19,3 @@ var useMountState = function () {
|
|
|
22
19
|
}, []);
|
|
23
20
|
return function () { return mounted.current; };
|
|
24
21
|
};
|
|
25
|
-
exports.useMountState = useMountState;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useRerender = void 0;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
var 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
|
-
var useRerender = function () {
|
|
12
|
-
var isMounted =
|
|
13
|
-
var renderCount =
|
|
14
|
-
var _a =
|
|
8
|
+
export var useRerender = function () {
|
|
9
|
+
var isMounted = useMountState();
|
|
10
|
+
var renderCount = useRef(0);
|
|
11
|
+
var _a = useState(renderCount.current), forceRerender = _a[1];
|
|
15
12
|
renderCount.current++;
|
|
16
|
-
var rerender =
|
|
13
|
+
var rerender = useCallback(function () {
|
|
17
14
|
var resolve;
|
|
18
15
|
var promise = new Promise(function (_r) { return resolve = _r; });
|
|
19
16
|
var execute = function () {
|
|
@@ -39,4 +36,3 @@ var useRerender = function () {
|
|
|
39
36
|
refresher.currentCount = renderCount.current;
|
|
40
37
|
return refresher;
|
|
41
38
|
};
|
|
42
|
-
exports.useRerender = useRerender;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.canIndex = void 0;
|
|
4
|
-
var canIndex = function (key, targetObject) {
|
|
1
|
+
export var canIndex = function (key, targetObject) {
|
|
5
2
|
var test = typeof key === 'number' ? "".concat(key) : key;
|
|
6
3
|
return Reflect.ownKeys(targetObject).includes(test);
|
|
7
4
|
};
|
|
8
|
-
exports.canIndex = canIndex;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Use = void 0;
|
|
4
|
-
var 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
|
-
var Use = function (params) {
|
|
6
|
+
export var Use = function (params) {
|
|
10
7
|
var useGenericHook = params.hook, argumentsList = params.argumentsList, onUpdate = params.onUpdate;
|
|
11
8
|
var output = useGenericHook.apply(void 0, argumentsList);
|
|
12
|
-
|
|
9
|
+
useEffect(function () {
|
|
13
10
|
onUpdate(output);
|
|
14
11
|
}, [output]);
|
|
15
12
|
return null;
|
|
16
13
|
};
|
|
17
|
-
exports.Use = Use;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/build/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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';
|
package/build/slots/hook.js
CHANGED
|
@@ -1,27 +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 __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
1
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
26
2
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
27
3
|
if (ar || !(i in from)) {
|
|
@@ -31,18 +7,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
31
7
|
}
|
|
32
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
9
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
var react_1 = __importStar(require("react"));
|
|
38
|
-
var isElementChild = function (child) {
|
|
10
|
+
import { throwDevError } from '../helpers/errors';
|
|
11
|
+
import React, { useMemo } from 'react';
|
|
12
|
+
export var isElementChild = function (child) {
|
|
39
13
|
if (child && typeof child === 'object' && 'type' in child) {
|
|
40
14
|
return true;
|
|
41
15
|
}
|
|
42
16
|
return false;
|
|
43
17
|
};
|
|
44
|
-
|
|
45
|
-
var getComponentSlotName = function (TargetComponent, child) {
|
|
18
|
+
export var getComponentSlotName = function (TargetComponent, child) {
|
|
46
19
|
if (child) {
|
|
47
20
|
var keyTypes = ['string', 'number', 'symbol'];
|
|
48
21
|
var slotName = child.props['data-slot-name'];
|
|
@@ -61,13 +34,11 @@ var getComponentSlotName = function (TargetComponent, child) {
|
|
|
61
34
|
}
|
|
62
35
|
return undefined;
|
|
63
36
|
};
|
|
64
|
-
|
|
65
|
-
var isPortalChild = function (child) {
|
|
37
|
+
export var isPortalChild = function (child) {
|
|
66
38
|
return (!!child
|
|
67
39
|
&& typeof child === 'object'
|
|
68
40
|
&& 'children' in child);
|
|
69
41
|
};
|
|
70
|
-
exports.isPortalChild = isPortalChild;
|
|
71
42
|
/**
|
|
72
43
|
* Groups `children` prop into predefined slots.
|
|
73
44
|
*
|
|
@@ -78,15 +49,15 @@ exports.isPortalChild = isPortalChild;
|
|
|
78
49
|
*
|
|
79
50
|
* @see {@link SlotComponent} for more on how to use the returned slot nodes.
|
|
80
51
|
*/
|
|
81
|
-
var useSlots = function (children, Caller) {
|
|
82
|
-
var slotsAliasLookup =
|
|
52
|
+
export var useSlots = function (children, Caller) {
|
|
53
|
+
var slotsAliasLookup = useMemo(function () {
|
|
83
54
|
var entries = Object.entries(Caller.Slots);
|
|
84
55
|
var aliasLookup = {};
|
|
85
56
|
entries.forEach(function (_a) {
|
|
86
57
|
var alias = _a[0], RegisteredSlotComponent = _a[1];
|
|
87
|
-
var slotName =
|
|
58
|
+
var slotName = getComponentSlotName(RegisteredSlotComponent);
|
|
88
59
|
if (!slotName) {
|
|
89
|
-
|
|
60
|
+
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: ".concat(RegisteredSlotComponent));
|
|
90
61
|
return;
|
|
91
62
|
}
|
|
92
63
|
aliasLookup[slotName] = alias;
|
|
@@ -94,33 +65,33 @@ var useSlots = function (children, Caller) {
|
|
|
94
65
|
return aliasLookup;
|
|
95
66
|
}, [Caller.Slots]);
|
|
96
67
|
// @todo Expose original source order of `children` with respect to slot aliases.
|
|
97
|
-
var result =
|
|
68
|
+
var result = useMemo(function () {
|
|
98
69
|
var _a;
|
|
99
70
|
var slotNodes = {};
|
|
100
71
|
var unmatchedChildren = [];
|
|
101
72
|
var invalidChildren = [];
|
|
102
73
|
var requiredSlotAliases = __spreadArray([], ((_a = Caller.requiredSlotAliases) !== null && _a !== void 0 ? _a : []), true);
|
|
103
|
-
|
|
74
|
+
React.Children.forEach(children, function (_child) {
|
|
104
75
|
var _a;
|
|
105
76
|
var child = _child;
|
|
106
77
|
if (!child) {
|
|
107
78
|
invalidChildren.push(child);
|
|
108
79
|
return;
|
|
109
80
|
}
|
|
110
|
-
if (!
|
|
81
|
+
if (!React.isValidElement(child)) {
|
|
111
82
|
console.warn("Invalid node found in JSX children while parsing slots. Got: \"".concat(child, "\"."));
|
|
112
83
|
invalidChildren.push(child);
|
|
113
84
|
return;
|
|
114
85
|
}
|
|
115
86
|
;
|
|
116
87
|
// @todo Check for fragment
|
|
117
|
-
if (!
|
|
88
|
+
if (!isElementChild(child)) {
|
|
118
89
|
unmatchedChildren.push(child);
|
|
119
90
|
return;
|
|
120
91
|
}
|
|
121
92
|
var slotAlias = (function () {
|
|
122
93
|
var _a;
|
|
123
|
-
var slotName =
|
|
94
|
+
var slotName = getComponentSlotName(child.type, child);
|
|
124
95
|
return slotName ? (_a = slotsAliasLookup[slotName]) !== null && _a !== void 0 ? _a : null : null;
|
|
125
96
|
})();
|
|
126
97
|
if (slotAlias) {
|
|
@@ -141,11 +112,10 @@ var useSlots = function (children, Caller) {
|
|
|
141
112
|
});
|
|
142
113
|
requiredSlotAliases.forEach(function (slotAlias) {
|
|
143
114
|
if (!slotNodes[slotAlias]) {
|
|
144
|
-
|
|
115
|
+
throwDevError("Missing required slot \"".concat(String(slotAlias), "\"."));
|
|
145
116
|
}
|
|
146
117
|
});
|
|
147
118
|
return [slotNodes, unmatchedChildren, invalidChildren];
|
|
148
119
|
}, [children]);
|
|
149
120
|
return result;
|
|
150
121
|
};
|
|
151
|
-
exports.useSlots = useSlots;
|
package/build/slots/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
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';
|
package/build/slots/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/build/tsconfig.json
CHANGED
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"forceConsistentCasingInFileNames": true,
|
|
24
24
|
"incremental": false,
|
|
25
25
|
"esModuleInterop": true,
|
|
26
|
-
"module": "
|
|
27
|
-
"moduleResolution": "
|
|
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.
|
|
3
|
+
"version": "2.0.0-alpha.16",
|
|
4
4
|
"description": "A library of helpers for writing cleaner React function components with object-oriented patterns.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
".npmrc"
|
|
11
11
|
],
|
|
12
12
|
"main": "build/index.js",
|
|
13
|
+
"type": "module",
|
|
13
14
|
"exports": {
|
|
14
15
|
".": "./build/classy/index.js",
|
|
15
16
|
"./base": "./build/base/index.js",
|