@deephaven/components 0.74.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/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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spectrum/picker/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spectrum/picker/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/picker/index.ts"],"sourcesContent":["export * from './Picker';\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/picker/index.ts"],"sourcesContent":["export * from './Picker';\nexport * from './PickerNormalized';\nexport * from './usePickerScrollOnOpen';\n"],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DOMRef } from '@react-types/shared';
|
|
2
|
+
export interface UsePickerScrollOnOpenOptions {
|
|
3
|
+
getInitialScrollPosition?: () => Promise<number | null | undefined>;
|
|
4
|
+
onScroll: (event: Event) => void;
|
|
5
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface UsePickerScrollOnOpenResult {
|
|
8
|
+
ref: DOMRef<HTMLElement>;
|
|
9
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handle scroll event registration and scrolling to initial scroll position
|
|
13
|
+
* whenever a Picker popover is opened.
|
|
14
|
+
* @param getInitialScrollPosition Function to get the initial scroll position.
|
|
15
|
+
* @param onScroll Callback for scroll events.
|
|
16
|
+
* @param onOpenChange Callback for open change events.
|
|
17
|
+
* @return A ref to attach to the Picker and a callback to handle open change
|
|
18
|
+
* events for the Picker.
|
|
19
|
+
*/
|
|
20
|
+
export declare function usePickerScrollOnOpen({ getInitialScrollPosition, onScroll, onOpenChange, }: UsePickerScrollOnOpenOptions): UsePickerScrollOnOpenResult;
|
|
21
|
+
export default usePickerScrollOnOpen;
|
|
22
|
+
//# sourceMappingURL=usePickerScrollOnOpen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePickerScrollOnOpen.d.ts","sourceRoot":"","sources":["../../../src/spectrum/picker/usePickerScrollOnOpen.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAMlD,MAAM,WAAW,4BAA4B;IAC3C,wBAAwB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACpE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IACzB,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,wBAAwB,EACxB,QAAQ,EACR,YAAY,GACb,EAAE,4BAA4B,GAAG,2BAA2B,CAqB5D;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { findSpectrumPickerScrollArea, usePopoverOnScrollRef } from '@deephaven/react-hooks';
|
|
3
|
+
/**
|
|
4
|
+
* Handle scroll event registration and scrolling to initial scroll position
|
|
5
|
+
* whenever a Picker popover is opened.
|
|
6
|
+
* @param getInitialScrollPosition Function to get the initial scroll position.
|
|
7
|
+
* @param onScroll Callback for scroll events.
|
|
8
|
+
* @param onOpenChange Callback for open change events.
|
|
9
|
+
* @return A ref to attach to the Picker and a callback to handle open change
|
|
10
|
+
* events for the Picker.
|
|
11
|
+
*/
|
|
12
|
+
export function usePickerScrollOnOpen(_ref) {
|
|
13
|
+
var {
|
|
14
|
+
getInitialScrollPosition,
|
|
15
|
+
onScroll,
|
|
16
|
+
onOpenChange
|
|
17
|
+
} = _ref;
|
|
18
|
+
var {
|
|
19
|
+
ref,
|
|
20
|
+
onOpenChange: popoverOnOpenChange
|
|
21
|
+
} = usePopoverOnScrollRef(findSpectrumPickerScrollArea, onScroll, getInitialScrollPosition);
|
|
22
|
+
var onOpenChangeInternal = useCallback(isOpen => {
|
|
23
|
+
// Attach scroll event handling
|
|
24
|
+
popoverOnOpenChange(isOpen);
|
|
25
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(isOpen);
|
|
26
|
+
}, [onOpenChange, popoverOnOpenChange]);
|
|
27
|
+
return {
|
|
28
|
+
ref,
|
|
29
|
+
onOpenChange: onOpenChangeInternal
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export default usePickerScrollOnOpen;
|
|
33
|
+
//# sourceMappingURL=usePickerScrollOnOpen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePickerScrollOnOpen.js","names":["useCallback","findSpectrumPickerScrollArea","usePopoverOnScrollRef","usePickerScrollOnOpen","_ref","getInitialScrollPosition","onScroll","onOpenChange","ref","popoverOnOpenChange","onOpenChangeInternal","isOpen"],"sources":["../../../src/spectrum/picker/usePickerScrollOnOpen.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport type { DOMRef } from '@react-types/shared';\nimport {\n findSpectrumPickerScrollArea,\n usePopoverOnScrollRef,\n} from '@deephaven/react-hooks';\n\nexport interface UsePickerScrollOnOpenOptions {\n getInitialScrollPosition?: () => Promise<number | null | undefined>;\n onScroll: (event: Event) => void;\n onOpenChange?: (isOpen: boolean) => void;\n}\n\nexport interface UsePickerScrollOnOpenResult {\n ref: DOMRef<HTMLElement>;\n onOpenChange: (isOpen: boolean) => void;\n}\n\n/**\n * Handle scroll event registration and scrolling to initial scroll position\n * whenever a Picker popover is opened.\n * @param getInitialScrollPosition Function to get the initial scroll position.\n * @param onScroll Callback for scroll events.\n * @param onOpenChange Callback for open change events.\n * @return A ref to attach to the Picker and a callback to handle open change\n * events for the Picker.\n */\nexport function usePickerScrollOnOpen({\n getInitialScrollPosition,\n onScroll,\n onOpenChange,\n}: UsePickerScrollOnOpenOptions): UsePickerScrollOnOpenResult {\n const { ref, onOpenChange: popoverOnOpenChange } = usePopoverOnScrollRef(\n findSpectrumPickerScrollArea,\n onScroll,\n getInitialScrollPosition\n );\n\n const onOpenChangeInternal = useCallback(\n (isOpen: boolean): void => {\n // Attach scroll event handling\n popoverOnOpenChange(isOpen);\n\n onOpenChange?.(isOpen);\n },\n [onOpenChange, popoverOnOpenChange]\n );\n\n return {\n ref,\n onOpenChange: onOpenChangeInternal,\n };\n}\n\nexport default usePickerScrollOnOpen;\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,OAAO;AAEnC,SACEC,4BAA4B,EAC5BC,qBAAqB,QAChB,wBAAwB;AAa/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAAC,IAAA,EAIyB;EAAA,IAJxB;IACpCC,wBAAwB;IACxBC,QAAQ;IACRC;EAC4B,CAAC,GAAAH,IAAA;EAC7B,IAAM;IAAEI,GAAG;IAAED,YAAY,EAAEE;EAAoB,CAAC,GAAGP,qBAAqB,CACtED,4BAA4B,EAC5BK,QAAQ,EACRD,wBACF,CAAC;EAED,IAAMK,oBAAoB,GAAGV,WAAW,CACrCW,MAAe,IAAW;IACzB;IACAF,mBAAmB,CAACE,MAAM,CAAC;IAE3BJ,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAGI,MAAM,CAAC;EACxB,CAAC,EACD,CAACJ,YAAY,EAAEE,mBAAmB,CACpC,CAAC;EAED,OAAO;IACLD,GAAG;IACHD,YAAY,EAAEG;EAChB,CAAC;AACH;AAEA,eAAeP,qBAAqB"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './itemUtils';
|
|
2
|
+
export * from './itemWrapperUtils';
|
|
2
3
|
export * from './themeUtils';
|
|
3
4
|
export * from './useRenderNormalizedItem';
|
|
4
5
|
export * from './useStringifiedMultiSelection';
|
|
6
|
+
export * from './useStringifiedSelection';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./itemUtils.js";
|
|
2
|
+
export * from "./itemWrapperUtils.js";
|
|
2
3
|
export * from "./themeUtils.js";
|
|
3
4
|
export * from "./useRenderNormalizedItem.js";
|
|
4
5
|
export * from "./useStringifiedMultiSelection.js";
|
|
6
|
+
export * from "./useStringifiedSelection.js";
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/utils/index.ts"],"sourcesContent":["export * from './itemUtils';\nexport * from './themeUtils';\nexport * from './useRenderNormalizedItem';\nexport * from './useStringifiedMultiSelection';\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/utils/index.ts"],"sourcesContent":["export * from './itemUtils';\nexport * from './itemWrapperUtils';\nexport * from './themeUtils';\nexport * from './useRenderNormalizedItem';\nexport * from './useStringifiedMultiSelection';\nexport * from './useStringifiedSelection';\n"],"mappings":""}
|
|
@@ -4,6 +4,11 @@ import type { ItemRenderer } from '@react-types/shared';
|
|
|
4
4
|
import { KeyedItem, SelectionT } from '@deephaven/utils';
|
|
5
5
|
import { ItemProps, SectionProps } from '../shared';
|
|
6
6
|
import { PopperOptions } from '../../popper';
|
|
7
|
+
/**
|
|
8
|
+
* `Item.textValue` prop needs to be a non-empty string for accessibility
|
|
9
|
+
* purposes. This is not displayed in the UI.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ITEM_EMPTY_STRING_TEXT_VALUE = "Empty";
|
|
7
12
|
export declare const INVALID_ITEM_ERROR_MESSAGE = "Items must be strings, numbers, booleans, <Item> or <Section> elements:";
|
|
8
13
|
/**
|
|
9
14
|
* React Spectrum <Section> supports an `ItemRenderer` function as a child. The
|
|
@@ -13,7 +18,7 @@ export declare const INVALID_ITEM_ERROR_MESSAGE = "Items must be strings, number
|
|
|
13
18
|
type SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {
|
|
14
19
|
children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;
|
|
15
20
|
};
|
|
16
|
-
type ItemElement = ReactElement<ItemProps<unknown>>;
|
|
21
|
+
export type ItemElement = ReactElement<ItemProps<unknown>>;
|
|
17
22
|
export type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;
|
|
18
23
|
export type ItemElementOrPrimitive = number | string | boolean | ItemElement;
|
|
19
24
|
export type ItemOrSection = ItemElementOrPrimitive | SectionElement;
|
|
@@ -33,7 +38,7 @@ export type ItemSelectionChangeHandler = (key: ItemKey) => void;
|
|
|
33
38
|
export interface NormalizedItemData {
|
|
34
39
|
key?: ItemKey;
|
|
35
40
|
content: ReactNode;
|
|
36
|
-
textValue
|
|
41
|
+
textValue: string | undefined;
|
|
37
42
|
}
|
|
38
43
|
export interface NormalizedSectionData {
|
|
39
44
|
key?: Key;
|
|
@@ -65,6 +70,20 @@ export type TooltipOptions = {
|
|
|
65
70
|
* @returns The `key` of the item or section
|
|
66
71
|
*/
|
|
67
72
|
export declare function getItemKey<TItem extends NormalizedItem | NormalizedSection, TKey extends TItem extends NormalizedItem ? ItemKey | undefined : TItem extends NormalizedSection ? Key | undefined : undefined>(item: TItem | null | undefined): TKey;
|
|
73
|
+
/**
|
|
74
|
+
* Get the position of the item with the given selected key in a list of items.
|
|
75
|
+
* @param items The items to search
|
|
76
|
+
* @param itemHeight The height of each item
|
|
77
|
+
* @param selectedKey The key of the selected item
|
|
78
|
+
* @param topOffset The top offset of the list
|
|
79
|
+
* @returns The position of the selected item or the top offset if not found
|
|
80
|
+
*/
|
|
81
|
+
export declare function getPositionOfSelectedItemElement<TKey extends string | number | boolean | undefined>({ items, itemHeight, selectedKey, topOffset, }: {
|
|
82
|
+
items: ItemElement[];
|
|
83
|
+
selectedKey: TKey | null | undefined;
|
|
84
|
+
itemHeight: number;
|
|
85
|
+
topOffset: number;
|
|
86
|
+
}): Promise<number>;
|
|
68
87
|
/**
|
|
69
88
|
* Determine if a node is a Section element.
|
|
70
89
|
* @param node The node to check
|
|
@@ -77,6 +96,13 @@ export declare function isSectionElement<T>(node: ReactNode): node is ReactEleme
|
|
|
77
96
|
* @returns True if the node is an Item element
|
|
78
97
|
*/
|
|
79
98
|
export declare function isItemElement<T>(node: ReactNode): node is ReactElement<ItemProps<T>>;
|
|
99
|
+
/**
|
|
100
|
+
* Determine if a node is an Item element containing a child `Text` element with
|
|
101
|
+
* a `slot` prop set to `description`.
|
|
102
|
+
* @param node The node to check
|
|
103
|
+
* @returns True if the node is an Item element with a description
|
|
104
|
+
*/
|
|
105
|
+
export declare function isItemElementWithDescription<T>(node: ReactNode): node is ReactElement<ItemProps<T>>;
|
|
80
106
|
/**
|
|
81
107
|
* Determine if a node is an array containing normalized items or sections with
|
|
82
108
|
* keys. Note that this only checks the first node in the array.
|
|
@@ -116,6 +142,6 @@ export declare function normalizeTooltipOptions(options?: boolean | TooltipOptio
|
|
|
116
142
|
* @param itemKeys The selection of `ItemKey`s
|
|
117
143
|
* @returns The selection of strings
|
|
118
144
|
*/
|
|
119
|
-
export declare function itemSelectionToStringSet
|
|
145
|
+
export declare function itemSelectionToStringSet<TKeys extends 'all' | Iterable<ItemKey> | undefined, TResult extends TKeys extends 'all' ? 'all' : TKeys extends Iterable<ItemKey> ? Set<string> : undefined>(itemKeys: TKeys): TResult;
|
|
120
146
|
export {};
|
|
121
147
|
//# sourceMappingURL=itemUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itemUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/itemUtils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"itemUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/itemUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,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KAAK,SAAS,KAAK,GAC/B,KAAK,GACL,KAAK,SAAS,QAAQ,CAAC,OAAO,CAAC,GAC/B,GAAG,CAAC,MAAM,CAAC,GACX,SAAS,EACb,QAAQ,EAAE,KAAK,GAAG,OAAO,CAM1B"}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
2
3
|
import Log from '@deephaven/log';
|
|
4
|
+
import { isElementOfType } from '@deephaven/react-hooks';
|
|
3
5
|
import { Item, Section } from "../shared.js";
|
|
6
|
+
import { Text } from "../Text.js";
|
|
7
|
+
import ItemContent from "../ItemContent.js";
|
|
4
8
|
var log = Log.module('itemUtils');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `Item.textValue` prop needs to be a non-empty string for accessibility
|
|
12
|
+
* purposes. This is not displayed in the UI.
|
|
13
|
+
*/
|
|
14
|
+
export var ITEM_EMPTY_STRING_TEXT_VALUE = 'Empty';
|
|
5
15
|
export var INVALID_ITEM_ERROR_MESSAGE = 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';
|
|
6
16
|
|
|
7
17
|
/**
|
|
@@ -45,13 +55,48 @@ export function getItemKey(item) {
|
|
|
45
55
|
return (_item$item$key = item === null || item === void 0 ? void 0 : (_item$item = item.item) === null || _item$item === void 0 ? void 0 : _item$item.key) !== null && _item$item$key !== void 0 ? _item$item$key : item === null || item === void 0 ? void 0 : item.key;
|
|
46
56
|
}
|
|
47
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Get the position of the item with the given selected key in a list of items.
|
|
60
|
+
* @param items The items to search
|
|
61
|
+
* @param itemHeight The height of each item
|
|
62
|
+
* @param selectedKey The key of the selected item
|
|
63
|
+
* @param topOffset The top offset of the list
|
|
64
|
+
* @returns The position of the selected item or the top offset if not found
|
|
65
|
+
*/
|
|
66
|
+
export function getPositionOfSelectedItemElement(_x) {
|
|
67
|
+
return _getPositionOfSelectedItemElement.apply(this, arguments);
|
|
68
|
+
}
|
|
69
|
+
|
|
48
70
|
/**
|
|
49
71
|
* Determine if a node is a Section element.
|
|
50
72
|
* @param node The node to check
|
|
51
73
|
* @returns True if the node is a Section element
|
|
52
74
|
*/
|
|
75
|
+
function _getPositionOfSelectedItemElement() {
|
|
76
|
+
_getPositionOfSelectedItemElement = _asyncToGenerator(function* (_ref) {
|
|
77
|
+
var {
|
|
78
|
+
items,
|
|
79
|
+
itemHeight,
|
|
80
|
+
selectedKey,
|
|
81
|
+
topOffset
|
|
82
|
+
} = _ref;
|
|
83
|
+
var position = topOffset;
|
|
84
|
+
if (selectedKey == null) {
|
|
85
|
+
return position;
|
|
86
|
+
}
|
|
87
|
+
for (var i = 0; i < items.length; i += 1) {
|
|
88
|
+
var _item = items[i];
|
|
89
|
+
if (_item.key === selectedKey) {
|
|
90
|
+
return position;
|
|
91
|
+
}
|
|
92
|
+
position += itemHeight;
|
|
93
|
+
}
|
|
94
|
+
return topOffset;
|
|
95
|
+
});
|
|
96
|
+
return _getPositionOfSelectedItemElement.apply(this, arguments);
|
|
97
|
+
}
|
|
53
98
|
export function isSectionElement(node) {
|
|
54
|
-
return
|
|
99
|
+
return isElementOfType(node, Section);
|
|
55
100
|
}
|
|
56
101
|
|
|
57
102
|
/**
|
|
@@ -60,7 +105,28 @@ export function isSectionElement(node) {
|
|
|
60
105
|
* @returns True if the node is an Item element
|
|
61
106
|
*/
|
|
62
107
|
export function isItemElement(node) {
|
|
63
|
-
return
|
|
108
|
+
return isElementOfType(node, Item);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Determine if a node is an Item element containing a child `Text` element with
|
|
113
|
+
* a `slot` prop set to `description`.
|
|
114
|
+
* @param node The node to check
|
|
115
|
+
* @returns True if the node is an Item element with a description
|
|
116
|
+
*/
|
|
117
|
+
export function isItemElementWithDescription(node) {
|
|
118
|
+
if (!isItemElement(node)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// If children are wrapped in `ItemContent`, go down 1 level
|
|
123
|
+
var children = isElementOfType(node.props.children, ItemContent) ? node.props.children.props.children : node.props.children;
|
|
124
|
+
var childrenArray = Array.isArray(children) ? children : [children];
|
|
125
|
+
var result = childrenArray.some(child => {
|
|
126
|
+
var _child$props;
|
|
127
|
+
return ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.slot) === 'description' && isElementOfType(child, Text);
|
|
128
|
+
});
|
|
129
|
+
return result;
|
|
64
130
|
}
|
|
65
131
|
|
|
66
132
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itemUtils.js","names":["isValidElement","Log","Item","Section","log","module","INVALID_ITEM_ERROR_MESSAGE","getItemKey","item","_item$item$key","_item$item","key","isSectionElement","node","type","isItemElement","isNormalizedItemsWithKeysList","Array","isArray","length","isItemOrSection","isNormalizedSection","maybeNormalizedSection","normalizeItemKey","itemOrSection","_itemOrSection$props$","props","title","undefined","textValue","children","normalizeTextValue","String","normalizeItem","debug","Error","items","normalizeItemList","filter","childItem","content","itemsOrSections","itemsArray","map","normalizeTooltipOptions","options","placement","arguments","itemSelectionToStringSet","itemKeys","Set"],"sources":["../../../src/spectrum/utils/itemUtils.ts"],"sourcesContent":["import { isValidElement, Key, ReactElement, ReactNode } from 'react';\nimport { SpectrumPickerProps } from '@adobe/react-spectrum';\nimport type { ItemRenderer } from '@react-types/shared';\nimport Log from '@deephaven/log';\nimport { KeyedItem, SelectionT } from '@deephaven/utils';\nimport { Item, ItemProps, Section, SectionProps } from '../shared';\nimport { PopperOptions } from '../../popper';\n\nconst log = Log.module('itemUtils');\n\nexport const INVALID_ITEM_ERROR_MESSAGE =\n 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';\n\n/**\n * React Spectrum <Section> supports an `ItemRenderer` function as a child. The\n * DH picker makes use of this internally, but we don't want to support it as\n * an incoming prop.\n */\ntype SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {\n children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;\n};\n\ntype ItemElement = ReactElement<ItemProps<unknown>>;\nexport type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;\n\nexport type ItemElementOrPrimitive = number | string | boolean | ItemElement;\nexport type ItemOrSection = ItemElementOrPrimitive | SectionElement;\n\n/**\n * Augment the Spectrum selection key type to include boolean values.\n * Spectrum collection components already supports this, but the built in types\n * don't reflect it.\n */\nexport type ItemKey = Key | boolean;\n\nexport type ItemSelection = SelectionT<ItemKey>;\n\n/**\n * Augment the Spectrum selection change handler type to include boolean keys.\n * Spectrum components already supports this, but the built in types don't\n * reflect it.\n */\nexport type ItemSelectionChangeHandler = (key: ItemKey) => void;\n\nexport interface NormalizedItemData {\n key?: ItemKey;\n content: ReactNode;\n textValue?: string;\n}\n\nexport interface NormalizedSectionData {\n key?: Key;\n title?: ReactNode;\n items: NormalizedItem[];\n}\n\n/**\n * Spectrum collection components support a variety of item types, including\n * strings, numbers, booleans, and more complex React elements. This type\n * represents a normalized form to make rendering items simpler and keep the\n * logic of transformation in separate util methods. It also adheres to the\n * `KeyedItem` interface to be compatible with Windowed data utils\n * (e.g. `useViewportData`).\n */\nexport type NormalizedItem = KeyedItem<NormalizedItemData, ItemKey | undefined>;\n\nexport type NormalizedSection = KeyedItem<\n NormalizedSectionData,\n Key | undefined\n>;\n\nexport type NormalizedItemOrSection<TItemOrSection extends ItemOrSection> =\n TItemOrSection extends SectionElement ? NormalizedSection : NormalizedItem;\n\nexport type NormalizedSpectrumPickerProps = SpectrumPickerProps<NormalizedItem>;\n\nexport type TooltipOptions = { placement: PopperOptions['placement'] };\n\n/**\n * DH wrappers of Spectrum collection components use a normalized item that\n * includes a `key` prop and an optional `item` prop. This is mostly to support\n * Windowed data where items are created before their data has been loaded (data\n * gets set in the `item` prop). If data has loaded, return its `key`. If not,\n * return the top-level `key` on the normalized item.\n * @param item The normalized item or section\n * @returns The `key` of the item or section\n */\nexport function getItemKey<\n TItem extends NormalizedItem | NormalizedSection,\n TKey extends TItem extends NormalizedItem\n ? ItemKey | undefined\n : TItem extends NormalizedSection\n ? Key | undefined\n : undefined,\n>(item: TItem | null | undefined): TKey {\n return (item?.item?.key ?? item?.key) as TKey;\n}\n\n/**\n * Determine if a node is a Section element.\n * @param node The node to check\n * @returns True if the node is a Section element\n */\nexport function isSectionElement<T>(\n node: ReactNode\n): node is ReactElement<SectionProps<T>> {\n return isValidElement<SectionProps<T>>(node) && node.type === Section;\n}\n\n/**\n * Determine if a node is an Item element.\n * @param node The node to check\n * @returns True if the node is an Item element\n */\nexport function isItemElement<T>(\n node: ReactNode\n): node is ReactElement<ItemProps<T>> {\n return isValidElement<ItemProps<T>>(node) && node.type === Item;\n}\n\n/**\n * Determine if a node is an array containing normalized items or sections with\n * keys. Note that this only checks the first node in the array.\n * @param node The node to check\n * @returns True if the node is a normalized item or section with keys array\n */\nexport function isNormalizedItemsWithKeysList<\n TItemOrSection extends ItemOrSection,\n>(\n node:\n | TItemOrSection\n | TItemOrSection[]\n | NormalizedItemOrSection<TItemOrSection>[]\n): node is NormalizedItemOrSection<TItemOrSection>[] {\n if (!Array.isArray(node)) {\n return false;\n }\n\n if (node.length === 0) {\n return true;\n }\n\n return !isItemOrSection(node[0]) && 'key' in node[0];\n}\n\n/**\n * Determine if an object is a normalized section.\n * @param maybeNormalizedSection The object to check\n * @returns True if the object is a normalized section\n */\nexport function isNormalizedSection(\n maybeNormalizedSection: NormalizedItem | NormalizedSection\n): maybeNormalizedSection is NormalizedSection {\n return (\n maybeNormalizedSection.item != null &&\n 'items' in maybeNormalizedSection.item\n );\n}\n\n/**\n * Determine if a node is an item or section. Valid types include strings,\n * numbers, booleans, Item elements, and Section elements.\n * @param node The node to check\n * @returns True if the node is an item or section\n */\nexport function isItemOrSection(node: ReactNode): node is ItemOrSection {\n return (\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean' ||\n isItemElement(node) ||\n isSectionElement(node)\n );\n}\n\n/**\n * Determine the `key` of an item or section.\n * @param itemOrSection The item or section\n * @returns A `ItemKey` for the item or undefined if a key can't be determined\n */\nfunction normalizeItemKey(item: ItemElementOrPrimitive): ItemKey | undefined;\nfunction normalizeItemKey(section: SectionElement): Key | undefined;\nfunction normalizeItemKey(\n itemOrSection: ItemElementOrPrimitive | SectionElement\n): Key | ItemKey | undefined {\n // string, number, or boolean\n if (typeof itemOrSection !== 'object') {\n return itemOrSection;\n }\n\n // If `key` prop is explicitly set\n if (itemOrSection.key != null) {\n return itemOrSection.key;\n }\n\n // Section element\n if (isSectionElement(itemOrSection)) {\n return typeof itemOrSection.props.title === 'string'\n ? itemOrSection.props.title\n : undefined;\n }\n\n // Item element\n return (\n itemOrSection.props.textValue ??\n (typeof itemOrSection.props.children === 'string'\n ? itemOrSection.props.children\n : undefined)\n );\n}\n\n/**\n * Get a normalized `textValue` for an item ensuring it is a string.\n * @param item The item\n * @returns A string `textValue` for the item\n */\nfunction normalizeTextValue(item: ItemElementOrPrimitive): string | undefined {\n if (typeof item !== 'object') {\n return String(item);\n }\n\n if (item.props.textValue != null) {\n return item.props.textValue;\n }\n\n if (typeof item.props.children === 'string') {\n return item.props.children;\n }\n\n return undefined;\n}\n\n/**\n * Normalize an item or section to an object form.\n * @param itemOrSection item to normalize\n * @returns NormalizedItem or NormalizedSection object\n */\nfunction normalizeItem<TItemOrSection extends ItemOrSection>(\n itemOrSection: TItemOrSection\n): NormalizedItemOrSection<TItemOrSection> {\n if (!isItemOrSection(itemOrSection)) {\n log.debug(INVALID_ITEM_ERROR_MESSAGE, itemOrSection);\n throw new Error(INVALID_ITEM_ERROR_MESSAGE);\n }\n\n if (isSectionElement(itemOrSection)) {\n const key = normalizeItemKey(itemOrSection);\n const { title } = itemOrSection.props;\n\n const items = normalizeItemList(itemOrSection.props.children).filter(\n // We don't support nested section elements\n childItem => !isSectionElement(childItem)\n ) as NormalizedItem[];\n\n return {\n item: { key, title, items },\n } as NormalizedItemOrSection<TItemOrSection>;\n }\n\n const key = normalizeItemKey(itemOrSection);\n const content = isItemElement(itemOrSection)\n ? itemOrSection.props.children\n : itemOrSection;\n const textValue = normalizeTextValue(itemOrSection);\n\n return {\n item: { key, content, textValue },\n } as NormalizedItemOrSection<TItemOrSection>;\n}\n\n/**\n * Normalize an item or section or a list of items or sections.\n * @param itemsOrSections An item or section or array of items or sections\n * @returns An array of normalized items or sections\n */\nexport function normalizeItemList<TItemOrSection extends ItemOrSection>(\n itemsOrSections: TItemOrSection | TItemOrSection[] | NormalizedItem[]\n): NormalizedItemOrSection<TItemOrSection>[] {\n // If already normalized, just return as-is\n if (isNormalizedItemsWithKeysList(itemsOrSections)) {\n return itemsOrSections as NormalizedItemOrSection<TItemOrSection>[];\n }\n\n const itemsArray: TItemOrSection[] = Array.isArray(itemsOrSections)\n ? itemsOrSections\n : [itemsOrSections];\n\n return itemsArray.map(normalizeItem);\n}\n\n/**\n * Returns a TooltipOptions object or null if options is false or null.\n * @param options Tooltip options\n * @param placement Default placement for the tooltip if `options` is set\n * explicitly to `true`\n * @returns TooltipOptions or null\n */\nexport function normalizeTooltipOptions(\n options?: boolean | TooltipOptions | null,\n placement: TooltipOptions['placement'] = 'right'\n): TooltipOptions | null {\n if (options == null || options === false) {\n return null;\n }\n\n if (options === true) {\n return { placement };\n }\n\n return options;\n}\n\n/**\n * Convert a selection of `ItemKey`s to a selection of strings.\n * @param itemKeys The selection of `ItemKey`s\n * @returns The selection of strings\n */\nexport function itemSelectionToStringSet(\n itemKeys?: 'all' | Iterable<ItemKey>\n): undefined | 'all' | Set<string> {\n if (itemKeys == null || itemKeys === 'all') {\n return itemKeys as undefined | 'all';\n }\n\n return new Set([...itemKeys].map(String));\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAsC,OAAO;AAGpE,OAAOC,GAAG,MAAM,gBAAgB;AAAC,SAExBC,IAAI,EAAaC,OAAO;AAGjC,IAAMC,GAAG,GAAGH,GAAG,CAACI,MAAM,CAAC,WAAW,CAAC;AAEnC,OAAO,IAAMC,0BAA0B,GACrC,yEAAyE;;AAE3E;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAOxBC,IAA8B,EAAQ;EAAA,IAAAC,cAAA,EAAAC,UAAA;EACtC,QAAAD,cAAA,GAAQD,IAAI,aAAJA,IAAI,wBAAAE,UAAA,GAAJF,IAAI,CAAEA,IAAI,cAAAE,UAAA,uBAAVA,UAAA,CAAYC,GAAG,cAAAF,cAAA,cAAAA,cAAA,GAAID,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,GAAG;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,IAAe,EACwB;EACvC,OAAO,aAAAb,cAAc,CAAkBa,IAAI,CAAC,IAAIA,IAAI,CAACC,IAAI,KAAKX,OAAO;AACvE;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASY,aAAaA,CAC3BF,IAAe,EACqB;EACpC,OAAO,aAAAb,cAAc,CAAea,IAAI,CAAC,IAAIA,IAAI,CAACC,IAAI,KAAKZ,IAAI;AACjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASc,6BAA6BA,CAG3CH,IAG6C,EACM;EACnD,IAAI,CAACI,KAAK,CAACC,OAAO,CAACL,IA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,CAAC,GACxCA,aAAa,CAACE,KAAK,CAACI,QAAQ,GAC5BN,aAAa;EACjB,IAAMK,SAAS,GAAGE,kBAAkB,CAACP,aAAa,CAAC;EAEnD,OAAO;IACLhB,IAAI,EAAE;MAAEG,GAAG;MAAE6B,OAAO;MAAEX;IAAU;EAClC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,iBAAiBA,CAC/BI,eAAqE,EAC1B;EAC3C;EACA,IAAIzB,6BAA6B,CAACyB,eAAe,CAAC,EAAE;IAClD,OAAOA,eAAe;EACxB;EAEA,IAAMC,UAA4B,GAAGzB,KAAK,CAACC,OAAO,CAACuB,eAAe,CAAC,GAC/DA,eAAe,GACf,CAACA,eAAe,CAAC;EAErB,OAAOC,UAAU,CAACC,GAAG,CAACV,aAAa,CAAC;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASW,uBAAuBA,CACrCC,OAAyC,EAElB;EAAA,IADvBC,SAAsC,GAAAC,SAAA,CAAA5B,MAAA,QAAA4B,SAAA,QAAAnB,SAAA,GAAAmB,SAAA,MAAG,OAAO;EAEhD,IAAIF,OAAO,IAAI,IAAI,IAAIA,OAAO,KAAK,KAAK,EAAE;IACxC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,KAAK,IAAI,EAAE;IACpB,OAAO;MAAEC;IAAU,CAAC;EACtB;EAEA,OAAOD,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,wBAAwBA,CACtCC,QAAoC,EACH;EACjC,IAAIA,QAAQ,IAAI,IAAI,IAAIA,QAAQ,KAAK,KAAK,EAAE;IAC1C,OAAOA,QAAQ;EACjB;EAEA,OAAO,IAAIC,GAAG,CAAC,CAAC,GAAGD,QAAQ,CAAC,CAACN,GAAG,CAACX,MAAM,CAAC,CAAC;AAC3C"}
|
|
1
|
+
{"version":3,"file":"itemUtils.js","names":["Log","isElementOfType","Item","Section","Text","ItemContent","log","module","ITEM_EMPTY_STRING_TEXT_VALUE","INVALID_ITEM_ERROR_MESSAGE","getItemKey","item","_item$item$key","_item$item","key","getPositionOfSelectedItemElement","_x","_getPositionOfSelectedItemElement","apply","arguments","_asyncToGenerator","_ref","items","itemHeight","selectedKey","topOffset","position","i","length","isSectionElement","node","isItemElement","isItemElementWithDescription","children","props","childrenArray","Array","isArray","result","some","child","_child$props","slot","isNormalizedItemsWithKeysList","isItemOrSection","isNormalizedSection","maybeNormalizedSection","normalizeItemKey","itemOrSection","_itemOrSection$props$","title","undefined","textValue","normalizeTextValue","String","normalizeItem","debug","Error","normalizeItemList","filter","childItem","content","itemsOrSections","itemsArray","map","normalizeTooltipOptions","options","placement","itemSelectionToStringSet","itemKeys","Set"],"sources":["../../../src/spectrum/utils/itemUtils.ts"],"sourcesContent":["import { Key, ReactElement, ReactNode } from 'react';\nimport { SpectrumPickerProps } from '@adobe/react-spectrum';\nimport type { ItemRenderer } from '@react-types/shared';\nimport Log from '@deephaven/log';\nimport { isElementOfType } from '@deephaven/react-hooks';\nimport { KeyedItem, SelectionT } from '@deephaven/utils';\nimport { Item, ItemProps, Section, SectionProps } from '../shared';\nimport { PopperOptions } from '../../popper';\nimport { Text } from '../Text';\nimport ItemContent from '../ItemContent';\n\nconst log = Log.module('itemUtils');\n\n/**\n * `Item.textValue` prop needs to be a non-empty string for accessibility\n * purposes. This is not displayed in the UI.\n */\nexport const ITEM_EMPTY_STRING_TEXT_VALUE = 'Empty';\n\nexport const INVALID_ITEM_ERROR_MESSAGE =\n 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';\n\n/**\n * React Spectrum <Section> supports an `ItemRenderer` function as a child. The\n * DH picker makes use of this internally, but we don't want to support it as\n * an incoming prop.\n */\ntype SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {\n children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;\n};\n\nexport type ItemElement = ReactElement<ItemProps<unknown>>;\nexport type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;\n\nexport type ItemElementOrPrimitive = number | string | boolean | ItemElement;\nexport type ItemOrSection = ItemElementOrPrimitive | SectionElement;\n\n/**\n * Augment the Spectrum selection key type to include boolean values.\n * Spectrum collection components already supports this, but the built in types\n * don't reflect it.\n */\nexport type ItemKey = Key | boolean;\n\nexport type ItemSelection = SelectionT<ItemKey>;\n\n/**\n * Augment the Spectrum selection change handler type to include boolean keys.\n * Spectrum components already supports this, but the built in types don't\n * reflect it.\n */\nexport type ItemSelectionChangeHandler = (key: ItemKey) => void;\n\nexport interface NormalizedItemData {\n key?: ItemKey;\n content: ReactNode;\n textValue: string | undefined;\n}\n\nexport interface NormalizedSectionData {\n key?: Key;\n title?: ReactNode;\n items: NormalizedItem[];\n}\n\n/**\n * Spectrum collection components support a variety of item types, including\n * strings, numbers, booleans, and more complex React elements. This type\n * represents a normalized form to make rendering items simpler and keep the\n * logic of transformation in separate util methods. It also adheres to the\n * `KeyedItem` interface to be compatible with Windowed data utils\n * (e.g. `useViewportData`).\n */\nexport type NormalizedItem = KeyedItem<NormalizedItemData, ItemKey | undefined>;\n\nexport type NormalizedSection = KeyedItem<\n NormalizedSectionData,\n Key | undefined\n>;\n\nexport type NormalizedItemOrSection<TItemOrSection extends ItemOrSection> =\n TItemOrSection extends SectionElement ? NormalizedSection : NormalizedItem;\n\nexport type NormalizedSpectrumPickerProps = SpectrumPickerProps<NormalizedItem>;\n\nexport type TooltipOptions = { placement: PopperOptions['placement'] };\n\n/**\n * DH wrappers of Spectrum collection components use a normalized item that\n * includes a `key` prop and an optional `item` prop. This is mostly to support\n * Windowed data where items are created before their data has been loaded (data\n * gets set in the `item` prop). If data has loaded, return its `key`. If not,\n * return the top-level `key` on the normalized item.\n * @param item The normalized item or section\n * @returns The `key` of the item or section\n */\nexport function getItemKey<\n TItem extends NormalizedItem | NormalizedSection,\n TKey extends TItem extends NormalizedItem\n ? ItemKey | undefined\n : TItem extends NormalizedSection\n ? Key | undefined\n : undefined,\n>(item: TItem | null | undefined): TKey {\n return (item?.item?.key ?? item?.key) as TKey;\n}\n\n/**\n * Get the position of the item with the given selected key in a list of items.\n * @param items The items to search\n * @param itemHeight The height of each item\n * @param selectedKey The key of the selected item\n * @param topOffset The top offset of the list\n * @returns The position of the selected item or the top offset if not found\n */\nexport async function getPositionOfSelectedItemElement<\n TKey extends string | number | boolean | undefined,\n>({\n items,\n itemHeight,\n selectedKey,\n topOffset,\n}: {\n items: ItemElement[];\n selectedKey: TKey | null | undefined;\n itemHeight: number;\n topOffset: number;\n}): Promise<number> {\n let position = topOffset;\n\n if (selectedKey == null) {\n return position;\n }\n\n for (let i = 0; i < items.length; i += 1) {\n const item = items[i];\n if (item.key === selectedKey) {\n return position;\n }\n\n position += itemHeight;\n }\n\n return topOffset;\n}\n\n/**\n * Determine if a node is a Section element.\n * @param node The node to check\n * @returns True if the node is a Section element\n */\nexport function isSectionElement<T>(\n node: ReactNode\n): node is ReactElement<SectionProps<T>> {\n return isElementOfType(node, Section);\n}\n\n/**\n * Determine if a node is an Item element.\n * @param node The node to check\n * @returns True if the node is an Item element\n */\nexport function isItemElement<T>(\n node: ReactNode\n): node is ReactElement<ItemProps<T>> {\n return isElementOfType(node, Item);\n}\n\n/**\n * Determine if a node is an Item element containing a child `Text` element with\n * a `slot` prop set to `description`.\n * @param node The node to check\n * @returns True if the node is an Item element with a description\n */\nexport function isItemElementWithDescription<T>(\n node: ReactNode\n): node is ReactElement<ItemProps<T>> {\n if (!isItemElement(node)) {\n return false;\n }\n\n // If children are wrapped in `ItemContent`, go down 1 level\n const children = isElementOfType(node.props.children, ItemContent)\n ? node.props.children.props.children\n : node.props.children;\n\n const childrenArray = Array.isArray(children) ? children : [children];\n\n const result = childrenArray.some(\n child => child.props?.slot === 'description' && isElementOfType(child, Text)\n );\n\n return result;\n}\n\n/**\n * Determine if a node is an array containing normalized items or sections with\n * keys. Note that this only checks the first node in the array.\n * @param node The node to check\n * @returns True if the node is a normalized item or section with keys array\n */\nexport function isNormalizedItemsWithKeysList<\n TItemOrSection extends ItemOrSection,\n>(\n node:\n | TItemOrSection\n | TItemOrSection[]\n | NormalizedItemOrSection<TItemOrSection>[]\n): node is NormalizedItemOrSection<TItemOrSection>[] {\n if (!Array.isArray(node)) {\n return false;\n }\n\n if (node.length === 0) {\n return true;\n }\n\n return !isItemOrSection(node[0]) && 'key' in node[0];\n}\n\n/**\n * Determine if an object is a normalized section.\n * @param maybeNormalizedSection The object to check\n * @returns True if the object is a normalized section\n */\nexport function isNormalizedSection(\n maybeNormalizedSection: NormalizedItem | NormalizedSection\n): maybeNormalizedSection is NormalizedSection {\n return (\n maybeNormalizedSection.item != null &&\n 'items' in maybeNormalizedSection.item\n );\n}\n\n/**\n * Determine if a node is an item or section. Valid types include strings,\n * numbers, booleans, Item elements, and Section elements.\n * @param node The node to check\n * @returns True if the node is an item or section\n */\nexport function isItemOrSection(node: ReactNode): node is ItemOrSection {\n return (\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean' ||\n isItemElement(node) ||\n isSectionElement(node)\n );\n}\n\n/**\n * Determine the `key` of an item or section.\n * @param itemOrSection The item or section\n * @returns A `ItemKey` for the item or undefined if a key can't be determined\n */\nfunction normalizeItemKey(item: ItemElementOrPrimitive): ItemKey | undefined;\nfunction normalizeItemKey(section: SectionElement): Key | undefined;\nfunction normalizeItemKey(\n itemOrSection: ItemElementOrPrimitive | SectionElement\n): Key | ItemKey | undefined {\n // string, number, or boolean\n if (typeof itemOrSection !== 'object') {\n return itemOrSection;\n }\n\n // If `key` prop is explicitly set\n if (itemOrSection.key != null) {\n return itemOrSection.key;\n }\n\n // Section element\n if (isSectionElement(itemOrSection)) {\n return typeof itemOrSection.props.title === 'string'\n ? itemOrSection.props.title\n : undefined;\n }\n\n // Item element\n return (\n itemOrSection.props.textValue ??\n (typeof itemOrSection.props.children === 'string'\n ? itemOrSection.props.children\n : undefined)\n );\n}\n\n/**\n * Get a normalized `textValue` for an item ensuring it is a string.\n * @param item The item\n * @returns A string `textValue` for the item\n */\nfunction normalizeTextValue(item: ItemElementOrPrimitive): string | undefined {\n if (typeof item !== 'object') {\n return String(item);\n }\n\n if (item.props.textValue != null) {\n return item.props.textValue;\n }\n\n if (typeof item.props.children === 'string') {\n return item.props.children;\n }\n\n return undefined;\n}\n\n/**\n * Normalize an item or section to an object form.\n * @param itemOrSection item to normalize\n * @returns NormalizedItem or NormalizedSection object\n */\nfunction normalizeItem<TItemOrSection extends ItemOrSection>(\n itemOrSection: TItemOrSection\n): NormalizedItemOrSection<TItemOrSection> {\n if (!isItemOrSection(itemOrSection)) {\n log.debug(INVALID_ITEM_ERROR_MESSAGE, itemOrSection);\n throw new Error(INVALID_ITEM_ERROR_MESSAGE);\n }\n\n if (isSectionElement(itemOrSection)) {\n const key = normalizeItemKey(itemOrSection);\n const { title } = itemOrSection.props;\n\n const items = normalizeItemList(itemOrSection.props.children).filter(\n // We don't support nested section elements\n childItem => !isSectionElement(childItem)\n ) as NormalizedItem[];\n\n return {\n item: { key, title, items },\n } as NormalizedItemOrSection<TItemOrSection>;\n }\n\n const key = normalizeItemKey(itemOrSection);\n const content = isItemElement(itemOrSection)\n ? itemOrSection.props.children\n : itemOrSection;\n const textValue = normalizeTextValue(itemOrSection);\n\n return {\n item: { key, content, textValue },\n } as NormalizedItemOrSection<TItemOrSection>;\n}\n\n/**\n * Normalize an item or section or a list of items or sections.\n * @param itemsOrSections An item or section or array of items or sections\n * @returns An array of normalized items or sections\n */\nexport function normalizeItemList<TItemOrSection extends ItemOrSection>(\n itemsOrSections: TItemOrSection | TItemOrSection[] | NormalizedItem[]\n): NormalizedItemOrSection<TItemOrSection>[] {\n // If already normalized, just return as-is\n if (isNormalizedItemsWithKeysList(itemsOrSections)) {\n return itemsOrSections as NormalizedItemOrSection<TItemOrSection>[];\n }\n\n const itemsArray: TItemOrSection[] = Array.isArray(itemsOrSections)\n ? itemsOrSections\n : [itemsOrSections];\n\n return itemsArray.map(normalizeItem);\n}\n\n/**\n * Returns a TooltipOptions object or null if options is false or null.\n * @param options Tooltip options\n * @param placement Default placement for the tooltip if `options` is set\n * explicitly to `true`\n * @returns TooltipOptions or null\n */\nexport function normalizeTooltipOptions(\n options?: boolean | TooltipOptions | null,\n placement: TooltipOptions['placement'] = 'right'\n): TooltipOptions | null {\n if (options == null || options === false) {\n return null;\n }\n\n if (options === true) {\n return { placement };\n }\n\n return options;\n}\n\n/**\n * Convert a selection of `ItemKey`s to a selection of strings.\n * @param itemKeys The selection of `ItemKey`s\n * @returns The selection of strings\n */\nexport function itemSelectionToStringSet<\n TKeys extends 'all' | Iterable<ItemKey> | undefined,\n TResult extends TKeys extends 'all'\n ? 'all'\n : TKeys extends Iterable<ItemKey>\n ? Set<string>\n : undefined,\n>(itemKeys: TKeys): TResult {\n if (itemKeys == null || itemKeys === 'all') {\n return itemKeys as undefined | 'all' as TResult;\n }\n\n return new Set([...itemKeys].map(String)) as TResult;\n}\n"],"mappings":";;AAGA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SAASC,eAAe,QAAQ,wBAAwB;AAAC,SAEhDC,IAAI,EAAaC,OAAO;AAAA,SAExBC,IAAI;AAAA,OACNC,WAAW;AAElB,IAAMC,GAAG,GAAGN,GAAG,CAACO,MAAM,CAAC,WAAW,CAAC;;AAEnC;AACA;AACA;AACA;AACA,OAAO,IAAMC,4BAA4B,GAAG,OAAO;AAEnD,OAAO,IAAMC,0BAA0B,GACrC,yEAAyE;;AAE3E;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAOxBC,IAA8B,EAAQ;EAAA,IAAAC,cAAA,EAAAC,UAAA;EACtC,QAAAD,cAAA,GAAQD,IAAI,aAAJA,IAAI,wBAAAE,UAAA,GAAJF,IAAI,CAAEA,IAAI,cAA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CAACA,eAAe,CAAC;EAErB,OAAOC,UAAU,CAACC,GAAG,CAACT,aAAa,CAAC;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASU,uBAAuBA,CACrCC,OAAyC,EAElB;EAAA,IADvBC,SAAsC,GAAAhD,SAAA,CAAAS,MAAA,QAAAT,SAAA,QAAAgC,SAAA,GAAAhC,SAAA,MAAG,OAAO;EAEhD,IAAI+C,OAAO,IAAI,IAAI,IAAIA,OAAO,KAAK,KAAK,EAAE;IACxC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,KAAK,IAAI,EAAE;IACpB,OAAO;MAAEC;IAAU,CAAC;EACtB;EAEA,OAAOD,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,wBAAwBA,CAOtCC,QAAe,EAAW;EAC1B,IAAIA,QAAQ,IAAI,IAAI,IAAIA,QAAQ,KAAK,KAAK,EAAE;IAC1C,OAAOA,QAAQ;EACjB;EAEA,OAAO,IAAIC,GAAG,CAAC,CAAC,GAAGD,QAAQ,CAAC,CAACL,GAAG,CAACV,MAAM,CAAC,CAAC;AAC3C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ItemElement, ItemOrSection, SectionElement, TooltipOptions } from './itemUtils';
|
|
2
|
+
/**
|
|
3
|
+
* Ensure all primitive children are wrapped in `Item` elements and that all
|
|
4
|
+
* `Item` element content is wrapped in `ItemContent` elements to handle text
|
|
5
|
+
* overflow consistently and to support tooltips.
|
|
6
|
+
* @param itemsOrSections The items or sections to wrap
|
|
7
|
+
* @param tooltipOptions The tooltip options to use when wrapping items
|
|
8
|
+
* @returns The wrapped items or sections
|
|
9
|
+
*/
|
|
10
|
+
export declare function wrapItemChildren(itemsOrSections: ItemOrSection | ItemOrSection[], tooltipOptions: TooltipOptions | null): (ItemElement | SectionElement)[];
|
|
11
|
+
export default wrapItemChildren;
|
|
12
|
+
//# sourceMappingURL=itemWrapperUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemWrapperUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/itemWrapperUtils.tsx"],"names":[],"mappings":"AAGA,OAAO,EAGL,WAAW,EACX,aAAa,EAEb,cAAc,EACd,cAAc,EACf,MAAM,aAAa,CAAC;AAIrB;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,aAAa,GAAG,aAAa,EAAE,EAChD,cAAc,EAAE,cAAc,GAAG,IAAI,GACpC,CAAC,WAAW,GAAG,cAAc,CAAC,EAAE,CA8DlC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
+
import { cloneElement } from 'react';
|
|
7
|
+
import { Item } from '@adobe/react-spectrum';
|
|
8
|
+
import { isElementOfType } from '@deephaven/react-hooks';
|
|
9
|
+
import { isItemElement, isSectionElement, ITEM_EMPTY_STRING_TEXT_VALUE } from "./itemUtils.js";
|
|
10
|
+
import ItemContent from "../ItemContent.js";
|
|
11
|
+
/**
|
|
12
|
+
* Ensure all primitive children are wrapped in `Item` elements and that all
|
|
13
|
+
* `Item` element content is wrapped in `ItemContent` elements to handle text
|
|
14
|
+
* overflow consistently and to support tooltips.
|
|
15
|
+
* @param itemsOrSections The items or sections to wrap
|
|
16
|
+
* @param tooltipOptions The tooltip options to use when wrapping items
|
|
17
|
+
* @returns The wrapped items or sections
|
|
18
|
+
*/
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
export function wrapItemChildren(itemsOrSections, tooltipOptions) {
|
|
21
|
+
var itemsOrSectionsArray = Array.isArray(itemsOrSections) ? itemsOrSections : [itemsOrSections];
|
|
22
|
+
return itemsOrSectionsArray.map(item => {
|
|
23
|
+
if (isItemElement(item)) {
|
|
24
|
+
var _item$key;
|
|
25
|
+
// Item content is already wrapped
|
|
26
|
+
if (isElementOfType(item.props.children, ItemContent)) {
|
|
27
|
+
return item;
|
|
28
|
+
}
|
|
29
|
+
var key = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.props.textValue;
|
|
30
|
+
var textValue = item.props.textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : item.props.textValue;
|
|
31
|
+
|
|
32
|
+
// Wrap in `ItemContent` so we can support tooltips and handle text
|
|
33
|
+
// overflow
|
|
34
|
+
return /*#__PURE__*/cloneElement(item, _objectSpread(_objectSpread({}, item.props), {}, {
|
|
35
|
+
key,
|
|
36
|
+
textValue,
|
|
37
|
+
children: /*#__PURE__*/_jsx(ItemContent, {
|
|
38
|
+
tooltipOptions: tooltipOptions,
|
|
39
|
+
children: item.props.children
|
|
40
|
+
})
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
if (isSectionElement(item)) {
|
|
44
|
+
var _item$key2;
|
|
45
|
+
return /*#__PURE__*/cloneElement(item, _objectSpread(_objectSpread({}, item.props), {}, {
|
|
46
|
+
key: (_item$key2 = item.key) !== null && _item$key2 !== void 0 ? _item$key2 : typeof item.props.title === 'string' ? item.props.title : undefined,
|
|
47
|
+
children: wrapItemChildren(item.props.children, tooltipOptions)
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') {
|
|
51
|
+
var text = String(item);
|
|
52
|
+
var _textValue = text === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : text;
|
|
53
|
+
return /*#__PURE__*/_jsx(Item, {
|
|
54
|
+
textValue: _textValue,
|
|
55
|
+
children: /*#__PURE__*/_jsx(ItemContent, {
|
|
56
|
+
tooltipOptions: tooltipOptions,
|
|
57
|
+
children: text
|
|
58
|
+
})
|
|
59
|
+
}, text);
|
|
60
|
+
}
|
|
61
|
+
return item;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export default wrapItemChildren;
|
|
65
|
+
//# sourceMappingURL=itemWrapperUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemWrapperUtils.js","names":["cloneElement","Item","isElementOfType","isItemElement","isSectionElement","ITEM_EMPTY_STRING_TEXT_VALUE","ItemContent","jsx","_jsx","wrapItemChildren","itemsOrSections","tooltipOptions","itemsOrSectionsArray","Array","isArray","map","item","_item$key","props","children","key","textValue","_objectSpread","_item$key2","title","undefined","text","String"],"sources":["../../../src/spectrum/utils/itemWrapperUtils.tsx"],"sourcesContent":["import { cloneElement, ReactElement } from 'react';\nimport { Item } from '@adobe/react-spectrum';\nimport { isElementOfType } from '@deephaven/react-hooks';\nimport {\n isItemElement,\n isSectionElement,\n ItemElement,\n ItemOrSection,\n ITEM_EMPTY_STRING_TEXT_VALUE,\n SectionElement,\n TooltipOptions,\n} from './itemUtils';\nimport { ItemProps } from '../shared';\nimport ItemContent from '../ItemContent';\n\n/**\n * Ensure all primitive children are wrapped in `Item` elements and that all\n * `Item` element content is wrapped in `ItemContent` elements to handle text\n * overflow consistently and to support tooltips.\n * @param itemsOrSections The items or sections to wrap\n * @param tooltipOptions The tooltip options to use when wrapping items\n * @returns The wrapped items or sections\n */\nexport function wrapItemChildren(\n itemsOrSections: ItemOrSection | ItemOrSection[],\n tooltipOptions: TooltipOptions | null\n): (ItemElement | SectionElement)[] {\n const itemsOrSectionsArray = Array.isArray(itemsOrSections)\n ? itemsOrSections\n : [itemsOrSections];\n\n return itemsOrSectionsArray.map(item => {\n if (isItemElement(item)) {\n // Item content is already wrapped\n if (isElementOfType(item.props.children, ItemContent)) {\n return item;\n }\n\n const key = item.key ?? item.props.textValue;\n const textValue =\n item.props.textValue === ''\n ? ITEM_EMPTY_STRING_TEXT_VALUE\n : item.props.textValue;\n\n // Wrap in `ItemContent` so we can support tooltips and handle text\n // overflow\n return cloneElement(item, {\n ...item.props,\n key,\n textValue,\n children: (\n <ItemContent tooltipOptions={tooltipOptions}>\n {item.props.children}\n </ItemContent>\n ),\n });\n }\n\n if (isSectionElement(item)) {\n return cloneElement(item, {\n ...item.props,\n key:\n item.key ??\n (typeof item.props.title === 'string' ? item.props.title : undefined),\n children: wrapItemChildren(\n item.props.children,\n tooltipOptions\n ) as ReactElement<ItemProps<unknown>>[],\n });\n }\n\n if (\n typeof item === 'string' ||\n typeof item === 'number' ||\n typeof item === 'boolean'\n ) {\n const text = String(item);\n const textValue = text === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : text;\n\n return (\n <Item key={text} textValue={textValue}>\n <ItemContent tooltipOptions={tooltipOptions}>{text}</ItemContent>\n </Item>\n );\n }\n\n return item;\n });\n}\n\nexport default wrapItemChildren;\n"],"mappings":";;;;;AAAA,SAASA,YAAY,QAAsB,O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AAAA,aAAA,KACnBN,IAAI,CAACE,KAAK;QACbE,GAAG,GAAAG,UAAA,GACDP,IAAI,CAACI,GAAG,cAAAG,UAAA,cAAAA,UAAA,GACP,OAAOP,IAAI,CAACE,KAAK,CAACM,KAAK,KAAK,QAAQ,GAAGR,IAAI,CAACE,KAAK,CAACM,KAAK,GAAGC,SAAU;QACvEN,QAAQ,EAAEV,gBAAgB,CACxBO,IAAI,CAACE,KAAK,CAACC,QAAQ,EACnBR,cACF;MAAuC,EACxC,CAAC;IACJ;IAEA,IACE,OAAOK,IAAI,KAAK,QAAQ,IACxB,OAAOA,IAAI,KAAK,QAAQ,IACxB,OAAOA,IAAI,KAAK,SAAS,EACzB;MACA,IAAMU,IAAI,GAAGC,MAAM,CAACX,IAAI,CAAC;MACzB,IAAMK,UAAS,GAAGK,IAAI,KAAK,EAAE,GAAGrB,4BAA4B,GAAGqB,IAAI;MAEnE,oBACElB,IAAA,CAACP,IAAI;QAAYoB,SAAS,EAAEA,UAAU;QAAAF,QAAA,eACpCX,IAAA,CAACF,WAAW;UAACK,cAAc,EAAEA,cAAe;UAAAQ,QAAA,EAAEO;QAAI,CAAc;MAAC,GADxDA,IAEL,CAAC;IAEX;IAEA,OAAOV,IAAI;EACb,CAAC,CAAC;AACJ;AAEA,eAAeP,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderNormalizedItem.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"names":[],"mappings":";AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"useRenderNormalizedItem.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"names":[],"mappings":";AAGA,OAAO,EAGL,cAAc,EACd,cAAc,EACf,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,cAAc,GAAG,IAAI,GACpC,CAAC,cAAc,EAAE,cAAc,KAAK,GAAG,CAAC,OAAO,CA+BjD;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -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,\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