@deephaven/components 0.74.1-beta.5 → 0.75.0

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.
Files changed (62) hide show
  1. package/dist/Button.d.ts +1 -1
  2. package/dist/ErrorView.css +77 -0
  3. package/dist/ErrorView.css.map +1 -0
  4. package/dist/ErrorView.d.ts +16 -0
  5. package/dist/ErrorView.d.ts.map +1 -0
  6. package/dist/ErrorView.js +73 -0
  7. package/dist/ErrorView.js.map +1 -0
  8. package/dist/Select.d.ts +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +1 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/spectrum/listView/ListView.d.ts +3 -2
  14. package/dist/spectrum/listView/ListView.d.ts.map +1 -1
  15. package/dist/spectrum/listView/ListView.js +10 -63
  16. package/dist/spectrum/listView/ListView.js.map +1 -1
  17. package/dist/spectrum/listView/ListViewNormalized.d.ts +22 -0
  18. package/dist/spectrum/listView/ListViewNormalized.d.ts.map +1 -0
  19. package/dist/spectrum/listView/ListViewNormalized.js +80 -0
  20. package/dist/spectrum/listView/ListViewNormalized.js.map +1 -0
  21. package/dist/spectrum/listView/ListViewWrapper.css +39 -0
  22. package/dist/spectrum/listView/ListViewWrapper.css.map +1 -0
  23. package/dist/spectrum/listView/ListViewWrapper.d.ts +21 -0
  24. package/dist/spectrum/listView/ListViewWrapper.d.ts.map +1 -0
  25. package/dist/spectrum/listView/ListViewWrapper.js +71 -0
  26. package/dist/spectrum/listView/ListViewWrapper.js.map +1 -0
  27. package/dist/spectrum/listView/index.d.ts +2 -0
  28. package/dist/spectrum/listView/index.d.ts.map +1 -1
  29. package/dist/spectrum/listView/index.js +2 -0
  30. package/dist/spectrum/listView/index.js.map +1 -1
  31. package/dist/spectrum/picker/Picker.d.ts.map +1 -1
  32. package/dist/spectrum/picker/Picker.js +2 -2
  33. package/dist/spectrum/picker/Picker.js.map +1 -1
  34. package/dist/spectrum/picker/PickerNormalized.d.ts +2 -1
  35. package/dist/spectrum/picker/PickerNormalized.d.ts.map +1 -1
  36. package/dist/spectrum/picker/PickerNormalized.js +31 -15
  37. package/dist/spectrum/picker/PickerNormalized.js.map +1 -1
  38. package/dist/spectrum/shared.d.ts +13 -9
  39. package/dist/spectrum/shared.d.ts.map +1 -1
  40. package/dist/spectrum/shared.js +16 -1
  41. package/dist/spectrum/shared.js.map +1 -1
  42. package/dist/spectrum/utils/index.d.ts +1 -0
  43. package/dist/spectrum/utils/index.d.ts.map +1 -1
  44. package/dist/spectrum/utils/index.js +1 -0
  45. package/dist/spectrum/utils/index.js.map +1 -1
  46. package/dist/spectrum/utils/itemUtils.d.ts +9 -14
  47. package/dist/spectrum/utils/itemUtils.d.ts.map +1 -1
  48. package/dist/spectrum/utils/itemUtils.js +8 -108
  49. package/dist/spectrum/utils/itemUtils.js.map +1 -1
  50. package/dist/spectrum/utils/itemWrapperUtils.d.ts +19 -3
  51. package/dist/spectrum/utils/itemWrapperUtils.d.ts.map +1 -1
  52. package/dist/spectrum/utils/itemWrapperUtils.js +65 -19
  53. package/dist/spectrum/utils/itemWrapperUtils.js.map +1 -1
  54. package/dist/spectrum/utils/propsUtils.d.ts +14 -0
  55. package/dist/spectrum/utils/propsUtils.d.ts.map +1 -0
  56. package/dist/spectrum/utils/propsUtils.js +93 -0
  57. package/dist/spectrum/utils/propsUtils.js.map +1 -0
  58. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts +11 -2
  59. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts.map +1 -1
  60. package/dist/spectrum/utils/useRenderNormalizedItem.js +21 -8
  61. package/dist/spectrum/utils/useRenderNormalizedItem.js.map +1 -1
  62. package/package.json +7 -7
@@ -1,4 +1,4 @@
1
- var _excluded = ["normalizedItems", "tooltip", "selectedKey", "defaultSelectedKey", "disabledKeys", "UNSAFE_className", "getInitialScrollPosition", "onChange", "onOpenChange", "onScroll", "onSelectionChange"];
1
+ var _excluded = ["normalizedItems", "tooltip", "selectedKey", "defaultSelectedKey", "disabledKeys", "showItemIcons", "UNSAFE_className", "getInitialScrollPosition", "onChange", "onOpenChange", "onScroll", "onSelectionChange"];
2
2
  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; }
3
3
  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; }
4
4
  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; }
@@ -14,6 +14,7 @@ import { Section } from "../shared.js";
14
14
  import { getItemKey, isNormalizedSection, normalizeTooltipOptions, useRenderNormalizedItem, useStringifiedSelection } from "../utils/index.js";
15
15
  import usePickerScrollOnOpen from "./usePickerScrollOnOpen.js";
16
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
+ import { createElement as _createElement } from "react";
17
18
  /**
18
19
  * Picker that takes an array of `NormalizedItem` or `NormalizedSection` items
19
20
  * as children and uses a render item function to render the items. This is
@@ -26,6 +27,7 @@ export function PickerNormalized(_ref) {
26
27
  selectedKey,
27
28
  defaultSelectedKey,
28
29
  disabledKeys,
30
+ showItemIcons,
29
31
  UNSAFE_className,
30
32
  getInitialScrollPosition,
31
33
  onChange,
@@ -35,7 +37,21 @@ export function PickerNormalized(_ref) {
35
37
  } = _ref,
36
38
  props = _objectWithoutProperties(_ref, _excluded);
37
39
  var tooltipOptions = useMemo(() => normalizeTooltipOptions(tooltip), [tooltip]);
38
- var renderNormalizedItem = useRenderNormalizedItem(tooltipOptions);
40
+ var renderNormalizedItem = useRenderNormalizedItem({
41
+ itemIconSlot: 'icon',
42
+ // Descriptions introduce variable item heights which throws off calculation
43
+ // of initial scroll position and setting viewport on windowed data. For now
44
+ // not going to implement description support in Picker.
45
+ // https://github.com/deephaven/web-client-ui/issues/1958
46
+ showItemDescriptions: false,
47
+ showItemIcons,
48
+ tooltipOptions
49
+ });
50
+
51
+ // Spectrum doesn't re-render if only the `renderNormalizedItems` function
52
+ // changes, so we create a key from its dependencies that can be used to force
53
+ // re-render.
54
+ var forceRerenderKey = "".concat(showItemIcons, "-").concat(tooltipOptions === null || tooltipOptions === void 0 ? void 0 : tooltipOptions.placement);
39
55
  var {
40
56
  ref: scrollRef,
41
57
  onOpenChange: onOpenChangeInternal
@@ -60,9 +76,10 @@ export function PickerNormalized(_ref) {
60
76
  disabledKeys,
61
77
  onChange: onChange !== null && onChange !== void 0 ? onChange : onSelectionChange
62
78
  });
63
- return /*#__PURE__*/_jsx(SpectrumPicker
79
+ return /*#__PURE__*/_createElement(SpectrumPicker
64
80
  // eslint-disable-next-line react/jsx-props-no-spreading
65
81
  , _objectSpread(_objectSpread({}, props), {}, {
82
+ key: forceRerenderKey,
66
83
  ref: scrollRef,
67
84
  UNSAFE_className: cl('dh-picker', 'dh-picker-normalized', UNSAFE_className),
68
85
  items: normalizedItems,
@@ -70,19 +87,18 @@ export function PickerNormalized(_ref) {
70
87
  defaultSelectedKey: defaultSelectedStringKey,
71
88
  disabledKeys: disabledStringKeys,
72
89
  onSelectionChange: onStringSelectionChange,
73
- onOpenChange: onOpenChangeInternal,
74
- children: itemOrSection => {
75
- if (isNormalizedSection(itemOrSection)) {
76
- var _itemOrSection$item, _itemOrSection$item2;
77
- return /*#__PURE__*/_jsx(Section, {
78
- title: (_itemOrSection$item = itemOrSection.item) === null || _itemOrSection$item === void 0 ? void 0 : _itemOrSection$item.title,
79
- items: (_itemOrSection$item2 = itemOrSection.item) === null || _itemOrSection$item2 === void 0 ? void 0 : _itemOrSection$item2.items,
80
- children: renderNormalizedItem
81
- }, getItemKey(itemOrSection));
82
- }
83
- return renderNormalizedItem(itemOrSection);
90
+ onOpenChange: onOpenChangeInternal
91
+ }), itemOrSection => {
92
+ if (isNormalizedSection(itemOrSection)) {
93
+ var _itemOrSection$item, _itemOrSection$item2;
94
+ return /*#__PURE__*/_jsx(Section, {
95
+ title: (_itemOrSection$item = itemOrSection.item) === null || _itemOrSection$item === void 0 ? void 0 : _itemOrSection$item.title,
96
+ items: (_itemOrSection$item2 = itemOrSection.item) === null || _itemOrSection$item2 === void 0 ? void 0 : _itemOrSection$item2.items,
97
+ children: renderNormalizedItem
98
+ }, getItemKey(itemOrSection));
84
99
  }
85
- }));
100
+ return renderNormalizedItem(itemOrSection);
101
+ });
86
102
  }
87
103
  export default PickerNormalized;
88
104
  //# sourceMappingURL=PickerNormalized.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PickerNormalized.js","names":["useMemo","Picker","SpectrumPicker","cl","EMPTY_FUNCTION","Section","getItemKey","isNormalizedSection","normalizeTooltipOptions","useRenderNormalizedItem","useStringifiedSelection","usePickerScrollOnOpen","jsx","_jsx","PickerNormalized","_ref","normalizedItems","tooltip","selectedKey","defaultSelectedKey","disabledKeys","UNSAFE_className","getInitialScrollPosition","onChange","onOpenChange","onScroll","onSelectionChange","props","_objectWithoutProperties","_excluded","tooltipOptions","renderNormalizedItem","ref","scrollRef","onOpenChangeInternal","selectedStringKey","defaultSelectedStringKey","disabledStringKeys","onStringSelectionChange","_objectSpread","items","children","itemOrSection","_itemOrSection$item","_itemOrSection$item2","title","item"],"sources":["../../../src/spectrum/picker/PickerNormalized.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { Picker as SpectrumPicker } from '@adobe/react-spectrum';\nimport type { DOMRef } from '@react-types/shared';\nimport cl from 'classnames';\nimport { EMPTY_FUNCTION } from '@deephaven/utils';\nimport { Section } from '../shared';\nimport type { PickerProps as PickerBaseProps } from './Picker';\n\nimport {\n getItemKey,\n isNormalizedSection,\n NormalizedItem,\n NormalizedSection,\n normalizeTooltipOptions,\n useRenderNormalizedItem,\n useStringifiedSelection,\n} from '../utils';\nimport usePickerScrollOnOpen from './usePickerScrollOnOpen';\n\nexport interface PickerNormalizedProps\n extends Omit<PickerBaseProps, 'children'> {\n normalizedItems: (NormalizedItem | NormalizedSection)[];\n getInitialScrollPosition?: () => Promise<number | null | undefined>;\n onScroll?: (event: Event) => void;\n}\n\n/**\n * Picker that takes an array of `NormalizedItem` or `NormalizedSection` items\n * as children and uses a render item function to render the items. This is\n * necessary to support windowed data.\n */\nexport function PickerNormalized({\n normalizedItems,\n tooltip = true,\n selectedKey,\n defaultSelectedKey,\n disabledKeys,\n UNSAFE_className,\n getInitialScrollPosition,\n onChange,\n onOpenChange,\n onScroll = EMPTY_FUNCTION,\n onSelectionChange,\n ...props\n}: PickerNormalizedProps): JSX.Element {\n const tooltipOptions = useMemo(\n () => normalizeTooltipOptions(tooltip),\n [tooltip]\n );\n\n const renderNormalizedItem = useRenderNormalizedItem(tooltipOptions);\n\n const { ref: scrollRef, onOpenChange: onOpenChangeInternal } =\n usePickerScrollOnOpen({\n getInitialScrollPosition,\n onScroll,\n onOpenChange,\n });\n\n // Spectrum Picker treats keys as strings if the `key` prop is explicitly\n // set on `Item` elements. Since we do this in `renderItem`, we need to\n // map original key types to and from strings so that selection works.\n const {\n selectedStringKey,\n defaultSelectedStringKey,\n disabledStringKeys,\n onStringSelectionChange,\n } = useStringifiedSelection({\n normalizedItems,\n selectedKey,\n defaultSelectedKey,\n disabledKeys,\n onChange: onChange ?? onSelectionChange,\n });\n\n return (\n <SpectrumPicker\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...props}\n ref={scrollRef as DOMRef<HTMLDivElement>}\n UNSAFE_className={cl(\n 'dh-picker',\n 'dh-picker-normalized',\n UNSAFE_className\n )}\n items={normalizedItems}\n selectedKey={selectedStringKey}\n defaultSelectedKey={defaultSelectedStringKey}\n disabledKeys={disabledStringKeys}\n onSelectionChange={onStringSelectionChange}\n onOpenChange={onOpenChangeInternal}\n >\n {itemOrSection => {\n if (isNormalizedSection(itemOrSection)) {\n return (\n <Section\n key={getItemKey(itemOrSection)}\n title={itemOrSection.item?.title}\n items={itemOrSection.item?.items}\n >\n {renderNormalizedItem}\n </Section>\n );\n }\n\n return renderNormalizedItem(itemOrSection);\n }}\n </SpectrumPicker>\n );\n}\n\nexport default PickerNormalized;\n"],"mappings":";;;;;;;;AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,MAAM,IAAIC,cAAc,QAAQ,uBAAuB;AAEhE,OAAOC,EAAE,MAAM,YAAY;AAC3B,SAASC,cAAc,QAAQ,kBAAkB;AAAC,SACzCC,OAAO;AAAA,SAIdC,UAAU,EACVC,mBAAmB,EAGnBC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB;AAAA,OAElBC,qBAAqB;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAS5B;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAAC,IAAA,EAaO;EAAA,IAbN;MAC/BC,eAAe;MACfC,OAAO,GAAG,IAAI;MACdC,WAAW;MACXC,kBAAkB;MAClBC,YAAY;MACZC,gBAAgB;MAChBC,wBAAwB;MACxBC,QAAQ;MACRC,YAAY;MACZC,QAAQ,GAAGrB,cAAc;MACzBsB;IAEqB,CAAC,GAAAX,IAAA;IADnBY,KAAK,GAAAC,wBAAA,CAAAb,IAAA,EAAAc,SAAA;EAER,IAAMC,cAAc,GAAG9B,OAAO,CAC5B,MAAMQ,uBAAuB,CAACS,OAAO,CAAC,EACtC,CAACA,OAAO,CACV,CAAC;EAED,IAAMc,oBAAoB,GAAGtB,uBAAuB,CAACqB,cAAc,CAAC;EAEpE,IAAM;IAAEE,GAAG,EAAEC,SAAS;IAAET,YAAY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
+ {"version":3,"file":"PickerNormalized.js","names":["useMemo","Picker","SpectrumPicker","cl","EMPTY_FUNCTION","Section","getItemKey","isNormalizedSection","normalizeTooltipOptions","useRenderNormalizedItem","useStringifiedSelection","usePickerScrollOnOpen","jsx","_jsx","createElement","_createElement","PickerNormalized","_ref","normalizedItems","tooltip","selectedKey","defaultSelectedKey","disabledKeys","showItemIcons","UNSAFE_className","getInitialScrollPosition","onChange","onOpenChange","onScroll","onSelectionChange","props","_objectWithoutProperties","_excluded","tooltipOptions","renderNormalizedItem","itemIconSlot","showItemDescriptions","forceRerenderKey","concat","placement","ref","scrollRef","onOpenChangeInternal","selectedStringKey","defaultSelectedStringKey","disabledStringKeys","onStringSelectionChange","_objectSpread","key","items","itemOrSection","_itemOrSection$item","_itemOrSection$item2","title","item","children"],"sources":["../../../src/spectrum/picker/PickerNormalized.tsx"],"sourcesContent":["import { useMemo } from 'react';\nimport { Picker as SpectrumPicker } from '@adobe/react-spectrum';\nimport type { DOMRef } from '@react-types/shared';\nimport cl from 'classnames';\nimport { EMPTY_FUNCTION } from '@deephaven/utils';\nimport { Section } from '../shared';\nimport type { PickerProps as PickerBaseProps } from './Picker';\n\nimport {\n getItemKey,\n isNormalizedSection,\n NormalizedItem,\n NormalizedSection,\n normalizeTooltipOptions,\n useRenderNormalizedItem,\n useStringifiedSelection,\n} from '../utils';\nimport usePickerScrollOnOpen from './usePickerScrollOnOpen';\n\nexport interface PickerNormalizedProps\n extends Omit<PickerBaseProps, 'children'> {\n normalizedItems: (NormalizedItem | NormalizedSection)[];\n showItemIcons: boolean;\n getInitialScrollPosition?: () => Promise<number | null | undefined>;\n onScroll?: (event: Event) => void;\n}\n\n/**\n * Picker that takes an array of `NormalizedItem` or `NormalizedSection` items\n * as children and uses a render item function to render the items. This is\n * necessary to support windowed data.\n */\nexport function PickerNormalized({\n normalizedItems,\n tooltip = true,\n selectedKey,\n defaultSelectedKey,\n disabledKeys,\n showItemIcons,\n UNSAFE_className,\n getInitialScrollPosition,\n onChange,\n onOpenChange,\n onScroll = EMPTY_FUNCTION,\n onSelectionChange,\n ...props\n}: PickerNormalizedProps): JSX.Element {\n const tooltipOptions = useMemo(\n () => normalizeTooltipOptions(tooltip),\n [tooltip]\n );\n\n const renderNormalizedItem = useRenderNormalizedItem({\n itemIconSlot: 'icon',\n // Descriptions introduce variable item heights which throws off calculation\n // of initial scroll position and setting viewport on windowed data. For now\n // not going to implement description support in Picker.\n // https://github.com/deephaven/web-client-ui/issues/1958\n showItemDescriptions: false,\n showItemIcons,\n tooltipOptions,\n });\n\n // Spectrum doesn't re-render if only the `renderNormalizedItems` function\n // changes, so we create a key from its dependencies that can be used to force\n // re-render.\n const forceRerenderKey = `${showItemIcons}-${tooltipOptions?.placement}`;\n\n const { ref: scrollRef, onOpenChange: onOpenChangeInternal } =\n usePickerScrollOnOpen({\n getInitialScrollPosition,\n onScroll,\n onOpenChange,\n });\n\n // Spectrum Picker treats keys as strings if the `key` prop is explicitly\n // set on `Item` elements. Since we do this in `renderItem`, we need to\n // map original key types to and from strings so that selection works.\n const {\n selectedStringKey,\n defaultSelectedStringKey,\n disabledStringKeys,\n onStringSelectionChange,\n } = useStringifiedSelection({\n normalizedItems,\n selectedKey,\n defaultSelectedKey,\n disabledKeys,\n onChange: onChange ?? onSelectionChange,\n });\n\n return (\n <SpectrumPicker\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...props}\n key={forceRerenderKey}\n ref={scrollRef as DOMRef<HTMLDivElement>}\n UNSAFE_className={cl(\n 'dh-picker',\n 'dh-picker-normalized',\n UNSAFE_className\n )}\n items={normalizedItems}\n selectedKey={selectedStringKey}\n defaultSelectedKey={defaultSelectedStringKey}\n disabledKeys={disabledStringKeys}\n onSelectionChange={onStringSelectionChange}\n onOpenChange={onOpenChangeInternal}\n >\n {itemOrSection => {\n if (isNormalizedSection(itemOrSection)) {\n return (\n <Section\n key={getItemKey(itemOrSection)}\n title={itemOrSection.item?.title}\n items={itemOrSection.item?.items}\n >\n {renderNormalizedItem}\n </Section>\n );\n }\n\n return renderNormalizedItem(itemOrSection);\n }}\n </SpectrumPicker>\n );\n}\n\nexport default PickerNormalized;\n"],"mappings":";;;;;;;;AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,MAAM,IAAIC,cAAc,QAAQ,uBAAuB;AAEhE,OAAOC,EAAE,MAAM,YAAY;AAC3B,SAASC,cAAc,QAAQ,kBAAkB;AAAC,SACzCC,OAAO;AAAA,SAIdC,UAAU,EACVC,mBAAmB,EAGnBC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB;AAAA,OAElBC,qBAAqB;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,aAAA,IAAAC,cAAA;AAU5B;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAAC,IAAA,EAcO;EAAA,IAdN;MAC/BC,eAAe;MACfC,OAAO,GAAG,IAAI;MACdC,WAAW;MACXC,kBAAkB;MAClBC,YAAY;MACZC,aAAa;MACbC,gBAAgB;MAChBC,wBAAwB;MACxBC,QAAQ;MACRC,YAAY;MACZC,QAAQ,GAAGxB,cAAc;MACzByB;IAEqB,CAAC,GAAAZ,IAAA;IADnBa,KAAK,GAAAC,wBAAA,CAAAd,IAAA,EAAAe,SAAA;EAER,IAAMC,cAAc,GAAGjC,OAAO,CAC5B,MAAMQ,uBAAuB,CAACW,OAAO,CAAC,EACtC,CAACA,OAAO,CACV,CAAC;EAED,IAAMe,oBAAoB,GAAGzB,uBAAuB,CAAC;IACnD0B,YAAY,EAAE,MAAM;IACpB;IACA;IACA;IACA;IACAC,oBAAoB,EAAE,KAAK;IAC3Bb,aAAa;IACbU;EACF,CAAC,CAAC;;EAEF;EACA;EACA;EACA,IAAMI,gBAAgB,MAAAC,MAAA,CAAMf,aAAa,OAAAe,MAAA,CAAIL,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAEM,SAAS,CAAE;EAExE,IAAM;IAAEC,GAAG,EAAEC,SAAS;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C;AAErB;AAEA,eAAelC,gBAAgB"}
@@ -1,12 +1,16 @@
1
+ /// <reference types="react" />
2
+ import type { ItemElement, ItemRenderer, SectionProps as SpectrumSectionProps } from '@react-types/shared';
3
+ export { Item } from '@adobe/react-spectrum';
4
+ export type { ItemProps } from '@react-types/shared';
5
+ export type ItemElementOrPrimitive<T = unknown> = number | string | boolean | ItemElement<T>;
1
6
  /**
2
- * Wrapping Spectrum `Item` and `Section` components will break functionality
3
- * due to the way they are consumed by collection components. They are only used
4
- * to pass data and don't render anything on their own, so they don't need to be
5
- * wrapped. If we do ever need to wrap them for whatever reason, the static
6
- * `getCollectionNode` method will need to be implemented.
7
- * See https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Item.ts#L17
8
- * https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Section.ts#L18
7
+ * Spectrum SectionProps augmented with support for primitive item children.
9
8
  */
10
- export { Item, Section } from '@adobe/react-spectrum';
11
- export type { ItemProps, SectionProps } from '@react-types/shared';
9
+ export type SectionProps<T> = Omit<SpectrumSectionProps<T>, 'children'> & {
10
+ children: ItemElementOrPrimitive<T> | ItemElementOrPrimitive<T>[] | ItemRenderer<T>;
11
+ };
12
+ /**
13
+ * Re-export Spectrum Section component with augmented props type.
14
+ */
15
+ export declare const Section: <T>(props: SectionProps<T>) => JSX.Element;
12
16
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/spectrum/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/spectrum/shared.ts"],"names":[],"mappings":";AAUA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,YAAY,IAAI,oBAAoB,EACrC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAMrD,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAC1C,MAAM,GACN,MAAM,GACN,OAAO,GACP,WAAW,CAAC,CAAC,CAAC,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;IACxE,QAAQ,EACJ,sBAAsB,CAAC,CAAC,CAAC,GACzB,sBAAsB,CAAC,CAAC,CAAC,EAAE,GAC3B,YAAY,CAAC,CAAC,CAAC,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,iCAEf,WAAW,CAAC"}
@@ -7,5 +7,20 @@
7
7
  * See https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Item.ts#L17
8
8
  * https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Section.ts#L18
9
9
  */
10
- export { Item, Section } from '@adobe/react-spectrum';
10
+ import { Section as SpectrumSection } from '@adobe/react-spectrum';
11
+ export { Item } from '@adobe/react-spectrum';
12
+
13
+ /*
14
+ * We support primitive values as shorthand for `Item` elements in certain
15
+ * components. This type represents this augmentation of the Spectrum types.
16
+ */
17
+
18
+ /**
19
+ * Spectrum SectionProps augmented with support for primitive item children.
20
+ */
21
+
22
+ /**
23
+ * Re-export Spectrum Section component with augmented props type.
24
+ */
25
+ export var Section = SpectrumSection;
11
26
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","names":["Item","Section"],"sources":["../../src/spectrum/shared.ts"],"sourcesContent":["/**\n * Wrapping Spectrum `Item` and `Section` components will break functionality\n * due to the way they are consumed by collection components. They are only used\n * to pass data and don't render anything on their own, so they don't need to be\n * wrapped. If we do ever need to wrap them for whatever reason, the static\n * `getCollectionNode` method will need to be implemented.\n * See https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Item.ts#L17\n * https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Section.ts#L18\n */\nexport { Item, Section } from '@adobe/react-spectrum';\nexport type { ItemProps, SectionProps } from '@react-types/shared';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,IAAI,EAAEC,OAAO,QAAQ,uBAAuB"}
1
+ {"version":3,"file":"shared.js","names":["Section","SpectrumSection","Item"],"sources":["../../src/spectrum/shared.ts"],"sourcesContent":["/**\n * Wrapping Spectrum `Item` and `Section` components will break functionality\n * due to the way they are consumed by collection components. They are only used\n * to pass data and don't render anything on their own, so they don't need to be\n * wrapped. If we do ever need to wrap them for whatever reason, the static\n * `getCollectionNode` method will need to be implemented.\n * See https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Item.ts#L17\n * https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/collections/src/Section.ts#L18\n */\nimport { Section as SpectrumSection } from '@adobe/react-spectrum';\nimport type {\n ItemElement,\n ItemRenderer,\n SectionProps as SpectrumSectionProps,\n} from '@react-types/shared';\n\nexport { Item } from '@adobe/react-spectrum';\nexport type { ItemProps } from '@react-types/shared';\n\n/*\n * We support primitive values as shorthand for `Item` elements in certain\n * components. This type represents this augmentation of the Spectrum types.\n */\nexport type ItemElementOrPrimitive<T = unknown> =\n | number\n | string\n | boolean\n | ItemElement<T>;\n\n/**\n * Spectrum SectionProps augmented with support for primitive item children.\n */\nexport type SectionProps<T> = Omit<SpectrumSectionProps<T>, 'children'> & {\n children:\n | ItemElementOrPrimitive<T>\n | ItemElementOrPrimitive<T>[]\n | ItemRenderer<T>;\n};\n\n/**\n * Re-export Spectrum Section component with augmented props type.\n */\nexport const Section = SpectrumSection as <T>(\n props: SectionProps<T>\n) => JSX.Element;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,eAAe,QAAQ,uBAAuB;AAOlE,SAASC,IAAI,QAAQ,uBAAuB;;AAG5C;AACA;AACA;AACA;;AAOA;AACA;AACA;;AAQA;AACA;AACA;AACA,OAAO,IAAMF,OAAO,GAAGC,eAEP"}
@@ -1,5 +1,6 @@
1
1
  export * from './itemUtils';
2
2
  export * from './itemWrapperUtils';
3
+ export * from './propsUtils';
3
4
  export * from './themeUtils';
4
5
  export * from './useRenderNormalizedItem';
5
6
  export * from './useStringifiedMultiSelection';
@@ -1 +1 @@
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
+ {"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,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from "./itemUtils.js";
2
2
  export * from "./itemWrapperUtils.js";
3
+ export * from "./propsUtils.js";
3
4
  export * from "./themeUtils.js";
4
5
  export * from "./useRenderNormalizedItem.js";
5
6
  export * from "./useStringifiedMultiSelection.js";
@@ -1 +1 @@
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":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/utils/index.ts"],"sourcesContent":["export * from './itemUtils';\nexport * from './itemWrapperUtils';\nexport * from './propsUtils';\nexport * from './themeUtils';\nexport * from './useRenderNormalizedItem';\nexport * from './useStringifiedMultiSelection';\nexport * from './useStringifiedSelection';\n"],"mappings":""}
@@ -2,14 +2,13 @@ import { Key, ReactElement, ReactNode } from 'react';
2
2
  import { SpectrumPickerProps } from '@adobe/react-spectrum';
3
3
  import type { ItemRenderer } from '@react-types/shared';
4
4
  import { KeyedItem, SelectionT } from '@deephaven/utils';
5
- import { ItemProps, SectionProps } from '../shared';
5
+ import { ItemElementOrPrimitive, ItemProps, SectionProps } from '../shared';
6
6
  import { PopperOptions } from '../../popper';
7
7
  /**
8
8
  * `Item.textValue` prop needs to be a non-empty string for accessibility
9
9
  * purposes. This is not displayed in the UI.
10
10
  */
11
11
  export declare const ITEM_EMPTY_STRING_TEXT_VALUE = "Empty";
12
- export declare const INVALID_ITEM_ERROR_MESSAGE = "Items must be strings, numbers, booleans, <Item> or <Section> elements:";
13
12
  /**
14
13
  * React Spectrum <Section> supports an `ItemRenderer` function as a child. The
15
14
  * DH picker makes use of this internally, but we don't want to support it as
@@ -18,10 +17,10 @@ export declare const INVALID_ITEM_ERROR_MESSAGE = "Items must be strings, number
18
17
  type SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {
19
18
  children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;
20
19
  };
21
- export type ItemElement = ReactElement<ItemProps<unknown>>;
22
- export type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;
23
- export type ItemElementOrPrimitive = number | string | boolean | ItemElement;
24
- export type ItemOrSection = ItemElementOrPrimitive | SectionElement;
20
+ export type ItemElement<T = unknown> = ReactElement<ItemProps<T>>;
21
+ export type SectionElement<T = unknown> = ReactElement<SectionPropsNoItemRenderer<T>>;
22
+ export type ItemOrSection<T = unknown> = ItemElementOrPrimitive<T> | SectionElement<T>;
23
+ export type ItemIconSlot = 'icon' | 'image' | 'illustration';
25
24
  /**
26
25
  * Augment the Spectrum selection key type to include boolean values.
27
26
  * Spectrum collection components already supports this, but the built in types
@@ -38,6 +37,8 @@ export type ItemSelectionChangeHandler = (key: ItemKey) => void;
38
37
  export interface NormalizedItemData {
39
38
  key?: ItemKey;
40
39
  content: ReactNode;
40
+ description?: ReactNode;
41
+ icon?: ReactNode;
41
42
  textValue: string | undefined;
42
43
  }
43
44
  export interface NormalizedSectionData {
@@ -89,13 +90,13 @@ export declare function getPositionOfSelectedItemElement<TKey extends string | n
89
90
  * @param node The node to check
90
91
  * @returns True if the node is a Section element
91
92
  */
92
- export declare function isSectionElement<T>(node: ReactNode): node is ReactElement<SectionProps<T>>;
93
+ export declare function isSectionElement<T>(node: ReactNode): node is SectionElement<T>;
93
94
  /**
94
95
  * Determine if a node is an Item element.
95
96
  * @param node The node to check
96
97
  * @returns True if the node is an Item element
97
98
  */
98
- export declare function isItemElement<T>(node: ReactNode): node is ReactElement<ItemProps<T>>;
99
+ export declare function isItemElement<T>(node: ReactNode): node is ItemElement<T>;
99
100
  /**
100
101
  * Determine if a node is an Item element containing a child `Text` element with
101
102
  * a `slot` prop set to `description`.
@@ -123,12 +124,6 @@ export declare function isNormalizedSection(maybeNormalizedSection: NormalizedIt
123
124
  * @returns True if the node is an item or section
124
125
  */
125
126
  export declare function isItemOrSection(node: ReactNode): node is ItemOrSection;
126
- /**
127
- * Normalize an item or section or a list of items or sections.
128
- * @param itemsOrSections An item or section or array of items or sections
129
- * @returns An array of normalized items or sections
130
- */
131
- export declare function normalizeItemList<TItemOrSection extends ItemOrSection>(itemsOrSections: TItemOrSection | TItemOrSection[] | NormalizedItem[]): NormalizedItemOrSection<TItemOrSection>[];
132
127
  /**
133
128
  * Returns a TooltipOptions object or null if options is false or null.
134
129
  * @param options Tooltip options
@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ChB,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;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;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,SAAS,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,EACnD,OAAO,SAAS,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,18 +1,15 @@
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
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); }); }; }
3
- import Log from '@deephaven/log';
4
3
  import { isElementOfType } from '@deephaven/react-hooks';
4
+ import { ensureArray } from '@deephaven/utils';
5
5
  import { Item, Section } from "../shared.js";
6
6
  import { Text } from "../Text.js";
7
7
  import ItemContent from "../ItemContent.js";
8
- var log = Log.module('itemUtils');
9
-
10
8
  /**
11
9
  * `Item.textValue` prop needs to be a non-empty string for accessibility
12
10
  * purposes. This is not displayed in the UI.
13
11
  */
14
12
  export var ITEM_EMPTY_STRING_TEXT_VALUE = 'Empty';
15
- export var INVALID_ITEM_ERROR_MESSAGE = 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';
16
13
 
17
14
  /**
18
15
  * React Spectrum <Section> supports an `ItemRenderer` function as a child. The
@@ -20,18 +17,19 @@ export var INVALID_ITEM_ERROR_MESSAGE = 'Items must be strings, numbers, boolean
20
17
  * an incoming prop.
21
18
  */
22
19
 
20
+ // Picker uses `icon` slot. ListView can use `image` or `illustration` slots.
21
+ // https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/picker/src/Picker.tsx#L194
22
+ // https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/list/src/ListViewItem.tsx#L266-L267
23
23
  /**
24
24
  * Augment the Spectrum selection key type to include boolean values.
25
25
  * Spectrum collection components already supports this, but the built in types
26
26
  * don't reflect it.
27
27
  */
28
-
29
28
  /**
30
29
  * Augment the Spectrum selection change handler type to include boolean keys.
31
30
  * Spectrum components already supports this, but the built in types don't
32
31
  * reflect it.
33
32
  */
34
-
35
33
  /**
36
34
  * Spectrum collection components support a variety of item types, including
37
35
  * strings, numbers, booleans, and more complex React elements. This type
@@ -40,7 +38,6 @@ export var INVALID_ITEM_ERROR_MESSAGE = 'Items must be strings, numbers, boolean
40
38
  * `KeyedItem` interface to be compatible with Windowed data utils
41
39
  * (e.g. `useViewportData`).
42
40
  */
43
-
44
41
  /**
45
42
  * DH wrappers of Spectrum collection components use a normalized item that
46
43
  * includes a `key` prop and an optional `item` prop. This is mostly to support
@@ -85,8 +82,8 @@ function _getPositionOfSelectedItemElement() {
85
82
  return position;
86
83
  }
87
84
  for (var i = 0; i < items.length; i += 1) {
88
- var _item = items[i];
89
- if (_item.key === selectedKey) {
85
+ var item = items[i];
86
+ if (item.key === selectedKey) {
90
87
  return position;
91
88
  }
92
89
  position += itemHeight;
@@ -121,10 +118,10 @@ export function isItemElementWithDescription(node) {
121
118
 
122
119
  // If children are wrapped in `ItemContent`, go down 1 level
123
120
  var children = isElementOfType(node.props.children, ItemContent) ? node.props.children.props.children : node.props.children;
124
- var childrenArray = Array.isArray(children) ? children : [children];
121
+ var childrenArray = ensureArray(children);
125
122
  var result = childrenArray.some(child => {
126
123
  var _child$props;
127
- return ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.slot) === 'description' && isElementOfType(child, Text);
124
+ return isElementOfType(child, Text) && ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.slot) === 'description';
128
125
  });
129
126
  return result;
130
127
  }
@@ -164,103 +161,6 @@ export function isItemOrSection(node) {
164
161
  return typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean' || isItemElement(node) || isSectionElement(node);
165
162
  }
166
163
 
167
- /**
168
- * Determine the `key` of an item or section.
169
- * @param itemOrSection The item or section
170
- * @returns A `ItemKey` for the item or undefined if a key can't be determined
171
- */
172
-
173
- function normalizeItemKey(itemOrSection) {
174
- var _itemOrSection$props$;
175
- // string, number, or boolean
176
- if (typeof itemOrSection !== 'object') {
177
- return itemOrSection;
178
- }
179
-
180
- // If `key` prop is explicitly set
181
- if (itemOrSection.key != null) {
182
- return itemOrSection.key;
183
- }
184
-
185
- // Section element
186
- if (isSectionElement(itemOrSection)) {
187
- return typeof itemOrSection.props.title === 'string' ? itemOrSection.props.title : undefined;
188
- }
189
-
190
- // Item element
191
- return (_itemOrSection$props$ = itemOrSection.props.textValue) !== null && _itemOrSection$props$ !== void 0 ? _itemOrSection$props$ : typeof itemOrSection.props.children === 'string' ? itemOrSection.props.children : undefined;
192
- }
193
-
194
- /**
195
- * Get a normalized `textValue` for an item ensuring it is a string.
196
- * @param item The item
197
- * @returns A string `textValue` for the item
198
- */
199
- function normalizeTextValue(item) {
200
- if (typeof item !== 'object') {
201
- return String(item);
202
- }
203
- if (item.props.textValue != null) {
204
- return item.props.textValue;
205
- }
206
- if (typeof item.props.children === 'string') {
207
- return item.props.children;
208
- }
209
- return undefined;
210
- }
211
-
212
- /**
213
- * Normalize an item or section to an object form.
214
- * @param itemOrSection item to normalize
215
- * @returns NormalizedItem or NormalizedSection object
216
- */
217
- function normalizeItem(itemOrSection) {
218
- if (!isItemOrSection(itemOrSection)) {
219
- log.debug(INVALID_ITEM_ERROR_MESSAGE, itemOrSection);
220
- throw new Error(INVALID_ITEM_ERROR_MESSAGE);
221
- }
222
- if (isSectionElement(itemOrSection)) {
223
- var _key = normalizeItemKey(itemOrSection);
224
- var {
225
- title
226
- } = itemOrSection.props;
227
- var items = normalizeItemList(itemOrSection.props.children).filter(
228
- // We don't support nested section elements
229
- childItem => !isSectionElement(childItem));
230
- return {
231
- item: {
232
- key: _key,
233
- title,
234
- items
235
- }
236
- };
237
- }
238
- var key = normalizeItemKey(itemOrSection);
239
- var content = isItemElement(itemOrSection) ? itemOrSection.props.children : itemOrSection;
240
- var textValue = normalizeTextValue(itemOrSection);
241
- return {
242
- item: {
243
- key,
244
- content,
245
- textValue
246
- }
247
- };
248
- }
249
-
250
- /**
251
- * Normalize an item or section or a list of items or sections.
252
- * @param itemsOrSections An item or section or array of items or sections
253
- * @returns An array of normalized items or sections
254
- */
255
- export function normalizeItemList(itemsOrSections) {
256
- // If already normalized, just return as-is
257
- if (isNormalizedItemsWithKeysList(itemsOrSections)) {
258
- return itemsOrSections;
259
- }
260
- var itemsArray = Array.isArray(itemsOrSections) ? itemsOrSections : [itemsOrSections];
261
- return itemsArray.map(normalizeItem);
262
- }
263
-
264
164
  /**
265
165
  * Returns a TooltipOptions object or null if options is false or null.
266
166
  * @param options Tooltip options
@@ -1 +1 @@
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,cAAAE,UAAA,uBAAVA,UAAA,CAAYC,GAAG,cAAAF,cAAA,cAAAA,cAAA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AAC;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"}
1
+ {"version":3,"file":"itemUtils.js","names":["isElementOfType","ensureArray","Item","Section","Text","ItemContent","ITEM_EMPTY_STRING_TEXT_VALUE","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","result","some","child","_child$props","slot","isNormalizedItemsWithKeysList","Array","isArray","isItemOrSection","isNormalizedSection","maybeNormalizedSection","normalizeTooltipOptions","options","placement","undefined","itemSelectionToStringSet","itemKeys","Set","map","String"],"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 { isElementOfType } from '@deephaven/react-hooks';\nimport { ensureArray, KeyedItem, SelectionT } from '@deephaven/utils';\nimport {\n Item,\n ItemElementOrPrimitive,\n ItemProps,\n Section,\n SectionProps,\n} from '../shared';\nimport { PopperOptions } from '../../popper';\nimport { Text } from '../Text';\nimport ItemContent from '../ItemContent';\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\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<T = unknown> = ReactElement<ItemProps<T>>;\nexport type SectionElement<T = unknown> = ReactElement<\n SectionPropsNoItemRenderer<T>\n>;\n\nexport type ItemOrSection<T = unknown> =\n | ItemElementOrPrimitive<T>\n | SectionElement<T>;\n\n// Picker uses `icon` slot. ListView can use `image` or `illustration` slots.\n// https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/picker/src/Picker.tsx#L194\n// https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/list/src/ListViewItem.tsx#L266-L267\nexport type ItemIconSlot = 'icon' | 'image' | 'illustration';\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 description?: ReactNode;\n icon?: 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 SectionElement<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>(node: ReactNode): node is ItemElement<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 = ensureArray(children);\n\n const result = childrenArray.some(\n child => isElementOfType(child, Text) && child.props?.slot === 'description'\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 * 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,SAASA,eAAe,QAAQ,wBAAwB;AACxD,SAASC,WAAW,QAA+B,kBAAkB;AAAC,SAEpEC,IAAI,EAGJC,OAAO;AAAA,SAIAC,IAAI;AAAA,OACNC,WAAW;AAElB;AACA;AACA;AACA;AACA,OAAO,IAAMC,4BAA4B,GAAG,OAAO;;AAEnD;AACA;AACA;AACA;AACA;;AAcA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAKA;AACA;AACA;AACA;AACA;AAiBA;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,I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EAAyB;EACtE,OACE,OAAOA,IAAI,KAAK,QAAQ,IACxB,OAAOA,IAAI,KAAK,QAAQ,IACxB,OAAOA,IAAI,KAAK,SAAS,IACzBC,aAAa,CAACD,IAAI,CAAC,IACnBD,gBAAgB,CAACC,IAAI,CAAC;AAE1B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASiB,uBAAuBA,CACrCC,OAAyC,EAElB;EAAA,IADvBC,SAAsC,GAAA9B,SAAA,CAAAS,MAAA,QAAAT,SAAA,QAAA+B,SAAA,GAAA/B,SAAA,MAAG,OAAO;EAEhD,IAAI6B,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,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,CAACE,GAAG,CAACC,MAAM,CAAC,CAAC;AAC3C"}
@@ -1,4 +1,14 @@
1
- import { ItemElement, ItemOrSection, SectionElement, TooltipOptions } from './itemUtils';
1
+ import { ReactNode } from 'react';
2
+ import { ItemElement, ItemIconSlot, ItemOrSection, SectionElement, TooltipOptions } from './itemUtils';
3
+ /**
4
+ * If the given content is a string, wrap it in an Icon component. Otherwise,
5
+ * return the original content. If the key is not found in the dhIcons object,
6
+ * the vsBlank icon will be used.
7
+ * @param maybeIconKey The content to wrap
8
+ * @param slot The slot to use for the Icon component
9
+ * @returns The wrapped content or original content if not a string
10
+ */
11
+ export declare function wrapIcon(maybeIconKey: ReactNode, slot: ItemIconSlot): ReactNode;
2
12
  /**
3
13
  * Ensure all primitive children are wrapped in `Item` elements and that all
4
14
  * `Item` element content is wrapped in `ItemContent` elements to handle text
@@ -7,6 +17,12 @@ import { ItemElement, ItemOrSection, SectionElement, TooltipOptions } from './it
7
17
  * @param tooltipOptions The tooltip options to use when wrapping items
8
18
  * @returns The wrapped items or sections
9
19
  */
10
- export declare function wrapItemChildren(itemsOrSections: ItemOrSection | ItemOrSection[], tooltipOptions: TooltipOptions | null): (ItemElement | SectionElement)[];
11
- export default wrapItemChildren;
20
+ export declare function wrapItemChildren(itemsOrSections: ItemOrSection | ItemOrSection[], tooltipOptions: TooltipOptions | null): ItemElement | SectionElement | (ItemElement | SectionElement)[];
21
+ /**
22
+ * If the given content is a primitive type, wrap it in a Text component.
23
+ * @param content The content to wrap
24
+ * @param slot The slot to use for the Text component
25
+ * @returns The wrapped content or original content if not a primitive type
26
+ */
27
+ export declare function wrapPrimitiveWithText(content?: ReactNode, slot?: string): ReactNode;
12
28
  //# sourceMappingURL=itemWrapperUtils.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"itemWrapperUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/itemWrapperUtils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA8B,SAAS,EAAE,MAAM,OAAO,CAAC;AAM9D,OAAO,EAGL,WAAW,EACX,YAAY,EACZ,aAAa,EAEb,cAAc,EACd,cAAc,EACf,MAAM,aAAa,CAAC;AAMrB;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CACtB,YAAY,EAAE,SAAS,EACvB,IAAI,EAAE,YAAY,GACjB,SAAS,CAaX;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,aAAa,GAAG,aAAa,EAAE,EAChD,cAAc,EAAE,cAAc,GAAG,IAAI,GACpC,WAAW,GAAG,cAAc,GAAG,CAAC,WAAW,GAAG,cAAc,CAAC,EAAE,CAuDjE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,SAAS,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,SAAS,CAeX"}