@cleanweb/oore 1.2.0-alpha.1 → 1.2.0-alpha.10
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/slots/hook.d.ts +4 -1
- package/build/slots/hook.js +34 -10
- package/build/slots/types.d.ts +14 -14
- package/build/slots/types.js +0 -2
- package/package.json +1 -1
package/build/slots/hook.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { IUseSlots, PotentialSlotComponent } from './types';
|
|
3
3
|
export declare const isElementChild: (child: ReactNode) => child is ReactElement<any, any>;
|
|
4
|
-
|
|
4
|
+
interface IGetSlotName {
|
|
5
|
+
(TargetComponent: PotentialSlotComponent, child?: ReactElement): string | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare const getComponentSlotName: IGetSlotName;
|
|
5
8
|
export declare const useSlots: IUseSlots;
|
|
6
9
|
export type { SlotNamedComponent, SlottedComponent, TSlotsRecord, PotentialSlotComponent, } from './types';
|
package/build/slots/hook.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -13,7 +22,17 @@ var isElementChild = function (child) {
|
|
|
13
22
|
return false;
|
|
14
23
|
};
|
|
15
24
|
exports.isElementChild = isElementChild;
|
|
16
|
-
var getComponentSlotName = function (TargetComponent) {
|
|
25
|
+
var getComponentSlotName = function (TargetComponent, child) {
|
|
26
|
+
if (child) {
|
|
27
|
+
var keyTypes = ['string', 'number', 'symbol'];
|
|
28
|
+
var slotName = child.props['data-slot-name'];
|
|
29
|
+
if (keyTypes.includes(typeof slotName)) {
|
|
30
|
+
if (typeof child.type === 'string') {
|
|
31
|
+
child.props.tagName = child.type;
|
|
32
|
+
}
|
|
33
|
+
return slotName;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
17
36
|
if (typeof TargetComponent === 'string') {
|
|
18
37
|
return TargetComponent;
|
|
19
38
|
}
|
|
@@ -23,13 +42,11 @@ var getComponentSlotName = function (TargetComponent) {
|
|
|
23
42
|
else if ('displayName' in TargetComponent) {
|
|
24
43
|
return TargetComponent.displayName;
|
|
25
44
|
}
|
|
26
|
-
|
|
27
|
-
return undefined;
|
|
45
|
+
return undefined;
|
|
28
46
|
};
|
|
29
47
|
exports.getComponentSlotName = getComponentSlotName;
|
|
30
|
-
var useSlots = function (children, slotComponents) {
|
|
48
|
+
var useSlots = function (children, slotComponents, _requiredSlots) {
|
|
31
49
|
var useMemo = react_1.default.useMemo;
|
|
32
|
-
console.log({ slotComponents: slotComponents });
|
|
33
50
|
var slotsAliasLookup = useMemo(function () {
|
|
34
51
|
var entries = Object.entries(slotComponents);
|
|
35
52
|
var aliasLookup = {};
|
|
@@ -44,11 +61,11 @@ var useSlots = function (children, slotComponents) {
|
|
|
44
61
|
});
|
|
45
62
|
return aliasLookup;
|
|
46
63
|
}, [slotComponents]);
|
|
47
|
-
console.log({ slotsAliasLookup: slotsAliasLookup });
|
|
48
64
|
var result = useMemo(function () {
|
|
49
65
|
var slotNodes = {};
|
|
50
66
|
var unmatchedChildren = [];
|
|
51
67
|
var invalidChildren = [];
|
|
68
|
+
var requiredSlots = __spreadArray([], (_requiredSlots !== null && _requiredSlots !== void 0 ? _requiredSlots : []), true);
|
|
52
69
|
react_1.default.Children.forEach(children, function (child) {
|
|
53
70
|
if (!child) {
|
|
54
71
|
invalidChildren.push(child);
|
|
@@ -65,17 +82,24 @@ var useSlots = function (children, slotComponents) {
|
|
|
65
82
|
return;
|
|
66
83
|
}
|
|
67
84
|
var slotAlias = (function () {
|
|
68
|
-
var
|
|
69
|
-
var slotName = (0, exports.getComponentSlotName)(ChildComponent);
|
|
85
|
+
var slotName = (0, exports.getComponentSlotName)(child.type, child);
|
|
70
86
|
return slotName ? slotsAliasLookup[slotName] : null;
|
|
71
87
|
})();
|
|
72
|
-
|
|
88
|
+
if (slotAlias && (typeof slotComponents[slotAlias] !== 'string')) {
|
|
89
|
+
if (slotComponents[slotAlias].isRequiredSlot) {
|
|
90
|
+
requiredSlots.push(slotAlias);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
73
93
|
if (slotAlias)
|
|
74
94
|
slotNodes[slotAlias] = child;
|
|
75
95
|
else
|
|
76
96
|
unmatchedChildren.push(child);
|
|
77
97
|
});
|
|
78
|
-
|
|
98
|
+
requiredSlots.forEach(function (slotAlias) {
|
|
99
|
+
if (!slotNodes[slotAlias]) {
|
|
100
|
+
(0, errors_1.throwDevError)("Missing required slot \"".concat(String(slotAlias), "\"."));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
79
103
|
return [slotNodes, unmatchedChildren, invalidChildren];
|
|
80
104
|
}, [children]);
|
|
81
105
|
return result;
|
package/build/slots/types.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { ReactElement, ReactNode, JSXElementConstructor
|
|
1
|
+
import type { ReactElement, ReactNode, JSXElementConstructor } from 'react';
|
|
2
2
|
export type TComponent = JSXElementConstructor<any>;
|
|
3
3
|
export type TSlotName = keyof any;
|
|
4
4
|
export type TSlotAlias = keyof any;
|
|
5
5
|
export type TSlotsRecord<TKey extends TSlotAlias = TSlotAlias> = {
|
|
6
|
-
[Key in TKey]:
|
|
6
|
+
[Key in TKey]: string | SlotComponent;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
displayName:
|
|
10
|
-
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
export type DisplayNamedComponent<TComponentArg extends TComponent = TComponent, TDisplayNameArg extends string = string> = TComponentArg & {
|
|
9
|
+
displayName: TDisplayNameArg;
|
|
10
|
+
};
|
|
11
|
+
export type SlotNamedComponent<TComponentArg extends TComponent = TComponent, TSlotNameArg extends TSlotName = TSlotName> = TComponentArg & {
|
|
12
|
+
slotName: TSlotNameArg;
|
|
13
|
+
};
|
|
14
|
+
export type SlotComponent<TComponentArg extends TComponent = TComponent> = (SlotNamedComponent<TComponentArg> | DisplayNamedComponent<TComponentArg>) & {
|
|
15
|
+
isRequiredSlot?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type SlottedComponent<TComponentArg extends TComponent = TComponent, TSlotAliasArg extends TSlotAlias = TSlotAlias, TSlotsRecordArg extends TSlotsRecord<TSlotAliasArg> = TSlotsRecord<TSlotAliasArg>> = TComponentArg & {
|
|
18
18
|
Slots: TSlotsRecordArg;
|
|
19
|
-
}
|
|
19
|
+
};
|
|
20
20
|
export type TSlotNodes<TSlotAliasArg extends TSlotAlias> = {
|
|
21
21
|
[Key in TSlotAliasArg]?: ReactElement<any>;
|
|
22
22
|
};
|
|
@@ -26,6 +26,6 @@ export type TUseSlotsResult<TSlotAliasArg extends TSlotAlias = TSlotAlias> = Rea
|
|
|
26
26
|
invalidChildren: any[]
|
|
27
27
|
]>;
|
|
28
28
|
export interface IUseSlots {
|
|
29
|
-
<TSlotAliasArg extends TSlotAlias = TSlotAlias>(children: ReactNode, slotComponents: TSlotsRecord<TSlotAliasArg
|
|
29
|
+
<TSlotAliasArg extends TSlotAlias = TSlotAlias>(children: ReactNode, slotComponents: TSlotsRecord<TSlotAliasArg>, requiredSlots?: TSlotAliasArg[]): TUseSlotsResult<TSlotAliasArg>;
|
|
30
30
|
}
|
|
31
31
|
export type PotentialSlotComponent = string | SlotComponent | TComponent;
|
package/build/slots/types.js
CHANGED
package/package.json
CHANGED