@cocreate/utils 1.3.16 → 1.4.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,31 @@
1
+ # [1.4.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.3.19...v1.4.0) (2021-12-14)
2
+
3
+
4
+ ### Features
5
+
6
+ * cssPath and domParser update to support nested contenteditable elements ([a7b700a](https://github.com/CoCreate-app/CoCreate-utils/commit/a7b700add647856071cf2c3bfa0ce95b36144e0a))
7
+
8
+ ## [1.3.19](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.3.18...v1.3.19) (2021-12-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * cssPath nth-child if childern > 1 ([caa0f54](https://github.com/CoCreate-app/CoCreate-utils/commit/caa0f5480c58a3f5a5e8e117133ccad9f4acde66))
14
+
15
+ ## [1.3.18](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.3.17...v1.3.18) (2021-12-08)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * csspath element null return ([dd4ac41](https://github.com/CoCreate-app/CoCreate-utils/commit/dd4ac41f123105f1b4364e858bc221914220427c))
21
+
22
+ ## [1.3.17](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.3.16...v1.3.17) (2021-11-27)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * update dependencies ([d09ebd8](https://github.com/CoCreate-app/CoCreate-utils/commit/d09ebd8f0c9f0be1ffc9a84cd86252faf7d13bfd))
28
+
1
29
  ## [1.3.16](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.3.15...v1.3.16) (2021-11-27)
2
30
 
3
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.3.16",
3
+ "version": "1.4.0",
4
4
  "description": "A simple utils component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "utils",
@@ -61,6 +61,6 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/docs": "^1.2.59"
64
+ "@cocreate/docs": "^1.2.61"
65
65
  }
66
66
  }
package/src/index.js CHANGED
@@ -17,6 +17,10 @@ export function cssPath(node, container) {
17
17
  do {
18
18
  if (!node || !node.tagName) return false;
19
19
  let pathSplit = node.tagName.toLowerCase();
20
+ // if (node.tagName == "DOM-PARSER" || node.hasAttribute('contenteditable')){
21
+ // pathSplit = "[contenteditable]";
22
+ // node = '';
23
+ // }
20
24
  if (node.id){
21
25
  pathSplit += "#" + node.id;
22
26
  node = '';
@@ -34,17 +38,27 @@ export function cssPath(node, container) {
34
38
  });
35
39
  }
36
40
 
37
- if (node.parentNode) {
41
+ if (node.parentNode && node.parentNode.children.length > 1) {
42
+ // ToDo: improve array logic so ignores javascript generated html??
43
+ let children = []
44
+ for (let child of node.parentNode.children){
45
+ // if (!child.matches('.mirror'))
46
+ // children.push(child);
47
+ if (child.tagName == node.tagName)
48
+ children.push(child);
49
+ }
38
50
  let index = Array.prototype.indexOf.call(
39
- node.parentNode.children,
51
+ children,
40
52
  node
41
53
  );
42
- pathSplit += `:nth-child(${index + 1})`;
54
+ // if (children.length > 1)
55
+ // pathSplit += `:nth-child(${index + 1})`;
56
+ pathSplit += `:nth-of-type(${index + 1})`;
43
57
  }
44
58
 
45
59
  // pathSplits.unshift(pathSplit);
46
60
  node = node.parentNode;
47
- if (node.tagName == "HTML" || node.nodeName == "#document" || node.hasAttribute('contenteditable'))
61
+ if (node == null || node.tagName == "HTML" || node.tagName == "DOM-PARSER" || node.nodeName == "#document" || node.hasAttribute('contenteditable'))
48
62
  node = '';
49
63
  }
50
64
  }
@@ -72,7 +86,7 @@ export function domParser(str) {
72
86
  return doc.head;
73
87
 
74
88
  default:
75
- let con = document.createElement('div');
89
+ let con = document.createElement('dom-parser');
76
90
  con.innerHTML = str;
77
91
  return con;
78
92
  }