@deephaven/components 0.73.1-beta.0 → 0.74.1-beta.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/dist/Button.d.ts +1 -1
- package/dist/HierarchicalCheckboxMenu.js +1 -1
- package/dist/HierarchicalCheckboxMenu.js.map +1 -1
- package/dist/Select.d.ts +1 -1
- package/dist/spectrum/ItemContent.d.ts.map +1 -1
- package/dist/spectrum/ItemContent.js +2 -1
- package/dist/spectrum/ItemContent.js.map +1 -1
- package/dist/spectrum/picker/Picker.d.ts +6 -8
- package/dist/spectrum/picker/Picker.d.ts.map +1 -1
- package/dist/spectrum/picker/Picker.js +54 -59
- package/dist/spectrum/picker/Picker.js.map +1 -1
- package/dist/spectrum/picker/PickerNormalized.d.ts +16 -0
- package/dist/spectrum/picker/PickerNormalized.d.ts.map +1 -0
- package/dist/spectrum/picker/PickerNormalized.js +88 -0
- package/dist/spectrum/picker/PickerNormalized.js.map +1 -0
- package/dist/spectrum/picker/index.d.ts +2 -0
- package/dist/spectrum/picker/index.d.ts.map +1 -1
- package/dist/spectrum/picker/index.js +2 -0
- package/dist/spectrum/picker/index.js.map +1 -1
- package/dist/spectrum/picker/usePickerScrollOnOpen.d.ts +22 -0
- package/dist/spectrum/picker/usePickerScrollOnOpen.d.ts.map +1 -0
- package/dist/spectrum/picker/usePickerScrollOnOpen.js +33 -0
- package/dist/spectrum/picker/usePickerScrollOnOpen.js.map +1 -0
- package/dist/spectrum/utils/index.d.ts +2 -0
- package/dist/spectrum/utils/index.d.ts.map +1 -1
- package/dist/spectrum/utils/index.js +2 -0
- package/dist/spectrum/utils/index.js.map +1 -1
- package/dist/spectrum/utils/itemUtils.d.ts +29 -3
- package/dist/spectrum/utils/itemUtils.d.ts.map +1 -1
- package/dist/spectrum/utils/itemUtils.js +69 -3
- package/dist/spectrum/utils/itemUtils.js.map +1 -1
- package/dist/spectrum/utils/itemWrapperUtils.d.ts +12 -0
- package/dist/spectrum/utils/itemWrapperUtils.d.ts.map +1 -0
- package/dist/spectrum/utils/itemWrapperUtils.js +65 -0
- package/dist/spectrum/utils/itemWrapperUtils.js.map +1 -0
- package/dist/spectrum/utils/useRenderNormalizedItem.d.ts.map +1 -1
- package/dist/spectrum/utils/useRenderNormalizedItem.js +3 -3
- package/dist/spectrum/utils/useRenderNormalizedItem.js.map +1 -1
- package/dist/spectrum/utils/useStringifiedMultiSelection.d.ts.map +1 -1
- package/dist/spectrum/utils/useStringifiedMultiSelection.js +5 -2
- package/dist/spectrum/utils/useStringifiedMultiSelection.js.map +1 -1
- package/dist/spectrum/utils/useStringifiedSelection.d.ts +33 -0
- package/dist/spectrum/utils/useStringifiedSelection.d.ts.map +1 -0
- package/dist/spectrum/utils/useStringifiedSelection.js +50 -0
- package/dist/spectrum/utils/useStringifiedSelection.js.map +1 -0
- package/package.json +7 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { ItemContent } from "../ItemContent.js";
|
|
3
3
|
import { Item } from "../shared.js";
|
|
4
|
-
import { getItemKey } from "./itemUtils.js";
|
|
4
|
+
import { getItemKey, ITEM_EMPTY_STRING_TEXT_VALUE } from "./itemUtils.js";
|
|
5
5
|
/**
|
|
6
6
|
* Returns a render function that can be used to render a normalized item in
|
|
7
7
|
* collection components.
|
|
@@ -27,8 +27,8 @@ export function useRenderNormalizedItem(tooltipOptions) {
|
|
|
27
27
|
// The `textValue` prop gets used to provide the content of `<option>`
|
|
28
28
|
// elements that back the Spectrum Picker. These are not visible in the UI,
|
|
29
29
|
// but are used for accessibility purposes, so we set to an arbitrary
|
|
30
|
-
//
|
|
31
|
-
textValue: textValue === '' ?
|
|
30
|
+
// `ITEM_EMPTY_STRING_TEXT_VALUE` value so that they are not empty strings.
|
|
31
|
+
textValue: textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : textValue,
|
|
32
32
|
children: /*#__PURE__*/_jsx(ItemContent, {
|
|
33
33
|
tooltipOptions: tooltipOptions,
|
|
34
34
|
children: content
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderNormalizedItem.js","names":["useCallback","ItemContent","Item","getItemKey","jsx","_jsx","useRenderNormalizedItem","tooltipOptions","normalizedItem","_normalizedItem$item$","_normalizedItem$item","_normalizedItem$item$2","_normalizedItem$item2","key","content","item","textValue","children"],"sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"sourcesContent":["import { Key, useCallback } from 'react';\nimport { ItemContent } from '../ItemContent';\nimport { Item } from '../shared';\nimport {
|
|
1
|
+
{"version":3,"file":"useRenderNormalizedItem.js","names":["useCallback","ItemContent","Item","getItemKey","ITEM_EMPTY_STRING_TEXT_VALUE","jsx","_jsx","useRenderNormalizedItem","tooltipOptions","normalizedItem","_normalizedItem$item$","_normalizedItem$item","_normalizedItem$item$2","_normalizedItem$item2","key","content","item","textValue","children"],"sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"sourcesContent":["import { Key, useCallback } from 'react';\nimport { ItemContent } from '../ItemContent';\nimport { Item } from '../shared';\nimport {\n getItemKey,\n ITEM_EMPTY_STRING_TEXT_VALUE,\n NormalizedItem,\n TooltipOptions,\n} from './itemUtils';\n\n/**\n * Returns a render function that can be used to render a normalized item in\n * collection components.\n * @param tooltipOptions Tooltip options to use when rendering the item\n * @returns Render function for normalized items\n */\nexport function useRenderNormalizedItem(\n tooltipOptions: TooltipOptions | null\n): (normalizedItem: NormalizedItem) => JSX.Element {\n return useCallback(\n (normalizedItem: NormalizedItem) => {\n const key = getItemKey(normalizedItem);\n const content = normalizedItem.item?.content ?? '';\n const textValue = normalizedItem.item?.textValue ?? '';\n\n return (\n <Item\n // Note that setting the `key` prop explicitly on `Item` elements\n // causes the picker to expect `selectedKey` and `defaultSelectedKey`\n // to be strings. It also passes the stringified value of the key to\n // `onSelectionChange` handlers` regardless of the actual type of the\n // key. We can't really get around setting in order to support Windowed\n // data, so we'll need to do some manual conversion of keys to strings\n // in other components that use this hook.\n key={key as Key}\n // The `textValue` prop gets used to provide the content of `<option>`\n // elements that back the Spectrum Picker. These are not visible in the UI,\n // but are used for accessibility purposes, so we set to an arbitrary\n // `ITEM_EMPTY_STRING_TEXT_VALUE` value so that they are not empty strings.\n textValue={\n textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : textValue\n }\n >\n <ItemContent tooltipOptions={tooltipOptions}>{content}</ItemContent>\n </Item>\n );\n },\n [tooltipOptions]\n );\n}\n\nexport default useRenderNormalizedItem;\n"],"mappings":"AAAA,SAAcA,WAAW,QAAQ,OAAO;AAAC,SAChCC,WAAW;AAAA,SACXC,IAAI;AAAA,SAEXC,UAAU,EACVC,4BAA4B;AAK9B;AACA;AACA;AACA;AACA;AACA;AALA,SAAAC,GAAA,IAAAC,IAAA;AAMA,OAAO,SAASC,uBAAuBA,CACrCC,cAAqC,EACY;EACjD,OAAOR,WAAW,CACfS,cAA8B,IAAK;IAAA,IAAAC,qBAAA,EAAAC,oBAAA,EAAAC,sBAAA,EAAAC,qBAAA;IAClC,IAAMC,GAAG,GAAGX,UAAU,CAACM,cAAc,CAAC;IACtC,IAAMM,OAAO,IAAAL,qBAAA,IAAAC,oBAAA,GAAGF,cAAc,CAACO,IAAI,cAAAL,oBAAA,uBAAnBA,oBAAA,CAAqBI,OAAO,cAAAL,qBAAA,cAAAA,qBAAA,GAAI,EAAE;IAClD,IAAMO,SAAS,IAAAL,sBAAA,IAAAC,qBAAA,GAAGJ,cAAc,CAACO,IAAI,cAAAH,qBAAA,uBAAnBA,qBAAA,CAAqBI,SAAS,cAAAL,sBAAA,cAAAA,sBAAA,GAAI,EAAE;IAEtD,oBACEN,IAAA,CAACJ;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IAAA;MAEA;MACA;MACA;MACA;MACAe,SAAS,EACPA,SAAS,KAAK,EAAE,GAAGb,4BAA4B,GAAGa,SACnD;MAAAC,QAAA,eAEDZ,IAAA,CAACL,WAAW;QAACO,cAAc,EAAEA,cAAe;QAAAU,QAAA,EAAEH;MAAO,CAAc;IAAC,GAT/DD,GAUD,CAAC;EAEX,CAAC,EACD,CAACN,cAAc,CACjB,CAAC;AACH;AAEA,eAAeD,uBAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStringifiedMultiSelection.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useStringifiedMultiSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,OAAO,CAAC;AAClD,OAAO,EAEL,OAAO,EACP,aAAa,EAEb,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,mCAAmC;IAClD,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,YAAY,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,mBAAmB,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChD,YAAY,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,kCAAkC;IACjD,iCAAiC;IACjC,kBAAkB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACtC,yCAAyC;IACzC,yBAAyB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,gCAAgC;IAChC,kBAAkB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACtC,mEAAmE;IACnE,uBAAuB,EAAE,CAAC,IAAI,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CAC3D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,EAAE,mCAAmC,GAAG,kCAAkC,
|
|
1
|
+
{"version":3,"file":"useStringifiedMultiSelection.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useStringifiedMultiSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,OAAO,CAAC;AAClD,OAAO,EAEL,OAAO,EACP,aAAa,EAEb,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,mCAAmC;IAClD,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,YAAY,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,mBAAmB,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChD,YAAY,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,kCAAkC;IACjD,iCAAiC;IACjC,kBAAkB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACtC,yCAAyC;IACzC,yBAAyB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,gCAAgC;IAChC,kBAAkB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACtC,mEAAmE;IACnE,uBAAuB,EAAE,CAAC,IAAI,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CAC3D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,EAAE,mCAAmC,GAAG,kCAAkC,CA8C1E;AAED,eAAe,4BAA4B,CAAC"}
|
|
@@ -27,8 +27,11 @@ export function useStringifiedMultiSelection(_ref) {
|
|
|
27
27
|
var defaultSelectedStringKeys = useMemo(() => itemSelectionToStringSet(defaultSelectedKeys), [defaultSelectedKeys]);
|
|
28
28
|
var disabledStringKeys = useMemo(() => itemSelectionToStringSet(disabledKeys), [disabledKeys]);
|
|
29
29
|
var onStringSelectionChange = useCallback(keys => {
|
|
30
|
+
if (onChange == null) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
30
33
|
if (keys === 'all') {
|
|
31
|
-
onChange
|
|
34
|
+
onChange('all');
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
34
37
|
var actualKeys = new Set();
|
|
@@ -37,7 +40,7 @@ export function useStringifiedMultiSelection(_ref) {
|
|
|
37
40
|
actualKeys.add(getItemKey(item));
|
|
38
41
|
}
|
|
39
42
|
});
|
|
40
|
-
onChange
|
|
43
|
+
onChange(actualKeys);
|
|
41
44
|
}, [normalizedItems, onChange]);
|
|
42
45
|
return {
|
|
43
46
|
selectedStringKeys,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStringifiedMultiSelection.js","names":["useCallback","useMemo","getItemKey","itemSelectionToStringSet","useStringifiedMultiSelection","_ref","normalizedItems","defaultSelectedKeys","disabledKeys","selectedKeys","onChange","selectedStringKeys","defaultSelectedStringKeys","disabledStringKeys","onStringSelectionChange","keys","actualKeys","Set","forEach","item","has","String","add"],"sources":["../../../src/spectrum/utils/useStringifiedMultiSelection.ts"],"sourcesContent":["import { Key, useCallback, useMemo } from 'react';\nimport {\n getItemKey,\n ItemKey,\n ItemSelection,\n itemSelectionToStringSet,\n NormalizedItem,\n} from './itemUtils';\n\nexport interface UseStringifiedMultiSelectionOptions {\n normalizedItems: NormalizedItem[];\n selectedKeys?: 'all' | Iterable<ItemKey>;\n defaultSelectedKeys?: 'all' | Iterable<ItemKey>;\n disabledKeys?: Iterable<ItemKey>;\n /**\n * Handler that is called when the selection change.\n * Note that under the hood, this is just an alias for Spectrum's\n * `onSelectionChange`. We are renaming for better consistency with other\n * components.\n */\n onChange?: (keys: ItemSelection) => void;\n}\n\nexport interface UseStringifiedMultiSelectionResult {\n /** Stringified selection keys */\n selectedStringKeys?: 'all' | Set<Key>;\n /** Stringified default selection keys */\n defaultSelectedStringKeys?: 'all' | Set<Key>;\n /** Stringified disabled keys */\n disabledStringKeys?: 'all' | Set<Key>;\n /** Handler that is called when the string key selections change */\n onStringSelectionChange: (keys: 'all' | Set<Key>) => void;\n}\n\n/**\n * Spectrum collection components treat keys as strings if the `key` prop is\n * explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,\n * we need to ensure that keys are strings in order for selection to work. We\n * then need to convert back to the original key types in the onChange handler.\n * This hook encapsulates converting to and from strings so that keys can match\n * the original key type.\n * @param normalizedItems The normalized items to select from.\n * @param selectedKeys The currently selected keys in the collection.\n * @param defaultSelectedKeys The initial selected keys in the collection.\n * @param disabledKeys The currently disabled keys in the collection.\n * @param onChange Handler that is called when the selection changes.\n * @returns UseStringifiedMultiSelectionResult with stringified key sets and\n * string key selection change handler.\n */\nexport function useStringifiedMultiSelection({\n normalizedItems,\n defaultSelectedKeys,\n disabledKeys,\n selectedKeys,\n onChange,\n}: UseStringifiedMultiSelectionOptions): UseStringifiedMultiSelectionResult {\n const selectedStringKeys = useMemo(\n () => itemSelectionToStringSet(selectedKeys),\n [selectedKeys]\n );\n\n const defaultSelectedStringKeys = useMemo(\n () => itemSelectionToStringSet(defaultSelectedKeys),\n [defaultSelectedKeys]\n );\n\n const disabledStringKeys = useMemo(\n () => itemSelectionToStringSet(disabledKeys),\n [disabledKeys]\n );\n\n const onStringSelectionChange = useCallback(\n (keys: 'all' | Set<Key>) => {\n if (keys === 'all') {\n onChange
|
|
1
|
+
{"version":3,"file":"useStringifiedMultiSelection.js","names":["useCallback","useMemo","getItemKey","itemSelectionToStringSet","useStringifiedMultiSelection","_ref","normalizedItems","defaultSelectedKeys","disabledKeys","selectedKeys","onChange","selectedStringKeys","defaultSelectedStringKeys","disabledStringKeys","onStringSelectionChange","keys","actualKeys","Set","forEach","item","has","String","add"],"sources":["../../../src/spectrum/utils/useStringifiedMultiSelection.ts"],"sourcesContent":["import { Key, useCallback, useMemo } from 'react';\nimport {\n getItemKey,\n ItemKey,\n ItemSelection,\n itemSelectionToStringSet,\n NormalizedItem,\n} from './itemUtils';\n\nexport interface UseStringifiedMultiSelectionOptions {\n normalizedItems: NormalizedItem[];\n selectedKeys?: 'all' | Iterable<ItemKey>;\n defaultSelectedKeys?: 'all' | Iterable<ItemKey>;\n disabledKeys?: Iterable<ItemKey>;\n /**\n * Handler that is called when the selection change.\n * Note that under the hood, this is just an alias for Spectrum's\n * `onSelectionChange`. We are renaming for better consistency with other\n * components.\n */\n onChange?: (keys: ItemSelection) => void;\n}\n\nexport interface UseStringifiedMultiSelectionResult {\n /** Stringified selection keys */\n selectedStringKeys?: 'all' | Set<Key>;\n /** Stringified default selection keys */\n defaultSelectedStringKeys?: 'all' | Set<Key>;\n /** Stringified disabled keys */\n disabledStringKeys?: 'all' | Set<Key>;\n /** Handler that is called when the string key selections change */\n onStringSelectionChange: (keys: 'all' | Set<Key>) => void;\n}\n\n/**\n * Spectrum collection components treat keys as strings if the `key` prop is\n * explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,\n * we need to ensure that keys are strings in order for selection to work. We\n * then need to convert back to the original key types in the onChange handler.\n * This hook encapsulates converting to and from strings so that keys can match\n * the original key type.\n * @param normalizedItems The normalized items to select from.\n * @param selectedKeys The currently selected keys in the collection.\n * @param defaultSelectedKeys The initial selected keys in the collection.\n * @param disabledKeys The currently disabled keys in the collection.\n * @param onChange Handler that is called when the selection changes.\n * @returns UseStringifiedMultiSelectionResult with stringified key sets and\n * string key selection change handler.\n */\nexport function useStringifiedMultiSelection({\n normalizedItems,\n defaultSelectedKeys,\n disabledKeys,\n selectedKeys,\n onChange,\n}: UseStringifiedMultiSelectionOptions): UseStringifiedMultiSelectionResult {\n const selectedStringKeys = useMemo(\n () => itemSelectionToStringSet(selectedKeys),\n [selectedKeys]\n );\n\n const defaultSelectedStringKeys = useMemo(\n () => itemSelectionToStringSet(defaultSelectedKeys),\n [defaultSelectedKeys]\n );\n\n const disabledStringKeys = useMemo(\n () => itemSelectionToStringSet(disabledKeys),\n [disabledKeys]\n );\n\n const onStringSelectionChange = useCallback(\n (keys: 'all' | Set<Key>) => {\n if (onChange == null) {\n return;\n }\n\n if (keys === 'all') {\n onChange('all');\n return;\n }\n\n const actualKeys = new Set<ItemKey>();\n\n normalizedItems.forEach(item => {\n if (keys.has(String(getItemKey(item)))) {\n actualKeys.add(getItemKey(item));\n }\n });\n\n onChange(actualKeys);\n },\n [normalizedItems, onChange]\n );\n\n return {\n selectedStringKeys,\n defaultSelectedStringKeys,\n disabledStringKeys,\n onStringSelectionChange,\n };\n}\n\nexport default useStringifiedMultiSelection;\n"],"mappings":"AAAA,SAAcA,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAAC,SAEhDC,UAAU,EAGVC,wBAAwB;AA6B1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,4BAA4BA,CAAAC,IAAA,EAMgC;EAAA,IAN/B;IAC3CC,eAAe;IACfC,mBAAmB;IACnBC,YAAY;IACZC,YAAY;IACZC;EACmC,CAAC,GAAAL,IAAA;EACpC,IAAMM,kBAAkB,GAAGV,OAAO,CAChC,MAAME,wBAAwB,CAACM,YAAY,CAAC,EAC5C,CAACA,YAAY,CACf,CAAC;EAED,IAAMG,yBAAyB,GAAGX,OAAO,CACvC,MAAME,wBAAwB,CAACI,mBAAmB,CAAC,EACnD,CAACA,mBAAmB,CACtB,CAAC;EAED,IAAMM,kBAAkB,GAAGZ,OAAO,CAChC,MAAME,wBAAwB,CAACK,YAAY,CAAC,EAC5C,CAACA,YAAY,CACf,CAAC;EAED,IAAMM,uBAAuB,GAAGd,WAAW,CACxCe,IAAsB,IAAK;IAC1B,IAAIL,QAAQ,IAAI,IAAI,EAAE;MACpB;IACF;IAEA,IAAIK,IAAI,KAAK,KAAK,EAAE;MAClBL,QAAQ,CAAC,KAAK,CAAC;MACf;IACF;IAEA,IAAMM,UAAU,GAAG,IAAIC,GAAG,CAAU,CAAC;IAErCX,eAAe,CAACY,OAAO,CAACC,IAAI,IAAI;MAC9B,IAAIJ,IAAI,CAACK,GAAG,CAACC,MAAM,CAACnB,UAAU,CAACiB,IAAI,CAAC,CAAC,CAAC,EAAE;QACtCH,UAAU,CAACM,GAAG,CAACpB,UAAU,CAACiB,IAAI,CAAC,CAAC;MAClC;IACF,CAAC,CAAC;IAEFT,QAAQ,CAACM,UAAU,CAAC;EACtB,CAAC,EACD,CAACV,eAAe,EAAEI,QAAQ,CAC5B,CAAC;EAED,OAAO;IACLC,kBAAkB;IAClBC,yBAAyB;IACzBC,kBAAkB;IAClBC;EACF,CAAC;AACH;AAEA,eAAeV,4BAA4B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Key } from 'react';
|
|
2
|
+
import { ItemKey, NormalizedItem, NormalizedSection } from './itemUtils';
|
|
3
|
+
export interface UseStringifiedSelectionOptions {
|
|
4
|
+
normalizedItems: (NormalizedItem | NormalizedSection)[];
|
|
5
|
+
selectedKey: ItemKey | null | undefined;
|
|
6
|
+
defaultSelectedKey: ItemKey | undefined;
|
|
7
|
+
disabledKeys: Iterable<ItemKey> | undefined;
|
|
8
|
+
onChange: ((key: ItemKey) => void) | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface UseStringifiedSelectionResult {
|
|
11
|
+
defaultSelectedStringKey?: Key;
|
|
12
|
+
selectedStringKey?: Key | null;
|
|
13
|
+
disabledStringKeys?: Set<Key>;
|
|
14
|
+
onStringSelectionChange: (key: Key) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Spectrum collection components treat keys as strings if the `key` prop is
|
|
18
|
+
* explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,
|
|
19
|
+
* we need to ensure that keys are strings in order for selection to work. We
|
|
20
|
+
* then need to convert back to the original key types in the onChange handler.
|
|
21
|
+
* This hook encapsulates converting to and from strings so that keys can match
|
|
22
|
+
* the original key type.
|
|
23
|
+
* @param normalizedItems The normalized items to select from.
|
|
24
|
+
* @param selectedKey The currently selected key in the collection.
|
|
25
|
+
* @param defaultSelectedKey The initial selected key in the collection.
|
|
26
|
+
* @param disabledKeys The currently disabled keys in the collection.
|
|
27
|
+
* @param onChange Handler that is called when the selection changes.
|
|
28
|
+
* @returns UseStringifiedSelectionResult with stringified key sets and string
|
|
29
|
+
* key selection change handler.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useStringifiedSelection({ normalizedItems, defaultSelectedKey, selectedKey, disabledKeys, onChange, }: UseStringifiedSelectionOptions): UseStringifiedSelectionResult;
|
|
32
|
+
export default useStringifiedSelection;
|
|
33
|
+
//# sourceMappingURL=useStringifiedSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStringifiedSelection.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useStringifiedSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,OAAO,CAAC;AAClD,OAAO,EAEL,OAAO,EAEP,cAAc,EACd,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,8BAA8B;IAC7C,eAAe,EAAE,CAAC,cAAc,GAAG,iBAAiB,CAAC,EAAE,CAAC;IACxD,WAAW,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IACxC,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC5C,QAAQ,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAChD;AAED,MAAM,WAAW,6BAA6B;IAC5C,wBAAwB,CAAC,EAAE,GAAG,CAAC;IAC/B,iBAAiB,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IAC/B,kBAAkB,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,uBAAuB,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;CAC7C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,eAAe,EACf,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,QAAQ,GACT,EAAE,8BAA8B,GAAG,6BAA6B,CA6ChE;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { getItemKey, itemSelectionToStringSet } from "./itemUtils.js";
|
|
3
|
+
/**
|
|
4
|
+
* Spectrum collection components treat keys as strings if the `key` prop is
|
|
5
|
+
* explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,
|
|
6
|
+
* we need to ensure that keys are strings in order for selection to work. We
|
|
7
|
+
* then need to convert back to the original key types in the onChange handler.
|
|
8
|
+
* This hook encapsulates converting to and from strings so that keys can match
|
|
9
|
+
* the original key type.
|
|
10
|
+
* @param normalizedItems The normalized items to select from.
|
|
11
|
+
* @param selectedKey The currently selected key in the collection.
|
|
12
|
+
* @param defaultSelectedKey The initial selected key in the collection.
|
|
13
|
+
* @param disabledKeys The currently disabled keys in the collection.
|
|
14
|
+
* @param onChange Handler that is called when the selection changes.
|
|
15
|
+
* @returns UseStringifiedSelectionResult with stringified key sets and string
|
|
16
|
+
* key selection change handler.
|
|
17
|
+
*/
|
|
18
|
+
export function useStringifiedSelection(_ref) {
|
|
19
|
+
var {
|
|
20
|
+
normalizedItems,
|
|
21
|
+
defaultSelectedKey,
|
|
22
|
+
selectedKey,
|
|
23
|
+
disabledKeys,
|
|
24
|
+
onChange
|
|
25
|
+
} = _ref;
|
|
26
|
+
var selectedStringKey = useMemo(() => selectedKey == null ? selectedKey : String(selectedKey), [selectedKey]);
|
|
27
|
+
var defaultSelectedStringKey = useMemo(() => defaultSelectedKey == null ? defaultSelectedKey : String(defaultSelectedKey), [defaultSelectedKey]);
|
|
28
|
+
var disabledStringKeys = useMemo(() => itemSelectionToStringSet(disabledKeys), [disabledKeys]);
|
|
29
|
+
var onStringSelectionChange = useCallback(key => {
|
|
30
|
+
var _getItemKey;
|
|
31
|
+
if (onChange == null) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The `key` arg will always be a string due to us setting the `Item` key
|
|
36
|
+
// prop in `renderItem`. We need to find the matching item to determine
|
|
37
|
+
// the actual key.
|
|
38
|
+
var selectedItem = normalizedItems.find(item => String(getItemKey(item)) === key);
|
|
39
|
+
var actualKey = (_getItemKey = getItemKey(selectedItem)) !== null && _getItemKey !== void 0 ? _getItemKey : key;
|
|
40
|
+
onChange(actualKey);
|
|
41
|
+
}, [normalizedItems, onChange]);
|
|
42
|
+
return {
|
|
43
|
+
selectedStringKey,
|
|
44
|
+
defaultSelectedStringKey,
|
|
45
|
+
disabledStringKeys,
|
|
46
|
+
onStringSelectionChange
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export default useStringifiedSelection;
|
|
50
|
+
//# sourceMappingURL=useStringifiedSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStringifiedSelection.js","names":["useCallback","useMemo","getItemKey","itemSelectionToStringSet","useStringifiedSelection","_ref","normalizedItems","defaultSelectedKey","selectedKey","disabledKeys","onChange","selectedStringKey","String","defaultSelectedStringKey","disabledStringKeys","onStringSelectionChange","key","_getItemKey","selectedItem","find","item","actualKey"],"sources":["../../../src/spectrum/utils/useStringifiedSelection.ts"],"sourcesContent":["import { Key, useCallback, useMemo } from 'react';\nimport {\n getItemKey,\n ItemKey,\n itemSelectionToStringSet,\n NormalizedItem,\n NormalizedSection,\n} from './itemUtils';\n\nexport interface UseStringifiedSelectionOptions {\n normalizedItems: (NormalizedItem | NormalizedSection)[];\n selectedKey: ItemKey | null | undefined;\n defaultSelectedKey: ItemKey | undefined;\n disabledKeys: Iterable<ItemKey> | undefined;\n onChange: ((key: ItemKey) => void) | undefined;\n}\n\nexport interface UseStringifiedSelectionResult {\n defaultSelectedStringKey?: Key;\n selectedStringKey?: Key | null;\n disabledStringKeys?: Set<Key>;\n onStringSelectionChange: (key: Key) => void;\n}\n\n/**\n * Spectrum collection components treat keys as strings if the `key` prop is\n * explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,\n * we need to ensure that keys are strings in order for selection to work. We\n * then need to convert back to the original key types in the onChange handler.\n * This hook encapsulates converting to and from strings so that keys can match\n * the original key type.\n * @param normalizedItems The normalized items to select from.\n * @param selectedKey The currently selected key in the collection.\n * @param defaultSelectedKey The initial selected key in the collection.\n * @param disabledKeys The currently disabled keys in the collection.\n * @param onChange Handler that is called when the selection changes.\n * @returns UseStringifiedSelectionResult with stringified key sets and string\n * key selection change handler.\n */\nexport function useStringifiedSelection({\n normalizedItems,\n defaultSelectedKey,\n selectedKey,\n disabledKeys,\n onChange,\n}: UseStringifiedSelectionOptions): UseStringifiedSelectionResult {\n const selectedStringKey = useMemo(\n () => (selectedKey == null ? selectedKey : String(selectedKey)),\n [selectedKey]\n );\n\n const defaultSelectedStringKey = useMemo(\n () =>\n defaultSelectedKey == null\n ? defaultSelectedKey\n : String(defaultSelectedKey),\n [defaultSelectedKey]\n );\n\n const disabledStringKeys = useMemo(\n () => itemSelectionToStringSet(disabledKeys),\n [disabledKeys]\n );\n\n const onStringSelectionChange = useCallback(\n (key: Key): void => {\n if (onChange == null) {\n return;\n }\n\n // The `key` arg will always be a string due to us setting the `Item` key\n // prop in `renderItem`. We need to find the matching item to determine\n // the actual key.\n const selectedItem = normalizedItems.find(\n item => String(getItemKey(item)) === key\n );\n\n const actualKey = getItemKey(selectedItem) ?? key;\n\n onChange(actualKey);\n },\n [normalizedItems, onChange]\n );\n\n return {\n selectedStringKey,\n defaultSelectedStringKey,\n disabledStringKeys,\n onStringSelectionChange,\n };\n}\n\nexport default useStringifiedSelection;\n"],"mappings":"AAAA,SAAcA,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAAC,SAEhDC,UAAU,EAEVC,wBAAwB;AAoB1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAAAC,IAAA,EAM2B;EAAA,IAN1B;IACtCC,eAAe;IACfC,kBAAkB;IAClBC,WAAW;IACXC,YAAY;IACZC;EAC8B,CAAC,GAAAL,IAAA;EAC/B,IAAMM,iBAAiB,GAAGV,OAAO,CAC/B,MAAOO,WAAW,IAAI,IAAI,GAAGA,WAAW,GAAGI,MAAM,CAACJ,WAAW,CAAE,EAC/D,CAACA,WAAW,CACd,CAAC;EAED,IAAMK,wBAAwB,GAAGZ,OAAO,CACtC,MACEM,kBAAkB,IAAI,IAAI,GACtBA,kBAAkB,GAClBK,MAAM,CAACL,kBAAkB,CAAC,EAChC,CAACA,kBAAkB,CACrB,CAAC;EAED,IAAMO,kBAAkB,GAAGb,OAAO,CAChC,MAAME,wBAAwB,CAACM,YAAY,CAAC,EAC5C,CAACA,YAAY,CACf,CAAC;EAED,IAAMM,uBAAuB,GAAGf,WAAW,CACxCgB,GAAQ,IAAW;IAAA,IAAAC,WAAA;IAClB,IAAIP,QAAQ,IAAI,IAAI,EAAE;MACpB;IACF;;IAEA;IACA;IACA;IACA,IAAMQ,YAAY,GAAGZ,eAAe,CAACa,IAAI,CACvCC,IAAI,IAAIR,MAAM,CAACV,UAAU,CAACkB,IAAI,CAAC,CAAC,KAAKJ,GACvC,CAAC;IAED,IAAMK,SAAS,IAAAJ,WAAA,GAAGf,UAAU,CAACgB,YAAY,CAAC,cAAAD,WAAA,cAAAA,WAAA,GAAID,GAAG;IAEjDN,QAAQ,CAACW,SAAS,CAAC;EACrB,CAAC,EACD,CAACf,eAAe,EAAEI,QAAQ,CAC5B,CAAC;EAED,OAAO;IACLC,iBAAiB;IACjBE,wBAAwB;IACxBC,kBAAkB;IAClBC;EACF,CAAC;AACH;AAEA,eAAeX,uBAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.74.1-beta.1+5f497611",
|
|
4
4
|
"description": "Deephaven React component library",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@adobe/react-spectrum": "^3.34.1",
|
|
28
|
-
"@deephaven/icons": "^0.
|
|
29
|
-
"@deephaven/log": "^0.
|
|
30
|
-
"@deephaven/react-hooks": "^0.
|
|
31
|
-
"@deephaven/utils": "^0.
|
|
28
|
+
"@deephaven/icons": "^0.74.1-beta.1+5f497611",
|
|
29
|
+
"@deephaven/log": "^0.74.1-beta.1+5f497611",
|
|
30
|
+
"@deephaven/react-hooks": "^0.74.1-beta.1+5f497611",
|
|
31
|
+
"@deephaven/utils": "^0.74.1-beta.1+5f497611",
|
|
32
32
|
"@fortawesome/fontawesome-svg-core": "^6.2.1",
|
|
33
33
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
34
34
|
"@react-spectrum/theme-default": "^3.5.1",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"react-dom": ">=16.8.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@deephaven/mocks": "^0.
|
|
58
|
+
"@deephaven/mocks": "^0.74.1-beta.1+5f497611"
|
|
59
59
|
},
|
|
60
60
|
"files": [
|
|
61
61
|
"dist",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "5f4976115bfc016e6d9cbe9fd77413c3fd8f8353"
|
|
73
73
|
}
|