@cocreate/text 1.12.21 → 1.12.25
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 +29 -0
- package/package.json +9 -9
- package/src/index.js +11 -4
- package/src/updateDom.js +69 -64
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
## [1.12.25](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.24...v1.12.25) (2021-11-23)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* update dependencies ([c0f3d30](https://github.com/CoCreate-app/CoCreate-text/commit/c0f3d3033a4806b82f16555ed3dc02cc059ed4fa))
|
7
|
+
|
8
|
+
## [1.12.24](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.23...v1.12.24) (2021-11-23)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* update crud dependency ([19e931d](https://github.com/CoCreate-app/CoCreate-text/commit/19e931dc1234a5209412ca2bcccaf246d154f557))
|
14
|
+
* update selction and crdt dependencies ([a7dc2ca](https://github.com/CoCreate-app/CoCreate-text/commit/a7dc2ca004eb945e51b93d8a20f8095cc8d9b1b3))
|
15
|
+
|
16
|
+
## [1.12.23](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.22...v1.12.23) (2021-11-23)
|
17
|
+
|
18
|
+
|
19
|
+
### Bug Fixes
|
20
|
+
|
21
|
+
* handleing textNode and activeElement for curCaret ([a73b1d9](https://github.com/CoCreate-app/CoCreate-text/commit/a73b1d9ad0b32819779b9aaaebec13176e5cab1c))
|
22
|
+
|
23
|
+
## [1.12.22](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.21...v1.12.22) (2021-11-22)
|
24
|
+
|
25
|
+
|
26
|
+
### Bug Fixes
|
27
|
+
|
28
|
+
* isSave for textarea and inputs... remove value before texts sets value on intialization ([e8fb19b](https://github.com/CoCreate-app/CoCreate-text/commit/e8fb19bc370769f2bffd937fb92b2e0ace886508))
|
29
|
+
|
1
30
|
## [1.12.21](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.20...v1.12.21) (2021-11-20)
|
2
31
|
|
3
32
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/text",
|
3
|
-
"version": "1.12.
|
3
|
+
"version": "1.12.25",
|
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",
|
@@ -61,13 +61,13 @@
|
|
61
61
|
"webpack-log": "^3.0.1"
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
|
-
"@cocreate/action": "^1.3.
|
65
|
-
"@cocreate/crdt": "^1.8.
|
66
|
-
"@cocreate/crud-client": "^1.4.
|
67
|
-
"@cocreate/cursors": "^1.10.
|
68
|
-
"@cocreate/docs": "^1.2.
|
69
|
-
"@cocreate/hosting": "^1.2.
|
70
|
-
"@cocreate/observer": "^1.3.
|
71
|
-
"@cocreate/selection": "^1.2.
|
64
|
+
"@cocreate/action": "^1.3.17",
|
65
|
+
"@cocreate/crdt": "^1.8.21",
|
66
|
+
"@cocreate/crud-client": "^1.4.33",
|
67
|
+
"@cocreate/cursors": "^1.10.11",
|
68
|
+
"@cocreate/docs": "^1.2.55",
|
69
|
+
"@cocreate/hosting": "^1.2.51",
|
70
|
+
"@cocreate/observer": "^1.3.47",
|
71
|
+
"@cocreate/selection": "^1.2.13"
|
72
72
|
}
|
73
73
|
}
|
package/src/index.js
CHANGED
@@ -51,8 +51,15 @@ function initElement (element) {
|
|
51
51
|
if (value)
|
52
52
|
crdt.replaceText({ collection, document_id, name, value, crud: isCrud, save: isSave, read: isRead });
|
53
53
|
}
|
54
|
-
else
|
54
|
+
else {
|
55
|
+
if (element.hasAttribute('contenteditable')){
|
56
|
+
element.innerHTML = '';
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
element.value = '';
|
60
|
+
}
|
55
61
|
updateElement({ element, collection, document_id, name, value: response, start: 0 })
|
62
|
+
}
|
56
63
|
});
|
57
64
|
}
|
58
65
|
}
|
@@ -180,7 +187,7 @@ function updateText ({element, value, start, end, range}) {
|
|
180
187
|
if(isCrdt == "false") return;
|
181
188
|
let length = end - start;
|
182
189
|
if (element.tagName === "INPUT" || element.tagName === "TEXTAREA") {
|
183
|
-
crdt.updateText({ collection, document_id, name, value, start, length, crud: isCrud });
|
190
|
+
crdt.updateText({ collection, document_id, name, value, start, length, crud: isCrud, save: isSave });
|
184
191
|
} else {
|
185
192
|
let startEl = range.startContainer.parentElement;
|
186
193
|
let endEl = range.endContainer.parentElement;
|
@@ -209,8 +216,8 @@ function updateElements({elements, collection, document_id, name, value, start,
|
|
209
216
|
let isCrdt = element.getAttribute('crdt');
|
210
217
|
// if(isCrdt == 'false' && !element.hasAttribute('crdt') && !element.contentEditable) return;
|
211
218
|
// if(element.hasAttribute('contenteditable')){
|
212
|
-
let isEditable = element.getAttribute('contenteditable');
|
213
|
-
|
219
|
+
// let isEditable = element.getAttribute('contenteditable');
|
220
|
+
if (!element.hasAttribute('contenteditable') && isCrdt == 'false') return;
|
214
221
|
|
215
222
|
updateElement({element, collection, document_id, name, value, start, length});
|
216
223
|
});
|
package/src/updateDom.js
CHANGED
@@ -7,81 +7,86 @@ export function updateDom({domTextEditor, value, start, end, html}) {
|
|
7
7
|
throw new Error('position is out of range');
|
8
8
|
|
9
9
|
let {element, path, position, type} = getElementPosition(domTextEditor.htmlString, start, end);
|
10
|
-
|
11
|
-
if (element) {
|
12
10
|
parseHtml(domTextEditor);
|
13
|
-
let domEl, newEl = element, oldEl, curCaret;
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
let domEl, newEl = element, oldEl, curCaret;
|
13
|
+
if(!newEl){
|
14
|
+
newEl = domTextEditor.cloneNode(true);
|
15
|
+
newEl.innerHTML = html || domTextEditor.htmlString;
|
16
|
+
domEl = domTextEditor;
|
17
|
+
type = 'innerHTML';
|
18
|
+
}
|
19
|
+
else if(element.tagName == 'HTML') {
|
20
|
+
domEl = domTextEditor;
|
21
|
+
type = 'innerHTML';
|
22
|
+
}
|
23
|
+
else if(path) {
|
24
|
+
domEl = domTextEditor.querySelector(path);
|
25
|
+
oldEl = domTextEditor.oldHtml.querySelector(path);
|
26
|
+
}
|
27
|
+
|
28
|
+
let activeElement = domEl.ownerDocument.activeElement;
|
29
|
+
if (activeElement == domEl)
|
30
|
+
curCaret = getSelection(activeElement);
|
31
|
+
else if (activeElement.tagName == 'BODY')
|
32
|
+
curCaret = getSelection(domEl);
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
if (!value && type != 'isStartTag' && type != 'textNode'){
|
35
|
+
type = 'innerHTML';
|
36
|
+
}
|
37
|
+
|
38
|
+
if(domEl && newEl) {
|
39
|
+
if(start != end && type == 'innerHTML') {
|
40
|
+
domTextEditor.htmlString = html;
|
41
|
+
if (domEl.tagName != 'HTML'){
|
42
|
+
if (newEl.parentElement)
|
36
43
|
domEl.parentElement.replaceChildren(...newEl.parentElement.childNodes);
|
37
44
|
else
|
38
|
-
domEl.replaceChildren(...newEl.childNodes);
|
39
|
-
domEl = newEl;
|
40
|
-
if (curCaret.range) {
|
41
|
-
curCaret.range.startContainer = domEl;
|
42
|
-
curCaret.range.endContainer = domEl;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
else if (type == 'isStartTag')
|
46
|
-
assignAttributes(newEl, oldEl, domEl);
|
47
|
-
else if (type == 'insertAdjacent')
|
48
|
-
domEl.insertAdjacentHTML(position, value);
|
49
|
-
else if (type == 'textNode'){
|
50
|
-
if(start != end)
|
51
|
-
domTextEditor.htmlString = html;
|
52
|
-
domEl.innerHTML = newEl.innerHTML;
|
45
|
+
domEl.replaceChildren(...newEl.childNodes);
|
53
46
|
}
|
54
|
-
else
|
55
|
-
domEl.replaceChildren(...newEl.childNodes);
|
47
|
+
else
|
48
|
+
domEl.replaceChildren(...newEl.childNodes);
|
49
|
+
// domEl = newEl;
|
50
|
+
if (curCaret && curCaret.range) {
|
51
|
+
curCaret.range.startContainer = domEl;
|
52
|
+
curCaret.range.endContainer = domEl;
|
56
53
|
}
|
57
54
|
}
|
58
|
-
if(
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
else if (type == 'isStartTag')
|
56
|
+
assignAttributes(newEl, oldEl, domEl);
|
57
|
+
else if (type == 'insertAdjacent')
|
58
|
+
domEl.insertAdjacentHTML(position, value);
|
59
|
+
else if (type == 'textNode'){
|
60
|
+
if(start != end)
|
61
|
+
domTextEditor.htmlString = html;
|
62
|
+
domEl.innerHTML = newEl.innerHTML;
|
62
63
|
}
|
63
|
-
|
64
|
-
|
65
|
-
let scripts;
|
66
|
-
if (newEl.tagName == 'SCRIPT'){
|
67
|
-
scripts = [newEl]
|
68
|
-
}
|
69
|
-
else{
|
70
|
-
scripts = domEl.querySelectorAll('script');
|
71
|
-
}
|
72
|
-
for (let script of scripts) {
|
73
|
-
let newScript = domEl.ownerDocument.createElement('script');
|
74
|
-
for(let attribute of script.attributes) {
|
75
|
-
newScript.setAttribute(attribute.name, attribute.value);
|
76
|
-
}
|
77
|
-
newScript.innerHTML = script.innerHTML;
|
78
|
-
script.replaceWith(newScript);
|
79
|
-
}
|
64
|
+
else if (type == 'innerHTML') {
|
65
|
+
domEl.replaceChildren(...newEl.childNodes);
|
80
66
|
}
|
81
67
|
}
|
82
|
-
|
83
|
-
|
84
|
-
|
68
|
+
if(curCaret && start && end) {
|
69
|
+
let p = processSelection(domEl, value, curCaret.start, curCaret.end, start, end, curCaret.range);
|
70
|
+
sendPosition(domEl);
|
71
|
+
_dispatchInputEvent(p.element, p.value, p.start, p.end, p.prev_start, p.prev_end);
|
72
|
+
}
|
73
|
+
|
74
|
+
if (newEl.tagName == 'HTML' || 'HEAD' || 'BODY' || 'SCRIPT'){
|
75
|
+
let scripts;
|
76
|
+
if (newEl.tagName == 'SCRIPT'){
|
77
|
+
scripts = [newEl];
|
78
|
+
}
|
79
|
+
else{
|
80
|
+
scripts = domEl.querySelectorAll('script');
|
81
|
+
}
|
82
|
+
for (let script of scripts) {
|
83
|
+
let newScript = domEl.ownerDocument.createElement('script');
|
84
|
+
for(let attribute of script.attributes) {
|
85
|
+
newScript.setAttribute(attribute.name, attribute.value);
|
86
|
+
}
|
87
|
+
newScript.innerHTML = script.innerHTML;
|
88
|
+
script.replaceWith(newScript);
|
89
|
+
}
|
85
90
|
}
|
86
91
|
}
|
87
92
|
|