@fluentui/react-utilities 9.0.0-rc.1 → 9.0.0-rc.10
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 +194 -1
- package/CHANGELOG.md +146 -68
- package/dist/{react-utilities.d.ts → index.d.ts} +14 -272
- package/{lib → dist}/tsdoc-metadata.json +0 -0
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/index.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 +1 -2
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js +9 -3
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedEventCallbacks.js.map +1 -1
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useTimeout.js +1 -2
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js +4 -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/ssr/index.js.map +1 -1
- package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
- 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.map +1 -1
- package/lib/utils/getReactCallbackName.js.map +1 -1
- package/lib/utils/getTriggerChild.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/isFluentTrigger.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 +4 -0
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.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 +1 -3
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js +9 -3
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js +1 -3
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js +158 -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/ssr/index.js.map +1 -1
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
- 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.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
- package/lib-commonjs/utils/getTriggerChild.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/isFluentTrigger.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 +4 -0
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/package.json +12 -10
- 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/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/index.d.ts +0 -9
- package/lib/utils/isFluentTrigger.d.ts +0 -22
- 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/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/index.d.ts +0 -9
- package/lib-commonjs/utils/isFluentTrigger.d.ts +0 -22
- 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
@@ -1,13 +1,6 @@
|
|
1
1
|
import { DispatchWithoutAction } from 'react';
|
2
2
|
import * as React_2 from 'react';
|
3
3
|
|
4
|
-
/**
|
5
|
-
* An array of A tag properties and events.
|
6
|
-
*
|
7
|
-
* @public
|
8
|
-
*/
|
9
|
-
export declare const anchorProperties: Record<string, number>;
|
10
|
-
|
11
4
|
/**
|
12
5
|
* Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
|
13
6
|
*/
|
@@ -21,38 +14,10 @@ export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: Reac
|
|
21
14
|
* type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;
|
22
15
|
* ```
|
23
16
|
*/
|
24
|
-
|
17
|
+
declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = {
|
25
18
|
as?: As;
|
26
19
|
};
|
27
20
|
|
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
21
|
/**
|
57
22
|
* Verifies if an application can use DOM.
|
58
23
|
*/
|
@@ -67,10 +32,6 @@ export declare function canUseDOM(): boolean;
|
|
67
32
|
*/
|
68
33
|
export declare const clamp: (value: number, min: number, max: number) => number;
|
69
34
|
|
70
|
-
export declare const colGroupProperties: Record<string, number>;
|
71
|
-
|
72
|
-
export declare const colProperties: Record<string, number>;
|
73
|
-
|
74
35
|
/**
|
75
36
|
* Defines the Props type for a component given its slots and the definition of which one is the primary slot,
|
76
37
|
* defaulting to root if one is not provided.
|
@@ -88,20 +49,6 @@ export declare type ComponentState<Slots extends SlotPropsRecord> = {
|
|
88
49
|
[Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
|
89
50
|
};
|
90
51
|
|
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
52
|
/**
|
106
53
|
* HTML element types that are not allowed to have children.
|
107
54
|
*
|
@@ -131,13 +78,6 @@ export declare type FluentTriggerComponent = {
|
|
131
78
|
isFluentTriggerComponent?: boolean;
|
132
79
|
};
|
133
80
|
|
134
|
-
/**
|
135
|
-
* An array of FORM tag properties and events.
|
136
|
-
*
|
137
|
-
* @public
|
138
|
-
*/
|
139
|
-
export declare const formProperties: Record<string, number>;
|
140
|
-
|
141
81
|
/**
|
142
82
|
* Return type for `React.forwardRef`, including inference of the proper typing for the ref.
|
143
83
|
*/
|
@@ -152,22 +92,6 @@ export declare type ForwardRefComponent<Props> = ObscureEventName extends keyof
|
|
152
92
|
*/
|
153
93
|
export declare function getNativeElementProps<TAttributes extends React_2.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
|
154
94
|
|
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
95
|
/**
|
172
96
|
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
|
173
97
|
*
|
@@ -240,39 +164,6 @@ export declare const getTriggerChild: (children: React_2.ReactNode) => React_2.R
|
|
240
164
|
ref?: React_2.Ref<unknown>;
|
241
165
|
};
|
242
166
|
|
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
167
|
/**
|
277
168
|
* Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
|
278
169
|
* * Removes legacy string ref.
|
@@ -282,12 +173,6 @@ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = Re
|
|
282
173
|
children?: never;
|
283
174
|
} : {});
|
284
175
|
|
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
176
|
/**
|
292
177
|
* Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
|
293
178
|
*
|
@@ -296,24 +181,10 @@ export declare const isFluentTrigger: (element: React_2.ReactElement) => boolean
|
|
296
181
|
* IsSingleton<'a' | 'b' | 'c'> // false
|
297
182
|
* ```
|
298
183
|
*/
|
299
|
-
|
184
|
+
declare type IsSingleton<T extends string> = {
|
300
185
|
[K in T]: Exclude<T, K> extends never ? true : false;
|
301
186
|
}[T];
|
302
187
|
|
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
188
|
declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
318
189
|
[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
190
|
};
|
@@ -332,30 +203,6 @@ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
|
|
332
203
|
*/
|
333
204
|
declare type ObscureEventName = 'onLostPointerCaptureCapture';
|
334
205
|
|
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
206
|
/**
|
360
207
|
* Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
|
361
208
|
* IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
|
@@ -363,7 +210,7 @@ export declare const optionProperties: Record<string, number>;
|
|
363
210
|
* The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
|
364
211
|
* types, to prevent unions from being expanded.
|
365
212
|
*/
|
366
|
-
|
213
|
+
declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
|
367
214
|
|
368
215
|
/**
|
369
216
|
* A Ref function which can be treated like a ref object in that it has an attached
|
@@ -374,7 +221,7 @@ export declare type RefObjectFunction<T> = React_2.RefObject<T> & ((value: T) =>
|
|
374
221
|
/**
|
375
222
|
* If type T includes `null`, remove it and add `undefined` instead.
|
376
223
|
*/
|
377
|
-
|
224
|
+
declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
|
378
225
|
|
379
226
|
/**
|
380
227
|
* Resets generated IDs, should be used only in tests.
|
@@ -401,13 +248,6 @@ export declare type ResolveShorthandOptions<Props, Required extends boolean = fa
|
|
401
248
|
defaultProps?: Props;
|
402
249
|
};
|
403
250
|
|
404
|
-
/**
|
405
|
-
* An array of SELECT tag properties and events.
|
406
|
-
*
|
407
|
-
* @public
|
408
|
-
*/
|
409
|
-
export declare const selectProperties: Record<string, number>;
|
410
|
-
|
411
251
|
/**
|
412
252
|
* Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
|
413
253
|
*
|
@@ -445,6 +285,13 @@ export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.Comp
|
|
445
285
|
} & WithSlotRenderFunction<IntrisicElementProps<As>>;
|
446
286
|
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
|
447
287
|
|
288
|
+
/**
|
289
|
+
* Helper type to correctly define the slot class names object.
|
290
|
+
*/
|
291
|
+
export declare type SlotClassNames<Slots> = {
|
292
|
+
[SlotName in keyof Slots]-?: string;
|
293
|
+
};
|
294
|
+
|
448
295
|
/**
|
449
296
|
* Matches any component's Slots type (such as ButtonSlots).
|
450
297
|
*
|
@@ -464,18 +311,6 @@ export declare type Slots<S extends SlotPropsRecord> = {
|
|
464
311
|
*/
|
465
312
|
export declare type SlotShorthandValue = React_2.ReactChild | React_2.ReactNodeArray | React_2.ReactPortal;
|
466
313
|
|
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
314
|
/**
|
480
315
|
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
481
316
|
* are consistent between the client and server.
|
@@ -484,45 +319,10 @@ export declare type SSRContextValue = {
|
|
484
319
|
*/
|
485
320
|
export declare const SSRProvider: React_2.FC;
|
486
321
|
|
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
322
|
/**
|
523
323
|
* Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
|
524
324
|
*/
|
525
|
-
|
325
|
+
declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
|
526
326
|
|
527
327
|
/**
|
528
328
|
* Matches any slot props type.
|
@@ -530,42 +330,10 @@ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U :
|
|
530
330
|
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
|
531
331
|
* it shouldn't be used as the type of a slot.
|
532
332
|
*/
|
533
|
-
|
333
|
+
declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
534
334
|
as?: keyof JSX.IntrinsicElements;
|
535
335
|
};
|
536
336
|
|
537
|
-
/**
|
538
|
-
* Hook to store a value and generate callbacks for setting the value to true or false.
|
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.
|
562
|
-
*
|
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
337
|
/**
|
570
338
|
* A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
|
571
339
|
* such as a checked state or text input string.
|
@@ -632,7 +400,7 @@ export declare function useForceUpdate(): DispatchWithoutAction;
|
|
632
400
|
/**
|
633
401
|
* Hook to generate a unique ID.
|
634
402
|
*
|
635
|
-
* @param prefix - Optional prefix for the ID
|
403
|
+
* @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
|
636
404
|
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
637
405
|
* without conditioning the hook call
|
638
406
|
* @returns The ID
|
@@ -683,13 +451,6 @@ export declare function useMergedEventCallbacks<Args extends unknown[]>(callback
|
|
683
451
|
*/
|
684
452
|
export declare function useMergedRefs<T>(...refs: (React_2.Ref<T> | undefined)[]): RefObjectFunction<T>;
|
685
453
|
|
686
|
-
/**
|
687
|
-
* Hook which asynchronously executes a callback once the component has been mounted.
|
688
|
-
*
|
689
|
-
* @param callback - Function to call before mount.
|
690
|
-
*/
|
691
|
-
export declare const useMount: (callback: () => void) => void;
|
692
|
-
|
693
454
|
export declare type UseOnClickOrScrollOutsideOptions = {
|
694
455
|
/**
|
695
456
|
* The element to listen for the click event
|
@@ -727,11 +488,6 @@ export declare const useOnScrollOutside: (options: UseOnClickOrScrollOutsideOpti
|
|
727
488
|
|
728
489
|
export declare const usePrevious: <ValueType = unknown>(value: ValueType) => ValueType | null;
|
729
490
|
|
730
|
-
/**
|
731
|
-
* @internal
|
732
|
-
*/
|
733
|
-
export declare function useSSRContext(): SSRContextValue;
|
734
|
-
|
735
491
|
/**
|
736
492
|
* Helper to manage a browser timeout.
|
737
493
|
* Ensures that the timeout isn't set multiple times at once,
|
@@ -741,20 +497,6 @@ export declare function useSSRContext(): SSRContextValue;
|
|
741
497
|
*/
|
742
498
|
export declare function useTimeout(): readonly [(fn: () => void, delay: number) => void, () => void];
|
743
499
|
|
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
500
|
/**
|
759
501
|
* Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
|
760
502
|
* to be a render function that takes those props.
|
File without changes
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
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;AAKxB,QAAM,KAAK,GAAG,EAAd;AACA,QAAM,SAAS,GAAG,EAAlB;AAEA,QAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;AACA,OAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;AAChC,UAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;AACA,IAAA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;AACA,IAAA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;AACD;;AACD,SAAO;AAAE,IAAA,KAAF;AAAS,IAAA,SAAS,EAAG;AAArB,GAAP;AACD;;AAED,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;AAEX,MAAI,KAAK,CAAC,QAAD,CAAL,KAAoB,SAAxB,EAAmC;AACjC,WAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD;;AACD,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,EAAE,EAAE,MAAhB;AAAwB,OAAG;AAA3B,MAAoC,KAAK,CAAC,QAAD,CAA/C;AAEA,QAAM,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;;AAIA,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,UAAM,MAAM,GAAG,QAAf;AACA,WAAO,CACL,KAAK,CAAC,QADD,EAEJ;AACC,MAAA,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;AADjB,KAFI,CAAP;AAMD;;AAED,QAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAA4B,CAAA,EAAA,GAAA,KAAK,CAAC,QAAD,CAAL,MAAe,IAAf,IAAe,EAAA,KAAA,KAAA,CAAf,GAAe,KAAA,CAAf,GAAe,EAAA,CAAE,EAA7C,CAAzB;AACA,QAAM,SAAS,GAAI,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,QAAD,CAAN,EAAmB,CAAC,IAAD,CAAnB,CAAP,GAAoC,KAAK,CAAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n} from './types';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\ntype ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P\n : never;\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: (slotProps as unknown) as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n if (state[slotName] === undefined) {\n return [null, undefined as R[K]];\n }\n const { children, as: asProp, ...rest } = state[slotName]!;\n\n const slot = (state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]) as React.ElementType<R[K]>;\n\n if (typeof children === 'function') {\n const render = children as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n ({\n children: render(slot, rest as Omit<R[K], 'children' | 'as'>),\n } as unknown) as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && state[slotName]?.as;\n const slotProps = (shouldOmitAsProp ? omit(state[slotName]!, ['as']) : state[slotName]) as R[K];\n\n return [slot, slotProps];\n}\n"],"sourceRoot":"../src/"}
|
package/lib/compose/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
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 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
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;AAC3E,QAAM;AAAE,IAAA,QAAQ,GAAG,KAAb;AAAoB,IAAA;AAApB,MAAqC,OAAO,IAAI,EAAtD;;AACA,MAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;AACxD,WAAO,SAAP;AACD;;AAED,MAAI,iBAAiB,GAAG,EAAxB;;AAEA,MAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,iBAAkF,cAAc,CAAC,KAAD,CAApG,EAA6G;AAC3G,IAAA,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;AACD,GAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;AACpC,IAAA,iBAAiB,GAAG,KAApB;AACD;;AAED,SAAO,YAAY,GAAG,EAAE,GAAG,YAAL;AAAmB,OAAG;AAAtB,GAAH,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":["
|
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 | 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
@@ -1,17 +1,13 @@
|
|
1
1
|
export * from './useControllableState';
|
2
|
-
export * from './useBoolean';
|
3
|
-
export * from './useConst';
|
4
2
|
export * from './useEventCallback';
|
5
3
|
export * from './useFirstMount';
|
4
|
+
export * from './useForceUpdate';
|
6
5
|
export * from './useId';
|
7
6
|
export * from './useIsomorphicLayoutEffect';
|
8
7
|
export * from './useMergedEventCallbacks';
|
9
8
|
export * from './useMergedRefs';
|
10
|
-
export * from './useMount';
|
11
9
|
export * from './useOnClickOutside';
|
12
10
|
export * from './useOnScrollOutside';
|
13
11
|
export * from './usePrevious';
|
14
12
|
export * from './useTimeout';
|
15
|
-
export * from './useUnmount';
|
16
|
-
export * from './useForceUpdate';
|
17
13
|
//# sourceMappingURL=index.js.map
|
package/lib/hooks/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
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,2BAA2B,CAAC;AAC1C,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 './useMergedEventCallbacks';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useTimeout';\n"]}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { useConst } from './useConst';
|
3
2
|
|
4
3
|
function isFactoryDispatch(newState) {
|
5
4
|
return typeof newState === 'function';
|
@@ -51,7 +50,7 @@ export const useControllableState = options => {
|
|
51
50
|
*/
|
52
51
|
|
53
52
|
const useIsControlled = controlledValue => {
|
54
|
-
const isControlled =
|
53
|
+
const [isControlled] = React.useState(() => controlledValue !== undefined);
|
55
54
|
|
56
55
|
if (process.env.NODE_ENV !== 'production') {
|
57
56
|
// We don't want these warnings in production even though it is against native behaviour
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["hooks/useControllableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;;AAkBA,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;AACrE,SAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;;;;;;;;;;AAaG;;;AACH,OAAO,MAAM,oBAAoB,GAC/B,OADkC,IAEsB;AACxD,QAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;AACA,QAAM,YAAY,GAAG,OAAO,OAAO,CAAC,YAAf,KAAgC,WAAhC,GAA8C,OAAO,CAAC,YAAtD,GAAqE,OAAO,CAAC,YAAlG;AACA,QAAM,CAAC,aAAD,EAAgB,gBAAhB,IAAoC,KAAK,CAAC,QAAN,CAAsB,YAAtB,CAA1C;AAEA,QAAM,KAAK,GAAG,YAAY,GAAI,OAAO,CAAC,KAAZ,GAA8B,aAAxD;AAEA,QAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAb,CAAjB;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,IAAA,QAAQ,CAAC,OAAT,GAAmB,KAAnB;AACD,GAFD,EAEG,CAAC,KAAD,CAFH,EARwD,CAYxD;AACA;;AACA,QAAM,QAAQ,GAAG,KAAK,CAAC,WAAN,CAAmB,QAAD,IAA0C;AAC3E;AACA;AACA,QAAI,iBAAiB,CAAC,QAAD,CAArB,EAAiC;AAC/B,MAAA,QAAQ,CAAC,OAAT,GAAmB,QAAQ,CAAC,QAAQ,CAAC,OAAV,CAA3B;AACD,KAFD,MAEO;AACL,MAAA,QAAQ,CAAC,OAAT,GAAmB,QAAnB;AACD;;AAED,IAAA,gBAAgB,CAAC,QAAQ,CAAC,OAAV,CAAhB;AACD,GAVgB,EAUd,EAVc,CAAjB;AAYA,SAAO,CAAC,KAAD,EAAQ,QAAR,CAAP;AACD,CA7BM;AA+BP;;;;AAIG;;AACH,MAAM,eAAe,GAAI,eAAD,IAA6B;AACnD,QAAM,CAAC,YAAD,IAAiB,KAAK,CAAC,QAAN,CAAwB,MAAM,eAAe,KAAK,SAAlD,CAAvB;;AAEA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA;AACA,IAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,UAAI,YAAY,MAAM,eAAe,KAAK,SAA1B,CAAhB,EAAsD;AACpD,cAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;AAEA,cAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;AAIA,cAAM,gBAAgB,GAAG,YAAY,GAAG,yBAAH,GAA+B,wBAApE,CAPoD,CASpD;;AACA,QAAA,OAAO,CAAC,KAAR,CACE,CACE;AACA,qCAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;AAUD;AACF,KAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;AAuBD;;AAED,SAAO,YAAP;AACD,CAhCD","sourcesContent":["import * as React from 'react';\n\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,\n * such as a checked state or text input string.\n *\n * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a\n * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.\n *\n * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array\n * of the current value and an updater (dispatch) function. The updater function is referentially\n * stable (won't change during the component's lifecycle). It can take either a new value, or a\n * function which is passed the previous value and returns the new value. Unlike `setState`, calls\n * to the updater function will only be respected if the component is uncontrolled.\n * @see https://reactjs.org/docs/uncontrolled-components.html\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n const isControlled = useIsControlled(options.state);\n const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;\n const [internalState, setInternalState] = React.useState<State>(initialState);\n\n const state = isControlled ? (options.state as State) : internalState;\n\n const stateRef = React.useRef(state);\n React.useEffect(() => {\n stateRef.current = state;\n }, [state]);\n\n // To match the behavior of the setter returned by React.useState, this callback's identity\n // should never change. This means it MUST NOT directly reference variables that can change.\n const setState = React.useCallback((newState: React.SetStateAction<State>) => {\n // React dispatch can use a factory\n // https://reactjs.org/docs/hooks-reference.html#functional-updates\n if (isFactoryDispatch(newState)) {\n stateRef.current = newState(stateRef.current);\n } else {\n stateRef.current = newState;\n }\n\n setInternalState(stateRef.current);\n }, []);\n\n return [state, setState];\n};\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = (controlledValue: unknown) => {\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n 'changing from ' + undefinedWarning + ' value, which should not happen.',\n 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',\n 'More info: https://reactjs.org/link/controlled-components',\n error.stack,\n ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["hooks/useEventCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,QAA0C,6BAA1C;AAEA;;;;;;;;;;;AAWG;;AACH,OAAO,MAAM,gBAAgB,GAAoC,EAAjC,IAAkE;AAChG,QAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,MAAK;AAC/C,UAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;AACD,GAFmB,CAApB;AAIA,EAAA,yBAAyB,CAAC,MAAK;AAC7B,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFwB,EAEtB,CAAC,EAAD,CAFsB,CAAzB;AAIA,SAAO,KAAK,CAAC,WAAN,CACL,CAAC,GAAG,IAAJ,KAAkB;AAChB,UAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;AACA,WAAO,QAAQ,CAAC,GAAG,IAAJ,CAAf;AACD,GAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["hooks/useFirstMount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;AASG;;AACH,OAAM,SAAU,aAAV,GAAuB;AAC3B,QAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAhB;;AAEA,MAAI,OAAO,CAAC,OAAZ,EAAqB;AACnB,IAAA,OAAO,CAAC,OAAR,GAAkB,KAAlB;AACA,WAAO,IAAP;AACD;;AAED,SAAO,OAAO,CAAC,OAAf;AACD","sourcesContent":["import * as React from 'react';\n\n/**\n * Checks if components was mounted the first time.\n * Since concurrent mode will be released in the future this needs to be verified\n * Currently (React 17) will always render the initial mount once\n * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx\n * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx\n *\n * @example\n * const isFirstMount = useFirstMount();\n */\nexport function useFirstMount(): boolean {\n const isFirst = React.useRef(true);\n\n if (isFirst.current) {\n isFirst.current = false;\n return true;\n }\n\n return isFirst.current;\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["hooks/useForceUpdate.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,OAA3B;AAEA;;AAEG;;AACH,OAAM,SAAU,cAAV,GAAwB;AAC5B,SAAO,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAV,EAAa,CAAb,CAAV,CAA0B,CAA1B,CAAP;AACD","sourcesContent":["import { useReducer } from 'react';\n\n/**\n * Forces a re-render, similar to `forceUpdate` in class components.\n */\nexport function useForceUpdate() {\n return useReducer(x => x + 1, 0)[1];\n}\n"],"sourceRoot":"../src/"}
|
package/lib/hooks/useId.js
CHANGED
@@ -12,14 +12,20 @@ export function resetIdsForTests() {
|
|
12
12
|
/**
|
13
13
|
* Hook to generate a unique ID.
|
14
14
|
*
|
15
|
-
* @param prefix - Optional prefix for the ID
|
15
|
+
* @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
|
16
16
|
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
17
17
|
* without conditioning the hook call
|
18
18
|
* @returns The ID
|
19
19
|
*/
|
20
20
|
|
21
|
-
export function useId(prefix, providedId) {
|
21
|
+
export function useId(prefix = 'fui-', providedId) {
|
22
22
|
const contextValue = useSSRContext();
|
23
|
-
return React.useMemo(() =>
|
23
|
+
return React.useMemo(() => {
|
24
|
+
if (providedId) {
|
25
|
+
return providedId;
|
26
|
+
}
|
27
|
+
|
28
|
+
return `${prefix}${++contextValue.current}`;
|
29
|
+
}, [prefix, providedId, contextValue]);
|
24
30
|
}
|
25
31
|
//# sourceMappingURL=useId.js.map
|
package/lib/hooks/useId.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["hooks/useId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,sBAAT,EAAiC,aAAjC,QAAsD,cAAtD;AAEA;;;;AAIG;;AACH,OAAM,SAAU,gBAAV,GAA0B;AAC9B,EAAA,sBAAsB,CAAC,OAAvB,GAAiC,CAAjC;AACD;AAED;;;;;;;AAOG;;AACH,OAAM,SAAU,KAAV,CAAgB,MAAA,GAAiB,MAAjC,EAAyC,UAAzC,EAA4D;AAChE,QAAM,YAAY,GAAG,aAAa,EAAlC;AAEA,SAAO,KAAK,CAAC,OAAN,CAAc,MAAK;AACxB,QAAI,UAAJ,EAAgB;AACd,aAAO,UAAP;AACD;;AAED,WAAO,GAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAO,EAAzC;AACD,GANM,EAMJ,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CANI,CAAP;AAOD","sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\n/**\n * Resets generated IDs, should be used only in tests.\n *\n * @private\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n const contextValue = useSSRContext();\n\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${prefix}${++contextValue.current}`;\n }, [prefix, providedId, contextValue]);\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,cAA1B;AAEA;;;;;;;;AAQG;AACH;;AACA,OAAO,MAAM,yBAAyB,GAA2B,aAAA,SAAS,KAAK,KAAK,CAAC,eAAX,GAA6B,KAAK,CAAC,SAAtG","sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '../ssr/index';\n\n/**\n * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally\n * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to\n * ensure we don't get a render flash for certain operations, but we may also need affected components to render on\n * the server.\n *\n * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\n * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js\n */\n// eslint-disable-next-line no-restricted-properties\nexport const useIsomorphicLayoutEffect: typeof React.useEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["hooks/useMergedEventCallbacks.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAT,QAAiC,oBAAjC;AAEA;;;;;;;;;;;;;;;;AAgBG;;AACH,OAAM,SAAU,uBAAV,CACJ,SADI,EAEJ,SAFI,EAE4C;AAEhD,SAAO,gBAAgB,CAAC,CAAC,GAAG,IAAJ,KAAkB;AACxC,IAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;AACA,IAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;AACD,GAHsB,CAAvB;AAID","sourcesContent":["import { useEventCallback } from './useEventCallback';\n\n/**\n * Combine two event callbacks into a single callback function that calls each one in order.\n *\n * This is useful to add an event listener to an existing element without overwriting the current listener, if any.\n *\n * For example:\n * ```ts\n * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {\n * // Handle onChange\n * });\n * ```\n *\n * @param callback1 - The first callback to be called\n * @param callback2 - The second callback to be called\n *\n * @returns An event callback that calls the callbacks in order, and is stable between renders\n */\nexport function useMergedEventCallbacks<Args extends unknown[]>(\n callback1: ((...args: Args) => void) | undefined,\n callback2: ((...args: Args) => void) | undefined,\n) {\n return useEventCallback((...args: Args) => {\n callback1?.(...args);\n callback2?.(...args);\n });\n}\n"],"sourceRoot":"../src/"}
|