@domql/utils 2.5.156 → 2.5.161
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/array.js +4 -4
- package/component.js +2 -2
- package/dist/cjs/array.js +3 -3
- package/dist/cjs/component.js +1 -1
- package/dist/cjs/object.js +39 -63
- package/dist/esm/array.js +122 -0
- package/dist/esm/component.js +241 -0
- package/dist/esm/cookie.js +60 -0
- package/dist/esm/env.js +12 -0
- package/dist/esm/function.js +61 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/key.js +13 -0
- package/dist/esm/log.js +15 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +665 -0
- package/dist/esm/string.js +124 -0
- package/dist/esm/tags.js +145 -0
- package/dist/esm/types.js +64 -0
- package/object.js +67 -113
- package/package.json +6 -6
package/array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { deepClone, deepMerge } from './object'
|
|
4
4
|
import { isArray, isNumber, isString } from './types'
|
|
5
5
|
|
|
6
6
|
export const arrayContainsOtherArray = (arr1, arr2) => {
|
|
@@ -39,15 +39,15 @@ export const joinArrays = (...arrays) => {
|
|
|
39
39
|
/**
|
|
40
40
|
* Merges array extendtypes
|
|
41
41
|
*/
|
|
42
|
-
export const mergeArray = (arr,
|
|
43
|
-
return arr.reduce((a, c) => deepMerge(a,
|
|
42
|
+
export const mergeArray = (arr, exclude = []) => {
|
|
43
|
+
return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude }), exclude), {})
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Merges array extends
|
|
48
48
|
*/
|
|
49
49
|
export const mergeAndCloneIfArray = obj => {
|
|
50
|
-
return isArray(obj) ? mergeArray(obj) :
|
|
50
|
+
return isArray(obj) ? mergeArray(obj) : deepClone(obj)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export const cutArrayBeforeValue = (arr, value) => {
|
package/component.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
deepClone,
|
|
5
5
|
exec,
|
|
6
6
|
isArray,
|
|
7
7
|
isFunction,
|
|
@@ -116,7 +116,7 @@ export const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
|
116
116
|
|
|
117
117
|
if (newChild?.ignoreExtend) continue
|
|
118
118
|
if (newChild === null) assignChild(null)
|
|
119
|
-
else if (!childElem) assignChild(
|
|
119
|
+
else if (!childElem) assignChild(deepClone(newChild))
|
|
120
120
|
else {
|
|
121
121
|
const isSugarChildElem = checkIfSugar(childElem, parent, key)
|
|
122
122
|
if (isSugarChildElem) continue
|
package/dist/cjs/array.js
CHANGED
|
@@ -67,11 +67,11 @@ const swapItemsInArray = (arr, i, j) => {
|
|
|
67
67
|
const joinArrays = (...arrays) => {
|
|
68
68
|
return [].concat(...arrays);
|
|
69
69
|
};
|
|
70
|
-
const mergeArray = (arr,
|
|
71
|
-
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.
|
|
70
|
+
const mergeArray = (arr, exclude = []) => {
|
|
71
|
+
return arr.reduce((a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, { exclude }), exclude), {});
|
|
72
72
|
};
|
|
73
73
|
const mergeAndCloneIfArray = (obj) => {
|
|
74
|
-
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.
|
|
74
|
+
return (0, import_types.isArray)(obj) ? mergeArray(obj) : (0, import_object.deepClone)(obj);
|
|
75
75
|
};
|
|
76
76
|
const cutArrayBeforeValue = (arr, value) => {
|
|
77
77
|
const index = arr.indexOf(value);
|
package/dist/cjs/component.js
CHANGED
|
@@ -135,7 +135,7 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
|
135
135
|
if (newChild === null)
|
|
136
136
|
assignChild(null);
|
|
137
137
|
else if (!childElem)
|
|
138
|
-
assignChild((0, import__.
|
|
138
|
+
assignChild((0, import__.deepClone)(newChild));
|
|
139
139
|
else {
|
|
140
140
|
const isSugarChildElem = checkIfSugar(childElem, parent, key);
|
|
141
141
|
if (isSugarChildElem)
|
package/dist/cjs/object.js
CHANGED
|
@@ -22,8 +22,6 @@ __export(object_exports, {
|
|
|
22
22
|
createNestedObject: () => createNestedObject,
|
|
23
23
|
createObjectWithoutPrototype: () => createObjectWithoutPrototype,
|
|
24
24
|
deepClone: () => deepClone,
|
|
25
|
-
deepCloneExclude: () => deepCloneExclude,
|
|
26
|
-
deepCloneWithExtend: () => deepCloneWithExtend,
|
|
27
25
|
deepContains: () => deepContains,
|
|
28
26
|
deepDestringify: () => deepDestringify,
|
|
29
27
|
deepDiff: () => deepDiff,
|
|
@@ -117,78 +115,56 @@ const clone = (obj, excludeFrom = []) => {
|
|
|
117
115
|
}
|
|
118
116
|
return o;
|
|
119
117
|
};
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if ((0, import_types.isArray)(v)) {
|
|
134
|
-
o[k] = v.map((x) => deepCloneExclude(x, excludeFrom));
|
|
135
|
-
} else if ((0, import_types.isObject)(v)) {
|
|
136
|
-
o[k] = deepCloneExclude(v, excludeFrom);
|
|
137
|
-
} else
|
|
138
|
-
o[k] = v;
|
|
139
|
-
}
|
|
140
|
-
return o;
|
|
141
|
-
};
|
|
142
|
-
const mergeArrayExclude = (arr, excl = []) => {
|
|
143
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepCloneExclude(curr, excl)), {});
|
|
144
|
-
};
|
|
145
|
-
const deepClone = (obj, exclude = [], cleanUndefined = false, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
146
|
-
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj))
|
|
118
|
+
const mergeArrayExclude = (arr, exclude = []) => {
|
|
119
|
+
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
|
|
120
|
+
};
|
|
121
|
+
const deepClone = (obj, options = {}) => {
|
|
122
|
+
const {
|
|
123
|
+
exclude = [],
|
|
124
|
+
cleanUndefined = false,
|
|
125
|
+
cleanNull = false,
|
|
126
|
+
window: targetWindow,
|
|
127
|
+
visited = /* @__PURE__ */ new WeakMap(),
|
|
128
|
+
handleExtend = false
|
|
129
|
+
} = options;
|
|
130
|
+
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
|
|
147
131
|
return obj;
|
|
148
|
-
|
|
132
|
+
}
|
|
133
|
+
if (visited.has(obj)) {
|
|
149
134
|
return visited.get(obj);
|
|
150
|
-
|
|
135
|
+
}
|
|
136
|
+
const clone2 = targetWindow ? (0, import_types.isArray)(obj) ? new targetWindow.Array() : new targetWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
|
|
151
137
|
visited.set(obj, clone2);
|
|
152
138
|
for (const key in obj) {
|
|
153
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return clone2;
|
|
167
|
-
};
|
|
168
|
-
const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
|
|
169
|
-
if ((0, import_types.isObjectLike)(obj)) {
|
|
170
|
-
if (visited.has(obj)) {
|
|
171
|
-
return obj;
|
|
139
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key))
|
|
140
|
+
continue;
|
|
141
|
+
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
|
|
142
|
+
continue;
|
|
143
|
+
const value = obj[key];
|
|
144
|
+
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value))
|
|
145
|
+
continue;
|
|
146
|
+
if ((0, import_node.isDOMNode)(value)) {
|
|
147
|
+
clone2[key] = value;
|
|
148
|
+
continue;
|
|
172
149
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
|
|
176
|
-
for (const prop in obj) {
|
|
177
|
-
if (!Object.prototype.hasOwnProperty.call(obj, prop))
|
|
150
|
+
if (handleExtend && key === "extend" && (0, import_types.isArray)(value)) {
|
|
151
|
+
clone2[key] = (0, import_array.mergeArray)(value, exclude);
|
|
178
152
|
continue;
|
|
179
|
-
|
|
180
|
-
if (
|
|
153
|
+
}
|
|
154
|
+
if ((0, import_types.isFunction)(value) && targetWindow) {
|
|
155
|
+
clone2[key] = targetWindow.eval("(" + value.toString() + ")");
|
|
181
156
|
continue;
|
|
182
157
|
}
|
|
183
|
-
if ((0, import_types.isObjectLike)(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
158
|
+
if ((0, import_types.isObjectLike)(value)) {
|
|
159
|
+
clone2[key] = deepClone(value, {
|
|
160
|
+
...options,
|
|
161
|
+
visited
|
|
162
|
+
});
|
|
187
163
|
} else {
|
|
188
|
-
|
|
164
|
+
clone2[key] = value;
|
|
189
165
|
}
|
|
190
166
|
}
|
|
191
|
-
return
|
|
167
|
+
return clone2;
|
|
192
168
|
};
|
|
193
169
|
const deepStringify = (obj, stringified = {}) => {
|
|
194
170
|
var _a, _b;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { deepClone, deepMerge } from "./object";
|
|
2
|
+
import { isArray, isNumber, isString } from "./types";
|
|
3
|
+
const arrayContainsOtherArray = (arr1, arr2) => {
|
|
4
|
+
return arr2.every((val) => arr1.includes(val));
|
|
5
|
+
};
|
|
6
|
+
const getFrequencyInArray = (arr, value) => {
|
|
7
|
+
return arr.reduce((count, currentValue) => {
|
|
8
|
+
return currentValue === value ? count + 1 : count;
|
|
9
|
+
}, 0);
|
|
10
|
+
};
|
|
11
|
+
const removeFromArray = (arr, index) => {
|
|
12
|
+
if (isString(index))
|
|
13
|
+
index = parseInt(index);
|
|
14
|
+
if (isNumber(index)) {
|
|
15
|
+
if (index < 0 || index >= arr.length || isNaN(index)) {
|
|
16
|
+
throw new Error("Invalid index");
|
|
17
|
+
}
|
|
18
|
+
arr.splice(index, 1);
|
|
19
|
+
} else if (isArray(index)) {
|
|
20
|
+
index.forEach((idx) => removeFromArray(arr, idx));
|
|
21
|
+
} else {
|
|
22
|
+
throw new Error("Invalid index");
|
|
23
|
+
}
|
|
24
|
+
return arr;
|
|
25
|
+
};
|
|
26
|
+
const swapItemsInArray = (arr, i, j) => {
|
|
27
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
28
|
+
};
|
|
29
|
+
const joinArrays = (...arrays) => {
|
|
30
|
+
return [].concat(...arrays);
|
|
31
|
+
};
|
|
32
|
+
const mergeArray = (arr, exclude = []) => {
|
|
33
|
+
return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude }), exclude), {});
|
|
34
|
+
};
|
|
35
|
+
const mergeAndCloneIfArray = (obj) => {
|
|
36
|
+
return isArray(obj) ? mergeArray(obj) : deepClone(obj);
|
|
37
|
+
};
|
|
38
|
+
const cutArrayBeforeValue = (arr, value) => {
|
|
39
|
+
const index = arr.indexOf(value);
|
|
40
|
+
if (index !== -1) {
|
|
41
|
+
return arr.slice(0, index);
|
|
42
|
+
}
|
|
43
|
+
return arr;
|
|
44
|
+
};
|
|
45
|
+
const cutArrayAfterValue = (arr, value) => {
|
|
46
|
+
if (!isArray(arr))
|
|
47
|
+
return;
|
|
48
|
+
const index = arr.indexOf(value);
|
|
49
|
+
if (index !== -1) {
|
|
50
|
+
return arr.slice(index + 1);
|
|
51
|
+
}
|
|
52
|
+
return arr;
|
|
53
|
+
};
|
|
54
|
+
const removeValueFromArray = (arr, value) => {
|
|
55
|
+
const index = arr.indexOf(value);
|
|
56
|
+
if (index > -1) {
|
|
57
|
+
const newArray = [...arr];
|
|
58
|
+
newArray.splice(index, 1);
|
|
59
|
+
return newArray;
|
|
60
|
+
}
|
|
61
|
+
return arr;
|
|
62
|
+
};
|
|
63
|
+
const removeValueFromArrayAll = (arr, value) => {
|
|
64
|
+
return arr.filter((item) => item !== value);
|
|
65
|
+
};
|
|
66
|
+
const addItemAfterEveryElement = (array, item) => {
|
|
67
|
+
const result = [];
|
|
68
|
+
for (let i = 0; i < array.length; i++) {
|
|
69
|
+
result.push(array[i]);
|
|
70
|
+
if (i < array.length - 1) {
|
|
71
|
+
result.push(item);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
|
|
77
|
+
const newArray = [...array];
|
|
78
|
+
const indexToMove = newArray.indexOf(valueToMove);
|
|
79
|
+
const indexToInsertBefore = newArray.indexOf(insertBeforeValue);
|
|
80
|
+
if (indexToMove !== -1 && indexToInsertBefore !== -1) {
|
|
81
|
+
const removedItem = newArray.splice(indexToMove, 1)[0];
|
|
82
|
+
const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1;
|
|
83
|
+
newArray.splice(insertIndex, 0, removedItem);
|
|
84
|
+
}
|
|
85
|
+
return newArray;
|
|
86
|
+
};
|
|
87
|
+
const arraysEqual = (arr1, arr2) => {
|
|
88
|
+
if (arr1.length !== arr2.length) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
92
|
+
if (arr1[i] !== arr2[i]) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
const filterArrays = (sourceArr, excludeArr) => {
|
|
99
|
+
return sourceArr.filter((item) => !excludeArr.includes(item));
|
|
100
|
+
};
|
|
101
|
+
const filterArraysFast = (sourceArr, excludeArr) => {
|
|
102
|
+
const excludeSet = new Set(excludeArr);
|
|
103
|
+
return sourceArr.filter((item) => !excludeSet.has(item));
|
|
104
|
+
};
|
|
105
|
+
export {
|
|
106
|
+
addItemAfterEveryElement,
|
|
107
|
+
arrayContainsOtherArray,
|
|
108
|
+
arraysEqual,
|
|
109
|
+
cutArrayAfterValue,
|
|
110
|
+
cutArrayBeforeValue,
|
|
111
|
+
filterArrays,
|
|
112
|
+
filterArraysFast,
|
|
113
|
+
getFrequencyInArray,
|
|
114
|
+
joinArrays,
|
|
115
|
+
mergeAndCloneIfArray,
|
|
116
|
+
mergeArray,
|
|
117
|
+
removeFromArray,
|
|
118
|
+
removeValueFromArray,
|
|
119
|
+
removeValueFromArrayAll,
|
|
120
|
+
reorderArrayByValues,
|
|
121
|
+
swapItemsInArray
|
|
122
|
+
};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import {
|
|
21
|
+
deepClone,
|
|
22
|
+
exec,
|
|
23
|
+
isArray,
|
|
24
|
+
isFunction,
|
|
25
|
+
isObject,
|
|
26
|
+
isString,
|
|
27
|
+
joinArrays
|
|
28
|
+
} from ".";
|
|
29
|
+
const ENV = "development";
|
|
30
|
+
const checkIfKeyIsComponent = (key) => {
|
|
31
|
+
const isFirstKeyString = isString(key);
|
|
32
|
+
if (!isFirstKeyString)
|
|
33
|
+
return;
|
|
34
|
+
const firstCharKey = key.slice(0, 1);
|
|
35
|
+
return /^[A-Z]*$/.test(firstCharKey);
|
|
36
|
+
};
|
|
37
|
+
const checkIfKeyIsProperty = (key) => {
|
|
38
|
+
const isFirstKeyString = isString(key);
|
|
39
|
+
if (!isFirstKeyString)
|
|
40
|
+
return;
|
|
41
|
+
const firstCharKey = key.slice(0, 1);
|
|
42
|
+
return /^[a-z]*$/.test(firstCharKey);
|
|
43
|
+
};
|
|
44
|
+
const addAdditionalExtend = (newExtend, element) => {
|
|
45
|
+
if (!newExtend)
|
|
46
|
+
return element;
|
|
47
|
+
const { extend: elementExtend } = element;
|
|
48
|
+
const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend];
|
|
49
|
+
const receivedArray = isArray(newExtend) ? newExtend : [newExtend];
|
|
50
|
+
const extend = joinArrays(receivedArray, originalArray);
|
|
51
|
+
return __spreadProps(__spreadValues({}, element), { extend });
|
|
52
|
+
};
|
|
53
|
+
const checkIfSugar = (element, parent, key) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const {
|
|
56
|
+
extend,
|
|
57
|
+
props,
|
|
58
|
+
childExtend,
|
|
59
|
+
extends: extendProps,
|
|
60
|
+
childExtends,
|
|
61
|
+
childProps,
|
|
62
|
+
children,
|
|
63
|
+
on,
|
|
64
|
+
$collection,
|
|
65
|
+
$stateCollection,
|
|
66
|
+
$propsCollection
|
|
67
|
+
} = element;
|
|
68
|
+
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
|
|
69
|
+
if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
|
|
70
|
+
const logErr = (_a = parent || element) == null ? void 0 : _a.error;
|
|
71
|
+
if (logErr)
|
|
72
|
+
logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
|
|
73
|
+
}
|
|
74
|
+
return !hasComponentAttrs || childProps || extendProps || children || childExtends;
|
|
75
|
+
};
|
|
76
|
+
const extendizeByKey = (element, parent, key) => {
|
|
77
|
+
const { context } = parent;
|
|
78
|
+
const { tag, extend, childExtends } = element;
|
|
79
|
+
const isSugar = checkIfSugar(element, parent, key);
|
|
80
|
+
const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
|
|
81
|
+
const isExtendKeyComponent = context && context.components[extendFromKey];
|
|
82
|
+
if (element === isExtendKeyComponent)
|
|
83
|
+
return element;
|
|
84
|
+
else if (isSugar) {
|
|
85
|
+
const newElem = addAdditionalExtend(element.extends, {
|
|
86
|
+
extend: extendFromKey,
|
|
87
|
+
tag,
|
|
88
|
+
props: __spreadValues({}, element)
|
|
89
|
+
});
|
|
90
|
+
if (childExtends)
|
|
91
|
+
newElem.childExtend = childExtends;
|
|
92
|
+
return newElem;
|
|
93
|
+
} else if (!extend || extend === true) {
|
|
94
|
+
return __spreadProps(__spreadValues({}, element), {
|
|
95
|
+
tag,
|
|
96
|
+
extend: extendFromKey
|
|
97
|
+
});
|
|
98
|
+
} else if (extend) {
|
|
99
|
+
return addAdditionalExtend(extendFromKey, element);
|
|
100
|
+
} else if (isFunction(element)) {
|
|
101
|
+
return {
|
|
102
|
+
extend: extendFromKey,
|
|
103
|
+
tag,
|
|
104
|
+
props: __spreadValues({}, exec(element, parent))
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function getCapitalCaseKeys(obj) {
|
|
109
|
+
return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
|
|
110
|
+
}
|
|
111
|
+
const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
112
|
+
const childElems = getCapitalCaseKeys(element.props);
|
|
113
|
+
if (!childElems.length)
|
|
114
|
+
return element;
|
|
115
|
+
for (const i in childElems) {
|
|
116
|
+
const childKey = childElems[i];
|
|
117
|
+
const childElem = element[childKey];
|
|
118
|
+
const newChild = element.props[childKey];
|
|
119
|
+
const assignChild = (val) => {
|
|
120
|
+
element[childKey] = val;
|
|
121
|
+
delete element.props[childKey];
|
|
122
|
+
};
|
|
123
|
+
if (newChild == null ? void 0 : newChild.ignoreExtend)
|
|
124
|
+
continue;
|
|
125
|
+
if (newChild === null)
|
|
126
|
+
assignChild(null);
|
|
127
|
+
else if (!childElem)
|
|
128
|
+
assignChild(deepClone(newChild));
|
|
129
|
+
else {
|
|
130
|
+
const isSugarChildElem = checkIfSugar(childElem, parent, key);
|
|
131
|
+
if (isSugarChildElem)
|
|
132
|
+
continue;
|
|
133
|
+
assignChild({
|
|
134
|
+
extend: element[childKey],
|
|
135
|
+
props: newChild
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const applyKeyComponentAsExtend = (element, parent, key) => {
|
|
141
|
+
return extendizeByKey(element, parent, key) || element;
|
|
142
|
+
};
|
|
143
|
+
const applyComponentFromContext = (element, parent, options) => {
|
|
144
|
+
const { context } = element;
|
|
145
|
+
if (!context || !context.components)
|
|
146
|
+
return;
|
|
147
|
+
const { components } = context;
|
|
148
|
+
const { extend } = element;
|
|
149
|
+
const execExtend = exec(extend, element);
|
|
150
|
+
if (isString(execExtend)) {
|
|
151
|
+
const componentExists = components[execExtend] || components["smbls." + execExtend];
|
|
152
|
+
if (componentExists)
|
|
153
|
+
element.extend = componentExists;
|
|
154
|
+
else {
|
|
155
|
+
if ((ENV === "test" || ENV === "development") && options.verbose) {
|
|
156
|
+
console.warn(execExtend, "is not in library", components, element);
|
|
157
|
+
console.warn("replacing with ", {});
|
|
158
|
+
}
|
|
159
|
+
element.extend = {};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const isVariant = (param) => {
|
|
164
|
+
if (!isString(param))
|
|
165
|
+
return;
|
|
166
|
+
const firstCharKey = param.slice(0, 1);
|
|
167
|
+
return firstCharKey === ".";
|
|
168
|
+
};
|
|
169
|
+
const hasVariantProp = (element) => {
|
|
170
|
+
const { props } = element;
|
|
171
|
+
if (isObject(props) && isString(props.variant))
|
|
172
|
+
return true;
|
|
173
|
+
};
|
|
174
|
+
const getChildrenComponentsByKey = (key, el) => {
|
|
175
|
+
if (key === el.key || el.__ref.__componentKey === key) {
|
|
176
|
+
return el;
|
|
177
|
+
}
|
|
178
|
+
if (el.extend) {
|
|
179
|
+
const foundString = isString(el.extend) && el.extend === key;
|
|
180
|
+
const foundInArray = isArray(el.extend) && el.extend.filter((v) => v === key).length;
|
|
181
|
+
if (foundString || foundInArray)
|
|
182
|
+
return el;
|
|
183
|
+
}
|
|
184
|
+
if (el.parent && el.parent.childExtend) {
|
|
185
|
+
const foundString = isString(el.parent.childExtend) && el.parent.childExtend === key;
|
|
186
|
+
const foundInArray = isArray(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
|
|
187
|
+
if (foundString || foundInArray)
|
|
188
|
+
return el;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const getExtendsInElement = (obj) => {
|
|
192
|
+
let result = [];
|
|
193
|
+
function traverse(o) {
|
|
194
|
+
for (const key in o) {
|
|
195
|
+
if (Object.hasOwnProperty.call(o, key)) {
|
|
196
|
+
if (checkIfKeyIsComponent(key)) {
|
|
197
|
+
result.push(key);
|
|
198
|
+
}
|
|
199
|
+
if (key === "extend") {
|
|
200
|
+
if (typeof o[key] === "string") {
|
|
201
|
+
result.push(o[key]);
|
|
202
|
+
} else if (Array.isArray(o[key])) {
|
|
203
|
+
result = result.concat(o[key]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (typeof o[key] === "object" && o[key] !== null) {
|
|
207
|
+
traverse(o[key]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
traverse(obj);
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
const setContentKey = (el, opts = {}) => {
|
|
216
|
+
const { __ref: ref } = el;
|
|
217
|
+
const contentElementKey = opts.contentElementKey;
|
|
218
|
+
if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
|
|
219
|
+
ref.contentElementKey = contentElementKey || "content";
|
|
220
|
+
} else
|
|
221
|
+
ref.contentElementKey = "content";
|
|
222
|
+
if (contentElementKey !== "content")
|
|
223
|
+
opts.contentElementKey = "content";
|
|
224
|
+
return ref.contentElementKey;
|
|
225
|
+
};
|
|
226
|
+
export {
|
|
227
|
+
addAdditionalExtend,
|
|
228
|
+
addChildrenIfNotInOriginal,
|
|
229
|
+
applyComponentFromContext,
|
|
230
|
+
applyKeyComponentAsExtend,
|
|
231
|
+
checkIfKeyIsComponent,
|
|
232
|
+
checkIfKeyIsProperty,
|
|
233
|
+
checkIfSugar,
|
|
234
|
+
extendizeByKey,
|
|
235
|
+
getCapitalCaseKeys,
|
|
236
|
+
getChildrenComponentsByKey,
|
|
237
|
+
getExtendsInElement,
|
|
238
|
+
hasVariantProp,
|
|
239
|
+
isVariant,
|
|
240
|
+
setContentKey
|
|
241
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isUndefined } from "./types";
|
|
2
|
+
import { document } from "@domql/utils";
|
|
3
|
+
const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
|
|
4
|
+
const setCookie = (cname, cvalue, exdays = 365) => {
|
|
5
|
+
if (isUndefined(document) || isUndefined(document.cookie))
|
|
6
|
+
return;
|
|
7
|
+
const d = /* @__PURE__ */ new Date();
|
|
8
|
+
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
|
|
9
|
+
const expires = `expires=${d.toUTCString()}`;
|
|
10
|
+
document.cookie = `${cname}=${cvalue};${expires};path=/`;
|
|
11
|
+
};
|
|
12
|
+
const getCookie = (cname) => {
|
|
13
|
+
if (isUndefined(document) || isUndefined(document.cookie))
|
|
14
|
+
return;
|
|
15
|
+
const name = `${cname}=`;
|
|
16
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
17
|
+
const ca = decodedCookie.split(";");
|
|
18
|
+
for (let i = 0; i < ca.length; i++) {
|
|
19
|
+
let c = ca[i];
|
|
20
|
+
while (c.charAt(0) === " ")
|
|
21
|
+
c = c.substring(1);
|
|
22
|
+
if (c.indexOf(name) === 0)
|
|
23
|
+
return c.substring(name.length, c.length);
|
|
24
|
+
}
|
|
25
|
+
return "";
|
|
26
|
+
};
|
|
27
|
+
const removeCookie = (cname) => {
|
|
28
|
+
if (isUndefined(document) || isUndefined(document.cookie))
|
|
29
|
+
return;
|
|
30
|
+
document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
31
|
+
};
|
|
32
|
+
function getLocalStorage(key) {
|
|
33
|
+
let savedJSON;
|
|
34
|
+
if (window.localStorage) {
|
|
35
|
+
try {
|
|
36
|
+
savedJSON = JSON.parse(window.localStorage.getItem(key));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (typeof savedJSON !== "undefined") {
|
|
41
|
+
return savedJSON;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function setLocalStorage(key, data) {
|
|
45
|
+
if (data && window.localStorage) {
|
|
46
|
+
if (typeof data === "object") {
|
|
47
|
+
window.localStorage.setItem(key, JSON.stringify(data));
|
|
48
|
+
} else {
|
|
49
|
+
window.localStorage.setItem(key, data);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
getCookie,
|
|
55
|
+
getLocalStorage,
|
|
56
|
+
isMobile,
|
|
57
|
+
removeCookie,
|
|
58
|
+
setCookie,
|
|
59
|
+
setLocalStorage
|
|
60
|
+
};
|
package/dist/esm/env.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const NODE_ENV = "development";
|
|
2
|
+
const isProduction = (env = NODE_ENV) => env === "production" || env === "prod" || env !== "development" && env !== "dev" && env !== "test";
|
|
3
|
+
const isTest = (env = NODE_ENV) => env === "test";
|
|
4
|
+
const isDevelopment = (env = NODE_ENV) => env === "development" || env === "dev";
|
|
5
|
+
const getNev = (key, env = NODE_ENV) => env[key];
|
|
6
|
+
export {
|
|
7
|
+
NODE_ENV,
|
|
8
|
+
getNev,
|
|
9
|
+
isDevelopment,
|
|
10
|
+
isProduction,
|
|
11
|
+
isTest
|
|
12
|
+
};
|