@cocreate/text 1.12.22 → 1.12.26

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 CHANGED
@@ -1,3 +1,32 @@
1
+ ## [1.12.26](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.25...v1.12.26) (2021-11-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * improved on logical conditons on when to processSelection ([53f8ad4](https://github.com/CoCreate-app/CoCreate-text/commit/53f8ad4e075c77b89ade24e56b6512431ac17b35))
7
+
8
+ ## [1.12.25](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.24...v1.12.25) (2021-11-23)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update dependencies ([c0f3d30](https://github.com/CoCreate-app/CoCreate-text/commit/c0f3d3033a4806b82f16555ed3dc02cc059ed4fa))
14
+
15
+ ## [1.12.24](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.23...v1.12.24) (2021-11-23)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * update crud dependency ([19e931d](https://github.com/CoCreate-app/CoCreate-text/commit/19e931dc1234a5209412ca2bcccaf246d154f557))
21
+ * update selction and crdt dependencies ([a7dc2ca](https://github.com/CoCreate-app/CoCreate-text/commit/a7dc2ca004eb945e51b93d8a20f8095cc8d9b1b3))
22
+
23
+ ## [1.12.23](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.22...v1.12.23) (2021-11-23)
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * handleing textNode and activeElement for curCaret ([a73b1d9](https://github.com/CoCreate-app/CoCreate-text/commit/a73b1d9ad0b32819779b9aaaebec13176e5cab1c))
29
+
1
30
  ## [1.12.22](https://github.com/CoCreate-app/CoCreate-text/compare/v1.12.21...v1.12.22) (2021-11-22)
2
31
 
3
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/text",
3
- "version": "1.12.22",
3
+ "version": "1.12.26",
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.15",
65
- "@cocreate/crdt": "^1.8.17",
66
- "@cocreate/crud-client": "^1.4.29",
67
- "@cocreate/cursors": "^1.10.9",
68
- "@cocreate/docs": "^1.2.53",
69
- "@cocreate/hosting": "^1.2.48",
70
- "@cocreate/observer": "^1.3.45",
71
- "@cocreate/selection": "^1.2.9"
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,7 +51,7 @@ 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
55
  if (element.hasAttribute('contenteditable')){
56
56
  element.innerHTML = '';
57
57
  }
@@ -59,6 +59,7 @@ function initElement (element) {
59
59
  element.value = '';
60
60
  }
61
61
  updateElement({ element, collection, document_id, name, value: response, start: 0 })
62
+ }
62
63
  });
63
64
  }
64
65
  }
package/src/updateDom.js CHANGED
@@ -7,81 +7,91 @@ 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
- if(element.tagName == 'HTML') {
16
- domEl = domTextEditor;
17
- curCaret = getSelection(domEl);
18
- type = 'innerHTML';
19
- }
20
- else if(path) {
21
- domEl = domTextEditor.querySelector(path);
22
- oldEl = domTextEditor.oldHtml.querySelector(path);
23
- curCaret = getSelection(domEl);
24
- }
25
- else {
26
- curCaret = getSelection(domEl);
27
- }
28
- if (!value && type != 'isStartTag' && type != 'textNode'){
29
- type = 'innerHTML';
30
- }
12
+ let domEl, newEl = element, oldEl, curCaret;
13
+ if(!newEl){
14
+ newEl = domTextEditor.cloneNode(true);
15
+ if (html != undefined)
16
+ newEl.innerHTML = html;
17
+ else
18
+ newEl.innerHTML = domTextEditor.htmlString;
19
+ domEl = domTextEditor;
20
+ type = 'innerHTML';
21
+ }
22
+ else if(element.tagName == 'HTML') {
23
+ domEl = domTextEditor;
24
+ type = 'innerHTML';
25
+ }
26
+ else if(path) {
27
+ domEl = domTextEditor.querySelector(path);
28
+ oldEl = domTextEditor.oldHtml.querySelector(path);
29
+ }
30
+
31
+ let activeElement = domEl.ownerDocument.activeElement;
32
+ if (activeElement == domEl)
33
+ curCaret = getSelection(activeElement);
34
+ else if (activeElement.tagName == 'BODY')
35
+ curCaret = getSelection(domEl);
31
36
 
32
- if(domEl && newEl) {
33
- if(start != end && type == 'innerHTML') {
34
- domTextEditor.htmlString = html;
35
- if (domEl.tagName != 'HTML')
37
+ if (!value && type != 'isStartTag' && type != 'textNode'){
38
+ type = 'innerHTML';
39
+ }
40
+
41
+ if(domEl && newEl) {
42
+ if(start != end && type == 'innerHTML') {
43
+ domTextEditor.htmlString = html;
44
+ if (domEl.tagName != 'HTML'){
45
+ if (newEl.parentElement)
36
46
  domEl.parentElement.replaceChildren(...newEl.parentElement.childNodes);
37
47
  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;
48
+ domEl.replaceChildren(...newEl.childNodes);
53
49
  }
54
- else if (type == 'innerHTML') {
55
- domEl.replaceChildren(...newEl.childNodes);
50
+ else
51
+ domEl.replaceChildren(...newEl.childNodes);
52
+ // domEl = newEl;
53
+ if (curCaret && curCaret.range) {
54
+ curCaret.range.startContainer = domEl;
55
+ curCaret.range.endContainer = domEl;
56
56
  }
57
57
  }
58
- if(start && end) {
58
+ else if (type == 'isStartTag')
59
+ assignAttributes(newEl, oldEl, domEl);
60
+ else if (type == 'insertAdjacent')
61
+ domEl.insertAdjacentHTML(position, value);
62
+ else if (type == 'textNode'){
63
+ if(start != end)
64
+ domTextEditor.htmlString = html;
65
+ domEl.innerHTML = newEl.innerHTML;
66
+ }
67
+ else if (type == 'innerHTML') {
68
+ domEl.replaceChildren(...newEl.childNodes);
69
+ }
70
+ }
71
+ if(curCaret && start >= 0 && end >= 0) {
72
+ if (curCaret.range && curCaret.start >= curCaret.range.startOffset) {
59
73
  let p = processSelection(domEl, value, curCaret.start, curCaret.end, start, end, curCaret.range);
60
74
  sendPosition(domEl);
61
75
  _dispatchInputEvent(p.element, p.value, p.start, p.end, p.prev_start, p.prev_end);
62
76
  }
63
-
64
- if (newEl.tagName == 'HTML' || 'HEAD' || 'BODY' || 'SCRIPT'){
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
- }
80
- }
81
77
  }
82
- else {
83
- element = domTextEditor;
84
- element.innerHTML = value;
78
+
79
+ if (newEl.tagName == 'HTML' || 'HEAD' || 'BODY' || 'SCRIPT'){
80
+ let scripts;
81
+ if (newEl.tagName == 'SCRIPT'){
82
+ scripts = [newEl];
83
+ }
84
+ else{
85
+ scripts = domEl.querySelectorAll('script');
86
+ }
87
+ for (let script of scripts) {
88
+ let newScript = domEl.ownerDocument.createElement('script');
89
+ for(let attribute of script.attributes) {
90
+ newScript.setAttribute(attribute.name, attribute.value);
91
+ }
92
+ newScript.innerHTML = script.innerHTML;
93
+ script.replaceWith(newScript);
94
+ }
85
95
  }
86
96
  }
87
97