@cocreate/text 1.17.0 → 1.17.3
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 +2 -1
- package/src/index.js +9 -2
- package/src/updateDom.js +83 -52
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
## [1.17.3](https://github.com/CoCreate-app/CoCreate-text/compare/v1.17.2...v1.17.3) (2022-07-25)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* if name includes_id, organization_id or beginswith $ return ([a7dbfeb](https://github.com/CoCreate-app/CoCreate-text/commit/a7dbfebda7eddaef5b0abe58c2e0615f2250b5d3))
|
7
|
+
|
8
|
+
## [1.17.2](https://github.com/CoCreate-app/CoCreate-text/compare/v1.17.1...v1.17.2) (2022-07-09)
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* updateDom will sendPosition if the currentContainer = domEl ([c1e9f56](https://github.com/CoCreate-app/CoCreate-text/commit/c1e9f56359c88dbff943c3b82d81746d30833fdb))
|
14
|
+
|
15
|
+
## [1.17.1](https://github.com/CoCreate-app/CoCreate-text/compare/v1.17.0...v1.17.1) (2022-06-24)
|
16
|
+
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
* imporved handeling of path fallback to html element if no matches amoung parentElements ([5c331d0](https://github.com/CoCreate-app/CoCreate-text/commit/5c331d0d32ffd60587f684b44e69766097193c33))
|
21
|
+
|
1
22
|
# [1.17.0](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.5...v1.17.0) (2022-06-23)
|
2
23
|
|
3
24
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cocreate/text",
|
3
|
-
"version": "1.17.
|
3
|
+
"version": "1.17.3",
|
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",
|
@@ -69,6 +69,7 @@
|
|
69
69
|
"@cocreate/hosting": "^1.3.3",
|
70
70
|
"@cocreate/observer": "^1.5.3",
|
71
71
|
"@cocreate/selection": "^1.4.11",
|
72
|
+
"@cocreate/utils": "^1.7.4",
|
72
73
|
"@cocreate/uuid": "^1.2.4"
|
73
74
|
}
|
74
75
|
}
|
package/src/index.js
CHANGED
@@ -29,8 +29,15 @@ function initElements (elements) {
|
|
29
29
|
function initElement (element) {
|
30
30
|
const { collection, document_id, name, isRealtime, isCrdt, isCrud, isSave, isRead } = crud.getAttr(element);
|
31
31
|
if (document_id == "pending") return;
|
32
|
-
if (
|
33
|
-
|
32
|
+
if (['_id', 'organization_id'].includes(name))
|
33
|
+
return
|
34
|
+
if (isCrdt == "false" || isRealtime == "false" || element.type == 'number')
|
35
|
+
return;
|
36
|
+
if (!crud.checkAttrValue(collection) || !crud.checkAttrValue(document_id)|| !crud.checkAttrValue(name))
|
37
|
+
return;
|
38
|
+
if(name && name.startsWith('$'))
|
39
|
+
return
|
40
|
+
|
34
41
|
if (element.tagName === "INPUT" && ["text", "tel", "url"].includes(element.type) || element.tagName === "TEXTAREA" || element.hasAttribute('contenteditable')) {
|
35
42
|
if (!collection || !document_id || !name) return;
|
36
43
|
|
package/src/updateDom.js
CHANGED
@@ -12,28 +12,27 @@ export function updateDom({domTextEditor, value, start, end, html}) {
|
|
12
12
|
parseHtml(domTextEditor, html);
|
13
13
|
|
14
14
|
let domEl, oldEl, curCaret, newEl;
|
15
|
-
|
16
|
-
|
17
|
-
if (index != -1)
|
18
|
-
path = path.slice(0, index)
|
19
|
-
else{
|
20
|
-
index = path.lastIndexOf('<')
|
21
|
-
path = path.slice(0, index)
|
22
|
-
}
|
23
|
-
}
|
15
|
+
// console.log('element', element)
|
16
|
+
// console.log('path', path)
|
24
17
|
|
25
18
|
try {
|
26
19
|
newEl = domTextEditor.newHtml.querySelector(path);
|
27
20
|
} catch(err){
|
28
21
|
console.log('error', err)
|
29
22
|
}
|
23
|
+
|
30
24
|
if (path && !newEl){
|
31
|
-
let index
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
let index
|
26
|
+
do {
|
27
|
+
index = path.lastIndexOf(' >')
|
28
|
+
if (index != -1)
|
29
|
+
path = path.slice(0, index)
|
30
|
+
newEl = domTextEditor.newHtml.querySelector(path);
|
31
|
+
} while (!newEl && index != -1)
|
35
32
|
}
|
33
|
+
|
36
34
|
if(!newEl){
|
35
|
+
// console.log("no newEL", path)
|
37
36
|
newEl = domTextEditor.cloneNode(true);
|
38
37
|
if (html != undefined)
|
39
38
|
newEl.innerHTML = html;
|
@@ -43,38 +42,65 @@ export function updateDom({domTextEditor, value, start, end, html}) {
|
|
43
42
|
type = 'innerHTML';
|
44
43
|
}
|
45
44
|
else if(element.tagName == 'HTML') {
|
45
|
+
// console.log('element = html')
|
46
46
|
domEl = domTextEditor;
|
47
47
|
type = 'innerHTML';
|
48
48
|
}
|
49
49
|
else if(path) {
|
50
|
+
// console.log("else path", path)
|
50
51
|
domEl = domTextEditor.querySelector(path);
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
// if (!domEl || !oldEl){
|
53
|
+
// let eid = newEl.getAttribute('eid');
|
54
|
+
// if (!domEl && eid){
|
55
|
+
// domEl = domTextEditor.querySelector(`[eid='${eid}']`);
|
56
|
+
// }
|
57
|
+
// if (!oldEl && eid){
|
58
|
+
// oldEl = domTextEditor.oldHtml.querySelector(`[eid='${eid}']`);
|
59
|
+
// }
|
60
|
+
// }
|
61
|
+
}
|
62
|
+
|
63
|
+
if (!domEl) {
|
64
|
+
// console.log('no domEl')
|
65
|
+
let index
|
66
|
+
do {
|
67
|
+
index = path.lastIndexOf(' >')
|
68
|
+
if (index != -1)
|
69
|
+
path = path.slice(0, index)
|
70
|
+
domEl = domTextEditor.querySelector(path);
|
71
|
+
} while (!domEl && index != -1)
|
72
|
+
|
73
|
+
if (domEl) {
|
74
|
+
newEl = domTextEditor.newHtml.querySelector(path);
|
75
|
+
}
|
76
|
+
|
77
|
+
if (!domEl || !newEl){
|
78
|
+
newEl = domTextEditor.cloneNode(true);
|
79
|
+
if (html != undefined)
|
80
|
+
newEl.innerHTML = html;
|
81
|
+
else
|
82
|
+
newEl.innerHTML = domTextEditor.htmlString;
|
83
|
+
domEl = domTextEditor;
|
84
|
+
type = 'innerHTML';
|
60
85
|
}
|
61
86
|
}
|
62
87
|
|
63
|
-
if
|
88
|
+
if(domEl && newEl) {
|
64
89
|
let activeElement = domEl.ownerDocument.activeElement;
|
65
90
|
if (activeElement == domEl)
|
66
91
|
curCaret = getSelection(activeElement);
|
67
|
-
else if (activeElement.tagName == 'BODY')
|
92
|
+
else if (activeElement && activeElement.tagName == 'BODY')
|
68
93
|
curCaret = getSelection(domEl);
|
69
94
|
else
|
70
95
|
curCaret = getSelection(activeElement);
|
71
|
-
|
96
|
+
|
72
97
|
|
73
|
-
|
74
|
-
|
75
|
-
|
98
|
+
if (!value && type != 'isStartTag' && type != 'textNode'){
|
99
|
+
type = 'innerHTML';
|
100
|
+
}
|
76
101
|
|
77
|
-
|
102
|
+
// console.log('domEl', domEl)
|
103
|
+
// console.log('newEl', newEl)
|
78
104
|
if(start != end && type == 'innerHTML') {
|
79
105
|
domTextEditor.htmlString = html;
|
80
106
|
if (domEl.tagName != 'HTML'){
|
@@ -96,6 +122,9 @@ export function updateDom({domTextEditor, value, start, end, html}) {
|
|
96
122
|
}
|
97
123
|
}
|
98
124
|
else if (type == 'isStartTag') {
|
125
|
+
oldEl = domTextEditor.oldHtml.querySelector(path);
|
126
|
+
if (!oldEl && domEl.tagName == 'HTML')
|
127
|
+
oldEl = domTextEditor.oldHtml
|
99
128
|
assignAttributes(newEl, oldEl, domEl);
|
100
129
|
// console.log('isStartTag', domEl, newEl)
|
101
130
|
|
@@ -116,31 +145,33 @@ export function updateDom({domTextEditor, value, start, end, html}) {
|
|
116
145
|
// console.log('innerHtml', domEl, newEl)
|
117
146
|
}
|
118
147
|
domTextEditor.htmlString = html;
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
if (newEl.tagName == 'HTML' || 'HEAD' || 'BODY' || 'SCRIPT'){
|
129
|
-
let scripts;
|
130
|
-
if (newEl.tagName == 'SCRIPT'){
|
131
|
-
scripts = [newEl];
|
132
|
-
}
|
133
|
-
else{
|
134
|
-
scripts = domEl.querySelectorAll('script');
|
148
|
+
|
149
|
+
if(curCaret && start >= 0 && end >= 0) {
|
150
|
+
if (curCaret.range.startContainer == domEl)
|
151
|
+
if (curCaret.range && curCaret.start >= curCaret.range.startOffset) {
|
152
|
+
let p = processSelection(domEl, value, curCaret.start, curCaret.end, start, end, curCaret.range);
|
153
|
+
sendPosition(domEl);
|
154
|
+
_dispatchInputEvent(p.element, p.value, p.start, p.end, p.prev_start, p.prev_end);
|
155
|
+
}
|
135
156
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
157
|
+
|
158
|
+
if (['HTML', 'HEAD', 'BODY', 'SCRIPT'].includes(newEl.tagName)){
|
159
|
+
let scripts;
|
160
|
+
if (newEl.tagName == 'SCRIPT'){
|
161
|
+
scripts = [newEl];
|
140
162
|
}
|
141
|
-
|
142
|
-
|
143
|
-
|
163
|
+
else{
|
164
|
+
scripts = domEl.querySelectorAll('script');
|
165
|
+
}
|
166
|
+
for (let script of scripts) {
|
167
|
+
let newScript = domEl.ownerDocument.createElement('script');
|
168
|
+
for(let attribute of script.attributes) {
|
169
|
+
newScript.setAttribute(attribute.name, attribute.value);
|
170
|
+
}
|
171
|
+
newScript.innerHTML = script.innerHTML;
|
172
|
+
script.replaceWith(newScript);
|
173
|
+
}
|
174
|
+
}
|
144
175
|
}
|
145
176
|
}
|
146
177
|
|