@domql/element 2.27.0 → 2.27.8
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/methods/index.js +12 -5
- package/dist/esm/methods/index.js +21 -6
- package/methods/index.js +40 -11
- package/package.json +8 -8
|
@@ -53,7 +53,8 @@ function spotByPath(path) {
|
|
|
53
53
|
const element = this;
|
|
54
54
|
const arr = [].concat(path);
|
|
55
55
|
let active = import_tree.TREE[arr[0]];
|
|
56
|
-
if (!arr || !arr.length)
|
|
56
|
+
if (!arr || !arr.length)
|
|
57
|
+
return console.log(arr, "on", element.key, "is undefined");
|
|
57
58
|
while (active.key === arr[0]) {
|
|
58
59
|
arr.shift();
|
|
59
60
|
if (!arr.length) break;
|
|
@@ -66,7 +67,8 @@ function lookup(param) {
|
|
|
66
67
|
const el = this;
|
|
67
68
|
let { parent } = el;
|
|
68
69
|
if ((0, import_utils.isFunction)(param)) {
|
|
69
|
-
if (parent.state && param(parent, parent.state, parent.context))
|
|
70
|
+
if (parent.state && param(parent, parent.state, parent.context))
|
|
71
|
+
return parent;
|
|
70
72
|
else if (parent.parent) return parent.lookup(param);
|
|
71
73
|
else return;
|
|
72
74
|
}
|
|
@@ -136,7 +138,11 @@ async function remove(opts) {
|
|
|
136
138
|
element.log();
|
|
137
139
|
}
|
|
138
140
|
delete element.parent[element.key];
|
|
139
|
-
if (element.parent.__ref)
|
|
141
|
+
if (element.parent.__ref)
|
|
142
|
+
element.parent.__ref.__children = (0, import_utils.removeValueFromArray)(
|
|
143
|
+
element.parent.__ref.__children,
|
|
144
|
+
element.key
|
|
145
|
+
);
|
|
140
146
|
await (0, import_event.triggerEventOn)("remove", element, opts);
|
|
141
147
|
}
|
|
142
148
|
function get(param) {
|
|
@@ -184,7 +190,8 @@ function parse(excl = []) {
|
|
|
184
190
|
} else if (v === "props") {
|
|
185
191
|
const { __element, update, ...props } = element[v];
|
|
186
192
|
obj[v] = props;
|
|
187
|
-
} else if ((0, import_utils.isDefined)(val) && Object.hasOwnProperty.call(element, v))
|
|
193
|
+
} else if ((0, import_utils.isDefined)(val) && Object.hasOwnProperty.call(element, v))
|
|
194
|
+
obj[v] = val;
|
|
188
195
|
});
|
|
189
196
|
return obj;
|
|
190
197
|
}
|
|
@@ -265,7 +272,7 @@ function variables(obj = {}) {
|
|
|
265
272
|
}
|
|
266
273
|
return {
|
|
267
274
|
changed: (cb) => {
|
|
268
|
-
if (!changed) return;
|
|
275
|
+
if (!changed || !varCaches) return;
|
|
269
276
|
const returns = cb(changes, (0, import_utils.deepClone)(varCaches));
|
|
270
277
|
for (const key in changes) {
|
|
271
278
|
varCaches[key] = changes[key];
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { triggerEventOn } from "@domql/event";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isDefined,
|
|
4
|
+
isObject,
|
|
5
|
+
isFunction,
|
|
6
|
+
isObjectLike,
|
|
7
|
+
isProduction,
|
|
8
|
+
removeValueFromArray,
|
|
9
|
+
deepClone
|
|
10
|
+
} from "@domql/utils";
|
|
3
11
|
import { TREE } from "../tree.js";
|
|
4
12
|
import { parseFilters, REGISTRY } from "../mixins/index.js";
|
|
5
13
|
const ENV = "development";
|
|
@@ -7,7 +15,8 @@ function spotByPath(path) {
|
|
|
7
15
|
const element = this;
|
|
8
16
|
const arr = [].concat(path);
|
|
9
17
|
let active = TREE[arr[0]];
|
|
10
|
-
if (!arr || !arr.length)
|
|
18
|
+
if (!arr || !arr.length)
|
|
19
|
+
return console.log(arr, "on", element.key, "is undefined");
|
|
11
20
|
while (active.key === arr[0]) {
|
|
12
21
|
arr.shift();
|
|
13
22
|
if (!arr.length) break;
|
|
@@ -20,7 +29,8 @@ function lookup(param) {
|
|
|
20
29
|
const el = this;
|
|
21
30
|
let { parent } = el;
|
|
22
31
|
if (isFunction(param)) {
|
|
23
|
-
if (parent.state && param(parent, parent.state, parent.context))
|
|
32
|
+
if (parent.state && param(parent, parent.state, parent.context))
|
|
33
|
+
return parent;
|
|
24
34
|
else if (parent.parent) return parent.lookup(param);
|
|
25
35
|
else return;
|
|
26
36
|
}
|
|
@@ -90,7 +100,11 @@ async function remove(opts) {
|
|
|
90
100
|
element.log();
|
|
91
101
|
}
|
|
92
102
|
delete element.parent[element.key];
|
|
93
|
-
if (element.parent.__ref)
|
|
103
|
+
if (element.parent.__ref)
|
|
104
|
+
element.parent.__ref.__children = removeValueFromArray(
|
|
105
|
+
element.parent.__ref.__children,
|
|
106
|
+
element.key
|
|
107
|
+
);
|
|
94
108
|
await triggerEventOn("remove", element, opts);
|
|
95
109
|
}
|
|
96
110
|
function get(param) {
|
|
@@ -138,7 +152,8 @@ function parse(excl = []) {
|
|
|
138
152
|
} else if (v === "props") {
|
|
139
153
|
const { __element, update, ...props } = element[v];
|
|
140
154
|
obj[v] = props;
|
|
141
|
-
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
155
|
+
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
156
|
+
obj[v] = val;
|
|
142
157
|
});
|
|
143
158
|
return obj;
|
|
144
159
|
}
|
|
@@ -219,7 +234,7 @@ function variables(obj = {}) {
|
|
|
219
234
|
}
|
|
220
235
|
return {
|
|
221
236
|
changed: (cb) => {
|
|
222
|
-
if (!changed) return;
|
|
237
|
+
if (!changed || !varCaches) return;
|
|
223
238
|
const returns = cb(changes, deepClone(varCaches));
|
|
224
239
|
for (const key in changes) {
|
|
225
240
|
varCaches[key] = changes[key];
|
package/methods/index.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { triggerEventOn } from '@domql/event'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
isDefined,
|
|
6
|
+
isObject,
|
|
7
|
+
isFunction,
|
|
8
|
+
isObjectLike,
|
|
9
|
+
isProduction,
|
|
10
|
+
removeValueFromArray,
|
|
11
|
+
deepClone
|
|
12
|
+
} from '@domql/utils'
|
|
5
13
|
import { TREE } from '../tree.js'
|
|
6
14
|
import { parseFilters, REGISTRY } from '../mixins/index.js'
|
|
7
15
|
const ENV = process.env.NODE_ENV
|
|
@@ -12,7 +20,8 @@ export function spotByPath (path) {
|
|
|
12
20
|
const arr = [].concat(path)
|
|
13
21
|
let active = TREE[arr[0]]
|
|
14
22
|
|
|
15
|
-
if (!arr || !arr.length)
|
|
23
|
+
if (!arr || !arr.length)
|
|
24
|
+
return console.log(arr, 'on', element.key, 'is undefined')
|
|
16
25
|
|
|
17
26
|
while (active.key === arr[0]) {
|
|
18
27
|
arr.shift()
|
|
@@ -30,7 +39,8 @@ export function lookup (param) {
|
|
|
30
39
|
let { parent } = el
|
|
31
40
|
|
|
32
41
|
if (isFunction(param)) {
|
|
33
|
-
if (parent.state && param(parent, parent.state, parent.context))
|
|
42
|
+
if (parent.state && param(parent, parent.state, parent.context))
|
|
43
|
+
return parent
|
|
34
44
|
else if (parent.parent) return parent.lookup(param)
|
|
35
45
|
else return
|
|
36
46
|
}
|
|
@@ -111,7 +121,11 @@ export async function remove (opts) {
|
|
|
111
121
|
element.log()
|
|
112
122
|
}
|
|
113
123
|
delete element.parent[element.key]
|
|
114
|
-
if (element.parent.__ref)
|
|
124
|
+
if (element.parent.__ref)
|
|
125
|
+
element.parent.__ref.__children = removeValueFromArray(
|
|
126
|
+
element.parent.__ref.__children,
|
|
127
|
+
element.key
|
|
128
|
+
)
|
|
115
129
|
await triggerEventOn('remove', element, opts)
|
|
116
130
|
}
|
|
117
131
|
|
|
@@ -148,7 +162,12 @@ export function keys () {
|
|
|
148
162
|
const element = this
|
|
149
163
|
const keys = []
|
|
150
164
|
for (const param in element) {
|
|
151
|
-
if (
|
|
165
|
+
if (
|
|
166
|
+
(REGISTRY[param] && !parseFilters.elementKeys.includes(param)) ||
|
|
167
|
+
!Object.hasOwnProperty.call(element, param)
|
|
168
|
+
) {
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
152
171
|
keys.push(param)
|
|
153
172
|
}
|
|
154
173
|
return keys
|
|
@@ -164,14 +183,17 @@ export function parse (excl = []) {
|
|
|
164
183
|
if (v === 'state') {
|
|
165
184
|
if (element.__ref && !element.__ref.__hasRootState) return
|
|
166
185
|
const parsedVal = isFunction(val && val.parse) ? val.parse() : val
|
|
167
|
-
obj[v] = isFunction(parsedVal)
|
|
186
|
+
obj[v] = isFunction(parsedVal)
|
|
187
|
+
? parsedVal
|
|
188
|
+
: JSON.parse(JSON.stringify(parsedVal || {}))
|
|
168
189
|
} else if (v === 'scope') {
|
|
169
190
|
if (element.__ref && !element.__ref.__hasRootScope) return
|
|
170
191
|
obj[v] = JSON.parse(JSON.stringify(val || {}))
|
|
171
192
|
} else if (v === 'props') {
|
|
172
193
|
const { __element, update, ...props } = element[v]
|
|
173
194
|
obj[v] = props
|
|
174
|
-
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
195
|
+
} else if (isDefined(val) && Object.hasOwnProperty.call(element, v))
|
|
196
|
+
obj[v] = val
|
|
175
197
|
})
|
|
176
198
|
return obj
|
|
177
199
|
}
|
|
@@ -181,7 +203,9 @@ export function parseDeep (excl = []) {
|
|
|
181
203
|
const obj = parse.call(element, excl)
|
|
182
204
|
for (const v in obj) {
|
|
183
205
|
if (excl.includes(v)) return
|
|
184
|
-
if (isObjectLike(obj[v])) {
|
|
206
|
+
if (isObjectLike(obj[v])) {
|
|
207
|
+
obj[v] = parseDeep.call(obj[v], excl)
|
|
208
|
+
}
|
|
185
209
|
}
|
|
186
210
|
return obj
|
|
187
211
|
}
|
|
@@ -260,8 +284,8 @@ export function variables (obj = {}) {
|
|
|
260
284
|
}
|
|
261
285
|
}
|
|
262
286
|
return {
|
|
263
|
-
changed:
|
|
264
|
-
if (!changed) return
|
|
287
|
+
changed: cb => {
|
|
288
|
+
if (!changed || !varCaches) return
|
|
265
289
|
const returns = cb(changes, deepClone(varCaches))
|
|
266
290
|
for (const key in changes) {
|
|
267
291
|
varCaches[key] = changes[key]
|
|
@@ -280,7 +304,12 @@ export function variables (obj = {}) {
|
|
|
280
304
|
|
|
281
305
|
export function call (fnKey, ...args) {
|
|
282
306
|
const context = this.context
|
|
283
|
-
return (
|
|
307
|
+
return (
|
|
308
|
+
context.utils[fnKey] ||
|
|
309
|
+
context.functions[fnKey] ||
|
|
310
|
+
context.methods[fnKey] ||
|
|
311
|
+
context.snippets[fnKey]
|
|
312
|
+
)?.call(this, ...args)
|
|
284
313
|
}
|
|
285
314
|
|
|
286
315
|
export const METHODS = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
24
|
-
"build:esm": "npx esbuild *.js **/*.js --target=es2019 --format=esm --outdir=dist/esm",
|
|
25
|
-
"build:cjs": "npx esbuild *.js **/*.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
24
|
+
"build:esm": "cross-env NODE_ENV=$NODE_ENV npx esbuild *.js **/*.js --target=es2019 --format=esm --outdir=dist/esm",
|
|
25
|
+
"build:cjs": "cross-env NODE_ENV=$NODE_ENV npx esbuild *.js **/*.js --target=node16 --format=cjs --outdir=dist/cjs",
|
|
26
26
|
"build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
27
27
|
"prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@domql/event": "^2.27.
|
|
31
|
-
"@domql/render": "^2.27.
|
|
32
|
-
"@domql/state": "^2.27.
|
|
33
|
-
"@domql/utils": "^2.27.
|
|
30
|
+
"@domql/event": "^2.27.8",
|
|
31
|
+
"@domql/render": "^2.27.8",
|
|
32
|
+
"@domql/state": "^2.27.8",
|
|
33
|
+
"@domql/utils": "^2.27.8"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "e783fd54228d5c7aaab9d4b5624199a17a6c4713",
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/core": "^7.26.0"
|
|
38
38
|
}
|