2023-03-10 19:30:46 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { TldrawApp, Tldraw } from '@tldraw/tldraw';
|
|
|
|
import SlideCalcUtil, { HUNDRED_PERCENT } from '/imports/utils/slideCalcUtils';
|
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
import { Utils } from '@tldraw/core';
|
|
|
|
import Cursors from './cursors/container';
|
2022-11-01 00:42:38 +08:00
|
|
|
import Settings from '/imports/ui/services/settings';
|
2023-01-24 04:00:05 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2023-02-06 21:37:34 +08:00
|
|
|
import KEY_CODES from '/imports/utils/keyCodes';
|
2023-03-27 23:33:10 +08:00
|
|
|
import {
|
|
|
|
presentationMenuHeight,
|
|
|
|
styleMenuOffset,
|
|
|
|
styleMenuOffsetSmall
|
|
|
|
} from '/imports/ui/stylesheets/styled-components/general';
|
2023-02-24 07:47:34 +08:00
|
|
|
import Styled from './styles';
|
2023-02-25 01:17:54 +08:00
|
|
|
import PanToolInjector from './pan-tool-injector/component';
|
2023-03-10 19:30:46 +08:00
|
|
|
import {
|
|
|
|
findRemoved, filterInvalidShapes, mapLanguage, sendShapeChanges, usePrevious,
|
|
|
|
} from './utils';
|
2023-04-05 20:42:05 +08:00
|
|
|
import { throttle } from '/imports/utils/throttle';
|
|
|
|
import { isEqual } from 'radash';
|
2022-11-01 00:42:38 +08:00
|
|
|
|
2022-08-13 03:08:26 +08:00
|
|
|
const SMALL_HEIGHT = 435;
|
2023-05-30 02:03:39 +08:00
|
|
|
const SMALLEST_DOCK_HEIGHT = 475;
|
2022-11-18 07:37:17 +08:00
|
|
|
const SMALL_WIDTH = 800;
|
2023-05-30 02:03:39 +08:00
|
|
|
const SMALLEST_DOCK_WIDTH = 710;
|
2022-08-13 03:08:26 +08:00
|
|
|
const TOOLBAR_SMALL = 28;
|
2023-05-30 02:03:39 +08:00
|
|
|
const TOOLBAR_LARGE = 32;
|
2022-08-12 00:38:17 +08:00
|
|
|
|
2022-04-05 22:49:13 +08:00
|
|
|
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,
|
|
|
|
persistShape,
|
|
|
|
shapes,
|
2022-10-06 04:43:48 +08:00
|
|
|
assets,
|
2022-04-05 22:49:13 +08:00
|
|
|
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-07-08 23:06:00 +08:00
|
|
|
presentationWidth,
|
|
|
|
presentationHeight,
|
2022-06-02 23:00:28 +08:00
|
|
|
isViewersCursorLocked,
|
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,
|
2022-10-21 22:05:31 +08:00
|
|
|
intl,
|
2022-11-09 02:39:16 +08:00
|
|
|
svgUri,
|
2022-11-24 01:03:20 +08:00
|
|
|
maxStickyNoteLength,
|
2023-01-16 19:40:42 +08:00
|
|
|
fontFamily,
|
2023-01-25 02:32:49 +08:00
|
|
|
hasShapeAccess,
|
2023-01-26 02:49:09 +08:00
|
|
|
presentationAreaHeight,
|
|
|
|
presentationAreaWidth,
|
2023-02-03 03:47:16 +08:00
|
|
|
maxNumberOfAnnotations,
|
|
|
|
notifyShapeNumberExceeded,
|
2023-02-14 11:28:36 +08:00
|
|
|
darkTheme,
|
2023-02-24 07:47:34 +08:00
|
|
|
isPanning: shortcutPanning,
|
2023-03-10 19:30:46 +08:00
|
|
|
setTldrawIsMounting,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
hasMultiUserAccess,
|
2023-03-13 20:17:14 +08:00
|
|
|
tldrawAPI,
|
|
|
|
setTldrawAPI,
|
2023-03-27 06:08:09 +08:00
|
|
|
whiteboardToolbarAutoHide,
|
|
|
|
toggleToolsAnimations,
|
2023-03-27 23:45:16 +08:00
|
|
|
isIphone,
|
2023-04-13 02:36:13 +08:00
|
|
|
sidebarNavigationWidth,
|
2023-04-14 23:27:37 +08:00
|
|
|
animations,
|
2023-04-19 02:03:22 +08:00
|
|
|
isToolbarVisible,
|
2022-04-05 22:49:13 +08:00
|
|
|
} = props;
|
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({
|
2023-03-10 19:30:46 +08:00
|
|
|
name: 'test',
|
2022-04-05 22:49:13 +08:00
|
|
|
version: TldrawApp.version,
|
2022-05-16 10:35:17 +08:00
|
|
|
id: whiteboardId,
|
2022-04-05 22:49:13 +08:00
|
|
|
pages,
|
|
|
|
pageStates,
|
|
|
|
bindings: {},
|
2022-07-08 23:06:00 +08:00
|
|
|
assets: {},
|
2022-04-05 22:49:13 +08:00
|
|
|
});
|
2022-11-01 18:46:17 +08:00
|
|
|
const [history, setHistory] = React.useState(null);
|
2022-08-16 20:12:43 +08:00
|
|
|
const [zoom, setZoom] = React.useState(HUNDRED_PERCENT);
|
2023-01-26 02:49:09 +08:00
|
|
|
const [tldrawZoom, setTldrawZoom] = React.useState(1);
|
2022-08-16 20:12:43 +08:00
|
|
|
const [isMounting, setIsMounting] = React.useState(true);
|
2022-04-11 00:31:12 +08:00
|
|
|
const prevShapes = usePrevious(shapes);
|
2022-08-16 20:12:43 +08:00
|
|
|
const prevSlidePosition = usePrevious(slidePosition);
|
|
|
|
const prevFitToWidth = usePrevious(fitToWidth);
|
2022-11-09 02:39:16 +08:00
|
|
|
const prevSvgUri = usePrevious(svgUri);
|
2022-11-01 00:42:38 +08:00
|
|
|
const language = mapLanguage(Settings?.application?.locale?.toLowerCase() || 'en');
|
2023-01-12 03:32:03 +08:00
|
|
|
const [currentTool, setCurrentTool] = React.useState(null);
|
2023-04-02 04:18:03 +08:00
|
|
|
const [currentStyle, setCurrentStyle] = React.useState({});
|
2023-02-11 02:30:24 +08:00
|
|
|
const [isMoving, setIsMoving] = React.useState(false);
|
2023-02-24 07:47:34 +08:00
|
|
|
const [isPanning, setIsPanning] = React.useState(shortcutPanning);
|
|
|
|
const [panSelected, setPanSelected] = React.useState(isPanning);
|
2023-02-25 07:00:15 +08:00
|
|
|
const isMountedRef = React.useRef(true);
|
2023-03-09 21:42:05 +08:00
|
|
|
const [isToolLocked, setIsToolLocked] = React.useState(tldrawAPI?.appState?.isToolLocked);
|
2023-05-25 01:36:58 +08:00
|
|
|
const [bgShape, setBgShape] = React.useState(null);
|
2023-02-25 07:00:15 +08:00
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
// eslint-disable-next-line arrow-body-style
|
2023-02-25 07:00:15 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
return () => {
|
|
|
|
isMountedRef.current = false;
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const setSafeTLDrawAPI = (api) => {
|
|
|
|
if (isMountedRef.current) {
|
2023-03-13 20:17:14 +08:00
|
|
|
setTldrawAPI(api);
|
2023-02-25 07:00:15 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-24 07:47:34 +08:00
|
|
|
const toggleOffCheck = (evt) => {
|
|
|
|
const clickedElement = evt.target;
|
2023-02-25 01:17:54 +08:00
|
|
|
const panBtnClicked = clickedElement?.getAttribute('data-test') === 'panButton'
|
2023-03-10 19:30:46 +08:00
|
|
|
|| clickedElement?.parentElement?.getAttribute('data-test') === 'panButton';
|
2023-03-09 04:41:25 +08:00
|
|
|
|
|
|
|
setIsToolLocked(false);
|
|
|
|
|
2023-02-25 06:51:03 +08:00
|
|
|
const panButton = document.querySelector('[data-test="panButton"]');
|
2023-02-25 01:17:54 +08:00
|
|
|
if (panBtnClicked) {
|
2023-02-25 06:51:03 +08:00
|
|
|
const dataZoom = panButton.getAttribute('data-zoom');
|
|
|
|
if ((dataZoom <= HUNDRED_PERCENT && !fitToWidth)) {
|
2023-03-10 19:30:46 +08:00
|
|
|
return;
|
2023-02-25 06:51:03 +08:00
|
|
|
}
|
|
|
|
panButton.classList.add('select');
|
|
|
|
panButton.classList.remove('selectOverride');
|
|
|
|
} else {
|
2023-02-24 07:47:34 +08:00
|
|
|
setIsPanning(false);
|
2023-02-25 06:51:03 +08:00
|
|
|
setPanSelected(false);
|
|
|
|
panButton.classList.add('selectOverride');
|
|
|
|
panButton.classList.remove('select');
|
2023-02-24 07:47:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-27 02:39:09 +08:00
|
|
|
const setDockPosition = (setSetting) => {
|
|
|
|
if (hasWBAccess || isPresenter) {
|
|
|
|
if (((height < SMALLEST_HEIGHT) || (width < SMALLEST_WIDTH))) {
|
|
|
|
setSetting('dockPosition', 'bottom');
|
|
|
|
} else {
|
|
|
|
setSetting('dockPosition', isRTL ? 'left' : 'right');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-24 07:47:34 +08:00
|
|
|
React.useEffect(() => {
|
2023-03-10 19:30:46 +08:00
|
|
|
const toolbar = document.getElementById('TD-PrimaryTools');
|
2023-02-24 07:47:34 +08:00
|
|
|
const handleClick = (evt) => {
|
|
|
|
toggleOffCheck(evt);
|
|
|
|
};
|
2023-03-10 19:30:46 +08:00
|
|
|
const handleDBClick = (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
evt.stopPropagation();
|
2023-03-09 04:41:25 +08:00
|
|
|
setIsToolLocked(true);
|
|
|
|
tldrawAPI?.patchState(
|
|
|
|
{
|
|
|
|
appState: {
|
|
|
|
isToolLocked: true,
|
|
|
|
},
|
2023-03-10 19:30:46 +08:00
|
|
|
},
|
2023-03-09 04:41:25 +08:00
|
|
|
);
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
2023-02-24 07:47:34 +08:00
|
|
|
toolbar?.addEventListener('click', handleClick);
|
2023-03-10 19:30:46 +08:00
|
|
|
toolbar?.addEventListener('dblclick', handleDBClick);
|
2023-03-09 04:41:25 +08:00
|
|
|
|
2023-02-24 07:47:34 +08:00
|
|
|
return () => {
|
|
|
|
toolbar?.removeEventListener('click', handleClick);
|
2023-03-10 19:30:46 +08:00
|
|
|
toolbar?.removeEventListener('dblclick', handleDBClick);
|
2023-02-24 07:47:34 +08:00
|
|
|
};
|
2023-03-09 04:41:25 +08:00
|
|
|
}, [tldrawAPI, isToolLocked]);
|
2022-04-11 00:31:12 +08:00
|
|
|
|
2023-03-27 06:08:09 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (whiteboardToolbarAutoHide) {
|
2023-04-14 23:27:37 +08:00
|
|
|
toggleToolsAnimations('fade-in', 'fade-out', animations ? '3s' : '0s');
|
2023-03-27 06:08:09 +08:00
|
|
|
} else {
|
2023-04-14 23:27:37 +08:00
|
|
|
toggleToolsAnimations('fade-out', 'fade-in', animations ? '.3s' : '0s');
|
2023-03-27 06:08:09 +08:00
|
|
|
}
|
|
|
|
}, [whiteboardToolbarAutoHide]);
|
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
const calculateZoom = (localWidth, localHeight) => {
|
|
|
|
const calcedZoom = fitToWidth ? (presentationWidth / localWidth) : Math.min(
|
|
|
|
(presentationWidth) / localWidth,
|
|
|
|
(presentationHeight) / localHeight,
|
2023-01-27 23:49:32 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
return (calcedZoom === 0 || calcedZoom === Infinity) ? HUNDRED_PERCENT : calcedZoom;
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
2022-10-21 22:05:31 +08:00
|
|
|
|
2022-11-26 05:24:06 +08:00
|
|
|
React.useEffect(() => {
|
2023-03-10 19:30:46 +08:00
|
|
|
setTldrawIsMounting(true);
|
2022-11-26 05:24:06 +08:00
|
|
|
}, []);
|
|
|
|
|
2023-01-18 21:12:16 +08:00
|
|
|
const checkClientBounds = (e) => {
|
|
|
|
if (
|
2023-03-10 19:30:46 +08:00
|
|
|
e.clientX > document.documentElement.clientWidth
|
|
|
|
|| e.clientX < 0
|
|
|
|
|| e.clientY > document.documentElement.clientHeight
|
|
|
|
|| e.clientY < 0
|
2023-01-18 21:12:16 +08:00
|
|
|
) {
|
|
|
|
if (tldrawAPI?.session) {
|
|
|
|
tldrawAPI?.completeSession?.();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-20 04:27:30 +08:00
|
|
|
const checkVisibility = () => {
|
|
|
|
if (document.visibilityState === 'hidden' && tldrawAPI?.session) {
|
|
|
|
tldrawAPI?.completeSession?.();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-14 00:16:37 +08:00
|
|
|
const handleWheelEvent = (event) => {
|
|
|
|
if (!event.ctrlKey) {
|
|
|
|
// Prevent the event from reaching the tldraw library
|
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
const newEvent = new WheelEvent('wheel', {
|
|
|
|
deltaX: event.deltaX,
|
|
|
|
deltaY: event.deltaY,
|
|
|
|
deltaZ: event.deltaZ,
|
|
|
|
ctrlKey: true,
|
|
|
|
clientX: event.clientX,
|
|
|
|
clientY: event.clientY,
|
|
|
|
});
|
2023-03-14 01:22:38 +08:00
|
|
|
const canvas = document.getElementById('canvas');
|
2023-03-27 06:08:09 +08:00
|
|
|
if (canvas) {
|
|
|
|
canvas.dispatchEvent(newEvent);
|
|
|
|
}
|
2023-03-14 00:16:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 21:12:16 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
document.addEventListener('mouseup', checkClientBounds);
|
2023-01-20 04:27:30 +08:00
|
|
|
document.addEventListener('visibilitychange', checkVisibility);
|
2023-01-18 21:12:16 +08:00
|
|
|
|
|
|
|
return () => {
|
|
|
|
document.removeEventListener('mouseup', checkClientBounds);
|
2023-01-20 04:27:30 +08:00
|
|
|
document.removeEventListener('visibilitychange', checkVisibility);
|
2023-03-14 00:16:37 +08:00
|
|
|
const canvas = document.getElementById('canvas');
|
|
|
|
if (canvas) {
|
|
|
|
canvas.removeEventListener('wheel', handleWheelEvent);
|
|
|
|
}
|
2023-01-18 21:12:16 +08:00
|
|
|
};
|
|
|
|
}, [tldrawAPI]);
|
|
|
|
|
2023-05-25 02:45:08 +08:00
|
|
|
/* needed to prevent an issue with presentation images not loading correctly in Firefox
|
|
|
|
more info: https://github.com/bigbluebutton/bigbluebutton/issues/17969#issuecomment-1561758200 */
|
2023-05-25 01:36:58 +08:00
|
|
|
React.useEffect(() => {
|
2023-05-30 21:18:11 +08:00
|
|
|
if (bgShape && bgShape.parentElement && bgShape.parentElement.clientWidth > 0) {
|
2023-05-25 01:36:58 +08:00
|
|
|
bgShape.parentElement.style.width = `${bgShape.parentElement.clientWidth + .1}px`;
|
|
|
|
}
|
|
|
|
}, [bgShape]);
|
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
const doc = React.useMemo(() => {
|
2022-04-05 22:49:13 +08:00
|
|
|
const currentDoc = rDocument.current;
|
|
|
|
|
2023-03-08 21:01:18 +08:00
|
|
|
// update document if the number of pages has changed
|
|
|
|
if (currentDoc.id !== whiteboardId && currentDoc?.pages.length !== curPres?.pages.length) {
|
2023-03-29 20:35:10 +08:00
|
|
|
const currentPageShapes = currentDoc?.pages[curPageId]?.shapes;
|
2023-03-08 21:01:18 +08:00
|
|
|
currentDoc.id = whiteboardId;
|
|
|
|
currentDoc.pages = pages;
|
2023-03-29 20:35:10 +08:00
|
|
|
currentDoc.pages[curPageId].shapes = currentPageShapes;
|
2023-03-08 21:01:18 +08:00
|
|
|
currentDoc.pageStates = pageStates;
|
|
|
|
}
|
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
const next = { ...currentDoc };
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2022-05-19 03:35:42 +08:00
|
|
|
let changed = false;
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2023-02-23 21:27:16 +08:00
|
|
|
if (next.pageStates[curPageId] && !isEqual(prevShapes, shapes)) {
|
2022-11-16 12:12:28 +08:00
|
|
|
const editingShape = tldrawAPI?.getShape(tldrawAPI?.getPageState()?.editingId);
|
2022-11-16 23:01:12 +08:00
|
|
|
|
2022-11-16 12:12:28 +08:00
|
|
|
if (editingShape) {
|
|
|
|
shapes[editingShape?.id] = editingShape;
|
|
|
|
}
|
2022-04-26 21:55:05 +08:00
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
const removed = prevShapes && findRemoved(Object.keys(prevShapes), Object.keys((shapes)));
|
2022-10-25 23:53:19 +08:00
|
|
|
if (removed && removed.length > 0) {
|
2023-01-24 04:00:05 +08:00
|
|
|
const patchedShapes = Object.fromEntries(removed.map((id) => [id, undefined]));
|
|
|
|
|
|
|
|
try {
|
|
|
|
tldrawAPI?.patchState(
|
|
|
|
{
|
|
|
|
document: {
|
|
|
|
pageStates: {
|
|
|
|
[curPageId]: {
|
2023-03-10 19:30:46 +08:00
|
|
|
selectedIds:
|
|
|
|
tldrawAPI?.selectedIds?.filter((id) => !removed.includes(id)) || [],
|
2023-01-24 04:00:05 +08:00
|
|
|
},
|
2022-10-25 23:53:19 +08:00
|
|
|
},
|
2023-01-24 04:00:05 +08:00
|
|
|
pages: {
|
|
|
|
[curPageId]: {
|
|
|
|
shapes: patchedShapes,
|
|
|
|
},
|
2022-10-25 23:53:19 +08:00
|
|
|
},
|
2022-10-21 22:05:31 +08:00
|
|
|
},
|
|
|
|
},
|
2023-01-24 04:00:05 +08:00
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'whiteboard_shapes_remove_error',
|
|
|
|
extraInfo: { error },
|
|
|
|
}, 'Whiteboard catch error on removing shapes');
|
|
|
|
}
|
2022-10-25 23:53:19 +08:00
|
|
|
}
|
2023-01-10 03:40:47 +08:00
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
next.pages[curPageId].shapes = filterInvalidShapes(shapes, curPageId, tldrawAPI);
|
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
|
|
|
|
2023-04-05 20:42:05 +08:00
|
|
|
if (curPageId && (!next.assets[`slide-background-asset-${curPageId}`] || (svgUri && !isEqual(prevSvgUri, svgUri)))) {
|
2023-03-10 19:30:46 +08:00
|
|
|
next.assets[`slide-background-asset-${curPageId}`] = assets[`slide-background-asset-${curPageId}`];
|
2022-10-21 22:05:31 +08:00
|
|
|
tldrawAPI?.patchState(
|
|
|
|
{
|
|
|
|
document: {
|
2023-03-10 19:30:46 +08:00
|
|
|
assets,
|
2022-10-21 22:05:31 +08:00
|
|
|
},
|
2022-05-19 03:35:42 +08:00
|
|
|
},
|
2022-10-21 22:05:31 +08:00
|
|
|
);
|
2023-01-18 01:45:15 +08:00
|
|
|
changed = true;
|
2022-04-05 22:49:13 +08:00
|
|
|
}
|
|
|
|
|
2022-10-21 22:05:31 +08:00
|
|
|
if (changed && tldrawAPI) {
|
|
|
|
// merge patch manually (this improves performance and reduce side effects on fast updates)
|
|
|
|
const patch = {
|
|
|
|
document: {
|
|
|
|
pages: {
|
2023-03-10 19:30:46 +08:00
|
|
|
[curPageId]: { shapes: filterInvalidShapes(shapes, curPageId, tldrawAPI) },
|
2022-10-21 22:05:31 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const prevState = tldrawAPI._state;
|
|
|
|
const nextState = Utils.deepMerge(tldrawAPI._state, patch);
|
2023-03-10 19:30:46 +08:00
|
|
|
if (nextState.document.pages[curPageId].shapes) {
|
|
|
|
filterInvalidShapes(nextState.document.pages[curPageId].shapes, curPageId, tldrawAPI);
|
2023-01-24 04:00:05 +08:00
|
|
|
}
|
2022-10-25 23:53:19 +08:00
|
|
|
const final = tldrawAPI.cleanup(nextState, prevState, patch, '');
|
|
|
|
tldrawAPI._state = final;
|
2023-01-24 04:00:05 +08:00
|
|
|
|
|
|
|
try {
|
|
|
|
tldrawAPI?.forceUpdate();
|
2023-03-10 19:30:46 +08:00
|
|
|
} catch (error) {
|
2023-01-24 04:00:05 +08:00
|
|
|
logger.error({
|
|
|
|
logCode: 'whiteboard_shapes_update_error',
|
|
|
|
extraInfo: { error },
|
|
|
|
}, 'Whiteboard catch error on updating shapes');
|
|
|
|
}
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// move poll result text to bottom right
|
2023-01-20 04:56:20 +08:00
|
|
|
if (next.pages[curPageId] && slidePosition) {
|
2022-06-01 03:40:31 +08:00
|
|
|
const pollResults = Object.entries(next.pages[curPageId].shapes)
|
2023-03-10 19:30:46 +08:00
|
|
|
.filter(([, shape]) => shape.name?.includes('poll-result'));
|
|
|
|
pollResults.forEach(([id, shape]) => {
|
2023-02-23 21:27:16 +08:00
|
|
|
if (isEqual(shape.point, [0, 0])) {
|
2023-03-15 02:02:02 +08:00
|
|
|
try {
|
|
|
|
const shapeBounds = tldrawAPI?.getShapeBounds(id);
|
|
|
|
if (shapeBounds) {
|
|
|
|
const editedShape = shape;
|
|
|
|
editedShape.point = [
|
|
|
|
slidePosition.width - shapeBounds.width,
|
|
|
|
slidePosition.height - shapeBounds.height,
|
|
|
|
];
|
|
|
|
editedShape.size = [shapeBounds.width, shapeBounds.height];
|
|
|
|
if (isPresenter) persistShape(editedShape, whiteboardId);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'whiteboard_poll_results_error',
|
|
|
|
extraInfo: { error },
|
|
|
|
}, 'Whiteboard catch error on moving unpublished poll results');
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-10 19:30:46 +08:00
|
|
|
});
|
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-07-08 23:06:00 +08:00
|
|
|
}, [shapes, tldrawAPI, curPageId, slidePosition]);
|
2022-04-11 00:31:12 +08:00
|
|
|
|
2022-07-08 23:06:00 +08:00
|
|
|
// when presentationSizes change, update tldraw camera
|
2022-06-01 03:40:31 +08:00
|
|
|
React.useEffect(() => {
|
2023-03-10 19:30:46 +08:00
|
|
|
if (curPageId && slidePosition && tldrawAPI
|
|
|
|
&& presentationWidth > 0 && presentationHeight > 0
|
|
|
|
) {
|
2022-08-16 20:12:43 +08:00
|
|
|
if (prevFitToWidth !== null && fitToWidth !== prevFitToWidth) {
|
2023-03-10 19:30:46 +08:00
|
|
|
const newZoom = calculateZoom(slidePosition.width, slidePosition.height);
|
|
|
|
tldrawAPI?.setCamera([0, 0], newZoom);
|
|
|
|
const viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
|
|
|
|
tldrawAPI?.viewport.height, slidePosition.height,
|
|
|
|
);
|
2022-09-30 22:35:29 +08:00
|
|
|
setZoom(HUNDRED_PERCENT);
|
|
|
|
zoomChanger(HUNDRED_PERCENT);
|
2023-03-10 19:30:46 +08:00
|
|
|
zoomSlide(parseInt(curPageId, 10), podId, HUNDRED_PERCENT, viewedRegionH, 0, 0);
|
2022-08-16 20:12:43 +08:00
|
|
|
} else {
|
2023-03-10 19:30:46 +08:00
|
|
|
const currentAspectRatio = Math.round((presentationWidth / presentationHeight) * 100) / 100;
|
|
|
|
const previousAspectRatio = Math.round(
|
|
|
|
(slidePosition.viewBoxWidth / slidePosition.viewBoxHeight) * 100,
|
|
|
|
) / 100;
|
2022-09-30 22:35:29 +08:00
|
|
|
if (fitToWidth && currentAspectRatio !== previousAspectRatio) {
|
2023-03-07 12:29:00 +08:00
|
|
|
// we need this to ensure tldraw updates the viewport size after re-mounting
|
2022-08-24 02:19:17 +08:00
|
|
|
setTimeout(() => {
|
2023-03-10 19:30:46 +08:00
|
|
|
const newZoom = calculateZoom(slidePosition.viewBoxWidth, slidePosition.viewBoxHeight);
|
|
|
|
tldrawAPI.setCamera([slidePosition.x, slidePosition.y], newZoom, 'zoomed');
|
2022-08-24 02:19:17 +08:00
|
|
|
}, 50);
|
|
|
|
} else {
|
2023-03-10 19:30:46 +08:00
|
|
|
const newZoom = calculateZoom(slidePosition.viewBoxWidth, slidePosition.viewBoxHeight);
|
|
|
|
tldrawAPI?.setCamera([slidePosition.x, slidePosition.y], newZoom);
|
2022-08-24 02:19:17 +08:00
|
|
|
}
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
2022-07-08 23:06:00 +08:00
|
|
|
}, [presentationWidth, presentationHeight, curPageId, document?.documentElement?.dir]);
|
2022-06-01 03:40:31 +08:00
|
|
|
|
2022-09-30 22:35:29 +08:00
|
|
|
React.useEffect(() => {
|
2023-01-20 04:56:20 +08:00
|
|
|
if (presentationWidth > 0 && presentationHeight > 0 && slidePosition) {
|
2022-09-30 22:35:29 +08:00
|
|
|
const cameraZoom = tldrawAPI?.getPageState()?.camera?.zoom;
|
|
|
|
const newzoom = calculateZoom(slidePosition.viewBoxWidth, slidePosition.viewBoxHeight);
|
|
|
|
if (cameraZoom && cameraZoom === 1) {
|
2023-03-10 19:30:46 +08:00
|
|
|
tldrawAPI?.setCamera([slidePosition.x, slidePosition.y], newzoom);
|
2022-09-30 22:35:29 +08:00
|
|
|
} else if (isMounting) {
|
2022-10-19 23:13:08 +08:00
|
|
|
setIsMounting(false);
|
2023-03-10 19:30:46 +08:00
|
|
|
setTldrawIsMounting(false);
|
|
|
|
const currentAspectRatio = Math.round((presentationWidth / presentationHeight) * 100) / 100;
|
|
|
|
const previousAspectRatio = Math.round(
|
|
|
|
(slidePosition.viewBoxWidth / slidePosition.viewBoxHeight) * 100,
|
|
|
|
) / 100;
|
2022-10-19 23:13:08 +08:00
|
|
|
// case where the presenter had fit-to-width enabled and he reloads the page
|
|
|
|
if (!fitToWidth && currentAspectRatio !== previousAspectRatio) {
|
2022-09-30 22:35:29 +08:00
|
|
|
// wee need this to ensure tldraw updates the viewport size after re-mounting
|
|
|
|
setTimeout(() => {
|
|
|
|
tldrawAPI?.setCamera([slidePosition.x, slidePosition.y], newzoom, 'zoomed');
|
|
|
|
}, 50);
|
|
|
|
} else {
|
|
|
|
tldrawAPI?.setCamera([slidePosition.x, slidePosition.y], newzoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [tldrawAPI?.getPageState()?.camera, presentationWidth, presentationHeight]);
|
|
|
|
|
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(() => {
|
2023-01-20 04:56:20 +08:00
|
|
|
if (tldrawAPI && curPageId && slidePosition) {
|
2022-06-01 03:40:31 +08:00
|
|
|
tldrawAPI.changePage(curPageId);
|
2023-03-10 19:30:46 +08:00
|
|
|
const newZoom = prevSlidePosition
|
2022-08-16 20:12:43 +08:00
|
|
|
? calculateZoom(prevSlidePosition.viewBoxWidth, prevSlidePosition.viewBoxHeight)
|
2023-03-10 19:30:46 +08:00
|
|
|
: calculateZoom(slidePosition.viewBoxWidth, slidePosition.viewBoxHeight);
|
|
|
|
tldrawAPI?.setCamera([slidePosition.x, slidePosition.y], newZoom, 'zoomed_previous_page');
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
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) {
|
2023-03-10 19:30:46 +08:00
|
|
|
const newZoom = calculateZoom(slidePosition.viewBoxWidth, slidePosition.viewBoxHeight);
|
|
|
|
tldrawAPI?.setCamera([slidePosition.x, slidePosition.y], newZoom, 'zoomed');
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
2022-05-20 01:24:47 +08:00
|
|
|
}, [curPageId, slidePosition]);
|
|
|
|
|
2022-08-16 20:12:43 +08:00
|
|
|
// update zoom according to toolbar
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (tldrawAPI && isPresenter && curPageId && slidePosition && zoom !== zoomValue) {
|
|
|
|
const zoomFitSlide = calculateZoom(slidePosition.width, slidePosition.height);
|
|
|
|
const zoomCamera = (zoomFitSlide * zoomValue) / HUNDRED_PERCENT;
|
2022-09-30 22:35:29 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
tldrawAPI?.zoomTo(zoomCamera);
|
|
|
|
}, 50);
|
2022-08-16 20:12:43 +08:00
|
|
|
}
|
|
|
|
}, [zoomValue]);
|
|
|
|
|
2022-10-19 23:13:08 +08:00
|
|
|
// update zoom when presenter changes if the aspectRatio has changed
|
2022-08-19 02:18:02 +08:00
|
|
|
React.useEffect(() => {
|
2022-09-30 22:35:29 +08:00
|
|
|
if (tldrawAPI && isPresenter && curPageId && slidePosition && !isMounting) {
|
2023-03-10 19:30:46 +08:00
|
|
|
const currentAspectRatio = Math.round((presentationWidth / presentationHeight) * 100) / 100;
|
|
|
|
const previousAspectRatio = Math.round(
|
|
|
|
(slidePosition.viewBoxWidth / slidePosition.viewBoxHeight) * 100,
|
|
|
|
) / 100;
|
2022-10-19 23:13:08 +08:00
|
|
|
if (previousAspectRatio !== currentAspectRatio) {
|
|
|
|
if (fitToWidth) {
|
2023-03-10 19:30:46 +08:00
|
|
|
const newZoom = calculateZoom(slidePosition.width, slidePosition.height);
|
|
|
|
tldrawAPI?.setCamera([0, 0], newZoom);
|
|
|
|
const viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
|
|
|
|
tldrawAPI?.viewport.height, slidePosition.height,
|
|
|
|
);
|
|
|
|
zoomSlide(parseInt(curPageId, 10), podId, HUNDRED_PERCENT, viewedRegionH, 0, 0);
|
2022-10-19 23:13:08 +08:00
|
|
|
setZoom(HUNDRED_PERCENT);
|
|
|
|
zoomChanger(HUNDRED_PERCENT);
|
|
|
|
} else if (!isMounting) {
|
2023-03-10 19:30:46 +08:00
|
|
|
let viewedRegionW = SlideCalcUtil.calcViewedRegionWidth(
|
|
|
|
tldrawAPI?.viewport.width, slidePosition.width,
|
|
|
|
);
|
|
|
|
let viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
|
|
|
|
tldrawAPI?.viewport.height, slidePosition.height,
|
|
|
|
);
|
2022-10-19 23:13:08 +08:00
|
|
|
const camera = tldrawAPI?.getPageState()?.camera;
|
|
|
|
const zoomFitSlide = calculateZoom(slidePosition.width, slidePosition.height);
|
|
|
|
if (!fitToWidth && camera.zoom === zoomFitSlide) {
|
|
|
|
viewedRegionW = HUNDRED_PERCENT;
|
|
|
|
viewedRegionH = HUNDRED_PERCENT;
|
|
|
|
}
|
2023-03-10 19:30:46 +08:00
|
|
|
zoomSlide(
|
|
|
|
parseInt(curPageId, 10),
|
|
|
|
podId,
|
|
|
|
viewedRegionW,
|
|
|
|
viewedRegionH,
|
|
|
|
camera.point[0],
|
|
|
|
camera.point[1],
|
|
|
|
);
|
|
|
|
const zoomToolbar = Math.round(
|
|
|
|
((HUNDRED_PERCENT * camera.zoom) / zoomFitSlide) * 100,
|
|
|
|
) / 100;
|
2022-10-19 23:13:08 +08:00
|
|
|
if (zoom !== zoomToolbar) {
|
|
|
|
setZoom(zoomToolbar);
|
|
|
|
zoomChanger(zoomToolbar);
|
|
|
|
}
|
2022-09-30 22:35:29 +08:00
|
|
|
}
|
2022-06-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-19 02:18:02 +08:00
|
|
|
}, [isPresenter]);
|
2022-05-20 01:24:47 +08:00
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
const hasWBAccess = hasMultiUserAccess(whiteboardId, currentUser.userId);
|
2022-08-03 22:30:22 +08:00
|
|
|
|
2022-08-15 06:49:39 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (tldrawAPI) {
|
|
|
|
tldrawAPI.isForcePanning = isPanning;
|
|
|
|
}
|
|
|
|
}, [isPanning]);
|
|
|
|
|
2023-05-27 02:39:09 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
tldrawAPI && setDockPosition(tldrawAPI?.setSetting);
|
|
|
|
}, [height, width]);
|
|
|
|
|
2022-11-01 00:42:38 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
tldrawAPI?.setSetting('language', language);
|
|
|
|
}, [language]);
|
|
|
|
|
2022-12-17 03:00:02 +08:00
|
|
|
// Reset zoom to default when current presentation changes.
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (isPresenter && slidePosition && tldrawAPI) {
|
2023-01-27 21:05:08 +08:00
|
|
|
tldrawAPI.zoomTo(0);
|
2023-03-30 03:30:32 +08:00
|
|
|
setHistory(null);
|
2023-03-23 02:00:19 +08:00
|
|
|
tldrawAPI.resetHistory();
|
2022-12-17 03:00:02 +08:00
|
|
|
}
|
|
|
|
}, [curPres?.id]);
|
|
|
|
|
2023-01-26 02:49:09 +08:00
|
|
|
React.useEffect(() => {
|
|
|
|
const currentZoom = tldrawAPI?.getPageState()?.camera?.zoom;
|
2023-03-10 19:30:46 +08:00
|
|
|
if (currentZoom !== tldrawZoom) {
|
2023-01-26 02:49:09 +08:00
|
|
|
setTldrawZoom(currentZoom);
|
|
|
|
}
|
2023-05-25 01:36:58 +08:00
|
|
|
setBgShape(null);
|
2023-01-26 02:49:09 +08:00
|
|
|
}, [presentationAreaHeight, presentationAreaWidth]);
|
|
|
|
|
2023-02-06 21:37:34 +08:00
|
|
|
const fullscreenToggleHandler = () => {
|
|
|
|
const {
|
|
|
|
fullscreenElementId,
|
|
|
|
isFullscreen,
|
|
|
|
layoutContextDispatch,
|
|
|
|
fullscreenAction,
|
|
|
|
fullscreenRef,
|
|
|
|
handleToggleFullScreen,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
handleToggleFullScreen(fullscreenRef);
|
|
|
|
const newElement = isFullscreen ? '' : fullscreenElementId;
|
|
|
|
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: fullscreenAction,
|
|
|
|
value: {
|
|
|
|
element: newElement,
|
|
|
|
group: '',
|
|
|
|
},
|
|
|
|
});
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
2023-02-06 21:37:34 +08:00
|
|
|
|
|
|
|
const nextSlideHandler = (event) => {
|
2023-03-10 19:30:46 +08:00
|
|
|
const { nextSlide, numberOfSlides } = props;
|
2023-02-06 21:37:34 +08:00
|
|
|
|
|
|
|
if (event) event.currentTarget.blur();
|
|
|
|
nextSlide(+curPageId, numberOfSlides, podId);
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
2023-02-06 21:37:34 +08:00
|
|
|
|
|
|
|
const previousSlideHandler = (event) => {
|
2023-03-10 19:30:46 +08:00
|
|
|
const { previousSlide } = props;
|
2023-02-06 21:37:34 +08:00
|
|
|
|
|
|
|
if (event) event.currentTarget.blur();
|
|
|
|
previousSlide(+curPageId, podId);
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
2023-02-06 21:37:34 +08:00
|
|
|
|
2023-03-15 22:39:33 +08:00
|
|
|
const handleOnKeyDown = (event) => {
|
|
|
|
const { which, ctrlKey } = event;
|
2023-02-06 21:37:34 +08:00
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
case KEY_CODES.ARROW_LEFT:
|
|
|
|
case KEY_CODES.PAGE_UP:
|
|
|
|
previousSlideHandler();
|
|
|
|
break;
|
|
|
|
case KEY_CODES.ARROW_RIGHT:
|
|
|
|
case KEY_CODES.PAGE_DOWN:
|
|
|
|
nextSlideHandler();
|
|
|
|
break;
|
|
|
|
case KEY_CODES.ENTER:
|
|
|
|
fullscreenToggleHandler();
|
|
|
|
break;
|
2023-03-15 22:39:33 +08:00
|
|
|
case KEY_CODES.A:
|
|
|
|
if (ctrlKey) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
tldrawAPI?.selectAll();
|
|
|
|
}
|
|
|
|
break;
|
2023-02-06 21:37:34 +08:00
|
|
|
default:
|
|
|
|
}
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
2023-02-06 21:37:34 +08:00
|
|
|
|
2022-07-21 02:50:13 +08:00
|
|
|
const onMount = (app) => {
|
2023-05-27 02:39:09 +08:00
|
|
|
setDockPosition(app?.setSetting);
|
2023-03-10 19:30:46 +08:00
|
|
|
const menu = document.getElementById('TD-Styles')?.parentElement;
|
2023-03-14 00:16:37 +08:00
|
|
|
const canvas = document.getElementById('canvas');
|
|
|
|
if (canvas) {
|
|
|
|
canvas.addEventListener('wheel', handleWheelEvent, { capture: true });
|
|
|
|
}
|
|
|
|
|
2022-10-27 21:15:09 +08:00
|
|
|
if (menu) {
|
2023-03-10 19:30:46 +08:00
|
|
|
const MENU_OFFSET = '48px';
|
|
|
|
menu.style.position = 'relative';
|
2023-02-10 21:37:29 +08:00
|
|
|
menu.style.height = presentationMenuHeight;
|
2023-04-19 02:03:22 +08:00
|
|
|
menu.setAttribute('id', 'TD-Styles-Parent');
|
2022-10-28 01:16:44 +08:00
|
|
|
if (isRTL) {
|
|
|
|
menu.style.left = MENU_OFFSET;
|
|
|
|
} else {
|
|
|
|
menu.style.right = MENU_OFFSET;
|
|
|
|
}
|
|
|
|
|
2022-10-27 21:15:09 +08:00
|
|
|
[...menu.children]
|
2023-03-10 19:30:46 +08:00
|
|
|
.sort((a, b) => (a?.id > b?.id ? -1 : 1))
|
|
|
|
.forEach((n) => menu.appendChild(n));
|
2022-10-27 21:15:09 +08:00
|
|
|
}
|
2023-03-27 06:08:09 +08:00
|
|
|
|
2022-11-01 00:42:38 +08:00
|
|
|
app.setSetting('language', language);
|
2022-11-14 02:15:17 +08:00
|
|
|
app?.setSetting('isDarkMode', false);
|
2023-05-16 21:41:24 +08:00
|
|
|
|
|
|
|
const textAlign = isRTL ? 'end' : 'start';
|
|
|
|
|
2022-11-14 02:15:17 +08:00
|
|
|
app?.patchState(
|
|
|
|
{
|
|
|
|
appState: {
|
|
|
|
currentStyle: {
|
2023-05-16 21:41:24 +08:00
|
|
|
textAlign: currentStyle?.textAlign || textAlign,
|
|
|
|
font: currentStyle?.font || fontFamily,
|
2022-11-14 02:15:17 +08:00
|
|
|
},
|
|
|
|
},
|
2023-03-10 19:30:46 +08:00
|
|
|
},
|
2022-11-14 02:15:17 +08:00
|
|
|
);
|
|
|
|
|
2023-02-25 07:00:15 +08:00
|
|
|
setSafeTLDrawAPI(app);
|
2022-07-21 02:50:13 +08:00
|
|
|
// disable for non presenter that doesn't have multi user access
|
|
|
|
if (!hasWBAccess && !isPresenter) {
|
2023-03-10 19:30:46 +08:00
|
|
|
const newApp = app;
|
|
|
|
newApp.onPan = () => { };
|
|
|
|
newApp.setSelectedIds = () => { };
|
|
|
|
newApp.setHoveredId = () => { };
|
2022-07-21 02:50:13 +08:00
|
|
|
}
|
2022-11-01 18:46:17 +08:00
|
|
|
|
|
|
|
if (history) {
|
|
|
|
app.replaceHistory(history);
|
|
|
|
}
|
2023-03-23 02:00:19 +08:00
|
|
|
|
|
|
|
if (curPageId) {
|
|
|
|
app.patchState(
|
|
|
|
{
|
|
|
|
appState: {
|
|
|
|
currentPageId: curPageId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
setIsMounting(true);
|
|
|
|
}
|
|
|
|
|
2022-07-21 02:50:13 +08:00
|
|
|
};
|
2022-05-03 22:47:45 +08:00
|
|
|
|
2022-08-03 22:19:12 +08:00
|
|
|
const onPatch = (e, t, reason) => {
|
2023-03-01 11:32:24 +08:00
|
|
|
if (!e?.pageState || !reason) return;
|
2023-03-06 07:20:56 +08:00
|
|
|
if (((isPanning || panSelected) && (reason === 'selected' || reason === 'set_hovered_id'))) {
|
2023-03-10 19:30:46 +08:00
|
|
|
e.patchState(
|
2023-03-01 11:32:24 +08:00
|
|
|
{
|
|
|
|
document: {
|
|
|
|
pageStates: {
|
|
|
|
[e.getPage()?.id]: {
|
|
|
|
selectedIds: [],
|
|
|
|
hoveredId: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-10 19:30:46 +08:00
|
|
|
},
|
2023-03-01 11:32:24 +08:00
|
|
|
);
|
2023-03-10 19:30:46 +08:00
|
|
|
return;
|
2023-03-01 11:32:24 +08:00
|
|
|
}
|
2023-01-26 21:11:31 +08:00
|
|
|
|
2022-10-21 22:05:31 +08:00
|
|
|
// don't allow select others shapes for editing if don't have permission
|
2023-03-10 19:30:46 +08:00
|
|
|
if (reason && reason.includes('set_editing_id')) {
|
2022-10-21 22:05:31 +08:00
|
|
|
if (!hasShapeAccess(e.pageState.editingId)) {
|
|
|
|
e.pageState.editingId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// don't allow hover others shapes for editing if don't have permission
|
2023-03-10 19:30:46 +08:00
|
|
|
if (reason && reason.includes('set_hovered_id')) {
|
2022-10-21 22:05:31 +08:00
|
|
|
if (!hasShapeAccess(e.pageState.hoveredId)) {
|
|
|
|
e.pageState.hoveredId = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// don't allow select others shapes if don't have permission
|
2023-03-10 19:30:46 +08:00
|
|
|
if (reason && reason.includes('selected')) {
|
2022-10-21 22:05:31 +08:00
|
|
|
const validIds = [];
|
2023-03-10 19:30:46 +08:00
|
|
|
e.pageState.selectedIds.forEach((id) => hasShapeAccess(id) && validIds.push(id));
|
2022-10-21 22:05:31 +08:00
|
|
|
e.pageState.selectedIds = validIds;
|
|
|
|
e.patchState(
|
|
|
|
{
|
|
|
|
document: {
|
|
|
|
pageStates: {
|
|
|
|
[e.getPage()?.id]: {
|
|
|
|
selectedIds: validIds,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-10 19:30:46 +08:00
|
|
|
},
|
2022-10-21 22:05:31 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
// don't allow selecting others shapes with ctrl (brush)
|
2023-03-10 19:30:46 +08:00
|
|
|
if (e?.session?.type === 'brush' && e?.session?.status === 'brushing') {
|
2022-10-21 22:05:31 +08:00
|
|
|
const validIds = [];
|
2023-03-10 19:30:46 +08:00
|
|
|
e.pageState.selectedIds.forEach((id) => hasShapeAccess(id) && validIds.push(id));
|
2022-10-21 22:05:31 +08:00
|
|
|
e.pageState.selectedIds = validIds;
|
2023-03-10 19:30:46 +08:00
|
|
|
if (!validIds.find((id) => id === e.pageState.hoveredId)) {
|
2022-10-21 22:05:31 +08:00
|
|
|
e.pageState.hoveredId = undefined;
|
|
|
|
}
|
|
|
|
}
|
2022-10-27 21:15:09 +08:00
|
|
|
|
2023-02-11 02:30:24 +08:00
|
|
|
// change cursor when moving shapes
|
2023-03-10 19:30:46 +08:00
|
|
|
if (e?.session?.type === 'translate' && e?.session?.status === 'translating') {
|
2023-02-11 02:30:24 +08:00
|
|
|
if (!isMoving) setIsMoving(true);
|
2023-03-10 19:30:46 +08:00
|
|
|
if (reason === 'set_status:idle') setIsMoving(false);
|
2023-02-11 02:30:24 +08:00
|
|
|
}
|
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
if (reason && isPresenter && slidePosition && (reason.includes('zoomed') || reason.includes('panned'))) {
|
2023-02-24 07:47:34 +08:00
|
|
|
const camera = tldrawAPI?.getPageState()?.camera;
|
2022-08-16 20:12:43 +08:00
|
|
|
|
|
|
|
// limit bounds
|
|
|
|
if (tldrawAPI?.viewport.maxX > slidePosition.width) {
|
2023-03-10 19:30:46 +08:00
|
|
|
camera.point[0] += (tldrawAPI?.viewport.maxX - slidePosition.width);
|
2022-08-16 20:12:43 +08:00
|
|
|
}
|
|
|
|
if (tldrawAPI?.viewport.maxY > slidePosition.height) {
|
2023-03-10 19:30:46 +08:00
|
|
|
camera.point[1] += (tldrawAPI?.viewport.maxY - slidePosition.height);
|
2022-08-16 20:12:43 +08:00
|
|
|
}
|
|
|
|
if (camera.point[0] > 0 || tldrawAPI?.viewport.minX < 0) {
|
|
|
|
camera.point[0] = 0;
|
|
|
|
}
|
|
|
|
if (camera.point[1] > 0 || tldrawAPI?.viewport.minY < 0) {
|
|
|
|
camera.point[1] = 0;
|
2022-07-21 02:50:13 +08:00
|
|
|
}
|
2022-08-16 20:12:43 +08:00
|
|
|
const zoomFitSlide = calculateZoom(slidePosition.width, slidePosition.height);
|
|
|
|
if (camera.zoom < zoomFitSlide) {
|
|
|
|
camera.zoom = zoomFitSlide;
|
|
|
|
}
|
2023-01-27 23:49:32 +08:00
|
|
|
|
2022-08-16 20:12:43 +08:00
|
|
|
tldrawAPI?.setCamera([camera.point[0], camera.point[1]], camera.zoom);
|
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
const zoomToolbar = Math.round(((HUNDRED_PERCENT * camera.zoom) / zoomFitSlide) * 100) / 100;
|
2022-08-16 20:12:43 +08:00
|
|
|
if (zoom !== zoomToolbar) {
|
|
|
|
setZoom(zoomToolbar);
|
2023-03-10 19:30:46 +08:00
|
|
|
if (isPresenter) zoomChanger(zoomToolbar);
|
2022-07-21 02:50:13 +08:00
|
|
|
}
|
2022-08-16 20:12:43 +08:00
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
let viewedRegionW = SlideCalcUtil.calcViewedRegionWidth(
|
|
|
|
tldrawAPI?.viewport.width, slidePosition.width,
|
|
|
|
);
|
|
|
|
let viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
|
|
|
|
tldrawAPI?.viewport.height, slidePosition.height,
|
|
|
|
);
|
2022-08-24 02:19:17 +08:00
|
|
|
|
|
|
|
if (!fitToWidth && camera.zoom === zoomFitSlide) {
|
|
|
|
viewedRegionW = HUNDRED_PERCENT;
|
|
|
|
viewedRegionH = HUNDRED_PERCENT;
|
|
|
|
}
|
2022-08-16 20:12:43 +08:00
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
zoomSlide(
|
|
|
|
parseInt(curPageId, 10),
|
|
|
|
podId,
|
|
|
|
viewedRegionW,
|
|
|
|
viewedRegionH,
|
|
|
|
camera.point[0],
|
|
|
|
camera.point[1],
|
|
|
|
);
|
2022-07-21 02:50:13 +08:00
|
|
|
}
|
2023-03-10 19:30:46 +08:00
|
|
|
// don't allow non-presenters to pan&zoom
|
|
|
|
if (slidePosition && reason && !isPresenter && (reason.includes('zoomed') || reason.includes('panned'))) {
|
|
|
|
const newZoom = calculateZoom(slidePosition.viewBoxWidth, slidePosition.viewBoxHeight);
|
|
|
|
tldrawAPI?.setCamera([slidePosition.x, slidePosition.y], newZoom);
|
2022-07-21 02:50:13 +08:00
|
|
|
}
|
2022-09-03 04:59:03 +08:00
|
|
|
// disable select for non presenter that doesn't have multi user access
|
|
|
|
if (!hasWBAccess && !isPresenter) {
|
|
|
|
if (e?.getPageState()?.brush || e?.selectedIds?.length !== 0) {
|
|
|
|
e.patchState(
|
|
|
|
{
|
|
|
|
document: {
|
|
|
|
pageStates: {
|
|
|
|
[e?.currentPageId]: {
|
|
|
|
selectedIds: [],
|
|
|
|
brush: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-09-01 03:01:53 +08:00
|
|
|
|
2023-01-15 04:37:43 +08:00
|
|
|
if (reason && reason === 'patched_shapes' && e?.session?.type === 'edit') {
|
2022-09-01 03:01:53 +08:00
|
|
|
const patchedShape = e?.getShape(e?.getPageState()?.editingId);
|
2022-11-24 01:03:20 +08:00
|
|
|
|
2023-01-15 04:37:43 +08:00
|
|
|
if (e?.session?.initialShape?.type === 'sticky' && patchedShape?.text?.length > maxStickyNoteLength) {
|
2022-11-24 01:03:20 +08:00
|
|
|
patchedShape.text = patchedShape.text.substring(0, maxStickyNoteLength);
|
|
|
|
}
|
|
|
|
|
2023-01-15 04:37:43 +08:00
|
|
|
if (e?.session?.initialShape?.type === 'text' && !shapes[patchedShape.id]) {
|
2023-02-03 20:11:07 +08:00
|
|
|
// check for maxShapes
|
|
|
|
const currentShapes = e?.document?.pages[e?.currentPageId]?.shapes;
|
|
|
|
const shapeNumberExceeded = Object.keys(currentShapes).length - 1 > maxNumberOfAnnotations;
|
|
|
|
if (shapeNumberExceeded) {
|
|
|
|
notifyShapeNumberExceeded(intl, maxNumberOfAnnotations);
|
|
|
|
e?.cancelSession?.();
|
|
|
|
} else {
|
|
|
|
patchedShape.userId = currentUser?.userId;
|
|
|
|
persistShape(patchedShape, whiteboardId);
|
|
|
|
}
|
2022-10-21 22:05:31 +08:00
|
|
|
} else {
|
|
|
|
const diff = {
|
|
|
|
id: patchedShape.id,
|
|
|
|
point: patchedShape.point,
|
2023-01-15 04:37:43 +08:00
|
|
|
text: patchedShape.text,
|
|
|
|
};
|
2022-10-21 22:05:31 +08:00
|
|
|
persistShape(diff, whiteboardId);
|
2022-09-01 03:01:53 +08:00
|
|
|
}
|
|
|
|
}
|
2022-11-15 06:33:11 +08:00
|
|
|
|
2023-01-12 03:32:03 +08:00
|
|
|
if (reason && reason.includes('selected_tool')) {
|
|
|
|
const tool = reason.split(':')[1];
|
|
|
|
setCurrentTool(tool);
|
2023-02-24 07:47:34 +08:00
|
|
|
setPanSelected(false);
|
|
|
|
setIsPanning(false);
|
2022-11-15 06:33:11 +08:00
|
|
|
}
|
2023-03-09 04:41:25 +08:00
|
|
|
|
2023-04-02 05:05:27 +08:00
|
|
|
if (reason && reason.includes('ui:toggled_is_loading')) {
|
|
|
|
e?.patchState(
|
|
|
|
{
|
|
|
|
appState: {
|
|
|
|
currentStyle,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-09 04:41:25 +08:00
|
|
|
e?.patchState(
|
|
|
|
{
|
|
|
|
appState: {
|
2023-03-10 19:30:46 +08:00
|
|
|
isToolLocked,
|
2023-03-09 04:41:25 +08:00
|
|
|
},
|
2023-03-10 19:30:46 +08:00
|
|
|
},
|
2023-03-09 04:41:25 +08:00
|
|
|
);
|
2023-03-29 00:48:25 +08:00
|
|
|
|
|
|
|
if ((panSelected || isPanning)) {
|
|
|
|
e.isForcePanning = isPanning;
|
|
|
|
}
|
2022-07-21 02:50:13 +08:00
|
|
|
};
|
|
|
|
|
2022-10-21 22:05:31 +08:00
|
|
|
const onUndo = (app) => {
|
|
|
|
if (app.currentPageId !== curPageId) {
|
|
|
|
if (isPresenter) {
|
|
|
|
// change slide for others
|
2023-03-10 19:30:46 +08:00
|
|
|
skipToSlide(Number.parseInt(app.currentPageId, 10), podId);
|
2022-10-21 22:05:31 +08:00
|
|
|
} else {
|
|
|
|
// ignore, stay on same page
|
|
|
|
app.changePage(curPageId);
|
2022-09-03 03:26:26 +08:00
|
|
|
}
|
2022-10-21 22:05:31 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-03-10 19:30:46 +08:00
|
|
|
const lastCommand = app.stack[app.pointer + 1];
|
2022-10-21 22:05:31 +08:00
|
|
|
const changedShapes = lastCommand?.before?.document?.pages[app.currentPageId]?.shapes;
|
|
|
|
if (changedShapes) {
|
2023-03-10 19:30:46 +08:00
|
|
|
sendShapeChanges(
|
|
|
|
app, changedShapes, shapes, prevShapes, hasShapeAccess,
|
|
|
|
whiteboardId, currentUser, intl, true,
|
|
|
|
);
|
2022-10-21 22:05:31 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
const onRedo = (app) => {
|
2022-10-21 22:05:31 +08:00
|
|
|
if (app.currentPageId !== curPageId) {
|
|
|
|
if (isPresenter) {
|
|
|
|
// change slide for others
|
2023-03-10 19:30:46 +08:00
|
|
|
skipToSlide(Number.parseInt(app.currentPageId, 10), podId);
|
2022-10-21 22:05:31 +08:00
|
|
|
} else {
|
|
|
|
// ignore, stay on same page
|
|
|
|
app.changePage(curPageId);
|
2022-09-01 03:01:53 +08:00
|
|
|
}
|
2022-10-21 22:05:31 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const lastCommand = app.stack[app.pointer];
|
|
|
|
const changedShapes = lastCommand?.after?.document?.pages[app.currentPageId]?.shapes;
|
|
|
|
if (changedShapes) {
|
2023-03-10 19:30:46 +08:00
|
|
|
sendShapeChanges(
|
|
|
|
app, changedShapes, shapes, prevShapes, hasShapeAccess, whiteboardId, currentUser, intl,
|
|
|
|
);
|
2022-10-21 22:05:31 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-30 03:30:32 +08:00
|
|
|
const onCommand = (app, command) => {
|
|
|
|
const isFirstCommand = command.id === "change_page" && command.before?.appState.currentPageId === "0";
|
|
|
|
if (!isFirstCommand){
|
|
|
|
setHistory(app.history);
|
|
|
|
}
|
2023-04-02 04:18:03 +08:00
|
|
|
|
2023-04-19 04:56:18 +08:00
|
|
|
if (whiteboardToolbarAutoHide && command && command.id === "change_page") {
|
|
|
|
toggleToolsAnimations('fade-in', 'fade-out', '0s');
|
|
|
|
}
|
|
|
|
|
2023-04-02 04:18:03 +08:00
|
|
|
if (command?.id?.includes('style')) {
|
|
|
|
setCurrentStyle({ ...currentStyle, ...command?.after?.appState?.currentStyle });
|
|
|
|
}
|
2023-04-02 04:22:50 +08:00
|
|
|
|
2022-10-21 22:05:31 +08:00
|
|
|
const changedShapes = command.after?.document?.pages[app.currentPageId]?.shapes;
|
|
|
|
if (!isMounting && app.currentPageId !== curPageId) {
|
|
|
|
// can happen then the "move to page action" is called, or using undo after changing a page
|
2023-03-10 19:30:46 +08:00
|
|
|
const currentPage = curPres.pages.find(
|
|
|
|
(page) => page.num === Number.parseInt(app.currentPageId, 10),
|
|
|
|
);
|
2023-03-08 05:11:40 +08:00
|
|
|
if (!currentPage) return;
|
|
|
|
const newWhiteboardId = currentPage.id;
|
2023-03-10 19:30:46 +08:00
|
|
|
// remove from previous page and persist on new
|
|
|
|
if (changedShapes) {
|
|
|
|
removeShapes(Object.keys(changedShapes), whiteboardId);
|
|
|
|
Object.entries(changedShapes)
|
|
|
|
.forEach(([id, shape]) => {
|
|
|
|
const shapeBounds = app.getShapeBounds(id);
|
|
|
|
const editedShape = shape;
|
|
|
|
editedShape.size = [shapeBounds.width, shapeBounds.height];
|
|
|
|
persistShape(editedShape, newWhiteboardId);
|
|
|
|
});
|
|
|
|
}
|
2022-10-21 22:05:31 +08:00
|
|
|
if (isPresenter) {
|
|
|
|
// change slide for others
|
2023-03-10 19:30:46 +08:00
|
|
|
skipToSlide(Number.parseInt(app.currentPageId, 10), podId);
|
2022-10-21 22:05:31 +08:00
|
|
|
} else {
|
|
|
|
// ignore, stay on same page
|
|
|
|
app.changePage(curPageId);
|
|
|
|
}
|
2023-03-10 19:30:46 +08:00
|
|
|
} else if (changedShapes) {
|
|
|
|
sendShapeChanges(
|
|
|
|
app, changedShapes, shapes, prevShapes, hasShapeAccess, whiteboardId, currentUser, intl,
|
|
|
|
);
|
2022-09-01 03:01:53 +08:00
|
|
|
}
|
2022-07-21 02:50:13 +08:00
|
|
|
};
|
|
|
|
|
2022-08-22 22:37:34 +08:00
|
|
|
const webcams = document.getElementById('cameraDock');
|
2023-03-10 19:30:46 +08:00
|
|
|
const dockPos = webcams?.getAttribute('data-position');
|
2023-05-25 01:36:58 +08:00
|
|
|
const backgroundShape = document.getElementById('slide-background-shape_image');
|
2023-01-26 02:49:09 +08:00
|
|
|
|
2023-03-27 21:38:05 +08:00
|
|
|
if (currentTool && !isPanning && !tldrawAPI?.isForcePanning) tldrawAPI?.selectTool(currentTool);
|
2023-01-26 02:49:09 +08:00
|
|
|
|
2023-05-30 21:18:11 +08:00
|
|
|
if (backgroundShape && backgroundShape.src // if there is a background image
|
|
|
|
&& backgroundShape.complete // and it's fully downloaded
|
|
|
|
&& backgroundShape.src !== bgShape?.src // and if it's a different image
|
|
|
|
&& backgroundShape.parentElement?.clientWidth > 0 // and if the whiteboard area is visible
|
2023-05-30 20:39:31 +08:00
|
|
|
) {
|
2023-05-25 01:36:58 +08:00
|
|
|
setBgShape(backgroundShape);
|
|
|
|
}
|
2022-07-21 02:50:13 +08:00
|
|
|
const editableWB = (
|
2023-03-15 22:39:33 +08:00
|
|
|
<Styled.EditableWBWrapper onKeyDown={handleOnKeyDown}>
|
2022-12-14 00:11:56 +08:00
|
|
|
<Tldraw
|
2023-04-13 02:36:13 +08:00
|
|
|
key={`wb-${isRTL}-${dockPos}-${presentationAreaHeight}-${presentationAreaWidth}-${sidebarNavigationWidth}`}
|
2022-12-14 00:11:56 +08:00
|
|
|
document={doc}
|
|
|
|
// disable the ability to drag and drop files onto the whiteboard
|
|
|
|
// until we handle saving of assets in akka.
|
2023-03-10 19:30:46 +08:00
|
|
|
disableAssets
|
2022-12-14 00:11:56 +08:00
|
|
|
// Disable automatic focus. Users were losing focus on shared notes
|
|
|
|
// and chat on presentation mount.
|
|
|
|
autofocus={false}
|
|
|
|
onMount={onMount}
|
|
|
|
showPages={false}
|
|
|
|
showZoom={false}
|
|
|
|
showUI={curPres ? (isPresenter || hasWBAccess) : true}
|
2023-03-10 19:30:46 +08:00
|
|
|
showMenu={!curPres}
|
2022-12-14 00:11:56 +08:00
|
|
|
showMultiplayerMenu={false}
|
|
|
|
readOnly={false}
|
|
|
|
onPatch={onPatch}
|
|
|
|
onUndo={onUndo}
|
|
|
|
onRedo={onRedo}
|
|
|
|
onCommand={onCommand}
|
|
|
|
/>
|
2023-03-10 19:30:46 +08:00
|
|
|
</Styled.EditableWBWrapper>
|
2022-07-21 02:50:13 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
const readOnlyWB = (
|
|
|
|
<Tldraw
|
2023-03-10 19:30:46 +08:00
|
|
|
key="wb-readOnly"
|
2022-07-21 02:50:13 +08:00
|
|
|
document={doc}
|
|
|
|
onMount={onMount}
|
|
|
|
// disable the ability to drag and drop files onto the whiteboard
|
|
|
|
// until we handle saving of assets in akka.
|
2023-03-10 19:30:46 +08:00
|
|
|
disableAssets
|
2022-07-21 02:50:13 +08:00
|
|
|
// Disable automatic focus. Users were losing focus on shared notes
|
|
|
|
// and chat on presentation mount.
|
|
|
|
autofocus={false}
|
|
|
|
showPages={false}
|
|
|
|
showZoom={false}
|
|
|
|
showUI={false}
|
|
|
|
showMenu={false}
|
|
|
|
showMultiplayerMenu={false}
|
2023-03-10 19:30:46 +08:00
|
|
|
readOnly
|
2022-07-21 02:50:13 +08:00
|
|
|
onPatch={onPatch}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2023-03-10 19:30:46 +08:00
|
|
|
const size = ((height < SMALL_HEIGHT) || (width < SMALL_WIDTH))
|
|
|
|
? TOOLBAR_SMALL : TOOLBAR_LARGE;
|
2023-01-18 08:22:50 +08:00
|
|
|
|
2023-01-23 23:30:59 +08:00
|
|
|
if (hasWBAccess || isPresenter) {
|
2023-05-30 02:03:39 +08:00
|
|
|
if (((height < SMALLEST_DOCK_HEIGHT) || (width < SMALLEST_DOCK_WIDTH))) {
|
2023-01-23 23:30:59 +08:00
|
|
|
tldrawAPI?.setSetting('dockPosition', 'bottom');
|
|
|
|
} else {
|
|
|
|
tldrawAPI?.setSetting('dockPosition', isRTL ? 'left' : 'right');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-27 23:33:10 +08:00
|
|
|
const menuOffsetValues = {
|
|
|
|
true: {
|
|
|
|
true: `${styleMenuOffsetSmall}`,
|
|
|
|
false: `${styleMenuOffset}`,
|
|
|
|
},
|
|
|
|
false: {
|
|
|
|
true: `-${styleMenuOffsetSmall}`,
|
|
|
|
false: `-${styleMenuOffset}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const menuOffset = menuOffsetValues[isRTL][isIphone];
|
|
|
|
|
2022-07-21 02:50:13 +08:00
|
|
|
return (
|
2023-04-14 23:27:37 +08:00
|
|
|
<div key={`animations=-${animations}`}>
|
2022-07-21 02:50:13 +08:00
|
|
|
<Cursors
|
|
|
|
tldrawAPI={tldrawAPI}
|
|
|
|
currentUser={currentUser}
|
2023-03-10 19:30:46 +08:00
|
|
|
hasMultiUserAccess={hasMultiUserAccess}
|
2022-07-21 02:50:13 +08:00
|
|
|
whiteboardId={whiteboardId}
|
|
|
|
isViewersCursorLocked={isViewersCursorLocked}
|
|
|
|
isMultiUserActive={isMultiUserActive}
|
2023-03-10 19:30:46 +08:00
|
|
|
isPanning={isPanning || panSelected}
|
2023-02-11 02:30:24 +08:00
|
|
|
isMoving={isMoving}
|
2023-01-12 03:32:03 +08:00
|
|
|
currentTool={currentTool}
|
2023-03-27 06:08:09 +08:00
|
|
|
whiteboardToolbarAutoHide={whiteboardToolbarAutoHide}
|
|
|
|
toggleToolsAnimations={toggleToolsAnimations}
|
2022-07-21 02:50:13 +08:00
|
|
|
>
|
2023-04-13 01:03:54 +08:00
|
|
|
{(hasWBAccess || isPresenter) ? editableWB : readOnlyWB}
|
2023-03-10 19:30:46 +08:00
|
|
|
<Styled.TldrawGlobalStyle
|
2023-01-18 08:22:50 +08:00
|
|
|
hideContextMenu={!hasWBAccess && !isPresenter}
|
2023-02-14 11:28:36 +08:00
|
|
|
{...{
|
|
|
|
hasWBAccess,
|
|
|
|
isPresenter,
|
|
|
|
size,
|
2023-03-01 10:03:33 +08:00
|
|
|
darkTheme,
|
2023-03-27 23:33:10 +08:00
|
|
|
menuOffset,
|
2023-04-02 22:39:41 +08:00
|
|
|
panSelected,
|
2023-04-19 02:03:22 +08:00
|
|
|
isToolbarVisible,
|
2023-02-14 11:28:36 +08:00
|
|
|
}}
|
2022-11-01 01:07:03 +08:00
|
|
|
/>
|
2022-04-26 21:55:05 +08:00
|
|
|
</Cursors>
|
2023-03-10 19:30:46 +08:00
|
|
|
{isPresenter && (
|
2023-02-24 07:47:34 +08:00
|
|
|
<PanToolInjector
|
|
|
|
{...{
|
|
|
|
tldrawAPI,
|
|
|
|
fitToWidth,
|
|
|
|
isPanning,
|
|
|
|
setIsPanning,
|
|
|
|
zoomValue,
|
|
|
|
panSelected,
|
|
|
|
setPanSelected,
|
2023-02-25 01:17:54 +08:00
|
|
|
currentTool,
|
2023-02-24 07:47:34 +08:00
|
|
|
}}
|
|
|
|
formatMessage={intl?.formatMessage}
|
|
|
|
/>
|
2023-03-10 19:30:46 +08:00
|
|
|
)}
|
2023-04-14 23:27:37 +08:00
|
|
|
</div>
|
2022-04-05 22:49:13 +08:00
|
|
|
);
|
|
|
|
}
|
2023-03-10 19:30:46 +08:00
|
|
|
|
|
|
|
Whiteboard.propTypes = {
|
|
|
|
isPresenter: PropTypes.bool.isRequired,
|
2023-03-27 23:45:16 +08:00
|
|
|
isIphone: PropTypes.bool.isRequired,
|
2023-03-10 19:30:46 +08:00
|
|
|
removeShapes: PropTypes.func.isRequired,
|
|
|
|
initDefaultPages: PropTypes.func.isRequired,
|
|
|
|
persistShape: PropTypes.func.isRequired,
|
|
|
|
notifyNotAllowedChange: PropTypes.func.isRequired,
|
|
|
|
shapes: PropTypes.objectOf(PropTypes.shape).isRequired,
|
|
|
|
assets: PropTypes.objectOf(PropTypes.shape).isRequired,
|
|
|
|
currentUser: PropTypes.shape({
|
|
|
|
userId: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
curPres: PropTypes.shape({
|
|
|
|
pages: PropTypes.arrayOf(PropTypes.shape({})),
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
}),
|
|
|
|
whiteboardId: PropTypes.string,
|
|
|
|
podId: PropTypes.string.isRequired,
|
|
|
|
zoomSlide: PropTypes.func.isRequired,
|
|
|
|
skipToSlide: PropTypes.func.isRequired,
|
|
|
|
slidePosition: PropTypes.shape({
|
|
|
|
x: PropTypes.number.isRequired,
|
|
|
|
y: PropTypes.number.isRequired,
|
|
|
|
height: PropTypes.number.isRequired,
|
|
|
|
width: PropTypes.number.isRequired,
|
|
|
|
viewBoxWidth: PropTypes.number.isRequired,
|
|
|
|
viewBoxHeight: PropTypes.number.isRequired,
|
|
|
|
}),
|
|
|
|
curPageId: PropTypes.string.isRequired,
|
|
|
|
presentationWidth: PropTypes.number.isRequired,
|
|
|
|
presentationHeight: PropTypes.number.isRequired,
|
|
|
|
isViewersCursorLocked: PropTypes.bool.isRequired,
|
|
|
|
zoomChanger: PropTypes.func.isRequired,
|
|
|
|
isMultiUserActive: 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,
|
|
|
|
hasShapeAccess: PropTypes.func.isRequired,
|
|
|
|
presentationAreaHeight: PropTypes.number.isRequired,
|
|
|
|
presentationAreaWidth: PropTypes.number.isRequired,
|
|
|
|
maxNumberOfAnnotations: PropTypes.number.isRequired,
|
|
|
|
notifyShapeNumberExceeded: PropTypes.func.isRequired,
|
|
|
|
darkTheme: PropTypes.bool.isRequired,
|
|
|
|
isPanning: PropTypes.bool.isRequired,
|
|
|
|
setTldrawIsMounting: PropTypes.func.isRequired,
|
|
|
|
width: PropTypes.number.isRequired,
|
|
|
|
height: PropTypes.number.isRequired,
|
|
|
|
hasMultiUserAccess: PropTypes.func.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,
|
|
|
|
nextSlide: PropTypes.func.isRequired,
|
|
|
|
numberOfSlides: PropTypes.number.isRequired,
|
|
|
|
previousSlide: PropTypes.func.isRequired,
|
2023-04-13 02:36:13 +08:00
|
|
|
sidebarNavigationWidth: PropTypes.number,
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Whiteboard.defaultProps = {
|
|
|
|
curPres: undefined,
|
|
|
|
fullscreenRef: undefined,
|
|
|
|
slidePosition: undefined,
|
|
|
|
svgUri: undefined,
|
|
|
|
whiteboardId: undefined,
|
2023-04-13 02:36:13 +08:00
|
|
|
sidebarNavigationWidth: 0,
|
2023-03-10 19:30:46 +08:00
|
|
|
};
|