@cocreate/utils 1.2.1 → 1.3.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,15 @@
1
+ # [1.3.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.2.1...v1.3.0) (2021-11-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * cssPath did not push and return path if it was id ([4af00bd](https://github.com/CoCreate-app/CoCreate-utils/commit/4af00bd4c3fd376a1fd15d7dd1eeeec63ff0ddcf))
7
+
8
+
9
+ ### Features
10
+
11
+ * cssPath will stop and return path if id or eid found... rather then continuing to travel up the dom tree ([17d6ced](https://github.com/CoCreate-app/CoCreate-utils/commit/17d6ced222f0552f870f2feeffecf7970ad653a3))
12
+
1
13
  ## [1.2.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.2.0...v1.2.1) (2021-10-29)
2
14
 
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.2.1",
3
+ "version": "1.3.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",
package/src/index.js CHANGED
@@ -17,26 +17,38 @@ 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.id) pathSplit += "#" + node.id;
21
-
22
- if (node.classList.length) {
23
- node.classList.forEach((item) => {
24
- if (item.indexOf(":") === -1) pathSplit += "." + item;
25
- });
20
+ if (node.id){
21
+ pathSplit += "#" + node.id;
22
+ node = '';
26
23
  }
27
-
28
- if (node.parentNode) {
29
- let index = Array.prototype.indexOf.call(
30
- node.parentNode.children,
31
- node
32
- );
33
- pathSplit += `:nth-child(${index + 1})`;
24
+ else {
25
+ let eid = node.getAttribute('eid');
26
+ if (eid) {
27
+ pathSplit += `[eid="${eid}"]`;
28
+ node = '';
29
+ }
30
+ else {
31
+ if (node.classList.length) {
32
+ node.classList.forEach((item) => {
33
+ if (item.indexOf(":") === -1) pathSplit += "." + item;
34
+ });
35
+ }
36
+
37
+ if (node.parentNode) {
38
+ let index = Array.prototype.indexOf.call(
39
+ node.parentNode.children,
40
+ node
41
+ );
42
+ pathSplit += `:nth-child(${index + 1})`;
43
+ }
44
+
45
+ // pathSplits.unshift(pathSplit);
46
+ node = node.parentNode;
47
+ if (node.tagName == "HTML" || node.nodeName == "#document" || node.hasAttribute('contenteditable'))
48
+ node = '';
49
+ }
34
50
  }
35
-
36
51
  pathSplits.unshift(pathSplit);
37
- node = node.parentNode;
38
- if (node.tagName == "HTML" || node.nodeName == "#document" || node.hasAttribute('contenteditable'))
39
- node = '';
40
52
  } while (node);
41
53
  return pathSplits.join(" > ");
42
54
  }
package/src/index.old.js CHANGED
@@ -319,6 +319,33 @@ export function frameQuerySelectorAll(comSelector) {
319
319
 
320
320
  }
321
321
 
322
+ async function complexSelector(comSelector, callback) {
323
+ let [canvasSelector, selector] = comSelector.split(';');
324
+ let canvas = document.querySelector(canvasSelector);
325
+ if(!canvas) {
326
+ console.warn('complex selector canvas now found for', comSelector);
327
+ return;
328
+ }
329
+
330
+ if(canvas.contentDocument.readyState === 'loading') {
331
+ try {
332
+ await new Promise((resolve, reject) => {
333
+ canvas.contentWindow.addEventListener('load', (e) => resolve());
334
+ });
335
+ }
336
+ catch(err) {
337
+ console.error('iframe can not be loaded');
338
+ }
339
+ }
340
+
341
+ if(canvas.contentWindow.parent.CoCreate.observer && !observerInit.has(canvas.contentWindow)) {
342
+ observerElements(canvas.contentWindow);
343
+ }
344
+
345
+ return callback(canvas.contentWindow.document, selector);
346
+ }
347
+
348
+
322
349
  // export function computeStyles(el, properties) {
323
350
  // let computed = window.getComputedStyle(el);
324
351
  // let result = {};