2022-04-05 22:49:13 +08:00
|
|
|
import * as React from "react";
|
2022-04-26 21:55:05 +08:00
|
|
|
import _ from "lodash";
|
2022-04-05 22:49:13 +08:00
|
|
|
import Cursors from "./cursors/container";
|
|
|
|
import { TldrawApp, Tldraw } from "@tldraw/tldraw";
|
2022-05-13 23:15:44 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2022-04-26 21:55:05 +08:00
|
|
|
import {
|
|
|
|
ColorStyle,
|
|
|
|
DashStyle,
|
|
|
|
SizeStyle,
|
|
|
|
TDDocument,
|
|
|
|
TDShapeType,
|
|
|
|
} from "@tldraw/tldraw";
|
2022-06-01 03:40:31 +08:00
|
|
|
import { Renderer, Utils } from "@tldraw/core";
|
2022-04-11 00:31:12 +08:00
|
|
|
|
|
|
|
function usePrevious(value) {
|
|
|
|
const ref = React.useRef();
|
|
|
|
React.useEffect(() => {
|
|
|
|
ref.current = value;
|
|
|
|
}, [value]);
|
|
|
|
return ref.current;
|
|
|
|
}
|
2022-04-05 22:49:13 +08:00
|
|
|
|
|
|
|
const findRemoved = (A, B) => {
|
|
|
|
return A.filter((a) => {
|
|
|
|
return !B.includes(a);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function Whiteboard(props) {
|
|
|
|
const {
|
|
|
|
isPresenter,
|
2022-05-04 20:40:56 +08:00
|
|
|
removeShapes,
|
2022-04-05 22:49:13 +08:00
|
|
|
initDefaultPages,
|
|
|
|
meetingId,
|
|
|
|
persistShape,
|
|
|
|
persistAsset,
|
|
|
|
shapes,
|
|
|
|
assets,
|
|
|
|
currentUser,
|
2022-04-26 21:55:05 +08:00
|
|
|
curPres,
|
2022-05-07 00:37:43 +08:00
|
|
|
whiteboardId,
|
2022-05-12 05:58:16 +08:00
|
|
|
podId,
|
|
|
|
zoomSlide,
|
2022-05-19 03:35:42 +08:00
|
|
|
skipToSlide,
|
2022-05-12 05:58:16 +08:00
|
|
|
slidePosition,
|
2022-05-16 10:35:17 +08:00
|
|
|
curPageId,
|
2022-05-19 03:35:42 +08:00
|
|
|
svgUri,
|
2022-06-02 23:00:28 +08:00
|
|
|
presentationBounds,
|
|
|
|
isViewersCursorLocked,
|
2022-06-16 03:46:06 +08:00
|
|
|
setIsZoomed,
|
2022-06-17 08:35:27 +08:00
|
|
|
zoomChanger,
|
2022-06-16 03:46:06 +08:00
|
|
|
isZoomed,
|
2022-06-30 04:25:32 +08:00
|
|
|
isMultiUserActive,
|
2022-04-05 22:49:13 +08:00
|
|
|
} = props;
|
2022-05-16 10:35:17 +08:00
|
|
|
|
2022-04-26 21:55:05 +08:00
|
|
|
const { pages, pageStates } = initDefaultPages(curPres?.pages.length || 1);
|
2022-04-05 22:49:13 +08:00
|
|
|
const rDocument = React.useRef({
|
|
|
|
name: "test",
|
|
|
|
version: TldrawApp.version,
|
2022-05-16 10:35:17 +08:00
|
|
|
id: whiteboardId,
|
2022-04-05 22:49:13 +08:00
|
|
|
pages,
|
|
|
|
pageStates,
|
|
|
|
bindings: {},
|
|
|
|
assets,
|
|
|
|
});
|
2022-05-19 03:35:42 +08:00
|
|
|
//const [doc, setDoc] = React.useState(rDocument.current);
|
2022-05-11 08:22:30 +08:00
|
|
|
const [_assets, setAssets] = React.useState(assets);
|
2022-04-26 21:55:05 +08:00
|
|
|
const [command, setCommand] = React.useState("");
|
2022-05-16 10:35:17 +08:00
|
|
|
const [wbAccess, setWBAccess] = React.useState(props?.hasMultiUserAccess(props.whiteboardId, props.currentUser.userId));
|
2022-04-26 21:55:05 +08:00
|
|
|
const [selectedIds, setSelectedIds] = React.useState([]);
|
2022-04-11 00:31:12 +08:00
|
|
|
const [tldrawAPI, setTLDrawAPI] = React.useState(null);
|
2022-06-01 03:40:31 +08:00
|
|
|
const [cameraFitSlide, setCameraFitSlide] = React.useState({point: [0, 0], zoom: 0});
|
2022-04-11 00:31:12 +08:00
|
|
|
const prevShapes = usePrevious(shapes);
|
2022-05-12 05:58:16 +08:00
|
|
|
const prevSlidePosition = usePrevious(slidePosition);
|
2022-05-19 03:35:42 +08:00
|
|
|
const prevPageId = usePrevious(curPageId);
|
2022-04-11 00:31:12 +08:00
|
|
|
|
2022-06-01 03:40:31 +08:00
|
|
|
const calculateCameraFitSlide = () => {
|
2022-06-16 01:55:14 +08:00
|
|
|
let zoom =
|
2022-06-01 03:40:31 +08:00
|
|
|
Math.min(
|
|
|
|
(presentationBounds.width) / slidePosition.width,
|
|
|
|
(presentationBounds.height) / slidePosition.height
|
2022-06-16 01:55:14 +08:00
|
|
|
);
|
|
|
|
|
2022-06-01 03:40:31 +08:00
|
|
|
zoom = Utils.clamp(zoom, 0.1, 5);
|
|
|
|
|
|
|
|
let point = [0, 0];
|
2022-06-16 01:55:14 +08:00
|
|
|
if ((presentationBounds.width / presentationBounds.height) >
|
|
|
|
(slidePosition.width / slidePosition.height))
|
|
|
|
{
|
2022-06-01 03:40:31 +08:00
|
|
|
point[0] = (presentationBounds.width - (slidePosition.width * zoom)) / 2 / zoom
|
|
|
|
} else {
|
|
|
|
point[1] = (presentationBounds.height - (slidePosition.height * zoom)) / 2 / zoom
|
|
|
|
}
|
|
|
|
|
2022-06-17 08:35:27 +08:00
|
|
|
isPresenter && zoomChanger(zoom);
|
2022-06-01 03:40:31 +08:00
|
|
|
return {point, zoom}
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
const doc = React.useMemo(() => {
|
2022-04-05 22:49:13 +08:00
|
|
|
const currentDoc = rDocument.current;
|
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
let next = { ...currentDoc };
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
let pageBindings = null;
|
|
|
|
let history = null;
|
2022-05-19 08:52:45 +08:00
|
|
|
let stack = null;
|
2022-05-19 03:35:42 +08:00
|
|
|
let changed = false;
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
if (next.pageStates[curPageId] && !_.isEqual(prevShapes, shapes)) {
|
|
|
|
// mergeDocument loses bindings and history, save it
|
|
|
|
pageBindings = tldrawAPI?.getPage(curPageId)?.bindings;
|
|
|
|
history = tldrawAPI?.history
|
2022-05-19 08:52:45 +08:00
|
|
|
stack = tldrawAPI?.stack
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
next.pages[curPageId].shapes = shapes;
|
2022-06-16 01:55:14 +08:00
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
changed = true;
|
2022-04-26 21:55:05 +08:00
|
|
|
}
|
2022-04-05 22:49:13 +08:00
|
|
|
|
2022-06-16 01:55:14 +08:00
|
|
|
if (next.pages[curPageId] && !next.pages[curPageId].shapes["slide-background-shape"]) {
|
2022-05-19 03:35:42 +08:00
|
|
|
next.assets[`slide-background-asset-${curPageId}`] = {
|
|
|
|
id: `slide-background-asset-${curPageId}`,
|
|
|
|
size: [slidePosition?.width || 0, slidePosition?.height || 0],
|
|
|
|
src: svgUri,
|
|
|
|
type: "image",
|
|
|
|
};
|
|
|
|
|
|
|
|
next.pages[curPageId].shapes["slide-background-shape"] = {
|
|
|
|
assetId: `slide-background-asset-${curPageId}`,
|
2022-06-01 03:40:31 +08:00
|
|
|
childIndex: 0.5,
|
2022-05-19 03:35:42 +08:00
|
|
|
id: "slide-background-shape",
|
|
|
|
name: "Image",
|
|
|
|
type: TDShapeType.Image,
|
|
|
|
parentId: `${curPageId}`,
|
|
|
|
point: [0, 0],
|
|
|
|
isLocked: true,
|
|
|
|
size: [slidePosition?.width || 0, slidePosition?.height || 0],
|
|
|
|
style: {
|
|
|
|
dash: DashStyle.Draw,
|
|
|
|
size: SizeStyle.Medium,
|
|
|
|
color: ColorStyle.Blue,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
changed = true;
|
2022-04-05 22:49:13 +08:00
|
|
|
}
|
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
if (changed) {
|
2022-06-01 03:40:31 +08:00
|
|
|
if (pageBindings) next.pages[curPageId].bindings = pageBindings;
|
2022-05-19 03:35:42 +08:00
|
|
|
tldrawAPI?.mergeDocument(next);
|
|
|
|
if (tldrawAPI && history) tldrawAPI.history = history;
|
2022-05-19 08:52:45 +08:00
|
|
|
if (tldrawAPI && stack) tldrawAPI.stack = stack;
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// move poll result text to bottom right
|
|
|
|
if (next.pages[curPageId]) {
|
|
|
|
const pollResults = Object.entries(next.pages[curPageId].shapes)
|
|
|
|
.filter(([id, shape]) => shape.name.includes("poll-result"))
|
|
|
|
for (const [id, shape] of pollResults) {
|
|
|
|
if (_.isEqual(shape.point, [0, 0])) {
|
|
|
|
const shapeBounds = tldrawAPI?.getShapeBounds(id);
|
|
|
|
if (shapeBounds) {
|
|
|
|
shape.point = [
|
|
|
|
slidePosition.width - shapeBounds.width,
|
|
|
|
slidePosition.height - shapeBounds.height
|
|
|
|
]
|
|
|
|
shape.size = [shapeBounds.width, shapeBounds.height]
|
|
|
|
isPresenter && persistShape(shape, whiteboardId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-04-26 21:55:05 +08:00
|
|
|
}
|
2022-05-19 10:32:32 +08:00
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
return currentDoc;
|
2022-05-20 01:24:47 +08:00
|
|
|
}, [assets, shapes, tldrawAPI, curPageId, slidePosition]);
|
2022-04-11 00:31:12 +08:00
|
|
|
|
2022-06-01 03:40:31 +08:00
|
|
|
// when presentationBounds change, update tldraw camera
|
|
|
|
// to fit slide on center if zoomed out
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (curPageId && slidePosition) {
|
|
|
|
const camera = calculateCameraFitSlide();
|
|
|
|
setCameraFitSlide(camera);
|
2022-06-16 03:46:06 +08:00
|
|
|
if (!isZoomed) {
|
2022-06-01 03:40:31 +08:00
|
|
|
tldrawAPI?.setCamera(camera.point, camera.zoom);
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 00:48:42 +08:00
|
|
|
}, [presentationBounds, curPageId, document?.documentElement?.dir]);
|
2022-06-01 03:40:31 +08:00
|
|
|
|
2022-05-20 01:24:47 +08:00
|
|
|
// change tldraw page when presentation page changes
|
2022-04-26 21:55:05 +08:00
|
|
|
React.useEffect(() => {
|
2022-06-01 03:40:31 +08:00
|
|
|
if (tldrawAPI && curPageId) {
|
|
|
|
const previousPageZoom = tldrawAPI.getPageState()?.camera?.zoom;
|
|
|
|
tldrawAPI.changePage(curPageId);
|
2022-05-20 01:24:47 +08:00
|
|
|
//change zoom of the new page to follow the previous one
|
2022-06-16 03:46:06 +08:00
|
|
|
if (!isZoomed && cameraFitSlide.zoom !== 0) {
|
2022-06-01 03:40:31 +08:00
|
|
|
tldrawAPI?.setCamera(cameraFitSlide.point, cameraFitSlide.zoom, "zoomed");
|
|
|
|
} else {
|
|
|
|
previousPageZoom &&
|
2022-06-16 01:55:14 +08:00
|
|
|
slidePosition &&
|
2022-06-01 03:40:31 +08:00
|
|
|
tldrawAPI.setCamera([slidePosition.xCamera, slidePosition.yCamera], previousPageZoom, "zoomed");
|
|
|
|
}
|
|
|
|
}
|
2022-05-19 03:35:42 +08:00
|
|
|
}, [curPageId]);
|
2022-04-05 22:49:13 +08:00
|
|
|
|
2022-05-20 01:24:47 +08:00
|
|
|
// change tldraw camera when slidePosition changes
|
|
|
|
React.useEffect(() => {
|
2022-06-01 03:40:31 +08:00
|
|
|
if (tldrawAPI && !isPresenter && curPageId && slidePosition) {
|
|
|
|
if (slidePosition.zoom === 0 && slidePosition.xCamera === 0 && slidePosition.yCamera === 0) {
|
|
|
|
tldrawAPI?.setCamera(cameraFitSlide.point, cameraFitSlide.zoom);
|
2022-06-16 03:46:06 +08:00
|
|
|
setIsZoomed(false);
|
2022-06-01 03:40:31 +08:00
|
|
|
} else {
|
|
|
|
tldrawAPI?.setCamera([slidePosition.xCamera, slidePosition.yCamera], slidePosition.zoom);
|
2022-06-16 03:46:06 +08:00
|
|
|
setIsZoomed(true);
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
2022-05-20 01:24:47 +08:00
|
|
|
}, [curPageId, slidePosition]);
|
|
|
|
|
2022-05-16 10:35:17 +08:00
|
|
|
const hasWBAccess = props?.hasMultiUserAccess(props.whiteboardId, props.currentUser.userId);
|
|
|
|
|
2022-04-05 22:49:13 +08:00
|
|
|
return (
|
2022-04-26 21:55:05 +08:00
|
|
|
<>
|
|
|
|
<Cursors
|
|
|
|
tldrawAPI={tldrawAPI}
|
|
|
|
currentUser={currentUser}
|
2022-06-29 04:12:14 +08:00
|
|
|
hasMultiUserAccess={props?.hasMultiUserAccess}
|
2022-05-07 00:37:43 +08:00
|
|
|
whiteboardId={whiteboardId}
|
2022-06-02 23:00:28 +08:00
|
|
|
isViewersCursorLocked={isViewersCursorLocked}
|
2022-06-30 04:25:32 +08:00
|
|
|
isMultiUserActive={isMultiUserActive}
|
2022-04-26 21:55:05 +08:00
|
|
|
>
|
|
|
|
<Tldraw
|
2022-07-01 00:48:42 +08:00
|
|
|
key={`wb-${!hasWBAccess && !isPresenter}-${document?.documentElement?.dir}`}
|
2022-04-26 21:55:05 +08:00
|
|
|
document={doc}
|
2022-06-16 01:55:14 +08:00
|
|
|
// disable the ability to drag and drop files onto the whiteboard
|
|
|
|
// until we handle saving of assets in akka.
|
|
|
|
disableAssets={true}
|
2022-04-26 21:55:05 +08:00
|
|
|
onMount={(app) => {
|
|
|
|
setTLDrawAPI(app);
|
2022-05-16 10:35:17 +08:00
|
|
|
props.setTldrawAPI(app);
|
2022-06-29 03:16:35 +08:00
|
|
|
// disable for non presenter that doesn't have multi user access
|
|
|
|
if (!hasWBAccess && !isPresenter) {
|
|
|
|
app.onPan = () => {};
|
|
|
|
app.setSelectedIds = () => {};
|
|
|
|
app.setHoveredId = () => {};
|
|
|
|
} else {
|
|
|
|
// disable hover highlight for background slide shape
|
|
|
|
app.setHoveredId = (id) => {
|
|
|
|
if (id.includes('slide-background')) return null;
|
|
|
|
app.patchState(
|
|
|
|
{
|
|
|
|
document: {
|
|
|
|
pageStates: {
|
|
|
|
[app.getPage()?.id]: {
|
|
|
|
hoveredId: id,
|
|
|
|
},
|
2022-06-26 02:47:15 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 03:16:35 +08:00
|
|
|
`set_hovered_id`
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
2022-06-26 02:47:15 +08:00
|
|
|
|
2022-06-01 03:40:31 +08:00
|
|
|
if (curPageId) {
|
|
|
|
app.changePage(curPageId);
|
|
|
|
if (slidePosition.zoom === 0) {
|
|
|
|
// first load, center the view to fit slide
|
|
|
|
const cameraFitSlide = calculateCameraFitSlide();
|
|
|
|
app.setCamera(cameraFitSlide.point, cameraFitSlide.zoom);
|
|
|
|
setCameraFitSlide(cameraFitSlide);
|
|
|
|
} else {
|
2022-06-16 03:46:06 +08:00
|
|
|
app.setCamera([slidePosition.xCamera, slidePosition.yCamera], slidePosition.zoom);
|
|
|
|
setIsZoomed(true);
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
2022-04-26 21:55:05 +08:00
|
|
|
}}
|
2022-05-16 10:35:17 +08:00
|
|
|
showPages={false}
|
|
|
|
showZoom={false}
|
2022-05-20 20:12:58 +08:00
|
|
|
showUI={curPres ? (isPresenter || hasWBAccess) : true}
|
|
|
|
showMenu={curPres ? false : true}
|
2022-04-26 21:55:05 +08:00
|
|
|
showMultiplayerMenu={false}
|
2022-05-16 10:35:17 +08:00
|
|
|
readOnly={!isPresenter && !hasWBAccess}
|
2022-05-19 03:35:42 +08:00
|
|
|
onUndo={(e, s) => {
|
|
|
|
e?.selectedIds?.map(id => {
|
|
|
|
persistShape(e.getShape(id), whiteboardId);
|
2022-05-03 22:47:45 +08:00
|
|
|
})
|
2022-05-19 03:35:42 +08:00
|
|
|
const pageShapes = e.state.document.pages[e.getPage()?.id]?.shapes;
|
|
|
|
let shapesIdsToRemove = findRemoved(Object.keys(shapes), Object.keys(pageShapes))
|
|
|
|
removeShapes(shapesIdsToRemove, whiteboardId)
|
2022-05-03 22:47:45 +08:00
|
|
|
}}
|
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
onRedo={(e, s) => {
|
|
|
|
e?.selectedIds?.map(id => {
|
2022-05-19 08:52:45 +08:00
|
|
|
persistShape(e.getShape(id), whiteboardId);
|
2022-05-03 22:47:45 +08:00
|
|
|
});
|
2022-05-19 08:52:45 +08:00
|
|
|
const pageShapes = e.state.document.pages[e.getPage()?.id]?.shapes;
|
|
|
|
let shapesIdsToRemove = findRemoved(Object.keys(shapes), Object.keys(pageShapes))
|
|
|
|
removeShapes(shapesIdsToRemove, whiteboardId)
|
2022-05-03 22:47:45 +08:00
|
|
|
}}
|
|
|
|
|
|
|
|
onChangePage={(app, s, b, a) => {
|
2022-05-19 03:35:42 +08:00
|
|
|
if (app.getPage()?.id !== curPageId) {
|
|
|
|
skipToSlide(Number.parseInt(app.getPage()?.id), podId)
|
|
|
|
}
|
2022-05-03 22:47:45 +08:00
|
|
|
}}
|
|
|
|
onCommand={(e, s, g) => {
|
|
|
|
if (s.includes("session:complete:DrawSession")) {
|
2022-05-19 03:35:42 +08:00
|
|
|
Object.entries(e.state.document.pages[e.getPage()?.id]?.shapes)
|
2022-05-03 22:47:45 +08:00
|
|
|
.filter(([k, s]) => s?.type === 'draw')
|
|
|
|
.forEach(([k, s]) => {
|
2022-05-19 03:35:42 +08:00
|
|
|
if (!e.prevShapes[k] && !k.includes('slide-background')) {
|
2022-06-01 03:40:31 +08:00
|
|
|
const shapeBounds = e.getShapeBounds(k);
|
|
|
|
s.size = [shapeBounds.width, shapeBounds.height];
|
2022-05-07 00:37:43 +08:00
|
|
|
persistShape(s, whiteboardId);
|
2022-05-03 22:47:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.includes("style")
|
|
|
|
|| s?.includes("session:complete:ArrowSession")) {
|
|
|
|
e.selectedIds.forEach(id => {
|
2022-06-01 03:40:31 +08:00
|
|
|
const shape = e.getShape(id);
|
|
|
|
const shapeBounds = e.getShapeBounds(id);
|
|
|
|
shape.size = [shapeBounds.width, shapeBounds.height];
|
|
|
|
persistShape(shape, whiteboardId);
|
2022-06-16 01:55:14 +08:00
|
|
|
});
|
2022-05-03 22:47:45 +08:00
|
|
|
}
|
|
|
|
|
2022-05-17 03:29:21 +08:00
|
|
|
if (s.includes('move_to_page')) {
|
|
|
|
const movedShapes = e.selectedIds.map(id => {
|
|
|
|
return e.getShape(id);
|
|
|
|
});
|
|
|
|
//remove shapes on origin page
|
|
|
|
removeShapes(e.selectedIds, whiteboardId);
|
|
|
|
//persist shapes for destination page
|
2022-05-19 03:35:42 +08:00
|
|
|
const newWhiteboardId = curPres.pages.find(page => page.num === Number.parseInt(e.getPage()?.id)).id;
|
2022-05-17 03:29:21 +08:00
|
|
|
movedShapes.forEach(s => {
|
2022-05-19 03:35:42 +08:00
|
|
|
persistShape(s, newWhiteboardId);
|
2022-05-17 03:29:21 +08:00
|
|
|
});
|
2022-06-01 03:40:31 +08:00
|
|
|
return;
|
2022-05-17 03:29:21 +08:00
|
|
|
}
|
|
|
|
|
2022-05-21 01:14:32 +08:00
|
|
|
const conditions = [
|
|
|
|
"session:complete:TransformSingleSession", "session:complete:TranslateSession",
|
2022-06-16 01:55:14 +08:00
|
|
|
"session:complete:RotateSession", "session:complete:HandleSession",
|
|
|
|
"updated_shapes", "duplicate", "stretch", "align", "move",
|
2022-06-01 03:40:31 +08:00
|
|
|
"create", "flip", "toggle", "group", "translate"
|
2022-05-21 01:14:32 +08:00
|
|
|
]
|
|
|
|
if (conditions.some(el => s?.includes(el))) {
|
2022-05-03 22:47:45 +08:00
|
|
|
e.selectedIds.forEach(id => {
|
2022-06-01 03:40:31 +08:00
|
|
|
const shape = e.getShape(id);
|
|
|
|
const shapeBounds = e.getShapeBounds(id);
|
|
|
|
shape.size = [shapeBounds.width, shapeBounds.height];
|
|
|
|
persistShape(shape, whiteboardId);
|
|
|
|
//checks to find any bindings assosiated with the selected shapes.
|
|
|
|
//If any, they need to be updated as well.
|
|
|
|
const pageBindings = e.state.document.pages[e.getPage()?.id]?.bindings;
|
|
|
|
const boundShapes = [];
|
|
|
|
if (pageBindings) {
|
|
|
|
Object.entries(pageBindings).map(([k,b]) => {
|
|
|
|
if (b.toId.includes(id)) {
|
|
|
|
boundShapes.push(e.state.document.pages[e.getPage()?.id]?.shapes[b.fromId])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
//persist shape(s) that was updated by the client and any shapes bound to it.
|
|
|
|
boundShapes.forEach(bs => {
|
|
|
|
const shapeBounds = e.getShapeBounds(bs.id);
|
|
|
|
bs.size = [shapeBounds.width, shapeBounds.height];
|
|
|
|
persistShape(bs, whiteboardId)
|
|
|
|
})
|
|
|
|
const children = e.getShape(id).children
|
|
|
|
//also persist children of the selected shape (grouped shapes)
|
|
|
|
children && children.forEach(c => {
|
|
|
|
const shape = e.getShape(c);
|
|
|
|
const shapeBounds = e.getShapeBounds(c);
|
|
|
|
shape.size = [shapeBounds.width, shapeBounds.height];
|
|
|
|
persistShape(shape, whiteboardId)
|
|
|
|
})
|
2022-05-03 22:47:45 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s?.includes("session:complete:EraseSession") || s?.includes("delete")) {
|
2022-05-19 03:35:42 +08:00
|
|
|
const pageShapes = e.state.document.pages[e.getPage()?.id]?.shapes;
|
|
|
|
let shapesIdsToRemove = findRemoved(Object.keys(shapes), Object.keys(pageShapes))
|
2022-05-07 00:37:43 +08:00
|
|
|
removeShapes(shapesIdsToRemove, whiteboardId)
|
2022-05-03 22:47:45 +08:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
2022-05-12 05:58:16 +08:00
|
|
|
onPatch={(s, reason) => {
|
|
|
|
if (reason && isPresenter && (reason.includes("zoomed") || reason.includes("panned"))) {
|
2022-06-01 03:40:31 +08:00
|
|
|
const camera = tldrawAPI.getPageState().camera;
|
|
|
|
//don't allow zoom out more than fit
|
|
|
|
if (camera.zoom <= cameraFitSlide.zoom) {
|
|
|
|
tldrawAPI?.setCamera(cameraFitSlide.point, cameraFitSlide.zoom);
|
2022-06-16 03:46:06 +08:00
|
|
|
setIsZoomed(false);
|
2022-06-01 03:40:31 +08:00
|
|
|
zoomSlide(parseInt(curPageId), podId, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
zoomSlide(parseInt(curPageId), podId, camera.zoom, camera.point[0], camera.point[1]);
|
2022-06-16 03:46:06 +08:00
|
|
|
setIsZoomed(true);
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
2022-05-12 05:58:16 +08:00
|
|
|
}
|
2022-06-01 03:40:31 +08:00
|
|
|
//don't allow non-presenters to pan&zoom
|
|
|
|
if (slidePosition && reason && !isPresenter && (reason.includes("zoomed") || reason.includes("panned"))) {
|
|
|
|
if (slidePosition.zoom === 0 && slidePosition.xCamera === 0 && slidePosition.yCamera === 0) {
|
|
|
|
tldrawAPI?.setCamera(cameraFitSlide.point, cameraFitSlide.zoom);
|
2022-06-16 03:46:06 +08:00
|
|
|
setIsZoomed(false);
|
2022-06-01 03:40:31 +08:00
|
|
|
} else {
|
|
|
|
tldrawAPI?.setCamera([slidePosition.xCamera, slidePosition.yCamera], slidePosition.zoom);
|
2022-06-16 03:46:06 +08:00
|
|
|
setIsZoomed(true);
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
2022-06-16 01:55:14 +08:00
|
|
|
}
|
2022-05-12 05:58:16 +08:00
|
|
|
}}
|
2022-04-26 21:55:05 +08:00
|
|
|
/>
|
|
|
|
</Cursors>
|
|
|
|
</>
|
2022-04-05 22:49:13 +08:00
|
|
|
);
|
|
|
|
}
|