@domql/utils 2.5.200 → 3.0.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.
Files changed (58) hide show
  1. package/array.js +26 -13
  2. package/cache.js +4 -0
  3. package/component.js +10 -227
  4. package/cookie.js +27 -24
  5. package/dist/cjs/array.js +27 -10
  6. package/dist/cjs/cache.js +26 -0
  7. package/dist/cjs/component.js +15 -206
  8. package/dist/cjs/cookie.js +14 -14
  9. package/dist/cjs/element.js +137 -0
  10. package/dist/cjs/events.js +37 -0
  11. package/dist/cjs/extends.js +351 -0
  12. package/dist/cjs/if.js +30 -0
  13. package/dist/cjs/index.js +10 -0
  14. package/dist/cjs/key.js +5 -0
  15. package/dist/cjs/keys.js +178 -0
  16. package/dist/cjs/methods.js +305 -0
  17. package/dist/cjs/object.js +78 -191
  18. package/dist/cjs/props.js +220 -0
  19. package/dist/cjs/scope.js +28 -0
  20. package/dist/cjs/state.js +175 -0
  21. package/dist/cjs/string.js +27 -15
  22. package/dist/cjs/update.js +42 -0
  23. package/dist/esm/array.js +27 -10
  24. package/dist/esm/cache.js +6 -0
  25. package/dist/esm/component.js +16 -225
  26. package/dist/esm/cookie.js +14 -14
  27. package/dist/esm/element.js +135 -0
  28. package/dist/esm/events.js +17 -0
  29. package/dist/esm/extends.js +349 -0
  30. package/dist/esm/if.js +10 -0
  31. package/dist/esm/index.js +10 -0
  32. package/dist/esm/key.js +5 -0
  33. package/dist/esm/keys.js +158 -0
  34. package/dist/esm/methods.js +285 -0
  35. package/dist/esm/object.js +79 -193
  36. package/dist/esm/props.js +216 -0
  37. package/dist/esm/scope.js +8 -0
  38. package/dist/esm/state.js +185 -0
  39. package/dist/esm/string.js +27 -15
  40. package/dist/esm/update.js +22 -0
  41. package/element.js +149 -0
  42. package/env.js +5 -2
  43. package/events.js +17 -0
  44. package/extends.js +425 -0
  45. package/if.js +14 -0
  46. package/index.js +10 -0
  47. package/key.js +6 -0
  48. package/keys.js +157 -0
  49. package/log.js +4 -1
  50. package/methods.js +315 -0
  51. package/node.js +21 -13
  52. package/object.js +122 -236
  53. package/package.json +3 -3
  54. package/props.js +249 -0
  55. package/scope.js +8 -0
  56. package/state.js +208 -0
  57. package/string.js +66 -30
  58. package/update.js +27 -0
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var state_exports = {};
20
+ __export(state_exports, {
21
+ applyDependentState: () => applyDependentState,
22
+ checkForStateTypes: () => checkForStateTypes,
23
+ checkIfInherits: () => checkIfInherits,
24
+ createInheritedState: () => createInheritedState,
25
+ createNestedObjectByKeyPath: () => createNestedObjectByKeyPath,
26
+ findInheritedState: () => findInheritedState,
27
+ getChildStateInKey: () => getChildStateInKey,
28
+ getParentStateInKey: () => getParentStateInKey,
29
+ getRootStateInKey: () => getRootStateInKey,
30
+ isState: () => isState,
31
+ overwriteState: () => overwriteState
32
+ });
33
+ module.exports = __toCommonJS(state_exports);
34
+ var import_array = require("./array.js");
35
+ var import_keys = require("./keys.js");
36
+ var import_object = require("./object.js");
37
+ var import_types = require("./types.js");
38
+ const checkForStateTypes = async (element) => {
39
+ const { state: orig, props, __ref: ref } = element;
40
+ const state = (props == null ? void 0 : props.state) || orig;
41
+ if ((0, import_types.isFunction)(state)) {
42
+ ref.__state = state;
43
+ return await (0, import_object.execPromise)(state, element);
44
+ } else if ((0, import_types.is)(state)("string", "number")) {
45
+ ref.__state = state;
46
+ return { value: state };
47
+ } else if (state === true) {
48
+ ref.__state = element.key;
49
+ return {};
50
+ } else if (state) {
51
+ ref.__hasRootState = true;
52
+ return state;
53
+ } else {
54
+ return false;
55
+ }
56
+ };
57
+ const getRootStateInKey = (stateKey, parentState) => {
58
+ if (!stateKey.includes("~/")) return;
59
+ const arr = stateKey.split("~/");
60
+ if (arr.length > 1) return parentState.root;
61
+ };
62
+ const getParentStateInKey = (stateKey, parentState) => {
63
+ if (!stateKey.includes("../")) return;
64
+ const arr = stateKey.split("../");
65
+ const arrLength = arr.length - 1;
66
+ for (let i = 0; i < arrLength; i++) {
67
+ if (!parentState.parent) return null;
68
+ parentState = parentState.parent;
69
+ }
70
+ return parentState;
71
+ };
72
+ const getChildStateInKey = (stateKey, parentState, options = {}) => {
73
+ const arr = (0, import_types.isString)(stateKey) ? stateKey.split("/") : [stateKey];
74
+ const arrLength = arr.length - 1;
75
+ for (let i = 0; i < arrLength; i++) {
76
+ const childKey = arr[i];
77
+ const grandChildKey = arr[i + 1];
78
+ if (childKey === "__proto__" || grandChildKey === "__proto__") return;
79
+ let childInParent = parentState[childKey];
80
+ if (!childInParent) childInParent = parentState[childKey] = {};
81
+ if (!childInParent[grandChildKey]) childInParent[grandChildKey] = {};
82
+ stateKey = grandChildKey;
83
+ parentState = childInParent;
84
+ }
85
+ if (options.returnParent) return parentState;
86
+ return parentState[stateKey];
87
+ };
88
+ const findInheritedState = (element, parent, options = {}) => {
89
+ const ref = element.__ref;
90
+ let stateKey = ref.__state;
91
+ if (!checkIfInherits(element)) return;
92
+ const rootState = getRootStateInKey(stateKey, parent.state);
93
+ let parentState = parent.state;
94
+ if (rootState) {
95
+ parentState = rootState;
96
+ stateKey = stateKey.replaceAll("~/", "");
97
+ } else {
98
+ const findGrandParentState = getParentStateInKey(stateKey, parent.state);
99
+ if (findGrandParentState) {
100
+ parentState = findGrandParentState;
101
+ stateKey = stateKey.replaceAll("../", "");
102
+ }
103
+ }
104
+ if (!parentState) return;
105
+ return getChildStateInKey(stateKey, parentState, options);
106
+ };
107
+ const createInheritedState = (element, parent) => {
108
+ const ref = element.__ref;
109
+ const inheritedState = findInheritedState(element, parent);
110
+ if ((0, import_types.isUndefined)(inheritedState)) return element.state;
111
+ if ((0, import_types.is)(inheritedState)("object", "array")) {
112
+ return (0, import_object.deepClone)(inheritedState);
113
+ } else if ((0, import_types.is)(inheritedState)("string", "number", "boolean")) {
114
+ ref.__stateType = typeof inheritedState;
115
+ return { value: inheritedState };
116
+ }
117
+ console.warn(ref.__state, "is not present. Replacing with", {});
118
+ };
119
+ const checkIfInherits = (element) => {
120
+ const { __ref: ref } = element;
121
+ const stateKey = ref == null ? void 0 : ref.__state;
122
+ if (stateKey && (0, import_types.is)(stateKey)("number", "string", "boolean")) return true;
123
+ return false;
124
+ };
125
+ const isState = function(state) {
126
+ if (!(0, import_types.isObjectLike)(state)) return false;
127
+ return Boolean(
128
+ state.update && state.parse && state.clean && state.create && state.parent && state.destroy && state.rootUpdate && state.parentUpdate && state.keys && state.values && state.toggle && state.replace && state.quietUpdate && state.quietReplace && state.add && state.apply && state.applyReplace && state.setByPath && state.setPathCollection && state.removeByPath && state.removePathCollection && state.getByPath && state.applyFunction && state.__element && state.__children
129
+ );
130
+ };
131
+ const createNestedObjectByKeyPath = (path, value) => {
132
+ if (!path) {
133
+ return value || {};
134
+ }
135
+ const keys = path.split("/");
136
+ const obj = {};
137
+ let ref = obj;
138
+ keys.forEach((key, index) => {
139
+ ref[key] = index === keys.length - 1 ? value || {} : {};
140
+ ref = ref[key];
141
+ });
142
+ return obj;
143
+ };
144
+ const applyDependentState = async (element, state) => {
145
+ const { __element } = state;
146
+ const origState = await (0, import_object.execPromise)(__element == null ? void 0 : __element.state, element);
147
+ if (!origState) return;
148
+ const dependentState = (0, import_object.deepClone)(origState, import_keys.STATE_METHODS);
149
+ const newDepends = { [element.key]: dependentState };
150
+ const __depends = (0, import_types.isObject)(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
151
+ if (Array.isArray(origState)) {
152
+ (0, import_array.addProtoToArray)(origState, {
153
+ ...Object.getPrototypeOf(origState),
154
+ __depends
155
+ });
156
+ } else {
157
+ Object.setPrototypeOf(origState, {
158
+ ...Object.getPrototypeOf(origState),
159
+ __depends
160
+ });
161
+ }
162
+ return dependentState;
163
+ };
164
+ const overwriteState = (state, obj, options = {}) => {
165
+ const { overwrite } = options;
166
+ if (!overwrite) return;
167
+ const shallow = overwrite === "shallow";
168
+ const merge = overwrite === "merge";
169
+ if (merge) {
170
+ (0, import_object.deepMerge)(state, obj, import_keys.STATE_METHODS);
171
+ return;
172
+ }
173
+ const overwriteFunc = shallow ? import_object.overwriteShallow : import_object.overwriteDeep;
174
+ overwriteFunc(state, obj, import_keys.STATE_METHODS);
175
+ };
@@ -43,28 +43,37 @@ const trimStringFromSymbols = (str, characters) => {
43
43
  return str.replace(pattern, "");
44
44
  };
45
45
  const brackRegex = {
46
- 2: /\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}/g,
47
- 3: /\{\{\{\s*((?:\.\.\/)+)?([^}\s]+)\s*\}\}\}/g
46
+ 2: /{{\s*((?:\.\.\/)*)([\w\d.]+)\s*}}/g,
47
+ 3: /{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*}}}/g
48
48
  };
49
- function replaceLiteralsWithObjectFields(str, options = {}, forcedState) {
50
- if (!str.includes(options.bracketsLength === 3 ? "{{{" : "{{")) return str;
51
- const reg = brackRegex[options.bracketsLength || 2];
52
- const obj = forcedState || (this == null ? void 0 : this.state) || {};
49
+ const getNestedValue = (obj, path) => {
50
+ return path.split(".").reduce((acc, part) => {
51
+ return acc && acc[part] !== void 0 ? acc[part] : void 0;
52
+ }, obj);
53
+ };
54
+ function replaceLiteralsWithObjectFields(str, state = {}, options = {}) {
55
+ const { bracketsLength = 2 } = options;
56
+ const bracketPattern = bracketsLength === 3 ? "{{{" : "{{";
57
+ if (!str.includes(bracketPattern)) return str;
58
+ const reg = brackRegex[bracketsLength];
59
+ const obj = state || {};
53
60
  return str.replace(reg, (_, parentPath, variable) => {
54
61
  if (parentPath) {
55
- const parentLevels = parentPath.match(options.bracketsLength === 3 ? /\.\.\.\//g : /\.\.\//g).length;
62
+ const parentLevels = (parentPath.match(/\.\.\//g) || []).length;
56
63
  let parentState = obj;
57
64
  for (let i = 0; i < parentLevels; i++) {
65
+ if (!parentState || !parentState.parent) return "";
58
66
  parentState = parentState.parent;
59
- if (!parentState) {
60
- return "";
61
- }
62
67
  }
63
- const value = parentState[variable.trim()];
64
- return value !== void 0 ? `${value}` : "";
68
+ const key = variable.trim();
69
+ if (key === "parent") {
70
+ return parentState.value !== void 0 ? String(parentState.value) : "";
71
+ }
72
+ const value = getNestedValue(parentState, key);
73
+ return value !== void 0 ? String(value) : "";
65
74
  } else {
66
- const value = obj[variable.trim()];
67
- return value !== void 0 ? `${value}` : "";
75
+ const value = getNestedValue(obj, variable.trim());
76
+ return value !== void 0 ? String(value) : "";
68
77
  }
69
78
  });
70
79
  }
@@ -140,5 +149,8 @@ const customEncodeURIComponent = (str) => {
140
149
  }).join("");
141
150
  };
142
151
  const customDecodeURIComponent = (encodedStr) => {
143
- return encodedStr.replace(/%[0-9A-Fa-f]{2}/g, (match) => String.fromCharCode(parseInt(match.slice(1), 16)));
152
+ return encodedStr.replace(
153
+ /%[0-9A-Fa-f]{2}/g,
154
+ (match) => String.fromCharCode(parseInt(match.slice(1), 16))
155
+ );
144
156
  };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var update_exports = {};
20
+ __export(update_exports, {
21
+ captureSnapshot: () => captureSnapshot
22
+ });
23
+ module.exports = __toCommonJS(update_exports);
24
+ var import_key = require("./key.js");
25
+ const snapshot = {
26
+ snapshotId: import_key.createSnapshotId
27
+ };
28
+ const captureSnapshot = (element, options) => {
29
+ const ref = element.__ref;
30
+ const { currentSnapshot, calleeElement } = options;
31
+ const isCallee = calleeElement === element;
32
+ if (!calleeElement || isCallee) {
33
+ const createdStanpshot = snapshot.snapshotId();
34
+ ref.__currentSnapshot = createdStanpshot;
35
+ return [createdStanpshot, element];
36
+ }
37
+ const snapshotOnCallee = calleeElement.__ref.__currentSnapshot;
38
+ if (currentSnapshot < snapshotOnCallee) {
39
+ return [snapshotOnCallee, calleeElement, true];
40
+ }
41
+ return [snapshotOnCallee, calleeElement];
42
+ };
package/dist/esm/array.js CHANGED
@@ -15,24 +15,23 @@ const removeFromArray = (arr, index) => {
15
15
  throw new Error("Invalid index");
16
16
  }
17
17
  arr.splice(index, 1);
18
- } else if (isArray(index)) {
19
- index.forEach((idx) => removeFromArray(arr, idx));
20
18
  } else {
21
19
  throw new Error("Invalid index");
22
20
  }
23
21
  return arr;
24
22
  };
25
23
  const swapItemsInArray = (arr, i, j) => {
24
+ ;
26
25
  [arr[i], arr[j]] = [arr[j], arr[i]];
27
26
  };
28
27
  const joinArrays = (...arrays) => {
29
28
  return [].concat(...arrays);
30
29
  };
31
- const mergeArray = (arr, exclude = []) => {
32
- return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude }), exclude), {});
33
- };
34
- const mergeAndCloneIfArray = (obj) => {
35
- return isArray(obj) ? mergeArray(obj) : deepClone(obj);
30
+ const unstackArrayOfObjects = (arr, exclude = []) => {
31
+ return arr.reduce(
32
+ (a, c) => deepMerge(a, deepClone(c, { exclude }), exclude),
33
+ {}
34
+ );
36
35
  };
37
36
  const cutArrayBeforeValue = (arr, value) => {
38
37
  const index = arr.indexOf(value);
@@ -104,8 +103,26 @@ const checkIfStringIsInArray = (string, arr) => {
104
103
  if (!string) return;
105
104
  return arr.filter((v) => string.includes(v)).length;
106
105
  };
106
+ const removeDuplicatesInArray = (arr) => {
107
+ if (!isArray(arr)) return arr;
108
+ return [...new Set(arr)];
109
+ };
110
+ const addProtoToArray = (state, proto) => {
111
+ for (const key in proto) {
112
+ Object.defineProperty(state, key, {
113
+ value: proto[key],
114
+ enumerable: false,
115
+ // Set this to true if you want the method to appear in for...in loops
116
+ configurable: true,
117
+ // Set this to true if you want to allow redefining/removing the property later
118
+ writable: true
119
+ // Set this to true if you want to allow changing the function later
120
+ });
121
+ }
122
+ };
107
123
  export {
108
124
  addItemAfterEveryElement,
125
+ addProtoToArray,
109
126
  arrayContainsOtherArray,
110
127
  arraysEqual,
111
128
  checkIfStringIsInArray,
@@ -115,11 +132,11 @@ export {
115
132
  filterArraysFast,
116
133
  getFrequencyInArray,
117
134
  joinArrays,
118
- mergeAndCloneIfArray,
119
- mergeArray,
135
+ removeDuplicatesInArray,
120
136
  removeFromArray,
121
137
  removeValueFromArray,
122
138
  removeValueFromArrayAll,
123
139
  reorderArrayByValues,
124
- swapItemsInArray
140
+ swapItemsInArray,
141
+ unstackArrayOfObjects
125
142
  };
@@ -0,0 +1,6 @@
1
+ const cache = {};
2
+ const OPTIONS = {};
3
+ export {
4
+ OPTIONS,
5
+ cache
6
+ };
@@ -1,236 +1,27 @@
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 { joinArrays } from "./array.js";
21
- import { deepClone, exec } from "./object.js";
22
- import { isArray, isFunction, isObject, isString } from "./types.js";
23
- const ENV = "development";
24
- const checkIfKeyIsComponent = (key) => {
1
+ import { createExtendsFromKeys } from "./extends.js";
2
+ import { isString } from "./types.js";
3
+ const matchesComponentNaming = (key) => {
25
4
  const isFirstKeyString = isString(key);
26
5
  if (!isFirstKeyString) return;
27
6
  const firstCharKey = key.slice(0, 1);
28
7
  return /^[A-Z]*$/.test(firstCharKey);
29
8
  };
30
- const checkIfKeyIsProperty = (key) => {
31
- const isFirstKeyString = isString(key);
32
- if (!isFirstKeyString) return;
33
- const firstCharKey = key.slice(0, 1);
34
- return /^[a-z]*$/.test(firstCharKey);
35
- };
36
- const addAdditionalExtend = (newExtend, element) => {
37
- if (!newExtend) return element;
38
- const { extend: elementExtend } = element;
39
- const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend];
40
- const receivedArray = isArray(newExtend) ? newExtend : [newExtend];
41
- const extend = joinArrays(receivedArray, originalArray);
42
- return __spreadProps(__spreadValues({}, element), { extend });
43
- };
44
- const checkIfSugar = (element, parent, key) => {
45
- var _a;
46
- const {
47
- extend,
48
- props,
49
- childExtend,
50
- extends: extendProps,
51
- childExtends,
52
- childProps,
53
- children,
54
- on,
55
- $collection,
56
- $stateCollection,
57
- $propsCollection
58
- } = element;
59
- const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
60
- if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
61
- const logErr = (_a = parent || element) == null ? void 0 : _a.error;
62
- if (logErr) logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
63
- }
64
- return !hasComponentAttrs || childProps || extendProps || children || childExtends;
65
- };
66
- const extractComponentKeyFromKey = (key) => {
67
- return key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
68
- };
69
- const extendizeByKey = (element, parent, key) => {
70
- const { context } = parent;
71
- const { tag, extend, childExtends } = element;
72
- const isSugar = checkIfSugar(element, parent, key);
73
- const extendFromKey = extractComponentKeyFromKey(key);
74
- const isExtendKeyComponent = context && context.components[extendFromKey];
75
- if (element === isExtendKeyComponent) return element;
76
- else if (isSugar) {
77
- const newElem = addAdditionalExtend(element.extends, {
78
- extend: extendFromKey,
79
- tag,
80
- props: __spreadValues({}, element)
81
- });
82
- if (newElem.props.data) {
83
- newElem.data = newElem.props.data;
84
- delete newElem.props.data;
85
- }
86
- if (newElem.props.state) {
87
- newElem.state = newElem.props.state;
88
- delete newElem.props.state;
89
- }
90
- if (newElem.props.attr) {
91
- newElem.attr = newElem.props.attr;
92
- delete newElem.props.attr;
93
- }
94
- if (newElem.props.if) {
95
- newElem.if = newElem.props.if;
96
- delete newElem.props.if;
97
- }
98
- if (childExtends) newElem.childExtend = childExtends;
99
- return newElem;
100
- } else if (!extend || extend === true) {
101
- return __spreadProps(__spreadValues({}, element), {
102
- tag,
103
- extend: extendFromKey
104
- });
105
- } else if (extend) {
106
- return addAdditionalExtend(extendFromKey, element);
107
- } else if (isFunction(element)) {
108
- return {
109
- extend: extendFromKey,
110
- tag,
111
- props: __spreadValues({}, exec(element, parent))
112
- };
113
- }
114
- };
115
9
  function getCapitalCaseKeys(obj) {
116
10
  return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
117
11
  }
118
- const addChildrenIfNotInOriginal = (element, parent, key) => {
119
- const childElems = getCapitalCaseKeys(element.props);
120
- if (!childElems.length) return element;
121
- for (const i in childElems) {
122
- const childKey = childElems[i];
123
- const childElem = element[childKey];
124
- const newChild = element.props[childKey];
125
- const assignChild = (val) => {
126
- element[childKey] = val;
127
- delete element.props[childKey];
128
- };
129
- if (newChild == null ? void 0 : newChild.ignoreExtend) continue;
130
- if (newChild === null) assignChild(null);
131
- else if (!childElem) assignChild(deepClone(newChild));
132
- else {
133
- const isSugarChildElem = checkIfSugar(childElem, parent, key);
134
- if (isSugarChildElem) continue;
135
- assignChild({
136
- extend: element[childKey],
137
- props: newChild
138
- });
139
- }
140
- }
141
- };
142
- const applyKeyComponentAsExtend = (element, parent, key) => {
143
- return extendizeByKey(element, parent, key) || element;
144
- };
145
- const applyComponentFromContext = (element, parent, options) => {
146
- const { context } = element;
147
- if (!context || !context.components) return;
148
- const { components } = context;
149
- const { extend } = element;
150
- const execExtend = exec(extend, element);
151
- if (isString(execExtend)) {
152
- const componentExists = components[execExtend] || components["smbls." + execExtend];
153
- if (componentExists) 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)) return;
165
- const firstCharKey = param.slice(0, 1);
166
- return firstCharKey === ".";
167
- };
168
- const hasVariantProp = (element) => {
169
- const { props } = element;
170
- if (isObject(props) && isString(props.variant)) return true;
171
- };
172
- const getChildrenComponentsByKey = (key, el) => {
173
- if (key === el.key || el.__ref.__componentKey === key) {
174
- return el;
175
- }
176
- if (el.extend) {
177
- const foundString = isString(el.extend) && el.extend === key;
178
- const foundInArray = isArray(el.extend) && el.extend.filter((v) => v === key).length;
179
- if (foundString || foundInArray) return el;
180
- }
181
- if (el.parent && el.parent.childExtend) {
182
- const foundString = isString(el.parent.childExtend) && el.parent.childExtend === key;
183
- const foundInArray = isArray(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
184
- if (foundString || foundInArray) return el;
185
- }
186
- };
187
- const getExtendsInElement = (obj) => {
188
- let result = [];
189
- function traverse(o) {
190
- for (const key in o) {
191
- if (Object.hasOwnProperty.call(o, key)) {
192
- if (checkIfKeyIsComponent(key)) {
193
- result.push(key);
194
- }
195
- if (key === "extend" || key === "extends") {
196
- if (typeof o[key] === "string") {
197
- result.push(o[key]);
198
- } else if (Array.isArray(o[key])) {
199
- result = result.concat(o[key]);
200
- }
201
- }
202
- if (typeof o[key] === "object" && o[key] !== null) {
203
- traverse(o[key]);
204
- }
205
- }
206
- }
207
- }
208
- traverse(obj);
209
- return result;
210
- };
211
- const setContentKey = (el, opts = {}) => {
212
- const { __ref: ref } = el;
213
- const contentElementKey = opts.contentElementKey;
214
- if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
215
- ref.contentElementKey = contentElementKey || "content";
216
- } else ref.contentElementKey = "content";
217
- if (contentElementKey !== "content") opts.contentElementKey = "content";
218
- return ref.contentElementKey;
219
- };
12
+ function getSpreadChildren(obj) {
13
+ return Object.keys(obj).filter((key) => /^\d+$/.test(key));
14
+ }
15
+ function isContextComponent(element, parent, passedKey) {
16
+ var _a, _b;
17
+ const { context } = parent || {};
18
+ const [extendsKey] = createExtendsFromKeys(passedKey);
19
+ const key = passedKey || extendsKey;
20
+ return ((_a = context == null ? void 0 : context.components) == null ? void 0 : _a[key]) || ((_b = context == null ? void 0 : context.pages) == null ? void 0 : _b[key]);
21
+ }
220
22
  export {
221
- addAdditionalExtend,
222
- addChildrenIfNotInOriginal,
223
- applyComponentFromContext,
224
- applyKeyComponentAsExtend,
225
- checkIfKeyIsComponent,
226
- checkIfKeyIsProperty,
227
- checkIfSugar,
228
- extendizeByKey,
229
- extractComponentKeyFromKey,
230
23
  getCapitalCaseKeys,
231
- getChildrenComponentsByKey,
232
- getExtendsInElement,
233
- hasVariantProp,
234
- isVariant,
235
- setContentKey
24
+ getSpreadChildren,
25
+ isContextComponent,
26
+ matchesComponentNaming
236
27
  };
@@ -25,25 +25,25 @@ const removeCookie = (cname) => {
25
25
  document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
26
26
  };
27
27
  function getLocalStorage(key) {
28
- let savedJSON;
29
- if (window.localStorage) {
30
- try {
31
- savedJSON = JSON.parse(window.localStorage.getItem(key));
32
- } catch (e) {
33
- }
28
+ if (!window.localStorage) {
29
+ return void 0;
34
30
  }
35
- if (typeof savedJSON !== "undefined") {
36
- return savedJSON;
31
+ const item = window.localStorage.getItem(key);
32
+ if (item === null) {
33
+ return void 0;
34
+ }
35
+ try {
36
+ return JSON.parse(item);
37
+ } catch (e) {
38
+ return void 0;
37
39
  }
38
40
  }
39
41
  function setLocalStorage(key, data) {
40
- if (data && window.localStorage) {
41
- if (typeof data === "object") {
42
- window.localStorage.setItem(key, JSON.stringify(data));
43
- } else {
44
- window.localStorage.setItem(key, data);
45
- }
42
+ if (!window.localStorage || data === void 0 || data === null) {
43
+ return;
46
44
  }
45
+ const value = typeof data === "object" ? JSON.stringify(data) : data;
46
+ window.localStorage.setItem(key, value);
47
47
  }
48
48
  export {
49
49
  getCookie,