@salutejs/plasma-new-hope 0.158.0-dev.0 → 0.158.1-canary.1454.11140695341.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/cjs/components/Attach/Attach.js +13 -9
  2. package/cjs/components/Attach/Attach.js.map +1 -1
  3. package/cjs/components/Attach/utils/addSeparator.js +17 -0
  4. package/cjs/components/Attach/utils/addSeparator.js.map +1 -0
  5. package/cjs/components/Attach/utils/index.js +11 -0
  6. package/cjs/components/Attach/utils/index.js.map +1 -0
  7. package/emotion/cjs/components/Attach/Attach.js +9 -6
  8. package/emotion/cjs/components/Attach/utils/addSeparator.js +15 -0
  9. package/emotion/cjs/components/Attach/utils/index.js +9 -7
  10. package/emotion/es/components/Attach/Attach.js +10 -7
  11. package/emotion/es/components/Attach/utils/addSeparator.js +9 -0
  12. package/emotion/es/components/Attach/utils/index.js +2 -1
  13. package/es/components/Attach/Attach.js +13 -9
  14. package/es/components/Attach/Attach.js.map +1 -1
  15. package/es/components/Attach/utils/addSeparator.js +13 -0
  16. package/es/components/Attach/utils/addSeparator.js.map +1 -0
  17. package/es/components/Attach/utils/index.js +7 -0
  18. package/es/components/Attach/utils/index.js.map +1 -0
  19. package/package.json +2 -2
  20. package/styled-components/cjs/components/Attach/Attach.js +9 -6
  21. package/styled-components/cjs/components/Attach/utils/addSeparator.js +15 -0
  22. package/styled-components/cjs/components/Attach/utils/index.js +9 -7
  23. package/styled-components/es/components/Attach/Attach.js +10 -7
  24. package/styled-components/es/components/Attach/utils/addSeparator.js +9 -0
  25. package/styled-components/es/components/Attach/utils/index.js +2 -1
  26. package/types/components/Attach/Attach.d.ts.map +1 -1
  27. package/types/components/Attach/utils/addSeparator.d.ts +2 -0
  28. package/types/components/Attach/utils/addSeparator.d.ts.map +1 -0
  29. package/types/components/Attach/utils/index.d.ts +2 -1
  30. package/types/components/Attach/utils/index.d.ts.map +1 -1
  31. package/cjs/components/Attach/utils/truncateFilename.js +0 -24
  32. package/cjs/components/Attach/utils/truncateFilename.js.map +0 -1
  33. package/emotion/cjs/components/Attach/utils/truncateFilename.js +0 -23
  34. package/emotion/es/components/Attach/utils/truncateFilename.js +0 -17
  35. package/es/components/Attach/utils/truncateFilename.js +0 -20
  36. package/es/components/Attach/utils/truncateFilename.js.map +0 -1
  37. package/styled-components/cjs/components/Attach/utils/truncateFilename.js +0 -23
  38. package/styled-components/es/components/Attach/utils/truncateFilename.js +0 -17
  39. package/types/components/Attach/utils/truncateFilename.d.ts +0 -7
  40. package/types/components/Attach/utils/truncateFilename.d.ts.map +0 -1
@@ -12,12 +12,13 @@ var base$1 = require('./variations/_size/base.js');
12
12
  var base = require('./variations/_view/base.js');
13
13
  var Attach_styles = require('./Attach.styles.js');
14
14
  var Cell_styles = require('./ui/Cell/Cell.styles.js');
15
- var extractExtension = require('./utils/extractExtension.js');
16
- var getFileicon = require('./utils/getFileicon.js');
17
- var truncateFilename = require('./utils/truncateFilename.js');
15
+ var index$1 = require('./utils/index.js');
18
16
  var Attach_tokens = require('./Attach.tokens.js');
19
17
  var AttachButton = require('./components/AttachButton/AttachButton.js');
20
18
  var IconButton_styles = require('./ui/IconButton/IconButton.styles.js');
19
+ var extractExtension = require('./utils/extractExtension.js');
20
+ var addSeparator = require('./utils/addSeparator.js');
21
+ var getFileicon = require('./utils/getFileicon.js');
21
22
 
22
23
  var _IconCloseCircleOutli;
23
24
  var _excluded = ["flow", "buttonType", "hasAttachment", "acceptedFileFormats", "size", "view", "className", "style", "isLoading", "disabled"];
@@ -76,15 +77,18 @@ var attachRoot = function attachRoot(Root) {
76
77
  cellLeft = _cellRef$current$getB.left;
77
78
  var leftDiff = cellLeft - parentLeft;
78
79
  var currentTextWidth = textWidth;
79
- var currFilename = filename;
80
- for (var i = filename.length - 1; i > 0; i -= 1) {
80
+ if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth || currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
81
+ setTruncatedFilename(filename);
82
+ return;
83
+ }
84
+ var currFilename = addSeparator.addSeparator(filename, index$1.separator);
85
+ for (var i = currFilename.indexOf(index$1.separator) - 1; i > 0; i -= 1) {
81
86
  if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {
82
87
  break;
83
88
  }
84
- var newFilename = truncateFilename.truncateFilename({
85
- filename: inputHelperRef.current.textContent,
86
- startNameTruncationIndex: i
87
- });
89
+ var left = currFilename.slice(0, i);
90
+ var right = currFilename.slice(i + 1);
91
+ var newFilename = "".concat(left).concat(right);
88
92
  inputHelperRef.current.textContent = newFilename;
89
93
  currentTextWidth = inputHelperRef.current.offsetWidth;
90
94
  if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
@@ -1 +1 @@
1
- {"version":3,"file":"Attach.js","sources":["../../../src/components/Attach/Attach.tsx"],"sourcesContent":["import React, { forwardRef, useEffect, useRef, useState } from 'react';\nimport { useForkRef, useIsomorphicLayoutEffect } from '@salutejs/plasma-core';\n\nimport { RootProps } from '../../engines';\nimport { cx } from '../../utils';\nimport { IconCloseCircleOutline } from '../_Icon';\n\nimport { AttachProps } from './Attach.types';\nimport { base as sizeCSS } from './variations/_size/base';\nimport { base as viewCSS } from './variations/_view/base';\nimport { base, StyledHiddenInput, StyledHiddenInputHelper } from './Attach.styles';\nimport { StyledCell } from './ui/Cell/Cell';\nimport { extractExtension, getFileicon, truncateFilename } from './utils';\nimport { classes } from './Attach.tokens';\nimport { AttachButton } from './components/AttachButton';\nimport { StyledIconButtonCancel } from './ui/IconButton/IconButton.styles';\n\nexport const attachRoot = (Root: RootProps<HTMLDivElement, AttachProps>) =>\n forwardRef<HTMLDivElement, AttachProps>((props, outerRef) => {\n const {\n flow = 'auto',\n buttonType = 'button',\n hasAttachment = true,\n acceptedFileFormats,\n size,\n view,\n className,\n style,\n isLoading,\n disabled,\n ...rest\n } = props;\n\n const innerRef = useRef<HTMLDivElement>(null);\n const ref = useForkRef(outerRef, innerRef);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const inputHelperRef = useRef<HTMLDivElement | null>(null);\n const cellRef = useRef<HTMLDivElement | null>(null);\n const buttonRef = useRef<HTMLButtonElement | null>(null);\n\n const emptyTextCellWidth = useRef<number | null>(null);\n\n const [filename, setFilename] = useState<string>('');\n const [truncatedFilename, setTruncatedFilename] = useState<string>('');\n\n const horizontalClass = flow === 'horizontal' ? classes.horizontal : undefined;\n const verticalClass = flow === 'vertical' ? classes.vertical : undefined;\n const autoClass = flow === 'auto' ? classes.auto : undefined;\n const cellHiddenClass = truncatedFilename.length === 0 ? classes.cellHidden : undefined;\n\n const accept = acceptedFileFormats?.join(',');\n const extension = extractExtension(filename);\n const cellContentLeft = getFileicon(extension, size);\n\n useEffect(() => {\n emptyTextCellWidth.current = cellRef.current?.offsetWidth || 0;\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n if (\n !cellRef.current ||\n !cellRef.current.parentElement ||\n !inputHelperRef.current ||\n !inputHelperRef.current.textContent ||\n !emptyTextCellWidth.current ||\n !buttonRef.current\n ) {\n return;\n }\n\n const { offsetWidth: textWidth } = inputHelperRef.current;\n const { offsetWidth: buttonWidth } = buttonRef.current;\n const { width: parentWidth, left: parentLeft } = cellRef.current.parentElement.getBoundingClientRect();\n const { left: cellLeft } = cellRef.current.getBoundingClientRect();\n const leftDiff = cellLeft - parentLeft;\n\n let currentTextWidth = textWidth;\n let currFilename = filename;\n\n for (let i = filename.length - 1; i > 0; i -= 1) {\n if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {\n break;\n }\n\n const newFilename = truncateFilename({\n filename: inputHelperRef.current.textContent,\n startNameTruncationIndex: i,\n });\n inputHelperRef.current.textContent = newFilename;\n currentTextWidth = inputHelperRef.current.offsetWidth;\n\n if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {\n break;\n }\n\n currFilename = newFilename;\n }\n\n inputHelperRef.current.textContent = filename;\n setTruncatedFilename(currFilename);\n });\n\n const handleClick = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.click();\n };\n\n const handleChange = () => {\n if (!inputRef.current || !inputRef.current.files) {\n return;\n }\n\n setFilename(inputRef.current.files[0].name);\n };\n\n const handleClear = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.value = '';\n setFilename('');\n setTruncatedFilename('');\n };\n\n return (\n <Root\n className={cx(horizontalClass, verticalClass, autoClass, className)}\n style={style}\n size={size}\n view={view}\n ref={ref}\n >\n <StyledHiddenInput\n ref={inputRef}\n accept={accept}\n type=\"file\"\n id=\"attachHiddenInput\"\n name=\"attachHiddenInput\"\n onChange={handleChange}\n />\n <StyledHiddenInputHelper ref={inputHelperRef} id=\"attachHiddenInputHelper\">\n {filename}\n </StyledHiddenInputHelper>\n\n <AttachButton\n buttonType={buttonType}\n view={view}\n size={size}\n onClick={handleClick}\n isLoading={isLoading}\n disabled={disabled}\n ref={buttonRef}\n {...rest}\n />\n {hasAttachment && (\n <StyledCell\n stretching=\"fixed\"\n className={cellHiddenClass}\n ref={cellRef}\n size={size}\n title={truncatedFilename}\n contentLeft={cellContentLeft}\n contentRight={\n <StyledIconButtonCancel view={view} size={size} onClick={handleClear}>\n <IconCloseCircleOutline size=\"xs\" color=\"inherit\" />\n </StyledIconButtonCancel>\n }\n />\n )}\n </Root>\n );\n });\n\nexport const attachConfig = {\n name: 'Attach',\n tag: 'div',\n layout: attachRoot,\n base,\n variations: {\n view: {\n css: viewCSS,\n },\n size: {\n css: sizeCSS,\n },\n },\n defaults: {\n view: 'default',\n size: 'm',\n },\n};\n"],"names":["attachRoot","Root","forwardRef","props","outerRef","_props$flow","flow","_props$buttonType","buttonType","_props$hasAttachment","hasAttachment","acceptedFileFormats","size","view","className","style","isLoading","disabled","rest","_objectWithoutProperties","_excluded","innerRef","useRef","ref","useForkRef","inputRef","inputHelperRef","cellRef","buttonRef","emptyTextCellWidth","_useState","useState","_useState2","_slicedToArray","filename","setFilename","_useState3","_useState4","truncatedFilename","setTruncatedFilename","horizontalClass","classes","horizontal","undefined","verticalClass","vertical","autoClass","auto","cellHiddenClass","length","cellHidden","accept","join","extension","extractExtension","cellContentLeft","getFileicon","useEffect","_cellRef$current","current","offsetWidth","useIsomorphicLayoutEffect","parentElement","textContent","textWidth","buttonWidth","_cellRef$current$pare","getBoundingClientRect","parentWidth","width","parentLeft","left","_cellRef$current$getB","cellLeft","leftDiff","currentTextWidth","currFilename","i","newFilename","truncateFilename","startNameTruncationIndex","handleClick","click","handleChange","files","name","handleClear","value","React","createElement","cx","StyledHiddenInput","type","id","onChange","StyledHiddenInputHelper","AttachButton","_extends","onClick","StyledCell","stretching","title","contentLeft","contentRight","StyledIconButtonCancel","_IconCloseCircleOutli","IconCloseCircleOutline","color","attachConfig","tag","layout","base","variations","css","viewCSS","sizeCSS","defaults"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;IAiBaA,UAAU,GAAG,SAAbA,UAAUA,CAAIC,IAA4C,EAAA;AAAA,EAAA,oBACnEC,gBAAU,CAA8B,UAACC,KAAK,EAAEC,QAAQ,EAAK;AACzD,IAAA,IAAAC,WAAA,GAYIF,KAAK,CAXLG,IAAI;AAAJA,MAAAA,IAAI,GAAAD,WAAA,KAAG,KAAA,CAAA,GAAA,MAAM,GAAAA,WAAA;MAAAE,iBAAA,GAWbJ,KAAK,CAVLK,UAAU;AAAVA,MAAAA,UAAU,GAAAD,iBAAA,KAAG,KAAA,CAAA,GAAA,QAAQ,GAAAA,iBAAA;MAAAE,oBAAA,GAUrBN,KAAK,CATLO,aAAa;AAAbA,MAAAA,aAAa,GAAAD,oBAAA,KAAG,KAAA,CAAA,GAAA,IAAI,GAAAA,oBAAA;MACpBE,mBAAmB,GAQnBR,KAAK,CARLQ,mBAAmB;MACnBC,IAAI,GAOJT,KAAK,CAPLS,IAAI;MACJC,IAAI,GAMJV,KAAK,CANLU,IAAI;MACJC,SAAS,GAKTX,KAAK,CALLW,SAAS;MACTC,KAAK,GAILZ,KAAK,CAJLY,KAAK;MACLC,SAAS,GAGTb,KAAK,CAHLa,SAAS;MACTC,QAAQ,GAERd,KAA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IAAI,EAAC,IAAI;AAAC+F,QAAAA,KAAK,EAAC,SAAA;AAAS,OAAE,CAAC,CAChC,CAAA;AAC3B,KACJ,CAEH,CAAC,CAAA;AAEf,GAAC,CAAC,CAAA;AAAA,EAAA;AAEC,IAAMC,YAAY,GAAG;AACxBvB,EAAAA,IAAI,EAAE,QAAQ;AACdwB,EAAAA,GAAG,EAAE,KAAK;AACVC,EAAAA,MAAM,EAAE9G,UAAU;AAClB+G,EAAAA,IAAI,EAAJA,kBAAI;AACJC,EAAAA,UAAU,EAAE;AACRnG,IAAAA,IAAI,EAAE;AACFoG,MAAAA,GAAG,EAAEC,SAAAA;KACR;AACDtG,IAAAA,IAAI,EAAE;AACFqG,MAAAA,GAAG,EAAEE,WAAAA;AACT,KAAA;GACH;AACDC,EAAAA,QAAQ,EAAE;AACNvG,IAAAA,IAAI,EAAE,SAAS;AACfD,IAAAA,IAAI,EAAE,GAAA;AACV,GAAA;AACJ;;;;;"}
1
+ {"version":3,"file":"Attach.js","sources":["../../../src/components/Attach/Attach.tsx"],"sourcesContent":["import React, { forwardRef, useEffect, useRef, useState } from 'react';\nimport { useForkRef, useIsomorphicLayoutEffect } from '@salutejs/plasma-core';\n\nimport { RootProps } from '../../engines';\nimport { cx } from '../../utils';\nimport { IconCloseCircleOutline } from '../_Icon';\n\nimport { AttachProps } from './Attach.types';\nimport { base as sizeCSS } from './variations/_size/base';\nimport { base as viewCSS } from './variations/_view/base';\nimport { base, StyledHiddenInput, StyledHiddenInputHelper } from './Attach.styles';\nimport { StyledCell } from './ui/Cell/Cell';\nimport { extractExtension, getFileicon, addSeparator, separator } from './utils';\nimport { classes } from './Attach.tokens';\nimport { AttachButton } from './components/AttachButton';\nimport { StyledIconButtonCancel } from './ui/IconButton/IconButton.styles';\n\nexport const attachRoot = (Root: RootProps<HTMLDivElement, AttachProps>) =>\n forwardRef<HTMLDivElement, AttachProps>((props, outerRef) => {\n const {\n flow = 'auto',\n buttonType = 'button',\n hasAttachment = true,\n acceptedFileFormats,\n size,\n view,\n className,\n style,\n isLoading,\n disabled,\n ...rest\n } = props;\n\n const innerRef = useRef<HTMLDivElement>(null);\n const ref = useForkRef(outerRef, innerRef);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const inputHelperRef = useRef<HTMLDivElement | null>(null);\n const cellRef = useRef<HTMLDivElement | null>(null);\n const buttonRef = useRef<HTMLButtonElement | null>(null);\n\n const emptyTextCellWidth = useRef<number | null>(null);\n\n const [filename, setFilename] = useState<string>('');\n const [truncatedFilename, setTruncatedFilename] = useState<string>('');\n\n const horizontalClass = flow === 'horizontal' ? classes.horizontal : undefined;\n const verticalClass = flow === 'vertical' ? classes.vertical : undefined;\n const autoClass = flow === 'auto' ? classes.auto : undefined;\n const cellHiddenClass = truncatedFilename.length === 0 ? classes.cellHidden : undefined;\n\n const accept = acceptedFileFormats?.join(',');\n const extension = extractExtension(filename);\n const cellContentLeft = getFileicon(extension, size);\n\n useEffect(() => {\n emptyTextCellWidth.current = cellRef.current?.offsetWidth || 0;\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n if (\n !cellRef.current ||\n !cellRef.current.parentElement ||\n !inputHelperRef.current ||\n !inputHelperRef.current.textContent ||\n !emptyTextCellWidth.current ||\n !buttonRef.current\n ) {\n return;\n }\n\n const { offsetWidth: textWidth } = inputHelperRef.current;\n const { offsetWidth: buttonWidth } = buttonRef.current;\n const { width: parentWidth, left: parentLeft } = cellRef.current.parentElement.getBoundingClientRect();\n const { left: cellLeft } = cellRef.current.getBoundingClientRect();\n const leftDiff = cellLeft - parentLeft;\n let currentTextWidth = textWidth;\n\n if (\n currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth ||\n currentTextWidth + emptyTextCellWidth.current < buttonWidth\n ) {\n setTruncatedFilename(filename);\n return;\n }\n\n let currFilename = addSeparator(filename, separator);\n for (let i = currFilename.indexOf(separator) - 1; i > 0; i -= 1) {\n if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {\n break;\n }\n\n const left = currFilename.slice(0, i);\n const right = currFilename.slice(i + 1);\n const newFilename = `${left}${right}`;\n inputHelperRef.current.textContent = newFilename;\n currentTextWidth = inputHelperRef.current.offsetWidth;\n\n if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {\n break;\n }\n\n currFilename = newFilename;\n }\n\n inputHelperRef.current.textContent = filename;\n setTruncatedFilename(currFilename);\n });\n\n const handleClick = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.click();\n };\n\n const handleChange = () => {\n if (!inputRef.current || !inputRef.current.files) {\n return;\n }\n\n setFilename(inputRef.current.files[0].name);\n };\n\n const handleClear = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.value = '';\n setFilename('');\n setTruncatedFilename('');\n };\n\n return (\n <Root\n className={cx(horizontalClass, verticalClass, autoClass, className)}\n style={style}\n size={size}\n view={view}\n ref={ref}\n >\n <StyledHiddenInput\n ref={inputRef}\n accept={accept}\n type=\"file\"\n id=\"attachHiddenInput\"\n name=\"attachHiddenInput\"\n onChange={handleChange}\n />\n <StyledHiddenInputHelper ref={inputHelperRef} id=\"attachHiddenInputHelper\">\n {filename}\n </StyledHiddenInputHelper>\n\n <AttachButton\n buttonType={buttonType}\n view={view}\n size={size}\n onClick={handleClick}\n isLoading={isLoading}\n disabled={disabled}\n ref={buttonRef}\n {...rest}\n />\n {hasAttachment && (\n <StyledCell\n stretching=\"fixed\"\n className={cellHiddenClass}\n ref={cellRef}\n size={size}\n title={truncatedFilename}\n contentLeft={cellContentLeft}\n contentRight={\n <StyledIconButtonCancel view={view} size={size} onClick={handleClear}>\n <IconCloseCircleOutline size=\"xs\" color=\"inherit\" />\n </StyledIconButtonCancel>\n }\n />\n )}\n </Root>\n );\n });\n\nexport const attachConfig = {\n name: 'Attach',\n tag: 'div',\n layout: attachRoot,\n base,\n variations: {\n view: {\n css: viewCSS,\n },\n size: {\n css: sizeCSS,\n },\n },\n defaults: {\n view: 'default',\n size: 'm',\n },\n};\n"],"names":["attachRoot","Root","forwardRef","props","outerRef","_props$flow","flow","_props$buttonType","buttonType","_props$hasAttachment","hasAttachment","acceptedFileFormats","size","view","className","style","isLoading","disabled","rest","_objectWithoutProperties","_excluded","innerRef","useRef","ref","useForkRef","inputRef","inputHelperRef","cellRef","buttonRef","emptyTextCellWidth","_useState","useState","_useState2","_slicedToArray","filename","setFilename","_useState3","_useState4","truncatedFilename","setTruncatedFilename","horizontalClass","classes","horizontal","undefined","verticalClass","vertical","autoClass","auto","cellHiddenClass","length","cellHidden","accept","join","extension","extractExtension","cellContentLeft","getFileicon","useEffect","_cellRef$current","current","offsetWidth","useIsomorphicLayoutEffect","parentElement","textContent","textWidth","buttonWidth","_cellRef$current$pare","getBoundingClientRect","parentWidth","width","parentLeft","left","_cellRef$current$getB","cellLeft","leftDiff","currentTextWidth","currFilename","addSeparator","separator","i","indexOf","slice","right","newFilename","concat","handleClick","click","handleChange","files","name","handleClear","value","React","createElement","cx","StyledHiddenInput","type","id","onChange","StyledHiddenInputHelper","AttachButton","_extends","onClick","StyledCell","stretching","title","contentLeft","contentRight","StyledIconButtonCancel","_IconCloseCircleOutli","IconCloseCircleOutline","color","attachConfig","tag","layout","base","variations","css","viewCSS","sizeCSS","defaults"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;IAiBaA,UAAU,GAAG,SAAbA,UAAUA,CAAIC,IAA4C,EAAA;AAAA,EAAA,oBACnEC,gBAAU,CAA8B,UAACC,KAAK,EAAEC,QAAQ,EAAK;AACzD,IAAA,IAAAC,WAAA,GAYIF,KAAK,CAXLG,IAAI;AAAJA,MAAAA,IAAI,GAAAD,WAAA,KAAG,KAAA,CAAA,GAAA,MAAM,GAAAA,WAAA;MAAAE,iBAAA,GAWbJ,KAAK,CAVLK,UAAU;AAAVA,MAAAA,UAAU,GAAAD,iBAAA,KAAG,KAAA,CAAA,GAAA,QAAQ,GAAAA,iBAAA;MAAAE,oBAAA,GAUrBN,KAAK,CATLO,aAAa;AAAbA,MAAAA,aA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AAS;AACfD,IAAAA,IAAI,EAAE,GAAA;AACV,GAAA;AACJ;;;;;"}
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var extractExtension = require('./extractExtension.js');
6
+
7
+ var addSeparator = function addSeparator(filename, separator) {
8
+ var extension = extractExtension.extractExtension(filename);
9
+ var strings = filename.split('.');
10
+ var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
11
+ var lastChar = name[name.length - 1];
12
+ var dotChar = '.';
13
+ return extension === name ? "".concat(name.slice(0, -1)).concat(separator).concat(lastChar) : "".concat(name.slice(0, -1)).concat(separator).concat(lastChar).concat(dotChar).concat(extension);
14
+ };
15
+
16
+ exports.addSeparator = addSeparator;
17
+ //# sourceMappingURL=addSeparator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addSeparator.js","sources":["../../../../src/components/Attach/utils/addSeparator.ts"],"sourcesContent":["import { extractExtension } from './extractExtension';\n\nexport const addSeparator = (filename: string, separator: string) => {\n const extension = extractExtension(filename);\n\n const strings = filename.split('.');\n const name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];\n const lastChar = name[name.length - 1];\n const dotChar = '.';\n\n return extension === name\n ? `${name.slice(0, -1)}${separator}${lastChar}`\n : `${name.slice(0, -1)}${separator}${lastChar}${dotChar}${extension}`;\n};\n"],"names":["addSeparator","filename","separator","extension","extractExtension","strings","split","name","length","slice","join","lastChar","dotChar","concat"],"mappings":";;;;;;AAEO,IAAMA,YAAY,GAAG,SAAfA,YAAYA,CAAIC,QAAgB,EAAEC,SAAiB,EAAK;AACjE,EAAA,IAAMC,SAAS,GAAGC,iCAAgB,CAACH,QAAQ,CAAC,CAAA;AAE5C,EAAA,IAAMI,OAAO,GAAGJ,QAAQ,CAACK,KAAK,CAAC,GAAG,CAAC,CAAA;EACnC,IAAMC,IAAI,GAAGF,OAAO,CAACG,MAAM,GAAG,CAAC,GAAGH,OAAO,CAACI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,GAAGL,OAAO,CAAC,CAAC,CAAC,CAAA;EAC7E,IAAMM,QAAQ,GAAGJ,IAAI,CAACA,IAAI,CAACC,MAAM,GAAG,CAAC,CAAC,CAAA;EACtC,IAAMI,OAAO,GAAG,GAAG,CAAA;EAEnB,OAAOT,SAAS,KAAKI,IAAI,GAAA,EAAA,CAAAM,MAAA,CAChBN,IAAI,CAACE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA,CAAAI,MAAA,CAAGX,SAAS,CAAAW,CAAAA,MAAA,CAAGF,QAAQ,CAAAE,GAAAA,EAAAA,CAAAA,MAAA,CACxCN,IAAI,CAACE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAAI,CAAAA,MAAA,CAAGX,SAAS,EAAAW,MAAA,CAAGF,QAAQ,CAAA,CAAAE,MAAA,CAAGD,OAAO,CAAAC,CAAAA,MAAA,CAAGV,SAAS,CAAE,CAAA;AAC7E;;;;"}
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('react');
6
+ require('@linaria/react');
7
+
8
+ var separator = '...';
9
+
10
+ exports.separator = separator;
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/Attach/utils/index.ts"],"sourcesContent":["export { extractExtension } from './extractExtension';\nexport { getFileicon } from './getFileicon';\nexport { addSeparator } from './addSeparator';\n\nexport const separator = '...';\n"],"names":["separator"],"mappings":";;;;;;;AAIO,IAAMA,SAAS,GAAG;;;;"}
@@ -85,15 +85,18 @@ var attachRoot = exports.attachRoot = function attachRoot(Root) {
85
85
  cellLeft = _cellRef$current$getB.left;
86
86
  var leftDiff = cellLeft - parentLeft;
87
87
  var currentTextWidth = textWidth;
88
- var currFilename = filename;
89
- for (var i = filename.length - 1; i > 0; i -= 1) {
88
+ if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth || currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
89
+ setTruncatedFilename(filename);
90
+ return;
91
+ }
92
+ var currFilename = (0, _utils2.addSeparator)(filename, _utils2.separator);
93
+ for (var i = currFilename.indexOf(_utils2.separator) - 1; i > 0; i -= 1) {
90
94
  if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {
91
95
  break;
92
96
  }
93
- var newFilename = (0, _utils2.truncateFilename)({
94
- filename: inputHelperRef.current.textContent,
95
- startNameTruncationIndex: i
96
- });
97
+ var left = currFilename.slice(0, i);
98
+ var right = currFilename.slice(i + 1);
99
+ var newFilename = "".concat(left).concat(right);
97
100
  inputHelperRef.current.textContent = newFilename;
98
101
  currentTextWidth = inputHelperRef.current.offsetWidth;
99
102
  if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addSeparator = void 0;
7
+ var _extractExtension = /*#__PURE__*/require("./extractExtension");
8
+ var addSeparator = exports.addSeparator = function addSeparator(filename, separator) {
9
+ var extension = (0, _extractExtension.extractExtension)(filename);
10
+ var strings = filename.split('.');
11
+ var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
12
+ var lastChar = name[name.length - 1];
13
+ var dotChar = '.';
14
+ return extension === name ? "".concat(name.slice(0, -1)).concat(separator).concat(lastChar) : "".concat(name.slice(0, -1)).concat(separator).concat(lastChar).concat(dotChar).concat(extension);
15
+ };
@@ -3,24 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "extractExtension", {
6
+ Object.defineProperty(exports, "addSeparator", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _extractExtension.extractExtension;
9
+ return _addSeparator.addSeparator;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "getFileicon", {
12
+ Object.defineProperty(exports, "extractExtension", {
13
13
  enumerable: true,
14
14
  get: function get() {
15
- return _getFileicon.getFileicon;
15
+ return _extractExtension.extractExtension;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "truncateFilename", {
18
+ Object.defineProperty(exports, "getFileicon", {
19
19
  enumerable: true,
20
20
  get: function get() {
21
- return _truncateFilename.truncateFilename;
21
+ return _getFileicon.getFileicon;
22
22
  }
23
23
  });
24
+ exports.separator = void 0;
24
25
  var _extractExtension = /*#__PURE__*/require("./extractExtension");
25
26
  var _getFileicon = /*#__PURE__*/require("./getFileicon");
26
- var _truncateFilename = /*#__PURE__*/require("./truncateFilename");
27
+ var _addSeparator = /*#__PURE__*/require("./addSeparator");
28
+ var separator = exports.separator = '...';
@@ -17,7 +17,7 @@ import { base as sizeCSS } from './variations/_size/base';
17
17
  import { base as viewCSS } from './variations/_view/base';
18
18
  import { base, StyledHiddenInput, StyledHiddenInputHelper } from './Attach.styles';
19
19
  import { StyledCell } from './ui/Cell/Cell';
20
- import { extractExtension, getFileicon, truncateFilename } from './utils';
20
+ import { extractExtension, getFileicon, addSeparator, separator } from './utils';
21
21
  import { classes } from './Attach.tokens';
22
22
  import { AttachButton } from './components/AttachButton';
23
23
  import { StyledIconButtonCancel } from './ui/IconButton/IconButton.styles';
@@ -76,15 +76,18 @@ export var attachRoot = function attachRoot(Root) {
76
76
  cellLeft = _cellRef$current$getB.left;
77
77
  var leftDiff = cellLeft - parentLeft;
78
78
  var currentTextWidth = textWidth;
79
- var currFilename = filename;
80
- for (var i = filename.length - 1; i > 0; i -= 1) {
79
+ if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth || currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
80
+ setTruncatedFilename(filename);
81
+ return;
82
+ }
83
+ var currFilename = addSeparator(filename, separator);
84
+ for (var i = currFilename.indexOf(separator) - 1; i > 0; i -= 1) {
81
85
  if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {
82
86
  break;
83
87
  }
84
- var newFilename = truncateFilename({
85
- filename: inputHelperRef.current.textContent,
86
- startNameTruncationIndex: i
87
- });
88
+ var left = currFilename.slice(0, i);
89
+ var right = currFilename.slice(i + 1);
90
+ var newFilename = "".concat(left).concat(right);
88
91
  inputHelperRef.current.textContent = newFilename;
89
92
  currentTextWidth = inputHelperRef.current.offsetWidth;
90
93
  if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
@@ -0,0 +1,9 @@
1
+ import { extractExtension } from './extractExtension';
2
+ export var addSeparator = function addSeparator(filename, separator) {
3
+ var extension = extractExtension(filename);
4
+ var strings = filename.split('.');
5
+ var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
6
+ var lastChar = name[name.length - 1];
7
+ var dotChar = '.';
8
+ return extension === name ? "".concat(name.slice(0, -1)).concat(separator).concat(lastChar) : "".concat(name.slice(0, -1)).concat(separator).concat(lastChar).concat(dotChar).concat(extension);
9
+ };
@@ -1,3 +1,4 @@
1
1
  export { extractExtension } from './extractExtension';
2
2
  export { getFileicon } from './getFileicon';
3
- export { truncateFilename } from './truncateFilename';
3
+ export { addSeparator } from './addSeparator';
4
+ export var separator = '...';
@@ -8,12 +8,13 @@ import { base as base$2 } from './variations/_size/base.js';
8
8
  import { base as base$1 } from './variations/_view/base.js';
9
9
  import { StyledHiddenInput, StyledHiddenInputHelper, base } from './Attach.styles.js';
10
10
  import { StyledCell } from './ui/Cell/Cell.styles.js';
11
- import { extractExtension } from './utils/extractExtension.js';
12
- import { getFileicon } from './utils/getFileicon.js';
13
- import { truncateFilename } from './utils/truncateFilename.js';
11
+ import { separator } from './utils/index.js';
14
12
  import { classes } from './Attach.tokens.js';
15
13
  import { AttachButton } from './components/AttachButton/AttachButton.js';
16
14
  import { StyledIconButtonCancel } from './ui/IconButton/IconButton.styles.js';
15
+ import { extractExtension } from './utils/extractExtension.js';
16
+ import { addSeparator } from './utils/addSeparator.js';
17
+ import { getFileicon } from './utils/getFileicon.js';
17
18
 
18
19
  var _IconCloseCircleOutli;
19
20
  var _excluded = ["flow", "buttonType", "hasAttachment", "acceptedFileFormats", "size", "view", "className", "style", "isLoading", "disabled"];
@@ -72,15 +73,18 @@ var attachRoot = function attachRoot(Root) {
72
73
  cellLeft = _cellRef$current$getB.left;
73
74
  var leftDiff = cellLeft - parentLeft;
74
75
  var currentTextWidth = textWidth;
75
- var currFilename = filename;
76
- for (var i = filename.length - 1; i > 0; i -= 1) {
76
+ if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth || currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
77
+ setTruncatedFilename(filename);
78
+ return;
79
+ }
80
+ var currFilename = addSeparator(filename, separator);
81
+ for (var i = currFilename.indexOf(separator) - 1; i > 0; i -= 1) {
77
82
  if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {
78
83
  break;
79
84
  }
80
- var newFilename = truncateFilename({
81
- filename: inputHelperRef.current.textContent,
82
- startNameTruncationIndex: i
83
- });
85
+ var left = currFilename.slice(0, i);
86
+ var right = currFilename.slice(i + 1);
87
+ var newFilename = "".concat(left).concat(right);
84
88
  inputHelperRef.current.textContent = newFilename;
85
89
  currentTextWidth = inputHelperRef.current.offsetWidth;
86
90
  if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
@@ -1 +1 @@
1
- {"version":3,"file":"Attach.js","sources":["../../../src/components/Attach/Attach.tsx"],"sourcesContent":["import React, { forwardRef, useEffect, useRef, useState } from 'react';\nimport { useForkRef, useIsomorphicLayoutEffect } from '@salutejs/plasma-core';\n\nimport { RootProps } from '../../engines';\nimport { cx } from '../../utils';\nimport { IconCloseCircleOutline } from '../_Icon';\n\nimport { AttachProps } from './Attach.types';\nimport { base as sizeCSS } from './variations/_size/base';\nimport { base as viewCSS } from './variations/_view/base';\nimport { base, StyledHiddenInput, StyledHiddenInputHelper } from './Attach.styles';\nimport { StyledCell } from './ui/Cell/Cell';\nimport { extractExtension, getFileicon, truncateFilename } from './utils';\nimport { classes } from './Attach.tokens';\nimport { AttachButton } from './components/AttachButton';\nimport { StyledIconButtonCancel } from './ui/IconButton/IconButton.styles';\n\nexport const attachRoot = (Root: RootProps<HTMLDivElement, AttachProps>) =>\n forwardRef<HTMLDivElement, AttachProps>((props, outerRef) => {\n const {\n flow = 'auto',\n buttonType = 'button',\n hasAttachment = true,\n acceptedFileFormats,\n size,\n view,\n className,\n style,\n isLoading,\n disabled,\n ...rest\n } = props;\n\n const innerRef = useRef<HTMLDivElement>(null);\n const ref = useForkRef(outerRef, innerRef);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const inputHelperRef = useRef<HTMLDivElement | null>(null);\n const cellRef = useRef<HTMLDivElement | null>(null);\n const buttonRef = useRef<HTMLButtonElement | null>(null);\n\n const emptyTextCellWidth = useRef<number | null>(null);\n\n const [filename, setFilename] = useState<string>('');\n const [truncatedFilename, setTruncatedFilename] = useState<string>('');\n\n const horizontalClass = flow === 'horizontal' ? classes.horizontal : undefined;\n const verticalClass = flow === 'vertical' ? classes.vertical : undefined;\n const autoClass = flow === 'auto' ? classes.auto : undefined;\n const cellHiddenClass = truncatedFilename.length === 0 ? classes.cellHidden : undefined;\n\n const accept = acceptedFileFormats?.join(',');\n const extension = extractExtension(filename);\n const cellContentLeft = getFileicon(extension, size);\n\n useEffect(() => {\n emptyTextCellWidth.current = cellRef.current?.offsetWidth || 0;\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n if (\n !cellRef.current ||\n !cellRef.current.parentElement ||\n !inputHelperRef.current ||\n !inputHelperRef.current.textContent ||\n !emptyTextCellWidth.current ||\n !buttonRef.current\n ) {\n return;\n }\n\n const { offsetWidth: textWidth } = inputHelperRef.current;\n const { offsetWidth: buttonWidth } = buttonRef.current;\n const { width: parentWidth, left: parentLeft } = cellRef.current.parentElement.getBoundingClientRect();\n const { left: cellLeft } = cellRef.current.getBoundingClientRect();\n const leftDiff = cellLeft - parentLeft;\n\n let currentTextWidth = textWidth;\n let currFilename = filename;\n\n for (let i = filename.length - 1; i > 0; i -= 1) {\n if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {\n break;\n }\n\n const newFilename = truncateFilename({\n filename: inputHelperRef.current.textContent,\n startNameTruncationIndex: i,\n });\n inputHelperRef.current.textContent = newFilename;\n currentTextWidth = inputHelperRef.current.offsetWidth;\n\n if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {\n break;\n }\n\n currFilename = newFilename;\n }\n\n inputHelperRef.current.textContent = filename;\n setTruncatedFilename(currFilename);\n });\n\n const handleClick = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.click();\n };\n\n const handleChange = () => {\n if (!inputRef.current || !inputRef.current.files) {\n return;\n }\n\n setFilename(inputRef.current.files[0].name);\n };\n\n const handleClear = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.value = '';\n setFilename('');\n setTruncatedFilename('');\n };\n\n return (\n <Root\n className={cx(horizontalClass, verticalClass, autoClass, className)}\n style={style}\n size={size}\n view={view}\n ref={ref}\n >\n <StyledHiddenInput\n ref={inputRef}\n accept={accept}\n type=\"file\"\n id=\"attachHiddenInput\"\n name=\"attachHiddenInput\"\n onChange={handleChange}\n />\n <StyledHiddenInputHelper ref={inputHelperRef} id=\"attachHiddenInputHelper\">\n {filename}\n </StyledHiddenInputHelper>\n\n <AttachButton\n buttonType={buttonType}\n view={view}\n size={size}\n onClick={handleClick}\n isLoading={isLoading}\n disabled={disabled}\n ref={buttonRef}\n {...rest}\n />\n {hasAttachment && (\n <StyledCell\n stretching=\"fixed\"\n className={cellHiddenClass}\n ref={cellRef}\n size={size}\n title={truncatedFilename}\n contentLeft={cellContentLeft}\n contentRight={\n <StyledIconButtonCancel view={view} size={size} onClick={handleClear}>\n <IconCloseCircleOutline size=\"xs\" color=\"inherit\" />\n </StyledIconButtonCancel>\n }\n />\n )}\n </Root>\n );\n });\n\nexport const attachConfig = {\n name: 'Attach',\n tag: 'div',\n layout: attachRoot,\n base,\n variations: {\n view: {\n css: viewCSS,\n },\n size: {\n css: sizeCSS,\n },\n },\n defaults: {\n view: 'default',\n size: 'm',\n },\n};\n"],"names":["attachRoot","Root","forwardRef","props","outerRef","_props$flow","flow","_props$buttonType","buttonType","_props$hasAttachment","hasAttachment","acceptedFileFormats","size","view","className","style","isLoading","disabled","rest","_objectWithoutProperties","_excluded","innerRef","useRef","ref","useForkRef","inputRef","inputHelperRef","cellRef","buttonRef","emptyTextCellWidth","_useState","useState","_useState2","_slicedToArray","filename","setFilename","_useState3","_useState4","truncatedFilename","setTruncatedFilename","horizontalClass","classes","horizontal","undefined","verticalClass","vertical","autoClass","auto","cellHiddenClass","length","cellHidden","accept","join","extension","extractExtension","cellContentLeft","getFileicon","useEffect","_cellRef$current","current","offsetWidth","useIsomorphicLayoutEffect","parentElement","textContent","textWidth","buttonWidth","_cellRef$current$pare","getBoundingClientRect","parentWidth","width","parentLeft","left","_cellRef$current$getB","cellLeft","leftDiff","currentTextWidth","currFilename","i","newFilename","truncateFilename","startNameTruncationIndex","handleClick","click","handleChange","files","name","handleClear","value","React","createElement","cx","StyledHiddenInput","type","id","onChange","StyledHiddenInputHelper","AttachButton","_extends","onClick","StyledCell","stretching","title","contentLeft","contentRight","StyledIconButtonCancel","_IconCloseCircleOutli","IconCloseCircleOutline","color","attachConfig","tag","layout","base","variations","css","viewCSS","sizeCSS","defaults"],"mappings":";;;;;;;;;;;;;;;;;;;IAiBaA,UAAU,GAAG,SAAbA,UAAUA,CAAIC,IAA4C,EAAA;AAAA,EAAA,oBACnEC,UAAU,CAA8B,UAACC,KAAK,EAAEC,QAAQ,EAAK;AACzD,IAAA,IAAAC,WAAA,GAYIF,KAAK,CAXLG,IAAI;AAAJA,MAAAA,IAAI,GAAAD,WAAA,KAAG,KAAA,CAAA,GAAA,MAAM,GAAAA,WAAA;MAAAE,iBAAA,GAWbJ,KAAK,CAVLK,UAAU;AAAVA,MAAAA,UAAU,GAAAD,iBAAA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zB,MAAAA,GAAG,EAAEI,OAAQ;AACbf,MAAAA,IAAI,EAAEA,IAAK;AACXyF,MAAAA,KAAK,EAAE/D,iBAAkB;AACzBgE,MAAAA,WAAW,EAAE/C,eAAgB;AAC7BgD,MAAAA,YAAY,eACRf,KAAA,CAAAC,aAAA,CAACe,sBAAsB,EAAA;AAAC3F,QAAAA,IAAI,EAAEA,IAAK;AAACD,QAAAA,IAAI,EAAEA,IAAK;AAACsF,QAAAA,OAAO,EAAEZ,WAAAA;OAAYmB,EAAAA,qBAAA,KAAAA,qBAAA,gBACjEjB,KAAA,CAAAC,aAAA,CAACiB,sBAAsB,EAAA;AAAC9F,QAAAA,IAAI,EAAC,IAAI;AAAC+F,QAAAA,KAAK,EAAC,SAAA;AAAS,OAAE,CAAC,CAChC,CAAA;AAC3B,KACJ,CAEH,CAAC,CAAA;AAEf,GAAC,CAAC,CAAA;AAAA,EAAA;AAEC,IAAMC,YAAY,GAAG;AACxBvB,EAAAA,IAAI,EAAE,QAAQ;AACdwB,EAAAA,GAAG,EAAE,KAAK;AACVC,EAAAA,MAAM,EAAE9G,UAAU;AAClB+G,EAAAA,IAAI,EAAJA,IAAI;AACJC,EAAAA,UAAU,EAAE;AACRnG,IAAAA,IAAI,EAAE;AACFoG,MAAAA,GAAG,EAAEC,MAAAA;KACR;AACDtG,IAAAA,IAAI,EAAE;AACFqG,MAAAA,GAAG,EAAEE,MAAAA;AACT,KAAA;GACH;AACDC,EAAAA,QAAQ,EAAE;AACNvG,IAAAA,IAAI,EAAE,SAAS;AACfD,IAAAA,IAAI,EAAE,GAAA;AACV,GAAA;AACJ;;;;"}
1
+ {"version":3,"file":"Attach.js","sources":["../../../src/components/Attach/Attach.tsx"],"sourcesContent":["import React, { forwardRef, useEffect, useRef, useState } from 'react';\nimport { useForkRef, useIsomorphicLayoutEffect } from '@salutejs/plasma-core';\n\nimport { RootProps } from '../../engines';\nimport { cx } from '../../utils';\nimport { IconCloseCircleOutline } from '../_Icon';\n\nimport { AttachProps } from './Attach.types';\nimport { base as sizeCSS } from './variations/_size/base';\nimport { base as viewCSS } from './variations/_view/base';\nimport { base, StyledHiddenInput, StyledHiddenInputHelper } from './Attach.styles';\nimport { StyledCell } from './ui/Cell/Cell';\nimport { extractExtension, getFileicon, addSeparator, separator } from './utils';\nimport { classes } from './Attach.tokens';\nimport { AttachButton } from './components/AttachButton';\nimport { StyledIconButtonCancel } from './ui/IconButton/IconButton.styles';\n\nexport const attachRoot = (Root: RootProps<HTMLDivElement, AttachProps>) =>\n forwardRef<HTMLDivElement, AttachProps>((props, outerRef) => {\n const {\n flow = 'auto',\n buttonType = 'button',\n hasAttachment = true,\n acceptedFileFormats,\n size,\n view,\n className,\n style,\n isLoading,\n disabled,\n ...rest\n } = props;\n\n const innerRef = useRef<HTMLDivElement>(null);\n const ref = useForkRef(outerRef, innerRef);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n const inputHelperRef = useRef<HTMLDivElement | null>(null);\n const cellRef = useRef<HTMLDivElement | null>(null);\n const buttonRef = useRef<HTMLButtonElement | null>(null);\n\n const emptyTextCellWidth = useRef<number | null>(null);\n\n const [filename, setFilename] = useState<string>('');\n const [truncatedFilename, setTruncatedFilename] = useState<string>('');\n\n const horizontalClass = flow === 'horizontal' ? classes.horizontal : undefined;\n const verticalClass = flow === 'vertical' ? classes.vertical : undefined;\n const autoClass = flow === 'auto' ? classes.auto : undefined;\n const cellHiddenClass = truncatedFilename.length === 0 ? classes.cellHidden : undefined;\n\n const accept = acceptedFileFormats?.join(',');\n const extension = extractExtension(filename);\n const cellContentLeft = getFileicon(extension, size);\n\n useEffect(() => {\n emptyTextCellWidth.current = cellRef.current?.offsetWidth || 0;\n }, []);\n\n useIsomorphicLayoutEffect(() => {\n if (\n !cellRef.current ||\n !cellRef.current.parentElement ||\n !inputHelperRef.current ||\n !inputHelperRef.current.textContent ||\n !emptyTextCellWidth.current ||\n !buttonRef.current\n ) {\n return;\n }\n\n const { offsetWidth: textWidth } = inputHelperRef.current;\n const { offsetWidth: buttonWidth } = buttonRef.current;\n const { width: parentWidth, left: parentLeft } = cellRef.current.parentElement.getBoundingClientRect();\n const { left: cellLeft } = cellRef.current.getBoundingClientRect();\n const leftDiff = cellLeft - parentLeft;\n let currentTextWidth = textWidth;\n\n if (\n currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth ||\n currentTextWidth + emptyTextCellWidth.current < buttonWidth\n ) {\n setTruncatedFilename(filename);\n return;\n }\n\n let currFilename = addSeparator(filename, separator);\n for (let i = currFilename.indexOf(separator) - 1; i > 0; i -= 1) {\n if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {\n break;\n }\n\n const left = currFilename.slice(0, i);\n const right = currFilename.slice(i + 1);\n const newFilename = `${left}${right}`;\n inputHelperRef.current.textContent = newFilename;\n currentTextWidth = inputHelperRef.current.offsetWidth;\n\n if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {\n break;\n }\n\n currFilename = newFilename;\n }\n\n inputHelperRef.current.textContent = filename;\n setTruncatedFilename(currFilename);\n });\n\n const handleClick = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.click();\n };\n\n const handleChange = () => {\n if (!inputRef.current || !inputRef.current.files) {\n return;\n }\n\n setFilename(inputRef.current.files[0].name);\n };\n\n const handleClear = () => {\n if (!inputRef.current) {\n return;\n }\n\n inputRef.current.value = '';\n setFilename('');\n setTruncatedFilename('');\n };\n\n return (\n <Root\n className={cx(horizontalClass, verticalClass, autoClass, className)}\n style={style}\n size={size}\n view={view}\n ref={ref}\n >\n <StyledHiddenInput\n ref={inputRef}\n accept={accept}\n type=\"file\"\n id=\"attachHiddenInput\"\n name=\"attachHiddenInput\"\n onChange={handleChange}\n />\n <StyledHiddenInputHelper ref={inputHelperRef} id=\"attachHiddenInputHelper\">\n {filename}\n </StyledHiddenInputHelper>\n\n <AttachButton\n buttonType={buttonType}\n view={view}\n size={size}\n onClick={handleClick}\n isLoading={isLoading}\n disabled={disabled}\n ref={buttonRef}\n {...rest}\n />\n {hasAttachment && (\n <StyledCell\n stretching=\"fixed\"\n className={cellHiddenClass}\n ref={cellRef}\n size={size}\n title={truncatedFilename}\n contentLeft={cellContentLeft}\n contentRight={\n <StyledIconButtonCancel view={view} size={size} onClick={handleClear}>\n <IconCloseCircleOutline size=\"xs\" color=\"inherit\" />\n </StyledIconButtonCancel>\n }\n />\n )}\n </Root>\n );\n });\n\nexport const attachConfig = {\n name: 'Attach',\n tag: 'div',\n layout: attachRoot,\n base,\n variations: {\n view: {\n css: viewCSS,\n },\n size: {\n css: sizeCSS,\n },\n },\n defaults: {\n view: 'default',\n size: 'm',\n },\n};\n"],"names":["attachRoot","Root","forwardRef","props","outerRef","_props$flow","flow","_props$buttonType","buttonType","_props$hasAttachment","hasAttachment","acceptedFileFormats","size","view","className","style","isLoading","disabled","rest","_objectWithoutProperties","_excluded","innerRef","useRef","ref","useForkRef","inputRef","inputHelperRef","cellRef","buttonRef","emptyTextCellWidth","_useState","useState","_useState2","_slicedToArray","filename","setFilename","_useState3","_useState4","truncatedFilename","setTruncatedFilename","horizontalClass","classes","horizontal","undefined","verticalClass","vertical","autoClass","auto","cellHiddenClass","length","cellHidden","accept","join","extension","extractExtension","cellContentLeft","getFileicon","useEffect","_cellRef$current","current","offsetWidth","useIsomorphicLayoutEffect","parentElement","textContent","textWidth","buttonWidth","_cellRef$current$pare","getBoundingClientRect","parentWidth","width","parentLeft","left","_cellRef$current$getB","cellLeft","leftDiff","currentTextWidth","currFilename","addSeparator","separator","i","indexOf","slice","right","newFilename","concat","handleClick","click","handleChange","files","name","handleClear","value","React","createElement","cx","StyledHiddenInput","type","id","onChange","StyledHiddenInputHelper","AttachButton","_extends","onClick","StyledCell","stretching","title","contentLeft","contentRight","StyledIconButtonCancel","_IconCloseCircleOutli","IconCloseCircleOutline","color","attachConfig","tag","layout","base","variations","css","viewCSS","sizeCSS","defaults"],"mappings":";;;;;;;;;;;;;;;;;;;;IAiBaA,UAAU,GAAG,SAAb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AAA;AAEC,IAAMC,YAAY,GAAG;AACxBvB,EAAAA,IAAI,EAAE,QAAQ;AACdwB,EAAAA,GAAG,EAAE,KAAK;AACVC,EAAAA,MAAM,EAAElH,UAAU;AAClBmH,EAAAA,IAAI,EAAJA,IAAI;AACJC,EAAAA,UAAU,EAAE;AACRvG,IAAAA,IAAI,EAAE;AACFwG,MAAAA,GAAG,EAAEC,MAAAA;KACR;AACD1G,IAAAA,IAAI,EAAE;AACFyG,MAAAA,GAAG,EAAEE,MAAAA;AACT,KAAA;GACH;AACDC,EAAAA,QAAQ,EAAE;AACN3G,IAAAA,IAAI,EAAE,SAAS;AACfD,IAAAA,IAAI,EAAE,GAAA;AACV,GAAA;AACJ;;;;"}
@@ -0,0 +1,13 @@
1
+ import { extractExtension } from './extractExtension.js';
2
+
3
+ var addSeparator = function addSeparator(filename, separator) {
4
+ var extension = extractExtension(filename);
5
+ var strings = filename.split('.');
6
+ var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
7
+ var lastChar = name[name.length - 1];
8
+ var dotChar = '.';
9
+ return extension === name ? "".concat(name.slice(0, -1)).concat(separator).concat(lastChar) : "".concat(name.slice(0, -1)).concat(separator).concat(lastChar).concat(dotChar).concat(extension);
10
+ };
11
+
12
+ export { addSeparator };
13
+ //# sourceMappingURL=addSeparator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addSeparator.js","sources":["../../../../src/components/Attach/utils/addSeparator.ts"],"sourcesContent":["import { extractExtension } from './extractExtension';\n\nexport const addSeparator = (filename: string, separator: string) => {\n const extension = extractExtension(filename);\n\n const strings = filename.split('.');\n const name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];\n const lastChar = name[name.length - 1];\n const dotChar = '.';\n\n return extension === name\n ? `${name.slice(0, -1)}${separator}${lastChar}`\n : `${name.slice(0, -1)}${separator}${lastChar}${dotChar}${extension}`;\n};\n"],"names":["addSeparator","filename","separator","extension","extractExtension","strings","split","name","length","slice","join","lastChar","dotChar","concat"],"mappings":";;AAEO,IAAMA,YAAY,GAAG,SAAfA,YAAYA,CAAIC,QAAgB,EAAEC,SAAiB,EAAK;AACjE,EAAA,IAAMC,SAAS,GAAGC,gBAAgB,CAACH,QAAQ,CAAC,CAAA;AAE5C,EAAA,IAAMI,OAAO,GAAGJ,QAAQ,CAACK,KAAK,CAAC,GAAG,CAAC,CAAA;EACnC,IAAMC,IAAI,GAAGF,OAAO,CAACG,MAAM,GAAG,CAAC,GAAGH,OAAO,CAACI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,GAAGL,OAAO,CAAC,CAAC,CAAC,CAAA;EAC7E,IAAMM,QAAQ,GAAGJ,IAAI,CAACA,IAAI,CAACC,MAAM,GAAG,CAAC,CAAC,CAAA;EACtC,IAAMI,OAAO,GAAG,GAAG,CAAA;EAEnB,OAAOT,SAAS,KAAKI,IAAI,GAAA,EAAA,CAAAM,MAAA,CAChBN,IAAI,CAACE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA,CAAAI,MAAA,CAAGX,SAAS,CAAAW,CAAAA,MAAA,CAAGF,QAAQ,CAAAE,GAAAA,EAAAA,CAAAA,MAAA,CACxCN,IAAI,CAACE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAAI,CAAAA,MAAA,CAAGX,SAAS,EAAAW,MAAA,CAAGF,QAAQ,CAAA,CAAAE,MAAA,CAAGD,OAAO,CAAAC,CAAAA,MAAA,CAAGV,SAAS,CAAE,CAAA;AAC7E;;;;"}
@@ -0,0 +1,7 @@
1
+ import 'react';
2
+ import '@linaria/react';
3
+
4
+ var separator = '...';
5
+
6
+ export { separator };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/components/Attach/utils/index.ts"],"sourcesContent":["export { extractExtension } from './extractExtension';\nexport { getFileicon } from './getFileicon';\nexport { addSeparator } from './addSeparator';\n\nexport const separator = '...';\n"],"names":["separator"],"mappings":";;;AAIO,IAAMA,SAAS,GAAG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salutejs/plasma-new-hope",
3
- "version": "0.158.0-dev.0",
3
+ "version": "0.158.1-canary.1454.11140695341.0",
4
4
  "description": "Salute Design System blueprint",
5
5
  "main": "cjs/index.js",
6
6
  "module": "es/index.js",
@@ -123,5 +123,5 @@
123
123
  "react-popper": "2.3.0",
124
124
  "storeon": "3.1.5"
125
125
  },
126
- "gitHead": "c2ff366bbcf143241c514ca6e3538d3ff6acfdbc"
126
+ "gitHead": "a971a51abe61c336d4a7a6d8944b1c92585ef6d3"
127
127
  }
@@ -85,15 +85,18 @@ var attachRoot = exports.attachRoot = function attachRoot(Root) {
85
85
  cellLeft = _cellRef$current$getB.left;
86
86
  var leftDiff = cellLeft - parentLeft;
87
87
  var currentTextWidth = textWidth;
88
- var currFilename = filename;
89
- for (var i = filename.length - 1; i > 0; i -= 1) {
88
+ if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth || currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
89
+ setTruncatedFilename(filename);
90
+ return;
91
+ }
92
+ var currFilename = (0, _utils2.addSeparator)(filename, _utils2.separator);
93
+ for (var i = currFilename.indexOf(_utils2.separator) - 1; i > 0; i -= 1) {
90
94
  if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {
91
95
  break;
92
96
  }
93
- var newFilename = (0, _utils2.truncateFilename)({
94
- filename: inputHelperRef.current.textContent,
95
- startNameTruncationIndex: i
96
- });
97
+ var left = currFilename.slice(0, i);
98
+ var right = currFilename.slice(i + 1);
99
+ var newFilename = "".concat(left).concat(right);
97
100
  inputHelperRef.current.textContent = newFilename;
98
101
  currentTextWidth = inputHelperRef.current.offsetWidth;
99
102
  if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addSeparator = void 0;
7
+ var _extractExtension = /*#__PURE__*/require("./extractExtension");
8
+ var addSeparator = exports.addSeparator = function addSeparator(filename, separator) {
9
+ var extension = (0, _extractExtension.extractExtension)(filename);
10
+ var strings = filename.split('.');
11
+ var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
12
+ var lastChar = name[name.length - 1];
13
+ var dotChar = '.';
14
+ return extension === name ? "".concat(name.slice(0, -1)).concat(separator).concat(lastChar) : "".concat(name.slice(0, -1)).concat(separator).concat(lastChar).concat(dotChar).concat(extension);
15
+ };
@@ -3,24 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "extractExtension", {
6
+ Object.defineProperty(exports, "addSeparator", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _extractExtension.extractExtension;
9
+ return _addSeparator.addSeparator;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "getFileicon", {
12
+ Object.defineProperty(exports, "extractExtension", {
13
13
  enumerable: true,
14
14
  get: function get() {
15
- return _getFileicon.getFileicon;
15
+ return _extractExtension.extractExtension;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "truncateFilename", {
18
+ Object.defineProperty(exports, "getFileicon", {
19
19
  enumerable: true,
20
20
  get: function get() {
21
- return _truncateFilename.truncateFilename;
21
+ return _getFileicon.getFileicon;
22
22
  }
23
23
  });
24
+ exports.separator = void 0;
24
25
  var _extractExtension = /*#__PURE__*/require("./extractExtension");
25
26
  var _getFileicon = /*#__PURE__*/require("./getFileicon");
26
- var _truncateFilename = /*#__PURE__*/require("./truncateFilename");
27
+ var _addSeparator = /*#__PURE__*/require("./addSeparator");
28
+ var separator = exports.separator = '...';
@@ -17,7 +17,7 @@ import { base as sizeCSS } from './variations/_size/base';
17
17
  import { base as viewCSS } from './variations/_view/base';
18
18
  import { base, StyledHiddenInput, StyledHiddenInputHelper } from './Attach.styles';
19
19
  import { StyledCell } from './ui/Cell/Cell';
20
- import { extractExtension, getFileicon, truncateFilename } from './utils';
20
+ import { extractExtension, getFileicon, addSeparator, separator } from './utils';
21
21
  import { classes } from './Attach.tokens';
22
22
  import { AttachButton } from './components/AttachButton';
23
23
  import { StyledIconButtonCancel } from './ui/IconButton/IconButton.styles';
@@ -76,15 +76,18 @@ export var attachRoot = function attachRoot(Root) {
76
76
  cellLeft = _cellRef$current$getB.left;
77
77
  var leftDiff = cellLeft - parentLeft;
78
78
  var currentTextWidth = textWidth;
79
- var currFilename = filename;
80
- for (var i = filename.length - 1; i > 0; i -= 1) {
79
+ if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth || currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
80
+ setTruncatedFilename(filename);
81
+ return;
82
+ }
83
+ var currFilename = addSeparator(filename, separator);
84
+ for (var i = currFilename.indexOf(separator) - 1; i > 0; i -= 1) {
81
85
  if (currentTextWidth + emptyTextCellWidth.current + leftDiff <= parentWidth) {
82
86
  break;
83
87
  }
84
- var newFilename = truncateFilename({
85
- filename: inputHelperRef.current.textContent,
86
- startNameTruncationIndex: i
87
- });
88
+ var left = currFilename.slice(0, i);
89
+ var right = currFilename.slice(i + 1);
90
+ var newFilename = "".concat(left).concat(right);
88
91
  inputHelperRef.current.textContent = newFilename;
89
92
  currentTextWidth = inputHelperRef.current.offsetWidth;
90
93
  if (currentTextWidth + emptyTextCellWidth.current < buttonWidth) {
@@ -0,0 +1,9 @@
1
+ import { extractExtension } from './extractExtension';
2
+ export var addSeparator = function addSeparator(filename, separator) {
3
+ var extension = extractExtension(filename);
4
+ var strings = filename.split('.');
5
+ var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
6
+ var lastChar = name[name.length - 1];
7
+ var dotChar = '.';
8
+ return extension === name ? "".concat(name.slice(0, -1)).concat(separator).concat(lastChar) : "".concat(name.slice(0, -1)).concat(separator).concat(lastChar).concat(dotChar).concat(extension);
9
+ };
@@ -1,3 +1,4 @@
1
1
  export { extractExtension } from './extractExtension';
2
2
  export { getFileicon } from './getFileicon';
3
- export { truncateFilename } from './truncateFilename';
3
+ export { addSeparator } from './addSeparator';
4
+ export var separator = '...';
@@ -1 +1 @@
1
- {"version":3,"file":"Attach.d.ts","sourceRoot":"","sources":["../../../src/components/Attach/Attach.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAGvE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C,eAAO,MAAM,UAAU,SAAU,UAAU,cAAc,EAAE,WAAW,CAAC,uFA+JjE,CAAC;AAEP,eAAO,MAAM,YAAY;;;mBAjKQ,UAAU,cAAc,EAAE,WAAW,CAAC;;;;;;;;;;;;;;CAkLtE,CAAC"}
1
+ {"version":3,"file":"Attach.d.ts","sourceRoot":"","sources":["../../../src/components/Attach/Attach.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkD,MAAM,OAAO,CAAC;AAGvE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C,eAAO,MAAM,UAAU,SAAU,UAAU,cAAc,EAAE,WAAW,CAAC,uFAqKjE,CAAC;AAEP,eAAO,MAAM,YAAY;;;mBAvKQ,UAAU,cAAc,EAAE,WAAW,CAAC;;;;;;;;;;;;;;CAwLtE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const addSeparator: (filename: string, separator: string) => string;
2
+ //# sourceMappingURL=addSeparator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addSeparator.d.ts","sourceRoot":"","sources":["../../../../src/components/Attach/utils/addSeparator.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,aAAc,MAAM,aAAa,MAAM,WAW/D,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export { extractExtension } from './extractExtension';
2
2
  export { getFileicon } from './getFileicon';
3
- export { truncateFilename } from './truncateFilename';
3
+ export { addSeparator } from './addSeparator';
4
+ export declare const separator = "...";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Attach/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Attach/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,SAAS,QAAQ,CAAC"}
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var truncateFilename = function truncateFilename(_ref) {
6
- var filename = _ref.filename,
7
- startNameTruncationIndex = _ref.startNameTruncationIndex,
8
- _ref$separator = _ref.separator,
9
- separator = _ref$separator === void 0 ? '...' : _ref$separator,
10
- _ref$minNameLength = _ref.minNameLength,
11
- minNameLength = _ref$minNameLength === void 0 ? 5 : _ref$minNameLength;
12
- var strings = filename.split('.');
13
- var extension = strings.length > 1 ? strings[strings.length - 1] : null;
14
- var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
15
- if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {
16
- return filename;
17
- }
18
- var lastNameLetter = name[name.length - 1];
19
- var truncatedName = "".concat(name.substring(0, startNameTruncationIndex)).concat(separator).concat(lastNameLetter);
20
- return extension ? "".concat(truncatedName, ".").concat(extension) : truncatedName;
21
- };
22
-
23
- exports.truncateFilename = truncateFilename;
24
- //# sourceMappingURL=truncateFilename.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"truncateFilename.js","sources":["../../../../src/components/Attach/utils/truncateFilename.ts"],"sourcesContent":["export const truncateFilename = ({\n filename,\n startNameTruncationIndex,\n separator = '...',\n minNameLength = 5,\n}: {\n filename: string;\n startNameTruncationIndex: number;\n separator?: string;\n minNameLength?: number;\n}) => {\n const strings = filename.split('.');\n const extension = strings.length > 1 ? strings[strings.length - 1] : null;\n const name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];\n\n if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {\n return filename;\n }\n\n const lastNameLetter = name[name.length - 1];\n const truncatedName = `${name.substring(0, startNameTruncationIndex)}${separator}${lastNameLetter}`;\n\n return extension ? `${truncatedName}.${extension}` : truncatedName;\n};\n"],"names":["truncateFilename","_ref","filename","startNameTruncationIndex","_ref$separator","separator","_ref$minNameLength","minNameLength","strings","split","extension","length","name","slice","join","lastNameLetter","truncatedName","concat","substring"],"mappings":";;;;IAAaA,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAAC,IAAA,EAUvB;AAAA,EAAA,IATFC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,wBAAwB,GAAAF,IAAA,CAAxBE,wBAAwB;IAAAC,cAAA,GAAAH,IAAA,CACxBI,SAAS;AAATA,IAAAA,SAAS,GAAAD,cAAA,KAAG,KAAA,CAAA,GAAA,KAAK,GAAAA,cAAA;IAAAE,kBAAA,GAAAL,IAAA,CACjBM,aAAa;AAAbA,IAAAA,aAAa,GAAAD,kBAAA,KAAG,KAAA,CAAA,GAAA,CAAC,GAAAA,kBAAA,CAAA;AAOjB,EAAA,IAAME,OAAO,GAAGN,QAAQ,CAACO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnC,EAAA,IAAMC,SAAS,GAAGF,OAAO,CAACG,MAAM,GAAG,CAAC,GAAGH,OAAO,CAACA,OAAO,CAACG,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAA;EACzE,IAAMC,IAAI,GAAGJ,OAAO,CAACG,MAAM,GAAG,CAAC,GAAGH,OAAO,CAACK,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,GAAGN,OAAO,CAAC,CAAC,CAAC,CAAA;AAE7E,EAAA,IAAII,IAAI,CAACD,MAAM,IAAIJ,aAAa,IAAIJ,wBAAwB,IAAIS,IAAI,CAACD,MAAM,GAAG,CAAC,EAAE;AAC7E,IAAA,OAAOT,QAAQ,CAAA;AACnB,GAAA;EAEA,IAAMa,cAAc,GAAGH,IAAI,CAACA,IAAI,CAACD,MAAM,GAAG,CAAC,CAAC,CAAA;EAC5C,IAAMK,aAAa,MAAAC,MAAA,CAAML,IAAI,CAACM,SAAS,CAAC,CAAC,EAAEf,wBAAwB,CAAC,CAAA,CAAAc,MAAA,CAAGZ,SAAS,EAAAY,MAAA,CAAGF,cAAc,CAAE,CAAA;EAEnG,OAAOL,SAAS,GAAAO,EAAAA,CAAAA,MAAA,CAAMD,aAAa,OAAAC,MAAA,CAAIP,SAAS,CAAA,GAAKM,aAAa,CAAA;AACtE;;;;"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.truncateFilename = void 0;
7
- var truncateFilename = exports.truncateFilename = function truncateFilename(_ref) {
8
- var filename = _ref.filename,
9
- startNameTruncationIndex = _ref.startNameTruncationIndex,
10
- _ref$separator = _ref.separator,
11
- separator = _ref$separator === void 0 ? '...' : _ref$separator,
12
- _ref$minNameLength = _ref.minNameLength,
13
- minNameLength = _ref$minNameLength === void 0 ? 5 : _ref$minNameLength;
14
- var strings = filename.split('.');
15
- var extension = strings.length > 1 ? strings[strings.length - 1] : null;
16
- var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
17
- if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {
18
- return filename;
19
- }
20
- var lastNameLetter = name[name.length - 1];
21
- var truncatedName = "".concat(name.substring(0, startNameTruncationIndex)).concat(separator).concat(lastNameLetter);
22
- return extension ? "".concat(truncatedName, ".").concat(extension) : truncatedName;
23
- };
@@ -1,17 +0,0 @@
1
- export var truncateFilename = function truncateFilename(_ref) {
2
- var filename = _ref.filename,
3
- startNameTruncationIndex = _ref.startNameTruncationIndex,
4
- _ref$separator = _ref.separator,
5
- separator = _ref$separator === void 0 ? '...' : _ref$separator,
6
- _ref$minNameLength = _ref.minNameLength,
7
- minNameLength = _ref$minNameLength === void 0 ? 5 : _ref$minNameLength;
8
- var strings = filename.split('.');
9
- var extension = strings.length > 1 ? strings[strings.length - 1] : null;
10
- var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
11
- if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {
12
- return filename;
13
- }
14
- var lastNameLetter = name[name.length - 1];
15
- var truncatedName = "".concat(name.substring(0, startNameTruncationIndex)).concat(separator).concat(lastNameLetter);
16
- return extension ? "".concat(truncatedName, ".").concat(extension) : truncatedName;
17
- };
@@ -1,20 +0,0 @@
1
- var truncateFilename = function truncateFilename(_ref) {
2
- var filename = _ref.filename,
3
- startNameTruncationIndex = _ref.startNameTruncationIndex,
4
- _ref$separator = _ref.separator,
5
- separator = _ref$separator === void 0 ? '...' : _ref$separator,
6
- _ref$minNameLength = _ref.minNameLength,
7
- minNameLength = _ref$minNameLength === void 0 ? 5 : _ref$minNameLength;
8
- var strings = filename.split('.');
9
- var extension = strings.length > 1 ? strings[strings.length - 1] : null;
10
- var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
11
- if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {
12
- return filename;
13
- }
14
- var lastNameLetter = name[name.length - 1];
15
- var truncatedName = "".concat(name.substring(0, startNameTruncationIndex)).concat(separator).concat(lastNameLetter);
16
- return extension ? "".concat(truncatedName, ".").concat(extension) : truncatedName;
17
- };
18
-
19
- export { truncateFilename };
20
- //# sourceMappingURL=truncateFilename.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"truncateFilename.js","sources":["../../../../src/components/Attach/utils/truncateFilename.ts"],"sourcesContent":["export const truncateFilename = ({\n filename,\n startNameTruncationIndex,\n separator = '...',\n minNameLength = 5,\n}: {\n filename: string;\n startNameTruncationIndex: number;\n separator?: string;\n minNameLength?: number;\n}) => {\n const strings = filename.split('.');\n const extension = strings.length > 1 ? strings[strings.length - 1] : null;\n const name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];\n\n if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {\n return filename;\n }\n\n const lastNameLetter = name[name.length - 1];\n const truncatedName = `${name.substring(0, startNameTruncationIndex)}${separator}${lastNameLetter}`;\n\n return extension ? `${truncatedName}.${extension}` : truncatedName;\n};\n"],"names":["truncateFilename","_ref","filename","startNameTruncationIndex","_ref$separator","separator","_ref$minNameLength","minNameLength","strings","split","extension","length","name","slice","join","lastNameLetter","truncatedName","concat","substring"],"mappings":"IAAaA,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAAC,IAAA,EAUvB;AAAA,EAAA,IATFC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,wBAAwB,GAAAF,IAAA,CAAxBE,wBAAwB;IAAAC,cAAA,GAAAH,IAAA,CACxBI,SAAS;AAATA,IAAAA,SAAS,GAAAD,cAAA,KAAG,KAAA,CAAA,GAAA,KAAK,GAAAA,cAAA;IAAAE,kBAAA,GAAAL,IAAA,CACjBM,aAAa;AAAbA,IAAAA,aAAa,GAAAD,kBAAA,KAAG,KAAA,CAAA,GAAA,CAAC,GAAAA,kBAAA,CAAA;AAOjB,EAAA,IAAME,OAAO,GAAGN,QAAQ,CAACO,KAAK,CAAC,GAAG,CAAC,CAAA;AACnC,EAAA,IAAMC,SAAS,GAAGF,OAAO,CAACG,MAAM,GAAG,CAAC,GAAGH,OAAO,CAACA,OAAO,CAACG,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAA;EACzE,IAAMC,IAAI,GAAGJ,OAAO,CAACG,MAAM,GAAG,CAAC,GAAGH,OAAO,CAACK,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC,GAAGN,OAAO,CAAC,CAAC,CAAC,CAAA;AAE7E,EAAA,IAAII,IAAI,CAACD,MAAM,IAAIJ,aAAa,IAAIJ,wBAAwB,IAAIS,IAAI,CAACD,MAAM,GAAG,CAAC,EAAE;AAC7E,IAAA,OAAOT,QAAQ,CAAA;AACnB,GAAA;EAEA,IAAMa,cAAc,GAAGH,IAAI,CAACA,IAAI,CAACD,MAAM,GAAG,CAAC,CAAC,CAAA;EAC5C,IAAMK,aAAa,MAAAC,MAAA,CAAML,IAAI,CAACM,SAAS,CAAC,CAAC,EAAEf,wBAAwB,CAAC,CAAA,CAAAc,MAAA,CAAGZ,SAAS,EAAAY,MAAA,CAAGF,cAAc,CAAE,CAAA;EAEnG,OAAOL,SAAS,GAAAO,EAAAA,CAAAA,MAAA,CAAMD,aAAa,OAAAC,MAAA,CAAIP,SAAS,CAAA,GAAKM,aAAa,CAAA;AACtE;;;;"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.truncateFilename = void 0;
7
- var truncateFilename = exports.truncateFilename = function truncateFilename(_ref) {
8
- var filename = _ref.filename,
9
- startNameTruncationIndex = _ref.startNameTruncationIndex,
10
- _ref$separator = _ref.separator,
11
- separator = _ref$separator === void 0 ? '...' : _ref$separator,
12
- _ref$minNameLength = _ref.minNameLength,
13
- minNameLength = _ref$minNameLength === void 0 ? 5 : _ref$minNameLength;
14
- var strings = filename.split('.');
15
- var extension = strings.length > 1 ? strings[strings.length - 1] : null;
16
- var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
17
- if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {
18
- return filename;
19
- }
20
- var lastNameLetter = name[name.length - 1];
21
- var truncatedName = "".concat(name.substring(0, startNameTruncationIndex)).concat(separator).concat(lastNameLetter);
22
- return extension ? "".concat(truncatedName, ".").concat(extension) : truncatedName;
23
- };
@@ -1,17 +0,0 @@
1
- export var truncateFilename = function truncateFilename(_ref) {
2
- var filename = _ref.filename,
3
- startNameTruncationIndex = _ref.startNameTruncationIndex,
4
- _ref$separator = _ref.separator,
5
- separator = _ref$separator === void 0 ? '...' : _ref$separator,
6
- _ref$minNameLength = _ref.minNameLength,
7
- minNameLength = _ref$minNameLength === void 0 ? 5 : _ref$minNameLength;
8
- var strings = filename.split('.');
9
- var extension = strings.length > 1 ? strings[strings.length - 1] : null;
10
- var name = strings.length > 1 ? strings.slice(0, -1).join('.') : strings[0];
11
- if (name.length <= minNameLength || startNameTruncationIndex >= name.length - 1) {
12
- return filename;
13
- }
14
- var lastNameLetter = name[name.length - 1];
15
- var truncatedName = "".concat(name.substring(0, startNameTruncationIndex)).concat(separator).concat(lastNameLetter);
16
- return extension ? "".concat(truncatedName, ".").concat(extension) : truncatedName;
17
- };
@@ -1,7 +0,0 @@
1
- export declare const truncateFilename: ({ filename, startNameTruncationIndex, separator, minNameLength, }: {
2
- filename: string;
3
- startNameTruncationIndex: number;
4
- separator?: string | undefined;
5
- minNameLength?: number | undefined;
6
- }) => string;
7
- //# sourceMappingURL=truncateFilename.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"truncateFilename.d.ts","sourceRoot":"","sources":["../../../../src/components/Attach/utils/truncateFilename.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;cAMf,MAAM;8BACU,MAAM;;;YAgBnC,CAAC"}