@cocreate/utils 1.7.4 → 1.8.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 +21 -0
- package/package.json +1 -1
- package/src/index.js +39 -51
- package/src/index.old.js +56 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
# [1.8.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.6...v1.8.0) (2022-07-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* queryDocumentSelectorAll - ability to query iframes and parent of iframes ([90bd26b](https://github.com/CoCreate-app/CoCreate-utils/commit/90bd26b139a6a5413ac67a92504cf533f10e0838))
|
|
7
|
+
|
|
8
|
+
## [1.7.6](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.5...v1.7.6) (2022-06-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* remove functon getAttributes ([162228d](https://github.com/CoCreate-app/CoCreate-utils/commit/162228ddd99bcdf64a59088bddf2a6216a911898))
|
|
14
|
+
|
|
15
|
+
## [1.7.5](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.4...v1.7.5) (2022-06-24)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* check path for character < if exist clean up path to mak it in to a valid selector ([9321063](https://github.com/CoCreate-app/CoCreate-utils/commit/93210634425db2dff507919dd32415f0d7bdfc95))
|
|
21
|
+
|
|
1
22
|
## [1.7.4](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.3...v1.7.4) (2022-06-18)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -20,13 +20,6 @@ function clickedElement() {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function getAttributes(element) {
|
|
24
|
-
return element.getAttributeNames().reduce((attrMap, name) => {
|
|
25
|
-
attrMap[name] = element.getAttribute(name);
|
|
26
|
-
return attrMap;
|
|
27
|
-
}, {});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
23
|
export function parseTextToHtml(text) {
|
|
31
24
|
let doc = new DOMParser().parseFromString(text, "text/html");
|
|
32
25
|
if (doc.head.children[0]) return doc.head.children[0];
|
|
@@ -47,15 +40,15 @@ export function cssPath(node, container) {
|
|
|
47
40
|
node = '';
|
|
48
41
|
}
|
|
49
42
|
else {
|
|
50
|
-
let eid = node.getAttribute('eid');
|
|
51
|
-
if(/{{\s*([\w\W]+)\s*}}/g.test(eid)) {
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
if (eid) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
43
|
+
// let eid = node.getAttribute('eid');
|
|
44
|
+
// if(/{{\s*([\w\W]+)\s*}}/g.test(eid)) {
|
|
45
|
+
// eid = false;
|
|
46
|
+
// }
|
|
47
|
+
// if (eid) {
|
|
48
|
+
// pathSplit += `[eid="${eid}"]`;
|
|
49
|
+
// node = '';
|
|
50
|
+
// }
|
|
51
|
+
// else {
|
|
59
52
|
// if (node.classList.length) {
|
|
60
53
|
// node.classList.forEach((item) => {
|
|
61
54
|
// if (item.indexOf(":") === -1) pathSplit += "." + item;
|
|
@@ -85,10 +78,21 @@ export function cssPath(node, container) {
|
|
|
85
78
|
if (node == null || node.tagName == "HTML" || node.tagName == "DOM-PARSER" || node.nodeName == "#document" || node.hasAttribute('contenteditable'))
|
|
86
79
|
node = '';
|
|
87
80
|
}
|
|
88
|
-
}
|
|
81
|
+
// }
|
|
89
82
|
pathSplits.unshift(pathSplit);
|
|
90
83
|
} while (node);
|
|
91
|
-
|
|
84
|
+
let path = pathSplits.join(" > ")
|
|
85
|
+
if (path && path.includes('<')) {
|
|
86
|
+
let index = path.lastIndexOf(' >')
|
|
87
|
+
if (index != -1)
|
|
88
|
+
path = path.slice(0, index)
|
|
89
|
+
else{
|
|
90
|
+
index = path.lastIndexOf('<')
|
|
91
|
+
path = path.slice(0, index)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return path;
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
export function domParser(str) {
|
|
@@ -116,29 +120,7 @@ export function domParser(str) {
|
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
export function
|
|
120
|
-
let selectorArray = [];
|
|
121
|
-
if (selector) {
|
|
122
|
-
let selectors = [selector];
|
|
123
|
-
if(selector.indexOf(',') !== -1){
|
|
124
|
-
selectors = selector.split(',');
|
|
125
|
-
}
|
|
126
|
-
for (let selector of selectors){
|
|
127
|
-
let els;
|
|
128
|
-
if(selector.indexOf(';') !== -1) {
|
|
129
|
-
let [documentSelector, targetSelector] = selector.split(';');
|
|
130
|
-
let frame = document.querySelector(documentSelector);
|
|
131
|
-
if (frame)
|
|
132
|
-
selectorArray.push({Document: frame.contentDocument, selector: targetSelector});
|
|
133
|
-
}
|
|
134
|
-
else
|
|
135
|
-
selectorArray.push({Document: document, selector: selector});
|
|
136
|
-
}
|
|
137
|
-
return selectorArray;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function queryFrameSelectorAll(selector) {
|
|
123
|
+
export function queryDocumentSelectorAll(selector) {
|
|
142
124
|
let elements = [];
|
|
143
125
|
|
|
144
126
|
if (selector) {
|
|
@@ -149,16 +131,22 @@ export function queryFrameSelectorAll(selector) {
|
|
|
149
131
|
for (let selector of selectors){
|
|
150
132
|
let els;
|
|
151
133
|
if(selector.indexOf(';') !== -1) {
|
|
134
|
+
let targetDocument;
|
|
152
135
|
let [documentSelector, targetSelector] = selector.split(';');
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
136
|
+
if (['parent', 'parentDocument'].includes(documentSelector))
|
|
137
|
+
targetDocument = window.parent.document;
|
|
138
|
+
else {
|
|
139
|
+
let frame = document.querySelector(documentSelector);
|
|
140
|
+
if (frame)
|
|
141
|
+
targetDocument = frame.contentDocument;
|
|
142
|
+
}
|
|
143
|
+
if (targetDocument){
|
|
144
|
+
if (targetSelector)
|
|
145
|
+
els = targetDocument.querySelectorAll(targetSelector);
|
|
146
|
+
else
|
|
147
|
+
if (targetDocument.clickedElement)
|
|
148
|
+
els = [targetDocument.clickedElement];
|
|
149
|
+
}
|
|
162
150
|
}
|
|
163
151
|
else
|
|
164
152
|
els = document.querySelectorAll(selector);
|
|
@@ -196,8 +184,8 @@ clickedElement();
|
|
|
196
184
|
|
|
197
185
|
export default {
|
|
198
186
|
parseTextToHtml,
|
|
199
|
-
getAttributes,
|
|
200
187
|
cssPath,
|
|
201
188
|
domParser,
|
|
189
|
+
queryDocumentSelectorAll,
|
|
202
190
|
queryFrameSelectorAll
|
|
203
191
|
};
|
package/src/index.old.js
CHANGED
|
@@ -371,7 +371,62 @@ async function complexSelector(comSelector, callback) {
|
|
|
371
371
|
return true;
|
|
372
372
|
}
|
|
373
373
|
|
|
374
|
-
|
|
374
|
+
export function getFrameSelector(selector) {
|
|
375
|
+
let selectorArray = [];
|
|
376
|
+
if (selector) {
|
|
377
|
+
let selectors = [selector];
|
|
378
|
+
if(selector.indexOf(',') !== -1){
|
|
379
|
+
selectors = selector.split(',');
|
|
380
|
+
}
|
|
381
|
+
for (let selector of selectors){
|
|
382
|
+
let els;
|
|
383
|
+
if(selector.indexOf(';') !== -1) {
|
|
384
|
+
let [documentSelector, targetSelector] = selector.split(';');
|
|
385
|
+
let frame = document.querySelector(documentSelector);
|
|
386
|
+
if (frame)
|
|
387
|
+
selectorArray.push({Document: frame.contentDocument, selector: targetSelector});
|
|
388
|
+
}
|
|
389
|
+
else
|
|
390
|
+
selectorArray.push({Document: document, selector: selector});
|
|
391
|
+
}
|
|
392
|
+
return selectorArray;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
export function queryFrameSelectorAll(selector) {
|
|
396
|
+
let elements = [];
|
|
397
|
+
|
|
398
|
+
if (selector) {
|
|
399
|
+
let selectors = [selector];
|
|
400
|
+
if(selector.indexOf(',') !== -1){
|
|
401
|
+
selectors = selector.split(',');
|
|
402
|
+
}
|
|
403
|
+
for (let selector of selectors){
|
|
404
|
+
let els;
|
|
405
|
+
if(selector.indexOf(';') !== -1) {
|
|
406
|
+
let [documentSelector, targetSelector] = selector.split(';');
|
|
407
|
+
let frame = document.querySelector(documentSelector);
|
|
408
|
+
if (frame) {
|
|
409
|
+
let targetDocument = frame.contentDocument;
|
|
410
|
+
if (targetSelector)
|
|
411
|
+
els = targetDocument.querySelectorAll(targetSelector);
|
|
412
|
+
else
|
|
413
|
+
if (targetDocument.clickedElement)
|
|
414
|
+
els = [targetDocument.clickedElement];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else
|
|
418
|
+
els = document.querySelectorAll(selector);
|
|
419
|
+
if (els){
|
|
420
|
+
els = Array.prototype.slice.call(els);
|
|
421
|
+
elements = elements.concat(els);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return elements;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
375
430
|
export default {
|
|
376
431
|
getElementPath,
|
|
377
432
|
isValidSelector,
|