@domql/utils 2.5.150 → 2.5.152

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 CHANGED
@@ -6,10 +6,8 @@ import {
6
6
  isArray,
7
7
  isFunction,
8
8
  isObject,
9
- isObjectLike,
10
9
  isString,
11
- joinArrays,
12
- overwriteDeep
10
+ joinArrays
13
11
  } from '.'
14
12
  const ENV = process.env.NODE_ENV
15
13
 
@@ -52,7 +50,7 @@ const checkIfSugar = (element, parent, key) => {
52
50
  } = element
53
51
  const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection
54
52
  if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
55
- element.error('Sugar component includes params for builtin components')
53
+ parent.error('Sugar component includes params for builtin components', { verbose: true })
56
54
  }
57
55
  return !hasComponentAttrs || childProps || extendProps || children || childrenExtends
58
56
  }
@@ -60,7 +58,7 @@ const checkIfSugar = (element, parent, key) => {
60
58
  export const extendizeByKey = (element, parent, key) => {
61
59
  const { context } = parent
62
60
  const { tag, extend, childrenExtends } = element
63
- const isSugar = checkIfSugar(element)
61
+ const isSugar = checkIfSugar(element, parent, key)
64
62
 
65
63
  const extendFromKey = key.includes('+')
66
64
  ? key.split('+') // get array of componentKeys
@@ -70,9 +68,6 @@ export const extendizeByKey = (element, parent, key) => {
70
68
  ? [key.split('.')[0]] // get component key split .
71
69
  : [key]
72
70
 
73
- // console.log(extendFromKey)
74
- // console.log(context, context?.components)
75
- // console.log(element)
76
71
  const isExtendKeyComponent = context && context.components[extendFromKey]
77
72
  if (element === isExtendKeyComponent) return element
78
73
  else if (isSugar) {
@@ -112,20 +107,24 @@ export const addChildrenIfNotInOriginal = (element, parent, key) => {
112
107
  const childKey = childElems[i]
113
108
  const childElem = element[childKey]
114
109
  const newChild = element.props[childKey]
110
+
111
+ const assignChild = (val) => {
112
+ element[childKey] = val
113
+ delete element.props[childKey]
114
+ }
115
+
115
116
  if (newChild?.ignoreExtend) continue
116
- if (!childElem) element[childKey] = deepCloneWithExtend(newChild)
117
+ if (newChild === null && childElem) {
118
+ console.log('is null', element)
119
+ assignChild(null)
120
+ } else if (!childElem) assignChild(deepCloneWithExtend(newChild))
117
121
  else {
118
- const isSugar = checkIfSugar(childElem)
119
- if (!isSugar) continue
120
- const inheritedChildElem = element[childKey].props
121
- if (isObjectLike(newChild)) {
122
- overwriteDeep(inheritedChildElem, newChild)
123
- } else if (isFunction(newChild)) {
124
- element[childKey] = {
125
- extend: element[childKey],
126
- props: newChild
127
- }
128
- }
122
+ const isSugarChildElem = checkIfSugar(childElem, parent, key)
123
+ if (isSugarChildElem) continue
124
+ assignChild({
125
+ extend: element[childKey],
126
+ props: newChild
127
+ })
129
128
  }
130
129
  }
131
130
  }
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
+ }
@@ -73,14 +73,14 @@ const checkIfSugar = (element, parent, key) => {
73
73
  } = element;
74
74
  const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
75
75
  if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
76
- element.error("Sugar component includes params for builtin components");
76
+ parent.error("Sugar component includes params for builtin components", { verbose: true });
77
77
  }
78
78
  return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
79
79
  };
80
80
  const extendizeByKey = (element, parent, key) => {
81
81
  const { context } = parent;
82
82
  const { tag, extend, childrenExtends } = element;
83
- const isSugar = checkIfSugar(element);
83
+ const isSugar = checkIfSugar(element, parent, key);
84
84
  const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
85
85
  const isExtendKeyComponent = context && context.components[extendFromKey];
86
86
  if (element === isExtendKeyComponent)
@@ -121,23 +121,25 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
121
121
  const childKey = childElems[i];
122
122
  const childElem = element[childKey];
123
123
  const newChild = element.props[childKey];
124
+ const assignChild = (val) => {
125
+ element[childKey] = val;
126
+ delete element.props[childKey];
127
+ };
124
128
  if (newChild == null ? void 0 : newChild.ignoreExtend)
125
129
  continue;
126
- if (!childElem)
127
- element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
130
+ if (newChild === null && childElem) {
131
+ console.log("is null", element);
132
+ assignChild(null);
133
+ } else if (!childElem)
134
+ assignChild((0, import__.deepCloneWithExtend)(newChild));
128
135
  else {
129
- const isSugar = checkIfSugar(childElem);
130
- if (!isSugar)
136
+ const isSugarChildElem = checkIfSugar(childElem, parent, key);
137
+ if (isSugarChildElem)
131
138
  continue;
132
- const inheritedChildElem = element[childKey].props;
133
- if ((0, import__.isObjectLike)(newChild)) {
134
- (0, import__.overwriteDeep)(inheritedChildElem, newChild);
135
- } else if ((0, import__.isFunction)(newChild)) {
136
- element[childKey] = {
137
- extend: element[childKey],
138
- props: newChild
139
- };
140
- }
139
+ assignChild({
140
+ extend: element[childKey],
141
+ props: newChild
142
+ });
141
143
  }
142
144
  }
143
145
  };
@@ -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
+ }
@@ -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
- console.warn("Trying to clone element or state at", obj);
197
- obj = (_a = obj.parse) == null ? void 0 : _a.call(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
- console.warn('Trying to clone element or state at', obj)
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.150",
3
+ "version": "2.5.152",
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": "8e04bcc422d23520fd394f79be15dc4336cd59a6",
28
+ "gitHead": "249d2545f3ee35b450ca90d399fc7c3e54a4a7bc",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }