/
ContextPadProvider.ts
81 lines (74 loc) · 2.49 KB
/
ContextPadProvider.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Element } from '../../model/Types';
import { ContextPadTarget } from './ContextPad';
export type ContextPadEntry<ElementType extends Element = Element> = {
action: (event: Event, target: ContextPadTarget<ElementType>, autoActivate: boolean) => void;
className?: string;
group?: string;
html?: string;
imageUrl?: string;
title?: string;
};
export type ContextPadEntries<ElementType extends Element = Element> = Record<string, ContextPadEntry<ElementType>>;
export type ContextPadEntriesCallback<ElementType extends Element = Element> = (entries: ContextPadEntries<ElementType>) => ContextPadEntries<ElementType>;
/**
* An interface to be implemented by a context menu provider.
*/
export default interface ContextPadProvider<ElementType extends Element = Element> {
/**
* Returns a map of entries or a function that receives, modifies and returns
* a map of entries for one element.
*
* The following example shows how to replace any entries returned by previous
* providers with one entry which alerts the ID of the given element when
* clicking on the entry.
*
* @example
*
* ```javascript
* getPopupMenuEntries(element) {
* return function(entries) {
* return {
* alert: {
* action: (event, target, autoActivate) => {
* alert(element.id);
* },
* className: 'alert',
* title: 'Alert element ID'
* }
* };
* };
* }
* ```
*
* @param element
*/
getContextPadEntries?: (element: ElementType) => ContextPadEntriesCallback<ElementType> | ContextPadEntries<ElementType>;
/**
* Returns a map of entries or a function that receives, modifies and returns
* a map of entries for many elements.
*
* The following example shows how to replace any entries returned by previous
* providers with one entry which alerts the IDs of the given elements when
* clicking on the entry.
*
* @example
*
* ```javascript
* getMultiElementContextPadEntries(elements) {
* return function(entries) {
* return {
* alert: {
* action: (event, target, autoActivate) => {
* elements.forEach(element => alert(element.id));
* },
* className: 'alert',
* title: 'Alert element IDs'
* }
* };
* }
* ```
*
* @param elements
*/
getMultiElementContextPadEntries?: (elements: ElementType[]) => ContextPadEntriesCallback<ElementType> | ContextPadEntries<ElementType>;
}