/
alt3rmann
/
label-studio
Обзор
Документация
Войти
/
alt3rmann
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
web/libs/editor/src/tools/Selection.js
90 строк
2 KB
Yousif Yassi
chore: OPTIC-1778: Unify and prettify icons (#7169)
21 мар 2025, 17:21
Не верифицирован
21 мар 2025, 17:21
b75cace
Код
Авторство
О чём код?
import { observer } from "mobx-react"; import { types } from "mobx-state-tree"; import { IconMoveTool } from "@humansignal/icons"; import { Tool } from "../components/Toolbar/Tool"; import { AnnotationMixin } from "../mixins/AnnotationMixin"; import ToolMixin from "../mixins/Tool"; import { FF_LSDV_4930, isFF } from "../utils/feature-flags"; import BaseTool from "./Base"; const ToolView = observer(({ item }) => { return ( <Tool ariaLabel="move-tool" active={item.selected} icon={<IconMoveTool />} label="Move" shortcut={item.shortcut} extraShortcuts={item.extraShortcuts} onClick={() => { item.manager.selectTool(item, !item.selected); }} /> ); }); const _Tool = types .model("SelectionTool", { shortcut: "V", group: "control", }) .views((self) => { return { get viewClass() { return () => <ToolView item={self} />; }, get useTransformer() { return true; }, }; }) .actions((self) => { let isSelecting = false; return { /** * Indicates that move tool always interacts with regions */ shouldSkipInteractions() { return false; }, mousedownEv(ev, [x, y]) { isSelecting = true; self.obj.setSelectionStart({ x, y }); }, mousemoveEv(ev, [x, y]) { if (!isSelecting) return; self.obj.setSelectionEnd({ x, y }); }, mouseupEv(ev, [x, y]) { if (!isSelecting) return; self.obj.setSelectionEnd({ x, y }); const { regionsInSelectionArea } = self.obj; self.obj.resetSelection(); if (ev.ctrlKey || ev.metaKey) { self.annotation.extendSelectionWith(regionsInSelectionArea); } else { self.annotation.selectAreas(regionsInSelectionArea); } isSelecting = false; }, clickEv(ev) { if (isFF(FF_LSDV_4930)) { isSelecting = false; self.obj.resetSelection(); if (!ev.ctrlKey && !ev.metaKey) { self.annotation.unselectAreas(); } } }, }; }); const Selection = types.compose("MoveTool", ToolMixin, BaseTool, AnnotationMixin, _Tool); export { Selection };