@cocreate/utils 1.4.3 → 1.6.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 +28 -0
- package/docs/index.html +1 -1
- package/package.json +2 -2
- package/src/index.js +72 -16
- package/src/index.old.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [1.6.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.6.0...v1.6.1) (2022-02-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* replaced show and hide class hidden with attribute hidden ([f1ad793](https://github.com/CoCreate-app/CoCreate-utils/commit/f1ad793841db4abe67032a24625e8a46f7560bbf))
|
|
7
|
+
|
|
8
|
+
# [1.6.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.5.1...v1.6.0) (2022-02-03)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* 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))
|
|
14
|
+
|
|
15
|
+
## [1.5.1](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.5.0...v1.5.1) (2022-02-01)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* update dependency versions ([f85b89a](https://github.com/CoCreate-app/CoCreate-utils/commit/f85b89a8b27e0a92153739e89345c753917b350f))
|
|
21
|
+
|
|
22
|
+
# [1.5.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.4.3...v1.5.0) (2022-01-29)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* 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))
|
|
28
|
+
|
|
1
29
|
## [1.4.3](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.4.2...v1.4.3) (2022-01-01)
|
|
2
30
|
|
|
3
31
|
|
package/docs/index.html
CHANGED
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
<div class="container svColumn overflow:hidden card position:relative border-radius:2px width:auto height:100%" id="sandbox">
|
|
105
105
|
<div class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
|
|
106
106
|
<a class="margin-right:10px" id="code" show="#preview" hide="#code, #view"><i class="far fa-eye"></i></a>
|
|
107
|
-
<a class="margin-right:10px
|
|
107
|
+
<a class="margin-right:10px" id="preview" show="#code, #view" hide="#preview" hidden><i class="fas fa-code"></i></a>
|
|
108
108
|
<a class="margin-right:5px" fullscreen target="#playground"><i class="fas fa-expand"></i></a>
|
|
109
109
|
</div>
|
|
110
110
|
<div class="svRow">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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",
|
|
@@ -61,6 +61,6 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/docs": "^1.2.
|
|
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
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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