This is an automated email from the ASF dual-hosted git repository.
robin0716 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/answer-plugins.git
The following commit(s) were added to refs/heads/main by this push:
new 27ad6e9 fix(editor-stacks/Component): add MIME type conversion for
file extensions and hide specific menu buttons
27ad6e9 is described below
commit 27ad6e9d07342de4b98cb996bbce68341e25bc58
Author: robin <[email protected]>
AuthorDate: Wed Dec 31 15:59:33 2025 +0800
fix(editor-stacks/Component): add MIME type conversion for file extensions
and hide specific menu buttons
---
editor-stacks/Component.tsx | 53 ++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 48 insertions(+), 5 deletions(-)
diff --git a/editor-stacks/Component.tsx b/editor-stacks/Component.tsx
index 880ce66..85d1d63 100644
--- a/editor-stacks/Component.tsx
+++ b/editor-stacks/Component.tsx
@@ -117,6 +117,37 @@ const Component: FC<EditorProps> = ({
let editorInstance: StacksEditor | null = null;
try {
+ // Convert file extensions to MIME types for editor-stacks validation
+ const extensionToMimeType = (ext: string): string => {
+ const extension = ext.toLowerCase().replace(/^\./, '');
+ const mimeTypeMap: Record<string, string> = {
+ jpg: 'image/jpeg',
+ jpeg: 'image/jpeg',
+ png: 'image/png',
+ gif: 'image/gif',
+ webp: 'image/webp',
+ svg: 'image/svg+xml',
+ bmp: 'image/bmp',
+ ico: 'image/x-icon',
+ pdf: 'application/pdf',
+ doc: 'application/msword',
+ docx:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
+ xls: 'application/vnd.ms-excel',
+ xlsx:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ ppt: 'application/vnd.ms-powerpoint',
+ pptx:
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
+ zip: 'application/zip',
+ rar: 'application/x-rar-compressed',
+ txt: 'text/plain',
+ csv: 'text/csv',
+ };
+ return mimeTypeMap[extension] || ext;
+ };
+
+ const allowedFileTypes = uploadConfig?.allowedExtensions
+ ? uploadConfig.allowedExtensions.map(extensionToMimeType)
+ : undefined;
+
editorInstance = new StacksEditor(containerRef.current, value || '', {
placeholderText: placeholder || t('placeholder', ''),
parserFeatures: {
@@ -127,7 +158,7 @@ const Component: FC<EditorProps> = ({
? {
handler: imageUploadHandler,
sizeLimitMib: uploadConfig?.maxImageSizeMiB,
- acceptedFileTypes: uploadConfig?.allowedExtensions,
+ acceptedFileTypes: allowedFileTypes,
}
: undefined,
editorHelpLink: 'https://stackoverflow.com/editing-help',
@@ -212,10 +243,22 @@ const Component: FC<EditorProps> = ({
}, [value]);
return (
- <div
- className="editor-stacks-wrapper editor-stacks-scope"
- ref={containerRef}
- />
+ <>
+ <style>{`
+ /* Hide specific menu buttons */
+ .editor-stacks-wrapper [data-key="tag-btn"],
+ .editor-stacks-wrapper [data-key="meta-tag-btn"],
+ .editor-stacks-wrapper [data-key="spoiler-btn"],
+ .editor-stacks-wrapper [data-key="subscript-btn"],
+ .editor-stacks-wrapper [data-key="superscript-btn"] {
+ display: none !important;
+ }
+ `}</style>
+ <div
+ className="editor-stacks-wrapper editor-stacks-scope"
+ ref={containerRef}
+ />
+ </>
);
};