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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/build/base/index.d.ts +3 -3
  2. package/build/base/index.js +19 -3
  3. package/build/base/merged-state.d.ts +1 -0
  4. package/build/base/merged-state.js +58 -30
  5. package/build/base/methods.d.ts +6 -5
  6. package/build/base/methods.js +28 -19
  7. package/build/base/state/class-types.d.ts +2 -2
  8. package/build/base/state/class-types.js +2 -1
  9. package/build/base/state/class.d.ts +1 -1
  10. package/build/base/state/class.js +72 -45
  11. package/build/base/state/hook-types.d.ts +1 -1
  12. package/build/base/state/hook-types.js +2 -1
  13. package/build/base/state/hooks.d.ts +1 -1
  14. package/build/base/state/hooks.js +16 -8
  15. package/build/base/state/index.d.ts +6 -5
  16. package/build/base/state/index.js +32 -3
  17. package/build/classy/class/index.d.ts +5 -18
  18. package/build/classy/class/index.js +87 -98
  19. package/build/classy/class/types/extractor.d.ts +1 -1
  20. package/build/classy/class/types/extractor.js +2 -1
  21. package/build/classy/class/utils/function-name.js +5 -1
  22. package/build/classy/index.d.ts +3 -3
  23. package/build/classy/index.js +19 -3
  24. package/build/classy/instance/index.d.ts +4 -4
  25. package/build/classy/instance/index.js +88 -58
  26. package/build/classy/instance/mount-callbacks.d.ts +1 -1
  27. package/build/classy/instance/mount-callbacks.js +12 -8
  28. package/build/classy/instance/types/hook.d.ts +1 -1
  29. package/build/classy/instance/types/hook.js +2 -1
  30. package/build/classy/logic/index.d.ts +2 -2
  31. package/build/classy/logic/index.js +32 -22
  32. package/build/classy/logic/types/hook.d.ts +1 -1
  33. package/build/classy/logic/types/hook.js +2 -1
  34. package/build/docs-src/api/base-classes.d.ts +3 -3
  35. package/build/docs-src/api/base-classes.js +9 -3
  36. package/build/docs-src/api/index.d.ts +8 -8
  37. package/build/docs-src/api/index.js +39 -8
  38. package/build/docs-src/api/references.d.ts +5 -5
  39. package/build/docs-src/api/references.js +31 -5
  40. package/build/globals.d.ts +83 -130
  41. package/build/globals.js +4 -0
  42. package/build/helpers/errors.js +5 -1
  43. package/build/helpers/index.d.ts +4 -7
  44. package/build/helpers/index.js +23 -8
  45. package/build/helpers/mount-state.js +10 -6
  46. package/build/helpers/rerender.js +16 -12
  47. package/build/helpers/type-guards.js +6 -2
  48. package/build/helpers/use-component/index.d.ts +1 -1
  49. package/build/helpers/use-component/index.js +9 -5
  50. package/build/helpers/use-component/types.js +2 -1
  51. package/build/index.d.ts +4 -3
  52. package/build/index.js +19 -3
  53. package/build/slots/hook.d.ts +2 -2
  54. package/build/slots/hook.js +78 -44
  55. package/build/slots/index.d.ts +1 -1
  56. package/build/slots/index.js +17 -1
  57. package/build/slots/types.d.ts +14 -11
  58. package/build/slots/types.js +2 -1
  59. package/build/tsconfig.json +6 -9
  60. package/package.json +11 -31
  61. package/build/_cjs/base/index.d.ts +0 -3
  62. package/build/_cjs/base/index.js +0 -19
  63. package/build/_cjs/base/merged-state.d.ts +0 -19
  64. package/build/_cjs/base/merged-state.js +0 -60
  65. package/build/_cjs/base/methods.d.ts +0 -58
  66. package/build/_cjs/base/methods.js +0 -95
  67. package/build/_cjs/base/state/class-types.d.ts +0 -20
  68. package/build/_cjs/base/state/class-types.js +0 -2
  69. package/build/_cjs/base/state/class.d.ts +0 -69
  70. package/build/_cjs/base/state/class.js +0 -129
  71. package/build/_cjs/base/state/hook-types.d.ts +0 -32
  72. package/build/_cjs/base/state/hook-types.js +0 -2
  73. package/build/_cjs/base/state/hooks.d.ts +0 -12
  74. package/build/_cjs/base/state/hooks.js +0 -41
  75. package/build/_cjs/base/state/index.d.ts +0 -8
  76. package/build/_cjs/base/state/index.js +0 -34
  77. package/build/_cjs/classy/class/index.d.ts +0 -128
  78. package/build/_cjs/classy/class/index.js +0 -176
  79. package/build/_cjs/classy/class/types/extractor.d.ts +0 -5
  80. package/build/_cjs/classy/class/types/extractor.js +0 -2
  81. package/build/_cjs/classy/class/utils/function-name.d.ts +0 -2
  82. package/build/_cjs/classy/class/utils/function-name.js +0 -17
  83. package/build/_cjs/classy/index.d.ts +0 -3
  84. package/build/_cjs/classy/index.js +0 -19
  85. package/build/_cjs/classy/instance/index.d.ts +0 -144
  86. package/build/_cjs/classy/instance/index.js +0 -177
  87. package/build/_cjs/classy/instance/mount-callbacks.d.ts +0 -5
  88. package/build/_cjs/classy/instance/mount-callbacks.js +0 -30
  89. package/build/_cjs/classy/instance/types/hook.d.ts +0 -13
  90. package/build/_cjs/classy/instance/types/hook.js +0 -2
  91. package/build/_cjs/classy/logic/index.d.ts +0 -116
  92. package/build/_cjs/classy/logic/index.js +0 -123
  93. package/build/_cjs/classy/logic/types/hook.d.ts +0 -16
  94. package/build/_cjs/classy/logic/types/hook.js +0 -2
  95. package/build/_cjs/docs-src/api/base-classes.d.ts +0 -3
  96. package/build/_cjs/docs-src/api/base-classes.js +0 -9
  97. package/build/_cjs/docs-src/api/index.d.ts +0 -13
  98. package/build/_cjs/docs-src/api/index.js +0 -44
  99. package/build/_cjs/docs-src/api/references.d.ts +0 -5
  100. package/build/_cjs/docs-src/api/references.js +0 -31
  101. package/build/_cjs/helpers/debounce/index.d.ts +0 -55
  102. package/build/_cjs/helpers/debounce/index.js +0 -111
  103. package/build/_cjs/helpers/debounce/react-state.d.ts +0 -14
  104. package/build/_cjs/helpers/debounce/react-state.js +0 -32
  105. package/build/_cjs/helpers/errors.d.ts +0 -10
  106. package/build/_cjs/helpers/errors.js +0 -21
  107. package/build/_cjs/helpers/index.d.ts +0 -16
  108. package/build/_cjs/helpers/index.js +0 -34
  109. package/build/_cjs/helpers/mount-state.d.ts +0 -5
  110. package/build/_cjs/helpers/mount-state.js +0 -25
  111. package/build/_cjs/helpers/object-gate.d.ts +0 -74
  112. package/build/_cjs/helpers/object-gate.js +0 -67
  113. package/build/_cjs/helpers/rerender.d.ts +0 -24
  114. package/build/_cjs/helpers/rerender.js +0 -42
  115. package/build/_cjs/helpers/type-guards.d.ts +0 -1
  116. package/build/_cjs/helpers/type-guards.js +0 -8
  117. package/build/_cjs/helpers/use-component/index.d.ts +0 -6
  118. package/build/_cjs/helpers/use-component/index.js +0 -17
  119. package/build/_cjs/helpers/use-component/types.d.ts +0 -22
  120. package/build/_cjs/helpers/use-component/types.js +0 -2
  121. package/build/_cjs/index.d.ts +0 -3
  122. package/build/_cjs/index.js +0 -19
  123. package/build/_cjs/slots/hook.d.ts +0 -20
  124. package/build/_cjs/slots/hook.js +0 -147
  125. package/build/_cjs/slots/index.d.ts +0 -1
  126. package/build/_cjs/slots/index.js +0 -17
  127. package/build/_cjs/slots/types.d.ts +0 -128
  128. package/build/_cjs/slots/types.js +0 -2
  129. package/build/helpers/debounce/index.d.ts +0 -55
  130. package/build/helpers/debounce/index.js +0 -107
  131. package/build/helpers/debounce/react-state.d.ts +0 -14
  132. package/build/helpers/debounce/react-state.js +0 -29
  133. package/build/helpers/object-gate.d.ts +0 -74
  134. package/build/helpers/object-gate.js +0 -64
@@ -1,34 +0,0 @@
1
- "use strict";
2
- /**
3
- * <!-- @ mergeModuleWith API -->
4
- * @module Helpers
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.noOp = void 0;
22
- __exportStar(require("./mount-state.js"), exports);
23
- __exportStar(require("./rerender.js"), exports);
24
- __exportStar(require("./use-component/index.js"), exports);
25
- __exportStar(require("./object-gate.js"), exports);
26
- __exportStar(require("./debounce/index.js"), exports);
27
- __exportStar(require("./debounce/react-state.js"), exports);
28
- __exportStar(require("./type-guards.js"), exports);
29
- /**
30
- * An empty function.
31
- * It returns (void) without performing any operations.
32
- */
33
- const noOp = () => { };
34
- exports.noOp = noOp;
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns a value that is false before the component has been mounted,
3
- * then true during all subsequent rerenders.
4
- */
5
- export declare const useMountState: () => () => boolean;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useMountState = void 0;
4
- const react_1 = require("react");
5
- /**
6
- * Returns a value that is false before the component has been mounted,
7
- * then true during all subsequent rerenders.
8
- */
9
- const useMountState = () => {
10
- /**
11
- * This must not be a state value. It should not be the cause of a rerender.
12
- * It merely provides information about the render count,
13
- * without influencing that count itself.
14
- * So `mounted` should never be created with `useState`.
15
- */
16
- const mounted = (0, react_1.useRef)(false);
17
- (0, react_1.useEffect)(() => {
18
- mounted.current = true;
19
- return () => {
20
- mounted.current = false;
21
- };
22
- }, []);
23
- return () => mounted.current;
24
- };
25
- exports.useMountState = useMountState;
@@ -1,74 +0,0 @@
1
- type TRecord = Record<keyof any, any>;
2
- declare namespace _ObjectGate {
3
- /** Configure property access for a proxy object. */
4
- interface IGateConfig<TSource extends TRecord> {
5
- /**
6
- * The keys to be exposed for read access through the proxy.
7
- * Defaults to [`Reflect.ownKeys(source)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys) —
8
- * so if omitted, all ["_own properties_"](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Enumerability_and_ownership_of_properties)
9
- * present on the source at
10
- * instantiation time will be exposed for read access through the proxy.
11
- */
12
- getters?: Readonly<Array<keyof TSource>>;
13
- /**
14
- * Keys that should definitely be omitted from read access,
15
- * even if they are present in {@link getters}.
16
- * @default [] - Empty array.
17
- */
18
- gettersExclude?: Readonly<Array<keyof TSource>>;
19
- /**
20
- * The keys to be exposed for write access through the proxy.
21
- * This defaults to an empty array, so if omitted, none of the gated
22
- * properties will be writeable.
23
- * @default [] - Empty array.
24
- */
25
- setters?: Readonly<Array<keyof TSource> | true>;
26
- /**
27
- * Keys that should definitely be omitted from write access,
28
- * even if they are present in {@link setters}.
29
- * @default [] - Empty array.
30
- */
31
- settersExclude?: Readonly<Array<keyof TSource>>;
32
- }
33
- type Params<TSource extends TRecord> = [
34
- /**
35
- * The target object, where the actual values are stored.
36
- * Keys on the created gate object will use JavaScript getters to return
37
- * the real-time value of the same key from this source object.
38
- */
39
- source: TSource,
40
- /** @see {@link IGateConfig} */
41
- config?: Readonly<IGateConfig<TSource>>
42
- ];
43
- class Gate<TSource extends TRecord> {
44
- constructor(...params: Params<TSource>);
45
- }
46
- interface IConstructor {
47
- new <TOutput extends Partial<TSource>, TSource extends TRecord>(...params: _ObjectGate.Params<TSource>): TOutput;
48
- }
49
- }
50
- /**
51
- * Creates a new object that acts as a real-time proxy
52
- * for the {@link _ObjectGate.Params | `source`} object.
53
- * This lets you prevent access to some properties, effectively making them private,
54
- * while selectively exposing access to only the properties you specify
55
- * in the {@link _ObjectGate.IGateConfig.getters | `getters`} config option.
56
- *
57
- * The exposed properties are read-only by default,
58
- * exposing only a [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description)
59
- * with no corresponding [setter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set#description).
60
- *
61
- * The {@link _ObjectGate.Params | `config`} argument also lets you selectively allow
62
- * write access to specific properties through the
63
- * {@link _ObjectGate.IGateConfig.setters | `setters`} config option.
64
- *
65
- * Unlike [`structuredClone`](https://developer.mozilla.org/docs/Web/API/Window/structuredClone)
66
- * this doesn't return a _copy_ of the `source` object.
67
- *
68
- * Instead, it returns a _**Real-time proxy**_. This means that a value is read
69
- * from the source object each time a property is accessed through the proxy.
70
- * So accessing a property through the gate object is guaranteed to always return
71
- * the latest value.
72
- */
73
- export declare const ObjectGate: _ObjectGate.IConstructor;
74
- export {};
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObjectGate = void 0;
4
- var _ObjectGate;
5
- (function (_ObjectGate) {
6
- class Gate {
7
- constructor(...params) {
8
- var _a, _b, _c, _d;
9
- const [source, config] = params;
10
- const getters = (_a = config === null || config === void 0 ? void 0 : config.getters) !== null && _a !== void 0 ? _a : Reflect.ownKeys(source);
11
- const gettersExclude = (_b = config === null || config === void 0 ? void 0 : config.gettersExclude) !== null && _b !== void 0 ? _b : [];
12
- const setters = (config === null || config === void 0 ? void 0 : config.setters) === true
13
- ? getters
14
- : ((_c = config === null || config === void 0 ? void 0 : config.setters) !== null && _c !== void 0 ? _c : []);
15
- const settersExclude = (_d = config === null || config === void 0 ? void 0 : config.settersExclude) !== null && _d !== void 0 ? _d : [];
16
- getters.forEach((_key) => {
17
- const key = _key;
18
- if (gettersExclude.includes(key))
19
- return;
20
- Object.defineProperty(this, key, {
21
- enumerable: true,
22
- configurable: true,
23
- get() {
24
- return source[key];
25
- },
26
- });
27
- });
28
- setters.forEach((_key) => {
29
- const key = _key;
30
- if (settersExclude.includes(key))
31
- return;
32
- Object.defineProperty(this, key, {
33
- enumerable: true,
34
- set(value) {
35
- source[key] = value;
36
- },
37
- });
38
- });
39
- }
40
- }
41
- _ObjectGate.Gate = Gate;
42
- ;
43
- })(_ObjectGate || (_ObjectGate = {}));
44
- /**
45
- * Creates a new object that acts as a real-time proxy
46
- * for the {@link _ObjectGate.Params | `source`} object.
47
- * This lets you prevent access to some properties, effectively making them private,
48
- * while selectively exposing access to only the properties you specify
49
- * in the {@link _ObjectGate.IGateConfig.getters | `getters`} config option.
50
- *
51
- * The exposed properties are read-only by default,
52
- * exposing only a [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#description)
53
- * with no corresponding [setter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set#description).
54
- *
55
- * The {@link _ObjectGate.Params | `config`} argument also lets you selectively allow
56
- * write access to specific properties through the
57
- * {@link _ObjectGate.IGateConfig.setters | `setters`} config option.
58
- *
59
- * Unlike [`structuredClone`](https://developer.mozilla.org/docs/Web/API/Window/structuredClone)
60
- * this doesn't return a _copy_ of the `source` object.
61
- *
62
- * Instead, it returns a _**Real-time proxy**_. This means that a value is read
63
- * from the source object each time a property is accessed through the proxy.
64
- * So accessing a property through the gate object is guaranteed to always return
65
- * the latest value.
66
- */
67
- exports.ObjectGate = _ObjectGate.Gate;
@@ -1,24 +0,0 @@
1
- interface ICountRef {
2
- current: number;
3
- }
4
- interface IRefresherReturn {
5
- /** The last render count just before the rerender was triggered. */
6
- previousCount: number;
7
- /** A {@link useRef | RefObject} whose `current` property always has the latest render count. */
8
- latestCountRef: ICountRef;
9
- }
10
- interface IRefresher {
11
- (): Promise<IRefresherReturn>;
12
- }
13
- interface IUseRender {
14
- (): IRefresher & {
15
- /** The number of times this instance of the component has been (re)rendered. */
16
- currentCount: number;
17
- };
18
- }
19
- /**
20
- * Returns a function that can be called to manually trigger
21
- * a rerender of your component.
22
- */
23
- export declare const useRerender: IUseRender;
24
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useRerender = void 0;
4
- const react_1 = require("react");
5
- const mount_state_1 = require("../helpers/mount-state.js");
6
- ;
7
- /**
8
- * Returns a function that can be called to manually trigger
9
- * a rerender of your component.
10
- */
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
- renderCount.current++;
16
- const rerender = (0, react_1.useCallback)(() => {
17
- let resolve;
18
- const promise = new Promise((_r) => resolve = _r);
19
- const execute = () => {
20
- forceRerender(renderCount.current);
21
- resolve({
22
- previousCount: renderCount.current,
23
- latestCountRef: renderCount,
24
- });
25
- };
26
- if (isMounted())
27
- execute();
28
- else {
29
- setTimeout(() => {
30
- if (isMounted())
31
- execute();
32
- else
33
- console.log('Cannot rerender an unmounted component.');
34
- }, 1000);
35
- }
36
- return promise;
37
- }, [forceRerender, renderCount]);
38
- const refresher = () => rerender();
39
- refresher.currentCount = renderCount.current;
40
- return refresher;
41
- };
42
- exports.useRerender = useRerender;
@@ -1 +0,0 @@
1
- export declare const canIndex: <T extends object>(key: keyof any, targetObject: T) => key is keyof T;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canIndex = void 0;
4
- const canIndex = (key, targetObject) => {
5
- const test = typeof key === 'number' ? `${key}` : key;
6
- return Reflect.ownKeys(targetObject).includes(test);
7
- };
8
- exports.canIndex = canIndex;
@@ -1,6 +0,0 @@
1
- import type { ClassComponentHookWrapper } from './types.js';
2
- /**
3
- * A component you can use to consume React hooks
4
- * in a {@link Component | React.Component} class.
5
- */
6
- export declare const Use: ClassComponentHookWrapper;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Use = void 0;
4
- const react_1 = require("react");
5
- /**
6
- * A component you can use to consume React hooks
7
- * in a {@link Component | React.Component} class.
8
- */
9
- const Use = (params) => {
10
- const { hook: useGenericHook, argumentsList, onUpdate } = params;
11
- const output = useGenericHook(...argumentsList);
12
- (0, react_1.useEffect)(() => {
13
- onUpdate(output);
14
- }, [output]);
15
- return null;
16
- };
17
- exports.Use = Use;
@@ -1,22 +0,0 @@
1
- interface HookWrapperProps<THookFunction extends AnyFunction> {
2
- /**
3
- * The React hook you which to consume.
4
- * Render a separate instance of the `<Use />` component for each hook.
5
- * You can also create a custom hook that combines multiple hooks,
6
- * then use that wrapper hook with a single `<Use />` instance.
7
- */
8
- hook: THookFunction;
9
- /**
10
- * An array containing the list of arguments
11
- * to be passed to your hook, in the right order.
12
- */
13
- argumentsList: Parameters<THookFunction>;
14
- /**
15
- * A callback that will be called with whatever value your hook returns.
16
- * Use this to update your component's state with the value.
17
- * This will allow your component to rerender whenever the hook returns a new value.
18
- */
19
- onUpdate: (output: ReturnType<THookFunction>) => void;
20
- }
21
- export type ClassComponentHookWrapper = <Hook extends AnyFunction>(props: HookWrapperProps<Hook>) => null;
22
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export * from './classy/index.js';
2
- export * from './base/index.js';
3
- export * from './helpers/index.js';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./classy/index.js"), exports);
18
- __exportStar(require("./base/index.js"), exports);
19
- __exportStar(require("./helpers/index.js"), exports);
@@ -1,20 +0,0 @@
1
- import type { ReactElement, ReactNode, ReactPortal } from 'react';
2
- import type { IUseSlots, PotentialSlotComponent } from './types.js';
3
- export declare const isElementChild: (child: ReactNode) => child is ReactElement<any, any>;
4
- interface IGetSlotName {
5
- (TargetComponent: PotentialSlotComponent, child?: ReactElement): string | undefined;
6
- }
7
- export declare const getComponentSlotName: IGetSlotName;
8
- export declare const isPortalChild: (child: ReactNode) => child is ReactPortal;
9
- /**
10
- * Groups `children` prop into predefined slots.
11
- *
12
- * @returns A {@link TUseSlotsResult} array,
13
- * which includes a `slotNodes` object that maps the keys from
14
- * the predefined {@link Caller.slots} object to the corresponding
15
- * React node(s) that were rendered for that slot.
16
- *
17
- * @see {@link SlotComponent} for more on how to use the returned slot nodes.
18
- */
19
- export declare const useSlots: IUseSlots;
20
- export type { SlottedComponent, TSlotsRecord, SlotComponent, PotentialSlotComponent, } from './types.js';
@@ -1,147 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.useSlots = exports.isPortalChild = exports.getComponentSlotName = exports.isElementChild = void 0;
27
- const errors_1 = require("../helpers/errors.js");
28
- const react_1 = __importStar(require("react"));
29
- const isElementChild = (child) => {
30
- if (child && typeof child === 'object' && 'type' in child) {
31
- return true;
32
- }
33
- return false;
34
- };
35
- exports.isElementChild = isElementChild;
36
- const getComponentSlotName = (TargetComponent, child) => {
37
- if (child) {
38
- const keyTypes = ['string', 'number', 'symbol'];
39
- const slotName = child.props['data-slot-name'];
40
- if (keyTypes.includes(typeof slotName)) {
41
- return slotName;
42
- }
43
- }
44
- if (typeof TargetComponent === 'string') {
45
- return TargetComponent;
46
- }
47
- else if ('slotName' in TargetComponent) {
48
- return TargetComponent.slotName;
49
- }
50
- else if ('displayName' in TargetComponent) {
51
- return TargetComponent.displayName;
52
- }
53
- else if ('name' in TargetComponent) {
54
- return TargetComponent.name;
55
- }
56
- return undefined;
57
- };
58
- exports.getComponentSlotName = getComponentSlotName;
59
- const isPortalChild = (child) => {
60
- return (!!child
61
- && typeof child === 'object'
62
- && 'children' in child);
63
- };
64
- exports.isPortalChild = isPortalChild;
65
- /**
66
- * Groups `children` prop into predefined slots.
67
- *
68
- * @returns A {@link TUseSlotsResult} array,
69
- * which includes a `slotNodes` object that maps the keys from
70
- * the predefined {@link Caller.slots} object to the corresponding
71
- * React node(s) that were rendered for that slot.
72
- *
73
- * @see {@link SlotComponent} for more on how to use the returned slot nodes.
74
- */
75
- const useSlots = (children, Caller) => {
76
- const slotsAliasLookup = (0, react_1.useMemo)(() => {
77
- const entries = Object.entries(Caller.Slots);
78
- const aliasLookup = {
79
- byName: {},
80
- byIdentity: new Map(),
81
- };
82
- entries.forEach(([alias, RegisteredSlotComponent]) => {
83
- const slotName = (0, exports.getComponentSlotName)(RegisteredSlotComponent);
84
- if (!slotName) {
85
- aliasLookup.byIdentity.set(RegisteredSlotComponent, alias);
86
- aliasLookup.byName[alias] = alias;
87
- }
88
- else
89
- aliasLookup.byName[slotName] = alias;
90
- });
91
- return aliasLookup;
92
- }, [Caller.Slots]);
93
- // @todo Expose original source order of `children` with respect to slot aliases.
94
- const result = (0, react_1.useMemo)(() => {
95
- var _a;
96
- const slotNodes = {};
97
- const unmatchedChildren = [];
98
- const invalidChildren = [];
99
- const requiredSlotAliases = [
100
- ...((_a = Caller.requiredSlotAliases) !== null && _a !== void 0 ? _a : [])
101
- ];
102
- react_1.default.Children.forEach(children, (_child) => {
103
- const child = _child;
104
- if (!child) {
105
- invalidChildren.push(child);
106
- return;
107
- }
108
- if (!react_1.default.isValidElement(child)) {
109
- console.warn(`Invalid node found in JSX children while parsing slots. Got: "${child}".`);
110
- invalidChildren.push(child);
111
- return;
112
- }
113
- ;
114
- // @todo Check for fragment
115
- if (!(0, exports.isElementChild)(child)) {
116
- unmatchedChildren.push(child);
117
- return;
118
- }
119
- const slotAlias = (() => {
120
- const slotName = (0, exports.getComponentSlotName)(child.type, child);
121
- const alias = slotName
122
- ? slotsAliasLookup.byName[slotName]
123
- : slotsAliasLookup.byIdentity.get(child.type);
124
- return alias !== null && alias !== void 0 ? alias : null;
125
- })();
126
- if (slotAlias) {
127
- if (slotNodes[slotAlias]) {
128
- slotNodes[slotAlias].push(child);
129
- }
130
- else {
131
- slotNodes[slotAlias] = [child];
132
- }
133
- }
134
- else
135
- unmatchedChildren.push(child);
136
- });
137
- /** @todo Type keys as NonNullable if included in this array. */
138
- requiredSlotAliases.forEach((slotAlias) => {
139
- if (!slotNodes[slotAlias]) {
140
- (0, errors_1.throwDevError)(`Missing required slot "${String(slotAlias)}".`);
141
- }
142
- });
143
- return [slotNodes, unmatchedChildren, invalidChildren];
144
- }, [children]);
145
- return result;
146
- };
147
- exports.useSlots = useSlots;
@@ -1 +0,0 @@
1
- export * from './hook.js';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./hook.js"), exports);