@domql/utils 2.5.148 → 2.5.151
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/component.js +21 -9
- package/cookie.js +34 -0
- package/dist/cjs/component.js +22 -5
- package/dist/cjs/cookie.js +24 -1
- package/dist/cjs/object.js +3 -3
- package/object.js +1 -1
- package/package.json +2 -2
package/component.js
CHANGED
|
@@ -28,6 +28,7 @@ export const checkIfKeyIsProperty = (key) => {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export const addAdditionalExtend = (newExtend, element) => {
|
|
31
|
+
if (!newExtend) return element
|
|
31
32
|
const { extend: elementExtend } = element
|
|
32
33
|
const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend]
|
|
33
34
|
const receivedArray = isArray(newExtend) ? newExtend : [newExtend]
|
|
@@ -36,15 +37,30 @@ export const addAdditionalExtend = (newExtend, element) => {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const checkIfSugar = (element, parent, key) => {
|
|
39
|
-
const {
|
|
40
|
+
const {
|
|
41
|
+
extend,
|
|
42
|
+
props,
|
|
43
|
+
childExtend,
|
|
44
|
+
extends: extendProps,
|
|
45
|
+
childrenExtends,
|
|
46
|
+
childProps,
|
|
47
|
+
children,
|
|
48
|
+
on,
|
|
49
|
+
$collection,
|
|
50
|
+
$stateCollection,
|
|
51
|
+
$propsCollection
|
|
52
|
+
} = element
|
|
40
53
|
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection
|
|
54
|
+
if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
|
|
55
|
+
parent.error('Sugar component includes params for builtin components', { verbose: true })
|
|
56
|
+
}
|
|
41
57
|
return !hasComponentAttrs || childProps || extendProps || children || childrenExtends
|
|
42
58
|
}
|
|
43
59
|
|
|
44
60
|
export const extendizeByKey = (element, parent, key) => {
|
|
45
61
|
const { context } = parent
|
|
46
62
|
const { tag, extend, childrenExtends } = element
|
|
47
|
-
const isSugar = checkIfSugar(element)
|
|
63
|
+
const isSugar = checkIfSugar(element, parent, key)
|
|
48
64
|
|
|
49
65
|
const extendFromKey = key.includes('+')
|
|
50
66
|
? key.split('+') // get array of componentKeys
|
|
@@ -54,18 +70,14 @@ export const extendizeByKey = (element, parent, key) => {
|
|
|
54
70
|
? [key.split('.')[0]] // get component key split .
|
|
55
71
|
: [key]
|
|
56
72
|
|
|
57
|
-
// console.log(extendFromKey)
|
|
58
|
-
// console.log(context, context?.components)
|
|
59
|
-
// console.log(element)
|
|
60
73
|
const isExtendKeyComponent = context && context.components[extendFromKey]
|
|
61
|
-
|
|
62
74
|
if (element === isExtendKeyComponent) return element
|
|
63
75
|
else if (isSugar) {
|
|
64
|
-
const newElem = {
|
|
76
|
+
const newElem = addAdditionalExtend(element.extends, {
|
|
65
77
|
extend: extendFromKey,
|
|
66
78
|
tag,
|
|
67
79
|
props: { ...element }
|
|
68
|
-
}
|
|
80
|
+
})
|
|
69
81
|
if (childrenExtends) newElem.childExtend = childrenExtends
|
|
70
82
|
return newElem
|
|
71
83
|
} else if (!extend || extend === true) {
|
|
@@ -100,7 +112,7 @@ export const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
|
100
112
|
if (newChild?.ignoreExtend) continue
|
|
101
113
|
if (!childElem) element[childKey] = deepCloneWithExtend(newChild)
|
|
102
114
|
else {
|
|
103
|
-
const isSugar = checkIfSugar(childElem)
|
|
115
|
+
const isSugar = checkIfSugar(childElem, parent, key)
|
|
104
116
|
if (!isSugar) continue
|
|
105
117
|
const inheritedChildElem = element[childKey].props
|
|
106
118
|
if (isObjectLike(newChild)) {
|
package/cookie.js
CHANGED
|
@@ -32,3 +32,37 @@ export const removeCookie = (cname) => {
|
|
|
32
32
|
if (isUndefined(document) || isUndefined(document.cookie)) return
|
|
33
33
|
document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Load item from the localStorage
|
|
38
|
+
*
|
|
39
|
+
* @param key -- string to identify the storage item
|
|
40
|
+
*/
|
|
41
|
+
export function getLocalStorage (key) {
|
|
42
|
+
let savedJSON
|
|
43
|
+
|
|
44
|
+
if (window.localStorage) {
|
|
45
|
+
try {
|
|
46
|
+
savedJSON = JSON.parse(window.localStorage.getItem(key))
|
|
47
|
+
} catch (e) {}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (typeof savedJSON !== 'undefined') {
|
|
51
|
+
return savedJSON
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Save the data to window.localStorage
|
|
56
|
+
*
|
|
57
|
+
* @param key - local storage key to save the data under
|
|
58
|
+
* @param data - the data to save
|
|
59
|
+
*/
|
|
60
|
+
export function setLocalStorage (key, data) {
|
|
61
|
+
if (data && window.localStorage) {
|
|
62
|
+
if (typeof data === 'object') {
|
|
63
|
+
window.localStorage.setItem(key, JSON.stringify(data))
|
|
64
|
+
} else {
|
|
65
|
+
window.localStorage.setItem(key, data)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/dist/cjs/component.js
CHANGED
|
@@ -49,6 +49,8 @@ const checkIfKeyIsProperty = (key) => {
|
|
|
49
49
|
return /^[a-z]*$/.test(firstCharKey);
|
|
50
50
|
};
|
|
51
51
|
const addAdditionalExtend = (newExtend, element) => {
|
|
52
|
+
if (!newExtend)
|
|
53
|
+
return element;
|
|
52
54
|
const { extend: elementExtend } = element;
|
|
53
55
|
const originalArray = (0, import__.isArray)(elementExtend) ? elementExtend : [elementExtend];
|
|
54
56
|
const receivedArray = (0, import__.isArray)(newExtend) ? newExtend : [newExtend];
|
|
@@ -56,24 +58,39 @@ const addAdditionalExtend = (newExtend, element) => {
|
|
|
56
58
|
return { ...element, extend };
|
|
57
59
|
};
|
|
58
60
|
const checkIfSugar = (element, parent, key) => {
|
|
59
|
-
const {
|
|
61
|
+
const {
|
|
62
|
+
extend,
|
|
63
|
+
props,
|
|
64
|
+
childExtend,
|
|
65
|
+
extends: extendProps,
|
|
66
|
+
childrenExtends,
|
|
67
|
+
childProps,
|
|
68
|
+
children,
|
|
69
|
+
on,
|
|
70
|
+
$collection,
|
|
71
|
+
$stateCollection,
|
|
72
|
+
$propsCollection
|
|
73
|
+
} = element;
|
|
60
74
|
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
|
|
75
|
+
if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
|
|
76
|
+
parent.error("Sugar component includes params for builtin components", { verbose: true });
|
|
77
|
+
}
|
|
61
78
|
return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
|
|
62
79
|
};
|
|
63
80
|
const extendizeByKey = (element, parent, key) => {
|
|
64
81
|
const { context } = parent;
|
|
65
82
|
const { tag, extend, childrenExtends } = element;
|
|
66
|
-
const isSugar = checkIfSugar(element);
|
|
83
|
+
const isSugar = checkIfSugar(element, parent, key);
|
|
67
84
|
const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
|
|
68
85
|
const isExtendKeyComponent = context && context.components[extendFromKey];
|
|
69
86
|
if (element === isExtendKeyComponent)
|
|
70
87
|
return element;
|
|
71
88
|
else if (isSugar) {
|
|
72
|
-
const newElem = {
|
|
89
|
+
const newElem = addAdditionalExtend(element.extends, {
|
|
73
90
|
extend: extendFromKey,
|
|
74
91
|
tag,
|
|
75
92
|
props: { ...element }
|
|
76
|
-
};
|
|
93
|
+
});
|
|
77
94
|
if (childrenExtends)
|
|
78
95
|
newElem.childExtend = childrenExtends;
|
|
79
96
|
return newElem;
|
|
@@ -109,7 +126,7 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
|
109
126
|
if (!childElem)
|
|
110
127
|
element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
|
|
111
128
|
else {
|
|
112
|
-
const isSugar = checkIfSugar(childElem);
|
|
129
|
+
const isSugar = checkIfSugar(childElem, parent, key);
|
|
113
130
|
if (!isSugar)
|
|
114
131
|
continue;
|
|
115
132
|
const inheritedChildElem = element[childKey].props;
|
package/dist/cjs/cookie.js
CHANGED
|
@@ -19,9 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var cookie_exports = {};
|
|
20
20
|
__export(cookie_exports, {
|
|
21
21
|
getCookie: () => getCookie,
|
|
22
|
+
getLocalStorage: () => getLocalStorage,
|
|
22
23
|
isMobile: () => isMobile,
|
|
23
24
|
removeCookie: () => removeCookie,
|
|
24
|
-
setCookie: () => setCookie
|
|
25
|
+
setCookie: () => setCookie,
|
|
26
|
+
setLocalStorage: () => setLocalStorage
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(cookie_exports);
|
|
27
29
|
var import_types = require("./types");
|
|
@@ -55,3 +57,24 @@ const removeCookie = (cname) => {
|
|
|
55
57
|
return;
|
|
56
58
|
import_utils.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
57
59
|
};
|
|
60
|
+
function getLocalStorage(key) {
|
|
61
|
+
let savedJSON;
|
|
62
|
+
if (window.localStorage) {
|
|
63
|
+
try {
|
|
64
|
+
savedJSON = JSON.parse(window.localStorage.getItem(key));
|
|
65
|
+
} catch (e) {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (typeof savedJSON !== "undefined") {
|
|
69
|
+
return savedJSON;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function setLocalStorage(key, data) {
|
|
73
|
+
if (data && window.localStorage) {
|
|
74
|
+
if (typeof data === "object") {
|
|
75
|
+
window.localStorage.setItem(key, JSON.stringify(data));
|
|
76
|
+
} else {
|
|
77
|
+
window.localStorage.setItem(key, data);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
package/dist/cjs/object.js
CHANGED
|
@@ -191,10 +191,10 @@ const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited
|
|
|
191
191
|
return o;
|
|
192
192
|
};
|
|
193
193
|
const deepStringify = (obj, stringified = {}) => {
|
|
194
|
-
var _a;
|
|
194
|
+
var _a, _b;
|
|
195
195
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
196
|
-
|
|
197
|
-
obj = (
|
|
196
|
+
(obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn("Trying to clone element or state at", obj);
|
|
197
|
+
obj = (_b = obj.parse) == null ? void 0 : _b.call(obj);
|
|
198
198
|
}
|
|
199
199
|
for (const prop in obj) {
|
|
200
200
|
const objProp = obj[prop];
|
package/object.js
CHANGED
|
@@ -217,7 +217,7 @@ export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}, v
|
|
|
217
217
|
*/
|
|
218
218
|
export const deepStringify = (obj, stringified = {}) => {
|
|
219
219
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
220
|
-
|
|
220
|
+
(obj.__element || obj.parent?.__element).warn('Trying to clone element or state at', obj)
|
|
221
221
|
obj = obj.parse?.()
|
|
222
222
|
}
|
|
223
223
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.151",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "yarn build:cjs",
|
|
26
26
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "f37b51f84b8bca80b8bce7887e83d61ac25eb3d5",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|