diff --git a/src/editor/components/seExplorerButton.js b/src/editor/components/seExplorerButton.js index 1bb8afd5..ac858346 100644 --- a/src/editor/components/seExplorerButton.js +++ b/src/editor/components/seExplorerButton.js @@ -50,8 +50,8 @@ template.innerHTML = ` } .menu { position: absolute; - top:2px; - left:171px; + top:0px; + left:204px; background: none !important; display:none; } @@ -63,7 +63,7 @@ template.innerHTML = ` display: none; flex-wrap: wrap; flex-direction: row; - width: 136px; + width: 170px; } .menu-item { line-height: 1em; @@ -247,8 +247,9 @@ export class ExplorerButton extends HTMLElement { break; case 'SE-BUTTON': // change to the current action - this.$img.setAttribute('src', ev.target.getAttribute('src')); this.currentAction = ev.target; + this.$img.setAttribute('src', this.currentAction.getAttribute('src')); + this.dataset.draw = this.data[this.currentAction.dataset.shape]; this.currentAction.setAttribute('pressed', 'pressed'); // and close the menu this.$menu.classList.remove('open'); @@ -280,17 +281,17 @@ export class ExplorerButton extends HTMLElement { // initialize buttons for all shapes defined for this library const response = await fetch(`${libDir}${lib}.json`); const json = await response.json(); - const {data} = json; + this.data = json.data; const size = json.size ?? 300; const fill = json.fill ? '#333' : 'none'; const off = size * 0.05; const vb = [-off, -off, size + off * 2, size + off * 2].join(' '); const stroke = json.fill ? 0 : (size / 30); // eslint-disable-next-line no-unsanitized/property - this.$lib.innerHTML = Object.entries(data).map(([key, path]) => { + this.$lib.innerHTML = Object.entries(this.data).map(([key, path]) => { const encoded = btoa(` - + `); return ``; }).join(''); diff --git a/src/editor/extensions/ext-shapes/ext-shapes.js b/src/editor/extensions/ext-shapes/ext-shapes.js index 16f02ab8..ae12d761 100644 --- a/src/editor/extensions/ext-shapes/ext-shapes.js +++ b/src/editor/extensions/ext-shapes/ext-shapes.js @@ -28,98 +28,13 @@ export default { const svgroot = canv.getRootElem(); let lastBBox = {}; - // This populates the category list - const {categories} = strings; - const library = { - basic: { - buttons: [] - } - }; const modeId = 'shapelib'; const startClientPos = {}; - let currentD, curShapeId, curShape, startX, startY; - let curLib = library.basic; + let curShape; + let startX; + let startY; - /** - * - * @returns {void} - */ - function loadIcons () { - $('#shape_buttons').empty().append(curLib.buttons); - } - - /** - * @typedef {PlainObject} module:Extension.Shapes.Shapes - * @property {PlainObject} data - * @property {Integer} [size] - * @property {boolean} [fill] - */ - - /** - * @param {string|"basic"} cat Category ID - * @param {module:Extension.Shapes.Shapes} shapes - * @returns {void} - */ - function makeButtons (cat, shapes) { - const size = curLib.size || 300; - const fill = curLib.fill || false; - const off = size * 0.05; - const vb = [-off, -off, size + off * 2, size + off * 2].join(' '); - const stroke = fill ? 0 : (size / 30); - const shapeIcon = new DOMParser().parseFromString( - '' + - '' + - '', - 'text/xml' - ); - - const width = 24; - const height = 24; - shapeIcon.documentElement.setAttribute('width', width); - shapeIcon.documentElement.setAttribute('height', height); - const svgElem = $(document.importNode(shapeIcon.documentElement, true)); - - const {data} = shapes; - - curLib.buttons = Object.entries(data).map(([id, pathD]) => { - const icon = svgElem.clone(); - icon.find('path').attr('d', pathD); - - const iconBtn = icon.wrap('
').parent().attr({ - id: modeId + '_' + id, - title: id - }); - // Store for later use - return iconBtn[0]; - }); - } - - /** - * @param {string|"basic"} catId - * @returns {void} - */ - function loadLibrary (catId) { - const lib = library[catId]; - - if (!lib) { - $('#shape_buttons').html(strings.loading); - $.getJSON('./shapelib/' + catId + '.json', function (result) { - curLib = library[catId] = { - data: result.data, - size: result.size, - fill: result.fill - }; - makeButtons(catId, result); - loadIcons(); - }); - return; - } - curLib = lib; - if (!lib.buttons.length) { makeButtons(catId, lib); } - loadIcons(); - } const buttons = [{ id: 'tool_shapelib_show', type: 'mode_flyout', @@ -136,101 +51,13 @@ export default { return Object.assign(buttons[i], button); }), callback () { - $('