@domql/state 2.3.121 → 2.3.122

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/createState.js CHANGED
@@ -5,7 +5,7 @@ import { deepClone, exec, is, isFunction, isObject } from '@domql/utils'
5
5
  import { IGNORE_STATE_PARAMS } from './ignore'
6
6
  import { add, apply, clean, destroy, parse, remove, rootUpdate, toggle } from './methods'
7
7
  import { updateState } from './updateState'
8
- import { checkIfInherits, createInheritedState } from './utils'
8
+ import { checkIfInherits, createInheritedState } from './inherit'
9
9
 
10
10
  export const createState = function (element, parent, opts) {
11
11
  const skip = (opts && opts.skip) ? opts.skip : false
@@ -26,7 +26,7 @@ var import_utils = require("@domql/utils");
26
26
  var import_ignore = require("./ignore");
27
27
  var import_methods = require("./methods");
28
28
  var import_updateState = require("./updateState");
29
- var import_utils2 = require("./utils");
29
+ var import_inherit = require("./inherit");
30
30
  const createState = function(element, parent, opts) {
31
31
  const skip = opts && opts.skip ? opts.skip : false;
32
32
  const objectizeState = checkForTypes(element);
@@ -37,8 +37,8 @@ const createState = function(element, parent, opts) {
37
37
  const whatInitReturns = (0, import_event.triggerEventOn)("stateInit", element);
38
38
  if (whatInitReturns === false)
39
39
  return element.state;
40
- if ((0, import_utils2.checkIfInherits)(element)) {
41
- element.state = (0, import_utils2.createInheritedState)(element, parent) || {};
40
+ if ((0, import_inherit.checkIfInherits)(element)) {
41
+ element.state = (0, import_inherit.createInheritedState)(element, parent) || {};
42
42
  }
43
43
  const dependentState = applyDependentState(element, state);
44
44
  if (dependentState)
package/dist/cjs/index.js CHANGED
@@ -19,4 +19,4 @@ __reExport(state_exports, require("./ignore"), module.exports);
19
19
  __reExport(state_exports, require("./createState"), module.exports);
20
20
  __reExport(state_exports, require("./updateState"), module.exports);
21
21
  __reExport(state_exports, require("./methods"), module.exports);
22
- __reExport(state_exports, require("./utils"), module.exports);
22
+ __reExport(state_exports, require("./inherit"), module.exports);
@@ -16,18 +16,19 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var utils_exports = {};
20
- __export(utils_exports, {
19
+ var inherit_exports = {};
20
+ __export(inherit_exports, {
21
21
  checkIfInherits: () => checkIfInherits,
22
22
  createInheritedState: () => createInheritedState,
23
+ findInheritedState: () => findInheritedState,
23
24
  getChildStateInKey: () => getChildStateInKey,
24
25
  getParentStateInKey: () => getParentStateInKey,
25
26
  isState: () => isState
26
27
  });
27
- module.exports = __toCommonJS(utils_exports);
28
+ module.exports = __toCommonJS(inherit_exports);
28
29
  var import_utils = require("@domql/utils");
29
- const getParentStateInKey = (stateKey, parentState) => {
30
- const arr = stateKey.split("../");
30
+ const getParentStateInKey = (stateKey2, parentState) => {
31
+ const arr = stateKey2.split("../");
31
32
  const arrLength = arr.length - 1;
32
33
  for (let i = 0; i < arrLength; i++) {
33
34
  if (!parentState.parent)
@@ -36,48 +37,52 @@ const getParentStateInKey = (stateKey, parentState) => {
36
37
  }
37
38
  return parentState;
38
39
  };
39
- const getChildStateInKey = (stateKey, parentState) => {
40
- const arr = stateKey.split("/");
40
+ const getChildStateInKey = (stateKey2, parentState) => {
41
+ const arr = stateKey2.split("/");
41
42
  const arrLength = arr.length - 1;
42
43
  for (let i = 0; i < arrLength; i++) {
43
44
  const childKey = arr[i];
44
45
  const grandChildKey = arr[i + 1];
45
46
  const childInParent = parentState[childKey];
46
47
  if (childInParent && childInParent[grandChildKey]) {
47
- stateKey = grandChildKey;
48
+ stateKey2 = grandChildKey;
48
49
  parentState = childInParent;
49
50
  } else
50
51
  return;
51
52
  }
52
- return parentState[stateKey];
53
+ return parentState[stateKey2];
53
54
  };
54
- const createInheritedState = (element, parent) => {
55
- const __elementRef = element.__ref;
56
- let stateKey = __elementRef.__state;
57
- if (!stateKey || (0, import_utils.isNot)(stateKey)("number", "string"))
55
+ const findInheritedState = (element, parent) => {
56
+ const ref = element.__ref;
57
+ let stateKey2 = ref.__state;
58
+ if (!stateKey2 || (0, import_utils.isNot)(stateKey2)("number", "string"))
58
59
  return element.state;
59
60
  let parentState = parent.state;
60
- if (stateKey.includes("../")) {
61
- parentState = getParentStateInKey(stateKey, parent.state);
62
- stateKey = stateKey.replaceAll("../", "");
61
+ if (stateKey2.includes("../")) {
62
+ parentState = getParentStateInKey(stateKey2, parent.state);
63
+ stateKey2 = stateKey2.replaceAll("../", "");
63
64
  }
64
65
  if (!parentState)
65
66
  return;
66
- const keyInParentState = getChildStateInKey(stateKey, parentState);
67
- if (!keyInParentState)
67
+ return getChildStateInKey(stateKey2, parentState);
68
+ };
69
+ const createInheritedState = (element, parent) => {
70
+ const ref = element.__ref;
71
+ const inheritedState = findInheritedState(element, parent);
72
+ if (!inheritedState)
68
73
  return;
69
- if ((0, import_utils.is)(keyInParentState)("object", "array")) {
70
- return (0, import_utils.deepClone)(keyInParentState);
71
- } else if ((0, import_utils.is)(keyInParentState)("string", "number")) {
72
- __elementRef.__stateType = "string";
73
- return { value: keyInParentState };
74
+ if ((0, import_utils.is)(inheritedState)("object", "array")) {
75
+ return (0, import_utils.deepClone)(inheritedState);
76
+ } else if ((0, import_utils.is)(inheritedState)("string", "number")) {
77
+ ref.__stateType = "string";
78
+ return { value: inheritedState };
74
79
  }
75
80
  console.warn(stateKey, "is not present. Replacing with", {});
76
81
  };
77
82
  const checkIfInherits = (element) => {
78
- const __elementRef = element.__ref;
79
- const stateKey = __elementRef.__state;
80
- if (!stateKey || (0, import_utils.isNot)(stateKey)("number", "string"))
83
+ const ref = element.__ref;
84
+ const stateKey2 = ref.__state;
85
+ if (!stateKey2 || (0, import_utils.isNot)(stateKey2)("number", "string"))
81
86
  return false;
82
87
  return true;
83
88
  };
@@ -25,7 +25,7 @@ var import_report = require("@domql/report");
25
25
  var import_event = require("@domql/event");
26
26
  var import_ignore = require("./ignore");
27
27
  var import_utils = require("@domql/utils");
28
- var import_utils2 = require("./utils");
28
+ var import_inherit = require("./inherit");
29
29
  const updateState = function(obj, options = {}) {
30
30
  const state = this;
31
31
  const element = state.__element;
@@ -58,20 +58,21 @@ const applyOverwrite = (state, obj, options) => {
58
58
  };
59
59
  const hoistStateUpdate = (state, obj, options) => {
60
60
  const element = state.__element;
61
- const __elementRef = element.__ref;
62
- const stateKey = __elementRef.__state;
61
+ const { parent, __ref: ref } = element;
62
+ const stateKey = ref.__state;
63
63
  if (!stateKey)
64
64
  return;
65
- const asksForInherit = (0, import_utils2.checkIfInherits)(element);
66
- const shouldPropagateState = asksForInherit && !options.stopStatePropagation;
67
- const parentState = element.parent.state;
65
+ const asksForInherit = (0, import_inherit.checkIfInherits)(element);
66
+ const inheritedState = (0, import_inherit.findInheritedState)(element, parent);
67
+ const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
68
68
  if (!shouldPropagateState)
69
69
  return;
70
- const isStringState = __elementRef.__stateType === "string";
70
+ console.log(inheritedState);
71
+ const isStringState = ref.__stateType === "string";
71
72
  const value = isStringState ? state.value : state.parse();
72
73
  const passedValue = isStringState ? state.value : obj;
73
- parentState[stateKey] = value;
74
- parentState.update({ [stateKey]: passedValue }, {
74
+ inheritedState[stateKey] = value;
75
+ inheritedState.update({ [stateKey]: passedValue }, {
75
76
  skipOverwrite: true,
76
77
  preventUpdate: options.preventHoistElementUpdate,
77
78
  ...options
package/index.js CHANGED
@@ -4,4 +4,4 @@ export * from './ignore'
4
4
  export * from './createState'
5
5
  export * from './updateState'
6
6
  export * from './methods'
7
- export * from './utils'
7
+ export * from './inherit'
@@ -27,9 +27,9 @@ export const getChildStateInKey = (stateKey, parentState) => {
27
27
  return parentState[stateKey]
28
28
  }
29
29
 
30
- export const createInheritedState = (element, parent) => {
31
- const __elementRef = element.__ref
32
- let stateKey = __elementRef.__state
30
+ export const findInheritedState = (element, parent) => {
31
+ const ref = element.__ref
32
+ let stateKey = ref.__state
33
33
  if (!stateKey || isNot(stateKey)('number', 'string')) return element.state
34
34
 
35
35
  let parentState = parent.state
@@ -38,23 +38,27 @@ export const createInheritedState = (element, parent) => {
38
38
  stateKey = stateKey.replaceAll('../', '')
39
39
  }
40
40
  if (!parentState) return
41
+ return getChildStateInKey(stateKey, parentState)
42
+ }
41
43
 
42
- const keyInParentState = getChildStateInKey(stateKey, parentState)
43
- if (!keyInParentState) return
44
+ export const createInheritedState = (element, parent) => {
45
+ const ref = element.__ref
46
+ const inheritedState = findInheritedState(element, parent)
47
+ if (!inheritedState) return
44
48
 
45
- if (is(keyInParentState)('object', 'array')) {
46
- return deepClone(keyInParentState)
47
- } else if (is(keyInParentState)('string', 'number')) {
48
- __elementRef.__stateType = 'string'
49
- return { value: keyInParentState }
49
+ if (is(inheritedState)('object', 'array')) {
50
+ return deepClone(inheritedState)
51
+ } else if (is(inheritedState)('string', 'number')) {
52
+ ref.__stateType = 'string'
53
+ return { value: inheritedState }
50
54
  }
51
55
 
52
56
  console.warn(stateKey, 'is not present. Replacing with', {})
53
57
  }
54
58
 
55
59
  export const checkIfInherits = (element) => {
56
- const __elementRef = element.__ref
57
- const stateKey = __elementRef.__state
60
+ const ref = element.__ref
61
+ const stateKey = ref.__state
58
62
  if (!stateKey || isNot(stateKey)('number', 'string')) return false
59
63
  return true
60
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.3.121",
3
+ "version": "2.3.122",
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": "7bb63fd5aab7bfa92c0aaa3a7205ff9a002fac1c"
29
+ "gitHead": "e599b1dc425a72bd3ec989b909f47bb51bf4dbac"
30
30
  }
package/updateState.js CHANGED
@@ -4,7 +4,7 @@ import { report } from '@domql/report'
4
4
  import { triggerEventOn } from '@domql/event'
5
5
  import { IGNORE_STATE_PARAMS } from './ignore'
6
6
  import { deepMerge, overwriteDeep, overwriteShallow } from '@domql/utils'
7
- import { checkIfInherits } from './utils'
7
+ import { checkIfInherits, findInheritedState } from './inherit'
8
8
 
9
9
  export const updateState = function (obj, options = {}) {
10
10
  const state = this
@@ -48,21 +48,22 @@ const applyOverwrite = (state, obj, options) => {
48
48
 
49
49
  const hoistStateUpdate = (state, obj, options) => {
50
50
  const element = state.__element
51
- const __elementRef = element.__ref
52
- const stateKey = __elementRef.__state
51
+ const { parent, __ref: ref } = element
52
+ const stateKey = ref.__state
53
53
  if (!stateKey) return
54
54
 
55
55
  const asksForInherit = checkIfInherits(element)
56
- const shouldPropagateState = asksForInherit && !options.stopStatePropagation
57
- const parentState = element.parent.state
58
-
56
+ const inheritedState = findInheritedState(element, parent)
57
+ const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation
59
58
  if (!shouldPropagateState) return
60
- const isStringState = (__elementRef.__stateType === 'string')
59
+ console.log(inheritedState)
60
+
61
+ const isStringState = (ref.__stateType === 'string')
61
62
  const value = isStringState ? state.value : state.parse()
62
63
  const passedValue = isStringState ? state.value : obj
63
64
 
64
- parentState[stateKey] = value
65
- parentState.update({ [stateKey]: passedValue }, {
65
+ inheritedState[stateKey] = value
66
+ inheritedState.update({ [stateKey]: passedValue }, {
66
67
  skipOverwrite: true,
67
68
  preventUpdate: options.preventHoistElementUpdate,
68
69
  ...options