reiji-h 2 лет назад
Родитель
Сommit
35cab35a16
1 измененных файлов с 13 добавлено и 0 удалено
  1. 13 0
      packages/editor/src/components/playground/Playground.tsx

+ 13 - 0
packages/editor/src/components/playground/Playground.tsx

@@ -37,6 +37,17 @@ export const Playground = (): JSX.Element => {
     toast.success('Saved.', { autoClose: 2000 });
     toast.success('Saved.', { autoClose: 2000 });
   }, [codeMirrorEditor]);
   }, [codeMirrorEditor]);
 
 
+  // the upload event handler
+  const uploadHandler = useCallback((files: File[]) => {
+    files.forEach((file) => {
+
+      const insertText = `[${file.name}](/attachment/aaaabbbbccccdddd)\n`;
+      codeMirrorEditor?.insertText(insertText);
+    });
+
+  }, [codeMirrorEditor]);
+
+
   return (
   return (
     <>
     <>
       <div className="flex-expand-vert justify-content-center align-items-center bg-dark" style={{ minHeight: '83px' }}>
       <div className="flex-expand-vert justify-content-center align-items-center bg-dark" style={{ minHeight: '83px' }}>
@@ -47,6 +58,8 @@ export const Playground = (): JSX.Element => {
           <CodeMirrorEditorMain
           <CodeMirrorEditorMain
             onSave={saveHandler}
             onSave={saveHandler}
             onChange={setMarkdownToPreview}
             onChange={setMarkdownToPreview}
+            onUpload={uploadHandler}
+            indentSize={4}
           />
           />
         </div>
         </div>
         <div className="flex-expand-vert d-none d-lg-flex bg-light text-dark border-start border-dark-subtle p-3">
         <div className="flex-expand-vert d-none d-lg-flex bg-light text-dark border-start border-dark-subtle p-3">