@livingdocs/editable.js 5.0.10 → 5.0.11
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/editable.js +1 -1
- package/dist/editable.js.map +1 -1
- package/package.json +4 -4
- package/src/dispatcher.js +6 -41
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livingdocs/editable.js",
|
|
3
3
|
"description": "Friendly contenteditable API",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.11",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@babel/runtime": "^7.16.7",
|
|
7
7
|
"lodash-es": "^4.17.21"
|
|
@@ -82,11 +82,11 @@
|
|
|
82
82
|
"isCi": true,
|
|
83
83
|
"name": "Drone",
|
|
84
84
|
"service": "drone",
|
|
85
|
-
"commit": "
|
|
86
|
-
"build": "
|
|
85
|
+
"commit": "85675583caacbfd2acf2577f7e7d170992627f60",
|
|
86
|
+
"build": "1700",
|
|
87
87
|
"branch": "master",
|
|
88
88
|
"isPr": false,
|
|
89
89
|
"slug": "livingdocsIO/editable.js",
|
|
90
|
-
"date": "2024-07-
|
|
90
|
+
"date": "2024-07-22T15:51:53.699Z"
|
|
91
91
|
}
|
|
92
92
|
}
|
package/src/dispatcher.js
CHANGED
|
@@ -7,11 +7,6 @@ import Keyboard from './keyboard.js'
|
|
|
7
7
|
import {closest} from './util/dom.js'
|
|
8
8
|
import {replaceLast, endsWithSingleSpace} from './util/string.js'
|
|
9
9
|
|
|
10
|
-
// This will be set to true once we detect the input event is working.
|
|
11
|
-
// Input event description on MDN:
|
|
12
|
-
// https://developer.mozilla.org/en-US/docs/Web/Reference/Events/input
|
|
13
|
-
let isInputEventSupported = false
|
|
14
|
-
|
|
15
10
|
/**
|
|
16
11
|
* The Dispatcher module is responsible for dealing with events and their handlers.
|
|
17
12
|
*
|
|
@@ -23,7 +18,6 @@ export default class Dispatcher {
|
|
|
23
18
|
constructor (editable) {
|
|
24
19
|
const win = editable.win
|
|
25
20
|
eventable(this, editable)
|
|
26
|
-
this.supportsInputEvent = false
|
|
27
21
|
this.document = win.document
|
|
28
22
|
this.config = editable.config
|
|
29
23
|
this.editable = editable
|
|
@@ -122,7 +116,6 @@ export default class Dispatcher {
|
|
|
122
116
|
const selection = this.selectionWatcher.getFreshSelection()
|
|
123
117
|
if (selection && selection.isSelection) {
|
|
124
118
|
this.notify('clipboard', block, 'cut', selection)
|
|
125
|
-
this.triggerChangeEvent(block)
|
|
126
119
|
}
|
|
127
120
|
})
|
|
128
121
|
.setupDocumentListener('paste', function pasteListener (evt) {
|
|
@@ -151,14 +144,7 @@ export default class Dispatcher {
|
|
|
151
144
|
.setupDocumentListener('input', function inputListener (evt) {
|
|
152
145
|
const block = this.getEditableBlockByEvent(evt)
|
|
153
146
|
if (!block) return
|
|
154
|
-
|
|
155
|
-
this.notify('change', block)
|
|
156
|
-
} else {
|
|
157
|
-
// Most likely the event was already handled manually by
|
|
158
|
-
// triggerChangeEvent so the first time we just switch the
|
|
159
|
-
// isInputEventSupported flag without notifying the change event.
|
|
160
|
-
isInputEventSupported = true
|
|
161
|
-
}
|
|
147
|
+
this.notify('change', block)
|
|
162
148
|
})
|
|
163
149
|
|
|
164
150
|
.setupDocumentListener('formatEditable', function formatEditableListener (evt) {
|
|
@@ -168,26 +154,6 @@ export default class Dispatcher {
|
|
|
168
154
|
})
|
|
169
155
|
}
|
|
170
156
|
|
|
171
|
-
/**
|
|
172
|
-
* Trigger a change event
|
|
173
|
-
*
|
|
174
|
-
* This should be done in these cases:
|
|
175
|
-
* - typing a letter
|
|
176
|
-
* - delete (backspace and delete keys)
|
|
177
|
-
* - cut
|
|
178
|
-
* - paste
|
|
179
|
-
* - copy and paste (not easily possible manually as far as I know)
|
|
180
|
-
*
|
|
181
|
-
* Preferably this is done using the input event. But the input event is not
|
|
182
|
-
* supported on all browsers for contenteditable elements.
|
|
183
|
-
* To make things worse it is not detectable either. So instead of detecting
|
|
184
|
-
* we set 'isInputEventSupported' when the input event fires the first time.
|
|
185
|
-
*/
|
|
186
|
-
triggerChangeEvent (target) {
|
|
187
|
-
if (isInputEventSupported) return
|
|
188
|
-
this.notify('change', target)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
157
|
dispatchSwitchEvent (event, element, direction) {
|
|
192
158
|
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return
|
|
193
159
|
const cursor = this.selectionWatcher.getFreshSelection()
|
|
@@ -228,8 +194,7 @@ export default class Dispatcher {
|
|
|
228
194
|
this.setupDocumentListener('keydown', function (evt) {
|
|
229
195
|
const block = this.getEditableBlockByEvent(evt)
|
|
230
196
|
if (!block) return
|
|
231
|
-
|
|
232
|
-
this.keyboard.dispatchKeyEvent(evt, block, notifyCharacterEvent)
|
|
197
|
+
this.keyboard.dispatchKeyEvent(evt, block, false)
|
|
233
198
|
}, true)
|
|
234
199
|
}
|
|
235
200
|
|
|
@@ -253,10 +218,10 @@ export default class Dispatcher {
|
|
|
253
218
|
|
|
254
219
|
.on('backspace', function (event) {
|
|
255
220
|
const rangeContainer = self.selectionWatcher.getFreshRange()
|
|
256
|
-
if (!rangeContainer.isCursor) return
|
|
221
|
+
if (!rangeContainer.isCursor) return
|
|
257
222
|
|
|
258
223
|
const cursor = rangeContainer.getCursor()
|
|
259
|
-
if (!cursor.isAtBeginning()) return
|
|
224
|
+
if (!cursor.isAtBeginning()) return
|
|
260
225
|
|
|
261
226
|
event.preventDefault()
|
|
262
227
|
event.stopPropagation()
|
|
@@ -265,10 +230,10 @@ export default class Dispatcher {
|
|
|
265
230
|
|
|
266
231
|
.on('delete', function (event) {
|
|
267
232
|
const rangeContainer = self.selectionWatcher.getFreshRange()
|
|
268
|
-
if (!rangeContainer.isCursor) return
|
|
233
|
+
if (!rangeContainer.isCursor) return
|
|
269
234
|
|
|
270
235
|
const cursor = rangeContainer.getCursor()
|
|
271
|
-
if (!cursor.isAtTextEnd()) return
|
|
236
|
+
if (!cursor.isAtTextEnd()) return
|
|
272
237
|
|
|
273
238
|
event.preventDefault()
|
|
274
239
|
event.stopPropagation()
|