@cocreate/text 1.16.3 → 1.17.0

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,29 @@
1
+ # [1.17.0](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.5...v1.17.0) (2022-06-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * try to update parent element of previous element rather then html tag ([37ab36c](https://github.com/CoCreate-app/CoCreate-text/commit/37ab36ce79fa270b3a43daaf14597e765f42e371))
7
+
8
+
9
+ ### Features
10
+
11
+ * if newEl can not be found using path, update path to query parent element ([2c637f1](https://github.com/CoCreate-app/CoCreate-text/commit/2c637f1e0c3d15f00d1664c4d744d4ee9c4581c6))
12
+
13
+ ## [1.16.5](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.4...v1.16.5) (2022-06-22)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * ifactiveElement inputEvent skip = false ([0b61519](https://github.com/CoCreate-app/CoCreate-text/commit/0b61519e2bd9592502ebb7a2ba88b71a16e11e55))
19
+
20
+ ## [1.16.4](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.3...v1.16.4) (2022-06-18)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * bump dependencies ([2128b8d](https://github.com/CoCreate-app/CoCreate-text/commit/2128b8d11122a2024d7549e571b286ae6aa1d463))
26
+
1
27
  ## [1.16.3](https://github.com/CoCreate-app/CoCreate-text/compare/v1.16.2...v1.16.3) (2022-06-16)
2
28
 
3
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/text",
3
- "version": "1.16.3",
3
+ "version": "1.17.0",
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,14 +61,14 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/actions": "^1.4.2",
65
- "@cocreate/crdt": "^1.11.0",
66
- "@cocreate/crud-client": "^1.7.0",
67
- "@cocreate/cursors": "^1.11.20",
68
- "@cocreate/docs": "^1.3.2",
69
- "@cocreate/hosting": "^1.3.2",
70
- "@cocreate/observer": "^1.5.2",
71
- "@cocreate/selection": "^1.4.10",
72
- "@cocreate/uuid": "^1.2.2"
64
+ "@cocreate/actions": "^1.4.3",
65
+ "@cocreate/crdt": "^1.11.1",
66
+ "@cocreate/crud-client": "^1.7.1",
67
+ "@cocreate/cursors": "^1.11.21",
68
+ "@cocreate/docs": "^1.3.3",
69
+ "@cocreate/hosting": "^1.3.3",
70
+ "@cocreate/observer": "^1.5.3",
71
+ "@cocreate/selection": "^1.4.11",
72
+ "@cocreate/uuid": "^1.2.4"
73
73
  }
74
74
  }
package/src/index.js CHANGED
@@ -359,6 +359,9 @@ function _updateElementText (element, value, start, end) {
359
359
 
360
360
  export function _dispatchInputEvent(element, content, start, end, prev_start, prev_end) {
361
361
  let detail = {value: content, start, end, prev_start, prev_end, skip: true};
362
+ let activeElement = element.ownerDocument.activeElement;
363
+ if (activeElement == element)
364
+ detail.skip = false;
362
365
  if (eventObj) {
363
366
  let event = new CustomEvent(eventObj.type, { bubbles: true });
364
367
  Object.defineProperty(event, 'stopCCText', { writable: false, value: true });
package/src/updateDom.js CHANGED
@@ -11,8 +11,28 @@ export function updateDom({domTextEditor, value, start, end, html}) {
11
11
  let {element, path, position, type} = getElementPosition(domTextEditor.htmlString, start, end);
12
12
  parseHtml(domTextEditor, html);
13
13
 
14
- let domEl, oldEl, curCaret;
15
- let newEl = domTextEditor.newHtml.querySelector(path);
14
+ let domEl, oldEl, curCaret, newEl;
15
+ if (path && path.includes('<')) {
16
+ let index = path.lastIndexOf(' >')
17
+ if (index != -1)
18
+ path = path.slice(0, index)
19
+ else{
20
+ index = path.lastIndexOf('<')
21
+ path = path.slice(0, index)
22
+ }
23
+ }
24
+
25
+ try {
26
+ newEl = domTextEditor.newHtml.querySelector(path);
27
+ } catch(err){
28
+ console.log('error', err)
29
+ }
30
+ if (path && !newEl){
31
+ let index = path.lastIndexOf(' >')
32
+ if (index != -1)
33
+ path = path.slice(0, index)
34
+ newEl = domTextEditor.newHtml.querySelector(path);
35
+ }
16
36
  if(!newEl){
17
37
  newEl = domTextEditor.cloneNode(true);
18
38
  if (html != undefined)
@@ -40,46 +60,60 @@ export function updateDom({domTextEditor, value, start, end, html}) {
40
60
  }
41
61
  }
42
62
 
43
- let activeElement = domEl.ownerDocument.activeElement;
44
- if (activeElement == domEl)
45
- curCaret = getSelection(activeElement);
46
- else if (activeElement.tagName == 'BODY')
47
- curCaret = getSelection(domEl);
48
- else
49
- curCaret = getSelection(activeElement);
50
-
63
+ if (domEl) {
64
+ let activeElement = domEl.ownerDocument.activeElement;
65
+ if (activeElement == domEl)
66
+ curCaret = getSelection(activeElement);
67
+ else if (activeElement.tagName == 'BODY')
68
+ curCaret = getSelection(domEl);
69
+ else
70
+ curCaret = getSelection(activeElement);
71
+ }
72
+
51
73
  if (!value && type != 'isStartTag' && type != 'textNode'){
52
74
  type = 'innerHTML';
53
75
  }
54
-
76
+
55
77
  if(domEl && newEl) {
56
78
  if(start != end && type == 'innerHTML') {
57
79
  domTextEditor.htmlString = html;
58
80
  if (domEl.tagName != 'HTML'){
59
- if (newEl.parentElement)
81
+ if (newEl.parentElement) {
60
82
  domEl.parentElement.replaceChildren(...newEl.parentElement.childNodes);
61
- else
83
+ // console.log('parent', domEl.parentElement)
84
+ } else {
62
85
  domEl.replaceChildren(...newEl.childNodes);
86
+ // console.log('domEl', domEl)
87
+ }
63
88
  }
64
- else
89
+ else {
65
90
  domEl.replaceChildren(...newEl.childNodes);
66
- // domEl = newEl;
91
+ // console.log('Html tag', domEl)
92
+ }
67
93
  if (curCaret && curCaret.range) {
68
94
  curCaret.range.startContainer = domEl;
69
95
  curCaret.range.endContainer = domEl;
70
96
  }
71
97
  }
72
- else if (type == 'isStartTag')
98
+ else if (type == 'isStartTag') {
73
99
  assignAttributes(newEl, oldEl, domEl);
74
- else if (type == 'insertAdjacent')
100
+ // console.log('isStartTag', domEl, newEl)
101
+
102
+ }
103
+ else if (type == 'insertAdjacent') {
75
104
  domEl.insertAdjacentHTML(position, value);
105
+ // console.log('insertAdjacent', domEl, value)
106
+ }
76
107
  else if (type == 'textNode'){
77
108
  if(start != end)
78
109
  domTextEditor.htmlString = html;
79
110
  domEl.innerHTML = newEl.innerHTML;
111
+ // console.log('textnode', domEl.innerHTML, newEl.innerHTML)
112
+
80
113
  }
81
114
  else if (type == 'innerHTML') {
82
115
  domEl.replaceChildren(...newEl.childNodes);
116
+ // console.log('innerHtml', domEl, newEl)
83
117
  }
84
118
  domTextEditor.htmlString = html;
85
119
  }