@cocreate/utils 1.5.1 → 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 +7 -0
- package/package.json +1 -1
- package/src/index.js +49 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [1.5.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.5.0...v1.5.1) (2022-02-01)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -113,29 +113,61 @@ export function domParser(str) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
export function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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});
|
|
124
130
|
}
|
|
131
|
+
else
|
|
132
|
+
selectorArray.push({Document: document, selector: selector});
|
|
125
133
|
}
|
|
134
|
+
return selectorArray;
|
|
135
|
+
}
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
export function queryFrameSelectorAll(selector) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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);
|
|
136
165
|
}
|
|
137
166
|
}
|
|
167
|
+
return elements;
|
|
168
|
+
}
|
|
138
169
|
}
|
|
170
|
+
|
|
139
171
|
// export function computeStyles(el, properties) {
|
|
140
172
|
// let computed = window.getComputedStyle(el);
|
|
141
173
|
// let result = {};
|
|
@@ -163,5 +195,6 @@ export default {
|
|
|
163
195
|
parseTextToHtml,
|
|
164
196
|
getAttributes,
|
|
165
197
|
cssPath,
|
|
166
|
-
domParser
|
|
198
|
+
domParser,
|
|
199
|
+
queryFrameSelectorAll
|
|
167
200
|
};
|