editable.ts 0.0.1
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/LICENSE +21 -0
- package/README.md +571 -0
- package/dist/editable.umd.cjs +2 -0
- package/dist/editable.umd.cjs.map +1 -0
- package/lib/block.d.ts +13 -0
- package/lib/block.d.ts.map +1 -0
- package/lib/block.js +58 -0
- package/lib/block.js.map +1 -0
- package/lib/clipboard.d.ts +22 -0
- package/lib/clipboard.d.ts.map +1 -0
- package/lib/clipboard.js +154 -0
- package/lib/clipboard.js.map +1 -0
- package/lib/config.d.ts +37 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +64 -0
- package/lib/config.js.map +1 -0
- package/lib/content.d.ts +37 -0
- package/lib/content.d.ts.map +1 -0
- package/lib/content.js +526 -0
- package/lib/content.js.map +1 -0
- package/lib/core.d.ts +97 -0
- package/lib/core.d.ts.map +1 -0
- package/lib/core.js +261 -0
- package/lib/core.js.map +1 -0
- package/lib/create-default-behavior.d.ts +31 -0
- package/lib/create-default-behavior.d.ts.map +1 -0
- package/lib/create-default-behavior.js +178 -0
- package/lib/create-default-behavior.js.map +1 -0
- package/lib/create-default-events.d.ts +152 -0
- package/lib/create-default-events.d.ts.map +1 -0
- package/lib/create-default-events.js +183 -0
- package/lib/create-default-events.js.map +1 -0
- package/lib/cursor.d.ts +68 -0
- package/lib/cursor.d.ts.map +1 -0
- package/lib/cursor.js +354 -0
- package/lib/cursor.js.map +1 -0
- package/lib/dispatcher.d.ts +78 -0
- package/lib/dispatcher.d.ts.map +1 -0
- package/lib/dispatcher.js +416 -0
- package/lib/dispatcher.js.map +1 -0
- package/lib/eventable.d.ts +2 -0
- package/lib/eventable.d.ts.map +1 -0
- package/lib/eventable.js +104 -0
- package/lib/eventable.js.map +1 -0
- package/lib/feature-detection.d.ts +12 -0
- package/lib/feature-detection.d.ts.map +1 -0
- package/lib/feature-detection.js +42 -0
- package/lib/feature-detection.js.map +1 -0
- package/lib/highlight-support.d.ts +24 -0
- package/lib/highlight-support.d.ts.map +1 -0
- package/lib/highlight-support.js +172 -0
- package/lib/highlight-support.js.map +1 -0
- package/lib/highlight-text.d.ts +21 -0
- package/lib/highlight-text.d.ts.map +1 -0
- package/lib/highlight-text.js +147 -0
- package/lib/highlight-text.js.map +1 -0
- package/lib/keyboard.d.ts +33 -0
- package/lib/keyboard.d.ts.map +1 -0
- package/lib/keyboard.js +189 -0
- package/lib/keyboard.js.map +1 -0
- package/lib/monitored-highlighting.d.ts +28 -0
- package/lib/monitored-highlighting.d.ts.map +1 -0
- package/lib/monitored-highlighting.js +194 -0
- package/lib/monitored-highlighting.js.map +1 -0
- package/lib/node-iterator.d.ts +16 -0
- package/lib/node-iterator.d.ts.map +1 -0
- package/lib/node-iterator.js +97 -0
- package/lib/node-iterator.js.map +1 -0
- package/lib/node-type.d.ts +13 -0
- package/lib/node-type.d.ts.map +1 -0
- package/lib/node-type.js +15 -0
- package/lib/node-type.js.map +1 -0
- package/lib/parser.d.ts +89 -0
- package/lib/parser.d.ts.map +1 -0
- package/lib/parser.js +251 -0
- package/lib/parser.js.map +1 -0
- package/lib/plugins/highlighting/match-collection.d.ts +7 -0
- package/lib/plugins/highlighting/match-collection.d.ts.map +1 -0
- package/lib/plugins/highlighting/match-collection.js +62 -0
- package/lib/plugins/highlighting/match-collection.js.map +1 -0
- package/lib/plugins/highlighting/spellcheck-service.d.ts +12 -0
- package/lib/plugins/highlighting/spellcheck-service.d.ts.map +1 -0
- package/lib/plugins/highlighting/spellcheck-service.js +24 -0
- package/lib/plugins/highlighting/spellcheck-service.js.map +1 -0
- package/lib/plugins/highlighting/text-search.d.ts +10 -0
- package/lib/plugins/highlighting/text-search.d.ts.map +1 -0
- package/lib/plugins/highlighting/text-search.js +92 -0
- package/lib/plugins/highlighting/text-search.js.map +1 -0
- package/lib/plugins/highlighting/whitespace-highlighting.d.ts +14 -0
- package/lib/plugins/highlighting/whitespace-highlighting.d.ts.map +1 -0
- package/lib/plugins/highlighting/whitespace-highlighting.js +52 -0
- package/lib/plugins/highlighting/whitespace-highlighting.js.map +1 -0
- package/lib/quotes.d.ts +8 -0
- package/lib/quotes.d.ts.map +1 -0
- package/lib/quotes.js +170 -0
- package/lib/quotes.js.map +1 -0
- package/lib/range-container.d.ts +22 -0
- package/lib/range-container.d.ts.map +1 -0
- package/lib/range-container.js +52 -0
- package/lib/range-container.js.map +1 -0
- package/lib/range-save-restore.d.ts +13 -0
- package/lib/range-save-restore.d.ts.map +1 -0
- package/lib/range-save-restore.js +153 -0
- package/lib/range-save-restore.js.map +1 -0
- package/lib/selection-watcher.d.ts +55 -0
- package/lib/selection-watcher.d.ts.map +1 -0
- package/lib/selection-watcher.js +126 -0
- package/lib/selection-watcher.js.map +1 -0
- package/lib/selection.d.ts +74 -0
- package/lib/selection.d.ts.map +1 -0
- package/lib/selection.js +341 -0
- package/lib/selection.js.map +1 -0
- package/lib/smartQuotes.d.ts +16 -0
- package/lib/smartQuotes.d.ts.map +1 -0
- package/lib/smartQuotes.js +92 -0
- package/lib/smartQuotes.js.map +1 -0
- package/lib/util/binary_search.d.ts +23 -0
- package/lib/util/binary_search.d.ts.map +1 -0
- package/lib/util/binary_search.js +137 -0
- package/lib/util/binary_search.js.map +1 -0
- package/lib/util/clone-deep.d.ts +8 -0
- package/lib/util/clone-deep.d.ts.map +1 -0
- package/lib/util/clone-deep.js +10 -0
- package/lib/util/clone-deep.js.map +1 -0
- package/lib/util/dom.d.ts +43 -0
- package/lib/util/dom.d.ts.map +1 -0
- package/lib/util/dom.js +272 -0
- package/lib/util/dom.js.map +1 -0
- package/lib/util/element.d.ts +10 -0
- package/lib/util/element.d.ts.map +1 -0
- package/lib/util/element.js +29 -0
- package/lib/util/element.js.map +1 -0
- package/lib/util/error.d.ts +2 -0
- package/lib/util/error.d.ts.map +1 -0
- package/lib/util/error.js +16 -0
- package/lib/util/error.js.map +1 -0
- package/lib/util/log.d.ts +2 -0
- package/lib/util/log.d.ts.map +1 -0
- package/lib/util/log.js +18 -0
- package/lib/util/log.js.map +1 -0
- package/lib/util/merge.d.ts +6 -0
- package/lib/util/merge.d.ts.map +1 -0
- package/lib/util/merge.js +31 -0
- package/lib/util/merge.js.map +1 -0
- package/lib/util/string.d.ts +25 -0
- package/lib/util/string.d.ts.map +1 -0
- package/lib/util/string.js +68 -0
- package/lib/util/string.js.map +1 -0
- package/lib/util/viewport.d.ts +6 -0
- package/lib/util/viewport.d.ts.map +1 -0
- package/lib/util/viewport.js +8 -0
- package/lib/util/viewport.js.map +1 -0
- package/package.json +86 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import SelectionWatcher from './selection-watcher.js';
|
|
2
|
+
import Keyboard from './keyboard.js';
|
|
3
|
+
import type { Editable } from './core.js';
|
|
4
|
+
/**
|
|
5
|
+
* The Dispatcher module is responsible for dealing with events and their handlers.
|
|
6
|
+
*
|
|
7
|
+
* @module core
|
|
8
|
+
* @submodule dispatcher
|
|
9
|
+
*/
|
|
10
|
+
export default class Dispatcher {
|
|
11
|
+
document: Document;
|
|
12
|
+
config: any;
|
|
13
|
+
editable: Editable;
|
|
14
|
+
editableSelector: string;
|
|
15
|
+
selectionWatcher: SelectionWatcher;
|
|
16
|
+
keyboard: Keyboard;
|
|
17
|
+
activeListeners: Array<{
|
|
18
|
+
event: string;
|
|
19
|
+
listener: EventListener;
|
|
20
|
+
capture: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
suspended?: boolean;
|
|
23
|
+
switchContext?: {
|
|
24
|
+
events: string[];
|
|
25
|
+
positionX?: number;
|
|
26
|
+
};
|
|
27
|
+
getEditableBlockByEvent: (evt: Event) => HTMLElement | undefined;
|
|
28
|
+
notify: (event: string, ...args: any[]) => void;
|
|
29
|
+
off: (...args: any[]) => void;
|
|
30
|
+
on: (event: string, handler: (...args: any[]) => any) => this | ((events: Record<string, (...args: any[]) => any>) => this);
|
|
31
|
+
constructor(editable: Editable);
|
|
32
|
+
setupDocumentListener(event: string, func: (evt: Event) => void, capture?: boolean): this;
|
|
33
|
+
/**
|
|
34
|
+
* Sets up all events that Editable.JS is catching.
|
|
35
|
+
*
|
|
36
|
+
* @method setup
|
|
37
|
+
*/
|
|
38
|
+
setup(): void;
|
|
39
|
+
unload(): void;
|
|
40
|
+
suspend(): void;
|
|
41
|
+
continue(): void;
|
|
42
|
+
setupEventListeners(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets up events that are triggered on modifying an element.
|
|
45
|
+
*
|
|
46
|
+
* @method setupElementListeners
|
|
47
|
+
*/
|
|
48
|
+
setupElementListeners(): void;
|
|
49
|
+
dispatchSwitchEvent(event: KeyboardEvent, element: HTMLElement, direction: 'up' | 'down'): void;
|
|
50
|
+
/**
|
|
51
|
+
* Sets up listener for keydown event which forwards events to
|
|
52
|
+
* the Keyboard instance.
|
|
53
|
+
*
|
|
54
|
+
* @method setupKeydownListener
|
|
55
|
+
*/
|
|
56
|
+
setupKeydownListener(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Sets up handlers for the keyboard events.
|
|
59
|
+
* Keyboard definitions are in {{#crossLink "Keyboard"}}{{/crossLink}}.
|
|
60
|
+
*
|
|
61
|
+
* @method setupKeyboardEvents
|
|
62
|
+
*/
|
|
63
|
+
setupKeyboardEvents(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Sets up events that are triggered on a selection change.
|
|
66
|
+
*
|
|
67
|
+
* @method setupSelectionChangeListeners
|
|
68
|
+
*/
|
|
69
|
+
setupSelectionChangeListeners(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Fallback solution to support selection change events on browsers that don't
|
|
72
|
+
* support selectionChange.
|
|
73
|
+
*
|
|
74
|
+
* @method setupSelectionChangeFallbackListeners
|
|
75
|
+
*/
|
|
76
|
+
setupSelectionChangeFallbackListeners(): void;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRo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B/B,qBAAqB,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,EAAE,OAAO,GAAE,OAAe,GAAG,IAAI;IAQjG;;;;MAIE;IACF,KAAK;IAML,MAAM;IAQN,OAAO;IASP,QAAQ;IAMR,mBAAmB;IAWnB;;;;MAIE;IACF,qBAAqB;IAyFrB,mBAAmB,CAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI;IA8BhG;;;;;MAKE;IACF,oBAAoB;IASpB;;;;;MAKE;IACF,mBAAmB;IA4FnB;;;;MAIE;IACF,6BAA6B;IA4D7B;;;;;MAKE;IACF,qCAAqC;CAiCtC"}
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { selectionchange } from './feature-detection.js';
|
|
2
|
+
import * as clipboard from './clipboard.js';
|
|
3
|
+
import * as content from './content.js';
|
|
4
|
+
import eventable from './eventable.js';
|
|
5
|
+
import SelectionWatcher from './selection-watcher.js';
|
|
6
|
+
import config from './config.js';
|
|
7
|
+
import Keyboard from './keyboard.js';
|
|
8
|
+
import { closest } from './util/dom.js';
|
|
9
|
+
import { replaceLast, endsWithSingleSpace } from './util/string.js';
|
|
10
|
+
import { applySmartQuotes, shouldApplySmartQuotes } from './smartQuotes.js';
|
|
11
|
+
/**
|
|
12
|
+
* The Dispatcher module is responsible for dealing with events and their handlers.
|
|
13
|
+
*
|
|
14
|
+
* @module core
|
|
15
|
+
* @submodule dispatcher
|
|
16
|
+
*/
|
|
17
|
+
export default class Dispatcher {
|
|
18
|
+
constructor(editable) {
|
|
19
|
+
const win = editable.win;
|
|
20
|
+
eventable(this, editable);
|
|
21
|
+
this.document = win.document;
|
|
22
|
+
this.config = editable.config;
|
|
23
|
+
this.editable = editable;
|
|
24
|
+
this.editableSelector = editable.editableSelector;
|
|
25
|
+
this.selectionWatcher = new SelectionWatcher(this, win);
|
|
26
|
+
this.keyboard = new Keyboard(this.selectionWatcher);
|
|
27
|
+
this.activeListeners = [];
|
|
28
|
+
this.setup();
|
|
29
|
+
this.getEditableBlockByEvent = (evt) => {
|
|
30
|
+
const target = evt.target;
|
|
31
|
+
return target ? closest(target, editable.editableSelector) : undefined;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
setupDocumentListener(event, func, capture = false) {
|
|
35
|
+
const listener = { event, listener: func.bind(this), capture };
|
|
36
|
+
this.activeListeners.push(listener);
|
|
37
|
+
this.document.addEventListener(event, listener.listener, capture);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Sets up all events that Editable.JS is catching.
|
|
42
|
+
*
|
|
43
|
+
* @method setup
|
|
44
|
+
*/
|
|
45
|
+
setup() {
|
|
46
|
+
// setup all events listeners and keyboard handlers
|
|
47
|
+
this.setupKeyboardEvents();
|
|
48
|
+
this.setupEventListeners();
|
|
49
|
+
}
|
|
50
|
+
unload() {
|
|
51
|
+
this.off();
|
|
52
|
+
for (const l of this.activeListeners) {
|
|
53
|
+
this.document.removeEventListener(l.event, l.listener, l.capture);
|
|
54
|
+
}
|
|
55
|
+
this.activeListeners.length = 0;
|
|
56
|
+
}
|
|
57
|
+
suspend() {
|
|
58
|
+
if (this.suspended)
|
|
59
|
+
return;
|
|
60
|
+
this.suspended = true;
|
|
61
|
+
for (const l of this.activeListeners) {
|
|
62
|
+
this.document.removeEventListener(l.event, l.listener, l.capture);
|
|
63
|
+
}
|
|
64
|
+
this.activeListeners.length = 0;
|
|
65
|
+
}
|
|
66
|
+
continue() {
|
|
67
|
+
if (!this.suspended)
|
|
68
|
+
return;
|
|
69
|
+
this.suspended = false;
|
|
70
|
+
this.setupEventListeners();
|
|
71
|
+
}
|
|
72
|
+
setupEventListeners() {
|
|
73
|
+
this.setupElementListeners();
|
|
74
|
+
this.setupKeydownListener();
|
|
75
|
+
if (selectionchange) {
|
|
76
|
+
this.setupSelectionChangeListeners();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.setupSelectionChangeFallbackListeners();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets up events that are triggered on modifying an element.
|
|
84
|
+
*
|
|
85
|
+
* @method setupElementListeners
|
|
86
|
+
*/
|
|
87
|
+
setupElementListeners() {
|
|
88
|
+
const currentInput = { offset: undefined };
|
|
89
|
+
this
|
|
90
|
+
.setupDocumentListener('focus', function focusListener(evt) {
|
|
91
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
92
|
+
if (!block)
|
|
93
|
+
return;
|
|
94
|
+
const target = evt.target;
|
|
95
|
+
if (target && target.getAttribute(config.pastingAttribute))
|
|
96
|
+
return;
|
|
97
|
+
this.selectionWatcher.syncSelection();
|
|
98
|
+
this.notify('focus', block);
|
|
99
|
+
}, true)
|
|
100
|
+
.setupDocumentListener('blur', function blurListener(evt) {
|
|
101
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
102
|
+
if (!block)
|
|
103
|
+
return;
|
|
104
|
+
if (block.getAttribute(config.pastingAttribute))
|
|
105
|
+
return;
|
|
106
|
+
this.notify('blur', block);
|
|
107
|
+
}, true)
|
|
108
|
+
.setupDocumentListener('copy', function copyListener(evt) {
|
|
109
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
110
|
+
if (!block)
|
|
111
|
+
return;
|
|
112
|
+
const selection = this.selectionWatcher.getFreshSelection();
|
|
113
|
+
if (selection && selection.isSelection) {
|
|
114
|
+
this.notify('clipboard', block, 'copy', selection);
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
.setupDocumentListener('cut', function cutListener(evt) {
|
|
118
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
119
|
+
if (!block)
|
|
120
|
+
return;
|
|
121
|
+
const selection = this.selectionWatcher.getFreshSelection();
|
|
122
|
+
if (selection && selection.isSelection) {
|
|
123
|
+
this.notify('clipboard', block, 'cut', selection);
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
.setupDocumentListener('paste', function pasteListener(evt) {
|
|
127
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
128
|
+
if (!block)
|
|
129
|
+
return;
|
|
130
|
+
const clipEvent = evt;
|
|
131
|
+
clipEvent.preventDefault();
|
|
132
|
+
const selection = this.selectionWatcher.getFreshSelection();
|
|
133
|
+
if (!selection || !clipEvent.clipboardData)
|
|
134
|
+
return;
|
|
135
|
+
const clipboardContent = clipEvent.clipboardData.getData('text/html') || clipEvent.clipboardData.getData('text/plain');
|
|
136
|
+
const { blocks, cursor } = clipboard.paste(block, selection, clipboardContent);
|
|
137
|
+
if (blocks.length) {
|
|
138
|
+
const target = clipEvent.target;
|
|
139
|
+
if (target && endsWithSingleSpace(target.innerText)) {
|
|
140
|
+
cursor.retainVisibleSelection(() => {
|
|
141
|
+
block.innerHTML = replaceLast(block.innerHTML, ' ', ' ');
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
this.notify('paste', block, blocks, cursor);
|
|
145
|
+
// The input event does not fire when we process the content manually
|
|
146
|
+
// and insert it via script
|
|
147
|
+
this.notify('change', block);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
cursor.setVisibleSelection();
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
.setupDocumentListener('input', function inputListener(evt) {
|
|
154
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
155
|
+
if (!block)
|
|
156
|
+
return;
|
|
157
|
+
const target = evt.target;
|
|
158
|
+
if (target && shouldApplySmartQuotes(this.config, target)) {
|
|
159
|
+
const selection = this.selectionWatcher.getFreshSelection();
|
|
160
|
+
if (!selection || !selection.range)
|
|
161
|
+
return;
|
|
162
|
+
// Save offset of new input, to reset cursor correctly after timeout delay
|
|
163
|
+
currentInput.offset = selection.range.startOffset;
|
|
164
|
+
const inputEvent = evt;
|
|
165
|
+
const quotesConfig = this.config.quotes || { quotes: [], singleQuotes: [] };
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
if (inputEvent.data) {
|
|
168
|
+
applySmartQuotes(selection.range, quotesConfig, inputEvent.data, target, currentInput.offset);
|
|
169
|
+
}
|
|
170
|
+
}, 300);
|
|
171
|
+
}
|
|
172
|
+
this.notify('change', block);
|
|
173
|
+
})
|
|
174
|
+
.setupDocumentListener('formatEditable', function formatEditableListener(evt) {
|
|
175
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
176
|
+
if (!block)
|
|
177
|
+
return;
|
|
178
|
+
this.notify('change', block);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
dispatchSwitchEvent(event, element, direction) {
|
|
182
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
183
|
+
return;
|
|
184
|
+
const cursor = this.selectionWatcher.getFreshSelection();
|
|
185
|
+
if (!cursor || cursor.isSelection)
|
|
186
|
+
return;
|
|
187
|
+
// store position
|
|
188
|
+
if (!this.switchContext) {
|
|
189
|
+
this.switchContext = {
|
|
190
|
+
positionX: cursor.getBoundingClientRect().left,
|
|
191
|
+
events: ['cursor']
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
this.switchContext.events = ['cursor'];
|
|
196
|
+
}
|
|
197
|
+
if (direction === 'up' && cursor.isAtFirstLine()) {
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
event.stopPropagation();
|
|
200
|
+
this.switchContext.events = ['switch', 'blur', 'focus', 'cursor'];
|
|
201
|
+
this.notify('switch', element, direction, cursor);
|
|
202
|
+
}
|
|
203
|
+
if (direction === 'down' && cursor.isAtLastLine()) {
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
event.stopPropagation();
|
|
206
|
+
this.switchContext.events = ['switch', 'blur', 'focus', 'cursor'];
|
|
207
|
+
this.notify('switch', element, direction, cursor);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Sets up listener for keydown event which forwards events to
|
|
212
|
+
* the Keyboard instance.
|
|
213
|
+
*
|
|
214
|
+
* @method setupKeydownListener
|
|
215
|
+
*/
|
|
216
|
+
setupKeydownListener() {
|
|
217
|
+
this.setupDocumentListener('keydown', function (evt) {
|
|
218
|
+
const block = this.getEditableBlockByEvent(evt);
|
|
219
|
+
if (!block)
|
|
220
|
+
return;
|
|
221
|
+
const keyEvent = evt;
|
|
222
|
+
this.keyboard.dispatchKeyEvent(keyEvent, block, false);
|
|
223
|
+
}, true);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Sets up handlers for the keyboard events.
|
|
227
|
+
* Keyboard definitions are in {{#crossLink "Keyboard"}}{{/crossLink}}.
|
|
228
|
+
*
|
|
229
|
+
* @method setupKeyboardEvents
|
|
230
|
+
*/
|
|
231
|
+
setupKeyboardEvents() {
|
|
232
|
+
const self = this;
|
|
233
|
+
this.keyboard
|
|
234
|
+
.on('up', function (event) {
|
|
235
|
+
self.dispatchSwitchEvent(event, this, 'up');
|
|
236
|
+
})
|
|
237
|
+
.on('down', function (event) {
|
|
238
|
+
self.dispatchSwitchEvent(event, this, 'down');
|
|
239
|
+
})
|
|
240
|
+
.on('backspace', function (event) {
|
|
241
|
+
const editableBlock = this;
|
|
242
|
+
const rangeContainer = self.selectionWatcher.getFreshRange();
|
|
243
|
+
if (!rangeContainer.isCursor)
|
|
244
|
+
return;
|
|
245
|
+
const cursor = rangeContainer.getCursor();
|
|
246
|
+
if (!cursor || !cursor.isAtBeginning())
|
|
247
|
+
return;
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
event.stopPropagation();
|
|
250
|
+
self.notify('merge', editableBlock, 'before', cursor);
|
|
251
|
+
})
|
|
252
|
+
.on('delete', function (event) {
|
|
253
|
+
const editableBlock = this;
|
|
254
|
+
const rangeContainer = self.selectionWatcher.getFreshRange();
|
|
255
|
+
if (!rangeContainer.isCursor)
|
|
256
|
+
return;
|
|
257
|
+
const cursor = rangeContainer.getCursor();
|
|
258
|
+
if (!cursor || !cursor.isAtTextEnd())
|
|
259
|
+
return;
|
|
260
|
+
event.preventDefault();
|
|
261
|
+
event.stopPropagation();
|
|
262
|
+
self.notify('merge', editableBlock, 'after', cursor);
|
|
263
|
+
})
|
|
264
|
+
.on('enter', function (event) {
|
|
265
|
+
const editableBlock = this;
|
|
266
|
+
event.preventDefault();
|
|
267
|
+
event.stopPropagation();
|
|
268
|
+
const rangeContainer = self.selectionWatcher.getFreshRange();
|
|
269
|
+
const cursor = rangeContainer.forceCursor();
|
|
270
|
+
if (!cursor)
|
|
271
|
+
return;
|
|
272
|
+
if (cursor.isAtTextEnd()) {
|
|
273
|
+
self.notify('insert', editableBlock, 'after', cursor);
|
|
274
|
+
}
|
|
275
|
+
else if (cursor.isAtBeginning()) {
|
|
276
|
+
self.notify('insert', editableBlock, 'before', cursor);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
const beforeFragment = cursor.before();
|
|
280
|
+
const afterFragment = cursor.after();
|
|
281
|
+
self.notify('split', editableBlock, content.getInnerHtmlOfFragment(beforeFragment), content.getInnerHtmlOfFragment(afterFragment), cursor);
|
|
282
|
+
}
|
|
283
|
+
})
|
|
284
|
+
.on('shiftEnter', function (event) {
|
|
285
|
+
const editableBlock = this;
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
event.stopPropagation();
|
|
288
|
+
const cursor = self.selectionWatcher.forceCursor();
|
|
289
|
+
if (cursor) {
|
|
290
|
+
self.notify('newline', editableBlock, cursor);
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
.on('bold', function (event) {
|
|
294
|
+
event.preventDefault();
|
|
295
|
+
event.stopPropagation();
|
|
296
|
+
const selection = self.selectionWatcher.getFreshSelection();
|
|
297
|
+
if (selection && selection.isSelection) {
|
|
298
|
+
self.notify('toggleBold', selection);
|
|
299
|
+
}
|
|
300
|
+
})
|
|
301
|
+
.on('italic', function (event) {
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
event.stopPropagation();
|
|
304
|
+
const selection = self.selectionWatcher.getFreshSelection();
|
|
305
|
+
if (selection && selection.isSelection) {
|
|
306
|
+
self.notify('toggleEmphasis', selection);
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
.on('character', function (event) {
|
|
310
|
+
const editableBlock = this;
|
|
311
|
+
self.notify('change', editableBlock);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Sets up events that are triggered on a selection change.
|
|
316
|
+
*
|
|
317
|
+
* @method setupSelectionChangeListeners
|
|
318
|
+
*/
|
|
319
|
+
setupSelectionChangeListeners() {
|
|
320
|
+
let selectionDirty = false;
|
|
321
|
+
let suppressSelectionChanges = false;
|
|
322
|
+
const selectionWatcher = this.selectionWatcher;
|
|
323
|
+
// fires on mousemove (thats probably a bit too much)
|
|
324
|
+
// catches changes like 'select all' from context menu
|
|
325
|
+
this.setupDocumentListener('selectionchange', (evt) => {
|
|
326
|
+
let didSyncSelection = false;
|
|
327
|
+
let cursor = this.selectionWatcher.getFreshSelection();
|
|
328
|
+
if (!cursor) {
|
|
329
|
+
selectionWatcher.selectionChanged();
|
|
330
|
+
didSyncSelection = true;
|
|
331
|
+
cursor = this.selectionWatcher.getSelection();
|
|
332
|
+
}
|
|
333
|
+
if (cursor && cursor.isSelection && cursor.isAtBeginning() && cursor.isAtEnd()) {
|
|
334
|
+
this.notify('selectToBoundary', cursor.host, evt, 'both');
|
|
335
|
+
}
|
|
336
|
+
else if (cursor && cursor.isSelection && cursor.isAtBeginning()) {
|
|
337
|
+
this.notify('selectToBoundary', cursor.host, evt, 'start');
|
|
338
|
+
}
|
|
339
|
+
else if (cursor && cursor.isSelection && cursor.isAtEnd()) {
|
|
340
|
+
this.notify('selectToBoundary', cursor.host, evt, 'end');
|
|
341
|
+
}
|
|
342
|
+
if (suppressSelectionChanges) {
|
|
343
|
+
selectionDirty = true;
|
|
344
|
+
}
|
|
345
|
+
else if (!didSyncSelection) {
|
|
346
|
+
selectionWatcher.selectionChanged();
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
// listen for selection changes by mouse so we can
|
|
350
|
+
// suppress the selectionchange event and only fire the
|
|
351
|
+
// change event on mouseup
|
|
352
|
+
this.setupDocumentListener('mousedown', function (evt) {
|
|
353
|
+
const mouseEvent = evt;
|
|
354
|
+
if (!this.getEditableBlockByEvent(evt))
|
|
355
|
+
return;
|
|
356
|
+
if (this.config.mouseMoveSelectionChanges === false) {
|
|
357
|
+
suppressSelectionChanges = true;
|
|
358
|
+
// Without this timeout the previous selection is active
|
|
359
|
+
// until the mouseup event (no. not good).
|
|
360
|
+
setTimeout(() => selectionWatcher.selectionChanged(), 0);
|
|
361
|
+
}
|
|
362
|
+
const self = this;
|
|
363
|
+
this.document.addEventListener('mouseup', () => {
|
|
364
|
+
suppressSelectionChanges = false;
|
|
365
|
+
if (selectionDirty) {
|
|
366
|
+
selectionDirty = false;
|
|
367
|
+
selectionWatcher.selectionChanged();
|
|
368
|
+
}
|
|
369
|
+
}, {
|
|
370
|
+
capture: true,
|
|
371
|
+
once: true
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Fallback solution to support selection change events on browsers that don't
|
|
377
|
+
* support selectionChange.
|
|
378
|
+
*
|
|
379
|
+
* @method setupSelectionChangeFallbackListeners
|
|
380
|
+
*/
|
|
381
|
+
setupSelectionChangeFallbackListeners() {
|
|
382
|
+
const notifySelectionBoundary = (evt) => {
|
|
383
|
+
const cursor = this.selectionWatcher.getFreshSelection();
|
|
384
|
+
if (cursor && cursor.isSelection && cursor.isAtBeginning() && cursor.isAtEnd()) {
|
|
385
|
+
this.notify('selectToBoundary', cursor.host, evt, 'both');
|
|
386
|
+
}
|
|
387
|
+
else if (cursor && cursor.isSelection && cursor.isAtBeginning()) {
|
|
388
|
+
this.notify('selectToBoundary', cursor.host, evt, 'start');
|
|
389
|
+
}
|
|
390
|
+
else if (cursor && cursor.isSelection && cursor.isAtEnd()) {
|
|
391
|
+
this.notify('selectToBoundary', cursor.host, evt, 'end');
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
// listen for selection changes by mouse
|
|
395
|
+
this.setupDocumentListener('mouseup', (evt) => {
|
|
396
|
+
// In Opera when clicking outside of a block
|
|
397
|
+
// it does not update the selection as it should
|
|
398
|
+
// without the timeout
|
|
399
|
+
setTimeout(() => {
|
|
400
|
+
this.selectionWatcher.selectionChanged();
|
|
401
|
+
notifySelectionBoundary(evt);
|
|
402
|
+
}, 0);
|
|
403
|
+
});
|
|
404
|
+
// listen for selection changes by keys
|
|
405
|
+
this.setupDocumentListener('keyup', (evt) => {
|
|
406
|
+
if (!this.getEditableBlockByEvent(evt))
|
|
407
|
+
return;
|
|
408
|
+
// when pressing Command + Shift + Left for example the keyup is only triggered
|
|
409
|
+
// after at least two keys are released. Strange. The culprit seems to be the
|
|
410
|
+
// Command key. Do we need a workaround?
|
|
411
|
+
this.selectionWatcher.selectionChanged();
|
|
412
|
+
notifySelectionBoundary(evt);
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,gBAAgB,MAAM,wBAAwB,CAAA;AACrD,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAA;AACrC,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAC,gBAAgB,EAAE,sBAAs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AAC;gBAC5D,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;YAC1D,CAAC;QACH,CAAC,CAAA;QAED,wCAAwC;QACxC,IAAI,CAAC,qBAAqB,CAAC,SAAS,EAAE,CAAC,GAAU,EAAE,EAAE;YACnD,4CAA4C;YAC5C,gDAAgD;YAChD,sBAAsB;YACtB,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAA;gBACxC,uBAAuB,CAAC,GAAG,CAAC,CAAA;YAC9B,CAAC,EAAE,CAAC,CAAC,CAAA;QACP,CAAC,CAAC,CAAA;QAEF,uCAAuC;QACvC,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;YACjD,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC;gBAAE,OAAM;YAC9C,+EAA+E;YAC/E,6EAA6E;YAC7E,wCAAwC;YACxC,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAA;YACxC,uBAAuB,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventable.d.ts","sourceRoot":"","sources":["../src/eventable.ts"],"names":[],"mappings":"AAwCA,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,aAAa,CAAC,EAAE,GAAG,GAAG,IAAI,CAKrE"}
|
package/lib/eventable.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Eventable Mixin.
|
|
2
|
+
//
|
|
3
|
+
// Simple mixin to add event emitter methods to an object (Publish/Subscribe).
|
|
4
|
+
//
|
|
5
|
+
// Add on, off and notify methods to an object:
|
|
6
|
+
// eventable(obj)
|
|
7
|
+
//
|
|
8
|
+
// publish an event:
|
|
9
|
+
// obj.notify(context, 'action', param1, param2)
|
|
10
|
+
//
|
|
11
|
+
// Optionally pass a context that will be applied to every event:
|
|
12
|
+
// eventable(obj, context)
|
|
13
|
+
//
|
|
14
|
+
// With this publishing can omit the context argument:
|
|
15
|
+
// obj.notify('action', param1, param2)
|
|
16
|
+
//
|
|
17
|
+
// Subscribe to a 'channel'
|
|
18
|
+
// obj.on('action', funtion(param1, param2){ ... })
|
|
19
|
+
//
|
|
20
|
+
// Unsubscribe an individual listener:
|
|
21
|
+
// obj.off('action', method)
|
|
22
|
+
//
|
|
23
|
+
// Unsubscribe all listeners of a channel:
|
|
24
|
+
// obj.off('action')
|
|
25
|
+
//
|
|
26
|
+
// Unsubscribe all listeners of all channels:
|
|
27
|
+
// obj.off()
|
|
28
|
+
export default function eventable(obj, notifyContext) {
|
|
29
|
+
const events = getEventableModule(notifyContext);
|
|
30
|
+
obj.on = events.on;
|
|
31
|
+
obj.off = events.off;
|
|
32
|
+
obj.notify = events.notify;
|
|
33
|
+
}
|
|
34
|
+
function getEventableModule(notifyContext) {
|
|
35
|
+
const listeners = {};
|
|
36
|
+
function addListener(events, listener) {
|
|
37
|
+
events.split(' ').forEach(event => {
|
|
38
|
+
listeners[event] = listeners[event] || [];
|
|
39
|
+
listeners[event].unshift(listener);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function removeListener(event, listener) {
|
|
43
|
+
const eventListeners = listeners[event];
|
|
44
|
+
if (!eventListeners)
|
|
45
|
+
return;
|
|
46
|
+
const index = eventListeners.indexOf(listener);
|
|
47
|
+
if (index < 0)
|
|
48
|
+
return;
|
|
49
|
+
eventListeners.splice(index, 1);
|
|
50
|
+
}
|
|
51
|
+
// Public Methods
|
|
52
|
+
const result = {
|
|
53
|
+
on(eventOrEvents, listener) {
|
|
54
|
+
if (arguments.length === 2 && typeof eventOrEvents === 'string') {
|
|
55
|
+
addListener(eventOrEvents, listener);
|
|
56
|
+
}
|
|
57
|
+
else if (arguments.length === 1 && typeof eventOrEvents === 'object') {
|
|
58
|
+
for (const eventType in eventOrEvents)
|
|
59
|
+
addListener(eventType, eventOrEvents[eventType]);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
},
|
|
63
|
+
off(event, listener) {
|
|
64
|
+
if (arguments.length === 2) {
|
|
65
|
+
removeListener(event, listener);
|
|
66
|
+
}
|
|
67
|
+
else if (arguments.length === 1) {
|
|
68
|
+
listeners[event] = [];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
Object.keys(listeners).forEach(key => delete listeners[key]);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
notify(context, event, ...args) {
|
|
75
|
+
const allArgs = Array.from(arguments);
|
|
76
|
+
let actualContext;
|
|
77
|
+
let actualEvent;
|
|
78
|
+
let actualArgs;
|
|
79
|
+
if (notifyContext) {
|
|
80
|
+
actualEvent = context;
|
|
81
|
+
actualContext = notifyContext;
|
|
82
|
+
actualArgs = allArgs.slice(1);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
actualContext = context;
|
|
86
|
+
actualEvent = event;
|
|
87
|
+
actualArgs = allArgs.slice(2);
|
|
88
|
+
}
|
|
89
|
+
if (result.switchContext) {
|
|
90
|
+
const nextEvent = result.switchContext.events.shift();
|
|
91
|
+
if (actualEvent !== nextEvent)
|
|
92
|
+
result.switchContext = undefined;
|
|
93
|
+
}
|
|
94
|
+
const eventListeners = listeners[actualEvent];
|
|
95
|
+
if (!eventListeners)
|
|
96
|
+
return;
|
|
97
|
+
// Execute the newest listeners first.
|
|
98
|
+
// Stop if a listener returns false.
|
|
99
|
+
eventListeners.every((listener) => listener.apply(actualContext, actualArgs) !== false);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=eventable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventable.js","sourceRoot":"","sources":["../src/eventable.ts"],"names":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AAa,EAAE,CAAC;gBAClB,WAAW,GAAG,OAAO,CAAA;gBACrB,aAAa,GAAG,aAAa,CAAA;gBAC7B,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC/B,CAAC;iBAAM,CAAC;gBACN,aAAa,GAAG,OAAO,CAAA;gBACvB,WAAW,GAAG,KAAK,CAAA;gBACnB,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAC/B,CAAC;YAED,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,MAAM,SAAS,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;gBACrD,IAAI,WAAW,KAAK,SAAS;oBAAE,MAAM,CAAC,aAAa,GAAG,SAAS,CAAA;YACjE,CAAC;YAED,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,CAAC,CAAA;YAC7C,IAAI,CAAC,cAAc;gBAAE,OAAM;YAE3B,sCAAsC;YACtC,oCAAoC;YACpC,cAAc,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,EAAE,UAAU,CAAC,KAAK,KAAK,CAAC,CAAA;QACzF,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check for contenteditable support
|
|
3
|
+
*
|
|
4
|
+
* (from Modernizr)
|
|
5
|
+
* this is known to false positive in some mobile browsers
|
|
6
|
+
* here is a whitelist of verified working browsers:
|
|
7
|
+
* https://github.com/NielsLeenheer/html5test/blob/549f6eac866aa861d9649a0707ff2c0157895706/scripts/engine.js#L2083
|
|
8
|
+
*/
|
|
9
|
+
export declare const contenteditable: boolean;
|
|
10
|
+
export declare const selectionchange: boolean;
|
|
11
|
+
export declare const contenteditableSpanBug: boolean;
|
|
12
|
+
//# sourceMappingURL=feature-detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature-detection.d.ts","sourceRoot":"","sources":["../src/feature-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AACF,eAAO,MAAM,eAAe,SAAkE,CAAA;AA+B9F,eAAO,MAAM,eAAe,SAA4C,CAAA;AAGxE,eAAO,MAAM,sBAAsB,SAAW,CAAA"}
|