Skip to content

Commit af2f417

Browse files
committed
chore: update dependencies and UX improvements
1 parent 6a4a011 commit af2f417

File tree

5 files changed

+112
-118
lines changed

5 files changed

+112
-118
lines changed

code/components/room-components/hooks/use-context-menu.tsx

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
import { v4 as uuidv4 } from "uuid";
66
import {
7-
WeaveCopyPastePasteMode,
8-
WEAVE_COPY_PASTE_PASTE_MODES,
97
WeaveContextMenuPlugin,
108
WeaveCopyPasteNodesPlugin,
119
WeaveExportNodesActionParams,
1210
WeaveStageContextMenuPluginOnNodeContextMenuEvent,
1311
} from "@inditextech/weave-sdk";
12+
import { Vector2d } from "konva/lib/types";
1413
import { WeaveSelection } from "@inditextech/weave-types";
1514
import { useCollaborationRoom } from "@/store/store";
1615
import React from "react";
@@ -38,21 +37,6 @@ import { useMutation } from "@tanstack/react-query";
3837
import { postRemoveBackground } from "@/api/post-remove-background";
3938
import { useIACapabilities } from "@/store/ia";
4039

41-
const EXTERNAL_PASTE_TYPES = ["image/png", "image/jpeg"];
42-
43-
const canHandleExternalPaste = async (items: ClipboardItems) => {
44-
let canHandleExternal = false;
45-
for (const type of EXTERNAL_PASTE_TYPES) {
46-
for (const item of items) {
47-
if (item.types.includes(type)) {
48-
canHandleExternal = true;
49-
break;
50-
}
51-
}
52-
}
53-
return Promise.resolve(canHandleExternal);
54-
};
55-
5640
function useContextMenu() {
5741
const instance = useWeave((state) => state.instance);
5842

@@ -110,17 +94,16 @@ function useContextMenu() {
11094
canUnGroup,
11195
nodes,
11296
canGroup,
97+
clickPoint,
11398
}: {
11499
actActionActive: string | undefined;
115100
canUnGroup: boolean;
116101
canGroup: boolean;
117102
nodes: WeaveSelection[];
103+
clickPoint: Vector2d;
118104
}): Promise<ContextMenuOption[]> => {
119105
if (!instance) return [];
120106

121-
const copyPasteNodesPlugin =
122-
instance.getPlugin<WeaveCopyPasteNodesPlugin>("copyPasteNodes");
123-
124107
const options: ContextMenuOption[] = [];
125108

126109
const singleLocked =
@@ -291,45 +274,45 @@ function useContextMenu() {
291274
}
292275
}
293276

294-
const pastMode = await copyPasteNodesPlugin?.getAvailablePasteMode(
295-
canHandleExternalPaste
296-
);
277+
// const pastMode = await copyPasteNodesPlugin?.getAvailablePasteMode(
278+
// canHandleExternalPaste
279+
// );
297280

298281
// PASTE
299-
if (
300-
pastMode &&
301-
(
302-
[
303-
WEAVE_COPY_PASTE_PASTE_MODES.INTERNAL,
304-
WEAVE_COPY_PASTE_PASTE_MODES.EXTERNAL,
305-
] as WeaveCopyPastePasteMode[]
306-
).includes(pastMode)
307-
)
308-
options.push({
309-
id: "paste",
310-
type: "button",
311-
label: (
312-
<div className="w-full flex justify-between items-center">
313-
<div>Paste</div>
314-
<ShortcutElement
315-
shortcuts={{
316-
[SYSTEM_OS.MAC]: "⌘ P",
317-
[SYSTEM_OS.OTHER]: "Ctrl P",
318-
}}
319-
/>
320-
</div>
321-
),
322-
icon: <ClipboardPaste size={16} />,
323-
disabled: !["selectionTool"].includes(actActionActive ?? ""),
324-
onClick: async () => {
325-
const weaveCopyPasteNodesPlugin =
326-
instance.getPlugin<WeaveCopyPasteNodesPlugin>("copyPasteNodes");
327-
if (weaveCopyPasteNodesPlugin) {
328-
await weaveCopyPasteNodesPlugin.paste();
329-
setContextMenuShow(false);
330-
}
331-
},
332-
});
282+
// if (
283+
// pastMode &&
284+
// (
285+
// [
286+
// WEAVE_COPY_PASTE_PASTE_MODES.INTERNAL,
287+
// WEAVE_COPY_PASTE_PASTE_MODES.EXTERNAL,
288+
// ] as WeaveCopyPastePasteMode[]
289+
// ).includes(pastMode)
290+
// )
291+
options.push({
292+
id: "paste",
293+
type: "button",
294+
label: (
295+
<div className="w-full flex justify-between items-center">
296+
<div>Paste here</div>
297+
<ShortcutElement
298+
shortcuts={{
299+
[SYSTEM_OS.MAC]: "⌘ P",
300+
[SYSTEM_OS.OTHER]: "Ctrl P",
301+
}}
302+
/>
303+
</div>
304+
),
305+
icon: <ClipboardPaste size={16} />,
306+
disabled: !["selectionTool"].includes(actActionActive ?? ""),
307+
onClick: async () => {
308+
const weaveCopyPasteNodesPlugin =
309+
instance.getPlugin<WeaveCopyPasteNodesPlugin>("copyPasteNodes");
310+
if (weaveCopyPasteNodesPlugin) {
311+
await weaveCopyPasteNodesPlugin.paste(clickPoint);
312+
setContextMenuShow(false);
313+
}
314+
},
315+
});
333316
if (!singleLocked && nodes.length > 0) {
334317
// SEPARATOR
335318
options.push({
@@ -598,7 +581,8 @@ function useContextMenu() {
598581
const onNodeContextMenuHandler = React.useCallback(
599582
async ({
600583
selection,
601-
point,
584+
contextMenuPoint,
585+
clickPoint,
602586
visible,
603587
}: WeaveStageContextMenuPluginOnNodeContextMenuEvent) => {
604588
if (!instance) return;
@@ -616,11 +600,12 @@ function useContextMenu() {
616600
canUnGroup,
617601
nodes: selection,
618602
canGroup,
603+
clickPoint,
619604
});
620605

621606
if (contextMenu.length > 0) {
622607
setContextMenuShow(visible);
623-
setContextMenuPosition(point);
608+
setContextMenuPosition(contextMenuPoint);
624609
setContextMenuOptions(contextMenu);
625610
} else {
626611
const contextMenuPlugin =

code/components/room-components/overlay/tools-overlay.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import { ToolsNodesOverlay } from "./tools-nodes-overlay";
2222
import { useNodeActionName } from "./hooks/use-node-action-name";
2323
import { ToolsMaskingOverlay } from "./tools-masking-overlay";
2424
import { isClipboardAPIAvailable } from "@/lib/utils";
25+
import {
26+
WeaveImageToolActionOnAddedEvent,
27+
WeaveNodesSelectionPlugin,
28+
} from "@inditextech/weave-sdk";
2529

2630
export function ToolsOverlay() {
2731
useKeyboardHandler();
@@ -118,9 +122,26 @@ export function ToolsOverlay() {
118122
return;
119123
}
120124

121-
instance?.addEventListener("onAddedImage", () => {
122-
setUploadingImage(false);
123-
});
125+
instance?.addEventListener<WeaveImageToolActionOnAddedEvent>(
126+
"onAddedImage",
127+
({ nodeId }) => {
128+
setUploadingImage(false);
129+
130+
const node = instance?.getStage().findOne(`#${nodeId}`);
131+
if (node) {
132+
const selectionPlugin =
133+
instance.getPlugin<WeaveNodesSelectionPlugin>("nodesSelection");
134+
if (selectionPlugin) {
135+
selectionPlugin.setSelectedNodes([node]);
136+
}
137+
138+
instance?.triggerAction("fitToSelectionTool", {
139+
previousAction: "selectionTool",
140+
smartZoom: true,
141+
});
142+
}
143+
}
144+
);
124145

125146
setUploadingImage(true);
126147
const file = new File([blob], "external.image");

code/components/room/room.layout.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,8 @@ export const RoomLayout = () => {
133133
// sidebarLeftActive !== null && sidebarRightActive !== null,
134134
})}
135135
>
136-
<div
137-
id="paste-catcher"
138-
contentEditable="true"
139-
tabIndex={0}
140-
style={{
141-
position: "absolute",
142-
left: "-9999px",
143-
width: "1px",
144-
height: "1px",
145-
}}
146-
></div>
147136
<div
148137
id="weave"
149-
// contentEditable="true"
150138
tabIndex={0}
151139
className={cn("w-full h-full relative overflow-hidden", {
152140
["pointer-events-none"]:

code/package-lock.json

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)