@domql/element 2.31.37 → 2.32.1
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/iterate.js +25 -7
- package/dist/cjs/mixins/attr.js +12 -3
- package/dist/cjs/mixins/classList.js +8 -8
- package/dist/cjs/mixins/content.js +6 -4
- package/dist/cjs/mixins/html.js +2 -2
- package/dist/cjs/mixins/state.js +2 -2
- package/dist/cjs/mixins/text.js +2 -2
- package/dist/cjs/node.js +2 -3
- package/dist/cjs/props/create.js +7 -4
- package/dist/cjs/props/update.js +4 -3
- package/dist/cjs/set.js +36 -9
- package/dist/cjs/update.js +11 -9
- package/dist/cjs/utils/applyParam.js +7 -1
- package/dist/esm/iterate.js +25 -7
- package/dist/esm/mixins/attr.js +12 -3
- package/dist/esm/mixins/classList.js +8 -8
- package/dist/esm/mixins/content.js +6 -4
- package/dist/esm/mixins/html.js +2 -2
- package/dist/esm/mixins/state.js +2 -2
- package/dist/esm/mixins/text.js +3 -6
- package/dist/esm/node.js +2 -3
- package/dist/esm/props/create.js +7 -4
- package/dist/esm/props/update.js +4 -3
- package/dist/esm/set.js +36 -9
- package/dist/esm/update.js +11 -9
- package/dist/esm/utils/applyParam.js +7 -1
- package/iterate.js +25 -7
- package/mixins/attr.js +12 -3
- package/mixins/classList.js +14 -9
- package/mixins/content.js +7 -8
- package/mixins/html.js +4 -2
- package/mixins/state.js +2 -2
- package/mixins/text.js +3 -6
- package/node.js +3 -3
- package/package.json +6 -6
- package/props/create.js +14 -9
- package/props/update.js +4 -3
- package/set.js +44 -29
- package/update.js +14 -9
- package/utils/applyParam.js +7 -1
package/dist/esm/props/create.js
CHANGED
|
@@ -22,7 +22,7 @@ const syncProps = async (props, element, opts) => {
|
|
|
22
22
|
if (IGNORE_PROPS_PARAMS.includes(v)) return;
|
|
23
23
|
let execProps;
|
|
24
24
|
try {
|
|
25
|
-
execProps = exec(v, element);
|
|
25
|
+
execProps = exec(v, element, element.state, element.context, opts);
|
|
26
26
|
} catch (e) {
|
|
27
27
|
element.error(e, opts);
|
|
28
28
|
}
|
|
@@ -33,7 +33,10 @@ const syncProps = async (props, element, opts) => {
|
|
|
33
33
|
);
|
|
34
34
|
});
|
|
35
35
|
element.props = mergedProps;
|
|
36
|
-
const methods = {
|
|
36
|
+
const methods = {
|
|
37
|
+
update: await update.bind(element.props),
|
|
38
|
+
__element: element
|
|
39
|
+
};
|
|
37
40
|
Object.setPrototypeOf(element.props, methods);
|
|
38
41
|
return element.props;
|
|
39
42
|
};
|
|
@@ -43,7 +46,7 @@ const createProps = function(element, parent, options) {
|
|
|
43
46
|
const propsStack = options.cachedProps || createPropsStack(element, parent);
|
|
44
47
|
if (propsStack.length) {
|
|
45
48
|
ref.__props = propsStack;
|
|
46
|
-
syncProps(propsStack, element);
|
|
49
|
+
syncProps(propsStack, element, options);
|
|
47
50
|
} else {
|
|
48
51
|
ref.__props = options.cachedProps || [];
|
|
49
52
|
element.props = {};
|
|
@@ -56,7 +59,7 @@ const createProps = function(element, parent, options) {
|
|
|
56
59
|
} catch (e) {
|
|
57
60
|
element.props = {};
|
|
58
61
|
ref.__props = options.cachedProps || [];
|
|
59
|
-
element.error("Error applying props", e);
|
|
62
|
+
element.error("Error applying props", e, options);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
const methods = { update: update.bind(element.props), __element: element };
|
package/dist/esm/props/update.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { syncProps } from "./create.js";
|
|
2
2
|
import { inheritParentProps } from "./inherit.js";
|
|
3
|
-
const updateProps = (newProps, element, parent) => {
|
|
3
|
+
const updateProps = (newProps, element, parent, opts) => {
|
|
4
4
|
const { __ref } = element;
|
|
5
5
|
let propsStack = __ref.__props;
|
|
6
6
|
const parentProps = inheritParentProps(element, parent);
|
|
7
|
-
if (parentProps.length)
|
|
7
|
+
if (parentProps.length)
|
|
8
|
+
propsStack = __ref.__props = [].concat(parentProps, propsStack);
|
|
8
9
|
if (newProps) propsStack = __ref.__props = [].concat(newProps, propsStack);
|
|
9
|
-
if (propsStack) syncProps(propsStack, element);
|
|
10
|
+
if (propsStack) syncProps(propsStack, element, opts);
|
|
10
11
|
return element;
|
|
11
12
|
};
|
|
12
13
|
export {
|
package/dist/esm/set.js
CHANGED
|
@@ -7,12 +7,20 @@ import { triggerEventOn, triggerEventOnUpdate } from "@domql/event";
|
|
|
7
7
|
const resetElement = async (params, element, options) => {
|
|
8
8
|
if (!options.preventRemove) removeContent(element, options);
|
|
9
9
|
const { __ref: ref } = element;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const contentElementKey = setContentKey(element, options);
|
|
11
|
+
const { __cached } = ref;
|
|
12
|
+
const newContent = await create(
|
|
13
|
+
params,
|
|
14
|
+
element,
|
|
15
|
+
ref.contentElementKey || "content",
|
|
16
|
+
{
|
|
17
|
+
ignoreChildExtend: true,
|
|
18
|
+
...registry.defaultOptions,
|
|
19
|
+
...OPTIONS.create,
|
|
20
|
+
...options
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
__cached[contentElementKey] = newContent;
|
|
16
24
|
};
|
|
17
25
|
const reset = async (options) => {
|
|
18
26
|
const element = void 0;
|
|
@@ -24,16 +32,35 @@ const reset = async (options) => {
|
|
|
24
32
|
});
|
|
25
33
|
};
|
|
26
34
|
const set = async function(params, options = {}, el) {
|
|
27
|
-
var _a, _b, _c;
|
|
35
|
+
var _a, _b, _c, _d;
|
|
28
36
|
const element = el || this;
|
|
37
|
+
const { __ref: ref } = element;
|
|
29
38
|
if (options.preventContentUpdate || options.preventUpdate && ((_b = (_a = options.preventUpdate).includes) == null ? void 0 : _b.call(_a, "content")))
|
|
30
39
|
return;
|
|
31
40
|
if (options.routerContentElement && options.lastElement) {
|
|
32
41
|
if (options.routerContentElement !== options.lastElement.content) return;
|
|
33
42
|
}
|
|
43
|
+
const contentKey = setContentKey(element, options);
|
|
44
|
+
const content = element[contentKey];
|
|
45
|
+
const __contentRef = content && content.__ref;
|
|
34
46
|
const lazyLoad = element.props && element.props.lazyLoad;
|
|
35
|
-
const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection;
|
|
47
|
+
const hasCollection = element.$collection || element.$stateCollection || element.$propsCollection || ((_c = element.props) == null ? void 0 : _c.children);
|
|
36
48
|
if (options.preventContentUpdate === true && !hasCollection) return;
|
|
49
|
+
if (!options.forceReset && (ref.__noCollectionDifference || __contentRef && __contentRef.__cached && deepContains(params, content))) {
|
|
50
|
+
if (!options.preventBeforeUpdateListener && !options.preventListeners) {
|
|
51
|
+
const beforeUpdateReturns = await triggerEventOnUpdate(
|
|
52
|
+
"beforeUpdate",
|
|
53
|
+
params,
|
|
54
|
+
element,
|
|
55
|
+
options
|
|
56
|
+
);
|
|
57
|
+
if (beforeUpdateReturns === false) return element;
|
|
58
|
+
}
|
|
59
|
+
if (content == null ? void 0 : content.update) await content.update({}, options);
|
|
60
|
+
if (!options.preventUpdateListener)
|
|
61
|
+
await triggerEventOn("update", element, options);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
37
64
|
if (params) {
|
|
38
65
|
let { childExtend, props } = params;
|
|
39
66
|
if (!props) props = params.props = {};
|
|
@@ -41,7 +68,7 @@ const set = async function(params, options = {}, el) {
|
|
|
41
68
|
params.childExtend = element.childExtend;
|
|
42
69
|
props.ignoreChildExtend = true;
|
|
43
70
|
}
|
|
44
|
-
if (!(props == null ? void 0 : props.childProps) && ((
|
|
71
|
+
if (!(props == null ? void 0 : props.childProps) && ((_d = element.props) == null ? void 0 : _d.childProps)) {
|
|
45
72
|
props.childProps = element.props.childProps;
|
|
46
73
|
props.ignoreChildProps = true;
|
|
47
74
|
}
|
package/dist/esm/update.js
CHANGED
|
@@ -54,27 +54,27 @@ const update = async function(params = {}, opts) {
|
|
|
54
54
|
element,
|
|
55
55
|
options
|
|
56
56
|
);
|
|
57
|
-
if (snapshotHasUpdated) return;
|
|
58
|
-
if (checkIfStorm(element, options)) return;
|
|
57
|
+
if (snapshotHasUpdated) return false;
|
|
58
|
+
if (checkIfStorm(element, options)) return false;
|
|
59
59
|
if (!options.preventListeners)
|
|
60
60
|
await triggerEventOn("eventStart", element, options);
|
|
61
61
|
if (!options.preventListeners)
|
|
62
62
|
await triggerEventOnUpdate("startUpdate", params, element, options);
|
|
63
63
|
if (preventInheritAtCurrentState && preventInheritAtCurrentState.__element === element)
|
|
64
|
-
return;
|
|
64
|
+
return false;
|
|
65
65
|
if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS);
|
|
66
66
|
if (isString(params) || isNumber(params)) {
|
|
67
67
|
params = { text: params };
|
|
68
68
|
}
|
|
69
69
|
const inheritState = await inheritStateUpdates(element, options);
|
|
70
|
-
if (inheritState === false) return;
|
|
70
|
+
if (inheritState === false) return false;
|
|
71
71
|
const ifFails = checkIfOnUpdate(element, parent, options);
|
|
72
|
-
if (ifFails) return;
|
|
72
|
+
if (ifFails) return false;
|
|
73
73
|
if (ref.__if && !options.preventPropsUpdate) {
|
|
74
74
|
const hasParentProps = parent.props && (parent.props[key] || parent.props.childProps);
|
|
75
75
|
const hasFunctionInProps = ref.__props.filter((v) => isFunction(v));
|
|
76
76
|
const props = params.props || hasParentProps || hasFunctionInProps.length;
|
|
77
|
-
if (props) updateProps(props, element, parent);
|
|
77
|
+
if (props) updateProps(props, element, parent, options);
|
|
78
78
|
}
|
|
79
79
|
if (!options.preventBeforeUpdateListener && !options.preventListeners) {
|
|
80
80
|
const beforeUpdateReturns = await triggerEventOnUpdate(
|
|
@@ -86,15 +86,17 @@ const update = async function(params = {}, opts) {
|
|
|
86
86
|
if (beforeUpdateReturns === false) return element;
|
|
87
87
|
}
|
|
88
88
|
overwriteDeep(element, params, { exclude: METHODS_EXL });
|
|
89
|
-
throughExecProps(element);
|
|
89
|
+
throughExecProps(element, options);
|
|
90
90
|
await throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS });
|
|
91
|
-
await throughUpdatedDefine(element);
|
|
91
|
+
await throughUpdatedDefine(element, options);
|
|
92
92
|
if (!options.isForced && !options.preventListeners) {
|
|
93
93
|
await triggerEventOn("beforeClassAssign", element, options);
|
|
94
94
|
}
|
|
95
95
|
if (!ref.__if) return false;
|
|
96
96
|
if (!node) {
|
|
97
|
-
return;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (element.tag !== "fragment" && !document.body.contains(node)) {
|
|
98
100
|
}
|
|
99
101
|
const {
|
|
100
102
|
preventUpdate,
|
|
@@ -2,7 +2,13 @@ import { exec, isFunction } from "@domql/utils";
|
|
|
2
2
|
import { REGISTRY } from "../mixins/index.js";
|
|
3
3
|
const applyParam = async (param, element, options) => {
|
|
4
4
|
const { node, context, __ref: ref } = element;
|
|
5
|
-
const prop = await exec(
|
|
5
|
+
const prop = await exec(
|
|
6
|
+
element[param],
|
|
7
|
+
element,
|
|
8
|
+
element.state,
|
|
9
|
+
element.context,
|
|
10
|
+
options
|
|
11
|
+
);
|
|
6
12
|
const { onlyUpdate } = options;
|
|
7
13
|
const DOMQLProperty = REGISTRY[param];
|
|
8
14
|
const DOMQLPropertyFromContext = context && context.registry && context.registry[param];
|
package/iterate.js
CHANGED
|
@@ -65,7 +65,7 @@ export const throughUpdatedExec = async (
|
|
|
65
65
|
return changes
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export const throughExecProps = (element) => {
|
|
68
|
+
export const throughExecProps = (element, opts) => {
|
|
69
69
|
const { __ref: ref } = element
|
|
70
70
|
const { props } = element
|
|
71
71
|
for (const k in props) {
|
|
@@ -75,15 +75,21 @@ export const throughExecProps = (element) => {
|
|
|
75
75
|
return warn.call(element, 'Element was not initiated to execute props')
|
|
76
76
|
const cachedExecProp = ref.__execProps[k]
|
|
77
77
|
if (isFunction(cachedExecProp)) {
|
|
78
|
-
props[k] = exec(
|
|
78
|
+
props[k] = exec(
|
|
79
|
+
cachedExecProp,
|
|
80
|
+
element,
|
|
81
|
+
element.state,
|
|
82
|
+
element.context,
|
|
83
|
+
opts
|
|
84
|
+
)
|
|
79
85
|
} else if (isDefine && isFunction(props[k])) {
|
|
80
86
|
ref.__execProps[k] = props[k]
|
|
81
|
-
props[k] = exec(props[k], element)
|
|
87
|
+
props[k] = exec(props[k], element, element.state, element.context, opts)
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
export const throughInitialDefine = async (element) => {
|
|
92
|
+
export const throughInitialDefine = async (element, opts) => {
|
|
87
93
|
const { define, context, __ref: ref } = element
|
|
88
94
|
|
|
89
95
|
let defineObj = {}
|
|
@@ -100,7 +106,13 @@ export const throughInitialDefine = async (element) => {
|
|
|
100
106
|
!isVariant(param)
|
|
101
107
|
) {
|
|
102
108
|
ref.__exec[param] = elementProp
|
|
103
|
-
const execParam = (elementProp = await exec(
|
|
109
|
+
const execParam = (elementProp = await exec(
|
|
110
|
+
elementProp,
|
|
111
|
+
element,
|
|
112
|
+
element.state,
|
|
113
|
+
element.context,
|
|
114
|
+
opts
|
|
115
|
+
))
|
|
104
116
|
|
|
105
117
|
if (execParam) {
|
|
106
118
|
elementProp = element[param] = execParam.parse
|
|
@@ -121,7 +133,7 @@ export const throughInitialDefine = async (element) => {
|
|
|
121
133
|
return element
|
|
122
134
|
}
|
|
123
135
|
|
|
124
|
-
export const throughUpdatedDefine = async (element) => {
|
|
136
|
+
export const throughUpdatedDefine = async (element, opts) => {
|
|
125
137
|
const { context, define, __ref: ref } = element
|
|
126
138
|
const changes = {}
|
|
127
139
|
|
|
@@ -137,7 +149,13 @@ export const throughUpdatedDefine = async (element) => {
|
|
|
137
149
|
element.state,
|
|
138
150
|
element.context
|
|
139
151
|
)
|
|
140
|
-
const cached = await exec(
|
|
152
|
+
const cached = await exec(
|
|
153
|
+
ref.__defineCache[param],
|
|
154
|
+
element,
|
|
155
|
+
element.state,
|
|
156
|
+
element.context,
|
|
157
|
+
opts
|
|
158
|
+
)
|
|
141
159
|
const newExecParam = await obj[param](
|
|
142
160
|
cached,
|
|
143
161
|
element,
|
package/mixins/attr.js
CHANGED
|
@@ -7,14 +7,20 @@ import { deepMerge } from '../utils/index.js'
|
|
|
7
7
|
/**
|
|
8
8
|
* Recursively add attributes to a DOM node
|
|
9
9
|
*/
|
|
10
|
-
export function attr(params, element, node) {
|
|
10
|
+
export function attr(params, element, node, opts) {
|
|
11
11
|
const { __ref: ref, props } = element
|
|
12
12
|
const { __attr } = ref
|
|
13
13
|
if (isNot('object')) report('HTMLInvalidAttr', params)
|
|
14
14
|
if (params) {
|
|
15
15
|
if (props.attr) deepMerge(params, props.attr)
|
|
16
16
|
for (const attr in params) {
|
|
17
|
-
const val = exec(
|
|
17
|
+
const val = exec(
|
|
18
|
+
params[attr],
|
|
19
|
+
element,
|
|
20
|
+
element.state,
|
|
21
|
+
element.context,
|
|
22
|
+
opts
|
|
23
|
+
)
|
|
18
24
|
// if (__attr[attr] === val) return
|
|
19
25
|
if (
|
|
20
26
|
val !== false &&
|
|
@@ -22,7 +28,10 @@ export function attr(params, element, node) {
|
|
|
22
28
|
!isNull(val) &&
|
|
23
29
|
node.setAttribute
|
|
24
30
|
)
|
|
25
|
-
node.setAttribute(
|
|
31
|
+
node.setAttribute(
|
|
32
|
+
attr,
|
|
33
|
+
exec(val, element, element.state, element.context, opts)
|
|
34
|
+
)
|
|
26
35
|
else if (node.removeAttribute) node.removeAttribute(attr)
|
|
27
36
|
__attr[attr] = val
|
|
28
37
|
}
|
package/mixins/classList.js
CHANGED
|
@@ -5,31 +5,36 @@ import { exec, isObject, isString } from '@domql/utils'
|
|
|
5
5
|
export const assignKeyAsClassname = (element) => {
|
|
6
6
|
const { key } = element
|
|
7
7
|
if (element.class === true) element.class = key
|
|
8
|
-
else if (
|
|
8
|
+
else if (
|
|
9
|
+
!element.class &&
|
|
10
|
+
typeof key === 'string' &&
|
|
11
|
+
key.charAt(0) === '_' &&
|
|
12
|
+
key.charAt(1) !== '_'
|
|
13
|
+
) {
|
|
9
14
|
element.class = key.slice(1)
|
|
10
15
|
}
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
// stringifies class object
|
|
14
|
-
export const classify = (obj, element) => {
|
|
19
|
+
export const classify = (obj, element, opts) => {
|
|
15
20
|
let className = ''
|
|
16
21
|
for (const item in obj) {
|
|
17
22
|
const param = obj[item]
|
|
18
23
|
if (typeof param === 'boolean' && param) className += ` ${item}`
|
|
19
24
|
else if (typeof param === 'string') className += ` ${param}`
|
|
20
25
|
else if (typeof param === 'function') {
|
|
21
|
-
className += ` ${exec(param, element)}`
|
|
26
|
+
className += ` ${exec(param, element, element.state, element.context, opts)}`
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
return className
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
export const classList = (params, element) => {
|
|
32
|
+
export const classList = (params, element, opts) => {
|
|
28
33
|
if (!params) return
|
|
29
34
|
const { key } = element
|
|
30
35
|
if (params === true) params = element.class = { key }
|
|
31
36
|
if (isString(params)) params = element.class = { default: params }
|
|
32
|
-
if (isObject(params)) params = classify(params, element)
|
|
37
|
+
if (isObject(params)) params = classify(params, element, opts)
|
|
33
38
|
// TODO: fails on string
|
|
34
39
|
const className = params.replace(/\s+/g, ' ').trim()
|
|
35
40
|
if (element.ref) element.ref.class = className // TODO: this check is NOT needed in new DOMQL
|
|
@@ -37,14 +42,14 @@ export const classList = (params, element) => {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
// LEGACY (still needed in old domql)
|
|
40
|
-
export const applyClassListOnNode = (params, element, node) => {
|
|
41
|
-
const className = classList(params, element)
|
|
45
|
+
export const applyClassListOnNode = (params, element, node, opts) => {
|
|
46
|
+
const className = classList(params, element, opts)
|
|
42
47
|
node.classList = className
|
|
43
48
|
return className
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
export function applyClasslist
|
|
47
|
-
applyClassListOnNode(params, element, node)
|
|
51
|
+
export function applyClasslist(params, element, node, opts) {
|
|
52
|
+
applyClassListOnNode(params, element, node, opts)
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export default applyClasslist
|
package/mixins/content.js
CHANGED
|
@@ -24,7 +24,7 @@ export const removeContent = function (el, opts = {}) {
|
|
|
24
24
|
if (element[contentElementKey]) {
|
|
25
25
|
if (element[contentElementKey].node && element.node) {
|
|
26
26
|
if (element[contentElementKey].tag === 'fragment')
|
|
27
|
-
element.node.innerHTML = ''
|
|
27
|
+
element.node.innerHTML = '' // TODO: deep check to only remove `content` children and not other children
|
|
28
28
|
else {
|
|
29
29
|
const contentNode = element[contentElementKey].node
|
|
30
30
|
if (contentNode.parentNode === element.node)
|
|
@@ -34,13 +34,12 @@ export const removeContent = function (el, opts = {}) {
|
|
|
34
34
|
|
|
35
35
|
const { __cached } = ref
|
|
36
36
|
if (__cached && __cached[contentElementKey]) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
__cached[contentElementKey].remove()
|
|
37
|
+
const cachedContent = __cached[contentElementKey]
|
|
38
|
+
if (cachedContent.tag === 'fragment')
|
|
39
|
+
cachedContent.parent.node.innerHTML = ''
|
|
40
|
+
else if (cachedContent && isFunction(cachedContent.remove))
|
|
41
|
+
cachedContent.remove()
|
|
42
|
+
delete __cached[contentElementKey]
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
ref.__children.splice(ref.__children.indexOf(contentElementKey), 1)
|
package/mixins/html.js
CHANGED
|
@@ -6,8 +6,10 @@ import { exec } from '@domql/utils'
|
|
|
6
6
|
* Appends raw HTML as content
|
|
7
7
|
* an original one as a child
|
|
8
8
|
*/
|
|
9
|
-
export function html
|
|
10
|
-
const prop =
|
|
9
|
+
export function html(param, element, node, opts) {
|
|
10
|
+
const prop =
|
|
11
|
+
exec(param, element, element.state, element.context, opts) ||
|
|
12
|
+
exec(element?.props?.html, element, element.state, element.context, opts)
|
|
11
13
|
const { __ref } = element
|
|
12
14
|
if (prop !== __ref.__html) {
|
|
13
15
|
// const parser = new window.DOMParser()
|
package/mixins/state.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { IGNORE_STATE_PARAMS } from '@domql/state'
|
|
4
4
|
import { exec, isObject } from '@domql/utils'
|
|
5
5
|
|
|
6
|
-
export async function state
|
|
7
|
-
const state = exec(params, element)
|
|
6
|
+
export async function state(params, element, node, opts) {
|
|
7
|
+
const state = exec(params, element, element.state, element.context, opts)
|
|
8
8
|
|
|
9
9
|
if (isObject(state)) {
|
|
10
10
|
for (const param in state) {
|
package/mixins/text.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { create } from '../create.js'
|
|
4
|
-
import {
|
|
5
|
-
exec,
|
|
6
|
-
isString
|
|
7
|
-
} from '@domql/utils'
|
|
4
|
+
import { exec, isString } from '@domql/utils'
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Creates a text node and appends into
|
|
11
8
|
* an original one as a child
|
|
12
9
|
*/
|
|
13
|
-
export function text
|
|
14
|
-
let prop = exec(param, element)
|
|
10
|
+
export function text(param, element, node, opts) {
|
|
11
|
+
let prop = exec(param, element, element.state, element.context, opts)
|
|
15
12
|
if (isString(prop) && prop.includes('{{')) {
|
|
16
13
|
prop = element.call('replaceLiteralsWithObjectFields', prop)
|
|
17
14
|
}
|
package/node.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import { REGISTRY } from './mixins/index.js'
|
|
21
21
|
import { applyParam } from './utils/applyParam.js'
|
|
22
22
|
import { propagateEventsFromProps } from './utils/propEvents.js'
|
|
23
|
-
import { isNotProduction } from '@domql/utils/env.js'
|
|
23
|
+
// import { isNotProduction } from '@domql/utils/env.js'
|
|
24
24
|
// import { defineSetter } from './methods'
|
|
25
25
|
|
|
26
26
|
export const createNode = async (element, options) => {
|
|
@@ -54,10 +54,10 @@ export const createNode = async (element, options) => {
|
|
|
54
54
|
// }
|
|
55
55
|
|
|
56
56
|
// iterate through exec props
|
|
57
|
-
throughExecProps(element)
|
|
57
|
+
throughExecProps(element, options)
|
|
58
58
|
|
|
59
59
|
// iterate through define
|
|
60
|
-
await throughInitialDefine(element)
|
|
60
|
+
await throughInitialDefine(element, options)
|
|
61
61
|
|
|
62
62
|
// iterate through exec
|
|
63
63
|
await throughInitialExec(element)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@domql/event": "^2.
|
|
31
|
-
"@domql/render": "^2.
|
|
32
|
-
"@domql/state": "^2.
|
|
33
|
-
"@domql/utils": "^2.
|
|
30
|
+
"@domql/event": "^2.32.1",
|
|
31
|
+
"@domql/render": "^2.32.1",
|
|
32
|
+
"@domql/state": "^2.32.1",
|
|
33
|
+
"@domql/utils": "^2.32.1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "dacd7cc0abd5d46a1be9c04dc99d6f266521970f",
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/core": "^7.27.1"
|
|
38
38
|
}
|
package/props/create.js
CHANGED
|
@@ -7,14 +7,14 @@ import { inheritParentProps } from './inherit.js'
|
|
|
7
7
|
|
|
8
8
|
const createPropsStack = (element, parent) => {
|
|
9
9
|
const { props, __ref: ref } = element
|
|
10
|
-
const propsStack = ref.__props = inheritParentProps(element, parent)
|
|
10
|
+
const propsStack = (ref.__props = inheritParentProps(element, parent))
|
|
11
11
|
|
|
12
12
|
if (isObject(props)) propsStack.push(props)
|
|
13
13
|
else if (props === 'inherit' && parent.props) propsStack.push(parent.props)
|
|
14
14
|
else if (props) propsStack.push(props)
|
|
15
15
|
|
|
16
16
|
if (isArray(ref.__extend)) {
|
|
17
|
-
ref.__extend.forEach(extend => {
|
|
17
|
+
ref.__extend.forEach((extend) => {
|
|
18
18
|
if (extend.props && extend.props !== props) propsStack.push(extend.props)
|
|
19
19
|
})
|
|
20
20
|
}
|
|
@@ -28,12 +28,14 @@ export const syncProps = async (props, element, opts) => {
|
|
|
28
28
|
element.props = {}
|
|
29
29
|
const mergedProps = {}
|
|
30
30
|
|
|
31
|
-
props.forEach(v => {
|
|
31
|
+
props.forEach((v) => {
|
|
32
32
|
if (IGNORE_PROPS_PARAMS.includes(v)) return
|
|
33
33
|
let execProps
|
|
34
34
|
try {
|
|
35
|
-
execProps = exec(v, element)
|
|
36
|
-
} catch (e) {
|
|
35
|
+
execProps = exec(v, element, element.state, element.context, opts)
|
|
36
|
+
} catch (e) {
|
|
37
|
+
element.error(e, opts)
|
|
38
|
+
}
|
|
37
39
|
// TODO: check if this failing the function props merge
|
|
38
40
|
// if (isObject(execProps) && execProps.__element) return
|
|
39
41
|
// it was causing infinite loop at early days
|
|
@@ -45,7 +47,10 @@ export const syncProps = async (props, element, opts) => {
|
|
|
45
47
|
})
|
|
46
48
|
element.props = mergedProps
|
|
47
49
|
|
|
48
|
-
const methods = {
|
|
50
|
+
const methods = {
|
|
51
|
+
update: await update.bind(element.props),
|
|
52
|
+
__element: element
|
|
53
|
+
}
|
|
49
54
|
Object.setPrototypeOf(element.props, methods)
|
|
50
55
|
|
|
51
56
|
return element.props
|
|
@@ -58,7 +63,7 @@ export const createProps = function (element, parent, options) {
|
|
|
58
63
|
const propsStack = options.cachedProps || createPropsStack(element, parent)
|
|
59
64
|
if (propsStack.length) {
|
|
60
65
|
ref.__props = propsStack
|
|
61
|
-
syncProps(propsStack, element)
|
|
66
|
+
syncProps(propsStack, element, options)
|
|
62
67
|
} else {
|
|
63
68
|
ref.__props = options.cachedProps || []
|
|
64
69
|
element.props = {}
|
|
@@ -72,7 +77,7 @@ export const createProps = function (element, parent, options) {
|
|
|
72
77
|
} catch (e) {
|
|
73
78
|
element.props = {}
|
|
74
79
|
ref.__props = options.cachedProps || []
|
|
75
|
-
element.error('Error applying props', e)
|
|
80
|
+
element.error('Error applying props', e, options)
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -82,7 +87,7 @@ export const createProps = function (element, parent, options) {
|
|
|
82
87
|
return element
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
async function update
|
|
90
|
+
async function update(props, options) {
|
|
86
91
|
const element = this.__element
|
|
87
92
|
await element.update({ props }, options)
|
|
88
93
|
}
|
package/props/update.js
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
import { syncProps } from './create.js'
|
|
4
4
|
import { inheritParentProps } from './inherit.js'
|
|
5
5
|
|
|
6
|
-
export const updateProps = (newProps, element, parent) => {
|
|
6
|
+
export const updateProps = (newProps, element, parent, opts) => {
|
|
7
7
|
const { __ref } = element
|
|
8
8
|
let propsStack = __ref.__props
|
|
9
9
|
|
|
10
10
|
const parentProps = inheritParentProps(element, parent)
|
|
11
|
-
if (parentProps.length)
|
|
11
|
+
if (parentProps.length)
|
|
12
|
+
propsStack = __ref.__props = [].concat(parentProps, propsStack)
|
|
12
13
|
if (newProps) propsStack = __ref.__props = [].concat(newProps, propsStack)
|
|
13
14
|
|
|
14
|
-
if (propsStack) syncProps(propsStack, element)
|
|
15
|
+
if (propsStack) syncProps(propsStack, element, opts)
|
|
15
16
|
|
|
16
17
|
return element
|
|
17
18
|
}
|