@fluentui/react-utilities 0.0.0-nightly-20220302-0405.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 (223) hide show
  1. package/CHANGELOG.json +1844 -0
  2. package/CHANGELOG.md +736 -0
  3. package/LICENSE +15 -0
  4. package/README.md +5 -0
  5. package/dist/react-utilities.d.ts +782 -0
  6. package/lib/compose/getSlots.d.ts +30 -0
  7. package/lib/compose/getSlots.js +63 -0
  8. package/lib/compose/getSlots.js.map +1 -0
  9. package/lib/compose/index.d.ts +3 -0
  10. package/lib/compose/index.js +4 -0
  11. package/lib/compose/index.js.map +1 -0
  12. package/lib/compose/resolveShorthand.d.ts +16 -0
  13. package/lib/compose/resolveShorthand.js +31 -0
  14. package/lib/compose/resolveShorthand.js.map +1 -0
  15. package/lib/compose/types.d.ts +155 -0
  16. package/lib/compose/types.js +6 -0
  17. package/lib/compose/types.js.map +1 -0
  18. package/lib/hooks/index.d.ts +16 -0
  19. package/lib/hooks/index.js +17 -0
  20. package/lib/hooks/index.js.map +1 -0
  21. package/lib/hooks/useBoolean.d.ts +17 -0
  22. package/lib/hooks/useBoolean.js +28 -0
  23. package/lib/hooks/useBoolean.js.map +1 -0
  24. package/lib/hooks/useConst.d.ts +12 -0
  25. package/lib/hooks/useConst.js +30 -0
  26. package/lib/hooks/useConst.js.map +1 -0
  27. package/lib/hooks/useControllableState.d.ts +31 -0
  28. package/lib/hooks/useControllableState.js +73 -0
  29. package/lib/hooks/useControllableState.js.map +1 -0
  30. package/lib/hooks/useEventCallback.d.ts +13 -0
  31. package/lib/hooks/useEventCallback.js +28 -0
  32. package/lib/hooks/useEventCallback.js.map +1 -0
  33. package/lib/hooks/useFirstMount.d.ts +11 -0
  34. package/lib/hooks/useFirstMount.js +23 -0
  35. package/lib/hooks/useFirstMount.js.map +1 -0
  36. package/lib/hooks/useForceUpdate.d.ts +4 -0
  37. package/lib/hooks/useForceUpdate.js +9 -0
  38. package/lib/hooks/useForceUpdate.js.map +1 -0
  39. package/lib/hooks/useId.d.ts +15 -0
  40. package/lib/hooks/useId.js +31 -0
  41. package/lib/hooks/useId.js.map +1 -0
  42. package/lib/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  43. package/lib/hooks/useIsomorphicLayoutEffect.js +15 -0
  44. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  45. package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
  46. package/lib/hooks/useMergedEventCallbacks.js +26 -0
  47. package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
  48. package/lib/hooks/useMergedRefs.d.ts +13 -0
  49. package/lib/hooks/useMergedRefs.js +26 -0
  50. package/lib/hooks/useMergedRefs.js.map +1 -0
  51. package/lib/hooks/useMount.d.ts +6 -0
  52. package/lib/hooks/useMount.js +17 -0
  53. package/lib/hooks/useMount.js.map +1 -0
  54. package/lib/hooks/useOnClickOutside.d.ts +29 -0
  55. package/lib/hooks/useOnClickOutside.js +136 -0
  56. package/lib/hooks/useOnClickOutside.js.map +1 -0
  57. package/lib/hooks/useOnScrollOutside.d.ts +5 -0
  58. package/lib/hooks/useOnScrollOutside.js +36 -0
  59. package/lib/hooks/useOnScrollOutside.js.map +1 -0
  60. package/lib/hooks/usePrevious.d.ts +1 -0
  61. package/lib/hooks/usePrevious.js +9 -0
  62. package/lib/hooks/usePrevious.js.map +1 -0
  63. package/lib/hooks/useTimeout.d.ts +8 -0
  64. package/lib/hooks/useTimeout.js +29 -0
  65. package/lib/hooks/useTimeout.js.map +1 -0
  66. package/lib/hooks/useUnmount.d.ts +6 -0
  67. package/lib/hooks/useUnmount.js +17 -0
  68. package/lib/hooks/useUnmount.js.map +1 -0
  69. package/lib/index.d.ts +4 -0
  70. package/lib/index.js +5 -0
  71. package/lib/index.js.map +1 -0
  72. package/lib/ssr/SSRContext.d.ts +33 -0
  73. package/lib/ssr/SSRContext.js +65 -0
  74. package/lib/ssr/SSRContext.js.map +1 -0
  75. package/lib/ssr/canUseDOM.d.ts +4 -0
  76. package/lib/ssr/canUseDOM.js +8 -0
  77. package/lib/ssr/canUseDOM.js.map +1 -0
  78. package/lib/ssr/index.d.ts +2 -0
  79. package/lib/ssr/index.js +3 -0
  80. package/lib/ssr/index.js.map +1 -0
  81. package/lib/tsdoc-metadata.json +11 -0
  82. package/lib/utils/applyTriggerPropsToChildren.d.ts +5 -0
  83. package/lib/utils/applyTriggerPropsToChildren.js +36 -0
  84. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -0
  85. package/lib/utils/clamp.d.ts +8 -0
  86. package/lib/utils/clamp.js +9 -0
  87. package/lib/utils/clamp.js.map +1 -0
  88. package/lib/utils/getNativeElementProps.d.ts +31 -0
  89. package/lib/utils/getNativeElementProps.js +61 -0
  90. package/lib/utils/getNativeElementProps.js.map +1 -0
  91. package/lib/utils/getRTLSafeKey.d.ts +4 -0
  92. package/lib/utils/getRTLSafeKey.js +21 -0
  93. package/lib/utils/getRTLSafeKey.js.map +1 -0
  94. package/lib/utils/getReactCallbackName.d.ts +25 -0
  95. package/lib/utils/getReactCallbackName.js +26 -0
  96. package/lib/utils/getReactCallbackName.js.map +1 -0
  97. package/lib/utils/getTriggerChild.d.ts +22 -0
  98. package/lib/utils/getTriggerChild.js +26 -0
  99. package/lib/utils/getTriggerChild.js.map +1 -0
  100. package/lib/utils/index.d.ts +9 -0
  101. package/lib/utils/index.js +10 -0
  102. package/lib/utils/index.js.map +1 -0
  103. package/lib/utils/isFluentTrigger.d.ts +22 -0
  104. package/lib/utils/isFluentTrigger.js +8 -0
  105. package/lib/utils/isFluentTrigger.js.map +1 -0
  106. package/lib/utils/omit.d.ts +14 -0
  107. package/lib/utils/omit.js +27 -0
  108. package/lib/utils/omit.js.map +1 -0
  109. package/lib/utils/properties.d.ts +154 -0
  110. package/lib/utils/properties.js +237 -0
  111. package/lib/utils/properties.js.map +1 -0
  112. package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  113. package/lib/utils/shouldPreventDefaultOnKeyDown.js +24 -0
  114. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  115. package/lib-commonjs/compose/getSlots.d.ts +30 -0
  116. package/lib-commonjs/compose/getSlots.js +74 -0
  117. package/lib-commonjs/compose/getSlots.js.map +1 -0
  118. package/lib-commonjs/compose/index.d.ts +3 -0
  119. package/lib-commonjs/compose/index.js +14 -0
  120. package/lib-commonjs/compose/index.js.map +1 -0
  121. package/lib-commonjs/compose/resolveShorthand.d.ts +16 -0
  122. package/lib-commonjs/compose/resolveShorthand.js +41 -0
  123. package/lib-commonjs/compose/resolveShorthand.js.map +1 -0
  124. package/lib-commonjs/compose/types.d.ts +155 -0
  125. package/lib-commonjs/compose/types.js +10 -0
  126. package/lib-commonjs/compose/types.js.map +1 -0
  127. package/lib-commonjs/hooks/index.d.ts +16 -0
  128. package/lib-commonjs/hooks/index.js +40 -0
  129. package/lib-commonjs/hooks/index.js.map +1 -0
  130. package/lib-commonjs/hooks/useBoolean.d.ts +17 -0
  131. package/lib-commonjs/hooks/useBoolean.js +39 -0
  132. package/lib-commonjs/hooks/useBoolean.js.map +1 -0
  133. package/lib-commonjs/hooks/useConst.d.ts +12 -0
  134. package/lib-commonjs/hooks/useConst.js +40 -0
  135. package/lib-commonjs/hooks/useConst.js.map +1 -0
  136. package/lib-commonjs/hooks/useControllableState.d.ts +31 -0
  137. package/lib-commonjs/hooks/useControllableState.js +83 -0
  138. package/lib-commonjs/hooks/useControllableState.js.map +1 -0
  139. package/lib-commonjs/hooks/useEventCallback.d.ts +13 -0
  140. package/lib-commonjs/hooks/useEventCallback.js +39 -0
  141. package/lib-commonjs/hooks/useEventCallback.js.map +1 -0
  142. package/lib-commonjs/hooks/useFirstMount.d.ts +11 -0
  143. package/lib-commonjs/hooks/useFirstMount.js +33 -0
  144. package/lib-commonjs/hooks/useFirstMount.js.map +1 -0
  145. package/lib-commonjs/hooks/useForceUpdate.d.ts +4 -0
  146. package/lib-commonjs/hooks/useForceUpdate.js +19 -0
  147. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -0
  148. package/lib-commonjs/hooks/useId.d.ts +15 -0
  149. package/lib-commonjs/hooks/useId.js +44 -0
  150. package/lib-commonjs/hooks/useId.js.map +1 -0
  151. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  152. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +24 -0
  153. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  154. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  155. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  156. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  157. package/lib-commonjs/hooks/useMergedRefs.d.ts +13 -0
  158. package/lib-commonjs/hooks/useMergedRefs.js +36 -0
  159. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -0
  160. package/lib-commonjs/hooks/useMount.d.ts +6 -0
  161. package/lib-commonjs/hooks/useMount.js +27 -0
  162. package/lib-commonjs/hooks/useMount.js.map +1 -0
  163. package/lib-commonjs/hooks/useOnClickOutside.d.ts +29 -0
  164. package/lib-commonjs/hooks/useOnClickOutside.js +147 -0
  165. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -0
  166. package/lib-commonjs/hooks/useOnScrollOutside.d.ts +5 -0
  167. package/lib-commonjs/hooks/useOnScrollOutside.js +47 -0
  168. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -0
  169. package/lib-commonjs/hooks/usePrevious.d.ts +1 -0
  170. package/lib-commonjs/hooks/usePrevious.js +19 -0
  171. package/lib-commonjs/hooks/usePrevious.js.map +1 -0
  172. package/lib-commonjs/hooks/useTimeout.d.ts +8 -0
  173. package/lib-commonjs/hooks/useTimeout.js +40 -0
  174. package/lib-commonjs/hooks/useTimeout.js.map +1 -0
  175. package/lib-commonjs/hooks/useUnmount.d.ts +6 -0
  176. package/lib-commonjs/hooks/useUnmount.js +27 -0
  177. package/lib-commonjs/hooks/useUnmount.js.map +1 -0
  178. package/lib-commonjs/index.d.ts +4 -0
  179. package/lib-commonjs/index.js +16 -0
  180. package/lib-commonjs/index.js.map +1 -0
  181. package/lib-commonjs/ssr/SSRContext.d.ts +33 -0
  182. package/lib-commonjs/ssr/SSRContext.js +80 -0
  183. package/lib-commonjs/ssr/SSRContext.js.map +1 -0
  184. package/lib-commonjs/ssr/canUseDOM.d.ts +4 -0
  185. package/lib-commonjs/ssr/canUseDOM.js +17 -0
  186. package/lib-commonjs/ssr/canUseDOM.js.map +1 -0
  187. package/lib-commonjs/ssr/index.d.ts +2 -0
  188. package/lib-commonjs/ssr/index.js +12 -0
  189. package/lib-commonjs/ssr/index.js.map +1 -0
  190. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +5 -0
  191. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +47 -0
  192. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -0
  193. package/lib-commonjs/utils/clamp.d.ts +8 -0
  194. package/lib-commonjs/utils/clamp.js +18 -0
  195. package/lib-commonjs/utils/clamp.js.map +1 -0
  196. package/lib-commonjs/utils/getNativeElementProps.d.ts +31 -0
  197. package/lib-commonjs/utils/getNativeElementProps.js +73 -0
  198. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -0
  199. package/lib-commonjs/utils/getRTLSafeKey.d.ts +4 -0
  200. package/lib-commonjs/utils/getRTLSafeKey.js +30 -0
  201. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -0
  202. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  203. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  204. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  205. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  206. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  207. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  208. package/lib-commonjs/utils/index.d.ts +9 -0
  209. package/lib-commonjs/utils/index.js +26 -0
  210. package/lib-commonjs/utils/index.js.map +1 -0
  211. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  212. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  213. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  214. package/lib-commonjs/utils/omit.d.ts +14 -0
  215. package/lib-commonjs/utils/omit.js +36 -0
  216. package/lib-commonjs/utils/omit.js.map +1 -0
  217. package/lib-commonjs/utils/properties.d.ts +154 -0
  218. package/lib-commonjs/utils/properties.js +246 -0
  219. package/lib-commonjs/utils/properties.js.map +1 -0
  220. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  221. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +34 -0
  222. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  223. package/package.json +50 -0
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import { useConst } from './useConst';
3
+ /**
4
+ * Helper to manage a browser timeout.
5
+ * Ensures that the timeout isn't set multiple times at once,
6
+ * and is cleaned up when the component is unloaded.
7
+ *
8
+ * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
9
+ */
10
+
11
+ export function useTimeout() {
12
+ const timeout = useConst(() => ({
13
+ id: undefined,
14
+ set: (fn, delay) => {
15
+ timeout.clear();
16
+ timeout.id = setTimeout(fn, delay);
17
+ },
18
+ clear: () => {
19
+ if (timeout.id !== undefined) {
20
+ clearTimeout(timeout.id);
21
+ timeout.id = undefined;
22
+ }
23
+ }
24
+ })); // Clean up the timeout when the component is unloaded
25
+
26
+ React.useEffect(() => timeout.clear, [timeout]);
27
+ return [timeout.set, timeout.clear];
28
+ }
29
+ //# sourceMappingURL=useTimeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useTimeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;AAEA;;;;;;AAMG;;AACH,OAAM,SAAU,UAAV,GAAoB;AACxB,QAAM,OAAO,GAAG,QAAQ,CAAC,OAAO;AAC9B,IAAA,EAAE,EAAE,SAD0B;AAE9B,IAAA,GAAG,EAAE,CAAC,EAAD,EAAiB,KAAjB,KAAkC;AACrC,MAAA,OAAO,CAAC,KAAR;AACA,MAAA,OAAO,CAAC,EAAR,GAAa,UAAU,CAAC,EAAD,EAAK,KAAL,CAAvB;AACD,KAL6B;AAM9B,IAAA,KAAK,EAAE,MAAK;AACV,UAAI,OAAO,CAAC,EAAR,KAAe,SAAnB,EAA8B;AAC5B,QAAA,YAAY,CAAC,OAAO,CAAC,EAAT,CAAZ;AACA,QAAA,OAAO,CAAC,EAAR,GAAa,SAAb;AACD;AACF;AAX6B,GAAP,CAAD,CAAxB,CADwB,CAexB;;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAM,OAAO,CAAC,KAA9B,EAAqC,CAAC,OAAD,CAArC;AAEA,SAAO,CAAC,OAAO,CAAC,GAAT,EAAc,OAAO,CAAC,KAAtB,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { useConst } from './useConst';\n\n/**\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once,\n * and is cleaned up when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n const timeout = useConst(() => ({\n id: undefined as ReturnType<typeof setTimeout> | undefined,\n set: (fn: () => void, delay: number) => {\n timeout.clear();\n timeout.id = setTimeout(fn, delay);\n },\n clear: () => {\n if (timeout.id !== undefined) {\n clearTimeout(timeout.id);\n timeout.id = undefined;\n }\n },\n }));\n\n // Clean up the timeout when the component is unloaded\n React.useEffect(() => timeout.clear, [timeout]);\n\n return [timeout.set, timeout.clear] as const;\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Hook which synchronously executes a callback when the component is about to unmount.
3
+ *
4
+ * @param callback - Function to call during unmount.
5
+ */
6
+ export declare const useUnmount: (callback: () => void) => void;
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Hook which synchronously executes a callback when the component is about to unmount.
4
+ *
5
+ * @param callback - Function to call during unmount.
6
+ */
7
+
8
+ export const useUnmount = callback => {
9
+ const unmountRef = React.useRef(callback);
10
+ unmountRef.current = callback;
11
+ React.useEffect(() => () => {
12
+ var _a;
13
+
14
+ (_a = unmountRef.current) === null || _a === void 0 ? void 0 : _a.call(unmountRef);
15
+ }, []);
16
+ };
17
+ //# sourceMappingURL=useUnmount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useUnmount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;AAIG;;AACH,OAAO,MAAM,UAAU,GAAI,QAAD,IAAyB;AACjD,QAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAAa,QAAb,CAAnB;AACA,EAAA,UAAU,CAAC,OAAX,GAAqB,QAArB;AACA,EAAA,KAAK,CAAC,SAAN,CACE,MAAM,MAAK;;;AACT,KAAA,EAAA,GAAA,UAAU,CAAC,OAAX,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,KAAA,CAAlB,GAAkB,EAAA,CAAA,IAAA,CAAlB,UAAkB,CAAlB;AACD,GAHH,EAIE,EAJF;AAMD,CATM","sourcesContent":["import * as React from 'react';\n\n/**\n * Hook which synchronously executes a callback when the component is about to unmount.\n *\n * @param callback - Function to call during unmount.\n */\nexport const useUnmount = (callback: () => void) => {\n const unmountRef = React.useRef(callback);\n unmountRef.current = callback;\n React.useEffect(\n () => () => {\n unmountRef.current?.();\n },\n [],\n );\n};\n"],"sourceRoot":"../src/"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './compose/index';
2
+ export * from './hooks/index';
3
+ export * from './ssr/index';
4
+ export * from './utils/index';
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './compose/index';
2
+ export * from './hooks/index';
3
+ export * from './ssr/index';
4
+ export * from './utils/index';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC","sourcesContent":["export * from './compose/index';\nexport * from './hooks/index';\nexport * from './ssr/index';\nexport * from './utils/index';\n"]}
@@ -0,0 +1,33 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request
4
+ * to ensure the client and server are consistent.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare type SSRContextValue = {
9
+ current: number;
10
+ };
11
+ /**
12
+ * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare const defaultSSRContextValue: SSRContextValue;
17
+ export declare const SSRContext: React.Context<SSRContextValue>;
18
+ /**
19
+ * @internal
20
+ */
21
+ export declare function useSSRContext(): SSRContextValue;
22
+ /**
23
+ * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
24
+ * are consistent between the client and server.
25
+ *
26
+ * @public
27
+ */
28
+ export declare const SSRProvider: React.FC;
29
+ /**
30
+ * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
31
+ * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
32
+ */
33
+ export declare function useIsSSR(): boolean;
@@ -0,0 +1,65 @@
1
+ import * as React from 'react';
2
+ import { canUseDOM } from './canUseDOM';
3
+ /**
4
+ * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
5
+ *
6
+ * @internal
7
+ */
8
+
9
+ export const defaultSSRContextValue = {
10
+ current: 0
11
+ };
12
+ export const SSRContext = /*#__PURE__*/React.createContext(defaultSSRContextValue);
13
+ /**
14
+ * @internal
15
+ */
16
+
17
+ export function useSSRContext() {
18
+ return React.useContext(SSRContext);
19
+ }
20
+ /**
21
+ * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
22
+ * are consistent between the client and server.
23
+ *
24
+ * @public
25
+ */
26
+
27
+ export const SSRProvider = props => {
28
+ const [value] = React.useState(() => ({
29
+ current: 0
30
+ }));
31
+ return /*#__PURE__*/React.createElement(SSRContext.Provider, {
32
+ value: value
33
+ }, props.children);
34
+ };
35
+ /**
36
+ * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
37
+ * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
38
+ */
39
+
40
+ export function useIsSSR() {
41
+ const isInSSRContext = useSSRContext() !== defaultSSRContextValue;
42
+ const [isSSR, setIsSSR] = React.useState(isInSSRContext); // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the
43
+ // developer to add one.
44
+
45
+ if (process.env.NODE_ENV !== 'production') {
46
+ if (!isInSSRContext && !canUseDOM()) {
47
+ // eslint-disable-next-line no-console
48
+ console.error('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' + 'generated between the client and server.');
49
+ }
50
+ } // If on the client, and the component was initially server rendered, then schedule a layout effect to update the
51
+ // component after hydration.
52
+
53
+
54
+ if (canUseDOM() && isInSSRContext) {
55
+ // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
56
+ // mounting.
57
+ // eslint-disable-next-line
58
+ React.useLayoutEffect(() => {
59
+ setIsSSR(false);
60
+ }, []);
61
+ }
62
+
63
+ return isSSR;
64
+ }
65
+ //# sourceMappingURL=SSRContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ssr/SSRContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,aAA1B;AAYA;;;;AAIG;;AACH,OAAO,MAAM,sBAAsB,GAAoB;AACrD,EAAA,OAAO,EAAE;AAD4C,CAAhD;AAIP,OAAO,MAAM,UAAU,gBAAG,KAAK,CAAC,aAAN,CAAqC,sBAArC,CAAnB;AAEP;;AAEG;;AACH,OAAM,SAAU,aAAV,GAAuB;AAC3B,SAAO,KAAK,CAAC,UAAN,CAAiB,UAAjB,CAAP;AACD;AAED;;;;;AAKG;;AACH,OAAO,MAAM,WAAW,GAAa,KAAK,IAAG;AAC3C,QAAM,CAAC,KAAD,IAAU,KAAK,CAAC,QAAN,CAAgC,OAAO;AAAE,IAAA,OAAO,EAAE;AAAX,GAAP,CAAhC,CAAhB;AAEA,sBAAO,KAAA,CAAA,aAAA,CAAC,UAAU,CAAC,QAAZ,EAAoB;AAAC,IAAA,KAAK,EAAE;AAAR,GAApB,EAAoC,KAAK,CAAC,QAA1C,CAAP;AACD,CAJM;AAMP;;;AAGG;;AACH,OAAM,SAAU,QAAV,GAAkB;AACtB,QAAM,cAAc,GAAG,aAAa,OAAO,sBAA3C;AACA,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAe,cAAf,CAA1B,CAFsB,CAItB;AACA;;AACA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QAAI,CAAC,cAAD,IAAmB,CAAC,SAAS,EAAjC,EAAqC;AACnC;AACA,MAAA,OAAO,CAAC,KAAR,CACE,4GACE,0CAFJ;AAID;AACF,GAdqB,CAgBtB;AACA;;;AACA,MAAI,SAAS,MAAM,cAAnB,EAAmC;AACjC;AACA;AACA;AACA,IAAA,KAAK,CAAC,eAAN,CAAsB,MAAK;AACzB,MAAA,QAAQ,CAAC,KAAD,CAAR;AACD,KAFD,EAEG,EAFH;AAGD;;AAED,SAAO,KAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from './canUseDOM';\n\n/**\n * To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request\n * to ensure the client and server are consistent.\n *\n * @internal\n */\nexport type SSRContextValue = {\n current: number;\n};\n\n/**\n * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.\n *\n * @internal\n */\nexport const defaultSSRContextValue: SSRContextValue = {\n current: 0,\n};\n\nexport const SSRContext = React.createContext<SSRContextValue>(defaultSSRContextValue);\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext);\n}\n\n/**\n * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids\n * are consistent between the client and server.\n *\n * @public\n */\nexport const SSRProvider: React.FC = props => {\n const [value] = React.useState<SSRContextValue>(() => ({ current: 0 }));\n\n return <SSRContext.Provider value={value}>{props.children}</SSRContext.Provider>;\n};\n\n/**\n * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay\n * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.\n */\nexport function useIsSSR(): boolean {\n const isInSSRContext = useSSRContext() !== defaultSSRContextValue;\n const [isSSR, setIsSSR] = React.useState(isInSSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the\n // developer to add one.\n if (process.env.NODE_ENV !== 'production') {\n if (!isInSSRContext && !canUseDOM()) {\n // eslint-disable-next-line no-console\n console.error(\n 'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' +\n 'generated between the client and server.',\n );\n }\n }\n\n // If on the client, and the component was initially server rendered, then schedule a layout effect to update the\n // component after hydration.\n if (canUseDOM() && isInSSRContext) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line\n React.useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return isSSR;\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Verifies if an application can use DOM.
3
+ */
4
+ export declare function canUseDOM(): boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Verifies if an application can use DOM.
3
+ */
4
+ export function canUseDOM() {
5
+ return typeof window !== 'undefined' && !!(window.document && // eslint-disable-next-line deprecation/deprecation
6
+ window.document.createElement);
7
+ }
8
+ //# sourceMappingURL=canUseDOM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ssr/canUseDOM.ts"],"names":[],"mappings":"AAAA;;AAEG;AACH,OAAM,SAAU,SAAV,GAAmB;AACvB,SACE,OAAO,MAAP,KAAkB,WAAlB,IACA,CAAC,EACC,MAAM,CAAC,QAAP,IACA;AACA,EAAA,MAAM,CAAC,QAAP,CAAgB,aAHjB,CAFH;AAQD","sourcesContent":["/**\n * Verifies if an application can use DOM.\n */\nexport function canUseDOM(): boolean {\n return (\n typeof window !== 'undefined' &&\n !!(\n window.document &&\n // eslint-disable-next-line deprecation/deprecation\n window.document.createElement\n )\n );\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,2 @@
1
+ export * from './canUseDOM';
2
+ export * from './SSRContext';
@@ -0,0 +1,3 @@
1
+ export * from './canUseDOM';
2
+ export * from './SSRContext';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["ssr/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC","sourcesContent":["export * from './canUseDOM';\nexport * from './SSRContext';\n"]}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.18.1"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
4
+ */
5
+ export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React.ReactElement | null;
@@ -0,0 +1,36 @@
1
+ import * as React from 'react';
2
+ import { isFluentTrigger } from './isFluentTrigger';
3
+ /**
4
+ * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
5
+ */
6
+
7
+ export const applyTriggerPropsToChildren = (children, triggerProps) => {
8
+ if (typeof children === 'function') {
9
+ return children(triggerProps);
10
+ } else if (children) {
11
+ return cloneTriggerTree(children, triggerProps);
12
+ } // Components in React should return either JSX elements or "null", otherwise React will throw:
13
+ // Nothing was returned from render.
14
+ // This usually means a return statement is missing. Or, to render nothing, return null.
15
+
16
+
17
+ return children || null;
18
+ };
19
+ /**
20
+ * Clones a React element tree, and applies the given props to the first grandchild that is not
21
+ * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
22
+ */
23
+
24
+ const cloneTriggerTree = (child, triggerProps) => {
25
+ if (! /*#__PURE__*/React.isValidElement(child) || child.type === React.Fragment) {
26
+ throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
27
+ }
28
+
29
+ if (isFluentTrigger(child)) {
30
+ const grandchild = cloneTriggerTree(child.props.children, triggerProps);
31
+ return /*#__PURE__*/React.cloneElement(child, undefined, grandchild);
32
+ } else {
33
+ return /*#__PURE__*/React.cloneElement(child, triggerProps);
34
+ }
35
+ };
36
+ //# sourceMappingURL=applyTriggerPropsToChildren.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/applyTriggerPropsToChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAEA;;AAEG;;AACH,OAAO,MAAM,2BAA2B,GAAG,CACzC,QADyC,EAEzC,YAFyC,KAGZ;AAC7B,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,WAAO,QAAQ,CAAC,YAAD,CAAf;AACD,GAFD,MAEO,IAAI,QAAJ,EAAc;AACnB,WAAO,gBAAgB,CAAC,QAAD,EAAW,YAAX,CAAvB;AACD,GAL4B,CAO7B;AACA;AACA;;;AACA,SAAO,QAAQ,IAAI,IAAnB;AACD,CAdM;AAgBP;;;AAGG;;AACH,MAAM,gBAAgB,GAAG,CAAgB,KAAhB,EAAwC,YAAxC,KAA2F;AAClH,MAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;AACjE,UAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;AAID;;AAED,MAAI,eAAe,CAAC,KAAD,CAAnB,EAA4B;AAC1B,UAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;AACA,wBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;AACD,GAHD,MAGO;AACL,wBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;AACD;AACF,CAdD","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\n\n/**\n * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport const applyTriggerPropsToChildren = <TTriggerProps>(\n children: React.ReactElement | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined,\n triggerProps: TTriggerProps,\n): React.ReactElement | null => {\n if (typeof children === 'function') {\n return children(triggerProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n};\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nconst cloneTriggerTree = <TTriggerProps>(child: React.ReactNode, triggerProps: TTriggerProps): React.ReactElement => {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps);\n }\n};\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Clamps `value` to a number between the min and max.
3
+ *
4
+ * @param value - the value to be clamped
5
+ * @param min - the lowest valid value
6
+ * @param max - the highest valid value
7
+ */
8
+ export declare const clamp: (value: number, min: number, max: number) => number;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Clamps `value` to a number between the min and max.
3
+ *
4
+ * @param value - the value to be clamped
5
+ * @param min - the lowest valid value
6
+ * @param max - the highest valid value
7
+ */
8
+ export const clamp = (value, min, max) => Math.max(min, Math.min(max, value || 0));
9
+ //# sourceMappingURL=clamp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clamp.js","sourceRoot":"../src/","sources":["utils/clamp.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Clamps `value` to a number between the min and max.\n *\n * @param value - the value to be clamped\n * @param min - the lowest valid value\n * @param max - the highest valid value\n */\nexport const clamp = (value: number, min: number, max: number): number => Math.max(min, Math.min(max, value || 0));\n"]}
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Given an element tagname and user props, filters the props to only allowed props for the given
4
+ * element type.
5
+ * @param tagName - Tag name (e.g. "div")
6
+ * @param props - Props object
7
+ * @param excludedPropNames - List of props to disallow
8
+ */
9
+ export declare function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
10
+ /**
11
+ * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
12
+ *
13
+ * This function is only for use with components that have a primary slot other than `root`.
14
+ * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
15
+ *
16
+ * @returns An object containing the native props for the `root` and primary slots.
17
+ */
18
+ export declare const getPartitionedNativeProps: <Props extends Pick<React.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
19
+ /** The primary slot's element type (e.g. 'div') */
20
+ primarySlotTagName: keyof JSX.IntrinsicElements;
21
+ /** The component's props object */
22
+ props: Props;
23
+ /** List of native props to exclude from the returned value */
24
+ excludedPropNames?: ExcludedPropKeys[] | undefined;
25
+ }) => {
26
+ root: {
27
+ style: React.CSSProperties | undefined;
28
+ className: string | undefined;
29
+ };
30
+ primary: Omit<Props, ExcludedPropKeys>;
31
+ };
@@ -0,0 +1,61 @@
1
+ import { labelProperties, audioProperties, videoProperties, olProperties, liProperties, anchorProperties, buttonProperties, inputProperties, textAreaProperties, selectProperties, optionProperties, tableProperties, trProperties, thProperties, tdProperties, colGroupProperties, colProperties, fieldsetProperties, formProperties, iframeProperties, imgProperties, htmlElementProperties, getNativeProps } from './properties';
2
+ const nativeElementMap = {
3
+ label: labelProperties,
4
+ audio: audioProperties,
5
+ video: videoProperties,
6
+ ol: olProperties,
7
+ li: liProperties,
8
+ a: anchorProperties,
9
+ button: buttonProperties,
10
+ input: inputProperties,
11
+ textarea: textAreaProperties,
12
+ select: selectProperties,
13
+ option: optionProperties,
14
+ table: tableProperties,
15
+ tr: trProperties,
16
+ th: thProperties,
17
+ td: tdProperties,
18
+ colGroup: colGroupProperties,
19
+ col: colProperties,
20
+ fieldset: fieldsetProperties,
21
+ form: formProperties,
22
+ iframe: iframeProperties,
23
+ img: imgProperties
24
+ };
25
+ /**
26
+ * Given an element tagname and user props, filters the props to only allowed props for the given
27
+ * element type.
28
+ * @param tagName - Tag name (e.g. "div")
29
+ * @param props - Props object
30
+ * @param excludedPropNames - List of props to disallow
31
+ */
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
+
34
+ export function getNativeElementProps(tagName, props, excludedPropNames) {
35
+ const allowedPropNames = tagName && nativeElementMap[tagName] || htmlElementProperties;
36
+ allowedPropNames.as = 1;
37
+ return getNativeProps(props, allowedPropNames, excludedPropNames);
38
+ }
39
+ /**
40
+ * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
41
+ *
42
+ * This function is only for use with components that have a primary slot other than `root`.
43
+ * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
44
+ *
45
+ * @returns An object containing the native props for the `root` and primary slots.
46
+ */
47
+
48
+ export const getPartitionedNativeProps = ({
49
+ primarySlotTagName,
50
+ props,
51
+ excludedPropNames
52
+ }) => {
53
+ return {
54
+ root: {
55
+ style: props.style,
56
+ className: props.className
57
+ },
58
+ primary: getNativeElementProps(primarySlotTagName, props, [...(excludedPropNames || []), 'style', 'className'])
59
+ };
60
+ };
61
+ //# sourceMappingURL=getNativeElementProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/getNativeElementProps.ts"],"names":[],"mappings":"AACA,SACE,eADF,EAEE,eAFF,EAGE,eAHF,EAIE,YAJF,EAKE,YALF,EAME,gBANF,EAOE,gBAPF,EAQE,eARF,EASE,kBATF,EAUE,gBAVF,EAWE,gBAXF,EAYE,eAZF,EAaE,YAbF,EAcE,YAdF,EAeE,YAfF,EAgBE,kBAhBF,EAiBE,aAjBF,EAkBE,kBAlBF,EAmBE,cAnBF,EAoBE,gBApBF,EAqBE,aArBF,EAsBE,qBAtBF,EAuBE,cAvBF,QAwBO,cAxBP;AA0BA,MAAM,gBAAgB,GAA2C;AAC/D,EAAA,KAAK,EAAE,eADwD;AAE/D,EAAA,KAAK,EAAE,eAFwD;AAG/D,EAAA,KAAK,EAAE,eAHwD;AAI/D,EAAA,EAAE,EAAE,YAJ2D;AAK/D,EAAA,EAAE,EAAE,YAL2D;AAM/D,EAAA,CAAC,EAAE,gBAN4D;AAO/D,EAAA,MAAM,EAAE,gBAPuD;AAQ/D,EAAA,KAAK,EAAE,eARwD;AAS/D,EAAA,QAAQ,EAAE,kBATqD;AAU/D,EAAA,MAAM,EAAE,gBAVuD;AAW/D,EAAA,MAAM,EAAE,gBAXuD;AAY/D,EAAA,KAAK,EAAE,eAZwD;AAa/D,EAAA,EAAE,EAAE,YAb2D;AAc/D,EAAA,EAAE,EAAE,YAd2D;AAe/D,EAAA,EAAE,EAAE,YAf2D;AAgB/D,EAAA,QAAQ,EAAE,kBAhBqD;AAiB/D,EAAA,GAAG,EAAE,aAjB0D;AAkB/D,EAAA,QAAQ,EAAE,kBAlBqD;AAmB/D,EAAA,IAAI,EAAE,cAnByD;AAoB/D,EAAA,MAAM,EAAE,gBApBuD;AAqB/D,EAAA,GAAG,EAAE;AArB0D,CAAjE;AAwBA;;;;;;AAMG;AACH;;AACA,OAAM,SAAU,qBAAV,CACJ,OADI,EAEJ,KAFI,EAGJ,iBAHI,EAGwB;AAE5B,QAAM,gBAAgB,GAAI,OAAO,IAAI,gBAAgB,CAAC,OAAD,CAA5B,IAA0C,qBAAnE;AACA,EAAA,gBAAgB,CAAC,EAAjB,GAAsB,CAAtB;AAEA,SAAO,cAAc,CAAC,KAAD,EAAQ,gBAAR,EAA0B,iBAA1B,CAArB;AACD;AAED;;;;;;;AAOG;;AACH,OAAO,MAAM,yBAAyB,GAAG,CAGvC;AACA,EAAA,kBADA;AAEA,EAAA,KAFA;AAGA,EAAA;AAHA,CAHuC,KAgBpC;AACH,SAAO;AACL,IAAA,IAAI,EAAE;AAAE,MAAA,KAAK,EAAE,KAAK,CAAC,KAAf;AAAsB,MAAA,SAAS,EAAE,KAAK,CAAC;AAAvC,KADD;AAEL,IAAA,OAAO,EAAE,qBAAqB,CAAgC,kBAAhC,EAAoD,KAApD,EAA2D,CACvF,IAAI,iBAAiB,IAAI,EAAzB,CADuF,EAEvF,OAFuF,EAGvF,WAHuF,CAA3D;AAFzB,GAAP;AAQD,CAzBM","sourcesContent":["import * as React from 'react';\nimport {\n labelProperties,\n audioProperties,\n videoProperties,\n olProperties,\n liProperties,\n anchorProperties,\n buttonProperties,\n inputProperties,\n textAreaProperties,\n selectProperties,\n optionProperties,\n tableProperties,\n trProperties,\n thProperties,\n tdProperties,\n colGroupProperties,\n colProperties,\n fieldsetProperties,\n formProperties,\n iframeProperties,\n imgProperties,\n htmlElementProperties,\n getNativeProps,\n} from './properties';\n\nconst nativeElementMap: Record<string, Record<string, number>> = {\n label: labelProperties,\n audio: audioProperties,\n video: videoProperties,\n ol: olProperties,\n li: liProperties,\n a: anchorProperties,\n button: buttonProperties,\n input: inputProperties,\n textarea: textAreaProperties,\n select: selectProperties,\n option: optionProperties,\n table: tableProperties,\n tr: trProperties,\n th: thProperties,\n td: tdProperties,\n colGroup: colGroupProperties,\n col: colProperties,\n fieldset: fieldsetProperties,\n form: formProperties,\n iframe: iframeProperties,\n img: imgProperties,\n};\n\n/**\n * Given an element tagname and user props, filters the props to only allowed props for the given\n * element type.\n * @param tagName - Tag name (e.g. \"div\")\n * @param props - Props object\n * @param excludedPropNames - List of props to disallow\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(\n tagName: string,\n props: {},\n excludedPropNames?: string[],\n): TAttributes {\n const allowedPropNames = (tagName && nativeElementMap[tagName]) || htmlElementProperties;\n allowedPropNames.as = 1;\n\n return getNativeProps(props, allowedPropNames, excludedPropNames);\n}\n\n/**\n * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.\n *\n * This function is only for use with components that have a primary slot other than `root`.\n * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.\n *\n * @returns An object containing the native props for the `root` and primary slots.\n */\nexport const getPartitionedNativeProps = <\n Props extends Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>,\n ExcludedPropKeys extends Extract<keyof Props, string> = never\n>({\n primarySlotTagName,\n props,\n excludedPropNames,\n}: {\n /** The primary slot's element type (e.g. 'div') */\n primarySlotTagName: keyof JSX.IntrinsicElements;\n\n /** The component's props object */\n props: Props;\n\n /** List of native props to exclude from the returned value */\n excludedPropNames?: ExcludedPropKeys[];\n}) => {\n return {\n root: { style: props.style, className: props.className },\n primary: getNativeElementProps<Omit<Props, ExcludedPropKeys>>(primarySlotTagName, props, [\n ...(excludedPropNames || []),\n 'style',\n 'className',\n ]),\n };\n};\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Finds and swaps a provided key for it's right to left format.
3
+ */
4
+ export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Finds and swaps a provided key for it's right to left format.
3
+ */
4
+ export const getRTLSafeKey = (key, dir) => {
5
+ if (dir === 'rtl') {
6
+ switch (key) {
7
+ case 'ArrowLeft':
8
+ {
9
+ return 'ArrowRight';
10
+ }
11
+
12
+ case 'ArrowRight':
13
+ {
14
+ return 'ArrowLeft';
15
+ }
16
+ }
17
+ }
18
+
19
+ return key;
20
+ };
21
+ //# sourceMappingURL=getRTLSafeKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/getRTLSafeKey.ts"],"names":[],"mappings":"AAAA;;AAEG;AACH,OAAO,MAAM,aAAa,GAAG,CAAC,GAAD,EAAc,GAAd,KAAoC;AAC/D,MAAI,GAAG,KAAK,KAAZ,EAAmB;AACjB,YAAQ,GAAR;AACE,WAAK,WAAL;AAAkB;AAChB,iBAAO,YAAP;AACD;;AAED,WAAK,YAAL;AAAmB;AACjB,iBAAO,WAAP;AACD;AAPH;AASD;;AAED,SAAO,GAAP;AACD,CAdM","sourcesContent":["/**\n * Finds and swaps a provided key for it's right to left format.\n */\nexport const getRTLSafeKey = (key: string, dir: 'ltr' | 'rtl') => {\n if (dir === 'rtl') {\n switch (key) {\n case 'ArrowLeft': {\n return 'ArrowRight';\n }\n\n case 'ArrowRight': {\n return 'ArrowLeft';\n }\n }\n }\n\n return key;\n};\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ interface ReactSyntheticEvent extends React.SyntheticEvent<unknown> {
3
+ _reactName?: string;
4
+ dispatchConfig?: {
5
+ registrationName: string;
6
+ phasedRegistrationNames: {
7
+ bubbled: string;
8
+ captured: string;
9
+ };
10
+ };
11
+ }
12
+ declare type NonUndefined<A> = A extends undefined ? never : A;
13
+ declare type FunctionKeys<T extends object> = {
14
+ [K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;
15
+ }[keyof T];
16
+ export declare type ReactCallbackName = FunctionKeys<React.DOMAttributes<unknown>>;
17
+ /**
18
+ * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
19
+ *
20
+ * Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
21
+ * ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
22
+ * are handled in bubble phase.
23
+ */
24
+ export declare function getReactCallbackName(event: ReactSyntheticEvent): ReactCallbackName | undefined;
25
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.
3
+ *
4
+ * Ideally, it should also distinguish regular and "capture" callbacks, but it's possible only with React 17 as
5
+ * ".eventPhase" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events
6
+ * are handled in bubble phase.
7
+ */
8
+ export function getReactCallbackName(event) {
9
+ if (event._reactName) {
10
+ return event._reactName;
11
+ }
12
+
13
+ if (event.dispatchConfig) {
14
+ if (event.dispatchConfig.registrationName) {
15
+ return event.dispatchConfig.registrationName;
16
+ }
17
+
18
+ return event.dispatchConfig.phasedRegistrationNames.bubbled;
19
+ }
20
+
21
+ if (process.env.NODE_ENV !== 'production') {
22
+ // eslint-disable-next-line no-console
23
+ console.error(['Passed React.SyntheticEvent does not contain ".dispatchConfig" or "._reactName".', 'This should not happen, please report it to https://github.com/microsoft/fluentui']);
24
+ }
25
+ }
26
+ //# sourceMappingURL=getReactCallbackName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/getReactCallbackName.ts"],"names":[],"mappings":"AAwBA;;;;;;AAMG;AACH,OAAM,SAAU,oBAAV,CAA+B,KAA/B,EAAyD;AAC7D,MAAI,KAAK,CAAC,UAAV,EAAsB;AACpB,WAAO,KAAK,CAAC,UAAb;AACD;;AAED,MAAI,KAAK,CAAC,cAAV,EAA0B;AACxB,QAAI,KAAK,CAAC,cAAN,CAAqB,gBAAzB,EAA2C;AACzC,aAAO,KAAK,CAAC,cAAN,CAAqB,gBAA5B;AACD;;AAED,WAAO,KAAK,CAAC,cAAN,CAAqB,uBAArB,CAA6C,OAApD;AACD;;AAED,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA,IAAA,OAAO,CAAC,KAAR,CAAc,CACZ,kFADY,EAEZ,mFAFY,CAAd;AAID;AACF","sourcesContent":["import * as React from 'react';\n\ninterface ReactSyntheticEvent extends React.SyntheticEvent<unknown> {\n // React 17/18\n // See https://github.com/facebook/react/pull/19236\n _reactName?: string;\n\n // React 16\n dispatchConfig?: {\n registrationName: string;\n phasedRegistrationNames: {\n bubbled: string;\n captured: string;\n };\n };\n}\n\ntype NonUndefined<A> = A extends undefined ? never : A;\ntype FunctionKeys<T extends object> = {\n [K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;\n}[keyof T];\n\nexport type ReactCallbackName = FunctionKeys<React.DOMAttributes<unknown>>;\n\n/**\n * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.\n *\n * Ideally, it should also distinguish regular and \"capture\" callbacks, but it's possible only with React 17 as\n * \".eventPhase\" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events\n * are handled in bubble phase.\n */\nexport function getReactCallbackName(event: ReactSyntheticEvent): ReactCallbackName | undefined {\n if (event._reactName) {\n return event._reactName as ReactCallbackName;\n }\n\n if (event.dispatchConfig) {\n if (event.dispatchConfig.registrationName) {\n return event.dispatchConfig.registrationName as ReactCallbackName;\n }\n\n return event.dispatchConfig.phasedRegistrationNames.bubbled as ReactCallbackName;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error([\n 'Passed React.SyntheticEvent does not contain \".dispatchConfig\" or \"._reactName\".',\n 'This should not happen, please report it to https://github.com/microsoft/fluentui',\n ]);\n }\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
4
+ *
5
+ * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
6
+ * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
7
+ * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
8
+ *
9
+ * For example, the following returns `<div id="child" />`:
10
+ * ```jsx
11
+ * getTriggerChild(
12
+ * <Tooltip>
13
+ * <MenuTrigger>
14
+ * <div id="child" />
15
+ * </MenuTrigger>
16
+ * </Tooltip>
17
+ * );
18
+ * ```
19
+ */
20
+ export declare const getTriggerChild: (children: React.ReactNode) => React.ReactElement & {
21
+ ref?: React.Ref<unknown>;
22
+ };
@@ -0,0 +1,26 @@
1
+ import * as React from 'react';
2
+ import { isFluentTrigger } from './isFluentTrigger';
3
+ /**
4
+ * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
5
+ *
6
+ * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
7
+ * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
8
+ * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
9
+ *
10
+ * For example, the following returns `<div id="child" />`:
11
+ * ```jsx
12
+ * getTriggerChild(
13
+ * <Tooltip>
14
+ * <MenuTrigger>
15
+ * <div id="child" />
16
+ * </MenuTrigger>
17
+ * </Tooltip>
18
+ * );
19
+ * ```
20
+ */
21
+
22
+ export const getTriggerChild = children => {
23
+ const child = React.Children.only(children);
24
+ return isFluentTrigger(child) ? getTriggerChild(child.props.children) : child;
25
+ };
26
+ //# sourceMappingURL=getTriggerChild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/getTriggerChild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAEA;;;;;;;;;;;;;;;;;AAiBG;;AACH,OAAO,MAAM,eAAe,GAAI,QAAD,IAAiF;AAC9G,QAAM,KAAK,GAAG,KAAK,CAAC,QAAN,CAAe,IAAf,CAAoB,QAApB,CAAd;AACA,SAAO,eAAe,CAAC,KAAD,CAAf,GAAyB,eAAe,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,CAAxC,GAAiE,KAAxE;AACD,CAHM","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\n\n/**\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n */\nexport const getTriggerChild = (children: React.ReactNode): React.ReactElement & { ref?: React.Ref<unknown> } => {\n const child = React.Children.only(children) as React.ReactElement;\n return isFluentTrigger(child) ? getTriggerChild(child.props.children) : child;\n};\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,9 @@
1
+ export * from './applyTriggerPropsToChildren';
2
+ export * from './clamp';
3
+ export * from './getNativeElementProps';
4
+ export * from './getRTLSafeKey';
5
+ export * from './getTriggerChild';
6
+ export * from './isFluentTrigger';
7
+ export * from './omit';
8
+ export * from './properties';
9
+ export * from './shouldPreventDefaultOnKeyDown';
@@ -0,0 +1,10 @@
1
+ export * from './applyTriggerPropsToChildren';
2
+ export * from './clamp';
3
+ export * from './getNativeElementProps';
4
+ export * from './getRTLSafeKey';
5
+ export * from './getTriggerChild';
6
+ export * from './isFluentTrigger';
7
+ export * from './omit';
8
+ export * from './properties';
9
+ export * from './shouldPreventDefaultOnKeyDown';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iCAAiC,CAAC","sourcesContent":["export * from './applyTriggerPropsToChildren';\nexport * from './clamp';\nexport * from './getNativeElementProps';\nexport * from './getRTLSafeKey';\nexport * from './getTriggerChild';\nexport * from './isFluentTrigger';\nexport * from './omit';\nexport * from './properties';\nexport * from './shouldPreventDefaultOnKeyDown';\n"]}
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Allows a component to be tagged as a FluentUI trigger component.
4
+ *
5
+ * Triggers are special-case components: they attach event listeners and other props on their child,
6
+ * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.
7
+ *
8
+ * A component can be tagged as a trigger as follows:
9
+ * ```ts
10
+ * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;
11
+ *
12
+ * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true
13
+ * ```
14
+ */
15
+ export declare type FluentTriggerComponent = {
16
+ isFluentTriggerComponent?: boolean;
17
+ };
18
+ /**
19
+ * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
20
+ * See the {@link FluentTriggerComponent} type for more info.
21
+ */
22
+ export declare const isFluentTrigger: (element: React.ReactElement) => boolean | undefined;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
3
+ * See the {@link FluentTriggerComponent} type for more info.
4
+ */
5
+ export const isFluentTrigger = element => {
6
+ return element.type.isFluentTriggerComponent;
7
+ };
8
+ //# sourceMappingURL=isFluentTrigger.js.map