plain-design 1.0.0-beta.35 → 1.0.0-beta.38

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ import {RenderNode} from "plain-design-composition";
2
+
3
+ export function inheritSlots<
4
+ Slots extends Record<string, (() => RenderNode) & { isExist: () => boolean }>,
5
+ ScopeSlots extends Record<string, ((...args: any[]) => RenderNode) & { isExist: () => boolean }>,
6
+ >(
7
+ {
8
+ slots,
9
+ scopeSlots,
10
+ defaultSlots,
11
+ defaultScopeSlots,
12
+ }: {
13
+ slots?: Slots,
14
+ scopeSlots?: ScopeSlots,
15
+ defaultSlots?: { [k in keyof Slots]: Omit<Slots[k], 'isExist'> },
16
+ defaultScopeSlots?: { [k in keyof ScopeSlots]: Omit<ScopeSlots[k], 'isExist'> },
17
+ }
18
+ ) {
19
+ const ret = {} as any;
20
+
21
+ !!defaultSlots && Object.entries(defaultSlots).forEach(([key, val]) => {ret[key] = val;});
22
+ !!defaultScopeSlots && Object.entries(defaultScopeSlots).forEach(([key, val]) => {ret[key] = val;});
23
+
24
+ !!slots && Object.keys(slots).forEach((k: keyof Slots) => {if (slots[k].isExist()) {ret[k] = () => slots[k]();}});
25
+ !!scopeSlots && Object.keys(scopeSlots).forEach((k: keyof ScopeSlots) => {if (scopeSlots[k].isExist()) {ret[k] = (...args: any[]) => scopeSlots[k](...args);}});
26
+
27
+ return ret;
28
+ }