/* eslint-disable node/no-unpublished-import */ import 'elix/define/Dialog.js'; const template = document.createElement('template'); template.innerHTML = ` Apply Changes Cancel Copy the contents of this box into a text editor, then save the file with a .svg extension. Done `; /** * @class SeSvgSourceEditorDialog */ export class SeSvgSourceEditorDialog extends HTMLElement { /** * @function constructor */ constructor () { super(); // create the shadowDom and insert the template this._shadowRoot = this.attachShadow({mode: 'open'}); this._shadowRoot.append(template.content.cloneNode(true)); this.$dialog = this._shadowRoot.querySelector('#svg_source_editor'); this.$copyBtn = this._shadowRoot.querySelector('#copy_save_done'); this.$saveBtn = this._shadowRoot.querySelector('#tool_source_save'); this.$cancelBtn = this._shadowRoot.querySelector('#tool_source_cancel'); this.$sourceTxt = this._shadowRoot.querySelector('#svg_source_textarea'); this.$copySec = this._shadowRoot.querySelector('#save_output_btns'); this.$applySec = this._shadowRoot.querySelector('#tool_source_back'); } /** * @function observedAttributes * @returns {any} observed */ static get observedAttributes () { return ['dialog', 'value', 'applysec', 'copysec']; } /** * @function attributeChangedCallback * @param {string} name * @param {string} oldValue * @param {string} newValue * @returns {void} */ attributeChangedCallback (name, oldValue, newValue) { if (oldValue === newValue) return; switch (name) { case 'dialog': if (newValue === 'open') { this.$sourceTxt.focus(); this.$dialog.open(); } else { this.$dialog.close(); this.$sourceTxt.blur(); } break; case 'applysec': if (newValue === 'false') { this.$applySec.style.display = 'none'; } else { this.$applySec.style.display = 'block'; } break; case 'copysec': if (newValue === 'false') { this.$copySec.style.display = 'none'; } else { this.$copySec.style.display = 'block'; } break; case 'value': this.$sourceTxt.value = newValue; break; default: super.attributeChangedCallback(name, oldValue, newValue); break; } } /** * @function get * @returns {any} */ get dialog () { return this.getAttribute('dialog'); } /** * @function set * @returns {void} */ set dialog (value) { this.setAttribute('dialog', value); } /** * @function get * @returns {any} */ get value () { return this.getAttribute('value'); } /** * @function set * @returns {void} */ set value (value) { this.setAttribute('value', value); } /** * @function get * @returns {any} */ get applysec () { return this.getAttribute('applysec'); } /** * @function set * @returns {void} */ set applysec (value) { this.setAttribute('applysec', value); } /** * @function get * @returns {any} */ get copysec () { return this.getAttribute('copysec'); } /** * @function set * @returns {void} */ set copysec (value) { this.setAttribute('copysec', value); } /** * @function connectedCallback * @returns {void} */ connectedCallback () { const onCancelHandler = (ev) => { const closeEvent = new CustomEvent('change', {detail: { dialog: 'closed' }}); this.dispatchEvent(closeEvent); }; const onCopyHandler = (ev) => { const closeEvent = new CustomEvent('change', { detail: { copy: 'click', value: this.$sourceTxt.value } }); this.dispatchEvent(closeEvent); }; const onSaveHandler = (ev) => { const closeEvent = new CustomEvent('change', {detail: { value: this.$sourceTxt.value, dialog: 'close' }}); this.dispatchEvent(closeEvent); }; this.$copyBtn.addEventListener('click', onCopyHandler); this.$saveBtn.addEventListener('click', onSaveHandler); this.$cancelBtn.addEventListener('click', onCancelHandler); this.$dialog.addEventListener('close', onCancelHandler); } } // Register customElements.define('se-svg-source-editor-dialog', SeSvgSourceEditorDialog);
Copy the contents of this box into a text editor, then save the file with a .svg extension.