@chayns-components/core 5.5.62 → 5.5.64
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/AGENTS.md +24 -0
- package/lib/cjs/components/file-list/FileList.js +3 -1
- package/lib/cjs/components/file-list/FileList.js.map +1 -1
- package/lib/cjs/components/file-list/file-item/FileItem.js +27 -19
- package/lib/cjs/components/file-list/file-item/FileItem.js.map +1 -1
- package/lib/cjs/components/text-area/TextArea.js +9 -6
- package/lib/cjs/components/text-area/TextArea.js.map +1 -1
- package/lib/esm/components/file-list/FileList.js +3 -1
- package/lib/esm/components/file-list/FileList.js.map +1 -1
- package/lib/esm/components/file-list/file-item/FileItem.js +27 -19
- package/lib/esm/components/file-list/file-item/FileItem.js.map +1 -1
- package/lib/esm/components/text-area/TextArea.js +9 -6
- package/lib/esm/components/text-area/TextArea.js.map +1 -1
- package/lib/types/components/file-list/FileList.d.ts +6 -0
- package/package.json +2 -2
package/AGENTS.md
CHANGED
|
@@ -2037,6 +2037,30 @@ import { FileList } from '@chayns-components/core';
|
|
|
2037
2037
|
/>
|
|
2038
2038
|
```
|
|
2039
2039
|
|
|
2040
|
+
#### Custom Context Menu Items
|
|
2041
|
+
|
|
2042
|
+
```tsx
|
|
2043
|
+
<FileList
|
|
2044
|
+
files={[
|
|
2045
|
+
{
|
|
2046
|
+
id: '1',
|
|
2047
|
+
name: 'Document.txt',
|
|
2048
|
+
size: 1024,
|
|
2049
|
+
mimeType: 'text/plain',
|
|
2050
|
+
contextMenuItems: [
|
|
2051
|
+
{
|
|
2052
|
+
key: 'custom-download',
|
|
2053
|
+
text: 'Download via project',
|
|
2054
|
+
icons: ['fa fa-download'],
|
|
2055
|
+
onClick: () => action('custom-download')('1'),
|
|
2056
|
+
},
|
|
2057
|
+
],
|
|
2058
|
+
},
|
|
2059
|
+
]}
|
|
2060
|
+
shouldAllowDownload={false}
|
|
2061
|
+
/>
|
|
2062
|
+
```
|
|
2063
|
+
|
|
2040
2064
|
### Props
|
|
2041
2065
|
|
|
2042
2066
|
| name | type | required | description |
|
|
@@ -21,7 +21,8 @@ const FileList = ({
|
|
|
21
21
|
size,
|
|
22
22
|
name,
|
|
23
23
|
id,
|
|
24
|
-
source
|
|
24
|
+
source,
|
|
25
|
+
contextMenuItems
|
|
25
26
|
}) => /*#__PURE__*/_react.default.createElement(_FileItem.default, {
|
|
26
27
|
key: id,
|
|
27
28
|
id: id,
|
|
@@ -29,6 +30,7 @@ const FileList = ({
|
|
|
29
30
|
size: size,
|
|
30
31
|
mimeType: mimeType,
|
|
31
32
|
source: source,
|
|
33
|
+
contextMenuItems: contextMenuItems,
|
|
32
34
|
onRemove: onRemove,
|
|
33
35
|
shouldAllowDownload: shouldAllowDownload
|
|
34
36
|
})), [files, onRemove, shouldAllowDownload]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileList.js","names":["_react","_interopRequireWildcard","require","_textstrings","_List","_interopRequireDefault","_FileList","_FileItem","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","FileList","files","onRemove","shouldAllowDownload","content","useMemo","map","mimeType","size","name","id","source","createElement","key","TextStringProviderSSR","libraries","StyledFileList","displayName","_default","exports"],"sources":["../../../../src/components/file-list/FileList.tsx"],"sourcesContent":["import React, { FC, useMemo } from 'react';\nimport { TextStringProviderSSR } from '@chayns/textstrings';\nimport List from '../list/List';\nimport { StyledFileList } from './FileList.styles';\nimport FileItem from './file-item/FileItem';\n\nexport interface IFileItem {\n id: string;\n name: string;\n size?: number;\n mimeType: string;\n source?: string | File;\n}\n\nexport type FileListProps = {\n /**\n * Already uploaded files to display.\n */\n files?: IFileItem[];\n /**\n * A function to be executed when a file is removed.\n */\n onRemove?: (id: IFileItem['id']) => void;\n /**\n * Whether to show a download icon for files that have a `source` set.\n */\n shouldAllowDownload?: boolean;\n};\n\nconst FileList: FC<FileListProps> = ({ files, onRemove, shouldAllowDownload }) => {\n const content = useMemo(\n () =>\n files?.map(({ mimeType, size, name, id, source }) => (\n <FileItem\n key={id}\n id={id}\n name={name}\n size={size}\n mimeType={mimeType}\n source={source}\n onRemove={onRemove}\n shouldAllowDownload={shouldAllowDownload}\n />\n )),\n [files, onRemove, shouldAllowDownload],\n );\n\n return useMemo(\n () => (\n <TextStringProviderSSR libraries=\"chayns-components-v5-core\" id=\"file-list\">\n <StyledFileList>\n <List>{content}</List>\n </StyledFileList>\n </TextStringProviderSSR>\n ),\n [content],\n );\n};\n\nFileList.displayName = 'FileList';\n\nexport default FileList;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAF,sBAAA,CAAAH,OAAA;AAA4C,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAX,uBAAA,YAAAA,CAAAO,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAG,CAAA,OAAAK,CAAA,IAAAD,CAAA,GAAAS,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAG,CAAA,OAAAK,CAAA,CAAAI,GAAA,IAAAJ,CAAA,CAAAK,GAAA,IAAAN,CAAA,CAAAE,CAAA,EAAAN,CAAA,EAAAK,CAAA,IAAAC,CAAA,CAAAN,CAAA,IAAAH,CAAA,CAAAG,CAAA,WAAAM,CAAA,KAAAT,CAAA,EAAAG,CAAA;
|
|
1
|
+
{"version":3,"file":"FileList.js","names":["_react","_interopRequireWildcard","require","_textstrings","_List","_interopRequireDefault","_FileList","_FileItem","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","FileList","files","onRemove","shouldAllowDownload","content","useMemo","map","mimeType","size","name","id","source","contextMenuItems","createElement","key","TextStringProviderSSR","libraries","StyledFileList","displayName","_default","exports"],"sources":["../../../../src/components/file-list/FileList.tsx"],"sourcesContent":["import React, { FC, useMemo } from 'react';\nimport { TextStringProviderSSR } from '@chayns/textstrings';\nimport List from '../list/List';\nimport { StyledFileList } from './FileList.styles';\nimport FileItem from './file-item/FileItem';\nimport type { ContextMenuItem } from '../context-menu/ContextMenu.types';\n\nexport interface IFileItem {\n id: string;\n name: string;\n size?: number;\n mimeType: string;\n source?: string | File;\n /**\n * Additional context menu actions, appended after the built-in download and remove actions.\n * Use keys other than `download` and `remove` when those built-in actions are enabled.\n */\n contextMenuItems?: ContextMenuItem[];\n}\n\nexport type FileListProps = {\n /**\n * Already uploaded files to display.\n */\n files?: IFileItem[];\n /**\n * A function to be executed when a file is removed.\n */\n onRemove?: (id: IFileItem['id']) => void;\n /**\n * Whether to show a download icon for files that have a `source` set.\n */\n shouldAllowDownload?: boolean;\n};\n\nconst FileList: FC<FileListProps> = ({ files, onRemove, shouldAllowDownload }) => {\n const content = useMemo(\n () =>\n files?.map(({ mimeType, size, name, id, source, contextMenuItems }) => (\n <FileItem\n key={id}\n id={id}\n name={name}\n size={size}\n mimeType={mimeType}\n source={source}\n contextMenuItems={contextMenuItems}\n onRemove={onRemove}\n shouldAllowDownload={shouldAllowDownload}\n />\n )),\n [files, onRemove, shouldAllowDownload],\n );\n\n return useMemo(\n () => (\n <TextStringProviderSSR libraries=\"chayns-components-v5-core\" id=\"file-list\">\n <StyledFileList>\n <List>{content}</List>\n </StyledFileList>\n </TextStringProviderSSR>\n ),\n [content],\n );\n};\n\nFileList.displayName = 'FileList';\n\nexport default FileList;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAF,sBAAA,CAAAH,OAAA;AAA4C,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAX,uBAAA,YAAAA,CAAAO,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAA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CAAA8B,aAAA,CAACrC,YAAA,CAAAuC,qBAAqB;IAACC,SAAS,EAAC,2BAA2B;IAACN,EAAE,EAAC;EAAW,gBACvErC,MAAA,CAAAU,OAAA,CAAA8B,aAAA,CAAClC,SAAA,CAAAsC,cAAc,qBACX5C,MAAA,CAAAU,OAAA,CAAA8B,aAAA,CAACpC,KAAA,CAAAM,OAAI,QAAEqB,OAAc,CACT,CACG,CAC1B,EACD,CAACA,OAAO,CACZ,CAAC;AACL,CAAC;AAEDJ,QAAQ,CAACkB,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAArC,OAAA,GAEnBiB,QAAQ","ignoreList":[]}
|
|
@@ -23,12 +23,14 @@ const FileItem = ({
|
|
|
23
23
|
name,
|
|
24
24
|
id,
|
|
25
25
|
source,
|
|
26
|
-
shouldAllowDownload
|
|
26
|
+
shouldAllowDownload,
|
|
27
|
+
contextMenuItems
|
|
27
28
|
}) => {
|
|
28
29
|
const canDownload = shouldAllowDownload && !!source;
|
|
29
30
|
const canRemove = typeof onRemove === 'function';
|
|
31
|
+
const hasCustomActions = !!(contextMenuItems !== null && contextMenuItems !== void 0 && contextMenuItems.length);
|
|
30
32
|
const actionIconRef = (0, _react.useRef)(null);
|
|
31
|
-
const shouldShowKeyboardHighlighting = (0, _useKeyboardFocusHighlighting.useKeyboardFocusHighlighting)(canRemove || !!canDownload);
|
|
33
|
+
const shouldShowKeyboardHighlighting = (0, _useKeyboardFocusHighlighting.useKeyboardFocusHighlighting)(canRemove || !!canDownload || hasCustomActions);
|
|
32
34
|
(0, _useFocusRingPortal.useFocusRingPortal)(actionIconRef, {
|
|
33
35
|
isEnabled: shouldShowKeyboardHighlighting,
|
|
34
36
|
shape: 'circle'
|
|
@@ -37,7 +39,7 @@ const FileItem = ({
|
|
|
37
39
|
if (canRemove) {
|
|
38
40
|
onRemove(id);
|
|
39
41
|
}
|
|
40
|
-
}, [id, onRemove]);
|
|
42
|
+
}, [canRemove, id, onRemove]);
|
|
41
43
|
const handleItemKeyDown = (0, _react.useCallback)(event => {
|
|
42
44
|
if (event.key === 'Delete') {
|
|
43
45
|
event.preventDefault();
|
|
@@ -50,7 +52,7 @@ const FileItem = ({
|
|
|
50
52
|
event.stopPropagation();
|
|
51
53
|
handleRemove();
|
|
52
54
|
}
|
|
53
|
-
}, [handleRemove]);
|
|
55
|
+
}, [canRemove, handleRemove]);
|
|
54
56
|
const humanFileSize = (0, _react.useMemo)(() => {
|
|
55
57
|
if (typeof size === 'number') {
|
|
56
58
|
return (0, _file.getHumanSize)(size);
|
|
@@ -103,20 +105,26 @@ const FileItem = ({
|
|
|
103
105
|
const downloadText = t(_textStrings.default.components.fileItem.download);
|
|
104
106
|
const removeText = t(_textStrings.default.components.fileItem.remove);
|
|
105
107
|
const rightElement = (0, _react.useMemo)(() => {
|
|
106
|
-
if (!canDownload && !canRemove) return undefined;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
if (!canDownload && !canRemove && !hasCustomActions) return undefined;
|
|
109
|
+
if (hasCustomActions || canDownload && canRemove) {
|
|
110
|
+
const items = [];
|
|
111
|
+
if (canDownload) {
|
|
112
|
+
items.push({
|
|
113
|
+
icons: ['fa fa-download'],
|
|
114
|
+
key: 'download',
|
|
115
|
+
onClick: handleDownload,
|
|
116
|
+
text: downloadText
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (canRemove) {
|
|
120
|
+
items.push({
|
|
121
|
+
icons: ['fa fa-trash'],
|
|
122
|
+
key: 'remove',
|
|
123
|
+
onClick: handleRemove,
|
|
124
|
+
text: removeText
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
items.push(...(contextMenuItems ?? []));
|
|
120
128
|
return /*#__PURE__*/_react.default.createElement(_ContextMenu.default, {
|
|
121
129
|
items: items
|
|
122
130
|
});
|
|
@@ -139,7 +147,7 @@ const FileItem = ({
|
|
|
139
147
|
}, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
140
148
|
icons: [fileIcon]
|
|
141
149
|
}));
|
|
142
|
-
}, [canDownload, canRemove, downloadText, handleDownload, handleRemoveKeyDown, id, onRemove, removeText]);
|
|
150
|
+
}, [canDownload, canRemove, contextMenuItems, downloadText, handleDownload, handleRemove, handleRemoveKeyDown, hasCustomActions, id, onRemove, removeText]);
|
|
143
151
|
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_FileItem.StyledFileItem, null, /*#__PURE__*/_react.default.createElement(_FileItem.StyledFileItemKeyboardWrapper, {
|
|
144
152
|
onKeyDown: handleItemKeyDown,
|
|
145
153
|
tabIndex: -1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileItem.js","names":["_react","_interopRequireWildcard","require","_file","_Icon","_interopRequireDefault","_ContextMenu","_ListItem","_FileItem","_textstrings","_textStrings","_useFocusRingPortal","_useKeyboardFocusHighlighting","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","FileItem","mimeType","onRemove","size","name","id","source","shouldAllowDownload","canDownload","canRemove","actionIconRef","useRef","shouldShowKeyboardHighlighting","useKeyboardFocusHighlighting","useFocusRingPortal","isEnabled","shape","handleRemove","useCallback","handleItemKeyDown","event","key","preventDefault","handleRemoveKeyDown","stopPropagation","humanFileSize","useMemo","getHumanSize","undefined","icon","getIconByMimeType","handleDownload","File","url","URL","createObjectURL","a","document","createElement","href","download","body","appendChild","click","removeChild","revokeObjectURL","fetch","then","res","ok","Error","blob","catch","rel","target","useTranslation","downloadText","textStrings","components","fileItem","removeText","remove","rightElement","items","icons","onClick","text","handleClick","handleKeyDown","fileIcon","StyledFileItemIcon","ref","onKeyDown","role","tabIndex","StyledFileItem","StyledFileItemKeyboardWrapper","title","subtitle","rightElements","shouldEnableKeyboardHighlighting","displayName","_default","exports"],"sources":["../../../../../src/components/file-list/file-item/FileItem.tsx"],"sourcesContent":["import React, { FC, KeyboardEventHandler, useCallback, useMemo, useRef } from 'react';\nimport { getHumanSize, getIconByMimeType } from '../../../utils/file';\nimport Icon from '../../icon/Icon';\nimport ContextMenu from '../../context-menu/ContextMenu';\nimport type { ContextMenuItem } from '../../context-menu/ContextMenu.types';\nimport ListItem from '../../list/list-item/ListItem';\nimport type { IFileItem } from '../FileList';\nimport {\n StyledFileItem,\n StyledFileItemActions,\n StyledFileItemKeyboardWrapper,\n StyledFileItemRemoveButton,\n StyledFileItemIcon,\n} from './FileItem.styles';\nimport { useTranslation } from '@chayns/textstrings';\nimport textStrings from '../../../constants/textStrings';\nimport { useFocusRingPortal } from '../../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../../hooks/useKeyboardFocusHighlighting';\n\nexport type FileItemProps = IFileItem & {\n onRemove?: (name: string) => void;\n shouldAllowDownload?: boolean;\n};\n\nconst FileItem: FC<FileItemProps> = ({\n mimeType,\n onRemove,\n size,\n name,\n id,\n source,\n shouldAllowDownload,\n}) => {\n const canDownload = shouldAllowDownload && !!source;\n const canRemove = typeof onRemove === 'function';\n const actionIconRef = useRef<HTMLDivElement>(null);\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(canRemove || !!canDownload);\n useFocusRingPortal(actionIconRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n shape: 'circle',\n });\n\n const handleRemove = useCallback(() => {\n if (canRemove) {\n onRemove(id);\n }\n }, [id, onRemove]);\n\n const handleItemKeyDown = useCallback<KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n if (event.key === 'Delete') {\n event.preventDefault();\n handleRemove();\n }\n },\n [handleRemove],\n );\n\n const handleRemoveKeyDown = useCallback<KeyboardEventHandler<HTMLSpanElement>>(\n (event) => {\n if (canRemove && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n event.stopPropagation();\n handleRemove();\n }\n },\n [handleRemove],\n );\n\n const humanFileSize = useMemo(() => {\n if (typeof size === 'number') {\n return getHumanSize(size);\n }\n\n return undefined;\n }, [size]);\n\n const icon = useMemo(() => getIconByMimeType(mimeType), [mimeType]);\n\n const handleDownload = useCallback(() => {\n if (!source) return;\n\n if (source instanceof File) {\n const url = URL.createObjectURL(source);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n } else {\n // Try fetching as blob to force download. If CORS blocks it,\n // fall back to opening the URL directly.\n fetch(source)\n .then((res) => {\n if (!res.ok) throw new Error('fetch failed');\n return res.blob();\n })\n .then((blob) => {\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n })\n .catch(() => {\n // CORS or network error: fall back to direct link\n const a = document.createElement('a');\n a.href = source;\n a.download = name;\n a.rel = 'noopener noreferrer';\n a.target = '_blank';\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n });\n }\n }, [name, source]);\n\n const { t } = useTranslation();\n const downloadText = t(textStrings.components.fileItem.download);\n const removeText = t(textStrings.components.fileItem.remove);\n\n const rightElement = useMemo(() => {\n if (!canDownload && !canRemove) return undefined;\n // Both actions available → show as ContextMenu\n if (canDownload && canRemove) {\n const items: ContextMenuItem[] = [\n {\n icons: ['fa fa-download'],\n key: 'download',\n onClick: handleDownload,\n text: downloadText,\n },\n {\n icons: ['fa fa-trash'],\n key: 'remove',\n onClick: () => onRemove(id),\n text: removeText,\n },\n ];\n\n return <ContextMenu items={items} />;\n }\n\n const handleClick = () => {\n if (canRemove) {\n onRemove(id);\n return;\n }\n\n handleDownload();\n };\n\n const handleKeyDown = canRemove ? handleRemoveKeyDown : undefined;\n\n const fileIcon = canRemove ? 'ts-wrong' : 'fa fa-download';\n\n return (\n <StyledFileItemIcon\n ref={actionIconRef}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n >\n <Icon icons={[fileIcon]} />\n </StyledFileItemIcon>\n );\n }, [\n canDownload,\n canRemove,\n downloadText,\n handleDownload,\n handleRemoveKeyDown,\n id,\n onRemove,\n removeText,\n ]);\n\n return useMemo(\n () => (\n <StyledFileItem>\n <StyledFileItemKeyboardWrapper onKeyDown={handleItemKeyDown} tabIndex={-1}>\n <ListItem\n title={name}\n subtitle={humanFileSize}\n icons={[icon]}\n rightElements={rightElement}\n shouldEnableKeyboardHighlighting={shouldShowKeyboardHighlighting}\n />\n </StyledFileItemKeyboardWrapper>\n </StyledFileItem>\n ),\n [\n handleItemKeyDown,\n humanFileSize,\n icon,\n name,\n rightElement,\n shouldShowKeyboardHighlighting,\n ],\n );\n};\n\nFileItem.displayName = 'FileList';\n\nexport default FileItem;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,YAAA,GAAAD,sBAAA,CAAAH,OAAA;AAEA,IAAAK,SAAA,GAAAF,sBAAA,CAAAH,OAAA;AAEA,IAAAM,SAAA,GAAAN,OAAA;AAOA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,mBAAA,GAAAT,OAAA;AACA,IAAAU,6BAAA,GAAAV,OAAA;AAA2F,SAAAG,uBAAAQ,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAZ,wBAAAY,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAhB,uBAAA,YAAAA,CAAAY,CAAA,EAA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ACD,CACIO,iBAAiB,EACjBM,aAAa,EACbI,IAAI,EACJzB,IAAI,EACJ0D,YAAY,EACZlD,8BAA8B,CAEtC,CAAC;AACL,CAAC;AAEDZ,QAAQ,CAACiF,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAApG,OAAA,GAEnBiB,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"FileItem.js","names":["_react","_interopRequireWildcard","require","_file","_Icon","_interopRequireDefault","_ContextMenu","_ListItem","_FileItem","_textstrings","_textStrings","_useFocusRingPortal","_useKeyboardFocusHighlighting","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","FileItem","mimeType","onRemove","size","name","id","source","shouldAllowDownload","contextMenuItems","canDownload","canRemove","hasCustomActions","length","actionIconRef","useRef","shouldShowKeyboardHighlighting","useKeyboardFocusHighlighting","useFocusRingPortal","isEnabled","shape","handleRemove","useCallback","handleItemKeyDown","event","key","preventDefault","handleRemoveKeyDown","stopPropagation","humanFileSize","useMemo","getHumanSize","undefined","icon","getIconByMimeType","handleDownload","File","url","URL","createObjectURL","a","document","createElement","href","download","body","appendChild","click","removeChild","revokeObjectURL","fetch","then","res","ok","Error","blob","catch","rel","target","useTranslation","downloadText","textStrings","components","fileItem","removeText","remove","rightElement","items","push","icons","onClick","text","handleClick","handleKeyDown","fileIcon","StyledFileItemIcon","ref","onKeyDown","role","tabIndex","StyledFileItem","StyledFileItemKeyboardWrapper","title","subtitle","rightElements","shouldEnableKeyboardHighlighting","displayName","_default","exports"],"sources":["../../../../../src/components/file-list/file-item/FileItem.tsx"],"sourcesContent":["import React, { FC, KeyboardEventHandler, useCallback, useMemo, useRef } from 'react';\nimport { getHumanSize, getIconByMimeType } from '../../../utils/file';\nimport Icon from '../../icon/Icon';\nimport ContextMenu from '../../context-menu/ContextMenu';\nimport type { ContextMenuItem } from '../../context-menu/ContextMenu.types';\nimport ListItem from '../../list/list-item/ListItem';\nimport type { IFileItem } from '../FileList';\nimport {\n StyledFileItem,\n StyledFileItemKeyboardWrapper,\n StyledFileItemIcon,\n} from './FileItem.styles';\nimport { useTranslation } from '@chayns/textstrings';\nimport textStrings from '../../../constants/textStrings';\nimport { useFocusRingPortal } from '../../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../../hooks/useKeyboardFocusHighlighting';\n\nexport type FileItemProps = IFileItem & {\n onRemove?: (name: string) => void;\n shouldAllowDownload?: boolean;\n};\n\nconst FileItem: FC<FileItemProps> = ({\n mimeType,\n onRemove,\n size,\n name,\n id,\n source,\n shouldAllowDownload,\n contextMenuItems,\n}) => {\n const canDownload = shouldAllowDownload && !!source;\n const canRemove = typeof onRemove === 'function';\n const hasCustomActions = !!contextMenuItems?.length;\n const actionIconRef = useRef<HTMLDivElement>(null);\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n canRemove || !!canDownload || hasCustomActions,\n );\n useFocusRingPortal(actionIconRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n shape: 'circle',\n });\n\n const handleRemove = useCallback(() => {\n if (canRemove) {\n onRemove(id);\n }\n }, [canRemove, id, onRemove]);\n\n const handleItemKeyDown = useCallback<KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n if (event.key === 'Delete') {\n event.preventDefault();\n handleRemove();\n }\n },\n [handleRemove],\n );\n\n const handleRemoveKeyDown = useCallback<KeyboardEventHandler<HTMLSpanElement>>(\n (event) => {\n if (canRemove && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n event.stopPropagation();\n handleRemove();\n }\n },\n [canRemove, handleRemove],\n );\n\n const humanFileSize = useMemo(() => {\n if (typeof size === 'number') {\n return getHumanSize(size);\n }\n\n return undefined;\n }, [size]);\n\n const icon = useMemo(() => getIconByMimeType(mimeType), [mimeType]);\n\n const handleDownload = useCallback(() => {\n if (!source) return;\n\n if (source instanceof File) {\n const url = URL.createObjectURL(source);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n } else {\n // Try fetching as blob to force download. If CORS blocks it,\n // fall back to opening the URL directly.\n fetch(source)\n .then((res) => {\n if (!res.ok) throw new Error('fetch failed');\n return res.blob();\n })\n .then((blob) => {\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n })\n .catch(() => {\n // CORS or network error: fall back to direct link\n const a = document.createElement('a');\n a.href = source;\n a.download = name;\n a.rel = 'noopener noreferrer';\n a.target = '_blank';\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n });\n }\n }, [name, source]);\n\n const { t } = useTranslation();\n const downloadText = t(textStrings.components.fileItem.download);\n const removeText = t(textStrings.components.fileItem.remove);\n\n const rightElement = useMemo(() => {\n if (!canDownload && !canRemove && !hasCustomActions) return undefined;\n\n if (hasCustomActions || (canDownload && canRemove)) {\n const items: ContextMenuItem[] = [];\n\n if (canDownload) {\n items.push({\n icons: ['fa fa-download'],\n key: 'download',\n onClick: handleDownload,\n text: downloadText,\n });\n }\n\n if (canRemove) {\n items.push({\n icons: ['fa fa-trash'],\n key: 'remove',\n onClick: handleRemove,\n text: removeText,\n });\n }\n\n items.push(...(contextMenuItems ?? []));\n\n return <ContextMenu items={items} />;\n }\n\n const handleClick = () => {\n if (canRemove) {\n onRemove(id);\n return;\n }\n\n handleDownload();\n };\n\n const handleKeyDown = canRemove ? handleRemoveKeyDown : undefined;\n\n const fileIcon = canRemove ? 'ts-wrong' : 'fa fa-download';\n\n return (\n <StyledFileItemIcon\n ref={actionIconRef}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n >\n <Icon icons={[fileIcon]} />\n </StyledFileItemIcon>\n );\n }, [\n canDownload,\n canRemove,\n contextMenuItems,\n downloadText,\n handleDownload,\n handleRemove,\n handleRemoveKeyDown,\n hasCustomActions,\n id,\n onRemove,\n removeText,\n ]);\n\n return useMemo(\n () => (\n <StyledFileItem>\n <StyledFileItemKeyboardWrapper onKeyDown={handleItemKeyDown} tabIndex={-1}>\n <ListItem\n title={name}\n subtitle={humanFileSize}\n icons={[icon]}\n rightElements={rightElement}\n shouldEnableKeyboardHighlighting={shouldShowKeyboardHighlighting}\n />\n </StyledFileItemKeyboardWrapper>\n </StyledFileItem>\n ),\n [\n handleItemKeyDown,\n humanFileSize,\n icon,\n name,\n rightElement,\n shouldShowKeyboardHighlighting,\n ],\n );\n};\n\nFileItem.displayName = 'FileList';\n\nexport default FileItem;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,YAAA,GAAAD,sBAAA,CAAAH,OAAA;AAEA,IAAAK,SAAA,GAAAF,sBAAA,CAAAH,OAAA;AAEA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,YAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,mBAAA,GAAAT,OAAA;AACA,IAAAU,6BAAA,GAAAV,OAAA;AAA2F,SAAAG,uBAAAQ,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAZ,wBAAAY,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAhB,uBAAA,YAAAA,CAAAY,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA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G,MAAA,CAAAe,OAAA,CAAA0D,aAAA,CAAClE,SAAA,CAAAQ,OAAQ;IACLkG,KAAK,EAAE7E,IAAK;IACZ8E,QAAQ,EAAEtD,aAAc;IACxBwC,KAAK,EAAE,CAACpC,IAAI,CAAE;IACdmD,aAAa,EAAElB,YAAa;IAC5BmB,gCAAgC,EAAErE;EAA+B,CACpE,CAC0B,CACnB,CACnB,EACD,CACIO,iBAAiB,EACjBM,aAAa,EACbI,IAAI,EACJ5B,IAAI,EACJ6D,YAAY,EACZlD,8BAA8B,CAEtC,CAAC;AACL,CAAC;AAEDf,QAAQ,CAACqF,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAxG,OAAA,GAEnBiB,QAAQ","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _reactCompilerRuntime = require("react-compiler-runtime");
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _styledComponents = require("styled-components");
|
|
9
10
|
var _AreaContextProvider = require("../area-provider/AreaContextProvider");
|
|
10
11
|
var _Input = require("../input/Input.styles");
|
|
11
12
|
var _TextArea = require("./TextArea.styles");
|
|
@@ -17,7 +18,7 @@ const TextArea = /*#__PURE__*/(0, _react.forwardRef)((t0, ref) => {
|
|
|
17
18
|
"use memo";
|
|
18
19
|
|
|
19
20
|
var _rightElement$props;
|
|
20
|
-
const $ = (0, _reactCompilerRuntime.c)(
|
|
21
|
+
const $ = (0, _reactCompilerRuntime.c)(32);
|
|
21
22
|
const {
|
|
22
23
|
isDisabled,
|
|
23
24
|
isInvalid,
|
|
@@ -37,6 +38,7 @@ const TextArea = /*#__PURE__*/(0, _react.forwardRef)((t0, ref) => {
|
|
|
37
38
|
const minHeight = t2 === undefined ? "41px" : t2;
|
|
38
39
|
const [isOverflowing, setIsOverflowing] = (0, _react.useState)(false);
|
|
39
40
|
const areaProvider = (0, _react.useContext)(_AreaContextProvider.AreaContext);
|
|
41
|
+
const theme = (0, _styledComponents.useTheme)();
|
|
40
42
|
const textareaRef = (0, _react.useRef)(null);
|
|
41
43
|
(0, _resize.useCursorRepaint)(textareaRef);
|
|
42
44
|
const shouldShowBorder = (rightElement === null || rightElement === void 0 || (_rightElement$props = rightElement.props) === null || _rightElement$props === void 0 || (_rightElement$props = _rightElement$props.style) === null || _rightElement$props === void 0 ? void 0 : _rightElement$props.backgroundColor) === undefined;
|
|
@@ -111,7 +113,7 @@ const TextArea = /*#__PURE__*/(0, _react.forwardRef)((t0, ref) => {
|
|
|
111
113
|
}
|
|
112
114
|
const labelPosition = t8;
|
|
113
115
|
let t9;
|
|
114
|
-
if ($[11] !== (colors === null || colors === void 0 ? void 0 : colors.backgroundColor) || $[12] !== (colors === null || colors === void 0 ? void 0 : colors.borderColor) || $[13] !== hasValue || $[14] !== isDisabled || $[15] !== isInvalid || $[16] !== isOverflowing || $[17] !== labelPosition || $[18] !== maxHeight || $[19] !== minHeight || $[20] !== onBlur || $[21] !== onChange || $[22] !== onFocus || $[23] !== onKeyDown || $[24] !== placeholder || $[25] !== rightElement || $[26] !== shouldChangeColor || $[27] !== shouldShowBorder || $[28] !== shouldShowKeyboardHighlighting || $[29] !== value) {
|
|
116
|
+
if ($[11] !== (colors === null || colors === void 0 ? void 0 : colors.backgroundColor) || $[12] !== (colors === null || colors === void 0 ? void 0 : colors.borderColor) || $[13] !== hasValue || $[14] !== isDisabled || $[15] !== isInvalid || $[16] !== isOverflowing || $[17] !== labelPosition || $[18] !== maxHeight || $[19] !== minHeight || $[20] !== onBlur || $[21] !== onChange || $[22] !== onFocus || $[23] !== onKeyDown || $[24] !== placeholder || $[25] !== rightElement || $[26] !== shouldChangeColor || $[27] !== shouldShowBorder || $[28] !== shouldShowKeyboardHighlighting || $[29] !== theme.fontSize || $[30] !== value) {
|
|
115
117
|
colors === null || colors === void 0 || colors.backgroundColor;
|
|
116
118
|
colors === null || colors === void 0 || colors.borderColor;
|
|
117
119
|
t9 = (() => /*#__PURE__*/_react.default.createElement(_TextArea.StyledTextArea, {
|
|
@@ -138,7 +140,7 @@ const TextArea = /*#__PURE__*/(0, _react.forwardRef)((t0, ref) => {
|
|
|
138
140
|
rows: 1
|
|
139
141
|
}), /*#__PURE__*/_react.default.createElement(_TextArea.StyledTextAreaLabelWrapper, {
|
|
140
142
|
animate: {
|
|
141
|
-
fontSize: hasValue ? "9px" :
|
|
143
|
+
fontSize: hasValue ? "9px" : `${Number(theme.fontSize)}px`
|
|
142
144
|
},
|
|
143
145
|
initial: false,
|
|
144
146
|
style: labelPosition,
|
|
@@ -171,10 +173,11 @@ const TextArea = /*#__PURE__*/(0, _react.forwardRef)((t0, ref) => {
|
|
|
171
173
|
$[26] = shouldChangeColor;
|
|
172
174
|
$[27] = shouldShowBorder;
|
|
173
175
|
$[28] = shouldShowKeyboardHighlighting;
|
|
174
|
-
$[29] =
|
|
175
|
-
$[30] =
|
|
176
|
+
$[29] = theme.fontSize;
|
|
177
|
+
$[30] = value;
|
|
178
|
+
$[31] = t9;
|
|
176
179
|
} else {
|
|
177
|
-
t9 = $[
|
|
180
|
+
t9 = $[31];
|
|
178
181
|
}
|
|
179
182
|
return t9;
|
|
180
183
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","names":["_react","_interopRequireWildcard","require","_AreaContextProvider","_Input","_TextArea","_resize","_useFocusRingPortal","_useKeyboardFocusHighlighting","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TextArea","forwardRef","t0","ref","_rightElement$props","$","_reactCompilerRuntime","c","isDisabled","isInvalid","placeholder","value","onChange","onFocus","onKeyDown","rightElement","onBlur","maxHeight","t1","minHeight","t2","colors","shouldEnableKeyboardHighlighting","undefined","isOverflowing","setIsOverflowing","useState","areaProvider","useContext","AreaContext","textareaRef","useRef","useCursorRepaint","shouldShowBorder","props","style","backgroundColor","shouldChangeColor","shouldShowKeyboardHighlighting","useKeyboardFocusHighlighting","t3","isEnabled","useFocusRingPortal","t4","current","height","scrollHeight","parseInt","toString","adjustTextareaHeight","t5","Symbol","for","useImperativeHandle","t6","t7","length","useEffect","hasValue","t8","bottom","right","top","left","labelPosition","t9","borderColor","createElement","StyledTextArea","StyledTextAreaContentWrapper","$backgroundColor","$borderColor","StyledTextAreaContent","StyledTextAreaInput","className","rows","StyledTextAreaLabelWrapper","animate","fontSize","initial","transition","type","duration","StyledTextAreaLabel","StyledInputRightElement","$isInline","StyledRightElementWrapper","displayName","_default","exports"],"sources":["../../../../src/components/text-area/TextArea.tsx"],"sourcesContent":["import React, {\n ChangeEventHandler,\n CSSProperties,\n FocusEventHandler,\n forwardRef,\n KeyboardEventHandler,\n ReactElement,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport { StyledInputRightElement } from '../input/Input.styles';\nimport {\n StyledRightElementWrapper,\n StyledTextArea,\n StyledTextAreaContent,\n StyledTextAreaContentWrapper,\n StyledTextAreaInput,\n StyledTextAreaLabel,\n StyledTextAreaLabelWrapper,\n} from './TextArea.styles';\nimport { useCursorRepaint } from '../../hooks/resize';\nimport { useFocusRingPortal } from '../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../hooks/useKeyboardFocusHighlighting';\n\ntype TextAreaColors = {\n backgroundColor: CSSProperties['backgroundColor'];\n borderColor: CSSProperties['borderColor'];\n};\n\nexport type TextAreaProps = {\n /**\n * Disables the text area so that it cannot be changed.\n */\n isDisabled?: boolean;\n /**\n * If true, the text area is marked as invalid\n */\n isInvalid?: boolean;\n /**\n * The maximum height of the text area.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * The minimum height of the text area.\n */\n minHeight?: CSSProperties['minHeight'];\n /**\n * Function that is executed when the text area loses focus.\n */\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the text of the text area changes.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n /**\n * Placeholder for the text area field.\n */\n placeholder?: string | ReactElement;\n /**\n * An element that should be displayed on the right side of the Input.\n */\n rightElement?: ReactElement;\n /**\n * Value if the text area should be controlled.\n */\n value?: string;\n /**\n * Provide custom colors to the TextArea Component\n */\n colors?: TextAreaColors;\n /**\n * Enables keyboard-only focus highlighting.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n};\n\nconst TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(\n (\n {\n isDisabled,\n isInvalid,\n placeholder,\n value,\n onChange,\n onFocus,\n onKeyDown,\n rightElement,\n onBlur,\n maxHeight = '120px',\n minHeight = '41px',\n colors,\n shouldEnableKeyboardHighlighting,\n },\n ref,\n ) => {\n 'use memo';\n\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const areaProvider = useContext(AreaContext);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n useCursorRepaint(textareaRef);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const shouldShowBorder = rightElement?.props?.style?.backgroundColor === undefined;\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n shouldEnableKeyboardHighlighting && !isDisabled,\n );\n useFocusRingPortal(textareaRef, { isEnabled: shouldShowKeyboardHighlighting });\n\n const adjustTextareaHeight = useCallback(() => {\n if (textareaRef.current) {\n textareaRef.current.style.height = 'auto';\n textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;\n\n setIsOverflowing(\n textareaRef.current.scrollHeight > parseInt(maxHeight.toString(), 10),\n );\n }\n }, [maxHeight]);\n\n useImperativeHandle(ref, () => textareaRef.current as HTMLTextAreaElement);\n\n /**\n * This hook calculates the height of the TextArea after the displayValue is changed and the content is inside the \"textareaRef\".\n * To maintain the functionality while clearing the input, the length need to be greater than -1.\n */\n useEffect(() => {\n if (typeof value === 'string' && value.length > -1) {\n adjustTextareaHeight();\n }\n }, [adjustTextareaHeight, value]);\n\n const hasValue = value !== undefined && value.length > 0;\n\n const labelPosition = useMemo(\n () =>\n hasValue\n ? {\n bottom: '2px',\n right: '2px',\n }\n : {\n top: '12px',\n left: '10px',\n },\n [hasValue],\n );\n\n return useMemo(\n () => (\n <StyledTextArea $isDisabled={isDisabled}>\n <StyledTextAreaContentWrapper\n $isInvalid={isInvalid}\n $shouldChangeColor={shouldChangeColor}\n $backgroundColor={colors?.backgroundColor}\n $borderColor={colors?.borderColor}\n data-should-show-keyboard-highlighting={shouldShowKeyboardHighlighting}\n >\n <StyledTextAreaContent>\n <StyledTextAreaInput\n className=\"chayns-scrollbar\"\n disabled={isDisabled}\n $isInvalid={isInvalid}\n ref={textareaRef}\n value={value}\n onBlur={onBlur}\n onChange={onChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n $maxHeight={maxHeight}\n $minHeight={minHeight}\n $isOverflowing={isOverflowing}\n rows={1}\n />\n <StyledTextAreaLabelWrapper\n animate={{ fontSize: hasValue ? '9px' : undefined }}\n initial={false}\n style={labelPosition}\n transition={{ type: 'tween', duration: 0.1 }}\n >\n <StyledTextAreaLabel $isInvalid={isInvalid}>\n {placeholder}\n </StyledTextAreaLabel>\n </StyledTextAreaLabelWrapper>\n </StyledTextAreaContent>\n {rightElement && shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>\n {rightElement}\n </StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextAreaContentWrapper>\n {rightElement && !shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>{rightElement}</StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextArea>\n ),\n [\n isDisabled,\n isInvalid,\n shouldChangeColor,\n shouldShowKeyboardHighlighting,\n colors?.backgroundColor,\n colors?.borderColor,\n value,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n maxHeight,\n minHeight,\n isOverflowing,\n hasValue,\n labelPosition,\n placeholder,\n rightElement,\n shouldShowBorder,\n ],\n );\n },\n);\n\nTextArea.displayName = 'TextArea';\n\nexport default TextArea;\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAeA,IAAAC,oBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AASA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AACA,IAAAM,6BAAA,GAAAN,OAAA;AAAwF,SAAAD,wBAAAQ,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAV,uBAAA,YAAAA,CAAAQ,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAA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,OAAAgB,MAAA,aAAAA,MAAA,uBAAAA,MAAA,CAAA6C,WAAA;IAAA7D,CAAA,OAAAqD,QAAA;IAAArD,CAAA,OAAAG,UAAA;IAAAH,CAAA,OAAAI,SAAA;IAAAJ,CAAA,OAAAmB,aAAA;IAAAnB,CAAA,OAAA2D,aAAA;IAAA3D,CAAA,OAAAY,SAAA;IAAAZ,CAAA,OAAAc,SAAA;IAAAd,CAAA,OAAAW,MAAA;IAAAX,CAAA,OAAAO,QAAA;IAAAP,CAAA,OAAAQ,OAAA;IAAAR,CAAA,OAAAS,SAAA;IAAAT,CAAA,OAAAK,WAAA;IAAAL,CAAA,OAAAU,YAAA;IAAAV,CAAA,OAAAgC,iBAAA;IAAAhC,CAAA,OAAA4B,gBAAA;IAAA5B,CAAA,OAAAiC,8BAAA;IAAAjC,CAAA,OAAAM,KAAA;IAAAN,CAAA,OAAA4D,EAAA;EAAA;IAAAA,EAAA,GAAA5D,CAAA;EAAA;EAAA,OAzEM4D,EAyEN;AAAA,CAET,CAAC;AAEDjE,QAAQ,CAACuF,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAlG,OAAA,GAEnBS,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"TextArea.js","names":["_react","_interopRequireWildcard","require","_styledComponents","_AreaContextProvider","_Input","_TextArea","_resize","_useFocusRingPortal","_useKeyboardFocusHighlighting","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TextArea","forwardRef","t0","ref","_rightElement$props","$","_reactCompilerRuntime","c","isDisabled","isInvalid","placeholder","value","onChange","onFocus","onKeyDown","rightElement","onBlur","maxHeight","t1","minHeight","t2","colors","shouldEnableKeyboardHighlighting","undefined","isOverflowing","setIsOverflowing","useState","areaProvider","useContext","AreaContext","theme","useTheme","textareaRef","useRef","useCursorRepaint","shouldShowBorder","props","style","backgroundColor","shouldChangeColor","shouldShowKeyboardHighlighting","useKeyboardFocusHighlighting","t3","isEnabled","useFocusRingPortal","t4","current","height","scrollHeight","parseInt","toString","adjustTextareaHeight","t5","Symbol","for","useImperativeHandle","t6","t7","length","useEffect","hasValue","t8","bottom","right","top","left","labelPosition","t9","borderColor","fontSize","createElement","StyledTextArea","StyledTextAreaContentWrapper","$backgroundColor","$borderColor","StyledTextAreaContent","StyledTextAreaInput","className","rows","StyledTextAreaLabelWrapper","animate","Number","initial","transition","type","duration","StyledTextAreaLabel","StyledInputRightElement","$isInline","StyledRightElementWrapper","displayName","_default","exports"],"sources":["../../../../src/components/text-area/TextArea.tsx"],"sourcesContent":["import React, {\n ChangeEventHandler,\n CSSProperties,\n FocusEventHandler,\n forwardRef,\n KeyboardEventHandler,\n ReactElement,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useTheme } from 'styled-components';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport type { Theme } from '../color-scheme-provider/ColorSchemeProvider';\nimport { StyledInputRightElement } from '../input/Input.styles';\nimport {\n StyledRightElementWrapper,\n StyledTextArea,\n StyledTextAreaContent,\n StyledTextAreaContentWrapper,\n StyledTextAreaInput,\n StyledTextAreaLabel,\n StyledTextAreaLabelWrapper,\n} from './TextArea.styles';\nimport { useCursorRepaint } from '../../hooks/resize';\nimport { useFocusRingPortal } from '../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../hooks/useKeyboardFocusHighlighting';\n\ntype TextAreaColors = {\n backgroundColor: CSSProperties['backgroundColor'];\n borderColor: CSSProperties['borderColor'];\n};\n\nexport type TextAreaProps = {\n /**\n * Disables the text area so that it cannot be changed.\n */\n isDisabled?: boolean;\n /**\n * If true, the text area is marked as invalid\n */\n isInvalid?: boolean;\n /**\n * The maximum height of the text area.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * The minimum height of the text area.\n */\n minHeight?: CSSProperties['minHeight'];\n /**\n * Function that is executed when the text area loses focus.\n */\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the text of the text area changes.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n /**\n * Placeholder for the text area field.\n */\n placeholder?: string | ReactElement;\n /**\n * An element that should be displayed on the right side of the Input.\n */\n rightElement?: ReactElement;\n /**\n * Value if the text area should be controlled.\n */\n value?: string;\n /**\n * Provide custom colors to the TextArea Component\n */\n colors?: TextAreaColors;\n /**\n * Enables keyboard-only focus highlighting.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n};\n\nconst TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(\n (\n {\n isDisabled,\n isInvalid,\n placeholder,\n value,\n onChange,\n onFocus,\n onKeyDown,\n rightElement,\n onBlur,\n maxHeight = '120px',\n minHeight = '41px',\n colors,\n shouldEnableKeyboardHighlighting,\n },\n ref,\n ) => {\n 'use memo';\n\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const areaProvider = useContext(AreaContext);\n const theme = useTheme() as Theme;\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n useCursorRepaint(textareaRef);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const shouldShowBorder = rightElement?.props?.style?.backgroundColor === undefined;\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n shouldEnableKeyboardHighlighting && !isDisabled,\n );\n useFocusRingPortal(textareaRef, { isEnabled: shouldShowKeyboardHighlighting });\n\n const adjustTextareaHeight = useCallback(() => {\n if (textareaRef.current) {\n textareaRef.current.style.height = 'auto';\n textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;\n\n setIsOverflowing(\n textareaRef.current.scrollHeight > parseInt(maxHeight.toString(), 10),\n );\n }\n }, [maxHeight]);\n\n useImperativeHandle(ref, () => textareaRef.current as HTMLTextAreaElement);\n\n /**\n * This hook calculates the height of the TextArea after the displayValue is changed and the content is inside the \"textareaRef\".\n * To maintain the functionality while clearing the input, the length need to be greater than -1.\n */\n useEffect(() => {\n if (typeof value === 'string' && value.length > -1) {\n adjustTextareaHeight();\n }\n }, [adjustTextareaHeight, value]);\n\n const hasValue = value !== undefined && value.length > 0;\n\n const labelPosition = useMemo(\n () =>\n hasValue\n ? {\n bottom: '2px',\n right: '2px',\n }\n : {\n top: '12px',\n left: '10px',\n },\n [hasValue],\n );\n\n return useMemo(\n () => (\n <StyledTextArea $isDisabled={isDisabled}>\n <StyledTextAreaContentWrapper\n $isInvalid={isInvalid}\n $shouldChangeColor={shouldChangeColor}\n $backgroundColor={colors?.backgroundColor}\n $borderColor={colors?.borderColor}\n data-should-show-keyboard-highlighting={shouldShowKeyboardHighlighting}\n >\n <StyledTextAreaContent>\n <StyledTextAreaInput\n className=\"chayns-scrollbar\"\n disabled={isDisabled}\n $isInvalid={isInvalid}\n ref={textareaRef}\n value={value}\n onBlur={onBlur}\n onChange={onChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n $maxHeight={maxHeight}\n $minHeight={minHeight}\n $isOverflowing={isOverflowing}\n rows={1}\n />\n <StyledTextAreaLabelWrapper\n animate={{\n fontSize: hasValue ? '9px' : `${Number(theme.fontSize)}px`,\n }}\n initial={false}\n style={labelPosition}\n transition={{ type: 'tween', duration: 0.1 }}\n >\n <StyledTextAreaLabel $isInvalid={isInvalid}>\n {placeholder}\n </StyledTextAreaLabel>\n </StyledTextAreaLabelWrapper>\n </StyledTextAreaContent>\n {rightElement && shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>\n {rightElement}\n </StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextAreaContentWrapper>\n {rightElement && !shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>{rightElement}</StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextArea>\n ),\n [\n isDisabled,\n isInvalid,\n shouldChangeColor,\n shouldShowKeyboardHighlighting,\n colors?.backgroundColor,\n colors?.borderColor,\n value,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n maxHeight,\n minHeight,\n isOverflowing,\n hasValue,\n theme.fontSize,\n labelPosition,\n placeholder,\n rightElement,\n shouldShowBorder,\n ],\n );\n },\n);\n\nTextArea.displayName = 'TextArea';\n\nexport default TextArea;\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAeA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AASA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,mBAAA,GAAAN,OAAA;AACA,IAAAO,6BAAA,GAAAP,OAAA;AAAwF,SAAAD,wBAAAS,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAX,uBAAA,YAAAA,CAAAS,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ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|
|
18
19
|
key: id,
|
|
19
20
|
id: id,
|
|
@@ -21,6 +22,7 @@ const FileList = ({
|
|
|
21
22
|
size: size,
|
|
22
23
|
mimeType: mimeType,
|
|
23
24
|
source: source,
|
|
25
|
+
contextMenuItems: contextMenuItems,
|
|
24
26
|
onRemove: onRemove,
|
|
25
27
|
shouldAllowDownload: shouldAllowDownload
|
|
26
28
|
})), [files, onRemove, shouldAllowDownload]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileList.js","names":["React","useMemo","TextStringProviderSSR","List","StyledFileList","FileItem","FileList","files","onRemove","shouldAllowDownload","content","map","mimeType","size","name","id","source","createElement","key","libraries","displayName"],"sources":["../../../../src/components/file-list/FileList.tsx"],"sourcesContent":["import React, { FC, useMemo } from 'react';\nimport { TextStringProviderSSR } from '@chayns/textstrings';\nimport List from '../list/List';\nimport { StyledFileList } from './FileList.styles';\nimport FileItem from './file-item/FileItem';\n\nexport interface IFileItem {\n id: string;\n name: string;\n size?: number;\n mimeType: string;\n source?: string | File;\n}\n\nexport type FileListProps = {\n /**\n * Already uploaded files to display.\n */\n files?: IFileItem[];\n /**\n * A function to be executed when a file is removed.\n */\n onRemove?: (id: IFileItem['id']) => void;\n /**\n * Whether to show a download icon for files that have a `source` set.\n */\n shouldAllowDownload?: boolean;\n};\n\nconst FileList: FC<FileListProps> = ({ files, onRemove, shouldAllowDownload }) => {\n const content = useMemo(\n () =>\n files?.map(({ mimeType, size, name, id, source }) => (\n <FileItem\n key={id}\n id={id}\n name={name}\n size={size}\n mimeType={mimeType}\n source={source}\n onRemove={onRemove}\n shouldAllowDownload={shouldAllowDownload}\n />\n )),\n [files, onRemove, shouldAllowDownload],\n );\n\n return useMemo(\n () => (\n <TextStringProviderSSR libraries=\"chayns-components-v5-core\" id=\"file-list\">\n <StyledFileList>\n <List>{content}</List>\n </StyledFileList>\n </TextStringProviderSSR>\n ),\n [content],\n );\n};\n\nFileList.displayName = 'FileList';\n\nexport default FileList;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,OAAO,QAAQ,OAAO;AAC1C,SAASC,qBAAqB,QAAQ,qBAAqB;AAC3D,OAAOC,IAAI,MAAM,cAAc;AAC/B,SAASC,cAAc,QAAQ,mBAAmB;AAClD,OAAOC,QAAQ,MAAM,sBAAsB;
|
|
1
|
+
{"version":3,"file":"FileList.js","names":["React","useMemo","TextStringProviderSSR","List","StyledFileList","FileItem","FileList","files","onRemove","shouldAllowDownload","content","map","mimeType","size","name","id","source","contextMenuItems","createElement","key","libraries","displayName"],"sources":["../../../../src/components/file-list/FileList.tsx"],"sourcesContent":["import React, { FC, useMemo } from 'react';\nimport { TextStringProviderSSR } from '@chayns/textstrings';\nimport List from '../list/List';\nimport { StyledFileList } from './FileList.styles';\nimport FileItem from './file-item/FileItem';\nimport type { ContextMenuItem } from '../context-menu/ContextMenu.types';\n\nexport interface IFileItem {\n id: string;\n name: string;\n size?: number;\n mimeType: string;\n source?: string | File;\n /**\n * Additional context menu actions, appended after the built-in download and remove actions.\n * Use keys other than `download` and `remove` when those built-in actions are enabled.\n */\n contextMenuItems?: ContextMenuItem[];\n}\n\nexport type FileListProps = {\n /**\n * Already uploaded files to display.\n */\n files?: IFileItem[];\n /**\n * A function to be executed when a file is removed.\n */\n onRemove?: (id: IFileItem['id']) => void;\n /**\n * Whether to show a download icon for files that have a `source` set.\n */\n shouldAllowDownload?: boolean;\n};\n\nconst FileList: FC<FileListProps> = ({ files, onRemove, shouldAllowDownload }) => {\n const content = useMemo(\n () =>\n files?.map(({ mimeType, size, name, id, source, contextMenuItems }) => (\n <FileItem\n key={id}\n id={id}\n name={name}\n size={size}\n mimeType={mimeType}\n source={source}\n contextMenuItems={contextMenuItems}\n onRemove={onRemove}\n shouldAllowDownload={shouldAllowDownload}\n />\n )),\n [files, onRemove, shouldAllowDownload],\n );\n\n return useMemo(\n () => (\n <TextStringProviderSSR libraries=\"chayns-components-v5-core\" id=\"file-list\">\n <StyledFileList>\n <List>{content}</List>\n </StyledFileList>\n </TextStringProviderSSR>\n ),\n [content],\n );\n};\n\nFileList.displayName = 'FileList';\n\nexport default FileList;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,OAAO,QAAQ,OAAO;AAC1C,SAASC,qBAAqB,QAAQ,qBAAqB;AAC3D,OAAOC,IAAI,MAAM,cAAc;AAC/B,SAASC,cAAc,QAAQ,mBAAmB;AAClD,OAAOC,QAAQ,MAAM,sBAAsB;AA+B3C,MAAMC,QAA2B,GAAGA,CAAC;EAAEC,KAAK;EAAEC,QAAQ;EAAEC;AAAoB,CAAC,KAAK;EAC9E,MAAMC,OAAO,GAAGT,OAAO,CACnB,MACIM,KAAK,EAAEI,GAAG,CAAC,CAAC;IAAEC,QAAQ;IAAEC,IAAI;IAAEC,IAAI;IAAEC,EAAE;IAAEC,MAAM;IAAEC;EAAiB,CAAC,kBAC9DjB,KAAA,CAAAkB,aAAA,CAACb,QAAQ;IACLc,GAAG,EAAEJ,EAAG;IACRA,EAAE,EAAEA,EAAG;IACPD,IAAI,EAAEA,IAAK;IACXD,IAAI,EAAEA,IAAK;IACXD,QAAQ,EAAEA,QAAS;IACnBI,MAAM,EAAEA,MAAO;IACfC,gBAAgB,EAAEA,gBAAiB;IACnCT,QAAQ,EAAEA,QAAS;IACnBC,mBAAmB,EAAEA;EAAoB,CAC5C,CACJ,CAAC,EACN,CAACF,KAAK,EAAEC,QAAQ,EAAEC,mBAAmB,CACzC,CAAC;EAED,OAAOR,OAAO,CACV,mBACID,KAAA,CAAAkB,aAAA,CAAChB,qBAAqB;IAACkB,SAAS,EAAC,2BAA2B;IAACL,EAAE,EAAC;EAAW,gBACvEf,KAAA,CAAAkB,aAAA,CAACd,cAAc,qBACXJ,KAAA,CAAAkB,aAAA,CAACf,IAAI,QAAEO,OAAc,CACT,CACG,CAC1B,EACD,CAACA,OAAO,CACZ,CAAC;AACL,CAAC;AAEDJ,QAAQ,CAACe,WAAW,GAAG,UAAU;AAEjC,eAAef,QAAQ","ignoreList":[]}
|
|
@@ -15,12 +15,14 @@ const FileItem = ({
|
|
|
15
15
|
name,
|
|
16
16
|
id,
|
|
17
17
|
source,
|
|
18
|
-
shouldAllowDownload
|
|
18
|
+
shouldAllowDownload,
|
|
19
|
+
contextMenuItems
|
|
19
20
|
}) => {
|
|
20
21
|
const canDownload = shouldAllowDownload && !!source;
|
|
21
22
|
const canRemove = typeof onRemove === 'function';
|
|
23
|
+
const hasCustomActions = !!contextMenuItems?.length;
|
|
22
24
|
const actionIconRef = useRef(null);
|
|
23
|
-
const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(canRemove || !!canDownload);
|
|
25
|
+
const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(canRemove || !!canDownload || hasCustomActions);
|
|
24
26
|
useFocusRingPortal(actionIconRef, {
|
|
25
27
|
isEnabled: shouldShowKeyboardHighlighting,
|
|
26
28
|
shape: 'circle'
|
|
@@ -29,7 +31,7 @@ const FileItem = ({
|
|
|
29
31
|
if (canRemove) {
|
|
30
32
|
onRemove(id);
|
|
31
33
|
}
|
|
32
|
-
}, [id, onRemove]);
|
|
34
|
+
}, [canRemove, id, onRemove]);
|
|
33
35
|
const handleItemKeyDown = useCallback(event => {
|
|
34
36
|
if (event.key === 'Delete') {
|
|
35
37
|
event.preventDefault();
|
|
@@ -42,7 +44,7 @@ const FileItem = ({
|
|
|
42
44
|
event.stopPropagation();
|
|
43
45
|
handleRemove();
|
|
44
46
|
}
|
|
45
|
-
}, [handleRemove]);
|
|
47
|
+
}, [canRemove, handleRemove]);
|
|
46
48
|
const humanFileSize = useMemo(() => {
|
|
47
49
|
if (typeof size === 'number') {
|
|
48
50
|
return getHumanSize(size);
|
|
@@ -95,20 +97,26 @@ const FileItem = ({
|
|
|
95
97
|
const downloadText = t(textStrings.components.fileItem.download);
|
|
96
98
|
const removeText = t(textStrings.components.fileItem.remove);
|
|
97
99
|
const rightElement = useMemo(() => {
|
|
98
|
-
if (!canDownload && !canRemove) return undefined;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
if (!canDownload && !canRemove && !hasCustomActions) return undefined;
|
|
101
|
+
if (hasCustomActions || canDownload && canRemove) {
|
|
102
|
+
const items = [];
|
|
103
|
+
if (canDownload) {
|
|
104
|
+
items.push({
|
|
105
|
+
icons: ['fa fa-download'],
|
|
106
|
+
key: 'download',
|
|
107
|
+
onClick: handleDownload,
|
|
108
|
+
text: downloadText
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (canRemove) {
|
|
112
|
+
items.push({
|
|
113
|
+
icons: ['fa fa-trash'],
|
|
114
|
+
key: 'remove',
|
|
115
|
+
onClick: handleRemove,
|
|
116
|
+
text: removeText
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
items.push(...(contextMenuItems ?? []));
|
|
112
120
|
return /*#__PURE__*/React.createElement(ContextMenu, {
|
|
113
121
|
items: items
|
|
114
122
|
});
|
|
@@ -131,7 +139,7 @@ const FileItem = ({
|
|
|
131
139
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
132
140
|
icons: [fileIcon]
|
|
133
141
|
}));
|
|
134
|
-
}, [canDownload, canRemove, downloadText, handleDownload, handleRemoveKeyDown, id, onRemove, removeText]);
|
|
142
|
+
}, [canDownload, canRemove, contextMenuItems, downloadText, handleDownload, handleRemove, handleRemoveKeyDown, hasCustomActions, id, onRemove, removeText]);
|
|
135
143
|
return useMemo(() => /*#__PURE__*/React.createElement(StyledFileItem, null, /*#__PURE__*/React.createElement(StyledFileItemKeyboardWrapper, {
|
|
136
144
|
onKeyDown: handleItemKeyDown,
|
|
137
145
|
tabIndex: -1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileItem.js","names":["React","useCallback","useMemo","useRef","getHumanSize","getIconByMimeType","Icon","ContextMenu","ListItem","StyledFileItem","StyledFileItemKeyboardWrapper","StyledFileItemIcon","useTranslation","textStrings","useFocusRingPortal","useKeyboardFocusHighlighting","FileItem","mimeType","onRemove","size","name","id","source","shouldAllowDownload","canDownload","canRemove","actionIconRef","shouldShowKeyboardHighlighting","isEnabled","shape","handleRemove","handleItemKeyDown","event","key","preventDefault","handleRemoveKeyDown","stopPropagation","humanFileSize","undefined","icon","handleDownload","File","url","URL","createObjectURL","a","document","createElement","href","download","body","appendChild","click","removeChild","revokeObjectURL","fetch","then","res","ok","Error","blob","catch","rel","target","t","downloadText","components","fileItem","removeText","remove","rightElement","items","icons","onClick","text","handleClick","handleKeyDown","fileIcon","ref","onKeyDown","role","tabIndex","title","subtitle","rightElements","shouldEnableKeyboardHighlighting","displayName"],"sources":["../../../../../src/components/file-list/file-item/FileItem.tsx"],"sourcesContent":["import React, { FC, KeyboardEventHandler, useCallback, useMemo, useRef } from 'react';\nimport { getHumanSize, getIconByMimeType } from '../../../utils/file';\nimport Icon from '../../icon/Icon';\nimport ContextMenu from '../../context-menu/ContextMenu';\nimport type { ContextMenuItem } from '../../context-menu/ContextMenu.types';\nimport ListItem from '../../list/list-item/ListItem';\nimport type { IFileItem } from '../FileList';\nimport {\n StyledFileItem,\n StyledFileItemActions,\n StyledFileItemKeyboardWrapper,\n StyledFileItemRemoveButton,\n StyledFileItemIcon,\n} from './FileItem.styles';\nimport { useTranslation } from '@chayns/textstrings';\nimport textStrings from '../../../constants/textStrings';\nimport { useFocusRingPortal } from '../../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../../hooks/useKeyboardFocusHighlighting';\n\nexport type FileItemProps = IFileItem & {\n onRemove?: (name: string) => void;\n shouldAllowDownload?: boolean;\n};\n\nconst FileItem: FC<FileItemProps> = ({\n mimeType,\n onRemove,\n size,\n name,\n id,\n source,\n shouldAllowDownload,\n}) => {\n const canDownload = shouldAllowDownload && !!source;\n const canRemove = typeof onRemove === 'function';\n const actionIconRef = useRef<HTMLDivElement>(null);\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(canRemove || !!canDownload);\n useFocusRingPortal(actionIconRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n shape: 'circle',\n });\n\n const handleRemove = useCallback(() => {\n if (canRemove) {\n onRemove(id);\n }\n }, [id, onRemove]);\n\n const handleItemKeyDown = useCallback<KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n if (event.key === 'Delete') {\n event.preventDefault();\n handleRemove();\n }\n },\n [handleRemove],\n );\n\n const handleRemoveKeyDown = useCallback<KeyboardEventHandler<HTMLSpanElement>>(\n (event) => {\n if (canRemove && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n event.stopPropagation();\n handleRemove();\n }\n },\n [handleRemove],\n );\n\n const humanFileSize = useMemo(() => {\n if (typeof size === 'number') {\n return getHumanSize(size);\n }\n\n return undefined;\n }, [size]);\n\n const icon = useMemo(() => getIconByMimeType(mimeType), [mimeType]);\n\n const handleDownload = useCallback(() => {\n if (!source) return;\n\n if (source instanceof File) {\n const url = URL.createObjectURL(source);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n } else {\n // Try fetching as blob to force download. If CORS blocks it,\n // fall back to opening the URL directly.\n fetch(source)\n .then((res) => {\n if (!res.ok) throw new Error('fetch failed');\n return res.blob();\n })\n .then((blob) => {\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n })\n .catch(() => {\n // CORS or network error: fall back to direct link\n const a = document.createElement('a');\n a.href = source;\n a.download = name;\n a.rel = 'noopener noreferrer';\n a.target = '_blank';\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n });\n }\n }, [name, source]);\n\n const { t } = useTranslation();\n const downloadText = t(textStrings.components.fileItem.download);\n const removeText = t(textStrings.components.fileItem.remove);\n\n const rightElement = useMemo(() => {\n if (!canDownload && !canRemove) return undefined;\n // Both actions available → show as ContextMenu\n if (canDownload && canRemove) {\n const items: ContextMenuItem[] = [\n {\n icons: ['fa fa-download'],\n key: 'download',\n onClick: handleDownload,\n text: downloadText,\n },\n {\n icons: ['fa fa-trash'],\n key: 'remove',\n onClick: () => onRemove(id),\n text: removeText,\n },\n ];\n\n return <ContextMenu items={items} />;\n }\n\n const handleClick = () => {\n if (canRemove) {\n onRemove(id);\n return;\n }\n\n handleDownload();\n };\n\n const handleKeyDown = canRemove ? handleRemoveKeyDown : undefined;\n\n const fileIcon = canRemove ? 'ts-wrong' : 'fa fa-download';\n\n return (\n <StyledFileItemIcon\n ref={actionIconRef}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n >\n <Icon icons={[fileIcon]} />\n </StyledFileItemIcon>\n );\n }, [\n canDownload,\n canRemove,\n downloadText,\n handleDownload,\n handleRemoveKeyDown,\n id,\n onRemove,\n removeText,\n ]);\n\n return useMemo(\n () => (\n <StyledFileItem>\n <StyledFileItemKeyboardWrapper onKeyDown={handleItemKeyDown} tabIndex={-1}>\n <ListItem\n title={name}\n subtitle={humanFileSize}\n icons={[icon]}\n rightElements={rightElement}\n shouldEnableKeyboardHighlighting={shouldShowKeyboardHighlighting}\n />\n </StyledFileItemKeyboardWrapper>\n </StyledFileItem>\n ),\n [\n handleItemKeyDown,\n humanFileSize,\n icon,\n name,\n rightElement,\n shouldShowKeyboardHighlighting,\n ],\n );\n};\n\nFileItem.displayName = 'FileList';\n\nexport default FileItem;\n"],"mappings":"AAAA,OAAOA,KAAK,IAA8BC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AACrF,SAASC,YAAY,EAAEC,iBAAiB,QAAQ,qBAAqB;AACrE,OAAOC,IAAI,MAAM,iBAAiB;AAClC,OAAOC,WAAW,MAAM,gCAAgC;AAExD,OAAOC,QAAQ,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AO,CACV,mBACIF,KAAA,CAAA+C,aAAA,CAACtC,cAAc,qBACXT,KAAA,CAAA+C,aAAA,CAACrC,6BAA6B;IAACqE,SAAS,EAAEhD,iBAAkB;IAACkD,QAAQ,EAAE,CAAC;EAAE,gBACtEjF,KAAA,CAAA+C,aAAA,CAACvC,QAAQ;IACL0E,KAAK,EAAE9D,IAAK;IACZ+D,QAAQ,EAAE9C,aAAc;IACxBmC,KAAK,EAAE,CAACjC,IAAI,CAAE;IACd6C,aAAa,EAAEd,YAAa;IAC5Be,gCAAgC,EAAE1D;EAA+B,CACpE,CAC0B,CACnB,CACnB,EACD,CACII,iBAAiB,EACjBM,aAAa,EACbE,IAAI,EACJnB,IAAI,EACJkD,YAAY,EACZ3C,8BAA8B,CAEtC,CAAC;AACL,CAAC;AAEDX,QAAQ,CAACsE,WAAW,GAAG,UAAU;AAEjC,eAAetE,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"FileItem.js","names":["React","useCallback","useMemo","useRef","getHumanSize","getIconByMimeType","Icon","ContextMenu","ListItem","StyledFileItem","StyledFileItemKeyboardWrapper","StyledFileItemIcon","useTranslation","textStrings","useFocusRingPortal","useKeyboardFocusHighlighting","FileItem","mimeType","onRemove","size","name","id","source","shouldAllowDownload","contextMenuItems","canDownload","canRemove","hasCustomActions","length","actionIconRef","shouldShowKeyboardHighlighting","isEnabled","shape","handleRemove","handleItemKeyDown","event","key","preventDefault","handleRemoveKeyDown","stopPropagation","humanFileSize","undefined","icon","handleDownload","File","url","URL","createObjectURL","a","document","createElement","href","download","body","appendChild","click","removeChild","revokeObjectURL","fetch","then","res","ok","Error","blob","catch","rel","target","t","downloadText","components","fileItem","removeText","remove","rightElement","items","push","icons","onClick","text","handleClick","handleKeyDown","fileIcon","ref","onKeyDown","role","tabIndex","title","subtitle","rightElements","shouldEnableKeyboardHighlighting","displayName"],"sources":["../../../../../src/components/file-list/file-item/FileItem.tsx"],"sourcesContent":["import React, { FC, KeyboardEventHandler, useCallback, useMemo, useRef } from 'react';\nimport { getHumanSize, getIconByMimeType } from '../../../utils/file';\nimport Icon from '../../icon/Icon';\nimport ContextMenu from '../../context-menu/ContextMenu';\nimport type { ContextMenuItem } from '../../context-menu/ContextMenu.types';\nimport ListItem from '../../list/list-item/ListItem';\nimport type { IFileItem } from '../FileList';\nimport {\n StyledFileItem,\n StyledFileItemKeyboardWrapper,\n StyledFileItemIcon,\n} from './FileItem.styles';\nimport { useTranslation } from '@chayns/textstrings';\nimport textStrings from '../../../constants/textStrings';\nimport { useFocusRingPortal } from '../../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../../hooks/useKeyboardFocusHighlighting';\n\nexport type FileItemProps = IFileItem & {\n onRemove?: (name: string) => void;\n shouldAllowDownload?: boolean;\n};\n\nconst FileItem: FC<FileItemProps> = ({\n mimeType,\n onRemove,\n size,\n name,\n id,\n source,\n shouldAllowDownload,\n contextMenuItems,\n}) => {\n const canDownload = shouldAllowDownload && !!source;\n const canRemove = typeof onRemove === 'function';\n const hasCustomActions = !!contextMenuItems?.length;\n const actionIconRef = useRef<HTMLDivElement>(null);\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n canRemove || !!canDownload || hasCustomActions,\n );\n useFocusRingPortal(actionIconRef, {\n isEnabled: shouldShowKeyboardHighlighting,\n shape: 'circle',\n });\n\n const handleRemove = useCallback(() => {\n if (canRemove) {\n onRemove(id);\n }\n }, [canRemove, id, onRemove]);\n\n const handleItemKeyDown = useCallback<KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n if (event.key === 'Delete') {\n event.preventDefault();\n handleRemove();\n }\n },\n [handleRemove],\n );\n\n const handleRemoveKeyDown = useCallback<KeyboardEventHandler<HTMLSpanElement>>(\n (event) => {\n if (canRemove && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n event.stopPropagation();\n handleRemove();\n }\n },\n [canRemove, handleRemove],\n );\n\n const humanFileSize = useMemo(() => {\n if (typeof size === 'number') {\n return getHumanSize(size);\n }\n\n return undefined;\n }, [size]);\n\n const icon = useMemo(() => getIconByMimeType(mimeType), [mimeType]);\n\n const handleDownload = useCallback(() => {\n if (!source) return;\n\n if (source instanceof File) {\n const url = URL.createObjectURL(source);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n } else {\n // Try fetching as blob to force download. If CORS blocks it,\n // fall back to opening the URL directly.\n fetch(source)\n .then((res) => {\n if (!res.ok) throw new Error('fetch failed');\n return res.blob();\n })\n .then((blob) => {\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = name;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n })\n .catch(() => {\n // CORS or network error: fall back to direct link\n const a = document.createElement('a');\n a.href = source;\n a.download = name;\n a.rel = 'noopener noreferrer';\n a.target = '_blank';\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n });\n }\n }, [name, source]);\n\n const { t } = useTranslation();\n const downloadText = t(textStrings.components.fileItem.download);\n const removeText = t(textStrings.components.fileItem.remove);\n\n const rightElement = useMemo(() => {\n if (!canDownload && !canRemove && !hasCustomActions) return undefined;\n\n if (hasCustomActions || (canDownload && canRemove)) {\n const items: ContextMenuItem[] = [];\n\n if (canDownload) {\n items.push({\n icons: ['fa fa-download'],\n key: 'download',\n onClick: handleDownload,\n text: downloadText,\n });\n }\n\n if (canRemove) {\n items.push({\n icons: ['fa fa-trash'],\n key: 'remove',\n onClick: handleRemove,\n text: removeText,\n });\n }\n\n items.push(...(contextMenuItems ?? []));\n\n return <ContextMenu items={items} />;\n }\n\n const handleClick = () => {\n if (canRemove) {\n onRemove(id);\n return;\n }\n\n handleDownload();\n };\n\n const handleKeyDown = canRemove ? handleRemoveKeyDown : undefined;\n\n const fileIcon = canRemove ? 'ts-wrong' : 'fa fa-download';\n\n return (\n <StyledFileItemIcon\n ref={actionIconRef}\n onClick={handleClick}\n onKeyDown={handleKeyDown}\n role=\"button\"\n tabIndex={0}\n >\n <Icon icons={[fileIcon]} />\n </StyledFileItemIcon>\n );\n }, [\n canDownload,\n canRemove,\n contextMenuItems,\n downloadText,\n handleDownload,\n handleRemove,\n handleRemoveKeyDown,\n hasCustomActions,\n id,\n onRemove,\n removeText,\n ]);\n\n return useMemo(\n () => (\n <StyledFileItem>\n <StyledFileItemKeyboardWrapper onKeyDown={handleItemKeyDown} tabIndex={-1}>\n <ListItem\n title={name}\n subtitle={humanFileSize}\n icons={[icon]}\n rightElements={rightElement}\n shouldEnableKeyboardHighlighting={shouldShowKeyboardHighlighting}\n />\n </StyledFileItemKeyboardWrapper>\n </StyledFileItem>\n ),\n [\n handleItemKeyDown,\n humanFileSize,\n icon,\n name,\n rightElement,\n shouldShowKeyboardHighlighting,\n ],\n );\n};\n\nFileItem.displayName = 'FileList';\n\nexport default FileItem;\n"],"mappings":"AAAA,OAAOA,KAAK,IAA8BC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AACrF,SAASC,YAAY,EAAEC,iBAAiB,QAAQ,qBAAqB;AACrE,OAAOC,IAAI,MAAM,iBAAiB;AAClC,OAAOC,WAAW,MAAM,gCAAgC;AAExD,OAAOC,QAAQ,MAAM,+BAA+B;AAEpD,SACIC,cAAc,EACdC,6BAA6B,EAC7BC,kBAAkB,QACf,mBAAmB;AAC1B,SAASC,cAAc,QAAQ,qBAAqB;AACpD,OAAOC,WAAW,MAAM,gCAAgC;AACxD,SAASC,kBAAkB,QAAQ,mCAAmC;AACtE,SAASC,4BAA4B,QAAQ,6CAA6C;AAO1F,MAAMC,QAA2B,GAAGA,CAAC;EACjCC,QAAQ;EACRC,QAAQ;EACRC,IAAI;EACJC,IAAI;EACJC,EAAE;EACFC,MAAM;EACNC,mBAAmB;EACnBC;AACJ,CAAC,KAAK;EACF,MAAMC,WAAW,GAAGF,mBAAmB,IAAI,CAAC,CAACD,MAAM;EACn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,aAAA,CAACxC,6BAA6B;IAACyE,SAAS,EAAEjD,iBAAkB;IAACmD,QAAQ,EAAE,CAAC;EAAE,gBACtErF,KAAA,CAAAkD,aAAA,CAAC1C,QAAQ;IACL8E,KAAK,EAAElE,IAAK;IACZmE,QAAQ,EAAE/C,aAAc;IACxBoC,KAAK,EAAE,CAAClC,IAAI,CAAE;IACd8C,aAAa,EAAEf,YAAa;IAC5BgB,gCAAgC,EAAE3D;EAA+B,CACpE,CAC0B,CACnB,CACnB,EACD,CACII,iBAAiB,EACjBM,aAAa,EACbE,IAAI,EACJtB,IAAI,EACJqD,YAAY,EACZ3C,8BAA8B,CAEtC,CAAC;AACL,CAAC;AAEDd,QAAQ,CAAC0E,WAAW,GAAG,UAAU;AAEjC,eAAe1E,QAAQ","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { c as _c } from "react-compiler-runtime";
|
|
2
2
|
import React, { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useTheme } from 'styled-components';
|
|
3
4
|
import { AreaContext } from '../area-provider/AreaContextProvider';
|
|
4
5
|
import { StyledInputRightElement } from '../input/Input.styles';
|
|
5
6
|
import { StyledRightElementWrapper, StyledTextArea, StyledTextAreaContent, StyledTextAreaContentWrapper, StyledTextAreaInput, StyledTextAreaLabel, StyledTextAreaLabelWrapper } from './TextArea.styles';
|
|
@@ -9,7 +10,7 @@ import { useKeyboardFocusHighlighting } from '../../hooks/useKeyboardFocusHighli
|
|
|
9
10
|
const TextArea = /*#__PURE__*/forwardRef((t0, ref) => {
|
|
10
11
|
"use memo";
|
|
11
12
|
|
|
12
|
-
const $ = _c(
|
|
13
|
+
const $ = _c(32);
|
|
13
14
|
const {
|
|
14
15
|
isDisabled,
|
|
15
16
|
isInvalid,
|
|
@@ -29,6 +30,7 @@ const TextArea = /*#__PURE__*/forwardRef((t0, ref) => {
|
|
|
29
30
|
const minHeight = t2 === undefined ? "41px" : t2;
|
|
30
31
|
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
31
32
|
const areaProvider = useContext(AreaContext);
|
|
33
|
+
const theme = useTheme();
|
|
32
34
|
const textareaRef = useRef(null);
|
|
33
35
|
useCursorRepaint(textareaRef);
|
|
34
36
|
const shouldShowBorder = rightElement?.props?.style?.backgroundColor === undefined;
|
|
@@ -103,7 +105,7 @@ const TextArea = /*#__PURE__*/forwardRef((t0, ref) => {
|
|
|
103
105
|
}
|
|
104
106
|
const labelPosition = t8;
|
|
105
107
|
let t9;
|
|
106
|
-
if ($[11] !== colors?.backgroundColor || $[12] !== colors?.borderColor || $[13] !== hasValue || $[14] !== isDisabled || $[15] !== isInvalid || $[16] !== isOverflowing || $[17] !== labelPosition || $[18] !== maxHeight || $[19] !== minHeight || $[20] !== onBlur || $[21] !== onChange || $[22] !== onFocus || $[23] !== onKeyDown || $[24] !== placeholder || $[25] !== rightElement || $[26] !== shouldChangeColor || $[27] !== shouldShowBorder || $[28] !== shouldShowKeyboardHighlighting || $[29] !== value) {
|
|
108
|
+
if ($[11] !== colors?.backgroundColor || $[12] !== colors?.borderColor || $[13] !== hasValue || $[14] !== isDisabled || $[15] !== isInvalid || $[16] !== isOverflowing || $[17] !== labelPosition || $[18] !== maxHeight || $[19] !== minHeight || $[20] !== onBlur || $[21] !== onChange || $[22] !== onFocus || $[23] !== onKeyDown || $[24] !== placeholder || $[25] !== rightElement || $[26] !== shouldChangeColor || $[27] !== shouldShowBorder || $[28] !== shouldShowKeyboardHighlighting || $[29] !== theme.fontSize || $[30] !== value) {
|
|
107
109
|
colors?.backgroundColor;
|
|
108
110
|
colors?.borderColor;
|
|
109
111
|
t9 = (() => /*#__PURE__*/React.createElement(StyledTextArea, {
|
|
@@ -130,7 +132,7 @@ const TextArea = /*#__PURE__*/forwardRef((t0, ref) => {
|
|
|
130
132
|
rows: 1
|
|
131
133
|
}), /*#__PURE__*/React.createElement(StyledTextAreaLabelWrapper, {
|
|
132
134
|
animate: {
|
|
133
|
-
fontSize: hasValue ? "9px" :
|
|
135
|
+
fontSize: hasValue ? "9px" : `${Number(theme.fontSize)}px`
|
|
134
136
|
},
|
|
135
137
|
initial: false,
|
|
136
138
|
style: labelPosition,
|
|
@@ -163,10 +165,11 @@ const TextArea = /*#__PURE__*/forwardRef((t0, ref) => {
|
|
|
163
165
|
$[26] = shouldChangeColor;
|
|
164
166
|
$[27] = shouldShowBorder;
|
|
165
167
|
$[28] = shouldShowKeyboardHighlighting;
|
|
166
|
-
$[29] =
|
|
167
|
-
$[30] =
|
|
168
|
+
$[29] = theme.fontSize;
|
|
169
|
+
$[30] = value;
|
|
170
|
+
$[31] = t9;
|
|
168
171
|
} else {
|
|
169
|
-
t9 = $[
|
|
172
|
+
t9 = $[31];
|
|
170
173
|
}
|
|
171
174
|
return t9;
|
|
172
175
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","names":["React","forwardRef","useCallback","useContext","useEffect","useImperativeHandle","useMemo","useRef","useState","AreaContext","StyledInputRightElement","StyledRightElementWrapper","StyledTextArea","StyledTextAreaContent","StyledTextAreaContentWrapper","StyledTextAreaInput","StyledTextAreaLabel","StyledTextAreaLabelWrapper","useCursorRepaint","useFocusRingPortal","useKeyboardFocusHighlighting","TextArea","t0","ref","$","_c","isDisabled","isInvalid","placeholder","value","onChange","onFocus","onKeyDown","rightElement","onBlur","maxHeight","t1","minHeight","t2","colors","shouldEnableKeyboardHighlighting","undefined","isOverflowing","setIsOverflowing","areaProvider","textareaRef","shouldShowBorder","props","style","backgroundColor","shouldChangeColor","shouldShowKeyboardHighlighting","t3","isEnabled","t4","current","height","scrollHeight","parseInt","toString","adjustTextareaHeight","t5","Symbol","for","t6","t7","length","hasValue","t8","bottom","right","top","left","labelPosition","t9","borderColor","createElement","$backgroundColor","$borderColor","className","rows","animate","fontSize","initial","transition","type","duration","$isInline","displayName"],"sources":["../../../../src/components/text-area/TextArea.tsx"],"sourcesContent":["import React, {\n ChangeEventHandler,\n CSSProperties,\n FocusEventHandler,\n forwardRef,\n KeyboardEventHandler,\n ReactElement,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport { StyledInputRightElement } from '../input/Input.styles';\nimport {\n StyledRightElementWrapper,\n StyledTextArea,\n StyledTextAreaContent,\n StyledTextAreaContentWrapper,\n StyledTextAreaInput,\n StyledTextAreaLabel,\n StyledTextAreaLabelWrapper,\n} from './TextArea.styles';\nimport { useCursorRepaint } from '../../hooks/resize';\nimport { useFocusRingPortal } from '../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../hooks/useKeyboardFocusHighlighting';\n\ntype TextAreaColors = {\n backgroundColor: CSSProperties['backgroundColor'];\n borderColor: CSSProperties['borderColor'];\n};\n\nexport type TextAreaProps = {\n /**\n * Disables the text area so that it cannot be changed.\n */\n isDisabled?: boolean;\n /**\n * If true, the text area is marked as invalid\n */\n isInvalid?: boolean;\n /**\n * The maximum height of the text area.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * The minimum height of the text area.\n */\n minHeight?: CSSProperties['minHeight'];\n /**\n * Function that is executed when the text area loses focus.\n */\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the text of the text area changes.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n /**\n * Placeholder for the text area field.\n */\n placeholder?: string | ReactElement;\n /**\n * An element that should be displayed on the right side of the Input.\n */\n rightElement?: ReactElement;\n /**\n * Value if the text area should be controlled.\n */\n value?: string;\n /**\n * Provide custom colors to the TextArea Component\n */\n colors?: TextAreaColors;\n /**\n * Enables keyboard-only focus highlighting.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n};\n\nconst TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(\n (\n {\n isDisabled,\n isInvalid,\n placeholder,\n value,\n onChange,\n onFocus,\n onKeyDown,\n rightElement,\n onBlur,\n maxHeight = '120px',\n minHeight = '41px',\n colors,\n shouldEnableKeyboardHighlighting,\n },\n ref,\n ) => {\n 'use memo';\n\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const areaProvider = useContext(AreaContext);\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n useCursorRepaint(textareaRef);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const shouldShowBorder = rightElement?.props?.style?.backgroundColor === undefined;\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n shouldEnableKeyboardHighlighting && !isDisabled,\n );\n useFocusRingPortal(textareaRef, { isEnabled: shouldShowKeyboardHighlighting });\n\n const adjustTextareaHeight = useCallback(() => {\n if (textareaRef.current) {\n textareaRef.current.style.height = 'auto';\n textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;\n\n setIsOverflowing(\n textareaRef.current.scrollHeight > parseInt(maxHeight.toString(), 10),\n );\n }\n }, [maxHeight]);\n\n useImperativeHandle(ref, () => textareaRef.current as HTMLTextAreaElement);\n\n /**\n * This hook calculates the height of the TextArea after the displayValue is changed and the content is inside the \"textareaRef\".\n * To maintain the functionality while clearing the input, the length need to be greater than -1.\n */\n useEffect(() => {\n if (typeof value === 'string' && value.length > -1) {\n adjustTextareaHeight();\n }\n }, [adjustTextareaHeight, value]);\n\n const hasValue = value !== undefined && value.length > 0;\n\n const labelPosition = useMemo(\n () =>\n hasValue\n ? {\n bottom: '2px',\n right: '2px',\n }\n : {\n top: '12px',\n left: '10px',\n },\n [hasValue],\n );\n\n return useMemo(\n () => (\n <StyledTextArea $isDisabled={isDisabled}>\n <StyledTextAreaContentWrapper\n $isInvalid={isInvalid}\n $shouldChangeColor={shouldChangeColor}\n $backgroundColor={colors?.backgroundColor}\n $borderColor={colors?.borderColor}\n data-should-show-keyboard-highlighting={shouldShowKeyboardHighlighting}\n >\n <StyledTextAreaContent>\n <StyledTextAreaInput\n className=\"chayns-scrollbar\"\n disabled={isDisabled}\n $isInvalid={isInvalid}\n ref={textareaRef}\n value={value}\n onBlur={onBlur}\n onChange={onChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n $maxHeight={maxHeight}\n $minHeight={minHeight}\n $isOverflowing={isOverflowing}\n rows={1}\n />\n <StyledTextAreaLabelWrapper\n animate={{ fontSize: hasValue ? '9px' : undefined }}\n initial={false}\n style={labelPosition}\n transition={{ type: 'tween', duration: 0.1 }}\n >\n <StyledTextAreaLabel $isInvalid={isInvalid}>\n {placeholder}\n </StyledTextAreaLabel>\n </StyledTextAreaLabelWrapper>\n </StyledTextAreaContent>\n {rightElement && shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>\n {rightElement}\n </StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextAreaContentWrapper>\n {rightElement && !shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>{rightElement}</StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextArea>\n ),\n [\n isDisabled,\n isInvalid,\n shouldChangeColor,\n shouldShowKeyboardHighlighting,\n colors?.backgroundColor,\n colors?.borderColor,\n value,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n maxHeight,\n minHeight,\n isOverflowing,\n hasValue,\n labelPosition,\n placeholder,\n rightElement,\n shouldShowBorder,\n ],\n );\n },\n);\n\nTextArea.displayName = 'TextArea';\n\nexport default TextArea;\n"],"mappings":";AAAA,OAAOA,KAAK,IAIRC,UAAU,EAGVC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,Q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Q","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"TextArea.js","names":["React","forwardRef","useCallback","useContext","useEffect","useImperativeHandle","useMemo","useRef","useState","useTheme","AreaContext","StyledInputRightElement","StyledRightElementWrapper","StyledTextArea","StyledTextAreaContent","StyledTextAreaContentWrapper","StyledTextAreaInput","StyledTextAreaLabel","StyledTextAreaLabelWrapper","useCursorRepaint","useFocusRingPortal","useKeyboardFocusHighlighting","TextArea","t0","ref","$","_c","isDisabled","isInvalid","placeholder","value","onChange","onFocus","onKeyDown","rightElement","onBlur","maxHeight","t1","minHeight","t2","colors","shouldEnableKeyboardHighlighting","undefined","isOverflowing","setIsOverflowing","areaProvider","theme","textareaRef","shouldShowBorder","props","style","backgroundColor","shouldChangeColor","shouldShowKeyboardHighlighting","t3","isEnabled","t4","current","height","scrollHeight","parseInt","toString","adjustTextareaHeight","t5","Symbol","for","t6","t7","length","hasValue","t8","bottom","right","top","left","labelPosition","t9","borderColor","fontSize","createElement","$backgroundColor","$borderColor","className","rows","animate","Number","initial","transition","type","duration","$isInline","displayName"],"sources":["../../../../src/components/text-area/TextArea.tsx"],"sourcesContent":["import React, {\n ChangeEventHandler,\n CSSProperties,\n FocusEventHandler,\n forwardRef,\n KeyboardEventHandler,\n ReactElement,\n useCallback,\n useContext,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useTheme } from 'styled-components';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport type { Theme } from '../color-scheme-provider/ColorSchemeProvider';\nimport { StyledInputRightElement } from '../input/Input.styles';\nimport {\n StyledRightElementWrapper,\n StyledTextArea,\n StyledTextAreaContent,\n StyledTextAreaContentWrapper,\n StyledTextAreaInput,\n StyledTextAreaLabel,\n StyledTextAreaLabelWrapper,\n} from './TextArea.styles';\nimport { useCursorRepaint } from '../../hooks/resize';\nimport { useFocusRingPortal } from '../../hooks/useFocusRingPortal';\nimport { useKeyboardFocusHighlighting } from '../../hooks/useKeyboardFocusHighlighting';\n\ntype TextAreaColors = {\n backgroundColor: CSSProperties['backgroundColor'];\n borderColor: CSSProperties['borderColor'];\n};\n\nexport type TextAreaProps = {\n /**\n * Disables the text area so that it cannot be changed.\n */\n isDisabled?: boolean;\n /**\n * If true, the text area is marked as invalid\n */\n isInvalid?: boolean;\n /**\n * The maximum height of the text area.\n */\n maxHeight?: CSSProperties['maxHeight'];\n /**\n * The minimum height of the text area.\n */\n minHeight?: CSSProperties['minHeight'];\n /**\n * Function that is executed when the text area loses focus.\n */\n onBlur?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the text of the text area changes.\n */\n onChange?: ChangeEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when the input field is focused\n */\n onFocus?: FocusEventHandler<HTMLTextAreaElement>;\n /**\n * Function that is executed when a letter is pressed\n */\n onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;\n /**\n * Placeholder for the text area field.\n */\n placeholder?: string | ReactElement;\n /**\n * An element that should be displayed on the right side of the Input.\n */\n rightElement?: ReactElement;\n /**\n * Value if the text area should be controlled.\n */\n value?: string;\n /**\n * Provide custom colors to the TextArea Component\n */\n colors?: TextAreaColors;\n /**\n * Enables keyboard-only focus highlighting.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n};\n\nconst TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(\n (\n {\n isDisabled,\n isInvalid,\n placeholder,\n value,\n onChange,\n onFocus,\n onKeyDown,\n rightElement,\n onBlur,\n maxHeight = '120px',\n minHeight = '41px',\n colors,\n shouldEnableKeyboardHighlighting,\n },\n ref,\n ) => {\n 'use memo';\n\n const [isOverflowing, setIsOverflowing] = useState(false);\n\n const areaProvider = useContext(AreaContext);\n const theme = useTheme() as Theme;\n\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n\n useCursorRepaint(textareaRef);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const shouldShowBorder = rightElement?.props?.style?.backgroundColor === undefined;\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n const shouldShowKeyboardHighlighting = useKeyboardFocusHighlighting(\n shouldEnableKeyboardHighlighting && !isDisabled,\n );\n useFocusRingPortal(textareaRef, { isEnabled: shouldShowKeyboardHighlighting });\n\n const adjustTextareaHeight = useCallback(() => {\n if (textareaRef.current) {\n textareaRef.current.style.height = 'auto';\n textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;\n\n setIsOverflowing(\n textareaRef.current.scrollHeight > parseInt(maxHeight.toString(), 10),\n );\n }\n }, [maxHeight]);\n\n useImperativeHandle(ref, () => textareaRef.current as HTMLTextAreaElement);\n\n /**\n * This hook calculates the height of the TextArea after the displayValue is changed and the content is inside the \"textareaRef\".\n * To maintain the functionality while clearing the input, the length need to be greater than -1.\n */\n useEffect(() => {\n if (typeof value === 'string' && value.length > -1) {\n adjustTextareaHeight();\n }\n }, [adjustTextareaHeight, value]);\n\n const hasValue = value !== undefined && value.length > 0;\n\n const labelPosition = useMemo(\n () =>\n hasValue\n ? {\n bottom: '2px',\n right: '2px',\n }\n : {\n top: '12px',\n left: '10px',\n },\n [hasValue],\n );\n\n return useMemo(\n () => (\n <StyledTextArea $isDisabled={isDisabled}>\n <StyledTextAreaContentWrapper\n $isInvalid={isInvalid}\n $shouldChangeColor={shouldChangeColor}\n $backgroundColor={colors?.backgroundColor}\n $borderColor={colors?.borderColor}\n data-should-show-keyboard-highlighting={shouldShowKeyboardHighlighting}\n >\n <StyledTextAreaContent>\n <StyledTextAreaInput\n className=\"chayns-scrollbar\"\n disabled={isDisabled}\n $isInvalid={isInvalid}\n ref={textareaRef}\n value={value}\n onBlur={onBlur}\n onChange={onChange}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n $maxHeight={maxHeight}\n $minHeight={minHeight}\n $isOverflowing={isOverflowing}\n rows={1}\n />\n <StyledTextAreaLabelWrapper\n animate={{\n fontSize: hasValue ? '9px' : `${Number(theme.fontSize)}px`,\n }}\n initial={false}\n style={labelPosition}\n transition={{ type: 'tween', duration: 0.1 }}\n >\n <StyledTextAreaLabel $isInvalid={isInvalid}>\n {placeholder}\n </StyledTextAreaLabel>\n </StyledTextAreaLabelWrapper>\n </StyledTextAreaContent>\n {rightElement && shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>\n {rightElement}\n </StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextAreaContentWrapper>\n {rightElement && !shouldShowBorder && (\n <StyledInputRightElement $isInline>\n <StyledRightElementWrapper>{rightElement}</StyledRightElementWrapper>\n </StyledInputRightElement>\n )}\n </StyledTextArea>\n ),\n [\n isDisabled,\n isInvalid,\n shouldChangeColor,\n shouldShowKeyboardHighlighting,\n colors?.backgroundColor,\n colors?.borderColor,\n value,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n maxHeight,\n minHeight,\n isOverflowing,\n hasValue,\n theme.fontSize,\n labelPosition,\n placeholder,\n rightElement,\n shouldShowBorder,\n ],\n );\n },\n);\n\nTextArea.displayName = 'TextArea';\n\nexport default TextArea;\n"],"mappings":";AAAA,OAAOA,KAAK,IAIRC,UAAU,EAGVC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,WAAW,QAAQ,sCAAsC;AAElE,SAASC,uBAAuB,QAAQ,uBAAuB;AAC/D,SACIC,yBAAyB,EACzBC,cAAc,EACdC,qBAAqB,EACrBC,4BAA4B,EAC5BC,mBAAmB,EACnBC,mBAAmB,EACnBC,0BAA0B,QACvB,mBAAmB;AAC1B,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,kBAAkB,QAAQ,gCAAgC;AACnE,SAASC,4BAA4B,QAAQ,0CAA0C;AA8DvF,MAAMC,QAAQ,gBAAGrB,UAAU,CACvB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AA,CAAA+E,aAAA,CAACnE,yBAAyB,QACrBsB,YACsB,CAEnC,CAC0B,CAAC,EAC9BA,YAAiC,IAAjC,CAAiBc,gBAIjB,iBAJAhD,KAAA,CAAA+E,aAAA,CACIpE,uBAAuB;MAAC+E,SAAS,EAAT;IAAS,gBAC9B1F,KAAA,CAAA+E,aAAA,CAACnE,yBAAyB,QAAEsB,YAAwC,CAE5E,CACY,CACnB,EAuBL,CAAC;IAAAT,CAAA,OAAAe,MAAA,EAAAW,eAAA;IAAA1B,CAAA,OAAAe,MAAA,EAAAqC,WAAA;IAAApD,CAAA,OAAA4C,QAAA;IAAA5C,CAAA,OAAAE,UAAA;IAAAF,CAAA,OAAAG,SAAA;IAAAH,CAAA,OAAAkB,aAAA;IAAAlB,CAAA,OAAAkD,aAAA;IAAAlD,CAAA,OAAAW,SAAA;IAAAX,CAAA,OAAAa,SAAA;IAAAb,CAAA,OAAAU,MAAA;IAAAV,CAAA,OAAAM,QAAA;IAAAN,CAAA,OAAAO,OAAA;IAAAP,CAAA,OAAAQ,SAAA;IAAAR,CAAA,OAAAI,WAAA;IAAAJ,CAAA,OAAAS,YAAA;IAAAT,CAAA,OAAA2B,iBAAA;IAAA3B,CAAA,OAAAuB,gBAAA;IAAAvB,CAAA,OAAA4B,8BAAA;IAAA5B,CAAA,OAAAqB,KAAA,CAAAgC,QAAA;IAAArD,CAAA,OAAAK,KAAA;IAAAL,CAAA,OAAAmD,EAAA;EAAA;IAAAA,EAAA,GAAAnD,CAAA;EAAA;EAAA,OA5EMmD,EA4EN;AAAA,CAET,CAAC;AAEDtD,QAAQ,CAACqE,WAAW,GAAG,UAAU;AAEjC,eAAerE,QAAQ","ignoreList":[]}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
+
import type { ContextMenuItem } from '../context-menu/ContextMenu.types';
|
|
2
3
|
export interface IFileItem {
|
|
3
4
|
id: string;
|
|
4
5
|
name: string;
|
|
5
6
|
size?: number;
|
|
6
7
|
mimeType: string;
|
|
7
8
|
source?: string | File;
|
|
9
|
+
/**
|
|
10
|
+
* Additional context menu actions, appended after the built-in download and remove actions.
|
|
11
|
+
* Use keys other than `download` and `remove` when those built-in actions are enabled.
|
|
12
|
+
*/
|
|
13
|
+
contextMenuItems?: ContextMenuItem[];
|
|
8
14
|
}
|
|
9
15
|
export type FileListProps = {
|
|
10
16
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.64",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"publishConfig": {
|
|
94
94
|
"access": "public"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "dc5770e8b729b767a988f81ac5174408d31e425d"
|
|
97
97
|
}
|