import { copyAndPast } from '../diagram/group-select-applay.js'; import { copySvg, delSvg } from '../infrastructure/assets.js'; import { clickForAll, listen, classSingleAdd, evtTargetAttr } from '../infrastructure/util.js'; import { modalChangeTop, modalCreate } from './modal-create.js'; import { ShapeSmbl } from './shape-smbl.js'; /** * @param {import('../infrastructure/canvas-smbl').CanvasElement} canvas * @param {import('./shape-smbl').ShapeElement} shapeElement * @param {number} bottomX positon of the bottom left corner of the panel * @param {number} bottomY positon of the bottom left corner of the panel */ export function settingsPnlCreate(canvas, shapeElement, bottomX, bottomY) { const shapeSettings = new ShapeEdit(); listen(shapeSettings, 'cmd', /** @param {CustomEvent<{cmd:string, arg:string}>} evt */ evt => { switch (evt.detail.cmd) { case 'style': classSingleAdd(shapeElement, shapeElement[ShapeSmbl].data, 'cl-', evt.detail.arg); break; case 'del': shapeElement[ShapeSmbl].del(); break; case 'copy': copyAndPast(canvas, [shapeElement]); break; } }); return modalCreate(bottomX, bottomY, shapeSettings); } class ShapeEdit extends HTMLElement { connectedCallback() { const shadow = this.attachShadow({ mode: 'closed' }); shadow.innerHTML = `
${copySvg} ${delSvg}
`; // // tabs { const pnl = shadow.getElementById('pnl'); /** @param {1|-1} coef */ function modalSetTop(coef) { modalChangeTop(window.scrollY + coef * pnl.getBoundingClientRect().height); // window.scrollY fix IPhone keyboard } /** @type {HTMLElement} */ let currentTab; clickForAll(shadow, '[data-toggle]', evt => { if (currentTab) { modalSetTop(1); display(currentTab, false); } const tab = shadow.getElementById(evtTargetAttr(evt, 'data-toggle')); if (currentTab !== tab) { display(tab, true); modalSetTop(-1); currentTab = tab; } else { currentTab = null; } }); } // // commands clickForAll(shadow, '[data-cmd]', evt => { this.dispatchEvent(new CustomEvent('cmd', { detail: { cmd: evtTargetAttr(evt, 'data-cmd'), arg: evtTargetAttr(evt, 'data-cmd-arg') } })); }); } } customElements.define('ap-shape-edit', ShapeEdit); /** @param {ElementCSSInlineStyle} el, @param {boolean} isDisp */ function display(el, isDisp) { el.style.display = isDisp ? 'unset' : 'none'; }