@cocreate/utils 1.7.5 → 1.8.1

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,24 @@
1
+ ## [1.8.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.8.0...v1.8.1) (2022-07-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * remove function queryFrameSelector rhas been replaced by queryDocumentSelectorAll ([3c11054](https://github.com/CoCreate-app/CoCreate-utils/commit/3c110543598ded5753c9d715f3cb650d46e93263))
7
+
8
+ # [1.8.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.6...v1.8.0) (2022-07-01)
9
+
10
+
11
+ ### Features
12
+
13
+ * queryDocumentSelectorAll - ability to query iframes and parent of iframes ([90bd26b](https://github.com/CoCreate-app/CoCreate-utils/commit/90bd26b139a6a5413ac67a92504cf533f10e0838))
14
+
15
+ ## [1.7.6](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.5...v1.7.6) (2022-06-27)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * remove functon getAttributes ([162228d](https://github.com/CoCreate-app/CoCreate-utils/commit/162228ddd99bcdf64a59088bddf2a6216a911898))
21
+
1
22
  ## [1.7.5](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.7.4...v1.7.5) (2022-06-24)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.7.5",
3
+ "version": "1.8.1",
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
@@ -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];
@@ -127,29 +120,7 @@ export function domParser(str) {
127
120
  }
128
121
  }
129
122
 
130
- export function getFrameSelector(selector) {
131
- let selectorArray = [];
132
- if (selector) {
133
- let selectors = [selector];
134
- if(selector.indexOf(',') !== -1){
135
- selectors = selector.split(',');
136
- }
137
- for (let selector of selectors){
138
- let els;
139
- if(selector.indexOf(';') !== -1) {
140
- let [documentSelector, targetSelector] = selector.split(';');
141
- let frame = document.querySelector(documentSelector);
142
- if (frame)
143
- selectorArray.push({Document: frame.contentDocument, selector: targetSelector});
144
- }
145
- else
146
- selectorArray.push({Document: document, selector: selector});
147
- }
148
- return selectorArray;
149
- }
150
- }
151
-
152
- export function queryFrameSelectorAll(selector) {
123
+ export function queryDocumentSelectorAll(selector) {
153
124
  let elements = [];
154
125
 
155
126
  if (selector) {
@@ -160,16 +131,22 @@ export function queryFrameSelectorAll(selector) {
160
131
  for (let selector of selectors){
161
132
  let els;
162
133
  if(selector.indexOf(';') !== -1) {
134
+ let targetDocument;
163
135
  let [documentSelector, targetSelector] = selector.split(';');
164
- let frame = document.querySelector(documentSelector);
165
- if (frame) {
166
- let targetDocument = frame.contentDocument;
167
- if (targetSelector)
168
- els = targetDocument.querySelectorAll(targetSelector);
169
- else
170
- if (targetDocument.clickedElement)
171
- els = [targetDocument.clickedElement];
172
- }
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
+ }
173
150
  }
174
151
  else
175
152
  els = document.querySelectorAll(selector);
@@ -207,8 +184,7 @@ clickedElement();
207
184
 
208
185
  export default {
209
186
  parseTextToHtml,
210
- getAttributes,
211
187
  cssPath,
212
188
  domParser,
213
- queryFrameSelectorAll
189
+ queryDocumentSelectorAll
214
190
  };
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,