From cfb47fa952782480937940ec20a72063e17f56ff Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Sat, 7 Aug 2021 00:06:58 +0200 Subject: [PATCH] change to css grid --- src/editor/Editor.js | 36 +- src/editor/EditorStartup.js | 82 +-- src/editor/MainMenu.js | 1 - src/editor/Rulers.js | 2 +- src/editor/components/seInput.js | 7 + src/editor/components/seSpinInput.js | 7 + .../ext-overview_window.js | 10 +- .../extensions/ext-storage/ext-storage.js | 2 +- src/editor/index.html | 6 +- src/editor/panels/BottomPanel.js | 8 +- src/editor/panels/LayersPanel.js | 4 +- src/editor/panels/LeftPanel.js | 2 +- src/editor/panels/TopPanel.js | 468 +++++++++--------- src/editor/svgedit.css | 190 +++---- src/editor/templates/editorTemplate.js | 45 +- src/editor/templates/rulersTemplate.js | 42 +- 16 files changed, 422 insertions(+), 490 deletions(-) diff --git a/src/editor/Editor.js b/src/editor/Editor.js index 2e6029f4..38a93a24 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -457,23 +457,23 @@ class Editor extends EditorStartup { */ updateCanvas(center, newCtr) { const zoom = this.svgCanvas.getZoom(); - const wArea = this.workarea; + const { workarea } = this; const cnvs = $id("svgcanvas"); - let w = parseFloat(getComputedStyle(this.workarea, null).width.replace("px", "")); let h = parseFloat(getComputedStyle(this.workarea, null).height.replace("px", "")); + let w = parseFloat(getComputedStyle(workarea, null).width.replace("px", "")); let h = parseFloat(getComputedStyle(workarea, null).height.replace("px", "")); const wOrig = w; const hOrig = h; const oldCtr = { - x: wArea.scrollLeft + wOrig / 2, - y: wArea.scrollTop + hOrig / 2 + x: workarea.scrollLeft + wOrig / 2, + y: workarea.scrollTop + hOrig / 2 }; const multi = this.configObj.curConfig.canvas_expansion; w = Math.max(wOrig, this.svgCanvas.contentW * zoom * multi); h = Math.max(hOrig, this.svgCanvas.contentH * zoom * multi); if (w === wOrig && h === hOrig) { - this.workarea.style.overflow = 'hidden'; + workarea.style.overflow = 'hidden'; } else { - this.workarea.style.overflow = 'scroll'; + workarea.style.overflow = 'scroll'; } const oldCanY = parseFloat(getComputedStyle(cnvs, null).height.replace("px", "")) / 2; @@ -508,22 +508,22 @@ class Editor extends EditorStartup { if (center) { // Go to top-left for larger documents - if (this.svgCanvas.contentW > parseFloat(getComputedStyle(wArea, null).width.replace("px", ""))) { + if (this.svgCanvas.contentW > parseFloat(getComputedStyle(workarea, null).width.replace("px", ""))) { // Top-left - this.workarea.scrollLeft = offset.x - 10; - this.workarea.scrollTop = offset.y - 10; + workarea.scrollLeft = offset.x - 10; + workarea.scrollTop = offset.y - 10; } else { // Center - wArea.scrollLeft = scrollX; - wArea.scrollTop = scrollY; + workarea.scrollLeft = scrollX; + workarea.scrollTop = scrollY; } } else { - wArea.scrollLeft = newCtr.x - wOrig / 2; - wArea.scrollTop = newCtr.y - hOrig / 2; + workarea.scrollLeft = newCtr.x - wOrig / 2; + workarea.scrollTop = newCtr.y - hOrig / 2; } if (this.configObj.curConfig.showRulers) { this.rulers.updateRulers(cnvs, zoom); - this.workarea.scroll(); + workarea.scroll(); } if (this.configObj.urldata.storagePrompt !== true && this.storagePromptState === 'ignore') { @@ -706,8 +706,7 @@ class Editor extends EditorStartup { */ zoomChanged(win, bbox, autoCenter) { const scrbar = 15; - const wArea = this.workarea; - const zInfo = this.svgCanvas.setBBoxZoom(bbox, parseFloat(getComputedStyle(wArea, null).width.replace("px", "")) - scrbar, parseFloat(getComputedStyle(wArea, null).height.replace("px", "")) - scrbar); + const zInfo = this.svgCanvas.setBBoxZoom(bbox, parseFloat(getComputedStyle(this.workarea, null).width.replace("px", "")) - scrbar, parseFloat(getComputedStyle(this.workarea, null).height.replace("px", "")) - scrbar); if (!zInfo) { return; } const zoomlevel = zInfo.zoom; const bb = zInfo.bbox; @@ -857,9 +856,10 @@ class Editor extends EditorStartup { * @returns {void} */ pasteInCenter() { + const { workarea } = this; const zoom = this.svgCanvas.getZoom(); - const x = (this.workarea.scrollLeft + parseFloat(getComputedStyle(this.workarea, null).width.replace("px", "")) / 2) / zoom - this.svgCanvas.contentW; - const y = (this.workarea.scrollTop + parseFloat(getComputedStyle(this.workarea, null).height.replace("px", "")) / 2) / zoom - this.svgCanvas.contentH; + const x = (workarea.scrollLeft + parseFloat(getComputedStyle(workarea, null).width.replace("px", "")) / 2) / zoom - this.svgCanvas.contentW; + const y = (workarea.scrollTop + parseFloat(getComputedStyle(workarea, null).height.replace("px", "")) / 2) / zoom - this.svgCanvas.contentH; this.svgCanvas.pasteElements('point', x, y); } diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index c12de021..99f9c471 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -41,7 +41,7 @@ const readySignal = () => { } }; -const { $id } = SvgCanvas; +const { $id, $qq } = SvgCanvas; /** * @@ -53,7 +53,7 @@ class EditorStartup { constructor (div) { this.extensionsAdded = false; this.messageQueue = []; - this.$svgEditor = div??$id('svg_editor'); + this.$container = div??$id('svg_editor'); } /** * Auto-run after a Promise microtask. @@ -65,43 +65,44 @@ class EditorStartup { this.storage = window.localStorage; } this.configObj.load(); - const self = this; const { i18next } = await putLocale(this.configObj.pref('lang'), this.goodLangs); this.i18next = i18next; await import(`./components/index.js`); await import(`./dialogs/index.js`); - // allow to prepare the dom without display - this.$svgEditor.style.visibility = 'hidden'; try { // add editor components to the DOM - this.$svgEditor.append(editorTemplate.content.cloneNode(true)); + this.$container.append(editorTemplate.content.cloneNode(true)); + this.$svgEditor = $qq('.svg_editor'); + // allow to prepare the dom without display + // JFH this.$svgEditor.style.visibility = 'hidden'; + this.workarea = $id('workarea'); // Image props dialog added to DOM const newSeImgPropDialog = document.createElement('se-img-prop-dialog'); newSeImgPropDialog.setAttribute('id', 'se-img-prop'); - this.$svgEditor.append(newSeImgPropDialog); + this.$container.append(newSeImgPropDialog); newSeImgPropDialog.init(this.i18next); // editor prefences dialoag added to DOM const newSeEditPrefsDialog = document.createElement('se-edit-prefs-dialog'); newSeEditPrefsDialog.setAttribute('id', 'se-edit-prefs'); - this.$svgEditor.append(newSeEditPrefsDialog); + this.$container.append(newSeEditPrefsDialog); newSeEditPrefsDialog.init(this.i18next); // canvas menu added to DOM const dialogBox = document.createElement('se-cmenu_canvas-dialog'); dialogBox.setAttribute('id', 'se-cmenu_canvas'); - this.$svgEditor.append(dialogBox); + this.$container.append(dialogBox); dialogBox.init(this.i18next); // alertDialog added to DOM const alertBox = document.createElement('se-alert-dialog'); alertBox.setAttribute('id', 'se-alert-dialog'); - this.$svgEditor.append(alertBox); + this.$container.append(alertBox); // promptDialog added to DOM const promptBox = document.createElement('se-prompt-dialog'); promptBox.setAttribute('id', 'se-prompt-dialog'); - this.$svgEditor.append(promptBox); + this.$container.append(promptBox); // Export dialog added to DOM const exportDialog = document.createElement('se-export-dialog'); exportDialog.setAttribute('id', 'se-export-dialog'); - this.$svgEditor.append(exportDialog); + this.$container.append(exportDialog); exportDialog.init(this.i18next); } catch (err) { console.error(err); @@ -123,8 +124,7 @@ class EditorStartup { this.mainMenu.init(); const { undoMgr } = this.svgCanvas; - this.workarea = document.getElementById('workarea'); - this.canvMenu = document.getElementById('se-cmenu_canvas'); + this.canvMenu = $id('se-cmenu_canvas'); this.exportWindow = null; this.defaultImageURL = this.configObj.curConfig.imgPath + 'logo.svg'; const zoomInIcon = 'crosshair'; @@ -218,9 +218,9 @@ class EditorStartup { // fired when user wants to move elements to another layer let promptMoveLayerOnce = false; - $id('selLayerNames').addEventListener('change', function(evt) { + $id('selLayerNames').addEventListener('change', (evt) => { const destLayer = evt.currentTarget.options[evt.currentTarget.selectedIndex].value; - const confirmStr = self.i18next.t('notification.QmoveElemsToLayer').replace('%s', destLayer); + const confirmStr = this.i18next.t('notification.QmoveElemsToLayer').replace('%s', destLayer); /** * @param {boolean} ok * @returns {void} @@ -228,9 +228,9 @@ class EditorStartup { const moveToLayer = (ok) => { if (!ok) { return; } promptMoveLayerOnce = true; - self.svgCanvas.moveSelectedToLayer(destLayer); - self.svgCanvas.clearSelection(); - self.layersPanel.populateLayers(); + this.svgCanvas.moveSelectedToLayer(destLayer); + this.svgCanvas.clearSelection(); + this.layersPanel.populateLayers(); }; if (destLayer) { if (promptMoveLayerOnce) { @@ -244,12 +244,12 @@ class EditorStartup { } } }); - $id('tool_font_family').addEventListener('change', function(evt) { - self.svgCanvas.setFontFamily(evt.detail.value); + $id('tool_font_family').addEventListener('change', (evt) => { + this.svgCanvas.setFontFamily(evt.detail.value); }); - $id('seg_type').addEventListener('change', function(evt) { - self.svgCanvas.setSegType(evt.currentTarget.value); + $id('seg_type').addEventListener('change', (evt) => { + this.svgCanvas.setSegType(evt.currentTarget.value); }); function addListenerMulti(element, eventNames, listener) { @@ -259,35 +259,33 @@ class EditorStartup { } } - addListenerMulti($id('text'), 'keyup input', function(evt){ - self.svgCanvas.setTextContent(evt.currentTarget.value); + addListenerMulti($id('text'), 'keyup input', (evt) => { + this.svgCanvas.setTextContent(evt.currentTarget.value); }); - $id('image_url').addEventListener('change', function(evt) { - self.setImageURL(evt.currentTarget.value); + $id('image_url').addEventListener('change', (evt) => { + this.setImageURL(evt.currentTarget.value); }); - $id('link_url').addEventListener('change', function(evt) { + $id('link_url').addEventListener('change', (evt) => { if (evt.currentTarget.value.length) { - self.svgCanvas.setLinkURL(evt.currentTarget.value); + this.svgCanvas.setLinkURL(evt.currentTarget.value); } else { - self.svgCanvas.removeHyperlink(); + this.svgCanvas.removeHyperlink(); } }); - $id('g_title').addEventListener('change', function(evt) { - self.svgCanvas.setGroupTitle(evt.currentTarget.value); + $id('g_title').addEventListener('change', (evt) => { + this.svgCanvas.setGroupTitle(evt.currentTarget.value); }); - const wArea = this.workarea; - let lastX = null; let lastY = null; let panning = false; let keypan = false; - $id('svgcanvas').addEventListener('mouseup', function(evt) { + $id('svgcanvas').addEventListener('mouseup', (evt) => { if (panning === false) { return true; } - wArea.scrollLeft -= (evt.clientX - lastX); - wArea.scrollTop -= (evt.clientY - lastY); + this.workarea.scrollLeft -= (evt.clientX - lastX); + this.workarea.scrollTop -= (evt.clientY - lastY); lastX = evt.clientX; lastY = evt.clientY; @@ -298,8 +296,8 @@ class EditorStartup { $id('svgcanvas').addEventListener('mousemove', function(evt) { if (panning === false) { return true; } - wArea.scrollLeft -= (evt.clientX - lastX); - wArea.scrollTop -= (evt.clientY - lastY); + this.workarea.scrollLeft -= (evt.clientX - lastX); + this.workarea.scrollTop -= (evt.clientY - lastY); lastX = evt.clientX; lastY = evt.clientY; @@ -535,7 +533,11 @@ class EditorStartup { $id('tool_wireframe').click(); } - $id('rulers').style.display = (this.configObj.curConfig.showRulers) ? 'block' : 'none'; + if (this.configObj.curConfig.showRulers) { + $id('rulers').style.removeProperty('display'); + } else { + $id('rulers').style.display = 'none'; + } if (this.configObj.curConfig.showRulers) { $editDialog.setAttribute('showrulers', true); diff --git a/src/editor/MainMenu.js b/src/editor/MainMenu.js index 7d16be70..17db34cd 100644 --- a/src/editor/MainMenu.js +++ b/src/editor/MainMenu.js @@ -306,7 +306,6 @@ class MainMenu { // eslint-disable-next-line no-unsanitized/property template.innerHTML = ` - diff --git a/src/editor/Rulers.js b/src/editor/Rulers.js index c263214f..e1a49c23 100644 --- a/src/editor/Rulers.js +++ b/src/editor/Rulers.js @@ -18,7 +18,7 @@ class Rulers { this.svgCanvas = editor.svgCanvas; this.editor = editor; // add rulers component to the DOM - this.editor.$svgEditor.append(rulersTemplate.content.cloneNode(true)); + this.editor.workarea.append(rulersTemplate.content.cloneNode(true)); } /** * @type {Module} diff --git a/src/editor/components/seInput.js b/src/editor/components/seInput.js index a4cd4d8f..708bc413 100644 --- a/src/editor/components/seInput.js +++ b/src/editor/components/seInput.js @@ -3,6 +3,11 @@ import 'elix/define/Input.js'; const template = document.createElement('template'); template.innerHTML = ` +
icon label +
`; /** diff --git a/src/editor/components/seSpinInput.js b/src/editor/components/seSpinInput.js index b80ffcb3..67fb5657 100644 --- a/src/editor/components/seSpinInput.js +++ b/src/editor/components/seSpinInput.js @@ -3,6 +3,11 @@ import '../dialogs/se-elix/define/NumberSpinBox.js'; const template = document.createElement('template'); template.innerHTML = ` +
icon label +
`; /** diff --git a/src/editor/extensions/ext-overview_window/ext-overview_window.js b/src/editor/extensions/ext-overview_window/ext-overview_window.js index 582b7963..b045b01a 100644 --- a/src/editor/extensions/ext-overview_window/ext-overview_window.js +++ b/src/editor/extensions/ext-overview_window/ext-overview_window.js @@ -51,11 +51,11 @@ export default { // Define dynamic animation of the view box. const updateViewBox = function () { - const warea = document.getElementById('workarea'); - const portHeight = parseFloat(getComputedStyle(warea, null).height.replace("px", "")); - const portWidth = parseFloat(getComputedStyle(warea, null).width.replace("px", "")); - const portX = warea.scrollLeft; - const portY = warea.scrollTop; + const { workarea } = svgEditor; + const portHeight = parseFloat(getComputedStyle(workarea, null).height.replace("px", "")); + const portWidth = parseFloat(getComputedStyle(workarea, null).width.replace("px", "")); + const portX = workarea.scrollLeft; + const portY = workarea.scrollTop; const windowWidth = parseFloat(getComputedStyle($id("svgcanvas"), null).width.replace("px", "")); const windowHeight = parseFloat(getComputedStyle($id("svgcanvas"), null).height.replace("px", "")); const overviewWidth = parseFloat(getComputedStyle($id("overviewMiniView"), null).width.replace("px", "")); diff --git a/src/editor/extensions/ext-storage/ext-storage.js b/src/editor/extensions/ext-storage/ext-storage.js index 739acb68..dc3136d0 100644 --- a/src/editor/extensions/ext-storage/ext-storage.js +++ b/src/editor/extensions/ext-storage/ext-storage.js @@ -82,7 +82,7 @@ export default { // storageDialog added to DOM const storageBox = document.createElement('se-storage-dialog'); storageBox.setAttribute('id', 'se-storage-dialog'); - svgEditor.$svgEditor.append(storageBox); + svgEditor.$container.append(storageBox); storageBox.init(svgEditor.i18next); // manage the change in the storageDialog diff --git a/src/editor/index.html b/src/editor/index.html index 698a9096..9c2d1b8f 100644 --- a/src/editor/index.html +++ b/src/editor/index.html @@ -25,7 +25,7 @@