@cocreate/utils 1.4.2 → 1.6.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.6.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.5.1...v1.6.0) (2022-02-03)
2
+
3
+
4
+ ### Features
5
+
6
+ * queryFrameSelectorAll to return elements from other documents, getFrameSelector to pase a selector and return document and selector ([c3b8c27](https://github.com/CoCreate-app/CoCreate-utils/commit/c3b8c27fc1f452b7eac0ac801770e3c0809295f8))
7
+
8
+ ## [1.5.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.5.0...v1.5.1) (2022-02-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * update dependency versions ([f85b89a](https://github.com/CoCreate-app/CoCreate-utils/commit/f85b89a8b27e0a92153739e89345c753917b350f))
14
+
15
+ # [1.5.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.4.3...v1.5.0) (2022-01-29)
16
+
17
+
18
+ ### Features
19
+
20
+ * function to add click event to all documents in order to apply clickedElement to document dom object. this provides a refrence to the element that was actively clicked ([537003d](https://github.com/CoCreate-app/CoCreate-utils/commit/537003de6aa749a8dc215e70926dfc3dd2b830fb))
21
+
22
+ ## [1.4.3](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.4.2...v1.4.3) (2022-01-01)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * get-value attribute value now supports a selector added # to all values currently in get-value attributes ([d48bcd5](https://github.com/CoCreate-app/CoCreate-utils/commit/d48bcd5bdbc715b3aacb8db3b99cd8aa581b72ce))
28
+
1
29
  ## [1.4.2](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.4.1...v1.4.2) (2021-12-25)
2
30
 
3
31
 
package/docs/index.html CHANGED
@@ -117,7 +117,7 @@
117
117
  <div class="svSplitter svHorizontal"> </div>
118
118
 
119
119
  <div class="svPanel">
120
- <iframe get-value="demo" frameBorder="0" height="100%" width="100%" class="min-width:300px"></iframe>
120
+ <iframe get-value="#demo" frameBorder="0" height="100%" width="100%" class="min-width:300px"></iframe>
121
121
  </div>
122
122
 
123
123
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.4.2",
3
+ "version": "1.6.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.62"
64
+ "@cocreate/docs": "^1.2.65"
65
65
  }
66
66
  }
package/src/index.js CHANGED
@@ -1,4 +1,25 @@
1
1
  /*globals DOMParser*/
2
+ function clickedElement() {
3
+ document.addEventListener('click', e => {
4
+ document.clickedElement = e.target;
5
+ });
6
+ let frameDocuments = window.top.frameDocuments;
7
+ if (!frameDocuments){
8
+ window.top.frameDocuments = new Map();
9
+ frameDocuments = window.top.frameDocuments;
10
+ }
11
+ let frames = document.querySelectorAll('iframe');
12
+ for (let frame of frames){
13
+ let frameDocument = frame.contentDocument;
14
+ if (!frameDocuments.has(frameDocument)){
15
+ frameDocuments.set(frameDocument, '')
16
+ frameDocument.addEventListener('click', e => {
17
+ frameDocument.clickedElement = e.target;
18
+ });
19
+ }
20
+ }
21
+ }
22
+
2
23
  export function getAttributes(element) {
3
24
  return element.getAttributeNames().reduce((attrMap, name) => {
4
25
  attrMap[name] = element.getAttribute(name);
@@ -92,29 +113,61 @@ export function domParser(str) {
92
113
  }
93
114
  }
94
115
 
95
- export function queryFrameSelector(selector) {
96
- if(selector.indexOf(';') !== -1) {
97
- let [frameSelector, target] = selector.split(';');
98
- let frame = document.querySelector(frameSelector);
99
- if (frame) {
100
- let Document = frame.contentDocument;
101
- let elements = Document.querySelectorAll(target);
102
- return elements;
116
+ export function getFrameSelector(selector) {
117
+ let selectorArray = [];
118
+ if (selector) {
119
+ let selectors = [selector];
120
+ if(selector.indexOf(',') !== -1){
121
+ selectors = selector.split(',');
122
+ }
123
+ for (let selector of selectors){
124
+ let els;
125
+ if(selector.indexOf(';') !== -1) {
126
+ let [documentSelector, targetSelector] = selector.split(';');
127
+ let frame = document.querySelector(documentSelector);
128
+ if (frame)
129
+ selectorArray.push({Document: frame.contentDocument, selector: targetSelector});
103
130
  }
131
+ else
132
+ selectorArray.push({Document: document, selector: selector});
104
133
  }
134
+ return selectorArray;
135
+ }
105
136
  }
106
137
 
107
138
  export function queryFrameSelectorAll(selector) {
108
- if(selector.indexOf(';') !== -1) {
109
- let [frameSelector, target] = selector.split(';');
110
- let frame = document.querySelector(frameSelector);
111
- if (frame) {
112
- let Document = frame.contentDocument;
113
- let element = Document.querySelector(target);
114
- return element;
139
+ let elements = [];
140
+
141
+ if (selector) {
142
+ let selectors = [selector];
143
+ if(selector.indexOf(',') !== -1){
144
+ selectors = selector.split(',');
145
+ }
146
+ for (let selector of selectors){
147
+ let els;
148
+ if(selector.indexOf(';') !== -1) {
149
+ let [documentSelector, targetSelector] = selector.split(';');
150
+ let frame = document.querySelector(documentSelector);
151
+ if (frame) {
152
+ let targetDocument = frame.contentDocument;
153
+ if (targetSelector)
154
+ els = targetDocument.querySelectorAll(targetSelector);
155
+ else
156
+ if (targetDocument.clickedElement)
157
+ els = [targetDocument.clickedElement];
158
+ }
159
+ }
160
+ else
161
+ els = document.querySelectorAll(selector);
162
+ if (els){
163
+ els = Array.prototype.slice.call(els);
164
+ elements = elements.concat(els);
115
165
  }
116
166
  }
167
+ return elements;
168
+ }
117
169
  }
170
+
118
171
  // export function computeStyles(el, properties) {
119
172
  // let computed = window.getComputedStyle(el);
120
173
  // let result = {};
@@ -136,9 +189,12 @@ export function queryFrameSelectorAll(selector) {
136
189
  // } while (parentElement);
137
190
  // }
138
191
 
192
+ clickedElement();
193
+
139
194
  export default {
140
195
  parseTextToHtml,
141
196
  getAttributes,
142
197
  cssPath,
143
- domParser
198
+ domParser,
199
+ queryFrameSelectorAll
144
200
  };
package/src/index.old.js CHANGED
@@ -366,6 +366,11 @@ async function complexSelector(comSelector, callback) {
366
366
  // return result;
367
367
  // }
368
368
 
369
+ function isObjectEmpty(obj) {
370
+ for (var x in obj) { return false; }
371
+ return true;
372
+ }
373
+
369
374
 
370
375
  export default {
371
376
  getElementPath,