From aadd3679c4a4e8b96d680ff3a72e859869e84620 Mon Sep 17 00:00:00 2001 From: agriyadev5 Date: Mon, 20 Sep 2021 20:14:10 +0530 Subject: [PATCH] #631 se-list-item modification changes --- src/editor/components/seList.js | 23 +++- src/editor/components/seListItem.js | 62 ++++++++++- src/editor/panels/BottomPanel.js | 29 ++--- src/editor/panels/TopPanel.js | 157 ++++++++++------------------ 4 files changed, 150 insertions(+), 121 deletions(-) diff --git a/src/editor/components/seList.js b/src/editor/components/seList.js index e36a19ab..31356168 100644 --- a/src/editor/components/seList.js +++ b/src/editor/components/seList.js @@ -40,13 +40,15 @@ export class SeList extends HTMLElement { this._shadowRoot.append(template.content.cloneNode(true)); this.$dropdown = this._shadowRoot.querySelector('elix-dropdown-list'); this.$label = this._shadowRoot.querySelector('label'); + this.$selction = this.$dropdown.shadowRoot.querySelector('#source').querySelector('#value'); + this.items = this.querySelectorAll("se-list-item"); } /** * @function observedAttributes * @returns {any} observed */ static get observedAttributes () { - return [ 'label', 'width', 'height', 'title' ]; + return [ 'label', 'width', 'height', 'title', 'value' ]; } /** @@ -57,6 +59,7 @@ export class SeList extends HTMLElement { * @returns {void} */ attributeChangedCallback (name, oldValue, newValue) { + const currentObj = this; if (oldValue === newValue) return; switch (name) { case 'title': @@ -71,6 +74,23 @@ export class SeList extends HTMLElement { case 'width': this.$dropdown.style.width = newValue; break; + case 'value': + Array.from(this.items).forEach(function (element) { + if(element.getAttribute("value") === newValue) { + if (element.hasAttribute("src")) { + while(currentObj.$selction.firstChild) + currentObj.$selction.removeChild(currentObj.$selction.firstChild); + const img = document.createElement('img'); + img.src = './images/' + element.getAttribute("src"); + img.style.height = element.getAttribute("img-height"); + img.setAttribute('title', t(element.getAttribute("title"))); + currentObj.$selction.append(img); + } else { + currentObj.$selction.textContent = t(element.getAttribute('option')); + } + } + }); + break; default: // eslint-disable-next-line no-console console.error(`unknown attribute: ${name}`); @@ -149,6 +169,7 @@ export class SeList extends HTMLElement { const closeEvent = new CustomEvent('change', { detail: { value } }); currentObj.dispatchEvent(closeEvent); currentObj.value = value; + currentObj.setAttribute("value", value); } }); this.$dropdown.addEventListener('close', (_e) => { diff --git a/src/editor/components/seListItem.js b/src/editor/components/seListItem.js index ee1a7972..7ad6e5de 100644 --- a/src/editor/components/seListItem.js +++ b/src/editor/components/seListItem.js @@ -1,4 +1,5 @@ import 'elix/define/Option.js'; +import { t } from '../locale.js'; const template = document.createElement('template'); template.innerHTML = ` @@ -12,6 +13,7 @@ template.innerHTML = ` } + icon `; @@ -30,13 +32,15 @@ export class SeListItem extends HTMLElement { this.$menuitem = this._shadowRoot.querySelector('elix-option'); this.$svg = this.$menuitem.shadowRoot.querySelector('#checkmark'); this.$svg.setAttribute('style', 'display: none;'); + this.$img = this._shadowRoot.querySelector('img'); + this.$img.setAttribute('style', 'display: none;'); } /** * @function observedAttributes * @returns {any} observed */ static get observedAttributes () { - return [ 'option' ]; + return [ 'option', 'src', 'title', 'img-height' ]; } /** @@ -51,6 +55,17 @@ export class SeListItem extends HTMLElement { switch (name) { case 'option': this.$menuitem.setAttribute('option', newValue); + this.$menuitem.textContent = t(newValue); + break; + case 'src': + this.$img.setAttribute('style', 'display: block;'); + this.$img.setAttribute('src', './images/' + newValue); + break; + case 'title': + this.$img.setAttribute('title', t(newValue)); + break; + case 'img-height': + this.$img.setAttribute('height', newValue); break; default: // eslint-disable-next-line no-console @@ -73,6 +88,51 @@ export class SeListItem extends HTMLElement { set option (value) { this.setAttribute('option', value); } + /** + * @function get + * @returns {any} + */ + get title () { + return this.getAttribute('title'); + } + + /** + * @function set + * @returns {void} + */ + set title (value) { + this.setAttribute('title', value); + } + /** + * @function get + * @returns {any} + */ + get imgHeight () { + return this.getAttribute('img-height'); + } + + /** + * @function set + * @returns {void} + */ + set imgHeight (value) { + this.setAttribute('img-height', value); + } + /** + * @function get + * @returns {any} + */ + get src () { + return this.getAttribute('src'); + } + + /** + * @function set + * @returns {void} + */ + set src (value) { + this.setAttribute('src', value); + } } // Register diff --git a/src/editor/panels/BottomPanel.js b/src/editor/panels/BottomPanel.js index 1ca506f9..79c9c6b7 100644 --- a/src/editor/panels/BottomPanel.js +++ b/src/editor/panels/BottomPanel.js @@ -164,7 +164,6 @@ class BottomPanel { // register actions for Bottom panel const template = document.createElement('template'); const { i18next } = this.editor; - const { imgPath } = this.editor.configObj.curConfig; // eslint-disable-next-line no-unsanitized/property template.innerHTML = ` @@ -187,27 +186,21 @@ class BottomPanel { - - ... - - - - - . - - .. + + ... + - - + - . + - .. - - - + + + - - - + + + diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js index 5ede530b..c67af4c4 100644 --- a/src/editor/panels/TopPanel.js +++ b/src/editor/panels/TopPanel.js @@ -111,18 +111,20 @@ class TopPanel { $id("stroke_width").value = this.selectedElement.getAttribute("stroke-width") || 1; $id("stroke_style").value = this.selectedElement.getAttribute("stroke-dasharray") || "none"; + $id("stroke_style").setAttribute("value", $id("stroke_style").value); let attr = this.selectedElement.getAttribute("stroke-linejoin") || "miter"; - if ($id("linejoin_" + attr).length) { + if ($id("linejoin_" + attr)) { this.setStrokeOpt($id("linejoin_" + attr)); + $id("stroke_linejoin").setAttribute("value", attr); } attr = this.selectedElement.getAttribute("stroke-linecap") || "butt"; - - if ($id("linecap_" + attr).length) { + if ($id("linecap_" + attr)) { this.setStrokeOpt($id("linecap_" + attr)); + $id("stroke_linecap").setAttribute("value", attr); } } } @@ -343,7 +345,7 @@ class TopPanel { this.displayTool("text_panel"); $id("tool_italic").pressed = this.editor.svgCanvas.getItalic(); $id("tool_bold").pressed = this.editor.svgCanvas.getBold(); - $id("tool_font_family").value = elem.getAttribute("font-family"); + $id("tool_font_family").setAttribute("value", elem.getAttribute("font-family")); $id("font_size").value = elem.getAttribute("font-size"); $id("text").value = elem.textContent; const textAnchorStart = $id("tool_text_anchor_start"); @@ -824,24 +826,13 @@ class TopPanel { // add Top panel const template = document.createElement("template"); const { i18next } = this.editor; - const { imgPath } = this.editor.configObj.curConfig; // eslint-disable-next-line no-unsanitized/property template.innerHTML = `
- - + +
@@ -870,29 +861,15 @@ class TopPanel {
- - + + - - - - - - - - - - - - - - - - - - + + + + + +
@@ -905,8 +882,7 @@ class TopPanel {
- +
@@ -920,78 +896,64 @@ class TopPanel { - ${i18next.t('tools.selected_objects')} - ${i18next.t('tools.largest_object')} - ${i18next.t('tools.smallest_object')} - ${i18next.t('tools.page')} + + + +
- - - - - + + +
- - - + +
- +
- - + +
- +
- - - - + +
- - - - + +
- - - - - - - - + + + +
- ${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')} + + + + + + + + - +
- - - + + +
@@ -1000,13 +962,10 @@ class TopPanel {
- - +
- - +
@@ -1017,21 +976,17 @@ class TopPanel {
- - +
- - - - + + - - +