/
ToolAction.ts
54 lines (52 loc) · 1.78 KB
/
ToolAction.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type { Annotation } from './AnnotationTypes';
import type { InteractionEventType } from './EventTypes';
import type { SetToolBindingsType } from './ISetToolModeOptions';
/**
* An action that may be defined at the tool configuration level
*
* Annotations can have actions that run a specific task (ex: showing a dropdown
* containing a list of all predefined zoom levels - advanced magnifier glass).
* Each action must have at least one binding option (mouse button + [modifier(s)])
* and a action runs if and only if no other tool is using that same binding options
* to draw an annotation because action has lower priority.
*
* Actions are defined in the following way in a annotation tool constructor:
*
* class MyAnnotationTool extends AnnotationTool {
* constructor(
* toolProps: PublicToolProps = {},
* defaultToolProps: ToolProps = {
* configuration: {
* actions: [
* {
* method: 'myAction',
* bindings: [
* {
* mouseButton: MouseBindings.Secondary,
* modifierKey: KeyboardBindings.Shift,
* }
* ]
* }
* ]
* }
* }
* ) {
* super(toolProps, defaultToolProps);
* }
*
* public myAction(evt: EventTypes.InteractionEventType, annotation: MyAnnotation) {
* // action code
* }
* }
*
* The "method" property may be a string or a javascript function. In case it is
* a string a function with same name must exists in the tool class. In both ways
* (string or function) the function is called in the tool's context (`this`)
*/
type ToolAction = {
method:
| string
| ((evt: InteractionEventType, annotation: Annotation) => void);
bindings: SetToolBindingsType[];
};
export default ToolAction;