diff --git a/src/editor/Editor.js b/src/editor/Editor.js index ae6aebf8..2b3887e4 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -337,34 +337,6 @@ class Editor extends EditorStartup { }); } - /** - * @param {boolean} editmode - * @param {module:svgcanvas.SvgCanvas#event:selected} elems - * @returns {void} - */ - togglePathEditMode(editMode, elems) { - const { imgPath } = this.configObj.curConfig; - if (editMode) { - $id('path_node_panel').style.removeProperty('display'); - } else { - $id('path_node_panel').style.display = 'none'; - } - if (editMode) { - // Change select icon - $id('tool_path').pressed = false; - $id('tool_select').pressed = true; - $id('tool_select').setAttribute('src', `${imgPath}/select_node.svg`); - this.multiselected = false; - if (elems.length) { - this.selectedElement = elems[0]; - } - } else { - setTimeout(() => { - $id('tool_select').setAttribute('src', `${imgPath}/select.svg`); - }, 1000); - } - } - /** * @param {external:Window} win * @param {module:svgcanvas.SvgCanvas#event:exported} data @@ -549,7 +521,7 @@ class Editor extends EditorStartup { } // if (!isNullish(elem)) // Deal with pathedit mode - this.togglePathEditMode(isNode, elems); + this.topPanel.togglePathEditMode(isNode, elems); this.topPanel.updateContextPanel(); this.svgCanvas.runExtensions('selectedChanged', /** @type {module:svgcanvas.SvgCanvas#event:ext_selectedChanged} */ { elems, diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index 3257a32b..90a4bd57 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -252,12 +252,9 @@ class EditorStartup { this.svgCanvas.setSegType(evt.currentTarget.value); }); - function addListenerMulti(element, eventNames, listener) { - const events = eventNames.split(' '); - for (let i=0, iLen=events.length; i { + eventNames.split(' ').forEach((eventName)=> element.addEventListener(eventName, listener, false)); + }; addListenerMulti($id('text'), 'keyup input', (evt) => { this.svgCanvas.setTextContent(evt.currentTarget.value); diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js index 02d134f9..b0466cee 100644 --- a/src/editor/panels/TopPanel.js +++ b/src/editor/panels/TopPanel.js @@ -3,7 +3,7 @@ import SvgCanvas from "../../svgcanvas/svgcanvas.js"; import { isValidUnit, getTypeMap, convertUnit } from "../../common/units.js"; -const { $id, isNullish } = SvgCanvas; +const { $qa, $id } = SvgCanvas; /* * register actions for left panel @@ -21,15 +21,15 @@ class TopPanel { /** * @type {module} */ - displayTool(id) { + displayTool(className) { // default display is 'none' so removing the property will make the panel visible - $id(id).style.removeProperty('display'); + $qa(`.${className}`).map( (el) => el.style.removeProperty('display')); } /** * @type {module} */ - hideTool(id) { - $id(id).style.display = 'none'; + hideTool(className) { + $qa(`.${className}`).map( (el) => el.style.display = 'none'); } /** * @type {module} @@ -81,7 +81,7 @@ class TopPanel { */ update() { let i; let len; - if (!isNullish(this.selectedElement)) { + if (this.selectedElement) { switch (this.selectedElement.tagName) { case "use": case "image": @@ -129,7 +129,7 @@ class TopPanel { } // All elements including image and group have opacity - if (!isNullish(this.selectedElement)) { + if (this.selectedElement) { const opacPerc = (this.selectedElement.getAttribute("opacity") || 1.0) * 100; $id("opacity").value = opacPerc; @@ -165,7 +165,7 @@ class TopPanel { updateContextPanel() { let elem = this.editor.selectedElement; // If element has just been deleted, consider it null - if (!isNullish(elem) && !elem.parentNode) { + if (!elem?.parentNode) { elem = null; } const currentLayerName = this.editor.svgCanvas @@ -616,7 +616,7 @@ class TopPanel { * @returns {void} */ convertToPath() { - if (!isNullish(this.editor.selectedElement)) { + if (this.editor.selectedElement) { this.editor.svgCanvas.convertToPath(); } } @@ -625,7 +625,7 @@ class TopPanel { * @returns {void} */ reorientPath() { - if (!isNullish(this.editor.selectedElement)) { + if (this.editor.selectedElement) { this.path.reorient(); } } @@ -634,7 +634,7 @@ class TopPanel { * @returns {void} Resolves to `undefined` */ makeHyperlink() { - if (!isNullish(this.editor.selectedElement) || this.multiselected) { + if (this.editor.selectedElement || this.multiselected) { // eslint-disable-next-line no-alert const url = prompt( this.editor.i18next.t('notification.enterNewLinkURL'), @@ -700,7 +700,7 @@ class TopPanel { * @returns {void} */ deleteSelected() { - if (!isNullish(this.editor.selectedElement) || this.editor.multiselected) { + if (this.editor.selectedElement || this.editor.multiselected) { this.editor.svgCanvas.deleteSelectedElements(); } } @@ -709,7 +709,7 @@ class TopPanel { * @returns {void} */ moveToTopSelected() { - if (!isNullish(this.editor.selectedElement)) { + if (this.editor.selectedElement) { this.editor.svgCanvas.moveToTopSelectedElement(); } } @@ -719,7 +719,7 @@ class TopPanel { * @returns {void} */ moveToBottomSelected() { - if (!isNullish(this.editor.selectedElement)) { + if (this.editor.selectedElement) { this.editor.svgCanvas.moveToBottomSelectedElement(); } } @@ -789,6 +789,33 @@ class TopPanel { this.displayTool("image_url"); } } + /** + * @param {boolean} editmode + * @param {module:svgcanvas.SvgCanvas#event:selected} elems + * @returns {void} + */ + togglePathEditMode(editMode, elems) { + const { imgPath } = this.editor.configObj.curConfig; + if (editMode) { + this.displayTool('path_node_panel'); + } else { + this.hideTool('path_node_panel'); + } + if (editMode) { + // Change select icon + $id('tool_path').pressed = false; + $id('tool_select').pressed = true; + $id('tool_select').setAttribute('src', `${imgPath}/select_node.svg`); + this.editor.multiselected = false; + if (elems.length) { + this.editor.selectedElement = elems[0]; + } + } else { + setTimeout(() => { + $id('tool_select').setAttribute('src', `${imgPath}/select.svg`); + }, 1000); + } + } /** * @type {module} @@ -822,32 +849,28 @@ class TopPanel { -
-
-
- - - -
-
-
- - - - -
-
- - - -
-
-
- -
-
- - +
+ + +
+
+
+ + +
+
+ + + +
+
+
+ +
+
+ + @@ -871,21 +894,21 @@ class TopPanel { - -
-
- - - - -
-
+ +
+ + + + +
-
+
+
+
@@ -902,54 +925,44 @@ class TopPanel { ${i18next.t('tools.smallest_object')} ${i18next.t('tools.page')} -
-
-
+
-
-
-
+
-
-
+
+
-
-
-
-
+
+
-
-
+
+
-
-
-
-
+
+
-
-
+
+
-
-
-
-
+
+
@@ -958,53 +971,51 @@ class TopPanel { -
-
-
-
- - +
+
+ + + + ${i18next.t('properties.serif')} + ${i18next.t('properties.sans_serif')} + ${i18next.t('properties.cursive')} + ${i18next.t('properties.fantasy')} + ${i18next.t('properties.monospace')} + ${i18next.t('properties.courier')} + ${i18next.t('properties.helvetica')} + ${i18next.t('properties.times')} + + +
+
- - ${i18next.t('properties.serif')} - ${i18next.t('properties.sans_serif')} - ${i18next.t('properties.cursive')} - ${i18next.t('properties.fantasy')} - ${i18next.t('properties.monospace')} - ${i18next.t('properties.courier')} - ${i18next.t('properties.helvetica')} - ${i18next.t('properties.times')} - - -
- - -
- -
+
+ + +
-
+
-
+
-
+
-
+
diff --git a/src/editor/svgedit.css b/src/editor/svgedit.css index 348c2a31..5db6c45f 100644 --- a/src/editor/svgedit.css +++ b/src/editor/svgedit.css @@ -359,10 +359,6 @@ hr { float: left; } -#multiselected_panel .selected_tool { - vertical-align: 12px; -} - #cur_context_panel { position: absolute; top: 57px; @@ -386,11 +382,6 @@ hr { text-decoration: underline; } -.toolset { - display: flex; - flex-direction: row; -} - input[type=text] { padding: 2px; }