@domql/state 2.3.130 → 2.3.132
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/dist/cjs/inherit.js +15 -15
- package/dist/cjs/methods.js +1 -1
- package/inherit.js +9 -9
- package/methods.js +1 -1
- package/package.json +2 -2
package/dist/cjs/inherit.js
CHANGED
|
@@ -29,10 +29,10 @@ __export(inherit_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(inherit_exports);
|
|
30
30
|
var import_utils = require("@domql/utils");
|
|
31
31
|
var import_ignore = require("./ignore");
|
|
32
|
-
const getParentStateInKey = (
|
|
33
|
-
if (!
|
|
32
|
+
const getParentStateInKey = (stateKey, parentState) => {
|
|
33
|
+
if (!stateKey.includes("../"))
|
|
34
34
|
return;
|
|
35
|
-
const arr =
|
|
35
|
+
const arr = stateKey.split("../");
|
|
36
36
|
const arrLength = arr.length - 1;
|
|
37
37
|
for (let i = 0; i < arrLength; i++) {
|
|
38
38
|
if (!parentState.parent)
|
|
@@ -41,37 +41,37 @@ const getParentStateInKey = (stateKey2, parentState) => {
|
|
|
41
41
|
}
|
|
42
42
|
return parentState;
|
|
43
43
|
};
|
|
44
|
-
const getChildStateInKey = (
|
|
45
|
-
const arr =
|
|
44
|
+
const getChildStateInKey = (stateKey, parentState, options) => {
|
|
45
|
+
const arr = stateKey.split("/");
|
|
46
46
|
const arrLength = arr.length - 1;
|
|
47
47
|
for (let i = 0; i < arrLength; i++) {
|
|
48
48
|
const childKey = arr[i];
|
|
49
49
|
const grandChildKey = arr[i + 1];
|
|
50
50
|
const childInParent = parentState[childKey];
|
|
51
51
|
if (childInParent && childInParent[grandChildKey]) {
|
|
52
|
-
|
|
52
|
+
stateKey = grandChildKey;
|
|
53
53
|
parentState = childInParent;
|
|
54
54
|
} else
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
if (options.returnParent)
|
|
58
58
|
return parentState;
|
|
59
|
-
return parentState[
|
|
59
|
+
return parentState[stateKey];
|
|
60
60
|
};
|
|
61
61
|
const findInheritedState = (element, parent, options = {}) => {
|
|
62
62
|
const ref = element.__ref;
|
|
63
|
-
let
|
|
63
|
+
let stateKey = ref.__state;
|
|
64
64
|
if (!checkIfInherits(element))
|
|
65
65
|
return;
|
|
66
66
|
let parentState = parent.state;
|
|
67
|
-
const findGrandParentState = getParentStateInKey(
|
|
67
|
+
const findGrandParentState = getParentStateInKey(stateKey, parent.state);
|
|
68
68
|
if (findGrandParentState) {
|
|
69
69
|
parentState = findGrandParentState;
|
|
70
|
-
|
|
70
|
+
stateKey = stateKey.replaceAll("../", "");
|
|
71
71
|
}
|
|
72
72
|
if (!parentState)
|
|
73
73
|
return;
|
|
74
|
-
return getChildStateInKey(
|
|
74
|
+
return getChildStateInKey(stateKey, parentState, options);
|
|
75
75
|
};
|
|
76
76
|
const createInheritedState = (element, parent) => {
|
|
77
77
|
const ref = element.__ref;
|
|
@@ -84,12 +84,12 @@ const createInheritedState = (element, parent) => {
|
|
|
84
84
|
ref.__stateType = "string";
|
|
85
85
|
return { value: inheritedState };
|
|
86
86
|
}
|
|
87
|
-
console.warn(
|
|
87
|
+
console.warn(ref.__state, "is not present. Replacing with", {});
|
|
88
88
|
};
|
|
89
89
|
const checkIfInherits = (element) => {
|
|
90
90
|
const ref = element.__ref;
|
|
91
|
-
const
|
|
92
|
-
if (!
|
|
91
|
+
const stateKey = ref.__state;
|
|
92
|
+
if (!stateKey || (0, import_utils.isNot)(stateKey)("number", "string"))
|
|
93
93
|
return false;
|
|
94
94
|
return true;
|
|
95
95
|
};
|
|
@@ -104,7 +104,7 @@ const createChangesByKey = (path, value) => {
|
|
|
104
104
|
return value || {};
|
|
105
105
|
}
|
|
106
106
|
const keys = path.split("/");
|
|
107
|
-
|
|
107
|
+
const obj = {};
|
|
108
108
|
let ref = obj;
|
|
109
109
|
keys.forEach((key, index) => {
|
|
110
110
|
ref[key] = index === keys.length - 1 ? value || {} : {};
|
package/dist/cjs/methods.js
CHANGED
|
@@ -125,6 +125,6 @@ const apply = function(func, options = {}) {
|
|
|
125
125
|
const state = this;
|
|
126
126
|
if ((0, import_utils.isFunction)(func)) {
|
|
127
127
|
func(state);
|
|
128
|
-
return state.update(state, {
|
|
128
|
+
return state.update(state, { replace: true, ...options });
|
|
129
129
|
}
|
|
130
130
|
};
|
package/inherit.js
CHANGED
|
@@ -58,7 +58,7 @@ export const createInheritedState = (element, parent) => {
|
|
|
58
58
|
return { value: inheritedState }
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
console.warn(
|
|
61
|
+
console.warn(ref.__state, 'is not present. Replacing with', {})
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export const checkIfInherits = (element) => {
|
|
@@ -76,14 +76,14 @@ export const isState = function (state) {
|
|
|
76
76
|
|
|
77
77
|
export const createChangesByKey = (path, value) => {
|
|
78
78
|
if (!path) {
|
|
79
|
-
return value || {}
|
|
79
|
+
return value || {}
|
|
80
80
|
}
|
|
81
|
-
const keys = path.split('/')
|
|
82
|
-
|
|
83
|
-
let ref = obj
|
|
81
|
+
const keys = path.split('/')
|
|
82
|
+
const obj = {}
|
|
83
|
+
let ref = obj
|
|
84
84
|
keys.forEach((key, index) => {
|
|
85
|
-
ref[key] = index === keys.length - 1 ? value || {} : {}
|
|
86
|
-
ref = ref[key]
|
|
87
|
-
})
|
|
88
|
-
return obj
|
|
85
|
+
ref[key] = index === keys.length - 1 ? value || {} : {}
|
|
86
|
+
ref = ref[key]
|
|
87
|
+
})
|
|
88
|
+
return obj
|
|
89
89
|
}
|
package/methods.js
CHANGED
|
@@ -108,6 +108,6 @@ export const apply = function (func, options = {}) {
|
|
|
108
108
|
const state = this
|
|
109
109
|
if (isFunction(func)) {
|
|
110
110
|
func(state)
|
|
111
|
-
return state.update(state, {
|
|
111
|
+
return state.update(state, { replace: true, ...options })
|
|
112
112
|
}
|
|
113
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.132",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@domql/report": "latest",
|
|
27
27
|
"@domql/utils": "latest"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "2df037bb2c72a090715d27e3368c39c605dac733"
|
|
30
30
|
}
|