@deephaven/components 0.72.1-xcomponent.2 → 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 (93) hide show
  1. package/dist/Button.d.ts +1 -1
  2. package/dist/Select.d.ts +1 -1
  3. package/dist/index.d.ts +0 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +0 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/shortcuts/GlobalShortcuts.d.ts +1 -0
  8. package/dist/shortcuts/GlobalShortcuts.d.ts.map +1 -1
  9. package/dist/shortcuts/GlobalShortcuts.js +7 -0
  10. package/dist/shortcuts/GlobalShortcuts.js.map +1 -1
  11. package/dist/spectrum/Heading.d.ts +4 -1
  12. package/dist/spectrum/Heading.d.ts.map +1 -1
  13. package/dist/spectrum/Heading.js +5 -3
  14. package/dist/spectrum/Heading.js.map +1 -1
  15. package/dist/spectrum/ItemContent.d.ts +15 -0
  16. package/dist/spectrum/ItemContent.d.ts.map +1 -0
  17. package/dist/spectrum/{picker/PickerItemContent.js → ItemContent.js} +42 -18
  18. package/dist/spectrum/ItemContent.js.map +1 -0
  19. package/dist/spectrum/ItemTooltip.d.ts +12 -0
  20. package/dist/spectrum/ItemTooltip.d.ts.map +1 -0
  21. package/dist/spectrum/ItemTooltip.js +30 -0
  22. package/dist/spectrum/ItemTooltip.js.map +1 -0
  23. package/dist/spectrum/Text.d.ts +4 -1
  24. package/dist/spectrum/Text.d.ts.map +1 -1
  25. package/dist/spectrum/Text.js +5 -4
  26. package/dist/spectrum/Text.js.map +1 -1
  27. package/dist/spectrum/View.d.ts +4 -1
  28. package/dist/spectrum/View.d.ts.map +1 -1
  29. package/dist/spectrum/View.js +5 -3
  30. package/dist/spectrum/View.js.map +1 -1
  31. package/dist/spectrum/collections.d.ts +1 -1
  32. package/dist/spectrum/collections.d.ts.map +1 -1
  33. package/dist/spectrum/collections.js +1 -1
  34. package/dist/spectrum/collections.js.map +1 -1
  35. package/dist/spectrum/icons.d.ts +2 -0
  36. package/dist/spectrum/icons.d.ts.map +1 -0
  37. package/dist/spectrum/icons.js +3 -0
  38. package/dist/spectrum/icons.js.map +1 -0
  39. package/dist/spectrum/index.d.ts +4 -0
  40. package/dist/spectrum/index.d.ts.map +1 -1
  41. package/dist/spectrum/index.js +4 -0
  42. package/dist/spectrum/index.js.map +1 -1
  43. package/dist/spectrum/listView/ListView.d.ts +28 -0
  44. package/dist/spectrum/listView/ListView.d.ts.map +1 -0
  45. package/dist/spectrum/listView/ListView.js +91 -0
  46. package/dist/spectrum/listView/ListView.js.map +1 -0
  47. package/dist/spectrum/listView/index.d.ts +2 -0
  48. package/dist/spectrum/listView/index.d.ts.map +1 -0
  49. package/dist/spectrum/listView/index.js +2 -0
  50. package/dist/spectrum/listView/index.js.map +1 -0
  51. package/dist/spectrum/picker/Picker.d.ts.map +1 -1
  52. package/dist/spectrum/picker/Picker.js +9 -60
  53. package/dist/spectrum/picker/Picker.js.map +1 -1
  54. package/dist/spectrum/picker/index.d.ts +0 -1
  55. package/dist/spectrum/picker/index.d.ts.map +1 -1
  56. package/dist/spectrum/picker/index.js +0 -1
  57. package/dist/spectrum/picker/index.js.map +1 -1
  58. package/dist/spectrum/utils/index.d.ts +2 -0
  59. package/dist/spectrum/utils/index.d.ts.map +1 -1
  60. package/dist/spectrum/utils/index.js +2 -0
  61. package/dist/spectrum/utils/index.js.map +1 -1
  62. package/dist/spectrum/utils/itemUtils.d.ts +21 -11
  63. package/dist/spectrum/utils/itemUtils.d.ts.map +1 -1
  64. package/dist/spectrum/utils/itemUtils.js +23 -8
  65. package/dist/spectrum/utils/itemUtils.js.map +1 -1
  66. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts +11 -0
  67. package/dist/spectrum/utils/useRenderNormalizedItem.d.ts.map +1 -0
  68. package/dist/spectrum/utils/useRenderNormalizedItem.js +40 -0
  69. package/dist/spectrum/utils/useRenderNormalizedItem.js.map +1 -0
  70. package/dist/spectrum/utils/useStringifiedMultiSelection.d.ts +43 -0
  71. package/dist/spectrum/utils/useStringifiedMultiSelection.d.ts.map +1 -0
  72. package/dist/spectrum/utils/useStringifiedMultiSelection.js +50 -0
  73. package/dist/spectrum/utils/useStringifiedMultiSelection.js.map +1 -0
  74. package/dist/theme/index.d.ts +1 -0
  75. package/dist/theme/index.d.ts.map +1 -1
  76. package/dist/theme/index.js +1 -0
  77. package/dist/theme/index.js.map +1 -1
  78. package/dist/theme/useSpectrumThemeProvider.d.ts +4 -0
  79. package/dist/theme/useSpectrumThemeProvider.d.ts.map +1 -0
  80. package/dist/theme/useSpectrumThemeProvider.js +4 -0
  81. package/dist/theme/useSpectrumThemeProvider.js.map +1 -0
  82. package/package.json +7 -7
  83. package/dist/XComponent.d.ts +0 -43
  84. package/dist/XComponent.d.ts.map +0 -1
  85. package/dist/XComponent.js +0 -57
  86. package/dist/XComponent.js.map +0 -1
  87. package/dist/XComponentMap.d.ts +0 -14
  88. package/dist/XComponentMap.d.ts.map +0 -1
  89. package/dist/XComponentMap.js +0 -20
  90. package/dist/XComponentMap.js.map +0 -1
  91. package/dist/spectrum/picker/PickerItemContent.d.ts +0 -11
  92. package/dist/spectrum/picker/PickerItemContent.d.ts.map +0 -1
  93. package/dist/spectrum/picker/PickerItemContent.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { Key, ReactElement, ReactNode } from 'react';
2
2
  import { SpectrumPickerProps } from '@adobe/react-spectrum';
3
3
  import type { ItemRenderer } from '@react-types/shared';
4
- import { KeyedItem } from '@deephaven/utils';
4
+ import { KeyedItem, SelectionT } from '@deephaven/utils';
5
5
  import { ItemProps, SectionProps } from '../shared';
6
6
  import { PopperOptions } from '../../popper';
7
7
  export declare const INVALID_ITEM_ERROR_MESSAGE = "Items must be strings, numbers, booleans, <Item> or <Section> elements:";
@@ -23,6 +23,7 @@ export type ItemOrSection = ItemElementOrPrimitive | SectionElement;
23
23
  * don't reflect it.
24
24
  */
25
25
  export type ItemKey = Key | boolean;
26
+ export type ItemSelection = SelectionT<ItemKey>;
26
27
  /**
27
28
  * Augment the Spectrum selection change handler type to include boolean keys.
28
29
  * Spectrum components already supports this, but the built in types don't
@@ -49,6 +50,7 @@ export interface NormalizedSectionData {
49
50
  */
50
51
  export type NormalizedItem = KeyedItem<NormalizedItemData, ItemKey | undefined>;
51
52
  export type NormalizedSection = KeyedItem<NormalizedSectionData, Key | undefined>;
53
+ export type NormalizedItemOrSection<TItemOrSection extends ItemOrSection> = TItemOrSection extends SectionElement ? NormalizedSection : NormalizedItem;
52
54
  export type NormalizedSpectrumPickerProps = SpectrumPickerProps<NormalizedItem>;
53
55
  export type TooltipOptions = {
54
56
  placement: PopperOptions['placement'];
@@ -76,12 +78,12 @@ export declare function isSectionElement<T>(node: ReactNode): node is ReactEleme
76
78
  */
77
79
  export declare function isItemElement<T>(node: ReactNode): node is ReactElement<ItemProps<T>>;
78
80
  /**
79
- * Determine if a node is an array containing normalized items with keys.
80
- * Note that this only checks the first node in the array.
81
+ * Determine if a node is an array containing normalized items or sections with
82
+ * keys. Note that this only checks the first node in the array.
81
83
  * @param node The node to check
82
- * @returns True if the node is a normalized item with keys array
84
+ * @returns True if the node is a normalized item or section with keys array
83
85
  */
84
- export declare function isNormalizedItemsWithKeysList(node: ItemOrSection | ItemOrSection[] | (NormalizedItem | NormalizedSection)[]): node is (NormalizedItem | NormalizedSection)[];
86
+ export declare function isNormalizedItemsWithKeysList<TItemOrSection extends ItemOrSection>(node: TItemOrSection | TItemOrSection[] | NormalizedItemOrSection<TItemOrSection>[]): node is NormalizedItemOrSection<TItemOrSection>[];
85
87
  /**
86
88
  * Determine if an object is a normalized section.
87
89
  * @param maybeNormalizedSection The object to check
@@ -96,16 +98,24 @@ export declare function isNormalizedSection(maybeNormalizedSection: NormalizedIt
96
98
  */
97
99
  export declare function isItemOrSection(node: ReactNode): node is ItemOrSection;
98
100
  /**
99
- * Get normalized items from an item or array of items.
100
- * @param itemsOrSections An item or array of items
101
- * @returns An array of normalized items
101
+ * Normalize an item or section or a list of items or sections.
102
+ * @param itemsOrSections An item or section or array of items or sections
103
+ * @returns An array of normalized items or sections
102
104
  */
103
- export declare function normalizeItemList(itemsOrSections: ItemOrSection | ItemOrSection[] | NormalizedItem[]): (NormalizedItem | NormalizedSection)[];
105
+ export declare function normalizeItemList<TItemOrSection extends ItemOrSection>(itemsOrSections: TItemOrSection | TItemOrSection[] | NormalizedItem[]): NormalizedItemOrSection<TItemOrSection>[];
104
106
  /**
105
107
  * Returns a TooltipOptions object or null if options is false or null.
106
- * @param options
108
+ * @param options Tooltip options
109
+ * @param placement Default placement for the tooltip if `options` is set
110
+ * explicitly to `true`
107
111
  * @returns TooltipOptions or null
108
112
  */
109
- export declare function normalizeTooltipOptions(options?: boolean | TooltipOptions | null): TooltipOptions | null;
113
+ export declare function normalizeTooltipOptions(options?: boolean | TooltipOptions | null, placement?: TooltipOptions['placement']): TooltipOptions | null;
114
+ /**
115
+ * Convert a selection of `ItemKey`s to a selection of strings.
116
+ * @param itemKeys The selection of `ItemKey`s
117
+ * @returns The selection of strings
118
+ */
119
+ export declare function itemSelectionToStringSet(itemKeys?: 'all' | Iterable<ItemKey>): undefined | 'all' | Set<string>;
110
120
  export {};
111
121
  //# sourceMappingURL=itemUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"itemUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/itemUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAQ,SAAS,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,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,CAAC,CAAC,CAAC,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,SAAS,GACd,IAAI,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAEpC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,cAAc,SAAS,aAAa,EAEpC,IAAI,EACA,cAAc,GACd,cAAc,EAAE,GAChB,uBAAuB,CAAC,cAAc,CAAC,EAAE,GAC5C,IAAI,IAAI,uBAAuB,CAAC,cAAc,CAAC,EAAE,CAUnD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,sBAAsB,EAAE,cAAc,GAAG,iBAAiB,GACzD,sBAAsB,IAAI,iBAAiB,CAK7C;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,IAAI,aAAa,CAQtE;AAiGD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,SAAS,aAAa,EACpE,eAAe,EAAE,cAAc,GAAG,cAAc,EAAE,GAAG,cAAc,EAAE,GACpE,uBAAuB,CAAC,cAAc,CAAC,EAAE,CAW3C;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,CAAC,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,EACzC,SAAS,GAAE,cAAc,CAAC,WAAW,CAAW,GAC/C,cAAc,GAAG,IAAI,CAUvB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GACnC,SAAS,GAAG,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAMjC"}
@@ -64,10 +64,10 @@ export function isItemElement(node) {
64
64
  }
65
65
 
66
66
  /**
67
- * Determine if a node is an array containing normalized items with keys.
68
- * Note that this only checks the first node in the array.
67
+ * Determine if a node is an array containing normalized items or sections with
68
+ * keys. Note that this only checks the first node in the array.
69
69
  * @param node The node to check
70
- * @returns True if the node is a normalized item with keys array
70
+ * @returns True if the node is a normalized item or section with keys array
71
71
  */
72
72
  export function isNormalizedItemsWithKeysList(node) {
73
73
  if (!Array.isArray(node)) {
@@ -182,9 +182,9 @@ function normalizeItem(itemOrSection) {
182
182
  }
183
183
 
184
184
  /**
185
- * Get normalized items from an item or array of items.
186
- * @param itemsOrSections An item or array of items
187
- * @returns An array of normalized items
185
+ * Normalize an item or section or a list of items or sections.
186
+ * @param itemsOrSections An item or section or array of items or sections
187
+ * @returns An array of normalized items or sections
188
188
  */
189
189
  export function normalizeItemList(itemsOrSections) {
190
190
  // If already normalized, just return as-is
@@ -197,18 +197,33 @@ export function normalizeItemList(itemsOrSections) {
197
197
 
198
198
  /**
199
199
  * Returns a TooltipOptions object or null if options is false or null.
200
- * @param options
200
+ * @param options Tooltip options
201
+ * @param placement Default placement for the tooltip if `options` is set
202
+ * explicitly to `true`
201
203
  * @returns TooltipOptions or null
202
204
  */
203
205
  export function normalizeTooltipOptions(options) {
206
+ var placement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'right';
204
207
  if (options == null || options === false) {
205
208
  return null;
206
209
  }
207
210
  if (options === true) {
208
211
  return {
209
- placement: 'right'
212
+ placement
210
213
  };
211
214
  }
212
215
  return options;
213
216
  }
217
+
218
+ /**
219
+ * Convert a selection of `ItemKey`s to a selection of strings.
220
+ * @param itemKeys The selection of `ItemKey`s
221
+ * @returns The selection of strings
222
+ */
223
+ export function itemSelectionToStringSet(itemKeys) {
224
+ if (itemKeys == null || itemKeys === 'all') {
225
+ return itemKeys;
226
+ }
227
+ return new Set([...itemKeys].map(String));
228
+ }
214
229
  //# sourceMappingURL=itemUtils.js.map
@@ -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,CAAC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iBA,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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B,IAAI,EAAE;MAAEG,GAAG;MAAE6B,OAAO;MAAEX;IAAU;EAClC,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASQ,iBAAiBA,CAC/BI,eAAqE,EAC1B;EAC3C;EACA,IAAIzB,6BAA6B,CAACyB,eAAe,CAAC,EAAE;IAClD,OAAOA,eAAe;EACxB;EAEA,IAAMC,UAA4B,GAAGzB,KAAK,CAACC,OAAO,CAACuB,eAAe,CAAC,GAC/DA,eAAe,GACf,CAACA,eAAe,CAAC;EAErB,OAAOC,UAAU,CAACC,GAAG,CAACV,aAAa,CAAC;AACtC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASW,uBAAuBA,CACrCC,OAAyC,EAElB;EAAA,IADvBC,SAAsC,GAAAC,SAAA,CAAA5B,MAAA,QAAA4B,SAAA,QAAAnB,SAAA,GAAAmB,SAAA,MAAG,OAAO;EAEhD,IAAIF,OAAO,IAAI,IAAI,IAAIA,OAAO,KAAK,KAAK,EAAE;IACxC,OAAO,IAAI;EACb;EAEA,IAAIA,OAAO,KAAK,IAAI,EAAE;IACpB,OAAO;MAAEC;IAAU,CAAC;EACtB;EAEA,OAAOD,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,wBAAwBA,CACtCC,QAAoC,EACH;EACjC,IAAIA,QAAQ,IAAI,IAAI,IAAIA,QAAQ,KAAK,KAAK,EAAE;IAC1C,OAAOA,QAAQ;EACjB;EAEA,OAAO,IAAIC,GAAG,CAAC,CAAC,GAAGD,QAAQ,CAAC,CAACN,GAAG,CAACX,MAAM,CAAC,CAAC;AAC3C"}
@@ -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-xcomponent.2+aa152d3f",
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-xcomponent.2+aa152d3f",
29
- "@deephaven/log": "^0.72.1-xcomponent.2+aa152d3f",
30
- "@deephaven/react-hooks": "^0.72.1-xcomponent.2+aa152d3f",
31
- "@deephaven/utils": "^0.72.1-xcomponent.2+aa152d3f",
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-xcomponent.2+aa152d3f"
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": "aa152d3f63ed6212e5b50003a7a164c8c329f446"
72
+ "gitHead": "9e9e272cee02bc7b2c7cda19a00bf55385a0cffb"
73
73
  }
@@ -1,43 +0,0 @@
1
- import React from 'react';
2
- import { XComponentType } from './XComponentMap';
3
- /**
4
- * Helper function that will wrap the provided component, and return an ExtendableComponent type.
5
- * Whenever that ExtendableComponent is used, it will check if there is a replacement component for the provided component on the context.
6
- * If there is, it will use that component instead of the provided component.
7
- * This is a similar concept to how swizzling is done in Docusaurus or obj-c, but for any React component.
8
- *
9
- * Usage:
10
- *
11
- * ```tsx
12
- * function MyComponent() {
13
- * return <div>MyComponent</div>;
14
- * }
15
- * const XMyComponent = extendableComponent(MyComponent);
16
- *
17
- *
18
- * function MyReplacementComponent() {
19
- * return <div>MyReplacementComponent</div>;
20
- * }
21
- *
22
- *
23
- * ...
24
- *
25
- * <XMyComponent /> // Will render MyComponent
26
- *
27
- * ...
28
- *
29
- * <XComponentMapProvider value={new Map([[XMyComponent, MyReplacementComponent]])}>
30
- * <XMyComponent /> // Will render MyReplacementComponent
31
- * </XComponentMapProvider>
32
- *
33
- * ```
34
- *
35
- * Is useful in cases where we have a component deep down in the component tree that we want to replace with a different component, but don't want to
36
- * have to provide props at the top level just to hook into that.
37
- *
38
- * @param Component The component to wrap
39
- * @returns The wrapped component
40
- */
41
- export declare function createXComponent<P extends Record<string, unknown>>(Component: React.ComponentType<P>): XComponentType<P>;
42
- export default createXComponent;
43
- //# sourceMappingURL=XComponent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XComponent.d.ts","sourceRoot":"","sources":["../src/XComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAiB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,GAChC,cAAc,CAAC,CAAC,CAAC,CAUnB;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,57 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
- import React from 'react';
7
- import { useXComponent } from "./XComponentMap.js";
8
- /**
9
- * Helper function that will wrap the provided component, and return an ExtendableComponent type.
10
- * Whenever that ExtendableComponent is used, it will check if there is a replacement component for the provided component on the context.
11
- * If there is, it will use that component instead of the provided component.
12
- * This is a similar concept to how swizzling is done in Docusaurus or obj-c, but for any React component.
13
- *
14
- * Usage:
15
- *
16
- * ```tsx
17
- * function MyComponent() {
18
- * return <div>MyComponent</div>;
19
- * }
20
- * const XMyComponent = extendableComponent(MyComponent);
21
- *
22
- *
23
- * function MyReplacementComponent() {
24
- * return <div>MyReplacementComponent</div>;
25
- * }
26
- *
27
- *
28
- * ...
29
- *
30
- * <XMyComponent /> // Will render MyComponent
31
- *
32
- * ...
33
- *
34
- * <XComponentMapProvider value={new Map([[XMyComponent, MyReplacementComponent]])}>
35
- * <XMyComponent /> // Will render MyReplacementComponent
36
- * </XComponentMapProvider>
37
- *
38
- * ```
39
- *
40
- * Is useful in cases where we have a component deep down in the component tree that we want to replace with a different component, but don't want to
41
- * have to provide props at the top level just to hook into that.
42
- *
43
- * @param Component The component to wrap
44
- * @returns The wrapped component
45
- */
46
- import { jsx as _jsx } from "react/jsx-runtime";
47
- export function createXComponent(Component) {
48
- var XComponent = function ExtendableComponent(props) {
49
- var ReplacementComponent = useXComponent(XComponent);
50
- // eslint-disable-next-line react/jsx-props-no-spreading
51
- return /*#__PURE__*/_jsx(ReplacementComponent, _objectSpread({}, props));
52
- };
53
- XComponent.Original = Component;
54
- return XComponent;
55
- }
56
- export default createXComponent;
57
- //# sourceMappingURL=XComponent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"XComponent.js","names":["React","useXComponent","jsx","_jsx","createXComponent","Component","XComponent","ExtendableComponent","props","ReplacementComponent","_objectSpread","Original"],"sources":["../src/XComponent.tsx"],"sourcesContent":["import React from 'react';\nimport { useXComponent, XComponentType } from './XComponentMap';\n\n/**\n * Helper function that will wrap the provided component, and return an ExtendableComponent type.\n * Whenever that ExtendableComponent is used, it will check if there is a replacement component for the provided component on the context.\n * If there is, it will use that component instead of the provided component.\n * This is a similar concept to how swizzling is done in Docusaurus or obj-c, but for any React component.\n *\n * Usage:\n *\n * ```tsx\n * function MyComponent() {\n * return <div>MyComponent</div>;\n * }\n * const XMyComponent = extendableComponent(MyComponent);\n *\n *\n * function MyReplacementComponent() {\n * return <div>MyReplacementComponent</div>;\n * }\n *\n *\n * ...\n *\n * <XMyComponent /> // Will render MyComponent\n *\n * ...\n *\n * <XComponentMapProvider value={new Map([[XMyComponent, MyReplacementComponent]])}>\n * <XMyComponent /> // Will render MyReplacementComponent\n * </XComponentMapProvider>\n *\n * ```\n *\n * Is useful in cases where we have a component deep down in the component tree that we want to replace with a different component, but don't want to\n * have to provide props at the top level just to hook into that.\n *\n * @param Component The component to wrap\n * @returns The wrapped component\n */\nexport function createXComponent<P extends Record<string, unknown>>(\n Component: React.ComponentType<P>\n): XComponentType<P> {\n const XComponent = function ExtendableComponent(props: P): JSX.Element {\n const ReplacementComponent = useXComponent(XComponent);\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <ReplacementComponent {...props} />;\n };\n\n XComponent.Original = Component;\n\n return XComponent;\n}\n\nexport default createXComponent;\n"],"mappings":";;;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AAAC,SACjBC,aAAa;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AArCA,SAAAC,GAAA,IAAAC,IAAA;AAsCA,OAAO,SAASC,gBAAgBA,CAC9BC,SAAiC,EACd;EACnB,IAAMC,UAAU,GAAG,SAASC,mBAAmBA,CAACC,KAAQ,EAAe;IACrE,IAAMC,oBAAoB,GAAGR,aAAa,CAACK,UAAU,CAAC;IACtD;IACA,oBAAOH,IAAA,CAACM,oBAAoB,EAAAC,aAAA,KAAKF,KAAK,CAAG,CAAC;EAC5C,CAAC;EAEDF,UAAU,CAACK,QAAQ,GAAGN,SAAS;EAE/B,OAAOC,UAAU;AACnB;AAEA,eAAeF,gBAAgB"}