@cocreate/text 1.20.16 → 1.20.18
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/CHANGELOG.md +15 -0
- package/CoCreate.config.js +1 -1
- package/package.json +8 -10
- package/src/index.js +106 -106
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## [1.20.18](https://github.com/CoCreate-app/CoCreate-text/compare/v1.20.17...v1.20.18) (2023-06-11)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* renamed db to storage ([6162fb4](https://github.com/CoCreate-app/CoCreate-text/commit/6162fb4a6769b5b4e0b9affd411d4034f41313bf))
|
7
|
+
* renamed hosts to host. the value can be a string or an array of strings ([b3f123e](https://github.com/CoCreate-app/CoCreate-text/commit/b3f123e6480462d716a58f28c5c7bd77924615b3))
|
8
|
+
|
9
|
+
## [1.20.17](https://github.com/CoCreate-app/CoCreate-text/compare/v1.20.16...v1.20.17) (2023-06-10)
|
10
|
+
|
11
|
+
|
12
|
+
### Bug Fixes
|
13
|
+
|
14
|
+
* Update dependencies versions for [@cocreate](https://github.com/cocreate) libraries ([44451b4](https://github.com/CoCreate-app/CoCreate-text/commit/44451b49adef3ef3872ceec9f6c85755f4201f76))
|
15
|
+
|
1
16
|
## [1.20.16](https://github.com/CoCreate-app/CoCreate-text/compare/v1.20.15...v1.20.16) (2023-06-10)
|
2
17
|
|
3
18
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/text",
|
3
|
-
"version": "1.20.
|
3
|
+
"version": "1.20.18",
|
4
4
|
"description": "A simple text component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
5
5
|
"keywords": [
|
6
6
|
"text",
|
@@ -27,7 +27,6 @@
|
|
27
27
|
"start": "npx webpack --config webpack.config.js",
|
28
28
|
"build": "NODE_ENV=production npx webpack --config webpack.config.js",
|
29
29
|
"dev": "npx webpack --config webpack.config.js --watch",
|
30
|
-
"docs": "node ./node_modules/@cocreate/docs/src/index.js",
|
31
30
|
"postinstall": "node ./node_modules/@cocreate/cli/check-coc.js"
|
32
31
|
},
|
33
32
|
"repository": {
|
@@ -60,14 +59,13 @@
|
|
60
59
|
"webpack-log": "^3.0.1"
|
61
60
|
},
|
62
61
|
"dependencies": {
|
63
|
-
"@cocreate/actions": "^1.8.
|
62
|
+
"@cocreate/actions": "^1.8.19",
|
64
63
|
"@cocreate/crdt": "^1.18.15",
|
65
|
-
"@cocreate/crud-client": "^1.21.
|
66
|
-
"@cocreate/cursors": "^1.16.
|
67
|
-
"@cocreate/
|
68
|
-
"@cocreate/
|
69
|
-
"@cocreate/
|
70
|
-
"@cocreate/
|
71
|
-
"@cocreate/uuid": "^1.4.15"
|
64
|
+
"@cocreate/crud-client": "^1.21.11",
|
65
|
+
"@cocreate/cursors": "^1.16.16",
|
66
|
+
"@cocreate/observer": "^1.8.6",
|
67
|
+
"@cocreate/selection": "^1.6.15",
|
68
|
+
"@cocreate/utils": "^1.21.4",
|
69
|
+
"@cocreate/uuid": "^1.4.16"
|
72
70
|
}
|
73
71
|
}
|
package/src/index.js
CHANGED
@@ -4,9 +4,9 @@ import crud from '@cocreate/crud-client';
|
|
4
4
|
import crdt from '@cocreate/crdt';
|
5
5
|
import cursors from '@cocreate/cursors';
|
6
6
|
import uuid from '@cocreate/uuid';
|
7
|
-
import {updateDom} from './updateDom';
|
8
|
-
import {insertAdjacentElement, removeElement, setInnerText, setAttribute, removeAttribute, setClass, setStyle, replaceInnerText} from './updateText';
|
9
|
-
import {getSelection, processSelection} from '@cocreate/selection';
|
7
|
+
import { updateDom } from './updateDom';
|
8
|
+
import { insertAdjacentElement, removeElement, setInnerText, setAttribute, removeAttribute, setClass, setStyle, replaceInnerText } from './updateText';
|
9
|
+
import { getSelection, processSelection } from '@cocreate/selection';
|
10
10
|
import action from '@cocreate/actions';
|
11
11
|
import './saveDomText';
|
12
12
|
|
@@ -21,48 +21,48 @@ function init() {
|
|
21
21
|
initDocument(document);
|
22
22
|
}
|
23
23
|
|
24
|
-
function initElements
|
25
|
-
for(let element of elements)
|
24
|
+
function initElements(elements) {
|
25
|
+
for (let element of elements)
|
26
26
|
initElement(element);
|
27
27
|
}
|
28
28
|
|
29
|
-
function initElement
|
30
|
-
let { collection, document_id, name, isRealtime, isCrdt, isCrud, isSave, isRead } = crud.getAttributes(element);
|
29
|
+
function initElement(element) {
|
30
|
+
let { collection, document_id, name, isRealtime, isCrdt, isCrud, isSave, isRead } = crud.getAttributes(element);
|
31
31
|
if (!collection || !document_id || !name)
|
32
32
|
return
|
33
33
|
if (document_id == 'pending') {
|
34
|
-
|
35
|
-
|
34
|
+
element.pendingDocument = true
|
35
|
+
return
|
36
36
|
}
|
37
|
-
if (['_id', 'organization_id', '
|
37
|
+
if (['_id', 'organization_id', 'storage', 'database', 'collection'].includes(name))
|
38
|
+
return
|
39
|
+
if (isCrdt == "false" || isRealtime == "false" || element.type == 'number')
|
38
40
|
return
|
39
|
-
if (
|
41
|
+
if (!crud.checkValue(collection) || !crud.checkValue(document_id) || !crud.checkValue(name))
|
40
42
|
return
|
41
|
-
if (!crud.checkValue(collection) || !crud.checkValue(document_id)|| !crud.checkValue(name))
|
42
|
-
return
|
43
43
|
if (name && name.startsWith("$"))
|
44
44
|
return
|
45
45
|
|
46
46
|
if (element.tagName === "INPUT" && ["text", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA" || element.hasAttribute('contenteditable')) {
|
47
47
|
|
48
48
|
if (!isCrdt) {
|
49
|
-
if (element.tagName == 'IFRAME'){
|
49
|
+
if (element.tagName == 'IFRAME') {
|
50
50
|
if (isCrdt != 'true')
|
51
51
|
_addEventListeners(element.contentDocument.documentElement);
|
52
52
|
let Document = element.contentDocument;
|
53
53
|
initDocument(Document);
|
54
|
-
}
|
55
|
-
else if (isCrdt != 'true'){
|
54
|
+
}
|
55
|
+
else if (isCrdt != 'true') {
|
56
56
|
_addEventListeners(element);
|
57
57
|
}
|
58
|
-
}
|
58
|
+
}
|
59
59
|
element.setAttribute('crdt', 'true');
|
60
|
-
element.crdt = {init: true};
|
60
|
+
element.crdt = { init: true };
|
61
61
|
|
62
62
|
// TODO: newDocument name consideration. its value is used for setting or overwriting existing value
|
63
63
|
let newDocument = ''
|
64
64
|
if (element.pendingDocument) {
|
65
|
-
|
65
|
+
|
66
66
|
let value;
|
67
67
|
if (element.hasAttribute('contenteditable'))
|
68
68
|
value = element.innerHTML;
|
@@ -72,19 +72,19 @@ function initElement (element) {
|
|
72
72
|
newDocument = value
|
73
73
|
|
74
74
|
delete element.pendingDocument
|
75
|
-
|
76
|
-
|
75
|
+
}
|
76
|
+
|
77
77
|
crdt.getText({ collection, document_id, name, crud: isCrud, save: isSave, read: isRead, newDocument }).then(response => {
|
78
|
-
if (response === undefined)
|
78
|
+
if (response === undefined)
|
79
79
|
return;
|
80
|
-
if (!response){
|
80
|
+
if (!response) {
|
81
81
|
// if (element.pendingDocument) {
|
82
82
|
// isRead = 'true'
|
83
83
|
// delete element.pendingDocument
|
84
84
|
// }
|
85
|
-
|
85
|
+
|
86
86
|
let value;
|
87
|
-
if (element.hasAttribute('contenteditable')){
|
87
|
+
if (element.hasAttribute('contenteditable')) {
|
88
88
|
value = element.innerHTML;
|
89
89
|
}
|
90
90
|
else {
|
@@ -94,7 +94,7 @@ function initElement (element) {
|
|
94
94
|
crdt.replaceText({ collection, document_id, name, value, crud: isCrud, save: isSave, read: isRead });
|
95
95
|
}
|
96
96
|
else {
|
97
|
-
if (element.hasAttribute('contenteditable')){
|
97
|
+
if (element.hasAttribute('contenteditable')) {
|
98
98
|
element.innerHTML = '';
|
99
99
|
}
|
100
100
|
else {
|
@@ -110,15 +110,15 @@ function initDocument(doc) {
|
|
110
110
|
let documents;
|
111
111
|
try {
|
112
112
|
documents = window.top.textDocuments;
|
113
|
-
} catch(e) {
|
113
|
+
} catch (e) {
|
114
114
|
console.log('cross-origin failed')
|
115
115
|
}
|
116
116
|
|
117
|
-
if (!documents){
|
117
|
+
if (!documents) {
|
118
118
|
documents = new Map();
|
119
119
|
try {
|
120
120
|
window.top.textDocuments = documents;
|
121
|
-
} catch(e) {
|
121
|
+
} catch (e) {
|
122
122
|
console.log('cross-origin failed')
|
123
123
|
}
|
124
124
|
}
|
@@ -127,11 +127,11 @@ function initDocument(doc) {
|
|
127
127
|
doc.addEventListener('selectionchange', (e) => {
|
128
128
|
let element = doc.activeElement;
|
129
129
|
sendPosition(element);
|
130
|
-
});
|
130
|
+
});
|
131
131
|
}
|
132
132
|
}
|
133
133
|
|
134
|
-
export function _addEventListeners
|
134
|
+
export function _addEventListeners(element) {
|
135
135
|
element.addEventListener('mousedown', _mousedown);
|
136
136
|
element.addEventListener('blur', _blur);
|
137
137
|
element.addEventListener('cut', _cut);
|
@@ -141,24 +141,24 @@ export function _addEventListeners (element) {
|
|
141
141
|
element.addEventListener('input', _input);
|
142
142
|
}
|
143
143
|
|
144
|
-
function _mousedown
|
144
|
+
function _mousedown(event) {
|
145
145
|
let domTextEditor = event.currentTarget;
|
146
146
|
if (domTextEditor.tagName === "INPUT" || domTextEditor.tagName === "TEXTAREA") return;
|
147
147
|
let target = event.target;
|
148
148
|
// const path = event.path || (event.composedPath && event.composedPath());
|
149
149
|
// console.log(path)
|
150
|
-
|
150
|
+
if (!target.id) {
|
151
151
|
let isEid = domTextEditor.getAttribute('eid');
|
152
|
-
|
152
|
+
if (isEid != 'false' && isEid != null && isEid != undefined) {
|
153
153
|
let eid = target.getAttribute('eid');
|
154
|
-
if (!eid){
|
154
|
+
if (!eid) {
|
155
155
|
eid = uuid.generate(6);
|
156
156
|
setAttribute({ domTextEditor, target, name: 'eid', value: eid });
|
157
157
|
}
|
158
158
|
}
|
159
|
-
|
160
|
-
|
161
|
-
|
159
|
+
}
|
160
|
+
let contentEditable = target.closest('[collection][document_id][name]');
|
161
|
+
if (contentEditable) {
|
162
162
|
target = contentEditable;
|
163
163
|
const { collection, document_id, name } = crud.getAttributes(target);
|
164
164
|
if (collection && document_id && name && !target.hasAttribute('contenteditable'))
|
@@ -167,15 +167,15 @@ function _mousedown (event) {
|
|
167
167
|
// sendPosition(element)
|
168
168
|
}
|
169
169
|
|
170
|
-
function _blur
|
170
|
+
function _blur(event) {
|
171
171
|
let element = event.currentTarget;
|
172
172
|
const { collection, document_id, name } = crud.getAttributes(element);
|
173
173
|
let start = null;
|
174
174
|
let end = null;
|
175
|
-
cursors.sendPosition({collection, document_id, name, start, end});
|
175
|
+
cursors.sendPosition({ collection, document_id, name, start, end });
|
176
176
|
}
|
177
177
|
|
178
|
-
function _cut
|
178
|
+
function _cut(event) {
|
179
179
|
let element = event.currentTarget;
|
180
180
|
if (element.getAttribute('crdt') == 'false')
|
181
181
|
return;
|
@@ -186,32 +186,32 @@ function _cut (event) {
|
|
186
186
|
event.clipboardData.setData('text/plain', selection.toString());
|
187
187
|
}
|
188
188
|
else {
|
189
|
-
navigator.clipboard.writeText(selection.toString()).then(function() {
|
190
|
-
|
191
|
-
}, function() {
|
192
|
-
|
189
|
+
navigator.clipboard.writeText(selection.toString()).then(function () {
|
190
|
+
/* clipboard successfully set */
|
191
|
+
}, function () {
|
192
|
+
/* clipboard write failed */
|
193
193
|
});
|
194
194
|
}
|
195
195
|
if (start != end) {
|
196
|
-
updateText({element, start, end, range});
|
196
|
+
updateText({ element, start, end, range });
|
197
197
|
}
|
198
198
|
event.preventDefault();
|
199
199
|
}
|
200
200
|
|
201
|
-
function _paste
|
201
|
+
function _paste(event) {
|
202
202
|
let element = event.currentTarget;
|
203
203
|
if (element.getAttribute('crdt') == 'false')
|
204
204
|
return;
|
205
205
|
let value = event.clipboardData.getData('text/plain').replace(/(\r\n|\r)/gm, "\n");;
|
206
206
|
const { start, end, range } = getSelection(element);
|
207
207
|
if (start != end) {
|
208
|
-
updateText({element, start, end, range});
|
208
|
+
updateText({ element, start, end, range });
|
209
209
|
}
|
210
|
-
updateText({element, value, start, range});
|
210
|
+
updateText({ element, value, start, range });
|
211
211
|
event.preventDefault();
|
212
212
|
}
|
213
213
|
|
214
|
-
function _keydown
|
214
|
+
function _keydown(event) {
|
215
215
|
if (event.stopCCText) return;
|
216
216
|
let element = event.currentTarget;
|
217
217
|
if (element.getAttribute('crdt') == 'false')
|
@@ -220,31 +220,31 @@ function _keydown (event) {
|
|
220
220
|
if (event.key == "Backspace" || event.key == "Tab" || event.key == "Enter") {
|
221
221
|
eventObj = event;
|
222
222
|
if (start != end) {
|
223
|
-
updateText({element, start, end, range});
|
223
|
+
updateText({ element, start, end, range });
|
224
224
|
}
|
225
|
-
|
225
|
+
|
226
226
|
if (event.key == "Backspace" && start == end) {
|
227
|
-
updateText({element, start: start - 1, end, range});
|
227
|
+
updateText({ element, start: start - 1, end, range });
|
228
228
|
}
|
229
229
|
else if (event.key == 'Tab') {
|
230
|
-
updateText({element, value: "\t", start, range});
|
230
|
+
updateText({ element, value: "\t", start, range });
|
231
231
|
}
|
232
232
|
else if (event.key == "Enter") {
|
233
|
-
updateText({element, value: "\n", start, range});
|
233
|
+
updateText({ element, value: "\n", start, range });
|
234
234
|
}
|
235
235
|
event.preventDefault();
|
236
236
|
}
|
237
237
|
else if (event.ctrlKey) {
|
238
238
|
if (event.keyCode == 90) {
|
239
|
-
updateText({element, range, undoRedo: 'undo'});
|
239
|
+
updateText({ element, range, undoRedo: 'undo' });
|
240
240
|
}
|
241
241
|
else if (event.keyCode == 89) {
|
242
|
-
updateText({element, range, undoRedo: 'redo'});
|
242
|
+
updateText({ element, range, undoRedo: 'redo' });
|
243
243
|
}
|
244
244
|
}
|
245
245
|
}
|
246
246
|
|
247
|
-
function _beforeinput
|
247
|
+
function _beforeinput(event) {
|
248
248
|
if (event.stopCCText) return;
|
249
249
|
let element = event.currentTarget;
|
250
250
|
if (element.getAttribute('crdt') == 'false')
|
@@ -252,22 +252,22 @@ function _beforeinput (event) {
|
|
252
252
|
let { start, end, range } = getSelection(element);
|
253
253
|
if (event.data) {
|
254
254
|
if (start != end) {
|
255
|
-
updateText({element, start, end, range});
|
255
|
+
updateText({ element, start, end, range });
|
256
256
|
}
|
257
257
|
eventObj = event;
|
258
|
-
updateText({element, value: event.data, start, range});
|
258
|
+
updateText({ element, value: event.data, start, range });
|
259
259
|
event.preventDefault();
|
260
260
|
}
|
261
261
|
}
|
262
262
|
|
263
|
-
function _input
|
263
|
+
function _input(event) {
|
264
264
|
if (event.stopCCText) return;
|
265
265
|
if (event.data) {
|
266
266
|
eventObj = event;
|
267
267
|
}
|
268
268
|
}
|
269
269
|
|
270
|
-
function _removeEventListeners
|
270
|
+
function _removeEventListeners(element) {
|
271
271
|
element.removeEventListener('mousedown', _mousedown);
|
272
272
|
element.removeEventListener('blur', _blur);
|
273
273
|
element.removeEventListener('cut', _cut);
|
@@ -278,11 +278,11 @@ function _removeEventListeners (element) {
|
|
278
278
|
}
|
279
279
|
|
280
280
|
let previousPosition = {};
|
281
|
-
export function sendPosition
|
281
|
+
export function sendPosition(element) {
|
282
282
|
// if (!element) return;
|
283
283
|
const { start, end, range } = getSelection(element);
|
284
284
|
if (range) {
|
285
|
-
if (range.element){
|
285
|
+
if (range.element) {
|
286
286
|
element = range.element;
|
287
287
|
}
|
288
288
|
if (element.tagName == 'HTML' && !element.hasAttribute('collection') || !element.hasAttribute('collection')) {
|
@@ -301,17 +301,17 @@ export function sendPosition (element) {
|
|
301
301
|
cursors.sendPosition({ collection, document_id, name, start, end });
|
302
302
|
}
|
303
303
|
|
304
|
-
function updateText
|
304
|
+
function updateText({ element, value, start, end, range, undoRedo }) {
|
305
305
|
if (range) {
|
306
306
|
if (range.element)
|
307
307
|
element = range.element;
|
308
|
-
|
309
|
-
if (element.tagName == 'HTML' && !element.hasAttribute('collection'))
|
308
|
+
|
309
|
+
if (element.tagName == 'HTML' && !element.hasAttribute('collection'))
|
310
310
|
element = element.ownerDocument.defaultView.frameElement;
|
311
311
|
}
|
312
312
|
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttributes(element);
|
313
313
|
if (isCrdt == "false" || !collection || !document_id || !name) return;
|
314
|
-
|
314
|
+
|
315
315
|
if (undoRedo == 'undo')
|
316
316
|
return crdt.undoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
317
317
|
if (undoRedo == 'redo')
|
@@ -321,38 +321,38 @@ function updateText ({element, value, start, end, range, undoRedo}) {
|
|
321
321
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
322
322
|
crdt.updateText({ collection, document_id, name, value, start, length, crud: isCrud, save: isSave });
|
323
323
|
} else {
|
324
|
-
let startEl =
|
325
|
-
let endEl =
|
324
|
+
let startEl = range.startContainer.parentElement;
|
325
|
+
let endEl = range.endContainer.parentElement;
|
326
326
|
if (startEl != endEl) {
|
327
|
-
|
328
|
-
|
329
|
-
|
327
|
+
// target = range.commonAncestorContainer;
|
328
|
+
// // value = target.innerHTML;
|
329
|
+
// // replaceInnerText(domTextEditor, target, value)
|
330
330
|
}
|
331
331
|
crdt.updateText({ collection, document_id, value, name, start, length, crud: isCrud, save: isSave });
|
332
332
|
}
|
333
333
|
}
|
334
334
|
|
335
|
-
function _crdtUpdateListener
|
336
|
-
window.addEventListener('cocreate-crdt-update', function(event) {
|
337
|
-
updateElements({...event.detail});
|
335
|
+
function _crdtUpdateListener() {
|
336
|
+
window.addEventListener('cocreate-crdt-update', function (event) {
|
337
|
+
updateElements({ ...event.detail });
|
338
338
|
});
|
339
339
|
}
|
340
340
|
|
341
|
-
function updateElements({elements, collection, document_id, name, value, start, length, string}){
|
342
|
-
if (!elements){
|
341
|
+
function updateElements({ elements, collection, document_id, name, value, start, length, string }) {
|
342
|
+
if (!elements) {
|
343
343
|
let selectors = `[collection='${collection}'][document_id='${document_id}'][name='${name}']`;
|
344
344
|
elements = document.querySelectorAll(`input${selectors}, textarea${selectors}, [contenteditable]${selectors}, [editor='dom']${selectors}`);
|
345
345
|
}
|
346
|
-
|
346
|
+
|
347
347
|
elements.forEach((element) => {
|
348
348
|
let isCrdt = element.getAttribute('crdt');
|
349
349
|
if (!element.hasAttribute('contenteditable') && isCrdt == 'false') return;
|
350
350
|
|
351
|
-
updateElement({element, collection, document_id, name, value, start, length, string});
|
351
|
+
updateElement({ element, collection, document_id, name, value, start, length, string });
|
352
352
|
});
|
353
353
|
}
|
354
354
|
|
355
|
-
async function updateElement
|
355
|
+
async function updateElement({ element, collection, document_id, name, value, start, length, string }) {
|
356
356
|
if (element.tagName == 'IFRAME') {
|
357
357
|
let eid = element.getAttribute('eid')
|
358
358
|
element = element.contentDocument.documentElement;
|
@@ -369,26 +369,26 @@ async function updateElement ({element, collection, document_id, name, value, st
|
|
369
369
|
if (value) {
|
370
370
|
_updateElementText(element, value, start, start);
|
371
371
|
}
|
372
|
-
}
|
372
|
+
}
|
373
373
|
else {
|
374
|
-
|
374
|
+
let domTextEditor = element;
|
375
375
|
if (string == undefined)
|
376
|
-
string = await crdt.getText({collection, document_id, name});
|
376
|
+
string = await crdt.getText({ collection, document_id, name });
|
377
377
|
let html = string;
|
378
|
-
|
378
|
+
if (length) {
|
379
379
|
let end = start + length;
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
380
|
+
updateDom({ domTextEditor, start, end, html });
|
381
|
+
}
|
382
|
+
if (value) {
|
383
|
+
if (element.innerHTML != value) {
|
384
|
+
updateDom({ domTextEditor, value, start, end: start, html });
|
385
|
+
}
|
386
|
+
}
|
387
387
|
}
|
388
388
|
}
|
389
389
|
}
|
390
390
|
|
391
|
-
function _updateElementText
|
391
|
+
function _updateElementText(element, value, start, end) {
|
392
392
|
if (element.tagName === "INPUT" && ["text", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA") {
|
393
393
|
let prev_start = element.selectionStart;
|
394
394
|
let prev_end = element.selectionEnd;
|
@@ -402,7 +402,7 @@ function _updateElementText (element, value, start, end) {
|
|
402
402
|
}
|
403
403
|
|
404
404
|
export function _dispatchInputEvent(element, content, start, end, prev_start, prev_end) {
|
405
|
-
let detail = {value: content, start, end, prev_start, prev_end, skip: true};
|
405
|
+
let detail = { value: content, start, end, prev_start, prev_end, skip: true };
|
406
406
|
let activeElement = element.ownerDocument.activeElement;
|
407
407
|
if (activeElement == element)
|
408
408
|
detail.skip = false;
|
@@ -412,7 +412,7 @@ export function _dispatchInputEvent(element, content, start, end, prev_start, pr
|
|
412
412
|
Object.defineProperty(event, 'target', { writable: false, value: element });
|
413
413
|
Object.defineProperty(event, 'detail', { writable: false, value: detail });
|
414
414
|
element.dispatchEvent(event);
|
415
|
-
}
|
415
|
+
}
|
416
416
|
let inputEvent = new CustomEvent('input', { bubbles: true });
|
417
417
|
Object.defineProperty(inputEvent, 'stopCCText', { writable: false, value: true });
|
418
418
|
Object.defineProperty(inputEvent, 'target', { writable: false, value: element });
|
@@ -424,7 +424,7 @@ observer.init({
|
|
424
424
|
name: 'CoCreateTextAddedNodes',
|
425
425
|
observe: ['addedNodes'],
|
426
426
|
target: selectors,
|
427
|
-
callback
|
427
|
+
callback(mutation) {
|
428
428
|
let isCrdt = mutation.target.getAttribute('crdt');
|
429
429
|
if (isCrdt) return;
|
430
430
|
initElement(mutation.target);
|
@@ -436,7 +436,7 @@ observer.init({
|
|
436
436
|
observe: ['attributes'],
|
437
437
|
attributeName: [...crud.getAttributeNames(['collection', 'document_id', 'name']), 'contenteditable'],
|
438
438
|
target: selectors,
|
439
|
-
callback
|
439
|
+
callback(mutation) {
|
440
440
|
let _id = mutation.target.getAttribute('document_id')
|
441
441
|
if (!_id) {
|
442
442
|
_removeEventListeners(mutation.target)
|
@@ -448,23 +448,23 @@ observer.init({
|
|
448
448
|
});
|
449
449
|
|
450
450
|
action.init({
|
451
|
-
|
452
|
-
|
453
|
-
|
451
|
+
name: "undo",
|
452
|
+
endEvent: "undo",
|
453
|
+
callback: (btn, data) => {
|
454
454
|
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttributes(btn);
|
455
455
|
crdt.undoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
456
|
-
|
456
|
+
}
|
457
457
|
});
|
458
458
|
|
459
459
|
action.init({
|
460
|
-
|
461
|
-
|
462
|
-
|
460
|
+
name: "redo",
|
461
|
+
endEvent: "redo",
|
462
|
+
callback: (btn, data) => {
|
463
463
|
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttributes(btn);
|
464
464
|
crdt.redoText({ collection, document_id, name, isCrud, isCrdt, isSave })
|
465
|
-
|
465
|
+
}
|
466
466
|
});
|
467
467
|
|
468
468
|
init();
|
469
469
|
|
470
|
-
export default {initElements, initElement, updateText, updateElement, _addEventListeners, insertAdjacentElement, removeElement, setInnerText, setAttribute, removeAttribute, setClass, setStyle, replaceInnerText};
|
470
|
+
export default { initElements, initElement, updateText, updateElement, _addEventListeners, insertAdjacentElement, removeElement, setInnerText, setAttribute, removeAttribute, setClass, setStyle, replaceInnerText };
|