@domql/state 2.5.198 → 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.
@@ -1,57 +0,0 @@
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 ignore_exports = {};
20
- __export(ignore_exports, {
21
- IGNORE_STATE_PARAMS: () => IGNORE_STATE_PARAMS
22
- });
23
- module.exports = __toCommonJS(ignore_exports);
24
- const IGNORE_STATE_PARAMS = [
25
- "update",
26
- "parse",
27
- "clean",
28
- "create",
29
- "destroy",
30
- "add",
31
- "toggle",
32
- "remove",
33
- "apply",
34
- "set",
35
- "reset",
36
- "replace",
37
- "quietReplace",
38
- "quietUpdate",
39
- "applyReplace",
40
- "applyFunction",
41
- "keys",
42
- "values",
43
- "ref",
44
- "rootUpdate",
45
- "parentUpdate",
46
- "parent",
47
- "__element",
48
- "__depends",
49
- "__ref",
50
- "__children",
51
- "root",
52
- "setByPath",
53
- "setPathCollection",
54
- "removeByPath",
55
- "removePathCollection",
56
- "getByPath"
57
- ];
@@ -1,130 +0,0 @@
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 inherit_exports = {};
20
- __export(inherit_exports, {
21
- checkIfInherits: () => checkIfInherits,
22
- createInheritedState: () => createInheritedState,
23
- createNestedObjectByKeyPath: () => createNestedObjectByKeyPath,
24
- findInheritedState: () => findInheritedState,
25
- getChildStateInKey: () => getChildStateInKey,
26
- getParentStateInKey: () => getParentStateInKey,
27
- getRootStateInKey: () => getRootStateInKey,
28
- isState: () => isState
29
- });
30
- module.exports = __toCommonJS(inherit_exports);
31
- var import_utils = require("@domql/utils");
32
- var import_ignore = require("./ignore.js");
33
- const getRootStateInKey = (stateKey, parentState) => {
34
- if (!stateKey.includes("~/"))
35
- return;
36
- const arr = stateKey.split("~/");
37
- if (arr.length > 1)
38
- return parentState.root;
39
- };
40
- const getParentStateInKey = (stateKey, parentState) => {
41
- if (!stateKey.includes("../"))
42
- return;
43
- const arr = stateKey.split("../");
44
- const arrLength = arr.length - 1;
45
- for (let i = 0; i < arrLength; i++) {
46
- if (!parentState.parent)
47
- return null;
48
- parentState = parentState.parent;
49
- }
50
- return parentState;
51
- };
52
- const getChildStateInKey = (stateKey, parentState, options = {}) => {
53
- const arr = stateKey.split("/");
54
- const arrLength = arr.length - 1;
55
- for (let i = 0; i < arrLength; i++) {
56
- const childKey = arr[i];
57
- const grandChildKey = arr[i + 1];
58
- if (childKey === "__proto__" || grandChildKey === "__proto__")
59
- return;
60
- let childInParent = parentState[childKey];
61
- if (!childInParent)
62
- childInParent = parentState[childKey] = {};
63
- if (!childInParent[grandChildKey])
64
- childInParent[grandChildKey] = {};
65
- stateKey = grandChildKey;
66
- parentState = childInParent;
67
- }
68
- if (options.returnParent)
69
- return parentState;
70
- return parentState[stateKey];
71
- };
72
- const findInheritedState = (element, parent, options = {}) => {
73
- const ref = element.__ref;
74
- let stateKey = ref.__state;
75
- if (!checkIfInherits(element))
76
- return;
77
- const rootState = getRootStateInKey(stateKey, parent.state);
78
- let parentState = parent.state;
79
- if (rootState) {
80
- parentState = rootState;
81
- stateKey = stateKey.replaceAll("~/", "");
82
- } else {
83
- const findGrandParentState = getParentStateInKey(stateKey, parent.state);
84
- if (findGrandParentState) {
85
- parentState = findGrandParentState;
86
- stateKey = stateKey.replaceAll("../", "");
87
- }
88
- }
89
- if (!parentState)
90
- return;
91
- return getChildStateInKey(stateKey, parentState, options);
92
- };
93
- const createInheritedState = (element, parent) => {
94
- const ref = element.__ref;
95
- const inheritedState = findInheritedState(element, parent);
96
- if ((0, import_utils.isUndefined)(inheritedState))
97
- return element.state;
98
- if ((0, import_utils.is)(inheritedState)("object", "array")) {
99
- return (0, import_utils.deepClone)(inheritedState, { exclude: import_ignore.IGNORE_STATE_PARAMS });
100
- } else if ((0, import_utils.is)(inheritedState)("string", "number", "boolean")) {
101
- ref.__stateType = typeof inheritedState;
102
- return { value: inheritedState };
103
- }
104
- console.warn(ref.__state, "is not present. Replacing with", {});
105
- };
106
- const checkIfInherits = (element) => {
107
- const ref = element.__ref;
108
- const stateKey = ref.__state;
109
- if (stateKey && (0, import_utils.is)(stateKey)("number", "string", "boolean"))
110
- return true;
111
- return false;
112
- };
113
- const isState = function(state) {
114
- if (!(0, import_utils.isObjectLike)(state))
115
- return false;
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;
117
- };
118
- const createNestedObjectByKeyPath = (path, value) => {
119
- if (!path) {
120
- return value || {};
121
- }
122
- const keys = path.split("/");
123
- const obj = {};
124
- let ref = obj;
125
- keys.forEach((key, index) => {
126
- ref[key] = index === keys.length - 1 ? value || {} : {};
127
- ref = ref[key];
128
- });
129
- return obj;
130
- };
@@ -1,37 +0,0 @@
1
- const IGNORE_STATE_PARAMS = [
2
- "update",
3
- "parse",
4
- "clean",
5
- "create",
6
- "destroy",
7
- "add",
8
- "toggle",
9
- "remove",
10
- "apply",
11
- "set",
12
- "reset",
13
- "replace",
14
- "quietReplace",
15
- "quietUpdate",
16
- "applyReplace",
17
- "applyFunction",
18
- "keys",
19
- "values",
20
- "ref",
21
- "rootUpdate",
22
- "parentUpdate",
23
- "parent",
24
- "__element",
25
- "__depends",
26
- "__ref",
27
- "__children",
28
- "root",
29
- "setByPath",
30
- "setPathCollection",
31
- "removeByPath",
32
- "removePathCollection",
33
- "getByPath"
34
- ];
35
- export {
36
- IGNORE_STATE_PARAMS
37
- };
@@ -1,110 +0,0 @@
1
- import { deepClone, is, isObjectLike, isUndefined } from "@domql/utils";
2
- import { IGNORE_STATE_PARAMS } from "./ignore.js";
3
- const getRootStateInKey = (stateKey, parentState) => {
4
- if (!stateKey.includes("~/"))
5
- return;
6
- const arr = stateKey.split("~/");
7
- if (arr.length > 1)
8
- return parentState.root;
9
- };
10
- const getParentStateInKey = (stateKey, parentState) => {
11
- if (!stateKey.includes("../"))
12
- return;
13
- const arr = stateKey.split("../");
14
- const arrLength = arr.length - 1;
15
- for (let i = 0; i < arrLength; i++) {
16
- if (!parentState.parent)
17
- return null;
18
- parentState = parentState.parent;
19
- }
20
- return parentState;
21
- };
22
- const getChildStateInKey = (stateKey, parentState, options = {}) => {
23
- const arr = stateKey.split("/");
24
- const arrLength = arr.length - 1;
25
- for (let i = 0; i < arrLength; i++) {
26
- const childKey = arr[i];
27
- const grandChildKey = arr[i + 1];
28
- if (childKey === "__proto__" || grandChildKey === "__proto__")
29
- return;
30
- let childInParent = parentState[childKey];
31
- if (!childInParent)
32
- childInParent = parentState[childKey] = {};
33
- if (!childInParent[grandChildKey])
34
- childInParent[grandChildKey] = {};
35
- stateKey = grandChildKey;
36
- parentState = childInParent;
37
- }
38
- if (options.returnParent)
39
- return parentState;
40
- return parentState[stateKey];
41
- };
42
- const findInheritedState = (element, parent, options = {}) => {
43
- const ref = element.__ref;
44
- let stateKey = ref.__state;
45
- if (!checkIfInherits(element))
46
- return;
47
- const rootState = getRootStateInKey(stateKey, parent.state);
48
- let parentState = parent.state;
49
- if (rootState) {
50
- parentState = rootState;
51
- stateKey = stateKey.replaceAll("~/", "");
52
- } else {
53
- const findGrandParentState = getParentStateInKey(stateKey, parent.state);
54
- if (findGrandParentState) {
55
- parentState = findGrandParentState;
56
- stateKey = stateKey.replaceAll("../", "");
57
- }
58
- }
59
- if (!parentState)
60
- return;
61
- return getChildStateInKey(stateKey, parentState, options);
62
- };
63
- const createInheritedState = (element, parent) => {
64
- const ref = element.__ref;
65
- const inheritedState = findInheritedState(element, parent);
66
- if (isUndefined(inheritedState))
67
- return element.state;
68
- if (is(inheritedState)("object", "array")) {
69
- return deepClone(inheritedState, { exclude: IGNORE_STATE_PARAMS });
70
- } else if (is(inheritedState)("string", "number", "boolean")) {
71
- ref.__stateType = typeof inheritedState;
72
- return { value: inheritedState };
73
- }
74
- console.warn(ref.__state, "is not present. Replacing with", {});
75
- };
76
- const checkIfInherits = (element) => {
77
- const ref = element.__ref;
78
- const stateKey = ref.__state;
79
- if (stateKey && is(stateKey)("number", "string", "boolean"))
80
- return true;
81
- return false;
82
- };
83
- const isState = function(state) {
84
- if (!isObjectLike(state))
85
- return false;
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;
87
- };
88
- const createNestedObjectByKeyPath = (path, value) => {
89
- if (!path) {
90
- return value || {};
91
- }
92
- const keys = path.split("/");
93
- const obj = {};
94
- let ref = obj;
95
- keys.forEach((key, index) => {
96
- ref[key] = index === keys.length - 1 ? value || {} : {};
97
- ref = ref[key];
98
- });
99
- return obj;
100
- };
101
- export {
102
- checkIfInherits,
103
- createInheritedState,
104
- createNestedObjectByKeyPath,
105
- findInheritedState,
106
- getChildStateInKey,
107
- getParentStateInKey,
108
- getRootStateInKey,
109
- isState
110
- };
package/ignore.js DELETED
@@ -1,8 +0,0 @@
1
- 'use strict'
2
-
3
- export const IGNORE_STATE_PARAMS = [
4
- 'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set', 'reset',
5
- 'replace', 'quietReplace', 'quietUpdate', 'applyReplace', 'applyFunction', 'keys', 'values', 'ref',
6
- 'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', 'root',
7
- 'setByPath', 'setPathCollection', 'removeByPath', 'removePathCollection', 'getByPath'
8
- ]
package/inherit.js DELETED
@@ -1,131 +0,0 @@
1
- 'use strict'
2
-
3
- import { deepClone, is, isObjectLike, isUndefined } from '@domql/utils'
4
- import { IGNORE_STATE_PARAMS } from './ignore.js'
5
-
6
- export const getRootStateInKey = (stateKey, parentState) => {
7
- if (!stateKey.includes('~/')) return
8
- const arr = stateKey.split('~/')
9
- if (arr.length > 1) return parentState.root
10
- }
11
-
12
- export const getParentStateInKey = (stateKey, parentState) => {
13
- if (!stateKey.includes('../')) return
14
- const arr = stateKey.split('../')
15
- const arrLength = arr.length - 1
16
- for (let i = 0; i < arrLength; i++) {
17
- if (!parentState.parent) return null
18
- parentState = parentState.parent
19
- }
20
- return parentState
21
- }
22
-
23
- export const getChildStateInKey = (stateKey, parentState, options = {}) => {
24
- const arr = stateKey.split('/')
25
- const arrLength = arr.length - 1
26
- for (let i = 0; i < arrLength; i++) {
27
- const childKey = arr[i]
28
- const grandChildKey = arr[i + 1]
29
-
30
- if (childKey === '__proto__' || grandChildKey === '__proto__') return
31
-
32
- let childInParent = parentState[childKey]
33
- if (!childInParent) childInParent = parentState[childKey] = {} // check for array
34
- if (!childInParent[grandChildKey]) childInParent[grandChildKey] = {} // check for array
35
-
36
- stateKey = grandChildKey
37
- parentState = childInParent
38
- }
39
- if (options.returnParent) return parentState
40
- return parentState[stateKey]
41
- }
42
-
43
- export const findInheritedState = (element, parent, options = {}) => {
44
- const ref = element.__ref
45
- let stateKey = ref.__state
46
- if (!checkIfInherits(element)) return
47
-
48
- const rootState = getRootStateInKey(stateKey, parent.state)
49
- let parentState = parent.state
50
-
51
- if (rootState) {
52
- parentState = rootState
53
- stateKey = stateKey.replaceAll('~/', '')
54
- } else {
55
- const findGrandParentState = getParentStateInKey(stateKey, parent.state)
56
- if (findGrandParentState) {
57
- parentState = findGrandParentState
58
- stateKey = stateKey.replaceAll('../', '')
59
- }
60
- }
61
-
62
- if (!parentState) return
63
- return getChildStateInKey(stateKey, parentState, options)
64
- }
65
-
66
- export const createInheritedState = (element, parent) => {
67
- const ref = element.__ref
68
- const inheritedState = findInheritedState(element, parent)
69
- if (isUndefined(inheritedState)) return element.state
70
-
71
- if (is(inheritedState)('object', 'array')) {
72
- return deepClone(inheritedState, { exclude: IGNORE_STATE_PARAMS })
73
- } else if (is(inheritedState)('string', 'number', 'boolean')) {
74
- ref.__stateType = typeof inheritedState
75
- return { value: inheritedState }
76
- }
77
-
78
- console.warn(ref.__state, 'is not present. Replacing with', {})
79
- }
80
-
81
- export const checkIfInherits = (element) => {
82
- const ref = element.__ref
83
- const stateKey = ref.__state
84
-
85
- if (stateKey && is(stateKey)('number', 'string', 'boolean')) return true
86
- return false
87
- }
88
-
89
- export const isState = function (state) {
90
- if (!isObjectLike(state)) return false
91
- return state.update &&
92
- state.parse &&
93
- state.clean &&
94
- state.create &&
95
- state.parent &&
96
- state.destroy &&
97
- state.rootUpdate &&
98
- state.parentUpdate &&
99
- state.keys &&
100
- state.values &&
101
- state.toggle &&
102
- state.replace &&
103
- state.quietUpdate &&
104
- state.quietReplace &&
105
- state.add &&
106
- state.apply &&
107
- state.applyReplace &&
108
- state.setByPath &&
109
- state.setPathCollection &&
110
- state.removeByPath &&
111
- state.removePathCollection &&
112
- state.getByPath &&
113
- state.applyFunction &&
114
- state.__element &&
115
- state.__children
116
- // return arrayContainsOtherArray(keys, ['update', 'parse', 'clean', 'create', 'parent', 'rootUpdate'])
117
- }
118
-
119
- export const createNestedObjectByKeyPath = (path, value) => {
120
- if (!path) {
121
- return value || {}
122
- }
123
- const keys = path.split('/')
124
- const obj = {}
125
- let ref = obj
126
- keys.forEach((key, index) => {
127
- ref[key] = index === keys.length - 1 ? value || {} : {}
128
- ref = ref[key]
129
- })
130
- return obj
131
- }