refactor to class step 1

This commit is contained in:
JFH
2020-12-29 14:18:22 +01:00
parent 22212f3096
commit eb77d57fa1
24 changed files with 1678 additions and 1747 deletions

View File

@@ -24,7 +24,7 @@ export default {
async init (S) {
const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const
addElem = svgCanvas.addSVGElementFromJson,
{nonce, $} = S,

View File

@@ -23,7 +23,7 @@ export default {
name: 'connector',
async init (S) {
const svgEditor = this;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const {getElem} = svgCanvas;
const {$, svgroot} = S,
addElem = svgCanvas.addSVGElementFromJson,
@@ -374,7 +374,7 @@ export default {
startX = opts.start_x;
startY = opts.start_y;
const mode = svgCanvas.getMode();
const {curConfig: {initStroke}} = svgEditor;
const {curConfig: {initStroke}} = svgEditor.configObj;
if (mode === 'connector') {
if (started) { return undefined; }

View File

@@ -26,7 +26,7 @@ export default {
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const {$, ChangeElementCommand} = S, // , svgcontent,
// svgdoc = S.svgroot.parentNode.ownerDocument,
svgCanvas = svgEditor.canvas,
{svgCanvas} = svgEditor,
addToHistory = function (cmd) { svgCanvas.undoMgr.addCommandToHistory(cmd); },
currentStyle = {
fillPaint: 'red', fillOpacity: 1.0,

View File

@@ -24,7 +24,7 @@ export default {
async init (S) {
const svgEditor = this;
const {$, text2xml, NS} = S;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const
// {svgcontent} = S,
// addElem = svgCanvas.addSVGElementFromJson,

View File

@@ -24,14 +24,14 @@ export default {
async init ({$, NS, getTypeMap}) {
const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const svgdoc = document.getElementById('svgcanvas').ownerDocument,
{assignAttributes} = svgCanvas,
hcanvas = document.createElement('canvas'),
canvBG = $('#canvasBackground'),
units = getTypeMap(), // Assumes prior `init()` call on `units.js` module
intervals = [0.01, 0.1, 1, 10, 100, 1000];
let showGrid = svgEditor.curConfig.showGrid || false;
let showGrid = svgEditor.configObj.curConfig.showGrid || false;
$(hcanvas).hide().appendTo('body');
@@ -90,7 +90,7 @@ export default {
*/
function updateGrid (zoom) {
// TODO: Try this with <line> elements, then compare performance difference
const unit = units[svgEditor.curConfig.baseUnit]; // 1 = 1px
const unit = units[svgEditor.configObj.curConfig.baseUnit]; // 1 = 1px
const uMulti = unit * zoom;
// Calculate the main number interval
const rawM = 100 / uMulti;
@@ -109,7 +109,7 @@ export default {
const part = bigInt / 10;
ctx.globalAlpha = 0.2;
ctx.strokeStyle = svgEditor.curConfig.gridColor;
ctx.strokeStyle = svgEditor.configObj.curConfig.gridColor;
for (let i = 1; i < 10; i++) {
const subD = Math.round(part * i) + 0.5;
// const lineNum = (i % 2)?12:10;
@@ -161,7 +161,7 @@ export default {
events: {
id: 'view_grid',
click () {
svgEditor.curConfig.showGrid = showGrid = !showGrid;
svgEditor.configObj.curConfig.showGrid = showGrid = !showGrid;
gridUpdate();
}
}

View File

@@ -30,7 +30,7 @@ export default {
async init ({$, importLocale}) {
const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
return {
name: strings.name,
events: [{

View File

@@ -47,7 +47,7 @@ export default {
const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const {$} = S;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const // {svgcontent} = S,
addElem = svgCanvas.addSVGElementFromJson;
const mtypes = ['start', 'mid', 'end'];

View File

@@ -25,7 +25,7 @@ export default {
async init ({$}) {
const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
// Configuration of the MathJax extention.

View File

@@ -27,7 +27,7 @@ export default {
async init ({importLocale}) {
const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const buttons = [{
id: 'ext-panning',
icon: 'panning.png',

View File

@@ -22,7 +22,7 @@ export default {
name: 'placemark',
async init (S) {
const svgEditor = this;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const addElem = svgCanvas.addSVGElementFromJson;
const {$} = S; // {svgcontent},
let

View File

@@ -22,7 +22,7 @@ export default {
name: 'polygon',
async init (S) {
const svgEditor = this;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const {$} = S, // {svgcontent}
// addElem = svgCanvas.addSVGElementFromJson,
editingitex = false;

View File

@@ -26,7 +26,7 @@ export default {
async init ({$, encode64, importLocale}) {
const svgEditor = this;
const strings = await loadExtensionTranslation(svgEditor.pref('lang'));
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const saveSvgAction = '/+modify';
// Create upload target (hidden iframe)

View File

@@ -11,7 +11,7 @@ export default {
name: 'shapes',
init ({$}) {
const svgEditor = this;
const canv = svgEditor.canvas;
const canv = svgEditor.svgCanvas;
const svgroot = canv.getRootElem();
let lastBBox = {};

View File

@@ -22,7 +22,7 @@ export default {
name: 'star',
async init (S) {
const svgEditor = this;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
const {$} = S; // {svgcontent},
let

View File

@@ -36,7 +36,7 @@ export default {
name: 'storage',
init ({$}) {
const svgEditor = this;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
// We could empty any already-set data for users when they decline storage,
// but it would be a risk for users who wanted to store but accidentally
@@ -56,7 +56,7 @@ export default {
// the "noStorageOnLoad" config setting to true in svgedit-config-*.js.
noStorageOnLoad,
forceStorage
} = svgEditor.curConfig;
} = svgEditor.configObj.curConfig;
const {storage, updateCanvas} = svgEditor;
/**
@@ -90,7 +90,7 @@ export default {
*/
function setSVGContentStorage (val) {
if (storage) {
const name = 'svgedit-' + svgEditor.curConfig.canvasName;
const name = 'svgedit-' + svgEditor.configObj.curConfig.canvasName;
if (!val) {
storage.removeItem(name);
} else {

View File

@@ -99,7 +99,7 @@ export default {
webappfind: {
type: saveMessage,
pathID,
content: svgEditor.canvas.getSvgString()
content: svgEditor.svgCanvas.getSvgString()
}
}, window.location.origin === 'null'
// Avoid "null" string error for `file:` protocol (even

View File

@@ -8,7 +8,7 @@ export default {
name: 'xdomain-messaging',
init () {
const svgEditor = this;
const svgCanvas = svgEditor.canvas;
const {svgCanvas} = svgEditor;
try {
window.addEventListener('message', function (e) {
// We accept and post strings for the sake of IE9 support
@@ -22,7 +22,7 @@ export default {
// The default is not to allow any origins, including even the same domain or
// if run on a `file:///` URL. See `svgedit-config-es.js` for an example of how
// to configure
const {allowedOrigins} = svgEditor.curConfig;
const {allowedOrigins} = svgEditor.configObj.curConfig;
if (!allowedOrigins.includes('*') && !allowedOrigins.includes(e.origin)) {
console.log(`Origin ${e.origin} not whitelisted for posting to ${window.origin}`); // eslint-disable-line no-console
return;