Skip to content

Commit 2ff4762

Browse files
authored
Extract anchor component (#1128)
1 parent 6704d32 commit 2ff4762

File tree

13 files changed

+38
-22
lines changed

13 files changed

+38
-22
lines changed

web_ui/packages/smart-tools/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,4 @@ export { type GrabcutData } from './src/grabcut/interfaces';
1414

1515
export { buildIntelligentScissorsInstance, IntelligentScissors } from './src/intelligent-scissors/intelligent-scissors';
1616

17-
export {
18-
buildSegmentAnythingInstance,
19-
SegmentAnythingModelWrapper,
20-
} from './src/segment-anything/segment-anything-wrapper';
21-
export { SegmentAnythingModel } from './src/segment-anything/segment-anything';
22-
export type { EncodingOutput } from './src/segment-anything/segment-anything-encoder';
17+
export { Anchor } from './src/edit-bounding-box/anchor.component';

web_ui/packages/smart-tools/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"./opencv": "./src/opencv/interfaces/index.d.ts",
3131
"./utils": "./src/utils/index.ts",
3232
"./types": "./src/shared/index.ts",
33-
"./ritm": "./src/ritm/index.ts"
33+
"./ritm": "./src/ritm/index.ts",
34+
"./segment-anything": "./src/segment-anything/index.ts"
3435
},
3536
"scripts": {
3637
"type-check": "tsc --noEmit -p tsconfig.json",

web_ui/src/pages/annotator/tools/edit-tool/anchor.component.tsx renamed to web_ui/packages/smart-tools/src/edit-bounding-box/anchor.component.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ import { CSSProperties, PointerEvent, ReactNode, useState } from 'react';
55

66
import { isFunction } from 'lodash-es';
77

8-
import { Point } from '../../../../core/annotations/shapes.interface';
9-
import { isLeftButton } from '../../../buttons-utils';
10-
import { PointerType } from '../tools.interface';
8+
import { Point } from '../shared/interfaces';
9+
10+
interface MouseButton {
11+
button: number;
12+
buttons: number;
13+
}
14+
15+
const BUTTON_LEFT = {
16+
button: 0,
17+
buttons: 1,
18+
};
19+
const isLeftButton = (button: MouseButton): boolean => {
20+
return button.button === BUTTON_LEFT.button || button.buttons === BUTTON_LEFT.buttons;
21+
};
1122

1223
interface AnchorProps {
1324
children: ReactNode;
@@ -41,7 +52,7 @@ export const Anchor = ({
4152
const onPointerDown = (event: PointerEvent) => {
4253
event.preventDefault();
4354

44-
if (event.pointerType === PointerType.Touch || !isLeftButton(event)) {
55+
if (event.pointerType === 'touch' || !isLeftButton(event)) {
4556
return;
4657
}
4758

@@ -66,7 +77,7 @@ export const Anchor = ({
6677
};
6778

6879
const onPointerUp = (event: PointerEvent) => {
69-
if (event.pointerType === PointerType.Touch || !isLeftButton(event)) {
80+
if (event.pointerType === 'touch' || !isLeftButton(event)) {
7081
return;
7182
}
7283

web_ui/src/pages/annotator/tools/edit-tool/anchor.test.tsx renamed to web_ui/packages/smart-tools/src/edit-bounding-box/anchor.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('anchor', (): void => {
3232
const anchorActor = screen.getByLabelText(properties.label);
3333
fireEvent.pointerDown(anchorActor);
3434
fireEvent.pointerMove(anchorActor, { clientX: 10, clientY: 10 });
35-
expect(moveAnchorCallback).toBeCalledTimes(1);
35+
expect(moveAnchorCallback).toHaveBeenCalledTimes(1);
3636
});
3737

3838
it('calls onComplete when clicked and released', () => {
@@ -48,6 +48,6 @@ describe('anchor', (): void => {
4848
fireEvent.pointerDown(anchorActor);
4949
fireEvent.pointerMove(anchorActor, { clientX: 10, clientY: 10 });
5050
fireEvent.pointerUp(anchorActor);
51-
expect(onCompleteCallback).toBeCalledTimes(1);
51+
expect(onCompleteCallback).toHaveBeenCalledTimes(1);
5252
});
5353
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (C) 2022-2025 Intel Corporation
2+
// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
3+
4+
export { buildSegmentAnythingInstance, SegmentAnythingModelWrapper } from './segment-anything-wrapper';
5+
export { SegmentAnythingModel } from './segment-anything';
6+
export type { EncodingOutput } from './segment-anything-encoder';

web_ui/src/hooks/use-load-ai-webworker/load-webworker.interface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (C) 2022-2025 Intel Corporation
22
// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
33

4-
import { Grabcut, InferenceImage, IntelligentScissors, SegmentAnythingModel, SSIM, Watershed } from '@geti/smart-tools';
4+
import { Grabcut, InferenceImage, IntelligentScissors, SSIM, Watershed } from '@geti/smart-tools';
55
import { RITM } from '@geti/smart-tools/ritm';
6+
import { SegmentAnythingModel } from '@geti/smart-tools/segment-anything';
67
import { Remote } from 'comlink';
78

89
import { AlgorithmType } from './algorithm.interface';

web_ui/src/pages/annotator/tools/edit-tool/edit-keypoint/rotation-anchor.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright (C) 2022-2025 Intel Corporation
22
// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
33

4+
import { Anchor } from '@geti/smart-tools';
45
import { radiansToDegrees, Vec2 } from '@geti/smart-tools/utils';
56
import { Rotation } from '@geti/ui/icons';
67
import { clsx } from 'clsx';
78

89
import { Point } from '../../../../../core/annotations/shapes.interface';
9-
import { Anchor } from '../anchor.component';
1010

1111
import styles from './rotation-anchor.module.scss';
1212

web_ui/src/pages/annotator/tools/edit-tool/edit-rotated-bounding-box/rotation-element/rotation-anchor.component.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
import { CSSProperties } from 'react';
55

6+
import { Anchor } from '@geti/smart-tools';
67
import { Rotation } from '@geti/ui/icons';
78

8-
import { Anchor } from '../../anchor.component';
9-
109
interface RotationAnchorProps {
1110
zoom: number;
1211
x: number;

web_ui/src/pages/annotator/tools/edit-tool/resize-anchor.component.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import { CSSProperties, ReactNode } from 'react';
55

6-
import { Anchor as InternalAnchor } from './anchor.component';
6+
import { Anchor as InternalAnchor } from '@geti/smart-tools';
7+
78
import { ResizeAnchorType } from './resize-anchor.enum';
89

910
export const ANCHOR_SIZE = 8;

web_ui/src/pages/annotator/tools/segment-anything-tool/segment-anything-state-provider.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { createContext, useContext, useEffect } from 'react';
55

6-
import { EncodingOutput } from '@geti/smart-tools';
6+
import { EncodingOutput } from '@geti/smart-tools/segment-anything';
77
import { useQueryClient, UseQueryResult } from '@tanstack/react-query';
88
import { isEmpty } from 'lodash-es';
99

0 commit comments

Comments
 (0)