@domql/state 2.5.200 → 2.5.203
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/create.js +10 -5
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/inherit.js +26 -13
- package/dist/cjs/methods.js +14 -7
- package/dist/cjs/updateState.js +24 -12
- package/dist/esm/create.js +10 -5
- package/dist/esm/inherit.js +26 -13
- package/dist/esm/methods.js +14 -7
- package/dist/esm/updateState.js +24 -12
- package/package.json +7 -7
package/dist/cjs/create.js
CHANGED
|
@@ -34,16 +34,20 @@ const createState = async function(element, parent, options) {
|
|
|
34
34
|
};
|
|
35
35
|
const applyInitialState = async function(element, parent, options) {
|
|
36
36
|
const objectizeState = await checkForTypes(element);
|
|
37
|
-
if (objectizeState === false)
|
|
38
|
-
|
|
37
|
+
if (objectizeState === false)
|
|
38
|
+
return parent.state || {};
|
|
39
|
+
else
|
|
40
|
+
element.state = objectizeState;
|
|
39
41
|
const whatInitReturns = (0, import_event.triggerEventOn)("stateInit", element, options);
|
|
40
|
-
if (whatInitReturns === false)
|
|
42
|
+
if (whatInitReturns === false)
|
|
43
|
+
return element.state;
|
|
41
44
|
if ((0, import_inherit.checkIfInherits)(element)) {
|
|
42
45
|
const inheritedState = (0, import_inherit.createInheritedState)(element, parent);
|
|
43
46
|
element.state = (0, import_utils.isUndefined)(inheritedState) ? {} : inheritedState;
|
|
44
47
|
}
|
|
45
48
|
const dependentState = applyDependentState(element, element.state || parent.state || {});
|
|
46
|
-
if (dependentState)
|
|
49
|
+
if (dependentState)
|
|
50
|
+
element.state = dependentState;
|
|
47
51
|
applyMethods(element);
|
|
48
52
|
(0, import_event.triggerEventOn)("stateCreated", element);
|
|
49
53
|
return element.state;
|
|
@@ -51,7 +55,8 @@ const applyInitialState = async function(element, parent, options) {
|
|
|
51
55
|
const applyDependentState = (element, state) => {
|
|
52
56
|
const { __ref, ref, __element } = state;
|
|
53
57
|
const origState = (0, import_utils.exec)(__ref || ref || (__element == null ? void 0 : __element.state), element);
|
|
54
|
-
if (!origState)
|
|
58
|
+
if (!origState)
|
|
59
|
+
return;
|
|
55
60
|
const dependentState = (0, import_utils.deepClone)(origState, import_ignore.IGNORE_STATE_PARAMS);
|
|
56
61
|
const newDepends = { [element.key]: dependentState };
|
|
57
62
|
const __depends = (0, import_utils.isObject)(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
|
package/dist/cjs/index.js
CHANGED
|
@@ -13,10 +13,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
13
13
|
};
|
|
14
14
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
-
var
|
|
17
|
-
module.exports = __toCommonJS(
|
|
18
|
-
__reExport(
|
|
19
|
-
__reExport(
|
|
20
|
-
__reExport(
|
|
21
|
-
__reExport(
|
|
22
|
-
__reExport(
|
|
16
|
+
var state_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(state_exports);
|
|
18
|
+
__reExport(state_exports, require("./ignore.js"), module.exports);
|
|
19
|
+
__reExport(state_exports, require("./create.js"), module.exports);
|
|
20
|
+
__reExport(state_exports, require("./updateState.js"), module.exports);
|
|
21
|
+
__reExport(state_exports, require("./methods.js"), module.exports);
|
|
22
|
+
__reExport(state_exports, require("./inherit.js"), module.exports);
|
package/dist/cjs/inherit.js
CHANGED
|
@@ -31,16 +31,20 @@ module.exports = __toCommonJS(inherit_exports);
|
|
|
31
31
|
var import_utils = require("@domql/utils");
|
|
32
32
|
var import_ignore = require("./ignore.js");
|
|
33
33
|
const getRootStateInKey = (stateKey, parentState) => {
|
|
34
|
-
if (!stateKey.includes("~/"))
|
|
34
|
+
if (!stateKey.includes("~/"))
|
|
35
|
+
return;
|
|
35
36
|
const arr = stateKey.split("~/");
|
|
36
|
-
if (arr.length > 1)
|
|
37
|
+
if (arr.length > 1)
|
|
38
|
+
return parentState.root;
|
|
37
39
|
};
|
|
38
40
|
const getParentStateInKey = (stateKey, parentState) => {
|
|
39
|
-
if (!stateKey.includes("../"))
|
|
41
|
+
if (!stateKey.includes("../"))
|
|
42
|
+
return;
|
|
40
43
|
const arr = stateKey.split("../");
|
|
41
44
|
const arrLength = arr.length - 1;
|
|
42
45
|
for (let i = 0; i < arrLength; i++) {
|
|
43
|
-
if (!parentState.parent)
|
|
46
|
+
if (!parentState.parent)
|
|
47
|
+
return null;
|
|
44
48
|
parentState = parentState.parent;
|
|
45
49
|
}
|
|
46
50
|
return parentState;
|
|
@@ -51,20 +55,25 @@ const getChildStateInKey = (stateKey, parentState, options = {}) => {
|
|
|
51
55
|
for (let i = 0; i < arrLength; i++) {
|
|
52
56
|
const childKey = arr[i];
|
|
53
57
|
const grandChildKey = arr[i + 1];
|
|
54
|
-
if (childKey === "__proto__" || grandChildKey === "__proto__")
|
|
58
|
+
if (childKey === "__proto__" || grandChildKey === "__proto__")
|
|
59
|
+
return;
|
|
55
60
|
let childInParent = parentState[childKey];
|
|
56
|
-
if (!childInParent)
|
|
57
|
-
|
|
61
|
+
if (!childInParent)
|
|
62
|
+
childInParent = parentState[childKey] = {};
|
|
63
|
+
if (!childInParent[grandChildKey])
|
|
64
|
+
childInParent[grandChildKey] = {};
|
|
58
65
|
stateKey = grandChildKey;
|
|
59
66
|
parentState = childInParent;
|
|
60
67
|
}
|
|
61
|
-
if (options.returnParent)
|
|
68
|
+
if (options.returnParent)
|
|
69
|
+
return parentState;
|
|
62
70
|
return parentState[stateKey];
|
|
63
71
|
};
|
|
64
72
|
const findInheritedState = (element, parent, options = {}) => {
|
|
65
73
|
const ref = element.__ref;
|
|
66
74
|
let stateKey = ref.__state;
|
|
67
|
-
if (!checkIfInherits(element))
|
|
75
|
+
if (!checkIfInherits(element))
|
|
76
|
+
return;
|
|
68
77
|
const rootState = getRootStateInKey(stateKey, parent.state);
|
|
69
78
|
let parentState = parent.state;
|
|
70
79
|
if (rootState) {
|
|
@@ -77,13 +86,15 @@ const findInheritedState = (element, parent, options = {}) => {
|
|
|
77
86
|
stateKey = stateKey.replaceAll("../", "");
|
|
78
87
|
}
|
|
79
88
|
}
|
|
80
|
-
if (!parentState)
|
|
89
|
+
if (!parentState)
|
|
90
|
+
return;
|
|
81
91
|
return getChildStateInKey(stateKey, parentState, options);
|
|
82
92
|
};
|
|
83
93
|
const createInheritedState = (element, parent) => {
|
|
84
94
|
const ref = element.__ref;
|
|
85
95
|
const inheritedState = findInheritedState(element, parent);
|
|
86
|
-
if ((0, import_utils.isUndefined)(inheritedState))
|
|
96
|
+
if ((0, import_utils.isUndefined)(inheritedState))
|
|
97
|
+
return element.state;
|
|
87
98
|
if ((0, import_utils.is)(inheritedState)("object", "array")) {
|
|
88
99
|
return (0, import_utils.deepClone)(inheritedState, { exclude: import_ignore.IGNORE_STATE_PARAMS });
|
|
89
100
|
} else if ((0, import_utils.is)(inheritedState)("string", "number", "boolean")) {
|
|
@@ -95,11 +106,13 @@ const createInheritedState = (element, parent) => {
|
|
|
95
106
|
const checkIfInherits = (element) => {
|
|
96
107
|
const ref = element.__ref;
|
|
97
108
|
const stateKey = ref.__state;
|
|
98
|
-
if (stateKey && (0, import_utils.is)(stateKey)("number", "string", "boolean"))
|
|
109
|
+
if (stateKey && (0, import_utils.is)(stateKey)("number", "string", "boolean"))
|
|
110
|
+
return true;
|
|
99
111
|
return false;
|
|
100
112
|
};
|
|
101
113
|
const isState = function(state) {
|
|
102
|
-
if (!(0, import_utils.isObjectLike)(state))
|
|
114
|
+
if (!(0, import_utils.isObjectLike)(state))
|
|
115
|
+
return false;
|
|
103
116
|
return 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;
|
|
104
117
|
};
|
|
105
118
|
const createNestedObjectByKeyPath = (path, value) => {
|
package/dist/cjs/methods.js
CHANGED
|
@@ -109,12 +109,14 @@ const destroy = function(options = {}) {
|
|
|
109
109
|
};
|
|
110
110
|
const parentUpdate = function(obj, options = {}) {
|
|
111
111
|
const state = this;
|
|
112
|
-
if (!state || !state.parent)
|
|
112
|
+
if (!state || !state.parent)
|
|
113
|
+
return;
|
|
113
114
|
return state.parent.update(obj, { isHoisted: true, ...options });
|
|
114
115
|
};
|
|
115
116
|
const rootUpdate = function(obj, options = {}) {
|
|
116
117
|
const state = this;
|
|
117
|
-
if (!state)
|
|
118
|
+
if (!state)
|
|
119
|
+
return;
|
|
118
120
|
const rootState = state.__element.__ref.root.state;
|
|
119
121
|
return rootState.update(obj, { isHoisted: false, ...options });
|
|
120
122
|
};
|
|
@@ -134,9 +136,12 @@ const toggle = function(key, options = {}) {
|
|
|
134
136
|
};
|
|
135
137
|
const remove = function(key, options = {}) {
|
|
136
138
|
const state = this;
|
|
137
|
-
if ((0, import_utils.isArray)(state))
|
|
138
|
-
|
|
139
|
-
if (
|
|
139
|
+
if ((0, import_utils.isArray)(state))
|
|
140
|
+
(0, import_utils.removeFromArray)(state, key);
|
|
141
|
+
if ((0, import_utils.isObject)(state))
|
|
142
|
+
(0, import_utils.removeFromObject)(state, key);
|
|
143
|
+
if (options.applyReset)
|
|
144
|
+
return state.set(state.parse(), { replace: true, ...options });
|
|
140
145
|
return state.update();
|
|
141
146
|
};
|
|
142
147
|
const set = function(val, options = {}) {
|
|
@@ -149,7 +154,8 @@ const setByPath = function(path, val, options = {}) {
|
|
|
149
154
|
const value = (0, import_utils.deepClone)(val);
|
|
150
155
|
(0, import_utils.setInObjectByPath)(state, path, val);
|
|
151
156
|
const update = (0, import_utils.createNestedObject)(path, value);
|
|
152
|
-
if (options.preventStateUpdate)
|
|
157
|
+
if (options.preventStateUpdate)
|
|
158
|
+
return update;
|
|
153
159
|
return state.update(update, options);
|
|
154
160
|
};
|
|
155
161
|
const setPathCollection = function(changes, options = {}) {
|
|
@@ -168,7 +174,8 @@ const setPathCollection = function(changes, options = {}) {
|
|
|
168
174
|
const removeByPath = function(path, options = {}) {
|
|
169
175
|
const state = this;
|
|
170
176
|
(0, import_utils.removeNestedKeyByPath)(state, path);
|
|
171
|
-
if (options.preventUpdate)
|
|
177
|
+
if (options.preventUpdate)
|
|
178
|
+
return path;
|
|
172
179
|
return state.update({}, options);
|
|
173
180
|
};
|
|
174
181
|
const removePathCollection = function(changes, options = {}) {
|
package/dist/cjs/updateState.js
CHANGED
|
@@ -36,19 +36,25 @@ const STATE_UPDATE_OPTIONS = {
|
|
|
36
36
|
const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
37
37
|
const state = this;
|
|
38
38
|
const element = state.__element;
|
|
39
|
-
if (options.onEach)
|
|
40
|
-
|
|
41
|
-
if (!
|
|
39
|
+
if (options.onEach)
|
|
40
|
+
options.onEach(element, state, element.context, options);
|
|
41
|
+
if (!options.updateByState)
|
|
42
|
+
(0, import_utils.merge)(options, STATE_UPDATE_OPTIONS);
|
|
43
|
+
if (!state.__element)
|
|
44
|
+
(0, import_report.report)("ElementOnStateIsNotDefined");
|
|
42
45
|
if (options.preventInheritAtCurrentState === true) {
|
|
43
46
|
options.preventInheritAtCurrentState = state;
|
|
44
|
-
} else if (options.preventInheritAtCurrentState)
|
|
47
|
+
} else if (options.preventInheritAtCurrentState)
|
|
48
|
+
return;
|
|
45
49
|
if (!options.preventBeforeStateUpdateListener) {
|
|
46
50
|
const beforeStateUpdateReturns = await (0, import_event.triggerEventOnUpdate)("beforeStateUpdate", obj, element, options);
|
|
47
|
-
if (beforeStateUpdateReturns === false)
|
|
51
|
+
if (beforeStateUpdateReturns === false)
|
|
52
|
+
return element;
|
|
48
53
|
}
|
|
49
54
|
applyOverwrite(state, obj, options);
|
|
50
55
|
const updateIsHoisted = hoistStateUpdate(state, obj, options);
|
|
51
|
-
if (updateIsHoisted)
|
|
56
|
+
if (updateIsHoisted)
|
|
57
|
+
return state;
|
|
52
58
|
updateDependentState(state, obj, options);
|
|
53
59
|
applyElementUpdate(state, obj, options);
|
|
54
60
|
if (!options.preventStateUpdateListener) {
|
|
@@ -58,7 +64,8 @@ const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
|
58
64
|
};
|
|
59
65
|
const applyOverwrite = (state, obj, options) => {
|
|
60
66
|
const { overwrite } = options;
|
|
61
|
-
if (!overwrite)
|
|
67
|
+
if (!overwrite)
|
|
68
|
+
return;
|
|
62
69
|
const shallow = overwrite === "shallow" || overwrite === "shallow-once";
|
|
63
70
|
const merge2 = overwrite === "merge";
|
|
64
71
|
if (merge2) {
|
|
@@ -66,7 +73,8 @@ const applyOverwrite = (state, obj, options) => {
|
|
|
66
73
|
return;
|
|
67
74
|
}
|
|
68
75
|
const overwriteFunc = shallow ? import_utils.overwriteShallow : import_utils.overwriteDeep;
|
|
69
|
-
if (options.overwrite === "shallow-once")
|
|
76
|
+
if (options.overwrite === "shallow-once")
|
|
77
|
+
options.overwrite = true;
|
|
70
78
|
overwriteFunc(state, obj, import_ignore.IGNORE_STATE_PARAMS);
|
|
71
79
|
};
|
|
72
80
|
const hoistStateUpdate = (state, obj, options) => {
|
|
@@ -74,11 +82,13 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
74
82
|
const { parent, __ref: ref } = element;
|
|
75
83
|
const stateKey = ref == null ? void 0 : ref.__state;
|
|
76
84
|
const stateType = ref == null ? void 0 : ref.__stateType;
|
|
77
|
-
if (!stateKey)
|
|
85
|
+
if (!stateKey)
|
|
86
|
+
return;
|
|
78
87
|
const asksForInherit = (0, import_inherit.checkIfInherits)(element);
|
|
79
88
|
const inheritedState = (0, import_inherit.findInheritedState)(element, parent, { returnParent: true });
|
|
80
89
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
|
|
81
|
-
if (!shouldPropagateState)
|
|
90
|
+
if (!shouldPropagateState)
|
|
91
|
+
return;
|
|
82
92
|
const isStringState = stateType === "string" || stateType === "number" || stateType === "boolean";
|
|
83
93
|
const value = isStringState ? state.value : state.parse();
|
|
84
94
|
const passedValue = isStringState ? state.value : obj;
|
|
@@ -86,7 +96,8 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
86
96
|
const findGrandParentState = (0, import_inherit.getParentStateInKey)(stateKey, parent.state);
|
|
87
97
|
const changesValue = (0, import_inherit.createNestedObjectByKeyPath)(stateKey, passedValue);
|
|
88
98
|
const targetParent = findRootState || findGrandParentState || parent.state;
|
|
89
|
-
if (options.replace)
|
|
99
|
+
if (options.replace)
|
|
100
|
+
(0, import_utils.overwriteDeep)(targetParent, changesValue || value);
|
|
90
101
|
targetParent.update(changesValue, {
|
|
91
102
|
execStateFunction: false,
|
|
92
103
|
isHoisted: true,
|
|
@@ -101,7 +112,8 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
101
112
|
return true;
|
|
102
113
|
};
|
|
103
114
|
const updateDependentState = (state, obj, options) => {
|
|
104
|
-
if (!state.__depends)
|
|
115
|
+
if (!state.__depends)
|
|
116
|
+
return;
|
|
105
117
|
for (const el in state.__depends) {
|
|
106
118
|
const dependentState = state.__depends[el];
|
|
107
119
|
dependentState.clean().update(state.parse(), options);
|
package/dist/esm/create.js
CHANGED
|
@@ -53,16 +53,20 @@ const createState = async function(element, parent, options) {
|
|
|
53
53
|
};
|
|
54
54
|
const applyInitialState = async function(element, parent, options) {
|
|
55
55
|
const objectizeState = await checkForTypes(element);
|
|
56
|
-
if (objectizeState === false)
|
|
57
|
-
|
|
56
|
+
if (objectizeState === false)
|
|
57
|
+
return parent.state || {};
|
|
58
|
+
else
|
|
59
|
+
element.state = objectizeState;
|
|
58
60
|
const whatInitReturns = triggerEventOn("stateInit", element, options);
|
|
59
|
-
if (whatInitReturns === false)
|
|
61
|
+
if (whatInitReturns === false)
|
|
62
|
+
return element.state;
|
|
60
63
|
if (checkIfInherits(element)) {
|
|
61
64
|
const inheritedState = createInheritedState(element, parent);
|
|
62
65
|
element.state = isUndefined(inheritedState) ? {} : inheritedState;
|
|
63
66
|
}
|
|
64
67
|
const dependentState = applyDependentState(element, element.state || parent.state || {});
|
|
65
|
-
if (dependentState)
|
|
68
|
+
if (dependentState)
|
|
69
|
+
element.state = dependentState;
|
|
66
70
|
applyMethods(element);
|
|
67
71
|
triggerEventOn("stateCreated", element);
|
|
68
72
|
return element.state;
|
|
@@ -70,7 +74,8 @@ const applyInitialState = async function(element, parent, options) {
|
|
|
70
74
|
const applyDependentState = (element, state) => {
|
|
71
75
|
const { __ref, ref, __element } = state;
|
|
72
76
|
const origState = exec(__ref || ref || (__element == null ? void 0 : __element.state), element);
|
|
73
|
-
if (!origState)
|
|
77
|
+
if (!origState)
|
|
78
|
+
return;
|
|
74
79
|
const dependentState = deepClone(origState, IGNORE_STATE_PARAMS);
|
|
75
80
|
const newDepends = { [element.key]: dependentState };
|
|
76
81
|
const __depends = isObject(origState.__depends) ? __spreadValues(__spreadValues({}, origState.__depends), newDepends) : newDepends;
|
package/dist/esm/inherit.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { deepClone, is, isObjectLike, isUndefined } from "@domql/utils";
|
|
2
2
|
import { IGNORE_STATE_PARAMS } from "./ignore.js";
|
|
3
3
|
const getRootStateInKey = (stateKey, parentState) => {
|
|
4
|
-
if (!stateKey.includes("~/"))
|
|
4
|
+
if (!stateKey.includes("~/"))
|
|
5
|
+
return;
|
|
5
6
|
const arr = stateKey.split("~/");
|
|
6
|
-
if (arr.length > 1)
|
|
7
|
+
if (arr.length > 1)
|
|
8
|
+
return parentState.root;
|
|
7
9
|
};
|
|
8
10
|
const getParentStateInKey = (stateKey, parentState) => {
|
|
9
|
-
if (!stateKey.includes("../"))
|
|
11
|
+
if (!stateKey.includes("../"))
|
|
12
|
+
return;
|
|
10
13
|
const arr = stateKey.split("../");
|
|
11
14
|
const arrLength = arr.length - 1;
|
|
12
15
|
for (let i = 0; i < arrLength; i++) {
|
|
13
|
-
if (!parentState.parent)
|
|
16
|
+
if (!parentState.parent)
|
|
17
|
+
return null;
|
|
14
18
|
parentState = parentState.parent;
|
|
15
19
|
}
|
|
16
20
|
return parentState;
|
|
@@ -21,20 +25,25 @@ const getChildStateInKey = (stateKey, parentState, options = {}) => {
|
|
|
21
25
|
for (let i = 0; i < arrLength; i++) {
|
|
22
26
|
const childKey = arr[i];
|
|
23
27
|
const grandChildKey = arr[i + 1];
|
|
24
|
-
if (childKey === "__proto__" || grandChildKey === "__proto__")
|
|
28
|
+
if (childKey === "__proto__" || grandChildKey === "__proto__")
|
|
29
|
+
return;
|
|
25
30
|
let childInParent = parentState[childKey];
|
|
26
|
-
if (!childInParent)
|
|
27
|
-
|
|
31
|
+
if (!childInParent)
|
|
32
|
+
childInParent = parentState[childKey] = {};
|
|
33
|
+
if (!childInParent[grandChildKey])
|
|
34
|
+
childInParent[grandChildKey] = {};
|
|
28
35
|
stateKey = grandChildKey;
|
|
29
36
|
parentState = childInParent;
|
|
30
37
|
}
|
|
31
|
-
if (options.returnParent)
|
|
38
|
+
if (options.returnParent)
|
|
39
|
+
return parentState;
|
|
32
40
|
return parentState[stateKey];
|
|
33
41
|
};
|
|
34
42
|
const findInheritedState = (element, parent, options = {}) => {
|
|
35
43
|
const ref = element.__ref;
|
|
36
44
|
let stateKey = ref.__state;
|
|
37
|
-
if (!checkIfInherits(element))
|
|
45
|
+
if (!checkIfInherits(element))
|
|
46
|
+
return;
|
|
38
47
|
const rootState = getRootStateInKey(stateKey, parent.state);
|
|
39
48
|
let parentState = parent.state;
|
|
40
49
|
if (rootState) {
|
|
@@ -47,13 +56,15 @@ const findInheritedState = (element, parent, options = {}) => {
|
|
|
47
56
|
stateKey = stateKey.replaceAll("../", "");
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
|
-
if (!parentState)
|
|
59
|
+
if (!parentState)
|
|
60
|
+
return;
|
|
51
61
|
return getChildStateInKey(stateKey, parentState, options);
|
|
52
62
|
};
|
|
53
63
|
const createInheritedState = (element, parent) => {
|
|
54
64
|
const ref = element.__ref;
|
|
55
65
|
const inheritedState = findInheritedState(element, parent);
|
|
56
|
-
if (isUndefined(inheritedState))
|
|
66
|
+
if (isUndefined(inheritedState))
|
|
67
|
+
return element.state;
|
|
57
68
|
if (is(inheritedState)("object", "array")) {
|
|
58
69
|
return deepClone(inheritedState, { exclude: IGNORE_STATE_PARAMS });
|
|
59
70
|
} else if (is(inheritedState)("string", "number", "boolean")) {
|
|
@@ -65,11 +76,13 @@ const createInheritedState = (element, parent) => {
|
|
|
65
76
|
const checkIfInherits = (element) => {
|
|
66
77
|
const ref = element.__ref;
|
|
67
78
|
const stateKey = ref.__state;
|
|
68
|
-
if (stateKey && is(stateKey)("number", "string", "boolean"))
|
|
79
|
+
if (stateKey && is(stateKey)("number", "string", "boolean"))
|
|
80
|
+
return true;
|
|
69
81
|
return false;
|
|
70
82
|
};
|
|
71
83
|
const isState = function(state) {
|
|
72
|
-
if (!isObjectLike(state))
|
|
84
|
+
if (!isObjectLike(state))
|
|
85
|
+
return false;
|
|
73
86
|
return 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;
|
|
74
87
|
};
|
|
75
88
|
const createNestedObjectByKeyPath = (path, value) => {
|
package/dist/esm/methods.js
CHANGED
|
@@ -93,12 +93,14 @@ const destroy = function(options = {}) {
|
|
|
93
93
|
};
|
|
94
94
|
const parentUpdate = function(obj, options = {}) {
|
|
95
95
|
const state = this;
|
|
96
|
-
if (!state || !state.parent)
|
|
96
|
+
if (!state || !state.parent)
|
|
97
|
+
return;
|
|
97
98
|
return state.parent.update(obj, __spreadValues({ isHoisted: true }, options));
|
|
98
99
|
};
|
|
99
100
|
const rootUpdate = function(obj, options = {}) {
|
|
100
101
|
const state = this;
|
|
101
|
-
if (!state)
|
|
102
|
+
if (!state)
|
|
103
|
+
return;
|
|
102
104
|
const rootState = state.__element.__ref.root.state;
|
|
103
105
|
return rootState.update(obj, __spreadValues({ isHoisted: false }, options));
|
|
104
106
|
};
|
|
@@ -118,9 +120,12 @@ const toggle = function(key, options = {}) {
|
|
|
118
120
|
};
|
|
119
121
|
const remove = function(key, options = {}) {
|
|
120
122
|
const state = this;
|
|
121
|
-
if (isArray(state))
|
|
122
|
-
|
|
123
|
-
if (
|
|
123
|
+
if (isArray(state))
|
|
124
|
+
removeFromArray(state, key);
|
|
125
|
+
if (isObject(state))
|
|
126
|
+
removeFromObject(state, key);
|
|
127
|
+
if (options.applyReset)
|
|
128
|
+
return state.set(state.parse(), __spreadValues({ replace: true }, options));
|
|
124
129
|
return state.update();
|
|
125
130
|
};
|
|
126
131
|
const set = function(val, options = {}) {
|
|
@@ -133,7 +138,8 @@ const setByPath = function(path, val, options = {}) {
|
|
|
133
138
|
const value = deepClone(val);
|
|
134
139
|
setInObjectByPath(state, path, val);
|
|
135
140
|
const update = createNestedObject(path, value);
|
|
136
|
-
if (options.preventStateUpdate)
|
|
141
|
+
if (options.preventStateUpdate)
|
|
142
|
+
return update;
|
|
137
143
|
return state.update(update, options);
|
|
138
144
|
};
|
|
139
145
|
const setPathCollection = function(changes, options = {}) {
|
|
@@ -152,7 +158,8 @@ const setPathCollection = function(changes, options = {}) {
|
|
|
152
158
|
const removeByPath = function(path, options = {}) {
|
|
153
159
|
const state = this;
|
|
154
160
|
removeNestedKeyByPath(state, path);
|
|
155
|
-
if (options.preventUpdate)
|
|
161
|
+
if (options.preventUpdate)
|
|
162
|
+
return path;
|
|
156
163
|
return state.update({}, options);
|
|
157
164
|
};
|
|
158
165
|
const removePathCollection = function(changes, options = {}) {
|
package/dist/esm/updateState.js
CHANGED
|
@@ -32,19 +32,25 @@ const STATE_UPDATE_OPTIONS = {
|
|
|
32
32
|
const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
33
33
|
const state = this;
|
|
34
34
|
const element = state.__element;
|
|
35
|
-
if (options.onEach)
|
|
36
|
-
|
|
37
|
-
if (!
|
|
35
|
+
if (options.onEach)
|
|
36
|
+
options.onEach(element, state, element.context, options);
|
|
37
|
+
if (!options.updateByState)
|
|
38
|
+
merge(options, STATE_UPDATE_OPTIONS);
|
|
39
|
+
if (!state.__element)
|
|
40
|
+
report("ElementOnStateIsNotDefined");
|
|
38
41
|
if (options.preventInheritAtCurrentState === true) {
|
|
39
42
|
options.preventInheritAtCurrentState = state;
|
|
40
|
-
} else if (options.preventInheritAtCurrentState)
|
|
43
|
+
} else if (options.preventInheritAtCurrentState)
|
|
44
|
+
return;
|
|
41
45
|
if (!options.preventBeforeStateUpdateListener) {
|
|
42
46
|
const beforeStateUpdateReturns = await triggerEventOnUpdate("beforeStateUpdate", obj, element, options);
|
|
43
|
-
if (beforeStateUpdateReturns === false)
|
|
47
|
+
if (beforeStateUpdateReturns === false)
|
|
48
|
+
return element;
|
|
44
49
|
}
|
|
45
50
|
applyOverwrite(state, obj, options);
|
|
46
51
|
const updateIsHoisted = hoistStateUpdate(state, obj, options);
|
|
47
|
-
if (updateIsHoisted)
|
|
52
|
+
if (updateIsHoisted)
|
|
53
|
+
return state;
|
|
48
54
|
updateDependentState(state, obj, options);
|
|
49
55
|
applyElementUpdate(state, obj, options);
|
|
50
56
|
if (!options.preventStateUpdateListener) {
|
|
@@ -54,7 +60,8 @@ const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
|
54
60
|
};
|
|
55
61
|
const applyOverwrite = (state, obj, options) => {
|
|
56
62
|
const { overwrite } = options;
|
|
57
|
-
if (!overwrite)
|
|
63
|
+
if (!overwrite)
|
|
64
|
+
return;
|
|
58
65
|
const shallow = overwrite === "shallow" || overwrite === "shallow-once";
|
|
59
66
|
const merge2 = overwrite === "merge";
|
|
60
67
|
if (merge2) {
|
|
@@ -62,7 +69,8 @@ const applyOverwrite = (state, obj, options) => {
|
|
|
62
69
|
return;
|
|
63
70
|
}
|
|
64
71
|
const overwriteFunc = shallow ? overwriteShallow : overwriteDeep;
|
|
65
|
-
if (options.overwrite === "shallow-once")
|
|
72
|
+
if (options.overwrite === "shallow-once")
|
|
73
|
+
options.overwrite = true;
|
|
66
74
|
overwriteFunc(state, obj, IGNORE_STATE_PARAMS);
|
|
67
75
|
};
|
|
68
76
|
const hoistStateUpdate = (state, obj, options) => {
|
|
@@ -70,11 +78,13 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
70
78
|
const { parent, __ref: ref } = element;
|
|
71
79
|
const stateKey = ref == null ? void 0 : ref.__state;
|
|
72
80
|
const stateType = ref == null ? void 0 : ref.__stateType;
|
|
73
|
-
if (!stateKey)
|
|
81
|
+
if (!stateKey)
|
|
82
|
+
return;
|
|
74
83
|
const asksForInherit = checkIfInherits(element);
|
|
75
84
|
const inheritedState = findInheritedState(element, parent, { returnParent: true });
|
|
76
85
|
const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
|
|
77
|
-
if (!shouldPropagateState)
|
|
86
|
+
if (!shouldPropagateState)
|
|
87
|
+
return;
|
|
78
88
|
const isStringState = stateType === "string" || stateType === "number" || stateType === "boolean";
|
|
79
89
|
const value = isStringState ? state.value : state.parse();
|
|
80
90
|
const passedValue = isStringState ? state.value : obj;
|
|
@@ -82,7 +92,8 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
82
92
|
const findGrandParentState = getParentStateInKey(stateKey, parent.state);
|
|
83
93
|
const changesValue = createNestedObjectByKeyPath(stateKey, passedValue);
|
|
84
94
|
const targetParent = findRootState || findGrandParentState || parent.state;
|
|
85
|
-
if (options.replace)
|
|
95
|
+
if (options.replace)
|
|
96
|
+
overwriteDeep(targetParent, changesValue || value);
|
|
86
97
|
targetParent.update(changesValue, __spreadValues({
|
|
87
98
|
execStateFunction: false,
|
|
88
99
|
isHoisted: true,
|
|
@@ -96,7 +107,8 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
96
107
|
return true;
|
|
97
108
|
};
|
|
98
109
|
const updateDependentState = (state, obj, options) => {
|
|
99
|
-
if (!state.__depends)
|
|
110
|
+
if (!state.__depends)
|
|
111
|
+
return;
|
|
100
112
|
for (const el in state.__depends) {
|
|
101
113
|
const dependentState = state.__depends[el];
|
|
102
114
|
dependentState.clean().update(state.parse(), options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.203",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"build:esm": "npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm",
|
|
25
25
|
"build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
26
26
|
"build:iife": "npx esbuild *.js --target=node16 --format=iife --outdir=dist/iife",
|
|
27
|
-
"build": "rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
28
|
-
"prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
27
|
+
"build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
28
|
+
"prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@domql/event": "^2.5.
|
|
32
|
-
"@domql/report": "^2.5.
|
|
33
|
-
"@domql/utils": "^2.5.
|
|
31
|
+
"@domql/event": "^2.5.203",
|
|
32
|
+
"@domql/report": "^2.5.203",
|
|
33
|
+
"@domql/utils": "^2.5.203"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "f8c712416647ab3789253b7176eaa762627fc677"
|
|
36
36
|
}
|