@@ -84,6 +84,31 @@ export default function EditorTabs({
8484
8585 const tabRef = useRef ( ) ;
8686 const imageRef = useRef ( ) ;
87+ const DnDRef = useRef ( ) ;
88+
89+ async function handleDnD ( e , index ) {
90+ e . preventDefault ( )
91+
92+ if ( e . dataTransfer && e . dataTransfer . files . length != 0 ) {
93+ let file = e . dataTransfer . files [ 0 ]
94+
95+ if ( file . size / 1024 / 1024 > 4 ) {
96+ alert ( 'You can only upload files 4Mb in size or less.' ) ;
97+ return ;
98+
99+ }
100+
101+ let data = await file . text ( ) ;
102+ let name = file . name ;
103+
104+ let newValue = [ ...value ] ;
105+ newValue [ index ] [ 'title' ] = name ;
106+ newValue [ index ] [ 'content' ] = data ;
107+
108+ setValue ( newValue ) ;
109+ }
110+
111+ }
87112
88113
89114 function handleSetImage ( e ) {
@@ -235,7 +260,7 @@ export default function EditorTabs({
235260 < AddBoxIcon className = { styles . addImagesButtonNS } > </ AddBoxIcon >
236261 </ div > : null }
237262
238- { value [ i ] [ 'image' ] ?
263+ { value [ i ] [ 'image' ] !== 'None' && value [ i ] [ 'image' ] !== null && value [ i ] [ 'image' ] !== undefined && value [ i ] [ 'image' ] !== "" ?
239264 < div
240265 className = { styles . addImageButtonContainer }
241266 onClick = { ( ) => setShowImage ( i ) }
@@ -252,13 +277,10 @@ export default function EditorTabs({
252277 >
253278 < SettingsIcon />
254279 </ div >
255- { langDropDown ? (
280+ { langDropDown && i === currTab ? (
256281 < div className = { styles . langParent } >
257282 < Dropdown className = { styles . dropDown } autoClose >
258283 { Object . keys ( languages ) . map ( ( v , index ) => {
259- if ( i !== currTab ) {
260- return < > </ > ;
261- }
262284 return (
263285 < DropdownItem
264286 key = { v }
@@ -302,22 +324,27 @@ export default function EditorTabs({
302324 className = { "maxed" }
303325 id = { `tab-${ i } ` }
304326 >
305- < MonacoEditor
306- language = { lang [ i ] }
307- onChange = { ( _ , newVal ) => {
308- if ( newVal . length > maxCharCount ) {
309- setCharCountToast ( true ) ;
310- newVal = newVal . slice ( 0 , maxCharCount ) ;
311- }
312- let newValue = [ ...value ] ;
313- newValue [ i ] [ "content" ] = newVal ;
314- setValue ( newValue ) ;
315- return `${ newVal } ` ;
316- } }
317- value = { v . content }
318- theme = { "mystBinDark" }
319- readOnly = { ! ! id }
320- />
327+ < div
328+ onDragOver = { ( e ) => e . preventDefault ( ) }
329+ onDrop = { async ( e ) => await handleDnD ( e , i ) }
330+ >
331+ < MonacoEditor
332+ language = { lang [ i ] }
333+ onChange = { ( _ , newVal ) => {
334+ if ( newVal . length > maxCharCount ) {
335+ setCharCountToast ( true ) ;
336+ newVal = newVal . slice ( 0 , maxCharCount ) ;
337+ }
338+ let newValue = [ ...value ] ;
339+ newValue [ i ] [ "content" ] = newVal ;
340+ setValue ( newValue ) ;
341+ return `${ newVal } ` ;
342+ } }
343+ value = { v . content }
344+ theme = { "mystBinDark" }
345+ readOnly = { ! ! id }
346+ />
347+ </ div >
321348 </ div >
322349 ) ) }
323350 </ div >
0 commit comments