@cocreate/utils 1.8.1 → 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 CHANGED
@@ -1,3 +1,15 @@
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
+
1
13
  ## [1.8.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.8.0...v1.8.1) (2022-07-01)
2
14
 
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/utils",
3
- "version": "1.8.1",
3
+ "version": "1.9.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
@@ -159,6 +159,41 @@ export function queryDocumentSelectorAll(selector) {
159
159
  }
160
160
  }
161
161
 
162
+ export function queryDocumentSelector(selector) {
163
+ if (selector) {
164
+ let selectors = [selector];
165
+ if(selector.indexOf(',') !== -1){
166
+ selectors = selector.split(',');
167
+ }
168
+ for (let selector of selectors){
169
+ let el;
170
+ if(selector.indexOf(';') !== -1) {
171
+ let targetDocument;
172
+ let [documentSelector, targetSelector] = selector.split(';');
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
+ }
187
+ }
188
+ else
189
+ el = document.querySelector(selector);
190
+ if (el)
191
+ return el
192
+ }
193
+ return;
194
+ }
195
+ }
196
+
162
197
  // export function computeStyles(el, properties) {
163
198
  // let computed = window.getComputedStyle(el);
164
199
  // let result = {};
@@ -186,5 +221,6 @@ export default {
186
221
  parseTextToHtml,
187
222
  cssPath,
188
223
  domParser,
224
+ queryDocumentSelector,
189
225
  queryDocumentSelectorAll
190
226
  };