remove change image and minor refactoring
parent
57c43e441f
commit
b50fe0aee1
|
@ -50,7 +50,7 @@ describe('Basic Module', function () {
|
||||||
opacity: 1
|
opacity: 1
|
||||||
},
|
},
|
||||||
initOpacity: 1,
|
initOpacity: 1,
|
||||||
imgPath: '../editor/images/',
|
imgPath: '../editor/images',
|
||||||
langPath: 'locale/',
|
langPath: 'locale/',
|
||||||
extPath: 'extensions/',
|
extPath: 'extensions/',
|
||||||
extensions: [ 'ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js' ],
|
extensions: [ 'ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js' ],
|
||||||
|
|
|
@ -37,7 +37,7 @@ const config = {
|
||||||
initStroke: { color: '000000', opacity: 1, width: 1 },
|
initStroke: { color: '000000', opacity: 1, width: 1 },
|
||||||
text: { stroke_width: 0, font_size: 24, font_family: 'serif' },
|
text: { stroke_width: 0, font_size: 24, font_family: 'serif' },
|
||||||
initOpacity: 1,
|
initOpacity: 1,
|
||||||
imgPath: '../src/editor/images/',
|
imgPath: '../src/editor/images',
|
||||||
dimensions: [ width, height ],
|
dimensions: [ width, height ],
|
||||||
baseUnit: 'px'
|
baseUnit: 'px'
|
||||||
};
|
};
|
||||||
|
|
|
@ -132,7 +132,7 @@ export default class ConfigObj {
|
||||||
no_save_warning: false,
|
no_save_warning: false,
|
||||||
// PATH CONFIGURATION
|
// PATH CONFIGURATION
|
||||||
// The following path configuration items are disallowed in the URL (as should any future path configurations)
|
// The following path configuration items are disallowed in the URL (as should any future path configurations)
|
||||||
imgPath: './images/',
|
imgPath: './images',
|
||||||
// DOCUMENT PROPERTIES
|
// DOCUMENT PROPERTIES
|
||||||
// Change the following to a preference (already in the Document Properties dialog)?
|
// Change the following to a preference (already in the Document Properties dialog)?
|
||||||
dimensions: [ 640, 480 ],
|
dimensions: [ 640, 480 ],
|
||||||
|
|
|
@ -399,46 +399,6 @@ class Editor extends EditorStartup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a selected image's URL.
|
|
||||||
* @function module:SVGthis.setImageURL
|
|
||||||
* @param {string} url
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
setImageURL(url) {
|
|
||||||
if (!url) {
|
|
||||||
url = this.defaultImageURL;
|
|
||||||
}
|
|
||||||
this.svgCanvas.setImageURL(url);
|
|
||||||
$id("image_url").value = url;
|
|
||||||
|
|
||||||
if (url.startsWith('data:')) {
|
|
||||||
// data URI found
|
|
||||||
$id("image_url").style.display = 'none';
|
|
||||||
$id("change_image_url").style.display = 'block';
|
|
||||||
} else {
|
|
||||||
// regular URL
|
|
||||||
const self = this;
|
|
||||||
const promised = this.svgCanvas.embedImage(url);
|
|
||||||
// eslint-disable-next-line promise/catch-or-return
|
|
||||||
promised
|
|
||||||
.then( function (dataURI) {
|
|
||||||
// eslint-disable-next-line promise/always-return
|
|
||||||
$id('url_notice').style.display = (!dataURI) ? 'block' : 'none';
|
|
||||||
// switch into "select" mode if we've clicked on an element
|
|
||||||
self.svgCanvas.setMode('select');
|
|
||||||
self.svgCanvas.selectOnly(self.svgCanvas.getSelectedElems(), true);
|
|
||||||
}, function (error) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log("error =", error);
|
|
||||||
seAlert(self.i18next.t('tools.no_embed'));
|
|
||||||
self.svgCanvas.deleteSelectedElements();
|
|
||||||
});
|
|
||||||
$id("image_url").style.display = 'block';
|
|
||||||
$id("change_image_url").style.display = 'none';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {string} color
|
* @param {string} color
|
||||||
|
@ -930,7 +890,7 @@ class Editor extends EditorStartup {
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line class-methods-use-this
|
// eslint-disable-next-line class-methods-use-this
|
||||||
hideSourceEditor() {
|
hideSourceEditor() {
|
||||||
const $editorDialog = document.getElementById('se-svg-editor-dialog');
|
const $editorDialog = $id('se-svg-editor-dialog');
|
||||||
$editorDialog.setAttribute('dialog', 'closed');
|
$editorDialog.setAttribute('dialog', 'closed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,7 +899,7 @@ class Editor extends EditorStartup {
|
||||||
* @returns {void} Resolves to `undefined`
|
* @returns {void} Resolves to `undefined`
|
||||||
*/
|
*/
|
||||||
async saveSourceEditor(e) {
|
async saveSourceEditor(e) {
|
||||||
const $editorDialog = document.getElementById('se-svg-editor-dialog');
|
const $editorDialog = $id('se-svg-editor-dialog');
|
||||||
if ($editorDialog.getAttribute('dialog') !== 'open') return;
|
if ($editorDialog.getAttribute('dialog') !== 'open') return;
|
||||||
const saveChanges = () => {
|
const saveChanges = () => {
|
||||||
this.svgCanvas.clearSelection();
|
this.svgCanvas.clearSelection();
|
||||||
|
@ -967,7 +927,7 @@ class Editor extends EditorStartup {
|
||||||
*/
|
*/
|
||||||
cancelOverlays(e) {
|
cancelOverlays(e) {
|
||||||
if ($id("dialog_box") != null) $id("dialog_box").style.display = 'none';
|
if ($id("dialog_box") != null) $id("dialog_box").style.display = 'none';
|
||||||
const $editorDialog = document.getElementById('se-svg-editor-dialog');
|
const $editorDialog = $id('se-svg-editor-dialog');
|
||||||
const editingsource = $editorDialog.getAttribute('dialog') === 'open';
|
const editingsource = $editorDialog.getAttribute('dialog') === 'open';
|
||||||
if (!editingsource && !this.docprops && !this.configObj.preferences) {
|
if (!editingsource && !this.docprops && !this.configObj.preferences) {
|
||||||
if (this.curContext) {
|
if (this.curContext) {
|
||||||
|
@ -1058,7 +1018,7 @@ class Editor extends EditorStartup {
|
||||||
setLang(lang) {
|
setLang(lang) {
|
||||||
this.langChanged = true;
|
this.langChanged = true;
|
||||||
this.configObj.pref('lang', lang);
|
this.configObj.pref('lang', lang);
|
||||||
const $editDialog = document.getElementById('se-edit-prefs');
|
const $editDialog = $id('se-edit-prefs');
|
||||||
$editDialog.setAttribute('lang', lang);
|
$editDialog.setAttribute('lang', lang);
|
||||||
const oldLayerName = ($id('#layerlist')) ? $id('#layerlist').querySelector('tr.layersel td.layername').textContent : "";
|
const oldLayerName = ($id('#layerlist')) ? $id('#layerlist').querySelector('tr.layersel td.layername').textContent : "";
|
||||||
const renameLayer = (oldLayerName === this.i18next.t('notification.common.layer') + ' 1');
|
const renameLayer = (oldLayerName === this.i18next.t('notification.common.layer') + ' 1');
|
||||||
|
|
|
@ -262,9 +262,6 @@ class EditorStartup {
|
||||||
addListenerMulti($id('text'), 'keyup input', (evt) => {
|
addListenerMulti($id('text'), 'keyup input', (evt) => {
|
||||||
this.svgCanvas.setTextContent(evt.currentTarget.value);
|
this.svgCanvas.setTextContent(evt.currentTarget.value);
|
||||||
});
|
});
|
||||||
$id('image_url').addEventListener('change', (evt) => {
|
|
||||||
this.setImageURL(evt.currentTarget.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
$id('link_url').addEventListener('change', (evt) => {
|
$id('link_url').addEventListener('change', (evt) => {
|
||||||
if (evt.currentTarget.value.length) {
|
if (evt.currentTarget.value.length) {
|
||||||
|
@ -416,10 +413,6 @@ class EditorStartup {
|
||||||
this.rulers.manageScroll();
|
this.rulers.manageScroll();
|
||||||
});
|
});
|
||||||
|
|
||||||
$id('url_notice').addEventListener('click', () => {
|
|
||||||
seAlert(this.title);
|
|
||||||
});
|
|
||||||
|
|
||||||
$id('stroke_width').value = this.configObj.curConfig.initStroke.width;
|
$id('stroke_width').value = this.configObj.curConfig.initStroke.width;
|
||||||
$id('opacity').value = this.configObj.curConfig.initOpacity * 100;
|
$id('opacity').value = this.configObj.curConfig.initOpacity * 100;
|
||||||
const elements = document.getElementsByClassName("push_button");
|
const elements = document.getElementsByClassName("push_button");
|
||||||
|
@ -598,12 +591,12 @@ class EditorStartup {
|
||||||
*/
|
*/
|
||||||
const editorObj = this;
|
const editorObj = this;
|
||||||
const importImage = function (e) {
|
const importImage = function (e) {
|
||||||
document.getElementById('se-prompt-dialog').title = editorObj.i18next.t('notification.loadingImage');
|
$id('se-prompt-dialog').title = editorObj.i18next.t('notification.loadingImage');
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const file = (e.type === 'drop') ? e.dataTransfer.files[0] : this.files[0];
|
const file = (e.type === 'drop') ? e.dataTransfer.files[0] : this.files[0];
|
||||||
if (!file) {
|
if (!file) {
|
||||||
document.getElementById('se-prompt-dialog').setAttribute('close', true);
|
$id('se-prompt-dialog').setAttribute('close', true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,7 +617,7 @@ class EditorStartup {
|
||||||
editorObj.svgCanvas.alignSelectedElements('c', 'page');
|
editorObj.svgCanvas.alignSelectedElements('c', 'page');
|
||||||
// highlight imported element, otherwise we get strange empty selectbox
|
// highlight imported element, otherwise we get strange empty selectbox
|
||||||
editorObj.svgCanvas.selectOnly([ newElement ]);
|
editorObj.svgCanvas.selectOnly([ newElement ]);
|
||||||
document.getElementById('se-prompt-dialog').setAttribute('close', true);
|
$id('se-prompt-dialog').setAttribute('close', true);
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
} else {
|
} else {
|
||||||
|
@ -654,7 +647,7 @@ class EditorStartup {
|
||||||
editorObj.svgCanvas.alignSelectedElements('m', 'page');
|
editorObj.svgCanvas.alignSelectedElements('m', 'page');
|
||||||
editorObj.svgCanvas.alignSelectedElements('c', 'page');
|
editorObj.svgCanvas.alignSelectedElements('c', 'page');
|
||||||
editorObj.topPanel.updateContextPanel();
|
editorObj.topPanel.updateContextPanel();
|
||||||
document.getElementById('se-prompt-dialog').setAttribute('close', true);
|
$id('se-prompt-dialog').setAttribute('close', true);
|
||||||
};
|
};
|
||||||
// create dummy img so we know the default dimensions
|
// create dummy img so we know the default dimensions
|
||||||
let imgWidth = 100;
|
let imgWidth = 100;
|
||||||
|
|
|
@ -45,7 +45,7 @@ class MainMenu {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
hideDocProperties() {
|
hideDocProperties() {
|
||||||
const $imgDialog = document.getElementById("se-img-prop");
|
const $imgDialog = $id("se-img-prop");
|
||||||
$imgDialog.setAttribute("dialog", "close");
|
$imgDialog.setAttribute("dialog", "close");
|
||||||
$imgDialog.setAttribute("save", this.editor.configObj.pref("img_save"));
|
$imgDialog.setAttribute("save", this.editor.configObj.pref("img_save"));
|
||||||
this.editor.docprops = false;
|
this.editor.docprops = false;
|
||||||
|
@ -56,7 +56,7 @@ class MainMenu {
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
hidePreferences() {
|
hidePreferences() {
|
||||||
const $editDialog = document.getElementById("se-edit-prefs");
|
const $editDialog = $id("se-edit-prefs");
|
||||||
$editDialog.setAttribute("dialog", "close");
|
$editDialog.setAttribute("dialog", "close");
|
||||||
this.editor.configObj.preferences = false;
|
this.editor.configObj.preferences = false;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ class MainMenu {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.editor.docprops = true;
|
this.editor.docprops = true;
|
||||||
const $imgDialog = document.getElementById("se-img-prop");
|
const $imgDialog = $id("se-img-prop");
|
||||||
|
|
||||||
// update resolution option with actual resolution
|
// update resolution option with actual resolution
|
||||||
const resolution = this.editor.svgCanvas.getResolution();
|
const resolution = this.editor.svgCanvas.getResolution();
|
||||||
|
@ -264,7 +264,7 @@ class MainMenu {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.editor.configObj.preferences = true;
|
this.editor.configObj.preferences = true;
|
||||||
const $editDialog = document.getElementById("se-edit-prefs");
|
const $editDialog = $id("se-edit-prefs");
|
||||||
// Update background color with current one
|
// Update background color with current one
|
||||||
const canvasBg = this.editor.configObj.curPrefs.bkgd_color;
|
const canvasBg = this.editor.configObj.curPrefs.bkgd_color;
|
||||||
const url = this.editor.configObj.pref("bkgd_url");
|
const url = this.editor.configObj.pref("bkgd_url");
|
||||||
|
@ -337,7 +337,7 @@ class MainMenu {
|
||||||
$id("tool_save").addEventListener(
|
$id("tool_save").addEventListener(
|
||||||
"click",
|
"click",
|
||||||
function() {
|
function() {
|
||||||
const $editorDialog = document.getElementById("se-svg-editor-dialog");
|
const $editorDialog = $id("se-svg-editor-dialog");
|
||||||
const editingsource = $editorDialog.getAttribute("dialog") === "open";
|
const editingsource = $editorDialog.getAttribute("dialog") === "open";
|
||||||
if (editingsource) {
|
if (editingsource) {
|
||||||
this.saveSourceEditor();
|
this.saveSourceEditor();
|
||||||
|
|
|
@ -217,7 +217,7 @@ export default {
|
||||||
);
|
);
|
||||||
dataStorage.put(ethis, 'c_' + pos, part.id);
|
dataStorage.put(ethis, 'c_' + pos, part.id);
|
||||||
dataStorage.put(ethis, pos + '_bb', svgCanvas.getStrokedBBox([ part ]));
|
dataStorage.put(ethis, pos + '_bb', svgCanvas.getStrokedBBox([ part ]));
|
||||||
} else part = document.getElementById(part);
|
} else part = $id(part);
|
||||||
parts.push(part);
|
parts.push(part);
|
||||||
}, ethis);
|
}, ethis);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default {
|
||||||
await loadExtensionTranslation(svgEditor);
|
await loadExtensionTranslation(svgEditor);
|
||||||
const { svgCanvas } = svgEditor;
|
const { svgCanvas } = svgEditor;
|
||||||
const { $id } = svgCanvas;
|
const { $id } = svgCanvas;
|
||||||
const svgdoc = document.getElementById('svgcanvas').ownerDocument;
|
const svgdoc = $id('svgcanvas').ownerDocument;
|
||||||
const { assignAttributes } = svgCanvas;
|
const { assignAttributes } = svgCanvas;
|
||||||
const hcanvas = document.createElement('canvas');
|
const hcanvas = document.createElement('canvas');
|
||||||
const canvBG = $id('canvasBackground');
|
const canvBG = $id('canvasBackground');
|
||||||
|
@ -154,7 +154,7 @@ export default {
|
||||||
updateGrid(svgCanvas.getZoom());
|
updateGrid(svgCanvas.getZoom());
|
||||||
}
|
}
|
||||||
$id('canvasGrid').style.display = (showGrid) ? 'block' : 'none';
|
$id('canvasGrid').style.display = (showGrid) ? 'block' : 'none';
|
||||||
document.getElementById('view_grid').pressed = showGrid;
|
$id('view_grid').pressed = showGrid;
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
name: svgEditor.i18next.t(`${name}:name`),
|
name: svgEditor.i18next.t(`${name}:name`),
|
||||||
|
|
|
@ -71,12 +71,12 @@ export default {
|
||||||
$id("overview_window_view_box").style.top = viewBoxY + 'px';
|
$id("overview_window_view_box").style.top = viewBoxY + 'px';
|
||||||
$id("overview_window_view_box").style.left = viewBoxX + 'px';
|
$id("overview_window_view_box").style.left = viewBoxX + 'px';
|
||||||
};
|
};
|
||||||
document.getElementById('workarea').addEventListener('scroll', () => {
|
$id('workarea').addEventListener('scroll', () => {
|
||||||
if (!(overviewWindowGlobals.viewBoxDragging)) {
|
if (!(overviewWindowGlobals.viewBoxDragging)) {
|
||||||
updateViewBox();
|
updateViewBox();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.getElementById('workarea').addEventListener('resize', updateViewBox);
|
$id('workarea').addEventListener('resize', updateViewBox);
|
||||||
updateViewBox();
|
updateViewBox();
|
||||||
|
|
||||||
// Compensate for changes in zoom and canvas size.
|
// Compensate for changes in zoom and canvas size.
|
||||||
|
|
|
@ -258,9 +258,9 @@ export default {
|
||||||
cy: opts.start_y,
|
cy: opts.start_y,
|
||||||
id: svgCanvas.getNextId(),
|
id: svgCanvas.getNextId(),
|
||||||
shape: "star",
|
shape: "star",
|
||||||
point: document.getElementById("starNumPoints").value,
|
point: $id("starNumPoints").value,
|
||||||
r: 0,
|
r: 0,
|
||||||
radialshift: document.getElementById("radialShift").value,
|
radialshift: $id("radialShift").value,
|
||||||
r2: 0,
|
r2: 0,
|
||||||
orient: "point",
|
orient: "point",
|
||||||
fill: rgb,
|
fill: rgb,
|
||||||
|
@ -287,7 +287,7 @@ export default {
|
||||||
cy: opts.start_y,
|
cy: opts.start_y,
|
||||||
id: svgCanvas.getNextId(),
|
id: svgCanvas.getNextId(),
|
||||||
shape: "regularPoly",
|
shape: "regularPoly",
|
||||||
sides: document.getElementById("polySides").value,
|
sides: $id("polySides").value,
|
||||||
orient: "x",
|
orient: "x",
|
||||||
edge: 0,
|
edge: 0,
|
||||||
fill: rgb,
|
fill: rgb,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* globals seAlert */
|
||||||
|
|
||||||
import SvgCanvas from "../../svgcanvas/svgcanvas.js";
|
import SvgCanvas from "../../svgcanvas/svgcanvas.js";
|
||||||
import { isValidUnit, getTypeMap, convertUnit } from "../../common/units.js";
|
import { isValidUnit, getTypeMap, convertUnit } from "../../common/units.js";
|
||||||
|
|
||||||
|
@ -16,6 +18,19 @@ class TopPanel {
|
||||||
constructor(editor) {
|
constructor(editor) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @type {module}
|
||||||
|
*/
|
||||||
|
displayTool(id) {
|
||||||
|
// default display is 'none' so removing the property will make the panel visible
|
||||||
|
$id(id).style.removeProperty('display');
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @type {module}
|
||||||
|
*/
|
||||||
|
hideTool(id) {
|
||||||
|
$id(id).style.display = 'none';
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @type {module}
|
* @type {module}
|
||||||
*/
|
*/
|
||||||
|
@ -119,10 +134,7 @@ class TopPanel {
|
||||||
(this.selectedElement.getAttribute("opacity") || 1.0) * 100;
|
(this.selectedElement.getAttribute("opacity") || 1.0) * 100;
|
||||||
$id("opacity").value = opacPerc;
|
$id("opacity").value = opacPerc;
|
||||||
$id("elem_id").value = this.selectedElement.id;
|
$id("elem_id").value = this.selectedElement.id;
|
||||||
$id("elem_class").value =
|
$id("elem_class").value = this.selectedElement.getAttribute("class") ?? "";
|
||||||
this.selectedElement.getAttribute("class") !== null
|
|
||||||
? this.selectedElement.getAttribute("class")
|
|
||||||
: "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.editor.bottomPanel.updateToolButtonState();
|
this.editor.bottomPanel.updateToolButtonState();
|
||||||
|
@ -141,7 +153,7 @@ class TopPanel {
|
||||||
curhref
|
curhref
|
||||||
);
|
);
|
||||||
if (url) {
|
if (url) {
|
||||||
this.editor.setImageURL(url);
|
this.setImageURL(url);
|
||||||
} else if (cancelDeletes) {
|
} else if (cancelDeletes) {
|
||||||
this.editor.svgCanvas.deleteSelectedElements();
|
this.editor.svgCanvas.deleteSelectedElements();
|
||||||
}
|
}
|
||||||
|
@ -167,19 +179,19 @@ class TopPanel {
|
||||||
|
|
||||||
const isNode = currentMode === "pathedit"; // elem ? (elem.id && elem.id.startsWith('pathpointgrip')) : false;
|
const isNode = currentMode === "pathedit"; // elem ? (elem.id && elem.id.startsWith('pathpointgrip')) : false;
|
||||||
const menuItems = document.getElementById("se-cmenu_canvas");
|
const menuItems = document.getElementById("se-cmenu_canvas");
|
||||||
$id("selected_panel").style.display = 'none';
|
this.hideTool("selected_panel");
|
||||||
$id("multiselected_panel").style.display = 'none';
|
this.hideTool("multiselected_panel");
|
||||||
$id("g_panel").style.display = 'none';
|
this.hideTool("g_panel");
|
||||||
$id("rect_panel").style.display = 'none';
|
this.hideTool("rect_panel");
|
||||||
$id("circle_panel").style.display = 'none';
|
this.hideTool("circle_panel");
|
||||||
$id("ellipse_panel").style.display = 'none';
|
this.hideTool("ellipse_panel");
|
||||||
$id("line_panel").style.display = 'none';
|
this.hideTool("line_panel");
|
||||||
$id("text_panel").style.display = 'none';
|
this.hideTool("text_panel");
|
||||||
$id("image_panel").style.display = 'none';
|
this.hideTool("image_panel");
|
||||||
$id("container_panel").style.display = 'none';
|
this.hideTool("container_panel");
|
||||||
$id("use_panel").style.display = 'none';
|
this.hideTool("use_panel");
|
||||||
$id("a_panel").style.display = 'none';
|
this.hideTool("a_panel");
|
||||||
if (!isNullish(elem)) {
|
if (elem) {
|
||||||
const elname = elem.nodeName;
|
const elname = elem.nodeName;
|
||||||
|
|
||||||
const angle = this.editor.svgCanvas.getRotationAngle(elem);
|
const angle = this.editor.svgCanvas.getRotationAngle(elem);
|
||||||
|
@ -198,10 +210,10 @@ class TopPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNode && currentMode !== "pathedit") {
|
if (!isNode && currentMode !== "pathedit") {
|
||||||
$id("selected_panel").style.removeProperty('display');
|
this.displayTool("selected_panel");
|
||||||
// Elements in this array already have coord fields
|
// Elements in this array already have coord fields
|
||||||
if ([ "line", "circle", "ellipse" ].includes(elname)) {
|
if ([ "line", "circle", "ellipse" ].includes(elname)) {
|
||||||
$id("xy_panel").style.display = 'none';
|
this.hideTool("xy_panel");
|
||||||
} else {
|
} else {
|
||||||
let x; let y;
|
let x; let y;
|
||||||
|
|
||||||
|
@ -223,20 +235,26 @@ class TopPanel {
|
||||||
|
|
||||||
$id("selected_x").value = (x || 0);
|
$id("selected_x").value = (x || 0);
|
||||||
$id("selected_y").value = (y || 0);
|
$id("selected_y").value = (y || 0);
|
||||||
$id("xy_panel").style.removeProperty('display');
|
this.displayTool("xy_panel");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Elements in this array cannot be converted to a path
|
// Elements in this array cannot be converted to a path
|
||||||
$id("tool_topath").style.display = [
|
if ([
|
||||||
"image",
|
"image",
|
||||||
"text",
|
"text",
|
||||||
"path",
|
"path",
|
||||||
"g",
|
"g",
|
||||||
"use"
|
"use"
|
||||||
].includes(elname)
|
].includes(elname)) {
|
||||||
? "none"
|
this.hideTool("tool_topath");
|
||||||
: "block";
|
} else {
|
||||||
$id("tool_reorient").style.display = (elname === "path") ? "block" : "none";
|
this.displayTool("tool_topath");
|
||||||
|
}
|
||||||
|
if (elname === "path") {
|
||||||
|
this.displayTool("tool_reorient");
|
||||||
|
} else {
|
||||||
|
this.hideTool("tool_reorient");
|
||||||
|
}
|
||||||
$id("tool_reorient").disabled = (angle === 0);
|
$id("tool_reorient").disabled = (angle === 0);
|
||||||
} else {
|
} else {
|
||||||
const point = this.path.getNodePoint();
|
const point = this.path.getNodePoint();
|
||||||
|
@ -284,7 +302,7 @@ class TopPanel {
|
||||||
let linkHref = null;
|
let linkHref = null;
|
||||||
if (tagName === "a") {
|
if (tagName === "a") {
|
||||||
linkHref = this.editor.svgCanvas.getHref(elem);
|
linkHref = this.editor.svgCanvas.getHref(elem);
|
||||||
$id("g_panel").style.removeProperty('display');
|
this.displayTool("g_panel");
|
||||||
}
|
}
|
||||||
// siblings
|
// siblings
|
||||||
if (elem.parentNode) {
|
if (elem.parentNode) {
|
||||||
|
@ -292,22 +310,24 @@ class TopPanel {
|
||||||
return child !== elem;
|
return child !== elem;
|
||||||
});
|
});
|
||||||
if (elem.parentNode.tagName === "a" && !selements.length) {
|
if (elem.parentNode.tagName === "a" && !selements.length) {
|
||||||
$id("a_panel").style.removeProperty('display');
|
this.displayTool("a_panel");
|
||||||
linkHref = this.editor.svgCanvas.getHref(elem.parentNode);
|
linkHref = this.editor.svgCanvas.getHref(elem.parentNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide/show the make_link buttons
|
// Hide/show the make_link buttons
|
||||||
$id('tool_make_link').style.display = (!linkHref) ? 'block' : 'none';
|
|
||||||
$id('tool_make_link_multi').style.display = (!linkHref) ? 'block' : 'none';
|
|
||||||
|
|
||||||
if (linkHref) {
|
if (linkHref) {
|
||||||
|
this.displayTool('tool_make_link');
|
||||||
|
this.displayTool('tool_make_link_multi');
|
||||||
$id("link_url").value = linkHref;
|
$id("link_url").value = linkHref;
|
||||||
|
} else {
|
||||||
|
this.hideTool('tool_make_link');
|
||||||
|
this.hideTool('tool_make_link_multi');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panels[tagName]) {
|
if (panels[tagName]) {
|
||||||
const curPanel = panels[tagName];
|
const curPanel = panels[tagName];
|
||||||
$id(tagName + "_panel").style.removeProperty('display');
|
this.displayTool(tagName + "_panel");
|
||||||
|
|
||||||
curPanel.forEach((item) => {
|
curPanel.forEach((item) => {
|
||||||
let attrVal = elem.getAttribute(item);
|
let attrVal = elem.getAttribute(item);
|
||||||
|
@ -319,7 +339,7 @@ class TopPanel {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tagName === "text") {
|
if (tagName === "text") {
|
||||||
$id("text_panel").style.removeProperty('display');
|
this.displayTool("text_panel");
|
||||||
$id("tool_italic").pressed = this.editor.svgCanvas.getItalic();
|
$id("tool_italic").pressed = this.editor.svgCanvas.getItalic();
|
||||||
$id("tool_bold").pressed = this.editor.svgCanvas.getBold();
|
$id("tool_bold").pressed = this.editor.svgCanvas.getBold();
|
||||||
$id("tool_font_family").value = elem.getAttribute("font-family");
|
$id("tool_font_family").value = elem.getAttribute("font-family");
|
||||||
|
@ -362,7 +382,7 @@ class TopPanel {
|
||||||
);
|
);
|
||||||
// image
|
// image
|
||||||
} else if (tagName === "g" || tagName === "use") {
|
} else if (tagName === "g" || tagName === "use") {
|
||||||
$id("container_panel").style.removeProperty('display');
|
this.displayTool("container_panel");
|
||||||
const title = this.editor.svgCanvas.getTitle();
|
const title = this.editor.svgCanvas.getTitle();
|
||||||
const label = $id("g_title");
|
const label = $id("g_title");
|
||||||
label.value = title;
|
label.value = title;
|
||||||
|
@ -381,7 +401,7 @@ class TopPanel {
|
||||||
|
|
||||||
// if (!isNullish(elem))
|
// if (!isNullish(elem))
|
||||||
} else if (this.multiselected) {
|
} else if (this.multiselected) {
|
||||||
$id("multiselected_panel").style.removeProperty('display');
|
this.displayTool("multiselected_panel");
|
||||||
menuItems.setAttribute("enablemenuitems", "#group");
|
menuItems.setAttribute("enablemenuitems", "#group");
|
||||||
menuItems.setAttribute("disablemenuitems", "#ungroup");
|
menuItems.setAttribute("disablemenuitems", "#ungroup");
|
||||||
} else {
|
} else {
|
||||||
|
@ -733,6 +753,42 @@ class TopPanel {
|
||||||
this.updateContextPanel();
|
this.updateContextPanel();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Set a selected image's URL.
|
||||||
|
* @function module:SVGthis.setImageURL
|
||||||
|
* @param {string} url
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
setImageURL(url) {
|
||||||
|
const { editor } = this;
|
||||||
|
if (!url) {
|
||||||
|
url = editor.defaultImageURL;
|
||||||
|
}
|
||||||
|
editor.svgCanvas.setImageURL(url);
|
||||||
|
$id("image_url").value = url;
|
||||||
|
|
||||||
|
if (url.startsWith('data:')) {
|
||||||
|
// data URI found
|
||||||
|
this.hideTool("image_url");
|
||||||
|
} else {
|
||||||
|
// regular URL
|
||||||
|
const promised = editor.svgCanvas.embedImage(url);
|
||||||
|
// eslint-disable-next-line promise/catch-or-return
|
||||||
|
promised
|
||||||
|
// eslint-disable-next-line promise/always-return
|
||||||
|
.then(() => {
|
||||||
|
// switch into "select" mode if we've clicked on an element
|
||||||
|
editor.svgCanvas.setMode('select');
|
||||||
|
editor.svgCanvas.selectOnly(editor.svgCanvas.getSelectedElems(), true);
|
||||||
|
}, (error) => {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log("error =", error);
|
||||||
|
seAlert(editor.i18next.t('tools.no_embed'));
|
||||||
|
editor.svgCanvas.deleteSelectedElements();
|
||||||
|
});
|
||||||
|
this.displayTool("image_url");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {module}
|
* @type {module}
|
||||||
|
@ -866,14 +922,7 @@ class TopPanel {
|
||||||
title="${i18next.t('properties.image_height')}"></se-spin-input>
|
title="${i18next.t('properties.image_height')}"></se-spin-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="toolset">
|
<div class="toolset">
|
||||||
<label id="tool_image_url">url:
|
<se-input id="image_url" data-attr="image_url" size="15" label="${i18next.t('properties.image_url')}"></se-input>
|
||||||
<input id="image_url" type="text" title="${i18next.t('properties.image_url')}" size="35" />
|
|
||||||
</label>
|
|
||||||
<label id="tool_change_image">
|
|
||||||
<button id="change_image_url" style="display: none;">Change Image</button>
|
|
||||||
<span id="url_notice"
|
|
||||||
title="${i18next.t('tools.no_embed')}"></span>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div> <!-- image_panel -->
|
</div> <!-- image_panel -->
|
||||||
<div id="circle_panel">
|
<div id="circle_panel">
|
||||||
|
@ -1098,10 +1147,10 @@ class TopPanel {
|
||||||
"click",
|
"click",
|
||||||
this.clickGroup.bind(this)
|
this.clickGroup.bind(this)
|
||||||
);
|
);
|
||||||
$id("change_image_url").addEventListener(
|
$id('image_url').addEventListener('change', (evt) => {
|
||||||
"click",
|
this.setImageURL(evt.currentTarget.value);
|
||||||
this.promptImgURL.bind(this)
|
});
|
||||||
);
|
|
||||||
// all top panel attributes
|
// all top panel attributes
|
||||||
[
|
[
|
||||||
"elem_id",
|
"elem_id",
|
||||||
|
|
|
@ -520,11 +520,6 @@ input[type=text] {
|
||||||
left: -9999px;
|
left: -9999px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#url_notice {
|
|
||||||
padding-top: 4px;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bottom-icon {
|
.bottom-icon {
|
||||||
width: 22px;
|
width: 22px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue