@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.
Files changed (86) hide show
  1. package/build/_cjs/base/index.d.ts +3 -0
  2. package/build/_cjs/base/index.js +19 -0
  3. package/build/_cjs/base/merged-state.d.ts +20 -0
  4. package/build/_cjs/base/merged-state.js +61 -0
  5. package/build/_cjs/base/methods.d.ts +58 -0
  6. package/build/_cjs/base/methods.js +95 -0
  7. package/build/_cjs/base/state/class-types.d.ts +20 -0
  8. package/build/_cjs/base/state/class-types.js +2 -0
  9. package/build/_cjs/base/state/class.d.ts +69 -0
  10. package/build/_cjs/base/state/class.js +129 -0
  11. package/build/_cjs/base/state/hook-types.d.ts +32 -0
  12. package/build/_cjs/base/state/hook-types.js +2 -0
  13. package/build/_cjs/base/state/hooks.d.ts +12 -0
  14. package/build/_cjs/base/state/hooks.js +41 -0
  15. package/build/_cjs/base/state/index.d.ts +9 -0
  16. package/build/_cjs/base/state/index.js +35 -0
  17. package/build/_cjs/classy/class/index.d.ts +128 -0
  18. package/build/_cjs/classy/class/index.js +174 -0
  19. package/build/_cjs/classy/class/types/extractor.d.ts +5 -0
  20. package/build/_cjs/classy/class/types/extractor.js +2 -0
  21. package/build/_cjs/classy/class/utils/function-name.d.ts +2 -0
  22. package/build/_cjs/classy/class/utils/function-name.js +17 -0
  23. package/build/_cjs/classy/index.d.ts +3 -0
  24. package/build/_cjs/classy/index.js +19 -0
  25. package/build/_cjs/classy/instance/index.d.ts +144 -0
  26. package/build/_cjs/classy/instance/index.js +177 -0
  27. package/build/_cjs/classy/instance/mount-callbacks.d.ts +5 -0
  28. package/build/_cjs/classy/instance/mount-callbacks.js +30 -0
  29. package/build/_cjs/classy/instance/types/hook.d.ts +13 -0
  30. package/build/_cjs/classy/instance/types/hook.js +2 -0
  31. package/build/_cjs/classy/logic/index.d.ts +116 -0
  32. package/build/_cjs/classy/logic/index.js +123 -0
  33. package/build/_cjs/classy/logic/types/hook.d.ts +16 -0
  34. package/build/_cjs/classy/logic/types/hook.js +2 -0
  35. package/build/_cjs/docs-src/api/base-classes.d.ts +3 -0
  36. package/build/_cjs/docs-src/api/base-classes.js +9 -0
  37. package/build/_cjs/docs-src/api/index.d.ts +13 -0
  38. package/build/_cjs/docs-src/api/index.js +44 -0
  39. package/build/_cjs/docs-src/api/references.d.ts +5 -0
  40. package/build/_cjs/docs-src/api/references.js +31 -0
  41. package/build/_cjs/helpers/errors.d.ts +10 -0
  42. package/build/_cjs/helpers/errors.js +21 -0
  43. package/build/_cjs/helpers/index.d.ts +13 -0
  44. package/build/_cjs/helpers/index.js +31 -0
  45. package/build/_cjs/helpers/mount-state.d.ts +5 -0
  46. package/build/_cjs/helpers/mount-state.js +25 -0
  47. package/build/_cjs/helpers/rerender.d.ts +24 -0
  48. package/build/_cjs/helpers/rerender.js +42 -0
  49. package/build/_cjs/helpers/type-guards.d.ts +1 -0
  50. package/build/_cjs/helpers/type-guards.js +8 -0
  51. package/build/_cjs/helpers/use-component/index.d.ts +6 -0
  52. package/build/_cjs/helpers/use-component/index.js +17 -0
  53. package/build/_cjs/helpers/use-component/types.d.ts +22 -0
  54. package/build/_cjs/helpers/use-component/types.js +2 -0
  55. package/build/_cjs/index.d.ts +3 -0
  56. package/build/_cjs/index.js +19 -0
  57. package/build/_cjs/slots/hook.d.ts +20 -0
  58. package/build/_cjs/slots/hook.js +143 -0
  59. package/build/_cjs/slots/index.d.ts +1 -0
  60. package/build/_cjs/slots/index.js +17 -0
  61. package/build/_cjs/slots/types.d.ts +131 -0
  62. package/build/_cjs/slots/types.js +2 -0
  63. package/build/base/merged-state.js +30 -53
  64. package/build/base/methods.d.ts +2 -3
  65. package/build/base/methods.js +18 -23
  66. package/build/base/state/class.js +45 -68
  67. package/build/base/state/hooks.js +6 -10
  68. package/build/classy/class/index.d.ts +15 -2
  69. package/build/classy/class/index.js +96 -83
  70. package/build/classy/class/utils/function-name.js +1 -1
  71. package/build/classy/instance/index.d.ts +1 -1
  72. package/build/classy/instance/index.js +57 -82
  73. package/build/classy/instance/mount-callbacks.js +8 -8
  74. package/build/classy/logic/index.js +21 -26
  75. package/build/globals.d.ts +130 -83
  76. package/build/helpers/errors.js +1 -1
  77. package/build/helpers/index.js +1 -1
  78. package/build/helpers/mount-state.js +6 -6
  79. package/build/helpers/rerender.js +12 -12
  80. package/build/helpers/type-guards.js +2 -2
  81. package/build/helpers/use-component/index.js +5 -5
  82. package/build/index.d.ts +0 -1
  83. package/build/slots/hook.js +28 -36
  84. package/build/tsconfig.json +5 -6
  85. package/package.json +31 -11
  86. 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
- var react_1 = require("react");
5
- var mount_state_1 = require("../../helpers/mount-state");
4
+ const react_1 = require("react");
5
+ const mount_state_1 = require("../../helpers/mount-state");
6
6
  /** @internal */
7
- var useMountCallbacks = function (instance) {
7
+ const useMountCallbacks = (instance) => {
8
8
  var _a;
9
- var isMounted = (0, mount_state_1.useMountState)();
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)(function () {
12
+ (0, react_1.useEffect)(() => {
13
13
  var _a;
14
- var mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
15
- return function () {
16
- var doCleanUp = function (runMountCleaners) {
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
- var react_1 = require("react");
5
- var state_1 = require("../../base/state");
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
- var ComponentLogic = /** @class */ (function () {
20
- function ComponentLogic() {
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 = function (props) { return ({}); };
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 = function () { };
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
- return ComponentLogic;
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
- var useLogic = function () {
54
+ const useLogic = (...args) => {
56
55
  var _a;
57
- var args = [];
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
- var latestInstance = (0, react_1.useMemo)(function () { return new Logic(); }, [Logic]);
60
+ const latestInstance = (0, react_1.useMemo)(() => new Logic(), [Logic]);
66
61
  // const latestInstance = useMemo(() => new Logic(), []);
67
- var instanceRef = (0, react_1.useRef)(latestInstance);
68
- var refreshState = function () {
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
- var oldInstance_1 = instanceRef.current;
79
- latestInstance._hmrPreserveKeys.forEach(function (_key) {
80
- var key = _key;
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] = oldInstance_1[key];
77
+ latestInstance[key] = oldInstance[key];
83
78
  });
84
- Reflect.ownKeys(oldInstance_1).forEach(function (_key) {
85
- var key = _key;
86
- delete oldInstance_1[key];
79
+ Reflect.ownKeys(oldInstance).forEach((_key) => {
80
+ const key = _key;
81
+ delete oldInstance[key];
87
82
  });
88
- Object.setPrototypeOf(oldInstance_1, latestInstance);
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, oldInstance_1);
86
+ (_a = latestInstance._onHmrUpdate) === null || _a === void 0 ? void 0 : _a.call(latestInstance, oldInstance);
92
87
  }
93
88
  else
94
89
  refreshState();
@@ -1,84 +1,131 @@
1
- declare const UniqueSecretSymbolKey: unique symbol;
2
- /** /testing: {
3
- const mySymbol = Symbol('asdfgh') as symbol;
4
-
5
- const tt = {
6
- // [mySymbol]: '' as never,
7
- // [UniqueSecretSymbolKey]: '',
8
- // '': '',
9
- }
10
-
11
- let TT: EmptyObject = {};
12
- TT = tt;
13
- }/**/
14
- declare global {
15
- type Optional<BaseType, AllowNull extends boolean = true> = (AllowNull extends true ? BaseType | undefined | null : BaseType | undefined);
16
- type Awaitable<Type> = Type | Promise<Type>;
17
- type Constructor<TInstance extends any = any, TParams extends any[] = never[]> = new (...args: TParams) => TInstance;
18
- /**
19
- * @example
20
- * ```js
21
- * const getNumber: AsyncFunction<number> = async () => {
22
- * return 5;
23
- * }
24
- * ```
25
- */
26
- type AsyncFunction<TReturnValue extends any = void, Params extends any[] = never[]> = (...params: Params) => Promise<TReturnValue>;
27
- /**
28
- * A function that takes no arguments and returns nothing.
29
- * Pass a type argument to set whether `async` and/or `sync` functions are allowed.
30
- */
31
- interface IVoidFunction<AsyncType extends 'async' | 'sync' | 'both' = 'both'> {
32
- (): AsyncType extends 'async' ? Promise<void> : AsyncType extends 'sync' ? void : void | Promise<void>;
33
- }
34
- type AnyFunction = (...args: any) => any;
35
- type FunctionType = AnyFunction;
36
- type TFunction = AnyFunction;
37
- /** @deprecated Use {@link NonNullish} */
38
- type NotNullish = {};
39
- type NonNullish = {};
40
- type NonPrimitive = object;
41
- /**
42
- * Describes an object that has no keys,
43
- * except for a secret unique symbol key,
44
- * whose value type is the union `never | undefuned`.
45
- *
46
- * Having a single key allows the object to throw type errors
47
- * of the form:
48
- * ```
49
- * Type `A` has no properties in common with `EmptyObject`.
50
- * ```
51
- * This may provide a slightly stricter type checking than simply
52
- * using the non-nullish (`{}`) or non-primitive (`object`)
53
- * built-in types.
54
- *
55
- * Note: `EmptyObject` is not assignable to `NeverObject`
56
- * because it has a key whose value type includes `undefined`,
57
- * but `NeverObject` keys can only have a type of `never`.
58
- */
59
- interface EmptyObject {
60
- [UniqueSecretSymbolKey]?: never;
61
- }
62
- /**
63
- * Describes an object that can have any key, but all keys have
64
- * a type of `never`. This effectively prevents any value
65
- * from ever being stored on the object. The object is therefore
66
- * guaranteed to always be empty.
67
- */
68
- interface NeverObject {
69
- [key: keyof any]: never;
70
- }
71
- type valueof<TObject> = TObject[keyof TObject];
72
- interface Window {
73
- }
74
- namespace JSX {
75
- interface IntrinsicElements {
76
- }
77
- }
78
- namespace NodeJS {
79
- interface ProcessEnv {
80
- NODE_ENV: 'development' | 'production' | 'test';
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 {};
@@ -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
- var throwDevError = function (message) {
13
+ const throwDevError = (message) => {
14
14
  if (process.env.NODE_ENV === 'production') {
15
15
  console.warn(message);
16
16
  }
@@ -27,5 +27,5 @@ __exportStar(require("./type-guards"), exports);
27
27
  * An empty function.
28
28
  * It returns (void) without performing any operations.
29
29
  */
30
- var noOp = function () { };
30
+ const noOp = () => { };
31
31
  exports.noOp = noOp;
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useMountState = void 0;
4
- var react_1 = require("react");
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
- var useMountState = function () {
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
- var mounted = (0, react_1.useRef)(false);
17
- (0, react_1.useEffect)(function () {
16
+ const mounted = (0, react_1.useRef)(false);
17
+ (0, react_1.useEffect)(() => {
18
18
  mounted.current = true;
19
- return function () {
19
+ return () => {
20
20
  mounted.current = false;
21
21
  };
22
22
  }, []);
23
- return function () { return mounted.current; };
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
- var react_1 = require("react");
5
- var mount_state_1 = require("../helpers/mount-state");
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
- var useRerender = function () {
12
- var isMounted = (0, mount_state_1.useMountState)();
13
- var renderCount = (0, react_1.useRef)(0);
14
- var _a = (0, react_1.useState)(renderCount.current), forceRerender = _a[1];
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
- var rerender = (0, react_1.useCallback)(function () {
17
- var resolve;
18
- var promise = new Promise(function (_r) { return resolve = _r; });
19
- var execute = function () {
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(function () {
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
- var refresher = function () { return rerender(); };
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
- var canIndex = function (key, targetObject) {
5
- var test = typeof key === 'number' ? "".concat(key) : key;
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
- var react_1 = require("react");
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
- var Use = function (params) {
10
- var useGenericHook = params.hook, argumentsList = params.argumentsList, onUpdate = params.onUpdate;
11
- var output = useGenericHook.apply(void 0, argumentsList);
12
- (0, react_1.useEffect)(function () {
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
@@ -1,4 +1,3 @@
1
1
  export * from './classy';
2
2
  export * from './base';
3
3
  export * from './helpers';
4
- export type { EmptyObject, NeverObject };
@@ -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
- var errors_1 = require("../helpers/errors");
37
- var react_1 = __importStar(require("react"));
38
- var isElementChild = function (child) {
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
- var getComponentSlotName = function (TargetComponent, child) {
36
+ const getComponentSlotName = (TargetComponent, child) => {
46
37
  if (child) {
47
- var keyTypes = ['string', 'number', 'symbol'];
48
- var slotName = child.props['data-slot-name'];
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
- var isPortalChild = function (child) {
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
- var useSlots = function (children, Caller) {
82
- var slotsAliasLookup = (0, react_1.useMemo)(function () {
83
- var entries = Object.entries(Caller.Slots);
84
- var aliasLookup = {};
85
- entries.forEach(function (_a) {
86
- var alias = _a[0], RegisteredSlotComponent = _a[1];
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)("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));
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
- var result = (0, react_1.useMemo)(function () {
87
+ const result = (0, react_1.useMemo)(() => {
98
88
  var _a;
99
- var slotNodes = {};
100
- var unmatchedChildren = [];
101
- var invalidChildren = [];
102
- var requiredSlotAliases = __spreadArray([], ((_a = Caller.requiredSlotAliases) !== null && _a !== void 0 ? _a : []), true);
103
- react_1.default.Children.forEach(children, function (_child) {
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
- var child = _child;
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("Invalid node found in JSX children while parsing slots. Got: \"".concat(child, "\"."));
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
- var slotAlias = (function () {
113
+ const slotAlias = (() => {
122
114
  var _a;
123
- var slotName = (0, exports.getComponentSlotName)(child.type, child);
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(function (slotAlias) {
134
+ requiredSlotAliases.forEach((slotAlias) => {
143
135
  if (!slotNodes[slotAlias]) {
144
- (0, errors_1.throwDevError)("Missing required slot \"".concat(String(slotAlias), "\"."));
136
+ (0, errors_1.throwDevError)(`Missing required slot "${String(slotAlias)}".`);
145
137
  }
146
138
  });
147
139
  return [slotNodes, unmatchedChildren, invalidChildren];