@fluentui/react-utilities 9.11.0 → 9.11.2

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/CHANGELOG.json CHANGED
@@ -2,7 +2,37 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 04 Aug 2023 08:48:24 GMT",
5
+ "date": "Wed, 23 Aug 2023 11:58:32 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.11.2",
7
+ "version": "9.11.2",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "bernardo.sunderhus@gmail.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "f94b6d05d7642563cb96e2718402fbbbab65cbbc",
14
+ "comment": "bugfix: ensure interop between assertSlots and old API"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Fri, 11 Aug 2023 12:14:25 GMT",
21
+ "tag": "@fluentui/react-utilities_v9.11.1",
22
+ "version": "9.11.1",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "bernardo.sunderhus@gmail.com",
27
+ "package": "@fluentui/react-utilities",
28
+ "commit": "f9f2b69201c81811e8e4ce23f971d6174127d0ca",
29
+ "comment": "chore: tests for slot.resolveShorthand behavior"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Fri, 04 Aug 2023 08:52:58 GMT",
6
36
  "tag": "@fluentui/react-utilities_v9.11.0",
7
37
  "version": "9.11.0",
8
38
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,30 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Fri, 04 Aug 2023 08:48:24 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 23 Aug 2023 11:58:32 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.11.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.11.2)
8
+
9
+ Wed, 23 Aug 2023 11:58:32 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.11.1..@fluentui/react-utilities_v9.11.2)
11
+
12
+ ### Patches
13
+
14
+ - bugfix: ensure interop between assertSlots and old API ([PR #28957](https://github.com/microsoft/fluentui/pull/28957) by bernardo.sunderhus@gmail.com)
15
+
16
+ ## [9.11.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.11.1)
17
+
18
+ Fri, 11 Aug 2023 12:14:25 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.11.0..@fluentui/react-utilities_v9.11.1)
20
+
21
+ ### Patches
22
+
23
+ - chore: tests for slot.resolveShorthand behavior ([PR #28819](https://github.com/microsoft/fluentui/pull/28819) by bernardo.sunderhus@gmail.com)
24
+
7
25
  ## [9.11.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.11.0)
8
26
 
9
- Fri, 04 Aug 2023 08:48:24 GMT
27
+ Fri, 04 Aug 2023 08:52:58 GMT
10
28
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.10.1..@fluentui/react-utilities_v9.11.0)
11
29
 
12
30
  ### Minor changes
@@ -1,5 +1,7 @@
1
+ import * as React from 'react';
1
2
  import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';
2
3
  import { isSlot } from './isSlot';
4
+ import { slot } from './index';
3
5
  /**
4
6
  * @internal
5
7
  * Assertion method to ensure state slots properties are properly declared.
@@ -29,12 +31,23 @@ import { isSlot } from './isSlot';
29
31
  if (slotElement === undefined) {
30
32
  continue;
31
33
  }
34
+ // this means a slot is being declared without using, slot.always or slot.optional or even resolveShorthand on the state hook,
35
+ // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type
36
+ // FIXME: this slot will still fail to support child render function scenario
32
37
  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'.`);
38
+ typedState[slotName] = slot.always(slotElement, {
39
+ elementType: typedState.components[slotName]
40
+ });
41
+ // eslint-disable-next-line no-console
42
+ console.warn(`${assertSlots.name} warning: state.${slotName} is not a slot.\n` + `Be sure to create slots properly by using 'slot.always' or 'slot.optional'.`);
34
43
  } else {
44
+ // This means a slot is being declared by using resolveShorthand on the state hook,
45
+ // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type
35
46
  const { [SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;
36
47
  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`);
48
+ slotElement[SLOT_ELEMENT_TYPE_SYMBOL] = typedState.components[slotName];
49
+ // eslint-disable-next-line no-console
50
+ console.warn(`${assertSlots.name} warning: 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
51
  }
39
52
  }
40
53
  }
@@ -1 +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"}
1
+ {"version":3,"sources":["assertSlots.ts"],"sourcesContent":["import * as React from 'react';\nimport { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { isSlot } from './isSlot';\nimport { ComponentState, ExtractSlotProps, SlotComponentType, SlotPropsRecord } from './types';\nimport { slot } from './index';\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 // this means a slot is being declared without using, slot.always or slot.optional or even resolveShorthand on the state hook,\n // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type\n // FIXME: this slot will still fail to support child render function scenario\n if (!isSlot(slotElement)) {\n typedState[slotName as keyof ComponentState<Slots>] = slot.always(slotElement, {\n elementType: typedState.components[slotName] as React.ComponentType<{}>,\n }) as ComponentState<Slots>[keyof ComponentState<Slots>];\n // eslint-disable-next-line no-console\n console.warn(\n `${assertSlots.name} warning: 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 // This means a slot is being declared by using resolveShorthand on the state hook,\n // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type\n const { [SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;\n if (elementType !== typedState.components[slotName]) {\n slotElement[SLOT_ELEMENT_TYPE_SYMBOL] = typedState.components[slotName] as React.ComponentType<{}>;\n // eslint-disable-next-line no-console\n console.warn(\n `${assertSlots.name} warning: 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":["React","SLOT_ELEMENT_TYPE_SYMBOL","isSlot","slot","assertSlots","state","process","env","NODE_ENV","typedState","slotName","Object","keys","components","slotElement","undefined","always","elementType","console","warn","name"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,wBAAwB,QAAQ,cAAc;AACvD,SAASC,MAAM,QAAQ,WAAW;AAElC,SAASC,IAAI,QAAQ,UAAU;AAM/B;;;;;;;;;;;;;;;;;;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,8HAA8H;YAC9H,4JAA4J;YAC5J,6EAA6E;YAC7E,IAAI,CAACb,OAAOY,cAAc;gBACxBL,UAAU,CAACC,SAAwC,GAAGP,KAAKa,MAAM,CAACF,aAAa;oBAC7EG,aAAaR,WAAWI,UAAU,CAACH,SAAS;gBAC9C;gBACA,sCAAsC;gBACtCQ,QAAQC,IAAI,CACV,CAAC,EAAEf,YAAYgB,IAAI,CAAC,gBAAgB,EAAEV,SAAS,iBAAiB,CAAC,GAC/D,CAAC,2EAA2E,CAAC;YAEnF,OAAO;gBACL,mFAAmF;gBACnF,4JAA4J;gBAC5J,MAAM,EAAE,CAACT,yBAAyB,EAAEgB,YAAW,EAAE,GAAGH;gBACpD,IAAIG,gBAAgBR,WAAWI,UAAU,CAACH,SAAS,EAAE;oBACnDI,WAAW,CAACb,yBAAyB,GAAGQ,WAAWI,UAAU,CAACH,SAAS;oBACvE,sCAAsC;oBACtCQ,QAAQC,IAAI,CACV,CAAC,EAAEf,YAAYgB,IAAI,CAAC,gBAAgB,EAAEV,SAAS,4CAA4C,EAAEA,SAAS,EAAE,EAAEO,YAAY,KAAK,EAAER,WAAWI,UAAU,CAACH,SAAS,CAAC,IAAI,CAAC,GAChK,CAAC,uGAAuG,CAAC;gBAE/G,CAAC;YACH,CAAC;QACH;IACF,CAAC;AACH,CAAC"}
@@ -55,5 +55,14 @@ import { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constan
55
55
  children: value
56
56
  };
57
57
  }
58
+ if (value && typeof value !== 'object' && process.env.NODE_ENV !== 'production') {
59
+ // TODO: would be nice to have a link to slot documentation in this error message
60
+ // eslint-disable-next-line no-console
61
+ console.error([
62
+ `[slot.resolveShorthand]: A slot got invalid value "${value}" (${typeof value}).`,
63
+ 'A valid value is a slot shorthand or slot properties object.',
64
+ 'Slot shorthands can be strings, numbers, arrays or JSX elements'
65
+ ].join('\n'));
66
+ }
58
67
  return value;
59
68
  }
@@ -1 +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"}
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 if (value && typeof value !== 'object' && process.env.NODE_ENV !== 'production') {\n // TODO: would be nice to have a link to slot documentation in this error message\n // eslint-disable-next-line no-console\n console.error(\n [\n `[slot.resolveShorthand]: A slot got invalid value \"${value}\" (${typeof value}).`,\n 'A valid value is a slot shorthand or slot properties object.',\n 'Slot shorthands can be strings, numbers, arrays or JSX elements',\n ].join('\\n'),\n );\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","process","env","NODE_ENV","console","error","join"],"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;IACD,IAAIA,SAAS,OAAOA,UAAU,YAAYc,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAC/E,iFAAiF;QACjF,sCAAsC;QACtCC,QAAQC,KAAK,CACX;YACE,CAAC,mDAAmD,EAAElB,MAAM,GAAG,EAAE,OAAOA,MAAM,EAAE,CAAC;YACjF;YACA;SACD,CAACmB,IAAI,CAAC;IAEX,CAAC;IAED,OAAOnB;AACT,CAAC"}
@@ -6,8 +6,11 @@ Object.defineProperty(exports, "assertSlots", {
6
6
  enumerable: true,
7
7
  get: ()=>assertSlots
8
8
  });
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
9
11
  const _constants = require("./constants");
10
12
  const _isSlot = require("./isSlot");
13
+ const _index = require("./index");
11
14
  function assertSlots(state) {
12
15
  /**
13
16
  * This verification is not necessary in production
@@ -19,12 +22,23 @@ function assertSlots(state) {
19
22
  if (slotElement === undefined) {
20
23
  continue;
21
24
  }
25
+ // this means a slot is being declared without using, slot.always or slot.optional or even resolveShorthand on the state hook,
26
+ // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type
27
+ // FIXME: this slot will still fail to support child render function scenario
22
28
  if (!(0, _isSlot.isSlot)(slotElement)) {
23
- 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'.`);
29
+ typedState[slotName] = _index.slot.always(slotElement, {
30
+ elementType: typedState.components[slotName]
31
+ });
32
+ // eslint-disable-next-line no-console
33
+ console.warn(`${assertSlots.name} warning: state.${slotName} is not a slot.\n` + `Be sure to create slots properly by using 'slot.always' or 'slot.optional'.`);
24
34
  } else {
35
+ // This means a slot is being declared by using resolveShorthand on the state hook,
36
+ // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type
25
37
  const { [_constants.SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;
26
38
  if (elementType !== typedState.components[slotName]) {
27
- 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`);
39
+ slotElement[_constants.SLOT_ELEMENT_TYPE_SYMBOL] = typedState.components[slotName];
40
+ // eslint-disable-next-line no-console
41
+ console.warn(`${assertSlots.name} warning: 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`);
28
42
  }
29
43
  }
30
44
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["assertSlots.js"],"sourcesContent":["import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { isSlot } from './isSlot';\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 */ export function assertSlots(state) {\n /**\n * This verification is not necessary in production\n * as we're verifying static properties that will not change between environments\n */ if (process.env.NODE_ENV !== 'production') {\n const typedState = state;\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(`${assertSlots.name} error: state.${slotName} is not a slot.\\n` + `Be sure to create slots properly by using 'slot.always' or 'slot.optional'.`);\n } else {\n const { [SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;\n if (elementType !== typedState.components[slotName]) {\n 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`);\n }\n }\n }\n }\n}\n"],"names":["assertSlots","state","process","env","NODE_ENV","typedState","slotName","Object","keys","components","slotElement","undefined","isSlot","Error","name","SLOT_ELEMENT_TYPE_SYMBOL","elementType","TypeError"],"mappings":";;;;+BAoBoBA;;aAAAA;;2BApBqB;wBAClB;AAmBZ,SAASA,YAAYC,KAAK,EAAE;IACnC;;;GAGD,GAAG,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,MAAMC,aAAaJ;QACnB,KAAK,MAAMK,YAAYC,OAAOC,IAAI,CAACH,WAAWI,UAAU,EAAE;YACtD,MAAMC,cAAcL,UAAU,CAACC,SAAS;YACxC,IAAII,gBAAgBC,WAAW;gBAC3B,QAAS;YACb,CAAC;YACD,IAAI,CAACC,IAAAA,cAAM,EAACF,cAAc;gBACtB,MAAM,IAAIG,MAAM,CAAC,EAAEb,YAAYc,IAAI,CAAC,cAAc,EAAER,SAAS,iBAAiB,CAAC,GAAG,CAAC,2EAA2E,CAAC,EAAE;YACrK,OAAO;gBACH,MAAM,EAAE,CAACS,mCAAwB,CAAC,EAAEC,YAAW,EAAG,GAAGN;gBACrD,IAAIM,gBAAgBX,WAAWI,UAAU,CAACH,SAAS,EAAE;oBACjD,MAAM,IAAIW,UAAU,CAAC,EAAEjB,YAAYc,IAAI,CAAC,cAAc,EAAER,SAAS,4CAA4C,EAAEA,SAAS,EAAE,EAAEU,YAAY,KAAK,EAAEX,WAAWI,UAAU,CAACH,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,uGAAuG,CAAC,EAAE;gBACtS,CAAC;YACL,CAAC;QACL;IACJ,CAAC;AACL"}
1
+ {"version":3,"sources":["assertSlots.js"],"sourcesContent":["import * as React from 'react';\nimport { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { isSlot } from './isSlot';\nimport { slot } from './index';\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 */ export function assertSlots(state) {\n /**\n * This verification is not necessary in production\n * as we're verifying static properties that will not change between environments\n */ if (process.env.NODE_ENV !== 'production') {\n const typedState = state;\n for (const slotName of Object.keys(typedState.components)){\n const slotElement = typedState[slotName];\n if (slotElement === undefined) {\n continue;\n }\n // this means a slot is being declared without using, slot.always or slot.optional or even resolveShorthand on the state hook,\n // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type\n // FIXME: this slot will still fail to support child render function scenario\n if (!isSlot(slotElement)) {\n typedState[slotName] = slot.always(slotElement, {\n elementType: typedState.components[slotName]\n });\n // eslint-disable-next-line no-console\n console.warn(`${assertSlots.name} warning: state.${slotName} is not a slot.\\n` + `Be sure to create slots properly by using 'slot.always' or 'slot.optional'.`);\n } else {\n // This means a slot is being declared by using resolveShorthand on the state hook,\n // but the render method is using the new `assertSlots` method. That scenario can be solved by simply updating the slot element with the proper element type\n const { [SLOT_ELEMENT_TYPE_SYMBOL]: elementType } = slotElement;\n if (elementType !== typedState.components[slotName]) {\n slotElement[SLOT_ELEMENT_TYPE_SYMBOL] = typedState.components[slotName];\n // eslint-disable-next-line no-console\n console.warn(`${assertSlots.name} warning: 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`);\n }\n }\n }\n }\n}\n"],"names":["assertSlots","state","process","env","NODE_ENV","typedState","slotName","Object","keys","components","slotElement","undefined","isSlot","slot","always","elementType","console","warn","name","SLOT_ELEMENT_TYPE_SYMBOL"],"mappings":";;;;+BAsBoBA;;aAAAA;;;6DAtBG;2BACkB;wBAClB;uBACF;AAmBV,SAASA,YAAYC,KAAK,EAAE;IACnC;;;GAGD,GAAG,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,MAAMC,aAAaJ;QACnB,KAAK,MAAMK,YAAYC,OAAOC,IAAI,CAACH,WAAWI,UAAU,EAAE;YACtD,MAAMC,cAAcL,UAAU,CAACC,SAAS;YACxC,IAAII,gBAAgBC,WAAW;gBAC3B,QAAS;YACb,CAAC;YACD,8HAA8H;YAC9H,4JAA4J;YAC5J,6EAA6E;YAC7E,IAAI,CAACC,IAAAA,cAAM,EAACF,cAAc;gBACtBL,UAAU,CAACC,SAAS,GAAGO,WAAI,CAACC,MAAM,CAACJ,aAAa;oBAC5CK,aAAaV,WAAWI,UAAU,CAACH,SAAS;gBAChD;gBACA,sCAAsC;gBACtCU,QAAQC,IAAI,CAAC,CAAC,EAAEjB,YAAYkB,IAAI,CAAC,gBAAgB,EAAEZ,SAAS,iBAAiB,CAAC,GAAG,CAAC,2EAA2E,CAAC;YAClK,OAAO;gBACH,mFAAmF;gBACnF,4JAA4J;gBAC5J,MAAM,EAAE,CAACa,mCAAwB,CAAC,EAAEJ,YAAW,EAAG,GAAGL;gBACrD,IAAIK,gBAAgBV,WAAWI,UAAU,CAACH,SAAS,EAAE;oBACjDI,WAAW,CAACS,mCAAwB,CAAC,GAAGd,WAAWI,UAAU,CAACH,SAAS;oBACvE,sCAAsC;oBACtCU,QAAQC,IAAI,CAAC,CAAC,EAAEjB,YAAYkB,IAAI,CAAC,gBAAgB,EAAEZ,SAAS,4CAA4C,EAAEA,SAAS,EAAE,EAAES,YAAY,KAAK,EAAEV,WAAWI,UAAU,CAACH,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,uGAAuG,CAAC;gBAC/R,CAAC;YACL,CAAC;QACL;IACJ,CAAC;AACL"}
@@ -48,5 +48,14 @@ function resolveShorthand(value) {
48
48
  children: value
49
49
  };
50
50
  }
51
+ if (value && typeof value !== 'object' && process.env.NODE_ENV !== 'production') {
52
+ // TODO: would be nice to have a link to slot documentation in this error message
53
+ // eslint-disable-next-line no-console
54
+ console.error([
55
+ `[slot.resolveShorthand]: A slot got invalid value "${value}" (${typeof value}).`,
56
+ 'A valid value is a slot shorthand or slot properties object.',
57
+ 'Slot shorthands can be strings, numbers, arrays or JSX elements'
58
+ ].join('\n'));
59
+ }
51
60
  return value;
52
61
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["slot.js"],"sourcesContent":["import * as React from 'react';\nimport { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\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 */ export function always(value, options) {\n const { defaultProps , elementType } = options;\n const props = resolveShorthand(value);\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 */ const propsWithMetadata = {\n ...defaultProps,\n ...props,\n [SLOT_ELEMENT_TYPE_SYMBOL]: elementType\n };\n if (props && typeof props.children === 'function') {\n propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children;\n propsWithMetadata.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;\n }\n return propsWithMetadata;\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 */ export function optional(value, options) {\n if (value === null || value === undefined && !options.renderByDefault) {\n return undefined;\n }\n return always(value, options);\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 */ export function resolveShorthand(value) {\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || // eslint-disable-next-line @typescript-eslint/no-explicit-any\n React.isValidElement(value)) {\n return {\n children: value\n };\n }\n return value;\n}\n"],"names":["always","optional","resolveShorthand","value","options","defaultProps","elementType","props","propsWithMetadata","SLOT_ELEMENT_TYPE_SYMBOL","children","SLOT_RENDER_FUNCTION_SYMBOL","undefined","renderByDefault","Array","isArray","React","isValidElement"],"mappings":";;;;;;;;;;;IASoBA,MAAM,MAANA;IA+BAC,QAAQ,MAARA;IAUAC,gBAAgB,MAAhBA;;;6DAlDG;2BAC+C;AAQ3D,SAASF,OAAOG,KAAK,EAAEC,OAAO,EAAE;IACvC,MAAM,EAAEC,aAAY,EAAGC,YAAW,EAAG,GAAGF;IACxC,MAAMG,QAAQL,iBAAiBC;IAC/B;;;;;GAKD,GAAG,MAAMK,oBAAoB;QACxB,GAAGH,YAAY;QACf,GAAGE,KAAK;QACR,CAACE,mCAAwB,CAAC,EAAEH;IAChC;IACA,IAAIC,SAAS,OAAOA,MAAMG,QAAQ,KAAK,YAAY;QAC/CF,iBAAiB,CAACG,sCAA2B,CAAC,GAAGJ,MAAMG,QAAQ;QAC/DF,kBAAkBE,QAAQ,GAAGL,iBAAiB,IAAI,IAAIA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaK,QAAQ;IAClH,CAAC;IACD,OAAOF;AACX;AAaW,SAASP,SAASE,KAAK,EAAEC,OAAO,EAAE;IACzC,IAAID,UAAU,IAAI,IAAIA,UAAUS,aAAa,CAACR,QAAQS,eAAe,EAAE;QACnE,OAAOD;IACX,CAAC;IACD,OAAOZ,OAAOG,OAAOC;AACzB;AAKW,SAASF,iBAAiBC,KAAK,EAAE;IACxC,IAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,YAAYW,MAAMC,OAAO,CAACZ,UAAU,8DAA8D;kBACpJa,OAAMC,cAAc,CAACd,QAAQ;QACzB,OAAO;YACHO,UAAUP;QACd;IACJ,CAAC;IACD,OAAOA;AACX"}
1
+ {"version":3,"sources":["slot.js"],"sourcesContent":["import * as React from 'react';\nimport { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\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 */ export function always(value, options) {\n const { defaultProps , elementType } = options;\n const props = resolveShorthand(value);\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 */ const propsWithMetadata = {\n ...defaultProps,\n ...props,\n [SLOT_ELEMENT_TYPE_SYMBOL]: elementType\n };\n if (props && typeof props.children === 'function') {\n propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children;\n propsWithMetadata.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;\n }\n return propsWithMetadata;\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 */ export function optional(value, options) {\n if (value === null || value === undefined && !options.renderByDefault) {\n return undefined;\n }\n return always(value, options);\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 */ export function resolveShorthand(value) {\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || // eslint-disable-next-line @typescript-eslint/no-explicit-any\n React.isValidElement(value)) {\n return {\n children: value\n };\n }\n if (value && typeof value !== 'object' && process.env.NODE_ENV !== 'production') {\n // TODO: would be nice to have a link to slot documentation in this error message\n // eslint-disable-next-line no-console\n console.error([\n `[slot.resolveShorthand]: A slot got invalid value \"${value}\" (${typeof value}).`,\n 'A valid value is a slot shorthand or slot properties object.',\n 'Slot shorthands can be strings, numbers, arrays or JSX elements'\n ].join('\\n'));\n }\n return value;\n}\n"],"names":["always","optional","resolveShorthand","value","options","defaultProps","elementType","props","propsWithMetadata","SLOT_ELEMENT_TYPE_SYMBOL","children","SLOT_RENDER_FUNCTION_SYMBOL","undefined","renderByDefault","Array","isArray","React","isValidElement","process","env","NODE_ENV","console","error","join"],"mappings":";;;;;;;;;;;IASoBA,MAAM,MAANA;IA+BAC,QAAQ,MAARA;IAUAC,gBAAgB,MAAhBA;;;6DAlDG;2BAC+C;AAQ3D,SAASF,OAAOG,KAAK,EAAEC,OAAO,EAAE;IACvC,MAAM,EAAEC,aAAY,EAAGC,YAAW,EAAG,GAAGF;IACxC,MAAMG,QAAQL,iBAAiBC;IAC/B;;;;;GAKD,GAAG,MAAMK,oBAAoB;QACxB,GAAGH,YAAY;QACf,GAAGE,KAAK;QACR,CAACE,mCAAwB,CAAC,EAAEH;IAChC;IACA,IAAIC,SAAS,OAAOA,MAAMG,QAAQ,KAAK,YAAY;QAC/CF,iBAAiB,CAACG,sCAA2B,CAAC,GAAGJ,MAAMG,QAAQ;QAC/DF,kBAAkBE,QAAQ,GAAGL,iBAAiB,IAAI,IAAIA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaK,QAAQ;IAClH,CAAC;IACD,OAAOF;AACX;AAaW,SAASP,SAASE,KAAK,EAAEC,OAAO,EAAE;IACzC,IAAID,UAAU,IAAI,IAAIA,UAAUS,aAAa,CAACR,QAAQS,eAAe,EAAE;QACnE,OAAOD;IACX,CAAC;IACD,OAAOZ,OAAOG,OAAOC;AACzB;AAKW,SAASF,iBAAiBC,KAAK,EAAE;IACxC,IAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,YAAYW,MAAMC,OAAO,CAACZ,UAAU,8DAA8D;kBACpJa,OAAMC,cAAc,CAACd,QAAQ;QACzB,OAAO;YACHO,UAAUP;QACd;IACJ,CAAC;IACD,IAAIA,SAAS,OAAOA,UAAU,YAAYe,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAC7E,iFAAiF;QACjF,sCAAsC;QACtCC,QAAQC,KAAK,CAAC;YACV,CAAC,mDAAmD,EAAEnB,MAAM,GAAG,EAAE,OAAOA,MAAM,EAAE,CAAC;YACjF;YACA;SACH,CAACoB,IAAI,CAAC;IACX,CAAC;IACD,OAAOpB;AACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-utilities",
3
- "version": "9.11.0",
3
+ "version": "9.11.2",
4
4
  "description": "A set of general React-specific utilities.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",