@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 @@
1
+ {"version":3,"sources":["utils/isFluentTrigger.ts"],"names":[],"mappings":"AAmBA;;;AAGG;AACH,OAAO,MAAM,eAAe,GAAI,OAAD,IAAgC;AAC7D,SAAQ,OAAO,CAAC,IAAR,CAAwC,wBAAhD;AACD,CAFM","sourcesContent":["import * as React from 'react';\n\n/**\n * Allows a component to be tagged as a FluentUI trigger component.\n *\n * Triggers are special-case components: they attach event listeners and other props on their child,\n * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.\n *\n * A component can be tagged as a trigger as follows:\n * ```ts\n * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;\n *\n * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true\n * ```\n */\nexport type FluentTriggerComponent = {\n isFluentTriggerComponent?: boolean;\n};\n\n/**\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport const isFluentTrigger = (element: React.ReactElement) => {\n return (element.type as FluentTriggerComponent).isFluentTriggerComponent;\n};\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Tiny helper to do the minimal amount of work in duplicating an object but omitting some
3
+ * props. This ends up faster than using object ...rest or reduce to filter.
4
+ *
5
+ * This behaves very much like filteredAssign, but does not merge many objects together,
6
+ * uses an exclusion object map, and avoids spreads all for optimal performance.
7
+ *
8
+ * See perf test for background:
9
+ * https://jsperf.com/omit-vs-rest-vs-reduce/1
10
+ *
11
+ * @param obj - The object to clone
12
+ * @param exclusions - The array of keys to exclude
13
+ */
14
+ export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Tiny helper to do the minimal amount of work in duplicating an object but omitting some
3
+ * props. This ends up faster than using object ...rest or reduce to filter.
4
+ *
5
+ * This behaves very much like filteredAssign, but does not merge many objects together,
6
+ * uses an exclusion object map, and avoids spreads all for optimal performance.
7
+ *
8
+ * See perf test for background:
9
+ * https://jsperf.com/omit-vs-rest-vs-reduce/1
10
+ *
11
+ * @param obj - The object to clone
12
+ * @param exclusions - The array of keys to exclude
13
+ */
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ export function omit(obj, exclusions) {
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ const result = {};
18
+
19
+ for (const key in obj) {
20
+ if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {
21
+ result[key] = obj[key];
22
+ }
23
+ }
24
+
25
+ return result;
26
+ }
27
+ //# sourceMappingURL=omit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;AAYG;AACH;AACA,OAAM,SAAU,IAAV,CACJ,GADI,EAEJ,UAFI,EAEkB;AAEtB;AACA,QAAM,MAAM,GAAwB,EAApC;;AAEA,OAAK,MAAM,GAAX,IAAkB,GAAlB,EAAuB;AACrB,QAAI,UAAU,CAAC,OAAX,CAAmB,GAAnB,MAA4B,CAAC,CAA7B,IAAkC,GAAG,CAAC,cAAJ,CAAmB,GAAnB,CAAtC,EAA+D;AAC7D,MAAA,MAAM,CAAC,GAAD,CAAN,GAAc,GAAG,CAAC,GAAD,CAAjB;AACD;AACF;;AAED,SAAO,MAAP;AACD","sourcesContent":["/**\n * Tiny helper to do the minimal amount of work in duplicating an object but omitting some\n * props. This ends up faster than using object ...rest or reduce to filter.\n *\n * This behaves very much like filteredAssign, but does not merge many objects together,\n * uses an exclusion object map, and avoids spreads all for optimal performance.\n *\n * See perf test for background:\n * https://jsperf.com/omit-vs-rest-vs-reduce/1\n *\n * @param obj - The object to clone\n * @param exclusions - The array of keys to exclude\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(\n obj: TObj,\n exclusions: Exclusions,\n): Omit<TObj, Exclusions[number]> {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n\n for (const key in obj) {\n if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {\n result[key] = obj[key];\n }\n }\n\n return result as TObj;\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,154 @@
1
+ /**
2
+ * An array of events that are allowed on every html element type.
3
+ *
4
+ * @public
5
+ */
6
+ export declare const baseElementEvents: Record<string, number>;
7
+ /**
8
+ * An array of element attributes which are allowed on every html element type.
9
+ *
10
+ * @public
11
+ */
12
+ export declare const baseElementProperties: Record<string, number>;
13
+ /**
14
+ * An array of HTML element properties and events.
15
+ *
16
+ * @public
17
+ */
18
+ export declare const htmlElementProperties: Record<string, number>;
19
+ /**
20
+ * An array of LABEL tag properties and events.
21
+ *
22
+ * @public
23
+ */
24
+ export declare const labelProperties: Record<string, number>;
25
+ /**
26
+ * An array of AUDIO tag properties and events.
27
+
28
+ * @public
29
+ */
30
+ export declare const audioProperties: Record<string, number>;
31
+ /**
32
+ * An array of VIDEO tag properties and events.
33
+ *
34
+ * @public
35
+ */
36
+ export declare const videoProperties: Record<string, number>;
37
+ /**
38
+ * An array of OL tag properties and events.
39
+ *
40
+ * @public
41
+ */
42
+ export declare const olProperties: Record<string, number>;
43
+ /**
44
+ * An array of LI tag properties and events.
45
+ *
46
+ * @public
47
+ */
48
+ export declare const liProperties: Record<string, number>;
49
+ /**
50
+ * An array of A tag properties and events.
51
+ *
52
+ * @public
53
+ */
54
+ export declare const anchorProperties: Record<string, number>;
55
+ /**
56
+ * An array of BUTTON tag properties and events.
57
+ *
58
+ * @public
59
+ */
60
+ export declare const buttonProperties: Record<string, number>;
61
+ /**
62
+ * An array of INPUT tag properties and events.
63
+ *
64
+ * @public
65
+ */
66
+ export declare const inputProperties: Record<string, number>;
67
+ /**
68
+ * An array of TEXTAREA tag properties and events.
69
+ *
70
+ * @public
71
+ */
72
+ export declare const textAreaProperties: Record<string, number>;
73
+ /**
74
+ * An array of SELECT tag properties and events.
75
+ *
76
+ * @public
77
+ */
78
+ export declare const selectProperties: Record<string, number>;
79
+ export declare const optionProperties: Record<string, number>;
80
+ /**
81
+ * An array of TABLE tag properties and events.
82
+ *
83
+ * @public
84
+ */
85
+ export declare const tableProperties: Record<string, number>;
86
+ /**
87
+ * An array of TR tag properties and events.
88
+ *
89
+ * @public
90
+ */
91
+ export declare const trProperties: Record<string, number>;
92
+ /**
93
+ * An array of TH tag properties and events.
94
+ *
95
+ * @public
96
+ */
97
+ export declare const thProperties: Record<string, number>;
98
+ /**
99
+ * An array of TD tag properties and events.
100
+ *
101
+ * @public
102
+ */
103
+ export declare const tdProperties: Record<string, number>;
104
+ export declare const colGroupProperties: Record<string, number>;
105
+ export declare const colProperties: Record<string, number>;
106
+ /**
107
+ * An array of FIELDSET tag properties and events.
108
+ *
109
+ * @public
110
+ */
111
+ export declare const fieldsetProperties: Record<string, number>;
112
+ /**
113
+ * An array of FORM tag properties and events.
114
+ *
115
+ * @public
116
+ */
117
+ export declare const formProperties: Record<string, number>;
118
+ /**
119
+ * An array of IFRAME tag properties and events.
120
+ *
121
+ * @public
122
+ */
123
+ export declare const iframeProperties: Record<string, number>;
124
+ /**
125
+ * An array of IMAGE tag properties and events.
126
+ *
127
+ * @public
128
+ */
129
+ export declare const imgProperties: Record<string, number>;
130
+ /**
131
+ * @deprecated Use imgProperties for img elements.
132
+ */
133
+ export declare const imageProperties: Record<string, number>;
134
+ /**
135
+ * An array of DIV tag properties and events.
136
+ *
137
+ * @public
138
+ */
139
+ export declare const divProperties: Record<string, number>;
140
+ /**
141
+ * Gets native supported props for an html element provided the allowance set. Use one of the property
142
+ * sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given
143
+ * props set. Note that all data- and aria- prefixed attributes will be allowed.
144
+ * NOTE: getNativeProps should always be applied first when adding props to a react component. The
145
+ * non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.
146
+ * For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to
147
+ * the component after an onClick function is added, then the getNativeProps onClick will override it.
148
+ *
149
+ * @public
150
+ * @param props - The unfiltered input props
151
+ * @param allowedPropsNames - The array or record of allowed prop names.
152
+ * @returns The filtered props
153
+ */
154
+ export declare function getNativeProps<T extends Record<string, any>>(props: Record<string, any>, allowedPropNames: string[] | Record<string, number>, excludedPropNames?: string[]): T;
@@ -0,0 +1,237 @@
1
+ const toObjectMap = (...items) => {
2
+ const result = {};
3
+
4
+ for (const item of items) {
5
+ const keys = Array.isArray(item) ? item : Object.keys(item);
6
+
7
+ for (const key of keys) {
8
+ result[key] = 1;
9
+ }
10
+ }
11
+
12
+ return result;
13
+ };
14
+ /**
15
+ * An array of events that are allowed on every html element type.
16
+ *
17
+ * @public
18
+ */
19
+
20
+
21
+ export const baseElementEvents = /*#__PURE__*/toObjectMap(['onAuxClick', 'onCopy', 'onCut', 'onPaste', 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate', 'onFocus', 'onFocusCapture', 'onBlur', 'onBlurCapture', 'onChange', 'onInput', 'onSubmit', 'onLoad', 'onError', 'onKeyDown', 'onKeyDownCapture', 'onKeyPress', 'onKeyUp', 'onAbort', 'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded', 'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying', 'onProgress', 'onRateChange', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend', 'onTimeUpdate', 'onVolumeChange', 'onWaiting', 'onClick', 'onClickCapture', 'onContextMenu', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseDownCapture', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onMouseUpCapture', 'onSelect', 'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart', 'onScroll', 'onWheel', 'onPointerCancel', 'onPointerDown', 'onPointerEnter', 'onPointerLeave', 'onPointerMove', 'onPointerOut', 'onPointerOver', 'onPointerUp', 'onGotPointerCapture', 'onLostPointerCapture']);
22
+ /**
23
+ * An array of element attributes which are allowed on every html element type.
24
+ *
25
+ * @public
26
+ */
27
+
28
+ export const baseElementProperties = /*#__PURE__*/toObjectMap(['accessKey', 'children', 'className', 'contentEditable', 'dir', 'draggable', 'hidden', 'htmlFor', 'id', 'lang', 'ref', 'role', 'style', 'tabIndex', 'title', 'translate', 'spellCheck', 'name' // global
29
+ ]);
30
+ /**
31
+ * An array of HTML element properties and events.
32
+ *
33
+ * @public
34
+ */
35
+
36
+ export const htmlElementProperties = /*#__PURE__*/toObjectMap(baseElementProperties, baseElementEvents);
37
+ /**
38
+ * An array of LABEL tag properties and events.
39
+ *
40
+ * @public
41
+ */
42
+
43
+ export const labelProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['form' // button, fieldset, input, label, meter, object, output, select, textarea
44
+ ]);
45
+ /**
46
+ * An array of AUDIO tag properties and events.
47
+
48
+ * @public
49
+ */
50
+
51
+ export const audioProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['height', 'loop', 'muted', 'preload', 'src', 'width' // canvas, embed, iframe, img, input, object, video
52
+ ]);
53
+ /**
54
+ * An array of VIDEO tag properties and events.
55
+ *
56
+ * @public
57
+ */
58
+
59
+ export const videoProperties = /*#__PURE__*/toObjectMap(audioProperties, ['poster' // video
60
+ ]);
61
+ /**
62
+ * An array of OL tag properties and events.
63
+ *
64
+ * @public
65
+ */
66
+
67
+ export const olProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['start' // ol
68
+ ]);
69
+ /**
70
+ * An array of LI tag properties and events.
71
+ *
72
+ * @public
73
+ */
74
+
75
+ export const liProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['value' // button, input, li, option, meter, progress, param
76
+ ]);
77
+ /**
78
+ * An array of A tag properties and events.
79
+ *
80
+ * @public
81
+ */
82
+
83
+ export const anchorProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['download', 'href', 'hrefLang', 'media', 'rel', 'target', 'type' // a, button, input, link, menu, object, script, source, style
84
+ ]);
85
+ /**
86
+ * An array of BUTTON tag properties and events.
87
+ *
88
+ * @public
89
+ */
90
+
91
+ export const buttonProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['autoFocus', 'disabled', 'form', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget', 'type', 'value' // button, input, li, option, meter, progress, param,
92
+ ]);
93
+ /**
94
+ * An array of INPUT tag properties and events.
95
+ *
96
+ * @public
97
+ */
98
+
99
+ export const inputProperties = /*#__PURE__*/toObjectMap(buttonProperties, ['accept', 'alt', 'autoCapitalize', 'autoComplete', 'checked', 'dirname', 'form', 'height', 'inputMode', 'list', 'max', 'maxLength', 'min', 'multiple', 'pattern', 'placeholder', 'readOnly', 'required', 'src', 'step', 'size', 'type', 'value', 'width' // canvas, embed, iframe, img, input, object, video
100
+ ]);
101
+ /**
102
+ * An array of TEXTAREA tag properties and events.
103
+ *
104
+ * @public
105
+ */
106
+
107
+ export const textAreaProperties = /*#__PURE__*/toObjectMap(buttonProperties, ['autoCapitalize', 'cols', 'dirname', 'form', 'maxLength', 'placeholder', 'readOnly', 'required', 'rows', 'wrap' // textarea
108
+ ]);
109
+ /**
110
+ * An array of SELECT tag properties and events.
111
+ *
112
+ * @public
113
+ */
114
+
115
+ export const selectProperties = /*#__PURE__*/toObjectMap(buttonProperties, ['form', 'multiple', 'required' // input, select, textarea
116
+ ]);
117
+ export const optionProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['selected', 'value' // button, input, li, option, meter, progress, param
118
+ ]);
119
+ /**
120
+ * An array of TABLE tag properties and events.
121
+ *
122
+ * @public
123
+ */
124
+
125
+ export const tableProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['cellPadding', 'cellSpacing' // table
126
+ ]);
127
+ /**
128
+ * An array of TR tag properties and events.
129
+ *
130
+ * @public
131
+ */
132
+
133
+ export const trProperties = htmlElementProperties;
134
+ /**
135
+ * An array of TH tag properties and events.
136
+ *
137
+ * @public
138
+ */
139
+
140
+ export const thProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['rowSpan', 'scope' // th
141
+ ]);
142
+ /**
143
+ * An array of TD tag properties and events.
144
+ *
145
+ * @public
146
+ */
147
+
148
+ export const tdProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['colSpan', 'headers', 'rowSpan', 'scope' // th
149
+ ]);
150
+ export const colGroupProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['span' // col, colgroup
151
+ ]);
152
+ export const colProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['span' // col, colgroup
153
+ ]);
154
+ /**
155
+ * An array of FIELDSET tag properties and events.
156
+ *
157
+ * @public
158
+ */
159
+
160
+ export const fieldsetProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['disabled', 'form' // button, fieldset, input, label, meter, object, output, select, textarea
161
+ ]);
162
+ /**
163
+ * An array of FORM tag properties and events.
164
+ *
165
+ * @public
166
+ */
167
+
168
+ export const formProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['acceptCharset', 'action', 'encType', 'encType', 'method', 'noValidate', 'target' // form
169
+ ]);
170
+ /**
171
+ * An array of IFRAME tag properties and events.
172
+ *
173
+ * @public
174
+ */
175
+
176
+ export const iframeProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['allow', 'allowFullScreen', 'allowPaymentRequest', 'allowTransparency', 'csp', 'height', 'importance', 'referrerPolicy', 'sandbox', 'src', 'srcDoc', 'width' // canvas, embed, iframe, img, input, object, video,
177
+ ]);
178
+ /**
179
+ * An array of IMAGE tag properties and events.
180
+ *
181
+ * @public
182
+ */
183
+
184
+ export const imgProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['alt', 'crossOrigin', 'height', 'src', 'srcSet', 'useMap', 'width' // canvas, embed, iframe, img, input, object, video
185
+ ]);
186
+ /**
187
+ * @deprecated Use imgProperties for img elements.
188
+ */
189
+
190
+ export const imageProperties = imgProperties;
191
+ /**
192
+ * An array of DIV tag properties and events.
193
+ *
194
+ * @public
195
+ */
196
+
197
+ export const divProperties = htmlElementProperties;
198
+ /**
199
+ * Gets native supported props for an html element provided the allowance set. Use one of the property
200
+ * sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given
201
+ * props set. Note that all data- and aria- prefixed attributes will be allowed.
202
+ * NOTE: getNativeProps should always be applied first when adding props to a react component. The
203
+ * non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.
204
+ * For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to
205
+ * the component after an onClick function is added, then the getNativeProps onClick will override it.
206
+ *
207
+ * @public
208
+ * @param props - The unfiltered input props
209
+ * @param allowedPropsNames - The array or record of allowed prop names.
210
+ * @returns The filtered props
211
+ */
212
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+
214
+ export function getNativeProps( // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
+ props, allowedPropNames, excludedPropNames) {
216
+ // It'd be great to properly type this while allowing 'aria-` and 'data-' attributes like TypeScript does for
217
+ // JSX attributes, but that ability is hardcoded into the TS compiler with no analog in TypeScript typings.
218
+ // Then we'd be able to enforce props extends native props (including aria- and data- attributes), and then
219
+ // return native props.
220
+ // We should be able to do this once this PR is merged: https://github.com/microsoft/TypeScript/pull/26797
221
+ const isArray = Array.isArray(allowedPropNames); // eslint-disable-next-line @typescript-eslint/no-explicit-any
222
+
223
+ const result = {};
224
+ const keys = Object.keys(props);
225
+
226
+ for (const key of keys) {
227
+ const isNativeProp = !isArray && allowedPropNames[key] || isArray && allowedPropNames.indexOf(key) >= 0 || key.indexOf('data-') === 0 || key.indexOf('aria-') === 0;
228
+
229
+ if (isNativeProp && (!excludedPropNames || (excludedPropNames === null || excludedPropNames === void 0 ? void 0 : excludedPropNames.indexOf(key)) === -1)) {
230
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
+ result[key] = props[key];
232
+ }
233
+ }
234
+
235
+ return result;
236
+ }
237
+ //# sourceMappingURL=properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/properties.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,CAAC,GAAG,KAAJ,KAAoD;AACtE,QAAM,MAAM,GAA2B,EAAvC;;AAEA,OAAK,MAAM,IAAX,IAAmB,KAAnB,EAA0B;AACxB,UAAM,IAAI,GAAG,KAAK,CAAC,OAAN,CAAc,IAAd,IAAsB,IAAtB,GAA6B,MAAM,CAAC,IAAP,CAAY,IAAZ,CAA1C;;AAEA,SAAK,MAAM,GAAX,IAAkB,IAAlB,EAAwB;AACtB,MAAA,MAAM,CAAC,GAAD,CAAN,GAAc,CAAd;AACD;AACF;;AAED,SAAO,MAAP;AACD,CAZD;AAcA;;;;AAIG;;;AACH,OAAO,MAAM,iBAAiB,gBAAG,WAAW,CAAC,CAC3C,YAD2C,EAE3C,QAF2C,EAG3C,OAH2C,EAI3C,SAJ2C,EAK3C,kBAL2C,EA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,CAAhB,EAAoF;AAClF;AACA,MAAA,MAAM,CAAC,GAAD,CAAN,GAAc,KAAM,CAAC,GAAD,CAApB;AACD;AACF;;AAED,SAAO,MAAP;AACD","sourcesContent":["const toObjectMap = (...items: (string[] | Record<string, number>)[]) => {\n const result: Record<string, number> = {};\n\n for (const item of items) {\n const keys = Array.isArray(item) ? item : Object.keys(item);\n\n for (const key of keys) {\n result[key] = 1;\n }\n }\n\n return result;\n};\n\n/**\n * An array of events that are allowed on every html element type.\n *\n * @public\n */\nexport const baseElementEvents = toObjectMap([\n 'onAuxClick',\n 'onCopy',\n 'onCut',\n 'onPaste',\n 'onCompositionEnd',\n 'onCompositionStart',\n 'onCompositionUpdate',\n 'onFocus',\n 'onFocusCapture',\n 'onBlur',\n 'onBlurCapture',\n 'onChange',\n 'onInput',\n 'onSubmit',\n 'onLoad',\n 'onError',\n 'onKeyDown',\n 'onKeyDownCapture',\n 'onKeyPress',\n 'onKeyUp',\n 'onAbort',\n 'onCanPlay',\n 'onCanPlayThrough',\n 'onDurationChange',\n 'onEmptied',\n 'onEncrypted',\n 'onEnded',\n 'onLoadedData',\n 'onLoadedMetadata',\n 'onLoadStart',\n 'onPause',\n 'onPlay',\n 'onPlaying',\n 'onProgress',\n 'onRateChange',\n 'onSeeked',\n 'onSeeking',\n 'onStalled',\n 'onSuspend',\n 'onTimeUpdate',\n 'onVolumeChange',\n 'onWaiting',\n 'onClick',\n 'onClickCapture',\n 'onContextMenu',\n 'onDoubleClick',\n 'onDrag',\n 'onDragEnd',\n 'onDragEnter',\n 'onDragExit',\n 'onDragLeave',\n 'onDragOver',\n 'onDragStart',\n 'onDrop',\n 'onMouseDown',\n 'onMouseDownCapture',\n 'onMouseEnter',\n 'onMouseLeave',\n 'onMouseMove',\n 'onMouseOut',\n 'onMouseOver',\n 'onMouseUp',\n 'onMouseUpCapture',\n 'onSelect',\n 'onTouchCancel',\n 'onTouchEnd',\n 'onTouchMove',\n 'onTouchStart',\n 'onScroll',\n 'onWheel',\n 'onPointerCancel',\n 'onPointerDown',\n 'onPointerEnter',\n 'onPointerLeave',\n 'onPointerMove',\n 'onPointerOut',\n 'onPointerOver',\n 'onPointerUp',\n 'onGotPointerCapture',\n 'onLostPointerCapture',\n]);\n\n/**\n * An array of element attributes which are allowed on every html element type.\n *\n * @public\n */\nexport const baseElementProperties = toObjectMap([\n 'accessKey', // global\n 'children', // global\n 'className', // global\n 'contentEditable', // global\n 'dir', // global\n 'draggable', // global\n 'hidden', // global\n 'htmlFor', // global\n 'id', // global\n 'lang', // global\n 'ref', // global\n 'role', // global\n 'style', // global\n 'tabIndex', // global\n 'title', // global\n 'translate', // global\n 'spellCheck', // global\n 'name', // global\n]);\n\n/**\n * An array of HTML element properties and events.\n *\n * @public\n */\nexport const htmlElementProperties = toObjectMap(baseElementProperties, baseElementEvents);\n\n/**\n * An array of LABEL tag properties and events.\n *\n * @public\n */\nexport const labelProperties = toObjectMap(htmlElementProperties, [\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n]);\n\n/**\n * An array of AUDIO tag properties and events.\n\n * @public\n */\nexport const audioProperties = toObjectMap(htmlElementProperties, [\n 'height', // canvas, embed, iframe, img, input, object, video\n 'loop', // audio, video\n 'muted', // audio, video\n 'preload', // audio, video\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'width', // canvas, embed, iframe, img, input, object, video\n]);\n\n/**\n * An array of VIDEO tag properties and events.\n *\n * @public\n */\nexport const videoProperties = toObjectMap(audioProperties, [\n 'poster', // video\n]);\n\n/**\n * An array of OL tag properties and events.\n *\n * @public\n */\nexport const olProperties = toObjectMap(htmlElementProperties, [\n 'start', // ol\n]);\n\n/**\n * An array of LI tag properties and events.\n *\n * @public\n */\nexport const liProperties = toObjectMap(htmlElementProperties, [\n 'value', // button, input, li, option, meter, progress, param\n]);\n\n/**\n * An array of A tag properties and events.\n *\n * @public\n */\nexport const anchorProperties = toObjectMap(htmlElementProperties, [\n 'download', // a, area\n 'href', // a, area, base, link\n 'hrefLang', // a, area, link\n 'media', // a, area, link, source, style\n 'rel', // a, area, link\n 'target', // a, area, base, form\n 'type', // a, button, input, link, menu, object, script, source, style\n]);\n\n/**\n * An array of BUTTON tag properties and events.\n *\n * @public\n */\nexport const buttonProperties = toObjectMap(htmlElementProperties, [\n 'autoFocus', // button, input, select, textarea\n 'disabled', // button, fieldset, input, optgroup, option, select, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'formAction', // input, button\n 'formEncType', // input, button\n 'formMethod', // input, button\n 'formNoValidate', // input, button\n 'formTarget', // input, button\n 'type', // a, button, input, link, menu, object, script, source, style\n 'value', // button, input, li, option, meter, progress, param,\n]);\n\n/**\n * An array of INPUT tag properties and events.\n *\n * @public\n */\nexport const inputProperties = toObjectMap(buttonProperties, [\n 'accept', // input\n 'alt', // area, img, input\n 'autoCapitalize', // input, textarea\n 'autoComplete', // form, input\n 'checked', // input\n 'dirname', // input, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'height', // canvas, embed, iframe, img, input, object, video\n 'inputMode', // input\n 'list', // input\n 'max', // input, meter\n 'maxLength', // input, textarea\n 'min', // input, meter\n 'multiple', // input, select\n 'pattern', // input\n 'placeholder', // input, textarea\n 'readOnly', // input, textarea\n 'required', // input, select, textarea\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'step', // input\n 'size', // input\n 'type', // a, button, input, link, menu, object, script, source, style\n 'value', // button, input, li, option, meter, progress, param\n 'width', // canvas, embed, iframe, img, input, object, video\n]);\n\n/**\n * An array of TEXTAREA tag properties and events.\n *\n * @public\n */\nexport const textAreaProperties = toObjectMap(buttonProperties, [\n 'autoCapitalize', // input, textarea\n 'cols', // textarea\n 'dirname', // input, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'maxLength', // input, textarea\n 'placeholder', // input, textarea\n 'readOnly', // input, textarea\n 'required', // input, select, textarea\n 'rows', // textarea\n 'wrap', // textarea\n]);\n\n/**\n * An array of SELECT tag properties and events.\n *\n * @public\n */\nexport const selectProperties = toObjectMap(buttonProperties, [\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n 'multiple', // input, select\n 'required', // input, select, textarea\n]);\n\nexport const optionProperties = toObjectMap(htmlElementProperties, [\n 'selected', // option\n 'value', // button, input, li, option, meter, progress, param\n]);\n\n/**\n * An array of TABLE tag properties and events.\n *\n * @public\n */\nexport const tableProperties = toObjectMap(htmlElementProperties, [\n 'cellPadding', // table\n 'cellSpacing', // table\n]);\n\n/**\n * An array of TR tag properties and events.\n *\n * @public\n */\nexport const trProperties = htmlElementProperties;\n\n/**\n * An array of TH tag properties and events.\n *\n * @public\n */\nexport const thProperties = toObjectMap(htmlElementProperties, [\n 'rowSpan', // td, th\n 'scope', // th\n]);\n\n/**\n * An array of TD tag properties and events.\n *\n * @public\n */\nexport const tdProperties = toObjectMap(htmlElementProperties, [\n 'colSpan', // td\n 'headers', // td\n 'rowSpan', // td, th\n 'scope', // th\n]);\n\nexport const colGroupProperties = toObjectMap(htmlElementProperties, [\n 'span', // col, colgroup\n]);\n\nexport const colProperties = toObjectMap(htmlElementProperties, [\n 'span', // col, colgroup\n]);\n\n/**\n * An array of FIELDSET tag properties and events.\n *\n * @public\n */\nexport const fieldsetProperties = toObjectMap(htmlElementProperties, [\n 'disabled', // button, fieldset, input, optgroup, option, select, textarea\n 'form', // button, fieldset, input, label, meter, object, output, select, textarea\n]);\n\n/**\n * An array of FORM tag properties and events.\n *\n * @public\n */\nexport const formProperties = toObjectMap(htmlElementProperties, [\n 'acceptCharset', // form\n 'action', // form\n 'encType', // form\n 'encType', // form\n 'method', // form\n 'noValidate', // form\n 'target', // form\n]);\n\n/**\n * An array of IFRAME tag properties and events.\n *\n * @public\n */\nexport const iframeProperties = toObjectMap(htmlElementProperties, [\n 'allow', // iframe\n 'allowFullScreen', // iframe\n 'allowPaymentRequest', // iframe\n 'allowTransparency', // iframe\n 'csp', // iframe\n 'height', // canvas, embed, iframe, img, input, object, video\n 'importance', // iframe\n 'referrerPolicy', // iframe\n 'sandbox', // iframe\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'srcDoc', // iframe\n 'width', // canvas, embed, iframe, img, input, object, video,\n]);\n\n/**\n * An array of IMAGE tag properties and events.\n *\n * @public\n */\nexport const imgProperties = toObjectMap(htmlElementProperties, [\n 'alt', // area, img, input\n 'crossOrigin', // img\n 'height', // canvas, embed, iframe, img, input, object, video\n 'src', // audio, embed, iframe, img, input, script, source, track, video\n 'srcSet', // img, source\n 'useMap', // img, object,\n 'width', // canvas, embed, iframe, img, input, object, video\n]);\n\n/**\n * @deprecated Use imgProperties for img elements.\n */\nexport const imageProperties = imgProperties;\n\n/**\n * An array of DIV tag properties and events.\n *\n * @public\n */\nexport const divProperties = htmlElementProperties;\n\n/**\n * Gets native supported props for an html element provided the allowance set. Use one of the property\n * sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given\n * props set. Note that all data- and aria- prefixed attributes will be allowed.\n * NOTE: getNativeProps should always be applied first when adding props to a react component. The\n * non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.\n * For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to\n * the component after an onClick function is added, then the getNativeProps onClick will override it.\n *\n * @public\n * @param props - The unfiltered input props\n * @param allowedPropsNames - The array or record of allowed prop names.\n * @returns The filtered props\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getNativeProps<T extends Record<string, any>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n props: Record<string, any>,\n allowedPropNames: string[] | Record<string, number>,\n excludedPropNames?: string[],\n): T {\n // It'd be great to properly type this while allowing 'aria-` and 'data-' attributes like TypeScript does for\n // JSX attributes, but that ability is hardcoded into the TS compiler with no analog in TypeScript typings.\n // Then we'd be able to enforce props extends native props (including aria- and data- attributes), and then\n // return native props.\n // We should be able to do this once this PR is merged: https://github.com/microsoft/TypeScript/pull/26797\n\n const isArray = Array.isArray(allowedPropNames);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result: Record<string, any> = {};\n const keys = Object.keys(props);\n\n for (const key of keys) {\n const isNativeProp =\n (!isArray && (allowedPropNames as Record<string, number>)[key]) ||\n (isArray && (allowedPropNames as string[]).indexOf(key) >= 0) ||\n key.indexOf('data-') === 0 ||\n key.indexOf('aria-') === 0;\n\n if (isNativeProp && (!excludedPropNames || excludedPropNames?.indexOf(key) === -1)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n result[key] = props![key] as any;\n }\n }\n\n return result as T;\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
4
+ *
5
+ * Useful for situations where a keydown needs to be transformed to a click event
6
+ */
7
+ export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React.KeyboardEvent): boolean;
@@ -0,0 +1,24 @@
1
+ import { Space, Enter } from '@fluentui/keyboard-keys';
2
+ /**
3
+ * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
4
+ *
5
+ * Useful for situations where a keydown needs to be transformed to a click event
6
+ */
7
+
8
+ export function shouldPreventDefaultOnKeyDown(e) {
9
+ if (e.defaultPrevented) {
10
+ return false;
11
+ }
12
+
13
+ const key = e.key;
14
+ const target = e.target;
15
+ const matchesByKey = key === Space || key === Enter;
16
+
17
+ if ((target === null || target === void 0 ? void 0 : target.tagName) === 'A') {
18
+ return key === Space;
19
+ }
20
+
21
+ const ignoredByTag = (target === null || target === void 0 ? void 0 : target.tagName) === 'INPUT' || (target === null || target === void 0 ? void 0 : target.tagName) === 'TEXTAREA' || (target === null || target === void 0 ? void 0 : target.isContentEditable) === true;
22
+ return matchesByKey && !ignoredByTag;
23
+ }
24
+ //# sourceMappingURL=shouldPreventDefaultOnKeyDown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["utils/shouldPreventDefaultOnKeyDown.ts"],"names":[],"mappings":"AAAA,SAAS,KAAT,EAAgB,KAAhB,QAA6B,yBAA7B;AAGA;;;;AAIG;;AACH,OAAM,SAAU,6BAAV,CAAwC,CAAxC,EAA8E;AAClF,MAAI,CAAC,CAAC,gBAAN,EAAwB;AACtB,WAAO,KAAP;AACD;;AAED,QAAM,GAAG,GAAG,CAAC,CAAC,GAAd;AACA,QAAM,MAAM,GAA4B,CAAC,CAAC,MAA1C;AAEA,QAAM,YAAY,GAAG,GAAG,KAAK,KAAR,IAAiB,GAAG,KAAK,KAA9C;;AAEA,MAAI,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,GAAxB,EAA6B;AAC3B,WAAO,GAAG,KAAK,KAAf;AACD;;AAED,QAAM,YAAY,GAChB,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,OAApB,IAA+B,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,OAAR,MAAoB,UAAnD,IAAiE,CAAA,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,iBAAR,MAA8B,IADjG;AAGA,SAAO,YAAY,IAAI,CAAC,YAAxB;AACD","sourcesContent":["import { Space, Enter } from '@fluentui/keyboard-keys';\nimport * as React from 'react';\n\n/**\n * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys\n *\n * Useful for situations where a keydown needs to be transformed to a click event\n */\nexport function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React.KeyboardEvent) {\n if (e.defaultPrevented) {\n return false;\n }\n\n const key = e.key;\n const target: HTMLElement | undefined = e.target as HTMLElement;\n\n const matchesByKey = key === Space || key === Enter;\n\n if (target?.tagName === 'A') {\n return key === Space;\n }\n\n const ignoredByTag =\n target?.tagName === 'INPUT' || target?.tagName === 'TEXTAREA' || target?.isContentEditable === true;\n\n return matchesByKey && !ignoredByTag;\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+ import type { AsIntrinsicElement, ComponentState, ExtractSlotProps, SlotPropsRecord, UnionToIntersection } from './types';
3
+ export declare type Slots<S extends SlotPropsRecord> = {
4
+ [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? As : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? React.ElementType<NonNullable<P>> : React.ElementType<ExtractSlotProps<S[K]>>;
5
+ };
6
+ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
7
+ [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React.ComponentType<infer P> ? P : never;
8
+ };
9
+ /**
10
+ * Given the state and an array of slot names, will break out `slots` and `slotProps`
11
+ * collections.
12
+ *
13
+ * The root is derived from a mix of `components` props and `as` prop.
14
+ *
15
+ * Slots will render as null if they are rendered as primitives with undefined children.
16
+ *
17
+ * The slotProps will always omit the `as` prop within them, and for slots that are string
18
+ * primitives, the props will be filtered according to the slot type by the type system.
19
+ * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
20
+ * anchor props. Note that this is only enforced at build time by Typescript -- there is no
21
+ * runtime code filtering props in this function.
22
+ *
23
+ * @param state - State including slot definitions
24
+ * @returns An object containing the `slots` map and `slotProps` map.
25
+ */
26
+ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentState<R>): {
27
+ slots: Slots<R>;
28
+ slotProps: ObjectSlotProps<R>;
29
+ };
30
+ export {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSlots = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const omit_1 = /*#__PURE__*/require("../utils/omit");
11
+ /**
12
+ * Given the state and an array of slot names, will break out `slots` and `slotProps`
13
+ * collections.
14
+ *
15
+ * The root is derived from a mix of `components` props and `as` prop.
16
+ *
17
+ * Slots will render as null if they are rendered as primitives with undefined children.
18
+ *
19
+ * The slotProps will always omit the `as` prop within them, and for slots that are string
20
+ * primitives, the props will be filtered according to the slot type by the type system.
21
+ * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable
22
+ * anchor props. Note that this is only enforced at build time by Typescript -- there is no
23
+ * runtime code filtering props in this function.
24
+ *
25
+ * @param state - State including slot definitions
26
+ * @returns An object containing the `slots` map and `slotProps` map.
27
+ */
28
+
29
+
30
+ function getSlots(state) {
31
+ const slots = {};
32
+ const slotProps = {};
33
+ const slotNames = Object.keys(state.components);
34
+
35
+ for (const slotName of slotNames) {
36
+ const [slot, props] = getSlot(state, slotName);
37
+ slots[slotName] = slot;
38
+ slotProps[slotName] = props;
39
+ }
40
+
41
+ return {
42
+ slots,
43
+ slotProps: slotProps
44
+ };
45
+ }
46
+
47
+ exports.getSlots = getSlots;
48
+
49
+ function getSlot(state, slotName) {
50
+ var _a, _b, _c;
51
+
52
+ if (state[slotName] === undefined) {
53
+ return [null, undefined];
54
+ }
55
+
56
+ const {
57
+ children,
58
+ as: asProp,
59
+ ...rest
60
+ } = state[slotName];
61
+ const slot = ((_a = state.components) === null || _a === void 0 ? void 0 : _a[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_b = state.components) === null || _b === void 0 ? void 0 : _b[slotName]) || 'div' : state.components[slotName];
62
+
63
+ if (typeof children === 'function') {
64
+ const render = children;
65
+ return [React.Fragment, {
66
+ children: render(slot, rest)
67
+ }];
68
+ }
69
+
70
+ const shouldOmitAsProp = typeof slot === 'string' && ((_c = state[slotName]) === null || _c === void 0 ? void 0 : _c.as);
71
+ const slotProps = shouldOmitAsProp ? omit_1.omit(state[slotName], ['as']) : state[slotName];
72
+ return [slot, slotProps];
73
+ }
74
+ //# sour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,CAAP,KAAsC,QAApF,GACV,MAAM,KAAI,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAG,QAAH,CAApB,CAAN,IAA0C,KADhC,GAEV,KAAK,CAAC,UAAN,CAAiB,QAAjB,CAFJ;;AAIA,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,UAAM,MAAM,GAAG,QAAf;AACA,WAAO,CACL,KAAK,CAAC,QADD,EAEJ;AACC,MAAA,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;AADjB,KAFI,CAAP;AAMD;;AAED,QAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAA4B,CAAA,EAAA,GAAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;AACA,QAAM,SAAS,GAAI,gBAAgB,GAAG,MAAA,CAAA,IAAA,CAAK,KAAK,CAAC,QAAD,CAAV,EAAuB,CAAC,IAAD,CAAvB,CAAH,GAAoC,KAAK,CAAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\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\ntype 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]>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P\n : never;\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 if (state[slotName] === undefined) {\n return [null, undefined as R[K]];\n }\n const { children, as: asProp, ...rest } = state[slotName]!;\n\n const slot = (state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]) as React.ElementType<R[K]>;\n\n if (typeof children === 'function') {\n const render = children as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n ({\n children: render(slot, rest as Omit<R[K], 'children' | 'as'>),\n } as unknown) as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && state[slotName]?.as;\n const slotProps = (shouldOmitAsProp ? omit(state[slotName]!, ['as']) : state[slotName]) as R[K];\n\n return [slot, slotProps];\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,3 @@
1
+ export * from './getSlots';
2
+ export * from './resolveShorthand';
3
+ export * from './types';