Skip to content

Commit b7d4c93

Browse files
committed
fix: removed unused utilties
1 parent 48bd0ab commit b7d4c93

File tree

1 file changed

+92
-194
lines changed

1 file changed

+92
-194
lines changed

src/index.js

+92-194
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//ToDo can be replaced with elememt.closest(selector) || elememt.parentElement.closest(selector)
12
export function getParentFromElement(element, parent_class, attributes) {
23
if (parent_class) {
34
if (element.classList.contains(parent_class)) {
@@ -30,20 +31,20 @@ export function getParentFromElement(element, parent_class, attributes) {
3031
}
3132

3233

33-
export function isJsonString(str_data) {
34-
try {
35-
let json_data = JSON.parse(str_data);
36-
if (typeof json_data === "object" && json_data != null) {
37-
return true;
38-
}
39-
else {
40-
return false;
41-
}
42-
}
43-
catch (e) {
44-
return false;
45-
}
46-
}
34+
// export function isJsonString(str_data) {
35+
// try {
36+
// let json_data = JSON.parse(str_data);
37+
// if (typeof json_data === "object" && json_data != null) {
38+
// return true;
39+
// }
40+
// else {
41+
// return false;
42+
// }
43+
// }
44+
// catch (e) {
45+
// return false;
46+
// }
47+
// }
4748

4849
export function getAttributes(element) {
4950
return element.getAttributeNames().reduce((attrMap, name) => {
@@ -52,114 +53,51 @@ export function getAttributes(element) {
5253
}, {});
5354
}
5455

55-
// ToDo: duplicate it is in crud.utils
56-
export function checkAttrValue(value) {
57-
if (!value) return false;
58-
if (/{{\s*([\w\W]+)\s*}}/g.test(value)) {
59-
return false;
60-
}
61-
62-
return true;
63-
}
64-
6556
// ToDo: Maybe can be deprciated
66-
export function getValueFromJonDeep(json, path) {
67-
try {
68-
if (typeof json == 'undefined')
69-
return false;
70-
let subpath = path.split('.');
71-
let find = subpath.shift();
72-
if (subpath.length > 0) {
73-
return this.__getValueFromJonDeep(json[find], subpath.join('.'))
74-
}
75-
return json[find];
76-
}
77-
catch (error) {
78-
console.log(error)
79-
return false;
80-
}
81-
}
82-
83-
// hosseins utills
84-
85-
// function to go through all frames
86-
export function allFrame(callback) {
87-
let allFrames = [{ document, window }];
88-
for (let frame of document.querySelectorAll("iframe")) {
89-
let frameDocument = frame.contentDocument || frame.contentWindow.document;
90-
let frameWindow = frame.contentWindow;
91-
allFrames.push({
92-
document: frameDocument,
93-
window: frameWindow,
94-
frameElement: frame,
95-
});
96-
}
97-
let result = new Set();
98-
for (let frame of allFrames) {
99-
let callbackResult = callback(frame);
100-
if (
101-
callbackResult &&
102-
typeof callbackResult[Symbol.iterator] === "function"
103-
)
104-
callbackResult.forEach((el) => result.add(el));
105-
else if (callbackResult) result.add(callbackResult);
106-
}
107-
108-
return Array.from(result);
109-
}
110-
111-
export function cssPath(node) {
112-
let pathSplits = [];
113-
do {
114-
if (!node || !node.tagName) return false;
115-
let pathSplit = node.tagName.toLowerCase();
116-
if (node.id && node.tagName !== "BODY") pathSplit += "#" + node.id;
117-
118-
if (node.classList.length && node.tagName !== "BODY") {
119-
node.classList.forEach((item) => {
120-
if (item.indexOf(":") === -1) pathSplit += "." + item;
121-
});
122-
}
123-
124-
if (node.tagName !== "BODY" && node.parentNode) {
125-
let index = Array.prototype.indexOf.call(
126-
node.parentNode.children,
127-
node
128-
);
129-
pathSplit += `:nth-child(${index + 1})`;
130-
}
131-
132-
pathSplits.unshift(pathSplit);
133-
node = node.parentNode;
134-
} while (node.tagName !== "HTML");
135-
136-
return pathSplits.join(" > ");
137-
}
138-
139-
export function getTopMostWindow() {
140-
let parentWindow = window;
141-
while (parentWindow !== window.parent) parentWindow = window.parent;
142-
return parentWindow;
143-
}
144-
145-
export function findIframeFromElement(windowObject, element) {
146-
let frameElement;
147-
allFrame((frame) => {
148-
if (frame.document.contains(element)) frameElement = frame.frameElement;
149-
// window.cc.findIframeFromElement(frame.window, element);
150-
});
151-
return frameElement;
152-
}
153-
154-
export function getIframeFromPath(path) {
155-
let topWindow = getTopMostWindow;
57+
// export function getValueFromJonDeep(json, path) {
58+
// try {
59+
// if (typeof json == 'undefined')
60+
// return false;
61+
// let subpath = path.split('.');
62+
// let find = subpath.shift();
63+
// if (subpath.length > 0) {
64+
// return this.__getValueFromJonDeep(json[find], subpath.join('.'))
65+
// }
66+
// return json[find];
67+
// }
68+
// catch (error) {
69+
// console.log(error)
70+
// return false;
71+
// }
72+
// }
15673

157-
path.forEach((selector) => {
158-
if (topWindow) topWindow = topWindow.querySelector(selector);
159-
});
160-
return topWindow;
161-
}
162-
// DO NOT REMOVE
74+
// export function cssPath(node) {
75+
// let pathSplits = [];
76+
// do {
77+
// if (!node || !node.tagName) return false;
78+
// let pathSplit = node.tagName.toLowerCase();
79+
// if (node.id && node.tagName !== "BODY") pathSplit += "#" + node.id;
80+
81+
// if (node.classList.length && node.tagName !== "BODY") {
82+
// node.classList.forEach((item) => {
83+
// if (item.indexOf(":") === -1) pathSplit += "." + item;
84+
// });
85+
// }
86+
87+
// if (node.tagName !== "BODY" && node.parentNode) {
88+
// let index = Array.prototype.indexOf.call(
89+
// node.parentNode.children,
90+
// node
91+
// );
92+
// pathSplit += `:nth-child(${index + 1})`;
93+
// }
94+
95+
// pathSplits.unshift(pathSplit);
96+
// node = node.parentNode;
97+
// } while (node.tagName !== "HTML");
98+
99+
// return pathSplits.join(" > ");
100+
// }
163101

164102
export function* configMatch(elementConfig, element) {
165103
for (let config of elementConfig) {
@@ -187,17 +125,17 @@ export function* configMatch(elementConfig, element) {
187125
// typeof elementConfig: array of objects and every objects containing keys as false, true or a selector
188126
// element: the element to read attributes
189127
// key: the key in which is in elementConfig and on match onSuccess callback will be called
190-
export function configExecuter(element, key, onSuccess, elementConfig) {
191-
for (let config of configMatch(elementConfig || window.elementConfig, element))
192-
if (config[key] === true) return onSuccess(element, config);
193-
else if (config[key] === false) return false;
194-
else if (config[key] === undefined) continue;
195-
else if (isValidSelector(config[key]))
196-
return onSuccess(element, config, true);
197-
else console.warn("builder: wrong element config ", config);
198-
199-
return false;
200-
}
128+
// export function configExecuter(element, key, onSuccess, elementConfig) {
129+
// for (let config of configMatch(elementConfig || window.elementConfig, element))
130+
// if (config[key] === true) return onSuccess(element, config);
131+
// else if (config[key] === false) return false;
132+
// else if (config[key] === undefined) continue;
133+
// else if (isValidSelector(config[key]))
134+
// return onSuccess(element, config, true);
135+
// else console.warn("builder: wrong element config ", config);
136+
137+
// return false;
138+
// }
201139

202140

203141
export function parseTextToHtml(text) {
@@ -206,24 +144,6 @@ export function parseTextToHtml(text) {
206144
else return doc.body.children[0];
207145
}
208146

209-
export function splitBydelimiter(str, delimiter) {
210-
return str.split(delimiter).map((s) => s.trim());
211-
}
212-
213-
export function joinBydelimiter(str, delimiter) {
214-
return str.map((s) => s.trim()).join(delimiter);
215-
}
216-
217-
export function isValidSelector(selector) {
218-
try {
219-
document.createDocumentFragment().querySelector(selector);
220-
}
221-
catch (error) {
222-
return false;
223-
}
224-
return true;
225-
}
226-
227147
export function getElementPath(element, returnContext) {
228148
let path = [];
229149

@@ -241,28 +161,28 @@ export function getElementPath(element, returnContext) {
241161
// }
242162
}
243163

244-
export function logger(level = "all") {
245-
if (!['all', 'error', 'warn', 'log', 'off'].includes(level))
246-
throw new Error('level must be one of all, error, warn, log or off')
247-
return {
248-
error: function(msg) {
249-
// if (compoentToLoad.includes(comName))
250-
if (['all', 'error'].includes(level))
251-
console.error.apply(console, arguments)
252-
},
253-
warn: function(msg) {
254-
// if (compoentToLoad.includes(comName))
255-
if (['all', 'error', 'warn'].includes(level))
256-
console.warn.apply(console, arguments)
257-
},
258-
log: function() {
259-
// if (compoentToLoad.includes(comName))
260-
if (['all', 'error', 'warn', 'log'].includes(level))
261-
console.log.apply(console, arguments)
262-
},
263-
}
164+
// export function logger(level = "all") {
165+
// if (!['all', 'error', 'warn', 'log', 'off'].includes(level))
166+
// throw new Error('level must be one of all, error, warn, log or off')
167+
// return {
168+
// error: function(msg) {
169+
// // if (compoentToLoad.includes(comName))
170+
// if (['all', 'error'].includes(level))
171+
// console.error.apply(console, arguments)
172+
// },
173+
// warn: function(msg) {
174+
// // if (compoentToLoad.includes(comName))
175+
// if (['all', 'error', 'warn'].includes(level))
176+
// console.warn.apply(console, arguments)
177+
// },
178+
// log: function() {
179+
// // if (compoentToLoad.includes(comName))
180+
// if (['all', 'error', 'warn', 'log'].includes(level))
181+
// console.log.apply(console, arguments)
182+
// },
183+
// }
264184

265-
}
185+
// }
266186

267187
export async function waitForLoad(doc) {
268188

@@ -280,16 +200,6 @@ export async function waitForLoad(doc) {
280200
}
281201
}
282202

283-
//export function frameQuerySelector(comSelector) {
284-
// let [canvasSelector, selector] = comSelector.split(';');
285-
// let canvas = this.querySelector(canvasSelector);
286-
// if (!canvas)
287-
// return null;
288-
289-
290-
// return canvas.contentWindow.document.querySelector(selector);
291-
// }
292-
293203
export function getComplexSelector(node, comSelector) {
294204
let selectors = comSelector.split(';');
295205
let canvas = node;
@@ -331,20 +241,8 @@ export function frameQuerySelectorAll(comSelector) {
331241

332242
export default {
333243
getElementPath,
334-
isValidSelector,
335-
joinBydelimiter,
336-
splitBydelimiter,
337244
parseTextToHtml,
338-
configExecuter,
339245
configMatch,
340-
getIframeFromPath,
341-
findIframeFromElement,
342-
getTopMostWindow,
343-
cssPath,
344-
allFrame,
345-
checkAttrValue,
346246
getAttributes,
347-
isJsonString,
348-
getParentFromElement,
349-
logger
350-
}
247+
getParentFromElement
248+
};

0 commit comments

Comments
 (0)