From 7e8136722e853509c14ce2a1e3cc69f37c4c94b6 Mon Sep 17 00:00:00 2001 From: agriyadev5 Date: Fri, 24 Sep 2021 18:57:48 +0530 Subject: [PATCH] #631 normal select change to se-select web component --- src/editor/EditorStartup.js | 2 +- src/editor/components/seSelect.js | 56 ++++++++++++++++++++++++------- src/editor/panels/BottomPanel.js | 2 +- src/editor/panels/LayersPanel.js | 21 ++++++------ src/editor/panels/TopPanel.js | 9 ++--- 5 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index 88052425..9a39c817 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -217,7 +217,7 @@ class EditorStartup { // fired when user wants to move elements to another layer let promptMoveLayerOnce = false; $id('selLayerNames').addEventListener('change', (evt) => { - const destLayer = evt.currentTarget.options[evt.currentTarget.selectedIndex].value; + const destLayer = evt.detail.value; const confirmStr = this.i18next.t('notification.QmoveElemsToLayer').replace('%s', destLayer); /** * @param {boolean} ok diff --git a/src/editor/components/seSelect.js b/src/editor/components/seSelect.js index ebef9dbe..a3ebce1b 100644 --- a/src/editor/components/seSelect.js +++ b/src/editor/components/seSelect.js @@ -42,7 +42,7 @@ export class SeSelect extends HTMLElement { * @returns {any} observed */ static get observedAttributes () { - return [ 'label', 'width', 'height', 'options', 'values', 'title' ]; + return [ 'label', 'width', 'height', 'options', 'values', 'title', 'disabled' ]; } /** @@ -62,6 +62,13 @@ export class SeSelect extends HTMLElement { case 'title': this.$select.setAttribute("title", t(newValue)); break; + case 'disabled': + if(newValue === null) { + this.$select.removeAttribute("disabled"); + } else { + this.$select.setAttribute("disabled", newValue); + } + break; case 'height': this.$select.style.height = newValue; break; @@ -69,19 +76,29 @@ export class SeSelect extends HTMLElement { this.$select.style.width = newValue; break; case 'options': - options = newValue.split(','); - options.forEach((option) => { - const optionNode = document.createElement("OPTION"); - const text = document.createTextNode(t(option)); - optionNode.appendChild(text); - this.$select.appendChild(optionNode); - }); + if(newValue === "") { + while(this.$select.firstChild) + this.$select.removeChild(this.$select.firstChild); + } else { + options = newValue.split(','); + options.forEach((option) => { + const optionNode = document.createElement("OPTION"); + const text = document.createTextNode(t(option)); + optionNode.appendChild(text); + this.$select.appendChild(optionNode); + }); + } break; case 'values': - options = newValue.split(' '); - options.forEach((option, index) => { - this.$select.children[index].setAttribute('value', option); - }); + if(newValue === "") { + while(this.$select.firstChild) + this.$select.removeChild(this.$select.firstChild); + } else { + options = newValue.split('::'); + options.forEach((option, index) => { + this.$select.children[index].setAttribute('value', option); + }); + } break; default: // eslint-disable-next-line no-console @@ -149,6 +166,21 @@ export class SeSelect extends HTMLElement { set value (value) { this.$select.value = value; } + /** + * @function get + * @returns {any} + */ + get disabled () { + return this.$select.getAttribute('disabled'); + } + + /** + * @function set + * @returns {void} + */ + set disabled (value) { + this.$select.setAttribute('disabled', value); + } /** * @function connectedCallback * @returns {void} diff --git a/src/editor/panels/BottomPanel.js b/src/editor/panels/BottomPanel.js index 5bd27ae1..ce78c322 100644 --- a/src/editor/panels/BottomPanel.js +++ b/src/editor/panels/BottomPanel.js @@ -186,7 +186,7 @@ class BottomPanel { + values="none::2,2::5,5::5,2,2,2::5,2,2,2,2,2"> diff --git a/src/editor/panels/LayersPanel.js b/src/editor/panels/LayersPanel.js index 141a89f9..be42e016 100644 --- a/src/editor/panels/LayersPanel.js +++ b/src/editor/panels/LayersPanel.js @@ -67,10 +67,9 @@ class LayersPanel { Layer 1 - - + + @@ -89,7 +88,6 @@ class LayersPanel { menuLayerBox.setAttribute("leftclick", false); this.editor.$container.append(menuLayerBox); menuLayerBox.init(i18next); - $id("selLayerNames").setAttribute("title", i18next.t('layers.move_selected')); $id("layer_new").addEventListener("click", this.newLayer.bind(this)); $id("layer_delete").addEventListener("click", this.deleteLayer.bind(this)); $id("layer_up").addEventListener("click", () => this.moveLayer.bind(this)(-1)); @@ -279,14 +277,13 @@ class LayersPanel { while(layerlist.firstChild) layerlist.removeChild(layerlist.firstChild); - const selLayerNames = $id("selLayerNames"); - // empty() ref: http://youmightnotneedjquery.com/#empty - while(selLayerNames.firstChild) - selLayerNames.removeChild(selLayerNames.firstChild); + $id("selLayerNames").setAttribute("options", ""); const drawing = this.editor.svgCanvas.getCurrentDrawing(); const currentLayerName = drawing.getCurrentLayerName(); let layer = this.editor.svgCanvas.getCurrentDrawing().getNumLayers(); // we get the layers in the reverse z-order (the layer rendered on top is listed first) + let values = ""; + let text = ""; while (layer--) { const name = drawing.getLayerName(layer); const layerTr = document.createElement("tr"); @@ -299,9 +296,11 @@ class LayersPanel { layerTr.appendChild(layerVis); layerTr.appendChild(layerName); layerlist.appendChild(layerTr); - // eslint-disable-next-line no-unsanitized/property - selLayerNames.innerHTML += ''; + values = (values) ? values + "::" + name : name; + text = (text) ? text + "," + name : name; } + $id("selLayerNames").setAttribute("options", text); + $id("selLayerNames").setAttribute("values", values); // handle selection of layer const nelements = $id('layerlist').querySelectorAll("td.layername"); Array.from(nelements).forEach(function(element) { diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js index f5a75fd0..910087f2 100644 --- a/src/editor/panels/TopPanel.js +++ b/src/editor/panels/TopPanel.js @@ -427,6 +427,7 @@ class TopPanel { // update the selected elements' layer $id("selLayerNames").removeAttribute("disabled"); $id("selLayerNames").value = currentLayerName; + $id("selLayerNames").setAttribute("value", currentLayerName); // Enable regular menu options const canCMenu = document.getElementById("se-cmenu_canvas"); @@ -435,7 +436,7 @@ class TopPanel { "#delete,#cut,#copy,#move_front,#move_up,#move_down,#move_back" ); } else { - $id("selLayerNames").disabled = "disabled"; + $id("selLayerNames").setAttribute("disabled", "disabled"); } } /** @@ -897,7 +898,7 @@ class TopPanel { + values="selected::largest::smallest::page">
@@ -936,7 +937,7 @@ class TopPanel {
- +
@@ -969,7 +970,7 @@ class TopPanel {
- +