@domql/element 2.5.51 → 2.5.53
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/create.js +4 -1
- package/dist/cjs/create.js +4 -1
- package/dist/cjs/node.js +2 -0
- package/dist/cjs/update.js +2 -2
- package/dist/cjs/utils/component.js +18 -2
- package/dist/cjs/utils/propEvents.js +38 -0
- package/node.js +2 -0
- package/package.json +2 -2
- package/update.js +6 -6
- package/utils/component.js +19 -2
- package/utils/propEvents.js +17 -0
package/create.js
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
applyKeyComponentAsExtend,
|
|
35
35
|
applyVariant,
|
|
36
36
|
checkIfKeyIsComponent,
|
|
37
|
+
createValidDomqlObjectFromSugar,
|
|
37
38
|
isVariant
|
|
38
39
|
} from './utils/component'
|
|
39
40
|
|
|
@@ -151,7 +152,9 @@ const createBasedOnType = (element, parent, key, options) => {
|
|
|
151
152
|
const redefineElement = (element, parent, key, options) => {
|
|
152
153
|
const elementWrapper = createBasedOnType(element, parent, key, options)
|
|
153
154
|
|
|
154
|
-
if (
|
|
155
|
+
if (options.syntaxv3 || element.props?.syntaxv3) {
|
|
156
|
+
return createValidDomqlObjectFromSugar(element, parent, key, options)
|
|
157
|
+
} else if (checkIfKeyIsComponent(key)) {
|
|
155
158
|
return applyKeyComponentAsExtend(elementWrapper, parent, key)
|
|
156
159
|
}
|
|
157
160
|
|
package/dist/cjs/create.js
CHANGED
|
@@ -115,8 +115,11 @@ const createBasedOnType = (element, parent, key, options) => {
|
|
|
115
115
|
return element;
|
|
116
116
|
};
|
|
117
117
|
const redefineElement = (element, parent, key, options) => {
|
|
118
|
+
var _a;
|
|
118
119
|
const elementWrapper = createBasedOnType(element, parent, key, options);
|
|
119
|
-
if ((0
|
|
120
|
+
if (options.syntaxv3 || ((_a = element.props) == null ? void 0 : _a.syntaxv3)) {
|
|
121
|
+
return (0, import_component.createValidDomqlObjectFromSugar)(element, parent, key, options);
|
|
122
|
+
} else if ((0, import_component.checkIfKeyIsComponent)(key)) {
|
|
120
123
|
return (0, import_component.applyKeyComponentAsExtend)(elementWrapper, parent, key);
|
|
121
124
|
}
|
|
122
125
|
if (checkIfMedia(key)) {
|
package/dist/cjs/node.js
CHANGED
|
@@ -41,6 +41,7 @@ var import_iterate = require("./iterate");
|
|
|
41
41
|
var import_mixins = require("./mixins");
|
|
42
42
|
var import_applyParam = require("./utils/applyParam");
|
|
43
43
|
var import_utils2 = require("./utils");
|
|
44
|
+
var import_propEvents = require("./utils/propEvents");
|
|
44
45
|
const ENV = "development";
|
|
45
46
|
const createNode = (element, options) => {
|
|
46
47
|
let { node, tag, __ref: ref } = element;
|
|
@@ -63,6 +64,7 @@ const createNode = (element, options) => {
|
|
|
63
64
|
(0, import_iterate.throughInitialDefine)(element);
|
|
64
65
|
(0, import_iterate.throughInitialExec)(element);
|
|
65
66
|
if (element.tag !== "string" && element.tag !== "fragment") {
|
|
67
|
+
(0, import_propEvents.propagateEventsFromProps)(element);
|
|
66
68
|
if (isNewNode && (0, import_utils.isObject)(element.on))
|
|
67
69
|
(0, import_event.applyEventsOnNode)(element, options);
|
|
68
70
|
}
|
package/dist/cjs/update.js
CHANGED
|
@@ -206,13 +206,13 @@ const inheritStateUpdates = (element, options) => {
|
|
|
206
206
|
if (!keyInParentState || options.preventInheritedStateUpdate)
|
|
207
207
|
return;
|
|
208
208
|
if (!options.preventInitStateUpdateListener) {
|
|
209
|
-
const initStateReturns = (0, import_event.triggerEventOnUpdate)("
|
|
209
|
+
const initStateReturns = (0, import_event.triggerEventOnUpdate)("initStateUpdate", keyInParentState, element, options);
|
|
210
210
|
if (initStateReturns === false)
|
|
211
211
|
return element;
|
|
212
212
|
}
|
|
213
213
|
const newState = createStateUpdate(element, parent, options);
|
|
214
214
|
if (!options.preventStateUpdateListener) {
|
|
215
|
-
(0, import_event.triggerEventOnUpdate)("
|
|
215
|
+
(0, import_event.triggerEventOnUpdate)("stateUpdate", newState.parse(), element, options);
|
|
216
216
|
}
|
|
217
217
|
};
|
|
218
218
|
const createStateUpdate = (element, parent, options) => {
|
|
@@ -34,7 +34,19 @@ module.exports = __toCommonJS(component_exports);
|
|
|
34
34
|
var import_utils = require("@domql/utils");
|
|
35
35
|
var import_extend = require("../extend");
|
|
36
36
|
const ENV = "development";
|
|
37
|
-
const DOMQL_BUILTINS = [
|
|
37
|
+
const DOMQL_BUILTINS = [
|
|
38
|
+
"extend",
|
|
39
|
+
"childExtend",
|
|
40
|
+
"childExtendRecursive",
|
|
41
|
+
"define",
|
|
42
|
+
"props",
|
|
43
|
+
"state",
|
|
44
|
+
"on",
|
|
45
|
+
"if",
|
|
46
|
+
"attr",
|
|
47
|
+
"key",
|
|
48
|
+
"tag"
|
|
49
|
+
];
|
|
38
50
|
const checkIfKeyIsComponent = (key) => {
|
|
39
51
|
const isFirstKeyString = (0, import_utils.isString)(key);
|
|
40
52
|
if (!isFirstKeyString)
|
|
@@ -57,7 +69,7 @@ const addAdditionalExtend = (newExtend, element) => {
|
|
|
57
69
|
return { ...element, extend };
|
|
58
70
|
};
|
|
59
71
|
const replaceOnKeys = (key) => key.replace(/on\w+/g, (match) => match.substring(2));
|
|
60
|
-
const createValidDomqlObjectFromSugar = (el) => {
|
|
72
|
+
const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
|
|
61
73
|
const newElem = {
|
|
62
74
|
props: {},
|
|
63
75
|
on: {}
|
|
@@ -72,6 +84,10 @@ const createValidDomqlObjectFromSugar = (el) => {
|
|
|
72
84
|
} else if (!isMethod && checkIfKeyIsProperty(k)) {
|
|
73
85
|
if (!DOMQL_BUILTINS.includes(k))
|
|
74
86
|
newElem.props[k] = prop;
|
|
87
|
+
} else if (checkIfKeyIsComponent(k)) {
|
|
88
|
+
newElem[k] = prop;
|
|
89
|
+
} else {
|
|
90
|
+
newElem[k] = prop;
|
|
75
91
|
}
|
|
76
92
|
}
|
|
77
93
|
return newElem;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 propEvents_exports = {};
|
|
20
|
+
__export(propEvents_exports, {
|
|
21
|
+
propagateEventsFromProps: () => propagateEventsFromProps
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(propEvents_exports);
|
|
24
|
+
var import_utils = require("@domql/utils");
|
|
25
|
+
const propagateEventsFromProps = (element) => {
|
|
26
|
+
const { props, on } = element;
|
|
27
|
+
const eventKeysFromProps = Object.keys(props).filter((key) => key.startsWith("on"));
|
|
28
|
+
eventKeysFromProps.forEach((v) => {
|
|
29
|
+
const eventName = (0, import_utils.lowercaseFirstLetter)(v.split("on")[1]);
|
|
30
|
+
if (on[eventName]) {
|
|
31
|
+
on[eventName] = (...args) => {
|
|
32
|
+
on[eventName](...args);
|
|
33
|
+
props[v](...args);
|
|
34
|
+
};
|
|
35
|
+
} else
|
|
36
|
+
on[eventName] = props[v];
|
|
37
|
+
});
|
|
38
|
+
};
|
package/node.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { registry } from './mixins'
|
|
15
15
|
import { applyParam } from './utils/applyParam'
|
|
16
16
|
import { isVariant } from './utils'
|
|
17
|
+
import { propagateEventsFromProps } from './utils/propEvents'
|
|
17
18
|
// import { defineSetter } from './methods'
|
|
18
19
|
|
|
19
20
|
const ENV = process.env.NODE_ENV
|
|
@@ -51,6 +52,7 @@ export const createNode = (element, options) => {
|
|
|
51
52
|
throughInitialExec(element)
|
|
52
53
|
|
|
53
54
|
if (element.tag !== 'string' && element.tag !== 'fragment') {
|
|
55
|
+
propagateEventsFromProps(element)
|
|
54
56
|
// apply events
|
|
55
57
|
if (isNewNode && isObject(element.on)) applyEventsOnNode(element, options)
|
|
56
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.53",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@domql/state": "latest",
|
|
32
32
|
"@domql/utils": "latest"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "aafcffa2ebe3d9c2fb96bd3adcb05325b62e68ff",
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/core": "^7.12.0"
|
|
37
37
|
}
|
package/update.js
CHANGED
|
@@ -213,8 +213,8 @@ const checkIfOnUpdate = (element, parent, options) => {
|
|
|
213
213
|
* @param {boolean} [options.execStateFunction] - Execute the state functions.
|
|
214
214
|
* @param {boolean} [options.stateFunctionOverwrite] - If true, overwrite (not merge) current state with what function returns.
|
|
215
215
|
* @param {boolean} [options.preventInheritedStateUpdate] - If true, prevent inheriting state updates.
|
|
216
|
-
* @param {boolean} [options.preventInitStateUpdateListener] - If true, prevent the '
|
|
217
|
-
* @param {boolean} [options.preventStateUpdateListener] - If true, prevent the '
|
|
216
|
+
* @param {boolean} [options.preventInitStateUpdateListener] - If true, prevent the 'initStateUpdate' event listener.
|
|
217
|
+
* @param {boolean} [options.preventStateUpdateListener] - If true, prevent the 'stateUpdate' event listener.
|
|
218
218
|
* @returns {boolean} - If returns false, it breaks the update function
|
|
219
219
|
*/
|
|
220
220
|
const inheritStateUpdates = (element, options) => {
|
|
@@ -243,18 +243,18 @@ const inheritStateUpdates = (element, options) => {
|
|
|
243
243
|
const keyInParentState = findInheritedState(element, element.parent)
|
|
244
244
|
if (!keyInParentState || options.preventInheritedStateUpdate) return
|
|
245
245
|
|
|
246
|
-
// Trigger on.
|
|
246
|
+
// Trigger on.initStateUpdate event
|
|
247
247
|
if (!options.preventInitStateUpdateListener) {
|
|
248
|
-
const initStateReturns = triggerEventOnUpdate('
|
|
248
|
+
const initStateReturns = triggerEventOnUpdate('initStateUpdate', keyInParentState, element, options)
|
|
249
249
|
if (initStateReturns === false) return element
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
// Recreate the state again
|
|
253
253
|
const newState = createStateUpdate(element, parent, options)
|
|
254
254
|
|
|
255
|
-
// Trigger on.
|
|
255
|
+
// Trigger on.stateUpdate event
|
|
256
256
|
if (!options.preventStateUpdateListener) {
|
|
257
|
-
triggerEventOnUpdate('
|
|
257
|
+
triggerEventOnUpdate('stateUpdate', newState.parse(), element, options)
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
|
package/utils/component.js
CHANGED
|
@@ -4,7 +4,19 @@ import { exec, isArray, isFunction, isObject, isString, joinArrays, overwriteDee
|
|
|
4
4
|
import { applyExtend } from '../extend'
|
|
5
5
|
const ENV = process.env.NODE_ENV
|
|
6
6
|
|
|
7
|
-
const DOMQL_BUILTINS = [
|
|
7
|
+
const DOMQL_BUILTINS = [
|
|
8
|
+
'extend',
|
|
9
|
+
'childExtend',
|
|
10
|
+
'childExtendRecursive',
|
|
11
|
+
'define',
|
|
12
|
+
'props',
|
|
13
|
+
'state',
|
|
14
|
+
'on',
|
|
15
|
+
'if',
|
|
16
|
+
'attr',
|
|
17
|
+
'key',
|
|
18
|
+
'tag'
|
|
19
|
+
]
|
|
8
20
|
|
|
9
21
|
export const checkIfKeyIsComponent = (key) => {
|
|
10
22
|
const isFirstKeyString = isString(key)
|
|
@@ -12,6 +24,7 @@ export const checkIfKeyIsComponent = (key) => {
|
|
|
12
24
|
const firstCharKey = key.slice(0, 1)
|
|
13
25
|
return /^[A-Z]*$/.test(firstCharKey)
|
|
14
26
|
}
|
|
27
|
+
|
|
15
28
|
export const checkIfKeyIsProperty = (key) => {
|
|
16
29
|
const isFirstKeyString = isString(key)
|
|
17
30
|
if (!isFirstKeyString) return
|
|
@@ -29,7 +42,7 @@ export const addAdditionalExtend = (newExtend, element) => {
|
|
|
29
42
|
|
|
30
43
|
const replaceOnKeys = key => key.replace(/on\w+/g, match => match.substring(2))
|
|
31
44
|
|
|
32
|
-
export const createValidDomqlObjectFromSugar = el => {
|
|
45
|
+
export const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
|
|
33
46
|
const newElem = {
|
|
34
47
|
props: {},
|
|
35
48
|
on: {}
|
|
@@ -43,6 +56,10 @@ export const createValidDomqlObjectFromSugar = el => {
|
|
|
43
56
|
newElem.on[onKey] = prop
|
|
44
57
|
} else if (!isMethod && checkIfKeyIsProperty(k)) {
|
|
45
58
|
if (!DOMQL_BUILTINS.includes(k)) newElem.props[k] = prop
|
|
59
|
+
} else if (checkIfKeyIsComponent(k)) {
|
|
60
|
+
newElem[k] = prop
|
|
61
|
+
} else {
|
|
62
|
+
newElem[k] = prop
|
|
46
63
|
}
|
|
47
64
|
}
|
|
48
65
|
return newElem
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { lowercaseFirstLetter } from '@domql/utils'
|
|
4
|
+
|
|
5
|
+
export const propagateEventsFromProps = (element) => {
|
|
6
|
+
const { props, on } = element
|
|
7
|
+
const eventKeysFromProps = Object.keys(props).filter(key => key.startsWith('on'))
|
|
8
|
+
eventKeysFromProps.forEach(v => {
|
|
9
|
+
const eventName = lowercaseFirstLetter(v.split('on')[1])
|
|
10
|
+
if (on[eventName]) {
|
|
11
|
+
on[eventName] = (...args) => {
|
|
12
|
+
on[eventName](...args)
|
|
13
|
+
props[v](...args)
|
|
14
|
+
}
|
|
15
|
+
} else on[eventName] = props[v]
|
|
16
|
+
})
|
|
17
|
+
}
|