@cocreate/text 1.15.9 → 1.15.12
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/CoCreate.config.js +1 -1
- package/package.json +1 -1
- package/src/index.js +39 -31
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## [1.15.12](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.11...v1.15.12) (2022-03-21)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* string formating differs between various OS \r\n and \r are replaced with \n ([87b0183](https://github.com/CoCreate-app/CoCreate-text/commit/87b018354240d6f25b57fb9fc272f52103c4072c))
|
7
|
+
|
8
|
+
## [1.15.11](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.10...v1.15.11) (2022-03-07)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* if crdt=false return before event prevent default for crud ([342411c](https://github.com/CoCreate-app/CoCreate-text/commit/342411c4ec654b554e9d92e071a932d1155cec09))
|
14
|
+
|
15
|
+
## [1.15.10](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.9...v1.15.10) (2022-02-24)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* CoCreate.config replace CoCreate.app with * ([0f6dedb](https://github.com/CoCreate-app/CoCreate-text/commit/0f6dedba0f88a05e82b3683e92834519bc395b98))
|
21
|
+
|
1
22
|
## [1.15.9](https://github.com/CoCreate-app/CoCreate-text/compare/v1.15.8...v1.15.9) (2022-02-16)
|
2
23
|
|
3
24
|
|
package/CoCreate.config.js
CHANGED
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,9 +111,9 @@ 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){
|
114
|
+
if (!target.id){
|
115
115
|
let eid = target.getAttribute('eid');
|
116
|
-
if(!eid){
|
116
|
+
if (!eid){
|
117
117
|
eid = uuid.generate(6);
|
118
118
|
setAttribute({ domTextEditor, target, name: 'eid', value: eid });
|
119
119
|
}
|
@@ -138,6 +138,8 @@ function _blur (event) {
|
|
138
138
|
|
139
139
|
function _cut (event) {
|
140
140
|
let element = event.currentTarget;
|
141
|
+
if (element.getAttribute('crdt') == 'false')
|
142
|
+
return;
|
141
143
|
const { start, end, range } = getSelection(element);
|
142
144
|
const selection = document.getSelection();
|
143
145
|
console.log(selection.toString());
|
@@ -151,7 +153,7 @@ function _cut (event) {
|
|
151
153
|
/* clipboard write failed */
|
152
154
|
});
|
153
155
|
}
|
154
|
-
if(start != end) {
|
156
|
+
if (start != end) {
|
155
157
|
updateText({element, start, end, range});
|
156
158
|
}
|
157
159
|
event.preventDefault();
|
@@ -159,9 +161,11 @@ function _cut (event) {
|
|
159
161
|
|
160
162
|
function _paste (event) {
|
161
163
|
let element = event.currentTarget;
|
162
|
-
|
164
|
+
if (element.getAttribute('crdt') == 'false')
|
165
|
+
return;
|
166
|
+
let value = event.clipboardData.getData('text/plain').replace(/(\r\n|\r)/gm, "\n");;
|
163
167
|
const { start, end, range } = getSelection(element);
|
164
|
-
if(start != end) {
|
168
|
+
if (start != end) {
|
165
169
|
updateText({element, start, end, range});
|
166
170
|
}
|
167
171
|
updateText({element, value, start, range});
|
@@ -169,22 +173,24 @@ function _paste (event) {
|
|
169
173
|
}
|
170
174
|
|
171
175
|
function _keydown (event) {
|
172
|
-
if(event.stopCCText) return;
|
176
|
+
if (event.stopCCText) return;
|
173
177
|
let element = event.currentTarget;
|
178
|
+
if (element.getAttribute('crdt') == 'false')
|
179
|
+
return;
|
174
180
|
const { start, end, range } = getSelection(element);
|
175
|
-
if(event.key == "Backspace" || event.key == "Tab" || event.key == "Enter") {
|
181
|
+
if (event.key == "Backspace" || event.key == "Tab" || event.key == "Enter") {
|
176
182
|
eventObj = event;
|
177
|
-
if(start != end) {
|
183
|
+
if (start != end) {
|
178
184
|
updateText({element, start, end, range});
|
179
185
|
}
|
180
186
|
|
181
|
-
if(event.key == "Backspace" && start == end) {
|
187
|
+
if (event.key == "Backspace" && start == end) {
|
182
188
|
updateText({element, start: start - 1, end, range});
|
183
189
|
}
|
184
|
-
else if(event.key == 'Tab') {
|
190
|
+
else if (event.key == 'Tab') {
|
185
191
|
updateText({element, value: "\t", start, range});
|
186
192
|
}
|
187
|
-
else if(event.key == "Enter") {
|
193
|
+
else if (event.key == "Enter") {
|
188
194
|
updateText({element, value: "\n", start, range});
|
189
195
|
}
|
190
196
|
event.preventDefault();
|
@@ -198,11 +204,13 @@ function _keydown (event) {
|
|
198
204
|
}
|
199
205
|
|
200
206
|
function _beforeinput (event) {
|
201
|
-
if(event.stopCCText) return;
|
207
|
+
if (event.stopCCText) return;
|
202
208
|
let element = event.currentTarget;
|
209
|
+
if (element.getAttribute('crdt') == 'false')
|
210
|
+
return;
|
203
211
|
let { start, end, range } = getSelection(element);
|
204
212
|
if (event.data) {
|
205
|
-
if(start != end) {
|
213
|
+
if (start != end) {
|
206
214
|
updateText({element, start, end, range});
|
207
215
|
}
|
208
216
|
eventObj = event;
|
@@ -212,7 +220,7 @@ function _beforeinput (event) {
|
|
212
220
|
}
|
213
221
|
|
214
222
|
function _input (event) {
|
215
|
-
if(event.stopCCText) return;
|
223
|
+
if (event.stopCCText) return;
|
216
224
|
if (event.data) {
|
217
225
|
eventObj = event;
|
218
226
|
}
|
@@ -230,7 +238,7 @@ let previousPosition = {};
|
|
230
238
|
export function sendPosition (element) {
|
231
239
|
// if (!element) return;
|
232
240
|
const { start, end, range } = getSelection(element);
|
233
|
-
if(range) {
|
241
|
+
if (range) {
|
234
242
|
if (range.element){
|
235
243
|
element = range.element;
|
236
244
|
}
|
@@ -250,7 +258,7 @@ export function sendPosition (element) {
|
|
250
258
|
}
|
251
259
|
|
252
260
|
function updateText ({element, value, start, end, range}) {
|
253
|
-
if(range) {
|
261
|
+
if (range) {
|
254
262
|
if (range.element)
|
255
263
|
element = range.element;
|
256
264
|
|
@@ -258,7 +266,7 @@ function updateText ({element, value, start, end, range}) {
|
|
258
266
|
element = element.ownerDocument.defaultView.frameElement;
|
259
267
|
}
|
260
268
|
const { collection, document_id, name, isCrud, isCrdt, isSave } = crud.getAttr(element);
|
261
|
-
if(isCrdt == "false") return;
|
269
|
+
if (isCrdt == "false") return;
|
262
270
|
|
263
271
|
let length = end - start;
|
264
272
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
@@ -282,15 +290,15 @@ function _crdtUpdateListener () {
|
|
282
290
|
}
|
283
291
|
|
284
292
|
function updateElements({elements, collection, document_id, name, value, start, length, string}){
|
285
|
-
if(!elements){
|
293
|
+
if (!elements){
|
286
294
|
let selectors = `[collection='${collection}'][document_id='${document_id}'][name='${name}']`;
|
287
295
|
elements = document.querySelectorAll(`input${selectors}, textarea${selectors}, [contenteditable]${selectors}, [editor='dom']${selectors}`);
|
288
296
|
}
|
289
297
|
|
290
298
|
elements.forEach((element) => {
|
291
299
|
let isCrdt = element.getAttribute('crdt');
|
292
|
-
// if(isCrdt == 'false' && !element.hasAttribute('crdt') && !element.contentEditable) return;
|
293
|
-
// if(element.hasAttribute('contenteditable')){
|
300
|
+
// if (isCrdt == 'false' && !element.hasAttribute('crdt') && !element.contentEditable) return;
|
301
|
+
// if (element.hasAttribute('contenteditable')){
|
294
302
|
// let isEditable = element.getAttribute('contenteditable');
|
295
303
|
if (!element.hasAttribute('contenteditable') && isCrdt == 'false') return;
|
296
304
|
|
@@ -304,12 +312,12 @@ async function updateElement ({element, collection, document_id, name, value, st
|
|
304
312
|
if (element.contenteditable != 'false')
|
305
313
|
element.contentEditable = true;
|
306
314
|
}
|
307
|
-
if(value || length) {
|
315
|
+
if (value || length) {
|
308
316
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
309
|
-
if(length) {
|
317
|
+
if (length) {
|
310
318
|
_updateElementText(element, "", start, start + length);
|
311
319
|
}
|
312
|
-
if(value) {
|
320
|
+
if (value) {
|
313
321
|
_updateElementText(element, value, start, start);
|
314
322
|
}
|
315
323
|
}
|
@@ -338,14 +346,14 @@ function _updateElementText (element, value, start, end) {
|
|
338
346
|
let activeElement = element.ownerDocument.activeElement;
|
339
347
|
element.setRangeText(value, start, end, "end");
|
340
348
|
let p = processSelection(element, value, prev_start, prev_end, start, end);
|
341
|
-
if(activeElement == element)
|
349
|
+
if (activeElement == element)
|
342
350
|
sendPosition(element);
|
343
351
|
_dispatchInputEvent(element, p.value, p.start, p.end, p.prev_start, p.prev_end);
|
344
352
|
}
|
345
353
|
|
346
354
|
export function _dispatchInputEvent(element, content, start, end, prev_start, prev_end) {
|
347
355
|
let detail = {value: content, start, end, prev_start, prev_end, skip: true};
|
348
|
-
if(eventObj) {
|
356
|
+
if (eventObj) {
|
349
357
|
let event = new CustomEvent(eventObj.type, { bubbles: true });
|
350
358
|
Object.defineProperty(event, 'stopCCText', { writable: false, value: true });
|
351
359
|
Object.defineProperty(event, 'target', { writable: false, value: element });
|