@fluentui/react-utilities 9.0.1-0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +98 -1
- package/CHANGELOG.md +28 -2
- package/dist/index.d.ts +58 -21
- package/lib/compose/index.js +1 -0
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/isResolvedShorthand.js +36 -0
- package/lib/compose/isResolvedShorthand.js.map +1 -0
- package/lib/compose/types.js.map +1 -1
- package/lib/hooks/index.js +0 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/ssr/SSRContext.js +4 -2
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/utils/getNativeElementProps.js +3 -2
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeCallbacks.js +30 -0
- package/lib/utils/mergeCallbacks.js.map +1 -0
- package/lib/utils/properties.js +16 -1
- package/lib/utils/properties.js.map +1 -1
- package/lib-commonjs/compose/index.js +2 -0
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/isResolvedShorthand.js +46 -0
- package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -0
- package/lib-commonjs/hooks/index.js +0 -2
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/index.js +13 -7
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js +4 -2
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js +2 -1
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/index.js +2 -0
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeCallbacks.js +39 -0
- package/lib-commonjs/utils/mergeCallbacks.js.map +1 -0
- package/lib-commonjs/utils/properties.js +17 -2
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/package.json +4 -3
- package/dist/tsdoc-metadata.json +0 -11
- package/lib/hooks/useMergedEventCallbacks.js +0 -27
- package/lib/hooks/useMergedEventCallbacks.js.map +0 -1
- package/lib-commonjs/hooks/useMergedEventCallbacks.js +0 -37
- package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +0 -1
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,104 @@
|
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "Thu,
|
5
|
+
"date": "Thu, 15 Sep 2022 09:44:18 GMT",
|
6
|
+
"tag": "@fluentui/react-utilities_v9.1.0",
|
7
|
+
"version": "9.1.0",
|
8
|
+
"comments": {
|
9
|
+
"none": [
|
10
|
+
{
|
11
|
+
"author": "martinhochel@microsoft.com",
|
12
|
+
"package": "@fluentui/react-utilities",
|
13
|
+
"commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
|
14
|
+
"comment": "chore: update package scaffold"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "martinhochel@microsoft.com",
|
18
|
+
"package": "@fluentui/react-utilities",
|
19
|
+
"commit": "16aa65dcae8f75c6a221225fd0eb43800650ac66",
|
20
|
+
"comment": "docs(react-utilities): re-generate api.md"
|
21
|
+
}
|
22
|
+
],
|
23
|
+
"patch": [
|
24
|
+
{
|
25
|
+
"author": "lingfangao@hotmail.com",
|
26
|
+
"package": "@fluentui/react-utilities",
|
27
|
+
"commit": "a0cfab0e5f74e3a3bfa9c269fff574295042d7f2",
|
28
|
+
"comment": "chore: fix no-context-default-value lint violations"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"author": "yuanboxue@microsoft.com",
|
32
|
+
"package": "@fluentui/react-utilities",
|
33
|
+
"commit": "8cd907f0c88ecd6d21d0f5b4ea1e60f57f9bd04f",
|
34
|
+
"comment": "fix: add microdata properties to allowed html properties"
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"author": "behowell@microsoft.com",
|
38
|
+
"package": "@fluentui/react-utilities",
|
39
|
+
"commit": "e598325b985cad3e5057f00893e0176416edd292",
|
40
|
+
"comment": "refactor: Replace useMergedEventCallbacks utility with mergeCallbacks"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"minor": [
|
44
|
+
{
|
45
|
+
"author": "bernardo.sunderhus@gmail.com",
|
46
|
+
"package": "@fluentui/react-utilities",
|
47
|
+
"commit": "6fd8556690d3716c3f37b88b366dd51502d11d76",
|
48
|
+
"comment": "feat: add dialog properties to getNativeElementProps"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"author": "tristan.watanabe@gmail.com",
|
52
|
+
"package": "@fluentui/react-utilities",
|
53
|
+
"commit": "c8f9d1ef1983bffe9917da81b097f503f587faa9",
|
54
|
+
"comment": "fix: Replace deprecated ReactNodeArray for React 17 support."
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"author": "bernardo.sunderhus@gmail.com",
|
58
|
+
"package": "@fluentui/react-utilities",
|
59
|
+
"commit": "a85b5f8ff499fddcb1edcee28c7b0dede92ab674",
|
60
|
+
"comment": "feat(react-utilities): adds isResolvedShorthand guard method"
|
61
|
+
}
|
62
|
+
]
|
63
|
+
}
|
64
|
+
},
|
65
|
+
{
|
66
|
+
"date": "Wed, 03 Aug 2022 16:04:09 GMT",
|
67
|
+
"tag": "@fluentui/react-utilities_v9.0.2",
|
68
|
+
"version": "9.0.2",
|
69
|
+
"comments": {
|
70
|
+
"none": [
|
71
|
+
{
|
72
|
+
"author": "lingfangao@hotmail.com",
|
73
|
+
"package": "@fluentui/react-utilities",
|
74
|
+
"commit": "99cc385631d04a76ee10ebc143cb9fecd99640b6",
|
75
|
+
"comment": "chore: Add `prerelease` as disallowed changetype for 9.0.0 packages"
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"author": "bernardo.sunderhus@gmail.com",
|
79
|
+
"package": "@fluentui/react-utilities",
|
80
|
+
"commit": "d966ea3d9169f2e8d69f0d2a4daf86fe4ca328d6",
|
81
|
+
"comment": "disables eslint rule @fluentui/no-context-default-value for local component context"
|
82
|
+
}
|
83
|
+
]
|
84
|
+
}
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"date": "Thu, 14 Jul 2022 21:21:07 GMT",
|
88
|
+
"tag": "@fluentui/react-utilities_v9.0.2",
|
89
|
+
"version": "9.0.2",
|
90
|
+
"comments": {
|
91
|
+
"patch": [
|
92
|
+
{
|
93
|
+
"author": "Humberto.Morimoto@microsoft.com",
|
94
|
+
"package": "@fluentui/react-utilities",
|
95
|
+
"commit": "802bc4e3730a88b0fc61b5bf42ef7fc6b6543fe2",
|
96
|
+
"comment": "fix: Fixing bad version bump of @fluentui/react-utilities."
|
97
|
+
}
|
98
|
+
]
|
99
|
+
}
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"date": "Thu, 14 Jul 2022 17:06:25 GMT",
|
6
103
|
"tag": "@fluentui/react-utilities_v9.0.1-0",
|
7
104
|
"version": "9.0.1-0",
|
8
105
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,38 @@
|
|
1
1
|
# Change Log - @fluentui/react-utilities
|
2
2
|
|
3
|
-
This log was last generated on Thu,
|
3
|
+
This log was last generated on Thu, 15 Sep 2022 09:44:18 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.1.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.1.0)
|
8
|
+
|
9
|
+
Thu, 15 Sep 2022 09:44:18 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.2..@fluentui/react-utilities_v9.1.0)
|
11
|
+
|
12
|
+
### Minor changes
|
13
|
+
|
14
|
+
- feat: add dialog properties to getNativeElementProps ([PR #24698](https://github.com/microsoft/fluentui/pull/24698) by bernardo.sunderhus@gmail.com)
|
15
|
+
- fix: Replace deprecated ReactNodeArray for React 17 support. ([PR #24356](https://github.com/microsoft/fluentui/pull/24356) by tristan.watanabe@gmail.com)
|
16
|
+
- feat(react-utilities): adds isResolvedShorthand guard method ([PR #24535](https://github.com/microsoft/fluentui/pull/24535) by bernardo.sunderhus@gmail.com)
|
17
|
+
|
18
|
+
### Patches
|
19
|
+
|
20
|
+
- chore: fix no-context-default-value lint violations ([PR #24276](https://github.com/microsoft/fluentui/pull/24276) by lingfangao@hotmail.com)
|
21
|
+
- fix: add microdata properties to allowed html properties ([PR #24652](https://github.com/microsoft/fluentui/pull/24652) by yuanboxue@microsoft.com)
|
22
|
+
- refactor: Replace useMergedEventCallbacks utility with mergeCallbacks ([PR #24152](https://github.com/microsoft/fluentui/pull/24152) by behowell@microsoft.com)
|
23
|
+
|
24
|
+
## [9.0.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.2)
|
25
|
+
|
26
|
+
Thu, 14 Jul 2022 21:21:07 GMT
|
27
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.1-0..@fluentui/react-utilities_v9.0.2)
|
28
|
+
|
29
|
+
### Patches
|
30
|
+
|
31
|
+
- fix: Fixing bad version bump of @fluentui/react-utilities. ([PR #23920](https://github.com/microsoft/fluentui/pull/23920) by Humberto.Morimoto@microsoft.com)
|
32
|
+
|
7
33
|
## [9.0.1-0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.0.1-0)
|
8
34
|
|
9
|
-
Thu, 14 Jul 2022 17:
|
35
|
+
Thu, 14 Jul 2022 17:06:25 GMT
|
10
36
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.0.0..@fluentui/react-utilities_v9.0.1-0)
|
11
37
|
|
12
38
|
### Changes
|
package/dist/index.d.ts
CHANGED
@@ -178,6 +178,38 @@ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = Re
|
|
178
178
|
children?: never;
|
179
179
|
} : {});
|
180
180
|
|
181
|
+
/**
|
182
|
+
* Guard method that validates if a shorthand is a slot
|
183
|
+
* can be used to extends properties provided by a slot
|
184
|
+
*
|
185
|
+
* @example
|
186
|
+
* ```
|
187
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
188
|
+
* defaultProps: {
|
189
|
+
* onClick: useEventCallback(event => {
|
190
|
+
* if (isResolvedShorthand(backdrop)) {
|
191
|
+
* backdrop.onClick?.(event)
|
192
|
+
* }
|
193
|
+
* // do something after passing click down the line
|
194
|
+
* }),
|
195
|
+
* },
|
196
|
+
* })
|
197
|
+
* ```
|
198
|
+
* @example
|
199
|
+
* ```
|
200
|
+
* const handleBackDropClick = (event) => {
|
201
|
+
* // do your thing
|
202
|
+
* }
|
203
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
204
|
+
* defaultProps: {
|
205
|
+
* onClick: useEventCallback(
|
206
|
+
* mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)
|
207
|
+
* )
|
208
|
+
* })
|
209
|
+
* ```
|
210
|
+
*/
|
211
|
+
export declare function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(shorthand?: Shorthand): shorthand is ExtractSlotProps<Shorthand>;
|
212
|
+
|
181
213
|
/**
|
182
214
|
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
|
183
215
|
*
|
@@ -190,6 +222,31 @@ declare type IsSingleton<T extends string> = {
|
|
190
222
|
[K in T]: Exclude<T, K> extends never ? true : false;
|
191
223
|
}[T];
|
192
224
|
|
225
|
+
/**
|
226
|
+
* @internal
|
227
|
+
* Combine two event callbacks into a single callback function that calls each one in order.
|
228
|
+
*
|
229
|
+
* Usage example:
|
230
|
+
* ```ts
|
231
|
+
* state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {
|
232
|
+
* // Handle onChange
|
233
|
+
* });
|
234
|
+
* ```
|
235
|
+
*
|
236
|
+
* The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a
|
237
|
+
* local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:
|
238
|
+
* * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.
|
239
|
+
* * Missing a call to the original onChange due to an early return or other conditional.
|
240
|
+
*
|
241
|
+
* If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.
|
242
|
+
*
|
243
|
+
* @param callback1 - The first callback to be called, or undefined
|
244
|
+
* @param callback2 - The second callback to be called, or undefined
|
245
|
+
*
|
246
|
+
* @returns A function that that calls the provided functions in order
|
247
|
+
*/
|
248
|
+
export declare function mergeCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
|
249
|
+
|
193
250
|
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
194
251
|
[K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? P : never;
|
195
252
|
};
|
@@ -314,7 +371,7 @@ export declare type Slots<S extends SlotPropsRecord> = {
|
|
314
371
|
/**
|
315
372
|
* The shorthand value of a slot allows specifying its child
|
316
373
|
*/
|
317
|
-
export declare type SlotShorthandValue = React_2.ReactChild | React_2.
|
374
|
+
export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNode[] | React_2.ReactPortal;
|
318
375
|
|
319
376
|
/**
|
320
377
|
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
@@ -438,26 +495,6 @@ export declare const useIsomorphicLayoutEffect: typeof React_2.useEffect;
|
|
438
495
|
*/
|
439
496
|
export declare function useIsSSR(): boolean;
|
440
497
|
|
441
|
-
/**
|
442
|
-
* @internal
|
443
|
-
* Combine two event callbacks into a single callback function that calls each one in order.
|
444
|
-
*
|
445
|
-
* This is useful to add an event listener to an existing element without overwriting the current listener, if any.
|
446
|
-
*
|
447
|
-
* For example:
|
448
|
-
* ```ts
|
449
|
-
* state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
|
450
|
-
* // Handle onChange
|
451
|
-
* });
|
452
|
-
* ```
|
453
|
-
*
|
454
|
-
* @param callback1 - The first callback to be called
|
455
|
-
* @param callback2 - The second callback to be called
|
456
|
-
*
|
457
|
-
* @returns An event callback that calls the callbacks in order, and is stable between renders
|
458
|
-
*/
|
459
|
-
export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
|
460
|
-
|
461
498
|
/**
|
462
499
|
* @internal
|
463
500
|
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
|
package/lib/compose/index.js
CHANGED
package/lib/compose/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n"]}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { isValidElement } from 'react';
|
2
|
+
/**
|
3
|
+
* Guard method that validates if a shorthand is a slot
|
4
|
+
* can be used to extends properties provided by a slot
|
5
|
+
*
|
6
|
+
* @example
|
7
|
+
* ```
|
8
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
9
|
+
* defaultProps: {
|
10
|
+
* onClick: useEventCallback(event => {
|
11
|
+
* if (isResolvedShorthand(backdrop)) {
|
12
|
+
* backdrop.onClick?.(event)
|
13
|
+
* }
|
14
|
+
* // do something after passing click down the line
|
15
|
+
* }),
|
16
|
+
* },
|
17
|
+
* })
|
18
|
+
* ```
|
19
|
+
* @example
|
20
|
+
* ```
|
21
|
+
* const handleBackDropClick = (event) => {
|
22
|
+
* // do your thing
|
23
|
+
* }
|
24
|
+
* const backdropSlot = resolveShorthand(backdrop, {
|
25
|
+
* defaultProps: {
|
26
|
+
* onClick: useEventCallback(
|
27
|
+
* mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)
|
28
|
+
* )
|
29
|
+
* })
|
30
|
+
* ```
|
31
|
+
*/
|
32
|
+
|
33
|
+
export function isResolvedShorthand(shorthand) {
|
34
|
+
return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && ! /*#__PURE__*/isValidElement(shorthand);
|
35
|
+
}
|
36
|
+
//# sourceMappingURL=isResolvedShorthand.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["compose/isResolvedShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA/B;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;;AACH,OAAM,SAAU,mBAAV,CACJ,SADI,EACiB;EAErB,OAAO,SAAS,KAAK,IAAd,IAAsB,OAAO,SAAP,KAAqB,QAA3C,IAAuD,CAAC,KAAK,CAAC,OAAN,CAAc,SAAd,CAAxD,IAAoF,eAAC,cAAc,CAAC,SAAD,CAA1G;AACD","sourcesContent":["import { isValidElement } from 'react';\nimport type { ExtractSlotProps, Slot, UnknownSlotProps } from './types';\n\n/**\n * Guard method that validates if a shorthand is a slot\n * can be used to extends properties provided by a slot\n *\n * @example\n * ```\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(event => {\n * if (isResolvedShorthand(backdrop)) {\n * backdrop.onClick?.(event)\n * }\n * // do something after passing click down the line\n * }),\n * },\n * })\n * ```\n * @example\n * ```\n * const handleBackDropClick = (event) => {\n * // do your thing\n * }\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(\n * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)\n * )\n * })\n * ```\n */\nexport function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(\n shorthand?: Shorthand,\n): shorthand is ExtractSlotProps<Shorthand> {\n return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !isValidElement(shorthand);\n}\n"],"sourceRoot":"../src/"}
|
package/lib/compose/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["compose/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\nexport type SlotRenderFunction<Props> = (\n Component: React.ElementType<Props>,\n props: Omit<Props, 'children' | 'as'>,\n) => React.ReactNode;\n\n/**\n * Matches any component's Slots type (such as ButtonSlots).\n *\n * This should ONLY be used in type templates as in `extends SlotPropsRecord`;\n * it shouldn't be used as a component's Slots type.\n */\nexport type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;\n\n/**\n * The shorthand value of a slot allows specifying its child\n */\nexport type SlotShorthandValue = React.ReactChild | React.
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["compose/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\nexport type SlotRenderFunction<Props> = (\n Component: React.ElementType<Props>,\n props: Omit<Props, 'children' | 'as'>,\n) => React.ReactNode;\n\n/**\n * Matches any component's Slots type (such as ButtonSlots).\n *\n * This should ONLY be used in type templates as in `extends SlotPropsRecord`;\n * it shouldn't be used as a component's Slots type.\n */\nexport type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;\n\n/**\n * The shorthand value of a slot allows specifying its child\n */\nexport type SlotShorthandValue = React.ReactChild | React.ReactNode[] | React.ReactPortal;\n\n/**\n * Matches any slot props type.\n *\n * This should ONLY be used in type templates as in `extends UnknownSlotProps`;\n * it shouldn't be used as the type of a slot.\n */\nexport type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {\n as?: keyof JSX.IntrinsicElements;\n};\n\n/**\n * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.\n */\ntype WithSlotShorthandValue<Props extends { children?: unknown }> =\n | Props\n | Extract<SlotShorthandValue, Props['children']>;\n\n/**\n * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`\n * to be a render function that takes those props.\n */\ntype WithSlotRenderFunction<Props extends { children?: unknown }> = Props & {\n children?: Props['children'] | SlotRenderFunction<Props>;\n};\n\n/**\n * HTML element types that are not allowed to have children.\n *\n * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element\n */\ntype EmptyIntrisicElements =\n | 'area'\n | 'base'\n | 'br'\n | 'col'\n | 'embed'\n | 'hr'\n | 'img'\n | 'input'\n | 'link'\n | 'meta'\n | 'param'\n | 'source'\n | 'track'\n | 'wbr';\n\n/**\n * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:\n * * Removes legacy string ref.\n * * Disallows children for empty tags like 'img'.\n */\ntype IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> &\n (Type extends EmptyIntrisicElements ? { children?: never } : {});\n\n/**\n * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,\n * or a component like `typeof Button`.\n *\n * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).\n *\n * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,\n * wrap with `NonNullable` (see examples below).\n *\n * @example\n * ```\n * // Intrinsic element examples:\n * Slot<'div'> // Slot is always div\n * Slot<'button', 'a'> // Defaults to button, but allows as=\"a\" with anchor-specific props\n * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as=\"div\" or as=\"pre\"\n * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)\n *\n * // Component examples:\n * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props\n * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)\n * ```\n */\nexport type Slot<\n Type extends keyof JSX.IntrinsicElements | React.ComponentType | React.VoidFunctionComponent | UnknownSlotProps,\n AlternateAs extends keyof JSX.IntrinsicElements = never\n> = IsSingleton<Extract<Type, string>> extends true\n ?\n | WithSlotShorthandValue<\n Type extends keyof JSX.IntrinsicElements // Intrinsic elements like `div`\n ? { as?: Type } & WithSlotRenderFunction<IntrisicElementProps<Type>>\n : Type extends React.ComponentType<infer Props> // Component types like `typeof Button`\n ? WithSlotRenderFunction<Props>\n : Type // Props types like `ButtonProps`\n >\n | {\n [As in AlternateAs]: { as: As } & WithSlotRenderFunction<IntrisicElementProps<As>>;\n }[AlternateAs]\n | null\n : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';\n\n/**\n * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.\n *\n * ```\n * IsSingleton<'a'> // true\n * IsSingleton<'a' | 'b' | 'c'> // false\n * ```\n */\nexport type IsSingleton<T extends string> = { [K in T]: Exclude<T, K> extends never ? true : false }[T];\n\n/**\n * Helper type for inferring the type of the as prop from a Props type.\n *\n * For example:\n * ```\n * type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;\n * ```\n */\nexport type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = { as?: As };\n\n/**\n * Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)\n */\nexport type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;\n\n/**\n * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by\n * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.\n *\n * The conditional \"extends unknown\" (always true) exploits a quirk in the way TypeScript handles conditional\n * types, to prevent unions from being expanded.\n */\nexport type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;\n\n/**\n * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.\n */\nexport type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;\n\n/**\n * Defines the Props type for a component given its slots and the definition of which one is the primary slot,\n * defaulting to root if one is not provided.\n */\nexport type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> =\n // Include a prop for each slot (see note below about the Omit)\n Omit<Slots, Primary & 'root'> &\n // Include all of the props of the primary slot inline in the component's props\n PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;\n\n// Note: the `Omit<Slots, Primary & 'root'>` above is a little tricky. Here's what it's doing:\n// * If the Primary slot is 'root', then omit the `root` slot prop.\n// * Otherwise, don't omit any props: include *both* the Primary and `root` props.\n// We need both props to allow the user to specify native props for either slot because the `root` slot is\n// special and always gets className and style props, per RFC https://github.com/microsoft/fluentui/pull/18983\n\n/**\n * If type T includes `null`, remove it and add `undefined` instead.\n */\nexport type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;\n\n/**\n * Defines the State object of a component given its slots.\n */\nexport type ComponentState<Slots extends SlotPropsRecord> = {\n components: {\n [Key in keyof Slots]-?:\n | React.ComponentType<ExtractSlotProps<Slots[Key]>>\n | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);\n };\n} & {\n // Include a prop for each slot, with the shorthand resolved to a props object\n // The root slot can never be null, so also exclude null from it\n [Key in keyof Slots]: ReplaceNullWithUndefined<\n Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>\n >;\n};\n\n/**\n * This is part of a hack to infer the element type from a native element *props* type.\n * The only place the original element is found in a native props type (at least that's workable\n * for inference) is in the event handlers, so some of the helper types use this event handler\n * name to infer the original element type.\n *\n * Notes:\n * - Using an extremely obscure event handler reduces the likelihood that its signature will be\n * modified in any component's props.\n * - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be\n * less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.\n */\ntype ObscureEventName = 'onLostPointerCaptureCapture';\n\n/**\n * Return type for `React.forwardRef`, including inference of the proper typing for the ref.\n */\nexport type ForwardRefComponent<Props> = ObscureEventName extends keyof Props\n ? Required<Props>[ObscureEventName] extends React.PointerEventHandler<infer Element>\n ? React.ForwardRefExoticComponent<Props & React.RefAttributes<Element>>\n : never\n : never;\n// A definition like this would also work, but typescript is more likely to unnecessarily expand\n// the props type with this version (and it's likely much more expensive to evaluate)\n// export type ForwardRefComponent<Props> = Props extends React.DOMAttributes<infer Element>\n// ? React.ForwardRefExoticComponent<Props> & React.RefAttributes<Element>\n// : never;\n\n/**\n * Helper type to correctly define the slot class names object.\n */\nexport type SlotClassNames<Slots> = {\n [SlotName in keyof Slots]-?: string;\n};\n"]}
|
package/lib/hooks/index.js
CHANGED
@@ -4,7 +4,6 @@ export * from './useFirstMount';
|
|
4
4
|
export * from './useForceUpdate';
|
5
5
|
export * from './useId';
|
6
6
|
export * from './useIsomorphicLayoutEffect';
|
7
|
-
export * from './useMergedEventCallbacks';
|
8
7
|
export * from './useMergedRefs';
|
9
8
|
export * from './useOnClickOutside';
|
10
9
|
export * from './useOnScrollOutside';
|
package/lib/hooks/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC","sourcesContent":["export * from './useControllableState';\nexport * from './useEventCallback';\nexport * from './useFirstMount';\nexport * from './useForceUpdate';\nexport * from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useTimeout';\n"]}
|
package/lib/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export { getSlots, resolveShorthand } from './compose/index';
|
2
|
-
export { resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect,
|
1
|
+
export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';
|
2
|
+
export { resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useTimeout } from './hooks/index';
|
3
3
|
export { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';
|
4
|
-
export { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, shouldPreventDefaultOnKeyDown } from './utils/index';
|
4
|
+
export { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, shouldPreventDefaultOnKeyDown } from './utils/index';
|
5
5
|
export { applyTriggerPropsToChildren, getTriggerChild } from './trigger/index';
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,gBAAnB,
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,gBAAnB,EAAqC,mBAArC,QAAgE,iBAAhE;AAgBA,SACE,gBADF,EAEE,oBAFF,EAGE,gBAHF,EAIE,aAJF,EAKE,cALF,EAME,KANF,EAOE,yBAPF,EAQE,aARF,EASE,iBATF,EAUE,kBAVF,EAWE,WAXF,EAYE,UAZF,QAaO,eAbP;AAgBA,SAAS,SAAT,EAAoB,QAApB,EAA8B,WAA9B,QAAiD,aAAjD;AAEA,SACE,KADF,EAEE,qBAFF,EAGE,yBAHF,EAIE,aAJF,EAKE,cALF,EAME,6BANF,QAOO,eAPP;AASA,SAAS,2BAAT,EAAsC,eAAtC,QAA6D,iBAA7D","sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n shouldPreventDefaultOnKeyDown,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild } from './trigger/index';\n\nexport type { FluentTriggerComponent } from './trigger/index';\n"],"sourceRoot":"../src/"}
|
package/lib/ssr/SSRContext.js
CHANGED
@@ -9,13 +9,15 @@ import { canUseDOM } from './canUseDOM';
|
|
9
9
|
export const defaultSSRContextValue = {
|
10
10
|
current: 0
|
11
11
|
};
|
12
|
-
export const SSRContext = /*#__PURE__*/React.createContext(
|
12
|
+
export const SSRContext = /*#__PURE__*/React.createContext(undefined);
|
13
13
|
/**
|
14
14
|
* @internal
|
15
15
|
*/
|
16
16
|
|
17
17
|
export function useSSRContext() {
|
18
|
-
|
18
|
+
var _a;
|
19
|
+
|
20
|
+
return (_a = React.useContext(SSRContext)) !== null && _a !== void 0 ? _a : defaultSSRContextValue;
|
19
21
|
}
|
20
22
|
/**
|
21
23
|
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
@@ -1 +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;EACrD,OAAO,EAAE;AAD4C,CAAhD;AAIP,OAAO,MAAM,UAAU,gBAAG,KAAK,CAAC,aAAN,
|
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;EACrD,OAAO,EAAE;AAD4C,CAAhD;AAIP,OAAO,MAAM,UAAU,gBAAG,KAAK,CAAC,aAAN,CAAiD,SAAjD,CAAnB;AAEP;;AAEG;;AACH,OAAM,SAAU,aAAV,GAAuB;;;EAC3B,OAAO,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,CAAiB,UAAjB,CAAA,MAA4B,IAA5B,IAA4B,EAAA,KAAA,KAAA,CAA5B,GAA4B,EAA5B,GAAgC,sBAAvC;AACD;AAED;;;;;AAKG;;AACH,OAAO,MAAM,WAAW,GAAa,KAAK,IAAG;EAC3C,MAAM,CAAC,KAAD,IAAU,KAAK,CAAC,QAAN,CAAgC,OAAO;IAAE,OAAO,EAAE;EAAX,CAAP,CAAhC,CAAhB;EAEA,oBAAO,KAAA,CAAA,aAAA,CAAC,UAAU,CAAC,QAAZ,EAAoB;IAAC,KAAK,EAAE;EAAR,CAApB,EAAoC,KAAK,CAAC,QAA1C,CAAP;AACD,CAJM;AAMP;;;AAGG;;AACH,OAAM,SAAU,QAAV,GAAkB;EACtB,MAAM,cAAc,GAAG,aAAa,OAAO,sBAA3C;EACA,MAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAe,cAAf,CAA1B,CAFsB,CAItB;EACA;;EACA,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAI,CAAC,cAAD,IAAmB,CAAC,SAAS,EAAjC,EAAqC;MACnC;MACA,OAAO,CAAC,KAAR,CACE,CACE,8BADF,EAEE,4GACE,0CAHJ,EAIE,IAJF,EAKE,IALF,EAME,oDANF,EAOE,IAPF,CAOO,EAPP,CADF;IAUD;EACF,CApBqB,CAsBtB;EACA;;;EACA,IAAI,SAAS,MAAM,cAAnB,EAAmC;IACjC;IACA;IACA;IACA,KAAK,CAAC,eAAN,CAAsB,MAAK;MACzB,QAAQ,CAAC,KAAD,CAAR;IACD,CAFD,EAEG,EAFH;EAGD;;EAED,OAAO,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 | undefined>(undefined) as React.Context<SSRContextValue>;\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext) ?? defaultSSRContextValue;\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 [\n '@fluentui/react-components: ',\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 'Check documentation at https://aka.ms/fluentui-ssr',\n ].join(''),\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/"}
|
@@ -1,4 +1,4 @@
|
|
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, timeProperties } from './properties';
|
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, timeProperties, dialogProperties } from './properties';
|
2
2
|
const nativeElementMap = {
|
3
3
|
label: labelProperties,
|
4
4
|
audio: audioProperties,
|
@@ -21,7 +21,8 @@ const nativeElementMap = {
|
|
21
21
|
form: formProperties,
|
22
22
|
iframe: iframeProperties,
|
23
23
|
img: imgProperties,
|
24
|
-
time: timeProperties
|
24
|
+
time: timeProperties,
|
25
|
+
dialog: dialogProperties
|
25
26
|
};
|
26
27
|
/**
|
27
28
|
* Given an element tagname and user props, filters the props to only allowed props for the given
|
@@ -1 +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,EAwBE,cAxBF,
|
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,EAwBE,cAxBF,EAyBE,gBAzBF,QA0BO,cA1BP;AA4BA,MAAM,gBAAgB,GAA2C;EAC/D,KAAK,EAAE,eADwD;EAE/D,KAAK,EAAE,eAFwD;EAG/D,KAAK,EAAE,eAHwD;EAI/D,EAAE,EAAE,YAJ2D;EAK/D,EAAE,EAAE,YAL2D;EAM/D,CAAC,EAAE,gBAN4D;EAO/D,MAAM,EAAE,gBAPuD;EAQ/D,KAAK,EAAE,eARwD;EAS/D,QAAQ,EAAE,kBATqD;EAU/D,MAAM,EAAE,gBAVuD;EAW/D,MAAM,EAAE,gBAXuD;EAY/D,KAAK,EAAE,eAZwD;EAa/D,EAAE,EAAE,YAb2D;EAc/D,EAAE,EAAE,YAd2D;EAe/D,EAAE,EAAE,YAf2D;EAgB/D,QAAQ,EAAE,kBAhBqD;EAiB/D,GAAG,EAAE,aAjB0D;EAkB/D,QAAQ,EAAE,kBAlBqD;EAmB/D,IAAI,EAAE,cAnByD;EAoB/D,MAAM,EAAE,gBApBuD;EAqB/D,GAAG,EAAE,aArB0D;EAsB/D,IAAI,EAAE,cAtByD;EAuB/D,MAAM,EAAE;AAvBuD,CAAjE;AA0BA;;;;;;AAMG;AACH;;AACA,OAAM,SAAU,qBAAV,CACJ,OADI,EAEJ,KAFI,EAGJ,iBAHI,EAGwB;EAE5B,MAAM,gBAAgB,GAAI,OAAO,IAAI,gBAAgB,CAAC,OAAD,CAA5B,IAA0C,qBAAnE;EACA,gBAAgB,CAAC,EAAjB,GAAsB,CAAtB;EAEA,OAAO,cAAc,CAAC,KAAD,EAAQ,gBAAR,EAA0B,iBAA1B,CAArB;AACD;AAED;;;;;;;AAOG;;AACH,OAAO,MAAM,yBAAyB,GAAG,CAGvC;EACA,kBADA;EAEA,KAFA;EAGA;AAHA,CAHuC,KAgBpC;EACH,OAAO;IACL,IAAI,EAAE;MAAE,KAAK,EAAE,KAAK,CAAC,KAAf;MAAsB,SAAS,EAAE,KAAK,CAAC;IAAvC,CADD;IAEL,OAAO,EAAE,qBAAqB,CAAgC,kBAAhC,EAAoD,KAApD,EAA2D,CACvF,IAAI,iBAAiB,IAAI,EAAzB,CADuF,EAEvF,OAFuF,EAGvF,WAHuF,CAA3D;EAFzB,CAAP;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 timeProperties,\n dialogProperties,\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 time: timeProperties,\n dialog: dialogProperties,\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/"}
|
package/lib/utils/index.js
CHANGED
package/lib/utils/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iCAAiC,CAAC","sourcesContent":["export * from './clamp';\nexport * from './getNativeElementProps';\nexport * from './getRTLSafeKey';\nexport * from './omit';\nexport * from './properties';\nexport * from './shouldPreventDefaultOnKeyDown';\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iCAAiC,CAAC","sourcesContent":["export * from './clamp';\nexport * from './getNativeElementProps';\nexport * from './getRTLSafeKey';\nexport * from './mergeCallbacks';\nexport * from './omit';\nexport * from './properties';\nexport * from './shouldPreventDefaultOnKeyDown';\n"]}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/**
|
2
|
+
* @internal
|
3
|
+
* Combine two event callbacks into a single callback function that calls each one in order.
|
4
|
+
*
|
5
|
+
* Usage example:
|
6
|
+
* ```ts
|
7
|
+
* state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {
|
8
|
+
* // Handle onChange
|
9
|
+
* });
|
10
|
+
* ```
|
11
|
+
*
|
12
|
+
* The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a
|
13
|
+
* local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:
|
14
|
+
* * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.
|
15
|
+
* * Missing a call to the original onChange due to an early return or other conditional.
|
16
|
+
*
|
17
|
+
* If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.
|
18
|
+
*
|
19
|
+
* @param callback1 - The first callback to be called, or undefined
|
20
|
+
* @param callback2 - The second callback to be called, or undefined
|
21
|
+
*
|
22
|
+
* @returns A function that that calls the provided functions in order
|
23
|
+
*/
|
24
|
+
export function mergeCallbacks(callback1, callback2) {
|
25
|
+
return (...args) => {
|
26
|
+
callback1 === null || callback1 === void 0 ? void 0 : callback1(...args);
|
27
|
+
callback2 === null || callback2 === void 0 ? void 0 : callback2(...args);
|
28
|
+
};
|
29
|
+
}
|
30
|
+
//# sourceMappingURL=mergeCallbacks.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils/mergeCallbacks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACH,OAAM,SAAU,cAAV,CACJ,SADI,EAEJ,SAFI,EAE4C;EAEhD,OAAO,CAAC,GAAG,IAAJ,KAAkB;IACvB,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;IACA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;EACD,CAHD;AAID","sourcesContent":["/**\n * @internal\n * Combine two event callbacks into a single callback function that calls each one in order.\n *\n * Usage example:\n * ```ts\n * state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {\n * // Handle onChange\n * });\n * ```\n *\n * The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a\n * local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:\n * * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.\n * * Missing a call to the original onChange due to an early return or other conditional.\n *\n * If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.\n *\n * @param callback1 - The first callback to be called, or undefined\n * @param callback2 - The second callback to be called, or undefined\n *\n * @returns A function that that calls the provided functions in order\n */\nexport function mergeCallbacks<Args extends unknown[]>(\n callback1: ((...args: Args) => void) | undefined,\n callback2: ((...args: Args) => void) | undefined,\n) {\n return (...args: Args) => {\n callback1?.(...args);\n callback2?.(...args);\n };\n}\n"],"sourceRoot":"../src/"}
|
package/lib/utils/properties.js
CHANGED
@@ -27,13 +27,21 @@ export const baseElementEvents = /*#__PURE__*/toObjectMap(['onAuxClick', 'onCopy
|
|
27
27
|
|
28
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
29
|
]);
|
30
|
+
/**
|
31
|
+
* An array of microdata attributes that are allowed on every html element type.
|
32
|
+
*
|
33
|
+
* @public
|
34
|
+
*/
|
35
|
+
|
36
|
+
export const microdataProperties = /*#__PURE__*/toObjectMap(['itemID', 'itemProp', 'itemRef', 'itemScope', 'itemType' // global
|
37
|
+
]);
|
30
38
|
/**
|
31
39
|
* An array of HTML element properties and events.
|
32
40
|
*
|
33
41
|
* @public
|
34
42
|
*/
|
35
43
|
|
36
|
-
export const htmlElementProperties = /*#__PURE__*/toObjectMap(baseElementProperties, baseElementEvents);
|
44
|
+
export const htmlElementProperties = /*#__PURE__*/toObjectMap(baseElementProperties, baseElementEvents, microdataProperties);
|
37
45
|
/**
|
38
46
|
* An array of LABEL tag properties and events.
|
39
47
|
*
|
@@ -191,6 +199,13 @@ export const iframeProperties = /*#__PURE__*/toObjectMap(htmlElementProperties,
|
|
191
199
|
|
192
200
|
export const imgProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['alt', 'crossOrigin', 'height', 'src', 'srcSet', 'useMap', 'width' // canvas, embed, iframe, img, input, object, video
|
193
201
|
]);
|
202
|
+
/**
|
203
|
+
* An array of DIALOG tag properties and events.
|
204
|
+
*
|
205
|
+
* @public
|
206
|
+
*/
|
207
|
+
|
208
|
+
export const dialogProperties = /*#__PURE__*/toObjectMap(htmlElementProperties, ['open', 'onCancel', 'onClose']);
|
194
209
|
/**
|
195
210
|
* An array of DIV tag properties and events.
|
196
211
|
*
|