@deephaven/components 0.71.1-beta.0 → 0.72.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.
- package/dist/Button.d.ts +1 -1
- package/dist/SearchInput.css +10 -12
- package/dist/SearchInput.css.map +1 -1
- package/dist/Select.d.ts +2 -1
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +5 -2
- package/dist/Select.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/spectrum/index.js +1 -1
- package/dist/spectrum/picker/Picker.d.ts +6 -6
- package/dist/spectrum/picker/Picker.d.ts.map +1 -1
- package/dist/spectrum/picker/Picker.js +10 -9
- package/dist/spectrum/picker/Picker.js.map +1 -1
- package/dist/spectrum/picker/index.d.ts +1 -1
- package/dist/spectrum/picker/index.d.ts.map +1 -1
- package/dist/spectrum/picker/index.js +1 -1
- package/dist/spectrum/picker/index.js.map +1 -1
- package/dist/spectrum/utils/index.d.ts +3 -0
- package/dist/spectrum/utils/index.d.ts.map +1 -0
- package/dist/spectrum/utils/index.js +3 -0
- package/dist/spectrum/utils/index.js.map +1 -0
- package/dist/spectrum/utils/itemUtils.d.ts +111 -0
- package/dist/spectrum/utils/itemUtils.d.ts.map +1 -0
- package/dist/spectrum/{picker/PickerUtils.js → utils/itemUtils.js} +46 -45
- package/dist/spectrum/utils/itemUtils.js.map +1 -0
- package/dist/spectrum/{utils.d.ts → utils/themeUtils.d.ts} +2 -1
- package/dist/spectrum/utils/themeUtils.d.ts.map +1 -0
- package/dist/spectrum/{utils.js → utils/themeUtils.js} +3 -2
- package/dist/spectrum/utils/themeUtils.js.map +1 -0
- package/dist/theme/SpectrumThemeProvider.js +1 -1
- package/package.json +8 -7
- package/dist/spectrum/picker/PickerUtils.d.ts +0 -111
- package/dist/spectrum/picker/PickerUtils.d.ts.map +0 -1
- package/dist/spectrum/picker/PickerUtils.js.map +0 -1
- package/dist/spectrum/utils.d.ts.map +0 -1
- package/dist/spectrum/utils.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Picker.js","names":["useCallback","useMemo","Flex","Picker","SpectrumPicker","Text","getPositionOfSelectedItem","findSpectrumPickerScrollArea","isElementOfType","usePopoverOnScrollRef","EMPTY_FUNCTION","PICKER_ITEM_HEIGHT","PICKER_TOP_OFFSET","cl","Tooltip","isNormalizedPickerSection","normalizePickerItemList","normalizeTooltipOptions","getPickerItemKey","PickerItemContent","Item","Section","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","createTooltipContent","content","String","Array","isArray","direction","alignItems","children","filter","node","_ref","tooltip","defaultSelectedKey","selectedKey","getInitialScrollPosition","onChange","onOpenChange","onScroll","onSelectionChange","UNSAFE_className","spectrumPickerProps","_objectWithoutProperties","_excluded","normalizedItems","tooltipOptions","renderItem","normalizedItem","_normalizedItem$item$","_normalizedItem$item","_normalizedItem$item$2","_normalizedItem$item2","key","item","textValue","options","getInitialScrollPositionInternal","keyedItems","itemHeight","topOffset","ref","scrollRef","popoverOnOpenChange","onOpenChangeInternal","isOpen","onSelectionChangeInternal","_getPickerItemKey","_ref2","selectedItem","find","actualKey","_objectSpread","items","toString","itemOrSection","_itemOrSection$item","_itemOrSection$item2","title"],"sources":["../../../src/spectrum/picker/Picker.tsx"],"sourcesContent":["import { Key, ReactNode, useCallback, useMemo } from 'react';\nimport { DOMRef } from '@react-types/shared';\nimport { Flex, Picker as SpectrumPicker, Text } from '@adobe/react-spectrum';\nimport {\n getPositionOfSelectedItem,\n findSpectrumPickerScrollArea,\n isElementOfType,\n usePopoverOnScrollRef,\n} from '@deephaven/react-hooks';\nimport {\n EMPTY_FUNCTION,\n PICKER_ITEM_HEIGHT,\n PICKER_TOP_OFFSET,\n} from '@deephaven/utils';\nimport cl from 'classnames';\nimport { Tooltip } from '../../popper';\nimport {\n isNormalizedPickerSection,\n NormalizedSpectrumPickerProps,\n normalizePickerItemList,\n normalizeTooltipOptions,\n NormalizedPickerItem,\n PickerItemOrSection,\n TooltipOptions,\n PickerItemKey,\n getPickerItemKey,\n} from './PickerUtils';\nimport { PickerItemContent } from './PickerItemContent';\nimport { Item, Section } from '../shared';\n\nexport type PickerProps = {\n children:\n | PickerItemOrSection\n | PickerItemOrSection[]\n | NormalizedPickerItem[];\n /** Can be set to true or a TooltipOptions to enable item tooltips */\n tooltip?: boolean | TooltipOptions;\n /** The currently selected key in the collection (controlled). */\n selectedKey?: PickerItemKey | null;\n /** The initial selected key in the collection (uncontrolled). */\n defaultSelectedKey?: PickerItemKey;\n /** Function to retrieve initial scroll position when opening the picker */\n getInitialScrollPosition?: () => Promise<number | null>;\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?: (key: PickerItemKey) => void;\n\n /** Handler that is called when the picker is scrolled. */\n onScroll?: (event: Event) => void;\n\n /**\n * Handler that is called when the selection changes.\n * @deprecated Use `onChange` instead\n */\n onSelectionChange?: (key: PickerItemKey) => void;\n} /*\n * Support remaining SpectrumPickerProps.\n * Note that `selectedKey`, `defaultSelectedKey`, and `onSelectionChange` are\n * re-defined above to account for boolean types which aren't included in the\n * React `Key` type, but are actually supported by the Spectrum Picker component.\n */ & Omit<\n NormalizedSpectrumPickerProps,\n | 'children'\n | 'items'\n | 'onSelectionChange'\n | 'selectedKey'\n | 'defaultSelectedKey'\n>;\n\n/**\n * Create tooltip content optionally wrapping with a Flex column for array\n * content. This is needed for Items containing description `Text` elements.\n */\nfunction createTooltipContent(content: ReactNode) {\n if (typeof content === 'boolean') {\n return String(content);\n }\n\n if (Array.isArray(content)) {\n return (\n <Flex direction=\"column\" alignItems=\"start\">\n {content.filter(node => isElementOfType(node, Text))}\n </Flex>\n );\n }\n\n return content;\n}\n\n/**\n * Picker component for selecting items from a list of items. Items can be\n * provided via the `items` prop or as children. Each item can be a string,\n * number, boolean, or a Spectrum <Item> element. The remaining props are just\n * pass through props for the Spectrum Picker component.\n * See https://react-spectrum.adobe.com/react-spectrum/Picker.html\n */\nexport function Picker({\n children,\n tooltip = true,\n defaultSelectedKey,\n selectedKey,\n getInitialScrollPosition,\n onChange,\n onOpenChange,\n onScroll = EMPTY_FUNCTION,\n onSelectionChange,\n // eslint-disable-next-line camelcase\n UNSAFE_className,\n ...spectrumPickerProps\n}: PickerProps): JSX.Element {\n const normalizedItems = useMemo(\n () => normalizePickerItemList(children),\n [children]\n );\n\n const tooltipOptions = useMemo(\n () => normalizeTooltipOptions(tooltip),\n [tooltip]\n );\n\n const renderItem = useCallback(\n (normalizedItem: NormalizedPickerItem) => {\n const key = getPickerItemKey(normalizedItem);\n const content = normalizedItem.item?.content ?? '';\n const textValue = normalizedItem.item?.textValue ?? '';\n\n return (\n <Item\n // Note that setting the `key` prop explicitly on `Item` elements\n // causes the picker to expect `selectedKey` and `defaultSelectedKey`\n // to be strings. It also passes the stringified value of the key to\n // `onSelectionChange` handlers` regardless of the actual type of the\n // key. We can't really get around setting in order to support Windowed\n // data, so we'll need to do some manual conversion of keys to strings\n // in other places of this component.\n key={key as Key}\n // The `textValue` prop gets used to provide the content of `<option>`\n // elements that back the Spectrum Picker. These are not visible in the UI,\n // but are used for accessibility purposes, so we set to an arbitrary\n // 'Empty' value so that they are not empty strings.\n textValue={textValue === '' ? 'Empty' : textValue}\n >\n <>\n <PickerItemContent>{content}</PickerItemContent>\n {tooltipOptions == null || content === '' ? null : (\n <Tooltip options={tooltipOptions}>\n {createTooltipContent(content)}\n </Tooltip>\n )}\n </>\n </Item>\n );\n },\n [tooltipOptions]\n );\n\n const getInitialScrollPositionInternal = useCallback(\n () =>\n getInitialScrollPosition == null\n ? getPositionOfSelectedItem({\n keyedItems: normalizedItems,\n // TODO: #1890 & deephaven-plugins#371 add support for sections and\n // items with descriptions since they impact the height calculations\n itemHeight: PICKER_ITEM_HEIGHT,\n selectedKey,\n topOffset: PICKER_TOP_OFFSET,\n })\n : getInitialScrollPosition(),\n [getInitialScrollPosition, normalizedItems, selectedKey]\n );\n\n const { ref: scrollRef, onOpenChange: popoverOnOpenChange } =\n usePopoverOnScrollRef(\n findSpectrumPickerScrollArea,\n onScroll,\n getInitialScrollPositionInternal\n );\n\n const onOpenChangeInternal = useCallback(\n (isOpen: boolean): void => {\n // Attach scroll event handling\n popoverOnOpenChange(isOpen);\n\n onOpenChange?.(isOpen);\n },\n [onOpenChange, popoverOnOpenChange]\n );\n\n const onSelectionChangeInternal = useCallback(\n (key: PickerItemKey): void => {\n // The `key` arg will always be a string due to us setting the `Item` key\n // prop in `renderItem`. We need to find the matching item to determine\n // the actual key.\n const selectedItem = normalizedItems.find(\n item => String(getPickerItemKey(item)) === key\n );\n\n const actualKey = getPickerItemKey(selectedItem) ?? key;\n\n (onChange ?? onSelectionChange)?.(actualKey);\n },\n [normalizedItems, onChange, onSelectionChange]\n );\n\n return (\n <SpectrumPicker\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...spectrumPickerProps}\n // The `ref` prop type defined by React Spectrum is incorrect here\n ref={scrollRef as unknown as DOMRef<HTMLDivElement>}\n onOpenChange={onOpenChangeInternal}\n UNSAFE_className={cl('dh-picker', UNSAFE_className)}\n items={normalizedItems}\n // Spectrum Picker treats keys as strings if the `key` prop is explicitly\n // set on `Item` elements. Since we do this in `renderItem`, we need to\n // ensure that `selectedKey` and `defaultSelectedKey` are strings in order\n // for selection to work.\n selectedKey={selectedKey?.toString()}\n defaultSelectedKey={defaultSelectedKey?.toString()}\n // `onChange` is just an alias for `onSelectionChange`\n onSelectionChange={\n onSelectionChangeInternal as NormalizedSpectrumPickerProps['onSelectionChange']\n }\n >\n {itemOrSection => {\n if (isNormalizedPickerSection(itemOrSection)) {\n return (\n <Section\n key={getPickerItemKey(itemOrSection)}\n title={itemOrSection.item?.title}\n items={itemOrSection.item?.items}\n >\n {renderItem}\n </Section>\n );\n }\n\n return renderItem(itemOrSection);\n }}\n </Spectrum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,GAAIG,iBAAiB,cAAA4B,KAAA,uBAA9BA,KAAA,CAAkCG,SAAS,CAAC;EAC9C,CAAC,EACD,CAAC1B,eAAe,EAAER,QAAQ,EAAEG,iBAAiB,CAC/C,CAAC;EAED,oBACEvB,IAAA,CAACnB;EACC;EAAA,EAAA0E,aAAA,CAAAA,aAAA,KACI9B,mBAAmB;IACvB;IACAmB,GAAG,EAAEC,SAA+C;IACpDxB,YAAY,EAAE0B,oBAAqB;IACnCvB,gBAAgB,EAAElC,EAAE,CAAC,WAAW,EAAEkC,gBAAgB,CAAE;IACpDgC,KAAK,EAAE5B;IACP;IACA;IACA;IACA;IAAA;IACAV,WAAW,EAAEA,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAEuC,QAAQ,CAAC,CAAE;IACrCxC,kBAAkB,EAAEA,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAEwC,QAAQ,CAAC;IACjD;IAAA;IACAlC,iBAAiB,EACf0B,yBACD;IAAArC,QAAA,EAEA8C,aAAa,IAAI;MAChB,IAAIlE,yBAAyB,CAACkE,aAAa,CAAC,EAAE;QAAA,IAAAC,mBAAA,EAAAC,oBAAA;QAC5C,oBACE5D,IAAA,CAACF,OAAO;UAEN+D,KAAK,GAAAF,mBAAA,GAAED,aAAa,CAACrB,IAAI,cAAAsB,mBAAA,uBAAlBA,mBAAA,CAAoBE,KAAM;UACjCL,KAAK,GAAAI,oBAAA,GAAEF,aAAa,CAACrB,IAAI,cAAAuB,oBAAA,uBAAlBA,oBAAA,CAAoBJ,KAAM;UAAA5C,QAAA,EAEhCkB;QAAU,GAJNnC,gBAAgB,CAAC+D,aAAa,CAK5B,CAAC;MAEd;MAEA,OAAO5B,UAAU,CAAC4B,aAAa,CAAC;IAClC;EAAC,EACa,CAAC;AAErB;AAEA,eAAe9E,MAAM"}
|
|
1
|
+
{"version":3,"file":"Picker.js","names":["useCallback","useMemo","Flex","Picker","SpectrumPicker","getPositionOfSelectedItem","findSpectrumPickerScrollArea","isElementOfType","usePopoverOnScrollRef","EMPTY_FUNCTION","PICKER_ITEM_HEIGHT","PICKER_TOP_OFFSET","cl","Tooltip","isNormalizedSection","normalizeItemList","normalizeTooltipOptions","getItemKey","PickerItemContent","Item","Section","Text","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","createTooltipContent","content","String","Array","isArray","direction","alignItems","children","filter","node","_ref","tooltip","defaultSelectedKey","selectedKey","getInitialScrollPosition","onChange","onOpenChange","onScroll","onSelectionChange","UNSAFE_className","spectrumPickerProps","_objectWithoutProperties","_excluded","normalizedItems","tooltipOptions","renderItem","normalizedItem","_normalizedItem$item$","_normalizedItem$item","_normalizedItem$item$2","_normalizedItem$item2","key","item","textValue","options","getInitialScrollPositionInternal","keyedItems","itemHeight","topOffset","ref","scrollRef","popoverOnOpenChange","onOpenChangeInternal","isOpen","onSelectionChangeInternal","_getItemKey","_ref2","selectedItem","find","actualKey","_objectSpread","items","toString","itemOrSection","_itemOrSection$item","_itemOrSection$item2","title"],"sources":["../../../src/spectrum/picker/Picker.tsx"],"sourcesContent":["import { Key, ReactNode, useCallback, useMemo } from 'react';\nimport { DOMRef } from '@react-types/shared';\nimport { Flex, Picker as SpectrumPicker } from '@adobe/react-spectrum';\nimport {\n getPositionOfSelectedItem,\n findSpectrumPickerScrollArea,\n isElementOfType,\n usePopoverOnScrollRef,\n} from '@deephaven/react-hooks';\nimport {\n EMPTY_FUNCTION,\n PICKER_ITEM_HEIGHT,\n PICKER_TOP_OFFSET,\n} from '@deephaven/utils';\nimport cl from 'classnames';\nimport { Tooltip } from '../../popper';\nimport {\n isNormalizedSection,\n NormalizedSpectrumPickerProps,\n normalizeItemList,\n normalizeTooltipOptions,\n NormalizedItem,\n ItemOrSection,\n TooltipOptions,\n ItemKey,\n getItemKey,\n} from '../utils/itemUtils';\nimport { PickerItemContent } from './PickerItemContent';\nimport { Item, Section } from '../shared';\nimport { Text } from '../Text';\n\nexport type PickerProps = {\n children: ItemOrSection | ItemOrSection[] | NormalizedItem[];\n /** Can be set to true or a TooltipOptions to enable item tooltips */\n tooltip?: boolean | TooltipOptions;\n /** The currently selected key in the collection (controlled). */\n selectedKey?: ItemKey | null;\n /** The initial selected key in the collection (uncontrolled). */\n defaultSelectedKey?: ItemKey;\n /** Function to retrieve initial scroll position when opening the picker */\n getInitialScrollPosition?: () => Promise<number | null>;\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?: (key: ItemKey) => void;\n\n /** Handler that is called when the picker is scrolled. */\n onScroll?: (event: Event) => void;\n\n /**\n * Handler that is called when the selection changes.\n * @deprecated Use `onChange` instead\n */\n onSelectionChange?: (key: ItemKey) => void;\n} /*\n * Support remaining SpectrumPickerProps.\n * Note that `selectedKey`, `defaultSelectedKey`, and `onSelectionChange` are\n * re-defined above to account for boolean types which aren't included in the\n * React `Key` type, but are actually supported by the Spectrum Picker component.\n */ & Omit<\n NormalizedSpectrumPickerProps,\n | 'children'\n | 'items'\n | 'onSelectionChange'\n | 'selectedKey'\n | 'defaultSelectedKey'\n>;\n\n/**\n * Create tooltip content optionally wrapping with a Flex column for array\n * content. This is needed for Items containing description `Text` elements.\n */\nfunction createTooltipContent(content: ReactNode) {\n if (typeof content === 'boolean') {\n return String(content);\n }\n\n if (Array.isArray(content)) {\n return (\n <Flex direction=\"column\" alignItems=\"start\">\n {content.filter(node => isElementOfType(node, Text))}\n </Flex>\n );\n }\n\n return content;\n}\n\n/**\n * Picker component for selecting items from a list of items. Items can be\n * provided via the `items` prop or as children. Each item can be a string,\n * number, boolean, or a Spectrum <Item> element. The remaining props are just\n * pass through props for the Spectrum Picker component.\n * See https://react-spectrum.adobe.com/react-spectrum/Picker.html\n */\nexport function Picker({\n children,\n tooltip = true,\n defaultSelectedKey,\n selectedKey,\n getInitialScrollPosition,\n onChange,\n onOpenChange,\n onScroll = EMPTY_FUNCTION,\n onSelectionChange,\n // eslint-disable-next-line camelcase\n UNSAFE_className,\n ...spectrumPickerProps\n}: PickerProps): JSX.Element {\n const normalizedItems = useMemo(\n () => normalizeItemList(children),\n [children]\n );\n\n const tooltipOptions = useMemo(\n () => normalizeTooltipOptions(tooltip),\n [tooltip]\n );\n\n const renderItem = useCallback(\n (normalizedItem: NormalizedItem) => {\n const key = getItemKey(normalizedItem);\n const content = normalizedItem.item?.content ?? '';\n const textValue = normalizedItem.item?.textValue ?? '';\n\n return (\n <Item\n // Note that setting the `key` prop explicitly on `Item` elements\n // causes the picker to expect `selectedKey` and `defaultSelectedKey`\n // to be strings. It also passes the stringified value of the key to\n // `onSelectionChange` handlers` regardless of the actual type of the\n // key. We can't really get around setting in order to support Windowed\n // data, so we'll need to do some manual conversion of keys to strings\n // in other places of this component.\n key={key as Key}\n // The `textValue` prop gets used to provide the content of `<option>`\n // elements that back the Spectrum Picker. These are not visible in the UI,\n // but are used for accessibility purposes, so we set to an arbitrary\n // 'Empty' value so that they are not empty strings.\n textValue={textValue === '' ? 'Empty' : textValue}\n >\n <>\n <PickerItemContent>{content}</PickerItemContent>\n {tooltipOptions == null || content === '' ? null : (\n <Tooltip options={tooltipOptions}>\n {createTooltipContent(content)}\n </Tooltip>\n )}\n </>\n </Item>\n );\n },\n [tooltipOptions]\n );\n\n const getInitialScrollPositionInternal = useCallback(\n () =>\n getInitialScrollPosition == null\n ? getPositionOfSelectedItem({\n keyedItems: normalizedItems,\n // TODO: #1890 & deephaven-plugins#371 add support for sections and\n // items with descriptions since they impact the height calculations\n itemHeight: PICKER_ITEM_HEIGHT,\n selectedKey,\n topOffset: PICKER_TOP_OFFSET,\n })\n : getInitialScrollPosition(),\n [getInitialScrollPosition, normalizedItems, selectedKey]\n );\n\n const { ref: scrollRef, onOpenChange: popoverOnOpenChange } =\n usePopoverOnScrollRef(\n findSpectrumPickerScrollArea,\n onScroll,\n getInitialScrollPositionInternal\n );\n\n const onOpenChangeInternal = useCallback(\n (isOpen: boolean): void => {\n // Attach scroll event handling\n popoverOnOpenChange(isOpen);\n\n onOpenChange?.(isOpen);\n },\n [onOpenChange, popoverOnOpenChange]\n );\n\n const onSelectionChangeInternal = useCallback(\n (key: ItemKey): void => {\n // The `key` arg will always be a string due to us setting the `Item` key\n // prop in `renderItem`. We need to find the matching item to determine\n // the actual key.\n const selectedItem = normalizedItems.find(\n item => String(getItemKey(item)) === key\n );\n\n const actualKey = getItemKey(selectedItem) ?? key;\n\n (onChange ?? onSelectionChange)?.(actualKey);\n },\n [normalizedItems, onChange, onSelectionChange]\n );\n\n return (\n <SpectrumPicker\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...spectrumPickerProps}\n // The `ref` prop type defined by React Spectrum is incorrect here\n ref={scrollRef as unknown as DOMRef<HTMLDivElement>}\n onOpenChange={onOpenChangeInternal}\n UNSAFE_className={cl('dh-picker', UNSAFE_className)}\n items={normalizedItems}\n // Spectrum Picker treats keys as strings if the `key` prop is explicitly\n // set on `Item` elements. Since we do this in `renderItem`, we need to\n // ensure that `selectedKey` and `defaultSelectedKey` are strings in order\n // for selection to work.\n selectedKey={selectedKey?.toString()}\n defaultSelectedKey={defaultSelectedKey?.toString()}\n // `onChange` is just an alias for `onSelectionChange`\n onSelectionChange={\n onSelectionChangeInternal as NormalizedSpectrumPickerProps['onSelectionChange']\n }\n >\n {itemOrSection => {\n if (isNormalizedSection(itemOrSection)) {\n return (\n <Section\n key={getItemKey(itemOrSection)}\n title={itemOrSection.item?.title}\n items={itemOrSection.item?.items}\n >\n {renderItem}\n </Section>\n );\n }\n\n return renderItem(itemOrSection);\n }}\n </SpectrumPicker>\n );\n}\n\nexport default Picker;\n"],"mappings":";;;;;;;;AAAA,SAAyBA,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAE5D,SAASC,IAAI,EAAEC,MAAM,IAAIC,cAAc,QAAQ,uBAAuB;AACtE,SACEC,yBAAyB,EACzBC,4BAA4B,EAC5BC,eAAe,EACfC,qBAAqB,QAChB,wBAAwB;AAC/B,SACEC,cAAc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AY,EAAE0B,oBAAqB;IACnCvB,gBAAgB,EAAEnC,EAAE,CAAC,WAAW,EAAEmC,gBAAgB,CAAE;IACpDgC,KAAK,EAAE5B;IACP;IACA;IACA;IACA;IAAA;IACAV,WAAW,EAAEA,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAEuC,QAAQ,CAAC,CAAE;IACrCxC,kBAAkB,EAAEA,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAEwC,QAAQ,CAAC;IACjD;IAAA;IACAlC,iBAAiB,EACf0B,yBACD;IAAArC,QAAA,EAEA8C,aAAa,IAAI;MAChB,IAAInE,mBAAmB,CAACmE,aAAa,CAAC,EAAE;QAAA,IAAAC,mBAAA,EAAAC,oBAAA;QACtC,oBACE5D,IAAA,CAACH,OAAO;UAENgE,KAAK,GAAAF,mBAAA,GAAED,aAAa,CAACrB,IAAI,cAAAsB,mBAAA,uBAAlBA,mBAAA,CAAoBE,KAAM;UACjCL,KAAK,GAAAI,oBAAA,GAAEF,aAAa,CAACrB,IAAI,cAAAuB,oBAAA,uBAAlBA,oBAAA,CAAoBJ,KAAM;UAAA5C,QAAA,EAEhCkB;QAAU,GAJNpC,UAAU,CAACgE,aAAa,CAKtB,CAAC;MAEd;MAEA,OAAO5B,UAAU,CAAC4B,aAAa,CAAC;IAClC;EAAC,EACa,CAAC;AAErB;AAEA,eAAe9E,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spectrum/picker/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spectrum/picker/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/picker/index.ts"],"sourcesContent":["export * from './Picker';\nexport * from './
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/picker/index.ts"],"sourcesContent":["export * from './Picker';\nexport * from './PickerItemContent';\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/spectrum/utils/index.ts"],"sourcesContent":["export * from './itemUtils';\nexport * from './themeUtils';\n"],"mappings":""}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Key, ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { SpectrumPickerProps } from '@adobe/react-spectrum';
|
|
3
|
+
import type { ItemRenderer } from '@react-types/shared';
|
|
4
|
+
import { KeyedItem } from '@deephaven/utils';
|
|
5
|
+
import { ItemProps, SectionProps } from '../shared';
|
|
6
|
+
import { PopperOptions } from '../../popper';
|
|
7
|
+
export declare const INVALID_ITEM_ERROR_MESSAGE = "Items must be strings, numbers, booleans, <Item> or <Section> elements:";
|
|
8
|
+
/**
|
|
9
|
+
* React Spectrum <Section> supports an `ItemRenderer` function as a child. The
|
|
10
|
+
* DH picker makes use of this internally, but we don't want to support it as
|
|
11
|
+
* an incoming prop.
|
|
12
|
+
*/
|
|
13
|
+
type SectionPropsNoItemRenderer<T> = Omit<SectionProps<T>, 'children'> & {
|
|
14
|
+
children: Exclude<SectionProps<T>['children'], ItemRenderer<T>>;
|
|
15
|
+
};
|
|
16
|
+
type ItemElement = ReactElement<ItemProps<unknown>>;
|
|
17
|
+
export type SectionElement = ReactElement<SectionPropsNoItemRenderer<unknown>>;
|
|
18
|
+
export type ItemElementOrPrimitive = number | string | boolean | ItemElement;
|
|
19
|
+
export type ItemOrSection = ItemElementOrPrimitive | SectionElement;
|
|
20
|
+
/**
|
|
21
|
+
* Augment the Spectrum selection key type to include boolean values.
|
|
22
|
+
* Spectrum collection components already supports this, but the built in types
|
|
23
|
+
* don't reflect it.
|
|
24
|
+
*/
|
|
25
|
+
export type ItemKey = Key | boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Augment the Spectrum selection change handler type to include boolean keys.
|
|
28
|
+
* Spectrum components already supports this, but the built in types don't
|
|
29
|
+
* reflect it.
|
|
30
|
+
*/
|
|
31
|
+
export type ItemSelectionChangeHandler = (key: ItemKey) => void;
|
|
32
|
+
export interface NormalizedItemData {
|
|
33
|
+
key?: ItemKey;
|
|
34
|
+
content: ReactNode;
|
|
35
|
+
textValue?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface NormalizedSectionData {
|
|
38
|
+
key?: Key;
|
|
39
|
+
title?: ReactNode;
|
|
40
|
+
items: NormalizedItem[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Spectrum collection components support a variety of item types, including
|
|
44
|
+
* strings, numbers, booleans, and more complex React elements. This type
|
|
45
|
+
* represents a normalized form to make rendering items simpler and keep the
|
|
46
|
+
* logic of transformation in separate util methods. It also adheres to the
|
|
47
|
+
* `KeyedItem` interface to be compatible with Windowed data utils
|
|
48
|
+
* (e.g. `useViewportData`).
|
|
49
|
+
*/
|
|
50
|
+
export type NormalizedItem = KeyedItem<NormalizedItemData, ItemKey | undefined>;
|
|
51
|
+
export type NormalizedSection = KeyedItem<NormalizedSectionData, Key | undefined>;
|
|
52
|
+
export type NormalizedSpectrumPickerProps = SpectrumPickerProps<NormalizedItem>;
|
|
53
|
+
export type TooltipOptions = {
|
|
54
|
+
placement: PopperOptions['placement'];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* DH wrappers of Spectrum collection components use a normalized item that
|
|
58
|
+
* includes a `key` prop and an optional `item` prop. This is mostly to support
|
|
59
|
+
* Windowed data where items are created before their data has been loaded (data
|
|
60
|
+
* gets set in the `item` prop). If data has loaded, return its `key`. If not,
|
|
61
|
+
* return the top-level `key` on the normalized item.
|
|
62
|
+
* @param item The normalized item or section
|
|
63
|
+
* @returns The `key` of the item or section
|
|
64
|
+
*/
|
|
65
|
+
export declare function getItemKey<TItem extends NormalizedItem | NormalizedSection, TKey extends TItem extends NormalizedItem ? ItemKey | undefined : TItem extends NormalizedSection ? Key | undefined : undefined>(item: TItem | null | undefined): TKey;
|
|
66
|
+
/**
|
|
67
|
+
* Determine if a node is a Section element.
|
|
68
|
+
* @param node The node to check
|
|
69
|
+
* @returns True if the node is a Section element
|
|
70
|
+
*/
|
|
71
|
+
export declare function isSectionElement<T>(node: ReactNode): node is ReactElement<SectionProps<T>>;
|
|
72
|
+
/**
|
|
73
|
+
* Determine if a node is an Item element.
|
|
74
|
+
* @param node The node to check
|
|
75
|
+
* @returns True if the node is an Item element
|
|
76
|
+
*/
|
|
77
|
+
export declare function isItemElement<T>(node: ReactNode): node is ReactElement<ItemProps<T>>;
|
|
78
|
+
/**
|
|
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
|
+
* @param node The node to check
|
|
82
|
+
* @returns True if the node is a normalized item with keys array
|
|
83
|
+
*/
|
|
84
|
+
export declare function isNormalizedItemsWithKeysList(node: ItemOrSection | ItemOrSection[] | (NormalizedItem | NormalizedSection)[]): node is (NormalizedItem | NormalizedSection)[];
|
|
85
|
+
/**
|
|
86
|
+
* Determine if an object is a normalized section.
|
|
87
|
+
* @param maybeNormalizedSection The object to check
|
|
88
|
+
* @returns True if the object is a normalized section
|
|
89
|
+
*/
|
|
90
|
+
export declare function isNormalizedSection(maybeNormalizedSection: NormalizedItem | NormalizedSection): maybeNormalizedSection is NormalizedSection;
|
|
91
|
+
/**
|
|
92
|
+
* Determine if a node is an item or section. Valid types include strings,
|
|
93
|
+
* numbers, booleans, Item elements, and Section elements.
|
|
94
|
+
* @param node The node to check
|
|
95
|
+
* @returns True if the node is an item or section
|
|
96
|
+
*/
|
|
97
|
+
export declare function isItemOrSection(node: ReactNode): node is ItemOrSection;
|
|
98
|
+
/**
|
|
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
|
|
102
|
+
*/
|
|
103
|
+
export declare function normalizeItemList(itemsOrSections: ItemOrSection | ItemOrSection[] | NormalizedItem[]): (NormalizedItem | NormalizedSection)[];
|
|
104
|
+
/**
|
|
105
|
+
* Returns a TooltipOptions object or null if options is false or null.
|
|
106
|
+
* @param options
|
|
107
|
+
* @returns TooltipOptions or null
|
|
108
|
+
*/
|
|
109
|
+
export declare function normalizeTooltipOptions(options?: boolean | TooltipOptions | null): TooltipOptions | null;
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=itemUtils.d.ts.map
|
|
@@ -0,0 +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,CAAC;AAI7C,eAAO,MAAM,0BAA0B,4EACoC,CAAC;AAE5E;;;;GAIG;AACH,KAAK,0BAA0B,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;IACvE,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,CAAC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O,GAAG,SAAS,GACnB,KAAK,SAAS,iBAAiB,GAC/B,GAAG,GAAG,SAAS,GACf,SAAS,EACb,IAAI,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,IAAI,EAAE,SAAS,GACd,IAAI,IAAI,YAAY,CAAC,YAAY,CAAC,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,IAAI,EAAE,aAAa,GAAG,aAAa,EAAE,GAAG,CAAC,cAAc,GAAG,iBAAiB,CAAC,EAAE,GAC7E,IAAI,IAAI,CAAC,cAAc,GAAG,iBAAiB,CAAC,EAAE,CAUhD;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,CAC/B,eAAe,EAAE,aAAa,GAAG,aAAa,EAAE,GAAG,cAAc,EAAE,GAClE,CAAC,cAAc,GAAG,iBAAiB,CAAC,EAAE,CAWxC;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,CAAC,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,GACxC,cAAc,GAAG,IAAI,CAUvB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isValidElement } from 'react';
|
|
2
2
|
import Log from '@deephaven/log';
|
|
3
3
|
import { Item, Section } from "../shared.js";
|
|
4
|
-
var log = Log.module('
|
|
5
|
-
export var
|
|
4
|
+
var log = Log.module('itemUtils');
|
|
5
|
+
export var INVALID_ITEM_ERROR_MESSAGE = 'Items must be strings, numbers, booleans, <Item> or <Section> elements:';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* React Spectrum <Section> supports an `ItemRenderer` function as a child. The
|
|
@@ -12,34 +12,35 @@ export var INVALID_PICKER_ITEM_ERROR_MESSAGE = 'Picker items must be strings, nu
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Augment the Spectrum selection key type to include boolean values.
|
|
15
|
-
*
|
|
16
|
-
* reflect it.
|
|
15
|
+
* Spectrum collection components already supports this, but the built in types
|
|
16
|
+
* don't reflect it.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Augment the Spectrum selection change handler type to include boolean keys.
|
|
21
|
-
*
|
|
21
|
+
* Spectrum components already supports this, but the built in types don't
|
|
22
22
|
* reflect it.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
* booleans, and more complex React elements. This type
|
|
28
|
-
* form to make rendering items simpler and keep the
|
|
29
|
-
* in separate util methods. It also adheres to the
|
|
30
|
-
* be compatible with Windowed data utils
|
|
26
|
+
* Spectrum collection components support a variety of item types, including
|
|
27
|
+
* strings, numbers, booleans, and more complex React elements. This type
|
|
28
|
+
* represents a normalized form to make rendering items simpler and keep the
|
|
29
|
+
* logic of transformation in separate util methods. It also adheres to the
|
|
30
|
+
* `KeyedItem` interface to be compatible with Windowed data utils
|
|
31
|
+
* (e.g. `useViewportData`).
|
|
31
32
|
*/
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
-
* `item` prop. This is mostly to support
|
|
36
|
-
* before their data has been loaded (data
|
|
37
|
-
* data has loaded, return its `key`. If not,
|
|
38
|
-
* normalized item.
|
|
39
|
-
* @param item The normalized
|
|
35
|
+
* DH wrappers of Spectrum collection components use a normalized item that
|
|
36
|
+
* includes a `key` prop and an optional `item` prop. This is mostly to support
|
|
37
|
+
* Windowed data where items are created before their data has been loaded (data
|
|
38
|
+
* gets set in the `item` prop). If data has loaded, return its `key`. If not,
|
|
39
|
+
* return the top-level `key` on the normalized item.
|
|
40
|
+
* @param item The normalized item or section
|
|
40
41
|
* @returns The `key` of the item or section
|
|
41
42
|
*/
|
|
42
|
-
export function
|
|
43
|
+
export function getItemKey(item) {
|
|
43
44
|
var _item$item$key, _item$item;
|
|
44
45
|
return (_item$item$key = item === null || item === void 0 ? void 0 : (_item$item = item.item) === null || _item$item === void 0 ? void 0 : _item$item.key) !== null && _item$item$key !== void 0 ? _item$item$key : item === null || item === void 0 ? void 0 : item.key;
|
|
45
46
|
}
|
|
@@ -75,32 +76,32 @@ export function isNormalizedItemsWithKeysList(node) {
|
|
|
75
76
|
if (node.length === 0) {
|
|
76
77
|
return true;
|
|
77
78
|
}
|
|
78
|
-
return !
|
|
79
|
+
return !isItemOrSection(node[0]) && 'key' in node[0];
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
/**
|
|
82
|
-
* Determine if an object is a normalized
|
|
83
|
-
* @param
|
|
84
|
-
* @returns True if the object is a normalized
|
|
83
|
+
* Determine if an object is a normalized section.
|
|
84
|
+
* @param maybeNormalizedSection The object to check
|
|
85
|
+
* @returns True if the object is a normalized section
|
|
85
86
|
*/
|
|
86
|
-
export function
|
|
87
|
-
return
|
|
87
|
+
export function isNormalizedSection(maybeNormalizedSection) {
|
|
88
|
+
return maybeNormalizedSection.item != null && 'items' in maybeNormalizedSection.item;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|
|
91
|
-
* Determine if a node is
|
|
92
|
+
* Determine if a node is an item or section. Valid types include strings,
|
|
92
93
|
* numbers, booleans, Item elements, and Section elements.
|
|
93
94
|
* @param node The node to check
|
|
94
|
-
* @returns True if the node is
|
|
95
|
+
* @returns True if the node is an item or section
|
|
95
96
|
*/
|
|
96
|
-
export function
|
|
97
|
+
export function isItemOrSection(node) {
|
|
97
98
|
return typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean' || isItemElement(node) || isSectionElement(node);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
* Determine the `key` of
|
|
102
|
-
* @param itemOrSection The
|
|
103
|
-
* @returns A `
|
|
102
|
+
* Determine the `key` of an item or section.
|
|
103
|
+
* @param itemOrSection The item or section
|
|
104
|
+
* @returns A `ItemKey` for the item or undefined if a key can't be determined
|
|
104
105
|
*/
|
|
105
106
|
|
|
106
107
|
function normalizeItemKey(itemOrSection) {
|
|
@@ -125,9 +126,9 @@ function normalizeItemKey(itemOrSection) {
|
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
/**
|
|
128
|
-
* Get a normalized `textValue` for
|
|
129
|
-
* @param item The
|
|
130
|
-
* @returns A string `textValue` for the
|
|
129
|
+
* Get a normalized `textValue` for an item ensuring it is a string.
|
|
130
|
+
* @param item The item
|
|
131
|
+
* @returns A string `textValue` for the item
|
|
131
132
|
*/
|
|
132
133
|
function normalizeTextValue(item) {
|
|
133
134
|
if (typeof item !== 'object') {
|
|
@@ -143,21 +144,21 @@ function normalizeTextValue(item) {
|
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
/**
|
|
146
|
-
* Normalize
|
|
147
|
+
* Normalize an item or section to an object form.
|
|
147
148
|
* @param itemOrSection item to normalize
|
|
148
|
-
* @returns
|
|
149
|
+
* @returns NormalizedItem or NormalizedSection object
|
|
149
150
|
*/
|
|
150
|
-
function
|
|
151
|
-
if (!
|
|
152
|
-
log.debug(
|
|
153
|
-
throw new Error(
|
|
151
|
+
function normalizeItem(itemOrSection) {
|
|
152
|
+
if (!isItemOrSection(itemOrSection)) {
|
|
153
|
+
log.debug(INVALID_ITEM_ERROR_MESSAGE, itemOrSection);
|
|
154
|
+
throw new Error(INVALID_ITEM_ERROR_MESSAGE);
|
|
154
155
|
}
|
|
155
156
|
if (isSectionElement(itemOrSection)) {
|
|
156
157
|
var _key = normalizeItemKey(itemOrSection);
|
|
157
158
|
var {
|
|
158
159
|
title
|
|
159
160
|
} = itemOrSection.props;
|
|
160
|
-
var items =
|
|
161
|
+
var items = normalizeItemList(itemOrSection.props.children).filter(
|
|
161
162
|
// We don't support nested section elements
|
|
162
163
|
childItem => !isSectionElement(childItem));
|
|
163
164
|
return {
|
|
@@ -181,17 +182,17 @@ function normalizePickerItem(itemOrSection) {
|
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
/**
|
|
184
|
-
* Get normalized
|
|
185
|
-
* @param itemsOrSections
|
|
186
|
-
* @returns An array of normalized
|
|
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
|
|
187
188
|
*/
|
|
188
|
-
export function
|
|
189
|
+
export function normalizeItemList(itemsOrSections) {
|
|
189
190
|
// If already normalized, just return as-is
|
|
190
191
|
if (isNormalizedItemsWithKeysList(itemsOrSections)) {
|
|
191
192
|
return itemsOrSections;
|
|
192
193
|
}
|
|
193
194
|
var itemsArray = Array.isArray(itemsOrSections) ? itemsOrSections : [itemsOrSections];
|
|
194
|
-
return itemsArray.map(
|
|
195
|
+
return itemsArray.map(normalizeItem);
|
|
195
196
|
}
|
|
196
197
|
|
|
197
198
|
/**
|
|
@@ -210,4 +211,4 @@ export function normalizeTooltipOptions(options) {
|
|
|
210
211
|
}
|
|
211
212
|
return options;
|
|
212
213
|
}
|
|
213
|
-
//# sourceMappingURL=
|
|
214
|
+
//# sourceMappingURL=itemUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemUtils.js","names":["isValidElement","Log","Item","Section","log","module","INVALID_ITEM_ERROR_MESSAGE","getItemKey","item","_item$item$key","_item$item","key","isSectionElement","node","type","isItemElement","isNormalizedItemsWithKeysList","Array","isArray","length","isItemOrSection","isNormalizedSection","maybeNormalizedSection","normalizeItemKey","itemOrSection","_itemOrSection$props$","props","title","undefined","textValue","children","normalizeTextValue","String","normalizeItem","debug","Error","items","normalizeItemList","filter","childItem","content","itemsOrSections","itemsArray","map","normalizeTooltipOptions","options","placement"],"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;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AAC,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,3 +1,4 @@
|
|
|
1
|
+
export { useStyleProps, baseStyleProps, viewStyleProps, } from '@react-spectrum/utils';
|
|
1
2
|
/**
|
|
2
3
|
* Extend light + dark theme variables with DH defaults.
|
|
3
4
|
*
|
|
@@ -42,4 +43,4 @@ export declare const themeDHDefault: {
|
|
|
42
43
|
medium: import("@react-types/provider").CSSModule | undefined;
|
|
43
44
|
large: import("@react-types/provider").CSSModule | undefined;
|
|
44
45
|
};
|
|
45
|
-
//# sourceMappingURL=
|
|
46
|
+
//# sourceMappingURL=themeUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeUtils.d.ts","sourceRoot":"","sources":["../../../src/spectrum/utils/themeUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,GACf,MAAM,uBAAuB,CAAC;AAI/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;CAa1B,CAAC"}
|
|
@@ -4,7 +4,8 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
4
4
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
5
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
6
|
import { theme } from '@react-spectrum/theme-default';
|
|
7
|
-
import { themeSpectrumClassesCommon } from "
|
|
7
|
+
import { themeSpectrumClassesCommon } from "../../theme/theme-spectrum/index.js";
|
|
8
|
+
export { useStyleProps, baseStyleProps, viewStyleProps } from '@react-spectrum/utils';
|
|
8
9
|
var {
|
|
9
10
|
global,
|
|
10
11
|
light,
|
|
@@ -55,4 +56,4 @@ export var themeDHDefault = {
|
|
|
55
56
|
medium,
|
|
56
57
|
large
|
|
57
58
|
};
|
|
58
|
-
//# sourceMappingURL=
|
|
59
|
+
//# sourceMappingURL=themeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeUtils.js","names":["theme","themeSpectrumClassesCommon","useStyleProps","baseStyleProps","viewStyleProps","global","light","dark","medium","large","themeDHDefault","_objectSpread"],"sources":["../../../src/spectrum/utils/themeUtils.ts"],"sourcesContent":["import { theme } from '@react-spectrum/theme-default';\nimport { themeSpectrumClassesCommon } from '../../theme/theme-spectrum';\n\nexport {\n useStyleProps,\n baseStyleProps,\n viewStyleProps,\n} from '@react-spectrum/utils';\n\nconst { global, light, dark, medium, large } = theme;\n\n/**\n * Extend light + dark theme variables with DH defaults.\n *\n * A theme is just a mapped collection of css class names that are generated\n * from a collection of css modules.\n *\n * e.g.\n * {\n * global: {\n * spectrum: 'spectrum_9e130c',\n * 'spectrum--medium': 'spectrum--medium_9e130c',\n * 'spectrum--large': 'spectrum--large_9e130c',\n * 'spectrum--darkest': 'spectrum--darkest_9e130c',\n * 'spectrum--dark': 'spectrum--dark_9e130c',\n * 'spectrum--light': 'spectrum--light_9e130c',\n * 'spectrum--lightest': 'spectrum--lightest_9e130c',\n * },\n * light: {\n * 'spectrum--light': 'spectrum--light_a40724',\n * 'dh-spectrum-theme--light': '_dh-spectrum-theme--light_1hblg_22',\n * },\n * dark: {\n * 'spectrum--darkest': 'spectrum--darkest_256eeb',\n * 'dh-spectrum-theme--dark': '_dh-spectrum-theme--dark_f7kge_22',\n * },\n * medium: {\n * 'spectrum--medium': 'spectrum--medium_4b172c',\n * },\n * large: {\n * 'spectrum--large': 'spectrum--large_c40598',\n * },\n * }\n */\n/* eslint-disable import/prefer-default-export */\nexport const themeDHDefault = {\n global,\n light: {\n ...light,\n ...themeSpectrumClassesCommon,\n },\n dark: {\n ...dark,\n ...themeSpectrumClassesCommon,\n },\n // scales\n medium,\n large,\n};\n"],"mappings":";;;;;AAAA,SAASA,KAAK,QAAQ,+BAA+B;AAAC,SAC7CC,0BAA0B;AAEnC,SACEC,aAAa,EACbC,cAAc,EACdC,cAAc,QACT,uBAAuB;AAE9B,IAAM;EAAEC,MAAM;EAAEC,KAAK;EAAEC,IAAI;EAAEC,MAAM;EAAEC;AAAM,CAAC,GAAGT,KAAK;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAMU,cAAc,GAAG;EAC5BL,MAAM;EACNC,KAAK,EAAAK,aAAA,CAAAA,aAAA,KACAL,KAAK,GACLL,0BAA0B,CAC9B;EACDM,IAAI,EAAAI,aAAA,CAAAA,aAAA,KACCJ,IAAI,GACJN,0BAA0B,CAC9B;EACD;EACAO,MAAM;EACNC;AACF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { Provider } from '@adobe/react-spectrum';
|
|
3
3
|
import shortid from 'shortid';
|
|
4
|
-
import { themeDHDefault } from "../spectrum/utils.js";
|
|
4
|
+
import { themeDHDefault } from "../spectrum/utils/index.js";
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
/**
|
|
7
7
|
* Wrapper around React Spectrum's theme Provider that provides DH mappings of
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.0",
|
|
4
4
|
"description": "Deephaven React component library",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,13 +25,14 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@adobe/react-spectrum": "^3.34.1",
|
|
28
|
-
"@deephaven/icons": "^0.
|
|
29
|
-
"@deephaven/log": "^0.
|
|
30
|
-
"@deephaven/react-hooks": "^0.
|
|
31
|
-
"@deephaven/utils": "^0.
|
|
28
|
+
"@deephaven/icons": "^0.72.0",
|
|
29
|
+
"@deephaven/log": "^0.72.0",
|
|
30
|
+
"@deephaven/react-hooks": "^0.72.0",
|
|
31
|
+
"@deephaven/utils": "^0.72.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",
|
|
35
|
+
"@react-spectrum/utils": "^3.11.5",
|
|
35
36
|
"@react-types/shared": "^3.22.1",
|
|
36
37
|
"@react-types/textfield": "^3.9.1",
|
|
37
38
|
"bootstrap": "4.6.2",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"react-dom": ">=16.8.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@deephaven/mocks": "^0.
|
|
58
|
+
"@deephaven/mocks": "^0.72.0"
|
|
58
59
|
},
|
|
59
60
|
"files": [
|
|
60
61
|
"dist",
|
|
@@ -68,5 +69,5 @@
|
|
|
68
69
|
"publishConfig": {
|
|
69
70
|
"access": "public"
|
|
70
71
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "cbff452ae56921ea2b5440d6c09d53a8844d6f65"
|
|
72
73
|
}
|