2023-12-06 02:15:25 +08:00
|
|
|
import * as React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
2024-03-25 01:22:49 +08:00
|
|
|
import { useRef } from "react";
|
|
|
|
import { debounce, isEqual } from "radash";
|
|
|
|
import {
|
|
|
|
Tldraw,
|
|
|
|
DefaultColorStyle,
|
|
|
|
DefaultDashStyle,
|
|
|
|
DefaultFillStyle,
|
|
|
|
DefaultFontStyle,
|
|
|
|
DefaultSizeStyle,
|
2024-04-04 10:00:56 +08:00
|
|
|
InstancePresenceRecordType,
|
2024-05-01 00:40:43 +08:00
|
|
|
setDefaultUiAssetUrls,
|
|
|
|
setDefaultEditorAssetUrls,
|
2024-05-23 05:49:28 +08:00
|
|
|
} from "@bigbluebutton/tldraw";
|
|
|
|
import "@bigbluebutton/tldraw/tldraw.css";
|
2024-03-25 01:22:49 +08:00
|
|
|
import SlideCalcUtil from "/imports/utils/slideCalcUtils";
|
|
|
|
import { HUNDRED_PERCENT } from "/imports/utils/slideCalcUtils";
|
2023-03-10 19:30:46 +08:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2024-06-08 04:13:25 +08:00
|
|
|
import Settings from '/imports/ui/services/settings';
|
|
|
|
import meetingClientSettingsInitialValues from '/imports/ui/core/initial-values/meetingClientSettings';
|
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2023-12-06 02:15:25 +08:00
|
|
|
import KEY_CODES from "/imports/utils/keyCodes";
|
|
|
|
import Styled from "./styles";
|
2023-03-10 19:30:46 +08:00
|
|
|
import {
|
2024-04-18 03:04:31 +08:00
|
|
|
mapLanguage,
|
|
|
|
isValidShapeType,
|
2023-12-06 02:15:25 +08:00
|
|
|
} from "./utils";
|
|
|
|
import { useMouseEvents, useCursor } from "./hooks";
|
2024-05-29 21:26:11 +08:00
|
|
|
import { notifyShapeNumberExceeded, getCustomEditorAssetUrls, getCustomAssetUrls } from "./service";
|
2022-11-01 00:42:38 +08:00
|
|
|
|
2024-05-02 08:40:58 +08:00
|
|
|
import NoopTool from './custom-tools/noop-tool/component';
|
2024-04-11 08:53:42 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
// Helper functions
|
|
|
|
const deleteLocalStorageItemsWithPrefix = (prefix) => {
|
|
|
|
const keysToRemove = Object.keys(localStorage).filter((key) =>
|
|
|
|
key.startsWith(prefix)
|
|
|
|
);
|
|
|
|
keysToRemove.forEach((key) => localStorage.removeItem(key));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Example of typical LocalStorage entry tldraw creates:
|
|
|
|
// `{ TLDRAW_USER_DATA_v3: '{"version":2,"user":{"id":"epDk1 ...`
|
|
|
|
const clearTldrawCache = () => {
|
|
|
|
deleteLocalStorageItemsWithPrefix("TLDRAW");
|
|
|
|
};
|
|
|
|
|
|
|
|
const calculateEffectiveZoom = (initViewboxWidth, curViewboxWidth) => {
|
|
|
|
// Calculate the effective zoom level based on the change in viewBoxWidth
|
|
|
|
const effectiveZoomValue = (initViewboxWidth * 100) / curViewboxWidth;
|
|
|
|
return effectiveZoomValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
const determineViewerFitToWidth = (currentPresentationPage) => {
|
|
|
|
return (
|
|
|
|
currentPresentationPage?.scaledViewBoxWidth ===
|
|
|
|
currentPresentationPage?.scaledWidth &&
|
|
|
|
currentPresentationPage?.scaledViewBoxHeight !==
|
|
|
|
currentPresentationPage?.scaledHeight
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-03-25 01:22:49 +08:00
|
|
|
const Whiteboard = React.memo(function Whiteboard(props) {
|
2022-04-05 22:49:13 +08:00
|
|
|
const {
|
|
|
|
isPresenter,
|
2022-05-04 20:40:56 +08:00
|
|
|
removeShapes,
|
2024-01-24 19:37:51 +08:00
|
|
|
persistShapeWrapper,
|
2022-04-05 22:49:13 +08:00
|
|
|
shapes,
|
2022-10-06 04:43:48 +08:00
|
|
|
assets,
|
2022-04-05 22:49:13 +08:00
|
|
|
currentUser,
|
2022-05-07 00:37:43 +08:00
|
|
|
whiteboardId,
|
2022-05-12 05:58:16 +08:00
|
|
|
zoomSlide,
|
2022-05-16 10:35:17 +08:00
|
|
|
curPageId,
|
2022-06-17 08:35:27 +08:00
|
|
|
zoomChanger,
|
2022-06-30 04:25:32 +08:00
|
|
|
isMultiUserActive,
|
2022-08-03 22:19:12 +08:00
|
|
|
isRTL,
|
2022-08-16 20:12:43 +08:00
|
|
|
fitToWidth,
|
|
|
|
zoomValue,
|
2024-01-20 22:01:20 +08:00
|
|
|
colorStyle,
|
|
|
|
dashStyle,
|
|
|
|
fillStyle,
|
|
|
|
fontStyle,
|
|
|
|
sizeStyle,
|
2023-01-26 02:49:09 +08:00
|
|
|
presentationAreaHeight,
|
|
|
|
presentationAreaWidth,
|
2023-03-10 19:30:46 +08:00
|
|
|
setTldrawIsMounting,
|
2023-03-13 20:17:14 +08:00
|
|
|
setTldrawAPI,
|
2023-03-27 06:08:09 +08:00
|
|
|
whiteboardToolbarAutoHide,
|
|
|
|
toggleToolsAnimations,
|
2023-04-14 23:27:37 +08:00
|
|
|
animations,
|
2023-04-19 02:03:22 +08:00
|
|
|
isToolbarVisible,
|
2023-06-06 04:02:06 +08:00
|
|
|
isModerator,
|
2023-09-28 04:42:47 +08:00
|
|
|
currentPresentationPage,
|
|
|
|
presentationId,
|
2023-10-12 04:17:10 +08:00
|
|
|
hasWBAccess,
|
2023-12-06 02:15:25 +08:00
|
|
|
bgShape,
|
|
|
|
publishCursorUpdate,
|
|
|
|
otherCursors,
|
|
|
|
hideViewersCursor,
|
2024-02-01 02:53:05 +08:00
|
|
|
presentationHeight,
|
|
|
|
presentationWidth,
|
2024-02-27 01:06:18 +08:00
|
|
|
skipToSlide,
|
2024-04-16 20:45:22 +08:00
|
|
|
intl,
|
|
|
|
maxNumberOfAnnotations,
|
2024-04-18 03:04:31 +08:00
|
|
|
notifyNotAllowedChange,
|
2024-05-10 11:48:22 +08:00
|
|
|
locale,
|
|
|
|
darkTheme,
|
|
|
|
selectedLayout,
|
2022-04-05 22:49:13 +08:00
|
|
|
} = props;
|
2023-10-13 02:29:29 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
clearTldrawCache();
|
|
|
|
|
|
|
|
const [tlEditor, setTlEditor] = React.useState(null);
|
2022-08-16 20:12:43 +08:00
|
|
|
const [isMounting, setIsMounting] = React.useState(true);
|
2024-04-02 23:33:55 +08:00
|
|
|
const [initialZoomSet, setInitialZoomSet] = React.useState(false);
|
2023-12-06 02:15:25 +08:00
|
|
|
const [initialViewBoxWidth, setInitialViewBoxWidth] = React.useState(null);
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
if (isMounting) {
|
|
|
|
setDefaultEditorAssetUrls(getCustomEditorAssetUrls());
|
|
|
|
setDefaultUiAssetUrls(getCustomAssetUrls());
|
|
|
|
}
|
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
const whiteboardRef = React.useRef(null);
|
|
|
|
const zoomValueRef = React.useRef(null);
|
2023-12-12 03:31:21 +08:00
|
|
|
const prevShapesRef = React.useRef(shapes);
|
|
|
|
const prevOtherCursorsRef = useRef(otherCursors);
|
2023-12-06 02:15:25 +08:00
|
|
|
const tlEditorRef = React.useRef(tlEditor);
|
|
|
|
const slideChanged = React.useRef(false);
|
|
|
|
const slideNext = React.useRef(null);
|
|
|
|
const prevZoomValueRef = React.useRef(null);
|
|
|
|
const initialZoomRef = useRef(null);
|
|
|
|
const isMouseDownRef = useRef(false);
|
|
|
|
const isMountedRef = useRef(false);
|
2024-01-09 22:31:08 +08:00
|
|
|
const isWheelZoomRef = useRef(false);
|
2024-02-19 06:10:04 +08:00
|
|
|
const isPresenterRef = useRef(isPresenter);
|
2024-02-08 01:07:40 +08:00
|
|
|
const whiteboardIdRef = React.useRef(whiteboardId);
|
|
|
|
const curPageIdRef = React.useRef(curPageId);
|
2024-02-08 04:20:06 +08:00
|
|
|
const hasWBAccessRef = React.useRef(hasWBAccess);
|
2024-02-29 00:50:14 +08:00
|
|
|
const isModeratorRef = React.useRef(isModerator);
|
2024-04-13 04:39:53 +08:00
|
|
|
const currentPresentationPageRef = React.useRef(currentPresentationPage);
|
|
|
|
const initialViewBoxWidthRef = React.useRef(null);
|
2023-08-28 02:45:37 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
const THRESHOLD = 0.1;
|
2024-06-04 22:53:21 +08:00
|
|
|
const CAMERA_UPDATE_DELAY = 650;
|
2023-12-06 02:15:25 +08:00
|
|
|
const lastKnownHeight = React.useRef(presentationAreaHeight);
|
|
|
|
const lastKnownWidth = React.useRef(presentationAreaWidth);
|
2023-02-25 07:00:15 +08:00
|
|
|
|
2024-02-21 10:18:36 +08:00
|
|
|
const [shapesVersion, setShapesVersion] = React.useState(0);
|
|
|
|
|
2024-03-25 01:22:49 +08:00
|
|
|
const setIsMouseDown = (val) => {
|
|
|
|
isMouseDownRef.current = val;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setIsWheelZoom = (val) => {
|
|
|
|
isWheelZoomRef.current = val;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setWheelZoomTimeout = () => {
|
|
|
|
isWheelZoomRef.currentTimeout = setTimeout(() => {
|
|
|
|
setIsWheelZoom(false);
|
|
|
|
}, 300);
|
|
|
|
};
|
|
|
|
|
2024-04-13 04:39:53 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
currentPresentationPageRef.current = currentPresentationPage;
|
|
|
|
}, [currentPresentationPage]);
|
|
|
|
|
2024-02-08 01:07:40 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
curPageIdRef.current = curPageId;
|
|
|
|
}, [curPageId]);
|
|
|
|
|
2024-02-29 00:50:14 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
isModeratorRef.current = isModerator;
|
|
|
|
}, [isModerator]);
|
|
|
|
|
2024-02-08 01:07:40 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
whiteboardIdRef.current = whiteboardId;
|
|
|
|
}, [whiteboardId]);
|
2024-02-08 04:20:06 +08:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
hasWBAccessRef.current = hasWBAccess;
|
|
|
|
|
|
|
|
if (!hasWBAccess && !isPresenter) {
|
2024-05-23 04:19:44 +08:00
|
|
|
tlEditorRef?.current?.setCurrentTool('noop');
|
|
|
|
} else if (hasWBAccess && !isPresenter) {
|
|
|
|
tlEditorRef?.current?.setCurrentTool('draw');
|
2024-02-08 04:20:06 +08:00
|
|
|
}
|
|
|
|
}, [hasWBAccess]);
|
2024-02-08 01:07:40 +08:00
|
|
|
|
2024-02-19 06:10:04 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
isPresenterRef.current = isPresenter;
|
|
|
|
|
2024-04-11 08:53:42 +08:00
|
|
|
if (!hasWBAccessRef.current && !isPresenter) {
|
2024-05-23 04:19:44 +08:00
|
|
|
tlEditorRef?.current?.setCurrentTool('noop');
|
2024-04-11 08:53:42 +08:00
|
|
|
}
|
|
|
|
}, [isPresenter]);
|
2024-02-19 06:10:04 +08:00
|
|
|
|
2023-12-12 03:31:21 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (!isEqual(prevShapesRef.current, shapes)) {
|
|
|
|
prevShapesRef.current = shapes;
|
2024-04-04 10:00:56 +08:00
|
|
|
setShapesVersion((v) => v + 1);
|
2023-02-24 07:47:34 +08:00
|
|
|
}
|
2023-12-12 03:31:21 +08:00
|
|
|
}, [shapes]);
|
2023-02-24 07:47:34 +08:00
|
|
|
|
2023-12-12 03:31:21 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (!isEqual(prevOtherCursorsRef.current, otherCursors)) {
|
|
|
|
prevOtherCursorsRef.current = otherCursors;
|
|
|
|
}
|
|
|
|
}, [otherCursors]);
|
2023-05-27 02:39:09 +08:00
|
|
|
|
2024-02-19 06:10:04 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (whiteboardRef.current) {
|
2024-04-04 10:00:56 +08:00
|
|
|
whiteboardRef.current.addEventListener("keydown", handleKeyDown, {
|
|
|
|
capture: true,
|
|
|
|
});
|
2024-02-19 06:10:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return () => {
|
2024-04-04 10:00:56 +08:00
|
|
|
whiteboardRef.current?.removeEventListener("keydown", handleKeyDown);
|
2024-02-19 06:10:04 +08:00
|
|
|
};
|
|
|
|
}, [whiteboardRef.current]);
|
|
|
|
|
2024-04-05 23:14:08 +08:00
|
|
|
const language = React.useMemo(() => {
|
2024-05-10 11:48:22 +08:00
|
|
|
return mapLanguage(locale?.toLowerCase() || "en");
|
|
|
|
}, [locale]);
|
2024-04-05 23:14:08 +08:00
|
|
|
|
|
|
|
const [cursorPosition, updateCursorPosition] = useCursor(
|
|
|
|
publishCursorUpdate,
|
|
|
|
whiteboardIdRef.current
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleKeyDown = (event) => {
|
2024-06-06 06:15:43 +08:00
|
|
|
if (event.key === 'Escape') {
|
|
|
|
tlEditorRef.current?.deselect(...tlEditorRef.current?.getSelectedShapes());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const editingShape = tlEditorRef.current?.getEditingShape();
|
|
|
|
if (editingShape && (isPresenterRef.current || hasWBAccessRef.current)) {
|
|
|
|
return;
|
2024-04-05 23:14:08 +08:00
|
|
|
}
|
2024-06-05 01:25:09 +08:00
|
|
|
|
|
|
|
// Mapping of simple key shortcuts to tldraw functions
|
|
|
|
const simpleKeyMap = {
|
|
|
|
'v': () => tlEditorRef.current?.setCurrentTool("select"),
|
|
|
|
'd': () => tlEditorRef.current?.setCurrentTool("draw"),
|
|
|
|
'e': () => tlEditorRef.current?.setCurrentTool("eraser"),
|
|
|
|
'h': () => tlEditorRef.current?.setCurrentTool("hand"),
|
|
|
|
'r': () => tlEditorRef.current?.setCurrentTool("rectangle"),
|
|
|
|
'o': () => tlEditorRef.current?.setCurrentTool("ellipse"),
|
|
|
|
'a': () => tlEditorRef.current?.setCurrentTool("arrow"),
|
|
|
|
'l': () => tlEditorRef.current?.setCurrentTool("line"),
|
|
|
|
't': () => tlEditorRef.current?.setCurrentTool("text"),
|
|
|
|
'f': () => tlEditorRef.current?.setCurrentTool("frame"),
|
|
|
|
'n': () => tlEditorRef.current?.setCurrentTool("note"),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (event.ctrlKey) {
|
|
|
|
const ctrlKeyMap = {
|
|
|
|
'a': () => {
|
|
|
|
tlEditorRef.current?.selectAll();
|
|
|
|
tlEditorRef.current?.setCurrentTool("select");
|
|
|
|
},
|
|
|
|
'd': () => {
|
|
|
|
tlEditorRef.current?.duplicateShapes(tlEditorRef.current?.getSelectedShapes(), { x: 10, y: 10 });
|
|
|
|
tlEditorRef.current?.selectNone();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
if (ctrlKeyMap[event.key]) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
ctrlKeyMap[event.key]();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (simpleKeyMap[event.key]) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
simpleKeyMap[event.key]();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-06 06:15:43 +08:00
|
|
|
const moveDistance = 10;
|
|
|
|
const selectedShapes = tlEditorRef.current?.getSelectedShapes().map(shape => shape.id);
|
|
|
|
|
|
|
|
const arrowKeyMap = {
|
|
|
|
'ArrowUp': { x: 0, y: -moveDistance },
|
|
|
|
'ArrowDown': { x: 0, y: moveDistance },
|
|
|
|
'ArrowLeft': { x: -moveDistance, y: 0 },
|
|
|
|
'ArrowRight': { x: moveDistance, y: 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (arrowKeyMap[event.key]) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
tlEditorRef.current?.nudgeShapes(selectedShapes, arrowKeyMap[event.key], { squashing: true });
|
2024-06-05 01:25:09 +08:00
|
|
|
}
|
2024-04-05 23:14:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleTldrawMount = (editor) => {
|
|
|
|
setTlEditor(editor);
|
|
|
|
setTldrawAPI(editor);
|
|
|
|
|
|
|
|
editor?.user?.updateUserPreferences({ locale: language });
|
|
|
|
|
|
|
|
const debouncePersistShape = debounce({ delay: 0 }, persistShapeWrapper);
|
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
const colorStyles = [
|
|
|
|
"black",
|
|
|
|
"blue",
|
|
|
|
"green",
|
|
|
|
"grey",
|
|
|
|
"light-blue",
|
|
|
|
"light-green",
|
|
|
|
"light-red",
|
|
|
|
"light-violet",
|
|
|
|
"orange",
|
|
|
|
"red",
|
|
|
|
"violet",
|
|
|
|
"yellow",
|
|
|
|
];
|
|
|
|
const dashStyles = ["dashed", "dotted", "draw", "solid"];
|
|
|
|
const fillStyles = ["none", "pattern", "semi", "solid"];
|
|
|
|
const fontStyles = ["draw", "mono", "sans", "serif"];
|
|
|
|
const sizeStyles = ["l", "m", "s", "xl"];
|
|
|
|
|
|
|
|
if (colorStyles.includes(colorStyle)) {
|
2024-04-05 23:14:08 +08:00
|
|
|
editor.setStyleForNextShapes(DefaultColorStyle, colorStyle);
|
|
|
|
}
|
2024-04-04 10:00:56 +08:00
|
|
|
if (dashStyles.includes(dashStyle)) {
|
2024-04-05 23:14:08 +08:00
|
|
|
editor.setStyleForNextShapes(DefaultDashStyle, dashStyle);
|
|
|
|
}
|
2024-04-04 10:00:56 +08:00
|
|
|
if (fillStyles.includes(fillStyle)) {
|
2024-04-05 23:14:08 +08:00
|
|
|
editor.setStyleForNextShapes(DefaultFillStyle, fillStyle);
|
|
|
|
}
|
2024-04-04 10:00:56 +08:00
|
|
|
if (fontStyles.includes(fontStyle)) {
|
2024-04-05 23:14:08 +08:00
|
|
|
editor.setStyleForNextShapes(DefaultFontStyle, fontStyle);
|
|
|
|
}
|
2024-04-04 10:00:56 +08:00
|
|
|
if (sizeStyles.includes(sizeStyle)) {
|
2024-04-05 23:14:08 +08:00
|
|
|
editor.setStyleForNextShapes(DefaultSizeStyle, sizeStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
editor.store.listen(
|
|
|
|
(entry) => {
|
|
|
|
const { changes } = entry;
|
|
|
|
const { added, updated, removed } = changes;
|
|
|
|
|
2024-04-24 02:59:26 +08:00
|
|
|
const addedCount = Object.keys(added).length;
|
|
|
|
const shapeNumberExceeded = Object.keys(prevShapesRef.current).length + addedCount > maxNumberOfAnnotations;
|
|
|
|
const invalidShapeType = Object.keys(added).find((id) => !isValidShapeType(added[id]));
|
|
|
|
|
|
|
|
if (shapeNumberExceeded || invalidShapeType) {
|
|
|
|
// notify and undo last command without persisting to not generate the onUndo/onRedo callback
|
|
|
|
if (shapeNumberExceeded) {
|
|
|
|
notifyShapeNumberExceeded(intl, maxNumberOfAnnotations);
|
|
|
|
} else {
|
|
|
|
notifyNotAllowedChange(intl);
|
|
|
|
}
|
|
|
|
editor.history.undo({ persist: false });
|
|
|
|
} else {
|
|
|
|
Object.values(added).forEach((record) => {
|
|
|
|
const updatedRecord = {
|
|
|
|
...record,
|
|
|
|
meta: {
|
|
|
|
...record.meta,
|
|
|
|
createdBy: currentUser?.userId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
persistShapeWrapper(
|
|
|
|
updatedRecord,
|
|
|
|
whiteboardIdRef.current,
|
|
|
|
isModeratorRef.current
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2024-04-05 23:14:08 +08:00
|
|
|
|
|
|
|
Object.values(updated).forEach(([_, record]) => {
|
2024-04-04 10:00:56 +08:00
|
|
|
const createdBy =
|
|
|
|
prevShapesRef.current[record?.id]?.meta?.createdBy ||
|
|
|
|
currentUser?.userId;
|
2024-04-05 23:14:08 +08:00
|
|
|
const updatedRecord = {
|
|
|
|
...record,
|
|
|
|
meta: {
|
|
|
|
createdBy,
|
|
|
|
updatedBy: currentUser?.userId,
|
|
|
|
},
|
|
|
|
};
|
2024-04-02 23:33:55 +08:00
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
persistShapeWrapper(
|
|
|
|
updatedRecord,
|
|
|
|
whiteboardIdRef.current,
|
|
|
|
isModeratorRef.current
|
|
|
|
);
|
2024-04-05 23:14:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
Object.values(removed).forEach((record) => {
|
|
|
|
removeShapes([record?.id]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
{ source: "user", scope: "document" }
|
|
|
|
);
|
|
|
|
|
|
|
|
editor.store.listen(
|
|
|
|
(entry) => {
|
|
|
|
const { changes, source } = entry;
|
|
|
|
const { updated } = changes;
|
|
|
|
const { "pointer:pointer": pointers } = updated;
|
2024-04-13 04:39:53 +08:00
|
|
|
|
2024-05-07 20:13:41 +08:00
|
|
|
if ((isPresenter || hasWBAccessRef.current) && pointers) {
|
2024-04-05 23:14:08 +08:00
|
|
|
const [prevPointer, nextPointer] = pointers;
|
|
|
|
updateCursorPosition(nextPointer?.x, nextPointer?.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
const camKey = `camera:page:${curPageIdRef.current}`;
|
|
|
|
const { [camKey]: cameras } = updated;
|
|
|
|
|
|
|
|
if (cameras) {
|
|
|
|
const [prevCam, nextCam] = cameras;
|
|
|
|
const panned = prevCam.x !== nextCam.x || prevCam.y !== nextCam.y;
|
|
|
|
|
|
|
|
if (panned && isPresenter) {
|
|
|
|
let viewedRegionW = SlideCalcUtil.calcViewedRegionWidth(
|
|
|
|
editor?.getViewportPageBounds()?.w,
|
|
|
|
currentPresentationPage?.scaledWidth
|
|
|
|
);
|
|
|
|
let viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
|
|
|
|
editor?.getViewportPageBounds()?.h,
|
|
|
|
currentPresentationPage?.scaledHeight
|
|
|
|
);
|
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
zoomSlide(viewedRegionW, viewedRegionH, nextCam.x, nextCam.y);
|
2024-04-05 23:14:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ source: "user" }
|
|
|
|
);
|
|
|
|
|
|
|
|
if (editor && curPageIdRef.current) {
|
|
|
|
const pages = [
|
|
|
|
{
|
|
|
|
meta: {},
|
|
|
|
id: `page:${curPageIdRef.current}`,
|
|
|
|
name: `Slide ${curPageIdRef.current}`,
|
|
|
|
index: `a1`,
|
|
|
|
typeName: "page",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
editor.store.mergeRemoteChanges(() => {
|
|
|
|
editor.batch(() => {
|
|
|
|
editor.store.put(pages);
|
|
|
|
// editor.deletePage(editor.currentPageId);
|
|
|
|
editor.setCurrentPage(`page:${curPageIdRef.current}`);
|
|
|
|
editor.store.put(assets);
|
|
|
|
editor.createShapes(bgShape);
|
|
|
|
editor.history.clear();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const remoteShapes = shapes;
|
|
|
|
const localShapes = editor.store.allRecords();
|
|
|
|
const filteredShapes =
|
|
|
|
localShapes.filter((item) => item.typeName === "shape") || [];
|
|
|
|
|
|
|
|
const localShapesObj = {};
|
|
|
|
filteredShapes.forEach((shape) => {
|
|
|
|
localShapesObj[shape.id] = shape;
|
|
|
|
});
|
|
|
|
|
|
|
|
const shapesToAdd = [];
|
|
|
|
for (let id in remoteShapes) {
|
|
|
|
if (
|
|
|
|
!localShapesObj[id] ||
|
|
|
|
JSON.stringify(remoteShapes[id]) !==
|
|
|
|
JSON.stringify(localShapesObj[id])
|
|
|
|
) {
|
|
|
|
shapesToAdd.push(remoteShapes[id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
editor.store.mergeRemoteChanges(() => {
|
|
|
|
if (shapesToAdd && shapesToAdd.length) {
|
|
|
|
shapesToAdd.forEach((shape) => {
|
|
|
|
delete shape.isModerator;
|
|
|
|
delete shape.questionType;
|
|
|
|
});
|
|
|
|
editor.store.put(shapesToAdd);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
editor.store.onBeforeChange = (prev, next, source) => {
|
|
|
|
if (next?.typeName === "instance_page_state") {
|
|
|
|
if (isPresenter || isModeratorRef.current) return next;
|
|
|
|
|
|
|
|
// Filter selectedShapeIds based on shape owner
|
2024-05-22 00:03:01 +08:00
|
|
|
if (next.selectedShapeIds.length > 0 && !isEqual(prev.selectedShapeIds, next.selectedShapeIds)) {
|
2024-04-04 10:00:56 +08:00
|
|
|
next.selectedShapeIds = next.selectedShapeIds.filter((shapeId) => {
|
2024-05-22 00:03:01 +08:00
|
|
|
const shapeOwner = prevShapesRef.current[shapeId]?.meta?.createdBy;
|
2024-04-05 23:14:08 +08:00
|
|
|
return !shapeOwner || shapeOwner === currentUser?.userId;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isEqual(prev.hoveredShapeId, next.hoveredShapeId)) {
|
2024-05-22 00:03:01 +08:00
|
|
|
const hoveredShapeOwner = prevShapesRef.current[next.hoveredShapeId]?.meta?.createdBy;
|
2024-04-05 23:14:08 +08:00
|
|
|
if (hoveredShapeOwner !== currentUser?.userId) {
|
|
|
|
next.hoveredShapeId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2024-05-22 00:03:01 +08:00
|
|
|
// Get viewport dimensions and bounds
|
|
|
|
const viewportPageBounds = editor.getViewportPageBounds();
|
|
|
|
const { w: viewportWidth, h: viewportHeight } = viewportPageBounds;
|
|
|
|
|
|
|
|
const presentationWidth = currentPresentationPage?.scaledWidth || 0;
|
|
|
|
const presentationHeight = currentPresentationPage?.scaledHeight || 0;
|
|
|
|
|
|
|
|
// Adjust camera position to ensure it stays within bounds
|
|
|
|
const panned = next?.id?.includes("camera") && (prev.x !== next.x || prev.y !== next.y);
|
2024-04-05 23:14:08 +08:00
|
|
|
if (panned) {
|
2024-05-22 00:03:01 +08:00
|
|
|
// Horizontal bounds check
|
|
|
|
if (next.x > 0) {
|
2024-04-05 23:14:08 +08:00
|
|
|
next.x = 0;
|
2024-05-22 00:03:01 +08:00
|
|
|
} else if (next.x < -(presentationWidth - viewportWidth)) {
|
|
|
|
next.x = -(presentationWidth - viewportWidth);
|
2024-04-05 23:14:08 +08:00
|
|
|
}
|
2024-05-22 00:03:01 +08:00
|
|
|
|
|
|
|
// Vertical bounds check
|
|
|
|
if (next.y > 0) {
|
2024-04-05 23:14:08 +08:00
|
|
|
next.y = 0;
|
2024-05-22 00:03:01 +08:00
|
|
|
} else if (next.y < -(presentationHeight - viewportHeight)) {
|
|
|
|
next.y = -(presentationHeight - viewportHeight);
|
2024-04-05 23:14:08 +08:00
|
|
|
}
|
|
|
|
}
|
2024-05-22 00:03:01 +08:00
|
|
|
|
2024-04-05 23:14:08 +08:00
|
|
|
return next;
|
|
|
|
};
|
2024-05-23 04:19:44 +08:00
|
|
|
|
|
|
|
if (!isPresenterRef.current && !hasWBAccessRef.current) {
|
|
|
|
editor.setCurrentTool('noop');
|
|
|
|
}
|
2024-04-05 23:14:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
isMountedRef.current = true;
|
|
|
|
};
|
|
|
|
|
2023-12-12 03:31:21 +08:00
|
|
|
const { shapesToAdd, shapesToUpdate, shapesToRemove } = React.useMemo(() => {
|
2024-04-05 23:14:08 +08:00
|
|
|
const selectedShapeIds = tlEditorRef.current?.getSelectedShapeIds() || [];
|
|
|
|
const localShapes = tlEditorRef.current?.getCurrentPageShapes();
|
2024-04-04 10:00:56 +08:00
|
|
|
const filteredShapes =
|
|
|
|
localShapes?.filter((item) => item?.index !== "a0") || [];
|
|
|
|
const localLookup = new Map(
|
|
|
|
filteredShapes.map((shape) => [shape.id, shape])
|
|
|
|
);
|
2023-12-12 03:31:21 +08:00
|
|
|
const remoteShapeIds = Object.keys(prevShapesRef.current);
|
2023-12-06 02:15:25 +08:00
|
|
|
const toAdd = [];
|
|
|
|
const toUpdate = [];
|
|
|
|
const toRemove = [];
|
|
|
|
|
|
|
|
filteredShapes.forEach((localShape) => {
|
|
|
|
if (!remoteShapeIds.includes(localShape.id)) {
|
2024-02-08 01:07:40 +08:00
|
|
|
toRemove.push(localShape.id);
|
2023-12-06 02:15:25 +08:00
|
|
|
}
|
|
|
|
});
|
2023-01-27 23:49:32 +08:00
|
|
|
|
2023-12-12 03:31:21 +08:00
|
|
|
Object.values(prevShapesRef.current).forEach((remoteShape) => {
|
2024-01-23 01:15:41 +08:00
|
|
|
if (!remoteShape.id) return;
|
2023-12-06 02:15:25 +08:00
|
|
|
const localShape = localLookup.get(remoteShape.id);
|
2024-01-23 01:15:41 +08:00
|
|
|
const prevShape = prevShapesRef.current[remoteShape.id];
|
2022-11-26 05:24:06 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
if (!localShape) {
|
2024-04-04 10:00:56 +08:00
|
|
|
delete remoteShape.isModerator;
|
|
|
|
delete remoteShape.questionType;
|
|
|
|
toAdd.push(remoteShape);
|
2024-02-08 01:07:40 +08:00
|
|
|
} else if (!isEqual(localShape, remoteShape) && prevShape) {
|
2024-06-04 20:37:58 +08:00
|
|
|
const remoteShapeMeta = remoteShape?.meta;
|
|
|
|
const isCreatedByCurrentUser = remoteShapeMeta?.createdBy === currentUser?.userId;
|
|
|
|
const isUpdatedByCurrentUser = remoteShapeMeta?.updatedBy === currentUser?.userId;
|
|
|
|
|
2024-06-04 22:53:21 +08:00
|
|
|
// System-level shapes (background image) lack createdBy and updatedBy metadata, which can cause false positives.
|
|
|
|
// These cases expect an early return and shouldn't be updated.
|
2024-06-04 08:00:37 +08:00
|
|
|
if (
|
2024-06-04 20:37:58 +08:00
|
|
|
remoteShapeMeta && (
|
|
|
|
(isCreatedByCurrentUser && isUpdatedByCurrentUser)
|
2024-06-04 22:53:21 +08:00
|
|
|
|| (!isCreatedByCurrentUser && isUpdatedByCurrentUser)
|
2024-06-04 20:37:58 +08:00
|
|
|
)
|
2024-06-04 08:00:37 +08:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
const diff = {
|
|
|
|
id: remoteShape.id,
|
|
|
|
type: remoteShape.type,
|
|
|
|
typeName: remoteShape.typeName,
|
|
|
|
};
|
2023-01-18 21:12:16 +08:00
|
|
|
|
2024-04-05 23:14:08 +08:00
|
|
|
Object.keys(remoteShape).forEach((key) => {
|
2024-04-04 10:00:56 +08:00
|
|
|
if (
|
|
|
|
key !== "isModerator" &&
|
|
|
|
!isEqual(remoteShape[key], localShape[key])
|
|
|
|
) {
|
2024-04-05 23:14:08 +08:00
|
|
|
diff[key] = remoteShape[key];
|
2023-12-12 03:31:21 +08:00
|
|
|
}
|
2024-04-05 23:14:08 +08:00
|
|
|
});
|
2023-12-12 03:31:21 +08:00
|
|
|
|
2024-04-05 23:14:08 +08:00
|
|
|
if (remoteShape.props) {
|
|
|
|
Object.keys(remoteShape.props).forEach((key) => {
|
|
|
|
if (!isEqual(remoteShape.props[key], localShape.props[key])) {
|
|
|
|
diff.props = diff.props || {};
|
|
|
|
diff.props[key] = remoteShape.props[key];
|
|
|
|
}
|
|
|
|
});
|
2023-12-06 02:15:25 +08:00
|
|
|
}
|
2024-04-05 23:14:08 +08:00
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
delete diff.isModerator;
|
|
|
|
delete diff.questionType;
|
2024-04-05 23:14:08 +08:00
|
|
|
toUpdate.push(diff);
|
2023-03-27 06:08:09 +08:00
|
|
|
}
|
2023-12-06 02:15:25 +08:00
|
|
|
});
|
2023-03-14 00:16:37 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
return {
|
|
|
|
shapesToAdd: toAdd,
|
|
|
|
shapesToUpdate: toUpdate,
|
|
|
|
shapesToRemove: toRemove,
|
2023-01-18 21:12:16 +08:00
|
|
|
};
|
2024-02-08 01:07:40 +08:00
|
|
|
}, [prevShapesRef.current, curPageIdRef.current]);
|
2023-01-18 21:12:16 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
const setCamera = (zoom, x = 0, y = 0) => {
|
|
|
|
if (tlEditorRef.current) {
|
|
|
|
tlEditorRef.current.setCamera({ x, y, z: zoom }, false);
|
2023-05-25 01:36:58 +08:00
|
|
|
}
|
2023-12-06 02:15:25 +08:00
|
|
|
};
|
|
|
|
|
2024-01-09 22:31:08 +08:00
|
|
|
const calculateZoomValue = (localWidth, localHeight, isViewer = false) => {
|
|
|
|
let calcedZoom;
|
|
|
|
if (isViewer) {
|
|
|
|
// Logic originally in calculateViewerZoom
|
|
|
|
calcedZoom = fitToWidth
|
|
|
|
? presentationAreaWidth / localWidth
|
|
|
|
: Math.min(
|
|
|
|
presentationAreaWidth / localWidth,
|
|
|
|
presentationAreaHeight / localHeight
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Logic originally in calculateZoom
|
|
|
|
calcedZoom = fitToWidth
|
|
|
|
? presentationAreaWidth / localWidth
|
|
|
|
: Math.min(
|
|
|
|
presentationAreaWidth / localWidth,
|
|
|
|
presentationAreaHeight / localHeight
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return calcedZoom === 0 || calcedZoom === Infinity
|
|
|
|
? HUNDRED_PERCENT
|
|
|
|
: calcedZoom;
|
|
|
|
};
|
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
const calculateZoomWithGapValue = (
|
|
|
|
localWidth,
|
|
|
|
localHeight,
|
|
|
|
isViewer = false,
|
|
|
|
widthAdjustment = 0
|
|
|
|
) => {
|
|
|
|
let presentationWidth = presentationAreaWidth - widthAdjustment;
|
|
|
|
let calcedZoom = (baseZoom = fitToWidth
|
|
|
|
? presentationWidth / localWidth
|
|
|
|
: Math.min(
|
|
|
|
presentationWidth / localWidth,
|
|
|
|
presentationAreaHeight / localHeight
|
|
|
|
));
|
|
|
|
return calcedZoom === 0 || calcedZoom === Infinity
|
|
|
|
? HUNDRED_PERCENT
|
|
|
|
: calcedZoom;
|
|
|
|
};
|
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
useMouseEvents(
|
2024-01-09 22:31:08 +08:00
|
|
|
{ whiteboardRef, tlEditorRef, isWheelZoomRef, initialZoomRef },
|
2023-12-06 02:15:25 +08:00
|
|
|
{
|
|
|
|
isPresenter,
|
2024-02-08 04:20:06 +08:00
|
|
|
hasWBAccess: hasWBAccessRef.current,
|
2023-12-06 02:15:25 +08:00
|
|
|
whiteboardToolbarAutoHide,
|
|
|
|
animations,
|
|
|
|
publishCursorUpdate,
|
2024-02-08 01:07:40 +08:00
|
|
|
whiteboardId: whiteboardIdRef.current,
|
2023-12-06 02:15:25 +08:00
|
|
|
cursorPosition,
|
|
|
|
updateCursorPosition,
|
|
|
|
toggleToolsAnimations,
|
2024-01-09 22:31:08 +08:00
|
|
|
currentPresentationPage,
|
2024-02-01 02:53:05 +08:00
|
|
|
zoomChanger,
|
2024-03-25 01:22:49 +08:00
|
|
|
setIsMouseDown,
|
|
|
|
setIsWheelZoom,
|
|
|
|
setWheelZoomTimeout,
|
2023-03-08 21:01:18 +08:00
|
|
|
}
|
2023-12-06 02:15:25 +08:00
|
|
|
);
|
2023-03-08 21:01:18 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
tlEditorRef.current = tlEditor;
|
|
|
|
}, [tlEditor]);
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2024-02-08 01:07:40 +08:00
|
|
|
React.useEffect(() => {
|
2024-02-09 00:13:38 +08:00
|
|
|
let undoRedoIntervalId = null;
|
|
|
|
|
|
|
|
const undo = () => {
|
2024-02-08 01:07:40 +08:00
|
|
|
tlEditorRef?.current?.history?.undo();
|
2024-02-09 00:13:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const redo = () => {
|
2024-02-08 01:07:40 +08:00
|
|
|
tlEditorRef?.current?.history?.redo();
|
2024-02-09 00:13:38 +08:00
|
|
|
};
|
2024-02-08 01:07:40 +08:00
|
|
|
|
2024-02-27 01:06:18 +08:00
|
|
|
const handleArrowPress = (event) => {
|
|
|
|
const currPageNum = parseInt(curPageIdRef.current);
|
2024-05-17 01:20:20 +08:00
|
|
|
const shapeSelected = tlEditorRef.current.getSelectedShapes()?.length > 0;
|
2024-02-27 01:06:18 +08:00
|
|
|
const changeSlide = (direction) => {
|
2024-03-16 04:11:56 +08:00
|
|
|
if (!currentPresentationPage) return;
|
2024-02-27 01:06:18 +08:00
|
|
|
let newSlideNum = currPageNum + direction;
|
2024-04-04 10:00:56 +08:00
|
|
|
const outOfBounds =
|
|
|
|
direction > 0
|
|
|
|
? newSlideNum > currentPresentationPage?.totalPages
|
|
|
|
: newSlideNum < 1;
|
2024-02-27 01:06:18 +08:00
|
|
|
|
|
|
|
if (outOfBounds) return;
|
|
|
|
|
|
|
|
skipToSlide(newSlideNum);
|
|
|
|
zoomChanger(HUNDRED_PERCENT);
|
|
|
|
zoomSlide(HUNDRED_PERCENT, HUNDRED_PERCENT, 0, 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!shapeSelected) {
|
2024-02-27 01:10:40 +08:00
|
|
|
if (event.keyCode === KEY_CODES.ARROW_RIGHT) {
|
2024-02-27 01:06:18 +08:00
|
|
|
changeSlide(1); // Move to the next slide
|
2024-02-27 01:10:40 +08:00
|
|
|
} else if (event.keyCode === KEY_CODES.ARROW_LEFT) {
|
2024-02-27 01:06:18 +08:00
|
|
|
changeSlide(-1); // Move to the previous slide
|
|
|
|
}
|
|
|
|
}
|
2024-04-04 10:00:56 +08:00
|
|
|
};
|
2024-02-27 01:06:18 +08:00
|
|
|
|
|
|
|
const handleUndoRedoOnCondition = (condition, action) => {
|
|
|
|
if (condition) {
|
|
|
|
action();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-08 01:07:40 +08:00
|
|
|
const handleKeyDown = (event) => {
|
2024-04-04 10:00:56 +08:00
|
|
|
const undoCondition =
|
|
|
|
event.ctrlKey && event.key === "z" && !event.shiftKey;
|
|
|
|
const redoCondition =
|
|
|
|
event.ctrlKey && event.shiftKey && event.key === "Z";
|
|
|
|
|
|
|
|
if (
|
|
|
|
(undoCondition || redoCondition) &&
|
2024-05-17 01:20:20 +08:00
|
|
|
(isPresenterRef.current || hasWBAccessRef.current)
|
2024-04-04 10:00:56 +08:00
|
|
|
) {
|
2024-02-08 01:07:40 +08:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2024-02-09 00:13:38 +08:00
|
|
|
|
|
|
|
if (!undoRedoIntervalId) {
|
|
|
|
undoRedoIntervalId = setInterval(() => {
|
2024-02-27 01:06:18 +08:00
|
|
|
handleUndoRedoOnCondition(undoCondition, undo);
|
|
|
|
handleUndoRedoOnCondition(redoCondition, redo);
|
2024-02-09 00:13:38 +08:00
|
|
|
}, 150);
|
|
|
|
}
|
2024-02-08 01:07:40 +08:00
|
|
|
}
|
2024-02-27 01:06:18 +08:00
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
if (
|
|
|
|
(event.keyCode === KEY_CODES.ARROW_RIGHT ||
|
|
|
|
event.keyCode === KEY_CODES.ARROW_LEFT) &&
|
2024-05-17 01:20:20 +08:00
|
|
|
isPresenterRef.current
|
2024-04-04 10:00:56 +08:00
|
|
|
) {
|
|
|
|
handleArrowPress(event);
|
2024-02-27 01:06:18 +08:00
|
|
|
}
|
2024-02-08 01:07:40 +08:00
|
|
|
};
|
|
|
|
|
2024-02-09 00:13:38 +08:00
|
|
|
const handleKeyUp = (event) => {
|
2024-04-04 10:00:56 +08:00
|
|
|
if ((event.key === "z" || event.key === "Z") && undoRedoIntervalId) {
|
2024-02-09 00:13:38 +08:00
|
|
|
clearInterval(undoRedoIntervalId);
|
|
|
|
undoRedoIntervalId = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
whiteboardRef.current?.addEventListener("keydown", handleKeyDown, {
|
|
|
|
capture: true,
|
|
|
|
});
|
|
|
|
whiteboardRef.current?.addEventListener("keyup", handleKeyUp, {
|
|
|
|
capture: true,
|
|
|
|
});
|
2024-02-08 01:07:40 +08:00
|
|
|
|
|
|
|
return () => {
|
2024-04-04 10:00:56 +08:00
|
|
|
whiteboardRef.current?.removeEventListener("keydown", handleKeyDown);
|
|
|
|
whiteboardRef.current?.removeEventListener("keyup", handleKeyUp);
|
2024-02-09 00:13:38 +08:00
|
|
|
if (undoRedoIntervalId) {
|
|
|
|
clearInterval(undoRedoIntervalId);
|
|
|
|
}
|
2024-02-08 01:07:40 +08:00
|
|
|
};
|
2024-02-09 00:13:38 +08:00
|
|
|
}, [whiteboardRef.current]);
|
2024-02-08 01:07:40 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
zoomValueRef.current = zoomValue;
|
2024-04-02 23:33:55 +08:00
|
|
|
let timeoutId = null;
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
if (
|
|
|
|
tlEditor &&
|
|
|
|
curPageIdRef.current &&
|
|
|
|
currentPresentationPage &&
|
|
|
|
isPresenter &&
|
|
|
|
isWheelZoomRef.current === false
|
|
|
|
) {
|
|
|
|
const zoomLevelForReset =
|
|
|
|
initialZoomRef.current ||
|
|
|
|
calculateZoomValue(
|
|
|
|
currentPresentationPage.scaledWidth,
|
|
|
|
currentPresentationPage.scaledHeight
|
|
|
|
);
|
2022-11-16 23:01:12 +08:00
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
const zoomCamera =
|
|
|
|
zoomValue === HUNDRED_PERCENT
|
|
|
|
? zoomLevelForReset
|
|
|
|
: (zoomLevelForReset * zoomValue) / HUNDRED_PERCENT;
|
2024-04-04 02:39:24 +08:00
|
|
|
const camera = tlEditorRef.current.getCamera();
|
2024-02-02 08:36:40 +08:00
|
|
|
|
|
|
|
const nextCamera = {
|
2024-04-04 10:00:56 +08:00
|
|
|
x:
|
|
|
|
zoomValue === HUNDRED_PERCENT
|
|
|
|
? 0
|
|
|
|
: camera.x +
|
|
|
|
((camera.x + tlEditorRef.current.getViewportPageBounds().w / 2) /
|
|
|
|
zoomCamera -
|
|
|
|
camera.x),
|
|
|
|
y:
|
|
|
|
zoomValue === HUNDRED_PERCENT
|
|
|
|
? 0
|
|
|
|
: camera.y +
|
|
|
|
((camera.y + tlEditorRef.current.getViewportPageBounds().h / 2) /
|
|
|
|
zoomCamera -
|
|
|
|
camera.y),
|
2024-02-02 08:36:40 +08:00
|
|
|
z: zoomCamera,
|
|
|
|
};
|
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
if (
|
|
|
|
zoomValue !== prevZoomValueRef.current ||
|
|
|
|
zoomValue === HUNDRED_PERCENT
|
|
|
|
) {
|
2024-02-02 08:36:40 +08:00
|
|
|
tlEditor.setCamera(nextCamera, false);
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2024-04-02 23:33:55 +08:00
|
|
|
timeoutId = setTimeout(() => {
|
2024-04-04 02:39:24 +08:00
|
|
|
if (zoomValue === HUNDRED_PERCENT) {
|
|
|
|
zoomChanger(HUNDRED_PERCENT);
|
2024-04-04 10:00:56 +08:00
|
|
|
zoomSlide(HUNDRED_PERCENT, HUNDRED_PERCENT, 0, 0);
|
2024-04-04 02:39:24 +08:00
|
|
|
} else {
|
|
|
|
// Recalculate viewed region width and height for zoomSlide call
|
|
|
|
let viewedRegionW = SlideCalcUtil.calcViewedRegionWidth(
|
|
|
|
tlEditorRef.current.getViewportPageBounds().w,
|
|
|
|
currentPresentationPage.scaledWidth
|
|
|
|
);
|
|
|
|
let viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
|
|
|
|
tlEditorRef.current.getViewportPageBounds().h,
|
|
|
|
currentPresentationPage.scaledHeight
|
|
|
|
);
|
2024-01-09 22:31:08 +08:00
|
|
|
|
2024-04-04 10:00:56 +08:00
|
|
|
zoomSlide(viewedRegionW, viewedRegionH, nextCamera.x, nextCamera.y);
|
2024-04-04 02:39:24 +08:00
|
|
|
}
|
2024-05-10 11:48:22 +08:00
|
|
|
}, 500);
|
2022-10-25 23:53:19 +08:00
|
|
|
}
|
2022-04-26 21:55:05 +08:00
|
|
|
}
|
2022-04-05 22:49:13 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
// Update the previous zoom value ref with the current zoom value
|
|
|
|
prevZoomValueRef.current = zoomValue;
|
2024-04-02 23:33:55 +08:00
|
|
|
return () => clearTimeout(timeoutId);
|
2024-02-08 01:07:40 +08:00
|
|
|
}, [zoomValue, tlEditor, curPageIdRef.current, isWheelZoomRef.current]);
|
2022-04-05 22:49:13 +08:00
|
|
|
|
2024-02-01 02:53:05 +08:00
|
|
|
React.useEffect(() => {
|
2024-04-02 23:33:55 +08:00
|
|
|
// A slight delay to ensure the canvas has rendered
|
|
|
|
const timeoutId = setTimeout(() => {
|
2024-04-04 10:00:56 +08:00
|
|
|
if (
|
|
|
|
currentPresentationPage.scaledWidth > 0 &&
|
|
|
|
currentPresentationPage.scaledHeight > 0
|
|
|
|
) {
|
2024-04-02 23:33:55 +08:00
|
|
|
// Subtract the toolbar height from the presentation area height for the presenter
|
2024-04-04 10:00:56 +08:00
|
|
|
const adjustedPresentationAreaHeight = isPresenter
|
|
|
|
? presentationAreaHeight - 40
|
|
|
|
: presentationAreaHeight;
|
|
|
|
const slideAspectRatio =
|
|
|
|
currentPresentationPage.scaledWidth /
|
|
|
|
currentPresentationPage.scaledHeight;
|
|
|
|
const presentationAreaAspectRatio =
|
|
|
|
presentationAreaWidth / adjustedPresentationAreaHeight;
|
2024-04-02 23:33:55 +08:00
|
|
|
|
|
|
|
let initialZoom;
|
|
|
|
|
|
|
|
if (slideAspectRatio > presentationAreaAspectRatio) {
|
2024-04-04 10:00:56 +08:00
|
|
|
initialZoom =
|
|
|
|
presentationAreaWidth / currentPresentationPage.scaledWidth;
|
2024-04-02 23:33:55 +08:00
|
|
|
} else {
|
2024-04-04 10:00:56 +08:00
|
|
|
initialZoom =
|
|
|
|
adjustedPresentationAreaHeight /
|
|
|
|
currentPresentationPage.scaledHeight;
|
2024-04-02 23:33:55 +08:00
|
|
|
}
|
2024-02-01 02:53:05 +08:00
|
|
|
|
2024-04-02 23:33:55 +08:00
|
|
|
const tldrawZoom = initialZoom;
|
|
|
|
initialZoomRef.current = initialZoom;
|
|
|
|
setInitialZoomSet(true);
|
|
|
|
prevZoomValueRef.current = zoomValue;
|
|
|
|
}
|
2024-05-10 11:48:22 +08:00
|
|
|
}, CAMERA_UPDATE_DELAY);
|
2024-04-02 23:33:55 +08:00
|
|
|
|
|
|
|
return () => clearTimeout(timeoutId);
|
|
|
|
}, [
|
|
|
|
currentPresentationPage,
|
|
|
|
presentationAreaWidth,
|
|
|
|
presentationAreaHeight,
|
|
|
|
isPresenter,
|
|
|
|
]);
|
2022-04-05 22:49:13 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
React.useEffect(() => {
|
2024-04-03 02:00:25 +08:00
|
|
|
const handleResize = () => {
|
2024-04-13 04:39:53 +08:00
|
|
|
if (!initialViewBoxWidthRef.current) {
|
|
|
|
initialViewBoxWidthRef.current = currentPresentationPageRef.current?.scaledViewBoxWidth;
|
|
|
|
}
|
2024-04-03 02:00:25 +08:00
|
|
|
// Calculate the absolute difference
|
2024-04-04 10:00:56 +08:00
|
|
|
const heightDifference = Math.abs(
|
|
|
|
presentationAreaHeight - lastKnownHeight.current
|
|
|
|
);
|
|
|
|
const widthDifference = Math.abs(
|
|
|
|
presentationAreaWidth - lastKnownWidth.current
|
|
|
|
);
|
2023-12-06 02:15:25 +08:00
|
|
|
|
2024-04-03 02:00:25 +08:00
|
|
|
// Check if the difference is greater than the threshold
|
|
|
|
if (heightDifference > THRESHOLD || widthDifference > THRESHOLD) {
|
|
|
|
// Update the last known dimensions
|
|
|
|
lastKnownHeight.current = presentationAreaHeight;
|
|
|
|
lastKnownWidth.current = presentationAreaWidth;
|
2022-04-11 00:31:12 +08:00
|
|
|
|
2024-04-03 02:00:25 +08:00
|
|
|
if (
|
|
|
|
presentationAreaHeight > 0 &&
|
|
|
|
presentationAreaWidth > 0 &&
|
|
|
|
tlEditor &&
|
|
|
|
currentPresentationPage &&
|
|
|
|
currentPresentationPage.scaledWidth > 0 &&
|
|
|
|
currentPresentationPage.scaledHeight > 0
|
|
|
|
) {
|
|
|
|
const currentZoom = zoomValueRef.current || HUNDRED_PERCENT;
|
|
|
|
const baseZoom = calculateZoomValue(
|
|
|
|
currentPresentationPage.scaledWidth,
|
|
|
|
currentPresentationPage.scaledHeight
|
|
|
|
);
|
|
|
|
let adjustedZoom = baseZoom * (currentZoom / HUNDRED_PERCENT);
|
|
|
|
if (isPresenter) {
|
2024-05-08 23:24:25 +08:00
|
|
|
const container = document.querySelector(
|
|
|
|
'[data-test="presentationContainer"]'
|
|
|
|
);
|
|
|
|
const innerWrapper = document.getElementById(
|
|
|
|
"presentationInnerWrapper"
|
|
|
|
);
|
|
|
|
const containerWidth = container ? container.offsetWidth : 0;
|
|
|
|
const innerWrapperWidth = innerWrapper
|
|
|
|
? innerWrapper.offsetWidth
|
|
|
|
: 0;
|
|
|
|
const widthGap = Math.max(containerWidth - innerWrapperWidth, 0);
|
|
|
|
const camera = tlEditorRef.current.getCamera();
|
|
|
|
|
|
|
|
let adjustedZoom;
|
|
|
|
if (widthGap > 0) {
|
|
|
|
adjustedZoom = calculateZoomWithGapValue(
|
|
|
|
currentPresentationPage.scaledWidth,
|
|
|
|
currentPresentationPage.scaledHeight,
|
|
|
|
false,
|
|
|
|
widthGap
|
2024-04-03 02:00:25 +08:00
|
|
|
);
|
2024-04-04 10:00:56 +08:00
|
|
|
|
2024-05-08 23:24:25 +08:00
|
|
|
adjustedZoom *= currentZoom / HUNDRED_PERCENT;
|
|
|
|
} else {
|
|
|
|
adjustedZoom = baseZoom * (currentZoom / HUNDRED_PERCENT);
|
|
|
|
}
|
2024-04-04 10:00:56 +08:00
|
|
|
|
2024-05-08 23:24:25 +08:00
|
|
|
const zoomToApply =
|
|
|
|
widthGap > 0
|
|
|
|
? adjustedZoom
|
|
|
|
: baseZoom * (currentZoom / HUNDRED_PERCENT);
|
2024-04-04 10:00:56 +08:00
|
|
|
|
2024-05-08 23:24:25 +08:00
|
|
|
setCamera(zoomToApply, camera.x, camera.y);
|
2023-12-06 02:15:25 +08:00
|
|
|
} else {
|
2024-04-03 02:00:25 +08:00
|
|
|
// Viewer logic
|
|
|
|
const effectiveZoom = calculateEffectiveZoom(
|
2024-04-13 04:39:53 +08:00
|
|
|
initialViewBoxWidthRef.current,
|
2024-04-03 02:00:25 +08:00
|
|
|
currentPresentationPage.scaledViewBoxWidth
|
|
|
|
);
|
|
|
|
adjustedZoom = baseZoom * (effectiveZoom / HUNDRED_PERCENT);
|
|
|
|
|
|
|
|
const camera = tlEditorRef.current.getCamera();
|
2024-03-02 01:50:08 +08:00
|
|
|
setCamera(adjustedZoom, camera.x, camera.y);
|
2023-12-06 02:15:25 +08:00
|
|
|
}
|
2022-08-24 02:19:17 +08:00
|
|
|
}
|
2022-09-30 22:35:29 +08:00
|
|
|
}
|
2024-04-04 10:00:56 +08:00
|
|
|
};
|
2024-04-03 02:00:25 +08:00
|
|
|
|
2024-05-10 11:48:22 +08:00
|
|
|
const timeoutId = setTimeout(handleResize, CAMERA_UPDATE_DELAY);
|
2024-04-03 02:00:25 +08:00
|
|
|
|
|
|
|
return () => clearTimeout(timeoutId);
|
2024-02-08 01:07:40 +08:00
|
|
|
}, [presentationAreaHeight, presentationAreaWidth, curPageIdRef.current]);
|
2022-09-30 22:35:29 +08:00
|
|
|
|
2022-04-26 21:55:05 +08:00
|
|
|
React.useEffect(() => {
|
2023-12-06 02:15:25 +08:00
|
|
|
if (!fitToWidth && isPresenter) {
|
|
|
|
zoomChanger(HUNDRED_PERCENT);
|
2024-04-04 10:00:56 +08:00
|
|
|
zoomSlide(HUNDRED_PERCENT, HUNDRED_PERCENT, 0, 0);
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
2023-12-06 02:15:25 +08:00
|
|
|
}, [fitToWidth, isPresenter]);
|
2022-04-05 22:49:13 +08:00
|
|
|
|
2022-05-20 01:24:47 +08:00
|
|
|
React.useEffect(() => {
|
2024-04-13 04:39:53 +08:00
|
|
|
if (!isPresenter && tlEditorRef.current && initialViewBoxWidthRef.current && currentPresentationPage) {
|
|
|
|
const currentZoomRatio = currentPresentationPage.scaledViewBoxWidth / currentPresentationPage.scaledWidth;
|
|
|
|
const initialZoomRatio = initialViewBoxWidthRef.current / currentPresentationPage.scaledWidth;
|
|
|
|
const effectiveZoom = initialZoomRatio / currentZoomRatio;
|
2023-12-06 02:15:25 +08:00
|
|
|
|
2024-04-13 04:39:53 +08:00
|
|
|
let adjustedZoom = calculateZoomValue(
|
|
|
|
currentPresentationPage.scaledWidth,
|
|
|
|
currentPresentationPage.scaledHeight
|
|
|
|
) * effectiveZoom;
|
2023-12-06 02:15:25 +08:00
|
|
|
|
2024-04-13 04:39:53 +08:00
|
|
|
const adjustedXPos = currentPresentationPage.xOffset;
|
|
|
|
const adjustedYPos = currentPresentationPage.yOffset;
|
2024-04-02 23:33:55 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
setCamera(
|
2024-04-13 04:39:53 +08:00
|
|
|
adjustedZoom,
|
|
|
|
adjustedXPos,
|
|
|
|
adjustedYPos
|
2023-12-06 02:15:25 +08:00
|
|
|
);
|
2023-08-28 03:19:04 +08:00
|
|
|
}
|
2024-04-13 04:39:53 +08:00
|
|
|
}, [currentPresentationPage, initialViewBoxWidthRef.current]);
|
2022-05-20 01:24:47 +08:00
|
|
|
|
2022-08-16 20:12:43 +08:00
|
|
|
React.useEffect(() => {
|
2023-12-12 03:31:21 +08:00
|
|
|
// Check if there are any changes to be made
|
2023-12-06 02:15:25 +08:00
|
|
|
if (shapesToAdd.length || shapesToUpdate.length || shapesToRemove.length) {
|
2024-02-14 08:44:47 +08:00
|
|
|
const tlStoreUpdateTimeoutId = setTimeout(() => {
|
|
|
|
tlEditor?.store?.mergeRemoteChanges(() => {
|
|
|
|
if (shapesToRemove.length > 0) {
|
|
|
|
tlEditor?.store?.remove(shapesToRemove);
|
|
|
|
}
|
|
|
|
if (shapesToAdd.length) {
|
|
|
|
tlEditor?.store?.put(shapesToAdd);
|
|
|
|
}
|
|
|
|
if (shapesToUpdate.length) {
|
|
|
|
tlEditor?.updateShapes(shapesToUpdate);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 150);
|
|
|
|
|
|
|
|
return () => clearTimeout(tlStoreUpdateTimeoutId);
|
2022-08-16 20:12:43 +08:00
|
|
|
}
|
2023-12-06 02:15:25 +08:00
|
|
|
}, [shapesToAdd, shapesToUpdate, shapesToRemove]);
|
2022-08-16 20:12:43 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
// Updating presences in tldraw store based on changes in cursors
|
2022-08-19 02:18:02 +08:00
|
|
|
React.useEffect(() => {
|
2023-12-06 02:15:25 +08:00
|
|
|
if (tlEditorRef.current) {
|
|
|
|
const useElement = document.querySelector(".tl-cursor use");
|
2024-01-18 01:44:31 +08:00
|
|
|
if (useElement && !isMultiUserActive && !isPresenter) {
|
2023-12-06 02:15:25 +08:00
|
|
|
useElement.setAttribute("href", "#redPointer");
|
|
|
|
} else if (useElement) {
|
|
|
|
useElement.setAttribute("href", "#cursor");
|
|
|
|
}
|
|
|
|
|
2023-12-12 03:31:21 +08:00
|
|
|
const updatedPresences = prevOtherCursorsRef.current
|
2023-12-06 02:15:25 +08:00
|
|
|
.map(({ userId, user, xPercent, yPercent }) => {
|
|
|
|
const { presenter, name } = user;
|
|
|
|
const id = InstancePresenceRecordType.createId(userId);
|
|
|
|
const active = yPercent !== -1 && yPercent !== -1;
|
|
|
|
// if cursor is not active remove it from tldraw store
|
2024-04-04 10:00:56 +08:00
|
|
|
if (
|
|
|
|
!active ||
|
|
|
|
(hideViewersCursor &&
|
|
|
|
user.role === "VIEWER" &&
|
|
|
|
!currentUser?.presenter) ||
|
|
|
|
(!presenter && !isMultiUserActive)
|
|
|
|
) {
|
2023-12-06 02:15:25 +08:00
|
|
|
tlEditorRef.current?.store.remove([id]);
|
|
|
|
return null;
|
2022-10-19 23:13:08 +08:00
|
|
|
}
|
2023-12-06 02:15:25 +08:00
|
|
|
|
|
|
|
const cursor = {
|
|
|
|
x: xPercent,
|
|
|
|
y: yPercent,
|
|
|
|
type: "default",
|
|
|
|
rotation: 0,
|
|
|
|
};
|
|
|
|
const color = presenter ? "#FF0000" : "#70DB70";
|
|
|
|
const c = {
|
|
|
|
...InstancePresenceRecordType.create({
|
|
|
|
id,
|
2024-04-05 23:14:08 +08:00
|
|
|
currentPageId: `page:${curPageIdRef.current}`,
|
2023-12-06 02:15:25 +08:00
|
|
|
userId,
|
|
|
|
userName: name,
|
|
|
|
cursor,
|
|
|
|
color,
|
|
|
|
}),
|
|
|
|
lastActivityTimestamp: Date.now(),
|
|
|
|
};
|
|
|
|
return c;
|
|
|
|
})
|
|
|
|
.filter((cursor) => cursor && cursor.userId !== currentUser?.userId);
|
|
|
|
|
|
|
|
// If there are any updated presences, put them all in the store
|
|
|
|
if (updatedPresences.length) {
|
|
|
|
tlEditorRef.current?.store.put(updatedPresences);
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
2023-12-12 03:31:21 +08:00
|
|
|
}, [prevOtherCursorsRef.current]);
|
2022-05-20 01:24:47 +08:00
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
// set current tldraw page when presentation id updates
|
2022-08-15 06:49:39 +08:00
|
|
|
React.useEffect(() => {
|
2024-02-08 01:07:40 +08:00
|
|
|
if (tlEditorRef.current && curPageIdRef.current !== "0") {
|
|
|
|
const pages = [
|
|
|
|
{
|
|
|
|
meta: {},
|
|
|
|
id: `page:${curPageIdRef.current}`,
|
|
|
|
name: `Slide ${curPageIdRef.current}`,
|
|
|
|
index: `a1`,
|
|
|
|
typeName: "page",
|
|
|
|
},
|
|
|
|
];
|
2022-08-15 06:49:39 +08:00
|
|
|
|
2024-02-08 01:07:40 +08:00
|
|
|
tlEditorRef.current.store.mergeRemoteChanges(() => {
|
|
|
|
tlEditorRef.current.batch(() => {
|
|
|
|
tlEditorRef.current.store.put(pages);
|
2024-04-05 23:14:08 +08:00
|
|
|
// tlEditorRef.current.deletePage(tlEditorRef.current.currentPageId);
|
2024-02-08 01:07:40 +08:00
|
|
|
tlEditorRef.current.setCurrentPage(`page:${curPageIdRef.current}`);
|
|
|
|
tlEditorRef.current.store.put(assets);
|
|
|
|
tlEditorRef.current.createShapes(bgShape);
|
|
|
|
tlEditorRef.current.history.clear();
|
|
|
|
});
|
|
|
|
});
|
2023-12-06 02:15:25 +08:00
|
|
|
|
|
|
|
whiteboardToolbarAutoHide &&
|
|
|
|
toggleToolsAnimations(
|
|
|
|
"fade-in",
|
|
|
|
"fade-out",
|
|
|
|
"0s",
|
2024-02-08 04:20:06 +08:00
|
|
|
hasWBAccessRef.current || isPresenter
|
2023-12-06 02:15:25 +08:00
|
|
|
);
|
|
|
|
slideChanged.current = false;
|
|
|
|
slideNext.current = null;
|
|
|
|
}
|
2024-02-08 01:07:40 +08:00
|
|
|
}, [curPageIdRef.current]);
|
2023-05-27 02:39:09 +08:00
|
|
|
|
2024-05-10 11:48:22 +08:00
|
|
|
const adjustCameraOnMount = (includeViewerLogic = true) => {
|
|
|
|
const storedWidth = localStorage.getItem('initialViewBoxWidth');
|
|
|
|
if (storedWidth) {
|
|
|
|
initialViewBoxWidthRef.current = parseFloat(storedWidth);
|
|
|
|
} else {
|
|
|
|
const currentZoomLevel = currentPresentationPageRef.current.scaledWidth / currentPresentationPageRef.current.scaledViewBoxWidth;
|
|
|
|
const calculatedWidth = currentZoomLevel !== 1
|
|
|
|
? currentPresentationPageRef.current.scaledWidth / currentZoomLevel
|
|
|
|
: currentPresentationPageRef.current.scaledWidth;
|
|
|
|
initialViewBoxWidthRef.current = calculatedWidth;
|
|
|
|
localStorage.setItem('initialViewBoxWidth', calculatedWidth.toString());
|
|
|
|
}
|
2024-04-13 04:39:53 +08:00
|
|
|
|
2024-05-10 11:48:22 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
if (
|
|
|
|
presentationAreaHeight > 0 &&
|
|
|
|
presentationAreaWidth > 0 &&
|
|
|
|
currentPresentationPageRef.current &&
|
|
|
|
currentPresentationPageRef.current.scaledWidth > 0 &&
|
|
|
|
currentPresentationPageRef.current.scaledHeight > 0
|
|
|
|
) {
|
|
|
|
const adjustedPresentationAreaHeight = isPresenter
|
|
|
|
? presentationAreaHeight - 40
|
|
|
|
: presentationAreaHeight;
|
2023-12-06 02:15:25 +08:00
|
|
|
|
2024-05-10 11:48:22 +08:00
|
|
|
let effectiveZoom = 1;
|
|
|
|
let baseZoom;
|
|
|
|
if (isPresenter) {
|
|
|
|
baseZoom = fitToWidth
|
|
|
|
? presentationAreaWidth / currentPresentationPageRef.current.scaledWidth
|
|
|
|
: Math.min(
|
|
|
|
presentationAreaWidth / currentPresentationPageRef.current.scaledWidth,
|
|
|
|
adjustedPresentationAreaHeight / currentPresentationPageRef.current.scaledHeight
|
|
|
|
);
|
2024-04-04 02:39:24 +08:00
|
|
|
|
2024-04-13 04:39:53 +08:00
|
|
|
const zoomAdjustmentFactor = currentPresentationPageRef.current.scaledWidth / currentPresentationPageRef.current.scaledViewBoxWidth;
|
|
|
|
baseZoom *= zoomAdjustmentFactor;
|
2024-04-04 02:39:24 +08:00
|
|
|
|
2024-05-10 11:48:22 +08:00
|
|
|
const adjustedXPos = currentPresentationPageRef.current.xOffset;
|
|
|
|
const adjustedYPos = currentPresentationPageRef.current.yOffset;
|
|
|
|
|
|
|
|
setCamera(baseZoom, adjustedXPos, adjustedYPos);
|
|
|
|
|
|
|
|
} else if (includeViewerLogic) {
|
|
|
|
baseZoom = Math.min(
|
|
|
|
presentationAreaWidth / currentPresentationPageRef.current.scaledWidth,
|
|
|
|
adjustedPresentationAreaHeight / currentPresentationPageRef.current.scaledHeight
|
|
|
|
);
|
|
|
|
|
|
|
|
const zoomAdjustmentFactor = currentPresentationPageRef.current.scaledWidth / currentPresentationPageRef.current.scaledViewBoxWidth;
|
|
|
|
baseZoom *= zoomAdjustmentFactor;
|
|
|
|
|
|
|
|
const adjustedXPos = currentPresentationPageRef.current.xOffset * effectiveZoom;
|
|
|
|
const adjustedYPos = currentPresentationPageRef.current.yOffset * effectiveZoom;
|
2024-04-13 04:39:53 +08:00
|
|
|
|
|
|
|
setCamera(baseZoom, adjustedXPos, adjustedYPos);
|
2023-12-06 02:15:25 +08:00
|
|
|
}
|
2024-05-10 11:48:22 +08:00
|
|
|
}
|
|
|
|
}, CAMERA_UPDATE_DELAY);
|
|
|
|
};
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (isMountedRef.current) {
|
|
|
|
adjustCameraOnMount(true);
|
2022-12-17 03:00:02 +08:00
|
|
|
}
|
2023-12-06 02:15:25 +08:00
|
|
|
}, [
|
|
|
|
isMountedRef.current,
|
|
|
|
presentationId,
|
2024-02-08 01:07:40 +08:00
|
|
|
curPageIdRef.current,
|
2023-12-06 02:15:25 +08:00
|
|
|
isMultiUserActive,
|
|
|
|
isPresenter,
|
2023-12-12 03:31:21 +08:00
|
|
|
animations,
|
2024-05-10 11:48:22 +08:00
|
|
|
locale,
|
|
|
|
whiteboardToolbarAutoHide,
|
|
|
|
darkTheme,
|
|
|
|
]);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (isMountedRef.current) {
|
|
|
|
adjustCameraOnMount(false);
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
isMountedRef.current,
|
|
|
|
selectedLayout,
|
2023-12-06 02:15:25 +08:00
|
|
|
]);
|
2022-12-17 03:00:02 +08:00
|
|
|
|
2024-04-13 04:39:53 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
setTldrawIsMounting(true);
|
|
|
|
return () => {
|
|
|
|
isMountedRef.current = false;
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
2023-01-26 02:49:09 +08:00
|
|
|
React.useEffect(() => {
|
2023-12-06 02:15:25 +08:00
|
|
|
if (isMounting) {
|
|
|
|
setIsMounting(false);
|
|
|
|
/// brings presentation toolbar back
|
|
|
|
setTldrawIsMounting(false);
|
|
|
|
}
|
2023-12-12 03:31:21 +08:00
|
|
|
}, [
|
|
|
|
tlEditorRef?.current?.camera,
|
|
|
|
presentationAreaWidth,
|
|
|
|
presentationAreaHeight,
|
|
|
|
]);
|
2023-12-06 02:15:25 +08:00
|
|
|
|
2024-06-08 04:13:25 +08:00
|
|
|
React.useEffect (() => {
|
|
|
|
const bbb_multi_user_tools = getFromUserSettings(
|
|
|
|
'bbb_multi_user_tools',
|
|
|
|
meetingClientSettingsInitialValues.public.whiteboard.toolbar.multiUserTools,
|
|
|
|
);
|
|
|
|
const allElements = document.querySelectorAll('[data-testid^="tools."]');
|
|
|
|
|
|
|
|
if (bbb_multi_user_tools.length >= 1 && !isModerator) {
|
|
|
|
allElements.forEach((element) => {
|
|
|
|
const toolName = element.getAttribute('data-testid').split('.')[1];
|
|
|
|
|
|
|
|
if (!bbb_multi_user_tools.includes(toolName)) {
|
|
|
|
element.style.display = 'none';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),[]
|
|
|
|
|
|
|
|
React.useEffect (() => {
|
|
|
|
const bbb_presenter_tools = getFromUserSettings(
|
|
|
|
'bbb_presenter_tools',
|
|
|
|
meetingClientSettingsInitialValues.public.whiteboard.toolbar.presenterTools,
|
|
|
|
);
|
|
|
|
const allElements = document.querySelectorAll('[data-testid^="tools."]');
|
|
|
|
|
|
|
|
if (bbb_presenter_tools.length >= 1 && isPresenter) {
|
|
|
|
allElements.forEach((element) => {
|
|
|
|
const toolName = element.getAttribute('data-testid').split('.')[1];
|
|
|
|
|
|
|
|
if (!bbb_presenter_tools.includes(toolName)) {
|
|
|
|
element.style.display = 'none';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),[]
|
|
|
|
|
|
|
|
React.useEffect (() => {
|
|
|
|
const bbb_multi_user_pen_only = getFromUserSettings(
|
|
|
|
'bbb_multi_user_pen_only',
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
const allElements = document.querySelectorAll('[data-testid^="tools."]');
|
|
|
|
|
|
|
|
if (bbb_multi_user_pen_only && !isModerator && !isPresenter) {
|
|
|
|
allElements.forEach((element) => {
|
|
|
|
const toolName = element.getAttribute('data-testid').split('.')[1];
|
|
|
|
|
|
|
|
if (toolName != 'draw') {
|
|
|
|
element.style.display = 'none';
|
|
|
|
} else {
|
|
|
|
element.style.display = 'flex';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),[]
|
|
|
|
|
2024-04-11 08:53:42 +08:00
|
|
|
const customTools = [NoopTool];
|
|
|
|
|
2023-12-06 02:15:25 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
ref={whiteboardRef}
|
|
|
|
id={"whiteboard-element"}
|
2024-02-29 00:50:14 +08:00
|
|
|
key={`animations=-${animations}-${whiteboardToolbarAutoHide}-${language}`}
|
2023-12-06 02:15:25 +08:00
|
|
|
>
|
2022-12-14 00:11:56 +08:00
|
|
|
<Tldraw
|
2024-05-11 00:22:56 +08:00
|
|
|
autoFocus={false}
|
2024-02-08 01:07:40 +08:00
|
|
|
key={`tldrawv2-${presentationId}-${animations}`}
|
2023-12-06 02:15:25 +08:00
|
|
|
forceMobile={true}
|
2024-02-08 04:20:06 +08:00
|
|
|
hideUi={hasWBAccessRef.current || isPresenter ? false : true}
|
2023-12-06 02:15:25 +08:00
|
|
|
onMount={handleTldrawMount}
|
2024-04-11 08:53:42 +08:00
|
|
|
tools={customTools}
|
2023-12-06 02:15:25 +08:00
|
|
|
/>
|
|
|
|
<Styled.TldrawV2GlobalStyle
|
2024-04-04 10:00:56 +08:00
|
|
|
{...{
|
|
|
|
hasWBAccess: hasWBAccessRef.current,
|
|
|
|
isPresenter,
|
|
|
|
isRTL,
|
|
|
|
isMultiUserActive,
|
|
|
|
isToolbarVisible,
|
2024-05-08 08:50:31 +08:00
|
|
|
presentationHeight,
|
2024-04-04 10:00:56 +08:00
|
|
|
}}
|
2022-12-14 00:11:56 +08:00
|
|
|
/>
|
2023-04-14 23:27:37 +08:00
|
|
|
</div>
|
2022-04-05 22:49:13 +08:00
|
|
|
);
|
2023-12-06 02:15:25 +08:00
|
|
|
});
|
2023-03-10 19:30:46 +08:00
|
|
|
|
2024-03-25 01:22:49 +08:00
|
|
|
export default Whiteboard;
|
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
Whiteboard.propTypes = {
|
2024-02-17 04:25:43 +08:00
|
|
|
isPresenter: PropTypes.bool,
|
2023-03-27 23:45:16 +08:00
|
|
|
isIphone: PropTypes.bool.isRequired,
|
2023-03-10 19:30:46 +08:00
|
|
|
removeShapes: PropTypes.func.isRequired,
|
2024-01-24 19:37:51 +08:00
|
|
|
persistShapeWrapper: PropTypes.func.isRequired,
|
2023-03-10 19:30:46 +08:00
|
|
|
notifyNotAllowedChange: PropTypes.func.isRequired,
|
|
|
|
shapes: PropTypes.objectOf(PropTypes.shape).isRequired,
|
2024-02-17 04:25:43 +08:00
|
|
|
assets: PropTypes.arrayOf(PropTypes.shape).isRequired,
|
2023-03-10 19:30:46 +08:00
|
|
|
currentUser: PropTypes.shape({
|
|
|
|
userId: PropTypes.string.isRequired,
|
2024-02-17 04:25:43 +08:00
|
|
|
}),
|
2023-03-10 19:30:46 +08:00
|
|
|
whiteboardId: PropTypes.string,
|
|
|
|
zoomSlide: PropTypes.func.isRequired,
|
|
|
|
curPageId: PropTypes.string.isRequired,
|
|
|
|
presentationWidth: PropTypes.number.isRequired,
|
|
|
|
presentationHeight: PropTypes.number.isRequired,
|
|
|
|
zoomChanger: PropTypes.func.isRequired,
|
|
|
|
isRTL: PropTypes.bool.isRequired,
|
|
|
|
fitToWidth: PropTypes.bool.isRequired,
|
|
|
|
zoomValue: PropTypes.number.isRequired,
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
svgUri: PropTypes.string,
|
|
|
|
maxStickyNoteLength: PropTypes.number.isRequired,
|
|
|
|
fontFamily: PropTypes.string.isRequired,
|
2024-01-20 22:01:20 +08:00
|
|
|
colorStyle: PropTypes.string.isRequired,
|
|
|
|
dashStyle: PropTypes.string.isRequired,
|
|
|
|
fillStyle: PropTypes.string.isRequired,
|
|
|
|
fontStyle: PropTypes.string.isRequired,
|
|
|
|
sizeStyle: PropTypes.string.isRequired,
|
2023-03-10 19:30:46 +08:00
|
|
|
presentationAreaHeight: PropTypes.number.isRequired,
|
|
|
|
presentationAreaWidth: PropTypes.number.isRequired,
|
|
|
|
maxNumberOfAnnotations: PropTypes.number.isRequired,
|
|
|
|
notifyShapeNumberExceeded: PropTypes.func.isRequired,
|
|
|
|
darkTheme: PropTypes.bool.isRequired,
|
|
|
|
setTldrawIsMounting: PropTypes.func.isRequired,
|
|
|
|
width: PropTypes.number.isRequired,
|
|
|
|
height: PropTypes.number.isRequired,
|
|
|
|
fullscreenElementId: PropTypes.string.isRequired,
|
|
|
|
isFullscreen: PropTypes.bool.isRequired,
|
|
|
|
layoutContextDispatch: PropTypes.func.isRequired,
|
|
|
|
fullscreenAction: PropTypes.string.isRequired,
|
|
|
|
fullscreenRef: PropTypes.instanceOf(Element),
|
|
|
|
handleToggleFullScreen: PropTypes.func.isRequired,
|
2024-02-17 04:25:43 +08:00
|
|
|
numberOfPages: PropTypes.number,
|
2023-04-13 02:36:13 +08:00
|
|
|
sidebarNavigationWidth: PropTypes.number,
|
2023-09-28 04:42:47 +08:00
|
|
|
presentationId: PropTypes.string,
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Whiteboard.defaultProps = {
|
|
|
|
fullscreenRef: undefined,
|
|
|
|
svgUri: undefined,
|
|
|
|
whiteboardId: undefined,
|
2023-04-13 02:36:13 +08:00
|
|
|
sidebarNavigationWidth: 0,
|
2023-09-28 04:42:47 +08:00
|
|
|
presentationId: undefined,
|
2024-02-17 04:25:43 +08:00
|
|
|
currentUser: {
|
2024-04-04 10:00:56 +08:00
|
|
|
userId: "",
|
2024-02-17 04:25:43 +08:00
|
|
|
},
|
|
|
|
isPresenter: false,
|
|
|
|
numberOfPages: 0,
|
2023-12-12 03:31:21 +08:00
|
|
|
};
|