@cocreate/utils 1.7.6 → 1.9.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 +26 -0
- package/package.json +1 -1
- package/src/index.js +47 -27
- package/src/index.old.js +56 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
# [1.9.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.8.1...v1.9.0) (2022-07-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add queryDocumentSelector to export default ([b067ed1](https://github.com/CoCreate-app/CoCreate-utils/commit/b067ed1354488cf52014e2d417d75c5be455fc6f))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* queryDocumentSelector to return one element from an iframe or iframes parent ([477f179](https://github.com/CoCreate-app/CoCreate-utils/commit/477f179ef4e00aab219d12a5a9ae3a5e1cfae992))
|
|
12
|
+
|
|
13
|
+
## [1.8.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.8.0...v1.8.1) (2022-07-01)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* remove function queryFrameSelector rhas been replaced by queryDocumentSelectorAll ([3c11054](https://github.com/CoCreate-app/CoCreate-utils/commit/3c110543598ded5753c9d715f3cb650d46e93263))
|
|
19
|
+
|
|
20
|
+
# [1.8.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.6...v1.8.0) (2022-07-01)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* queryDocumentSelectorAll - ability to query iframes and parent of iframes ([90bd26b](https://github.com/CoCreate-app/CoCreate-utils/commit/90bd26b139a6a5413ac67a92504cf533f10e0838))
|
|
26
|
+
|
|
1
27
|
## [1.7.6](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.5...v1.7.6) (2022-06-27)
|
|
2
28
|
|
|
3
29
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -120,8 +120,9 @@ export function domParser(str) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
export function
|
|
124
|
-
let
|
|
123
|
+
export function queryDocumentSelectorAll(selector) {
|
|
124
|
+
let elements = [];
|
|
125
|
+
|
|
125
126
|
if (selector) {
|
|
126
127
|
let selectors = [selector];
|
|
127
128
|
if(selector.indexOf(',') !== -1){
|
|
@@ -130,48 +131,66 @@ export function getFrameSelector(selector) {
|
|
|
130
131
|
for (let selector of selectors){
|
|
131
132
|
let els;
|
|
132
133
|
if(selector.indexOf(';') !== -1) {
|
|
134
|
+
let targetDocument;
|
|
133
135
|
let [documentSelector, targetSelector] = selector.split(';');
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
}
|
|
137
150
|
}
|
|
138
151
|
else
|
|
139
|
-
|
|
152
|
+
els = document.querySelectorAll(selector);
|
|
153
|
+
if (els){
|
|
154
|
+
els = Array.prototype.slice.call(els);
|
|
155
|
+
elements = elements.concat(els);
|
|
156
|
+
}
|
|
140
157
|
}
|
|
141
|
-
return
|
|
158
|
+
return elements;
|
|
142
159
|
}
|
|
143
160
|
}
|
|
144
161
|
|
|
145
|
-
export function
|
|
146
|
-
let elements = [];
|
|
147
|
-
|
|
162
|
+
export function queryDocumentSelector(selector) {
|
|
148
163
|
if (selector) {
|
|
149
164
|
let selectors = [selector];
|
|
150
165
|
if(selector.indexOf(',') !== -1){
|
|
151
166
|
selectors = selector.split(',');
|
|
152
167
|
}
|
|
153
168
|
for (let selector of selectors){
|
|
154
|
-
let
|
|
169
|
+
let el;
|
|
155
170
|
if(selector.indexOf(';') !== -1) {
|
|
171
|
+
let targetDocument;
|
|
156
172
|
let [documentSelector, targetSelector] = selector.split(';');
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
if (['parent', 'parentDocument'].includes(documentSelector))
|
|
174
|
+
targetDocument = window.parent.document;
|
|
175
|
+
else {
|
|
176
|
+
let frame = document.querySelector(documentSelector);
|
|
177
|
+
if (frame)
|
|
178
|
+
targetDocument = frame.contentDocument;
|
|
179
|
+
}
|
|
180
|
+
if (targetDocument){
|
|
181
|
+
if (targetSelector)
|
|
182
|
+
el = targetDocument.querySelector(targetSelector);
|
|
183
|
+
else
|
|
184
|
+
if (targetDocument.clickedElement)
|
|
185
|
+
el = [targetDocument.clickedElement];
|
|
186
|
+
}
|
|
166
187
|
}
|
|
167
188
|
else
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
elements = elements.concat(els);
|
|
172
|
-
}
|
|
189
|
+
el = document.querySelector(selector);
|
|
190
|
+
if (el)
|
|
191
|
+
return el
|
|
173
192
|
}
|
|
174
|
-
return
|
|
193
|
+
return;
|
|
175
194
|
}
|
|
176
195
|
}
|
|
177
196
|
|
|
@@ -202,5 +221,6 @@ export default {
|
|
|
202
221
|
parseTextToHtml,
|
|
203
222
|
cssPath,
|
|
204
223
|
domParser,
|
|
205
|
-
|
|
224
|
+
queryDocumentSelector,
|
|
225
|
+
queryDocumentSelectorAll
|
|
206
226
|
};
|
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,
|