@deephaven/components 0.74.1-beta.7 → 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 (52) hide show
  1. package/dist/Button.d.ts +1 -1
  2. package/dist/Select.d.ts +1 -1
  3. package/dist/spectrum/listView/ListView.d.ts +3 -2
  4. package/dist/spectrum/listView/ListView.d.ts.map +1 -1
  5. package/dist/spectrum/listView/ListView.js +10 -63
  6. package/dist/spectrum/listView/ListView.js.map +1 -1
  7. package/dist/spectrum/listView/ListViewNormalized.d.ts +22 -0
  8. package/dist/spectrum/listView/ListViewNormalized.d.ts.map +1 -0
  9. package/dist/spectrum/listView/ListViewNormalized.js +80 -0
  10. package/dist/spectrum/listView/ListViewNormalized.js.map +1 -0
  11. package/dist/spectrum/listView/ListViewWrapper.css +39 -0
  12. package/dist/spectrum/listView/ListViewWrapper.css.map +1 -0
  13. package/dist/spectrum/listView/ListViewWrapper.d.ts +21 -0
  14. package/dist/spectrum/listView/ListViewWrapper.d.ts.map +1 -0
  15. package/dist/spectrum/listView/ListViewWrapper.js +71 -0
  16. package/dist/spectrum/listView/ListViewWrapper.js.map +1 -0
  17. package/dist/spectrum/listView/index.d.ts +2 -0
  18. package/dist/spectrum/listView/index.d.ts.map +1 -1
  19. package/dist/spectrum/listView/index.js +2 -0
  20. package/dist/spectrum/listView/index.js.map +1 -1
  21. package/dist/spectrum/picker/Picker.d.ts.map +1 -1
  22. package/dist/spectrum/picker/Picker.js +2 -2
  23. package/dist/spectrum/picker/Picker.js.map +1 -1
  24. package/dist/spectrum/picker/PickerNormalized.d.ts +2 -1
  25. package/dist/spectrum/picker/PickerNormalized.d.ts.map +1 -1
  26. package/dist/spectrum/picker/PickerNormalized.js +31 -15
  27. package/dist/spectrum/picker/PickerNormalized.js.map +1 -1
  28. package/dist/spectrum/shared.d.ts +13 -9
  29. package/dist/spectrum/shared.d.ts.map +1 -1
  30. package/dist/spectrum/shared.js +16 -1
  31. package/dist/spectrum/shared.js.map +1 -1
  32. package/dist/spectrum/utils/index.d.ts +1 -0
  33. package/dist/spectrum/utils/index.d.ts.map +1 -1
  34. package/dist/spectrum/utils/index.js +1 -0
  35. package/dist/spectrum/utils/index.js.map +1 -1
  36. package/dist/spectrum/utils/itemUtils.d.ts +9 -14
  37. package/dist/spectrum/utils/itemUtils.d.ts.map +1 -1
  38. package/dist/spectrum/utils/itemUtils.js +8 -108
  39. package/dist/spectrum/utils/itemUtils.js.map +1 -1
  40. package/dist/spectrum/utils/itemWrapperUtils.d.ts +19 -3
  41. package/dist/spectrum/utils/itemWrapperUtils.d.ts.map +1 -1
  42. package/dist/spectrum/utils/itemWrapperUtils.js +65 -19
  43. package/dist/spectrum/utils/itemWrapperUtils.js.map +1 -1
  44. package/dist/spectrum/utils/propsUtils.d.ts +14 -0
  45. package/dist/spectrum/utils/propsUtils.d.ts.map +1 -0
  46. package/dist/spectrum/utils/propsUtils.js +93 -0
  47. package/dist/spectrum/utils/propsUtils.js.map +1 -0
  48. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts +11 -2
  49. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts.map +1 -1
  50. package/dist/spectrum/utils/useRenderNormalizedItem.js +21 -8
  51. package/dist/spectrum/utils/useRenderNormalizedItem.js.map +1 -1
  52. package/package.json +7 -7
@@ -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,GAAID,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,GAAG;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAsBC,gCAAgCA,CAAAC,EAAA;EAAA,OAAAC,iCAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;;AA+BtD;AACA;AACA;AACA;AACA;AAJA,SAAAF,kCAAA;EAAAA,iCAAA,GAAAG,iB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C,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,IAAI,aAAJA,IAAI,wBAAAE,UAAA,GAAJF,IAAI,CAAEA,IAAI,cAAAE,UAAA,uBAAVA,UAAA,CAAYC,GAAG,cAAAF,cAAA,cAAAA,cAAA,GAAID,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,GAAG;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAsBC,gCAAgCA,CAAAC,EAAA;E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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"}
@@ -5,9 +5,38 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
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 { cloneElement } from 'react';
7
7
  import { Item } from '@adobe/react-spectrum';
8
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
9
+ import { dh as dhIcons } from '@deephaven/icons';
8
10
  import { isElementOfType } from '@deephaven/react-hooks';
11
+ import { ensureArray, NON_BREAKING_SPACE } from '@deephaven/utils';
9
12
  import { isItemElement, isSectionElement, ITEM_EMPTY_STRING_TEXT_VALUE } from "./itemUtils.js";
10
- import ItemContent from "../ItemContent.js";
13
+ import { ItemContent } from "../ItemContent.js";
14
+ import { Icon } from "../icons.js";
15
+ import { Text } from "../Text.js";
16
+ /**
17
+ * If the given content is a string, wrap it in an Icon component. Otherwise,
18
+ * return the original content. If the key is not found in the dhIcons object,
19
+ * the vsBlank icon will be used.
20
+ * @param maybeIconKey The content to wrap
21
+ * @param slot The slot to use for the Icon component
22
+ * @returns The wrapped content or original content if not a string
23
+ */
24
+ import { jsx as _jsx } from "react/jsx-runtime";
25
+ export function wrapIcon(maybeIconKey, slot) {
26
+ var _maybeIconKey, _dhIcons$maybeIconKey;
27
+ // eslint-disable-next-line no-param-reassign
28
+ maybeIconKey = (_maybeIconKey = maybeIconKey) !== null && _maybeIconKey !== void 0 ? _maybeIconKey : '';
29
+ if (typeof maybeIconKey !== 'string') {
30
+ return maybeIconKey;
31
+ }
32
+ return /*#__PURE__*/_jsx(Icon, {
33
+ slot: slot,
34
+ children: /*#__PURE__*/_jsx(FontAwesomeIcon, {
35
+ icon: (_dhIcons$maybeIconKey = dhIcons[maybeIconKey]) !== null && _dhIcons$maybeIconKey !== void 0 ? _dhIcons$maybeIconKey : dhIcons.vsBlank
36
+ })
37
+ });
38
+ }
39
+
11
40
  /**
12
41
  * Ensure all primitive children are wrapped in `Item` elements and that all
13
42
  * `Item` element content is wrapped in `ItemContent` elements to handle text
@@ -16,10 +45,9 @@ import ItemContent from "../ItemContent.js";
16
45
  * @param tooltipOptions The tooltip options to use when wrapping items
17
46
  * @returns The wrapped items or sections
18
47
  */
19
- import { jsx as _jsx } from "react/jsx-runtime";
20
48
  export function wrapItemChildren(itemsOrSections, tooltipOptions) {
21
- var itemsOrSectionsArray = Array.isArray(itemsOrSections) ? itemsOrSections : [itemsOrSections];
22
- return itemsOrSectionsArray.map(item => {
49
+ var itemsOrSectionsArray = ensureArray(itemsOrSections);
50
+ var result = itemsOrSectionsArray.map(item => {
23
51
  if (isItemElement(item)) {
24
52
  var _item$key;
25
53
  // Item content is already wrapped
@@ -27,13 +55,13 @@ export function wrapItemChildren(itemsOrSections, tooltipOptions) {
27
55
  return item;
28
56
  }
29
57
  var key = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.props.textValue;
30
- var textValue = item.props.textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : item.props.textValue;
58
+ var _textValue = item.props.textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : item.props.textValue;
31
59
 
32
60
  // Wrap in `ItemContent` so we can support tooltips and handle text
33
61
  // overflow
34
62
  return /*#__PURE__*/cloneElement(item, _objectSpread(_objectSpread({}, item.props), {}, {
35
63
  key,
36
- textValue,
64
+ textValue: _textValue,
37
65
  children: /*#__PURE__*/_jsx(ItemContent, {
38
66
  tooltipOptions: tooltipOptions,
39
67
  children: item.props.children
@@ -47,19 +75,37 @@ export function wrapItemChildren(itemsOrSections, tooltipOptions) {
47
75
  children: wrapItemChildren(item.props.children, tooltipOptions)
48
76
  }));
49
77
  }
50
- if (typeof item === 'string' || typeof item === 'number' || typeof item === 'boolean') {
51
- var text = String(item);
52
- var _textValue = text === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : text;
53
- return /*#__PURE__*/_jsx(Item, {
54
- textValue: _textValue,
55
- children: /*#__PURE__*/_jsx(ItemContent, {
56
- tooltipOptions: tooltipOptions,
57
- children: text
58
- })
59
- }, text);
60
- }
61
- return item;
78
+ var text = String(item);
79
+ var textValue = text === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : text;
80
+ return /*#__PURE__*/_jsx(Item, {
81
+ textValue: textValue,
82
+ children: /*#__PURE__*/_jsx(ItemContent, {
83
+ tooltipOptions: tooltipOptions,
84
+ children: text
85
+ })
86
+ }, text);
62
87
  });
88
+
89
+ // Keep consistent with original data structure as array or single node
90
+ return Array.isArray(itemsOrSections) ? result : result[0];
91
+ }
92
+
93
+ /**
94
+ * If the given content is a primitive type, wrap it in a Text component.
95
+ * @param content The content to wrap
96
+ * @param slot The slot to use for the Text component
97
+ * @returns The wrapped content or original content if not a primitive type
98
+ */
99
+ export function wrapPrimitiveWithText(content, slot) {
100
+ var _content;
101
+ // eslint-disable-next-line no-param-reassign
102
+ content = (_content = content) !== null && _content !== void 0 ? _content : '';
103
+ if (['string', 'boolean', 'number'].includes(typeof content)) {
104
+ return /*#__PURE__*/_jsx(Text, {
105
+ slot: slot,
106
+ children: content === '' ? NON_BREAKING_SPACE : String(content)
107
+ });
108
+ }
109
+ return content;
63
110
  }
64
- export default wrapItemChildren;
65
111
  //# sourceMappingURL=itemWrapperUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"itemWrapperUtils.js","names":["cloneElement","Item","isElementOfType","isItemElement","isSectionElement","ITEM_EMPTY_STRING_TEXT_VALUE","ItemContent","jsx","_jsx","wrapItemChildren","itemsOrSections","tooltipOptions","itemsOrSectionsArray","Array","isArray","map","item","_item$key","props","children","key","textValue","_objectSpread","_item$key2","title","undefined","text","String"],"sources":["../../../src/spectrum/utils/itemWrapperUtils.tsx"],"sourcesContent":["import { cloneElement, ReactElement } from 'react';\nimport { Item } from '@adobe/react-spectrum';\nimport { isElementOfType } from '@deephaven/react-hooks';\nimport {\n isItemElement,\n isSectionElement,\n ItemElement,\n ItemOrSection,\n ITEM_EMPTY_STRING_TEXT_VALUE,\n SectionElement,\n TooltipOptions,\n} from './itemUtils';\nimport { ItemProps } from '../shared';\nimport ItemContent from '../ItemContent';\n\n/**\n * Ensure all primitive children are wrapped in `Item` elements and that all\n * `Item` element content is wrapped in `ItemContent` elements to handle text\n * overflow consistently and to support tooltips.\n * @param itemsOrSections The items or sections to wrap\n * @param tooltipOptions The tooltip options to use when wrapping items\n * @returns The wrapped items or sections\n */\nexport function wrapItemChildren(\n itemsOrSections: ItemOrSection | ItemOrSection[],\n tooltipOptions: TooltipOptions | null\n): (ItemElement | SectionElement)[] {\n const itemsOrSectionsArray = Array.isArray(itemsOrSections)\n ? itemsOrSections\n : [itemsOrSections];\n\n return itemsOrSectionsArray.map(item => {\n if (isItemElement(item)) {\n // Item content is already wrapped\n if (isElementOfType(item.props.children, ItemContent)) {\n return item;\n }\n\n const key = item.key ?? item.props.textValue;\n const textValue =\n item.props.textValue === ''\n ? ITEM_EMPTY_STRING_TEXT_VALUE\n : item.props.textValue;\n\n // Wrap in `ItemContent` so we can support tooltips and handle text\n // overflow\n return cloneElement(item, {\n ...item.props,\n key,\n textValue,\n children: (\n <ItemContent tooltipOptions={tooltipOptions}>\n {item.props.children}\n </ItemContent>\n ),\n });\n }\n\n if (isSectionElement(item)) {\n return cloneElement(item, {\n ...item.props,\n key:\n item.key ??\n (typeof item.props.title === 'string' ? item.props.title : undefined),\n children: wrapItemChildren(\n item.props.children,\n tooltipOptions\n ) as ReactElement<ItemProps<unknown>>[],\n });\n }\n\n if (\n typeof item === 'string' ||\n typeof item === 'number' ||\n typeof item === 'boolean'\n ) {\n const text = String(item);\n const textValue = text === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : text;\n\n return (\n <Item key={text} textValue={textValue}>\n <ItemContent tooltipOptions={tooltipOptions}>{text}</ItemContent>\n </Item>\n );\n }\n\n return item;\n });\n}\n\nexport default wrapItemChildren;\n"],"mappings":";;;;;AAAA,SAASA,YAAY,QAAsB,OAAO;AAClD,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,SAASC,eAAe,QAAQ,wBAAwB;AAAC,SAEvDC,aAAa,EACbC,gBAAgB,EAGhBC,4BAA4B;AAAA,OAKvBC,WAAW;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,SAAAC,GAAA,IAAAC,IAAA;AAQA,OAAO,SAASC,gBAAgBA,CAC9BC,eAAgD,EAChDC,cAAqC,EACH;EAClC,IAAMC,oBAAoB,GAAGC,KAAK,CAACC,OAAO,CAACJ,eAAe,CAAC,GACvDA,eAAe,GACf,CAACA,eAAe,CAAC;EAErB,OAAOE,oBAAoB,CAACG,GAAG,CAACC,IAAI,IAAI;IACtC,IAAIb,aAAa,CAACa,IAAI,CAAC,EAAE;MAAA,IAAAC,SAAA;MACvB;MACA,IAAIf,eAAe,CAACc,IAAI,CAACE,KAAK,CAACC,QAAQ,EAAEb,WAAW,CAAC,EAAE;QACrD,OAAOU,IAAI;MACb;MAEA,IAAMI,GAAG,IAAAH,SAAA,GAAGD,IAAI,CAACI,GAAG,cAAAH,SAAA,cAAAA,SAAA,GAAID,IAAI,CAACE,KAAK,CAACG,SAAS;MAC5C,IAAMA,SAAS,GACbL,IAAI,CAACE,KAAK,CAACG,SAAS,KAAK,EAAE,GACvBhB,4BAA4B,GAC5BW,IAAI,CAACE,KAAK,CAACG,SAAS;;MAE1B;MACA;MACA,oBAAOrB,YAAY,CAACgB,IAAI,EAAAM,aAAA,CAAAA,aAAA,KACnBN,IAAI,CAACE,KAAK;QACbE,GAAG;QACHC,SAAS;QACTF,QAAQ,eACNX,IAAA,CAACF,WAAW;UAACK,cAAc,EAAEA,cAAe;UAAAQ,QAAA,EACzCH,IAAI,CAACE,KAAK,CAACC;QAAQ,CACT;MACd,EACF,CAAC;IACJ;IAEA,IAAIf,gBAAgB,CAACY,IAAI,CAAC,EAAE;MAAA,IAAAO,UAAA;MAC1B,oBAAOvB,YAAY,CAACgB,IAAI,EAAAM,aAAA,CAAAA,aAAA,KACnBN,IAAI,CAACE,KAAK;QACbE,GAAG,GAAAG,UAAA,GACDP,IAAI,CAACI,GAAG,cAAAG,UAAA,cAAAA,UAAA,GACP,OAAOP,IAAI,CAACE,KAAK,CAACM,KAAK,KAAK,QAAQ,GAAGR,IAAI,CAACE,KAAK,CAACM,KAAK,GAAGC,SAAU;QACvEN,QAAQ,EAAEV,gBAAgB,CACxBO,IAAI,CAACE,KAAK,CAACC,QAAQ,EACnBR,cACF;MAAuC,EACxC,CAAC;IACJ;IAEA,IACE,OAAOK,IAAI,KAAK,QAAQ,IACxB,OAAOA,IAAI,KAAK,QAAQ,IACxB,OAAOA,IAAI,KAAK,SAAS,EACzB;MACA,IAAMU,IAAI,GAAGC,MAAM,CAACX,IAAI,CAAC;MACzB,IAAMK,UAAS,GAAGK,IAAI,KAAK,EAAE,GAAGrB,4BAA4B,GAAGqB,IAAI;MAEnE,oBACElB,IAAA,CAACP,IAAI;QAAYoB,SAAS,EAAEA,UAAU;QAAAF,QAAA,eACpCX,IAAA,CAACF,WAAW;UAACK,cAAc,EAAEA,cAAe;UAAAQ,QAAA,EAAEO;QAAI,CAAc;MAAC,GADxDA,IAEL,CAAC;IAEX;IAEA,OAAOV,IAAI;EACb,CAAC,CAAC;AACJ;AAEA,eAAeP,gBAAgB"}
1
+ {"version":3,"file":"itemWrapperUtils.js","names":["cloneElement","Item","FontAwesomeIcon","dh","dhIcons","isElementOfType","ensureArray","NON_BREAKING_SPACE","isItemElement","isSectionElement","ITEM_EMPTY_STRING_TEXT_VALUE","ItemContent","Icon","Text","jsx","_jsx","wrapIcon","maybeIconKey","slot","_maybeIconKey","_dhIcons$maybeIconKey","children","icon","vsBlank","wrapItemChildren","itemsOrSections","tooltipOptions","itemsOrSectionsArray","result","map","item","_item$key","props","key","textValue","_objectSpread","_item$key2","title","undefined","text","String","Array","isArray","wrapPrimitiveWithText","content","_content","includes"],"sources":["../../../src/spectrum/utils/itemWrapperUtils.tsx"],"sourcesContent":["import { cloneElement, ReactElement, ReactNode } from 'react';\nimport { Item } from '@adobe/react-spectrum';\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport { dh as dhIcons } from '@deephaven/icons';\nimport { isElementOfType } from '@deephaven/react-hooks';\nimport { ensureArray, NON_BREAKING_SPACE } from '@deephaven/utils';\nimport {\n isItemElement,\n isSectionElement,\n ItemElement,\n ItemIconSlot,\n ItemOrSection,\n ITEM_EMPTY_STRING_TEXT_VALUE,\n SectionElement,\n TooltipOptions,\n} from './itemUtils';\nimport { ItemProps } from '../shared';\nimport { ItemContent } from '../ItemContent';\nimport { Icon } from '../icons';\nimport { Text } from '../Text';\n\n/**\n * If the given content is a string, wrap it in an Icon component. Otherwise,\n * return the original content. If the key is not found in the dhIcons object,\n * the vsBlank icon will be used.\n * @param maybeIconKey The content to wrap\n * @param slot The slot to use for the Icon component\n * @returns The wrapped content or original content if not a string\n */\nexport function wrapIcon(\n maybeIconKey: ReactNode,\n slot: ItemIconSlot\n): ReactNode {\n // eslint-disable-next-line no-param-reassign\n maybeIconKey = maybeIconKey ?? '';\n\n if (typeof maybeIconKey !== 'string') {\n return maybeIconKey;\n }\n\n return (\n <Icon slot={slot}>\n <FontAwesomeIcon icon={dhIcons[maybeIconKey] ?? dhIcons.vsBlank} />\n </Icon>\n );\n}\n\n/**\n * Ensure all primitive children are wrapped in `Item` elements and that all\n * `Item` element content is wrapped in `ItemContent` elements to handle text\n * overflow consistently and to support tooltips.\n * @param itemsOrSections The items or sections to wrap\n * @param tooltipOptions The tooltip options to use when wrapping items\n * @returns The wrapped items or sections\n */\nexport function wrapItemChildren(\n itemsOrSections: ItemOrSection | ItemOrSection[],\n tooltipOptions: TooltipOptions | null\n): ItemElement | SectionElement | (ItemElement | SectionElement)[] {\n const itemsOrSectionsArray = ensureArray(itemsOrSections);\n\n const result = itemsOrSectionsArray.map(item => {\n if (isItemElement(item)) {\n // Item content is already wrapped\n if (isElementOfType(item.props.children, ItemContent)) {\n return item;\n }\n\n const key = item.key ?? item.props.textValue;\n const textValue =\n item.props.textValue === ''\n ? ITEM_EMPTY_STRING_TEXT_VALUE\n : item.props.textValue;\n\n // Wrap in `ItemContent` so we can support tooltips and handle text\n // overflow\n return cloneElement(item, {\n ...item.props,\n key,\n textValue,\n children: (\n <ItemContent tooltipOptions={tooltipOptions}>\n {item.props.children}\n </ItemContent>\n ),\n });\n }\n\n if (isSectionElement(item)) {\n return cloneElement(item, {\n ...item.props,\n key:\n item.key ??\n (typeof item.props.title === 'string' ? item.props.title : undefined),\n children: wrapItemChildren(\n item.props.children,\n tooltipOptions\n ) as ReactElement<ItemProps<unknown>>[],\n });\n }\n\n const text = String(item);\n const textValue = text === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : text;\n\n return (\n <Item key={text} textValue={textValue}>\n <ItemContent tooltipOptions={tooltipOptions}>{text}</ItemContent>\n </Item>\n );\n });\n\n // Keep consistent with original data structure as array or single node\n return Array.isArray(itemsOrSections) ? result : result[0];\n}\n\n/**\n * If the given content is a primitive type, wrap it in a Text component.\n * @param content The content to wrap\n * @param slot The slot to use for the Text component\n * @returns The wrapped content or original content if not a primitive type\n */\nexport function wrapPrimitiveWithText(\n content?: ReactNode,\n slot?: string\n): ReactNode {\n // eslint-disable-next-line no-param-reassign\n content = content ?? '';\n\n if (['string', 'boolean', 'number'].includes(typeof content)) {\n return (\n <Text slot={slot}>\n {/* Non-breaking space is needed to avoid the Text element's height \n collapsing when content is empty */}\n {content === '' ? NON_BREAKING_SPACE : String(content)}\n </Text>\n );\n }\n\n return content;\n}\n"],"mappings":";;;;;AAAA,SAASA,YAAY,QAAiC,OAAO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WAAW;QAACe,cAAc,EAAEA,cAAe;QAAAL,QAAA,EAAEkB;MAAI,CAAc;IAAC,GADxDA,IAEL,CAAC;EAEX,CAAC,CAAC;;EAEF;EACA,OAAOE,KAAK,CAACC,OAAO,CAACjB,eAAe,CAAC,GAAGG,MAAM,GAAGA,MAAM,CAAC,CAAC,CAAC;AAC5D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASe,qBAAqBA,CACnCC,OAAmB,EACnB1B,IAAa,EACF;EAAA,IAAA2B,QAAA;EACX;EACAD,OAAO,IAAAC,QAAA,GAAGD,OAAO,cAAAC,QAAA,cAAAA,QAAA,GAAI,EAAE;EAEvB,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,CAACC,QAAQ,CAAC,OAAOF,OAAO,CAAC,EAAE;IAC5D,oBACE7B,IAAA,CAACF,IAAI;MAACK,IAAI,EAAEA,IAAK;MAAAG,QAAA,EAGduB,OAAO,KAAK,EAAE,GAAGrC,kBAAkB,GAAGiC,MAAM,CAACI,OAAO;IAAC,CAClD,CAAC;EAEX;EAEA,OAAOA,OAAO;AAChB"}
@@ -0,0 +1,14 @@
1
+ import type { AriaLabelingProps, StyleProps } from '@react-types/shared';
2
+ /**
3
+ * Separate props for Spectrum components into AriaLabelingProps, StyleProps, and
4
+ * any remaining props.
5
+ * @param props The props to separate
6
+ * @returns The separated props
7
+ */
8
+ export declare function separateSpectrumProps<T extends AriaLabelingProps & StyleProps>(props: T): {
9
+ ariaLabelProps: AriaLabelingProps;
10
+ styleProps: StyleProps;
11
+ componentProps: Omit<T, keyof (AriaLabelingProps & StyleProps)>;
12
+ };
13
+ export default separateSpectrumProps;
14
+ //# sourceMappingURL=propsUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propsUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/propsUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEzE;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,iBAAiB,GAAG,UAAU,EAC5E,KAAK,EAAE,CAAC,GACP;IACD,cAAc,EAAE,iBAAiB,CAAC;IAClC,UAAU,EAAE,UAAU,CAAC;IACvB,cAAc,EAAE,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,iBAAiB,GAAG,UAAU,CAAC,CAAC,CAAC;CACjE,CAsFA;AAED,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,93 @@
1
+ var _excluded = ["aria-label", "aria-labelledby", "aria-describedby", "aria-details", "marginX", "marginY", "width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "flex", "flexGrow", "flexShrink", "flexBasis", "justifySelf", "alignSelf", "order", "gridArea", "gridColumn", "gridRow", "gridColumnStart", "gridColumnEnd", "gridRowStart", "gridRowEnd", "position", "zIndex", "top", "bottom", "start", "end", "left", "right", "isHidden"];
2
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
3
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
+ /**
5
+ * Separate props for Spectrum components into AriaLabelingProps, StyleProps, and
6
+ * any remaining props.
7
+ * @param props The props to separate
8
+ * @returns The separated props
9
+ */
10
+ export function separateSpectrumProps(props) {
11
+ var {
12
+ 'aria-label': ariaLabel,
13
+ 'aria-labelledby': ariaLabelledby,
14
+ 'aria-describedby': ariaDescribedby,
15
+ 'aria-details': ariaHidden,
16
+ marginX,
17
+ marginY,
18
+ width,
19
+ height,
20
+ minWidth,
21
+ minHeight,
22
+ maxWidth,
23
+ maxHeight,
24
+ flex,
25
+ flexGrow,
26
+ flexShrink,
27
+ flexBasis,
28
+ justifySelf,
29
+ alignSelf,
30
+ order,
31
+ gridArea,
32
+ gridColumn,
33
+ gridRow,
34
+ gridColumnStart,
35
+ gridColumnEnd,
36
+ gridRowStart,
37
+ gridRowEnd,
38
+ position,
39
+ zIndex,
40
+ top,
41
+ bottom,
42
+ start,
43
+ end,
44
+ left,
45
+ right,
46
+ isHidden
47
+ } = props,
48
+ componentProps = _objectWithoutProperties(props, _excluded);
49
+ return {
50
+ ariaLabelProps: {
51
+ 'aria-label': ariaLabel,
52
+ 'aria-labelledby': ariaLabelledby,
53
+ 'aria-describedby': ariaDescribedby,
54
+ 'aria-details': ariaHidden
55
+ },
56
+ styleProps: {
57
+ marginX,
58
+ marginY,
59
+ width,
60
+ height,
61
+ minWidth,
62
+ minHeight,
63
+ maxWidth,
64
+ maxHeight,
65
+ flex,
66
+ flexGrow,
67
+ flexShrink,
68
+ flexBasis,
69
+ justifySelf,
70
+ alignSelf,
71
+ order,
72
+ gridArea,
73
+ gridColumn,
74
+ gridRow,
75
+ gridColumnStart,
76
+ gridColumnEnd,
77
+ gridRowStart,
78
+ gridRowEnd,
79
+ position,
80
+ zIndex,
81
+ top,
82
+ bottom,
83
+ start,
84
+ end,
85
+ left,
86
+ right,
87
+ isHidden
88
+ },
89
+ componentProps: componentProps
90
+ };
91
+ }
92
+ export default separateSpectrumProps;
93
+ //# sourceMappingURL=propsUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"propsUtils.js","names":["separateSpectrumProps","props","ariaLabel","ariaLabelledby","ariaDescribedby","ariaHidden","marginX","marginY","width","height","minWidth","minHeight","maxWidth","maxHeight","flex","flexGrow","flexShrink","flexBasis","justifySelf","alignSelf","order","gridArea","gridColumn","gridRow","gridColumnStart","gridColumnEnd","gridRowStart","gridRowEnd","position","zIndex","top","bottom","start","end","left","right","isHidden","componentProps","_objectWithoutProperties","_excluded","ariaLabelProps","styleProps"],"sources":["../../../src/spectrum/utils/propsUtils.ts"],"sourcesContent":["import type { AriaLabelingProps, StyleProps } from '@react-types/shared';\n\n/**\n * Separate props for Spectrum components into AriaLabelingProps, StyleProps, and\n * any remaining props.\n * @param props The props to separate\n * @returns The separated props\n */\nexport function separateSpectrumProps<T extends AriaLabelingProps & StyleProps>(\n props: T\n): {\n ariaLabelProps: AriaLabelingProps;\n styleProps: StyleProps;\n componentProps: Omit<T, keyof (AriaLabelingProps & StyleProps)>;\n} {\n const {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby,\n 'aria-describedby': ariaDescribedby,\n 'aria-details': ariaHidden,\n\n marginX,\n marginY,\n width,\n height,\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n flex,\n flexGrow,\n flexShrink,\n flexBasis,\n justifySelf,\n alignSelf,\n order,\n gridArea,\n gridColumn,\n gridRow,\n gridColumnStart,\n gridColumnEnd,\n gridRowStart,\n gridRowEnd,\n position,\n zIndex,\n top,\n bottom,\n start,\n end,\n left,\n right,\n isHidden,\n ...componentProps\n } = props;\n\n return {\n ariaLabelProps: {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledby,\n 'aria-describedby': ariaDescribedby,\n 'aria-details': ariaHidden,\n },\n styleProps: {\n marginX,\n marginY,\n width,\n height,\n minWidth,\n minHeight,\n maxWidth,\n maxHeight,\n flex,\n flexGrow,\n flexShrink,\n flexBasis,\n justifySelf,\n alignSelf,\n order,\n gridArea,\n gridColumn,\n gridRow,\n gridColumnStart,\n gridColumnEnd,\n gridRowStart,\n gridRowEnd,\n position,\n zIndex,\n top,\n bottom,\n start,\n end,\n left,\n right,\n isHidden,\n },\n componentProps: componentProps as Omit<\n T,\n keyof (AriaLabelingProps & StyleProps)\n >,\n };\n}\n\nexport default separateSp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AEA;EAIlB,CAAC;AACH;AAEA,eAAerC,qBAAqB"}
@@ -1,11 +1,20 @@
1
1
  /// <reference types="react" />
2
- import { NormalizedItem, TooltipOptions } from './itemUtils';
2
+ import { ItemIconSlot, NormalizedItem, TooltipOptions } from './itemUtils';
3
+ export interface UseRenderNormalizedItemOptions {
4
+ itemIconSlot: ItemIconSlot;
5
+ showItemDescriptions: boolean;
6
+ showItemIcons: boolean;
7
+ tooltipOptions: TooltipOptions | null;
8
+ }
3
9
  /**
4
10
  * Returns a render function that can be used to render a normalized item in
5
11
  * collection components.
12
+ * @param itemIconSlot Slot to use for item icons
13
+ * @param showItemDescriptions Whether to show item descriptions
14
+ * @param showItemIcons Whether to show item icons
6
15
  * @param tooltipOptions Tooltip options to use when rendering the item
7
16
  * @returns Render function for normalized items
8
17
  */
9
- export declare function useRenderNormalizedItem(tooltipOptions: TooltipOptions | null): (normalizedItem: NormalizedItem) => JSX.Element;
18
+ export declare function useRenderNormalizedItem({ itemIconSlot, showItemDescriptions, showItemIcons, tooltipOptions, }: UseRenderNormalizedItemOptions): (normalizedItem: NormalizedItem) => JSX.Element;
10
19
  export default useRenderNormalizedItem;
11
20
  //# sourceMappingURL=useRenderNormalizedItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useRenderNormalizedItem.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"names":[],"mappings":";AAGA,OAAO,EAGL,cAAc,EACd,cAAc,EACf,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,cAAc,GAAG,IAAI,GACpC,CAAC,cAAc,EAAE,cAAc,KAAK,GAAG,CAAC,OAAO,CA+BjD;AAED,eAAe,uBAAuB,CAAC"}
1
+ {"version":3,"file":"useRenderNormalizedItem.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"names":[],"mappings":";AAGA,OAAO,EAEL,YAAY,EAEZ,cAAc,EACd,cAAc,EACf,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,8BAA8B;IAC7C,YAAY,EAAE,YAAY,CAAC;IAC3B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;CACvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,cAAc,GACf,EAAE,8BAA8B,GAAG,CAClC,cAAc,EAAE,cAAc,KAC3B,GAAG,CAAC,OAAO,CA2Cf;AAED,eAAe,uBAAuB,CAAC"}
@@ -2,19 +2,32 @@ import { useCallback } from 'react';
2
2
  import { ItemContent } from "../ItemContent.js";
3
3
  import { Item } from "../shared.js";
4
4
  import { getItemKey, ITEM_EMPTY_STRING_TEXT_VALUE } from "./itemUtils.js";
5
+ import { wrapIcon, wrapPrimitiveWithText } from "./itemWrapperUtils.js";
6
+ import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
5
8
  /**
6
9
  * Returns a render function that can be used to render a normalized item in
7
10
  * collection components.
11
+ * @param itemIconSlot Slot to use for item icons
12
+ * @param showItemDescriptions Whether to show item descriptions
13
+ * @param showItemIcons Whether to show item icons
8
14
  * @param tooltipOptions Tooltip options to use when rendering the item
9
15
  * @returns Render function for normalized items
10
16
  */
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- export function useRenderNormalizedItem(tooltipOptions) {
17
+ export function useRenderNormalizedItem(_ref) {
18
+ var {
19
+ itemIconSlot,
20
+ showItemDescriptions,
21
+ showItemIcons,
22
+ tooltipOptions
23
+ } = _ref;
13
24
  return useCallback(normalizedItem => {
14
- var _normalizedItem$item$, _normalizedItem$item, _normalizedItem$item$2, _normalizedItem$item2;
25
+ var _normalizedItem$item, _normalizedItem$item$, _normalizedItem$item2, _normalizedItem$item3, _normalizedItem$item4;
15
26
  var key = getItemKey(normalizedItem);
16
- 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$ : '';
17
- 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 : '';
27
+ var content = wrapPrimitiveWithText((_normalizedItem$item = normalizedItem.item) === null || _normalizedItem$item === void 0 ? void 0 : _normalizedItem$item.content);
28
+ var textValue = (_normalizedItem$item$ = (_normalizedItem$item2 = normalizedItem.item) === null || _normalizedItem$item2 === void 0 ? void 0 : _normalizedItem$item2.textValue) !== null && _normalizedItem$item$ !== void 0 ? _normalizedItem$item$ : '';
29
+ var description = showItemDescriptions ? wrapPrimitiveWithText((_normalizedItem$item3 = normalizedItem.item) === null || _normalizedItem$item3 === void 0 ? void 0 : _normalizedItem$item3.description, 'description') : null;
30
+ var icon = showItemIcons ? wrapIcon((_normalizedItem$item4 = normalizedItem.item) === null || _normalizedItem$item4 === void 0 ? void 0 : _normalizedItem$item4.icon, itemIconSlot) : null;
18
31
  return /*#__PURE__*/_jsx(Item
19
32
  // Note that setting the `key` prop explicitly on `Item` elements
20
33
  // causes the picker to expect `selectedKey` and `defaultSelectedKey`
@@ -29,12 +42,12 @@ export function useRenderNormalizedItem(tooltipOptions) {
29
42
  // but are used for accessibility purposes, so we set to an arbitrary
30
43
  // `ITEM_EMPTY_STRING_TEXT_VALUE` value so that they are not empty strings.
31
44
  textValue: textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : textValue,
32
- children: /*#__PURE__*/_jsx(ItemContent, {
45
+ children: /*#__PURE__*/_jsxs(ItemContent, {
33
46
  tooltipOptions: tooltipOptions,
34
- children: content
47
+ children: [icon, content, description]
35
48
  })
36
49
  }, key);
37
- }, [tooltipOptions]);
50
+ }, [itemIconSlot, showItemDescriptions, showItemIcons, tooltipOptions]);
38
51
  }
39
52
  export default useRenderNormalizedItem;
40
53
  //# sourceMappingURL=useRenderNormalizedItem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useRenderNormalizedItem.js","names":["useCallback","ItemContent","Item","getItemKey","ITEM_EMPTY_STRING_TEXT_VALUE","jsx","_jsx","useRenderNormalizedItem","tooltipOptions","normalizedItem","_normalizedItem$item$","_normalizedItem$item","_normalizedItem$item$2","_normalizedItem$item2","key","content","item","textValue","children"],"sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"sourcesContent":["import { Key, useCallback } from 'react';\nimport { ItemContent } from '../ItemContent';\nimport { Item } from '../shared';\nimport {\n getItemKey,\n ITEM_EMPTY_STRING_TEXT_VALUE,\n NormalizedItem,\n TooltipOptions,\n} from './itemUtils';\n\n/**\n * Returns a render function that can be used to render a normalized item in\n * collection components.\n * @param tooltipOptions Tooltip options to use when rendering the item\n * @returns Render function for normalized items\n */\nexport function useRenderNormalizedItem(\n tooltipOptions: TooltipOptions | null\n): (normalizedItem: NormalizedItem) => JSX.Element {\n return useCallback(\n (normalizedItem: NormalizedItem) => {\n const key = getItemKey(normalizedItem);\n const content = normalizedItem.item?.content ?? '';\n const textValue = normalizedItem.item?.textValue ?? '';\n\n return (\n <Item\n // Note that setting the `key` prop explicitly on `Item` elements\n // causes the picker to expect `selectedKey` and `defaultSelectedKey`\n // to be strings. It also passes the stringified value of the key to\n // `onSelectionChange` handlers` regardless of the actual type of the\n // key. We can't really get around setting in order to support Windowed\n // data, so we'll need to do some manual conversion of keys to strings\n // in other components that use this hook.\n key={key as Key}\n // The `textValue` prop gets used to provide the content of `<option>`\n // elements that back the Spectrum Picker. These are not visible in the UI,\n // but are used for accessibility purposes, so we set to an arbitrary\n // `ITEM_EMPTY_STRING_TEXT_VALUE` value so that they are not empty strings.\n textValue={\n textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : textValue\n }\n >\n <ItemContent tooltipOptions={tooltipOptions}>{content}</ItemContent>\n </Item>\n );\n },\n [tooltipOptions]\n );\n}\n\nexport default useRenderNormalizedItem;\n"],"mappings":"AAAA,SAAcA,WAAW,QAAQ,OAAO;AAAC,SAChCC,WAAW;AAAA,SACXC,IAAI;AAAA,SAEXC,UAAU,EACVC,4BAA4B;AAK9B;AACA;AACA;AACA;AACA;AACA;AALA,SAAAC,GAAA,IAAAC,IAAA;AAMA,OAAO,SAASC,uBAAuBA,CACrCC,cAAqC,EACY;EACjD,OAAOR,WAAW,CACfS,cAA8B,IAAK;IAAA,IAAAC,qBAAA,EAAAC,oBAAA,EAAAC,sBAAA,EAAAC,qBAAA;IAClC,IAAMC,GAAG,GAAGX,UAAU,CAACM,cAAc,CAAC;IACtC,IAAMM,OAAO,IAAAL,qBAAA,IAAAC,oBAAA,GAAGF,cAAc,CAACO,IAAI,cAAAL,oBAAA,uBAAnBA,oBAAA,CAAqBI,OAAO,cAAAL,qBAAA,cAAAA,qBAAA,GAAI,EAAE;IAClD,IAAMO,SAAS,IAAAL,sBAAA,IAAAC,qBAAA,GAAGJ,cAAc,CAACO,IAAI,cAAAH,qBAAA,uBAAnBA,qBAAA,CAAqBI,SAAS,cAAAL,sBAAA,cAAAA,sBAAA,GAAI,EAAE;IAEtD,oBACEN,IAAA,CAACJ;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IAAA;MAEA;MACA;MACA;MACA;MACAe,SAAS,EACPA,SAAS,KAAK,EAAE,GAAGb,4BAA4B,GAAGa,SACnD;MAAAC,QAAA,eAEDZ,IAAA,CAACL,WAAW;QAACO,cAAc,EAAEA,cAAe;QAAAU,QAAA,EAAEH;MAAO,CAAc;IAAC,GAT/DD,GAUD,CAAC;EAEX,CAAC,EACD,CAACN,cAAc,CACjB,CAAC;AACH;AAEA,eAAeD,uBAAuB"}
1
+ {"version":3,"file":"useRenderNormalizedItem.js","names":["useCallback","ItemContent","Item","getItemKey","ITEM_EMPTY_STRING_TEXT_VALUE","wrapIcon","wrapPrimitiveWithText","jsxs","_jsxs","jsx","_jsx","useRenderNormalizedItem","_ref","itemIconSlot","showItemDescriptions","showItemIcons","tooltipOptions","normalizedItem","_normalizedItem$item","_normalizedItem$item$","_normalizedItem$item2","_normalizedItem$item3","_normalizedItem$item4","key","content","item","textValue","description","icon","children"],"sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"sourcesContent":["import { Key, useCallback } from 'react';\nimport { ItemContent } from '../ItemContent';\nimport { Item } from '../shared';\nimport {\n getItemKey,\n ItemIconSlot,\n ITEM_EMPTY_STRING_TEXT_VALUE,\n NormalizedItem,\n TooltipOptions,\n} from './itemUtils';\nimport { wrapIcon, wrapPrimitiveWithText } from './itemWrapperUtils';\n\nexport interface UseRenderNormalizedItemOptions {\n itemIconSlot: ItemIconSlot;\n showItemDescriptions: boolean;\n showItemIcons: boolean;\n tooltipOptions: TooltipOptions | null;\n}\n\n/**\n * Returns a render function that can be used to render a normalized item in\n * collection components.\n * @param itemIconSlot Slot to use for item icons\n * @param showItemDescriptions Whether to show item descriptions\n * @param showItemIcons Whether to show item icons\n * @param tooltipOptions Tooltip options to use when rendering the item\n * @returns Render function for normalized items\n */\nexport function useRenderNormalizedItem({\n itemIconSlot,\n showItemDescriptions,\n showItemIcons,\n tooltipOptions,\n}: UseRenderNormalizedItemOptions): (\n normalizedItem: NormalizedItem\n) => JSX.Element {\n return useCallback(\n (normalizedItem: NormalizedItem) => {\n const key = getItemKey(normalizedItem);\n const content = wrapPrimitiveWithText(normalizedItem.item?.content);\n const textValue = normalizedItem.item?.textValue ?? '';\n\n const description = showItemDescriptions\n ? wrapPrimitiveWithText(normalizedItem.item?.description, 'description')\n : null;\n\n const icon = showItemIcons\n ? wrapIcon(normalizedItem.item?.icon, itemIconSlot)\n : null;\n\n return (\n <Item\n // Note that setting the `key` prop explicitly on `Item` elements\n // causes the picker to expect `selectedKey` and `defaultSelectedKey`\n // to be strings. It also passes the stringified value of the key to\n // `onSelectionChange` handlers` regardless of the actual type of the\n // key. We can't really get around setting in order to support Windowed\n // data, so we'll need to do some manual conversion of keys to strings\n // in other components that use this hook.\n key={key as Key}\n // The `textValue` prop gets used to provide the content of `<option>`\n // elements that back the Spectrum Picker. These are not visible in the UI,\n // but are used for accessibility purposes, so we set to an arbitrary\n // `ITEM_EMPTY_STRING_TEXT_VALUE` value so that they are not empty strings.\n textValue={\n textValue === '' ? ITEM_EMPTY_STRING_TEXT_VALUE : textValue\n }\n >\n <ItemContent tooltipOptions={tooltipOptions}>\n {icon}\n {content}\n {description}\n </ItemContent>\n </Item>\n );\n },\n [itemIconSlot, showItemDescriptions, showItemIcons, tooltipOptions]\n );\n}\n\nexport default useRenderNormalizedItem;\n"],"mappings":"AAAA,SAAcA,WAAW,QAAQ,OAAO;AAAC,SAChCC,WAAW;AAAA,SACXC,IAAI;AAAA,SAEXC,UAAU,EAEVC,4BAA4B;AAAA,SAIrBC,QAAQ,EAAEC,qBAAqB;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAAA,SAAAC,GAAA,IAAAC,IAAA;AASxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAAAC,IAAA,EAOtB;EAAA,IAPuB;IACtCC,YAAY;IACZC,oBAAoB;IACpBC,aAAa;IACbC;EAC8B,CAAC,GAAAJ,IAAA;EAG/B,OAAOZ,WAAW,CACfiB,cAA8B,IAAK;IAAA,IAAAC,oBAAA,EAAAC,qBAAA,EAAAC,qBAAA,EAAAC,qBAAA,EAAAC,qBAAA;IAClC,IAAMC,GAAG,GAAGpB,UAAU,CAACc,cAAc,CAAC;IACtC,IAAMO,OAAO,GAAGlB,qBAAqB,EAAAY,oBAAA,GAACD,cAAc,CAACQ,IAAI,cAAAP,oBAAA,uBAAnBA,oBAAA,CAAqBM,OAAO,CAAC;IACnE,IAAME,SAAS,IAAAP,qBAAA,IAAAC,qBAAA,GAAGH,cAAc,CAACQ,IAAI,cAAAL,qBAAA,uBAAnBA,qBAAA,CAAqBM,SAAS,cAAAP,qBAAA,cAAAA,qBAAA,GAAI,EAAE;IAEtD,IAAMQ,WAAW,GAAGb,oBAAoB,GACpCR,qBAAqB,EAAAe,qBAAA,GAACJ,cAAc,CAACQ,IAAI,cAAAJ,qBAAA,uBAAnBA,qBAAA,CAAqBM,WAAW,EAAE,aAAa,CAAC,GACtE,IAAI;IAER,IAAMC,IAAI,GAAGb,aAAa,GACtBV,QAAQ,EAAAiB,qBAAA,GAACL,cAAc,CAACQ,IAAI,cAAAH,qBAAA,uBAAnBA,qBAAA,CAAqBM,IAAI,EAAEf,YAAY,CAAC,GACjD,IAAI;IAER,oBACEH,IAAA,CAACR;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IAAA;MAEA;MACA;MACA;MACA;MACAwB,SAAS,EACPA,SAAS,KAAK,EAAE,GAAGtB,4BAA4B,GAAGsB,SACnD;MAAAG,QAAA,eAEDrB,KAAA,CAACP,WAAW;QAACe,cAAc,EAAEA,cAAe;QAAAa,QAAA,GACzCD,IAAI,EACJJ,OAAO,EACPG,WAAW;MAAA,CACD;IAAC,GAbTJ,GAcD,CAAC;EAEX,CAAC,EACD,CAACV,YAAY,EAAEC,oBAAoB,EAAEC,aAAa,EAAEC,cAAc,CACpE,CAAC;AACH;AAEA,eAAeL,uBAAuB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven/components",
3
- "version": "0.74.1-beta.7+fb63be1f",
3
+ "version": "0.75.0",
4
4
  "description": "Deephaven React component library",
5
5
  "author": "Deephaven Data Labs LLC",
6
6
  "license": "Apache-2.0",
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@adobe/react-spectrum": "^3.34.1",
28
- "@deephaven/icons": "^0.74.1-beta.7+fb63be1f",
29
- "@deephaven/log": "^0.74.1-beta.7+fb63be1f",
30
- "@deephaven/react-hooks": "^0.74.1-beta.7+fb63be1f",
31
- "@deephaven/utils": "^0.74.1-beta.7+fb63be1f",
28
+ "@deephaven/icons": "^0.75.0",
29
+ "@deephaven/log": "^0.75.0",
30
+ "@deephaven/react-hooks": "^0.75.0",
31
+ "@deephaven/utils": "^0.75.0",
32
32
  "@fortawesome/fontawesome-svg-core": "^6.2.1",
33
33
  "@fortawesome/react-fontawesome": "^0.2.0",
34
34
  "@react-spectrum/theme-default": "^3.5.1",
@@ -55,7 +55,7 @@
55
55
  "react-dom": ">=16.8.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@deephaven/mocks": "^0.74.1-beta.7+fb63be1f"
58
+ "@deephaven/mocks": "^0.75.0"
59
59
  },
60
60
  "files": [
61
61
  "dist",
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "gitHead": "fb63be1f4b437634c4b3bdbacc0578f174e212fb"
72
+ "gitHead": "cabfaf42c5c7e0b83561d10ba41cbeb305d1076e"
73
73
  }