Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export scene to clipboard or json to save locally which can be imported later #61

Merged
merged 7 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: save pasted elements structure
  • Loading branch information
nagy-nabil committed Sep 7, 2023
commit 65d961bdfe11caf7da09ec39c2003f60f3fa153a
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root = true

[*]
indent_style = spaces
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"trailingComma": "es5",
"trailingComma": "all",
"semi": true,
"singleQuote": false,
"tabWidth": 4,
Expand Down
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<link rel="icon" type="image/svg+xml" href="/src/public/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Zagydraw | The whiteboarding app</title>
<link rel="preload" as="font" href="/src/assets/fonts/FiraCode-VariableFont_wght.ttf" />
<link rel="preload" as="font" href="/src/assets/fonts/GochiHand-Regular.ttf" />
<link rel="preload" as="font" href="/src/assets/fonts/PressStart2P-Regular.ttf" />
</head>
<body>
<div id="root">
Expand Down
5 changes: 1 addition & 4 deletions src/actions/ExportScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { isText } from "@/types/general";
import { ZagyCanvasTextElement } from "@/types/general";
import { isHanddrawn } from "@/types/general";
import { ZagyCanvasHandDrawnElement } from "@/types/general";
import { getBoundingRect } from "@/utils";

export const DestOpts = {
CLIPBOARD: 0,
Expand Down Expand Up @@ -78,7 +77,6 @@ export class ActionExportScene extends Command {
return {
...baseTemp,
shape: el.shape,
path2D: el.path2D,
paths: el.paths,
options: el.options,
} satisfies CleanedElement<ZagyCanvasHandDrawnElement> as unknown as CleanedElement<T>;
Expand All @@ -98,14 +96,13 @@ export class ActionExportScene extends Command {
// choose which items to clean up
if (this.onlySelected) {
selectedElements.forEach((el) =>
portable.elements.push(ActionExportScene.cleanupItem(el))
portable.elements.push(ActionExportScene.cleanupItem(el)),
);
} else {
elements.forEach((el) => portable.elements.push(ActionExportScene.cleanupItem(el)));
}
// don't copy dump text into the user clipboard if there's no data to copy
if (portable.elements.length === 0) return;
console.log("copied bounding rect", getBoundingRect(...portable.elements));
// choose export mechanism
if (this.dest === DestOpts.CLIPBOARD) {
await navigator.clipboard.writeText(JSON.stringify(portable));
Expand Down
113 changes: 0 additions & 113 deletions src/actions/copySelected.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/actions/createText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TextAction {
}
private static _inProgress(
textAreaWrapper: HTMLDivElement | null,
textArea: HTMLTextAreaElement | null
textArea: HTMLTextAreaElement | null,
) {
const { cursorFn, zoomLevel } = useStore.getState();
if (!textAreaWrapper || !textArea || cursorFn !== CursorFn.Text) return;
Expand Down Expand Up @@ -58,7 +58,7 @@ class TextAction {

public static end(
canvas: HTMLCanvasElement | null,
textArea: HTMLTextAreaElement | null
textArea: HTMLTextAreaElement | null,
): UndoableCommand | null {
let element: ZagyCanvasElement | null = null;
const { cursorFn } = useStore.getState();
Expand Down
2 changes: 1 addition & 1 deletion src/actions/cutSelected.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionDeleteSelected } from "./deleteSelected";
import { ActionExportScene, DestOpts } from "./copySelected";
import { ActionExportScene, DestOpts } from "./ExportScene";
import { UndoableCommand } from "./types";

export class ActionCutSelected extends UndoableCommand {
Expand Down
4 changes: 2 additions & 2 deletions src/actions/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeleteAction {
if (el !== null) {
this.willDelete = true;
setElements((prev) =>
prev.map((val) => (val.id === el.id ? { ...val, willDelete: true } : val))
prev.map((val) => (val.id === el.id ? { ...val, willDelete: true } : val)),
);
}
}
Expand All @@ -42,7 +42,7 @@ class DeleteAction {
!(
val.shape === "image" &&
(val as ZagyCanvasImageElement).imgRef instanceof Promise
)
),
)
.map((val) => ({ ...val, willDelete: false }));
if (deletedElements.length === 0) return null;
Expand Down
2 changes: 1 addition & 1 deletion src/actions/deleteSelected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ActionDeleteSelected extends UndoableCommand {
!(
itm.shape === "image" &&
(itm as ZagyCanvasImageElement).imgRef instanceof Promise
)
),
);
// remove any elements that exist on selected elements array
// create hash of ids for easy check while filtring the elements
Expand Down
10 changes: 5 additions & 5 deletions src/actions/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ class DrawAction {
this.roughGenerator,
this.lastMouseDownPosition,
this.lastMouseUpPosition,
{ seed: this.currentSeed }
{ seed: this.currentSeed },
);
setPreviewElement(rect);
} else if (cursorFn === CursorFn.Line) {
const line: ZagyCanvasLineElement = generateLineElement(
this.roughGenerator,
this.lastMouseDownPosition,
this.lastMouseUpPosition,
{ seed: this.currentSeed }
{ seed: this.currentSeed },
);
setPreviewElement(line);
} else if (cursorFn === CursorFn.FreeDraw) {
Expand Down Expand Up @@ -113,7 +113,7 @@ class DrawAction {
this.lastMouseDownPosition,
this.lastMouseUpPosition,
zoomLevel,
{ seed: this.currentSeed }
{ seed: this.currentSeed },
);
el = line;
this.currentSeed = randomSeed();
Expand All @@ -123,7 +123,7 @@ class DrawAction {
this.lastMouseDownPosition,
this.lastMouseUpPosition,
zoomLevel,
{ seed: this.currentSeed }
{ seed: this.currentSeed },
);
if (rect.endX - rect.x < 10 || rect.endY - rect.y < 10) return;

Expand All @@ -132,7 +132,7 @@ class DrawAction {
} else if (cursorFn === CursorFn.FreeDraw) {
const handDrawnElement = generateCachedHandDrawnElement(
this.currentlyDrawnFreeHand,
zoomLevel
zoomLevel,
);
el = handDrawnElement;
this.currentlyDrawnFreeHand = [];
Expand Down
Loading