* fix issue #736

* Update ext-storage.js

* 7.1.3
master
JFH 2022-03-13 19:37:27 +01:00 committed by GitHub
parent a335e44dc8
commit ca5107f599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 57 deletions

View File

@ -1,4 +1,6 @@
# SVG-Edit CHANGES
## 7.1.3
- fix issue #736. could not move layers
## 7.1.2
- add the current document title in the toolbar
- allow user extensions to define optional parameters

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "svgedit",
"version": "7.1.2",
"version": "7.1.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "svgedit",
"version": "7.1.2",
"version": "7.1.3",
"license": "(MIT AND Apache-2.0 AND ISC AND LGPL-3.0-or-later AND X11)",
"dependencies": {
"@babel/polyfill": "7.12.1",

View File

@ -1,6 +1,6 @@
{
"name": "svgedit",
"version": "7.1.2",
"version": "7.1.3",
"description": "Powerful SVG-Editor for your browser ",
"main": "dist/Editor.js",
"module": "dist/Editor.js",

View File

@ -98,6 +98,7 @@ export default {
svgEditor.loadFromString(cached)
const name = storage.getItem(`title-${key}`) ?? 'untitled.svg'
svgEditor.topPanel.updateTitle(name)
svgEditor.layersPanel.populateLayers()
}
}

View File

@ -153,11 +153,7 @@ class LayersPanel {
index (el) {
if (!el) return -1
let i = 0
do {
i++
} while (el === el.previousElementSibling)
return i
return Array.from(document.querySelector('#layerlist tbody').children).indexOf(el)
}
/**
@ -181,12 +177,9 @@ class LayersPanel {
* @returns {void}
*/
moveLayer (pos) {
const total = this.editor.svgCanvas.getCurrentDrawing().getNumLayers()
let curIndex = (this.index(document.querySelector('#layerlist tr.layersel')) - 1)
if (curIndex > 0 || curIndex < total - 1) {
curIndex += pos
this.editor.svgCanvas.setCurrentLayerPosition(total - curIndex - 1)
const curPos = this.editor.svgCanvas.indexCurrentLayer()
if (curPos !== -1) {
this.editor.svgCanvas.setCurrentLayerPosition(curPos - pos)
this.populateLayers()
}
}

View File

@ -342,14 +342,9 @@ export class Drawing {
return null
}
let oldpos
for (oldpos = 0; oldpos < layerCount; ++oldpos) {
if (this.all_layers[oldpos] === this.current_layer) { break }
}
// some unknown error condition (current_layer not in all_layers)
if (oldpos === layerCount) { return null }
const oldpos = this.indexCurrentLayer()
if ((oldpos === -1) || (oldpos === newpos)) { return null }
if (oldpos !== newpos) {
// if our new position is below us, we need to insert before the node after newpos
const currentGroup = this.current_layer.getGroup()
const oldNextSibling = currentGroup.nextSibling
@ -373,8 +368,6 @@ export class Drawing {
oldNextSibling
}
}
return null
}
/**
* @param {module:history.HistoryRecordingService} hrService
@ -405,7 +398,7 @@ export class Drawing {
// Remove current layer's group
this.current_layer.removeGroup()
// Remove the current layer and set the previous layer as the new current layer
const index = this.all_layers.indexOf(this.current_layer)
const index = this.indexCurrentLayer()
if (index > 0) {
const name = this.current_layer.getName()
this.current_layer = this.all_layers[index - 1]
@ -451,6 +444,17 @@ export class Drawing {
return false
}
/**
* Sets the current layer. If the name is not a valid layer name, then this
* function returns `false`. Otherwise it returns `true`. This is not an
* undo-able action.
* @param {string} name - The name of the layer you want to switch to.
* @returns {boolean} `true` if the current layer was switched, otherwise `false`
*/
indexCurrentLayer () {
return this.all_layers.indexOf(this.current_layer)
}
/**
* Deletes the current layer from the drawing and then clears the selection.
* This function then calls the 'changed' handler. This is an undoable action.
@ -580,7 +584,7 @@ export class Drawing {
}
// Update layer containers and current_layer.
const index = this.all_layers.indexOf(this.current_layer)
const index = this.indexCurrentLayer()
if (index >= 0) {
this.all_layers.splice(index + 1, 0, layer)
} else {
@ -763,11 +767,20 @@ export const init = (canvas) => {
* @function module:draw.identifyLayers
* @returns {void}
*/
export const identifyLayers = function () {
export const identifyLayers = () => {
leaveContext()
svgCanvas.getCurrentDrawing().identifyLayers()
}
/**
* get current index
* @function module:draw.identifyLayers
* @returns {void}
*/
export const indexCurrentLayer = () => {
return svgCanvas.getCurrentDrawing().indexCurrentLayer()
}
/**
* Creates a new top-level layer in the drawing with the given name, sets the current layer
* to it, and then clears the selection. This function then calls the 'changed' handler.
@ -778,7 +791,7 @@ export const identifyLayers = function () {
* @fires module:svgcanvas.SvgCanvas#event:changed
* @returns {void}
*/
export const createLayer = function (name, hrService) {
export const createLayer = (name, hrService) => {
const newLayer = svgCanvas.getCurrentDrawing().createLayer(
name,
historyRecordingService(hrService)
@ -797,7 +810,7 @@ export const createLayer = function (name, hrService) {
* @fires module:svgcanvas.SvgCanvas#event:changed
* @returns {void}
*/
export const cloneLayer = function (name, hrService) {
export const cloneLayer = (name, hrService) => {
// Clone the current layer and make the cloned layer the new current layer
const newLayer = svgCanvas.getCurrentDrawing().cloneLayer(name, historyRecordingService(hrService))
@ -813,7 +826,7 @@ export const cloneLayer = function (name, hrService) {
* @fires module:svgcanvas.SvgCanvas#event:changed
* @returns {boolean} `true` if an old layer group was found to delete
*/
export const deleteCurrentLayer = function () {
export const deleteCurrentLayer = () => {
const { BatchCommand, RemoveElementCommand } = svgCanvas.history
let currentLayer = svgCanvas.getCurrentDrawing().getCurrentLayer()
const { nextSibling } = currentLayer
@ -838,7 +851,7 @@ export const deleteCurrentLayer = function () {
* @param {string} name - The name of the layer you want to switch to.
* @returns {boolean} true if the current layer was switched, otherwise false
*/
export const setCurrentLayer = function (name) {
export const setCurrentLayer = (name) => {
const result = svgCanvas.getCurrentDrawing().setCurrentLayer(toXml(name))
if (result) {
svgCanvas.clearSelection()
@ -855,7 +868,7 @@ export const setCurrentLayer = function (name) {
* @fires module:svgcanvas.SvgCanvas#event:changed
* @returns {boolean} Whether the rename succeeded
*/
export const renameCurrentLayer = function (newName) {
export const renameCurrentLayer = (newName) => {
const drawing = svgCanvas.getCurrentDrawing()
const layer = drawing.getCurrentLayer()
if (layer) {
@ -877,7 +890,7 @@ export const renameCurrentLayer = function (newName) {
* 0 and (number of layers - 1)
* @returns {boolean} `true` if the current layer position was changed, `false` otherwise.
*/
export const setCurrentLayerPosition = function (newPos) {
export const setCurrentLayerPosition = (newPos) => {
const { MoveElementCommand } = svgCanvas.history
const drawing = svgCanvas.getCurrentDrawing()
const result = drawing.setCurrentLayerPosition(newPos)
@ -896,7 +909,7 @@ export const setCurrentLayerPosition = function (newPos) {
* @param {boolean} bVisible - Whether the layer should be visible
* @returns {boolean} true if the layer's visibility was set, false otherwise
*/
export const setLayerVisibility = function (layerName, bVisible) {
export const setLayerVisibility = (layerName, bVisible) => {
const { ChangeElementCommand } = svgCanvas.history
const drawing = svgCanvas.getCurrentDrawing()
const prevVisibility = drawing.getLayerVisibility(layerName)
@ -923,7 +936,7 @@ export const setLayerVisibility = function (layerName, bVisible) {
* @param {string} layerName - The name of the layer you want to which you want to move the selected elements
* @returns {boolean} Whether the selected elements were moved to the layer.
*/
export const moveSelectedToLayer = function (layerName) {
export const moveSelectedToLayer = (layerName) => {
const { BatchCommand, MoveElementCommand } = svgCanvas.history
// find the layer
const drawing = svgCanvas.getCurrentDrawing()
@ -955,7 +968,7 @@ export const moveSelectedToLayer = function (layerName) {
* @param {module:history.HistoryRecordingService} hrService
* @returns {void}
*/
export const mergeLayer = function (hrService) {
export const mergeLayer = (hrService) => {
svgCanvas.getCurrentDrawing().mergeLayer(historyRecordingService(hrService))
svgCanvas.clearSelection()
leaveContext()
@ -967,7 +980,7 @@ export const mergeLayer = function (hrService) {
* @param {module:history.HistoryRecordingService} hrService
* @returns {void}
*/
export const mergeAllLayers = function (hrService) {
export const mergeAllLayers = (hrService) => {
svgCanvas.getCurrentDrawing().mergeAllLayers(historyRecordingService(hrService))
svgCanvas.clearSelection()
leaveContext()
@ -981,7 +994,7 @@ export const mergeAllLayers = function (hrService) {
* @fires module:svgcanvas.SvgCanvas#event:contextset
* @returns {void}
*/
export const leaveContext = function () {
export const leaveContext = () => {
const len = disabledElems.length
const dataStorage = svgCanvas.getDataStorage()
if (len) {
@ -1009,7 +1022,7 @@ export const leaveContext = function () {
* @fires module:svgcanvas.SvgCanvas#event:contextset
* @returns {void}
*/
export const setContext = function (elem) {
export const setContext = (elem) => {
const dataStorage = svgCanvas.getDataStorage()
leaveContext()
if (typeof elem === 'string') {

View File

@ -1303,6 +1303,7 @@ class SvgCanvas {
this.setCurrentLayer = draw.setCurrentLayer
this.renameCurrentLayer = draw.renameCurrentLayer
this.setCurrentLayerPosition = draw.setCurrentLayerPosition
this.indexCurrentLayer = draw.indexCurrentLayer
this.setLayerVisibility = draw.setLayerVisibility
this.moveSelectedToLayer = draw.moveSelectedToLayer
this.mergeLayer = draw.mergeLayer