@rh-support/components 2.5.7 → 2.5.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownEditor.d.ts","sourceRoot":"","sources":["../../../src/MarkdownEditor/MarkdownEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAwB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"MarkdownEditor.d.ts","sourceRoot":"","sources":["../../../src/MarkdownEditor/MarkdownEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAwB,MAAM,qBAAqB,CAAC;AA+B7E,OAAO,KAAK,EAAE,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;AAMtE,oBAAY,UAAU;IAClB,KAAK,cAAc;IACnB,QAAQ,aAAa;CACxB;AAED,UAAU,kBAAkB;IACxB,yBAAyB,EAAE,OAAO,CAAC;IACnC,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;IAClC,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACnD,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACnD,gBAAgB,EAAE,CAAC,IAAI,KAAA,KAAK,IAAI,CAAC;IACjC,eAAe,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IAChD,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC;IAC/B,eAAe,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,S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
19
19
|
import LinkIcon from '@patternfly/react-icons/dist/js/icons/link-icon';
|
|
20
20
|
import ListUlIcon from '@patternfly/react-icons/dist/js/icons/list-ul-icon';
|
|
21
21
|
import QuoteRightIcon from '@patternfly/react-icons/dist/js/icons/quote-right-icon';
|
|
22
|
-
import TrashIcon from '@patternfly/react-icons/dist/js/icons/trash-icon';
|
|
23
22
|
import { emojiPattern, haltEvent, isEmojiPattern, isImageFile } from '@rh-support/utils';
|
|
24
23
|
import cx from 'classnames';
|
|
25
24
|
import DOMPurify from 'dompurify';
|
|
@@ -59,18 +58,21 @@ export const validateFile = (file) => {
|
|
|
59
58
|
// Check file type
|
|
60
59
|
if (!ALLOWED_FILE_TYPES.includes(file.fileType)) {
|
|
61
60
|
// ToastNotification.addDangerMessage(t('Invalid file type, Only JPEG, PNG, GIF files are allowed.'));
|
|
62
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
isValid: false,
|
|
63
|
+
errorMsg: 'Invalid file type, Only JPEG, PNG, GIF files are allowed inside Markdown Editor',
|
|
64
|
+
};
|
|
63
65
|
}
|
|
64
66
|
// Check file size
|
|
65
67
|
if (file.sizeKB > MAX_FILE_SIZE) {
|
|
66
68
|
// ToastNotification.addDangerMessage(t('File too large, File size must be less than 2MB'));
|
|
67
|
-
return { isValid: false, errorMsg: 'File too large, File size must be less than 2MB' };
|
|
69
|
+
return { isValid: false, errorMsg: 'File too large, File size must be less than 2MB inside Markdown Editor' };
|
|
68
70
|
}
|
|
69
71
|
return { isValid: true, errorMsg: '' };
|
|
70
72
|
};
|
|
71
73
|
function MarkdownEditor(props) {
|
|
72
74
|
const { t } = useTranslation();
|
|
73
|
-
const { hidePreviewText, showPreviewText, mdPlaceholder, plainTextPlaceholder, textAreaClassName, bindTextArea, markedownOptions, allowEmoji, hideHeadingOptions, rows, showMarkdownPlainTextToggle, editorMode, className, charLimit, minCharsForCounter, id, value, onCommentExceedCharsLimit, fileSelectorProps: { onClipboardPaste,
|
|
75
|
+
const { hidePreviewText, showPreviewText, mdPlaceholder, plainTextPlaceholder, textAreaClassName, bindTextArea, markedownOptions, allowEmoji, hideHeadingOptions, rows, showMarkdownPlainTextToggle, editorMode, className, charLimit, minCharsForCounter, id, value, onCommentExceedCharsLimit, fileSelectorProps: { onClipboardPaste, onFileSelect, isSupportedFile, showFileSelectorInToolbar = false, isUploadingFile = false, filesList = [], attachFileBtn, } } = props, textAreaProps = __rest(props, ["hidePreviewText", "showPreviewText", "mdPlaceholder", "plainTextPlaceholder", "textAreaClassName", "bindTextArea", "markedownOptions", "allowEmoji", "hideHeadingOptions", "rows", "showMarkdownPlainTextToggle", "editorMode", "className", "charLimit", "minCharsForCounter", "id", "value", "onCommentExceedCharsLimit", "fileSelectorProps"]);
|
|
74
76
|
const [isPreview, setIsPreview] = useState(false);
|
|
75
77
|
const [mdValue, setMdValue] = useState(props.value || '');
|
|
76
78
|
const previousFileList = usePrevious(filesList);
|
|
@@ -80,6 +82,7 @@ function MarkdownEditor(props) {
|
|
|
80
82
|
// for access inside event handlers
|
|
81
83
|
const isPlainModeEnabledRef = useRef(isPlainModeEnabled);
|
|
82
84
|
const [isFileSelectorOpen, setIsFileSelectorOpen] = useState(false);
|
|
85
|
+
const [isFileFromOnPaste, setIsFileFromOnPaste] = useState(false);
|
|
83
86
|
const onFileSelectLocal = () => {
|
|
84
87
|
setIsFileSelectorOpen((open) => !open);
|
|
85
88
|
};
|
|
@@ -87,11 +90,17 @@ function MarkdownEditor(props) {
|
|
|
87
90
|
setIsFileSelectorOpen(isOpen);
|
|
88
91
|
};
|
|
89
92
|
useEffect(() => {
|
|
93
|
+
if (isFileFromOnPaste) {
|
|
94
|
+
onFileInsert(filesList[0]);
|
|
95
|
+
}
|
|
90
96
|
if ((previousFileList || []).length < (filesList || []).length && isUploadingFile) {
|
|
91
97
|
onFileInsert(filesList[0]);
|
|
92
98
|
}
|
|
99
|
+
return () => {
|
|
100
|
+
setIsFileFromOnPaste(false);
|
|
101
|
+
};
|
|
93
102
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
-
}, [filesList]);
|
|
103
|
+
}, [filesList.length]);
|
|
95
104
|
const onFileInsert = (file) => {
|
|
96
105
|
const { isValid, errorMsg } = validateFile(file);
|
|
97
106
|
if (!isValid) {
|
|
@@ -126,6 +135,7 @@ function MarkdownEditor(props) {
|
|
|
126
135
|
const files = [file];
|
|
127
136
|
event.preventDefault();
|
|
128
137
|
onClipboardPaste(files);
|
|
138
|
+
setIsFileFromOnPaste(true);
|
|
129
139
|
};
|
|
130
140
|
// To handle dropped images
|
|
131
141
|
const onDrop = (event) => {
|
|
@@ -137,23 +147,19 @@ function MarkdownEditor(props) {
|
|
|
137
147
|
const files = [file];
|
|
138
148
|
event.preventDefault();
|
|
139
149
|
onClipboardPaste(files);
|
|
150
|
+
setIsFileFromOnPaste(true);
|
|
140
151
|
};
|
|
141
152
|
const getFileSelectorList = (isMobile = false) => {
|
|
142
|
-
const filesAsDropdownItems = filesList
|
|
153
|
+
const filesAsDropdownItems = filesList
|
|
154
|
+
.filter((file) => validateFile(file).isValid)
|
|
155
|
+
.map((file) => {
|
|
143
156
|
return (React.createElement(React.Fragment, null,
|
|
144
157
|
React.createElement(DropdownItem, { key: file.id, onClick: () => {
|
|
145
158
|
onFileInsert(file);
|
|
146
159
|
} },
|
|
147
160
|
React.createElement(Flex, { flexWrap: { default: 'nowrap' } },
|
|
148
161
|
React.createElement(FlexItem, null,
|
|
149
|
-
React.createElement(Text, { component: TextVariants.small }, file.fileName))
|
|
150
|
-
onFileDelete && (React.createElement(FlexItem, { className: "pf-v5-u-ml-auto" },
|
|
151
|
-
React.createElement(Button, { variant: ButtonVariant.plain, onClick: (event) => {
|
|
152
|
-
onFileSelectToggle(false);
|
|
153
|
-
onFileDelete(file);
|
|
154
|
-
event.stopPropagation();
|
|
155
|
-
} },
|
|
156
|
-
React.createElement(TrashIcon, { color: "#c9190b" }))))))));
|
|
162
|
+
React.createElement(Text, { component: TextVariants.small }, file.fileName))))));
|
|
157
163
|
});
|
|
158
164
|
return isMobile
|
|
159
165
|
? [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/components",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.9",
|
|
4
4
|
"description": "Contains all reusabel components for support app",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"defaults and supports es6-module",
|
|
107
107
|
"maintained node versions"
|
|
108
108
|
],
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "1eeedd5135ac6a9b24533268c5a260d164a3811e"
|
|
110
110
|
}
|