master
JFH 2021-12-27 17:59:00 -03:00
parent cdc5b8cc75
commit f32be000a0
3 changed files with 20 additions and 21 deletions

View File

@ -28,7 +28,7 @@ export const init = function (canvas) {
* @returns {void}
*/
export const pasteElementsMethod = function (type, x, y) {
let clipb = JSON.parse(sessionStorage.getItem(svgCanvas.getClipBoardID()));
let clipb = JSON.parse(sessionStorage.getItem(svgCanvas.getClipboardID()));
if (!clipb) return;
let len = clipb.length;
if (!len) return;

View File

@ -11,7 +11,6 @@ import { getRotationAngle, getBBox, getStrokedBBox, isNullish } from './utilitie
import { transformListToTransform, transformBox, transformPoint } from './math.js';
let svgCanvas;
let config_;
let selectorManager_; // A Singleton
const gripRadius = isTouch() ? 10 : 4;
@ -364,7 +363,7 @@ export class SelectorManager {
r: gripRadius,
stroke: '#22C',
'stroke-width': 2,
style: `cursor:url(${config_.imgPath}/rotate.svg) 12 12, auto;`
style: `cursor:url(${this.curConfig.imgPath}/rotate.svg) 12 12, auto;`
}
});
this.selectorGripsGroup.append(this.rotateGrip);
@ -372,7 +371,7 @@ export class SelectorManager {
if (document.getElementById('canvasBackground')) { return; }
const [ width, height ] = config_.dimensions;
const [ width, height ] = this.curConfig.dimensions;
const canvasbg = svgCanvas.createSVGElement({
element: 'svg',
attr: {
@ -531,8 +530,7 @@ export class SelectorManager {
* @param {module:select.SVGFactory} svgFactory - An object implementing the SVGFactory interface.
* @returns {void}
*/
export const init = function (config, canvas) {
config_ = config;
export const init = (canvas) => {
svgCanvas = canvas;
selectorManager_ = new SelectorManager();
};

View File

@ -218,7 +218,7 @@ class SvgCanvas {
utilsInit(this);
coordsInit(this);
recalculateInit(this);
selectInit(this.curConfig, this);
selectInit(this);
undoInit(this);
selectionInit(this);
@ -267,34 +267,23 @@ class SvgCanvas {
blurInit(this);
selectedElemInit(this);
/**
* Flash the clipboard data momentarily on localStorage so all tabs can see.
* @returns {void}
*/
function flashStorage() {
const data = sessionStorage.getItem(CLIPBOARD_ID);
localStorage.setItem(CLIPBOARD_ID, data);
setTimeout(function () {
localStorage.removeItem(CLIPBOARD_ID);
}, 1);
}
/**
* Transfers sessionStorage from one tab to another.
* @param {!Event} ev Storage event.
* @returns {void}
*/
function storageChange(ev) {
const storageChange = (ev) => {
if (!ev.newValue) return; // This is a call from removeItem.
if (ev.key === CLIPBOARD_ID + '_startup') {
// Another tab asked for our sessionStorage.
localStorage.removeItem(CLIPBOARD_ID + '_startup');
flashStorage();
this.flashStorage();
} else if (ev.key === CLIPBOARD_ID) {
// Another tab sent data.
sessionStorage.setItem(CLIPBOARD_ID, ev.newValue);
}
}
};
// Listen for changes to localStorage.
window.addEventListener('storage', storageChange, false);
@ -418,6 +407,7 @@ class SvgCanvas {
setInitBbox(value) { this.initBbox = value; }
setRootSctm(value) { this.rootSctm = value; }
setCurrentResizeMode(value) { this.currentResizeMode = value; }
getLastClickPoint(key) { return this.lastClickPoint[key]; }
setLastClickPoint(value) { this.lastClickPoint = value; }
getId() { return this.getCurrentDrawing().getId(); }
getUIStrings() { return this.uiStrings; }
@ -557,6 +547,17 @@ class SvgCanvas {
return old;
}
/**
* Flash the clipboard data momentarily on localStorage so all tabs can see.
* @returns {void}
*/
flashStorage() {
const data = sessionStorage.getItem(CLIPBOARD_ID);
localStorage.setItem(CLIPBOARD_ID, data);
setTimeout(function () {
localStorage.removeItem(CLIPBOARD_ID);
}, 1);
}
/**
* Selects only the given elements, shortcut for `clearSelection(); addToSelection()`.
* @function module:svgcanvas.SvgCanvas#selectOnly
* @param {Element[]} elems - an array of DOM elements to be selected