box-annotations 5.2.1-beta.2 → 5.2.1-beta.20
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/dist/annotations.css +3 -4
- package/dist/annotations.js +1 -1
- package/dist/annotations.js.LICENSE.txt +3 -43
- package/i18n/en-US.js +4 -0
- package/i18n/en-US.properties +8 -0
- package/i18n/json/src/components/BoundingBoxHighlight/messages.json +1 -0
- package/i18n/json/src/components/Popups/messages.json +1 -1
- package/index.js +1 -1
- package/package.json +33 -15
- package/src/@types/api.ts +3 -2
- package/src/@types/events.ts +28 -7
- package/src/@types/global.ts +0 -9
- package/src/@types/model.ts +14 -0
- package/src/BoxAnnotations.ts +4 -1
- package/src/adapters/threadedAnnotationsAdapters.ts +164 -0
- package/src/api/APIFactory.ts +6 -1
- package/src/api/types.ts +50 -1
- package/src/boundingBoxHighlight/BoundingBoxHighlightContainer.tsx +33 -0
- package/src/boundingBoxHighlight/BoundingBoxHighlightManager.tsx +19 -0
- package/src/boundingBoxHighlight/index.ts +1 -0
- package/src/common/AnnotationCallbacksContext.ts +7 -0
- package/src/common/BaseAnnotator.scss +14 -1
- package/src/common/BaseAnnotator.ts +161 -14
- package/src/common/BaseManager.ts +2 -0
- package/src/common/DeselectListener.tsx +3 -1
- package/src/common/withProviders.tsx +6 -2
- package/src/components/BoundingBoxHighlight/BoundingBoxHighlightList.scss +8 -0
- package/src/components/BoundingBoxHighlight/BoundingBoxHighlightList.tsx +67 -0
- package/src/components/BoundingBoxHighlight/BoundingBoxHighlightNav.scss +73 -0
- package/src/components/BoundingBoxHighlight/BoundingBoxHighlightNav.tsx +68 -0
- package/src/components/BoundingBoxHighlight/BoundingBoxHighlightRect.scss +22 -0
- package/src/components/BoundingBoxHighlight/BoundingBoxHighlightRect.tsx +77 -0
- package/src/components/BoundingBoxHighlight/index.ts +4 -0
- package/src/components/BoundingBoxHighlight/messages.ts +14 -0
- package/src/components/Popups/PopupDrawingToolbar.tsx +0 -7
- package/src/components/Popups/PopupReply.tsx +8 -28
- package/src/components/Popups/PopupV2.scss +28 -0
- package/src/components/Popups/PopupV2.tsx +382 -0
- package/src/components/Popups/messages.ts +10 -0
- package/src/document/DocumentAnnotator.ts +79 -10
- package/src/document/docUtil.ts +2 -1
- package/src/drawing/DrawingAnnotations.tsx +23 -14
- package/src/drawing/DrawingAnnotationsContainer.tsx +3 -0
- package/src/drawing/DrawingCreator.tsx +9 -16
- package/src/drawing/DrawingManager.tsx +13 -2
- package/src/drawing/DrawingTarget.tsx +1 -0
- package/src/highlight/HighlightAnnotations.tsx +27 -14
- package/src/highlight/HighlightContainer.tsx +3 -0
- package/src/highlight/HighlightCreatorManager.ts +8 -5
- package/src/highlight/HighlightListener.ts +4 -2
- package/src/highlight/HighlightManager.tsx +13 -2
- package/src/highlight/HighlightTarget.tsx +1 -0
- package/src/icons/ChevronLeft.tsx +24 -0
- package/src/icons/ChevronRight.tsx +24 -0
- package/src/image/ImageAnnotator.ts +50 -3
- package/src/media/MediaAnnotator.ts +2 -1
- package/src/popup/PopupContainer.tsx +11 -1
- package/src/popup/PopupLayer.tsx +97 -22
- package/src/popup/PopupManager.tsx +24 -4
- package/src/region/RegionAnnotation.tsx +1 -0
- package/src/region/RegionCreation.tsx +4 -7
- package/src/region/RegionCreationContainer.tsx +2 -2
- package/src/region/RegionCreator.tsx +9 -17
- package/src/store/annotations/actions.ts +167 -3
- package/src/store/annotations/reducer.ts +71 -1
- package/src/store/boundingBoxHighlights/actions.ts +6 -0
- package/src/store/boundingBoxHighlights/index.ts +4 -0
- package/src/store/boundingBoxHighlights/reducer.ts +33 -0
- package/src/store/boundingBoxHighlights/selectors.ts +12 -0
- package/src/store/boundingBoxHighlights/types.ts +13 -0
- package/src/store/createRootReducer.ts +2 -0
- package/src/store/eventing/boundingBoxHighlightNav.ts +13 -0
- package/src/store/eventing/create.ts +3 -3
- package/src/store/eventing/delete.ts +27 -0
- package/src/store/eventing/middleware.ts +42 -3
- package/src/store/eventing/replyCreate.ts +34 -0
- package/src/store/eventing/replyDelete.ts +35 -0
- package/src/store/eventing/replyUpdate.ts +39 -0
- package/src/store/eventing/types.ts +4 -4
- package/src/store/eventing/update.ts +29 -0
- package/src/store/highlight/actions.ts +32 -3
- package/src/store/highlight/types.ts +1 -0
- package/src/store/index.ts +1 -0
- package/src/store/options/actions.ts +2 -0
- package/src/store/options/reducer.ts +9 -2
- package/src/store/options/selectors.ts +5 -1
- package/src/store/options/types.ts +7 -1
- package/src/store/types.ts +2 -0
- package/src/utils/rotate.ts +43 -0
- package/src/utils/scroll.ts +8 -3
- package/src/components/Popups/PopupReplyV2.tsx +0 -10
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import eventManager from '../../common/EventManager';
|
|
2
|
+
import { Annotation , Event } from '../../@types';
|
|
3
|
+
import { AppState } from '../types';
|
|
4
|
+
import { AsyncAction, Status } from './types';
|
|
5
|
+
|
|
6
|
+
type UpdateArg = { annotationId: string; payload: { message?: string; status?: string } };
|
|
7
|
+
|
|
8
|
+
const emitUpdateEvent = (action: AsyncAction<UpdateArg, Annotation>, status: Status): void => {
|
|
9
|
+
const { error, meta: { arg, requestId } = {}, payload } = action;
|
|
10
|
+
if (status === Status.SUCCESS && !payload) return;
|
|
11
|
+
const annotation = payload ?? (arg ? { id: arg.annotationId } : undefined);
|
|
12
|
+
eventManager.emit(Event.ANNOTATION_UPDATE, {
|
|
13
|
+
annotation,
|
|
14
|
+
error,
|
|
15
|
+
meta: { requestId, status },
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const updateHandler = (status: Status) => (
|
|
20
|
+
_prev: AppState,
|
|
21
|
+
_next: AppState,
|
|
22
|
+
action: AsyncAction,
|
|
23
|
+
): void => emitUpdateEvent(action as AsyncAction<UpdateArg, Annotation>, status);
|
|
24
|
+
|
|
25
|
+
const handleUpdateErrorEvents = updateHandler(Status.ERROR);
|
|
26
|
+
const handleUpdatePendingEvents = updateHandler(Status.PENDING);
|
|
27
|
+
const handleUpdateSuccessEvents = updateHandler(Status.SUCCESS);
|
|
28
|
+
|
|
29
|
+
export { handleUpdateErrorEvents, handleUpdatePendingEvents, handleUpdateSuccessEvents };
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { createAction } from '@reduxjs/toolkit';
|
|
2
|
-
import { combineRects } from '../../highlight/highlightUtil';
|
|
2
|
+
import { combineRects, getBoundingRect } from '../../highlight/highlightUtil';
|
|
3
|
+
import { getElementLocalPosition } from '../../utils/rotate';
|
|
3
4
|
import { SelectionItem } from './types';
|
|
4
5
|
import { Shape } from '../../@types';
|
|
5
6
|
|
|
6
7
|
export type SelectionArg = {
|
|
8
|
+
containerEl?: HTMLElement | null;
|
|
7
9
|
containerRect: DOMRect;
|
|
8
10
|
hasError?: boolean;
|
|
9
11
|
location: number;
|
|
10
12
|
range: Range;
|
|
13
|
+
rotation?: number;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
type Payload = {
|
|
@@ -83,7 +86,7 @@ export const setSelectionAction = createAction(
|
|
|
83
86
|
};
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
const { containerRect, hasError, location, range } = arg;
|
|
89
|
+
const { containerEl, containerRect, hasError, location, range, rotation } = arg;
|
|
87
90
|
|
|
88
91
|
let rects = Array.from(range.getClientRects());
|
|
89
92
|
// getClientRects on IE/Edge might return 0 rects
|
|
@@ -91,12 +94,38 @@ export const setSelectionAction = createAction(
|
|
|
91
94
|
rects = getClientRects(range);
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
const screenShapes = rects.map(getShape);
|
|
98
|
+
|
|
99
|
+
if (rotation && containerEl) {
|
|
100
|
+
// Convert screen rects to element-local coordinates
|
|
101
|
+
const localRects = screenShapes.map(shape => {
|
|
102
|
+
const [lx1, ly1] = getElementLocalPosition(shape.x, shape.y, containerEl, rotation);
|
|
103
|
+
const [lx2, ly2] = getElementLocalPosition(shape.x + shape.width, shape.y + shape.height, containerEl, rotation);
|
|
104
|
+
return {
|
|
105
|
+
x: Math.min(lx1, lx2),
|
|
106
|
+
y: Math.min(ly1, ly2),
|
|
107
|
+
width: Math.abs(lx2 - lx1),
|
|
108
|
+
height: Math.abs(ly2 - ly1),
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
payload: {
|
|
114
|
+
containerRect: { x: 0, y: 0, width: containerEl.offsetWidth, height: containerEl.offsetHeight },
|
|
115
|
+
hasError,
|
|
116
|
+
location,
|
|
117
|
+
popupRect: getBoundingRect(screenShapes),
|
|
118
|
+
rects: combineRects(localRects),
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
94
123
|
return {
|
|
95
124
|
payload: {
|
|
96
125
|
containerRect: getShape(containerRect),
|
|
97
126
|
hasError,
|
|
98
127
|
location,
|
|
99
|
-
rects: combineRects(
|
|
128
|
+
rects: combineRects(screenShapes),
|
|
100
129
|
},
|
|
101
130
|
};
|
|
102
131
|
},
|
package/src/store/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createAction } from '@reduxjs/toolkit';
|
|
2
2
|
import { Permissions } from '../../@types';
|
|
3
|
+
import { ViewMode } from './types';
|
|
3
4
|
|
|
4
5
|
export const setFileIdAction = createAction<string | null>('SET_FIlE_ID');
|
|
5
6
|
export const setFileVersionIdAction = createAction<string | null>('SET_FILE_VERSION_ID');
|
|
6
7
|
export const setPermissionsAction = createAction<Permissions>('SET_PERMISSIONS');
|
|
7
8
|
export const setRotationAction = createAction<number>('SET_ROTATION');
|
|
8
9
|
export const setScaleAction = createAction<number>('SET_SCALE');
|
|
10
|
+
export const setViewModeAction = createAction<ViewMode>('SET_VIEW_MODE');
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { createReducer } from '@reduxjs/toolkit';
|
|
2
|
-
import { OptionsState } from './types';
|
|
2
|
+
import { OptionsState, ViewMode } from './types';
|
|
3
3
|
import {
|
|
4
4
|
setFileIdAction,
|
|
5
5
|
setFileVersionIdAction,
|
|
6
6
|
setPermissionsAction,
|
|
7
7
|
setRotationAction,
|
|
8
8
|
setScaleAction,
|
|
9
|
+
setViewModeAction,
|
|
9
10
|
} from './actions';
|
|
10
11
|
|
|
11
|
-
export const initialState = {
|
|
12
|
+
export const initialState: OptionsState = {
|
|
13
|
+
apiHost: '',
|
|
12
14
|
features: {},
|
|
13
15
|
fileId: null,
|
|
14
16
|
fileVersionId: null,
|
|
@@ -16,6 +18,8 @@ export const initialState = {
|
|
|
16
18
|
permissions: {},
|
|
17
19
|
rotation: 0,
|
|
18
20
|
scale: 1,
|
|
21
|
+
token: '',
|
|
22
|
+
viewMode: 'annotations' as ViewMode,
|
|
19
23
|
};
|
|
20
24
|
|
|
21
25
|
export default createReducer<OptionsState>(initialState, builder =>
|
|
@@ -34,5 +38,8 @@ export default createReducer<OptionsState>(initialState, builder =>
|
|
|
34
38
|
})
|
|
35
39
|
.addCase(setScaleAction, (state, { payload }) => {
|
|
36
40
|
state.scale = payload;
|
|
41
|
+
})
|
|
42
|
+
.addCase(setViewModeAction, (state, { payload }) => {
|
|
43
|
+
state.viewMode = payload;
|
|
37
44
|
}),
|
|
38
45
|
);
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import getProp from 'lodash/get';
|
|
2
2
|
import { AppState } from '../types';
|
|
3
|
-
import { Permissions } from '../../@types';
|
|
3
|
+
import { Permissions, Token } from '../../@types';
|
|
4
4
|
import { Features } from '../../BoxAnnotations';
|
|
5
|
+
import { ViewMode } from './types';
|
|
5
6
|
|
|
6
7
|
type State = Pick<AppState, 'options'>;
|
|
7
8
|
|
|
9
|
+
export const getApiHost = (state: State): string => state.options.apiHost;
|
|
8
10
|
export const getFeatures = (state: State): Features => state.options.features;
|
|
11
|
+
export const getViewMode = (state: State): ViewMode => state.options.viewMode;
|
|
9
12
|
export const getFileId = (state: State): string | null => state.options.fileId;
|
|
10
13
|
export const getFileVersionId = (state: State): string | null => state.options.fileVersionId;
|
|
11
14
|
export const getIsCurrentFileVersion = (state: State): boolean => state.options.isCurrentFileVersion;
|
|
12
15
|
export const getPermissions = (state: State): Permissions => state.options.permissions;
|
|
13
16
|
export const getRotation = (state: State): number => state.options.rotation;
|
|
14
17
|
export const getScale = (state: State): number => state.options.scale;
|
|
18
|
+
export const getToken = (state: State): Token => state.options.token;
|
|
15
19
|
export const isFeatureEnabled = (state: State, featurename: string): boolean =>
|
|
16
20
|
getProp(getFeatures(state), featurename, false);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Features } from '../../BoxAnnotations';
|
|
2
|
-
import { Permissions } from '../../@types';
|
|
2
|
+
import { Permissions, Token } from '../../@types';
|
|
3
|
+
|
|
4
|
+
/** View mode: annotations and bounding boxes are mutually exclusive. */
|
|
5
|
+
export type ViewMode = 'annotations' | 'boundingBoxes';
|
|
3
6
|
|
|
4
7
|
export type OptionsState = {
|
|
8
|
+
apiHost: string;
|
|
5
9
|
features: Features;
|
|
6
10
|
fileId: string | null;
|
|
7
11
|
fileVersionId: string | null;
|
|
@@ -9,4 +13,6 @@ export type OptionsState = {
|
|
|
9
13
|
permissions: Permissions;
|
|
10
14
|
rotation: number;
|
|
11
15
|
scale: number;
|
|
16
|
+
token: Token;
|
|
17
|
+
viewMode: ViewMode;
|
|
12
18
|
};
|
package/src/store/types.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { CommonState } from './common';
|
|
|
6
6
|
import { CreatorState } from './creator';
|
|
7
7
|
import { DrawingState } from './drawing';
|
|
8
8
|
import { HighlightState } from './highlight';
|
|
9
|
+
import { BoundingBoxHighlightsState } from './boundingBoxHighlights';
|
|
9
10
|
import { OptionsState } from './options';
|
|
10
11
|
import { UsersState } from './users';
|
|
11
12
|
|
|
@@ -15,6 +16,7 @@ export type AppState = {
|
|
|
15
16
|
creator: CreatorState;
|
|
16
17
|
drawing: DrawingState;
|
|
17
18
|
highlight: HighlightState;
|
|
19
|
+
boundingBoxHighlights: BoundingBoxHighlightsState;
|
|
18
20
|
options: OptionsState;
|
|
19
21
|
users: UsersState;
|
|
20
22
|
};
|
package/src/utils/rotate.ts
CHANGED
|
@@ -129,3 +129,46 @@ export function getRotatedPosition({ x, y }: Position, rotation: number): Positi
|
|
|
129
129
|
const { x: rotatedX, y: rotatedY } = getRotatedShape({ height: 0, width: 0, x, y }, rotation);
|
|
130
130
|
return { x: rotatedX, y: rotatedY };
|
|
131
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Converts a mouse position (in browser window coordinates) to a position relative to
|
|
135
|
+
* a CSS-rotated element's own top-left corner.
|
|
136
|
+
*
|
|
137
|
+
* When an element has a CSS rotation, its internal axes are rotated with it.
|
|
138
|
+
* This function maps window coordinates to element-local coordinates.
|
|
139
|
+
*
|
|
140
|
+
* If element is null, returns the raw coordinates as a passthrough.
|
|
141
|
+
*
|
|
142
|
+
* Assumes transform-origin: center (the CSS default), which matches how
|
|
143
|
+
* box-content-preview applies rotation to annotation layers.
|
|
144
|
+
*/
|
|
145
|
+
export function getElementLocalPosition(
|
|
146
|
+
clientX: number,
|
|
147
|
+
clientY: number,
|
|
148
|
+
element: HTMLElement | null,
|
|
149
|
+
rotation: number,
|
|
150
|
+
): [number, number] {
|
|
151
|
+
if (!element) {
|
|
152
|
+
return [clientX, clientY];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const rect = element.getBoundingClientRect();
|
|
156
|
+
|
|
157
|
+
if (!rotation) {
|
|
158
|
+
return [clientX - rect.left, clientY - rect.top];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 1. Find the element's center (rotation doesn't move the center)
|
|
162
|
+
const centerX = rect.left + rect.width / 2;
|
|
163
|
+
const centerY = rect.top + rect.height / 2;
|
|
164
|
+
|
|
165
|
+
// 2. Get the mouse position relative to the center (in browser window coordinates)
|
|
166
|
+
const relX = clientX - centerX;
|
|
167
|
+
const relY = clientY - centerY;
|
|
168
|
+
|
|
169
|
+
// 3. Apply inverse rotation to obtain the mouse position from center in element-local coordinates
|
|
170
|
+
const local = rotatePoint({ x: relX, y: relY }, -rotation);
|
|
171
|
+
|
|
172
|
+
// 4. Convert coordinates from center-relative to top-left-relative
|
|
173
|
+
return [local.x + element.offsetWidth / 2, local.y + element.offsetHeight / 2];
|
|
174
|
+
}
|
package/src/utils/scroll.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { Position } from '../@types';
|
|
|
2
2
|
|
|
3
3
|
export type ScrollOptions = {
|
|
4
4
|
offsets?: Position;
|
|
5
|
+
smooth?: boolean;
|
|
5
6
|
threshold?: number;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
const DEFAULT_OFFSETS = { x: 0, y: 0 };
|
|
9
10
|
|
|
10
11
|
export function scrollToLocation(parentEl: HTMLElement, referenceEl: HTMLElement, options: ScrollOptions = {}): void {
|
|
11
|
-
const { offsets = DEFAULT_OFFSETS } = options;
|
|
12
|
+
const { offsets = DEFAULT_OFFSETS, smooth = false } = options;
|
|
12
13
|
const { x: offsetXPercentage, y: offsetYPercentage } = offsets;
|
|
13
14
|
// Get the bounding client rects so that the offsetLeft of the reference element can be calculated --
|
|
14
15
|
// even if it has been transformed via rotation
|
|
@@ -40,6 +41,10 @@ export function scrollToLocation(parentEl: HTMLElement, referenceEl: HTMLElement
|
|
|
40
41
|
const scrollLeft = Math.max(0, Math.min(parentEl.scrollLeft + offsetScrollLeft, parentEl.scrollWidth));
|
|
41
42
|
const scrollTop = Math.max(0, Math.min(parentEl.scrollTop + offsetScrollTop, parentEl.scrollHeight));
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
if (smooth) {
|
|
45
|
+
parentEl.scrollTo({ left: scrollLeft, top: scrollTop, behavior: 'smooth' });
|
|
46
|
+
} else {
|
|
47
|
+
parentEl.scrollLeft = scrollLeft;
|
|
48
|
+
parentEl.scrollTop = scrollTop;
|
|
49
|
+
}
|
|
45
50
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Placeholder for the threaded annotation reply popup (V2).
|
|
5
|
-
* Replaces PopupReply when the isThreadedAnnotation feature flag is enabled.
|
|
6
|
-
* Currently renders an empty container — props will be wired up when V2 is implemented.
|
|
7
|
-
*/
|
|
8
|
-
export default function PopupReplyV2(): JSX.Element {
|
|
9
|
-
return <div data-testid="popup-reply-v2" />;
|
|
10
|
-
}
|