2020-02-19 08:25:01 -08:00
|
|
|
import { AppState, FlooredNumber } from "./types";
|
2020-01-11 20:34:21 -08:00
|
|
|
import { getDateTime } from "./utils";
|
basic Socket.io implementation of collaborative editing (#879)
* Enable collaborative syncing for elements
* Don't fall back to local storage if using a room, as that is confusing
* Use remote socket server
* Send updates to new users when they join
* ~
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* Enable collaborative syncing for elements
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* prettier
* Fix bug with remote pointers not changing on scroll
* Enable collaborative syncing for elements
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* fix syncing bugs and add a button to start syncing mid session
* Fix bug with remote pointers not changing on scroll
* remove UI for collaboration
* remove link
* clean up lingering unused UI
* set random IV passed per encrypted message, reduce room id length, refactored socket broadcasting API, rename room_id to room, removed throttling of pointer movement
* fix package.json conflict
2020-03-09 08:48:25 -07:00
|
|
|
import { getCollaborationLinkData } from "./data";
|
2020-01-11 20:34:21 -08:00
|
|
|
|
|
|
|
const DEFAULT_PROJECT_NAME = `excalidraw-${getDateTime()}`;
|
2020-02-24 16:29:54 +01:00
|
|
|
export const DEFAULT_FONT = "20px Virgil";
|
2020-01-11 20:34:21 -08:00
|
|
|
|
|
|
|
export function getDefaultAppState(): AppState {
|
|
|
|
return {
|
|
|
|
draggingElement: null,
|
|
|
|
resizingElement: null,
|
2020-02-01 15:49:18 +04:00
|
|
|
multiElement: null,
|
2020-01-19 23:32:24 +01:00
|
|
|
editingElement: null,
|
2020-01-11 20:34:21 -08:00
|
|
|
elementType: "selection",
|
2020-01-20 15:52:19 -08:00
|
|
|
elementLocked: false,
|
2020-01-11 20:34:21 -08:00
|
|
|
exportBackground: true,
|
|
|
|
currentItemStrokeColor: "#000000",
|
|
|
|
currentItemBackgroundColor: "transparent",
|
2020-01-25 18:58:57 +01:00
|
|
|
currentItemFillStyle: "hachure",
|
|
|
|
currentItemStrokeWidth: 1,
|
|
|
|
currentItemRoughness: 1,
|
|
|
|
currentItemOpacity: 100,
|
2020-02-24 16:29:54 +01:00
|
|
|
currentItemFont: DEFAULT_FONT,
|
2020-01-11 20:34:21 -08:00
|
|
|
viewBackgroundColor: "#ffffff",
|
2020-02-19 08:25:01 -08:00
|
|
|
scrollX: 0 as FlooredNumber,
|
|
|
|
scrollY: 0 as FlooredNumber,
|
2020-01-11 20:34:21 -08:00
|
|
|
cursorX: 0,
|
|
|
|
cursorY: 0,
|
2020-02-01 16:52:10 +00:00
|
|
|
scrolledOutside: false,
|
2020-01-24 12:04:54 +02:00
|
|
|
name: DEFAULT_PROJECT_NAME,
|
basic Socket.io implementation of collaborative editing (#879)
* Enable collaborative syncing for elements
* Don't fall back to local storage if using a room, as that is confusing
* Use remote socket server
* Send updates to new users when they join
* ~
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* Enable collaborative syncing for elements
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* prettier
* Fix bug with remote pointers not changing on scroll
* Enable collaborative syncing for elements
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* fix syncing bugs and add a button to start syncing mid session
* Fix bug with remote pointers not changing on scroll
* remove UI for collaboration
* remove link
* clean up lingering unused UI
* set random IV passed per encrypted message, reduce room id length, refactored socket broadcasting API, rename room_id to room, removed throttling of pointer movement
* fix package.json conflict
2020-03-09 08:48:25 -07:00
|
|
|
isCollaborating: !!getCollaborationLinkData(window.location.href),
|
2020-02-03 21:52:21 +04:00
|
|
|
isResizing: false,
|
2020-02-05 22:47:10 +04:00
|
|
|
selectionElement: null,
|
2020-02-15 21:03:32 +01:00
|
|
|
zoom: 1,
|
2020-03-01 14:39:03 -05:00
|
|
|
openMenu: null,
|
2020-02-21 14:34:18 -05:00
|
|
|
lastPointerDownWith: "mouse",
|
2020-03-08 10:20:55 -07:00
|
|
|
selectedElementIds: {},
|
basic Socket.io implementation of collaborative editing (#879)
* Enable collaborative syncing for elements
* Don't fall back to local storage if using a room, as that is confusing
* Use remote socket server
* Send updates to new users when they join
* ~
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* Enable collaborative syncing for elements
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* prettier
* Fix bug with remote pointers not changing on scroll
* Enable collaborative syncing for elements
* add mouse tracking
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* Add Live button and app state to support tracking collaborator counts
* enable collaboration, rooms, and mouse tracking
* fix syncing bugs and add a button to start syncing mid session
* fix syncing bugs and add a button to start syncing mid session
* Fix bug with remote pointers not changing on scroll
* remove UI for collaboration
* remove link
* clean up lingering unused UI
* set random IV passed per encrypted message, reduce room id length, refactored socket broadcasting API, rename room_id to room, removed throttling of pointer movement
* fix package.json conflict
2020-03-09 08:48:25 -07:00
|
|
|
remotePointers: {},
|
|
|
|
collaboratorCount: 0,
|
2020-01-11 20:34:21 -08:00
|
|
|
};
|
|
|
|
}
|
2020-02-01 15:49:18 +04:00
|
|
|
|
2020-02-04 17:39:08 +04:00
|
|
|
export function clearAppStateForLocalStorage(appState: AppState) {
|
|
|
|
const {
|
|
|
|
draggingElement,
|
|
|
|
resizingElement,
|
|
|
|
multiElement,
|
|
|
|
editingElement,
|
2020-02-05 22:47:10 +04:00
|
|
|
selectionElement,
|
2020-02-04 17:39:08 +04:00
|
|
|
isResizing,
|
|
|
|
...exportedState
|
|
|
|
} = appState;
|
|
|
|
return exportedState;
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:47:10 +04:00
|
|
|
export function clearAppStatePropertiesForHistory(
|
|
|
|
appState: AppState,
|
|
|
|
): Partial<AppState> {
|
|
|
|
return {
|
|
|
|
exportBackground: appState.exportBackground,
|
|
|
|
currentItemStrokeColor: appState.currentItemStrokeColor,
|
|
|
|
currentItemBackgroundColor: appState.currentItemBackgroundColor,
|
|
|
|
currentItemFillStyle: appState.currentItemFillStyle,
|
|
|
|
currentItemStrokeWidth: appState.currentItemStrokeWidth,
|
|
|
|
currentItemRoughness: appState.currentItemRoughness,
|
|
|
|
currentItemOpacity: appState.currentItemOpacity,
|
|
|
|
currentItemFont: appState.currentItemFont,
|
|
|
|
viewBackgroundColor: appState.viewBackgroundColor,
|
|
|
|
name: appState.name,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-02-01 15:49:18 +04:00
|
|
|
export function cleanAppStateForExport(appState: AppState) {
|
|
|
|
return {
|
|
|
|
viewBackgroundColor: appState.viewBackgroundColor,
|
|
|
|
};
|
|
|
|
}
|