@cocreate/text 1.15.10 → 1.15.13
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 +21 -0
- package/package.json +1 -1
- package/src/index.js +49 -35
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## [1.15.13](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.12...v1.15.13) (2022-03-22)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* removed emit from message.send and message.listen ([b672bb5](https://github.com/CoCreate-app/CoCreate-text/commit/b672bb57ee7005a0d1933bd014c079a6faa96cbd))
|
7
|
+
|
8
|
+
## [1.15.12](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.11...v1.15.12) (2022-03-21)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* string formating differs between various OS \r\n and \r are replaced with \n ([87b0183](https://github.com/CoCreate-app/CoCreate-text/commit/87b018354240d6f25b57fb9fc272f52103c4072c))
|
14
|
+
|
15
|
+
## [1.15.11](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.10...v1.15.11) (2022-03-07)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* if crdt=false return before event prevent default for crud ([342411c](https://github.com/CoCreate-app/CoCreate-text/commit/342411c4ec654b554e9d92e071a932d1155cec09))
|
21
|
+
|
1
22
|
## [1.15.10](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.9...v1.15.10) (2022-02-24)
|
2
23
|
|
3
24
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -27,11 +27,11 @@ function initElements (elements) {
|
|
27
27
|
|
28
28
|
function initElement (element) {
|
29
29
|
const { collection, document_id, name, isRealtime, isCrdt, isCrud, isSave, isRead } = crud.getAttr(element);
|
30
|
-
if(document_id == "pending") return;
|
31
|
-
if(isCrdt == "false" || isRealtime == "false" || element.type == 'number' || name == '_id') return;
|
32
|
-
if(!crud.checkAttrValue(collection) || !crud.checkAttrValue(document_id)) return;
|
33
|
-
if(element.tagName === "INPUT" && ["text", "email", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA" || element.hasAttribute('contenteditable')) {
|
34
|
-
if(!collection || !document_id || !name) return;
|
30
|
+
if (document_id == "pending") return;
|
31
|
+
if (isCrdt == "false" || isRealtime == "false" || element.type == 'number' || name == '_id') return;
|
32
|
+
if (!crud.checkAttrValue(collection) || !crud.checkAttrValue(document_id)) return;
|
33
|
+
if (element.tagName === "INPUT" && ["text", "email", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA" || element.hasAttribute('contenteditable')) {
|
34
|
+
if (!collection || !document_id || !name) return;
|
35
35
|
|
36
36
|
if (!isCrdt) {
|
37
37
|
if (element.tagName == 'IFRAME'){
|
@@ -47,7 +47,7 @@ function initElement (element) {
|
|
47
47
|
element.setAttribute('crdt', 'true');
|
48
48
|
element.crdt = {init: true};
|
49
49
|
crdt.getText({ collection, document_id, name, crud: isCrud, save: isSave, read: isRead }).then(response => {
|
50
|
-
if(response === undefined)
|
50
|
+
if (response === undefined)
|
51
51
|
return;
|
52
52
|
if (!response){
|
53
53
|
let value;
|
@@ -111,12 +111,15 @@ function _mousedown (event) {
|
|
111
111
|
let target = event.target;
|
112
112
|
// const path = event.path || (event.composedPath && event.composedPath());
|
113
113
|
// console.log(path)
|
114
|
-
if(!target.id){
|
115
|
-
|
116
|
-
if(
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
if (!target.id){
|
115
|
+
let isEid = domTextEditor.getAttribute('eid');
|
116
|
+
if (isEid != 'false' && isEid != null && isEid != undefined){
|
117
|
+
let eid = target.getAttribute('eid');
|
118
|
+
if (!eid){
|
119
|
+
eid = uuid.generate(6);
|
120
|
+
setAttribute({ domTextEditor, target, name: 'eid', value: eid });
|
121
|
+
}
|
122
|
+
}
|
120
123
|
}
|
121
124
|
let contentEditable = target.closest('[collection][document_id][name]');
|
122
125
|
if (contentEditable){
|
@@ -138,6 +141,8 @@ function _blur (event) {
|
|
138
141
|
|
139
142
|
function _cut (event) {
|
140
143
|
let element = event.currentTarget;
|
144
|
+
if (element.getAttribute('crdt') == 'false')
|
145
|
+
return;
|
141
146
|
const { start, end, range } = getSelection(element);
|
142
147
|
const selection = document.getSelection();
|
143
148
|
console.log(selection.toString());
|
@@ -151,7 +156,7 @@ function _cut (event) {
|
|
151
156
|
/* clipboard write failed */
|
152
157
|
});
|
153
158
|
}
|
154
|
-
if(start != end) {
|
159
|
+
if (start != end) {
|
155
160
|
updateText({element, start, end, range});
|
156
161
|
}
|
157
162
|
event.preventDefault();
|
@@ -159,9 +164,11 @@ function _cut (event) {
|
|
159
164
|
|
160
165
|
function _paste (event) {
|
161
166
|
let element = event.currentTarget;
|
162
|
-
|
167
|
+
if (element.getAttribute('crdt') == 'false')
|
168
|
+
return;
|
169
|
+
let value = event.clipboardData.getData('text/plain').replace(/(\r\n|\r)/gm, "\n");;
|
163
170
|
const { start, end, range } = getSelection(element);
|
164
|
-
if(start != end) {
|
171
|
+
if (start != end) {
|
165
172
|
updateText({element, start, end, range});
|
166
173
|
}
|
167
174
|
updateText({element, value, start, range});
|
@@ -169,22 +176,24 @@ function _paste (event) {
|
|
169
176
|
}
|
170
177
|
|
171
178
|
function _keydown (event) {
|
172
|
-
if(event.stopCCText) return;
|
179
|
+
if (event.stopCCText) return;
|
173
180
|
let element = event.currentTarget;
|
181
|
+
if (element.getAttribute('crdt') == 'false')
|
182
|
+
return;
|
174
183
|
const { start, end, range } = getSelection(element);
|
175
|
-
if(event.key == "Backspace" || event.key == "Tab" || event.key == "Enter") {
|
184
|
+
if (event.key == "Backspace" || event.key == "Tab" || event.key == "Enter") {
|
176
185
|
eventObj = event;
|
177
|
-
if(start != end) {
|
186
|
+
if (start != end) {
|
178
187
|
updateText({element, start, end, range});
|
179
188
|
}
|
180
189
|
|
181
|
-
if(event.key == "Backspace" && start == end) {
|
190
|
+
if (event.key == "Backspace" && start == end) {
|
182
191
|
updateText({element, start: start - 1, end, range});
|
183
192
|
}
|
184
|
-
else if(event.key == 'Tab') {
|
193
|
+
else if (event.key == 'Tab') {
|
185
194
|
updateText({element, value: "\t", start, range});
|
186
195
|
}
|
187
|
-
else if(event.key == "Enter") {
|
196
|
+
else if (event.key == "Enter") {
|
188
197
|
updateText({element, value: "\n", start, range});
|
189
198
|
}
|
190
199
|
event.preventDefault();
|
@@ -198,11 +207,13 @@ function _keydown (event) {
|
|
198
207
|
}
|
199
208
|
|
200
209
|
function _beforeinput (event) {
|
201
|
-
if(event.stopCCText) return;
|
210
|
+
if (event.stopCCText) return;
|
202
211
|
let element = event.currentTarget;
|
212
|
+
if (element.getAttribute('crdt') == 'false')
|
213
|
+
return;
|
203
214
|
let { start, end, range } = getSelection(element);
|
204
215
|
if (event.data) {
|
205
|
-
if(start != end) {
|
216
|
+
if (start != end) {
|
206
217
|
updateText({element, start, end, range});
|
207
218
|
}
|
208
219
|
eventObj = event;
|
@@ -212,7 +223,7 @@ function _beforeinput (event) {
|
|
212
223
|
}
|
213
224
|
|
214
225
|
function _input (event) {
|
215
|
-
if(event.stopCCText) return;
|
226
|
+
if (event.stopCCText) return;
|
216
227
|
if (event.data) {
|
217
228
|
eventObj = event;
|
218
229
|
}
|
@@ -230,7 +241,7 @@ let previousPosition = {};
|
|
230
241
|
export function sendPosition (element) {
|
231
242
|
// if (!element) return;
|
232
243
|
const { start, end, range } = getSelection(element);
|
233
|
-
if(range) {
|
244
|
+
if (range) {
|
234
245
|
if (range.element){
|
235
246
|
element = range.element;
|
236
247
|
}
|
@@ -250,7 +261,7 @@ export function sendPosition (element) {
|
|
250
261
|
}
|
251
262
|
|
252
263
|
function updateText ({element, value, start, end, range}) {
|
253
|
-
if(range) {
|
264
|
+
if (range) {
|
254
265
|
if (range.element)
|
255
266
|
element = range.element;
|
256
267
|
|
@@ -258,7 +269,7 @@ function updateText ({element, value, start, end, range}) {
|
|
258
269
|
element = element.ownerDocument.defaultView.frameElement;
|
259
270
|
}
|
260
271
|
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttr(element);
|
261
|
-
if(isCrdt == "false") return;
|
272
|
+
if (isCrdt == "false") return;
|
262
273
|
|
263
274
|
let length = end - start;
|
264
275
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
@@ -282,15 +293,15 @@ function _crdtUpdateListener () {
|
|
282
293
|
}
|
283
294
|
|
284
295
|
function updateElements({elements, collection, document_id, name, value, start, length, string}){
|
285
|
-
if(!elements){
|
296
|
+
if (!elements){
|
286
297
|
let selectors = `[collection='${collection}'][document_id='${document_id}'][name='${name}']`;
|
287
298
|
elements = document.querySelectorAll(`input${selectors}, textarea${selectors}, [contenteditable]${selectors}, [editor='dom']${selectors}`);
|
288
299
|
}
|
289
300
|
|
290
301
|
elements.forEach((element) => {
|
291
302
|
let isCrdt = element.getAttribute('crdt');
|
292
|
-
// if(isCrdt == 'false' && !element.hasAttribute('crdt') && !element.contentEditable) return;
|
293
|
-
// if(element.hasAttribute('contenteditable')){
|
303
|
+
// if (isCrdt == 'false' && !element.hasAttribute('crdt') && !element.contentEditable) return;
|
304
|
+
// if (element.hasAttribute('contenteditable')){
|
294
305
|
// let isEditable = element.getAttribute('contenteditable');
|
295
306
|
if (!element.hasAttribute('contenteditable') && isCrdt == 'false') return;
|
296
307
|
|
@@ -300,16 +311,19 @@ function updateElements({elements, collection, document_id, name, value, start,
|
|
300
311
|
|
301
312
|
async function updateElement ({element, collection, document_id, name, value, start, length, string }) {
|
302
313
|
if (element.tagName == 'IFRAME') {
|
314
|
+
let eid = element.getAttribute('eid')
|
303
315
|
element = element.contentDocument.documentElement;
|
316
|
+
if (eid != 'false' && eid != null && eid != undefined)
|
317
|
+
element.setAttribute('eid', eid)
|
304
318
|
if (element.contenteditable != 'false')
|
305
319
|
element.contentEditable = true;
|
306
320
|
}
|
307
|
-
if(value || length) {
|
321
|
+
if (value || length) {
|
308
322
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
309
|
-
if(length) {
|
323
|
+
if (length) {
|
310
324
|
_updateElementText(element, "", start, start + length);
|
311
325
|
}
|
312
|
-
if(value) {
|
326
|
+
if (value) {
|
313
327
|
_updateElementText(element, value, start, start);
|
314
328
|
}
|
315
329
|
}
|
@@ -338,14 +352,14 @@ function _updateElementText (element, value, start, end) {
|
|
338
352
|
let activeElement = element.ownerDocument.activeElement;
|
339
353
|
element.setRangeText(value, start, end, "end");
|
340
354
|
let p = processSelection(element, value, prev_start, prev_end, start, end);
|
341
|
-
if(activeElement == element)
|
355
|
+
if (activeElement == element)
|
342
356
|
sendPosition(element);
|
343
357
|
_dispatchInputEvent(element, p.value, p.start, p.end, p.prev_start, p.prev_end);
|
344
358
|
}
|
345
359
|
|
346
360
|
export function _dispatchInputEvent(element, content, start, end, prev_start, prev_end) {
|
347
361
|
let detail = {value: content, start, end, prev_start, prev_end, skip: true};
|
348
|
-
if(eventObj) {
|
362
|
+
if (eventObj) {
|
349
363
|
let event = new CustomEvent(eventObj.type, { bubbles: true });
|
350
364
|
Object.defineProperty(event, 'stopCCText', { writable: false, value: true });
|
351
365
|
Object.defineProperty(event, 'target', { writable: false, value: element });
|