@cleanweb/oore 2.0.0-alpha.15 → 2.0.0-alpha.18
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/_cjs/base/index.d.ts +3 -0
- package/build/_cjs/base/index.js +19 -0
- package/build/_cjs/base/merged-state.d.ts +20 -0
- package/build/_cjs/base/merged-state.js +61 -0
- package/build/_cjs/base/methods.d.ts +58 -0
- package/build/_cjs/base/methods.js +95 -0
- package/build/_cjs/base/state/class-types.d.ts +20 -0
- package/build/_cjs/base/state/class-types.js +2 -0
- package/build/_cjs/base/state/class.d.ts +69 -0
- package/build/_cjs/base/state/class.js +129 -0
- package/build/_cjs/base/state/hook-types.d.ts +32 -0
- package/build/_cjs/base/state/hook-types.js +2 -0
- package/build/_cjs/base/state/hooks.d.ts +12 -0
- package/build/_cjs/base/state/hooks.js +41 -0
- package/build/_cjs/base/state/index.d.ts +9 -0
- package/build/_cjs/base/state/index.js +35 -0
- package/build/_cjs/classy/class/index.d.ts +128 -0
- package/build/_cjs/classy/class/index.js +174 -0
- package/build/_cjs/classy/class/types/extractor.d.ts +5 -0
- package/build/_cjs/classy/class/types/extractor.js +2 -0
- package/build/_cjs/classy/class/utils/function-name.d.ts +2 -0
- package/build/_cjs/classy/class/utils/function-name.js +17 -0
- package/build/_cjs/classy/index.d.ts +3 -0
- package/build/_cjs/classy/index.js +19 -0
- package/build/_cjs/classy/instance/index.d.ts +144 -0
- package/build/_cjs/classy/instance/index.js +177 -0
- package/build/_cjs/classy/instance/mount-callbacks.d.ts +5 -0
- package/build/_cjs/classy/instance/mount-callbacks.js +30 -0
- package/build/_cjs/classy/instance/types/hook.d.ts +13 -0
- package/build/_cjs/classy/instance/types/hook.js +2 -0
- package/build/_cjs/classy/logic/index.d.ts +116 -0
- package/build/_cjs/classy/logic/index.js +123 -0
- package/build/_cjs/classy/logic/types/hook.d.ts +16 -0
- package/build/_cjs/classy/logic/types/hook.js +2 -0
- package/build/_cjs/docs-src/api/base-classes.d.ts +3 -0
- package/build/_cjs/docs-src/api/base-classes.js +9 -0
- package/build/_cjs/docs-src/api/index.d.ts +13 -0
- package/build/_cjs/docs-src/api/index.js +44 -0
- package/build/_cjs/docs-src/api/references.d.ts +5 -0
- package/build/_cjs/docs-src/api/references.js +31 -0
- package/build/_cjs/helpers/errors.d.ts +10 -0
- package/build/_cjs/helpers/errors.js +21 -0
- package/build/_cjs/helpers/index.d.ts +13 -0
- package/build/_cjs/helpers/index.js +31 -0
- package/build/_cjs/helpers/mount-state.d.ts +5 -0
- package/build/_cjs/helpers/mount-state.js +25 -0
- package/build/_cjs/helpers/rerender.d.ts +24 -0
- package/build/_cjs/helpers/rerender.js +42 -0
- package/build/_cjs/helpers/type-guards.d.ts +1 -0
- package/build/_cjs/helpers/type-guards.js +8 -0
- package/build/_cjs/helpers/use-component/index.d.ts +6 -0
- package/build/_cjs/helpers/use-component/index.js +17 -0
- package/build/_cjs/helpers/use-component/types.d.ts +22 -0
- package/build/_cjs/helpers/use-component/types.js +2 -0
- package/build/_cjs/index.d.ts +3 -0
- package/build/_cjs/index.js +19 -0
- package/build/_cjs/slots/hook.d.ts +20 -0
- package/build/_cjs/slots/hook.js +143 -0
- package/build/_cjs/slots/index.d.ts +1 -0
- package/build/_cjs/slots/index.js +17 -0
- package/build/_cjs/slots/types.d.ts +131 -0
- package/build/_cjs/slots/types.js +2 -0
- package/build/base/merged-state.js +30 -53
- package/build/base/methods.d.ts +2 -3
- package/build/base/methods.js +18 -23
- package/build/base/state/class.js +45 -68
- package/build/base/state/hooks.js +6 -10
- package/build/classy/class/index.d.ts +15 -2
- package/build/classy/class/index.js +96 -83
- package/build/classy/class/utils/function-name.js +1 -1
- package/build/classy/instance/index.d.ts +1 -1
- package/build/classy/instance/index.js +57 -82
- package/build/classy/instance/mount-callbacks.js +8 -8
- package/build/classy/logic/index.js +21 -26
- package/build/globals.d.ts +130 -83
- package/build/helpers/errors.js +1 -1
- package/build/helpers/index.js +1 -1
- package/build/helpers/mount-state.js +6 -6
- package/build/helpers/rerender.js +12 -12
- package/build/helpers/type-guards.js +2 -2
- package/build/helpers/use-component/index.js +5 -5
- package/build/index.d.ts +0 -1
- package/build/slots/hook.js +28 -36
- package/build/tsconfig.json +5 -6
- package/package.json +31 -11
- package/build/globals.js +0 -4
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useMountCallbacks = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const mount_state_1 = require("../../helpers/mount-state");
|
|
6
6
|
/** @internal */
|
|
7
|
-
|
|
7
|
+
const useMountCallbacks = (instance) => {
|
|
8
8
|
var _a;
|
|
9
|
-
|
|
9
|
+
const isMounted = (0, mount_state_1.useMountState)();
|
|
10
10
|
if (!isMounted())
|
|
11
11
|
(_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
12
|
-
(0, react_1.useEffect)(
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
13
|
var _a;
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
14
|
+
const mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
15
|
+
return () => {
|
|
16
|
+
const doCleanUp = (runMountCleaners) => {
|
|
17
17
|
var _a;
|
|
18
18
|
runMountCleaners === null || runMountCleaners === void 0 ? void 0 : runMountCleaners();
|
|
19
19
|
(_a = instance.cleanUp) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLogic = exports.ComponentLogic = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const state_1 = require("../../base/state");
|
|
6
6
|
/**
|
|
7
7
|
* Base class for a class that holds methods to be used in a function component.
|
|
8
8
|
*
|
|
@@ -16,14 +16,14 @@ var state_1 = require("../../base/state");
|
|
|
16
16
|
*
|
|
17
17
|
* @typeParam TProps - {@include ./types/tprops.md}
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
class ComponentLogic {
|
|
20
|
+
constructor() {
|
|
21
21
|
/**
|
|
22
22
|
* Called before each instance of your component is mounted.
|
|
23
23
|
* It receives the initial `props` object and should return
|
|
24
24
|
* an object with the initial values for your component's state.
|
|
25
25
|
*/
|
|
26
|
-
this.getInitialState =
|
|
26
|
+
this.getInitialState = (props) => ({});
|
|
27
27
|
/**
|
|
28
28
|
* Call React hooks from here. If your component needs
|
|
29
29
|
* access to values return from the hooks you call,
|
|
@@ -32,7 +32,7 @@ var ComponentLogic = /** @class */ (function () {
|
|
|
32
32
|
* The returned object will be accessible as {@link hooks | `this.hooks`} within
|
|
33
33
|
* your component class.
|
|
34
34
|
*/
|
|
35
|
-
this.useHooks =
|
|
35
|
+
this.useHooks = () => { };
|
|
36
36
|
/**
|
|
37
37
|
* Persist class members during HMR. {@include ./hrm-preserve-keys.md}
|
|
38
38
|
* @privateRemarks
|
|
@@ -40,8 +40,7 @@ var ComponentLogic = /** @class */ (function () {
|
|
|
40
40
|
*/
|
|
41
41
|
this._hmrPreserveKeys = [];
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
}());
|
|
43
|
+
}
|
|
45
44
|
exports.ComponentLogic = ComponentLogic;
|
|
46
45
|
;
|
|
47
46
|
/**
|
|
@@ -52,20 +51,16 @@ exports.ComponentLogic = ComponentLogic;
|
|
|
52
51
|
*
|
|
53
52
|
* @see https://cleanjsweb.github.io/neat-react/functions/API.useLogic.html
|
|
54
53
|
*/
|
|
55
|
-
|
|
54
|
+
const useLogic = (...args) => {
|
|
56
55
|
var _a;
|
|
57
|
-
|
|
58
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
59
|
-
args[_i] = arguments[_i];
|
|
60
|
-
}
|
|
61
|
-
var Logic = args[0], _b = args[1], props = _b === void 0 ? {} : _b;
|
|
56
|
+
const [Logic, props = {}] = args;
|
|
62
57
|
// In production, we only use the latestInstance the first time, and it's ignored every other time.
|
|
63
58
|
// This means changing the class at runtime will have no effect in production.
|
|
64
59
|
// latestInstance is only extracted into a separate variable for use in dev mode during HMR.
|
|
65
|
-
|
|
60
|
+
const latestInstance = (0, react_1.useMemo)(() => new Logic(), [Logic]);
|
|
66
61
|
// const latestInstance = useMemo(() => new Logic(), []);
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const instanceRef = (0, react_1.useRef)(latestInstance);
|
|
63
|
+
const refreshState = () => {
|
|
69
64
|
var _a;
|
|
70
65
|
// @ts-expect-error
|
|
71
66
|
instanceRef.current.props = props;
|
|
@@ -75,20 +70,20 @@ var useLogic = function () {
|
|
|
75
70
|
instanceRef.current.hooks = (_a = instanceRef.current.useHooks()) !== null && _a !== void 0 ? _a : {};
|
|
76
71
|
};
|
|
77
72
|
if (process.env.NODE_ENV === 'development' && instanceRef.current !== latestInstance) {
|
|
78
|
-
|
|
79
|
-
latestInstance._hmrPreserveKeys.forEach(
|
|
80
|
-
|
|
73
|
+
const oldInstance = instanceRef.current;
|
|
74
|
+
latestInstance._hmrPreserveKeys.forEach((_key) => {
|
|
75
|
+
const key = _key;
|
|
81
76
|
// @ts-expect-error We're assigning to readonly properties. Also, Typescript doesn't know that the type of the left and right side will always match, due to the dynamic access.
|
|
82
|
-
latestInstance[key] =
|
|
77
|
+
latestInstance[key] = oldInstance[key];
|
|
83
78
|
});
|
|
84
|
-
Reflect.ownKeys(
|
|
85
|
-
|
|
86
|
-
delete
|
|
79
|
+
Reflect.ownKeys(oldInstance).forEach((_key) => {
|
|
80
|
+
const key = _key;
|
|
81
|
+
delete oldInstance[key];
|
|
87
82
|
});
|
|
88
|
-
Object.setPrototypeOf(
|
|
83
|
+
Object.setPrototypeOf(oldInstance, latestInstance);
|
|
89
84
|
instanceRef.current = latestInstance;
|
|
90
85
|
refreshState();
|
|
91
|
-
(_a = latestInstance._onHmrUpdate) === null || _a === void 0 ? void 0 : _a.call(latestInstance,
|
|
86
|
+
(_a = latestInstance._onHmrUpdate) === null || _a === void 0 ? void 0 : _a.call(latestInstance, oldInstance);
|
|
92
87
|
}
|
|
93
88
|
else
|
|
94
89
|
refreshState();
|
package/build/globals.d.ts
CHANGED
|
@@ -1,84 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
1
|
+
interface EmptyObject3 {
|
|
2
|
+
/**
|
|
3
|
+
* It appears keys of the base `symbol` type are excluded from
|
|
4
|
+
* excess property checks. This is likely a bug in TypeScript.
|
|
5
|
+
* Even the "has no properties in common" error disappears if the
|
|
6
|
+
* value being placed into a variable has a key typed as `symbol`.
|
|
7
|
+
* This only applies to the base `symbol` type. Specifc `'unique symbol'`
|
|
8
|
+
* types are unaffected.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Consider the following object:
|
|
12
|
+
* const myUniqueSymbol = Symbol('lkjhgfc');
|
|
13
|
+
* let myObj = { [myUniqueSymbol]?: 'a string value' };
|
|
14
|
+
*
|
|
15
|
+
* // We can attempt to reassign `myObj` with the expectation that TS will
|
|
16
|
+
* // warn if any key other than `myUniqueSymbol` is used in the new object.
|
|
17
|
+
* // But this breaks in one specific scenario.
|
|
18
|
+
*
|
|
19
|
+
* // No excess property check when this is used as a key.
|
|
20
|
+
* // Error "no properties in common" also suppressed when this is used as a key.
|
|
21
|
+
* const differentBasicSymbol = Symbol('qwertiop[') as symbol;
|
|
22
|
+
* myObj = { [differentBasicSymbol]: 5 };
|
|
23
|
+
*
|
|
24
|
+
* // Errors emitted as expected when this is used as a key.
|
|
25
|
+
* const differentUniqueSymbol = Symbol('zxcvbnm');
|
|
26
|
+
* myObj = { [differentUniqueSymbol]: 5 };
|
|
27
|
+
*/
|
|
28
|
+
[key: symbol]: never;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/////////////
|
|
33
|
+
const UniqueSecretSymbolKey = Symbol('asdfghjkliuytrewqaxcvb,nb');
|
|
34
|
+
|
|
35
|
+
type TEmptyObject1 = { ''?: never };
|
|
36
|
+
type TEmptyObject2 = Record<keyof any, never>;
|
|
37
|
+
|
|
38
|
+
type Optional<
|
|
39
|
+
BaseType,
|
|
40
|
+
AllowNull extends boolean = true
|
|
41
|
+
> = (
|
|
42
|
+
AllowNull extends true
|
|
43
|
+
? BaseType | undefined | null
|
|
44
|
+
: BaseType | undefined
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
type Awaitable<Type> = Type | Promise<Type>;
|
|
48
|
+
|
|
49
|
+
type Constructor<
|
|
50
|
+
TInstance extends any = any,
|
|
51
|
+
TParams extends any[] = never[]
|
|
52
|
+
> = new (...args: TParams) => TInstance;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @example
|
|
57
|
+
* ```js
|
|
58
|
+
* const getNumber: AsyncFunction<number> = async () => {
|
|
59
|
+
* return 5;
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
type AsyncFunction<
|
|
64
|
+
TReturnValue extends any = void,
|
|
65
|
+
Params extends any[] = never[]
|
|
66
|
+
> = (...params: Params) => Promise<TReturnValue>
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A function that takes no arguments and returns nothing.
|
|
70
|
+
* Pass a type argument to set whether `async` and/or `sync` functions are allowed.
|
|
71
|
+
*/
|
|
72
|
+
interface IVoidFunction<AsyncType extends 'async' | 'sync' | 'both' = 'both'> {
|
|
73
|
+
(): AsyncType extends 'async' ? Promise<void>
|
|
74
|
+
: AsyncType extends 'sync' ? void
|
|
75
|
+
: void | Promise<void>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type AnyFunction = (...args: any) => any;
|
|
79
|
+
type FunctionType = AnyFunction;
|
|
80
|
+
type TFunction = AnyFunction;
|
|
81
|
+
|
|
82
|
+
/** @deprecated Use {@link NonNullish} */
|
|
83
|
+
type NotNullish = {};
|
|
84
|
+
type NonNullish = {};
|
|
85
|
+
type NonPrimitive = object;
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Describes an object that has no keys,
|
|
90
|
+
* except for a secret unique symbol key,
|
|
91
|
+
* whose value type is the union `never | undefuned`.
|
|
92
|
+
*
|
|
93
|
+
* Having a single key allows the object to throw type errors
|
|
94
|
+
* of the form:
|
|
95
|
+
* ```
|
|
96
|
+
* Type `A` has no properties in common with `EmptyObject`.
|
|
97
|
+
* ```
|
|
98
|
+
* This may provide a slightly stricter type checking than simply
|
|
99
|
+
* using the non-nullish (`{}`) or non-primitive (`object`)
|
|
100
|
+
* built-in types.
|
|
101
|
+
*
|
|
102
|
+
* Note: `EmptyObject` is not assignable to `NeverObject`
|
|
103
|
+
* because it has a key whose value type includes `undefined`,
|
|
104
|
+
* but `NeverObject` keys can only have a type of `never`.
|
|
105
|
+
*/
|
|
106
|
+
interface EmptyObject {
|
|
107
|
+
[UniqueSecretSymbolKey]?: never;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Describes an object that can have any key, but all keys have
|
|
112
|
+
* a type of `never`. This effectively prevents any value
|
|
113
|
+
* from ever being stored on the object. The object is therefore
|
|
114
|
+
* guaranteed to always be empty.
|
|
115
|
+
*/
|
|
116
|
+
interface NeverObject {
|
|
117
|
+
[key: keyof any]: never;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
type valueof<TObject> = TObject[keyof TObject];
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
//////////////////
|
|
124
|
+
interface Window {
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
namespace NodeJS {
|
|
128
|
+
interface ProcessEnv {
|
|
129
|
+
NODE_ENV: 'development' | 'production' | 'test',
|
|
130
|
+
}
|
|
83
131
|
}
|
|
84
|
-
export {};
|
package/build/helpers/errors.js
CHANGED
|
@@ -10,7 +10,7 @@ exports.throwDevError = void 0;
|
|
|
10
10
|
* Useful for enforcing certain conditions in development
|
|
11
11
|
* while failing more gracefully in production.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
const throwDevError = (message) => {
|
|
14
14
|
if (process.env.NODE_ENV === 'production') {
|
|
15
15
|
console.warn(message);
|
|
16
16
|
}
|
package/build/helpers/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useMountState = void 0;
|
|
4
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
5
|
/**
|
|
6
6
|
* Returns a value that is false before the component has been mounted,
|
|
7
7
|
* then true during all subsequent rerenders.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const useMountState = () => {
|
|
10
10
|
/**
|
|
11
11
|
* This must not be a state value. It should not be the cause of a rerender.
|
|
12
12
|
* It merely provides information about the render count,
|
|
13
13
|
* without influencing that count itself.
|
|
14
14
|
* So `mounted` should never be created with `useState`.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
(0, react_1.useEffect)(
|
|
16
|
+
const mounted = (0, react_1.useRef)(false);
|
|
17
|
+
(0, react_1.useEffect)(() => {
|
|
18
18
|
mounted.current = true;
|
|
19
|
-
return
|
|
19
|
+
return () => {
|
|
20
20
|
mounted.current = false;
|
|
21
21
|
};
|
|
22
22
|
}, []);
|
|
23
|
-
return
|
|
23
|
+
return () => mounted.current;
|
|
24
24
|
};
|
|
25
25
|
exports.useMountState = useMountState;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useRerender = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const mount_state_1 = require("../helpers/mount-state");
|
|
6
6
|
;
|
|
7
7
|
/**
|
|
8
8
|
* Returns a function that can be called to manually trigger
|
|
9
9
|
* a rerender of your component.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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);
|
|
15
15
|
renderCount.current++;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const rerender = (0, react_1.useCallback)(() => {
|
|
17
|
+
let resolve;
|
|
18
|
+
const promise = new Promise((_r) => resolve = _r);
|
|
19
|
+
const execute = () => {
|
|
20
20
|
forceRerender(renderCount.current);
|
|
21
21
|
resolve({
|
|
22
22
|
previousCount: renderCount.current,
|
|
@@ -26,7 +26,7 @@ var useRerender = function () {
|
|
|
26
26
|
if (isMounted())
|
|
27
27
|
execute();
|
|
28
28
|
else {
|
|
29
|
-
setTimeout(
|
|
29
|
+
setTimeout(() => {
|
|
30
30
|
if (isMounted())
|
|
31
31
|
execute();
|
|
32
32
|
else
|
|
@@ -35,7 +35,7 @@ var useRerender = function () {
|
|
|
35
35
|
}
|
|
36
36
|
return promise;
|
|
37
37
|
}, [forceRerender, renderCount]);
|
|
38
|
-
|
|
38
|
+
const refresher = () => rerender();
|
|
39
39
|
refresher.currentCount = renderCount.current;
|
|
40
40
|
return refresher;
|
|
41
41
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.canIndex = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const canIndex = (key, targetObject) => {
|
|
5
|
+
const test = typeof key === 'number' ? `${key}` : key;
|
|
6
6
|
return Reflect.ownKeys(targetObject).includes(test);
|
|
7
7
|
};
|
|
8
8
|
exports.canIndex = canIndex;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Use = void 0;
|
|
4
|
-
|
|
4
|
+
const react_1 = require("react");
|
|
5
5
|
/**
|
|
6
6
|
* A component you can use to consume React hooks
|
|
7
7
|
* in a {@link Component | React.Component} class.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(0, react_1.useEffect)(
|
|
9
|
+
const Use = (params) => {
|
|
10
|
+
const { hook: useGenericHook, argumentsList, onUpdate } = params;
|
|
11
|
+
const output = useGenericHook(...argumentsList);
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
13
|
onUpdate(output);
|
|
14
14
|
}, [output]);
|
|
15
15
|
return null;
|
package/build/index.d.ts
CHANGED
package/build/slots/hook.js
CHANGED
|
@@ -22,30 +22,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
26
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
27
|
-
if (ar || !(i in from)) {
|
|
28
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
29
|
-
ar[i] = from[i];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.useSlots = exports.isPortalChild = exports.getComponentSlotName = exports.isElementChild = void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const errors_1 = require("../helpers/errors");
|
|
28
|
+
const react_1 = __importStar(require("react"));
|
|
29
|
+
const isElementChild = (child) => {
|
|
39
30
|
if (child && typeof child === 'object' && 'type' in child) {
|
|
40
31
|
return true;
|
|
41
32
|
}
|
|
42
33
|
return false;
|
|
43
34
|
};
|
|
44
35
|
exports.isElementChild = isElementChild;
|
|
45
|
-
|
|
36
|
+
const getComponentSlotName = (TargetComponent, child) => {
|
|
46
37
|
if (child) {
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
const keyTypes = ['string', 'number', 'symbol'];
|
|
39
|
+
const slotName = child.props['data-slot-name'];
|
|
49
40
|
if (keyTypes.includes(typeof slotName)) {
|
|
50
41
|
return slotName;
|
|
51
42
|
}
|
|
@@ -62,7 +53,7 @@ var getComponentSlotName = function (TargetComponent, child) {
|
|
|
62
53
|
return undefined;
|
|
63
54
|
};
|
|
64
55
|
exports.getComponentSlotName = getComponentSlotName;
|
|
65
|
-
|
|
56
|
+
const isPortalChild = (child) => {
|
|
66
57
|
return (!!child
|
|
67
58
|
&& typeof child === 'object'
|
|
68
59
|
&& 'children' in child);
|
|
@@ -78,15 +69,14 @@ exports.isPortalChild = isPortalChild;
|
|
|
78
69
|
*
|
|
79
70
|
* @see {@link SlotComponent} for more on how to use the returned slot nodes.
|
|
80
71
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
entries.forEach(
|
|
86
|
-
|
|
87
|
-
var slotName = (0, exports.getComponentSlotName)(RegisteredSlotComponent);
|
|
72
|
+
const useSlots = (children, Caller) => {
|
|
73
|
+
const slotsAliasLookup = (0, react_1.useMemo)(() => {
|
|
74
|
+
const entries = Object.entries(Caller.Slots);
|
|
75
|
+
const aliasLookup = {};
|
|
76
|
+
entries.forEach(([alias, RegisteredSlotComponent]) => {
|
|
77
|
+
const slotName = (0, exports.getComponentSlotName)(RegisteredSlotComponent);
|
|
88
78
|
if (!slotName) {
|
|
89
|
-
(0, errors_1.throwDevError)(
|
|
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}`);
|
|
90
80
|
return;
|
|
91
81
|
}
|
|
92
82
|
aliasLookup[slotName] = alias;
|
|
@@ -94,21 +84,23 @@ var useSlots = function (children, Caller) {
|
|
|
94
84
|
return aliasLookup;
|
|
95
85
|
}, [Caller.Slots]);
|
|
96
86
|
// @todo Expose original source order of `children` with respect to slot aliases.
|
|
97
|
-
|
|
87
|
+
const result = (0, react_1.useMemo)(() => {
|
|
98
88
|
var _a;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
89
|
+
const slotNodes = {};
|
|
90
|
+
const unmatchedChildren = [];
|
|
91
|
+
const invalidChildren = [];
|
|
92
|
+
const requiredSlotAliases = [
|
|
93
|
+
...((_a = Caller.requiredSlotAliases) !== null && _a !== void 0 ? _a : [])
|
|
94
|
+
];
|
|
95
|
+
react_1.default.Children.forEach(children, (_child) => {
|
|
104
96
|
var _a;
|
|
105
|
-
|
|
97
|
+
const child = _child;
|
|
106
98
|
if (!child) {
|
|
107
99
|
invalidChildren.push(child);
|
|
108
100
|
return;
|
|
109
101
|
}
|
|
110
102
|
if (!react_1.default.isValidElement(child)) {
|
|
111
|
-
console.warn(
|
|
103
|
+
console.warn(`Invalid node found in JSX children while parsing slots. Got: "${child}".`);
|
|
112
104
|
invalidChildren.push(child);
|
|
113
105
|
return;
|
|
114
106
|
}
|
|
@@ -118,9 +110,9 @@ var useSlots = function (children, Caller) {
|
|
|
118
110
|
unmatchedChildren.push(child);
|
|
119
111
|
return;
|
|
120
112
|
}
|
|
121
|
-
|
|
113
|
+
const slotAlias = (() => {
|
|
122
114
|
var _a;
|
|
123
|
-
|
|
115
|
+
const slotName = (0, exports.getComponentSlotName)(child.type, child);
|
|
124
116
|
return slotName ? (_a = slotsAliasLookup[slotName]) !== null && _a !== void 0 ? _a : null : null;
|
|
125
117
|
})();
|
|
126
118
|
if (slotAlias) {
|
|
@@ -139,9 +131,9 @@ var useSlots = function (children, Caller) {
|
|
|
139
131
|
else
|
|
140
132
|
unmatchedChildren.push(child);
|
|
141
133
|
});
|
|
142
|
-
requiredSlotAliases.forEach(
|
|
134
|
+
requiredSlotAliases.forEach((slotAlias) => {
|
|
143
135
|
if (!slotNodes[slotAlias]) {
|
|
144
|
-
(0, errors_1.throwDevError)(
|
|
136
|
+
(0, errors_1.throwDevError)(`Missing required slot "${String(slotAlias)}".`);
|
|
145
137
|
}
|
|
146
138
|
});
|
|
147
139
|
return [slotNodes, unmatchedChildren, invalidChildren];
|