@semcore/ellipsis 2.1.2 → 2.1.3-beta.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/lib/cjs/Ellipsis.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/index.js +2 -8
- package/lib/cjs/index.js.map +1 -1
- package/lib/es6/Ellipsis.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/index.js +1 -1
- package/lib/es6/index.js.map +1 -1
- package/lib/types/index.d.ts +47 -2
- package/package.json +2 -2
- package/lib/types/Ellipsis.d.ts +0 -37
- package/lib/types/useResizeObserver.d.ts +0 -6
package/lib/cjs/Ellipsis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ellipsis.js","names":["_core","_interopRequireWildcard","require","_react","_tooltip","_interopRequireDefault","_flexBox","_useResizeObserver","_useEnhancedEffect","_reactToText","_getOriginChildren","_pick","style","sstyled","insert","defaultTooltipProps","createMeasurerElement","element","styleElement","window","getComputedStyle","temporaryElement","document","createElement","display","padding","position","right","bottom","visibility","fontFamily","getPropertyValue","fontSize","fontWeight","innerHTML","isTextOverflowing","multiline","_element$getBoundingC","getBoundingClientRect","currentHeight","height","currentWidth","width","measuringElement","currentSize","initialSize","body","appendChild","concat","whiteSpace","removeChild","RootEllipsis","_Component","_inherits2","_super","_createSuper2","_this","_classCallCheck2","_len","arguments","length","args","Array","_key","call","apply","_defineProperty2","_assertThisInitialized2","visible","React","createRef","setState","showTooltip","_createClass2","key","value","_this$asProps$maxLine","asProps","maxLine","textRef","current","render","_ref3","SEllipsis","Root","SContainer","Tooltip","SNoTooltipContainer","Box","_this$asProps","styles","Children","tooltip","trim","containerRect","containerRef","includeTooltipProps","state","text","reactToText","getOriginChildren","tooltipProps","pick","_ref","EllipsisMiddle","cn","_ref2","_objectSpread2","handlerVisibleChange","Component","__excludeProps","props","resizeElement","useRef","_useState","useState","symbolWidth","_useState2","_slicedToArray2","dimension","setDimension","blockWidth","useResizeObserver","useEnhancedEffect","_containerRef$current","dateSpan","setAttribute","rect","STail","SBeginning","SContainerMiddle","displayedSymbols","useMemo","Math","round","_ref4","substring","_ref5","Ellipsis","createComponent","_default","exports"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState } from 'react';\nimport createComponent, { Component, Intergalactic, sstyled } from '@semcore/core';\nimport Tooltip, { TooltipProps } from '@semcore/tooltip';\nimport { Box, BoxProps } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\nimport pick from '@semcore/utils/lib/pick';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n includeTooltipProps?: string[];\n __excludeProps?: string[];\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n tooltipProps: TooltipProps;\n};\n\nexport type EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLDivElement>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n };\n\nconst defaultTooltipProps = [\n 'title',\n 'theme',\n 'strategy',\n 'modifiers',\n 'placement',\n 'interaction',\n 'timeout',\n 'visible',\n 'defaultVisible',\n 'onVisibleChange',\n 'offset',\n 'preventOverflow',\n 'arrow',\n 'flip',\n 'computeStyles',\n 'eventListeners',\n 'onFirstUpdate',\n];\n\nconst createMeasurerElement = (element: HTMLDivElement) => {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = 'inline-block';\n temporaryElement.style.padding = '0';\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '150%';\n temporaryElement.style.bottom = '150%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');\n temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');\n temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');\n\n temporaryElement.innerHTML = element.innerHTML;\n return temporaryElement;\n};\n\nfunction isTextOverflowing(element: HTMLDivElement, multiline: boolean): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element);\n let currentSize;\n let initialSize;\n document.body.appendChild(measuringElement);\n if (multiline) {\n currentSize = currentHeight;\n measuringElement.style.width = `${currentWidth}px`;\n initialSize = measuringElement.getBoundingClientRect().height;\n } else {\n currentSize = currentWidth;\n measuringElement.style.whiteSpace = 'nowrap';\n initialSize = measuringElement.getBoundingClientRect().width;\n }\n document.body.removeChild(measuringElement);\n return currentSize < initialSize;\n}\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n includeTooltipProps: defaultTooltipProps,\n __excludeProps: ['title'],\n };\n\n state = {\n visible: false,\n };\n\n textRef = React.createRef<HTMLDivElement>();\n\n showTooltip() {\n const { maxLine = 1 } = this.asProps;\n return isTextOverflowing(this.textRef.current!, maxLine > 1);\n }\n\n handlerVisibleChange = (visible: boolean) => {\n this.setState({ visible: visible && this.showTooltip() });\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const SNoTooltipContainer = Box;\n const {\n styles,\n Children,\n maxLine,\n tooltip,\n trim,\n containerRect,\n containerRef,\n includeTooltipProps,\n } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n const tooltipProps = pick(this.asProps, includeTooltipProps as any) as TooltipProps;\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n tooltipProps={tooltipProps}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer\n interaction='hover'\n title={text as any}\n visible={visible}\n onVisibleChange={this.handlerVisibleChange}\n {...tooltipProps}\n >\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SNoTooltipContainer>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SNoTooltipContainer>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef, tooltipProps } = props;\n const resizeElement = useRef<HTMLDivElement>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useEnhancedEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n document.body.removeChild(dateSpan);\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction={text.length > displayedSymbols ? 'hover' : 'none'}\n title={text as any}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n {...tooltipProps}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis) as any as Intergalactic.Component<\n 'div',\n EllipsisProps\n>;\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;;;;;;;;AACA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AADA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AAEA,IAAAE,QAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAL,OAAA;AACA,IAAAM,kBAAA,GAAAH,sBAAA,CAAAH,OAAA;AAGA,IAAAO,YAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,kBAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,KAAA,GAAAN,sBAAA,CAAAH,OAAA;AAA2C;A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tC,IAAI,CAACtC,MAAM,GAAGuE,gBAAgB,GAAG,CAAC,GAAG,CAAC,CAAC,CAAS,CACtD;EAEvB;AACF,CAAC;AAED,IAAMO,QAAQ,GAAG,IAAAC,gBAAe,EAACxF,YAAY,CAG5C;AAAC,IAAAyF,QAAA,GAEaF,QAAQ;AAAAG,OAAA,cAAAD,QAAA"}
|
|
1
|
+
{"version":3,"file":"Ellipsis.js","names":["_core","_interopRequireWildcard","require","_react","_tooltip","_interopRequireDefault","_flexBox","_useResizeObserver","_useEnhancedEffect","_reactToText","_getOriginChildren","_pick","style","sstyled","insert","defaultTooltipProps","createMeasurerElement","element","styleElement","window","getComputedStyle","temporaryElement","document","createElement","display","padding","position","right","bottom","visibility","fontFamily","getPropertyValue","fontSize","fontWeight","innerHTML","isTextOverflowing","multiline","_element$getBoundingC","getBoundingClientRect","currentHeight","height","currentWidth","width","measuringElement","currentSize","initialSize","body","appendChild","concat","whiteSpace","removeChild","RootEllipsis","_Component","_inherits2","_super","_createSuper2","_this","_classCallCheck2","_len","arguments","length","args","Array","_key","call","apply","_defineProperty2","_assertThisInitialized2","visible","React","createRef","setState","showTooltip","_createClass2","key","value","_this$asProps$maxLine","asProps","maxLine","textRef","current","render","_ref3","SEllipsis","Root","SContainer","Tooltip","SNoTooltipContainer","Box","_this$asProps","styles","Children","tooltip","trim","containerRect","containerRef","includeTooltipProps","state","text","reactToText","getOriginChildren","tooltipProps","pick","_ref","EllipsisMiddle","cn","_ref2","_objectSpread2","handlerVisibleChange","Component","__excludeProps","props","resizeElement","useRef","_useState","useState","symbolWidth","_useState2","_slicedToArray2","dimension","setDimension","blockWidth","useResizeObserver","useEnhancedEffect","_containerRef$current","dateSpan","setAttribute","rect","STail","SBeginning","SContainerMiddle","displayedSymbols","useMemo","Math","round","_ref4","substring","_ref5","Ellipsis","createComponent","_default","exports"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState } from 'react';\nimport createComponent, { Component, Intergalactic, sstyled } from '@semcore/core';\nimport Tooltip, { TooltipProps } from '@semcore/tooltip';\nimport { Box, BoxProps } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\nimport pick from '@semcore/utils/lib/pick';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n includeTooltipProps?: string[];\n __excludeProps?: string[];\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n tooltipProps: TooltipProps;\n};\n\ntype EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLDivElement>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n };\n\nconst defaultTooltipProps = [\n 'title',\n 'theme',\n 'strategy',\n 'modifiers',\n 'placement',\n 'interaction',\n 'timeout',\n 'visible',\n 'defaultVisible',\n 'onVisibleChange',\n 'offset',\n 'preventOverflow',\n 'arrow',\n 'flip',\n 'computeStyles',\n 'eventListeners',\n 'onFirstUpdate',\n];\n\nconst createMeasurerElement = (element: HTMLDivElement) => {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = 'inline-block';\n temporaryElement.style.padding = '0';\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '150%';\n temporaryElement.style.bottom = '150%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');\n temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');\n temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');\n\n temporaryElement.innerHTML = element.innerHTML;\n return temporaryElement;\n};\n\nfunction isTextOverflowing(element: HTMLDivElement, multiline: boolean): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element);\n let currentSize;\n let initialSize;\n document.body.appendChild(measuringElement);\n if (multiline) {\n currentSize = currentHeight;\n measuringElement.style.width = `${currentWidth}px`;\n initialSize = measuringElement.getBoundingClientRect().height;\n } else {\n currentSize = currentWidth;\n measuringElement.style.whiteSpace = 'nowrap';\n initialSize = measuringElement.getBoundingClientRect().width;\n }\n document.body.removeChild(measuringElement);\n return currentSize < initialSize;\n}\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n includeTooltipProps: defaultTooltipProps,\n __excludeProps: ['title'],\n };\n\n state = {\n visible: false,\n };\n\n textRef = React.createRef<HTMLDivElement>();\n\n showTooltip() {\n const { maxLine = 1 } = this.asProps;\n return isTextOverflowing(this.textRef.current!, maxLine > 1);\n }\n\n handlerVisibleChange = (visible: boolean) => {\n this.setState({ visible: visible && this.showTooltip() });\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const SNoTooltipContainer = Box;\n const {\n styles,\n Children,\n maxLine,\n tooltip,\n trim,\n containerRect,\n containerRef,\n includeTooltipProps,\n } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n const tooltipProps = pick(this.asProps, includeTooltipProps as any) as TooltipProps;\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n tooltipProps={tooltipProps}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer\n interaction='hover'\n title={text as any}\n visible={visible}\n onVisibleChange={this.handlerVisibleChange}\n {...tooltipProps}\n >\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SNoTooltipContainer>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SNoTooltipContainer>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef, tooltipProps } = props;\n const resizeElement = useRef<HTMLDivElement>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useEnhancedEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n document.body.removeChild(dateSpan);\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction={text.length > displayedSymbols ? 'hover' : 'none'}\n title={text as any}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n {...tooltipProps}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis) as any as Intergalactic.Component<\n 'div',\n EllipsisProps\n>;\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;;;;;;;;AACA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AADA,IAAAC,MAAA,GAAAF,uBAAA,CAAAC,OAAA;AAEA,IAAAE,QAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,kBAAA,GAAAL,OAAA;AACA,IAAAM,kBAAA,GAAAH,sBAAA,CAAAH,OAAA;AAGA,IAAAO,YAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,kBAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,KAAA,GAAAN,sBAAA,CAAAH,OAAA;AAA2C;AAAA,IAAAU,KAAA,+BAAAZ,KAAA,CAAAa,OAAA,CAAAC,MAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAwD3C,IAAMC,mBAAmB,GAAG,CAC1B,OAAO,EACP,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBA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@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { UnknownProperties, Intergalactic } from '@semcore/core';\nimport { RefObject } from 'react';\nimport { BoxProps } from '@semcore/flex-box';\nimport { TooltipProps } from '@semcore/tooltip';\n\n/** @deprecated */\nexport interface IEllipsisProps extends EllipsisProps, UnknownProperties {}\nexport type EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n
|
|
1
|
+
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { UnknownProperties, Intergalactic } from '@semcore/core';\nimport { RefObject } from 'react';\nimport { BoxProps } from '@semcore/flex-box';\nimport { TooltipProps } from '@semcore/tooltip';\n\n/** @deprecated */\nexport interface IEllipsisProps extends EllipsisProps, UnknownProperties {}\nexport type EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n containerRef?: RefObject<HTMLElement | null>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n };\n\ndeclare const useResizeObserver: (\n ref: RefObject<HTMLElement>,\n hookOverride?: { width: number },\n) => { width: number };\n\ndeclare const Ellipsis: Intergalactic.Component<'div', EllipsisProps>;\n\nexport { useResizeObserver };\nexport default Ellipsis;\n"],"mappings":""}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
Object.defineProperty(exports, "EllipsisProps", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function get() {
|
|
10
|
-
return _Ellipsis.EllipsisProps;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
7
|
Object.defineProperty(exports, "default", {
|
|
14
8
|
enumerable: true,
|
|
15
9
|
get: function get() {
|
|
@@ -22,6 +16,6 @@ Object.defineProperty(exports, "useResizeObserver", {
|
|
|
22
16
|
return _useResizeObserver.useResizeObserver;
|
|
23
17
|
}
|
|
24
18
|
});
|
|
25
|
-
var _Ellipsis =
|
|
19
|
+
var _Ellipsis = _interopRequireDefault(require("./Ellipsis"));
|
|
26
20
|
var _useResizeObserver = require("./useResizeObserver");
|
|
27
21
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_Ellipsis","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_Ellipsis","_interopRequireDefault","require","_useResizeObserver"],"sources":["../../src/index.js"],"sourcesContent":["export { default } from './Ellipsis';\nexport { useResizeObserver } from './useResizeObserver';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,kBAAA,GAAAD,OAAA"}
|
package/lib/es6/Ellipsis.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ellipsis.js","names":["React","useRef","useMemo","useState","createComponent","Component","sstyled","Tooltip","Box","useResizeObserver","useEnhancedEffect","style","_sstyled","insert","reactToText","getOriginChildren","pick","defaultTooltipProps","createMeasurerElement","element","styleElement","window","getComputedStyle","temporaryElement","document","createElement","display","padding","position","right","bottom","visibility","fontFamily","getPropertyValue","fontSize","fontWeight","innerHTML","isTextOverflowing","multiline","_element$getBoundingC","getBoundingClientRect","currentHeight","height","currentWidth","width","measuringElement","currentSize","initialSize","body","appendChild","concat","whiteSpace","removeChild","RootEllipsis","_Component","_inherits","_super","_createSuper","_this","_classCallCheck","_len","arguments","length","args","Array","_key","call","apply","_defineProperty","_assertThisInitialized","visible","createRef","setState","showTooltip","_createClass","key","value","_this$asProps$maxLine","asProps","maxLine","textRef","current","render","_ref3","SEllipsis","Root","SContainer","SNoTooltipContainer","_this$asProps","styles","Children","tooltip","trim","containerRect","containerRef","includeTooltipProps","state","text","tooltipProps","_ref","EllipsisMiddle","cn","_ref2","_objectSpread","handlerVisibleChange","__excludeProps","props","resizeElement","_useState","symbolWidth","_useState2","_slicedToArray","dimension","setDimension","blockWidth","_containerRef$current","dateSpan","setAttribute","rect","STail","SBeginning","SContainerMiddle","displayedSymbols","Math","round","_ref4","substring","_ref5","Ellipsis"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState } from 'react';\nimport createComponent, { Component, Intergalactic, sstyled } from '@semcore/core';\nimport Tooltip, { TooltipProps } from '@semcore/tooltip';\nimport { Box, BoxProps } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\nimport pick from '@semcore/utils/lib/pick';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n includeTooltipProps?: string[];\n __excludeProps?: string[];\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n tooltipProps: TooltipProps;\n};\n\nexport type EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLDivElement>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n };\n\nconst defaultTooltipProps = [\n 'title',\n 'theme',\n 'strategy',\n 'modifiers',\n 'placement',\n 'interaction',\n 'timeout',\n 'visible',\n 'defaultVisible',\n 'onVisibleChange',\n 'offset',\n 'preventOverflow',\n 'arrow',\n 'flip',\n 'computeStyles',\n 'eventListeners',\n 'onFirstUpdate',\n];\n\nconst createMeasurerElement = (element: HTMLDivElement) => {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = 'inline-block';\n temporaryElement.style.padding = '0';\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '150%';\n temporaryElement.style.bottom = '150%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');\n temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');\n temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');\n\n temporaryElement.innerHTML = element.innerHTML;\n return temporaryElement;\n};\n\nfunction isTextOverflowing(element: HTMLDivElement, multiline: boolean): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element);\n let currentSize;\n let initialSize;\n document.body.appendChild(measuringElement);\n if (multiline) {\n currentSize = currentHeight;\n measuringElement.style.width = `${currentWidth}px`;\n initialSize = measuringElement.getBoundingClientRect().height;\n } else {\n currentSize = currentWidth;\n measuringElement.style.whiteSpace = 'nowrap';\n initialSize = measuringElement.getBoundingClientRect().width;\n }\n document.body.removeChild(measuringElement);\n return currentSize < initialSize;\n}\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n includeTooltipProps: defaultTooltipProps,\n __excludeProps: ['title'],\n };\n\n state = {\n visible: false,\n };\n\n textRef = React.createRef<HTMLDivElement>();\n\n showTooltip() {\n const { maxLine = 1 } = this.asProps;\n return isTextOverflowing(this.textRef.current!, maxLine > 1);\n }\n\n handlerVisibleChange = (visible: boolean) => {\n this.setState({ visible: visible && this.showTooltip() });\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const SNoTooltipContainer = Box;\n const {\n styles,\n Children,\n maxLine,\n tooltip,\n trim,\n containerRect,\n containerRef,\n includeTooltipProps,\n } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n const tooltipProps = pick(this.asProps, includeTooltipProps as any) as TooltipProps;\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n tooltipProps={tooltipProps}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer\n interaction='hover'\n title={text as any}\n visible={visible}\n onVisibleChange={this.handlerVisibleChange}\n {...tooltipProps}\n >\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SNoTooltipContainer>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SNoTooltipContainer>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef, tooltipProps } = props;\n const resizeElement = useRef<HTMLDivElement>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useEnhancedEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n document.body.removeChild(dateSpan);\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction={text.length > displayedSymbols ? 'hover' : 'none'}\n title={text as any}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n {...tooltipProps}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis) as any as Intergalactic.Component<\n 'div',\n EllipsisProps\n>;\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;AAAA,OAAOA,KAAK,IAAeC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACnE,OAAOC,eAAe,IAAIC,SAAS,EAAiBC,OAAO,QAAQ,eAAe;AAClF,OAAOC,OAAO,MAAwB,kBAAkB;AACxD,SAASC,GAAG,QAAkB,mBAAmB;AACjD,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,OAAOC,iBAAiB,MAAM,0CAA0C;AAAC;AAAA,IAAAC,KAAA,+BAAAC,QAAA,CAAAC,MAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;AAAA;AAGzE,OAAOC,WAAW,MAAM,gCAAgC;AACxD,OAAOC,iBAAiB,MAAM,sCAAsC;AACpE,OAAOC,IAAI,MAAM,yBAAyB;AAwD1C,IAAMC,mBAAmB,GAAG,CAC1B,OAAO,EACP,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,MAAM,EACN,eAAe,EACf,gBAAgB,EAChB,eAAe,CAChB;AAED,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAqBA,CAAIC,OAAuB,EAAK;EACzD,IAAMC,YAAY,GAAGC,MAAM,CAACC,gBAAgB,CAACH,OAAO,EAAE,IAAI,CAAC;EAC3D,IAAMI,gBAAgB,GAAGC,QAAQ,CAACC,aAAa,CAAC,iBAAiB,CAAC;EAClEF,gBAAgB,CAACZ,KAAK,CAACe,OAAO,GAAG,cAAc;EAC/CH,gBAAgB,CAACZ,KAAK,CAACgB,OAAO,GAAG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F,MAAM,CAAC,eACpBzF,KAAA,CAAAyB,aAAA,CAACgG,gBAAgB,EAAAM,KAAA,CAAA1B,EAAA;MAAA,OAAMP,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAIa;IAAa,iBAClD3G,KAAA,CAAAyB,aAAA,CAAC+F,UAAU,EAAAO,KAAA,CAAA1B,EAAA,oBAAEJ,IAAI,CAAC6B,SAAS,CAAC,CAAC,EAAE7B,IAAI,CAACnC,MAAM,GAAG4D,gBAAgB,GAAG,CAAC,GAAG,CAAC,CAAC,CAAc,eACpF1H,KAAA,CAAAyB,aAAA,CAAC8F,KAAK,EAAAQ,KAAA,CAAA1B,EAAA,eAAEJ,IAAI,CAAC6B,SAAS,CAAC7B,IAAI,CAACnC,MAAM,GAAG4D,gBAAgB,GAAG,CAAC,GAAG,CAAC,CAAC,CAAS,CACtD;EAEvB;AACF,CAAC;AAED,IAAMM,QAAQ,GAAG5H,eAAe,CAACiD,YAAY,CAG5C;AAED,eAAe2E,QAAQ"}
|
|
1
|
+
{"version":3,"file":"Ellipsis.js","names":["React","useRef","useMemo","useState","createComponent","Component","sstyled","Tooltip","Box","useResizeObserver","useEnhancedEffect","style","_sstyled","insert","reactToText","getOriginChildren","pick","defaultTooltipProps","createMeasurerElement","element","styleElement","window","getComputedStyle","temporaryElement","document","createElement","display","padding","position","right","bottom","visibility","fontFamily","getPropertyValue","fontSize","fontWeight","innerHTML","isTextOverflowing","multiline","_element$getBoundingC","getBoundingClientRect","currentHeight","height","currentWidth","width","measuringElement","currentSize","initialSize","body","appendChild","concat","whiteSpace","removeChild","RootEllipsis","_Component","_inherits","_super","_createSuper","_this","_classCallCheck","_len","arguments","length","args","Array","_key","call","apply","_defineProperty","_assertThisInitialized","visible","createRef","setState","showTooltip","_createClass","key","value","_this$asProps$maxLine","asProps","maxLine","textRef","current","render","_ref3","SEllipsis","Root","SContainer","SNoTooltipContainer","_this$asProps","styles","Children","tooltip","trim","containerRect","containerRef","includeTooltipProps","state","text","tooltipProps","_ref","EllipsisMiddle","cn","_ref2","_objectSpread","handlerVisibleChange","__excludeProps","props","resizeElement","_useState","symbolWidth","_useState2","_slicedToArray","dimension","setDimension","blockWidth","_containerRef$current","dateSpan","setAttribute","rect","STail","SBeginning","SContainerMiddle","displayedSymbols","Math","round","_ref4","substring","_ref5","Ellipsis"],"sources":["../../src/Ellipsis.tsx"],"sourcesContent":["import React, { RefObject, useRef, useMemo, useState } from 'react';\nimport createComponent, { Component, Intergalactic, sstyled } from '@semcore/core';\nimport Tooltip, { TooltipProps } from '@semcore/tooltip';\nimport { Box, BoxProps } from '@semcore/flex-box';\nimport { useResizeObserver } from './useResizeObserver';\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n\nimport style from './style/ellipsis.shadow.css';\nimport reactToText from '@semcore/utils/lib/reactToText';\nimport getOriginChildren from '@semcore/utils/lib/getOriginChildren';\nimport pick from '@semcore/utils/lib/pick';\n\ntype AsProps = {\n maxLine?: number;\n trim?: 'end' | 'middle';\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n includeTooltipProps?: string[];\n __excludeProps?: string[];\n};\n\ntype AsPropsMiddle = {\n text: string;\n tooltip?: boolean;\n styles?: React.CSSProperties;\n containerRect?: { width: number };\n\n containerRef?: RefObject<HTMLDivElement>;\n tooltipProps: TooltipProps;\n};\n\ntype EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope\n containerRef?: RefObject<HTMLDivElement>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n };\n\nconst defaultTooltipProps = [\n 'title',\n 'theme',\n 'strategy',\n 'modifiers',\n 'placement',\n 'interaction',\n 'timeout',\n 'visible',\n 'defaultVisible',\n 'onVisibleChange',\n 'offset',\n 'preventOverflow',\n 'arrow',\n 'flip',\n 'computeStyles',\n 'eventListeners',\n 'onFirstUpdate',\n];\n\nconst createMeasurerElement = (element: HTMLDivElement) => {\n const styleElement = window.getComputedStyle(element, null);\n const temporaryElement = document.createElement('temporary-block');\n temporaryElement.style.display = 'inline-block';\n temporaryElement.style.padding = '0';\n temporaryElement.style.position = 'absolute';\n temporaryElement.style.right = '150%';\n temporaryElement.style.bottom = '150%';\n temporaryElement.style.visibility = 'hidden';\n temporaryElement.style.fontFamily = styleElement.getPropertyValue('font-family');\n temporaryElement.style.fontSize = styleElement.getPropertyValue('font-size');\n temporaryElement.style.fontWeight = styleElement.getPropertyValue('font-weight');\n\n temporaryElement.innerHTML = element.innerHTML;\n return temporaryElement;\n};\n\nfunction isTextOverflowing(element: HTMLDivElement, multiline: boolean): boolean {\n if (!element) return false;\n\n const { height: currentHeight, width: currentWidth } = element.getBoundingClientRect();\n const measuringElement = createMeasurerElement(element);\n let currentSize;\n let initialSize;\n document.body.appendChild(measuringElement);\n if (multiline) {\n currentSize = currentHeight;\n measuringElement.style.width = `${currentWidth}px`;\n initialSize = measuringElement.getBoundingClientRect().height;\n } else {\n currentSize = currentWidth;\n measuringElement.style.whiteSpace = 'nowrap';\n initialSize = measuringElement.getBoundingClientRect().width;\n }\n document.body.removeChild(measuringElement);\n return currentSize < initialSize;\n}\n\nclass RootEllipsis extends Component<AsProps> {\n static displayName = 'Ellipsis';\n static style = style;\n static defaultProps: AsProps = {\n trim: 'end',\n tooltip: true,\n includeTooltipProps: defaultTooltipProps,\n __excludeProps: ['title'],\n };\n\n state = {\n visible: false,\n };\n\n textRef = React.createRef<HTMLDivElement>();\n\n showTooltip() {\n const { maxLine = 1 } = this.asProps;\n return isTextOverflowing(this.textRef.current!, maxLine > 1);\n }\n\n handlerVisibleChange = (visible: boolean) => {\n this.setState({ visible: visible && this.showTooltip() });\n };\n\n render() {\n const SEllipsis = this.Root;\n const SContainer = Tooltip;\n const SNoTooltipContainer = Box;\n const {\n styles,\n Children,\n maxLine,\n tooltip,\n trim,\n containerRect,\n containerRef,\n includeTooltipProps,\n } = this.asProps;\n const { visible } = this.state;\n const text = reactToText(getOriginChildren(Children));\n const tooltipProps = pick(this.asProps, includeTooltipProps as any) as TooltipProps;\n if (trim === 'middle') {\n return sstyled(styles)(\n <EllipsisMiddle\n text={text}\n styles={styles}\n tooltip={tooltip}\n containerRect={containerRect}\n containerRef={containerRef}\n tooltipProps={tooltipProps}\n />,\n );\n }\n if (tooltip) {\n return sstyled(styles)(\n <SContainer\n interaction='hover'\n title={text as any}\n visible={visible}\n onVisibleChange={this.handlerVisibleChange}\n {...tooltipProps}\n >\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SContainer>,\n );\n }\n return sstyled(styles)(\n <SNoTooltipContainer>\n <SEllipsis render={Box} ref={this.textRef} maxLine={maxLine}>\n <Children />\n </SEllipsis>\n </SNoTooltipContainer>,\n );\n }\n}\n\nconst EllipsisMiddle: React.FC<AsPropsMiddle> = (props) => {\n const { styles, text, tooltip, containerRect, containerRef, tooltipProps } = props;\n const resizeElement = useRef<HTMLDivElement>(null);\n const [dimension, setDimension] = useState<{ fontSize: string; symbolWidth: number }>({\n fontSize: '14',\n symbolWidth: 0,\n });\n const blockWidth = useResizeObserver(resizeElement, containerRect).width;\n\n useEnhancedEffect(() => {\n const dateSpan = document.createElement('temporary-block');\n dateSpan.setAttribute('style', `fontSize: ${dimension.fontSize}px`);\n dateSpan.innerHTML = 'a';\n document.body.appendChild(dateSpan);\n const rect = dateSpan.getBoundingClientRect();\n\n setDimension({\n fontSize: window\n // @ts-ignore\n .getComputedStyle(containerRef?.current ?? resizeElement.current, null)\n .getPropertyValue('font-size'),\n symbolWidth: rect.width,\n });\n document.body.removeChild(dateSpan);\n }, []);\n\n const STail = 'span';\n const SBeginning = 'span';\n const SContainerMiddle = Box;\n const displayedSymbols = useMemo(\n () => Math.round(blockWidth / dimension.symbolWidth),\n [blockWidth, dimension.symbolWidth],\n );\n\n if (tooltip) {\n return sstyled(styles)(\n <SContainerMiddle\n interaction={text.length > displayedSymbols ? 'hover' : 'none'}\n title={text as any}\n ref={containerRef ?? resizeElement}\n tag={Tooltip}\n {...tooltipProps}\n >\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n } else {\n return sstyled(styles)(\n <SContainerMiddle ref={containerRef ?? resizeElement}>\n <SBeginning>{text.substring(0, text.length - displayedSymbols / 2 - 1)}</SBeginning>\n <STail>{text.substring(text.length - displayedSymbols / 2 - 1)}</STail>\n </SContainerMiddle>,\n ) as any;\n }\n};\n\nconst Ellipsis = createComponent(RootEllipsis) as any as Intergalactic.Component<\n 'div',\n EllipsisProps\n>;\n\nexport default Ellipsis;\n"],"mappings":";;;;;;;;;AAAA,OAAOA,KAAK,IAAeC,MAAM,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACnE,OAAOC,eAAe,IAAIC,SAAS,EAAiBC,OAAO,QAAQ,eAAe;AAClF,OAAOC,OAAO,MAAwB,kBAAkB;AACxD,SAASC,GAAG,QAAkB,mBAAmB;AACjD,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,OAAOC,iBAAiB,MAAM,0CAA0C;AAAC;AAAA,IAAAC,KAAA,+BAAAC,QAAA,CAAAC,MAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EAAA;EA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AAG5H,eAAe,CAACiD,YAAY,CAG5C;AAED,eAAe2E,QAAQ"}
|
package/lib/es6/index.d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { UnknownProperties, Intergalactic } from '@semcore/core';\nimport { RefObject } from 'react';\nimport { BoxProps } from '@semcore/flex-box';\nimport { TooltipProps } from '@semcore/tooltip';\n\n/** @deprecated */\nexport interface IEllipsisProps extends EllipsisProps, UnknownProperties {}\nexport type EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n
|
|
1
|
+
{"version":3,"file":"index.d.js","names":[],"sources":["../../src/index.d.ts"],"sourcesContent":["import { UnknownProperties, Intergalactic } from '@semcore/core';\nimport { RefObject } from 'react';\nimport { BoxProps } from '@semcore/flex-box';\nimport { TooltipProps } from '@semcore/tooltip';\n\n/** @deprecated */\nexport interface IEllipsisProps extends EllipsisProps, UnknownProperties {}\nexport type EllipsisProps = BoxProps &\n Partial<TooltipProps> & {\n /**\n * Rows count in multiline Ellipsis\n * @default 1\n */\n maxLine?: number;\n /**\n * Trimming type\n * @default end\n */\n trim?: 'end' | 'middle';\n /**\n * Show tooltip\n * @default true\n */\n tooltip?: boolean;\n /**\n * Ref to the item that will be observed by ResizeObserver\n */\n containerRef?: RefObject<HTMLElement | null>;\n /**\n * Explicit sizes of container text should be trimmed in\n **/\n containerRect?: { width: number };\n /** List of props that will be passed to tooltip\n * @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']\n */\n includeTooltipProps?: string[];\n };\n\ndeclare const useResizeObserver: (\n ref: RefObject<HTMLElement>,\n hookOverride?: { width: number },\n) => { width: number };\n\ndeclare const Ellipsis: Intergalactic.Component<'div', EllipsisProps>;\n\nexport { useResizeObserver };\nexport default Ellipsis;\n"],"mappings":""}
|
package/lib/es6/index.js
CHANGED
package/lib/es6/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["default","
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","useResizeObserver"],"sources":["../../src/index.js"],"sourcesContent":["export { default } from './Ellipsis';\nexport { useResizeObserver } from './useResizeObserver';\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AACpC,SAASC,iBAAiB,QAAQ,qBAAqB"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,2 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { UnknownProperties, Intergalactic } from '@semcore/core';
|
|
2
|
+
import { RefObject } from 'react';
|
|
3
|
+
import { BoxProps } from '@semcore/flex-box';
|
|
4
|
+
import { TooltipProps } from '@semcore/tooltip';
|
|
5
|
+
|
|
6
|
+
/** @deprecated */
|
|
7
|
+
export interface IEllipsisProps extends EllipsisProps, UnknownProperties {}
|
|
8
|
+
export type EllipsisProps = BoxProps &
|
|
9
|
+
Partial<TooltipProps> & {
|
|
10
|
+
/**
|
|
11
|
+
* Rows count in multiline Ellipsis
|
|
12
|
+
* @default 1
|
|
13
|
+
*/
|
|
14
|
+
maxLine?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Trimming type
|
|
17
|
+
* @default end
|
|
18
|
+
*/
|
|
19
|
+
trim?: 'end' | 'middle';
|
|
20
|
+
/**
|
|
21
|
+
* Show tooltip
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
tooltip?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Ref to the item that will be observed by ResizeObserver
|
|
27
|
+
*/
|
|
28
|
+
containerRef?: RefObject<HTMLElement | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Explicit sizes of container text should be trimmed in
|
|
31
|
+
**/
|
|
32
|
+
containerRect?: { width: number };
|
|
33
|
+
/** List of props that will be passed to tooltip
|
|
34
|
+
* @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']
|
|
35
|
+
*/
|
|
36
|
+
includeTooltipProps?: string[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
declare const useResizeObserver: (
|
|
40
|
+
ref: RefObject<HTMLElement>,
|
|
41
|
+
hookOverride?: { width: number },
|
|
42
|
+
) => { width: number };
|
|
43
|
+
|
|
44
|
+
declare const Ellipsis: Intergalactic.Component<'div', EllipsisProps>;
|
|
45
|
+
|
|
46
|
+
export { useResizeObserver };
|
|
47
|
+
export default Ellipsis;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/ellipsis",
|
|
3
3
|
"description": "Semrush Ellipsis Component",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.3-beta.0",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"directory": "semcore/ellipsis"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "pnpm semcore-builder"
|
|
31
|
+
"build": "pnpm semcore-builder --source=js"
|
|
32
32
|
}
|
|
33
33
|
}
|
package/lib/types/Ellipsis.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
import { Intergalactic } from '@semcore/core';
|
|
3
|
-
import { TooltipProps } from '@semcore/tooltip';
|
|
4
|
-
import { BoxProps } from '@semcore/flex-box';
|
|
5
|
-
export type EllipsisProps = BoxProps & Partial<TooltipProps> & {
|
|
6
|
-
/**
|
|
7
|
-
* Rows count in multiline Ellipsis
|
|
8
|
-
* @default 1
|
|
9
|
-
*/
|
|
10
|
-
maxLine?: number;
|
|
11
|
-
/**
|
|
12
|
-
* Trimming type
|
|
13
|
-
* @default end
|
|
14
|
-
*/
|
|
15
|
-
trim?: 'end' | 'middle';
|
|
16
|
-
/**
|
|
17
|
-
* Show tooltip
|
|
18
|
-
* @default true
|
|
19
|
-
*/
|
|
20
|
-
tooltip?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Ref to the item that will be observed by ResizeObserver
|
|
23
|
-
*/
|
|
24
|
-
containerRef?: RefObject<HTMLDivElement>;
|
|
25
|
-
/**
|
|
26
|
-
* Explicit sizes of container text should be trimmed in
|
|
27
|
-
**/
|
|
28
|
-
containerRect?: {
|
|
29
|
-
width: number;
|
|
30
|
-
};
|
|
31
|
-
/** List of props that will be passed to tooltip
|
|
32
|
-
* @default ['title', 'theme', 'strategy', 'modifiers', 'placement', 'interaction', 'timeout', 'visible', 'defaultVisible', 'onVisibleChange', 'offset', 'preventOverflow', 'arrow', 'flip', 'computeStyles', 'eventListeners', 'onFirstUpdate']
|
|
33
|
-
*/
|
|
34
|
-
includeTooltipProps?: string[];
|
|
35
|
-
};
|
|
36
|
-
declare const Ellipsis: Intergalactic.Component<"div", EllipsisProps, {}, never[]>;
|
|
37
|
-
export default Ellipsis;
|