@deephaven/components 0.71.1-beta.3 → 0.72.1-alpha-list-view.16
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/SearchInput.css +10 -12
- package/dist/SearchInput.css.map +1 -1
- package/dist/Select.d.ts +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/spectrum/Heading.d.ts +4 -1
- package/dist/spectrum/Heading.d.ts.map +1 -1
- package/dist/spectrum/Heading.js +5 -3
- package/dist/spectrum/Heading.js.map +1 -1
- package/dist/spectrum/ItemContent.d.ts +15 -0
- package/dist/spectrum/ItemContent.d.ts.map +1 -0
- package/dist/spectrum/{picker/PickerItemContent.js → ItemContent.js} +42 -18
- package/dist/spectrum/ItemContent.js.map +1 -0
- package/dist/spectrum/ItemTooltip.d.ts +12 -0
- package/dist/spectrum/ItemTooltip.d.ts.map +1 -0
- package/dist/spectrum/ItemTooltip.js +30 -0
- package/dist/spectrum/ItemTooltip.js.map +1 -0
- package/dist/spectrum/Text.d.ts +4 -1
- package/dist/spectrum/Text.d.ts.map +1 -1
- package/dist/spectrum/Text.js +5 -4
- package/dist/spectrum/Text.js.map +1 -1
- package/dist/spectrum/View.d.ts +4 -1
- package/dist/spectrum/View.d.ts.map +1 -1
- package/dist/spectrum/View.js +5 -3
- package/dist/spectrum/View.js.map +1 -1
- package/dist/spectrum/collections.d.ts +1 -1
- package/dist/spectrum/collections.d.ts.map +1 -1
- package/dist/spectrum/collections.js +1 -1
- package/dist/spectrum/collections.js.map +1 -1
- package/dist/spectrum/index.d.ts +3 -0
- package/dist/spectrum/index.d.ts.map +1 -1
- package/dist/spectrum/index.js +4 -1
- package/dist/spectrum/index.js.map +1 -1
- package/dist/spectrum/listView/ListView.d.ts +28 -0
- package/dist/spectrum/listView/ListView.d.ts.map +1 -0
- package/dist/spectrum/listView/ListView.js +59 -0
- package/dist/spectrum/listView/ListView.js.map +1 -0
- package/dist/spectrum/listView/index.d.ts +2 -0
- package/dist/spectrum/listView/index.d.ts.map +1 -0
- package/dist/spectrum/listView/index.js +2 -0
- package/dist/spectrum/listView/index.js.map +1 -0
- package/dist/spectrum/picker/Picker.d.ts +6 -6
- package/dist/spectrum/picker/Picker.d.ts.map +1 -1
- package/dist/spectrum/picker/Picker.js +16 -66
- package/dist/spectrum/picker/Picker.js.map +1 -1
- package/dist/spectrum/picker/index.d.ts +0 -1
- package/dist/spectrum/picker/index.d.ts.map +1 -1
- package/dist/spectrum/picker/index.js +0 -1
- package/dist/spectrum/picker/index.js.map +1 -1
- package/dist/spectrum/utils/index.d.ts +5 -0
- package/dist/spectrum/utils/index.d.ts.map +1 -0
- package/dist/spectrum/utils/index.js +5 -0
- package/dist/spectrum/utils/index.js.map +1 -0
- package/dist/spectrum/utils/itemUtils.d.ts +114 -0
- package/dist/spectrum/utils/itemUtils.d.ts.map +1 -0
- package/dist/spectrum/{picker/PickerUtils.js → utils/itemUtils.js} +54 -50
- package/dist/spectrum/utils/itemUtils.js.map +1 -0
- package/dist/spectrum/{utils.d.ts → utils/themeUtils.d.ts} +2 -1
- package/dist/spectrum/utils/themeUtils.d.ts.map +1 -0
- package/dist/spectrum/{utils.js → utils/themeUtils.js} +3 -2
- package/dist/spectrum/utils/themeUtils.js.map +1 -0
- package/dist/spectrum/utils/useRenderNormalizedItem.d.ts +5 -0
- package/dist/spectrum/utils/useRenderNormalizedItem.d.ts.map +1 -0
- package/dist/spectrum/utils/useRenderNormalizedItem.js +34 -0
- package/dist/spectrum/utils/useRenderNormalizedItem.js.map +1 -0
- package/dist/spectrum/utils/useStringifiedMultiSelection.d.ts +43 -0
- package/dist/spectrum/utils/useStringifiedMultiSelection.d.ts.map +1 -0
- package/dist/spectrum/utils/useStringifiedMultiSelection.js +56 -0
- package/dist/spectrum/utils/useStringifiedMultiSelection.js.map +1 -0
- package/dist/theme/SpectrumThemeProvider.js +1 -1
- package/package.json +8 -7
- package/dist/spectrum/picker/PickerItemContent.d.ts +0 -11
- package/dist/spectrum/picker/PickerItemContent.d.ts.map +0 -1
- package/dist/spectrum/picker/PickerItemContent.js.map +0 -1
- package/dist/spectrum/picker/PickerUtils.d.ts +0 -111
- package/dist/spectrum/picker/PickerUtils.d.ts.map +0 -1
- package/dist/spectrum/picker/PickerUtils.js.map +0 -1
- package/dist/spectrum/utils.d.ts.map +0 -1
- package/dist/spectrum/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/picker/index.ts"],"sourcesContent":["export * from './Picker';\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/picker/index.ts"],"sourcesContent":["export * from './Picker';\n"],"mappings":""}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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":""}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Key, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { SpectrumPickerProps } from '@adobe/react-spectrum';
|
|
3
|
+
import type { ItemRenderer } from '@react-types/shared';
|
|
4
|
+
import { KeyedItem } from '@deephaven/utils';
|
|
5
|
+
import { ItemProps, SectionProps } from '../shared';
|
|
6
|
+
import { PopperOptions } from '../../popper';
|
|
7
|
+
export declare const INVALID_ITEM_ERROR_MESSAGE = "Items must be strings, numbers, booleans, <Item> or <Section> elements:";
|
|
8
|
+
/**
|
|
9
|
+
* React Spectrum <Section> supports an `ItemRenderer` function as a child. The
|
|
10
|
+
* DH picker makes use of this internally, but we don't want to support it as
|
|
11
|
+
* an incoming prop.
|
|
12
|
+
*/
|
|
13
|
+
type SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {
|
|
14
|
+
children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;
|
|
15
|
+
};
|
|
16
|
+
type ItemElement = ReactElement<ItemProps<unknown>>;
|
|
17
|
+
export type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;
|
|
18
|
+
export type ItemElementOrPrimitive = number | string | boolean | ItemElement;
|
|
19
|
+
export type ItemOrSection = ItemElementOrPrimitive | SectionElement;
|
|
20
|
+
/**
|
|
21
|
+
* Augment the Spectrum selection key type to include boolean values.
|
|
22
|
+
* Spectrum collection components already supports this, but the built in types
|
|
23
|
+
* don't reflect it.
|
|
24
|
+
*/
|
|
25
|
+
export type ItemKey = Key | boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Augment the Spectrum selection change handler type to include boolean keys.
|
|
28
|
+
* Spectrum components already supports this, but the built in types don't
|
|
29
|
+
* reflect it.
|
|
30
|
+
*/
|
|
31
|
+
export type ItemSelectionChangeHandler = (key: ItemKey) => void;
|
|
32
|
+
export interface NormalizedItemData {
|
|
33
|
+
key?: ItemKey;
|
|
34
|
+
content: ReactNode;
|
|
35
|
+
textValue?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface NormalizedSectionData {
|
|
38
|
+
key?: Key;
|
|
39
|
+
title?: ReactNode;
|
|
40
|
+
items: NormalizedItem[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Spectrum collection components support a variety of item types, including
|
|
44
|
+
* strings, numbers, booleans, and more complex React elements. This type
|
|
45
|
+
* represents a normalized form to make rendering items simpler and keep the
|
|
46
|
+
* logic of transformation in separate util methods. It also adheres to the
|
|
47
|
+
* `KeyedItem` interface to be compatible with Windowed data utils
|
|
48
|
+
* (e.g. `useViewportData`).
|
|
49
|
+
*/
|
|
50
|
+
export type NormalizedItem = KeyedItem<NormalizedItemData, ItemKey | undefined>;
|
|
51
|
+
export type NormalizedSection = KeyedItem<NormalizedSectionData, Key | undefined>;
|
|
52
|
+
export type NormalizedItemOrSection<TItemOrSection extends ItemOrSection> = TItemOrSection extends SectionElement ? NormalizedSection : NormalizedItem;
|
|
53
|
+
export type NormalizedSpectrumPickerProps = SpectrumPickerProps<NormalizedItem>;
|
|
54
|
+
export type TooltipOptions = {
|
|
55
|
+
placement: PopperOptions['placement'];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* DH wrappers of Spectrum collection components use a normalized item that
|
|
59
|
+
* includes a `key` prop and an optional `item` prop. This is mostly to support
|
|
60
|
+
* Windowed data where items are created before their data has been loaded (data
|
|
61
|
+
* gets set in the `item` prop). If data has loaded, return its `key`. If not,
|
|
62
|
+
* return the top-level `key` on the normalized item.
|
|
63
|
+
* @param item The normalized item or section
|
|
64
|
+
* @returns The `key` of the item or section
|
|
65
|
+
*/
|
|
66
|
+
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;
|
|
67
|
+
/**
|
|
68
|
+
* Determine if a node is a Section element.
|
|
69
|
+
* @param node The node to check
|
|
70
|
+
* @returns True if the node is a Section element
|
|
71
|
+
*/
|
|
72
|
+
export declare function isSectionElement<T>(node: ReactNode): node is ReactElement<SectionProps<T>>;
|
|
73
|
+
/**
|
|
74
|
+
* Determine if a node is an Item element.
|
|
75
|
+
* @param node The node to check
|
|
76
|
+
* @returns True if the node is an Item element
|
|
77
|
+
*/
|
|
78
|
+
export declare function isItemElement<T>(node: ReactNode): node is ReactElement<ItemProps<T>>;
|
|
79
|
+
/**
|
|
80
|
+
* Determine if a node is an array containing normalized items or sections with
|
|
81
|
+
* keys. Note that this only checks the first node in the array.
|
|
82
|
+
* @param node The node to check
|
|
83
|
+
* @returns True if the node is a normalized item or section with keys array
|
|
84
|
+
*/
|
|
85
|
+
export declare function isNormalizedItemsWithKeysList<TItemOrSection extends ItemOrSection>(node: TItemOrSection | TItemOrSection[] | NormalizedItemOrSection<TItemOrSection>[]): node is NormalizedItemOrSection<TItemOrSection>[];
|
|
86
|
+
/**
|
|
87
|
+
* Determine if an object is a normalized section.
|
|
88
|
+
* @param maybeNormalizedSection The object to check
|
|
89
|
+
* @returns True if the object is a normalized section
|
|
90
|
+
*/
|
|
91
|
+
export declare function isNormalizedSection(maybeNormalizedSection: NormalizedItem | NormalizedSection): maybeNormalizedSection is NormalizedSection;
|
|
92
|
+
/**
|
|
93
|
+
* Determine if a node is an item or section. Valid types include strings,
|
|
94
|
+
* numbers, booleans, Item elements, and Section elements.
|
|
95
|
+
* @param node The node to check
|
|
96
|
+
* @returns True if the node is an item or section
|
|
97
|
+
*/
|
|
98
|
+
export declare function isItemOrSection(node: ReactNode): node is ItemOrSection;
|
|
99
|
+
/**
|
|
100
|
+
* Normalize an item or section or a list of items or sections.
|
|
101
|
+
* @param itemsOrSections An item or section or array of items or sections
|
|
102
|
+
* @returns An array of normalized items or sections
|
|
103
|
+
*/
|
|
104
|
+
export declare function normalizeItemList<TItemOrSection extends ItemOrSection>(itemsOrSections: TItemOrSection | TItemOrSection[] | NormalizedItem[]): NormalizedItemOrSection<TItemOrSection>[];
|
|
105
|
+
/**
|
|
106
|
+
* Returns a TooltipOptions object or null if options is false or null.
|
|
107
|
+
* @param options Tooltip options
|
|
108
|
+
* @param placement Default placement for the tooltip if `options` is set
|
|
109
|
+
* explicitly to `true`
|
|
110
|
+
* @returns TooltipOptions or null
|
|
111
|
+
*/
|
|
112
|
+
export declare function normalizeTooltipOptions(options?: boolean | TooltipOptions | null, placement?: TooltipOptions['placement']): TooltipOptions | null;
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceM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CAAC,CAAC,CAAC,CAAC,CAEpC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,cAAc,SAAS,aAAa,EAEpC,IAAI,EACA,cAAc,GACd,cAAc,EAAE,GAChB,uBAAuB,CAAC,cAAc,CAAC,EAAE,GAC5C,IAAI,IAAI,uBAAuB,CAAC,cAAc,CAAC,EAAE,CAUnD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,sBAAsB,EAAE,cAAc,GAAG,iBAAiB,GACzD,sBAAsB,IAAI,iBAAiB,CAK7C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,IAAI,aAAa,CAQtE;AAiGD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,SAAS,aAAa,EACpE,eAAe,EAAE,cAAc,GAAG,cAAc,EAAE,GAAG,cAAc,EAAE,GACpE,uBAAuB,CAAC,cAAc,CAAC,EAAE,CAW3C;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,CAAC,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,EACzC,SAAS,GAAE,cAAc,CAAC,WAAW,CAAW,GAC/C,cAAc,GAAG,IAAI,CAUvB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isValidElement } from 'react';
|
|
2
2
|
import Log from '@deephaven/log';
|
|
3
3
|
import { Item, Section } from "../shared.js";
|
|
4
|
-
var log = Log.module('
|
|
5
|
-
export var
|
|
4
|
+
var log = Log.module('itemUtils');
|
|
5
|
+
export var INVALID_ITEM_ERROR_MESSAGE = 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* React Spectrum <Section> supports an `ItemRenderer` function as a child. The
|
|
@@ -12,34 +12,35 @@ export var INVALID_PICKER_ITEM_ERROR_MESSAGE = 'Picker items must be strings, nu
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Augment the Spectrum selection key type to include boolean values.
|
|
15
|
-
*
|
|
16
|
-
* reflect it.
|
|
15
|
+
* Spectrum collection components already supports this, but the built in types
|
|
16
|
+
* don't reflect it.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Augment the Spectrum selection change handler type to include boolean keys.
|
|
21
|
-
*
|
|
21
|
+
* Spectrum components already supports this, but the built in types don't
|
|
22
22
|
* reflect it.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
* booleans, and more complex React elements. This type
|
|
28
|
-
* form to make rendering items simpler and keep the
|
|
29
|
-
* in separate util methods. It also adheres to the
|
|
30
|
-
* be compatible with Windowed data utils
|
|
26
|
+
* Spectrum collection components support a variety of item types, including
|
|
27
|
+
* strings, numbers, booleans, and more complex React elements. This type
|
|
28
|
+
* represents a normalized form to make rendering items simpler and keep the
|
|
29
|
+
* logic of transformation in separate util methods. It also adheres to the
|
|
30
|
+
* `KeyedItem` interface to be compatible with Windowed data utils
|
|
31
|
+
* (e.g. `useViewportData`).
|
|
31
32
|
*/
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
-
* `item` prop. This is mostly to support
|
|
36
|
-
* before their data has been loaded (data
|
|
37
|
-
* data has loaded, return its `key`. If not,
|
|
38
|
-
* normalized item.
|
|
39
|
-
* @param item The normalized
|
|
35
|
+
* DH wrappers of Spectrum collection components use a normalized item that
|
|
36
|
+
* includes a `key` prop and an optional `item` prop. This is mostly to support
|
|
37
|
+
* Windowed data where items are created before their data has been loaded (data
|
|
38
|
+
* gets set in the `item` prop). If data has loaded, return its `key`. If not,
|
|
39
|
+
* return the top-level `key` on the normalized item.
|
|
40
|
+
* @param item The normalized item or section
|
|
40
41
|
* @returns The `key` of the item or section
|
|
41
42
|
*/
|
|
42
|
-
export function
|
|
43
|
+
export function getItemKey(item) {
|
|
43
44
|
var _item$item$key, _item$item;
|
|
44
45
|
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;
|
|
45
46
|
}
|
|
@@ -63,10 +64,10 @@ export function isItemElement(node) {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
/**
|
|
66
|
-
* Determine if a node is an array containing normalized items with
|
|
67
|
-
* Note that this only checks the first node in the array.
|
|
67
|
+
* Determine if a node is an array containing normalized items or sections with
|
|
68
|
+
* keys. Note that this only checks the first node in the array.
|
|
68
69
|
* @param node The node to check
|
|
69
|
-
* @returns True if the node is a normalized item with keys array
|
|
70
|
+
* @returns True if the node is a normalized item or section with keys array
|
|
70
71
|
*/
|
|
71
72
|
export function isNormalizedItemsWithKeysList(node) {
|
|
72
73
|
if (!Array.isArray(node)) {
|
|
@@ -75,32 +76,32 @@ export function isNormalizedItemsWithKeysList(node) {
|
|
|
75
76
|
if (node.length === 0) {
|
|
76
77
|
return true;
|
|
77
78
|
}
|
|
78
|
-
return !
|
|
79
|
+
return !isItemOrSection(node[0]) && 'key' in node[0];
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* Determine if an object is a normalized
|
|
83
|
-
* @param
|
|
84
|
-
* @returns True if the object is a normalized
|
|
83
|
+
* Determine if an object is a normalized section.
|
|
84
|
+
* @param maybeNormalizedSection The object to check
|
|
85
|
+
* @returns True if the object is a normalized section
|
|
85
86
|
*/
|
|
86
|
-
export function
|
|
87
|
-
return
|
|
87
|
+
export function isNormalizedSection(maybeNormalizedSection) {
|
|
88
|
+
return maybeNormalizedSection.item != null && 'items' in maybeNormalizedSection.item;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
|
-
* Determine if a node is
|
|
92
|
+
* Determine if a node is an item or section. Valid types include strings,
|
|
92
93
|
* numbers, booleans, Item elements, and Section elements.
|
|
93
94
|
* @param node The node to check
|
|
94
|
-
* @returns True if the node is
|
|
95
|
+
* @returns True if the node is an item or section
|
|
95
96
|
*/
|
|
96
|
-
export function
|
|
97
|
+
export function isItemOrSection(node) {
|
|
97
98
|
return typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean' || isItemElement(node) || isSectionElement(node);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
* Determine the `key` of
|
|
102
|
-
* @param itemOrSection The
|
|
103
|
-
* @returns A `
|
|
102
|
+
* Determine the `key` of an item or section.
|
|
103
|
+
* @param itemOrSection The item or section
|
|
104
|
+
* @returns A `ItemKey` for the item or undefined if a key can't be determined
|
|
104
105
|
*/
|
|
105
106
|
|
|
106
107
|
function normalizeItemKey(itemOrSection) {
|
|
@@ -125,9 +126,9 @@ function normalizeItemKey(itemOrSection) {
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
|
-
* Get a normalized `textValue` for
|
|
129
|
-
* @param item The
|
|
130
|
-
* @returns A string `textValue` for the
|
|
129
|
+
* Get a normalized `textValue` for an item ensuring it is a string.
|
|
130
|
+
* @param item The item
|
|
131
|
+
* @returns A string `textValue` for the item
|
|
131
132
|
*/
|
|
132
133
|
function normalizeTextValue(item) {
|
|
133
134
|
if (typeof item !== 'object') {
|
|
@@ -143,21 +144,21 @@ function normalizeTextValue(item) {
|
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
/**
|
|
146
|
-
* Normalize
|
|
147
|
+
* Normalize an item or section to an object form.
|
|
147
148
|
* @param itemOrSection item to normalize
|
|
148
|
-
* @returns
|
|
149
|
+
* @returns NormalizedItem or NormalizedSection object
|
|
149
150
|
*/
|
|
150
|
-
function
|
|
151
|
-
if (!
|
|
152
|
-
log.debug(
|
|
153
|
-
throw new Error(
|
|
151
|
+
function normalizeItem(itemOrSection) {
|
|
152
|
+
if (!isItemOrSection(itemOrSection)) {
|
|
153
|
+
log.debug(INVALID_ITEM_ERROR_MESSAGE, itemOrSection);
|
|
154
|
+
throw new Error(INVALID_ITEM_ERROR_MESSAGE);
|
|
154
155
|
}
|
|
155
156
|
if (isSectionElement(itemOrSection)) {
|
|
156
157
|
var _key = normalizeItemKey(itemOrSection);
|
|
157
158
|
var {
|
|
158
159
|
title
|
|
159
160
|
} = itemOrSection.props;
|
|
160
|
-
var items =
|
|
161
|
+
var items = normalizeItemList(itemOrSection.props.children).filter(
|
|
161
162
|
// We don't support nested section elements
|
|
162
163
|
childItem => !isSectionElement(childItem));
|
|
163
164
|
return {
|
|
@@ -181,33 +182,36 @@ function normalizePickerItem(itemOrSection) {
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @param itemsOrSections
|
|
186
|
-
* @returns An array of normalized
|
|
185
|
+
* Normalize an item or section or a list of items or sections.
|
|
186
|
+
* @param itemsOrSections An item or section or array of items or sections
|
|
187
|
+
* @returns An array of normalized items or sections
|
|
187
188
|
*/
|
|
188
|
-
export function
|
|
189
|
+
export function normalizeItemList(itemsOrSections) {
|
|
189
190
|
// If already normalized, just return as-is
|
|
190
191
|
if (isNormalizedItemsWithKeysList(itemsOrSections)) {
|
|
191
192
|
return itemsOrSections;
|
|
192
193
|
}
|
|
193
194
|
var itemsArray = Array.isArray(itemsOrSections) ? itemsOrSections : [itemsOrSections];
|
|
194
|
-
return itemsArray.map(
|
|
195
|
+
return itemsArray.map(normalizeItem);
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
/**
|
|
198
199
|
* Returns a TooltipOptions object or null if options is false or null.
|
|
199
|
-
* @param options
|
|
200
|
+
* @param options Tooltip options
|
|
201
|
+
* @param placement Default placement for the tooltip if `options` is set
|
|
202
|
+
* explicitly to `true`
|
|
200
203
|
* @returns TooltipOptions or null
|
|
201
204
|
*/
|
|
202
205
|
export function normalizeTooltipOptions(options) {
|
|
206
|
+
var placement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'right';
|
|
203
207
|
if (options == null || options === false) {
|
|
204
208
|
return null;
|
|
205
209
|
}
|
|
206
210
|
if (options === true) {
|
|
207
211
|
return {
|
|
208
|
-
placement
|
|
212
|
+
placement
|
|
209
213
|
};
|
|
210
214
|
}
|
|
211
215
|
return options;
|
|
212
216
|
}
|
|
213
|
-
//# sourceMappingURL=
|
|
217
|
+
//# sourceMappingURL=itemUtils.js.map
|
|
@@ -0,0 +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"],"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 } 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\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"],"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;;AAGA;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,cA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O,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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { useStyleProps, baseStyleProps, viewStyleProps, } from '@react-spectrum/utils';
|
|
1
2
|
/**
|
|
2
3
|
* Extend light + dark theme variables with DH defaults.
|
|
3
4
|
*
|
|
@@ -42,4 +43,4 @@ export declare const themeDHDefault: {
|
|
|
42
43
|
medium: import("@react-types/provider").CSSModule | undefined;
|
|
43
44
|
large: import("@react-types/provider").CSSModule | undefined;
|
|
44
45
|
};
|
|
45
|
-
//# sourceMappingURL=
|
|
46
|
+
//# sourceMappingURL=themeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/themeUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,GACf,MAAM,uBAAuB,CAAC;AAI/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;CAa1B,CAAC"}
|
|
@@ -4,7 +4,8 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
4
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
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
6
|
import { theme } from '@react-spectrum/theme-default';
|
|
7
|
-
import { themeSpectrumClassesCommon } from "
|
|
7
|
+
import { themeSpectrumClassesCommon } from "../../theme/theme-spectrum/index.js";
|
|
8
|
+
export { useStyleProps, baseStyleProps, viewStyleProps } from '@react-spectrum/utils';
|
|
8
9
|
var {
|
|
9
10
|
global,
|
|
10
11
|
light,
|
|
@@ -55,4 +56,4 @@ export var themeDHDefault = {
|
|
|
55
56
|
medium,
|
|
56
57
|
large
|
|
57
58
|
};
|
|
58
|
-
//# sourceMappingURL=
|
|
59
|
+
//# sourceMappingURL=themeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeUtils.js","names":["theme","themeSpectrumClassesCommon","useStyleProps","baseStyleProps","viewStyleProps","global","light","dark","medium","large","themeDHDefault","_objectSpread"],"sources":["../../../src/spectrum/utils/themeUtils.ts"],"sourcesContent":["import { theme } from '@react-spectrum/theme-default';\nimport { themeSpectrumClassesCommon } from '../../theme/theme-spectrum';\n\nexport {\n useStyleProps,\n baseStyleProps,\n viewStyleProps,\n} from '@react-spectrum/utils';\n\nconst { global, light, dark, medium, large } = theme;\n\n/**\n * Extend light + dark theme variables with DH defaults.\n *\n * A theme is just a mapped collection of css class names that are generated\n * from a collection of css modules.\n *\n * e.g.\n * {\n * global: {\n * spectrum: 'spectrum_9e130c',\n * 'spectrum--medium': 'spectrum--medium_9e130c',\n * 'spectrum--large': 'spectrum--large_9e130c',\n * 'spectrum--darkest': 'spectrum--darkest_9e130c',\n * 'spectrum--dark': 'spectrum--dark_9e130c',\n * 'spectrum--light': 'spectrum--light_9e130c',\n * 'spectrum--lightest': 'spectrum--lightest_9e130c',\n * },\n * light: {\n * 'spectrum--light': 'spectrum--light_a40724',\n * 'dh-spectrum-theme--light': '_dh-spectrum-theme--light_1hblg_22',\n * },\n * dark: {\n * 'spectrum--darkest': 'spectrum--darkest_256eeb',\n * 'dh-spectrum-theme--dark': '_dh-spectrum-theme--dark_f7kge_22',\n * },\n * medium: {\n * 'spectrum--medium': 'spectrum--medium_4b172c',\n * },\n * large: {\n * 'spectrum--large': 'spectrum--large_c40598',\n * },\n * }\n */\n/* eslint-disable import/prefer-default-export */\nexport const themeDHDefault = {\n global,\n light: {\n ...light,\n ...themeSpectrumClassesCommon,\n },\n dark: {\n ...dark,\n ...themeSpectrumClassesCommon,\n },\n // scales\n medium,\n large,\n};\n"],"mappings":";;;;;AAAA,SAASA,KAAK,QAAQ,+BAA+B;AAAC,SAC7CC,0BAA0B;AAEnC,SACEC,aAAa,EACbC,cAAc,EACdC,cAAc,QACT,uBAAuB;AAE9B,IAAM;EAAEC,MAAM;EAAEC,KAAK;EAAEC,IAAI;EAAEC,MAAM;EAAEC;AAAM,CAAC,GAAGT,KAAK;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMU,cAAc,GAAG;EAC5BL,MAAM;EACNC,KAAK,EAAAK,aAAA,CAAAA,aAAA,KACAL,KAAK,GACLL,0BAA0B,CAC9B;EACDM,IAAI,EAAAI,aAAA,CAAAA,aAAA,KACCJ,IAAI,GACJN,0BAA0B,CAC9B;EACD;EACAO,MAAM;EACNC;AACF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { NormalizedItem, TooltipOptions } from './itemUtils';
|
|
3
|
+
export declare function useRenderNormalizedItem(tooltipOptions: TooltipOptions | null): (normalizedItem: NormalizedItem) => JSX.Element;
|
|
4
|
+
export default useRenderNormalizedItem;
|
|
5
|
+
//# sourceMappingURL=useRenderNormalizedItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRenderNormalizedItem.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAc,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzE,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,cAAc,GAAG,IAAI,GACpC,CAAC,cAAc,EAAE,cAAc,KAAK,GAAG,CAAC,OAAO,CA6BjD;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { ItemContent } from "../ItemContent.js";
|
|
3
|
+
import { Item } from "../shared.js";
|
|
4
|
+
import { getItemKey } from "./itemUtils.js";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export function useRenderNormalizedItem(tooltipOptions) {
|
|
7
|
+
return useCallback(normalizedItem => {
|
|
8
|
+
var _normalizedItem$item$, _normalizedItem$item, _normalizedItem$item$2, _normalizedItem$item2;
|
|
9
|
+
var key = getItemKey(normalizedItem);
|
|
10
|
+
var content = (_normalizedItem$item$ = (_normalizedItem$item = normalizedItem.item) === null || _normalizedItem$item === void 0 ? void 0 : _normalizedItem$item.content) !== null && _normalizedItem$item$ !== void 0 ? _normalizedItem$item$ : '';
|
|
11
|
+
var textValue = (_normalizedItem$item$2 = (_normalizedItem$item2 = normalizedItem.item) === null || _normalizedItem$item2 === void 0 ? void 0 : _normalizedItem$item2.textValue) !== null && _normalizedItem$item$2 !== void 0 ? _normalizedItem$item$2 : '';
|
|
12
|
+
return /*#__PURE__*/_jsx(Item
|
|
13
|
+
// Note that setting the `key` prop explicitly on `Item` elements
|
|
14
|
+
// causes the picker to expect `selectedKey` and `defaultSelectedKey`
|
|
15
|
+
// to be strings. It also passes the stringified value of the key to
|
|
16
|
+
// `onSelectionChange` handlers` regardless of the actual type of the
|
|
17
|
+
// key. We can't really get around setting in order to support Windowed
|
|
18
|
+
// data, so we'll need to do some manual conversion of keys to strings
|
|
19
|
+
// in other places of this component.
|
|
20
|
+
, {
|
|
21
|
+
// The `textValue` prop gets used to provide the content of `<option>`
|
|
22
|
+
// elements that back the Spectrum Picker. These are not visible in the UI,
|
|
23
|
+
// but are used for accessibility purposes, so we set to an arbitrary
|
|
24
|
+
// 'Empty' value so that they are not empty strings.
|
|
25
|
+
textValue: textValue === '' ? 'Empty' : textValue,
|
|
26
|
+
children: /*#__PURE__*/_jsx(ItemContent, {
|
|
27
|
+
tooltipOptions: tooltipOptions,
|
|
28
|
+
children: content
|
|
29
|
+
})
|
|
30
|
+
}, key);
|
|
31
|
+
}, [tooltipOptions]);
|
|
32
|
+
}
|
|
33
|
+
export default useRenderNormalizedItem;
|
|
34
|
+
//# sourceMappingURL=useRenderNormalizedItem.js.map
|
|
@@ -0,0 +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 { getItemKey, NormalizedItem, TooltipOptions } from './itemUtils';\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 places of this component.\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 // 'Empty' value so that they are not empty strings.\n textValue={textValue === '' ? 'Empty' : textValue}\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,SACJC,UAAU;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAEnB,OAAO,SAASC,uBAAuBA,CACrCC,cAAqC,EACY;EACjD,OAAOP,WAAW,CACfQ,cAA8B,IAAK;IAAA,IAAAC,qBAAA,EAAAC,oBAAA,EAAAC,sBAAA,EAAAC,qBAAA;IAClC,IAAMC,GAAG,GAAGV,UAAU,CAACK,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,CAACH;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IAAA;MAEA;MACA;MACA;MACA;MACAc,SAAS,EAAEA,SAAS,KAAK,EAAE,GAAG,OAAO,GAAGA,SAAU;MAAAC,QAAA,eAElDZ,IAAA,CAACJ,WAAW;QAACM,cAAc,EAAEA,cAAe;QAAAU,QAAA,EAAEH;MAAO,CAAc;IAAC,GAP/DD,GAQD,CAAC;EAEX,CAAC,EACD,CAACN,cAAc,CACjB,CAAC;AACH;AAEA,eAAeD,uBAAuB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Key } from 'react';
|
|
2
|
+
import { ItemKey, NormalizedItem } from './itemUtils';
|
|
3
|
+
export interface UseStringifiedMultiSelectionOptions {
|
|
4
|
+
normalizedItems: NormalizedItem[];
|
|
5
|
+
selectedKeys?: 'all' | Iterable<ItemKey>;
|
|
6
|
+
defaultSelectedKeys?: 'all' | Iterable<ItemKey>;
|
|
7
|
+
disabledKeys?: Iterable<ItemKey>;
|
|
8
|
+
/**
|
|
9
|
+
* Handler that is called when the selection change.
|
|
10
|
+
* Note that under the hood, this is just an alias for Spectrum's
|
|
11
|
+
* `onSelectionChange`. We are renaming for better consistency with other
|
|
12
|
+
* components.
|
|
13
|
+
*/
|
|
14
|
+
onChange?: (keys: 'all' | Set<ItemKey>) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface UseStringifiedMultiSelectionResult {
|
|
17
|
+
/** Stringified selection keys */
|
|
18
|
+
selectedStringKeys?: 'all' | Set<Key>;
|
|
19
|
+
/** Stringified default selection keys */
|
|
20
|
+
defaultSelectedStringKeys?: 'all' | Set<Key>;
|
|
21
|
+
/** Stringified disabled keys */
|
|
22
|
+
disabledStringKeys?: 'all' | Set<Key>;
|
|
23
|
+
/** Handler that is called when the string key selections change */
|
|
24
|
+
onStringSelectionChange: (keys: 'all' | Set<Key>) => void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Spectrum collection components treat keys as strings if the `key` prop is
|
|
28
|
+
* explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,
|
|
29
|
+
* we need to ensure that keys are strings in order for selection to work. We
|
|
30
|
+
* then need to convert back to the original key types in the onChange handler.
|
|
31
|
+
* This hook encapsulates converting to and from strings so that keys can match
|
|
32
|
+
* the original key type.
|
|
33
|
+
* @param normalizedItems The normalized items to select from.
|
|
34
|
+
* @param selectedKeys The currently selected keys in the collection.
|
|
35
|
+
* @param defaultSelectedKeys The initial selected keys in the collection.
|
|
36
|
+
* @param disabledKeys The currently disabled keys in the collection.
|
|
37
|
+
* @param onChange Handler that is called when the selection changes.
|
|
38
|
+
* @returns UseStringifiedMultiSelectionResult with stringified key sets and
|
|
39
|
+
* string key selection change handler.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useStringifiedMultiSelection({ normalizedItems, defaultSelectedKeys, disabledKeys, selectedKeys, onChange, }: UseStringifiedMultiSelectionOptions): UseStringifiedMultiSelectionResult;
|
|
42
|
+
export default useStringifiedMultiSelection;
|
|
43
|
+
//# sourceMappingURL=useStringifiedMultiSelection.d.ts.map
|
|
@@ -0,0 +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,EAAc,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAYlE,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,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CACjD;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,CA0C1E;AAED,eAAe,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { getItemKey } from "./itemUtils.js";
|
|
3
|
+
function toStringKeySet(keys) {
|
|
4
|
+
if (keys == null || keys === 'all') {
|
|
5
|
+
return keys;
|
|
6
|
+
}
|
|
7
|
+
return new Set([...keys].map(String));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Spectrum collection components treat keys as strings if the `key` prop is
|
|
11
|
+
* explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,
|
|
12
|
+
* we need to ensure that keys are strings in order for selection to work. We
|
|
13
|
+
* then need to convert back to the original key types in the onChange handler.
|
|
14
|
+
* This hook encapsulates converting to and from strings so that keys can match
|
|
15
|
+
* the original key type.
|
|
16
|
+
* @param normalizedItems The normalized items to select from.
|
|
17
|
+
* @param selectedKeys The currently selected keys in the collection.
|
|
18
|
+
* @param defaultSelectedKeys The initial selected keys in the collection.
|
|
19
|
+
* @param disabledKeys The currently disabled keys in the collection.
|
|
20
|
+
* @param onChange Handler that is called when the selection changes.
|
|
21
|
+
* @returns UseStringifiedMultiSelectionResult with stringified key sets and
|
|
22
|
+
* string key selection change handler.
|
|
23
|
+
*/
|
|
24
|
+
export function useStringifiedMultiSelection(_ref) {
|
|
25
|
+
var {
|
|
26
|
+
normalizedItems,
|
|
27
|
+
defaultSelectedKeys,
|
|
28
|
+
disabledKeys,
|
|
29
|
+
selectedKeys,
|
|
30
|
+
onChange
|
|
31
|
+
} = _ref;
|
|
32
|
+
var selectedStringKeys = useMemo(() => toStringKeySet(selectedKeys), [selectedKeys]);
|
|
33
|
+
var defaultSelectedStringKeys = useMemo(() => toStringKeySet(defaultSelectedKeys), [defaultSelectedKeys]);
|
|
34
|
+
var disabledStringKeys = useMemo(() => toStringKeySet(disabledKeys), [disabledKeys]);
|
|
35
|
+
var onStringSelectionChange = useCallback(keys => {
|
|
36
|
+
if (keys === 'all') {
|
|
37
|
+
onChange === null || onChange === void 0 ? void 0 : onChange('all');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var actualKeys = new Set();
|
|
41
|
+
normalizedItems.forEach(item => {
|
|
42
|
+
if (keys.has(String(getItemKey(item)))) {
|
|
43
|
+
actualKeys.add(getItemKey(item));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(actualKeys);
|
|
47
|
+
}, [normalizedItems, onChange]);
|
|
48
|
+
return {
|
|
49
|
+
selectedStringKeys,
|
|
50
|
+
defaultSelectedStringKeys,
|
|
51
|
+
disabledStringKeys,
|
|
52
|
+
onStringSelectionChange
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export default useStringifiedMultiSelection;
|
|
56
|
+
//# sourceMappingURL=useStringifiedMultiSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStringifiedMultiSelection.js","names":["useCallback","useMemo","getItemKey","toStringKeySet","keys","Set","map","String","useStringifiedMultiSelection","_ref","normalizedItems","defaultSelectedKeys","disabledKeys","selectedKeys","onChange","selectedStringKeys","defaultSelectedStringKeys","disabledStringKeys","onStringSelectionChange","actualKeys","forEach","item","has","add"],"sources":["../../../src/spectrum/utils/useStringifiedMultiSelection.ts"],"sourcesContent":["import { Key, useCallback, useMemo } from 'react';\nimport { getItemKey, ItemKey, NormalizedItem } from './itemUtils';\n\nfunction toStringKeySet(\n keys?: 'all' | Iterable<ItemKey>\n): undefined | 'all' | Set<Key> {\n if (keys == null || keys === 'all') {\n return keys as undefined | 'all';\n }\n\n return new Set([...keys].map(String));\n}\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: 'all' | Set<ItemKey>) => 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 () => toStringKeySet(selectedKeys),\n [selectedKeys]\n );\n\n const defaultSelectedStringKeys = useMemo(\n () => toStringKeySet(defaultSelectedKeys),\n [defaultSelectedKeys]\n );\n\n const disabledStringKeys = useMemo(\n () => toStringKeySet(disabledKeys),\n [disabledKeys]\n );\n\n const onStringSelectionChange = useCallback(\n (keys: 'all' | Set<Key>) => {\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,SACzCC,UAAU;AAEnB,SAASC,cAAcA,CACrBC,IAAgC,EACF;EAC9B,IAAIA,IAAI,IAAI,IAAI,IAAIA,IAAI,KAAK,KAAK,EAAE;IAClC,OAAOA,IAAI;EACb;EAEA,OAAO,IAAIC,GAAG,CAAC,CAAC,GAAGD,IAAI,CAAC,CAACE,GAAG,CAACC,MAAM,CAAC,CAAC;AACvC;AA2BA;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,GAAGd,OAAO,CAChC,MAAME,cAAc,CAACU,YAAY,CAAC,EAClC,CAACA,YAAY,CACf,CAAC;EAED,IAAMG,yBAAyB,GAAGf,OAAO,CACvC,MAAME,cAAc,CAACQ,mBAAmB,CAAC,EACzC,CAACA,mBAAmB,CACtB,CAAC;EAED,IAAMM,kBAAkB,GAAGhB,OAAO,CAChC,MAAME,cAAc,CAACS,YAAY,CAAC,EAClC,CAACA,YAAY,CACf,CAAC;EAED,IAAMM,uBAAuB,GAAGlB,WAAW,CACxCI,IAAsB,IAAK;IAC1B,IAAIA,IAAI,KAAK,KAAK,EAAE;MAClBU,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAG,KAAK,CAAC;MACjB;IACF;IAEA,IAAMK,UAAU,GAAG,IAAId,GAAG,CAAU,CAAC;IAErCK,eAAe,CAACU,OAAO,CAACC,IAAI,IAAI;MAC9B,IAAIjB,IAAI,CAACkB,GAAG,CAACf,MAAM,CAACL,UAAU,CAACmB,IAAI,CAAC,CAAC,CAAC,EAAE;QACtCF,UAAU,CAACI,GAAG,CAACrB,UAAU,CAACmB,IAAI,CAAC,CAAC;MAClC;IACF,CAAC,CAAC;IAEFP,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAGK,UAAU,CAAC;EACxB,CAAC,EACD,CAACT,eAAe,EAAEI,QAAQ,CAC5B,CAAC;EAED,OAAO;IACLC,kBAAkB;IAClBC,yBAAyB;IACzBC,kBAAkB;IAClBC;EACF,CAAC;AACH;AAEA,eAAeV,4BAA4B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { Provider } from '@adobe/react-spectrum';
|
|
3
3
|
import shortid from 'shortid';
|
|
4
|
-
import { themeDHDefault } from "../spectrum/utils.js";
|
|
4
|
+
import { themeDHDefault } from "../spectrum/utils/index.js";
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
/**
|
|
7
7
|
* Wrapper around React Spectrum's theme Provider that provides DH mappings of
|