@fluentui/react-utilities 0.0.0-nightlyff78d1e27a20220217.1 → 0.0.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 +232 -7
- package/CHANGELOG.md +159 -73
- package/dist/{react-utilities.d.ts → index.d.ts} +39 -272
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/compose/types.js +1 -5
- package/lib/compose/types.js.map +1 -1
- package/lib/hooks/index.js +1 -5
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useControllableState.js +3 -2
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js +1 -0
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js +1 -0
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js +1 -0
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js +9 -5
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js +1 -0
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedEventCallbacks.js +1 -0
- package/lib/hooks/useMergedEventCallbacks.js.map +1 -1
- package/lib/hooks/useMergedRefs.js +1 -0
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js +2 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js +1 -0
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js +4 -0
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useTimeout.js +2 -2
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js +5 -4
- package/lib/index.js.map +1 -1
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/ssr/canUseDOM.js.map +1 -1
- package/lib/{utils → trigger}/applyTriggerPropsToChildren.js +1 -0
- package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -0
- package/lib/{utils → trigger}/getTriggerChild.js +2 -0
- package/lib/trigger/getTriggerChild.js.map +1 -0
- package/lib/trigger/index.js +5 -0
- package/lib/trigger/index.js.map +1 -0
- package/lib/{utils → trigger}/isFluentTrigger.js +0 -0
- package/lib/trigger/isFluentTrigger.js.map +1 -0
- package/lib/trigger/types.js +2 -0
- package/lib/trigger/types.js.map +1 -0
- package/lib/utils/clamp.js +1 -0
- package/lib/utils/clamp.js.map +1 -1
- package/lib/utils/getNativeElementProps.js +4 -2
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getRTLSafeKey.js +1 -0
- package/lib/utils/getRTLSafeKey.js.map +1 -1
- package/lib/utils/getReactCallbackName.js.map +1 -1
- package/lib/utils/index.js +0 -3
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/properties.js +18 -6
- package/lib/utils/properties.js.map +1 -1
- package/lib/utils/shouldPreventDefaultOnKeyDown.js +5 -0
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/compose/types.js +1 -5
- package/lib-commonjs/compose/types.js.map +1 -1
- package/lib-commonjs/hooks/index.js +2 -10
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js +3 -3
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js +1 -0
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js +1 -0
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js +1 -0
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js +9 -5
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +1 -0
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedEventCallbacks.js +1 -0
- package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js +1 -0
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js +2 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js +1 -0
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js +4 -0
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js +2 -3
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js +161 -5
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
- package/lib-commonjs/{utils → trigger}/applyTriggerPropsToChildren.js +1 -0
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -0
- package/lib-commonjs/{utils → trigger}/getTriggerChild.js +2 -0
- package/lib-commonjs/trigger/getTriggerChild.js.map +1 -0
- package/lib-commonjs/trigger/index.js +16 -0
- package/lib-commonjs/trigger/index.js.map +1 -0
- package/lib-commonjs/{utils → trigger}/isFluentTrigger.js +0 -0
- package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -0
- package/lib-commonjs/trigger/types.js +6 -0
- package/lib-commonjs/trigger/types.js.map +1 -0
- package/lib-commonjs/utils/clamp.js +1 -0
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js +3 -1
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js +1 -0
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
- package/lib-commonjs/utils/index.js +0 -6
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/properties.js +19 -7
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +5 -0
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/package.json +13 -13
- package/lib/compose/getSlots.d.ts +0 -30
- package/lib/compose/index.d.ts +0 -3
- package/lib/compose/resolveShorthand.d.ts +0 -16
- package/lib/compose/types.d.ts +0 -155
- package/lib/hooks/index.d.ts +0 -16
- package/lib/hooks/useBoolean.d.ts +0 -17
- package/lib/hooks/useBoolean.js +0 -28
- package/lib/hooks/useBoolean.js.map +0 -1
- package/lib/hooks/useConst.d.ts +0 -12
- package/lib/hooks/useConst.js +0 -30
- package/lib/hooks/useConst.js.map +0 -1
- package/lib/hooks/useControllableState.d.ts +0 -31
- package/lib/hooks/useEventCallback.d.ts +0 -13
- package/lib/hooks/useFirstMount.d.ts +0 -11
- package/lib/hooks/useForceUpdate.d.ts +0 -4
- package/lib/hooks/useId.d.ts +0 -15
- package/lib/hooks/useIsomorphicLayoutEffect.d.ts +0 -11
- package/lib/hooks/useMergedEventCallbacks.d.ts +0 -18
- package/lib/hooks/useMergedRefs.d.ts +0 -13
- package/lib/hooks/useMount.d.ts +0 -6
- package/lib/hooks/useMount.js +0 -17
- package/lib/hooks/useMount.js.map +0 -1
- package/lib/hooks/useOnClickOutside.d.ts +0 -29
- package/lib/hooks/useOnScrollOutside.d.ts +0 -5
- package/lib/hooks/usePrevious.d.ts +0 -1
- package/lib/hooks/useTimeout.d.ts +0 -8
- package/lib/hooks/useUnmount.d.ts +0 -6
- package/lib/hooks/useUnmount.js +0 -17
- package/lib/hooks/useUnmount.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/ssr/SSRContext.d.ts +0 -33
- package/lib/ssr/canUseDOM.d.ts +0 -4
- package/lib/ssr/index.d.ts +0 -2
- package/lib/utils/applyTriggerPropsToChildren.d.ts +0 -5
- package/lib/utils/applyTriggerPropsToChildren.js.map +0 -1
- package/lib/utils/clamp.d.ts +0 -8
- package/lib/utils/getNativeElementProps.d.ts +0 -31
- package/lib/utils/getRTLSafeKey.d.ts +0 -4
- package/lib/utils/getReactCallbackName.d.ts +0 -25
- package/lib/utils/getTriggerChild.d.ts +0 -22
- package/lib/utils/getTriggerChild.js.map +0 -1
- package/lib/utils/index.d.ts +0 -9
- package/lib/utils/isFluentTrigger.d.ts +0 -22
- package/lib/utils/isFluentTrigger.js.map +0 -1
- package/lib/utils/omit.d.ts +0 -14
- package/lib/utils/properties.d.ts +0 -148
- package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +0 -7
- package/lib-commonjs/compose/getSlots.d.ts +0 -30
- package/lib-commonjs/compose/index.d.ts +0 -3
- package/lib-commonjs/compose/resolveShorthand.d.ts +0 -16
- package/lib-commonjs/compose/types.d.ts +0 -155
- package/lib-commonjs/hooks/index.d.ts +0 -16
- package/lib-commonjs/hooks/useBoolean.d.ts +0 -17
- package/lib-commonjs/hooks/useBoolean.js +0 -39
- package/lib-commonjs/hooks/useBoolean.js.map +0 -1
- package/lib-commonjs/hooks/useConst.d.ts +0 -12
- package/lib-commonjs/hooks/useConst.js +0 -40
- package/lib-commonjs/hooks/useConst.js.map +0 -1
- package/lib-commonjs/hooks/useControllableState.d.ts +0 -31
- package/lib-commonjs/hooks/useEventCallback.d.ts +0 -13
- package/lib-commonjs/hooks/useFirstMount.d.ts +0 -11
- package/lib-commonjs/hooks/useForceUpdate.d.ts +0 -4
- package/lib-commonjs/hooks/useId.d.ts +0 -15
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +0 -11
- package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +0 -18
- package/lib-commonjs/hooks/useMergedRefs.d.ts +0 -13
- package/lib-commonjs/hooks/useMount.d.ts +0 -6
- package/lib-commonjs/hooks/useMount.js +0 -27
- package/lib-commonjs/hooks/useMount.js.map +0 -1
- package/lib-commonjs/hooks/useOnClickOutside.d.ts +0 -29
- package/lib-commonjs/hooks/useOnScrollOutside.d.ts +0 -5
- package/lib-commonjs/hooks/usePrevious.d.ts +0 -1
- package/lib-commonjs/hooks/useTimeout.d.ts +0 -8
- package/lib-commonjs/hooks/useUnmount.d.ts +0 -6
- package/lib-commonjs/hooks/useUnmount.js +0 -27
- package/lib-commonjs/hooks/useUnmount.js.map +0 -1
- package/lib-commonjs/index.d.ts +0 -4
- package/lib-commonjs/ssr/SSRContext.d.ts +0 -33
- package/lib-commonjs/ssr/canUseDOM.d.ts +0 -4
- package/lib-commonjs/ssr/index.d.ts +0 -2
- package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +0 -5
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +0 -1
- package/lib-commonjs/utils/clamp.d.ts +0 -8
- package/lib-commonjs/utils/getNativeElementProps.d.ts +0 -31
- package/lib-commonjs/utils/getRTLSafeKey.d.ts +0 -4
- package/lib-commonjs/utils/getReactCallbackName.d.ts +0 -25
- package/lib-commonjs/utils/getTriggerChild.d.ts +0 -22
- package/lib-commonjs/utils/getTriggerChild.js.map +0 -1
- package/lib-commonjs/utils/index.d.ts +0 -9
- package/lib-commonjs/utils/isFluentTrigger.d.ts +0 -22
- package/lib-commonjs/utils/isFluentTrigger.js.map +0 -1
- package/lib-commonjs/utils/omit.d.ts +0 -14
- package/lib-commonjs/utils/properties.d.ts +0 -148
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +0 -7
@@ -2,13 +2,7 @@ import { DispatchWithoutAction } from 'react';
|
|
2
2
|
import * as React_2 from 'react';
|
3
3
|
|
4
4
|
/**
|
5
|
-
*
|
6
|
-
*
|
7
|
-
* @public
|
8
|
-
*/
|
9
|
-
export declare const anchorProperties: Record<string, number>;
|
10
|
-
|
11
|
-
/**
|
5
|
+
* @internal
|
12
6
|
* Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
|
13
7
|
*/
|
14
8
|
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>> | ((props: TTriggerProps) => React_2.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React_2.ReactElement | null;
|
@@ -21,44 +15,17 @@ export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: Reac
|
|
21
15
|
* type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;
|
22
16
|
* ```
|
23
17
|
*/
|
24
|
-
|
18
|
+
declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = {
|
25
19
|
as?: As;
|
26
20
|
};
|
27
21
|
|
28
|
-
/**
|
29
|
-
* An array of AUDIO tag properties and events.
|
30
|
-
|
31
|
-
* @public
|
32
|
-
*/
|
33
|
-
export declare const audioProperties: Record<string, number>;
|
34
|
-
|
35
|
-
/**
|
36
|
-
* An array of events that are allowed on every html element type.
|
37
|
-
*
|
38
|
-
* @public
|
39
|
-
*/
|
40
|
-
export declare const baseElementEvents: Record<string, number>;
|
41
|
-
|
42
|
-
/**
|
43
|
-
* An array of element attributes which are allowed on every html element type.
|
44
|
-
*
|
45
|
-
* @public
|
46
|
-
*/
|
47
|
-
export declare const baseElementProperties: Record<string, number>;
|
48
|
-
|
49
|
-
/**
|
50
|
-
* An array of BUTTON tag properties and events.
|
51
|
-
*
|
52
|
-
* @public
|
53
|
-
*/
|
54
|
-
export declare const buttonProperties: Record<string, number>;
|
55
|
-
|
56
22
|
/**
|
57
23
|
* Verifies if an application can use DOM.
|
58
24
|
*/
|
59
25
|
export declare function canUseDOM(): boolean;
|
60
26
|
|
61
27
|
/**
|
28
|
+
* @internal
|
62
29
|
* Clamps `value` to a number between the min and max.
|
63
30
|
*
|
64
31
|
* @param value - the value to be clamped
|
@@ -67,10 +34,6 @@ export declare function canUseDOM(): boolean;
|
|
67
34
|
*/
|
68
35
|
export declare const clamp: (value: number, min: number, max: number) => number;
|
69
36
|
|
70
|
-
export declare const colGroupProperties: Record<string, number>;
|
71
|
-
|
72
|
-
export declare const colProperties: Record<string, number>;
|
73
|
-
|
74
37
|
/**
|
75
38
|
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
|
76
39
|
* defaulting to root if one is not provided.
|
@@ -88,20 +51,6 @@ export declare type ComponentState<Slots extends SlotPropsRecord> = {
|
|
88
51
|
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
|
89
52
|
};
|
90
53
|
|
91
|
-
/**
|
92
|
-
* Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
|
93
|
-
*
|
94
|
-
* @internal
|
95
|
-
*/
|
96
|
-
export declare const defaultSSRContextValue: SSRContextValue;
|
97
|
-
|
98
|
-
/**
|
99
|
-
* An array of DIV tag properties and events.
|
100
|
-
*
|
101
|
-
* @public
|
102
|
-
*/
|
103
|
-
export declare const divProperties: Record<string, number>;
|
104
|
-
|
105
54
|
/**
|
106
55
|
* HTML element types that are not allowed to have children.
|
107
56
|
*
|
@@ -115,6 +64,7 @@ declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' |
|
|
115
64
|
export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
|
116
65
|
|
117
66
|
/**
|
67
|
+
* @internal
|
118
68
|
* Allows a component to be tagged as a FluentUI trigger component.
|
119
69
|
*
|
120
70
|
* Triggers are special-case components: they attach event listeners and other props on their child,
|
@@ -131,13 +81,6 @@ export declare type FluentTriggerComponent = {
|
|
131
81
|
isFluentTriggerComponent?: boolean;
|
132
82
|
};
|
133
83
|
|
134
|
-
/**
|
135
|
-
* An array of FORM tag properties and events.
|
136
|
-
*
|
137
|
-
* @public
|
138
|
-
*/
|
139
|
-
export declare const formProperties: Record<string, number>;
|
140
|
-
|
141
84
|
/**
|
142
85
|
* Return type for `React.forwardRef`, including inference of the proper typing for the ref.
|
143
86
|
*/
|
@@ -152,22 +95,6 @@ export declare type ForwardRefComponent<Props> = ObscureEventName extends keyof
|
|
152
95
|
*/
|
153
96
|
export declare function getNativeElementProps<TAttributes extends React_2.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
|
154
97
|
|
155
|
-
/**
|
156
|
-
* Gets native supported props for an html element provided the allowance set. Use one of the property
|
157
|
-
* sets defined (divProperties, buttonPropertes, etc) to filter out supported properties from a given
|
158
|
-
* props set. Note that all data- and aria- prefixed attributes will be allowed.
|
159
|
-
* NOTE: getNativeProps should always be applied first when adding props to a react component. The
|
160
|
-
* non-native props should be applied second. This will prevent getNativeProps from overriding your custom props.
|
161
|
-
* For example, if props passed to getNativeProps has an onClick function and getNativeProps is added to
|
162
|
-
* the component after an onClick function is added, then the getNativeProps onClick will override it.
|
163
|
-
*
|
164
|
-
* @public
|
165
|
-
* @param props - The unfiltered input props
|
166
|
-
* @param allowedPropsNames - The array or record of allowed prop names.
|
167
|
-
* @returns The filtered props
|
168
|
-
*/
|
169
|
-
export declare function getNativeProps<T extends Record<string, any>>(props: Record<string, any>, allowedPropNames: string[] | Record<string, number>, excludedPropNames?: string[]): T;
|
170
|
-
|
171
98
|
/**
|
172
99
|
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
|
173
100
|
*
|
@@ -192,6 +119,7 @@ export declare const getPartitionedNativeProps: <Props extends Pick<React_2.HTML
|
|
192
119
|
};
|
193
120
|
|
194
121
|
/**
|
122
|
+
* @internal
|
195
123
|
* Finds and swaps a provided key for it's right to left format.
|
196
124
|
*/
|
197
125
|
export declare const getRTLSafeKey: (key: string, dir: 'ltr' | 'rtl') => string;
|
@@ -219,6 +147,7 @@ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentStat
|
|
219
147
|
};
|
220
148
|
|
221
149
|
/**
|
150
|
+
* @internal
|
222
151
|
* Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
|
223
152
|
*
|
224
153
|
* In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
|
@@ -236,43 +165,10 @@ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentStat
|
|
236
165
|
* );
|
237
166
|
* ```
|
238
167
|
*/
|
239
|
-
export declare const getTriggerChild: (children: React_2.ReactNode) => React_2.ReactElement & {
|
240
|
-
ref?: React_2.Ref<unknown
|
168
|
+
export declare const getTriggerChild: <P = any>(children: React_2.ReactNode) => React_2.ReactElement<P, string | React_2.JSXElementConstructor<any>> & {
|
169
|
+
ref?: React_2.Ref<unknown> | undefined;
|
241
170
|
};
|
242
171
|
|
243
|
-
/**
|
244
|
-
* An array of HTML element properties and events.
|
245
|
-
*
|
246
|
-
* @public
|
247
|
-
*/
|
248
|
-
export declare const htmlElementProperties: Record<string, number>;
|
249
|
-
|
250
|
-
/**
|
251
|
-
* An array of IFRAME tag properties and events.
|
252
|
-
*
|
253
|
-
* @public
|
254
|
-
*/
|
255
|
-
export declare const iframeProperties: Record<string, number>;
|
256
|
-
|
257
|
-
/**
|
258
|
-
* @deprecated Use imgProperties for img elements.
|
259
|
-
*/
|
260
|
-
export declare const imageProperties: Record<string, number>;
|
261
|
-
|
262
|
-
/**
|
263
|
-
* An array of IMAGE tag properties and events.
|
264
|
-
*
|
265
|
-
* @public
|
266
|
-
*/
|
267
|
-
export declare const imgProperties: Record<string, number>;
|
268
|
-
|
269
|
-
/**
|
270
|
-
* An array of INPUT tag properties and events.
|
271
|
-
*
|
272
|
-
* @public
|
273
|
-
*/
|
274
|
-
export declare const inputProperties: Record<string, number>;
|
275
|
-
|
276
172
|
/**
|
277
173
|
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
|
278
174
|
* * Removes legacy string ref.
|
@@ -282,12 +178,6 @@ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = Re
|
|
282
178
|
children?: never;
|
283
179
|
} : {});
|
284
180
|
|
285
|
-
/**
|
286
|
-
* Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
|
287
|
-
* See the {@link FluentTriggerComponent} type for more info.
|
288
|
-
*/
|
289
|
-
export declare const isFluentTrigger: (element: React_2.ReactElement) => boolean | undefined;
|
290
|
-
|
291
181
|
/**
|
292
182
|
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
|
293
183
|
*
|
@@ -296,24 +186,10 @@ export declare const isFluentTrigger: (element: React_2.ReactElement) => boolean
|
|
296
186
|
* IsSingleton<'a' | 'b' | 'c'> // false
|
297
187
|
* ```
|
298
188
|
*/
|
299
|
-
|
189
|
+
declare type IsSingleton<T extends string> = {
|
300
190
|
[K in T]: Exclude<T, K> extends never ? true : false;
|
301
191
|
}[T];
|
302
192
|
|
303
|
-
/**
|
304
|
-
* An array of LABEL tag properties and events.
|
305
|
-
*
|
306
|
-
* @public
|
307
|
-
*/
|
308
|
-
export declare const labelProperties: Record<string, number>;
|
309
|
-
|
310
|
-
/**
|
311
|
-
* An array of LI tag properties and events.
|
312
|
-
*
|
313
|
-
* @public
|
314
|
-
*/
|
315
|
-
export declare const liProperties: Record<string, number>;
|
316
|
-
|
317
193
|
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
318
194
|
[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;
|
319
195
|
};
|
@@ -332,30 +208,6 @@ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
|
332
208
|
*/
|
333
209
|
declare type ObscureEventName = 'onLostPointerCaptureCapture';
|
334
210
|
|
335
|
-
/**
|
336
|
-
* An array of OL tag properties and events.
|
337
|
-
*
|
338
|
-
* @public
|
339
|
-
*/
|
340
|
-
export declare const olProperties: Record<string, number>;
|
341
|
-
|
342
|
-
/**
|
343
|
-
* Tiny helper to do the minimal amount of work in duplicating an object but omitting some
|
344
|
-
* props. This ends up faster than using object ...rest or reduce to filter.
|
345
|
-
*
|
346
|
-
* This behaves very much like filteredAssign, but does not merge many objects together,
|
347
|
-
* uses an exclusion object map, and avoids spreads all for optimal performance.
|
348
|
-
*
|
349
|
-
* See perf test for background:
|
350
|
-
* https://jsperf.com/omit-vs-rest-vs-reduce/1
|
351
|
-
*
|
352
|
-
* @param obj - The object to clone
|
353
|
-
* @param exclusions - The array of keys to exclude
|
354
|
-
*/
|
355
|
-
export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
|
356
|
-
|
357
|
-
export declare const optionProperties: Record<string, number>;
|
358
|
-
|
359
211
|
/**
|
360
212
|
* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
|
361
213
|
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
|
@@ -363,9 +215,10 @@ export declare const optionProperties: Record<string, number>;
|
|
363
215
|
* The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
|
364
216
|
* types, to prevent unions from being expanded.
|
365
217
|
*/
|
366
|
-
|
218
|
+
declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
|
367
219
|
|
368
220
|
/**
|
221
|
+
* @internal
|
369
222
|
* A Ref function which can be treated like a ref object in that it has an attached
|
370
223
|
* current property, which will be updated as the ref is evaluated.
|
371
224
|
*/
|
@@ -374,12 +227,10 @@ export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) =>
|
|
374
227
|
/**
|
375
228
|
* If type T includes `null`, remove it and add `undefined` instead.
|
376
229
|
*/
|
377
|
-
|
230
|
+
declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
|
378
231
|
|
379
232
|
/**
|
380
233
|
* Resets generated IDs, should be used only in tests.
|
381
|
-
*
|
382
|
-
* @private
|
383
234
|
*/
|
384
235
|
export declare function resetIdsForTests(): void;
|
385
236
|
|
@@ -402,13 +253,7 @@ export declare type ResolveShorthandOptions<Props, Required extends boolean = fa
|
|
402
253
|
};
|
403
254
|
|
404
255
|
/**
|
405
|
-
*
|
406
|
-
*
|
407
|
-
* @public
|
408
|
-
*/
|
409
|
-
export declare const selectProperties: Record<string, number>;
|
410
|
-
|
411
|
-
/**
|
256
|
+
* @internal
|
412
257
|
* Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
|
413
258
|
*
|
414
259
|
* Useful for situations where a keydown needs to be transformed to a click event
|
@@ -437,7 +282,7 @@ export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React_2
|
|
437
282
|
* NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
|
438
283
|
* ```
|
439
284
|
*/
|
440
|
-
export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
|
285
|
+
export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.ComponentType | React_2.VoidFunctionComponent | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
|
441
286
|
as?: Type;
|
442
287
|
} & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
|
443
288
|
[As in AlternateAs]: {
|
@@ -445,6 +290,13 @@ export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.Comp
|
|
445
290
|
} & WithSlotRenderFunction<IntrisicElementProps<As>>;
|
446
291
|
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
|
447
292
|
|
293
|
+
/**
|
294
|
+
* Helper type to correctly define the slot class names object.
|
295
|
+
*/
|
296
|
+
export declare type SlotClassNames<Slots> = {
|
297
|
+
[SlotName in keyof Slots]-?: string;
|
298
|
+
};
|
299
|
+
|
448
300
|
/**
|
449
301
|
* Matches any component's Slots type (such as ButtonSlots).
|
450
302
|
*
|
@@ -464,18 +316,6 @@ export declare type Slots<S extends SlotPropsRecord> = {
|
|
464
316
|
*/
|
465
317
|
export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal;
|
466
318
|
|
467
|
-
export declare const SSRContext: React_2.Context<SSRContextValue>;
|
468
|
-
|
469
|
-
/**
|
470
|
-
* To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request
|
471
|
-
* to ensure the client and server are consistent.
|
472
|
-
*
|
473
|
-
* @internal
|
474
|
-
*/
|
475
|
-
export declare type SSRContextValue = {
|
476
|
-
current: number;
|
477
|
-
};
|
478
|
-
|
479
319
|
/**
|
480
320
|
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
481
321
|
* are consistent between the client and server.
|
@@ -484,45 +324,10 @@ export declare type SSRContextValue = {
|
|
484
324
|
*/
|
485
325
|
export declare const SSRProvider: React_2.FC;
|
486
326
|
|
487
|
-
/**
|
488
|
-
* An array of TABLE tag properties and events.
|
489
|
-
*
|
490
|
-
* @public
|
491
|
-
*/
|
492
|
-
export declare const tableProperties: Record<string, number>;
|
493
|
-
|
494
|
-
/**
|
495
|
-
* An array of TD tag properties and events.
|
496
|
-
*
|
497
|
-
* @public
|
498
|
-
*/
|
499
|
-
export declare const tdProperties: Record<string, number>;
|
500
|
-
|
501
|
-
/**
|
502
|
-
* An array of TEXTAREA tag properties and events.
|
503
|
-
*
|
504
|
-
* @public
|
505
|
-
*/
|
506
|
-
export declare const textAreaProperties: Record<string, number>;
|
507
|
-
|
508
|
-
/**
|
509
|
-
* An array of TH tag properties and events.
|
510
|
-
*
|
511
|
-
* @public
|
512
|
-
*/
|
513
|
-
export declare const thProperties: Record<string, number>;
|
514
|
-
|
515
|
-
/**
|
516
|
-
* An array of TR tag properties and events.
|
517
|
-
*
|
518
|
-
* @public
|
519
|
-
*/
|
520
|
-
export declare const trProperties: Record<string, number>;
|
521
|
-
|
522
327
|
/**
|
523
328
|
* Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
|
524
329
|
*/
|
525
|
-
|
330
|
+
declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
|
526
331
|
|
527
332
|
/**
|
528
333
|
* Matches any slot props type.
|
@@ -530,43 +335,13 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U :
|
|
530
335
|
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
|
531
336
|
* it shouldn't be used as the type of a slot.
|
532
337
|
*/
|
533
|
-
|
338
|
+
declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
534
339
|
as?: keyof JSX.IntrinsicElements;
|
535
340
|
};
|
536
341
|
|
537
342
|
/**
|
538
|
-
*
|
539
|
-
* The identity of the callbacks will always stay the same.
|
540
|
-
*
|
541
|
-
* @param initialState - Initial value
|
542
|
-
* @returns Array with the current value and an object containing the updater callbacks.
|
543
|
-
*/
|
544
|
-
export declare function useBoolean(initialState: boolean): [boolean, UseBooleanCallbacks];
|
545
|
-
|
546
|
-
/** Updater callbacks returned by `useBoolean`. */
|
547
|
-
export declare type UseBooleanCallbacks = {
|
548
|
-
/** Set the value to true. Always has the same identity. */
|
549
|
-
setTrue: () => void;
|
550
|
-
/** Set the value to false. Always has the same identity. */
|
551
|
-
setFalse: () => void;
|
552
|
-
/** Toggle the value. Always has the same identity. */
|
553
|
-
toggle: () => void;
|
554
|
-
};
|
555
|
-
|
556
|
-
/**
|
557
|
-
* Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
|
558
|
-
* always return the same value (and if the initializer is a function, only call it once).
|
559
|
-
* This is similar to setting a private member in a class constructor.
|
560
|
-
*
|
561
|
-
* If the value should ever change based on dependencies, use `React.useMemo` instead.
|
343
|
+
* @internal
|
562
344
|
*
|
563
|
-
* @param initialValue - Initial value, or function to get the initial value. Similar to `useState`,
|
564
|
-
* only the value/function passed in the first time this is called is respected.
|
565
|
-
* @returns The value. The identity of this value will always be the same.
|
566
|
-
*/
|
567
|
-
export declare function useConst<T>(initialValue: T | (() => T)): T;
|
568
|
-
|
569
|
-
/**
|
570
345
|
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
571
346
|
* such as a checked state or text input string.
|
572
347
|
*
|
@@ -582,6 +357,9 @@ export declare function useConst<T>(initialValue: T | (() => T)): T;
|
|
582
357
|
*/
|
583
358
|
export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React_2.Dispatch<React_2.SetStateAction<State>>];
|
584
359
|
|
360
|
+
/**
|
361
|
+
* @internal
|
362
|
+
*/
|
585
363
|
export declare type UseControllableStateOptions<State> = {
|
586
364
|
/**
|
587
365
|
* User-provided default state or initializer, for uncontrolled usage.
|
@@ -599,6 +377,7 @@ export declare type UseControllableStateOptions<State> = {
|
|
599
377
|
};
|
600
378
|
|
601
379
|
/**
|
380
|
+
* @internal
|
602
381
|
* https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
|
603
382
|
*
|
604
383
|
* Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
|
@@ -613,6 +392,7 @@ export declare type UseControllableStateOptions<State> = {
|
|
613
392
|
export declare const useEventCallback: <Args extends unknown[], Return>(fn: (...args: Args) => Return) => (...args: Args) => Return;
|
614
393
|
|
615
394
|
/**
|
395
|
+
* @internal
|
616
396
|
* Checks if components was mounted the first time.
|
617
397
|
* Since concurrent mode will be released in the future this needs to be verified
|
618
398
|
* Currently (React 17) will always render the initial mount once
|
@@ -625,6 +405,7 @@ export declare const useEventCallback: <Args extends unknown[], Return>(fn: (...
|
|
625
405
|
export declare function useFirstMount(): boolean;
|
626
406
|
|
627
407
|
/**
|
408
|
+
* @internal
|
628
409
|
* Forces a re-render, similar to `forceUpdate` in class components.
|
629
410
|
*/
|
630
411
|
export declare function useForceUpdate(): DispatchWithoutAction;
|
@@ -632,7 +413,7 @@ export declare function useForceUpdate(): DispatchWithoutAction;
|
|
632
413
|
/**
|
633
414
|
* Hook to generate a unique ID.
|
634
415
|
*
|
635
|
-
* @param prefix - Optional prefix for the ID
|
416
|
+
* @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
|
636
417
|
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
637
418
|
* without conditioning the hook call
|
638
419
|
* @returns The ID
|
@@ -640,6 +421,7 @@ export declare function useForceUpdate(): DispatchWithoutAction;
|
|
640
421
|
export declare function useId(prefix?: string, providedId?: string): string;
|
641
422
|
|
642
423
|
/**
|
424
|
+
* @internal
|
643
425
|
* React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
|
644
426
|
* useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
|
645
427
|
* ensure we don't get a render flash for certain operations, but we may also need affected components to render on
|
@@ -657,6 +439,7 @@ export declare const useIsomorphicLayoutEffect: typeof React_2.useEffect;
|
|
657
439
|
export declare function useIsSSR(): boolean;
|
658
440
|
|
659
441
|
/**
|
442
|
+
* @internal
|
660
443
|
* Combine two event callbacks into a single callback function that calls each one in order.
|
661
444
|
*
|
662
445
|
* This is useful to add an event listener to an existing element without overwriting the current listener, if any.
|
@@ -676,6 +459,7 @@ export declare function useIsSSR(): boolean;
|
|
676
459
|
export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
|
677
460
|
|
678
461
|
/**
|
462
|
+
* @internal
|
679
463
|
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
|
680
464
|
* updates all provided refs
|
681
465
|
* @param refs - Refs to collectively update with one ref value.
|
@@ -684,12 +468,8 @@ export declare function useMergedEventCallbacks<Args extends unknown[]>(callback
|
|
684
468
|
export declare function useMergedRefs<T>(...refs: (React_2.Ref<T> | undefined)[]): RefObjectFunction<T>;
|
685
469
|
|
686
470
|
/**
|
687
|
-
*
|
688
|
-
*
|
689
|
-
* @param callback - Function to call before mount.
|
471
|
+
* @internal
|
690
472
|
*/
|
691
|
-
export declare const useMount: (callback: () => void) => void;
|
692
|
-
|
693
473
|
export declare type UseOnClickOrScrollOutsideOptions = {
|
694
474
|
/**
|
695
475
|
* The element to listen for the click event
|
@@ -716,23 +496,24 @@ export declare type UseOnClickOrScrollOutsideOptions = {
|
|
716
496
|
};
|
717
497
|
|
718
498
|
/**
|
499
|
+
* @internal
|
719
500
|
* Utility to perform checks where a click/touch event was made outside a component
|
720
501
|
*/
|
721
502
|
export declare const useOnClickOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
|
722
503
|
|
723
504
|
/**
|
505
|
+
* @internal
|
724
506
|
* Utility to perform checks where a click/touch event was made outside a component
|
725
507
|
*/
|
726
508
|
export declare const useOnScrollOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
|
727
509
|
|
728
|
-
export declare const usePrevious: <ValueType = unknown>(value: ValueType) => ValueType | null;
|
729
|
-
|
730
510
|
/**
|
731
511
|
* @internal
|
732
512
|
*/
|
733
|
-
export declare
|
513
|
+
export declare const usePrevious: <ValueType = unknown>(value: ValueType) => ValueType | null;
|
734
514
|
|
735
515
|
/**
|
516
|
+
* @internal
|
736
517
|
* Helper to manage a browser timeout.
|
737
518
|
* Ensures that the timeout isn't set multiple times at once,
|
738
519
|
* and is cleaned up when the component is unloaded.
|
@@ -741,20 +522,6 @@ export declare function useSSRContext(): SSRContextValue;
|
|
741
522
|
*/
|
742
523
|
export declare function useTimeout(): readonly [(fn: () => void, delay: number) => void, () => void];
|
743
524
|
|
744
|
-
/**
|
745
|
-
* Hook which synchronously executes a callback when the component is about to unmount.
|
746
|
-
*
|
747
|
-
* @param callback - Function to call during unmount.
|
748
|
-
*/
|
749
|
-
export declare const useUnmount: (callback: () => void) => void;
|
750
|
-
|
751
|
-
/**
|
752
|
-
* An array of VIDEO tag properties and events.
|
753
|
-
*
|
754
|
-
* @public
|
755
|
-
*/
|
756
|
-
export declare const videoProperties: Record<string, number>;
|
757
|
-
|
758
525
|
/**
|
759
526
|
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
|
760
527
|
* to be a render function that takes those props.
|
File without changes
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,IAAT,QAAqB,eAArB;AA6BA;;;;;;;;;;;;;;;;AAgBG;;AACH,OAAM,SAAU,QAAV,CACJ,KADI,EACoB;
|
1
|
+
{"version":3,"sources":["compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,IAAT,QAAqB,eAArB;AA6BA;;;;;;;;;;;;;;;;AAgBG;;AACH,OAAM,SAAU,QAAV,CACJ,KADI,EACoB;EAKxB,MAAM,KAAK,GAAG,EAAd;EACA,MAAM,SAAS,GAAG,EAAlB;EAEA,MAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;EACA,KAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;IAChC,MAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;IACA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;IACA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;EACD;;EACD,OAAO;IAAE,KAAF;IAAS,SAAS,EAAG;EAArB,CAAP;AACD;;AAED,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;EAEX,IAAI,KAAK,CAAC,QAAD,CAAL,KAAoB,SAAxB,EAAmC;IACjC,OAAO,CAAC,IAAD,EAAO,SAAP,CAAP;EACD;;EACD,MAAM;IAAE,QAAF;IAAY,EAAE,EAAE,MAAhB;IAAwB,GAAG;EAA3B,IAAoC,KAAK,CAAC,QAAD,CAA/C;EAEA,MAAM,IAAI,GAAI,CAAA,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAG,QAAH,CAAhB,MAAiC,SAAjC,IAA8C,OAAO,KAAK,CAAC,UAAN,CAAiB,QAAjB,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;;EAIA,IAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;IAClC,MAAM,MAAM,GAAG,QAAf;IACA,OAAO,CACL,KAAK,CAAC,QADD,EAEJ;MACC,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;IADjB,CAFI,CAAP;EAMD;;EAED,MAAM,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;EACA,MAAM,SAAS,GAAI,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAD,CAAN,EAAmB,CAAC,IAAD,CAAnB,CAAP,GAAoC,KAAK,CAAC,QAAD,CAA5E;EAEA,OAAO,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/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["compose/resolveShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA/B;AAkBA;;;;;AAKG;;AACH,OAAO,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;
|
1
|
+
{"version":3,"sources":["compose/resolveShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA/B;AAkBA;;;;;AAKG;;AACH,OAAO,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;EAC3E,MAAM;IAAE,QAAQ,GAAG,KAAb;IAAoB;EAApB,IAAqC,OAAO,IAAI,EAAtD;;EACA,IAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;IACxD,OAAO,SAAP;EACD;;EAED,IAAI,iBAAiB,GAAG,EAAxB;;EAEA,IAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,iBAAkF,cAAc,CAAC,KAAD,CAApG,EAA6G;IAC3G,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;EACD,CAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;IACpC,iBAAiB,GAAG,KAApB;EACD;;EAED,OAAO,YAAY,GAAG,EAAE,GAAG,YAAL;IAAmB,GAAG;EAAtB,CAAH,GAA+C,iBAAlE;AACD,CAfM","sourcesContent":["import { isValidElement } from 'react';\nimport type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = {\n required?: Required;\n defaultProps?: Props;\n};\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props | null>(\n value: P | SlotShorthandValue | undefined,\n options?: ResolveShorthandOptions<P, true>,\n ): ReplaceNullWithUndefined<P>;\n <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | ReplaceNullWithUndefined<P>\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction = (value, options) => {\n const { required = false, defaultProps } = options || {};\n if (value === null || (value === undefined && !required)) {\n return undefined;\n }\n\n let resolvedShorthand = {} as UnknownSlotProps;\n\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n return defaultProps ? { ...defaultProps, ...resolvedShorthand } : resolvedShorthand;\n};\n"],"sourceRoot":"../src/"}
|
package/lib/compose/types.js
CHANGED
@@ -1,6 +1,2 @@
|
|
1
|
-
export {};
|
2
|
-
// the props type with this version (and it's likely much more expensive to evaluate)
|
3
|
-
// export type ForwardRefComponent<Props> = Props extends React.DOMAttributes<infer Element>
|
4
|
-
// ? React.ForwardRefExoticComponent<Props> & React.RefAttributes<Element>
|
5
|
-
// : never;
|
1
|
+
export {};
|
6
2
|
//# sourceMappingURL=types.js.map
|
package/lib/compose/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["compose/types.ts"],"names":[],"mappings":"
|
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.ReactNodeArray | 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"]}
|