@fluentui/react-utilities 9.10.0 → 9.10.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 +22 -1
- package/CHANGELOG.md +12 -2
- package/dist/index.d.ts +5 -0
- package/lib/compose/getSlotsNext.js +5 -0
- package/lib/compose/getSlotsNext.js.map +1 -1
- package/lib/selection/useSelection.js +10 -22
- package/lib/selection/useSelection.js.map +1 -1
- package/lib-commonjs/compose/getSlotsNext.js.map +1 -1
- package/lib-commonjs/selection/useSelection.js +10 -22
- package/lib-commonjs/selection/useSelection.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,28 @@
|
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Mon, 03 Jul 2023 11:54:00 GMT",
|
6
|
+
"tag": "@fluentui/react-utilities_v9.10.1",
|
7
|
+
"version": "9.10.1",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "bernardo.sunderhus@gmail.com",
|
12
|
+
"package": "@fluentui/react-utilities",
|
13
|
+
"commit": "7d519bdcaef0a3249b6eae721fea0e5f096f6d35",
|
14
|
+
"comment": "bugfix: removes default prevention verification on selection"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"author": "bernardo.sunderhus@gmail.com",
|
18
|
+
"package": "@fluentui/react-utilities",
|
19
|
+
"commit": "cbfa9a3717782183ebc86149abcde6468f97afa8",
|
20
|
+
"comment": "chore: adds internal tag on jsdoc for getSlotsNext"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"date": "Wed, 28 Jun 2023 11:12:35 GMT",
|
6
27
|
"tag": "@fluentui/react-utilities_v9.10.0",
|
7
28
|
"version": "9.10.0",
|
8
29
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,22 @@
|
|
1
1
|
# Change Log - @fluentui/react-utilities
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Mon, 03 Jul 2023 11:54:00 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.10.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.10.1)
|
8
|
+
|
9
|
+
Mon, 03 Jul 2023 11:54:00 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.10.0..@fluentui/react-utilities_v9.10.1)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- bugfix: removes default prevention verification on selection ([PR #28365](https://github.com/microsoft/fluentui/pull/28365) by bernardo.sunderhus@gmail.com)
|
15
|
+
- chore: adds internal tag on jsdoc for getSlotsNext ([PR #28348](https://github.com/microsoft/fluentui/pull/28348) by bernardo.sunderhus@gmail.com)
|
16
|
+
|
7
17
|
## [9.10.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.10.0)
|
8
18
|
|
9
|
-
Wed, 28 Jun 2023 11:
|
19
|
+
Wed, 28 Jun 2023 11:12:35 GMT
|
10
20
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.9.4..@fluentui/react-utilities_v9.10.0)
|
11
21
|
|
12
22
|
### Minor changes
|
package/dist/index.d.ts
CHANGED
@@ -164,6 +164,11 @@ export declare function getSlots<R extends SlotPropsRecord>(state: ComponentStat
|
|
164
164
|
|
165
165
|
/**
|
166
166
|
* Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
|
167
|
+
*
|
168
|
+
* @internal
|
169
|
+
* This is an internal temporary method, this method will cease to exist eventually!
|
170
|
+
*
|
171
|
+
* * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️
|
167
172
|
*/
|
168
173
|
export declare function getSlotsNext<R extends SlotPropsRecord>(state: ComponentState<R>): {
|
169
174
|
slots: Slots<R>;
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
/**
|
3
3
|
* Similar to `getSlots`, main difference is that it's compatible with new custom jsx pragma
|
4
|
+
*
|
5
|
+
* @internal
|
6
|
+
* This is an internal temporary method, this method will cease to exist eventually!
|
7
|
+
*
|
8
|
+
* * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️
|
4
9
|
*/ export function getSlotsNext(state) {
|
5
10
|
const slots = {};
|
6
11
|
const slotProps = {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["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\n type NonUndefined<T> = T extends undefined ? never : T;\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp, ...propsWithoutAs } = props as NonUndefined<typeof 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"],"names":["React","getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAI/B
|
1
|
+
{"version":3,"sources":["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 *\n * @internal\n * This is an internal temporary method, this method will cease to exist eventually!\n *\n * * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️\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\n type NonUndefined<T> = T extends undefined ? never : T;\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp, ...propsWithoutAs } = props as NonUndefined<typeof 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"],"names":["React","getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAI/B;;;;;;;CAOC,GACD,OAAO,SAASC,aACdC,KAAwB,EAIxB;IACA,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IAEnB,MAAMC,YAAyBC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC3D,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;QAAER;QAAOC,WAAWA;IAA2C;AACxE,CAAC;AAED,SAASQ,YACPV,KAAwB,EACxBO,QAAW,EACsC;QAY/CP,mBACcA;IAZhB,MAAMS,QAAQT,KAAK,CAACO,SAAS;IAE7B,IAAIE,UAAUE,WAAW;QACvB,OAAO;YAAC,IAAI;YAAEA;SAAkB;IAClC,CAAC;IAGD,yFAAyF;IACzF,MAAM,EAAEC,IAAIC,OAAM,EAAE,GAAGC,gBAAgB,GAAGL;IAE1C,MAAMD,OACJR,CAAAA,CAAAA,oBAAAA,MAAMM,UAAU,cAAhBN,+BAAAA,KAAAA,IAAAA,iBAAkB,CAACO,SAAS,AAAD,MAAMI,aAAa,OAAOX,MAAMM,UAAU,CAACC,SAAS,KAAK,WAChFM,UAAUb,CAAAA,CAAAA,qBAAAA,MAAMM,UAAU,cAAhBN,gCAAAA,KAAAA,IAAAA,kBAAkB,CAACO,SAAS,AAAD,KAAK,QAC1CP,MAAMM,UAAU,CAACC,SAAS;IAGhC,MAAMQ,mBAAmB,OAAOP,SAAS,YAAYK;IACrD,MAAMX,YAA8Ba,mBAAmBD,iBAAiBL,KAAK;IAE7E,OAAO;QAACD;QAAMN;KAAkB;AAClC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { useControllableState } from '../hooks/useControllableState';
|
3
3
|
import { createSetFromIterable } from '../utils/createSetFromIterable';
|
4
|
-
function
|
4
|
+
function useSelectionState(params) {
|
5
5
|
const [selected, setSelected] = useControllableState({
|
6
6
|
initialState: new Set(),
|
7
7
|
defaultState: React.useMemo(()=>params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems), [
|
@@ -16,10 +16,15 @@ function useSingleSelection(params) {
|
|
16
16
|
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
17
17
|
selectedItems: nextSelectedItems
|
18
18
|
});
|
19
|
-
|
20
|
-
setSelected(nextSelectedItems);
|
21
|
-
}
|
19
|
+
setSelected(nextSelectedItems);
|
22
20
|
};
|
21
|
+
return [
|
22
|
+
selected,
|
23
|
+
changeSelection
|
24
|
+
];
|
25
|
+
}
|
26
|
+
function useSingleSelection(params) {
|
27
|
+
const [selected, changeSelection] = useSelectionState(params);
|
23
28
|
var _selected_has;
|
24
29
|
const methods = {
|
25
30
|
deselectItem: (event)=>changeSelection(event, new Set()),
|
@@ -43,24 +48,7 @@ function useSingleSelection(params) {
|
|
43
48
|
];
|
44
49
|
}
|
45
50
|
function useMultipleSelection(params) {
|
46
|
-
const [selected,
|
47
|
-
initialState: new Set(),
|
48
|
-
defaultState: React.useMemo(()=>params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems), [
|
49
|
-
params.defaultSelectedItems
|
50
|
-
]),
|
51
|
-
state: React.useMemo(()=>params.selectedItems && createSetFromIterable(params.selectedItems), [
|
52
|
-
params.selectedItems
|
53
|
-
])
|
54
|
-
});
|
55
|
-
const changeSelection = (event, nextSelectedItems)=>{
|
56
|
-
var _params_onSelectionChange;
|
57
|
-
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
58
|
-
selectedItems: nextSelectedItems
|
59
|
-
});
|
60
|
-
if (!event.isDefaultPrevented()) {
|
61
|
-
setSelected(nextSelectedItems);
|
62
|
-
}
|
63
|
-
};
|
51
|
+
const [selected, changeSelection] = useSelectionState(params);
|
64
52
|
const methods = {
|
65
53
|
toggleItem: (event, itemId)=>{
|
66
54
|
const nextSelectedItems = new Set(selected);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, SelectionItemId, SelectionMethods } from './types';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\n\nfunction
|
1
|
+
{"version":3,"sources":["useSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, SelectionItemId, SelectionMethods } from './types';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\n\nfunction useSelectionState(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, setSelected] = useControllableState<Set<SelectionItemId>>({\n initialState: new Set(),\n defaultState: React.useMemo(\n () => params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems),\n [params.defaultSelectedItems],\n ),\n state: React.useMemo(\n () => params.selectedItems && createSetFromIterable(params.selectedItems),\n [params.selectedItems],\n ),\n });\n const changeSelection = (event: React.SyntheticEvent, nextSelectedItems: Set<SelectionItemId>) => {\n params.onSelectionChange?.(event, { selectedItems: nextSelectedItems });\n setSelected(nextSelectedItems);\n };\n return [selected, changeSelection] as const;\n}\n\nfunction useSingleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n deselectItem: event => changeSelection(event, new Set()),\n selectItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n toggleAllItems: () => {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');\n }\n },\n toggleItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n clearItems: event => changeSelection(event, new Set()),\n isSelected: itemId => selected.has(itemId) ?? false,\n };\n return [selected, methods] as const;\n}\n\nfunction useMultipleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n toggleItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n if (selected.has(itemId)) {\n nextSelectedItems.delete(itemId);\n } else {\n nextSelectedItems.add(itemId);\n }\n changeSelection(event, nextSelectedItems);\n },\n selectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.add(itemId);\n changeSelection(event, nextSelectedItems);\n },\n deselectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.delete(itemId);\n changeSelection(event, nextSelectedItems);\n },\n clearItems: event => {\n changeSelection(event, new Set());\n },\n isSelected: itemId => selected.has(itemId),\n toggleAllItems: (event, itemIds) => {\n const allItemsSelected = itemIds.every(itemId => selected.has(itemId));\n const nextSelectedItems = new Set(selected);\n if (allItemsSelected) {\n nextSelectedItems.clear();\n } else {\n itemIds.forEach(itemId => nextSelectedItems.add(itemId));\n }\n changeSelection(event, nextSelectedItems);\n },\n };\n return [selected, methods] as const;\n}\n\nexport function useSelection(params: SelectionHookParams) {\n if (params.selectionMode === 'multiselect') {\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMultipleSelection(params);\n }\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSingleSelection(params);\n}\n"],"names":["React","useControllableState","createSetFromIterable","useSelectionState","params","selected","setSelected","initialState","Set","defaultState","useMemo","defaultSelectedItems","state","selectedItems","changeSelection","event","nextSelectedItems","onSelectionChange","useSingleSelection","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","useSelection","selectionMode"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,oBAAoB,QAAQ,gCAAgC;AACrE,SAASC,qBAAqB,QAAQ,iCAAiC;AAEvE,SAASC,kBAAkBC,MAAkD,EAAE;IAC7E,MAAM,CAACC,UAAUC,YAAY,GAAGL,qBAA2C;QACzEM,cAAc,IAAIC;QAClBC,cAAcT,MAAMU,OAAO,CACzB,IAAMN,OAAOO,oBAAoB,IAAIT,sBAAsBE,OAAOO,oBAAoB,GACtF;YAACP,OAAOO,oBAAoB;SAAC;QAE/BC,OAAOZ,MAAMU,OAAO,CAClB,IAAMN,OAAOS,aAAa,IAAIX,sBAAsBE,OAAOS,aAAa,GACxE;YAACT,OAAOS,aAAa;SAAC;IAE1B;IACA,MAAMC,kBAAkB,CAACC,OAA6BC,oBAA4C;YAChGZ;QAAAA,CAAAA,4BAAAA,OAAOa,iBAAiB,cAAxBb,uCAAAA,KAAAA,IAAAA,0BAAAA,KAAAA,QAA2BW,OAAO;YAAEF,eAAeG;QAAkB;QACrEV,YAAYU;IACd;IACA,OAAO;QAACX;QAAUS;KAAgB;AACpC;AAEA,SAASI,mBAAmBd,MAAkD,EAAE;IAC9E,MAAM,CAACC,UAAUS,gBAAgB,GAAGX,kBAAkBC;QAW9BC;IAVxB,MAAMc,UAA4B;QAChCC,cAAcL,CAAAA,QAASD,gBAAgBC,OAAO,IAAIP;QAClDa,YAAY,CAACN,OAAOO,SAAWR,gBAAgBC,OAAO,IAAIP,IAAI;gBAACc;aAAO;QACtEC,gBAAgB,IAAM;YACpB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;gBACzC,MAAM,IAAIC,MAAM,mFAAmF;YACrG,CAAC;QACH;QACAC,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kB,GAAG,CAACZ;YAClD,CAAC;YACDR,gBAAgBC,OAAOC;QACzB;IACF;IACA,OAAO;QAACX;QAAUc;KAAQ;AAC5B;AAEA,OAAO,SAASqB,aAAapC,MAA2B,EAAE;IACxD,IAAIA,OAAOqC,aAAa,KAAK,eAAe;QAC1C,0EAA0E;QAC1E,sDAAsD;QACtD,OAAOT,qBAAqB5B;IAC9B,CAAC;IACD,0EAA0E;IAC1E,sDAAsD;IACtD,OAAOc,mBAAmBd;AAC5B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["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 */ export 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 [\n null,\n undefined\n ];\n }\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp , ...propsWithoutAs } = 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 [\n slot,\n slotProps\n ];\n}\n"],"names":["getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","_state_components","_state_components1","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":";;;;+
|
1
|
+
{"version":3,"sources":["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 *\n * @internal\n * This is an internal temporary method, this method will cease to exist eventually!\n *\n * * ❗️❗️ **DO NOT USE IT EXTERNALLY** ❗️❗️\n */ export 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 [\n null,\n undefined\n ];\n }\n // TS Error: Property 'as' does not exist on type 'UnknownSlotProps | undefined'.ts(2339)\n const { as: asProp , ...propsWithoutAs } = 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 [\n slot,\n slotProps\n ];\n}\n"],"names":["getSlotsNext","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlotNext","_state_components","_state_components1","undefined","as","asProp","propsWithoutAs","shouldOmitAsProp"],"mappings":";;;;+BAQoBA;;aAAAA;;;6DARG;AAQZ,SAASA,aAAaC,KAAK,EAAE;IACpC,MAAMC,QAAQ,CAAC;IACf,MAAMC,YAAY,CAAC;IACnB,MAAMC,YAAYC,OAAOC,IAAI,CAACL,MAAMM,UAAU;IAC9C,KAAK,MAAMC,YAAYJ,UAAU;QAC7B,MAAM,CAACK,MAAMC,MAAM,GAAGC,YAAYV,OAAOO;QACzCN,KAAK,CAACM,SAAS,GAAGC;QAClBN,SAAS,CAACK,SAAS,GAAGE;IAC1B;IACA,OAAO;QACHR;QACAC,WAAWA;IACf;AACJ;AACA,SAASQ,YAAYV,KAAK,EAAEO,QAAQ,EAAE;IAClC,IAAII,mBAAmBC;IACvB,MAAMH,QAAQT,KAAK,CAACO,SAAS;IAC7B,IAAIE,UAAUI,WAAW;QACrB,OAAO;YACH,IAAI;YACJA;SACH;IACL,CAAC;IACD,yFAAyF;IACzF,MAAM,EAAEC,IAAIC,OAAM,EAAG,GAAGC,gBAAgB,GAAGP;IAC3C,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;QACHD;QACAN;KACH;AACL"}
|
@@ -10,7 +10,7 @@ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildc
|
|
10
10
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
11
11
|
const _useControllableState = require("../hooks/useControllableState");
|
12
12
|
const _createSetFromIterable = require("../utils/createSetFromIterable");
|
13
|
-
function
|
13
|
+
function useSelectionState(params) {
|
14
14
|
const [selected, setSelected] = (0, _useControllableState.useControllableState)({
|
15
15
|
initialState: new Set(),
|
16
16
|
defaultState: _react.useMemo(()=>params.defaultSelectedItems && (0, _createSetFromIterable.createSetFromIterable)(params.defaultSelectedItems), [
|
@@ -25,10 +25,15 @@ function useSingleSelection(params) {
|
|
25
25
|
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
26
26
|
selectedItems: nextSelectedItems
|
27
27
|
});
|
28
|
-
|
29
|
-
setSelected(nextSelectedItems);
|
30
|
-
}
|
28
|
+
setSelected(nextSelectedItems);
|
31
29
|
};
|
30
|
+
return [
|
31
|
+
selected,
|
32
|
+
changeSelection
|
33
|
+
];
|
34
|
+
}
|
35
|
+
function useSingleSelection(params) {
|
36
|
+
const [selected, changeSelection] = useSelectionState(params);
|
32
37
|
var _selected_has;
|
33
38
|
const methods = {
|
34
39
|
deselectItem: (event)=>changeSelection(event, new Set()),
|
@@ -52,24 +57,7 @@ function useSingleSelection(params) {
|
|
52
57
|
];
|
53
58
|
}
|
54
59
|
function useMultipleSelection(params) {
|
55
|
-
const [selected,
|
56
|
-
initialState: new Set(),
|
57
|
-
defaultState: _react.useMemo(()=>params.defaultSelectedItems && (0, _createSetFromIterable.createSetFromIterable)(params.defaultSelectedItems), [
|
58
|
-
params.defaultSelectedItems
|
59
|
-
]),
|
60
|
-
state: _react.useMemo(()=>params.selectedItems && (0, _createSetFromIterable.createSetFromIterable)(params.selectedItems), [
|
61
|
-
params.selectedItems
|
62
|
-
])
|
63
|
-
});
|
64
|
-
const changeSelection = (event, nextSelectedItems)=>{
|
65
|
-
var _params_onSelectionChange;
|
66
|
-
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
67
|
-
selectedItems: nextSelectedItems
|
68
|
-
});
|
69
|
-
if (!event.isDefaultPrevented()) {
|
70
|
-
setSelected(nextSelectedItems);
|
71
|
-
}
|
72
|
-
};
|
60
|
+
const [selected, changeSelection] = useSelectionState(params);
|
73
61
|
const methods = {
|
74
62
|
toggleItem: (event, itemId)=>{
|
75
63
|
const nextSelectedItems = new Set(selected);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useSelection.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\nfunction
|
1
|
+
{"version":3,"sources":["useSelection.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\nfunction useSelectionState(params) {\n const [selected, setSelected] = useControllableState({\n initialState: new Set(),\n defaultState: React.useMemo(()=>params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems), [\n params.defaultSelectedItems\n ]),\n state: React.useMemo(()=>params.selectedItems && createSetFromIterable(params.selectedItems), [\n params.selectedItems\n ])\n });\n const changeSelection = (event, nextSelectedItems)=>{\n var _params_onSelectionChange;\n (_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {\n selectedItems: nextSelectedItems\n });\n setSelected(nextSelectedItems);\n };\n return [\n selected,\n changeSelection\n ];\n}\nfunction useSingleSelection(params) {\n const [selected, changeSelection] = useSelectionState(params);\n var _selected_has;\n const methods = {\n deselectItem: (event)=>changeSelection(event, new Set()),\n selectItem: (event, itemId)=>changeSelection(event, new Set([\n itemId\n ])),\n toggleAllItems: ()=>{\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');\n }\n },\n toggleItem: (event, itemId)=>changeSelection(event, new Set([\n itemId\n ])),\n clearItems: (event)=>changeSelection(event, new Set()),\n isSelected: (itemId)=>(_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false\n };\n return [\n selected,\n methods\n ];\n}\nfunction useMultipleSelection(params) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods = {\n toggleItem: (event, itemId)=>{\n const nextSelectedItems = new Set(selected);\n if (selected.has(itemId)) {\n nextSelectedItems.delete(itemId);\n } else {\n nextSelectedItems.add(itemId);\n }\n changeSelection(event, nextSelectedItems);\n },\n selectItem: (event, itemId)=>{\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.add(itemId);\n changeSelection(event, nextSelectedItems);\n },\n deselectItem: (event, itemId)=>{\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.delete(itemId);\n changeSelection(event, nextSelectedItems);\n },\n clearItems: (event)=>{\n changeSelection(event, new Set());\n },\n isSelected: (itemId)=>selected.has(itemId),\n toggleAllItems: (event, itemIds)=>{\n const allItemsSelected = itemIds.every((itemId)=>selected.has(itemId));\n const nextSelectedItems = new Set(selected);\n if (allItemsSelected) {\n nextSelectedItems.clear();\n } else {\n itemIds.forEach((itemId)=>nextSelectedItems.add(itemId));\n }\n changeSelection(event, nextSelectedItems);\n }\n };\n return [\n selected,\n methods\n ];\n}\nexport function useSelection(params) {\n if (params.selectionMode === 'multiselect') {\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMultipleSelection(params);\n }\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSingleSelection(params);\n}\n"],"names":["useSelection","useSelectionState","params","selected","setSelected","useControllableState","initialState","Set","defaultState","React","useMemo","defaultSelectedItems","createSetFromIterable","state","selectedItems","changeSelection","event","nextSelectedItems","_params_onSelectionChange","onSelectionChange","call","useSingleSelection","_selected_has","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","selectionMode"],"mappings":";;;;+BA2FgBA;;aAAAA;;;6DA3FO;sCACc;uCACC;AACtC,SAASC,kBAAkBC,MAAM,EAAE;IAC/B,MAAM,CAACC,UAAUC,YAAY,GAAGC,IAAAA,0CAAoB,EAAC;QACjDC,cAAc,IAAIC;QAClBC,cAAcC,OAAMC,OAAO,CAAC,IAAIR,OAAOS,oBAAoB,IAAIC,IAAAA,4CAAqB,EAACV,OAAOS,oBAAoB,GAAG;YAC/GT,OAAOS,oBAAoB;SAC9B;QACDE,OAA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