@domql/element 2.4.1 → 2.4.2

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,223 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var update_exports = {};
30
- __export(update_exports, {
31
- default: () => update_default
32
- });
33
- module.exports = __toCommonJS(update_exports);
34
- var import_utils = require("@domql/utils");
35
- var import_event = require("@domql/event");
36
- var import_methods = require("./methods");
37
- var import_props = require("./props");
38
- var import_state = require("@domql/state");
39
- var import_utils2 = require("./utils");
40
- var import_create = __toESM(require("./create"), 1);
41
- var import_iterate = require("./iterate");
42
- var import_mixins = require("./mixins");
43
- var import_applyParam = require("./applyParam");
44
- var import_options = __toESM(require("./cache/options"), 1);
45
- const snapshot = {
46
- snapshotId: import_utils.createSnapshotId
47
- };
48
- const UPDATE_DEFAULT_OPTIONS = {
49
- stackChanges: false,
50
- cleanExec: true,
51
- preventRecursive: false,
52
- currentSnapshot: false,
53
- calleeElement: false,
54
- excludes: import_utils2.METHODS_EXL
55
- };
56
- const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
57
- const element = this;
58
- const { parent, node, key } = element;
59
- const { excludes, preventInheritAtCurrentState } = options;
60
- if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
61
- return;
62
- if (!excludes)
63
- (0, import_utils.merge)(options, UPDATE_DEFAULT_OPTIONS);
64
- let ref = element.__ref;
65
- if (!ref)
66
- ref = element.__ref = {};
67
- const [snapshotOnCallee, calleeElement, snapshotHasUpdated] = captureSnapshot(element, options);
68
- if (snapshotHasUpdated)
69
- return;
70
- if ((0, import_utils.isString)(params) || (0, import_utils.isNumber)(params)) {
71
- params = { text: params };
72
- }
73
- const ifFails = checkIfOnUpdate(element, parent, options);
74
- if (ifFails)
75
- return;
76
- const inheritState = inheritStateUpdates(element, options);
77
- if (inheritState === false)
78
- return;
79
- if (ref.__if && !options.preventPropsUpdate) {
80
- const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
81
- const hasFunctionInProps = ref.__props.filter((v) => (0, import_utils.isFunction)(v));
82
- const props = params.props || hasParentProps || hasFunctionInProps.length;
83
- if (props)
84
- (0, import_props.updateProps)(props, element, parent);
85
- }
86
- if (!options.isForced) {
87
- (0, import_event.triggerEventOn)("beforeClassAssign", element, options);
88
- }
89
- if (!options.preventInitUpdateListener) {
90
- const initUpdateReturns = (0, import_event.triggerEventOnUpdate)("initUpdate", params, element, options);
91
- if (initUpdateReturns === false)
92
- return element;
93
- }
94
- const overwriteChanges = (0, import_utils.overwriteDeep)(element, params, import_utils2.METHODS_EXL);
95
- const execChanges = (0, import_iterate.throughUpdatedExec)(element, { ignore: UPDATE_DEFAULT_OPTIONS });
96
- const definedChanges = (0, import_iterate.throughUpdatedDefine)(element);
97
- if (options.stackChanges && element.__stackChanges) {
98
- const stackChanges = (0, import_utils.merge)(definedChanges, (0, import_utils.merge)(execChanges, overwriteChanges));
99
- element.__stackChanges.push(stackChanges);
100
- }
101
- if (!ref.__if)
102
- return false;
103
- if (!node) {
104
- return;
105
- }
106
- for (const param in element) {
107
- const prop = element[param];
108
- const hasOnlyUpdateFalsy = options.onlyUpdate && (options.onlyUpdate !== param || !element.lookup(options.onlyUpdate));
109
- const isInPreventUpdate = (0, import_utils.isArray)(options.preventUpdate) && options.preventUpdate.includes(param);
110
- const isInPreventDefineUpdate = (0, import_utils.isArray)(options.preventDefineUpdate) && options.preventDefineUpdate.includes(param);
111
- if ((0, import_utils.isUndefined)(prop) || hasOnlyUpdateFalsy || isInPreventUpdate || isInPreventDefineUpdate || options.preventDefineUpdate === true || options.preventDefineUpdate === param || options.preventContentUpdate && param === "content" || (options.preventStateUpdate && param) === "state" || (0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || (0, import_utils2.isVariant)(param))
112
- continue;
113
- if (options.preventStateUpdate === "once")
114
- options.preventStateUpdate = false;
115
- const isElement = (0, import_applyParam.applyParam)(param, element, options);
116
- if (isElement) {
117
- const { hasDefine, hasContextDefine } = isElement;
118
- const canUpdate = (0, import_utils.isObject)(prop) && !hasDefine && !hasContextDefine && !options.preventRecursive;
119
- if (!canUpdate)
120
- continue;
121
- const childUpdateCall = () => update.call(prop, params[prop], {
122
- ...options,
123
- currentSnapshot: snapshotOnCallee,
124
- calleeElement
125
- });
126
- if (element.props && element.props.lazyLoad || options.lazyLoad) {
127
- import_utils.window.requestAnimationFrame(() => childUpdateCall());
128
- } else
129
- childUpdateCall();
130
- }
131
- }
132
- if (!options.preventUpdateListener)
133
- (0, import_event.triggerEventOn)("update", element, options);
134
- };
135
- const captureSnapshot = (element, options) => {
136
- const ref = element.__ref;
137
- const { currentSnapshot, calleeElement } = options;
138
- const isCallee = calleeElement === element;
139
- if (!calleeElement || isCallee) {
140
- const createdStanpshot = snapshot.snapshotId();
141
- ref.__currentSnapshot = createdStanpshot;
142
- return [createdStanpshot, element];
143
- }
144
- const snapshotOnCallee = ref.__currentSnapshot;
145
- if (currentSnapshot < snapshotOnCallee) {
146
- return [snapshotOnCallee, calleeElement, true];
147
- }
148
- return [snapshotOnCallee, calleeElement];
149
- };
150
- const checkIfOnUpdate = (element, parent, options) => {
151
- if (!(0, import_utils.isFunction)(element.if) || !element.state || !parent)
152
- return;
153
- const ref = element.__ref;
154
- const ifPassed = element.if(element, element.state, element.context, options);
155
- const itWasFalse = ref.__if !== true;
156
- if (ifPassed) {
157
- ref.__if = true;
158
- if (itWasFalse) {
159
- delete element.__hash;
160
- delete element.extend;
161
- if (!ref.__hasRootState) {
162
- delete element.state;
163
- }
164
- if (ref.__state) {
165
- element.state = ref.__state;
166
- }
167
- const created = (0, import_create.default)(element, parent, element.key, import_options.default.create);
168
- if (options.preventUpdate !== true && element.on && (0, import_utils.isFunction)(element.on.update)) {
169
- (0, import_event.applyEvent)(element.on.update, created, created.state);
170
- }
171
- return created;
172
- }
173
- } else if (element.node && !ifPassed) {
174
- element.node.remove();
175
- delete ref.__if;
176
- }
177
- };
178
- const inheritStateUpdates = (element, options) => {
179
- const { __ref: ref } = element;
180
- const stateKey = ref.__state;
181
- const { parent, state } = element;
182
- if (options.preventpdateTriggerStateUpdate)
183
- return;
184
- if (!stateKey && !ref.__hasRootState) {
185
- element.state = parent && parent.state || {};
186
- return;
187
- }
188
- const { isHoisted, execStateFunction, stateFunctionOverwrite } = options;
189
- const shouldForceStateUpdate = (0, import_utils.isFunction)(stateKey) && (!isHoisted && execStateFunction && stateFunctionOverwrite);
190
- if (shouldForceStateUpdate) {
191
- const execState = (0, import_utils.exec)(stateKey, element);
192
- state.set(execState, {
193
- ...options,
194
- preventUpdate: true
195
- });
196
- return;
197
- }
198
- const parentState = parent && parent.state || {};
199
- const keyInParentState = parentState[stateKey];
200
- if (!keyInParentState || options.preventInheritedStateUpdate)
201
- return;
202
- if (!options.preventInitStateUpdateListener) {
203
- const initStateReturns = (0, import_event.triggerEventOnUpdate)("initStateUpdated", keyInParentState, element, options);
204
- if (initStateReturns === false)
205
- return element;
206
- }
207
- const newState = createStateUpdate(element, parent, options);
208
- if (!options.preventStateUpdateListener) {
209
- (0, import_event.triggerEventOnUpdate)("stateUpdated", newState.parse(), element, options);
210
- }
211
- };
212
- const createStateUpdate = (element, parent, options) => {
213
- const __stateChildren = element.state.__children;
214
- const newState = (0, import_state.createState)(element, parent);
215
- element.state = newState;
216
- for (const child in __stateChildren) {
217
- if (newState[child])
218
- newState.__children[child] = __stateChildren[child];
219
- __stateChildren[child].parent = newState;
220
- }
221
- return newState;
222
- };
223
- var update_default = update;