Remove last committed point json (#2371)
Co-authored-by: rene_mbp <harryloveslearning@googlemail.com> Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
4371c29f0c
commit
a1fbec1030
@ -6,6 +6,7 @@ import { LibraryData, ImportedDataState } from "./types";
|
|||||||
import { calculateScrollCenter } from "../scene";
|
import { calculateScrollCenter } from "../scene";
|
||||||
import { MIME_TYPES } from "../constants";
|
import { MIME_TYPES } from "../constants";
|
||||||
import { CanvasError } from "../errors";
|
import { CanvasError } from "../errors";
|
||||||
|
import { clearElementsForExport } from "../element";
|
||||||
|
|
||||||
export const parseFileContents = async (blob: Blob | File) => {
|
export const parseFileContents = async (blob: Blob | File) => {
|
||||||
let contents: string;
|
let contents: string;
|
||||||
@ -90,7 +91,7 @@ export const loadFromBlob = async (
|
|||||||
}
|
}
|
||||||
return restore(
|
return restore(
|
||||||
{
|
{
|
||||||
elements: data.elements,
|
elements: clearElementsForExport(data.elements || []),
|
||||||
appState: {
|
appState: {
|
||||||
appearance: localAppState?.appearance,
|
appearance: localAppState?.appearance,
|
||||||
fileHandle:
|
fileHandle:
|
||||||
|
@ -6,6 +6,7 @@ import { fileOpen, fileSave } from "browser-nativefs";
|
|||||||
import { loadFromBlob } from "./blob";
|
import { loadFromBlob } from "./blob";
|
||||||
import { Library } from "./library";
|
import { Library } from "./library";
|
||||||
import { MIME_TYPES } from "../constants";
|
import { MIME_TYPES } from "../constants";
|
||||||
|
import { clearElementsForExport } from "../element";
|
||||||
|
|
||||||
export const serializeAsJSON = (
|
export const serializeAsJSON = (
|
||||||
elements: readonly ExcalidrawElement[],
|
elements: readonly ExcalidrawElement[],
|
||||||
@ -16,7 +17,7 @@ export const serializeAsJSON = (
|
|||||||
type: "excalidraw",
|
type: "excalidraw",
|
||||||
version: 2,
|
version: 2,
|
||||||
source: window.location.origin,
|
source: window.location.origin,
|
||||||
elements: elements.filter((element) => !element.isDeleted),
|
elements: clearElementsForExport(elements),
|
||||||
appState: cleanAppStateForExport(appState),
|
appState: cleanAppStateForExport(appState),
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
|
@ -2,6 +2,7 @@ import { ExcalidrawElement } from "../element/types";
|
|||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { clearAppStateForLocalStorage, getDefaultAppState } from "../appState";
|
import { clearAppStateForLocalStorage, getDefaultAppState } from "../appState";
|
||||||
import { STORAGE_KEYS } from "../constants";
|
import { STORAGE_KEYS } from "../constants";
|
||||||
|
import { clearElementsForLocalStorage } from "../element";
|
||||||
|
|
||||||
export const saveUsernameToLocalStorage = (username: string) => {
|
export const saveUsernameToLocalStorage = (username: string) => {
|
||||||
try {
|
try {
|
||||||
@ -36,7 +37,7 @@ export const saveToLocalStorage = (
|
|||||||
try {
|
try {
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
|
STORAGE_KEYS.LOCAL_STORAGE_ELEMENTS,
|
||||||
JSON.stringify(elements.filter((element) => !element.isDeleted)),
|
JSON.stringify(clearElementsForLocalStorage(elements)),
|
||||||
);
|
);
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
|
STORAGE_KEYS.LOCAL_STORAGE_APP_STATE,
|
||||||
@ -60,10 +61,10 @@ export const importFromLocalStorage = () => {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let elements = [];
|
let elements: ExcalidrawElement[] = [];
|
||||||
if (savedElements) {
|
if (savedElements) {
|
||||||
try {
|
try {
|
||||||
elements = JSON.parse(savedElements);
|
elements = clearElementsForLocalStorage(JSON.parse(savedElements));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
// Do nothing because elements array is already empty
|
// Do nothing because elements array is already empty
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
NonDeleted,
|
NonDeleted,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { isInvisiblySmallElement } from "./sizeHelpers";
|
import { isInvisiblySmallElement } from "./sizeHelpers";
|
||||||
|
import { isLinearElementType } from "./typeChecks";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
newElement,
|
newElement,
|
||||||
@ -85,3 +86,20 @@ export const getNonDeletedElements = (elements: readonly ExcalidrawElement[]) =>
|
|||||||
export const isNonDeletedElement = <T extends ExcalidrawElement>(
|
export const isNonDeletedElement = <T extends ExcalidrawElement>(
|
||||||
element: T,
|
element: T,
|
||||||
): element is NonDeleted<T> => !element.isDeleted;
|
): element is NonDeleted<T> => !element.isDeleted;
|
||||||
|
|
||||||
|
const _clearElements = (
|
||||||
|
elements: readonly ExcalidrawElement[],
|
||||||
|
): ExcalidrawElement[] =>
|
||||||
|
getNonDeletedElements(elements).map((element) =>
|
||||||
|
isLinearElementType(element.type)
|
||||||
|
? { ...element, lastCommittedPoint: null }
|
||||||
|
: element,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const clearElementsForExport = (
|
||||||
|
elements: readonly ExcalidrawElement[],
|
||||||
|
) => _clearElements(elements);
|
||||||
|
|
||||||
|
export const clearElementsForLocalStorage = (
|
||||||
|
elements: readonly ExcalidrawElement[],
|
||||||
|
) => _clearElements(elements);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user