@rivm-loculus-tools/sequence-editor 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitkeep +0 -0
- package/CHANGELOG.md +8 -0
- package/LICENSE +288 -0
- package/eslint.config.js +16 -0
- package/package.json +140 -3
- package/scripts/update-exports.js +9 -0
- package/src/classes/services/EditorWorkerService/EditorWorkerService.ts +163 -0
- package/src/classes/services/EditorWorkerService/index.ts +1 -0
- package/src/classes/services/SequenceEditorEventBusService/SequenceEditorEventBusService.ts +37 -0
- package/src/classes/services/SequenceEditorEventBusService/index.ts +1 -0
- package/src/classes/workers/EngineWorker/EngineWorker.ts +196 -0
- package/src/classes/workers/EngineWorker/index.ts +1 -0
- package/src/components/app/App/App.tsx +22 -0
- package/src/components/app/App/index.ts +1 -0
- package/src/components/pages/EmptyWorkspace.tsx +43 -0
- package/src/components/pages/SequenceEditorErrorPage/SequenceEditorErrorPage.tsx +16 -0
- package/src/components/pages/SequenceEditorErrorPage/index.ts +1 -0
- package/src/components/pages/SequenceEditorMainPage/SequenceEditorMainPage.tsx +76 -0
- package/src/components/pages/SequenceEditorMainPage/index.ts +1 -0
- package/src/components/ui/SequenceEditor/SequenceEditor.tsx +896 -0
- package/src/components/ui/SequenceEditor/SequenceEditorGotoPositionDialog.tsx +108 -0
- package/src/components/ui/SequenceEditor/SequenceEditorStatusBar.tsx +72 -0
- package/src/components/ui/SequenceEditor/index.ts +1 -0
- package/src/components/ui/SequenceEditorPage/SequenceEditorPage.tsx +23 -0
- package/src/components/ui/SequenceEditorPage/index.ts +1 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawer.tsx +234 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerColorForm.tsx +73 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerKeyboardShortcuts.tsx +230 -0
- package/src/components/ui/SequenceEditorPageDrawer/index.ts +1 -0
- package/src/components/ui/SequenceEditorPageHeader/SequenceEditorPageHeader.tsx +71 -0
- package/src/components/ui/SequenceEditorPageHeader/index.ts +1 -0
- package/src/components/ui/SequenceEditorSearchBar/SequenceEditorSearchBar.tsx +35 -0
- package/src/components/ui/SequenceEditorSearchBar/index.ts +1 -0
- package/src/constants/editor.ts +15 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/keyboard.ts +154 -0
- package/src/constants/palette.ts +227 -0
- package/src/models/editor.ts +6 -0
- package/src/models/index.ts +3 -0
- package/src/models/model.ts +295 -0
- package/src/models/palette.ts +68 -0
- package/src/stores/sequenceEditorStore/index.ts +1 -0
- package/src/stores/sequenceEditorStore/sequenceEditorStore.ts +103 -0
- package/src/utils/EditorUtil/EditorUtil.ts +892 -0
- package/src/utils/EditorUtil/index.ts +1 -0
- package/src/utils/EngineErrorUtil/EngineErrorUtil.ts +25 -0
- package/src/utils/PaletteUtil/PaletteUtil.ts +31 -0
- package/src/utils/PaletteUtil/index.ts +1 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +32 -0
- package/vite.config.ts +177 -0
- package/README.md +0 -3
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MouseEvent as ReactMouseEvent,
|
|
3
|
+
UIEvent,
|
|
4
|
+
} from 'react';
|
|
5
|
+
import {
|
|
6
|
+
useCallback,
|
|
7
|
+
useEffect,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import {
|
|
13
|
+
Box,
|
|
14
|
+
useTheme,
|
|
15
|
+
} from '@mui/material';
|
|
16
|
+
import { Subject } from '@gen-epix/ui-core/classes/Subject';
|
|
17
|
+
import { useDebouncedCallback } from 'use-debounce';
|
|
18
|
+
import { DevicePixelRatioService } from '@gen-epix/ui-core/classes/services/DevicePixelRatioService';
|
|
19
|
+
import { KeyboardShortcutService } from '@gen-epix/ui-core/classes/services/KeyboardShortcutService';
|
|
20
|
+
import { useStore } from 'zustand';
|
|
21
|
+
|
|
22
|
+
import { EditorWorkerService } from '../../../classes/services/EditorWorkerService';
|
|
23
|
+
import { SequenceEditorEventBusService } from '../../../classes/services/SequenceEditorEventBusService';
|
|
24
|
+
import type {
|
|
25
|
+
EditorAssembly,
|
|
26
|
+
EditorPathProperties,
|
|
27
|
+
EditorSelection,
|
|
28
|
+
EngineMeta,
|
|
29
|
+
EngineSearchResult,
|
|
30
|
+
GridGeometry,
|
|
31
|
+
GridRangeWithRowNames,
|
|
32
|
+
GridRangeWithViewportResults,
|
|
33
|
+
VisibleGridRangeWithArguments,
|
|
34
|
+
} from '../../../models';
|
|
35
|
+
import {
|
|
36
|
+
EDITOR_DIRECTION,
|
|
37
|
+
EDITOR_PATH_PROPERTIES_TYPE,
|
|
38
|
+
} from '../../../models';
|
|
39
|
+
import {
|
|
40
|
+
DEFAULT_GRID_GEOMETRY,
|
|
41
|
+
IUPAC_KEYS,
|
|
42
|
+
KEYBOARD_SHORTCUTS,
|
|
43
|
+
MIN_LABEL_WIDTH,
|
|
44
|
+
} from '../../../constants';
|
|
45
|
+
import { EditorUtil } from '../../../utils/EditorUtil';
|
|
46
|
+
import { sequenceEditorStore } from '../../../stores/sequenceEditorStore';
|
|
47
|
+
import { SequenceEditorSearchBar } from '../SequenceEditorSearchBar';
|
|
48
|
+
|
|
49
|
+
import { SequenceEditorStatusBar } from './SequenceEditorStatusBar';
|
|
50
|
+
import type { SequenceEditorGotoPositionDialogRefMethods } from './SequenceEditorGotoPositionDialog';
|
|
51
|
+
import { SequenceEditorGotoPositionDialog } from './SequenceEditorGotoPositionDialog';
|
|
52
|
+
|
|
53
|
+
export const SequenceEditor = () => {
|
|
54
|
+
const rawFasta = useStore(sequenceEditorStore, (state) => state.rawFasta);
|
|
55
|
+
const setLatestMessage = useStore(sequenceEditorStore, (state) => state.setLatestMessage);
|
|
56
|
+
const setMeta = useStore(sequenceEditorStore, (state) => state.setMeta);
|
|
57
|
+
const setSelection = useStore(sequenceEditorStore, (state) => state.setSelection);
|
|
58
|
+
const sequenceEditorGotoPositionDialogRef = useRef<null | SequenceEditorGotoPositionDialogRefMethods>(null);
|
|
59
|
+
const editorService = useMemo(() => EditorWorkerService.getInstance(), []);
|
|
60
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
61
|
+
const editorAssemblyRef = useRef<EditorAssembly | null>(null);
|
|
62
|
+
const labelResizeRef = useRef<{ startLabelWidth: number; startX: number } | null>(null);
|
|
63
|
+
const selectionDragRef = useRef<EditorPathProperties | null>(null);
|
|
64
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
65
|
+
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
|
66
|
+
const [containerDimensions, setContainerDimensions] = useState<{ height: number; width: number }>({ height: 0, width: 0 });
|
|
67
|
+
const [devicePixelRatio, setDevicePixelRatio] = useState(() => DevicePixelRatioService.getInstance().data);
|
|
68
|
+
const [verticalScrollBarSize, setVerticalScrollBarSize] = useState(0);
|
|
69
|
+
const [horizontalScrollBarSize, setHorizontalScrollBarSize] = useState(0);
|
|
70
|
+
const scrollSubject = useMemo(() => new Subject<{ scrollLeft: number; scrollTop: number }>({ scrollLeft: 0, scrollTop: 0 }), []);
|
|
71
|
+
const containerDimensionsRef = useRef(containerDimensions);
|
|
72
|
+
const metaSubject = useMemo(() => new Subject<EngineMeta | null>(null), []);
|
|
73
|
+
const visibleRangeSubject = useMemo(() => new Subject<null | VisibleGridRangeWithArguments>(null), []);
|
|
74
|
+
const cachedGridRangeWithViewPortResultRef = useRef<GridRangeWithViewportResults | null>(null);
|
|
75
|
+
const cachedGridRangeWithRowNamesRef = useRef<GridRangeWithRowNames | null>(null);
|
|
76
|
+
const geometrySubject = useMemo(() => new Subject<GridGeometry>(DEFAULT_GRID_GEOMETRY), []);
|
|
77
|
+
const selectionSubject = useMemo(() => new Subject<EditorSelection | null>(null), []);
|
|
78
|
+
const initialSelectionRef = useRef<EditorSelection | null>(null);
|
|
79
|
+
const visibleRangeRequestRef = useRef(0);
|
|
80
|
+
const pendingVisibleRangeRef = useRef<null | VisibleGridRangeWithArguments>(null);
|
|
81
|
+
const processingVisibleRangeRef = useRef(false);
|
|
82
|
+
const theme = useTheme();
|
|
83
|
+
|
|
84
|
+
const updateScrollbars = useCallback(() => {
|
|
85
|
+
const geometry = geometrySubject.data;
|
|
86
|
+
const meta = metaSubject.data;
|
|
87
|
+
if (!geometry || !meta) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const horizontalSize = geometry.labelWidth + geometry.cellWidth + meta.alignmentWidth * geometry.cellWidth;
|
|
91
|
+
const verticalSize = geometry.rulerHeight + meta.sequenceCount * geometry.cellHeight;
|
|
92
|
+
setHorizontalScrollBarSize(horizontalSize);
|
|
93
|
+
setVerticalScrollBarSize(verticalSize);
|
|
94
|
+
}, [geometrySubject, metaSubject]);
|
|
95
|
+
|
|
96
|
+
const updateMeta = useCallback(async () => {
|
|
97
|
+
const meta = await EditorWorkerService.getInstance().getMetaData();
|
|
98
|
+
metaSubject.next(meta);
|
|
99
|
+
}, [metaSubject]);
|
|
100
|
+
|
|
101
|
+
const updateVisibleRange = useCallback(() => {
|
|
102
|
+
const geometry = geometrySubject.data;
|
|
103
|
+
const meta = metaSubject.data;
|
|
104
|
+
if (!meta || !geometry) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const { scrollLeft, scrollTop } = scrollSubject.data;
|
|
108
|
+
const { height, width } = containerDimensionsRef.current;
|
|
109
|
+
const visibleRange = EditorUtil.getVisibleGridRange({
|
|
110
|
+
geometry,
|
|
111
|
+
numCols: meta.alignmentWidth,
|
|
112
|
+
numRows: meta.sequenceCount,
|
|
113
|
+
scrollLeft,
|
|
114
|
+
scrollTop,
|
|
115
|
+
viewportHeight: height,
|
|
116
|
+
viewportWidth: width,
|
|
117
|
+
});
|
|
118
|
+
visibleRangeSubject.next({
|
|
119
|
+
geometry,
|
|
120
|
+
scrollLeft,
|
|
121
|
+
scrollTop,
|
|
122
|
+
viewportHeight: height,
|
|
123
|
+
viewportWidth: width,
|
|
124
|
+
visibleGridRange: visibleRange,
|
|
125
|
+
});
|
|
126
|
+
}, [geometrySubject, metaSubject, scrollSubject, visibleRangeSubject]);
|
|
127
|
+
|
|
128
|
+
const updateDimensionsDebounced = useDebouncedCallback((width: number, height: number) => {
|
|
129
|
+
setContainerDimensions({ height, width });
|
|
130
|
+
}, 0, { trailing: true });
|
|
131
|
+
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
containerDimensionsRef.current = containerDimensions;
|
|
134
|
+
updateVisibleRange();
|
|
135
|
+
}, [containerDimensions, updateVisibleRange]);
|
|
136
|
+
|
|
137
|
+
const maxLabelWidth = containerDimensions.width > 0 ? containerDimensions.width / 2 : MIN_LABEL_WIDTH;
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
const removers = [
|
|
141
|
+
metaSubject.subscribe(data => {
|
|
142
|
+
setMeta(data);
|
|
143
|
+
}),
|
|
144
|
+
selectionSubject.subscribe(data => {
|
|
145
|
+
setSelection(data);
|
|
146
|
+
}),
|
|
147
|
+
];
|
|
148
|
+
return () => {
|
|
149
|
+
removers.forEach(remove => remove());
|
|
150
|
+
setLatestMessage(null);
|
|
151
|
+
setMeta(null);
|
|
152
|
+
setSelection(null);
|
|
153
|
+
};
|
|
154
|
+
}, [metaSubject, selectionSubject, setLatestMessage, setMeta, setSelection]);
|
|
155
|
+
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (containerDimensions.width <= 0) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const geometry = geometrySubject.data;
|
|
161
|
+
if (geometry.labelWidth > maxLabelWidth) {
|
|
162
|
+
geometrySubject.next({
|
|
163
|
+
...geometry,
|
|
164
|
+
labelWidth: maxLabelWidth,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}, [containerDimensions.width, geometrySubject, maxLabelWidth]);
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
// Observe the scroll container itself (not its outer wrapper) so contentRect
|
|
171
|
+
// reflects the area actually visible past the always-on scrollbar gutter.
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
const element = scrollContainerRef.current;
|
|
174
|
+
if (!element) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
178
|
+
if (!entry) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const height = Math.max(1, entry.contentRect.height);
|
|
182
|
+
const width = Math.max(1, entry.contentRect.width);
|
|
183
|
+
updateDimensionsDebounced(width, height);
|
|
184
|
+
|
|
185
|
+
});
|
|
186
|
+
observer.observe(element);
|
|
187
|
+
return () => observer.disconnect();
|
|
188
|
+
}, [editorService, updateDimensionsDebounced]);
|
|
189
|
+
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
const perform = async () => {
|
|
192
|
+
cachedGridRangeWithViewPortResultRef.current = null;
|
|
193
|
+
cachedGridRangeWithRowNamesRef.current = null;
|
|
194
|
+
scrollSubject.next({ scrollLeft: 0, scrollTop: 0 });
|
|
195
|
+
selectionSubject.next(null);
|
|
196
|
+
await editorService.initialize();
|
|
197
|
+
await editorService.loadFasta(rawFasta);
|
|
198
|
+
await updateMeta();
|
|
199
|
+
updateVisibleRange();
|
|
200
|
+
};
|
|
201
|
+
perform().catch((error) => {
|
|
202
|
+
console.error(error);
|
|
203
|
+
});
|
|
204
|
+
}, [editorService, rawFasta, scrollSubject, selectionSubject, updateMeta, updateVisibleRange]);
|
|
205
|
+
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
let animationFrame: null | number = null;
|
|
208
|
+
let isActive = true;
|
|
209
|
+
let searchResult: EngineSearchResult | null = null;
|
|
210
|
+
let searchResultHighlightedIndex: null | number = null;
|
|
211
|
+
|
|
212
|
+
const processVisibleRange = async (): Promise<void> => {
|
|
213
|
+
if (!isActive || processingVisibleRangeRef.current) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
processingVisibleRangeRef.current = true;
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
while (isActive && pendingVisibleRangeRef.current) {
|
|
220
|
+
const visibleGridRangeWithArguments = pendingVisibleRangeRef.current;
|
|
221
|
+
pendingVisibleRangeRef.current = null;
|
|
222
|
+
const requestId = visibleRangeRequestRef.current;
|
|
223
|
+
|
|
224
|
+
if (!cachedGridRangeWithRowNamesRef.current || !EditorUtil.isWithinGridRange({
|
|
225
|
+
cachedGridRange: cachedGridRangeWithRowNamesRef.current.range,
|
|
226
|
+
visibleGridRange: visibleGridRangeWithArguments.visibleGridRange.visible,
|
|
227
|
+
})) {
|
|
228
|
+
const rowNames: string[] = [];
|
|
229
|
+
for (let i = visibleGridRangeWithArguments.visibleGridRange.cache.startRow; i <= visibleGridRangeWithArguments.visibleGridRange.cache.endRow; i++) {
|
|
230
|
+
rowNames.push(await editorService.name(i));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!isActive) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
cachedGridRangeWithRowNamesRef.current = {
|
|
237
|
+
range: visibleGridRangeWithArguments.visibleGridRange.cache,
|
|
238
|
+
rowNames,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!cachedGridRangeWithViewPortResultRef.current || !EditorUtil.isWithinGridRange({
|
|
243
|
+
cachedGridRange: cachedGridRangeWithViewPortResultRef.current.range,
|
|
244
|
+
visibleGridRange: visibleGridRangeWithArguments.visibleGridRange.visible,
|
|
245
|
+
})) {
|
|
246
|
+
const viewportResult = await EditorWorkerService.getInstance().viewport({
|
|
247
|
+
endCol: visibleGridRangeWithArguments.visibleGridRange.cache.endCol,
|
|
248
|
+
endRow: visibleGridRangeWithArguments.visibleGridRange.cache.endRow,
|
|
249
|
+
startCol: visibleGridRangeWithArguments.visibleGridRange.cache.startCol,
|
|
250
|
+
startRow: visibleGridRangeWithArguments.visibleGridRange.cache.startRow,
|
|
251
|
+
});
|
|
252
|
+
if (!isActive) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
cachedGridRangeWithViewPortResultRef.current = {
|
|
256
|
+
range: visibleGridRangeWithArguments.visibleGridRange.cache,
|
|
257
|
+
viewportResult,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (requestId !== visibleRangeRequestRef.current) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (animationFrame !== null) {
|
|
265
|
+
cancelAnimationFrame(animationFrame);
|
|
266
|
+
}
|
|
267
|
+
animationFrame = requestAnimationFrame(() => {
|
|
268
|
+
if (!isActive || requestId !== visibleRangeRequestRef.current) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (!canvasRef.current || !sequenceEditorStore.getState().nucleotidePalette || !cachedGridRangeWithViewPortResultRef.current || !metaSubject.data || !cachedGridRangeWithRowNamesRef.current) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
editorAssemblyRef.current = EditorUtil.drawCanvas({
|
|
275
|
+
canvasElement: canvasRef.current,
|
|
276
|
+
devicePixelRatio: DevicePixelRatioService.getInstance().data,
|
|
277
|
+
geometry: visibleGridRangeWithArguments.geometry,
|
|
278
|
+
meta: metaSubject.data,
|
|
279
|
+
palette: sequenceEditorStore.getState().nucleotidePalette,
|
|
280
|
+
rowNames: cachedGridRangeWithRowNamesRef.current.rowNames,
|
|
281
|
+
rowNamesStartRow: cachedGridRangeWithRowNamesRef.current.range.startRow,
|
|
282
|
+
scrollLeft: visibleGridRangeWithArguments.scrollLeft,
|
|
283
|
+
scrollTop: visibleGridRangeWithArguments.scrollTop,
|
|
284
|
+
searchResult,
|
|
285
|
+
searchResultHighlightedIndex,
|
|
286
|
+
selection: selectionSubject.data,
|
|
287
|
+
viewport: cachedGridRangeWithViewPortResultRef.current.viewportResult,
|
|
288
|
+
viewportHeight: visibleGridRangeWithArguments.viewportHeight,
|
|
289
|
+
viewportWidth: visibleGridRangeWithArguments.viewportWidth,
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
} finally {
|
|
294
|
+
processingVisibleRangeRef.current = false;
|
|
295
|
+
if (isActive && pendingVisibleRangeRef.current) {
|
|
296
|
+
void processVisibleRange();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const unsubscribeItems = [
|
|
302
|
+
sequenceEditorStore.subscribe((state, prevState) => {
|
|
303
|
+
let shouldProcess = false;
|
|
304
|
+
if (state.searchResult !== prevState.searchResult) {
|
|
305
|
+
searchResult = state.searchResult;
|
|
306
|
+
shouldProcess = true;
|
|
307
|
+
}
|
|
308
|
+
if (state.searchResultHighlightedIndex !== prevState.searchResultHighlightedIndex) {
|
|
309
|
+
searchResultHighlightedIndex = state.searchResultHighlightedIndex;
|
|
310
|
+
EditorUtil.scrollToSearchResult({
|
|
311
|
+
geometry: geometrySubject.data,
|
|
312
|
+
scrollContainer: scrollContainerRef.current,
|
|
313
|
+
searchResult: state.searchResult,
|
|
314
|
+
searchResultHighlightedIndex: state.searchResultHighlightedIndex,
|
|
315
|
+
});
|
|
316
|
+
shouldProcess = true;
|
|
317
|
+
}
|
|
318
|
+
if (shouldProcess) {
|
|
319
|
+
updateVisibleRange();
|
|
320
|
+
}
|
|
321
|
+
}),
|
|
322
|
+
visibleRangeSubject.subscribe((visibleGridRangeWithArguments) => {
|
|
323
|
+
if (!visibleGridRangeWithArguments) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
pendingVisibleRangeRef.current = visibleGridRangeWithArguments;
|
|
327
|
+
visibleRangeRequestRef.current += 1;
|
|
328
|
+
void processVisibleRange();
|
|
329
|
+
}),
|
|
330
|
+
];
|
|
331
|
+
return () => {
|
|
332
|
+
isActive = false;
|
|
333
|
+
pendingVisibleRangeRef.current = null;
|
|
334
|
+
if (animationFrame !== null) {
|
|
335
|
+
cancelAnimationFrame(animationFrame);
|
|
336
|
+
}
|
|
337
|
+
visibleRangeRequestRef.current += 1;
|
|
338
|
+
unsubscribeItems.forEach(unsubscribe => unsubscribe());
|
|
339
|
+
};
|
|
340
|
+
}, [editorService, geometrySubject, metaSubject, selectionSubject, updateVisibleRange, visibleRangeSubject]);
|
|
341
|
+
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
const unsubscribeItems = [
|
|
344
|
+
sequenceEditorStore.subscribe((state, prevState) => {
|
|
345
|
+
if (state.nucleotidePalette?.name !== prevState.nucleotidePalette?.name) {
|
|
346
|
+
updateVisibleRange();
|
|
347
|
+
}
|
|
348
|
+
}),
|
|
349
|
+
geometrySubject.subscribe(() => {
|
|
350
|
+
updateScrollbars();
|
|
351
|
+
updateVisibleRange();
|
|
352
|
+
}),
|
|
353
|
+
scrollSubject.subscribe(() => updateVisibleRange()),
|
|
354
|
+
metaSubject.subscribe((data) => {
|
|
355
|
+
if (data) {
|
|
356
|
+
updateScrollbars();
|
|
357
|
+
updateVisibleRange();
|
|
358
|
+
}
|
|
359
|
+
}),
|
|
360
|
+
selectionSubject.subscribe(() => updateVisibleRange()),
|
|
361
|
+
DevicePixelRatioService.getInstance().subscribe((nextDevicePixelRatio) => {
|
|
362
|
+
setDevicePixelRatio(nextDevicePixelRatio);
|
|
363
|
+
updateScrollbars();
|
|
364
|
+
updateVisibleRange();
|
|
365
|
+
}),
|
|
366
|
+
];
|
|
367
|
+
return () => {
|
|
368
|
+
unsubscribeItems.forEach(unsubscribe => unsubscribe());
|
|
369
|
+
};
|
|
370
|
+
}, [editorService, geometrySubject, metaSubject, scrollSubject, selectionSubject, updateScrollbars, updateVisibleRange]);
|
|
371
|
+
|
|
372
|
+
// Captures raw keyboard shortcuts and forwards them as bus events; business logic lives in the listener effect below.
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
const mutateSelection = (event: KeyboardEvent) => {
|
|
375
|
+
const base = event.key.toUpperCase();
|
|
376
|
+
if (!IUPAC_KEYS.has(base)) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
event.preventDefault();
|
|
380
|
+
SequenceEditorEventBusService.getInstance().emit('onMutateSelection', base);
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const register = (shortcut: typeof KEYBOARD_SHORTCUTS[string]) => KeyboardShortcutService.getInstance().registerShortcut({
|
|
384
|
+
callback: shortcut.callback,
|
|
385
|
+
element: containerRef.current!,
|
|
386
|
+
...shortcut.shortcut,
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const removers = [
|
|
390
|
+
// Expand selection with shift + arrow keys
|
|
391
|
+
register(KEYBOARD_SHORTCUTS.expandSelectionLeft),
|
|
392
|
+
register(KEYBOARD_SHORTCUTS.expandSelectionRight),
|
|
393
|
+
register(KEYBOARD_SHORTCUTS.expandSelectionUp),
|
|
394
|
+
register(KEYBOARD_SHORTCUTS.expandSelectionDown),
|
|
395
|
+
|
|
396
|
+
// Move selection box with arrow keys
|
|
397
|
+
register(KEYBOARD_SHORTCUTS.moveSelectionLeft),
|
|
398
|
+
register(KEYBOARD_SHORTCUTS.moveSelectionRight),
|
|
399
|
+
register(KEYBOARD_SHORTCUTS.moveSelectionUp),
|
|
400
|
+
register(KEYBOARD_SHORTCUTS.moveSelectionDown),
|
|
401
|
+
|
|
402
|
+
// Move rows vertically (one step)
|
|
403
|
+
register(KEYBOARD_SHORTCUTS.moveRowUp),
|
|
404
|
+
register(KEYBOARD_SHORTCUTS.moveRowDown),
|
|
405
|
+
// Move rows vertically (top / bottom)
|
|
406
|
+
register(KEYBOARD_SHORTCUTS.moveRowToStart),
|
|
407
|
+
register(KEYBOARD_SHORTCUTS.moveRowToEnd),
|
|
408
|
+
|
|
409
|
+
// Move cells horizontally
|
|
410
|
+
register(KEYBOARD_SHORTCUTS.moveCellLeft),
|
|
411
|
+
register(KEYBOARD_SHORTCUTS.moveCellRight),
|
|
412
|
+
|
|
413
|
+
register(KEYBOARD_SHORTCUTS.scrollToLineStart),
|
|
414
|
+
register(KEYBOARD_SHORTCUTS.scrollToLineEnd),
|
|
415
|
+
register(KEYBOARD_SHORTCUTS.scrollPageUp),
|
|
416
|
+
register(KEYBOARD_SHORTCUTS.scrollPageDown),
|
|
417
|
+
|
|
418
|
+
register(KEYBOARD_SHORTCUTS.insertGap),
|
|
419
|
+
register(KEYBOARD_SHORTCUTS.deleteBackward),
|
|
420
|
+
register(KEYBOARD_SHORTCUTS.deleteSelection),
|
|
421
|
+
register(KEYBOARD_SHORTCUTS.deleteBase),
|
|
422
|
+
|
|
423
|
+
// Undo (Cmd+Z / Ctrl+Z)
|
|
424
|
+
register(KEYBOARD_SHORTCUTS.undo),
|
|
425
|
+
// Redo (Cmd+Shift+Z / Ctrl+Shift+Z)
|
|
426
|
+
register(KEYBOARD_SHORTCUTS.redo),
|
|
427
|
+
|
|
428
|
+
// Goto Position Dialog (Cmd+G / Ctrl+G)
|
|
429
|
+
register(KEYBOARD_SHORTCUTS.gotoPosition),
|
|
430
|
+
|
|
431
|
+
KeyboardShortcutService.getInstance().registerShortcut({ callback: mutateSelection, element: containerRef.current! }),
|
|
432
|
+
KeyboardShortcutService.getInstance().registerShortcut({ callback: mutateSelection, element: containerRef.current!, modifiers: [['Shift']] }),
|
|
433
|
+
];
|
|
434
|
+
return () => {
|
|
435
|
+
removers.forEach(callbackfn => callbackfn());
|
|
436
|
+
};
|
|
437
|
+
}, []);
|
|
438
|
+
|
|
439
|
+
// Executes the editor actions for the keyboard shortcuts emitted via the event bus.
|
|
440
|
+
useEffect(() => {
|
|
441
|
+
const execute = async (args: { command: () => Promise<void>; getSelectionPostCommand?: () => EditorSelection | null }) => {
|
|
442
|
+
const { command, getSelectionPostCommand } = args;
|
|
443
|
+
try {
|
|
444
|
+
await command();
|
|
445
|
+
cachedGridRangeWithViewPortResultRef.current = null;
|
|
446
|
+
cachedGridRangeWithRowNamesRef.current = null;
|
|
447
|
+
await updateMeta();
|
|
448
|
+
updateVisibleRange();
|
|
449
|
+
if (getSelectionPostCommand) {
|
|
450
|
+
const selection = getSelectionPostCommand();
|
|
451
|
+
selectionSubject.next(selection);
|
|
452
|
+
initialSelectionRef.current = selection;
|
|
453
|
+
}
|
|
454
|
+
} catch (error) {
|
|
455
|
+
console.error('Failed to post command:', error);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
const mutate = async (base: string) => {
|
|
460
|
+
if (!metaSubject.data) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const mutateRangeArguments = EditorUtil.getMutateArguments(selectionSubject.data, metaSubject.data);
|
|
464
|
+
if (!mutateRangeArguments) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
await execute({
|
|
468
|
+
command: async () => {
|
|
469
|
+
for (let column = mutateRangeArguments.startCol; column <= mutateRangeArguments.endCol; column += 1) {
|
|
470
|
+
await editorService.mutate(mutateRangeArguments.rows, column, base);
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
const moveSelection = (direction: EDITOR_DIRECTION) => {
|
|
477
|
+
if (!metaSubject.data) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const newSelection = EditorUtil.getMovedSelection(selectionSubject.data, direction, metaSubject.data);
|
|
481
|
+
if (newSelection) {
|
|
482
|
+
selectionSubject.next(newSelection);
|
|
483
|
+
if (initialSelectionRef.current) {
|
|
484
|
+
const newInitialSelection = EditorUtil.getMovedSelection(initialSelectionRef.current, direction, metaSubject.data);
|
|
485
|
+
initialSelectionRef.current = newInitialSelection;
|
|
486
|
+
} else {
|
|
487
|
+
initialSelectionRef.current = newSelection;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const expandSelection = (direction: EDITOR_DIRECTION) => {
|
|
493
|
+
if (!metaSubject.data || !initialSelectionRef.current || !selectionSubject.data) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const newSelection = EditorUtil.getExpandedSelection(selectionSubject.data, initialSelectionRef.current, direction, metaSubject.data);
|
|
497
|
+
if (newSelection) {
|
|
498
|
+
selectionSubject.next(newSelection);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
const moveRowsEnd = async (_direction: EDITOR_DIRECTION) => {
|
|
503
|
+
// TODO
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
const moveRows = async (direction: EDITOR_DIRECTION) => {
|
|
507
|
+
if (!metaSubject.data) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
const rows = EditorUtil.getRowsToMove(selectionSubject.data, direction, metaSubject.data);
|
|
511
|
+
if (!rows) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
await execute({
|
|
515
|
+
command: async () => {
|
|
516
|
+
if (direction === EDITOR_DIRECTION.UP) {
|
|
517
|
+
await editorService.moveRowsUp(rows);
|
|
518
|
+
} else {
|
|
519
|
+
await editorService.moveRowsDown(rows);
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
getSelectionPostCommand: () => EditorUtil.getMovedSelection(selectionSubject.data, direction, metaSubject.data!),
|
|
523
|
+
});
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
const moveCells = async (_direction: EDITOR_DIRECTION) => {
|
|
527
|
+
// TODO
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
const eventBusService = SequenceEditorEventBusService.getInstance();
|
|
531
|
+
const removers = [
|
|
532
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
533
|
+
eventBusService.addEventListener('onSearch', async (searchQuery) => {
|
|
534
|
+
if (!searchQuery) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
const result = await editorService.search(searchQuery, false);
|
|
538
|
+
sequenceEditorStore.getState().setSearchResult(result);
|
|
539
|
+
}),
|
|
540
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
541
|
+
eventBusService.addEventListener('onExpandSelection', (direction) => expandSelection(direction)),
|
|
542
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
543
|
+
eventBusService.addEventListener('onGotoPosition', () => sequenceEditorGotoPositionDialogRef.current?.open({})),
|
|
544
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
545
|
+
eventBusService.addEventListener('onMoveSelection', (direction) => moveSelection(direction)),
|
|
546
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
547
|
+
eventBusService.addEventListener('onMoveRows', (direction) => {
|
|
548
|
+
void moveRows(direction);
|
|
549
|
+
}),
|
|
550
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
551
|
+
eventBusService.addEventListener('onMoveRowsEnd', (direction) => {
|
|
552
|
+
void moveRowsEnd(direction);
|
|
553
|
+
}),
|
|
554
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
555
|
+
eventBusService.addEventListener('onMoveCells', (direction) => {
|
|
556
|
+
void moveCells(direction);
|
|
557
|
+
}),
|
|
558
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
559
|
+
eventBusService.addEventListener('onScrollToLineStart', () => {
|
|
560
|
+
const scrollContainer = scrollContainerRef.current;
|
|
561
|
+
if (scrollContainer) {
|
|
562
|
+
scrollContainer.scrollLeft = 0;
|
|
563
|
+
}
|
|
564
|
+
}),
|
|
565
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
566
|
+
eventBusService.addEventListener('onScrollToLineEnd', () => {
|
|
567
|
+
const scrollContainer = scrollContainerRef.current;
|
|
568
|
+
if (scrollContainer) {
|
|
569
|
+
scrollContainer.scrollLeft = scrollContainer.scrollWidth - scrollContainer.clientWidth;
|
|
570
|
+
}
|
|
571
|
+
}),
|
|
572
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
573
|
+
eventBusService.addEventListener('onScrollPageUp', () => {
|
|
574
|
+
const scrollContainer = scrollContainerRef.current;
|
|
575
|
+
if (scrollContainer) {
|
|
576
|
+
scrollContainer.scrollTop = Math.max(0, scrollContainer.scrollTop - scrollContainer.clientHeight);
|
|
577
|
+
}
|
|
578
|
+
}),
|
|
579
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
580
|
+
eventBusService.addEventListener('onScrollPageDown', () => {
|
|
581
|
+
const scrollContainer = scrollContainerRef.current;
|
|
582
|
+
if (scrollContainer) {
|
|
583
|
+
scrollContainer.scrollTop = Math.min(
|
|
584
|
+
scrollContainer.scrollHeight - scrollContainer.clientHeight,
|
|
585
|
+
scrollContainer.scrollTop + scrollContainer.clientHeight,
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
}),
|
|
589
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
590
|
+
eventBusService.addEventListener('onInsert', () => {
|
|
591
|
+
void (async () => {
|
|
592
|
+
if (!metaSubject.data) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const upsertArguments = EditorUtil.getUpsertArguments(selectionSubject.data, metaSubject.data);
|
|
596
|
+
if (!upsertArguments) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
await execute({
|
|
600
|
+
command: async () => editorService.insert(upsertArguments.rows, upsertArguments.col),
|
|
601
|
+
getSelectionPostCommand: () => EditorUtil.getPostUpsertSelection(selectionSubject.data, EDITOR_DIRECTION.RIGHT),
|
|
602
|
+
});
|
|
603
|
+
})();
|
|
604
|
+
}),
|
|
605
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
606
|
+
eventBusService.addEventListener('onDeleteBackward', () => {
|
|
607
|
+
void (async () => {
|
|
608
|
+
if (!metaSubject.data) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
const upsertArguments = EditorUtil.getUpsertArguments(selectionSubject.data, metaSubject.data, -1);
|
|
612
|
+
if (!upsertArguments) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
await execute({
|
|
616
|
+
command: async () => editorService.delete(upsertArguments.rows, upsertArguments.col),
|
|
617
|
+
getSelectionPostCommand: () => EditorUtil.getPostUpsertSelection(selectionSubject.data, EDITOR_DIRECTION.LEFT),
|
|
618
|
+
});
|
|
619
|
+
})();
|
|
620
|
+
}),
|
|
621
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
622
|
+
eventBusService.addEventListener('onMutateSelection', (base) => {
|
|
623
|
+
void mutate(base);
|
|
624
|
+
}),
|
|
625
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
626
|
+
eventBusService.addEventListener('onUndo', () => {
|
|
627
|
+
void execute({
|
|
628
|
+
command: async () => editorService.undo(),
|
|
629
|
+
getSelectionPostCommand: () => null,
|
|
630
|
+
});
|
|
631
|
+
}),
|
|
632
|
+
// eslint-disable-next-line @eslint-react/web-api-no-leaked-event-listener
|
|
633
|
+
eventBusService.addEventListener('onRedo', () => {
|
|
634
|
+
void execute({
|
|
635
|
+
command: async () => editorService.redo(),
|
|
636
|
+
getSelectionPostCommand: () => null,
|
|
637
|
+
});
|
|
638
|
+
}),
|
|
639
|
+
];
|
|
640
|
+
return () => {
|
|
641
|
+
removers.forEach(remover => remover());
|
|
642
|
+
};
|
|
643
|
+
}, [editorService, selectionSubject, updateMeta, updateVisibleRange, metaSubject]);
|
|
644
|
+
|
|
645
|
+
useEffect(() => {
|
|
646
|
+
updateVisibleRange();
|
|
647
|
+
}, [updateVisibleRange]);
|
|
648
|
+
|
|
649
|
+
const onScrollContainerScroll = useCallback((event: UIEvent<HTMLDivElement>) => {
|
|
650
|
+
const target = event.currentTarget;
|
|
651
|
+
scrollSubject.next({
|
|
652
|
+
scrollLeft: target.scrollLeft,
|
|
653
|
+
scrollTop: target.scrollTop,
|
|
654
|
+
});
|
|
655
|
+
}, [scrollSubject]);
|
|
656
|
+
|
|
657
|
+
const onScrollContainerMouseDown = useCallback((event: ReactMouseEvent<HTMLElement>) => {
|
|
658
|
+
containerRef.current?.focus();
|
|
659
|
+
const scrollContainer = event.currentTarget;
|
|
660
|
+
|
|
661
|
+
// Determine if the mouse event occurred on the scrollbars (allow the user to maintain the selection while interacting with the scrollbars)
|
|
662
|
+
const scrollContainerRect = scrollContainer.getBoundingClientRect();
|
|
663
|
+
const isVerticalScrollbar = event.clientX >= scrollContainerRect.left + scrollContainer.clientWidth;
|
|
664
|
+
const isHorizontalScrollbar = event.clientY >= scrollContainerRect.top + scrollContainer.clientHeight;
|
|
665
|
+
if (isVerticalScrollbar || isHorizontalScrollbar) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const canvas = canvasRef.current;
|
|
670
|
+
const editorAssembly = editorAssemblyRef.current;
|
|
671
|
+
const currentDevicePixelRatio = DevicePixelRatioService.getInstance().data;
|
|
672
|
+
if (!canvas || !editorAssembly) {
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const path = EditorUtil.getPathPropertiesFromCanvas({
|
|
677
|
+
canvas,
|
|
678
|
+
devicePixelRatio: currentDevicePixelRatio,
|
|
679
|
+
editorAssembly,
|
|
680
|
+
event: event.nativeEvent,
|
|
681
|
+
});
|
|
682
|
+
if (!path) {
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
if (path.type !== EDITOR_PATH_PROPERTIES_TYPE.DIVIDER) {
|
|
686
|
+
if (path.type === EDITOR_PATH_PROPERTIES_TYPE.LABEL && (event.metaKey || event.ctrlKey)) {
|
|
687
|
+
const selectedRows = selectionSubject.data?.rows ?? [];
|
|
688
|
+
const nextSelectedRows = selectedRows.includes(path.row)
|
|
689
|
+
? selectedRows.filter(row => row !== path.row)
|
|
690
|
+
: [...selectedRows, path.row].sort((firstRow, secondRow) => firstRow - secondRow);
|
|
691
|
+
|
|
692
|
+
event.preventDefault();
|
|
693
|
+
selectionDragRef.current = null;
|
|
694
|
+
if (nextSelectedRows.length === 0) {
|
|
695
|
+
selectionSubject.next(null);
|
|
696
|
+
initialSelectionRef.current = null;
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
selectionSubject.next({
|
|
700
|
+
rows: nextSelectedRows,
|
|
701
|
+
});
|
|
702
|
+
initialSelectionRef.current = {
|
|
703
|
+
rows: nextSelectedRows,
|
|
704
|
+
};
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
const selection = EditorUtil.getSelectionFromPathProperties({
|
|
709
|
+
endPath: path,
|
|
710
|
+
startPath: path,
|
|
711
|
+
});
|
|
712
|
+
if (!selection) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
event.preventDefault();
|
|
716
|
+
selectionDragRef.current = path;
|
|
717
|
+
selectionSubject.next(selection);
|
|
718
|
+
initialSelectionRef.current = selection;
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
event.preventDefault();
|
|
723
|
+
selectionDragRef.current = null;
|
|
724
|
+
labelResizeRef.current = {
|
|
725
|
+
startLabelWidth: geometrySubject.data.labelWidth,
|
|
726
|
+
startX: event.clientX,
|
|
727
|
+
};
|
|
728
|
+
}, [geometrySubject, selectionSubject]);
|
|
729
|
+
|
|
730
|
+
const onScrollContainerMouseMove = useCallback((event: ReactMouseEvent<HTMLElement>) => {
|
|
731
|
+
const canvas = canvasRef.current;
|
|
732
|
+
const container = containerRef.current;
|
|
733
|
+
const currentDevicePixelRatio = DevicePixelRatioService.getInstance().data;
|
|
734
|
+
const resize = labelResizeRef.current;
|
|
735
|
+
if (!container || !canvas) {
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
if (resize) {
|
|
740
|
+
const labelWidth = Math.min(maxLabelWidth, Math.max(MIN_LABEL_WIDTH, resize.startLabelWidth + event.clientX - resize.startX));
|
|
741
|
+
geometrySubject.next({
|
|
742
|
+
...geometrySubject.data,
|
|
743
|
+
labelWidth,
|
|
744
|
+
});
|
|
745
|
+
container.style.cursor = 'col-resize';
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
const selectionStart = selectionDragRef.current;
|
|
750
|
+
if (selectionStart) {
|
|
751
|
+
const editorAssembly = editorAssemblyRef.current;
|
|
752
|
+
if (!editorAssembly) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
const path = EditorUtil.getPathPropertiesFromCanvas({
|
|
757
|
+
canvas,
|
|
758
|
+
devicePixelRatio: currentDevicePixelRatio,
|
|
759
|
+
editorAssembly,
|
|
760
|
+
event: event.nativeEvent,
|
|
761
|
+
});
|
|
762
|
+
if (!path) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const selection = EditorUtil.getSelectionFromPathProperties({
|
|
767
|
+
endPath: path,
|
|
768
|
+
startPath: selectionStart,
|
|
769
|
+
});
|
|
770
|
+
if (selection) {
|
|
771
|
+
selectionSubject.next(selection);
|
|
772
|
+
initialSelectionRef.current = selection;
|
|
773
|
+
}
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
const editorAssembly = editorAssemblyRef.current;
|
|
778
|
+
if (!editorAssembly) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const path = EditorUtil.getPathPropertiesFromCanvas({
|
|
783
|
+
canvas,
|
|
784
|
+
devicePixelRatio: currentDevicePixelRatio,
|
|
785
|
+
editorAssembly,
|
|
786
|
+
event: event.nativeEvent,
|
|
787
|
+
});
|
|
788
|
+
if (!path) {
|
|
789
|
+
container.style.cursor = 'default';
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
if (path.type === EDITOR_PATH_PROPERTIES_TYPE.DIVIDER) {
|
|
794
|
+
container.style.cursor = 'col-resize';
|
|
795
|
+
} else {
|
|
796
|
+
container.style.cursor = 'default';
|
|
797
|
+
}
|
|
798
|
+
}, [geometrySubject, maxLabelWidth, selectionSubject]);
|
|
799
|
+
|
|
800
|
+
const onContainerMouseUp = useCallback(() => {
|
|
801
|
+
labelResizeRef.current = null;
|
|
802
|
+
selectionDragRef.current = null;
|
|
803
|
+
}, []);
|
|
804
|
+
|
|
805
|
+
const onGotoPosition = useCallback((x: null | number, y: null | number) => {
|
|
806
|
+
EditorUtil.scrollToPosition({
|
|
807
|
+
geometry: geometrySubject.data,
|
|
808
|
+
scrollContainer: scrollContainerRef.current,
|
|
809
|
+
x,
|
|
810
|
+
y,
|
|
811
|
+
});
|
|
812
|
+
}, [geometrySubject]);
|
|
813
|
+
|
|
814
|
+
const canvasWidth = Math.max(1, Math.floor(containerDimensions.width * devicePixelRatio));
|
|
815
|
+
const canvasHeight = Math.max(1, Math.floor(containerDimensions.height * devicePixelRatio));
|
|
816
|
+
|
|
817
|
+
return (
|
|
818
|
+
<Box
|
|
819
|
+
sx={{
|
|
820
|
+
display: 'grid',
|
|
821
|
+
gridTemplateRows: 'max-content auto',
|
|
822
|
+
height: '100%',
|
|
823
|
+
position: 'relative',
|
|
824
|
+
width: '100%',
|
|
825
|
+
}}
|
|
826
|
+
>
|
|
827
|
+
<SequenceEditorSearchBar />
|
|
828
|
+
<Box
|
|
829
|
+
onMouseUp={onContainerMouseUp}
|
|
830
|
+
ref={containerRef}
|
|
831
|
+
sx={{
|
|
832
|
+
height: `calc(100% - ${theme.spacing(3)})`,
|
|
833
|
+
marginBottom: theme.spacing(3),
|
|
834
|
+
position: 'relative',
|
|
835
|
+
width: '100%',
|
|
836
|
+
}}
|
|
837
|
+
tabIndex={0}
|
|
838
|
+
>
|
|
839
|
+
<Box
|
|
840
|
+
onMouseDown={onScrollContainerMouseDown}
|
|
841
|
+
onMouseMove={onScrollContainerMouseMove}
|
|
842
|
+
onScroll={onScrollContainerScroll}
|
|
843
|
+
ref={scrollContainerRef}
|
|
844
|
+
sx={{
|
|
845
|
+
height: '100%',
|
|
846
|
+
overflowX: 'scroll',
|
|
847
|
+
overflowY: 'scroll',
|
|
848
|
+
position: 'absolute',
|
|
849
|
+
width: '100%',
|
|
850
|
+
zIndex: 1,
|
|
851
|
+
}}
|
|
852
|
+
>
|
|
853
|
+
<Box
|
|
854
|
+
sx={{
|
|
855
|
+
height: `${Math.max(verticalScrollBarSize, containerDimensions.height)}px`,
|
|
856
|
+
pointerEvents: 'none',
|
|
857
|
+
width: `${Math.max(horizontalScrollBarSize, containerDimensions.width)}px`,
|
|
858
|
+
}}
|
|
859
|
+
/>
|
|
860
|
+
</Box>
|
|
861
|
+
<canvas
|
|
862
|
+
height={canvasHeight}
|
|
863
|
+
ref={canvasRef}
|
|
864
|
+
style={{
|
|
865
|
+
display: 'block',
|
|
866
|
+
height: `${containerDimensions.height}px`,
|
|
867
|
+
imageRendering: 'pixelated',
|
|
868
|
+
left: 0,
|
|
869
|
+
pointerEvents: 'auto',
|
|
870
|
+
position: 'absolute',
|
|
871
|
+
top: 0,
|
|
872
|
+
width: `${containerDimensions.width}px`,
|
|
873
|
+
zIndex: 0,
|
|
874
|
+
}}
|
|
875
|
+
width={canvasWidth}
|
|
876
|
+
/>
|
|
877
|
+
<Box
|
|
878
|
+
sx={{
|
|
879
|
+
bottom: theme.spacing(-3),
|
|
880
|
+
height: theme.spacing(3),
|
|
881
|
+
left: 0,
|
|
882
|
+
position: 'absolute',
|
|
883
|
+
width: '100%',
|
|
884
|
+
zIndex: 2,
|
|
885
|
+
}}
|
|
886
|
+
>
|
|
887
|
+
<SequenceEditorStatusBar />
|
|
888
|
+
</Box>
|
|
889
|
+
</Box>
|
|
890
|
+
<SequenceEditorGotoPositionDialog
|
|
891
|
+
onGotoPosition={onGotoPosition}
|
|
892
|
+
ref={sequenceEditorGotoPositionDialogRef}
|
|
893
|
+
/>
|
|
894
|
+
</Box>
|
|
895
|
+
);
|
|
896
|
+
};
|