@fluentui/react-utilities 9.10.0 → 9.11.0

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 (44) hide show
  1. package/CHANGELOG.json +52 -1
  2. package/CHANGELOG.md +21 -2
  3. package/dist/index.d.ts +111 -1
  4. package/lib/compose/assertSlots.js +42 -0
  5. package/lib/compose/assertSlots.js.map +1 -0
  6. package/lib/compose/constants.js +4 -0
  7. package/lib/compose/constants.js.map +1 -1
  8. package/lib/compose/getSlots.js +4 -1
  9. package/lib/compose/getSlots.js.map +1 -1
  10. package/lib/compose/getSlotsNext.js +5 -0
  11. package/lib/compose/getSlotsNext.js.map +1 -1
  12. package/lib/compose/index.js +4 -0
  13. package/lib/compose/index.js.map +1 -1
  14. package/lib/compose/isSlot.js +7 -0
  15. package/lib/compose/isSlot.js.map +1 -0
  16. package/lib/compose/resolveShorthand.js +8 -22
  17. package/lib/compose/resolveShorthand.js.map +1 -1
  18. package/lib/compose/slot.js +59 -0
  19. package/lib/compose/slot.js.map +1 -0
  20. package/lib/compose/types.js.map +1 -1
  21. package/lib/index.js +1 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib/selection/useSelection.js +10 -22
  24. package/lib/selection/useSelection.js.map +1 -1
  25. package/lib-commonjs/compose/assertSlots.js +32 -0
  26. package/lib-commonjs/compose/assertSlots.js.map +1 -0
  27. package/lib-commonjs/compose/constants.js +10 -3
  28. package/lib-commonjs/compose/constants.js.map +1 -1
  29. package/lib-commonjs/compose/getSlots.js +4 -1
  30. package/lib-commonjs/compose/getSlots.js.map +1 -1
  31. package/lib-commonjs/compose/getSlotsNext.js.map +1 -1
  32. package/lib-commonjs/compose/index.js +8 -0
  33. package/lib-commonjs/compose/index.js.map +1 -1
  34. package/lib-commonjs/compose/isSlot.js +12 -0
  35. package/lib-commonjs/compose/isSlot.js.map +1 -0
  36. package/lib-commonjs/compose/resolveShorthand.js +9 -22
  37. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  38. package/lib-commonjs/compose/slot.js +52 -0
  39. package/lib-commonjs/compose/slot.js.map +1 -0
  40. package/lib-commonjs/index.js +4 -0
  41. package/lib-commonjs/index.js.map +1 -1
  42. package/lib-commonjs/selection/useSelection.js +10 -22
  43. package/lib-commonjs/selection/useSelection.js.map +1 -1
  44. package/package.json +2 -2
package/CHANGELOG.json CHANGED
@@ -2,7 +2,58 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 28 Jun 2023 11:08:37 GMT",
5
+ "date": "Fri, 04 Aug 2023 08:48:24 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.11.0",
7
+ "version": "9.11.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "bernardo.sunderhus@gmail.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "6a8afe2b7becaf1b10cbc9ae98b39d352b8c7026",
14
+ "comment": "feat: implement new slot methods (slot and assertSlots)"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Thu, 20 Jul 2023 18:27:36 GMT",
21
+ "tag": "@fluentui/react-utilities_v9.10.1",
22
+ "version": "9.10.1",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "author": "olfedias@microsoft.com",
27
+ "package": "@fluentui/react-utilities",
28
+ "commit": "5a4b16715e8e929f11d8113f710e578ca73acaa6",
29
+ "comment": "chore: migrate to monosize"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Mon, 03 Jul 2023 11:57:14 GMT",
36
+ "tag": "@fluentui/react-utilities_v9.10.1",
37
+ "version": "9.10.1",
38
+ "comments": {
39
+ "patch": [
40
+ {
41
+ "author": "bernardo.sunderhus@gmail.com",
42
+ "package": "@fluentui/react-utilities",
43
+ "commit": "7d519bdcaef0a3249b6eae721fea0e5f096f6d35",
44
+ "comment": "bugfix: removes default prevention verification on selection"
45
+ },
46
+ {
47
+ "author": "bernardo.sunderhus@gmail.com",
48
+ "package": "@fluentui/react-utilities",
49
+ "commit": "cbfa9a3717782183ebc86149abcde6468f97afa8",
50
+ "comment": "chore: adds internal tag on jsdoc for getSlotsNext"
51
+ }
52
+ ]
53
+ }
54
+ },
55
+ {
56
+ "date": "Wed, 28 Jun 2023 11:12:35 GMT",
6
57
  "tag": "@fluentui/react-utilities_v9.10.0",
7
58
  "version": "9.10.0",
8
59
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,31 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Wed, 28 Jun 2023 11:08:37 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 04 Aug 2023 08:48:24 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.11.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.11.0)
8
+
9
+ Fri, 04 Aug 2023 08:48:24 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.10.1..@fluentui/react-utilities_v9.11.0)
11
+
12
+ ### Minor changes
13
+
14
+ - feat: implement new slot methods (slot and assertSlots) ([PR #28373](https://github.com/microsoft/fluentui/pull/28373) by bernardo.sunderhus@gmail.com)
15
+
16
+ ## [9.10.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.10.1)
17
+
18
+ Mon, 03 Jul 2023 11:57:14 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.10.0..@fluentui/react-utilities_v9.10.1)
20
+
21
+ ### Patches
22
+
23
+ - bugfix: removes default prevention verification on selection ([PR #28365](https://github.com/microsoft/fluentui/pull/28365) by bernardo.sunderhus@gmail.com)
24
+ - chore: adds internal tag on jsdoc for getSlotsNext ([PR #28348](https://github.com/microsoft/fluentui/pull/28348) by bernardo.sunderhus@gmail.com)
25
+
7
26
  ## [9.10.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.10.0)
8
27
 
9
- Wed, 28 Jun 2023 11:08:37 GMT
28
+ Wed, 28 Jun 2023 11:12:35 GMT
10
29
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.9.4..@fluentui/react-utilities_v9.10.0)
11
30
 
12
31
  ### Minor changes
package/dist/index.d.ts CHANGED
@@ -1,6 +1,16 @@
1
1
  import { DispatchWithoutAction } from 'react';
2
2
  import * as React_2 from 'react';
3
3
 
4
+ /**
5
+ * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)
6
+ * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties
7
+ * @param options - values you can pass to alter the signature of a slot, those values are:
8
+ *
9
+ * * `elementType` - the base element type of a slot, defaults to `'div'`
10
+ * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided.
11
+ */
12
+ declare function always<Props extends UnknownSlotProps>(value: Props | SlotShorthandValue | undefined, options: SlotOptions<Props>): SlotComponentType<Props>;
13
+
4
14
  /**
5
15
  * @internal
6
16
  * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.
@@ -19,6 +29,27 @@ declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = {
19
29
  as?: As;
20
30
  };
21
31
 
32
+ /**
33
+ * @internal
34
+ * Assertion method to ensure state slots properties are properly declared.
35
+ * A properly declared slot must be declared by using the `slot` method.
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * export const renderInput_unstable = (state: InputState) => {
40
+ assertSlots<InputSlots>(state);
41
+ return (
42
+ <state.root>
43
+ {state.contentBefore && <state.contentBefore />}
44
+ <state.input />
45
+ {state.contentAfter && <state.contentAfter />}
46
+ </state.root>
47
+ );
48
+ };
49
+ * ```
50
+ */
51
+ export declare function assertSlots<Slots extends SlotPropsRecord>(state: unknown): asserts state is SlotComponents<Slots>;
52
+
22
53
  /**
23
54
  * Verifies if an application can use DOM.
24
55
  */
@@ -164,6 +195,11 @@ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentStat
164
195
 
165
196
  /**
166
197
  * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
198
+ *
199
+ * @internal
200
+ * This is an internal temporary method, this method will cease to exist eventually!
201
+ *
202
+ * * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️
167
203
  */
168
204
  export declare function getSlotsNext<R extends SlotPropsRecord>(state: ComponentState<R>): {
169
205
  slots: Slots<R>;
@@ -298,6 +334,12 @@ declare type IsSingleton<T extends string> = {
298
334
  [K in T]: Exclude<T, K> extends never ? true : false;
299
335
  }[T];
300
336
 
337
+ /**
338
+ * Guard method to ensure a given element is a slot.
339
+ * This is mainly used internally to ensure a slot is being used as a component.
340
+ */
341
+ export declare function isSlot<Props extends {}>(element: unknown): element is SlotComponentType<Props>;
342
+
301
343
  /**
302
344
  * Returns true if event is a touch event. Useful when sharing logic between touch and mouse interactions.
303
345
  */
@@ -369,6 +411,23 @@ export declare type OnSelectionChangeData = {
369
411
  selectedItems: Set<SelectionItemId>;
370
412
  };
371
413
 
414
+ /**
415
+ * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)
416
+ * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties
417
+ * @param options - values you can pass to alter the signature of a slot, those values are:
418
+ *
419
+ * * `elementType` - the base element type of a slot, defaults to `'div'`
420
+ * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided
421
+ * * `renderByDefault` - a boolean that indicates if a slot will be rendered even if it's base value is `undefined`.
422
+ * By default if `props.SLOT_NAME` is `undefined` then `state.SLOT_NAME` becomes `undefined`
423
+ * and nothing will be rendered, but if `renderByDefault = true` then `state.SLOT_NAME` becomes an object
424
+ * with the values provided by `options.defaultProps` (or `{}`). This is useful for cases such as providing a default content
425
+ * in case no shorthand is provided, like the case of the `expandIcon` slot for the `AccordionHeader`
426
+ */
427
+ declare function optional<Props extends UnknownSlotProps>(value: Props | SlotShorthandValue | undefined | null, options: {
428
+ renderByDefault?: boolean;
429
+ } & SlotOptions<Props>): SlotComponentType<Props> | undefined;
430
+
372
431
  /**
373
432
  * @internal
374
433
  */
@@ -430,7 +489,14 @@ export declare function resetIdsForTests(): void;
430
489
  * @param value - the base shorthand props
431
490
  * @param options - options to resolve shorthand props
432
491
  */
433
- export declare const resolveShorthand: ResolveShorthandFunction;
492
+ export declare const resolveShorthand: ResolveShorthandFunction<UnknownSlotProps>;
493
+
494
+ /**
495
+ * Helper function that converts a slot shorthand or properties to a slot properties object
496
+ * The main difference between this function and `slot` is that this function does not return the metadata required for a slot to be considered a properly renderable slot, it only converts the value to a slot properties object
497
+ * @param value - the value of the slot, it can be a slot shorthand or a slot properties object
498
+ */
499
+ declare function resolveShorthand_2<Props extends UnknownSlotProps | null | undefined>(value: Props | SlotShorthandValue): Props;
434
500
 
435
501
  export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
436
502
  <P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;
@@ -505,6 +571,22 @@ export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.Comp
505
571
  } & WithSlotRenderFunction<IntrinsicElementProps<As>>;
506
572
  }[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
507
573
 
574
+ declare namespace slot {
575
+ export {
576
+ always,
577
+ optional,
578
+ resolveShorthand_2 as resolveShorthand,
579
+ SlotOptions
580
+ }
581
+ }
582
+ export { slot }
583
+
584
+ /**
585
+ * @internal
586
+ * Internal reference for the render function
587
+ */
588
+ export declare const SLOT_ELEMENT_TYPE_SYMBOL: unique symbol;
589
+
508
590
  /**
509
591
  * @internal
510
592
  * Internal reference for the render function
@@ -518,6 +600,34 @@ export declare type SlotClassNames<Slots> = {
518
600
  [SlotName in keyof Slots]-?: string;
519
601
  };
520
602
 
603
+ declare type SlotComponents<Slots extends SlotPropsRecord> = {
604
+ [K in keyof Slots]: SlotComponentType<ExtractSlotProps<Slots[K]>>;
605
+ };
606
+
607
+ /**
608
+ * A definition of a slot, as a component, very similar to how a React component is declared,
609
+ * but with some additional metadata that is used to determine how to render the slot.
610
+ */
611
+ export declare type SlotComponentType<Props extends UnknownSlotProps> = Props & {
612
+ /**
613
+ * **NOTE**: Slot components are not callable.
614
+ */
615
+ (props: React_2.PropsWithChildren<{}>): React_2.ReactElement | null;
616
+ /**
617
+ * @internal
618
+ */
619
+ [SLOT_RENDER_FUNCTION_SYMBOL]?: SlotRenderFunction<Props>;
620
+ /**
621
+ * @internal
622
+ */
623
+ [SLOT_ELEMENT_TYPE_SYMBOL]: React_2.ComponentType<Props> | (Props extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
624
+ };
625
+
626
+ export declare type SlotOptions<Props extends UnknownSlotProps> = {
627
+ elementType: React_2.ComponentType<Props> | (Props extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
628
+ defaultProps?: Partial<Props>;
629
+ };
630
+
521
631
  /**
522
632
  * Matches any component's Slots type (such as ButtonSlots).
523
633
  *
@@ -0,0 +1,42 @@
1
+ import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';
2
+ import { isSlot } from './isSlot';
3
+ /**
4
+ * @internal
5
+ * Assertion method to ensure state slots properties are properly declared.
6
+ * A properly declared slot must be declared by using the `slot` method.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * export const renderInput_unstable = (state: InputState) => {
11
+ assertSlots<InputSlots>(state);
12
+ return (
13
+ <state.root>
14
+ {state.contentBefore && <state.contentBefore />}
15
+ <state.input />
16
+ {state.contentAfter && <state.contentAfter />}
17
+ </state.root>
18
+ );
19
+ };
20
+ * ```
21
+ */ export function assertSlots(state) {
22
+ /**
23
+ * This verification is not necessary in production
24
+ * as we're verifying static properties that will not change between environments
25
+ */ if (process.env.NODE_ENV !== 'production') {
26
+ const typedState = state;
27
+ for (const slotName of Object.keys(typedState.components)){
28
+ const slotElement = typedState[slotName];
29
+ if (slotElement === undefined) {
30
+ continue;
31
+ }
32
+ if (!isSlot(slotElement)) {
33
+ throw new Error(`${assertSlots.name} error: state.${slotName} is not a slot.\n` + `Be sure to create slots properly by using 'slot.always' or 'slot.optional'.`);
34
+ } else {
35
+ const { [SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;
36
+ if (elementType !== typedState.components[slotName]) {
37
+ throw new TypeError(`${assertSlots.name} error: state.${slotName} element type differs from state.components.${slotName}, ${elementType} !== ${typedState.components[slotName]}. \n` + `Be sure to create slots properly by using 'slot.always' or 'slot.optional' with the correct elementType`);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["assertSlots.ts"],"sourcesContent":["import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { isSlot } from './isSlot';\nimport { ComponentState, ExtractSlotProps, SlotComponentType, SlotPropsRecord } from './types';\n\ntype SlotComponents<Slots extends SlotPropsRecord> = {\n [K in keyof Slots]: SlotComponentType<ExtractSlotProps<Slots[K]>>;\n};\n\n/**\n * @internal\n * Assertion method to ensure state slots properties are properly declared.\n * A properly declared slot must be declared by using the `slot` method.\n *\n * @example\n * ```tsx\n * export const renderInput_unstable = (state: InputState) => {\n assertSlots<InputSlots>(state);\n return (\n <state.root>\n {state.contentBefore && <state.contentBefore />}\n <state.input />\n {state.contentAfter && <state.contentAfter />}\n </state.root>\n );\n };\n * ```\n */\nexport function assertSlots<Slots extends SlotPropsRecord>(state: unknown): asserts state is SlotComponents<Slots> {\n /**\n * This verification is not necessary in production\n * as we're verifying static properties that will not change between environments\n */\n if (process.env.NODE_ENV !== 'production') {\n const typedState = state as ComponentState<Slots>;\n for (const slotName of Object.keys(typedState.components)) {\n const slotElement = typedState[slotName];\n if (slotElement === undefined) {\n continue;\n }\n if (!isSlot(slotElement)) {\n throw new Error(\n `${assertSlots.name} error: state.${slotName} is not a slot.\\n` +\n `Be sure to create slots properly by using 'slot.always' or 'slot.optional'.`,\n );\n } else {\n const { [SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;\n if (elementType !== typedState.components[slotName]) {\n throw new TypeError(\n `${assertSlots.name} error: state.${slotName} element type differs from state.components.${slotName}, ${elementType} !== ${typedState.components[slotName]}. \\n` +\n `Be sure to create slots properly by using 'slot.always' or 'slot.optional' with the correct elementType`,\n );\n }\n }\n }\n }\n}\n"],"names":["SLOT_ELEMENT_TYPE_SYMBOL","isSlot","assertSlots","state","process","env","NODE_ENV","typedState","slotName","Object","keys","components","slotElement","undefined","Error","name","elementType","TypeError"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,cAAc;AACvD,SAASC,MAAM,QAAQ,WAAW;AAOlC;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,YAA2CC,KAAc,EAA0C;IACjH;;;GAGC,GACD,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,MAAMC,aAAaJ;QACnB,KAAK,MAAMK,YAAYC,OAAOC,IAAI,CAACH,WAAWI,UAAU,EAAG;YACzD,MAAMC,cAAcL,UAAU,CAACC,SAAS;YACxC,IAAII,gBAAgBC,WAAW;gBAC7B,QAAS;YACX,CAAC;YACD,IAAI,CAACZ,OAAOW,cAAc;gBACxB,MAAM,IAAIE,MACR,CAAC,EAAEZ,YAAYa,IAAI,CAAC,cAAc,EAAEP,SAAS,iBAAiB,CAAC,GAC7D,CAAC,2EAA2E,CAAC,EAC/E;YACJ,OAAO;gBACL,MAAM,EAAE,CAACR,yBAAyB,EAAEgB,YAAW,EAAE,GAAGJ;gBACpD,IAAII,gBAAgBT,WAAWI,UAAU,CAACH,SAAS,EAAE;oBACnD,MAAM,IAAIS,UACR,CAAC,EAAEf,YAAYa,IAAI,CAAC,cAAc,EAAEP,SAAS,4CAA4C,EAAEA,SAAS,EAAE,EAAEQ,YAAY,KAAK,EAAET,WAAWI,UAAU,CAACH,SAAS,CAAC,IAAI,CAAC,GAC9J,CAAC,uGAAuG,CAAC,EAC3G;gBACJ,CAAC;YACH,CAAC;QACH;IACF,CAAC;AACH,CAAC"}
@@ -2,3 +2,7 @@
2
2
  * @internal
3
3
  * Internal reference for the render function
4
4
  */ export const SLOT_RENDER_FUNCTION_SYMBOL = Symbol('fui.slotRenderFunction');
5
+ /**
6
+ * @internal
7
+ * Internal reference for the render function
8
+ */ export const SLOT_ELEMENT_TYPE_SYMBOL = Symbol('fui.slotElementType');
@@ -1 +1 @@
1
- {"version":3,"sources":["constants.ts"],"sourcesContent":["/**\n * @internal\n * Internal reference for the render function\n */\nexport const SLOT_RENDER_FUNCTION_SYMBOL = Symbol('fui.slotRenderFunction');\n"],"names":["SLOT_RENDER_FUNCTION_SYMBOL","Symbol"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,8BAA8BC,OAAO,0BAA0B"}
1
+ {"version":3,"sources":["constants.ts"],"sourcesContent":["/**\n * @internal\n * Internal reference for the render function\n */\nexport const SLOT_RENDER_FUNCTION_SYMBOL = Symbol('fui.slotRenderFunction');\n/**\n * @internal\n * Internal reference for the render function\n */\nexport const SLOT_ELEMENT_TYPE_SYMBOL = Symbol('fui.slotElementType');\n"],"names":["SLOT_RENDER_FUNCTION_SYMBOL","Symbol","SLOT_ELEMENT_TYPE_SYMBOL"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,8BAA8BC,OAAO,0BAA0B;AAC5E;;;CAGC,GACD,OAAO,MAAMC,2BAA2BD,OAAO,uBAAuB"}
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { omit } from '../utils/omit';
3
+ import { isSlot } from './isSlot';
3
4
  import { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
4
5
  /**
5
6
  * Given the state and an array of slot names, will break out `slots` and `slotProps`
@@ -40,7 +41,9 @@ function getSlot(state, slotName) {
40
41
  undefined
41
42
  ];
42
43
  }
43
- const { children , as: asProp , [SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction , ...rest } = props;
44
+ // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)
45
+ const { as: asProp , children , ...rest } = props;
46
+ const renderFunction = isSlot(props) ? props[SLOT_RENDER_FUNCTION_SYMBOL] : undefined;
44
47
  const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
45
48
  if (renderFunction || typeof children === 'function') {
46
49
  const render = renderFunction || children;
@@ -1 +1 @@
1
- {"version":3,"sources":["getSlots.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n UnknownSlotProps,\n} from './types';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\nexport type ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]> // Slot<'div', 'span'>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P // Slot<typeof Button>\n : ExtractSlotProps<S[K]>; // Slot<ButtonProps>\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: slotProps as unknown as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n const props = state[slotName];\n\n if (props === undefined) {\n return [null, undefined as R[K]];\n }\n\n const {\n children,\n as: asProp,\n [SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction,\n ...rest\n } = props as typeof props & { [SLOT_RENDER_FUNCTION_SYMBOL]?: SlotRenderFunction<R[K]> };\n\n const slot = (\n state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n if (renderFunction || typeof children === 'function') {\n const render = renderFunction || (children as SlotRenderFunction<R[K]>);\n return [\n React.Fragment,\n {\n children: render(slot, rest as Omit<R[K], 'as'>),\n } as unknown as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps = (shouldOmitAsProp ? omit(props, ['as']) : (props as UnknownSlotProps)) as R[K];\n return [slot, slotProps];\n}\n"],"names":["React","omit","SLOT_RENDER_FUNCTION_SYMBOL","getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","undefined","children","as","asProp","renderFunction","rest","render","Fragment","shouldOmitAsProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,IAAI,QAAQ,gBAAgB;AACrC,SAASC,2BAA2B,QAAQ,cAAc;AA8B1D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASC,SACdC,KAAwB,EAIxB;IACA,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IAEnB,MAAMC,YAAyBC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC3D,KAAK,MAAMC,YAAYJ,UAAW;QAChC,MAAM,CAACK,MAAMC,MAAM,GAAGC,QAAQV,OAAOO;QACrCN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IACxB;IACA,OAAO;QAAER;QAAOC,WAAWA;IAA2C;AACxE,CAAC;AAED,SAASQ,QACPV,KAAwB,EACxBO,QAAW,EACsC;QAe/CP,mBACcA;IAfhB,MAAMS,QAAQT,KAAK,CAACO,SAAS;IAE7B,IAAIE,UAAUE,WAAW;QACvB,OAAO;YAAC,IAAI;YAAEA;SAAkB;IAClC,CAAC;IAED,MAAM,EACJC,SAAQ,EACRC,IAAIC,OAAM,EACV,CAAChB,4BAA4B,EAAEiB,eAAc,EAC7C,GAAGC,MACJ,GAAGP;IAEJ,MAAMD,OACJR,CAAAA,CAAAA,oBAAAA,MAAMM,UAAU,cAAhBN,+BAAAA,KAAAA,IAAAA,iBAAkB,CAACO,SAAS,AAAD,MAAMI,aAAa,OAAOX,MAAMM,UAAU,CAACC,SAAS,KAAK,WAChFO,UAAUd,CAAAA,CAAAA,qBAAAA,MAAMM,UAAU,cAAhBN,gCAAAA,KAAAA,IAAAA,kBAAkB,CAACO,SAAS,AAAD,KAAK,QAC1CP,MAAMM,UAAU,CAACC,SAAS;IAGhC,IAAIQ,kBAAkB,OAAOH,aAAa,YAAY;QACpD,MAAMK,SAASF,kBAAmBH;QAClC,OAAO;YACLhB,MAAMsB,QAAQ;YACd;gBACEN,UAAUK,OAAOT,MAAMQ;YACzB;SACD;IACH,CAAC;IAED,MAAMG,mBAAmB,OAAOX,SAAS,YAAYM;IACrD,MAAMZ,YAAaiB,mBAAmBtB,KAAKY,OAAO;QAAC;KAAK,IAAKA,KAA0B;IACvF,OAAO;QAACD;QAAMN;KAAU;AAC1B"}
1
+ {"version":3,"sources":["getSlots.ts"],"sourcesContent":["import * as React from 'react';\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n UnknownSlotProps,\n} from './types';\nimport { isSlot } from './isSlot';\nimport { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\nexport type ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]> // Slot<'div', 'span'>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P // Slot<typeof Button>\n : ExtractSlotProps<S[K]>; // Slot<ButtonProps>\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: slotProps as unknown as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n const props = state[slotName];\n\n if (props === undefined) {\n return [null, undefined as R[K]];\n }\n\n type NonUndefined<T> = T extends undefined ? never : T;\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp, children, ...rest } = props as NonUndefined<typeof props>;\n\n const renderFunction = isSlot(props) ? props[SLOT_RENDER_FUNCTION_SYMBOL] : undefined;\n\n const slot = (\n state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n if (renderFunction || typeof children === 'function') {\n const render = (renderFunction || children) as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n {\n children: render(slot, rest as Omit<R[K], 'as'>),\n } as unknown as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps = (shouldOmitAsProp ? omit(props, ['as']) : (props as UnknownSlotProps)) as R[K];\n return [slot, slotProps];\n}\n"],"names":["React","omit","isSlot","SLOT_RENDER_FUNCTION_SYMBOL","getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","undefined","as","asProp","children","rest","renderFunction","render","Fragment","shouldOmitAsProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,IAAI,QAAQ,gBAAgB;AAUrC,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,2BAA2B,QAAQ,cAAc;AAqB1D;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASC,SACdC,KAAwB,EAIxB;IACA,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IAEnB,MAAMC,YAAyBC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC3D,KAAK,MAAMC,YAAYJ,UAAW;QAChC,MAAM,CAACK,MAAMC,MAAM,GAAGC,QAAQV,OAAOO;QACrCN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IACxB;IACA,OAAO;QAAER;QAAOC,WAAWA;IAA2C;AACxE,CAAC;AAED,SAASQ,QACPV,KAAwB,EACxBO,QAAW,EACsC;QAc/CP,mBACcA;IAdhB,MAAMS,QAAQT,KAAK,CAACO,SAAS;IAE7B,IAAIE,UAAUE,WAAW;QACvB,OAAO;YAAC,IAAI;YAAEA;SAAkB;IAClC,CAAC;IAGD,yFAAyF;IACzF,MAAM,EAAEC,IAAIC,OAAM,EAAEC,SAAQ,EAAE,GAAGC,MAAM,GAAGN;IAE1C,MAAMO,iBAAiBnB,OAAOY,SAASA,KAAK,CAACX,4BAA4B,GAAGa,SAAS;IAErF,MAAMH,OACJR,CAAAA,CAAAA,oBAAAA,MAAMM,UAAU,cAAhBN,+BAAAA,KAAAA,IAAAA,iBAAkB,CAACO,SAAS,AAAD,MAAMI,aAAa,OAAOX,MAAMM,UAAU,CAACC,SAAS,KAAK,WAChFM,UAAUb,CAAAA,CAAAA,qBAAAA,MAAMM,UAAU,cAAhBN,gCAAAA,KAAAA,IAAAA,kBAAkB,CAACO,SAAS,AAAD,KAAK,QAC1CP,MAAMM,UAAU,CAACC,SAAS;IAGhC,IAAIS,kBAAkB,OAAOF,aAAa,YAAY;QACpD,MAAMG,SAAUD,kBAAkBF;QAClC,OAAO;YACLnB,MAAMuB,QAAQ;YACd;gBACEJ,UAAUG,OAAOT,MAAMO;YACzB;SACD;IACH,CAAC;IAED,MAAMI,mBAAmB,OAAOX,SAAS,YAAYK;IACrD,MAAMX,YAAaiB,mBAAmBvB,KAAKa,OAAO;QAAC;KAAK,IAAKA,KAA0B;IACvF,OAAO;QAACD;QAAMN;KAAU;AAC1B"}
@@ -1,6 +1,11 @@
1
1
  import * as React from 'react';
2
2
  /**
3
3
  * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
4
+ *
5
+ * @internal
6
+ * This is an internal temporary method, this method will cease to exist eventually!
7
+ *
8
+ * * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️
4
9
  */ export function getSlotsNext(state) {
5
10
  const slots = {};
6
11
  const slotProps = {};
@@ -1 +1 @@
1
- {"version":3,"sources":["getSlotsNext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentState, SlotPropsRecord, UnknownSlotProps } from './types';\nimport { ObjectSlotProps, Slots } from './getSlots';\n\n/**\n * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma\n */\nexport function getSlotsNext<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlotNext(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: slotProps as unknown as ObjectSlotProps<R> };\n}\n\nfunction getSlotNext<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n const props = state[slotName];\n\n if (props === undefined) {\n return [null, undefined as R[K]];\n }\n\n type NonUndefined<T> = T extends undefined ? never : T;\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp, ...propsWithoutAs } = props as NonUndefined<typeof props>;\n\n const slot = (\n state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps: UnknownSlotProps = shouldOmitAsProp ? propsWithoutAs : props;\n\n return [slot, slotProps as R[K]];\n}\n"],"names":["React","getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAI/B;;CAEC,GACD,OAAO,SAASC,aACdC,KAAwB,EAIxB;IACA,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IAEnB,MAAMC,YAAyBC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC3D,KAAK,MAAMC,YAAYJ,UAAW;QAChC,MAAM,CAACK,MAAMC,MAAM,GAAGC,YAAYV,OAAOO;QACzCN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IACxB;IACA,OAAO;QAAER;QAAOC,WAAWA;IAA2C;AACxE,CAAC;AAED,SAASQ,YACPV,KAAwB,EACxBO,QAAW,EACsC;QAY/CP,mBACcA;IAZhB,MAAMS,QAAQT,KAAK,CAACO,SAAS;IAE7B,IAAIE,UAAUE,WAAW;QACvB,OAAO;YAAC,IAAI;YAAEA;SAAkB;IAClC,CAAC;IAGD,yFAAyF;IACzF,MAAM,EAAEC,IAAIC,OAAM,EAAE,GAAGC,gBAAgB,GAAGL;IAE1C,MAAMD,OACJR,CAAAA,CAAAA,oBAAAA,MAAMM,UAAU,cAAhBN,+BAAAA,KAAAA,IAAAA,iBAAkB,CAACO,SAAS,AAAD,MAAMI,aAAa,OAAOX,MAAMM,UAAU,CAACC,SAAS,KAAK,WAChFM,UAAUb,CAAAA,CAAAA,qBAAAA,MAAMM,UAAU,cAAhBN,gCAAAA,KAAAA,IAAAA,kBAAkB,CAACO,SAAS,AAAD,KAAK,QAC1CP,MAAMM,UAAU,CAACC,SAAS;IAGhC,MAAMQ,mBAAmB,OAAOP,SAAS,YAAYK;IACrD,MAAMX,YAA8Ba,mBAAmBD,iBAAiBL,KAAK;IAE7E,OAAO;QAACD;QAAMN;KAAkB;AAClC"}
1
+ {"version":3,"sources":["getSlotsNext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentState, SlotPropsRecord, UnknownSlotProps } from './types';\nimport { ObjectSlotProps, Slots } from './getSlots';\n\n/**\n * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma\n *\n * @internal\n * This is an internal temporary method, this method will cease to exist eventually!\n *\n * * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️\n */\nexport function getSlotsNext<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlotNext(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: slotProps as unknown as ObjectSlotProps<R> };\n}\n\nfunction getSlotNext<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n const props = state[slotName];\n\n if (props === undefined) {\n return [null, undefined as R[K]];\n }\n\n type NonUndefined<T> = T extends undefined ? never : T;\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp, ...propsWithoutAs } = props as NonUndefined<typeof props>;\n\n const slot = (\n state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps: UnknownSlotProps = shouldOmitAsProp ? propsWithoutAs : props;\n\n return [slot, slotProps as R[K]];\n}\n"],"names":["React","getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAI/B;;;;;;;CAOC,GACD,OAAO,SAASC,aACdC,KAAwB,EAIxB;IACA,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IAEnB,MAAMC,YAAyBC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC3D,KAAK,MAAMC,YAAYJ,UAAW;QAChC,MAAM,CAACK,MAAMC,MAAM,GAAGC,YAAYV,OAAOO;QACzCN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IACxB;IACA,OAAO;QAAER;QAAOC,WAAWA;IAA2C;AACxE,CAAC;AAED,SAASQ,YACPV,KAAwB,EACxBO,QAAW,EACsC;QAY/CP,mBACcA;IAZhB,MAAMS,QAAQT,KAAK,CAACO,SAAS;IAE7B,IAAIE,UAAUE,WAAW;QACvB,OAAO;YAAC,IAAI;YAAEA;SAAkB;IAClC,CAAC;IAGD,yFAAyF;IACzF,MAAM,EAAEC,IAAIC,OAAM,EAAE,GAAGC,gBAAgB,GAAGL;IAE1C,MAAMD,OACJR,CAAAA,CAAAA,oBAAAA,MAAMM,UAAU,cAAhBN,+BAAAA,KAAAA,IAAAA,iBAAkB,CAACO,SAAS,AAAD,MAAMI,aAAa,OAAOX,MAAMM,UAAU,CAACC,SAAS,KAAK,WAChFM,UAAUb,CAAAA,CAAAA,qBAAAA,MAAMM,UAAU,cAAhBN,gCAAAA,KAAAA,IAAAA,kBAAkB,CAACO,SAAS,AAAD,KAAK,QAC1CP,MAAMM,UAAU,CAACC,SAAS;IAGhC,MAAMQ,mBAAmB,OAAOP,SAAS,YAAYK;IACrD,MAAMX,YAA8Ba,mBAAmBD,iBAAiBL,KAAK;IAE7E,OAAO;QAACD;QAAMN;KAAkB;AAClC"}
@@ -1,6 +1,10 @@
1
+ import * as slot from './slot';
1
2
  export * from './getSlots';
2
3
  export * from './resolveShorthand';
3
4
  export * from './types';
4
5
  export * from './isResolvedShorthand';
5
6
  export * from './constants';
6
7
  export * from './getSlotsNext';
8
+ export * from './isSlot';
9
+ export * from './assertSlots';
10
+ export { slot };
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\nexport * from './constants';\nexport * from './getSlotsNext';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,qBAAqB;AACnC,cAAc,UAAU;AACxB,cAAc,wBAAwB;AACtC,cAAc,cAAc;AAC5B,cAAc,iBAAiB"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["import * as slot from './slot';\n\nexport * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\nexport * from './constants';\nexport * from './getSlotsNext';\nexport * from './isSlot';\nexport * from './assertSlots';\n\nexport { slot };\nexport type { SlotOptions } from './slot';\n"],"names":["slot"],"mappings":"AAAA,YAAYA,UAAU,SAAS;AAE/B,cAAc,aAAa;AAC3B,cAAc,qBAAqB;AACnC,cAAc,UAAU;AACxB,cAAc,wBAAwB;AACtC,cAAc,cAAc;AAC5B,cAAc,iBAAiB;AAC/B,cAAc,WAAW;AACzB,cAAc,gBAAgB;AAE9B,SAASA,IAAI,GAAG"}
@@ -0,0 +1,7 @@
1
+ import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';
2
+ /**
3
+ * Guard method to ensure a given element is a slot.
4
+ * This is mainly used internally to ensure a slot is being used as a component.
5
+ */ export function isSlot(element) {
6
+ return Boolean(element === null || element === void 0 ? void 0 : element.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));
7
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["isSlot.ts"],"sourcesContent":["import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { SlotComponentType } from './types';\n\n/**\n * Guard method to ensure a given element is a slot.\n * This is mainly used internally to ensure a slot is being used as a component.\n */\nexport function isSlot<Props extends {}>(element: unknown): element is SlotComponentType<Props> {\n return Boolean((element as {} | undefined)?.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));\n}\n"],"names":["SLOT_ELEMENT_TYPE_SYMBOL","isSlot","element","Boolean","hasOwnProperty"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,cAAc;AAGvD;;;CAGC,GACD,OAAO,SAASC,OAAyBC,OAAgB,EAAuC;IAC9F,OAAOC,QAAQ,AAACD,oBAAAA,qBAAD,KAAA,IAAA,AAACA,QAA4BE,cAAc,CAACJ;AAC7D,CAAC"}
@@ -1,29 +1,15 @@
1
- import { isValidElement } from 'react';
2
- import { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
1
+ import * as slot from './slot';
3
2
  /**
4
3
  * Resolves shorthands into slot props, to ensure normalization of the signature
5
4
  * being passed down to getSlots method
6
5
  * @param value - the base shorthand props
7
6
  * @param options - options to resolve shorthand props
8
7
  */ export const resolveShorthand = (value, options)=>{
9
- const { required =false , defaultProps } = options || {};
10
- if (value === null || value === undefined && !required) {
11
- return undefined;
12
- }
13
- let resolvedShorthand = {};
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement(value)) {
16
- resolvedShorthand.children = value;
17
- } else if (typeof value === 'object') {
18
- resolvedShorthand = value;
19
- }
20
- resolvedShorthand = {
21
- ...defaultProps,
22
- ...resolvedShorthand
23
- };
24
- if (typeof resolvedShorthand.children === 'function') {
25
- resolvedShorthand[SLOT_RENDER_FUNCTION_SYMBOL] = resolvedShorthand.children;
26
- resolvedShorthand.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;
27
- }
28
- return resolvedShorthand;
8
+ return slot.optional(value, {
9
+ ...options,
10
+ renderByDefault: options === null || options === void 0 ? void 0 : options.required,
11
+ // elementType as undefined is the way to identify between a slot and a resolveShorthand call
12
+ // in the case elementType is undefined assertSlots will fail, ensuring it'll only work with slot method.
13
+ elementType: undefined
14
+ });
29
15
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["resolveShorthand.ts"],"sourcesContent":["import { isValidElement } from 'react';\nimport type { SlotRenderFunction, SlotShorthandValue, UnknownSlotProps } from './types';\nimport { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true\n ? { required: true; defaultProps?: Props }\n : { required?: Required; defaultProps?: Props };\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;\n <P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | P\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction = (value, options) => {\n const { required = false, defaultProps } = options || {};\n if (value === null || (value === undefined && !required)) {\n return undefined;\n }\n\n let resolvedShorthand: UnknownSlotProps & {\n [SLOT_RENDER_FUNCTION_SYMBOL]?: SlotRenderFunction<UnknownSlotProps>;\n } = {};\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement<any>(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n resolvedShorthand = {\n ...defaultProps,\n ...resolvedShorthand,\n };\n\n if (typeof resolvedShorthand.children === 'function') {\n resolvedShorthand[SLOT_RENDER_FUNCTION_SYMBOL] = resolvedShorthand.children as SlotRenderFunction<UnknownSlotProps>;\n resolvedShorthand.children = defaultProps?.children;\n }\n\n return resolvedShorthand;\n};\n"],"names":["isValidElement","SLOT_RENDER_FUNCTION_SYMBOL","resolveShorthand","value","options","required","defaultProps","undefined","resolvedShorthand","Array","isArray","children"],"mappings":"AAAA,SAASA,cAAc,QAAQ,QAAQ;AAEvC,SAASC,2BAA2B,QAAQ,cAAc;AAa1D;;;;;CAKC,GACD,OAAO,MAAMC,mBAA6C,CAACC,OAAOC,UAAY;IAC5E,MAAM,EAAEC,UAAW,KAAK,CAAA,EAAEC,aAAY,EAAE,GAAGF,WAAW,CAAC;IACvD,IAAID,UAAU,IAAI,IAAKA,UAAUI,aAAa,CAACF,UAAW;QACxD,OAAOE;IACT,CAAC;IAED,IAAIC,oBAEA,CAAC;IAEL,8DAA8D;IAC9D,IAAI,OAAOL,UAAU,YAAY,OAAOA,UAAU,YAAYM,MAAMC,OAAO,CAACP,UAAUH,eAAoBG,QAAQ;QAChHK,kBAAkBG,QAAQ,GAAGR;IAC/B,OAAO,IAAI,OAAOA,UAAU,UAAU;QACpCK,oBAAoBL;IACtB,CAAC;IAEDK,oBAAoB;QAClB,GAAGF,YAAY;QACf,GAAGE,iBAAiB;IACtB;IAEA,IAAI,OAAOA,kBAAkBG,QAAQ,KAAK,YAAY;QACpDH,iBAAiB,CAACP,4BAA4B,GAAGO,kBAAkBG,QAAQ;QAC3EH,kBAAkBG,QAAQ,GAAGL,yBAAAA,0BAAAA,KAAAA,IAAAA,aAAcK,QAAQ;IACrD,CAAC;IAED,OAAOH;AACT,EAAE"}
1
+ {"version":3,"sources":["resolveShorthand.ts"],"sourcesContent":["import * as slot from './slot';\nimport type { SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true\n ? { required: true; defaultProps?: Props }\n : { required?: Required; defaultProps?: Props };\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;\n <P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | P\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction<UnknownSlotProps> = (value, options) =>\n slot.optional<UnknownSlotProps>(value, {\n ...options,\n renderByDefault: options?.required,\n // elementType as undefined is the way to identify between a slot and a resolveShorthand call\n // in the case elementType is undefined assertSlots will fail, ensuring it'll only work with slot method.\n elementType: undefined!,\n });\n"],"names":["slot","resolveShorthand","value","options","optional","renderByDefault","required","elementType","undefined"],"mappings":"AAAA,YAAYA,UAAU,SAAS;AAc/B;;;;;CAKC,GACD,OAAO,MAAMC,mBAA+D,CAACC,OAAOC;IAClFH,OAAAA,KAAKI,QAAQ,CAAmBF,OAAO;QACrC,GAAGC,OAAO;QACVE,iBAAiBF,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASG,QAAQ;QAClC,6FAA6F;QAC7F,yGAAyG;QACzGC,aAAaC;IACf;EAAG"}
@@ -0,0 +1,59 @@
1
+ import * as React from 'react';
2
+ import { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
3
+ /**
4
+ * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)
5
+ * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties
6
+ * @param options - values you can pass to alter the signature of a slot, those values are:
7
+ *
8
+ * * `elementType` - the base element type of a slot, defaults to `'div'`
9
+ * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided.
10
+ */ export function always(value, options) {
11
+ const { defaultProps , elementType } = options;
12
+ const props = resolveShorthand(value);
13
+ /**
14
+ * Casting is required here as SlotComponentType is a function, not an object.
15
+ * Although SlotComponentType has a function signature, it is still just an object.
16
+ * This is required to make a slot callable (JSX compatible), this is the exact same approach
17
+ * that is used on `@types/react` components
18
+ */ const propsWithMetadata = {
19
+ ...defaultProps,
20
+ ...props,
21
+ [SLOT_ELEMENT_TYPE_SYMBOL]: elementType
22
+ };
23
+ if (props && typeof props.children === 'function') {
24
+ propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children;
25
+ propsWithMetadata.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;
26
+ }
27
+ return propsWithMetadata;
28
+ }
29
+ /**
30
+ * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)
31
+ * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties
32
+ * @param options - values you can pass to alter the signature of a slot, those values are:
33
+ *
34
+ * * `elementType` - the base element type of a slot, defaults to `'div'`
35
+ * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided
36
+ * * `renderByDefault` - a boolean that indicates if a slot will be rendered even if it's base value is `undefined`.
37
+ * By default if `props.SLOT_NAME` is `undefined` then `state.SLOT_NAME` becomes `undefined`
38
+ * and nothing will be rendered, but if `renderByDefault = true` then `state.SLOT_NAME` becomes an object
39
+ * with the values provided by `options.defaultProps` (or `{}`). This is useful for cases such as providing a default content
40
+ * in case no shorthand is provided, like the case of the `expandIcon` slot for the `AccordionHeader`
41
+ */ export function optional(value, options) {
42
+ if (value === null || value === undefined && !options.renderByDefault) {
43
+ return undefined;
44
+ }
45
+ return always(value, options);
46
+ }
47
+ /**
48
+ * Helper function that converts a slot shorthand or properties to a slot properties object
49
+ * The main difference between this function and `slot` is that this function does not return the metadata required for a slot to be considered a properly renderable slot, it only converts the value to a slot properties object
50
+ * @param value - the value of the slot, it can be a slot shorthand or a slot properties object
51
+ */ export function resolveShorthand(value) {
52
+ if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ React.isValidElement(value)) {
54
+ return {
55
+ children: value
56
+ };
57
+ }
58
+ return value;
59
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["slot.ts"],"sourcesContent":["import type {\n AsIntrinsicElement,\n SlotComponentType,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n} from './types';\nimport * as React from 'react';\nimport { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\n\nexport type SlotOptions<Props extends UnknownSlotProps> = {\n elementType:\n | React.ComponentType<Props>\n | (Props extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);\n defaultProps?: Partial<Props>;\n};\n\n/**\n * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)\n * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties\n * @param options - values you can pass to alter the signature of a slot, those values are:\n *\n * * `elementType` - the base element type of a slot, defaults to `'div'`\n * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided.\n */\nexport function always<Props extends UnknownSlotProps>(\n value: Props | SlotShorthandValue | undefined,\n options: SlotOptions<Props>,\n): SlotComponentType<Props> {\n const { defaultProps, elementType } = options;\n\n const props = resolveShorthand(value);\n\n /**\n * Casting is required here as SlotComponentType is a function, not an object.\n * Although SlotComponentType has a function signature, it is still just an object.\n * This is required to make a slot callable (JSX compatible), this is the exact same approach\n * that is used on `@types/react` components\n */\n const propsWithMetadata = {\n ...defaultProps,\n ...props,\n [SLOT_ELEMENT_TYPE_SYMBOL]: elementType,\n } as SlotComponentType<Props>;\n\n if (props && typeof props.children === 'function') {\n propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children as SlotRenderFunction<Props>;\n propsWithMetadata.children = defaultProps?.children;\n }\n\n return propsWithMetadata;\n}\n\n/**\n * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)\n * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties\n * @param options - values you can pass to alter the signature of a slot, those values are:\n *\n * * `elementType` - the base element type of a slot, defaults to `'div'`\n * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided\n * * `renderByDefault` - a boolean that indicates if a slot will be rendered even if it's base value is `undefined`.\n * By default if `props.SLOT_NAME` is `undefined` then `state.SLOT_NAME` becomes `undefined`\n * and nothing will be rendered, but if `renderByDefault = true` then `state.SLOT_NAME` becomes an object\n * with the values provided by `options.defaultProps` (or `{}`). This is useful for cases such as providing a default content\n * in case no shorthand is provided, like the case of the `expandIcon` slot for the `AccordionHeader`\n */\nexport function optional<Props extends UnknownSlotProps>(\n value: Props | SlotShorthandValue | undefined | null,\n options: { renderByDefault?: boolean } & SlotOptions<Props>,\n): SlotComponentType<Props> | undefined {\n if (value === null || (value === undefined && !options.renderByDefault)) {\n return undefined;\n }\n return always(value, options);\n}\n\n/**\n * Helper function that converts a slot shorthand or properties to a slot properties object\n * The main difference between this function and `slot` is that this function does not return the metadata required for a slot to be considered a properly renderable slot, it only converts the value to a slot properties object\n * @param value - the value of the slot, it can be a slot shorthand or a slot properties object\n */\nexport function resolveShorthand<Props extends UnknownSlotProps | null | undefined>(\n value: Props | SlotShorthandValue,\n): Props {\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n Array.isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n React.isValidElement<any>(value)\n ) {\n return { children: value } as Props;\n }\n\n return value;\n}\n"],"names":["React","SLOT_ELEMENT_TYPE_SYMBOL","SLOT_RENDER_FUNCTION_SYMBOL","always","value","options","defaultProps","elementType","props","resolveShorthand","propsWithMetadata","children","optional","undefined","renderByDefault","Array","isArray","isValidElement"],"mappings":"AAOA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,wBAAwB,EAAEC,2BAA2B,QAAQ,cAAc;AASpF;;;;;;;CAOC,GACD,OAAO,SAASC,OACdC,KAA6C,EAC7CC,OAA2B,EACD;IAC1B,MAAM,EAAEC,aAAY,EAAEC,YAAW,EAAE,GAAGF;IAEtC,MAAMG,QAAQC,iBAAiBL;IAE/B;;;;;GAKC,GACD,MAAMM,oBAAoB;QACxB,GAAGJ,YAAY;QACf,GAAGE,KAAK;QACR,CAACP,yBAAyB,EAAEM;IAC9B;IAEA,IAAIC,SAAS,OAAOA,MAAMG,QAAQ,KAAK,YAAY;QACjDD,iBAAiB,CAACR,4BAA4B,GAAGM,MAAMG,QAAQ;QAC/DD,kBAAkBC,QAAQ,GAAGL,yBAAAA,0BAAAA,KAAAA,IAAAA,aAAcK,QAAQ;IACrD,CAAC;IAED,OAAOD;AACT,CAAC;AAED;;;;;;;;;;;;CAYC,GACD,OAAO,SAASE,SACdR,KAAoD,EACpDC,OAA2D,EACrB;IACtC,IAAID,UAAU,IAAI,IAAKA,UAAUS,aAAa,CAACR,QAAQS,eAAe,EAAG;QACvE,OAAOD;IACT,CAAC;IACD,OAAOV,OAAOC,OAAOC;AACvB,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASI,iBACdL,KAAiC,EAC1B;IACP,IACE,OAAOA,UAAU,YACjB,OAAOA,UAAU,YACjBW,MAAMC,OAAO,CAACZ,UACd,8DAA8D;IAC9DJ,MAAMiB,cAAc,CAAMb,QAC1B;QACA,OAAO;YAAEO,UAAUP;QAAM;IAC3B,CAAC;IAED,OAAOA;AACT,CAAC"}