@deephaven/components 0.72.1-beta.5 → 0.73.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 (77) hide show
  1. package/dist/Button.d.ts +1 -1
  2. package/dist/Select.d.ts +1 -1
  3. package/dist/spectrum/Heading.d.ts +4 -1
  4. package/dist/spectrum/Heading.d.ts.map +1 -1
  5. package/dist/spectrum/Heading.js +5 -3
  6. package/dist/spectrum/Heading.js.map +1 -1
  7. package/dist/spectrum/ItemContent.d.ts +15 -0
  8. package/dist/spectrum/ItemContent.d.ts.map +1 -0
  9. package/dist/spectrum/{picker/PickerItemContent.js → ItemContent.js} +42 -18
  10. package/dist/spectrum/ItemContent.js.map +1 -0
  11. package/dist/spectrum/ItemTooltip.d.ts +12 -0
  12. package/dist/spectrum/ItemTooltip.d.ts.map +1 -0
  13. package/dist/spectrum/ItemTooltip.js +30 -0
  14. package/dist/spectrum/ItemTooltip.js.map +1 -0
  15. package/dist/spectrum/Text.d.ts +4 -1
  16. package/dist/spectrum/Text.d.ts.map +1 -1
  17. package/dist/spectrum/Text.js +5 -4
  18. package/dist/spectrum/Text.js.map +1 -1
  19. package/dist/spectrum/View.d.ts +4 -1
  20. package/dist/spectrum/View.d.ts.map +1 -1
  21. package/dist/spectrum/View.js +5 -3
  22. package/dist/spectrum/View.js.map +1 -1
  23. package/dist/spectrum/collections.d.ts +1 -1
  24. package/dist/spectrum/collections.d.ts.map +1 -1
  25. package/dist/spectrum/collections.js +1 -1
  26. package/dist/spectrum/collections.js.map +1 -1
  27. package/dist/spectrum/icons.d.ts +2 -0
  28. package/dist/spectrum/icons.d.ts.map +1 -0
  29. package/dist/spectrum/icons.js +3 -0
  30. package/dist/spectrum/icons.js.map +1 -0
  31. package/dist/spectrum/index.d.ts +4 -0
  32. package/dist/spectrum/index.d.ts.map +1 -1
  33. package/dist/spectrum/index.js +4 -0
  34. package/dist/spectrum/index.js.map +1 -1
  35. package/dist/spectrum/listView/ListView.d.ts +28 -0
  36. package/dist/spectrum/listView/ListView.d.ts.map +1 -0
  37. package/dist/spectrum/listView/ListView.js +91 -0
  38. package/dist/spectrum/listView/ListView.js.map +1 -0
  39. package/dist/spectrum/listView/index.d.ts +2 -0
  40. package/dist/spectrum/listView/index.d.ts.map +1 -0
  41. package/dist/spectrum/listView/index.js +2 -0
  42. package/dist/spectrum/listView/index.js.map +1 -0
  43. package/dist/spectrum/picker/Picker.d.ts.map +1 -1
  44. package/dist/spectrum/picker/Picker.js +9 -60
  45. package/dist/spectrum/picker/Picker.js.map +1 -1
  46. package/dist/spectrum/picker/index.d.ts +0 -1
  47. package/dist/spectrum/picker/index.d.ts.map +1 -1
  48. package/dist/spectrum/picker/index.js +0 -1
  49. package/dist/spectrum/picker/index.js.map +1 -1
  50. package/dist/spectrum/utils/index.d.ts +2 -0
  51. package/dist/spectrum/utils/index.d.ts.map +1 -1
  52. package/dist/spectrum/utils/index.js +2 -0
  53. package/dist/spectrum/utils/index.js.map +1 -1
  54. package/dist/spectrum/utils/itemUtils.d.ts +21 -11
  55. package/dist/spectrum/utils/itemUtils.d.ts.map +1 -1
  56. package/dist/spectrum/utils/itemUtils.js +23 -8
  57. package/dist/spectrum/utils/itemUtils.js.map +1 -1
  58. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts +11 -0
  59. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts.map +1 -0
  60. package/dist/spectrum/utils/useRenderNormalizedItem.js +40 -0
  61. package/dist/spectrum/utils/useRenderNormalizedItem.js.map +1 -0
  62. package/dist/spectrum/utils/useStringifiedMultiSelection.d.ts +43 -0
  63. package/dist/spectrum/utils/useStringifiedMultiSelection.d.ts.map +1 -0
  64. package/dist/spectrum/utils/useStringifiedMultiSelection.js +50 -0
  65. package/dist/spectrum/utils/useStringifiedMultiSelection.js.map +1 -0
  66. package/dist/theme/index.d.ts +1 -0
  67. package/dist/theme/index.d.ts.map +1 -1
  68. package/dist/theme/index.js +1 -0
  69. package/dist/theme/index.js.map +1 -1
  70. package/dist/theme/useSpectrumThemeProvider.d.ts +4 -0
  71. package/dist/theme/useSpectrumThemeProvider.d.ts.map +1 -0
  72. package/dist/theme/useSpectrumThemeProvider.js +4 -0
  73. package/dist/theme/useSpectrumThemeProvider.js.map +1 -0
  74. package/package.json +7 -7
  75. package/dist/spectrum/picker/PickerItemContent.d.ts +0 -11
  76. package/dist/spectrum/picker/PickerItemContent.d.ts.map +0 -1
  77. package/dist/spectrum/picker/PickerItemContent.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"itemUtils.js","names":["isValidElement","Log","Item","Section","log","module","INVALID_ITEM_ERROR_MESSAGE","getItemKey","item","_item$item$key","_item$item","key","isSectionElement","node","type","isItemElement","isNormalizedItemsWithKeysList","Array","isArray","length","isItemOrSection","isNormalizedSection","maybeNormalizedSection","normalizeItemKey","itemOrSection","_itemOrSection$props$","props","title","undefined","textValue","children","normalizeTextValue","String","normalizeItem","debug","Error","items","normalizeItemList","filter","childItem","content","itemsOrSections","itemsArray","map","normalizeTooltipOptions","options","placement"],"sources":["../../../src/spectrum/utils/itemUtils.ts"],"sourcesContent":["import { isValidElement, Key, ReactElement, ReactNode } from 'react';\nimport { SpectrumPickerProps } from '@adobe/react-spectrum';\nimport type { ItemRenderer } from '@react-types/shared';\nimport Log from '@deephaven/log';\nimport { KeyedItem } from '@deephaven/utils';\nimport { Item, ItemProps, Section, SectionProps } from '../shared';\nimport { PopperOptions } from '../../popper';\n\nconst log = Log.module('itemUtils');\n\nexport const INVALID_ITEM_ERROR_MESSAGE =\n 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';\n\n/**\n * React Spectrum <Section> supports an `ItemRenderer` function as a child. The\n * DH picker makes use of this internally, but we don't want to support it as\n * an incoming prop.\n */\ntype SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {\n children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;\n};\n\ntype ItemElement = ReactElement<ItemProps<unknown>>;\nexport type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;\n\nexport type ItemElementOrPrimitive = number | string | boolean | ItemElement;\nexport type ItemOrSection = ItemElementOrPrimitive | SectionElement;\n\n/**\n * Augment the Spectrum selection key type to include boolean values.\n * Spectrum collection components already supports this, but the built in types\n * don't reflect it.\n */\nexport type ItemKey = Key | boolean;\n\n/**\n * Augment the Spectrum selection change handler type to include boolean keys.\n * Spectrum components already supports this, but the built in types don't\n * reflect it.\n */\nexport type ItemSelectionChangeHandler = (key: ItemKey) => void;\n\nexport interface NormalizedItemData {\n key?: ItemKey;\n content: ReactNode;\n textValue?: string;\n}\n\nexport interface NormalizedSectionData {\n key?: Key;\n title?: ReactNode;\n items: NormalizedItem[];\n}\n\n/**\n * Spectrum collection components support a variety of item types, including\n * strings, numbers, booleans, and more complex React elements. This type\n * represents a normalized form to make rendering items simpler and keep the\n * logic of transformation in separate util methods. It also adheres to the\n * `KeyedItem` interface to be compatible with Windowed data utils\n * (e.g. `useViewportData`).\n */\nexport type NormalizedItem = KeyedItem<NormalizedItemData, ItemKey | undefined>;\n\nexport type NormalizedSection = KeyedItem<\n NormalizedSectionData,\n Key | undefined\n>;\n\nexport type NormalizedSpectrumPickerProps = SpectrumPickerProps<NormalizedItem>;\n\nexport type TooltipOptions = { placement: PopperOptions['placement'] };\n\n/**\n * DH wrappers of Spectrum collection components use a normalized item that\n * includes a `key` prop and an optional `item` prop. This is mostly to support\n * Windowed data where items are created before their data has been loaded (data\n * gets set in the `item` prop). If data has loaded, return its `key`. If not,\n * return the top-level `key` on the normalized item.\n * @param item The normalized item or section\n * @returns The `key` of the item or section\n */\nexport function getItemKey<\n TItem extends NormalizedItem | NormalizedSection,\n TKey extends TItem extends NormalizedItem\n ? ItemKey | undefined\n : TItem extends NormalizedSection\n ? Key | undefined\n : undefined,\n>(item: TItem | null | undefined): TKey {\n return (item?.item?.key ?? item?.key) as TKey;\n}\n\n/**\n * Determine if a node is a Section element.\n * @param node The node to check\n * @returns True if the node is a Section element\n */\nexport function isSectionElement<T>(\n node: ReactNode\n): node is ReactElement<SectionProps<T>> {\n return isValidElement<SectionProps<T>>(node) && node.type === Section;\n}\n\n/**\n * Determine if a node is an Item element.\n * @param node The node to check\n * @returns True if the node is an Item element\n */\nexport function isItemElement<T>(\n node: ReactNode\n): node is ReactElement<ItemProps<T>> {\n return isValidElement<ItemProps<T>>(node) && node.type === Item;\n}\n\n/**\n * Determine if a node is an array containing normalized items with keys.\n * 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 with keys array\n */\nexport function isNormalizedItemsWithKeysList(\n node: ItemOrSection | ItemOrSection[] | (NormalizedItem | NormalizedSection)[]\n): node is (NormalizedItem | NormalizedSection)[] {\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(\n itemOrSection: ItemOrSection\n): NormalizedItem | NormalizedSection {\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 };\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 };\n}\n\n/**\n * Get normalized items from an item or array of items.\n * @param itemsOrSections An item or array of items\n * @returns An array of normalized items\n */\nexport function normalizeItemList(\n itemsOrSections: ItemOrSection | ItemOrSection[] | NormalizedItem[]\n): (NormalizedItem | NormalizedSection)[] {\n // If already normalized, just return as-is\n if (isNormalizedItemsWithKeysList(itemsOrSections)) {\n return itemsOrSections;\n }\n\n const itemsArray = 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\n * @returns TooltipOptions or null\n */\nexport function normalizeTooltipOptions(\n options?: boolean | TooltipOptions | null\n): TooltipOptions | null {\n if (options == null || options === false) {\n return null;\n }\n\n if (options === true) {\n return { placement: 'right' };\n }\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAsC,OAAO;AAGpE,OAAOC,GAAG,MAAM,gBAAgB;AAAC,SAExBC,IAAI,EAAaC,OAAO;AAGjC,IAAMC,GAAG,GAAGH,GAAG,CAACI,MAAM,CAAC,WAAW,CAAC;AAEnC,OAAO,IAAMC,0BAA0B,GACrC,yEAAyE;;AAE3E;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAOxBC,IAA8B,EAAQ;EAAA,IAAAC,cAAA,EAAAC,UAAA;EACtC,QAAAD,cAAA,GAAQD,IAAI,aAAJA,IAAI,wBAAAE,UAAA,GAAJF,IAAI,CAAEA,IAAI,cAAAE,UAAA,uBAAVA,UAAA,CAAYC,GAAG,cAAAF,cAAA,cAAAA,cAAA,GAAID,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,GAAG;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,IAAe,EACwB;EACvC,OAAO,aAAAb,cAAc,CAAkBa,IAAI,CAAC,IAAIA,IAAI,CAACC,IAAI,KAAKX,OAAO;AACvE;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASY,aAAaA,CA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,CAAC2B,SAAS,CAC1C,CAAqB;IAErB,OAAO;MACL/B,IAAI,EAAE;QAAEG,GAAG,EAAHA,IAAG;QAAEgB,KAAK;QAAES;MAAM;IAC5B,CAAC;EACH;EAEA,IAAMzB,GAAG,GAAGY,gBAAgB,CAACC,aAAa,CAAC;EAC3C,IAAMgB,OAAO,GAAGzB,aAAa,CAACS,aAAa,CAAC,GACxCA,aAAa,CAACE,KAAK,CAACI,QAAQ,GAC5BN,aAAa;EACjB,IAAMK,SAAS,GAAGE,kBAAkB,CAACP,aAAa,CAAC;EAEnD,OAAO;IACLhB,IAAI,EAAE;MAAEG,GAAG;MAAE6B,OAAO;MAAEX;IAAU;EAClC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,iBAAiBA,CAC/BI,eAAmE,EAC3B;EACxC;EACA,IAAIzB,6BAA6B,CAACyB,eAAe,CAAC,EAAE;IAClD,OAAOA,eAAe;EACxB;EAEA,IAAMC,UAAU,GAAGzB,KAAK,CAACC,OAAO,CAACuB,eAAe,CAAC,GAC7CA,eAAe,GACf,CAACA,eAAe,CAAC;EAErB,OAAOC,UAAU,CAACC,GAAG,CAACV,aAAa,CAAC;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASW,uBAAuBA,CACrCC,OAAyC,EAClB;EACvB,IAAIA,OAAO,IAAI,IAAI,IAAIA,OAAO,KAAK,KAAK,EAAE;IACxC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,KAAK,IAAI,EAAE;IACpB,OAAO;MAAEC,SAAS,EAAE;IAAQ,CAAC;EAC/B;EAEA,OAAOD,OAAO;AAChB"}
1
+ {"version":3,"file":"itemUtils.js","names":["isValidElement","Log","Item","Section","log","module","INVALID_ITEM_ERROR_MESSAGE","getItemKey","item","_item$item$key","_item$item","key","isSectionElement","node","type","isItemElement","isNormalizedItemsWithKeysList","Array","isArray","length","isItemOrSection","isNormalizedSection","maybeNormalizedSection","normalizeItemKey","itemOrSection","_itemOrSection$props$","props","title","undefined","textValue","children","normalizeTextValue","String","normalizeItem","debug","Error","items","normalizeItemList","filter","childItem","content","itemsOrSections","itemsArray","map","normalizeTooltipOptions","options","placement","arguments","itemSelectionToStringSet","itemKeys","Set"],"sources":["../../../src/spectrum/utils/itemUtils.ts"],"sourcesContent":["import { isValidElement, Key, ReactElement, ReactNode } from 'react';\nimport { SpectrumPickerProps } from '@adobe/react-spectrum';\nimport type { ItemRenderer } from '@react-types/shared';\nimport Log from '@deephaven/log';\nimport { KeyedItem, SelectionT } from '@deephaven/utils';\nimport { Item, ItemProps, Section, SectionProps } from '../shared';\nimport { PopperOptions } from '../../popper';\n\nconst log = Log.module('itemUtils');\n\nexport const INVALID_ITEM_ERROR_MESSAGE =\n 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';\n\n/**\n * React Spectrum <Section> supports an `ItemRenderer` function as a child. The\n * DH picker makes use of this internally, but we don't want to support it as\n * an incoming prop.\n */\ntype SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {\n children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;\n};\n\ntype ItemElement = ReactElement<ItemProps<unknown>>;\nexport type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;\n\nexport type ItemElementOrPrimitive = number | string | boolean | ItemElement;\nexport type ItemOrSection = ItemElementOrPrimitive | SectionElement;\n\n/**\n * Augment the Spectrum selection key type to include boolean values.\n * Spectrum collection components already supports this, but the built in types\n * don't reflect it.\n */\nexport type ItemKey = Key | boolean;\n\nexport type ItemSelection = SelectionT<ItemKey>;\n\n/**\n * Augment the Spectrum selection change handler type to include boolean keys.\n * Spectrum components already supports this, but the built in types don't\n * reflect it.\n */\nexport type ItemSelectionChangeHandler = (key: ItemKey) => void;\n\nexport interface NormalizedItemData {\n key?: ItemKey;\n content: ReactNode;\n textValue?: string;\n}\n\nexport interface NormalizedSectionData {\n key?: Key;\n title?: ReactNode;\n items: NormalizedItem[];\n}\n\n/**\n * Spectrum collection components support a variety of item types, including\n * strings, numbers, booleans, and more complex React elements. This type\n * represents a normalized form to make rendering items simpler and keep the\n * logic of transformation in separate util methods. It also adheres to the\n * `KeyedItem` interface to be compatible with Windowed data utils\n * (e.g. `useViewportData`).\n */\nexport type NormalizedItem = KeyedItem<NormalizedItemData, ItemKey | undefined>;\n\nexport type NormalizedSection = KeyedItem<\n NormalizedSectionData,\n Key | undefined\n>;\n\nexport type NormalizedItemOrSection<TItemOrSection extends ItemOrSection> =\n TItemOrSection extends SectionElement ? NormalizedSection : NormalizedItem;\n\nexport type NormalizedSpectrumPickerProps = SpectrumPickerProps<NormalizedItem>;\n\nexport type TooltipOptions = { placement: PopperOptions['placement'] };\n\n/**\n * DH wrappers of Spectrum collection components use a normalized item that\n * includes a `key` prop and an optional `item` prop. This is mostly to support\n * Windowed data where items are created before their data has been loaded (data\n * gets set in the `item` prop). If data has loaded, return its `key`. If not,\n * return the top-level `key` on the normalized item.\n * @param item The normalized item or section\n * @returns The `key` of the item or section\n */\nexport function getItemKey<\n TItem extends NormalizedItem | NormalizedSection,\n TKey extends TItem extends NormalizedItem\n ? ItemKey | undefined\n : TItem extends NormalizedSection\n ? Key | undefined\n : undefined,\n>(item: TItem | null | undefined): TKey {\n return (item?.item?.key ?? item?.key) as TKey;\n}\n\n/**\n * Determine if a node is a Section element.\n * @param node The node to check\n * @returns True if the node is a Section element\n */\nexport function isSectionElement<T>(\n node: ReactNode\n): node is ReactElement<SectionProps<T>> {\n return isValidElement<SectionProps<T>>(node) && node.type === Section;\n}\n\n/**\n * Determine if a node is an Item element.\n * @param node The node to check\n * @returns True if the node is an Item element\n */\nexport function isItemElement<T>(\n node: ReactNode\n): node is ReactElement<ItemProps<T>> {\n return isValidElement<ItemProps<T>>(node) && node.type === Item;\n}\n\n/**\n * Determine if a node is an array containing normalized items or sections with\n * keys. Note that this only checks the first node in the array.\n * @param node The node to check\n * @returns True if the node is a normalized item or section with keys array\n */\nexport function isNormalizedItemsWithKeysList<\n TItemOrSection extends ItemOrSection,\n>(\n node:\n | TItemOrSection\n | TItemOrSection[]\n | NormalizedItemOrSection<TItemOrSection>[]\n): node is NormalizedItemOrSection<TItemOrSection>[] {\n if (!Array.isArray(node)) {\n return false;\n }\n\n if (node.length === 0) {\n return true;\n }\n\n return !isItemOrSection(node[0]) && 'key' in node[0];\n}\n\n/**\n * Determine if an object is a normalized section.\n * @param maybeNormalizedSection The object to check\n * @returns True if the object is a normalized section\n */\nexport function isNormalizedSection(\n maybeNormalizedSection: NormalizedItem | NormalizedSection\n): maybeNormalizedSection is NormalizedSection {\n return (\n maybeNormalizedSection.item != null &&\n 'items' in maybeNormalizedSection.item\n );\n}\n\n/**\n * Determine if a node is an item or section. Valid types include strings,\n * numbers, booleans, Item elements, and Section elements.\n * @param node The node to check\n * @returns True if the node is an item or section\n */\nexport function isItemOrSection(node: ReactNode): node is ItemOrSection {\n return (\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean' ||\n isItemElement(node) ||\n isSectionElement(node)\n );\n}\n\n/**\n * Determine the `key` of an item or section.\n * @param itemOrSection The item or section\n * @returns A `ItemKey` for the item or undefined if a key can't be determined\n */\nfunction normalizeItemKey(item: ItemElementOrPrimitive): ItemKey | undefined;\nfunction normalizeItemKey(section: SectionElement): Key | undefined;\nfunction normalizeItemKey(\n itemOrSection: ItemElementOrPrimitive | SectionElement\n): Key | ItemKey | undefined {\n // string, number, or boolean\n if (typeof itemOrSection !== 'object') {\n return itemOrSection;\n }\n\n // If `key` prop is explicitly set\n if (itemOrSection.key != null) {\n return itemOrSection.key;\n }\n\n // Section element\n if (isSectionElement(itemOrSection)) {\n return typeof itemOrSection.props.title === 'string'\n ? itemOrSection.props.title\n : undefined;\n }\n\n // Item element\n return (\n itemOrSection.props.textValue ??\n (typeof itemOrSection.props.children === 'string'\n ? itemOrSection.props.children\n : undefined)\n );\n}\n\n/**\n * Get a normalized `textValue` for an item ensuring it is a string.\n * @param item The item\n * @returns A string `textValue` for the item\n */\nfunction normalizeTextValue(item: ItemElementOrPrimitive): string | undefined {\n if (typeof item !== 'object') {\n return String(item);\n }\n\n if (item.props.textValue != null) {\n return item.props.textValue;\n }\n\n if (typeof item.props.children === 'string') {\n return item.props.children;\n }\n\n return undefined;\n}\n\n/**\n * Normalize an item or section to an object form.\n * @param itemOrSection item to normalize\n * @returns NormalizedItem or NormalizedSection object\n */\nfunction normalizeItem<TItemOrSection extends ItemOrSection>(\n itemOrSection: TItemOrSection\n): NormalizedItemOrSection<TItemOrSection> {\n if (!isItemOrSection(itemOrSection)) {\n log.debug(INVALID_ITEM_ERROR_MESSAGE, itemOrSection);\n throw new Error(INVALID_ITEM_ERROR_MESSAGE);\n }\n\n if (isSectionElement(itemOrSection)) {\n const key = normalizeItemKey(itemOrSection);\n const { title } = itemOrSection.props;\n\n const items = normalizeItemList(itemOrSection.props.children).filter(\n // We don't support nested section elements\n childItem => !isSectionElement(childItem)\n ) as NormalizedItem[];\n\n return {\n item: { key, title, items },\n } as NormalizedItemOrSection<TItemOrSection>;\n }\n\n const key = normalizeItemKey(itemOrSection);\n const content = isItemElement(itemOrSection)\n ? itemOrSection.props.children\n : itemOrSection;\n const textValue = normalizeTextValue(itemOrSection);\n\n return {\n item: { key, content, textValue },\n } as NormalizedItemOrSection<TItemOrSection>;\n}\n\n/**\n * Normalize an item or section or a list of items or sections.\n * @param itemsOrSections An item or section or array of items or sections\n * @returns An array of normalized items or sections\n */\nexport function normalizeItemList<TItemOrSection extends ItemOrSection>(\n itemsOrSections: TItemOrSection | TItemOrSection[] | NormalizedItem[]\n): NormalizedItemOrSection<TItemOrSection>[] {\n // If already normalized, just return as-is\n if (isNormalizedItemsWithKeysList(itemsOrSections)) {\n return itemsOrSections as NormalizedItemOrSection<TItemOrSection>[];\n }\n\n const itemsArray: TItemOrSection[] = Array.isArray(itemsOrSections)\n ? itemsOrSections\n : [itemsOrSections];\n\n return itemsArray.map(normalizeItem);\n}\n\n/**\n * Returns a TooltipOptions object or null if options is false or null.\n * @param options Tooltip options\n * @param placement Default placement for the tooltip if `options` is set\n * explicitly to `true`\n * @returns TooltipOptions or null\n */\nexport function normalizeTooltipOptions(\n options?: boolean | TooltipOptions | null,\n placement: TooltipOptions['placement'] = 'right'\n): TooltipOptions | null {\n if (options == null || options === false) {\n return null;\n }\n\n if (options === true) {\n return { placement };\n }\n\n return options;\n}\n\n/**\n * Convert a selection of `ItemKey`s to a selection of strings.\n * @param itemKeys The selection of `ItemKey`s\n * @returns The selection of strings\n */\nexport function itemSelectionToStringSet(\n itemKeys?: 'all' | Iterable<ItemKey>\n): undefined | 'all' | Set<string> {\n if (itemKeys == null || itemKeys === 'all') {\n return itemKeys as undefined | 'all';\n }\n\n return new Set([...itemKeys].map(String));\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAsC,OAAO;AAGpE,OAAOC,GAAG,MAAM,gBAAgB;AAAC,SAExBC,IAAI,EAAaC,OAAO;AAGjC,IAAMC,GAAG,GAAGH,GAAG,CAACI,MAAM,CAAC,WAAW,CAAC;AAEnC,OAAO,IAAMC,0BAA0B,GACrC,yEAAyE;;AAE3E;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAOxBC,IAA8B,EAAQ;EAAA,IAAAC,cAAA,EAAAC,UAAA;EACtC,QAAAD,cAAA,GAAQD,IAAI,aAAJA,IAAI,wBAAAE,UAAA,GAAJF,IAAI,CAAEA,IAAI,cAAAE,UAAA,uBAAVA,UAAA,CAAYC,GAAG,cAAAF,cAAA,cAAAA,cAAA,GAAID,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEG,GAAG;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,IAAe,EACwB;EACvC,OAAO,aAAAb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D,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,wBAAwBA,CACtCC,QAAoC,EACH;EACjC,IAAIA,QAAQ,IAAI,IAAI,IAAIA,QAAQ,KAAK,KAAK,EAAE;IAC1C,OAAOA,QAAQ;EACjB;EAEA,OAAO,IAAIC,GAAG,CAAC,CAAC,GAAGD,QAAQ,CAAC,CAACN,GAAG,CAACX,MAAM,CAAC,CAAC;AAC3C"}
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { NormalizedItem, TooltipOptions } from './itemUtils';
3
+ /**
4
+ * Returns a render function that can be used to render a normalized item in
5
+ * collection components.
6
+ * @param tooltipOptions Tooltip options to use when rendering the item
7
+ * @returns Render function for normalized items
8
+ */
9
+ export declare function useRenderNormalizedItem(tooltipOptions: TooltipOptions | null): (normalizedItem: NormalizedItem) => JSX.Element;
10
+ export default useRenderNormalizedItem;
11
+ //# sourceMappingURL=useRenderNormalizedItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderNormalizedItem.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAc,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,cAAc,GAAG,IAAI,GACpC,CAAC,cAAc,EAAE,cAAc,KAAK,GAAG,CAAC,OAAO,CA6BjD;AAED,eAAe,uBAAuB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { useCallback } from 'react';
2
+ import { ItemContent } from "../ItemContent.js";
3
+ import { Item } from "../shared.js";
4
+ import { getItemKey } from "./itemUtils.js";
5
+ /**
6
+ * Returns a render function that can be used to render a normalized item in
7
+ * collection components.
8
+ * @param tooltipOptions Tooltip options to use when rendering the item
9
+ * @returns Render function for normalized items
10
+ */
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ export function useRenderNormalizedItem(tooltipOptions) {
13
+ return useCallback(normalizedItem => {
14
+ var _normalizedItem$item$, _normalizedItem$item, _normalizedItem$item$2, _normalizedItem$item2;
15
+ 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 : '';
18
+ return /*#__PURE__*/_jsx(Item
19
+ // Note that setting the `key` prop explicitly on `Item` elements
20
+ // causes the picker to expect `selectedKey` and `defaultSelectedKey`
21
+ // to be strings. It also passes the stringified value of the key to
22
+ // `onSelectionChange` handlers` regardless of the actual type of the
23
+ // key. We can't really get around setting in order to support Windowed
24
+ // data, so we'll need to do some manual conversion of keys to strings
25
+ // in other components that use this hook.
26
+ , {
27
+ // The `textValue` prop gets used to provide the content of `<option>`
28
+ // elements that back the Spectrum Picker. These are not visible in the UI,
29
+ // but are used for accessibility purposes, so we set to an arbitrary
30
+ // 'Empty' value so that they are not empty strings.
31
+ textValue: textValue === '' ? 'Empty' : textValue,
32
+ children: /*#__PURE__*/_jsx(ItemContent, {
33
+ tooltipOptions: tooltipOptions,
34
+ children: content
35
+ })
36
+ }, key);
37
+ }, [tooltipOptions]);
38
+ }
39
+ export default useRenderNormalizedItem;
40
+ //# sourceMappingURL=useRenderNormalizedItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderNormalizedItem.js","names":["useCallback","ItemContent","Item","getItemKey","jsx","_jsx","useRenderNormalizedItem","tooltipOptions","normalizedItem","_normalizedItem$item$","_normalizedItem$item","_normalizedItem$item$2","_normalizedItem$item2","key","content","item","textValue","children"],"sources":["../../../src/spectrum/utils/useRenderNormalizedItem.tsx"],"sourcesContent":["import { Key, useCallback } from 'react';\nimport { ItemContent } from '../ItemContent';\nimport { Item } from '../shared';\nimport { getItemKey, NormalizedItem, TooltipOptions } from './itemUtils';\n\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 // 'Empty' value so that they are not empty strings.\n textValue={textValue === '' ? 'Empty' : textValue}\n >\n <ItemContent tooltipOptions={tooltipOptions}>{content}</ItemContent>\n </Item>\n );\n },\n [tooltipOptions]\n );\n}\n\nexport default useRenderNormalizedItem;\n"],"mappings":"AAAA,SAAcA,WAAW,QAAQ,OAAO;AAAC,SAChCC,WAAW;AAAA,SACXC,IAAI;AAAA,SACJC,UAAU;AAEnB;AACA;AACA;AACA;AACA;AACA;AALA,SAAAC,GAAA,IAAAC,IAAA;AAMA,OAAO,SAASC,uBAAuBA,CACrCC,cAAqC,EACY;EACjD,OAAOP,WAAW,CACfQ,cAA8B,IAAK;IAAA,IAAAC,qBAAA,EAAAC,oBAAA,EAAAC,sBAAA,EAAAC,qBAAA;IAClC,IAAMC,GAAG,GAAGV,UAAU,CAACK,cAAc,CAAC;IACtC,IAAMM,OAAO,IAAAL,qBAAA,IAAAC,oBAAA,GAAGF,cAAc,CAACO,IAAI,cAAAL,oBAAA,uBAAnBA,oBAAA,CAAqBI,OAAO,cAAAL,qBAAA,cAAAA,qBAAA,GAAI,EAAE;IAClD,IAAMO,SAAS,IAAAL,sBAAA,IAAAC,qBAAA,GAAGJ,cAAc,CAACO,IAAI,cAAAH,qBAAA,uBAAnBA,qBAAA,CAAqBI,SAAS,cAAAL,sBAAA,cAAAA,sBAAA,GAAI,EAAE;IAEtD,oBACEN,IAAA,CAACH;IACC;IACA;IACA;IACA;IACA;IACA;IACA;IAAA;MAEA;MACA;MACA;MACA;MACAc,SAAS,EAAEA,SAAS,KAAK,EAAE,GAAG,OAAO,GAAGA,SAAU;MAAAC,QAAA,eAElDZ,IAAA,CAACJ,WAAW;QAACM,cAAc,EAAEA,cAAe;QAAAU,QAAA,EAAEH;MAAO,CAAc;IAAC,GAP/DD,GAQD,CAAC;EAEX,CAAC,EACD,CAACN,cAAc,CACjB,CAAC;AACH;AAEA,eAAeD,uBAAuB"}
@@ -0,0 +1,43 @@
1
+ import { Key } from 'react';
2
+ import { ItemKey, ItemSelection, NormalizedItem } from './itemUtils';
3
+ export interface UseStringifiedMultiSelectionOptions {
4
+ normalizedItems: NormalizedItem[];
5
+ selectedKeys?: 'all' | Iterable<ItemKey>;
6
+ defaultSelectedKeys?: 'all' | Iterable<ItemKey>;
7
+ disabledKeys?: Iterable<ItemKey>;
8
+ /**
9
+ * Handler that is called when the selection change.
10
+ * Note that under the hood, this is just an alias for Spectrum's
11
+ * `onSelectionChange`. We are renaming for better consistency with other
12
+ * components.
13
+ */
14
+ onChange?: (keys: ItemSelection) => void;
15
+ }
16
+ export interface UseStringifiedMultiSelectionResult {
17
+ /** Stringified selection keys */
18
+ selectedStringKeys?: 'all' | Set<Key>;
19
+ /** Stringified default selection keys */
20
+ defaultSelectedStringKeys?: 'all' | Set<Key>;
21
+ /** Stringified disabled keys */
22
+ disabledStringKeys?: 'all' | Set<Key>;
23
+ /** Handler that is called when the string key selections change */
24
+ onStringSelectionChange: (keys: 'all' | Set<Key>) => void;
25
+ }
26
+ /**
27
+ * Spectrum collection components treat keys as strings if the `key` prop is
28
+ * explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,
29
+ * we need to ensure that keys are strings in order for selection to work. We
30
+ * then need to convert back to the original key types in the onChange handler.
31
+ * This hook encapsulates converting to and from strings so that keys can match
32
+ * the original key type.
33
+ * @param normalizedItems The normalized items to select from.
34
+ * @param selectedKeys The currently selected keys in the collection.
35
+ * @param defaultSelectedKeys The initial selected keys in the collection.
36
+ * @param disabledKeys The currently disabled keys in the collection.
37
+ * @param onChange Handler that is called when the selection changes.
38
+ * @returns UseStringifiedMultiSelectionResult with stringified key sets and
39
+ * string key selection change handler.
40
+ */
41
+ export declare function useStringifiedMultiSelection({ normalizedItems, defaultSelectedKeys, disabledKeys, selectedKeys, onChange, }: UseStringifiedMultiSelectionOptions): UseStringifiedMultiSelectionResult;
42
+ export default useStringifiedMultiSelection;
43
+ //# sourceMappingURL=useStringifiedMultiSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStringifiedMultiSelection.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/useStringifiedMultiSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,OAAO,CAAC;AAClD,OAAO,EAEL,OAAO,EACP,aAAa,EAEb,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,mCAAmC;IAClD,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,YAAY,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,mBAAmB,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChD,YAAY,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,kCAAkC;IACjD,iCAAiC;IACjC,kBAAkB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACtC,yCAAyC;IACzC,yBAAyB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,gCAAgC;IAChC,kBAAkB,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACtC,mEAAmE;IACnE,uBAAuB,EAAE,CAAC,IAAI,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CAC3D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,EAAE,mCAAmC,GAAG,kCAAkC,CA0C1E;AAED,eAAe,4BAA4B,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { getItemKey, itemSelectionToStringSet } from "./itemUtils.js";
3
+ /**
4
+ * Spectrum collection components treat keys as strings if the `key` prop is
5
+ * explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,
6
+ * we need to ensure that keys are strings in order for selection to work. We
7
+ * then need to convert back to the original key types in the onChange handler.
8
+ * This hook encapsulates converting to and from strings so that keys can match
9
+ * the original key type.
10
+ * @param normalizedItems The normalized items to select from.
11
+ * @param selectedKeys The currently selected keys in the collection.
12
+ * @param defaultSelectedKeys The initial selected keys in the collection.
13
+ * @param disabledKeys The currently disabled keys in the collection.
14
+ * @param onChange Handler that is called when the selection changes.
15
+ * @returns UseStringifiedMultiSelectionResult with stringified key sets and
16
+ * string key selection change handler.
17
+ */
18
+ export function useStringifiedMultiSelection(_ref) {
19
+ var {
20
+ normalizedItems,
21
+ defaultSelectedKeys,
22
+ disabledKeys,
23
+ selectedKeys,
24
+ onChange
25
+ } = _ref;
26
+ var selectedStringKeys = useMemo(() => itemSelectionToStringSet(selectedKeys), [selectedKeys]);
27
+ var defaultSelectedStringKeys = useMemo(() => itemSelectionToStringSet(defaultSelectedKeys), [defaultSelectedKeys]);
28
+ var disabledStringKeys = useMemo(() => itemSelectionToStringSet(disabledKeys), [disabledKeys]);
29
+ var onStringSelectionChange = useCallback(keys => {
30
+ if (keys === 'all') {
31
+ onChange === null || onChange === void 0 ? void 0 : onChange('all');
32
+ return;
33
+ }
34
+ var actualKeys = new Set();
35
+ normalizedItems.forEach(item => {
36
+ if (keys.has(String(getItemKey(item)))) {
37
+ actualKeys.add(getItemKey(item));
38
+ }
39
+ });
40
+ onChange === null || onChange === void 0 ? void 0 : onChange(actualKeys);
41
+ }, [normalizedItems, onChange]);
42
+ return {
43
+ selectedStringKeys,
44
+ defaultSelectedStringKeys,
45
+ disabledStringKeys,
46
+ onStringSelectionChange
47
+ };
48
+ }
49
+ export default useStringifiedMultiSelection;
50
+ //# sourceMappingURL=useStringifiedMultiSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStringifiedMultiSelection.js","names":["useCallback","useMemo","getItemKey","itemSelectionToStringSet","useStringifiedMultiSelection","_ref","normalizedItems","defaultSelectedKeys","disabledKeys","selectedKeys","onChange","selectedStringKeys","defaultSelectedStringKeys","disabledStringKeys","onStringSelectionChange","keys","actualKeys","Set","forEach","item","has","String","add"],"sources":["../../../src/spectrum/utils/useStringifiedMultiSelection.ts"],"sourcesContent":["import { Key, useCallback, useMemo } from 'react';\nimport {\n getItemKey,\n ItemKey,\n ItemSelection,\n itemSelectionToStringSet,\n NormalizedItem,\n} from './itemUtils';\n\nexport interface UseStringifiedMultiSelectionOptions {\n normalizedItems: NormalizedItem[];\n selectedKeys?: 'all' | Iterable<ItemKey>;\n defaultSelectedKeys?: 'all' | Iterable<ItemKey>;\n disabledKeys?: Iterable<ItemKey>;\n /**\n * Handler that is called when the selection change.\n * Note that under the hood, this is just an alias for Spectrum's\n * `onSelectionChange`. We are renaming for better consistency with other\n * components.\n */\n onChange?: (keys: ItemSelection) => void;\n}\n\nexport interface UseStringifiedMultiSelectionResult {\n /** Stringified selection keys */\n selectedStringKeys?: 'all' | Set<Key>;\n /** Stringified default selection keys */\n defaultSelectedStringKeys?: 'all' | Set<Key>;\n /** Stringified disabled keys */\n disabledStringKeys?: 'all' | Set<Key>;\n /** Handler that is called when the string key selections change */\n onStringSelectionChange: (keys: 'all' | Set<Key>) => void;\n}\n\n/**\n * Spectrum collection components treat keys as strings if the `key` prop is\n * explicitly set on `Item` elements. Since we do this in `useRenderNormalizedItem`,\n * we need to ensure that keys are strings in order for selection to work. We\n * then need to convert back to the original key types in the onChange handler.\n * This hook encapsulates converting to and from strings so that keys can match\n * the original key type.\n * @param normalizedItems The normalized items to select from.\n * @param selectedKeys The currently selected keys in the collection.\n * @param defaultSelectedKeys The initial selected keys in the collection.\n * @param disabledKeys The currently disabled keys in the collection.\n * @param onChange Handler that is called when the selection changes.\n * @returns UseStringifiedMultiSelectionResult with stringified key sets and\n * string key selection change handler.\n */\nexport function useStringifiedMultiSelection({\n normalizedItems,\n defaultSelectedKeys,\n disabledKeys,\n selectedKeys,\n onChange,\n}: UseStringifiedMultiSelectionOptions): UseStringifiedMultiSelectionResult {\n const selectedStringKeys = useMemo(\n () => itemSelectionToStringSet(selectedKeys),\n [selectedKeys]\n );\n\n const defaultSelectedStringKeys = useMemo(\n () => itemSelectionToStringSet(defaultSelectedKeys),\n [defaultSelectedKeys]\n );\n\n const disabledStringKeys = useMemo(\n () => itemSelectionToStringSet(disabledKeys),\n [disabledKeys]\n );\n\n const onStringSelectionChange = useCallback(\n (keys: 'all' | Set<Key>) => {\n if (keys === 'all') {\n onChange?.('all');\n return;\n }\n\n const actualKeys = new Set<ItemKey>();\n\n normalizedItems.forEach(item => {\n if (keys.has(String(getItemKey(item)))) {\n actualKeys.add(getItemKey(item));\n }\n });\n\n onChange?.(actualKeys);\n },\n [normalizedItems, onChange]\n );\n\n return {\n selectedStringKeys,\n defaultSelectedStringKeys,\n disabledStringKeys,\n onStringSelectionChange,\n };\n}\n\nexport default useStringifiedMultiSelection;\n"],"mappings":"AAAA,SAAcA,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAAC,SAEhDC,UAAU,EAGVC,wBAAwB;AA6B1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,4BAA4BA,CAAAC,IAAA,EAMgC;EAAA,IAN/B;IAC3CC,eAAe;IACfC,mBAAmB;IACnBC,YAAY;IACZC,YAAY;IACZC;EACmC,CAAC,GAAAL,IAAA;EACpC,IAAMM,kBAAkB,GAAGV,OAAO,CAChC,MAAME,wBAAwB,CAACM,YAAY,CAAC,EAC5C,CAACA,YAAY,CACf,CAAC;EAED,IAAMG,yBAAyB,GAAGX,OAAO,CACvC,MAAME,wBAAwB,CAACI,mBAAmB,CAAC,EACnD,CAACA,mBAAmB,CACtB,CAAC;EAED,IAAMM,kBAAkB,GAAGZ,OAAO,CAChC,MAAME,wBAAwB,CAACK,YAAY,CAAC,EAC5C,CAACA,YAAY,CACf,CAAC;EAED,IAAMM,uBAAuB,GAAGd,WAAW,CACxCe,IAAsB,IAAK;IAC1B,IAAIA,IAAI,KAAK,KAAK,EAAE;MAClBL,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAG,KAAK,CAAC;MACjB;IACF;IAEA,IAAMM,UAAU,GAAG,IAAIC,GAAG,CAAU,CAAC;IAErCX,eAAe,CAACY,OAAO,CAACC,IAAI,IAAI;MAC9B,IAAIJ,IAAI,CAACK,GAAG,CAACC,MAAM,CAACnB,UAAU,CAACiB,IAAI,CAAC,CAAC,CAAC,EAAE;QACtCH,UAAU,CAACM,GAAG,CAACpB,UAAU,CAACiB,IAAI,CAAC,CAAC;MAClC;IACF,CAAC,CAAC;IAEFT,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAGM,UAAU,CAAC;EACxB,CAAC,EACD,CAACV,eAAe,EAAEI,QAAQ,CAC5B,CAAC;EAED,OAAO;IACLC,kBAAkB;IAClBC,yBAAyB;IACzBC,kBAAkB;IAClBC;EACF,CAAC;AACH;AAEA,eAAeV,4BAA4B"}
@@ -7,4 +7,5 @@ export * from './ThemeUtils';
7
7
  export * from './useTheme';
8
8
  export * from './Logo';
9
9
  export * from './colorUtils';
10
+ export * from './useSpectrumThemeProvider';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/theme/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,4BAA4B,CAAC"}
@@ -7,4 +7,5 @@ export * from "./ThemeUtils.js";
7
7
  export * from "./useTheme.js";
8
8
  export * from "./Logo.js";
9
9
  export * from "./colorUtils.js";
10
+ export * from "./useSpectrumThemeProvider.js";
10
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/theme/index.ts"],"sourcesContent":["export * from './theme-dark';\nexport * from './theme-light';\nexport * from './ThemeModel';\nexport * from './ThemePicker';\nexport * from './ThemeProvider';\nexport * from './ThemeUtils';\nexport * from './useTheme';\nexport * from './Logo';\nexport * from './colorUtils';\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/theme/index.ts"],"sourcesContent":["export * from './theme-dark';\nexport * from './theme-light';\nexport * from './ThemeModel';\nexport * from './ThemePicker';\nexport * from './ThemeProvider';\nexport * from './ThemeUtils';\nexport * from './useTheme';\nexport * from './Logo';\nexport * from './colorUtils';\nexport * from './useSpectrumThemeProvider';\n"],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { useProvider } from '@adobe/react-spectrum';
2
+ export declare const useSpectrumThemeProvider: typeof useProvider;
3
+ export default useSpectrumThemeProvider;
4
+ //# sourceMappingURL=useSpectrumThemeProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSpectrumThemeProvider.d.ts","sourceRoot":"","sources":["../../src/theme/useSpectrumThemeProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,eAAO,MAAM,wBAAwB,oBAAc,CAAC;AAEpD,eAAe,wBAAwB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { useProvider } from '@adobe/react-spectrum';
2
+ export var useSpectrumThemeProvider = useProvider;
3
+ export default useSpectrumThemeProvider;
4
+ //# sourceMappingURL=useSpectrumThemeProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSpectrumThemeProvider.js","names":["useProvider","useSpectrumThemeProvider"],"sources":["../../src/theme/useSpectrumThemeProvider.ts"],"sourcesContent":["import { useProvider } from '@adobe/react-spectrum';\n\nexport const useSpectrumThemeProvider = useProvider;\n\nexport default useSpectrumThemeProvider;\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,uBAAuB;AAEnD,OAAO,IAAMC,wBAAwB,GAAGD,WAAW;AAEnD,eAAeC,wBAAwB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deephaven/components",
3
- "version": "0.72.1-beta.5+01c2a064",
3
+ "version": "0.73.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.72.1-beta.5+01c2a064",
29
- "@deephaven/log": "^0.72.1-beta.5+01c2a064",
30
- "@deephaven/react-hooks": "^0.72.1-beta.5+01c2a064",
31
- "@deephaven/utils": "^0.72.1-beta.5+01c2a064",
28
+ "@deephaven/icons": "^0.73.0",
29
+ "@deephaven/log": "^0.73.0",
30
+ "@deephaven/react-hooks": "^0.73.0",
31
+ "@deephaven/utils": "^0.73.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.72.1-beta.5+01c2a064"
58
+ "@deephaven/mocks": "^0.73.0"
59
59
  },
60
60
  "files": [
61
61
  "dist",
@@ -69,5 +69,5 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
- "gitHead": "01c2a064f287638382f0f7fe474098393b73b9ca"
72
+ "gitHead": "9e9e272cee02bc7b2c7cda19a00bf55385a0cffb"
73
73
  }
@@ -1,11 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export interface PickerItemContentProps {
3
- children: ReactNode;
4
- }
5
- /**
6
- * Picker item content. Text content will be wrapped in a Spectrum Text
7
- * component with ellipsis overflow handling.
8
- */
9
- export declare function PickerItemContent({ children: content, }: PickerItemContentProps): JSX.Element | null;
10
- export default PickerItemContent;
11
- //# sourceMappingURL=PickerItemContent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PickerItemContent.d.ts","sourceRoot":"","sources":["../../../src/spectrum/picker/PickerItemContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA0C,SAAS,EAAE,MAAM,OAAO,CAAC;AAM1E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EAAE,OAAO,GAClB,EAAE,sBAAsB,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAyC7C;AAED,eAAe,iBAAiB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PickerItemContent.js","names":["Children","cloneElement","isValidElement","Text","cl","isElementOfType","stylesCommon","jsx","_jsx","Fragment","_Fragment","PickerItemContent","_ref","children","content","String","Array","isArray","map","el","i","_objectSpread","props","UNSAFE_className","spectrumEllipsis"],"sources":["../../../src/spectrum/picker/PickerItemContent.tsx"],"sourcesContent":["import { Children, cloneElement, isValidElement, ReactNode } from 'react';\nimport { Text } from '@adobe/react-spectrum';\nimport cl from 'classnames';\nimport { isElementOfType } from '@deephaven/react-hooks';\nimport stylesCommon from '../../SpectrumComponent.module.scss';\n\nexport interface PickerItemContentProps {\n children: ReactNode;\n}\n\n/**\n * Picker item content. Text content will be wrapped in a Spectrum Text\n * component with ellipsis overflow handling.\n */\nexport function PickerItemContent({\n children: content,\n}: PickerItemContentProps): JSX.Element | null {\n if (isValidElement(content)) {\n return content;\n }\n\n /* eslint-disable no-param-reassign */\n if (content === '') {\n // Prevent the item height from collapsing when the content is empty\n content = '\\xa0'; // Non-breaking space\n } else if (typeof content === 'boolean') {\n // Boolean values need to be stringified to render\n content = String(content);\n } else if (Array.isArray(content)) {\n // For cases where there are multiple `Text` children, add a css class to\n // handle overflow. The primary use case for multiple text nodes is when a\n // description is provided for an item. e.g.\n // <Item textValue=\"Some Text\">\n // <SomeIcon />\n // <Text>Some Label</Text>\n // <Text slot=\"description\">Some Description</Text>\n // </Item>\n content = Children.map(content, (el, i) =>\n isElementOfType(el, Text)\n ? cloneElement(el, {\n ...el.props,\n UNSAFE_className: cl(\n el.props.UNSAFE_className,\n stylesCommon.spectrumEllipsis\n ),\n })\n : el\n );\n }\n /* eslint-enable no-param-reassign */\n\n return typeof content === 'string' || typeof content === 'number' ? (\n <Text UNSAFE_className={stylesCommon.spectrumEllipsis}>{content}</Text>\n ) : (\n // eslint-disable-next-line react/jsx-no-useless-fragment\n <>{content}</>\n );\n}\n\nexport default PickerItemContent;\n"],"mappings":";;;;;AAAA,SAASA,QAAQ,EAAEC,YAAY,EAAEC,cAAc,QAAmB,OAAO;AACzE,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,OAAOC,EAAE,MAAM,YAAY;AAC3B,SAASC,eAAe,QAAQ,wBAAwB;AAAC,OAClDC,YAAY;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAMnB;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAAC,IAAA,EAEc;EAAA,IAFb;IAChCC,QAAQ,EAAEC;EACY,CAAC,GAAAF,IAAA;EACvB,kBAAIV,cAAc,CAACY,OAAO,CAAC,EAAE;IAC3B,OAAOA,OAAO;EAChB;;EAEA;EACA,IAAIA,OAAO,KAAK,EAAE,EAAE;IAClB;IACAA,OAAO,GAAG,MAAM,CAAC,CAAC;EACpB,CAAC,MAAM,IAAI,OAAOA,OAAO,KAAK,SAAS,EAAE;IACvC;IACAA,OAAO,GAAGC,MAAM,CAACD,OAAO,CAAC;EAC3B,CAAC,MAAM,IAAIE,KAAK,CAACC,OAAO,CAACH,OAAO,CAAC,EAAE;IACjC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAA,OAAO,GAAGd,QAAQ,CAACkB,GAAG,CAACJ,OAAO,EAAE,CAACK,EAAE,EAAEC,CAAC,KACpCf,eAAe,CAACc,EAAE,EAAEhB,IAAI,CAAC,gBACrBF,YAAY,CAACkB,EAAE,EAAAE,aAAA,CAAAA,a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