|
135 | 135 | background: var(--supercode-modal-secondary); |
136 | 136 | color: var(--supercode-modal-primary); |
137 | 137 | } |
138 | | - ` |
| 138 | + `; |
| 139 | + |
| 140 | + const CLOSE_ICON_FALLBACK = `<svg width="24" height="24"><path d="M17.3 8.2 13.4 12l3.9 3.8a1 1 0 0 1-1.5 1.5L12 13.4l-3.8 3.9a1 1 0 0 1-1.5-1.5l3.9-3.8-3.9-3.8a1 1 0 0 1 1.5-1.5l3.8 3.9 3.8-3.9a1 1 0 0 1 1.5 1.5Z" fill-rule="evenodd"></path></svg>` |
| 141 | + const CODE_ICON_FALLBACK = `<svg width="24" height="24" focusable="false"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7ZM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7Z"></path></g></svg>` |
139 | 142 |
|
140 | 143 | let modal = null; |
141 | 144 |
|
|
197 | 200 | fallbackModal: false, // enabled in cases like inline, or versions where `CustomView` is not supported. |
198 | 201 | modalPrimaryColor: '#ffffff', |
199 | 202 | modalSecondaryColor: '#222f3e', |
200 | | - dark: false |
| 203 | + dark: false, |
| 204 | + debug: true |
| 205 | + } |
| 206 | + |
| 207 | + const debug = (msg) => { |
| 208 | + if(Config.debug){ |
| 209 | + console.warn(`${msg} \n\nUse debug:false option to disable this warning`); |
| 210 | + } |
201 | 211 | } |
202 | 212 |
|
203 | 213 | // Get Configurations |
|
231 | 241 | case 'shortcut': |
232 | 242 | case 'fallbackModal': |
233 | 243 | case 'dark': |
| 244 | + case 'debug': |
234 | 245 | if (typeof value === "boolean") { |
235 | 246 | Config[key] = value; |
236 | 247 | } |
|
250 | 261 | } |
251 | 262 |
|
252 | 263 | // Set plugin icon |
253 | | - Config.icon = editor.ui.registry.getAll().icons[Config.iconName]; |
| 264 | + Config.icon = editor.ui.registry.getAll?.().icons?.[Config.iconName]; |
254 | 265 | if (!Config.icon) { |
255 | | - throw new Error("Supercode Icon name is invalid"); |
| 266 | + Config.icon = CODE_ICON_FALLBACK; |
| 267 | + debug("Supercode Icon name is invalid or you are using older versions of tinyMCE. The icon is set to default fallback code icon."); |
256 | 268 | } |
257 | 269 |
|
258 | 270 | // Detect and set fallback model if its required |
|
310 | 322 | // If menu-bar exists utilize the space to show Title "Source Code Editor" |
311 | 323 | const menubar = newHeader.querySelector('.tox-menubar'); |
312 | 324 | if(menubar){ |
313 | | - menubar.innerHTML = `<b style='font-size: 14px; font-weight: bold; padding: 9px;'>Source Code Editor</b>` |
| 325 | + menubar.innerHTML = `<b style='font-size: 14px; font-weight: bold; padding: 11px 9px;'>Source Code Editor</b>` |
314 | 326 | } |
315 | 327 |
|
316 | | - // hide all the buttons except supercode button, attach event listener |
317 | | - let isOverflow = true; |
| 328 | + // disable all the buttons except supercode button, attach event listener |
| 329 | + let overflowButton = null, isPluginButton = false; |
318 | 330 | newHeader.querySelectorAll('.tox-tbtn, .tox-split-button').forEach((btn) => { |
319 | 331 | if(btn.getAttribute('data-mce-name') != 'supercode'){ |
320 | 332 | // remove overflow button to make space for code button |
321 | 333 | if(btn.getAttribute('data-mce-name') === 'overflow-button'){ |
322 | | - btn.style.display = 'none'; |
323 | | - btn.removeAttribute('data-mce-name') |
324 | | - return; |
325 | | - } |
| 334 | + overflowButton = btn; |
| 335 | + } |
326 | 336 | btn.classList.remove('tox-tbtn--enabled'); |
327 | 337 | btn.classList.add('tox-tbtn--disabled'); |
328 | 338 | btn.removeAttribute('data-mce-name'); |
329 | 339 | } |
330 | 340 | else{ |
331 | | - isOverflow = false; |
| 341 | + isPluginButton = true; |
332 | 342 | btn.setAttribute('data-mce-name', 'supercode-toggle') |
333 | 343 | btn.classList.add('tox-tbtn--enabled'); |
334 | 344 | btn.onclick = onSaveHandler; |
335 | 345 | } |
336 | 346 | }); |
337 | 347 |
|
338 | | - // in case of overflow, button is inside a floating toolbar |
339 | | - if(isOverflow){ |
340 | | - const div = document.createElement('div') |
341 | | - div.classList = 'tox-toolbar__group'; |
342 | | - div.style.position = 'absolute'; |
343 | | - div.style.right = 0; |
344 | | - div.style.height = '100%'; |
345 | | - const button = document.createElement('button'); |
346 | | - button.classList = 'tox-tbtn tox-tbtn--enabled'; |
347 | | - button.innerHTML = `<span class="tox-icon tox-tbtn__icon-wrap">${Config.icon}</span>`; |
348 | | - button.onclick = onSaveHandler; |
349 | | - div.append(button); |
350 | | - newHeader.append(div); |
| 348 | + // in case of overflow, replace the overflow button with code button |
| 349 | + if(!isPluginButton && overflowButton){ |
| 350 | + overflowButton.classList = 'tox-tbtn tox-tbtn--enabled'; |
| 351 | + overflowButton.innerHTML = `<span class="tox-icon tox-tbtn__icon-wrap">${Config.icon}</span>`; |
| 352 | + overflowButton.onclick = onSaveHandler; |
351 | 353 | } |
352 | 354 | view.innerHTML = ''; // delete any existing header |
353 | 355 | view.append(newHeader); |
|
410 | 412 | if(Config.dark){ |
411 | 413 | document.body.style.setProperty('--supercode-modal-border', 'rgba(255, 255, 255, 0.1)'); |
412 | 414 | } |
413 | | - document.querySelector('#supercode-close-btn').innerHTML = editor.ui.registry.getAll().icons['close'] |
| 415 | + |
| 416 | + modal.element.querySelector('#supercode-close-btn').innerHTML = editor.ui.registry.getAll?.().icons?.['close'] ?? CLOSE_ICON_FALLBACK; |
414 | 417 |
|
415 | 418 | modal.element.style.display = 'flex'; |
416 | 419 | setTimeout(() => { |
|
429 | 432 | setTimeout(() => { |
430 | 433 | modal.element.style.display = 'none'; |
431 | 434 | }, 10) |
432 | | - } |
| 435 | + }; |
433 | 436 |
|
434 | 437 | const onSaveHandler = () => { |
435 | 438 | editor.focus(); |
|
500 | 503 | if(isScreenSizeChanged){ |
501 | 504 | setHeader(codeView.querySelector('.supercode-header'), originalHeader); |
502 | 505 | codeView.querySelector('.supercode-body ').style.width = editorWidth+'px'; |
| 506 | + aceEditor.resize(); |
503 | 507 | } |
504 | 508 |
|
505 | 509 | // Only on First time plugin opened => mount view |
|
0 commit comments