@fluentui/react-utilities 0.0.0-nightly-20230501-0418.1 → 0.0.0-nightly-20230503-0419.1

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 (86) hide show
  1. package/CHANGELOG.json +5 -5
  2. package/CHANGELOG.md +5 -5
  3. package/dist/index.d.ts +710 -0
  4. package/lib/compose/constants.js +5 -0
  5. package/lib/compose/constants.js.map +1 -0
  6. package/lib/compose/getSlots.js +58 -0
  7. package/lib/compose/getSlots.js.map +1 -0
  8. package/lib/compose/getSlotsNext.js +34 -0
  9. package/lib/compose/getSlotsNext.js.map +1 -0
  10. package/lib/compose/index.js +7 -0
  11. package/lib/compose/index.js.map +1 -0
  12. package/lib/compose/isResolvedShorthand.js +35 -0
  13. package/lib/compose/isResolvedShorthand.js.map +1 -0
  14. package/lib/compose/resolveShorthand.js +34 -0
  15. package/lib/compose/resolveShorthand.js.map +1 -0
  16. package/lib/compose/types.js +2 -0
  17. package/lib/compose/types.js.map +1 -0
  18. package/lib/events/index.js +2 -0
  19. package/lib/events/index.js.map +1 -0
  20. package/lib/events/mouseTouchHelpers.js +39 -0
  21. package/lib/events/mouseTouchHelpers.js.map +1 -0
  22. package/lib/hooks/index.js +13 -0
  23. package/lib/hooks/index.js.map +1 -0
  24. package/lib/hooks/useControllableState.js +49 -0
  25. package/lib/hooks/useControllableState.js.map +1 -0
  26. package/lib/hooks/useEventCallback.js +28 -0
  27. package/lib/hooks/useEventCallback.js.map +1 -0
  28. package/lib/hooks/useFirstMount.js +21 -0
  29. package/lib/hooks/useFirstMount.js.map +1 -0
  30. package/lib/hooks/useForceUpdate.js +9 -0
  31. package/lib/hooks/useForceUpdate.js.map +1 -0
  32. package/lib/hooks/useId.js +48 -0
  33. package/lib/hooks/useId.js.map +1 -0
  34. package/lib/hooks/useIsomorphicLayoutEffect.js +13 -0
  35. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  36. package/lib/hooks/useMergedRefs.js +25 -0
  37. package/lib/hooks/useMergedRefs.js.map +1 -0
  38. package/lib/hooks/useOnClickOutside.js +135 -0
  39. package/lib/hooks/useOnClickOutside.js.map +1 -0
  40. package/lib/hooks/useOnScrollOutside.js +36 -0
  41. package/lib/hooks/useOnScrollOutside.js.map +1 -0
  42. package/lib/hooks/usePrevious.js +12 -0
  43. package/lib/hooks/usePrevious.js.map +1 -0
  44. package/lib/hooks/useScrollbarWidth.js +30 -0
  45. package/lib/hooks/useScrollbarWidth.js.map +1 -0
  46. package/lib/hooks/useTimeout.js +28 -0
  47. package/lib/hooks/useTimeout.js.map +1 -0
  48. package/lib/index.js +7 -0
  49. package/lib/index.js.map +1 -0
  50. package/lib/ssr/SSRContext.js +60 -0
  51. package/lib/ssr/SSRContext.js.map +1 -0
  52. package/lib/ssr/canUseDOM.js +8 -0
  53. package/lib/ssr/canUseDOM.js.map +1 -0
  54. package/lib/ssr/index.js +3 -0
  55. package/lib/ssr/index.js.map +1 -0
  56. package/lib/trigger/applyTriggerPropsToChildren.js +33 -0
  57. package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -0
  58. package/lib/trigger/getTriggerChild.js +34 -0
  59. package/lib/trigger/getTriggerChild.js.map +1 -0
  60. package/lib/trigger/index.js +5 -0
  61. package/lib/trigger/index.js.map +1 -0
  62. package/lib/trigger/isFluentTrigger.js +10 -0
  63. package/lib/trigger/isFluentTrigger.js.map +1 -0
  64. package/lib/trigger/types.js +2 -0
  65. package/lib/trigger/types.js.map +1 -0
  66. package/lib/utils/clamp.js +9 -0
  67. package/lib/utils/clamp.js.map +1 -0
  68. package/lib/utils/getNativeElementProps.js +61 -0
  69. package/lib/utils/getNativeElementProps.js.map +1 -0
  70. package/lib/utils/getRTLSafeKey.js +19 -0
  71. package/lib/utils/getRTLSafeKey.js.map +1 -0
  72. package/lib/utils/getReactCallbackName.js +24 -0
  73. package/lib/utils/getReactCallbackName.js.map +1 -0
  74. package/lib/utils/index.js +9 -0
  75. package/lib/utils/index.js.map +1 -0
  76. package/lib/utils/isHTMLElement.js +20 -0
  77. package/lib/utils/isHTMLElement.js.map +1 -0
  78. package/lib/utils/isInteractiveHTMLElement.js +22 -0
  79. package/lib/utils/isInteractiveHTMLElement.js.map +1 -0
  80. package/lib/utils/mergeCallbacks.js +29 -0
  81. package/lib/utils/mergeCallbacks.js.map +1 -0
  82. package/lib/utils/omit.js +24 -0
  83. package/lib/utils/omit.js.map +1 -0
  84. package/lib/utils/properties.js +200 -0
  85. package/lib/utils/properties.js.map +1 -0
  86. package/package.json +2 -2
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @internal
3
+ * Internal reference for the render function
4
+ */export const SLOT_RENDER_FUNCTION_SYMBOL = /*#__PURE__*/Symbol('fui.slotRenderFunction');
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SLOT_RENDER_FUNCTION_SYMBOL","Symbol"],"sources":["../../src/compose/constants.ts"],"sourcesContent":["/**\n * @internal\n * Internal reference for the render function\n */\nexport const SLOT_RENDER_FUNCTION_SYMBOL = Symbol('fui.slotRenderFunction');\n"],"mappings":"AAAA;;;GAIA,OAAO,MAAMA,2BAAA,gBAA8BC,MAAA,CAAO"}
@@ -0,0 +1,58 @@
1
+ import * as React from 'react';
2
+ import { omit } from '../utils/omit';
3
+ import { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
4
+ /**
5
+ * Given the state and an array of slot names, will break out `slots` and `slotProps`
6
+ * collections.
7
+ *
8
+ * The root is derived from a mix of `components` props and `as` prop.
9
+ *
10
+ * Slots will render as null if they are rendered as primitives with undefined children.
11
+ *
12
+ * The slotProps will always omit the `as` prop within them, and for slots that are string
13
+ * primitives, the props will be filtered according to the slot type by the type system.
14
+ * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
15
+ * anchor props. Note that this is only enforced at build time by Typescript -- there is no
16
+ * runtime code filtering props in this function.
17
+ *
18
+ * @param state - State including slot definitions
19
+ * @returns An object containing the `slots` map and `slotProps` map.
20
+ */
21
+ export function getSlots(state) {
22
+ const slots = {};
23
+ const slotProps = {};
24
+ const slotNames = Object.keys(state.components);
25
+ for (const slotName of slotNames) {
26
+ const [slot, props] = getSlot(state, slotName);
27
+ slots[slotName] = slot;
28
+ slotProps[slotName] = props;
29
+ }
30
+ return {
31
+ slots,
32
+ slotProps: slotProps
33
+ };
34
+ }
35
+ function getSlot(state, slotName) {
36
+ var _state_components, _state_components1;
37
+ const props = state[slotName];
38
+ if (props === undefined) {
39
+ return [null, undefined];
40
+ }
41
+ const {
42
+ children,
43
+ as: asProp,
44
+ [SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction,
45
+ ...rest
46
+ } = props;
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];
48
+ if (renderFunction || typeof children === 'function') {
49
+ const render = renderFunction || children;
50
+ return [React.Fragment, {
51
+ children: render(slot, rest)
52
+ }];
53
+ }
54
+ const shouldOmitAsProp = typeof slot === 'string' && asProp;
55
+ const slotProps = shouldOmitAsProp ? omit(props, ['as']) : props;
56
+ return [slot, slotProps];
57
+ }
58
+ //# sourceMappingURL=getSlots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","omit","SLOT_RENDER_FUNCTION_SYMBOL","getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","_state_components","_state_components1","undefined","children","as","asProp","renderFunction","rest","render","Fragment","shouldOmitAsProp"],"sources":["../../src/compose/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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAEvB,SAASC,IAAI,QAAQ;AACrB,SAASC,2BAA2B,QAAQ;AA8B5C;;;;;;;;;;;;;;;;;AAiBA,OAAO,SAASC,SACdC,KAAwB,EAIxB;EACA,MAAMC,KAAA,GAAQ,CAAC;EACf,MAAMC,SAAA,GAAY,CAAC;EAEnB,MAAMC,SAAA,GAAyBC,MAAA,CAAOC,IAAI,CAACL,KAAA,CAAMM,UAAU;EAC3D,KAAK,MAAMC,QAAA,IAAYJ,SAAA,EAAW;IAChC,MAAM,CAACK,IAAA,EAAMC,KAAA,CAAM,GAAGC,OAAA,CAAQV,KAAA,EAAOO,QAAA;IACrCN,KAAK,CAACM,QAAA,CAAS,GAAGC,IAAA;IAClBN,SAAS,CAACK,QAAA,CAAS,GAAGE,KAAA;EACxB;EACA,OAAO;IAAER,KAAA;IAAOC,SAAA,EAAWA;EAA2C;AACxE;AAEA,SAASQ,QACPV,KAAwB,EACxBO,QAAW,EACsC;MAe/CI,iBAAA,EACcC,kBAAA;EAfhB,MAAMH,KAAA,GAAQT,KAAK,CAACO,QAAA,CAAS;EAE7B,IAAIE,KAAA,KAAUI,SAAA,EAAW;IACvB,OAAO,CAAC,IAAI,EAAEA,SAAA,CAAkB;EAClC;EAEA,MAAM;IACJC,QAAA;IACAC,EAAA,EAAIC,MAAA;IACJ,CAAClB,2BAAA,GAA8BmB,cAAA;IAC/B,GAAGC;EAAA,CACJ,GAAGT,KAAA;EAEJ,MAAMD,IAAA,GACJ,EAAAG,iBAAA,GAAAX,KAAA,CAAMM,UAAU,cAAhBK,iBAAA,uBAAAA,iBAAkB,CAACJ,QAAA,CAAS,MAAKM,SAAA,IAAa,OAAOb,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS,KAAK,WAChFS,MAAA,KAAU,CAAAJ,kBAAA,GAAAZ,KAAA,CAAMM,UAAU,cAAhBM,kBAAA,uBAAAA,kBAAkB,CAACL,QAAA,CAAS,CAAD,IAAK,QAC1CP,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS;EAGhC,IAAIU,cAAA,IAAkB,OAAOH,QAAA,KAAa,YAAY;IACpD,MAAMK,MAAA,GAASF,cAAA,IAAmBH,QAAA;IAClC,OAAO,CACLlB,KAAA,CAAMwB,QAAQ,EACd;MACEN,QAAA,EAAUK,MAAA,CAAOX,IAAA,EAAMU,IAAA;IACzB,EACD;EACH;EAEA,MAAMG,gBAAA,GAAmB,OAAOb,IAAA,KAAS,YAAYQ,MAAA;EACrD,MAAMd,SAAA,GAAamB,gBAAA,GAAmBxB,IAAA,CAAKY,KAAA,EAAO,CAAC,KAAK,IAAKA,KAA0B;EACvF,OAAO,CAACD,IAAA,EAAMN,SAAA,CAAU;AAC1B"}
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
4
+ */
5
+ export function getSlotsNext(state) {
6
+ const slots = {};
7
+ const slotProps = {};
8
+ const slotNames = Object.keys(state.components);
9
+ for (const slotName of slotNames) {
10
+ const [slot, props] = getSlotNext(state, slotName);
11
+ slots[slotName] = slot;
12
+ slotProps[slotName] = props;
13
+ }
14
+ return {
15
+ slots,
16
+ slotProps: slotProps
17
+ };
18
+ }
19
+ function getSlotNext(state, slotName) {
20
+ var _state_components, _state_components1;
21
+ const props = state[slotName];
22
+ if (props === undefined) {
23
+ return [null, undefined];
24
+ }
25
+ const {
26
+ as: asProp,
27
+ ...propsWithoutAs
28
+ } = props;
29
+ 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];
30
+ const shouldOmitAsProp = typeof slot === 'string' && asProp;
31
+ const slotProps = shouldOmitAsProp ? propsWithoutAs : props;
32
+ return [slot, slotProps];
33
+ }
34
+ //# sourceMappingURL=getSlotsNext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","_state_components","_state_components1","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"sources":["../../src/compose/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 const { as: asProp, ...propsWithoutAs } = 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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAIvB;;;AAGA,OAAO,SAASC,aACdC,KAAwB,EAIxB;EACA,MAAMC,KAAA,GAAQ,CAAC;EACf,MAAMC,SAAA,GAAY,CAAC;EAEnB,MAAMC,SAAA,GAAyBC,MAAA,CAAOC,IAAI,CAACL,KAAA,CAAMM,UAAU;EAC3D,KAAK,MAAMC,QAAA,IAAYJ,SAAA,EAAW;IAChC,MAAM,CAACK,IAAA,EAAMC,KAAA,CAAM,GAAGC,WAAA,CAAYV,KAAA,EAAOO,QAAA;IACzCN,KAAK,CAACM,QAAA,CAAS,GAAGC,IAAA;IAClBN,SAAS,CAACK,QAAA,CAAS,GAAGE,KAAA;EACxB;EACA,OAAO;IAAER,KAAA;IAAOC,SAAA,EAAWA;EAA2C;AACxE;AAEA,SAASQ,YACPV,KAAwB,EACxBO,QAAW,EACsC;MAS/CI,iBAAA,EACcC,kBAAA;EAThB,MAAMH,KAAA,GAAQT,KAAK,CAACO,QAAA,CAAS;EAE7B,IAAIE,KAAA,KAAUI,SAAA,EAAW;IACvB,OAAO,CAAC,IAAI,EAAEA,SAAA,CAAkB;EAClC;EACA,MAAM;IAAEC,EAAA,EAAIC,MAAA;IAAQ,GAAGC;EAAA,CAAgB,GAAGP,KAAA;EAE1C,MAAMD,IAAA,GACJ,EAAAG,iBAAA,GAAAX,KAAA,CAAMM,UAAU,cAAhBK,iBAAA,uBAAAA,iBAAkB,CAACJ,QAAA,CAAS,MAAKM,SAAA,IAAa,OAAOb,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS,KAAK,WAChFQ,MAAA,KAAU,CAAAH,kBAAA,GAAAZ,KAAA,CAAMM,UAAU,cAAhBM,kBAAA,uBAAAA,kBAAkB,CAACL,QAAA,CAAS,CAAD,IAAK,QAC1CP,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS;EAGhC,MAAMU,gBAAA,GAAmB,OAAOT,IAAA,KAAS,YAAYO,MAAA;EACrD,MAAMb,SAAA,GAA8Be,gBAAA,GAAmBD,cAAA,GAAiBP,KAAK;EAE7E,OAAO,CAACD,IAAA,EAAMN,SAAA,CAAkB;AAClC"}
@@ -0,0 +1,7 @@
1
+ export * from './getSlots';
2
+ export * from './resolveShorthand';
3
+ export * from './types';
4
+ export * from './isResolvedShorthand';
5
+ export * from './constants';
6
+ export * from './getSlotsNext';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/compose/index.ts"],"sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\nexport * from './constants';\nexport * from './getSlotsNext';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
@@ -0,0 +1,35 @@
1
+ import { isValidElement } from 'react';
2
+ /**
3
+ * Guard method that validates if a shorthand is a slot
4
+ * can be used to extends properties provided by a slot
5
+ *
6
+ * @example
7
+ * ```
8
+ * const backdropSlot = resolveShorthand(backdrop, {
9
+ * defaultProps: {
10
+ * onClick: useEventCallback(event => {
11
+ * if (isResolvedShorthand(backdrop)) {
12
+ * backdrop.onClick?.(event)
13
+ * }
14
+ * // do something after passing click down the line
15
+ * }),
16
+ * },
17
+ * })
18
+ * ```
19
+ * @example
20
+ * ```
21
+ * const handleBackDropClick = (event) => {
22
+ * // do your thing
23
+ * }
24
+ * const backdropSlot = resolveShorthand(backdrop, {
25
+ * defaultProps: {
26
+ * onClick: useEventCallback(
27
+ * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)
28
+ * )
29
+ * })
30
+ * ```
31
+ */
32
+ export function isResolvedShorthand(shorthand) {
33
+ return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && ! /*#__PURE__*/isValidElement(shorthand);
34
+ }
35
+ //# sourceMappingURL=isResolvedShorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isValidElement","isResolvedShorthand","shorthand","Array","isArray"],"sources":["../../src/compose/isResolvedShorthand.ts"],"sourcesContent":["import { isValidElement } from 'react';\nimport type { ExtractSlotProps, Slot, UnknownSlotProps } from './types';\n\n/**\n * Guard method that validates if a shorthand is a slot\n * can be used to extends properties provided by a slot\n *\n * @example\n * ```\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(event => {\n * if (isResolvedShorthand(backdrop)) {\n * backdrop.onClick?.(event)\n * }\n * // do something after passing click down the line\n * }),\n * },\n * })\n * ```\n * @example\n * ```\n * const handleBackDropClick = (event) => {\n * // do your thing\n * }\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(\n * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)\n * )\n * })\n * ```\n */\nexport function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(\n shorthand?: Shorthand,\n): shorthand is ExtractSlotProps<Shorthand> {\n return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !isValidElement(shorthand);\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ;AAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,OAAO,SAASC,oBACdC,SAAqB,EACqB;EAC1C,OAAOA,SAAA,KAAc,IAAI,IAAI,OAAOA,SAAA,KAAc,YAAY,CAACC,KAAA,CAAMC,OAAO,CAACF,SAAA,KAAc,eAACF,cAAA,CAAeE,SAAA;AAC7G"}
@@ -0,0 +1,34 @@
1
+ import { isValidElement } from 'react';
2
+ import { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
3
+ /**
4
+ * Resolves shorthands into slot props, to ensure normalization of the signature
5
+ * being passed down to getSlots method
6
+ * @param value - the base shorthand props
7
+ * @param options - options to resolve shorthand props
8
+ */
9
+ export const resolveShorthand = (value, options) => {
10
+ const {
11
+ required = false,
12
+ defaultProps
13
+ } = options || {};
14
+ if (value === null || value === undefined && !required) {
15
+ return undefined;
16
+ }
17
+ let resolvedShorthand = {};
18
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
+ if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || /*#__PURE__*/isValidElement(value)) {
20
+ resolvedShorthand.children = value;
21
+ } else if (typeof value === 'object') {
22
+ resolvedShorthand = value;
23
+ }
24
+ resolvedShorthand = {
25
+ ...defaultProps,
26
+ ...resolvedShorthand
27
+ };
28
+ if (typeof resolvedShorthand.children === 'function') {
29
+ resolvedShorthand[SLOT_RENDER_FUNCTION_SYMBOL] = resolvedShorthand.children;
30
+ resolvedShorthand.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;
31
+ }
32
+ return resolvedShorthand;
33
+ };
34
+ //# sourceMappingURL=resolveShorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isValidElement","SLOT_RENDER_FUNCTION_SYMBOL","resolveShorthand","value","options","required","defaultProps","undefined","resolvedShorthand","Array","isArray","children"],"sources":["../../src/compose/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"],"mappings":"AAAA,SAASA,cAAc,QAAQ;AAE/B,SAASC,2BAA2B,QAAQ;AAa5C;;;;;;AAMA,OAAO,MAAMC,gBAAA,GAA6CA,CAACC,KAAA,EAAOC,OAAA,KAAY;EAC5E,MAAM;IAAEC,QAAA,GAAW,KAAK;IAAEC;EAAY,CAAE,GAAGF,OAAA,IAAW,CAAC;EACvD,IAAID,KAAA,KAAU,IAAI,IAAKA,KAAA,KAAUI,SAAA,IAAa,CAACF,QAAA,EAAW;IACxD,OAAOE,SAAA;EACT;EAEA,IAAIC,iBAAA,GAEA,CAAC;EAEL;EACA,IAAI,OAAOL,KAAA,KAAU,YAAY,OAAOA,KAAA,KAAU,YAAYM,KAAA,CAAMC,OAAO,CAACP,KAAA,kBAAUH,cAAA,CAAoBG,KAAA,GAAQ;IAChHK,iBAAA,CAAkBG,QAAQ,GAAGR,KAAA;EAC/B,OAAO,IAAI,OAAOA,KAAA,KAAU,UAAU;IACpCK,iBAAA,GAAoBL,KAAA;EACtB;EAEAK,iBAAA,GAAoB;IAClB,GAAGF,YAAY;IACf,GAAGE;EACL;EAEA,IAAI,OAAOA,iBAAA,CAAkBG,QAAQ,KAAK,YAAY;IACpDH,iBAAiB,CAACP,2BAAA,CAA4B,GAAGO,iBAAA,CAAkBG,QAAQ;IAC3EH,iBAAA,CAAkBG,QAAQ,GAAGL,YAAA,aAAAA,YAAA,uBAAAA,YAAA,CAAcK,QAAQ;EACrD;EAEA,OAAOH,iBAAA;AACT"}
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React"],"sources":["../../src/compose/types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type SlotRenderFunction<Props> = (\n Component: React.ElementType<Props>,\n props: Omit<Props, 'as'>,\n) => React.ReactNode;\n\n/**\n * Matches any component's Slots type (such as ButtonSlots).\n *\n * This should ONLY be used in type templates as in `extends SlotPropsRecord`;\n * it shouldn't be used as a component's Slots type.\n */\nexport type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;\n\n/**\n * The shorthand value of a slot allows specifying its child\n */\nexport type SlotShorthandValue = React.ReactChild | React.ReactNode[] | React.ReactPortal;\n\n/**\n * Matches any slot props type.\n *\n * This should ONLY be used in type templates as in `extends UnknownSlotProps`;\n * it shouldn't be used as the type of a slot.\n */\nexport type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {\n as?: keyof JSX.IntrinsicElements;\n};\n\n/**\n * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.\n */\ntype WithSlotShorthandValue<Props extends { children?: unknown }> =\n | Props\n | Extract<SlotShorthandValue, Props['children']>;\n\n/**\n * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`\n * to be a render function that takes those props.\n */\ntype WithSlotRenderFunction<Props> = Props & {\n children?: (Props extends { children?: unknown } ? Props['children'] : never) | SlotRenderFunction<Props>;\n};\n\n/**\n * HTML element types that are not allowed to have children.\n *\n * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element\n */\ntype EmptyIntrinsicElements =\n | 'area'\n | 'base'\n | 'br'\n | 'col'\n | 'embed'\n | 'hr'\n | 'img'\n | 'input'\n | 'link'\n | 'meta'\n | 'param'\n | 'source'\n | 'track'\n | 'wbr';\n\n/**\n * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:\n * * Removes legacy string ref.\n * * Disallows children for empty tags like 'img'.\n */\ntype IntrinsicElementProps<Type extends keyof JSX.IntrinsicElements> = Type extends EmptyIntrinsicElements\n ? PropsWithoutChildren<React.PropsWithRef<JSX.IntrinsicElements[Type]>>\n : React.PropsWithRef<JSX.IntrinsicElements[Type]>;\n\n/**\n * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,\n * or a component like `typeof Button`.\n *\n * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).\n *\n * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,\n * wrap with `NonNullable` (see examples below).\n *\n * @example\n * ```\n * // Intrinsic element examples:\n * Slot<'div'> // Slot is always div\n * Slot<'button', 'a'> // Defaults to button, but allows as=\"a\" with anchor-specific props\n * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as=\"div\" or as=\"pre\"\n * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)\n *\n * // Component examples:\n * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props\n * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)\n * ```\n */\nexport type Slot<\n Type extends keyof JSX.IntrinsicElements | React.ComponentType | React.VoidFunctionComponent | UnknownSlotProps,\n AlternateAs extends keyof JSX.IntrinsicElements = never,\n> = IsSingleton<Extract<Type, string>> extends true\n ?\n | WithSlotShorthandValue<\n Type extends keyof JSX.IntrinsicElements // Intrinsic elements like `div`\n ? { as?: Type } & WithSlotRenderFunction<IntrinsicElementProps<Type>>\n : Type extends React.ComponentType<infer Props> // Component types like `typeof Button`\n ? WithSlotRenderFunction<Props>\n : Type // Props types like `ButtonProps`\n >\n | {\n [As in AlternateAs]: { as: As } & WithSlotRenderFunction<IntrinsicElementProps<As>>;\n }[AlternateAs]\n | null\n : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';\n\n/**\n * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.\n *\n * ```\n * IsSingleton<'a'> // true\n * IsSingleton<'a' | 'b' | 'c'> // false\n * ```\n */\nexport type IsSingleton<T extends string> = { [K in T]: Exclude<T, K> extends never ? true : false }[T];\n\n/**\n * Helper type for inferring the type of the as prop from a Props type.\n *\n * For example:\n * ```\n * type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;\n * ```\n */\nexport type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = { as?: As };\n\n/**\n * Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)\n */\nexport type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;\n\n/**\n * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by\n * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.\n *\n * The conditional \"extends unknown\" (always true) exploits a quirk in the way TypeScript handles conditional\n * types, to prevent unions from being expanded.\n */\nexport type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;\n\n/**\n * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by\n * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.\n *\n * The conditional \"extends unknown\" (always true) exploits a quirk in the way TypeScript handles conditional\n * types, to prevent unions from being expanded.\n */\nexport type PropsWithoutChildren<P> = 'children' extends keyof P ? (P extends unknown ? Omit<P, 'children'> : P) : P;\n\n/**\n * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.\n */\nexport type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;\n\n/**\n * Defines the Props type for a component given its slots and the definition of which one is the primary slot,\n * defaulting to root if one is not provided.\n */\nexport type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> =\n // Include a prop for each slot (see note below about the Omit)\n Omit<Slots, Primary & 'root'> &\n // Include all of the props of the primary slot inline in the component's props\n PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;\n\n// Note: the `Omit<Slots, Primary & 'root'>` above is a little tricky. Here's what it's doing:\n// * If the Primary slot is 'root', then omit the `root` slot prop.\n// * Otherwise, don't omit any props: include *both* the Primary and `root` props.\n// We need both props to allow the user to specify native props for either slot because the `root` slot is\n// special and always gets className and style props, per RFC https://github.com/microsoft/fluentui/pull/18983\n\n/**\n * If type T includes `null`, remove it and add `undefined` instead.\n */\nexport type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;\n\n/**\n * Defines the State object of a component given its slots.\n */\nexport type ComponentState<Slots extends SlotPropsRecord> = {\n components: {\n [Key in keyof Slots]-?:\n | React.ComponentType<ExtractSlotProps<Slots[Key]>>\n | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);\n };\n} & {\n // Include a prop for each slot, with the shorthand resolved to a props object\n // The root slot can never be null, so also exclude null from it\n [Key in keyof Slots]: ReplaceNullWithUndefined<\n Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>\n >;\n};\n\n/**\n * This is part of a hack to infer the element type from a native element *props* type.\n * The only place the original element is found in a native props type (at least that's workable\n * for inference) is in the event handlers, so some of the helper types use this event handler\n * name to infer the original element type.\n *\n * Notes:\n * - Using an extremely obscure event handler reduces the likelihood that its signature will be\n * modified in any component's props.\n * - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be\n * less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.\n */\ntype ObscureEventName = 'onLostPointerCaptureCapture';\n\n/**\n * Return type for `React.forwardRef`, including inference of the proper typing for the ref.\n */\nexport type ForwardRefComponent<Props> = ObscureEventName extends keyof Props\n ? Required<Props>[ObscureEventName] extends React.PointerEventHandler<infer Element>\n ? React.ForwardRefExoticComponent<Props & React.RefAttributes<Element>>\n : never\n : never;\n// A definition like this would also work, but typescript is more likely to unnecessarily expand\n// the props type with this version (and it's likely much more expensive to evaluate)\n// export type ForwardRefComponent<Props> = Props extends React.DOMAttributes<infer Element>\n// ? React.ForwardRefExoticComponent<Props> & React.RefAttributes<Element>\n// : never;\n\n/**\n * Helper type to correctly define the slot class names object.\n */\nexport type SlotClassNames<Slots> = {\n [SlotName in keyof Slots]-?: string;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW"}
@@ -0,0 +1,2 @@
1
+ export * from './mouseTouchHelpers';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/events/index.ts"],"sourcesContent":["export * from './mouseTouchHelpers';\n"],"mappings":"AAAA,cAAc"}
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Returns true if event is a touch event. Useful when sharing logic between touch and mouse interactions.
4
+ */
5
+ export function isTouchEvent(event) {
6
+ return event.type.startsWith('touch');
7
+ }
8
+ /**
9
+ * Returns true if event is a mouse event. Useful when sharing logic between touch and mouse interactions.
10
+ */
11
+ export function isMouseEvent(event) {
12
+ return event.type.startsWith('mouse') || ['click', 'contextmenu', 'dblclick'].indexOf(event.type) > -1;
13
+ }
14
+ /**
15
+ * Returns an object with clientX, clientY for TouchOrMouseEvent.
16
+ * Returns zeros in case the event is not a mouse or a touch event.
17
+ */
18
+ export function getEventClientCoords(event) {
19
+ if (isMouseEvent(event)) {
20
+ return {
21
+ clientX: event.clientX,
22
+ clientY: event.clientY
23
+ };
24
+ } else if (isTouchEvent(event)) {
25
+ return {
26
+ clientX: event.touches[0].clientX,
27
+ clientY: event.touches[0].clientY
28
+ };
29
+ } else {
30
+ if (process.env.NODE_ENV !== 'production') {
31
+ throw new Error('@fluentui/react-utilities]: Unable to get clientX. Unknown event type.');
32
+ }
33
+ return {
34
+ clientX: 0,
35
+ clientY: 0
36
+ };
37
+ }
38
+ }
39
+ //# sourceMappingURL=mouseTouchHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","isTouchEvent","event","type","startsWith","isMouseEvent","indexOf","getEventClientCoords","clientX","clientY","touches","process","env","NODE_ENV","Error"],"sources":["../../src/events/mouseTouchHelpers.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type NativeTouchOrMouseEvent = MouseEvent | TouchEvent;\n\nexport type ReactTouchOrMouseEvent = React.MouseEvent | React.TouchEvent;\n\nexport type TouchOrMouseEvent = NativeTouchOrMouseEvent | ReactTouchOrMouseEvent;\n\n/**\n * Returns true if event is a touch event. Useful when sharing logic between touch and mouse interactions.\n */\nexport function isTouchEvent(event: TouchOrMouseEvent): event is TouchEvent | React.TouchEvent {\n return event.type.startsWith('touch');\n}\n\n/**\n * Returns true if event is a mouse event. Useful when sharing logic between touch and mouse interactions.\n */\nexport function isMouseEvent(event: TouchOrMouseEvent): event is MouseEvent | React.MouseEvent {\n return event.type.startsWith('mouse') || ['click', 'contextmenu', 'dblclick'].indexOf(event.type) > -1;\n}\n\n/**\n * Returns an object with clientX, clientY for TouchOrMouseEvent.\n * Returns zeros in case the event is not a mouse or a touch event.\n */\nexport function getEventClientCoords(event: TouchOrMouseEvent): { clientX: number; clientY: number } {\n if (isMouseEvent(event)) {\n return { clientX: event.clientX, clientY: event.clientY };\n } else if (isTouchEvent(event)) {\n return { clientX: event.touches[0].clientX, clientY: event.touches[0].clientY };\n } else {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('@fluentui/react-utilities]: Unable to get clientX. Unknown event type.');\n }\n return { clientX: 0, clientY: 0 };\n }\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAQvB;;;AAGA,OAAO,SAASC,aAAaC,KAAwB,EAA0C;EAC7F,OAAOA,KAAA,CAAMC,IAAI,CAACC,UAAU,CAAC;AAC/B;AAEA;;;AAGA,OAAO,SAASC,aAAaH,KAAwB,EAA0C;EAC7F,OAAOA,KAAA,CAAMC,IAAI,CAACC,UAAU,CAAC,YAAY,CAAC,SAAS,eAAe,WAAW,CAACE,OAAO,CAACJ,KAAA,CAAMC,IAAI,IAAI,CAAC;AACvG;AAEA;;;;AAIA,OAAO,SAASI,qBAAqBL,KAAwB,EAAwC;EACnG,IAAIG,YAAA,CAAaH,KAAA,GAAQ;IACvB,OAAO;MAAEM,OAAA,EAASN,KAAA,CAAMM,OAAO;MAAEC,OAAA,EAASP,KAAA,CAAMO;IAAQ;EAC1D,OAAO,IAAIR,YAAA,CAAaC,KAAA,GAAQ;IAC9B,OAAO;MAAEM,OAAA,EAASN,KAAA,CAAMQ,OAAO,CAAC,EAAE,CAACF,OAAO;MAAEC,OAAA,EAASP,KAAA,CAAMQ,OAAO,CAAC,EAAE,CAACD;IAAQ;EAChF,OAAO;IACL,IAAIE,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;MACzC,MAAM,IAAIC,KAAA,CAAM;IAClB;IACA,OAAO;MAAEN,OAAA,EAAS;MAAGC,OAAA,EAAS;IAAE;EAClC;AACF"}
@@ -0,0 +1,13 @@
1
+ export * from './useControllableState';
2
+ export * from './useEventCallback';
3
+ export * from './useFirstMount';
4
+ export * from './useForceUpdate';
5
+ export * from './useId';
6
+ export * from './useIsomorphicLayoutEffect';
7
+ export * from './useMergedRefs';
8
+ export * from './useOnClickOutside';
9
+ export * from './useOnScrollOutside';
10
+ export * from './usePrevious';
11
+ export * from './useScrollbarWidth';
12
+ export * from './useTimeout';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/hooks/index.ts"],"sourcesContent":["export * from './useControllableState';\nexport * from './useEventCallback';\nexport * from './useFirstMount';\nexport * from './useForceUpdate';\nexport * from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useScrollbarWidth';\nexport * from './useTimeout';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
@@ -0,0 +1,49 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @internal
4
+ *
5
+ * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
6
+ * such as a checked state or text input string.
7
+ *
8
+ * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
9
+ * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
10
+ *
11
+ * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
12
+ * of the current value and an updater (dispatch) function. The updater function is referentially
13
+ * stable (won't change during the component's lifecycle). It can take either a new value, or a
14
+ * function which is passed the previous value and returns the new value. Unlike `setState`, calls
15
+ * to the updater function will only be respected if the component is uncontrolled.
16
+ * @see https://reactjs.org/docs/uncontrolled-components.html
17
+ */
18
+ export const useControllableState = options => {
19
+ const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;
20
+ const [internalState, setInternalState] = React.useState(initialState);
21
+ return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];
22
+ };
23
+ function noop() {
24
+ /* noop */}
25
+ /**
26
+ * Helper hook to handle previous comparison of controlled/uncontrolled
27
+ * Prints an error when isControlled value switches between subsequent renders
28
+ * @returns - whether the value is controlled
29
+ */
30
+ const useIsControlled = controlledValue => {
31
+ const [isControlled] = React.useState(() => controlledValue !== undefined);
32
+ if (process.env.NODE_ENV !== 'production') {
33
+ // We don't want these warnings in production even though it is against native behaviour
34
+ // eslint-disable-next-line react-hooks/rules-of-hooks
35
+ React.useEffect(() => {
36
+ if (isControlled !== (controlledValue !== undefined)) {
37
+ const error = new Error();
38
+ const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
39
+ const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';
40
+ // eslint-disable-next-line no-console
41
+ console.error([
42
+ // Default react error
43
+ 'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));
44
+ }
45
+ }, [isControlled, controlledValue]);
46
+ }
47
+ return isControlled;
48
+ };
49
+ //# sourceMappingURL=useControllableState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useControllableState","options","initialState","defaultState","internalState","setInternalState","useState","useIsControlled","state","noop","controlledValue","isControlled","undefined","process","env","NODE_ENV","useEffect","error","Error","controlWarning","undefinedWarning","console","stack","join"],"sources":["../../src/hooks/useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\n/**\n * @internal\n *\n * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,\n * such as a checked state or text input string.\n *\n * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a\n * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.\n *\n * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array\n * of the current value and an updater (dispatch) function. The updater function is referentially\n * stable (won't change during the component's lifecycle). It can take either a new value, or a\n * function which is passed the previous value and returns the new value. Unlike `setState`, calls\n * to the updater function will only be respected if the component is uncontrolled.\n * @see https://reactjs.org/docs/uncontrolled-components.html\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;\n const [internalState, setInternalState] = React.useState<State>(initialState);\n return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];\n};\n\nfunction noop() {\n /* noop */\n}\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = <V>(controlledValue?: V): controlledValue is V => {\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n 'changing from ' + undefinedWarning + ' value, which should not happen.',\n 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',\n 'More info: https://reactjs.org/link/controlled-components',\n error.stack,\n ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAqBvB;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAMC,oBAAA,GACXC,OAAA,IACyD;EACzD,MAAMC,YAAA,GAAe,OAAOD,OAAA,CAAQE,YAAY,KAAK,cAAcF,OAAA,CAAQC,YAAY,GAAGD,OAAA,CAAQE,YAAY;EAC9G,MAAM,CAACC,aAAA,EAAeC,gBAAA,CAAiB,GAAGN,KAAA,CAAMO,QAAQ,CAAQJ,YAAA;EAChE,OAAOK,eAAA,CAAgBN,OAAA,CAAQO,KAAK,IAAI,CAACP,OAAA,CAAQO,KAAK,EAAEC,IAAA,CAAK,GAAG,CAACL,aAAA,EAAeC,gBAAA,CAAiB;AACnG;AAEA,SAASI,KAAA,EAAO;EACd;AAGF;;;;;AAKA,MAAMF,eAAA,GAAsBG,eAAA,IAA8C;EACxE,MAAM,CAACC,YAAA,CAAa,GAAGZ,KAAA,CAAMO,QAAQ,CAAU,MAAMI,eAAA,KAAoBE,SAAA;EAEzE,IAAIC,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACzC;IACA;IACAhB,KAAA,CAAMiB,SAAS,CAAC,MAAM;MACpB,IAAIL,YAAA,MAAkBD,eAAA,KAAoBE,SAAQ,GAAI;QACpD,MAAMK,KAAA,GAAQ,IAAIC,KAAA;QAElB,MAAMC,cAAA,GAAiBR,YAAA,GACnB,0CACA,wCAAwC;QAE5C,MAAMS,gBAAA,GAAmBT,YAAA,GAAe,4BAA4B,wBAAwB;QAE5F;QACAU,OAAA,CAAQJ,KAAK,CACX;QACE;QACA,6BAA6BE,cAAA,GAAiB,wCAC9C,mBAAmBC,gBAAA,GAAmB,oCACtC,sGACA,6DACAH,KAAA,CAAMK,KAAK,CACZ,CAACC,IAAI,CAAC;MAEX;IACF,GAAG,CAACZ,YAAA,EAAcD,eAAA,CAAgB;EACpC;EAEA,OAAOC,YAAA;AACT"}
@@ -0,0 +1,28 @@
1
+ import * as React from 'react';
2
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
3
+ /**
4
+ * @internal
5
+ * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
6
+ *
7
+ * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
8
+ * e.g. user props are dependencies which could change on every render
9
+ * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
10
+ *
11
+ * This should not be used often, but can be a useful re-render optimization since the callback is a ref and
12
+ * will not be invalidated between re-renders
13
+ *
14
+ * @param fn - The callback function that will be used
15
+ */
16
+ export const useEventCallback = fn => {
17
+ const callbackRef = React.useRef(() => {
18
+ throw new Error('Cannot call an event handler while rendering');
19
+ });
20
+ useIsomorphicLayoutEffect(() => {
21
+ callbackRef.current = fn;
22
+ }, [fn]);
23
+ return React.useCallback((...args) => {
24
+ const callback = callbackRef.current;
25
+ return callback(...args);
26
+ }, [callbackRef]);
27
+ };
28
+ //# sourceMappingURL=useEventCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useIsomorphicLayoutEffect","useEventCallback","fn","callbackRef","useRef","Error","current","useCallback","args","callback"],"sources":["../../src/hooks/useEventCallback.ts"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,yBAAyB,QAAQ;AAE1C;;;;;;;;;;;;;AAaA,OAAO,MAAMC,gBAAA,GAAoDC,EAAA,IAAkC;EACjG,MAAMC,WAAA,GAAcJ,KAAA,CAAMK,MAAM,CAAY,MAAM;IAChD,MAAM,IAAIC,KAAA,CAAM;EAClB;EAEAL,yBAAA,CAA0B,MAAM;IAC9BG,WAAA,CAAYG,OAAO,GAAGJ,EAAA;EACxB,GAAG,CAACA,EAAA,CAAG;EAEP,OAAOH,KAAA,CAAMQ,WAAW,CACtB,CAAC,GAAGC,IAAA,KAAe;IACjB,MAAMC,QAAA,GAAWN,WAAA,CAAYG,OAAO;IACpC,OAAOG,QAAA,IAAYD,IAAA;EACrB,GACA,CAACL,WAAA,CAAY;AAEjB"}
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @internal
4
+ * Checks if components was mounted the first time.
5
+ * Since concurrent mode will be released in the future this needs to be verified
6
+ * Currently (React 17) will always render the initial mount once
7
+ * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
8
+ * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
9
+ *
10
+ * @example
11
+ * const isFirstMount = useFirstMount();
12
+ */
13
+ export function useFirstMount() {
14
+ const isFirst = React.useRef(true);
15
+ if (isFirst.current) {
16
+ isFirst.current = false;
17
+ return true;
18
+ }
19
+ return isFirst.current;
20
+ }
21
+ //# sourceMappingURL=useFirstMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useFirstMount","isFirst","useRef","current"],"sources":["../../src/hooks/useFirstMount.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Checks if components was mounted the first time.\n * Since concurrent mode will be released in the future this needs to be verified\n * Currently (React 17) will always render the initial mount once\n * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx\n * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx\n *\n * @example\n * const isFirstMount = useFirstMount();\n */\nexport function useFirstMount(): boolean {\n const isFirst = React.useRef(true);\n\n if (isFirst.current) {\n isFirst.current = false;\n return true;\n }\n\n return isFirst.current;\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAEvB;;;;;;;;;;;AAWA,OAAO,SAASC,cAAA,EAAyB;EACvC,MAAMC,OAAA,GAAUF,KAAA,CAAMG,MAAM,CAAC,IAAI;EAEjC,IAAID,OAAA,CAAQE,OAAO,EAAE;IACnBF,OAAA,CAAQE,OAAO,GAAG,KAAK;IACvB,OAAO,IAAI;EACb;EAEA,OAAOF,OAAA,CAAQE,OAAO;AACxB"}
@@ -0,0 +1,9 @@
1
+ import { useReducer } from 'react';
2
+ /**
3
+ * @internal
4
+ * Forces a re-render, similar to `forceUpdate` in class components.
5
+ */
6
+ export function useForceUpdate() {
7
+ return useReducer(x => x + 1, 0)[1];
8
+ }
9
+ //# sourceMappingURL=useForceUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useReducer","useForceUpdate","x"],"sources":["../../src/hooks/useForceUpdate.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/**\n * @internal\n * Forces a re-render, similar to `forceUpdate` in class components.\n */\nexport function useForceUpdate() {\n return useReducer(x => x + 1, 0)[1];\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ;AAE3B;;;;AAIA,OAAO,SAASC,eAAA,EAAiB;EAC/B,OAAOD,UAAA,CAAWE,CAAA,IAAKA,CAAA,GAAI,GAAG,EAAE,CAAC,EAAE;AACrC"}
@@ -0,0 +1,48 @@
1
+ import * as React from 'react';
2
+ import { defaultSSRContextValue, useSSRContext } from '../ssr/index';
3
+ const IdPrefixContext = /*#__PURE__*/React.createContext(undefined);
4
+ /**
5
+ * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions
6
+ * between different bundles.
7
+ */
8
+ export const IdPrefixProvider = IdPrefixContext.Provider;
9
+ function useIdPrefix() {
10
+ return React.useContext(IdPrefixContext) || '';
11
+ }
12
+ /**
13
+ * Resets generated IDs, should be used only in tests.
14
+ */
15
+ export function resetIdsForTests() {
16
+ defaultSSRContextValue.current = 0;
17
+ }
18
+ /**
19
+ * Hook to generate a unique ID.
20
+ *
21
+ * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
22
+ * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
23
+ * without conditioning the hook call
24
+ * @returns The ID
25
+ */
26
+ export function useId(prefix = 'fui-', providedId) {
27
+ const contextValue = useSSRContext();
28
+ const idPrefix = useIdPrefix();
29
+ // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to
30
+ // prevent bundlers from complaining with older versions of React.
31
+ const _useId = React['use' + 'Id'];
32
+ if (_useId) {
33
+ const generatedId = _useId();
34
+ // eslint-disable-next-line react-hooks/rules-of-hooks
35
+ const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);
36
+ return providedId || `${idPrefix}${prefix}${escapedId}`;
37
+ }
38
+ // Hooks appear to be running conditionally, but they will always run in the same order since it's based on
39
+ // the version of React being used. This is safe to ignore.
40
+ // eslint-disable-next-line react-hooks/rules-of-hooks
41
+ return React.useMemo(() => {
42
+ if (providedId) {
43
+ return providedId;
44
+ }
45
+ return `${idPrefix}${prefix}${++contextValue.current}`;
46
+ }, [idPrefix, prefix, providedId, contextValue]);
47
+ }
48
+ //# sourceMappingURL=useId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","defaultSSRContextValue","useSSRContext","IdPrefixContext","createContext","undefined","IdPrefixProvider","Provider","useIdPrefix","useContext","resetIdsForTests","current","useId","prefix","providedId","contextValue","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"sources":["../../src/hooks/useId.ts"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\nconst IdPrefixContext = React.createContext<string | undefined>(undefined);\n\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */\nexport const IdPrefixProvider = IdPrefixContext.Provider;\n\nfunction useIdPrefix(): string {\n return React.useContext(IdPrefixContext) || '';\n}\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = (React as never)['use' + 'Id'] as (() => string) | undefined;\n\n if (_useId) {\n const generatedId = _useId();\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);\n\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [idPrefix, prefix, providedId, contextValue]);\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,sBAAsB,EAAEC,aAAa,QAAQ;AAEtD,MAAMC,eAAA,gBAAkBH,KAAA,CAAMI,aAAa,CAAqBC,SAAA;AAEhE;;;;AAIA,OAAO,MAAMC,gBAAA,GAAmBH,eAAA,CAAgBI,QAAQ;AAExD,SAASC,YAAA,EAAsB;EAC7B,OAAOR,KAAA,CAAMS,UAAU,CAACN,eAAA,KAAoB;AAC9C;AAEA;;;AAGA,OAAO,SAASO,iBAAA,EAAyB;EACvCT,sBAAA,CAAuBU,OAAO,GAAG;AACnC;AAEA;;;;;;;;AAQA,OAAO,SAASC,MAAMC,MAAA,GAAiB,MAAM,EAAEC,UAAmB,EAAU;EAC1E,MAAMC,YAAA,GAAeb,aAAA;EACrB,MAAMc,QAAA,GAAWR,WAAA;EAEjB;EACA;EACA,MAAMS,MAAA,GAASjB,KAAgB,CAAC,QAAQ,KAAK;EAE7C,IAAIiB,MAAA,EAAQ;IACV,MAAMC,WAAA,GAAcD,MAAA;IAEpB;IACA,MAAME,SAAA,GAAYnB,KAAA,CAAMoB,OAAO,CAAC,MAAMF,WAAA,CAAYG,OAAO,CAAC,MAAM,KAAK,CAACH,WAAA,CAAY;IAElF,OAAOJ,UAAA,IAAe,GAAEE,QAAS,GAAEH,MAAO,GAAEM,SAAU,EAAC;EACzD;EAEA;EACA;EACA;EACA,OAAOnB,KAAA,CAAMoB,OAAO,CAAC,MAAM;IACzB,IAAIN,UAAA,EAAY;MACd,OAAOA,UAAA;IACT;IAEA,OAAQ,GAAEE,QAAS,GAAEH,MAAO,GAAE,EAAEE,YAAA,CAAaJ,OAAQ,EAAC;EACxD,GAAG,CAACK,QAAA,EAAUH,MAAA,EAAQC,UAAA,EAAYC,YAAA,CAAa;AACjD"}
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { canUseDOM } from '../ssr/index';
3
+ /**
4
+ * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
5
+ * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
6
+ * ensure we don't get a render flash for certain operations, but we may also need affected components to render on
7
+ * the server.
8
+ *
9
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
10
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
11
+ */ // eslint-disable-next-line no-restricted-properties
12
+ export const useIsomorphicLayoutEffect = /*#__PURE__*/canUseDOM() ? React.useLayoutEffect : React.useEffect;
13
+ //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","canUseDOM","useIsomorphicLayoutEffect","useLayoutEffect","useEffect"],"sources":["../../src/hooks/useIsomorphicLayoutEffect.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '../ssr/index';\n\n/**\n * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally\n * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to\n * ensure we don't get a render flash for certain operations, but we may also need affected components to render on\n * the server.\n *\n * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\n * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js\n */\n// eslint-disable-next-line no-restricted-properties\nexport const useIsomorphicLayoutEffect: typeof React.useEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,SAAS,QAAQ;AAE1B;;;;;;;;GAAA,CASA;AACA,OAAO,MAAMC,yBAAA,GAAoD,aAAAD,SAAA,KAAcD,KAAA,CAAMG,eAAe,GAAGH,KAAA,CAAMI,SAAS"}
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
4
+ * updates all provided refs
5
+ * @param refs - Refs to collectively update with one ref value.
6
+ * @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
7
+ */
8
+ export function useMergedRefs(...refs) {
9
+ const mergedCallback = React.useCallback(value => {
10
+ // Update the "current" prop hanging on the function.
11
+ mergedCallback.current = value;
12
+ for (const ref of refs) {
13
+ if (typeof ref === 'function') {
14
+ ref(value);
15
+ } else if (ref) {
16
+ // work around the immutability of the React.Ref type
17
+ ref.current = value;
18
+ }
19
+ }
20
+ },
21
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive
22
+ [...refs]);
23
+ return mergedCallback;
24
+ }
25
+ //# sourceMappingURL=useMergedRefs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useMergedRefs","refs","mergedCallback","useCallback","value","current","ref"],"sources":["../../src/hooks/useMergedRefs.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n const mergedCallback: RefObjectFunction<T> = React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n (mergedCallback as unknown as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n (ref as unknown as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAQvB;;;;;;AAMA,OAAO,SAASC,cAAiB,GAAGC,IAAkC,EAAwB;EAC5F,MAAMC,cAAA,GAAuCH,KAAA,CAAMI,WAAW,CAC3DC,KAAA,IAAa;IACZ;IACCF,cAAA,CAAwDG,OAAO,GAAGD,KAAA;IAEnE,KAAK,MAAME,GAAA,IAAOL,IAAA,EAAM;MACtB,IAAI,OAAOK,GAAA,KAAQ,YAAY;QAC7BA,GAAA,CAAIF,KAAA;MACN,OAAO,IAAIE,GAAA,EAAK;QACd;QACCA,GAAA,CAA6CD,OAAO,GAAGD,KAAA;MAC1D;IACF;EACF;EACA;EACA,C,GAAIH,IAAA,CAAK;EAGX,OAAOC,cAAA;AACT"}