/* eslint-disable max-len */ /* eslint-disable node/no-unpublished-import */ import 'elix/define/Dialog.js'; const template = document.createElement('template'); template.innerHTML = `

By default and where supported, SVG-Edit can store your editor preferences and SVG content locally on your machine so you do not need to add these back each time you load SVG-Edit. If, for privacy reasons, you do not wish to store this information on your machine, you can change away from the default option below.

`; /** * @class SeStorageDialog */ export class SeStorageDialog extends HTMLElement { /** * @function constructor */ constructor () { super(); // create the shadowDom and insert the template this._shadowRoot = this.attachShadow({mode: 'open'}); this._shadowRoot.appendChild(template.content.cloneNode(true)); this.$dialog = this._shadowRoot.querySelector('#dialog_box'); this.$storage = this._shadowRoot.querySelector('#js-storage'); this.$okBtn = this._shadowRoot.querySelector('#storage_ok'); this.$cancelBtn = this._shadowRoot.querySelector('#storage_cancel'); this.$storageInput = this._shadowRoot.querySelector('#se-storage-pref'); this.$rememberInput = this._shadowRoot.querySelector('#se-remember'); } /** * @function observedAttributes * @returns {any} observed */ static get observedAttributes () { return ['dialog', 'storage']; } /** * @function attributeChangedCallback * @param {string} name * @param {string} oldValue * @param {string} newValue * @returns {void} */ attributeChangedCallback (name, oldValue, newValue) { switch (name) { case 'dialog': if (newValue === 'open') { this.$dialog.open(); } else { this.$dialog.close(); } break; case 'storage': if (newValue === 'true') { this.$storageInput.options[0].disabled = false; } else { this.$storageInput.options[0].disabled = true; } 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 connectedCallback * @returns {void} */ connectedCallback () { const onSubmitHandler = (e, action) => { const triggerEvent = new CustomEvent('change', {detail: { trigger: action, select: this.$storageInput.value, checkbox: this.$rememberInput.checked }}); this.dispatchEvent(triggerEvent); }; this.$okBtn.addEventListener('click', (evt) => onSubmitHandler(evt, 'ok')); this.$cancelBtn.addEventListener('click', (evt) => onSubmitHandler(evt, 'cancel')); } } // Register customElements.define('se-storage-dialog', SeStorageDialog);