@fluentui/react-utilities 9.7.4 → 9.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +71 -1
- package/CHANGELOG.md +28 -2
- package/dist/index.d.ts +25 -10
- package/lib/compose/constants.js +5 -0
- package/lib/compose/constants.js.map +1 -0
- package/lib/compose/getSlots.js +10 -7
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/getSlotsNext.js +34 -0
- package/lib/compose/getSlotsNext.js.map +1 -0
- package/lib/compose/index.js +2 -0
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/resolveShorthand.js +10 -5
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/hooks/useControllableState.js +21 -32
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/compose/constants.js +14 -0
- package/lib-commonjs/compose/constants.js.map +1 -0
- package/lib-commonjs/compose/getSlots.js +10 -8
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/getSlotsNext.js +44 -0
- package/lib-commonjs/compose/getSlotsNext.js.map +1 -0
- package/lib-commonjs/compose/index.js +2 -0
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.js +10 -5
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js +16 -27
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/index.js +2 -0
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +2 -2
- package/.swcrc +0 -30
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,77 @@
|
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Fri, 12 May 2023 20:22:33 GMT",
|
6
|
+
"tag": "@fluentui/react-utilities_v9.8.1",
|
7
|
+
"version": "9.8.1",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "bernardo.sunderhus@gmail.com",
|
12
|
+
"package": "@fluentui/react-utilities",
|
13
|
+
"commit": "88ff00c2979ecd025f725fa3fc4e4d370f95cfc4",
|
14
|
+
"comment": "feat: defers useControllableState state to initializer method"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "bernardo.sunderhus@gmail.com",
|
18
|
+
"package": "@fluentui/react-utilities",
|
19
|
+
"commit": "f0b05741d812ad90c52754b0b4035d5554cf2aa0",
|
20
|
+
"comment": "chore: updates useControllableState comments"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"author": "olfedias@microsoft.com",
|
24
|
+
"package": "@fluentui/react-utilities",
|
25
|
+
"commit": "c28decb23d191a0daaaf6d5d1832429715102129",
|
26
|
+
"comment": "chore: exclude .swcrc from being published"
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"author": "bernardo.sunderhus@gmail.com",
|
30
|
+
"package": "@fluentui/react-utilities",
|
31
|
+
"commit": "557ffca71ff7767a4d595b6fcc55ad4a1fe02360",
|
32
|
+
"comment": "chore: simplifies useControllableState hook internals"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"author": "beachball",
|
36
|
+
"package": "@fluentui/react-utilities",
|
37
|
+
"comment": "Bump @fluentui/keyboard-keys to v9.0.3",
|
38
|
+
"commit": "79c08ce5bbf6387b2b18ba4c3d2d5681e0177d4b"
|
39
|
+
}
|
40
|
+
],
|
41
|
+
"none": [
|
42
|
+
{
|
43
|
+
"author": "martinhochel@microsoft.com",
|
44
|
+
"package": "@fluentui/react-utilities",
|
45
|
+
"commit": "dbda7fa69e3000aaf8dd4a061e254ebd35198b8e",
|
46
|
+
"comment": "fix: update npmignore files to fix npm8/node16 regression how npm publish works"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"date": "Mon, 17 Apr 2023 17:54:02 GMT",
|
53
|
+
"tag": "@fluentui/react-utilities_v9.8.0",
|
54
|
+
"version": "9.8.0",
|
55
|
+
"comments": {
|
56
|
+
"patch": [
|
57
|
+
{
|
58
|
+
"author": "behowell@microsoft.com",
|
59
|
+
"package": "@fluentui/react-utilities",
|
60
|
+
"commit": "c156e7682a89d7766bed3c0b9f231dc2e0a2058b",
|
61
|
+
"comment": "fix: Fix slot render functions"
|
62
|
+
}
|
63
|
+
],
|
64
|
+
"minor": [
|
65
|
+
{
|
66
|
+
"author": "bernardo.sunderhus@gmail.com",
|
67
|
+
"package": "@fluentui/react-utilities",
|
68
|
+
"commit": "97af91aa7684bbfe149ace1b21b75fb7c04128a2",
|
69
|
+
"comment": "feat: ensure compatibility with custom JSX pragma"
|
70
|
+
}
|
71
|
+
]
|
72
|
+
}
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"date": "Wed, 12 Apr 2023 09:31:45 GMT",
|
6
76
|
"tag": "@fluentui/react-utilities_v9.7.4",
|
7
77
|
"version": "9.7.4",
|
8
78
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,38 @@
|
|
1
1
|
# Change Log - @fluentui/react-utilities
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Fri, 12 May 2023 20:22:33 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.8.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.8.1)
|
8
|
+
|
9
|
+
Fri, 12 May 2023 20:22:33 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.8.0..@fluentui/react-utilities_v9.8.1)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- feat: defers useControllableState state to initializer method ([PR #27717](https://github.com/microsoft/fluentui/pull/27717) by bernardo.sunderhus@gmail.com)
|
15
|
+
- chore: updates useControllableState comments ([PR #27754](https://github.com/microsoft/fluentui/pull/27754) by bernardo.sunderhus@gmail.com)
|
16
|
+
- chore: exclude .swcrc from being published ([PR #27740](https://github.com/microsoft/fluentui/pull/27740) by olfedias@microsoft.com)
|
17
|
+
- chore: simplifies useControllableState hook internals ([PR #27702](https://github.com/microsoft/fluentui/pull/27702) by bernardo.sunderhus@gmail.com)
|
18
|
+
- Bump @fluentui/keyboard-keys to v9.0.3 ([PR #27827](https://github.com/microsoft/fluentui/pull/27827) by beachball)
|
19
|
+
|
20
|
+
## [9.8.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.8.0)
|
21
|
+
|
22
|
+
Mon, 17 Apr 2023 17:54:02 GMT
|
23
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.7.4..@fluentui/react-utilities_v9.8.0)
|
24
|
+
|
25
|
+
### Minor changes
|
26
|
+
|
27
|
+
- feat: ensure compatibility with custom JSX pragma ([PR #27472](https://github.com/microsoft/fluentui/pull/27472) by bernardo.sunderhus@gmail.com)
|
28
|
+
|
29
|
+
### Patches
|
30
|
+
|
31
|
+
- fix: Fix slot render functions ([PR #27561](https://github.com/microsoft/fluentui/pull/27561) by behowell@microsoft.com)
|
32
|
+
|
7
33
|
## [9.7.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.7.4)
|
8
34
|
|
9
|
-
Wed, 12 Apr 2023 09:
|
35
|
+
Wed, 12 Apr 2023 09:31:45 GMT
|
10
36
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.7.3..@fluentui/react-utilities_v9.7.4)
|
11
37
|
|
12
38
|
### Patches
|
package/dist/index.d.ts
CHANGED
@@ -155,6 +155,14 @@ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentStat
|
|
155
155
|
slotProps: ObjectSlotProps<R>;
|
156
156
|
};
|
157
157
|
|
158
|
+
/**
|
159
|
+
* Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
|
160
|
+
*/
|
161
|
+
export declare function getSlotsNext<R extends SlotPropsRecord>(state: ComponentState<R>): {
|
162
|
+
slots: Slots<R>;
|
163
|
+
slotProps: ObjectSlotProps<R>;
|
164
|
+
};
|
165
|
+
|
158
166
|
/**
|
159
167
|
* @internal
|
160
168
|
* Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
|
@@ -435,6 +443,12 @@ export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.Comp
|
|
435
443
|
} & WithSlotRenderFunction<IntrinsicElementProps<As>>;
|
436
444
|
}[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
|
437
445
|
|
446
|
+
/**
|
447
|
+
* @internal
|
448
|
+
* Internal reference for the render function
|
449
|
+
*/
|
450
|
+
export declare const SLOT_RENDER_FUNCTION_SYMBOL: unique symbol;
|
451
|
+
|
438
452
|
/**
|
439
453
|
* Helper type to correctly define the slot class names object.
|
440
454
|
*/
|
@@ -494,25 +508,26 @@ declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never)
|
|
494
508
|
* This should ONLY be used in type templates as in `extends UnknownSlotProps`;
|
495
509
|
* it shouldn't be used as the type of a slot.
|
496
510
|
*/
|
497
|
-
declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
511
|
+
export declare type UnknownSlotProps = Pick<React_2.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
|
498
512
|
as?: keyof JSX.IntrinsicElements;
|
499
513
|
};
|
500
514
|
|
501
515
|
/**
|
502
516
|
* @internal
|
503
517
|
*
|
504
|
-
* A `useState
|
518
|
+
* A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook
|
519
|
+
* to manage a value that could be either `controlled` or `uncontrolled`,
|
505
520
|
* such as a checked state or text input string.
|
506
521
|
*
|
507
|
-
*
|
508
|
-
*
|
522
|
+
* @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`
|
523
|
+
*
|
524
|
+
* @returns an array of the current value and an updater (dispatcher) function.
|
525
|
+
* The updater function is referentially stable (won't change during the component's lifecycle).
|
526
|
+
* It can take either a new value, or a function which is passed the previous value and returns the new value.
|
527
|
+
*
|
528
|
+
* ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.
|
529
|
+
* Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.
|
509
530
|
*
|
510
|
-
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
511
|
-
* of the current value and an updater (dispatch) function. The updater function is referentially
|
512
|
-
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
513
|
-
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
514
|
-
* to the updater function will only be respected if the component is uncontrolled.
|
515
|
-
* @see https://reactjs.org/docs/uncontrolled-components.html
|
516
531
|
*/
|
517
532
|
export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React_2.Dispatch<React_2.SetStateAction<State>>];
|
518
533
|
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["SLOT_RENDER_FUNCTION_SYMBOL","Symbol"],"sources":["../../src/compose/constants.ts"],"sourcesContent":["/**\n * @internal\n * Internal reference for the render function\n */\nexport const SLOT_RENDER_FUNCTION_SYMBOL = Symbol('fui.slotRenderFunction');\n"],"mappings":"AAAA;;;GAIA,OAAO,MAAMA,2BAAA,gBAA8BC,MAAA,CAAO"}
|
package/lib/compose/getSlots.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { omit } from '../utils/omit';
|
3
|
+
import { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
|
3
4
|
/**
|
4
5
|
* Given the state and an array of slot names, will break out `slots` and `slotProps`
|
5
6
|
* collections.
|
@@ -32,24 +33,26 @@ export function getSlots(state) {
|
|
32
33
|
};
|
33
34
|
}
|
34
35
|
function getSlot(state, slotName) {
|
35
|
-
var _state_components, _state_components1
|
36
|
-
|
36
|
+
var _state_components, _state_components1;
|
37
|
+
const props = state[slotName];
|
38
|
+
if (props === undefined) {
|
37
39
|
return [null, undefined];
|
38
40
|
}
|
39
41
|
const {
|
40
42
|
children,
|
41
43
|
as: asProp,
|
44
|
+
[SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction,
|
42
45
|
...rest
|
43
|
-
} =
|
46
|
+
} = props;
|
44
47
|
const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
|
45
|
-
if (typeof children === 'function') {
|
46
|
-
const render = children;
|
48
|
+
if (renderFunction || typeof children === 'function') {
|
49
|
+
const render = renderFunction || children;
|
47
50
|
return [React.Fragment, {
|
48
51
|
children: render(slot, rest)
|
49
52
|
}];
|
50
53
|
}
|
51
|
-
const shouldOmitAsProp = typeof slot === 'string' &&
|
52
|
-
const slotProps = shouldOmitAsProp ? omit(
|
54
|
+
const shouldOmitAsProp = typeof slot === 'string' && asProp;
|
55
|
+
const slotProps = shouldOmitAsProp ? omit(props, ['as']) : props;
|
53
56
|
return [slot, slotProps];
|
54
57
|
}
|
55
58
|
//# sourceMappingURL=getSlots.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","omit","getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","_state_components","_state_components1","
|
1
|
+
{"version":3,"names":["React","omit","SLOT_RENDER_FUNCTION_SYMBOL","getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","_state_components","_state_components1","undefined","children","as","asProp","renderFunction","rest","render","Fragment","shouldOmitAsProp"],"sources":["../../src/compose/getSlots.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n UnknownSlotProps,\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\nexport type 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]> // Slot<'div', 'span'>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P // Slot<typeof Button>\n : ExtractSlotProps<S[K]>; // Slot<ButtonProps>\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 const props = state[slotName];\n\n if (props === undefined) {\n return [null, undefined as R[K]];\n }\n\n const {\n children,\n as: asProp,\n [SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction,\n ...rest\n } = props as typeof props & { [SLOT_RENDER_FUNCTION_SYMBOL]?: SlotRenderFunction<R[K]> };\n\n const slot = (\n state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n if (renderFunction || typeof children === 'function') {\n const render = renderFunction || (children as SlotRenderFunction<R[K]>);\n return [\n React.Fragment,\n {\n children: render(slot, rest as Omit<R[K], 'as'>),\n } as unknown as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps = (shouldOmitAsProp ? omit(props, ['as']) : (props as UnknownSlotProps)) as R[K];\n return [slot, slotProps];\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAEvB,SAASC,IAAI,QAAQ;AACrB,SAASC,2BAA2B,QAAQ;AA8B5C;;;;;;;;;;;;;;;;;AAiBA,OAAO,SAASC,SACdC,KAAwB,EAIxB;EACA,MAAMC,KAAA,GAAQ,CAAC;EACf,MAAMC,SAAA,GAAY,CAAC;EAEnB,MAAMC,SAAA,GAAyBC,MAAA,CAAOC,IAAI,CAACL,KAAA,CAAMM,UAAU;EAC3D,KAAK,MAAMC,QAAA,IAAYJ,SAAA,EAAW;IAChC,MAAM,CAACK,IAAA,EAAMC,KAAA,CAAM,GAAGC,OAAA,CAAQV,KAAA,EAAOO,QAAA;IACrCN,KAAK,CAACM,QAAA,CAAS,GAAGC,IAAA;IAClBN,SAAS,CAACK,QAAA,CAAS,GAAGE,KAAA;EACxB;EACA,OAAO;IAAER,KAAA;IAAOC,SAAA,EAAWA;EAA2C;AACxE;AAEA,SAASQ,QACPV,KAAwB,EACxBO,QAAW,EACsC;MAe/CI,iBAAA,EACcC,kBAAA;EAfhB,MAAMH,KAAA,GAAQT,KAAK,CAACO,QAAA,CAAS;EAE7B,IAAIE,KAAA,KAAUI,SAAA,EAAW;IACvB,OAAO,CAAC,IAAI,EAAEA,SAAA,CAAkB;EAClC;EAEA,MAAM;IACJC,QAAA;IACAC,EAAA,EAAIC,MAAA;IACJ,CAAClB,2BAAA,GAA8BmB,cAAA;IAC/B,GAAGC;EAAA,CACJ,GAAGT,KAAA;EAEJ,MAAMD,IAAA,GACJ,EAAAG,iBAAA,GAAAX,KAAA,CAAMM,UAAU,cAAhBK,iBAAA,uBAAAA,iBAAkB,CAACJ,QAAA,CAAS,MAAKM,SAAA,IAAa,OAAOb,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS,KAAK,WAChFS,MAAA,KAAU,CAAAJ,kBAAA,GAAAZ,KAAA,CAAMM,UAAU,cAAhBM,kBAAA,uBAAAA,kBAAkB,CAACL,QAAA,CAAS,CAAD,IAAK,QAC1CP,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS;EAGhC,IAAIU,cAAA,IAAkB,OAAOH,QAAA,KAAa,YAAY;IACpD,MAAMK,MAAA,GAASF,cAAA,IAAmBH,QAAA;IAClC,OAAO,CACLlB,KAAA,CAAMwB,QAAQ,EACd;MACEN,QAAA,EAAUK,MAAA,CAAOX,IAAA,EAAMU,IAAA;IACzB,EACD;EACH;EAEA,MAAMG,gBAAA,GAAmB,OAAOb,IAAA,KAAS,YAAYQ,MAAA;EACrD,MAAMd,SAAA,GAAamB,gBAAA,GAAmBxB,IAAA,CAAKY,KAAA,EAAO,CAAC,KAAK,IAAKA,KAA0B;EACvF,OAAO,CAACD,IAAA,EAAMN,SAAA,CAAU;AAC1B"}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
/**
|
3
|
+
* Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
|
4
|
+
*/
|
5
|
+
export function getSlotsNext(state) {
|
6
|
+
const slots = {};
|
7
|
+
const slotProps = {};
|
8
|
+
const slotNames = Object.keys(state.components);
|
9
|
+
for (const slotName of slotNames) {
|
10
|
+
const [slot, props] = getSlotNext(state, slotName);
|
11
|
+
slots[slotName] = slot;
|
12
|
+
slotProps[slotName] = props;
|
13
|
+
}
|
14
|
+
return {
|
15
|
+
slots,
|
16
|
+
slotProps: slotProps
|
17
|
+
};
|
18
|
+
}
|
19
|
+
function getSlotNext(state, slotName) {
|
20
|
+
var _state_components, _state_components1;
|
21
|
+
const props = state[slotName];
|
22
|
+
if (props === undefined) {
|
23
|
+
return [null, undefined];
|
24
|
+
}
|
25
|
+
const {
|
26
|
+
as: asProp,
|
27
|
+
...propsWithoutAs
|
28
|
+
} = props;
|
29
|
+
const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
|
30
|
+
const shouldOmitAsProp = typeof slot === 'string' && asProp;
|
31
|
+
const slotProps = shouldOmitAsProp ? propsWithoutAs : props;
|
32
|
+
return [slot, slotProps];
|
33
|
+
}
|
34
|
+
//# sourceMappingURL=getSlotsNext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["React","getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","_state_components","_state_components1","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"sources":["../../src/compose/getSlotsNext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentState, SlotPropsRecord, UnknownSlotProps } from './types';\nimport { ObjectSlotProps, Slots } from './getSlots';\n\n/**\n * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma\n */\nexport function getSlotsNext<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] = getSlotNext(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 getSlotNext<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n const props = state[slotName];\n\n if (props === undefined) {\n return [null, undefined as R[K]];\n }\n const { as: asProp, ...propsWithoutAs } = props;\n\n const slot = (\n state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps: UnknownSlotProps = shouldOmitAsProp ? propsWithoutAs : props;\n\n return [slot, slotProps as R[K]];\n}\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAIvB;;;AAGA,OAAO,SAASC,aACdC,KAAwB,EAIxB;EACA,MAAMC,KAAA,GAAQ,CAAC;EACf,MAAMC,SAAA,GAAY,CAAC;EAEnB,MAAMC,SAAA,GAAyBC,MAAA,CAAOC,IAAI,CAACL,KAAA,CAAMM,UAAU;EAC3D,KAAK,MAAMC,QAAA,IAAYJ,SAAA,EAAW;IAChC,MAAM,CAACK,IAAA,EAAMC,KAAA,CAAM,GAAGC,WAAA,CAAYV,KAAA,EAAOO,QAAA;IACzCN,KAAK,CAACM,QAAA,CAAS,GAAGC,IAAA;IAClBN,SAAS,CAACK,QAAA,CAAS,GAAGE,KAAA;EACxB;EACA,OAAO;IAAER,KAAA;IAAOC,SAAA,EAAWA;EAA2C;AACxE;AAEA,SAASQ,YACPV,KAAwB,EACxBO,QAAW,EACsC;MAS/CI,iBAAA,EACcC,kBAAA;EAThB,MAAMH,KAAA,GAAQT,KAAK,CAACO,QAAA,CAAS;EAE7B,IAAIE,KAAA,KAAUI,SAAA,EAAW;IACvB,OAAO,CAAC,IAAI,EAAEA,SAAA,CAAkB;EAClC;EACA,MAAM;IAAEC,EAAA,EAAIC,MAAA;IAAQ,GAAGC;EAAA,CAAgB,GAAGP,KAAA;EAE1C,MAAMD,IAAA,GACJ,EAAAG,iBAAA,GAAAX,KAAA,CAAMM,UAAU,cAAhBK,iBAAA,uBAAAA,iBAAkB,CAACJ,QAAA,CAAS,MAAKM,SAAA,IAAa,OAAOb,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS,KAAK,WAChFQ,MAAA,KAAU,CAAAH,kBAAA,GAAAZ,KAAA,CAAMM,UAAU,cAAhBM,kBAAA,uBAAAA,kBAAkB,CAACL,QAAA,CAAS,CAAD,IAAK,QAC1CP,KAAA,CAAMM,UAAU,CAACC,QAAA,CAAS;EAGhC,MAAMU,gBAAA,GAAmB,OAAOT,IAAA,KAAS,YAAYO,MAAA;EACrD,MAAMb,SAAA,GAA8Be,gBAAA,GAAmBD,cAAA,GAAiBP,KAAK;EAE7E,OAAO,CAACD,IAAA,EAAMN,SAAA,CAAkB;AAClC"}
|
package/lib/compose/index.js
CHANGED
package/lib/compose/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/compose/index.ts"],"sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
|
1
|
+
{"version":3,"names":[],"sources":["../../src/compose/index.ts"],"sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\nexport * from './constants';\nexport * from './getSlotsNext';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { isValidElement } from 'react';
|
2
|
+
import { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';
|
2
3
|
/**
|
3
4
|
* Resolves shorthands into slot props, to ensure normalization of the signature
|
4
5
|
* being passed down to getSlots method
|
@@ -14,16 +15,20 @@ export const resolveShorthand = (value, options) => {
|
|
14
15
|
return undefined;
|
15
16
|
}
|
16
17
|
let resolvedShorthand = {};
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
17
19
|
if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || /*#__PURE__*/isValidElement(value)) {
|
18
20
|
resolvedShorthand.children = value;
|
19
21
|
} else if (typeof value === 'object') {
|
20
|
-
resolvedShorthand =
|
21
|
-
...value
|
22
|
-
};
|
22
|
+
resolvedShorthand = value;
|
23
23
|
}
|
24
|
-
|
24
|
+
resolvedShorthand = {
|
25
25
|
...defaultProps,
|
26
26
|
...resolvedShorthand
|
27
|
-
}
|
27
|
+
};
|
28
|
+
if (typeof resolvedShorthand.children === 'function') {
|
29
|
+
resolvedShorthand[SLOT_RENDER_FUNCTION_SYMBOL] = resolvedShorthand.children;
|
30
|
+
resolvedShorthand.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;
|
31
|
+
}
|
32
|
+
return resolvedShorthand;
|
28
33
|
};
|
29
34
|
//# sourceMappingURL=resolveShorthand.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["isValidElement","resolveShorthand","value","options","required","defaultProps","undefined","resolvedShorthand","Array","isArray","children"],"sources":["../../src/compose/resolveShorthand.ts"],"sourcesContent":["import { isValidElement } from 'react';\nimport type { SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true\n ? { required: true; defaultProps?: Props }\n : { required?: Required; defaultProps?: Props };\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;\n <P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | 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
|
1
|
+
{"version":3,"names":["isValidElement","SLOT_RENDER_FUNCTION_SYMBOL","resolveShorthand","value","options","required","defaultProps","undefined","resolvedShorthand","Array","isArray","children"],"sources":["../../src/compose/resolveShorthand.ts"],"sourcesContent":["import { isValidElement } from 'react';\nimport type { SlotRenderFunction, SlotShorthandValue, UnknownSlotProps } from './types';\nimport { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true\n ? { required: true; defaultProps?: Props }\n : { required?: Required; defaultProps?: Props };\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;\n <P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | 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: UnknownSlotProps & {\n [SLOT_RENDER_FUNCTION_SYMBOL]?: SlotRenderFunction<UnknownSlotProps>;\n } = {};\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement<any>(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n resolvedShorthand = {\n ...defaultProps,\n ...resolvedShorthand,\n };\n\n if (typeof resolvedShorthand.children === 'function') {\n resolvedShorthand[SLOT_RENDER_FUNCTION_SYMBOL] = resolvedShorthand.children as SlotRenderFunction<UnknownSlotProps>;\n resolvedShorthand.children = defaultProps?.children;\n }\n\n return resolvedShorthand;\n};\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ;AAE/B,SAASC,2BAA2B,QAAQ;AAa5C;;;;;;AAMA,OAAO,MAAMC,gBAAA,GAA6CA,CAACC,KAAA,EAAOC,OAAA,KAAY;EAC5E,MAAM;IAAEC,QAAA,GAAW,KAAK;IAAEC;EAAY,CAAE,GAAGF,OAAA,IAAW,CAAC;EACvD,IAAID,KAAA,KAAU,IAAI,IAAKA,KAAA,KAAUI,SAAA,IAAa,CAACF,QAAA,EAAW;IACxD,OAAOE,SAAA;EACT;EAEA,IAAIC,iBAAA,GAEA,CAAC;EAEL;EACA,IAAI,OAAOL,KAAA,KAAU,YAAY,OAAOA,KAAA,KAAU,YAAYM,KAAA,CAAMC,OAAO,CAACP,KAAA,kBAAUH,cAAA,CAAoBG,KAAA,GAAQ;IAChHK,iBAAA,CAAkBG,QAAQ,GAAGR,KAAA;EAC/B,OAAO,IAAI,OAAOA,KAAA,KAAU,UAAU;IACpCK,iBAAA,GAAoBL,KAAA;EACtB;EAEAK,iBAAA,GAAoB;IAClB,GAAGF,YAAY;IACf,GAAGE;EACL;EAEA,IAAI,OAAOA,iBAAA,CAAkBG,QAAQ,KAAK,YAAY;IACpDH,iBAAiB,CAACP,2BAAA,CAA4B,GAAGO,iBAAA,CAAkBG,QAAQ;IAC3EH,iBAAA,CAAkBG,QAAQ,GAAGL,YAAA,aAAAA,YAAA,uBAAAA,YAAA,CAAcK,QAAQ;EACrD;EAEA,OAAOH,iBAAA;AACT"}
|
@@ -1,46 +1,35 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
function isFactoryDispatch(newState) {
|
3
|
-
return typeof newState === 'function';
|
4
|
-
}
|
5
2
|
/**
|
6
3
|
* @internal
|
7
4
|
*
|
8
|
-
* A `useState
|
5
|
+
* A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook
|
6
|
+
* to manage a value that could be either `controlled` or `uncontrolled`,
|
9
7
|
* such as a checked state or text input string.
|
10
8
|
*
|
11
|
-
*
|
12
|
-
*
|
9
|
+
* @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`
|
10
|
+
*
|
11
|
+
* @returns an array of the current value and an updater (dispatcher) function.
|
12
|
+
* The updater function is referentially stable (won't change during the component's lifecycle).
|
13
|
+
* It can take either a new value, or a function which is passed the previous value and returns the new value.
|
14
|
+
*
|
15
|
+
* ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.
|
16
|
+
* Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.
|
13
17
|
*
|
14
|
-
* @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
|
15
|
-
* of the current value and an updater (dispatch) function. The updater function is referentially
|
16
|
-
* stable (won't change during the component's lifecycle). It can take either a new value, or a
|
17
|
-
* function which is passed the previous value and returns the new value. Unlike `setState`, calls
|
18
|
-
* to the updater function will only be respected if the component is uncontrolled.
|
19
|
-
* @see https://reactjs.org/docs/uncontrolled-components.html
|
20
18
|
*/
|
21
19
|
export const useControllableState = options => {
|
22
|
-
const
|
23
|
-
|
24
|
-
|
25
|
-
const state = isControlled ? options.state : internalState;
|
26
|
-
const stateRef = React.useRef(state);
|
27
|
-
React.useEffect(() => {
|
28
|
-
stateRef.current = state;
|
29
|
-
}, [state]);
|
30
|
-
// To match the behavior of the setter returned by React.useState, this callback's identity
|
31
|
-
// should never change. This means it MUST NOT directly reference variables that can change.
|
32
|
-
const setState = React.useCallback(newState => {
|
33
|
-
// React dispatch can use a factory
|
34
|
-
// https://reactjs.org/docs/hooks-reference.html#functional-updates
|
35
|
-
if (isFactoryDispatch(newState)) {
|
36
|
-
stateRef.current = newState(stateRef.current);
|
37
|
-
} else {
|
38
|
-
stateRef.current = newState;
|
20
|
+
const [internalState, setInternalState] = React.useState(() => {
|
21
|
+
if (options.defaultState === undefined) {
|
22
|
+
return options.initialState;
|
39
23
|
}
|
40
|
-
|
41
|
-
}
|
42
|
-
return [state,
|
24
|
+
return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;
|
25
|
+
});
|
26
|
+
return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];
|
43
27
|
};
|
28
|
+
function isInitializer(value) {
|
29
|
+
return typeof value === 'function';
|
30
|
+
}
|
31
|
+
function noop() {
|
32
|
+
/* noop */}
|
44
33
|
/**
|
45
34
|
* Helper hook to handle previous comparison of controlled/uncontrolled
|
46
35
|
* Prints an error when isControlled value switches between subsequent renders
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","
|
1
|
+
{"version":3,"names":["React","useControllableState","options","internalState","setInternalState","useState","defaultState","undefined","initialState","isInitializer","useIsControlled","state","noop","value","controlledValue","isControlled","process","env","NODE_ENV","useEffect","error","Error","controlWarning","undefinedWarning","console","stack","join"],"sources":["../../src/hooks/useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\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\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n const [internalState, setInternalState] = React.useState<State>(() => {\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];\n};\n\nfunction isInitializer<State>(value: State | (() => State)): value is () => State {\n return typeof value === 'function';\n}\n\nfunction noop() {\n /* noop */\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 = <V>(controlledValue: V | undefined): controlledValue is V => {\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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAqBvB;;;;;;;;;;;;;;;;;AAiBA,OAAO,MAAMC,oBAAA,GACXC,OAAA,IACyD;EACzD,MAAM,CAACC,aAAA,EAAeC,gBAAA,CAAiB,GAAGJ,KAAA,CAAMK,QAAQ,CAAQ,MAAM;IACpE,IAAIH,OAAA,CAAQI,YAAY,KAAKC,SAAA,EAAW;MACtC,OAAOL,OAAA,CAAQM,YAAY;IAC7B;IACA,OAAOC,aAAA,CAAcP,OAAA,CAAQI,YAAY,IAAIJ,OAAA,CAAQI,YAAY,KAAKJ,OAAA,CAAQI,YAAY;EAC5F;EACA,OAAOI,eAAA,CAAgBR,OAAA,CAAQS,KAAK,IAAI,CAACT,OAAA,CAAQS,KAAK,EAAEC,IAAA,CAAK,GAAG,CAACT,aAAA,EAAeC,gBAAA,CAAiB;AACnG;AAEA,SAASK,cAAqBI,KAA4B,EAAwB;EAChF,OAAO,OAAOA,KAAA,KAAU;AAC1B;AAEA,SAASD,KAAA,EAAO;EACd;AAGF;;;;;AAKA,MAAMF,eAAA,GAAsBI,eAAA,IAAyD;EACnF,MAAM,CAACC,YAAA,CAAa,GAAGf,KAAA,CAAMK,QAAQ,CAAU,MAAMS,eAAA,KAAoBP,SAAA;EAEzE,IAAIS,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACzC;IACA;IACAlB,KAAA,CAAMmB,SAAS,CAAC,MAAM;MACpB,IAAIJ,YAAA,MAAkBD,eAAA,KAAoBP,SAAQ,GAAI;QACpD,MAAMa,KAAA,GAAQ,IAAIC,KAAA;QAElB,MAAMC,cAAA,GAAiBP,YAAA,GACnB,0CACA,wCAAwC;QAE5C,MAAMQ,gBAAA,GAAmBR,YAAA,GAAe,4BAA4B,wBAAwB;QAE5F;QACAS,OAAA,CAAQJ,KAAK,CACX;QACE;QACA,6BAA6BE,cAAA,GAAiB,wCAC9C,mBAAmBC,gBAAA,GAAmB,oCACtC,sGACA,6DACAH,KAAA,CAAMK,KAAK,CACZ,CAACC,IAAI,CAAC;MAEX;IACF,GAAG,CAACX,YAAA,EAAcD,eAAA,CAAgB;EACpC;EAEA,OAAOC,YAAA;AACT"}
|
package/lib/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';
|
1
|
+
export { getSlots, getSlotsNext, resolveShorthand, isResolvedShorthand, SLOT_RENDER_FUNCTION_SYMBOL } from './compose/index';
|
2
2
|
export { IdPrefixProvider, resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useScrollbarWidth, useTimeout } from './hooks/index';
|
3
3
|
export { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';
|
4
4
|
export { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, isHTMLElement, isInteractiveHTMLElement, omit } from './utils/index';
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["getSlots","resolveShorthand","isResolvedShorthand","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords"],"sources":["../src/index.ts"],"sourcesContent":["export {
|
1
|
+
{"version":3,"names":["getSlots","getSlotsNext","resolveShorthand","isResolvedShorthand","SLOT_RENDER_FUNCTION_SYMBOL","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords"],"sources":["../src/index.ts"],"sourcesContent":["export {\n getSlots,\n getSlotsNext,\n resolveShorthand,\n isResolvedShorthand,\n SLOT_RENDER_FUNCTION_SYMBOL,\n} from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n} from './compose/index';\n\nexport {\n IdPrefixProvider,\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useScrollbarWidth,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n isHTMLElement,\n isInteractiveHTMLElement,\n omit,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n\n/**\n * Event utils\n */\nexport type { NativeTouchOrMouseEvent, ReactTouchOrMouseEvent, TouchOrMouseEvent } from './events/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n"],"mappings":"AAAA,SACEA,QAAQ,EACRC,YAAY,EACZC,gBAAgB,EAChBC,mBAAmB,EACnBC,2BAA2B,QACtB;AAiBP,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,oBAAoB,EACpBC,gBAAgB,EAChBC,aAAa,EACbC,cAAc,EACdC,KAAK,EACLC,yBAAyB,EACzBC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,EACXC,iBAAiB,EACjBC,UAAU,QACL;AAGP,SAASC,SAAS,EAAEC,QAAQ,EAAEC,WAAW,QAAQ;AAEjD,SACEC,KAAK,EACLC,qBAAqB,EACrBC,yBAAyB,EACzBC,aAAa,EACbC,cAAc,EACdC,aAAa,EACbC,wBAAwB,EACxBC,IAAI,QACC;AAEP,SAASC,2BAA2B,EAAEC,eAAe,EAAEC,eAAe,QAAQ;AAQ9E,SAASC,YAAY,EAAEC,YAAY,EAAEC,oBAAoB,QAAQ"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* @internal
|
3
|
+
* Internal reference for the render function
|
4
|
+
*/ "use strict";
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
Object.defineProperty(exports, "SLOT_RENDER_FUNCTION_SYMBOL", {
|
9
|
+
enumerable: true,
|
10
|
+
get: ()=>SLOT_RENDER_FUNCTION_SYMBOL
|
11
|
+
});
|
12
|
+
const SLOT_RENDER_FUNCTION_SYMBOL = /*#__PURE__*/ Symbol('fui.slotRenderFunction'); //# sourceMappingURL=constants.js.map
|
13
|
+
|
14
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../lib/compose/constants.js"],"sourcesContent":["/**\n * @internal\n * Internal reference for the render function\n */export const SLOT_RENDER_FUNCTION_SYMBOL = /*#__PURE__*/Symbol('fui.slotRenderFunction');\n//# sourceMappingURL=constants.js.map"],"names":["SLOT_RENDER_FUNCTION_SYMBOL","Symbol"],"mappings":"AAAA;;;CAGC;;;;+BAAeA;;aAAAA;;AAAN,MAAMA,8BAA8B,WAAW,GAAEC,OAAO,2BAClE,qCAAqC"}
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "getSlots", {
|
|
9
9
|
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
10
10
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
11
11
|
const _omit = require("../utils/omit");
|
12
|
+
const _constants = require("./constants");
|
12
13
|
function getSlots(state) {
|
13
14
|
const slots = {};
|
14
15
|
const slotProps = {};
|
@@ -24,17 +25,18 @@ function getSlots(state) {
|
|
24
25
|
};
|
25
26
|
}
|
26
27
|
function getSlot(state, slotName) {
|
27
|
-
var _state_components, _state_components1
|
28
|
-
|
28
|
+
var _state_components, _state_components1;
|
29
|
+
const props = state[slotName];
|
30
|
+
if (props === undefined) {
|
29
31
|
return [
|
30
32
|
null,
|
31
33
|
undefined
|
32
34
|
];
|
33
35
|
}
|
34
|
-
const { children , as: asProp , ...rest } =
|
36
|
+
const { children , as: asProp , [_constants.SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction , ...rest } = props;
|
35
37
|
const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
|
36
|
-
if (typeof children === 'function') {
|
37
|
-
const render = children;
|
38
|
+
if (renderFunction || typeof children === 'function') {
|
39
|
+
const render = renderFunction || children;
|
38
40
|
return [
|
39
41
|
_react.Fragment,
|
40
42
|
{
|
@@ -42,10 +44,10 @@ function getSlot(state, slotName) {
|
|
42
44
|
}
|
43
45
|
];
|
44
46
|
}
|
45
|
-
const shouldOmitAsProp = typeof slot === 'string' &&
|
46
|
-
const slotProps = shouldOmitAsProp ? (0, _omit.omit)(
|
47
|
+
const shouldOmitAsProp = typeof slot === 'string' && asProp;
|
48
|
+
const slotProps = shouldOmitAsProp ? (0, _omit.omit)(props, [
|
47
49
|
'as'
|
48
|
-
]) :
|
50
|
+
]) : props;
|
49
51
|
return [
|
50
52
|
slot,
|
51
53
|
slotProps
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../lib/compose/getSlots.js"],"sourcesContent":["import * as React from 'react';\nimport { omit } from '../utils/omit';\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(state) {\n const slots = {};\n const slotProps = {};\n const slotNames = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot;\n slotProps[slotName] = props;\n }\n return {\n slots,\n slotProps: slotProps\n };\n}\nfunction getSlot(state, slotName) {\n var _state_components, _state_components1
|
1
|
+
{"version":3,"sources":["../../lib/compose/getSlots.js"],"sourcesContent":["import * as React from 'react';\nimport { omit } from '../utils/omit';\nimport { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\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(state) {\n const slots = {};\n const slotProps = {};\n const slotNames = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot;\n slotProps[slotName] = props;\n }\n return {\n slots,\n slotProps: slotProps\n };\n}\nfunction getSlot(state, slotName) {\n var _state_components, _state_components1;\n const props = state[slotName];\n if (props === undefined) {\n return [null, undefined];\n }\n const {\n children,\n as: asProp,\n [SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction,\n ...rest\n } = props;\n const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];\n if (renderFunction || typeof children === 'function') {\n const render = renderFunction || children;\n return [React.Fragment, {\n children: render(slot, rest)\n }];\n }\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps = shouldOmitAsProp ? omit(props, ['as']) : props;\n return [slot, slotProps];\n}\n//# sourceMappingURL=getSlots.js.map"],"names":["getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","_state_components","_state_components1","undefined","children","as","asProp","SLOT_RENDER_FUNCTION_SYMBOL","renderFunction","rest","render","React","Fragment","shouldOmitAsProp","omit"],"mappings":";;;;+BAoBgBA;;aAAAA;;;6DApBO;sBACF;2BACuB;AAkBrC,SAASA,SAASC,KAAK,EAAE;IAC9B,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IACnB,MAAMC,YAAYC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC9C,KAAK,MAAMC,YAAYJ,UAAW;QAChC,MAAM,CAACK,MAAMC,MAAM,GAAGC,QAAQV,OAAOO;QACrCN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IACxB;IACA,OAAO;QACLR;QACAC,WAAWA;IACb;AACF;AACA,SAASQ,QAAQV,KAAK,EAAEO,QAAQ,EAAE;IAChC,IAAII,mBAAmBC;IACvB,MAAMH,QAAQT,KAAK,CAACO,SAAS;IAC7B,IAAIE,UAAUI,WAAW;QACvB,OAAO;YAAC,IAAI;YAAEA;SAAU;IAC1B,CAAC;IACD,MAAM,EACJC,SAAQ,EACRC,IAAIC,OAAM,EACV,CAACC,sCAA2B,CAAC,EAAEC,eAAc,EAC7C,GAAGC,MACJ,GAAGV;IACJ,MAAMD,OAAO,AAAC,CAAA,AAACG,CAAAA,oBAAoBX,MAAMM,UAAU,AAAD,MAAO,IAAI,IAAIK,sBAAsB,KAAK,IAAI,KAAK,IAAIA,iBAAiB,CAACJ,SAAS,AAAD,MAAOM,aAAa,OAAOb,MAAMM,UAAU,CAACC,SAAS,KAAK,WAAWS,UAAW,CAAA,AAACJ,CAAAA,qBAAqBZ,MAAMM,UAAU,AAAD,MAAO,IAAI,IAAIM,uBAAuB,KAAK,IAAI,KAAK,IAAIA,kBAAkB,CAACL,SAAS,AAAD,KAAM,QAAQP,MAAMM,UAAU,CAACC,SAAS;IACnX,IAAIW,kBAAkB,OAAOJ,aAAa,YAAY;QACpD,MAAMM,SAASF,kBAAkBJ;QACjC,OAAO;YAACO,OAAMC,QAAQ;YAAE;gBACtBR,UAAUM,OAAOZ,MAAMW;YACzB;SAAE;IACJ,CAAC;IACD,MAAMI,mBAAmB,OAAOf,SAAS,YAAYQ;IACrD,MAAMd,YAAYqB,mBAAmBC,IAAAA,UAAI,EAACf,OAAO;QAAC;KAAK,IAAIA,KAAK;IAChE,OAAO;QAACD;QAAMN;KAAU;AAC1B,EACA,oCAAoC"}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "getSlotsNext", {
|
6
|
+
enumerable: true,
|
7
|
+
get: ()=>getSlotsNext
|
8
|
+
});
|
9
|
+
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
10
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
11
|
+
function getSlotsNext(state) {
|
12
|
+
const slots = {};
|
13
|
+
const slotProps = {};
|
14
|
+
const slotNames = Object.keys(state.components);
|
15
|
+
for (const slotName of slotNames){
|
16
|
+
const [slot, props] = getSlotNext(state, slotName);
|
17
|
+
slots[slotName] = slot;
|
18
|
+
slotProps[slotName] = props;
|
19
|
+
}
|
20
|
+
return {
|
21
|
+
slots,
|
22
|
+
slotProps: slotProps
|
23
|
+
};
|
24
|
+
}
|
25
|
+
function getSlotNext(state, slotName) {
|
26
|
+
var _state_components, _state_components1;
|
27
|
+
const props = state[slotName];
|
28
|
+
if (props === undefined) {
|
29
|
+
return [
|
30
|
+
null,
|
31
|
+
undefined
|
32
|
+
];
|
33
|
+
}
|
34
|
+
const { as: asProp , ...propsWithoutAs } = props;
|
35
|
+
const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];
|
36
|
+
const shouldOmitAsProp = typeof slot === 'string' && asProp;
|
37
|
+
const slotProps = shouldOmitAsProp ? propsWithoutAs : props;
|
38
|
+
return [
|
39
|
+
slot,
|
40
|
+
slotProps
|
41
|
+
];
|
42
|
+
} //# sourceMappingURL=getSlotsNext.js.map
|
43
|
+
|
44
|
+
//# sourceMappingURL=getSlotsNext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../lib/compose/getSlotsNext.js"],"sourcesContent":["import * as React from 'react';\n/**\n * Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma\n */\nexport function getSlotsNext(state) {\n const slots = {};\n const slotProps = {};\n const slotNames = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlotNext(state, slotName);\n slots[slotName] = slot;\n slotProps[slotName] = props;\n }\n return {\n slots,\n slotProps: slotProps\n };\n}\nfunction getSlotNext(state, slotName) {\n var _state_components, _state_components1;\n const props = state[slotName];\n if (props === undefined) {\n return [null, undefined];\n }\n const {\n as: asProp,\n ...propsWithoutAs\n } = props;\n const slot = ((_state_components = state.components) === null || _state_components === void 0 ? void 0 : _state_components[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_state_components1 = state.components) === null || _state_components1 === void 0 ? void 0 : _state_components1[slotName]) || 'div' : state.components[slotName];\n const shouldOmitAsProp = typeof slot === 'string' && asProp;\n const slotProps = shouldOmitAsProp ? propsWithoutAs : props;\n return [slot, slotProps];\n}\n//# sourceMappingURL=getSlotsNext.js.map"],"names":["getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","_state_components","_state_components1","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":";;;;+BAIgBA;;aAAAA;;;6DAJO;AAIhB,SAASA,aAAaC,KAAK,EAAE;IAClC,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IACnB,MAAMC,YAAYC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC9C,KAAK,MAAMC,YAAYJ,UAAW;QAChC,MAAM,CAACK,MAAMC,MAAM,GAAGC,YAAYV,OAAOO;QACzCN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IACxB;IACA,OAAO;QACLR;QACAC,WAAWA;IACb;AACF;AACA,SAASQ,YAAYV,KAAK,EAAEO,QAAQ,EAAE;IACpC,IAAII,mBAAmBC;IACvB,MAAMH,QAAQT,KAAK,CAACO,SAAS;IAC7B,IAAIE,UAAUI,WAAW;QACvB,OAAO;YAAC,IAAI;YAAEA;SAAU;IAC1B,CAAC;IACD,MAAM,EACJC,IAAIC,OAAM,EACV,GAAGC,gBACJ,GAAGP;IACJ,MAAMD,OAAO,AAAC,CAAA,AAACG,CAAAA,oBAAoBX,MAAMM,UAAU,AAAD,MAAO,IAAI,IAAIK,sBAAsB,KAAK,IAAI,KAAK,IAAIA,iBAAiB,CAACJ,SAAS,AAAD,MAAOM,aAAa,OAAOb,MAAMM,UAAU,CAACC,SAAS,KAAK,WAAWQ,UAAW,CAAA,AAACH,CAAAA,qBAAqBZ,MAAMM,UAAU,AAAD,MAAO,IAAI,IAAIM,uBAAuB,KAAK,IAAI,KAAK,IAAIA,kBAAkB,CAACL,SAAS,AAAD,KAAM,QAAQP,MAAMM,UAAU,CAACC,SAAS;IACnX,MAAMU,mBAAmB,OAAOT,SAAS,YAAYO;IACrD,MAAMb,YAAYe,mBAAmBD,iBAAiBP,KAAK;IAC3D,OAAO;QAACD;QAAMN;KAAU;AAC1B,EACA,wCAAwC"}
|
@@ -7,6 +7,8 @@ _exportStar(require("./getSlots"), exports);
|
|
7
7
|
_exportStar(require("./resolveShorthand"), exports);
|
8
8
|
_exportStar(require("./types"), exports);
|
9
9
|
_exportStar(require("./isResolvedShorthand"), exports);
|
10
|
+
_exportStar(require("./constants"), exports);
|
11
|
+
_exportStar(require("./getSlotsNext"), exports);
|
10
12
|
//# sourceMappingURL=index.js.map
|
11
13
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../lib/compose/index.js"],"sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;oBAAc;oBACA;oBACA;oBACA;CACd,iCAAiC"}
|
1
|
+
{"version":3,"sources":["../../lib/compose/index.js"],"sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\nexport * from './constants';\nexport * from './getSlotsNext';\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;oBAAc;oBACA;oBACA;oBACA;oBACA;oBACA;CACd,iCAAiC"}
|
@@ -7,23 +7,28 @@ Object.defineProperty(exports, "resolveShorthand", {
|
|
7
7
|
get: ()=>resolveShorthand
|
8
8
|
});
|
9
9
|
const _react = require("react");
|
10
|
+
const _constants = require("./constants");
|
10
11
|
const resolveShorthand = (value, options)=>{
|
11
12
|
const { required =false , defaultProps } = options || {};
|
12
13
|
if (value === null || value === undefined && !required) {
|
13
14
|
return undefined;
|
14
15
|
}
|
15
16
|
let resolvedShorthand = {};
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
16
18
|
if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || /*#__PURE__*/ (0, _react.isValidElement)(value)) {
|
17
19
|
resolvedShorthand.children = value;
|
18
20
|
} else if (typeof value === 'object') {
|
19
|
-
resolvedShorthand =
|
20
|
-
...value
|
21
|
-
};
|
21
|
+
resolvedShorthand = value;
|
22
22
|
}
|
23
|
-
|
23
|
+
resolvedShorthand = {
|
24
24
|
...defaultProps,
|
25
25
|
...resolvedShorthand
|
26
|
-
}
|
26
|
+
};
|
27
|
+
if (typeof resolvedShorthand.children === 'function') {
|
28
|
+
resolvedShorthand[_constants.SLOT_RENDER_FUNCTION_SYMBOL] = resolvedShorthand.children;
|
29
|
+
resolvedShorthand.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;
|
30
|
+
}
|
31
|
+
return resolvedShorthand;
|
27
32
|
}; //# sourceMappingURL=resolveShorthand.js.map
|
28
33
|
|
29
34
|
//# sourceMappingURL=resolveShorthand.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../lib/compose/resolveShorthand.js"],"sourcesContent":["import { isValidElement } from 'react';\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 = (value, options) => {\n const {\n required = false,\n defaultProps\n } = options || {};\n if (value === null || value === undefined && !required) {\n return undefined;\n }\n let resolvedShorthand = {};\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || /*#__PURE__*/isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand =
|
1
|
+
{"version":3,"sources":["../../lib/compose/resolveShorthand.js"],"sourcesContent":["import { isValidElement } from 'react';\nimport { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\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 = (value, options) => {\n const {\n required = false,\n defaultProps\n } = options || {};\n if (value === null || value === undefined && !required) {\n return undefined;\n }\n let resolvedShorthand = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || /*#__PURE__*/isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n resolvedShorthand = {\n ...defaultProps,\n ...resolvedShorthand\n };\n if (typeof resolvedShorthand.children === 'function') {\n resolvedShorthand[SLOT_RENDER_FUNCTION_SYMBOL] = resolvedShorthand.children;\n resolvedShorthand.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;\n }\n return resolvedShorthand;\n};\n//# sourceMappingURL=resolveShorthand.js.map"],"names":["resolveShorthand","value","options","required","defaultProps","undefined","resolvedShorthand","Array","isArray","isValidElement","children","SLOT_RENDER_FUNCTION_SYMBOL"],"mappings":";;;;+BAQaA;;aAAAA;;uBARkB;2BACa;AAOrC,MAAMA,mBAAmB,CAACC,OAAOC,UAAY;IAClD,MAAM,EACJC,UAAW,KAAK,CAAA,EAChBC,aAAY,EACb,GAAGF,WAAW,CAAC;IAChB,IAAID,UAAU,IAAI,IAAIA,UAAUI,aAAa,CAACF,UAAU;QACtD,OAAOE;IACT,CAAC;IACD,IAAIC,oBAAoB,CAAC;IACzB,8DAA8D;IAC9D,IAAI,OAAOL,UAAU,YAAY,OAAOA,UAAU,YAAYM,MAAMC,OAAO,CAACP,UAAU,WAAW,GAAEQ,IAAAA,qBAAc,EAACR,QAAQ;QACxHK,kBAAkBI,QAAQ,GAAGT;IAC/B,OAAO,IAAI,OAAOA,UAAU,UAAU;QACpCK,oBAAoBL;IACtB,CAAC;IACDK,oBAAoB;QAClB,GAAGF,YAAY;QACf,GAAGE,iBAAiB;IACtB;IACA,IAAI,OAAOA,kBAAkBI,QAAQ,KAAK,YAAY;QACpDJ,iBAAiB,CAACK,sCAA2B,CAAC,GAAGL,kBAAkBI,QAAQ;QAC3EJ,kBAAkBI,QAAQ,GAAGN,iBAAiB,IAAI,IAAIA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaM,QAAQ;IAChH,CAAC;IACD,OAAOJ;AACT,GACA,4CAA4C"}
|
@@ -8,37 +8,26 @@ Object.defineProperty(exports, "useControllableState", {
|
|
8
8
|
});
|
9
9
|
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
10
10
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
11
|
-
function isFactoryDispatch(newState) {
|
12
|
-
return typeof newState === 'function';
|
13
|
-
}
|
14
11
|
const useControllableState = (options)=>{
|
15
|
-
const
|
16
|
-
|
17
|
-
|
18
|
-
const state = isControlled ? options.state : internalState;
|
19
|
-
const stateRef = _react.useRef(state);
|
20
|
-
_react.useEffect(()=>{
|
21
|
-
stateRef.current = state;
|
22
|
-
}, [
|
23
|
-
state
|
24
|
-
]);
|
25
|
-
// To match the behavior of the setter returned by React.useState, this callback's identity
|
26
|
-
// should never change. This means it MUST NOT directly reference variables that can change.
|
27
|
-
const setState = _react.useCallback((newState)=>{
|
28
|
-
// React dispatch can use a factory
|
29
|
-
// https://reactjs.org/docs/hooks-reference.html#functional-updates
|
30
|
-
if (isFactoryDispatch(newState)) {
|
31
|
-
stateRef.current = newState(stateRef.current);
|
32
|
-
} else {
|
33
|
-
stateRef.current = newState;
|
12
|
+
const [internalState, setInternalState] = _react.useState(()=>{
|
13
|
+
if (options.defaultState === undefined) {
|
14
|
+
return options.initialState;
|
34
15
|
}
|
35
|
-
|
36
|
-
}
|
37
|
-
return [
|
38
|
-
state,
|
39
|
-
|
16
|
+
return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;
|
17
|
+
});
|
18
|
+
return useIsControlled(options.state) ? [
|
19
|
+
options.state,
|
20
|
+
noop
|
21
|
+
] : [
|
22
|
+
internalState,
|
23
|
+
setInternalState
|
40
24
|
];
|
41
25
|
};
|
26
|
+
function isInitializer(value) {
|
27
|
+
return typeof value === 'function';
|
28
|
+
}
|
29
|
+
function noop() {
|
30
|
+
/* noop */ }
|
42
31
|
/**
|
43
32
|
* Helper hook to handle previous comparison of controlled/uncontrolled
|
44
33
|
* Prints an error when isControlled value switches between subsequent renders
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../lib/hooks/useControllableState.js"],"sourcesContent":["import * as React from 'react';\
|
1
|
+
{"version":3,"sources":["../../lib/hooks/useControllableState.js"],"sourcesContent":["import * as React from 'react';\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */\nexport const useControllableState = options => {\n const [internalState, setInternalState] = React.useState(() => {\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];\n};\nfunction isInitializer(value) {\n return typeof value === 'function';\n}\nfunction noop() {\n /* noop */}\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 => {\n const [isControlled] = React.useState(() => controlledValue !== undefined);\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 const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n // eslint-disable-next-line no-console\n console.error([\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));\n }\n }, [isControlled, controlledValue]);\n }\n return isControlled;\n};\n//# sourceMappingURL=useControllableState.js.map"],"names":["useControllableState","options","internalState","setInternalState","React","useState","defaultState","undefined","initialState","isInitializer","useIsControlled","state","noop","value","controlledValue","isControlled","process","env","NODE_ENV","useEffect","error","Error","controlWarning","undefinedWarning","console","stack","join"],"mappings":";;;;+BAkBaA;;aAAAA;;;6DAlBU;AAkBhB,MAAMA,uBAAuBC,CAAAA,UAAW;IAC7C,MAAM,CAACC,eAAeC,iBAAiB,GAAGC,OAAMC,QAAQ,CAAC,IAAM;QAC7D,IAAIJ,QAAQK,YAAY,KAAKC,WAAW;YACtC,OAAON,QAAQO,YAAY;QAC7B,CAAC;QACD,OAAOC,cAAcR,QAAQK,YAAY,IAAIL,QAAQK,YAAY,KAAKL,QAAQK,YAAY;IAC5F;IACA,OAAOI,gBAAgBT,QAAQU,KAAK,IAAI;QAACV,QAAQU,KAAK;QAAEC;KAAK,GAAG;QAACV;QAAeC;KAAiB;AACnG;AACA,SAASM,cAAcI,KAAK,EAAE;IAC5B,OAAO,OAAOA,UAAU;AAC1B;AACA,SAASD,OAAO;AACd,QAAQ,GAAE;AACZ;;;;CAIC,GACD,MAAMF,kBAAkBI,CAAAA,kBAAmB;IACzC,MAAM,CAACC,aAAa,GAAGX,OAAMC,QAAQ,CAAC,IAAMS,oBAAoBP;IAChE,IAAIS,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,wFAAwF;QACxF,sDAAsD;QACtDd,OAAMe,SAAS,CAAC,IAAM;YACpB,IAAIJ,iBAAkBD,CAAAA,oBAAoBP,SAAQ,GAAI;gBACpD,MAAMa,QAAQ,IAAIC;gBAClB,MAAMC,iBAAiBP,eAAe,0CAA0C,wCAAwC;gBACxH,MAAMQ,mBAAmBR,eAAe,4BAA4B,wBAAwB;gBAC5F,sCAAsC;gBACtCS,QAAQJ,KAAK,CAAC;oBACd,sBAAsB;oBACtB,6BAA6BE,iBAAiB;oBAAwC,mBAAmBC,mBAAmB;oBAAoC;oBAAsG;oBAA6DH,MAAMK,KAAK;iBAAC,CAACC,IAAI,CAAC;YACvV,CAAC;QACH,GAAG;YAACX;YAAcD;SAAgB;IACpC,CAAC;IACD,OAAOC;AACT,GACA,gDAAgD"}
|
package/lib-commonjs/index.js
CHANGED
@@ -10,8 +10,10 @@ function _export(target, all) {
|
|
10
10
|
}
|
11
11
|
_export(exports, {
|
12
12
|
getSlots: ()=>_index.getSlots,
|
13
|
+
getSlotsNext: ()=>_index.getSlotsNext,
|
13
14
|
resolveShorthand: ()=>_index.resolveShorthand,
|
14
15
|
isResolvedShorthand: ()=>_index.isResolvedShorthand,
|
16
|
+
SLOT_RENDER_FUNCTION_SYMBOL: ()=>_index.SLOT_RENDER_FUNCTION_SYMBOL,
|
15
17
|
IdPrefixProvider: ()=>_index1.IdPrefixProvider,
|
16
18
|
resetIdsForTests: ()=>_index1.resetIdsForTests,
|
17
19
|
useControllableState: ()=>_index1.useControllableState,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../lib/index.js"],"sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport { IdPrefixProvider, resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useScrollbarWidth, useTimeout } from './hooks/index';\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\nexport { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, isHTMLElement, isInteractiveHTMLElement, omit } from './utils/index';\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n//# sourceMappingURL=index.js.map"],"names":["getSlots","resolveShorthand","isResolvedShorthand","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords"],"mappings":";;;;;;;;;;;IAASA,QAAQ,MAARA,eAAQ;IAAEC,gBAAgB,MAAhBA,uBAAgB;IAAEC,mBAAmB,MAAnBA,0BAAmB;
|
1
|
+
{"version":3,"sources":["../lib/index.js"],"sourcesContent":["export { getSlots, getSlotsNext, resolveShorthand, isResolvedShorthand, SLOT_RENDER_FUNCTION_SYMBOL } from './compose/index';\nexport { IdPrefixProvider, resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useScrollbarWidth, useTimeout } from './hooks/index';\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\nexport { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, isHTMLElement, isInteractiveHTMLElement, omit } from './utils/index';\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n//# sourceMappingURL=index.js.map"],"names":["getSlots","getSlotsNext","resolveShorthand","isResolvedShorthand","SLOT_RENDER_FUNCTION_SYMBOL","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords"],"mappings":";;;;;;;;;;;IAASA,QAAQ,MAARA,eAAQ;IAAEC,YAAY,MAAZA,mBAAY;IAAEC,gBAAgB,MAAhBA,uBAAgB;IAAEC,mBAAmB,MAAnBA,0BAAmB;IAAEC,2BAA2B,MAA3BA,kCAA2B;IAC1FC,gBAAgB,MAAhBA,wBAAgB;IAAEC,gBAAgB,MAAhBA,wBAAgB;IAAEC,oBAAoB,MAApBA,4BAAoB;IAAEC,gBAAgB,MAAhBA,wBAAgB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,cAAc,MAAdA,sBAAc;IAAEC,KAAK,MAALA,aAAK;IAAEC,yBAAyB,MAAzBA,iCAAyB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,iBAAiB,MAAjBA,yBAAiB;IAAEC,kBAAkB,MAAlBA,0BAAkB;IAAEC,WAAW,MAAXA,mBAAW;IAAEC,iBAAiB,MAAjBA,yBAAiB;IAAEC,UAAU,MAAVA,kBAAU;IAC7OC,SAAS,MAATA,iBAAS;IAAEC,QAAQ,MAARA,gBAAQ;IAAEC,WAAW,MAAXA,mBAAW;IAChCC,KAAK,MAALA,aAAK;IAAEC,qBAAqB,MAArBA,6BAAqB;IAAEC,yBAAyB,MAAzBA,iCAAyB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,cAAc,MAAdA,sBAAc;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,wBAAwB,MAAxBA,gCAAwB;IAAEC,IAAI,MAAJA,YAAI;IACrIC,2BAA2B,MAA3BA,mCAA2B;IAAEC,eAAe,MAAfA,uBAAe;IAAEC,eAAe,MAAfA,uBAAe;IAC7DC,YAAY,MAAZA,oBAAY;IAAEC,YAAY,MAAZA,oBAAY;IAAEC,oBAAoB,MAApBA,4BAAoB;;uBALkD;wBACmJ;wBAC7M;wBACqG;wBACxE;wBACb;CACjE,iCAAiC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.8.1",
|
4
4
|
"description": "A set of general React-specific utilities.",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -28,7 +28,7 @@
|
|
28
28
|
"@fluentui/scripts-tasks": "*"
|
29
29
|
},
|
30
30
|
"dependencies": {
|
31
|
-
"@fluentui/keyboard-keys": "^9.0.
|
31
|
+
"@fluentui/keyboard-keys": "^9.0.3",
|
32
32
|
"@swc/helpers": "^0.4.14"
|
33
33
|
},
|
34
34
|
"peerDependencies": {
|
package/.swcrc
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"$schema": "https://json.schemastore.org/swcrc",
|
3
|
-
"exclude": [
|
4
|
-
"/testing",
|
5
|
-
"/**/*.cy.ts",
|
6
|
-
"/**/*.cy.tsx",
|
7
|
-
"/**/*.spec.ts",
|
8
|
-
"/**/*.spec.tsx",
|
9
|
-
"/**/*.test.ts",
|
10
|
-
"/**/*.test.tsx"
|
11
|
-
],
|
12
|
-
"jsc": {
|
13
|
-
"parser": {
|
14
|
-
"syntax": "typescript",
|
15
|
-
"tsx": true,
|
16
|
-
"decorators": false,
|
17
|
-
"dynamicImport": false
|
18
|
-
},
|
19
|
-
"externalHelpers": true,
|
20
|
-
"transform": {
|
21
|
-
"react": {
|
22
|
-
"runtime": "classic",
|
23
|
-
"useSpread": true
|
24
|
-
}
|
25
|
-
},
|
26
|
-
"target": "es2019"
|
27
|
-
},
|
28
|
-
"minify": false,
|
29
|
-
"sourceMaps": true
|
30
|
-
}
|