diff --git a/src/editor/components/seDropdown.js b/src/editor/components/seDropdown.js index 917a93a0..4023c3f3 100644 --- a/src/editor/components/seDropdown.js +++ b/src/editor/components/seDropdown.js @@ -1,8 +1,9 @@ /* eslint-disable node/no-unpublished-import */ import ListComboBox from 'elix/define/ListComboBox.js'; import NumberSpinBox from 'elix/define/NumberSpinBox.js'; -import {defaultState, template} from 'elix/src/base/internal.js'; -import {templateFrom} from 'elix/src/core/htmlLiterals.js'; +import {defaultState} from 'elix/src/base/internal.js'; +import {templateFrom, fragmentFrom} from 'elix/src/core/htmlLiterals.js'; +import {internal} from 'elix'; /** * @class CustomCombo @@ -14,77 +15,49 @@ class CustomCombo extends ListComboBox { */ get [defaultState] () { return Object.assign(super[defaultState], { - inputPartType: NumberSpinBox + inputPartType: NumberSpinBox, + src: './imags.logo.svg' }); } /** * @function get * @returns {PlainObject} */ - get [template] () { - const result = super[template]; + get [internal.template] () { + const result = super[internal.template]; + const source = result.content.getElementById('source'); + source.prepend(fragmentFrom.html` + icon + + `.cloneNode(true)); result.content.append( templateFrom.html` `.content ); return result; } -} - -customElements.define('custom-combo', CustomCombo); - -const mytemplate = document.createElement('template'); -mytemplate.innerHTML = ` - - - icon - - - - -`; -/** - * @class Dropdown - */ -export class Dropdown extends HTMLElement { - /** - * @function constructor - */ - constructor () { - super(); - // create the shadowDom and insert the template - this._shadowRoot = this.attachShadow({mode: 'open'}); - this._shadowRoot.appendChild(mytemplate.content.cloneNode(true)); - this.$dropdown = this._shadowRoot.querySelector('custom-combo'); - this.$img = this._shadowRoot.querySelector('img'); - this.$span = this._shadowRoot.querySelector('span'); - // we retrieve all elements added in the slot (i.e. se-buttons) - // this.$elements = this.$menu.lastElementChild.assignedElements(); - } /** * @function observedAttributes * @returns {any} observed @@ -103,37 +76,57 @@ export class Dropdown extends HTMLElement { if (oldValue === newValue) return; switch (name) { case 'title': - { - const shortcut = this.getAttribute('shortcut'); - this.$span.setAttribute('title', `${newValue} ${shortcut ? `[${shortcut}]` : ''}`); - } + console.log({this: this, name, oldValue, newValue}); + // this.$span.setAttribute('title', `${newValue} ${shortcut ? `[${shortcut}]` : ''}`); break; case 'src': - this.$img.setAttribute('src', newValue); + console.log({name, oldValue, newValue}); + this.src = newValue; break; default: - // eslint-disable-next-line no-console - console.error(`unknown attribute: ${name}`); + super.attributeChangedCallback(name, oldValue, newValue); break; } } /** - * @function connectedCallback - * @returns {void} - */ + * @function connectedCallback + * @returns {void} + */ connectedCallback () { - this.$dropdown.addEventListener('selectedindexchange', (e) => { + super.connectedCallback(); + this.addEventListener('selectedindexchange', (e) => { console.log(e.detail); console.log(this.children[e.detail.selectedIndex].getAttribute('value')); console.log(this); }); - this.$dropdown.addEventListener('input', (e) => { + this.addEventListener('input', (e) => { console.log(e.detail); console.log(this.children[e.detail.selectedIndex].getAttribute('value')); console.log(this); }); } + /** + * @function [internal.render] + * @param {PlainObject} changed + * @returns {void} + */ + [internal.render] (changed) { + super[internal.render](changed); + console.log(this, changed, this[internal.firstRender], changed.src); + if (this[internal.firstRender]) { + this.$img = this.shadowRoot.querySelector('img'); + } + if (changed.src) { + this.$img.setAttribute('src', this[internal.state].src); + } + } + get src () { + return this[internal.state].src; + } + set src (src) { + this[internal.setState]({src}); + } } // Register -customElements.define('se-dropdown', Dropdown); +customElements.define('se-dropdown', CustomCombo); diff --git a/src/editor/index.html b/src/editor/index.html index 23b8a902..b7bb77dd 100644 --- a/src/editor/index.html +++ b/src/editor/index.html @@ -482,14 +482,12 @@ -
-