diff --git a/src/components/Select.tsx b/src/components/Select.tsx
index a412982..c358076 100644
--- a/src/components/Select.tsx
+++ b/src/components/Select.tsx
@@ -3,7 +3,7 @@ import Creatable from "react-select/creatable";
import { useThemeUI } from "theme-ui";
type SelectProps = {
- creatable: boolean;
+ creatable?: boolean;
} & Props;
function Select({ creatable, ...props }: SelectProps) {
@@ -76,4 +76,8 @@ function Select({ creatable, ...props }: SelectProps) {
);
}
+Select.defaultProps = {
+ creatable: false,
+};
+
export default Select;
diff --git a/src/components/map/DragOverlay.tsx b/src/components/map/DragOverlay.tsx
index cd831b6..c685e17 100644
--- a/src/components/map/DragOverlay.tsx
+++ b/src/components/map/DragOverlay.tsx
@@ -72,29 +72,31 @@ function DragOverlay({ dragging, node, onRemove }: DragOverlayProps) {
}
});
+ if (!dragging) {
+ return null;
+ }
+
return (
- dragging && (
-
-
-
-
-
- )
+
+
+
+
+
);
}
diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx
index e9c84e7..f4419ea 100644
--- a/src/components/map/Map.tsx
+++ b/src/components/map/Map.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import { useState } from "react";
import { Box } from "theme-ui";
import { useToasts } from "react-toast-notifications";
@@ -27,15 +27,48 @@ import {
RemoveStatesAction,
} from "../../actions";
import Session from "../../network/Session";
-import { Drawing } from "../../types/Drawing";
-import { Fog } from "../../types/Fog";
-import { Map, MapToolId } from "../../types/Map";
+import { Drawing, DrawingState } from "../../types/Drawing";
+import { Fog, FogState } from "../../types/Fog";
+import { Map, MapActions, MapToolId } from "../../types/Map";
import { MapState } from "../../types/MapState";
import { Settings } from "../../types/Settings";
import {
MapChangeEventHandler,
MapResetEventHandler,
+ MapTokensStateCreateHandler,
+ MapTokenStateRemoveHandler,
+ NoteChangeEventHandler,
+ NoteRemoveEventHander,
+ TokenStateChangeEventHandler,
} from "../../types/Events";
+import Action from "../../actions/Action";
+import Konva from "konva";
+import { TokenDraggingOptions, TokenMenuOptions } from "../../types/Token";
+import { Note, NoteDraggingOptions, NoteMenuOptions } from "../../types/Note";
+
+type MapProps = {
+ map: Map;
+ mapState: MapState;
+ mapActions: MapActions;
+ onMapTokenStateChange: TokenStateChangeEventHandler;
+ onMapTokenStateRemove: MapTokenStateRemoveHandler;
+ onMapChange: MapChangeEventHandler;
+ onMapReset: MapResetEventHandler;
+ onMapDraw: (action: Action) => void;
+ onMapDrawUndo: () => void;
+ onMapDrawRedo: () => void;
+ onFogDraw: (action: Action) => void;
+ onFogDrawUndo: () => void;
+ onFogDrawRedo: () => void;
+ onMapNoteChange: NoteChangeEventHandler;
+ onMapNoteRemove: NoteRemoveEventHander;
+ allowMapDrawing: boolean;
+ allowFogDrawing: boolean;
+ allowMapChange: boolean;
+ allowNoteEditing: boolean;
+ disabledTokens: string[];
+ session: Session;
+};
function Map({
map,
@@ -59,29 +92,7 @@ function Map({
allowNoteEditing,
disabledTokens,
session,
-}: {
- map: Map;
- mapState: MapState;
- mapActions: ;
- onMapTokenStateChange: ;
- onMapTokenStateRemove: ;
- onMapChange: MapChangeEventHandler;
- onMapReset: MapResetEventHandler;
- onMapDraw: ;
- onMapDrawUndo: ;
- onMapDrawRedo: ;
- onFogDraw: ;
- onFogDrawUndo: ;
- onFogDrawRedo: ;
- onMapNoteChange: ;
- onMapNoteRemove: ;
- allowMapDrawing: boolean;
- allowFogDrawing: boolean;
- allowMapChange: boolean;
- allowNoteEditing: boolean;
- disabledTokens: ;
- session: Session;
-}) {
+}: MapProps) {
const { addToast } = useToasts();
const { tokensById } = useTokenData();
@@ -141,7 +152,7 @@ function Map({
onFogDraw(new EditStatesAction(shapes));
}
- const disabledControls = [];
+ const disabledControls: MapToolId[] = [];
if (!allowMapDrawing) {
disabledControls.push("drawing");
}
@@ -206,9 +217,10 @@ function Map({
);
const [isTokenMenuOpen, setIsTokenMenuOpen] = useState(false);
- const [tokenMenuOptions, setTokenMenuOptions] = useState({});
- const [tokenDraggingOptions, setTokenDraggingOptions] = useState();
- function handleTokenMenuOpen(tokenStateId: string, tokenImage) {
+ const [tokenMenuOptions, setTokenMenuOptions] = useState();
+ const [tokenDraggingOptions, setTokenDraggingOptions] =
+ useState();
+ function handleTokenMenuOpen(tokenStateId: string, tokenImage: Konva.Node) {
setTokenMenuOptions({ tokenStateId, tokenImage });
setIsTokenMenuOpen(true);
}
@@ -220,7 +232,7 @@ function Map({
tokenDraggingOptions={tokenDraggingOptions}
setTokenDraggingOptions={setTokenDraggingOptions}
onMapTokenStateChange={onMapTokenStateChange}
- handleTokenMenuOpen={handleTokenMenuOpen}
+ onTokenMenuOpen={handleTokenMenuOpen}
selectedToolId={selectedToolId}
disabledTokens={disabledTokens}
/>
@@ -231,8 +243,12 @@ function Map({
isOpen={isTokenMenuOpen}
onRequestClose={() => setIsTokenMenuOpen(false)}
onTokenStateChange={onMapTokenStateChange}
- tokenState={mapState && mapState.tokens[tokenMenuOptions.tokenStateId]}
- tokenImage={tokenMenuOptions.tokenImage}
+ tokenState={
+ tokenMenuOptions &&
+ mapState &&
+ mapState.tokens[tokenMenuOptions.tokenStateId]
+ }
+ tokenImage={tokenMenuOptions && tokenMenuOptions.tokenImage}
map={map}
/>
);
@@ -241,7 +257,7 @@ function Map({
{
onMapTokenStateRemove(state);
- setTokenDraggingOptions(null);
+ setTokenDraggingOptions(undefined);
}}
onTokenStateChange={onMapTokenStateChange}
tokenState={tokenDraggingOptions && tokenDraggingOptions.tokenState}
@@ -291,14 +307,19 @@ function Map({
);
const [isNoteMenuOpen, setIsNoteMenuOpen] = useState(false);
- const [noteMenuOptions, setNoteMenuOptions] = useState({});
- const [noteDraggingOptions, setNoteDraggingOptions] = useState();
- function handleNoteMenuOpen(noteId: string, noteNode) {
+ const [noteMenuOptions, setNoteMenuOptions] = useState();
+ const [noteDraggingOptions, setNoteDraggingOptions] =
+ useState();
+ function handleNoteMenuOpen(noteId: string, noteNode: Konva.Node) {
setNoteMenuOptions({ noteId, noteNode });
setIsNoteMenuOpen(true);
}
- function sortNotes(a, b, noteDraggingOptions) {
+ function sortNotes(
+ a: Note,
+ b: Note,
+ noteDraggingOptions?: NoteDraggingOptions
+ ) {
if (
noteDraggingOptions &&
noteDraggingOptions.dragging &&
@@ -341,6 +362,7 @@ function Map({
setNoteDraggingOptions({ dragging: true, noteId, noteGroup: e.target })
}
onNoteDragEnd={() =>
+ noteDraggingOptions &&
setNoteDraggingOptions({ ...noteDraggingOptions, dragging: false })
}
fadeOnHover={selectedToolId === "drawing"}
@@ -352,23 +374,25 @@ function Map({
isOpen={isNoteMenuOpen}
onRequestClose={() => setIsNoteMenuOpen(false)}
onNoteChange={onMapNoteChange}
- note={mapState && mapState.notes[noteMenuOptions.noteId]}
- noteNode={noteMenuOptions.noteNode}
+ note={
+ noteMenuOptions && mapState && mapState.notes[noteMenuOptions.noteId]
+ }
+ noteNode={noteMenuOptions?.noteNode}
map={map}
/>
);
- const noteDragOverlay = (
+ const noteDragOverlay = noteDraggingOptions ? (
{
onMapNoteRemove(noteId);
- setNoteDraggingOptions(null);
+ setNoteDraggingOptions(undefined);
}}
/>
- );
+ ) : null;
return (
diff --git a/src/components/map/MapEditor.tsx b/src/components/map/MapEditor.tsx
index 167b8fc..ff1baf2 100644
--- a/src/components/map/MapEditor.tsx
+++ b/src/components/map/MapEditor.tsx
@@ -24,8 +24,7 @@ import MapGrid from "./MapGrid";
import MapGridEditor from "./MapGridEditor";
import { Map } from "../../types/Map";
import { GridInset } from "../../types/Grid";
-
-type MapSettingsChangeEventHandler = (change: Partial
@@ -197,7 +234,9 @@ function MapSettings({
onSettingsChange("showGrid", e.target.checked)}
+ onChange={(e) =>
+ onSettingsChange({ showGrid: e.target.checked })
+ }
/>
Draw Grid
@@ -206,7 +245,7 @@ function MapSettings({
checked={!mapEmpty && map.snapToGrid}
disabled={mapEmpty}
onChange={(e) =>
- onSettingsChange("snapToGrid", e.target.checked)
+ onSettingsChange({ snapToGrid: e.target.checked })
}
/>
Snap to Grid
@@ -224,12 +263,13 @@ function MapSettings({
: gridHexMeasurementTypeSettings
}
value={
- !mapEmpty &&
- gridSquareMeasurementTypeSettings.find(
- (s) => s.value === map.grid.measurement.type
- )
+ mapEmpty
+ ? undefined
+ : gridSquareMeasurementTypeSettings.find(
+ (s) => s.value === map.grid.measurement.type
+ )
}
- onChange={handleGridMeasurementTypeChange}
+ onChange={handleGridMeasurementTypeChange as any}
isSearchable={false}
/>
@@ -254,14 +294,17 @@ function MapSettings({