@domql/state 2.4.1 → 2.4.11

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 symbo.ls
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.4.1",
3
+ "version": "2.4.11",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
@@ -31,5 +31,5 @@
31
31
  "@domql/report": "latest",
32
32
  "@domql/utils": "latest"
33
33
  },
34
- "gitHead": "86251c1d94b9e87288cc9e84fd9badb6461b2973"
34
+ "gitHead": "e5952db705e332f062e2e78113d620bd48ba16d9"
35
35
  }
@@ -1,129 +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 createState_exports = {};
20
- __export(createState_exports, {
21
- createState: () => createState
22
- });
23
- module.exports = __toCommonJS(createState_exports);
24
- var import_event = require("@domql/event");
25
- var import_utils = require("@domql/utils");
26
- var import_ignore = require("./ignore");
27
- var import_methods = require("./methods");
28
- var import_updateState = require("./updateState");
29
- var import_inherit = require("./inherit");
30
- const createState = function(element, parent, options) {
31
- const skipApplyMethods = Boolean(options && options.skipApplyMethods);
32
- const objectizeState = checkForTypes(element);
33
- if (objectizeState === false)
34
- return parent.state || {};
35
- else
36
- element.state = (0, import_utils.deepClone)(objectizeState, import_ignore.IGNORE_STATE_PARAMS);
37
- const whatInitReturns = (0, import_event.triggerEventOn)("stateInit", element, options);
38
- if (whatInitReturns === false)
39
- return element.state;
40
- if ((0, import_inherit.checkIfInherits)(element)) {
41
- const inheritedState = (0, import_inherit.createInheritedState)(element, parent);
42
- element.state = inheritedState || {};
43
- }
44
- const dependentState = applyDependentState(element, element.state);
45
- if (dependentState)
46
- element.state = dependentState;
47
- if (skipApplyMethods) {
48
- if (element.parent && element.parent.state) {
49
- element.state.parent = element.parent.state;
50
- } else {
51
- element.state.parent = {};
52
- }
53
- return element.state;
54
- }
55
- applyMethods(element);
56
- (0, import_event.triggerEventOn)("stateCreated", element);
57
- return element.state;
58
- };
59
- const applyDependentState = (element, state) => {
60
- const { __ref: ref } = state;
61
- if (!ref)
62
- return;
63
- const dependentState = (0, import_utils.deepClone)(ref, import_ignore.IGNORE_STATE_PARAMS);
64
- const newDepends = { [element.key]: dependentState };
65
- ref.__depends = (0, import_utils.isObject)(ref.__depends) ? { ...ref.__depends, ...newDepends } : newDepends;
66
- return dependentState;
67
- };
68
- const checkForTypes = (element) => {
69
- const { state, __ref: ref } = element;
70
- if ((0, import_utils.isFunction)(state)) {
71
- ref.__state = state;
72
- return (0, import_utils.exec)(state, element);
73
- }
74
- if ((0, import_utils.is)(state)("string", "number")) {
75
- ref.__state = state;
76
- return {};
77
- }
78
- if (state === true) {
79
- ref.__state = element.key;
80
- return {};
81
- }
82
- if (state) {
83
- ref.__hasRootState = true;
84
- return state;
85
- }
86
- return false;
87
- };
88
- const addProtoToArray = (state, proto) => {
89
- for (const key in proto) {
90
- Object.defineProperty(state, key, {
91
- value: proto[key],
92
- enumerable: false,
93
- // Set this to true if you want the method to appear in for...in loops
94
- configurable: true,
95
- // Set this to true if you want to allow redefining/removing the property later
96
- writable: true
97
- // Set this to true if you want to allow changing the function later
98
- });
99
- }
100
- };
101
- const applyMethods = (element) => {
102
- const state = element.state;
103
- const ref = element.__ref;
104
- const proto = {
105
- clean: import_methods.clean.bind(state),
106
- parse: import_methods.parse.bind(state),
107
- destroy: import_methods.destroy.bind(state),
108
- update: import_updateState.updateState.bind(state),
109
- rootUpdate: import_methods.rootUpdate.bind(state),
110
- parentUpdate: import_methods.parentUpdate.bind(state),
111
- create: createState.bind(state),
112
- add: import_methods.add.bind(state),
113
- toggle: import_methods.toggle.bind(state),
114
- remove: import_methods.remove.bind(state),
115
- apply: import_methods.apply.bind(state),
116
- set: import_methods.set.bind(state),
117
- parent: element.parent.state,
118
- __element: element,
119
- __children: {},
120
- __root: ref.__root ? ref.__root.state : state
121
- };
122
- if ((0, import_utils.isArray)(state)) {
123
- addProtoToArray(state, proto);
124
- } else {
125
- Object.setPrototypeOf(state, proto);
126
- }
127
- if (state.parent)
128
- state.parent.__children[element.key] = state;
129
- };