@cleanweb/oore 1.2.0-alpha.6 → 1.2.0-alpha.7
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.js +21 -1
- package/build/slots/types.d.ts +5 -3
- package/package.json +1 -1
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
|
};
|
|
@@ -36,7 +45,7 @@ var getComponentSlotName = function (TargetComponent, child) {
|
|
|
36
45
|
return undefined;
|
|
37
46
|
};
|
|
38
47
|
exports.getComponentSlotName = getComponentSlotName;
|
|
39
|
-
var useSlots = function (children, slotComponents) {
|
|
48
|
+
var useSlots = function (children, slotComponents, _requiredSlots) {
|
|
40
49
|
var useMemo = react_1.default.useMemo;
|
|
41
50
|
console.log({ slotComponents: slotComponents });
|
|
42
51
|
var slotsAliasLookup = useMemo(function () {
|
|
@@ -58,6 +67,7 @@ var useSlots = function (children, slotComponents) {
|
|
|
58
67
|
var slotNodes = {};
|
|
59
68
|
var unmatchedChildren = [];
|
|
60
69
|
var invalidChildren = [];
|
|
70
|
+
var requiredSlots = __spreadArray([], (_requiredSlots !== null && _requiredSlots !== void 0 ? _requiredSlots : []), true);
|
|
61
71
|
react_1.default.Children.forEach(children, function (child) {
|
|
62
72
|
if (!child) {
|
|
63
73
|
invalidChildren.push(child);
|
|
@@ -78,12 +88,22 @@ var useSlots = function (children, slotComponents) {
|
|
|
78
88
|
return slotName ? slotsAliasLookup[slotName] : null;
|
|
79
89
|
})();
|
|
80
90
|
console.log('match:', { key: slotAlias });
|
|
91
|
+
if (slotAlias && (typeof slotComponents[slotAlias] !== 'string')) {
|
|
92
|
+
if (slotComponents[slotAlias].isRequiredSlot) {
|
|
93
|
+
requiredSlots.push(slotAlias);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
81
96
|
if (slotAlias)
|
|
82
97
|
slotNodes[slotAlias] = child;
|
|
83
98
|
else
|
|
84
99
|
unmatchedChildren.push(child);
|
|
85
100
|
});
|
|
86
101
|
console.log({ unmatchedChildren: unmatchedChildren, invalidChildren: invalidChildren });
|
|
102
|
+
requiredSlots.forEach(function (slotAlias) {
|
|
103
|
+
if (!slotNodes[slotAlias]) {
|
|
104
|
+
(0, errors_1.throwDevError)("Missing required slot \"".concat(String(slotAlias), "\"."));
|
|
105
|
+
}
|
|
106
|
+
});
|
|
87
107
|
return [slotNodes, unmatchedChildren, invalidChildren];
|
|
88
108
|
}, [children]);
|
|
89
109
|
return result;
|
package/build/slots/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ 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
8
|
export type DisplayNamedComponent<TComponentArg extends TComponent = TComponent, TDisplayNameArg extends string = string> = TComponentArg & {
|
|
9
9
|
displayName: TDisplayNameArg;
|
|
@@ -11,7 +11,9 @@ export type DisplayNamedComponent<TComponentArg extends TComponent = TComponent,
|
|
|
11
11
|
export type SlotNamedComponent<TComponentArg extends TComponent = TComponent, TSlotNameArg extends TSlotName = TSlotName> = TComponentArg & {
|
|
12
12
|
slotName: TSlotNameArg;
|
|
13
13
|
};
|
|
14
|
-
export type SlotComponent<TComponentArg extends TComponent = TComponent> = SlotNamedComponent<TComponentArg> | DisplayNamedComponent<TComponentArg
|
|
14
|
+
export type SlotComponent<TComponentArg extends TComponent = TComponent> = (SlotNamedComponent<TComponentArg> | DisplayNamedComponent<TComponentArg>) & {
|
|
15
|
+
isRequiredSlot?: boolean;
|
|
16
|
+
};
|
|
15
17
|
export type SlottedComponent<TComponentArg extends TComponent = TComponent, TSlotAliasArg extends TSlotAlias = TSlotAlias, TSlotsRecordArg extends TSlotsRecord<TSlotAliasArg> = TSlotsRecord<TSlotAliasArg>> = TComponentArg & {
|
|
16
18
|
Slots: TSlotsRecordArg;
|
|
17
19
|
};
|
|
@@ -24,6 +26,6 @@ export type TUseSlotsResult<TSlotAliasArg extends TSlotAlias = TSlotAlias> = Rea
|
|
|
24
26
|
invalidChildren: any[]
|
|
25
27
|
]>;
|
|
26
28
|
export interface IUseSlots {
|
|
27
|
-
<TSlotAliasArg extends TSlotAlias = TSlotAlias>(children: ReactNode, slotComponents: TSlotsRecord<TSlotAliasArg
|
|
29
|
+
<TSlotAliasArg extends TSlotAlias = TSlotAlias>(children: ReactNode, slotComponents: TSlotsRecord<TSlotAliasArg>, requiredSlots?: TSlotAliasArg[]): TUseSlotsResult<TSlotAliasArg>;
|
|
28
30
|
}
|
|
29
31
|
export type PotentialSlotComponent = string | SlotComponent | TComponent;
|
package/package.json
CHANGED