@domql/element 2.5.17 → 2.5.19
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 +17 -3
- package/dist/cjs/create.js +12 -1
- package/dist/cjs/extend.js +5 -6
- package/dist/cjs/mixins/index.js +2 -0
- package/dist/cjs/mixins/registry.js +1 -0
- package/dist/cjs/mixins/scope.js +36 -0
- package/dist/cjs/mixins/text.js +0 -17
- package/dist/cjs/node.js +17 -17
- package/dist/cjs/props/create.js +22 -11
- package/dist/cjs/props/update.js +1 -1
- package/dist/cjs/set.js +14 -5
- package/dist/cjs/update.js +12 -17
- package/dist/cjs/utils/component.js +5 -1
- package/dist/cjs/utils/extendUtils.js +12 -25
- package/extend.js +7 -8
- package/mixins/index.js +2 -0
- package/mixins/registry.js +2 -1
- package/mixins/scope.js +21 -0
- package/mixins/text.js +0 -13
- package/node.js +25 -26
- package/package.json +2 -2
- package/props/create.js +27 -10
- package/props/update.js +1 -1
- package/set.js +13 -4
- package/update.js +34 -18
- package/utils/component.js +5 -1
- package/utils/extendUtils.js +24 -24
package/create.js
CHANGED
|
@@ -45,6 +45,8 @@ const ENV = process.env.NODE_ENV
|
|
|
45
45
|
const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
46
46
|
cacheOptions(element, options)
|
|
47
47
|
|
|
48
|
+
// if (key === 'Title') debugger
|
|
49
|
+
|
|
48
50
|
// if element is STRING
|
|
49
51
|
if (checkIfPrimitive(element)) {
|
|
50
52
|
element = applyValueAsText(element, parent, key)
|
|
@@ -83,8 +85,18 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
83
85
|
|
|
84
86
|
addMethods(element, parent)
|
|
85
87
|
|
|
88
|
+
createScope(element, parent)
|
|
89
|
+
|
|
86
90
|
createState(element, parent)
|
|
91
|
+
if (element.scope === 'state') element.scope = element.state
|
|
92
|
+
|
|
93
|
+
createIfConditionFlag(element, parent)
|
|
94
|
+
|
|
95
|
+
// apply props settings
|
|
96
|
+
createProps(element, parent)
|
|
97
|
+
if (element.scope === 'props' || element.scope === true) element.scope = element.props
|
|
87
98
|
|
|
99
|
+
// recatch if it passess props again
|
|
88
100
|
createIfConditionFlag(element, parent)
|
|
89
101
|
|
|
90
102
|
// if it already HAS a NODE
|
|
@@ -92,9 +104,6 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
92
104
|
return assignNode(element, parent, key)
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
// apply props settings
|
|
96
|
-
createProps(element, parent)
|
|
97
|
-
|
|
98
107
|
// apply variants
|
|
99
108
|
applyVariant(element, parent)
|
|
100
109
|
|
|
@@ -235,6 +244,11 @@ const applyContext = (element, parent, options) => {
|
|
|
235
244
|
if (!element.context) element.context = parent.context || options.context || ROOT.context
|
|
236
245
|
}
|
|
237
246
|
|
|
247
|
+
const createScope = (element, parent) => {
|
|
248
|
+
const { __ref: ref } = element
|
|
249
|
+
if (!element.scope) element.scope = parent.scope || ref.__root.scope || {}
|
|
250
|
+
}
|
|
251
|
+
|
|
238
252
|
const createIfConditionFlag = (element, parent) => {
|
|
239
253
|
const { __ref: ref } = element
|
|
240
254
|
|
package/dist/cjs/create.js
CHANGED
|
@@ -70,12 +70,18 @@ const create = (element, parent, key, options = import_options.default.create ||
|
|
|
70
70
|
replaceOptions(element, parent, options);
|
|
71
71
|
addCaching(element, parent);
|
|
72
72
|
(0, import_set.addMethods)(element, parent);
|
|
73
|
+
createScope(element, parent);
|
|
73
74
|
(0, import_state.createState)(element, parent);
|
|
75
|
+
if (element.scope === "state")
|
|
76
|
+
element.scope = element.state;
|
|
77
|
+
createIfConditionFlag(element, parent);
|
|
78
|
+
(0, import_props.createProps)(element, parent);
|
|
79
|
+
if (element.scope === "props" || element.scope === true)
|
|
80
|
+
element.scope = element.props;
|
|
74
81
|
createIfConditionFlag(element, parent);
|
|
75
82
|
if (element.node && ref.__if) {
|
|
76
83
|
return (0, import_render.assignNode)(element, parent, key);
|
|
77
84
|
}
|
|
78
|
-
(0, import_props.createProps)(element, parent);
|
|
79
85
|
(0, import_component.applyVariant)(element, parent);
|
|
80
86
|
const onInit = (0, import_event.triggerEventOn)("init", element, options);
|
|
81
87
|
if (onInit === false)
|
|
@@ -182,6 +188,11 @@ const applyContext = (element, parent, options) => {
|
|
|
182
188
|
if (!element.context)
|
|
183
189
|
element.context = parent.context || options.context || import_tree.ROOT.context;
|
|
184
190
|
};
|
|
191
|
+
const createScope = (element, parent) => {
|
|
192
|
+
const { __ref: ref } = element;
|
|
193
|
+
if (!element.scope)
|
|
194
|
+
element.scope = parent.scope || ref.__root.scope || {};
|
|
195
|
+
};
|
|
185
196
|
const createIfConditionFlag = (element, parent) => {
|
|
186
197
|
const { __ref: ref } = element;
|
|
187
198
|
if ((0, import_utils.isFunction)(element.if)) {
|
package/dist/cjs/extend.js
CHANGED
|
@@ -29,19 +29,19 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
29
29
|
element = (0, import_utils.exec)(element, parent);
|
|
30
30
|
let { extend, props, context, __ref } = element;
|
|
31
31
|
extend = (0, import_utils2.fallbackStringExtend)(extend, context, options);
|
|
32
|
-
const extendStack = (0, import_utils2.getExtendStack)(extend);
|
|
32
|
+
const extendStack = (0, import_utils2.getExtendStack)(extend, context);
|
|
33
33
|
if (ENV !== "test" || ENV !== "development")
|
|
34
34
|
delete element.extend;
|
|
35
35
|
let childExtendStack = [];
|
|
36
36
|
if (parent) {
|
|
37
37
|
element.parent = parent;
|
|
38
38
|
if (!options.ignoreChildExtend && !(props && props.ignoreChildExtend)) {
|
|
39
|
-
childExtendStack = (0, import_utils2.getExtendStack)(parent.childExtend);
|
|
39
|
+
childExtendStack = (0, import_utils2.getExtendStack)(parent.childExtend, context);
|
|
40
40
|
const ignoreChildExtendRecursive = props && props.ignoreChildExtendRecursive;
|
|
41
41
|
if (parent.childExtendRecursive && !ignoreChildExtendRecursive) {
|
|
42
42
|
const canExtendRecursive = element.key !== "__text";
|
|
43
43
|
if (canExtendRecursive) {
|
|
44
|
-
const childExtendRecursiveStack = (0, import_utils2.getExtendStack)(parent.childExtendRecursive);
|
|
44
|
+
const childExtendRecursiveStack = (0, import_utils2.getExtendStack)(parent.childExtendRecursive, context);
|
|
45
45
|
childExtendStack = childExtendStack.concat(childExtendRecursiveStack);
|
|
46
46
|
element.childExtendRecursive = parent.childExtendRecursive;
|
|
47
47
|
}
|
|
@@ -60,13 +60,12 @@ const applyExtend = (element, parent, options = {}) => {
|
|
|
60
60
|
} else if (!options.extend)
|
|
61
61
|
return element;
|
|
62
62
|
if (options.extend) {
|
|
63
|
-
const defaultOptionsExtend = (0, import_utils2.getExtendStack)(options.extend);
|
|
63
|
+
const defaultOptionsExtend = (0, import_utils2.getExtendStack)(options.extend, context);
|
|
64
64
|
stack = [].concat(stack, defaultOptionsExtend);
|
|
65
65
|
}
|
|
66
66
|
if (__ref)
|
|
67
67
|
__ref.__extend = stack;
|
|
68
|
-
|
|
69
|
-
let mergedExtend = (0, import_utils2.cloneAndMergeArrayExtend)(findAndReplaceStrings);
|
|
68
|
+
let mergedExtend = (0, import_utils2.cloneAndMergeArrayExtend)(stack);
|
|
70
69
|
const COMPONENTS = context && context.components || options.components;
|
|
71
70
|
const component = (0, import_utils.exec)(element.component || mergedExtend.component, element);
|
|
72
71
|
if (component && COMPONENTS && COMPONENTS[component]) {
|
package/dist/cjs/mixins/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(mixins_exports, {
|
|
|
35
35
|
data: () => import_data.default,
|
|
36
36
|
html: () => import_html.default,
|
|
37
37
|
registry: () => import_registry.default,
|
|
38
|
+
scope: () => import_scope.default,
|
|
38
39
|
state: () => import_state.default,
|
|
39
40
|
style: () => import_style.default,
|
|
40
41
|
text: () => import_text.default
|
|
@@ -48,5 +49,6 @@ var import_html = __toESM(require("./html"), 1);
|
|
|
48
49
|
var import_style = __toESM(require("./style"), 1);
|
|
49
50
|
var import_text = __toESM(require("./text"), 1);
|
|
50
51
|
var import_state = __toESM(require("./state"), 1);
|
|
52
|
+
var import_scope = __toESM(require("./scope"), 1);
|
|
51
53
|
var import_registry = __toESM(require("./registry"), 1);
|
|
52
54
|
__reExport(mixins_exports, require("./registry"), module.exports);
|
|
@@ -0,0 +1,36 @@
|
|
|
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 scope_exports = {};
|
|
20
|
+
__export(scope_exports, {
|
|
21
|
+
default: () => scope_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(scope_exports);
|
|
24
|
+
var import_utils = require("@domql/utils");
|
|
25
|
+
var scope_default = (params, element, node) => {
|
|
26
|
+
if (!(0, import_utils.isObject)(params))
|
|
27
|
+
return;
|
|
28
|
+
for (const scopeItem in params) {
|
|
29
|
+
const value = params[scopeItem];
|
|
30
|
+
if ((0, import_utils.isFunction)(value)) {
|
|
31
|
+
element.scope[scopeItem] = value.bind(element);
|
|
32
|
+
} else {
|
|
33
|
+
element.scope[scopeItem] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
package/dist/cjs/mixins/text.js
CHANGED
|
@@ -18,34 +18,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var text_exports = {};
|
|
20
20
|
__export(text_exports, {
|
|
21
|
-
asd: () => asd,
|
|
22
21
|
default: () => text_default
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(text_exports);
|
|
25
24
|
var import__ = require("..");
|
|
26
25
|
var import_utils = require("@domql/utils");
|
|
27
|
-
const asd = (param, element, node) => {
|
|
28
|
-
const prop = (0, import_utils.exec)(param, element);
|
|
29
|
-
if (element.tag === "string") {
|
|
30
|
-
node.nodeValue = prop;
|
|
31
|
-
} else if (param !== void 0 || param !== null) {
|
|
32
|
-
if (element.__text && element.__text.text !== prop)
|
|
33
|
-
return;
|
|
34
|
-
element.__text.text = prop;
|
|
35
|
-
if (element.__text.node)
|
|
36
|
-
element.__text.node.nodeValue = prop;
|
|
37
|
-
else
|
|
38
|
-
(0, import__.create)({ tag: "string", text: prop }, element, "__text");
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
26
|
var text_default = (param, element, node) => {
|
|
42
27
|
let prop = (0, import_utils.exec)(param, element);
|
|
43
28
|
if ((0, import_utils.isString)(prop) && prop.includes("{{")) {
|
|
44
29
|
prop = (0, import_utils.replaceLiteralsWithObjectFields)(prop, element.state);
|
|
45
30
|
}
|
|
46
31
|
if (element.tag === "string") {
|
|
47
|
-
if (element.text === prop)
|
|
48
|
-
return;
|
|
49
32
|
node.nodeValue = prop;
|
|
50
33
|
} else if (param !== void 0 || param !== null) {
|
|
51
34
|
if (element.__text) {
|
package/dist/cjs/node.js
CHANGED
|
@@ -60,25 +60,25 @@ const createNode = (element, options) => {
|
|
|
60
60
|
if ((0, import_utils.isFunction)(node.setAttribute))
|
|
61
61
|
node.setAttribute("key", element.key);
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
(0, import_iterate.throughInitialDefine)(element);
|
|
64
|
+
(0, import_iterate.throughInitialExec)(element);
|
|
65
|
+
if (element.tag !== "string" && element.tag !== "fragment") {
|
|
66
66
|
if (isNewNode && (0, import_utils.isObject)(element.on))
|
|
67
67
|
(0, import_event.applyEventsOnNode)(element);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
}
|
|
69
|
+
for (const param in element) {
|
|
70
|
+
const value = element[param];
|
|
71
|
+
if ((0, import_utils.isUndefined)(value) || (0, import_methods.isMethod)(param) || (0, import_utils2.isVariant)(param) || (0, import_utils.isObject)(import_mixins.registry[param]))
|
|
72
|
+
continue;
|
|
73
|
+
const isElement = (0, import_applyParam.applyParam)(param, element, options);
|
|
74
|
+
if (isElement) {
|
|
75
|
+
const { hasDefine, hasContextDefine } = isElement;
|
|
76
|
+
if (element[param] && !hasDefine && !hasContextDefine) {
|
|
77
|
+
const createAsync = () => (0, import_create.default)((0, import_utils.exec)(value, element), element, param, options);
|
|
78
|
+
if (element.props && element.props.lazyLoad || options.lazyLoad) {
|
|
79
|
+
window.requestAnimationFrame(() => createAsync());
|
|
80
|
+
} else
|
|
81
|
+
createAsync();
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
package/dist/cjs/props/create.js
CHANGED
|
@@ -36,7 +36,7 @@ const createPropsStack = (element, parent) => {
|
|
|
36
36
|
propsStack.push(props);
|
|
37
37
|
if ((0, import_utils.isArray)(__ref.__extend)) {
|
|
38
38
|
__ref.__extend.forEach((extend) => {
|
|
39
|
-
if (extend.props)
|
|
39
|
+
if (extend.props && extend.props !== props)
|
|
40
40
|
propsStack.push(extend.props);
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -45,13 +45,11 @@ const createPropsStack = (element, parent) => {
|
|
|
45
45
|
};
|
|
46
46
|
const syncProps = (props, element) => {
|
|
47
47
|
element.props = {};
|
|
48
|
-
const mergedProps = {
|
|
48
|
+
const mergedProps = {};
|
|
49
49
|
props.forEach((v) => {
|
|
50
50
|
if (import_ignore.IGNORE_PROPS_PARAMS.includes(v))
|
|
51
51
|
return;
|
|
52
52
|
const execProps = (0, import_utils.exec)(v, element);
|
|
53
|
-
if ((0, import_utils.isObject)(execProps) && execProps.__element)
|
|
54
|
-
return;
|
|
55
53
|
element.props = (0, import_utils.deepMerge)(
|
|
56
54
|
mergedProps,
|
|
57
55
|
(0, import_utils.deepClone)(execProps, import_ignore.IGNORE_PROPS_PARAMS),
|
|
@@ -59,18 +57,31 @@ const syncProps = (props, element) => {
|
|
|
59
57
|
);
|
|
60
58
|
});
|
|
61
59
|
element.props = mergedProps;
|
|
60
|
+
const methods = { update: update.bind(element.props), __element: element };
|
|
61
|
+
Object.setPrototypeOf(element.props, methods);
|
|
62
62
|
return element.props;
|
|
63
63
|
};
|
|
64
64
|
const createProps = function(element, parent, cached) {
|
|
65
|
-
const propsStack = cached || createPropsStack(element, parent);
|
|
66
65
|
const { __ref: ref } = element;
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
if (ref.__if) {
|
|
67
|
+
try {
|
|
68
|
+
const propsStack = cached || createPropsStack(element, parent);
|
|
69
|
+
if (propsStack.length) {
|
|
70
|
+
ref.__props = propsStack;
|
|
71
|
+
syncProps(propsStack, element);
|
|
72
|
+
} else {
|
|
73
|
+
element.props = {};
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
element.props = {};
|
|
77
|
+
ref.__props = cached || [];
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
element.props = {};
|
|
81
|
+
ref.__props = cached || [];
|
|
73
82
|
}
|
|
83
|
+
const methods = { update: update.bind(element.props), __element: element };
|
|
84
|
+
Object.setPrototypeOf(element.props, methods);
|
|
74
85
|
return element;
|
|
75
86
|
};
|
|
76
87
|
function update(props, options) {
|
package/dist/cjs/props/update.js
CHANGED
|
@@ -27,7 +27,7 @@ const updateProps = (newProps, element, parent) => {
|
|
|
27
27
|
const { __ref } = element;
|
|
28
28
|
let propsStack = __ref.__props;
|
|
29
29
|
const parentProps = (0, import_inherit.inheritParentProps)(element, parent);
|
|
30
|
-
if (parentProps)
|
|
30
|
+
if (parentProps.length)
|
|
31
31
|
propsStack = __ref.__props = [].concat(parentProps, propsStack);
|
|
32
32
|
if (newProps)
|
|
33
33
|
propsStack = __ref.__props = [].concat(newProps, propsStack);
|
package/dist/cjs/set.js
CHANGED
|
@@ -39,21 +39,30 @@ var import_content = require("./mixins/content");
|
|
|
39
39
|
const set = function(params, options = {}, el) {
|
|
40
40
|
const element = el || this;
|
|
41
41
|
const __contentRef = element.content && element.content.__ref;
|
|
42
|
+
const lazyLoad = element.props && element.props.lazyLoad;
|
|
42
43
|
if (__contentRef && __contentRef.__cached && (0, import_utils.deepContains)(params, element.content)) {
|
|
43
44
|
console.log("is content equal");
|
|
44
45
|
return element.content.update();
|
|
45
46
|
}
|
|
46
|
-
(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
params.childExtend = element.childExtend;
|
|
47
|
+
if (options.preventContentUpdate === true)
|
|
48
|
+
return;
|
|
49
|
+
const setAsync = () => {
|
|
50
|
+
(0, import_content.removeContent)(element);
|
|
51
51
|
(0, import_create.default)(params, element, "content", {
|
|
52
52
|
ignoreChildExtend: true,
|
|
53
53
|
...import_mixins.registry.defaultOptions,
|
|
54
54
|
...import_options.default.create,
|
|
55
55
|
...options
|
|
56
56
|
});
|
|
57
|
+
};
|
|
58
|
+
if (params) {
|
|
59
|
+
const { childExtend } = params;
|
|
60
|
+
if (!childExtend && element.childExtend)
|
|
61
|
+
params.childExtend = element.childExtend;
|
|
62
|
+
if (lazyLoad) {
|
|
63
|
+
window.requestAnimationFrame(setAsync);
|
|
64
|
+
} else
|
|
65
|
+
setAsync();
|
|
57
66
|
}
|
|
58
67
|
return element;
|
|
59
68
|
};
|
package/dist/cjs/update.js
CHANGED
|
@@ -42,6 +42,7 @@ var import_iterate = require("./iterate");
|
|
|
42
42
|
var import_mixins = require("./mixins");
|
|
43
43
|
var import_applyParam = require("./applyParam");
|
|
44
44
|
var import_options = __toESM(require("./cache/options"), 1);
|
|
45
|
+
var import_inherit = require("../state/inherit");
|
|
45
46
|
const snapshot = {
|
|
46
47
|
snapshotId: import_utils.createSnapshotId
|
|
47
48
|
};
|
|
@@ -83,9 +84,6 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
83
84
|
if (props)
|
|
84
85
|
(0, import_props.updateProps)(props, element, parent);
|
|
85
86
|
}
|
|
86
|
-
if (!options.isForced) {
|
|
87
|
-
(0, import_event.triggerEventOn)("beforeClassAssign", element, options);
|
|
88
|
-
}
|
|
89
87
|
if (!options.preventInitUpdateListener) {
|
|
90
88
|
const initUpdateReturns = (0, import_event.triggerEventOnUpdate)("initUpdate", params, element, options);
|
|
91
89
|
if (initUpdateReturns === false)
|
|
@@ -94,6 +92,9 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
94
92
|
const overwriteChanges = (0, import_utils.overwriteDeep)(element, params, import_utils2.METHODS_EXL);
|
|
95
93
|
const execChanges = (0, import_iterate.throughUpdatedExec)(element, { ignore: UPDATE_DEFAULT_OPTIONS });
|
|
96
94
|
const definedChanges = (0, import_iterate.throughUpdatedDefine)(element);
|
|
95
|
+
if (!options.isForced) {
|
|
96
|
+
(0, import_event.triggerEventOn)("beforeClassAssign", element, options);
|
|
97
|
+
}
|
|
97
98
|
if (options.stackChanges && element.__stackChanges) {
|
|
98
99
|
const stackChanges = (0, import_utils.merge)(definedChanges, (0, import_utils.merge)(execChanges, overwriteChanges));
|
|
99
100
|
element.__stackChanges.push(stackChanges);
|
|
@@ -118,15 +119,13 @@ const update = function(params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
118
119
|
const canUpdate = (0, import_utils.isObject)(prop) && !hasDefine && !hasContextDefine && !options.preventRecursive;
|
|
119
120
|
if (!canUpdate)
|
|
120
121
|
continue;
|
|
122
|
+
const lazyLoad = element.props.lazyLoad || options.lazyLoad;
|
|
121
123
|
const childUpdateCall = () => update.call(prop, params[prop], {
|
|
122
124
|
...options,
|
|
123
125
|
currentSnapshot: snapshotOnCallee,
|
|
124
126
|
calleeElement
|
|
125
127
|
});
|
|
126
|
-
|
|
127
|
-
import_utils.window.requestAnimationFrame(() => childUpdateCall());
|
|
128
|
-
} else
|
|
129
|
-
childUpdateCall();
|
|
128
|
+
lazyLoad ? import_utils.window.requestAnimationFrame(() => childUpdateCall()) : childUpdateCall();
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
if (!options.preventUpdateListener)
|
|
@@ -179,24 +178,20 @@ const inheritStateUpdates = (element, options) => {
|
|
|
179
178
|
const { __ref: ref } = element;
|
|
180
179
|
const stateKey = ref.__state;
|
|
181
180
|
const { parent, state } = element;
|
|
182
|
-
|
|
181
|
+
const { preventUpdateTriggerStateUpdate, isHoisted, execStateFunction } = options;
|
|
182
|
+
if (preventUpdateTriggerStateUpdate)
|
|
183
183
|
return;
|
|
184
184
|
if (!stateKey && !ref.__hasRootState) {
|
|
185
185
|
element.state = parent && parent.state || {};
|
|
186
186
|
return;
|
|
187
187
|
}
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
if (shouldForceStateUpdate) {
|
|
188
|
+
const shouldForceFunctionState = (0, import_utils.isFunction)(stateKey) && !isHoisted && execStateFunction;
|
|
189
|
+
if (shouldForceFunctionState) {
|
|
191
190
|
const execState = (0, import_utils.exec)(stateKey, element);
|
|
192
|
-
state.set(execState, {
|
|
193
|
-
...options,
|
|
194
|
-
preventUpdate: true
|
|
195
|
-
});
|
|
191
|
+
state.set(execState, { ...options, preventUpdate: true });
|
|
196
192
|
return;
|
|
197
193
|
}
|
|
198
|
-
const
|
|
199
|
-
const keyInParentState = parentState[stateKey];
|
|
194
|
+
const keyInParentState = (0, import_inherit.findInheritedState)(element, element.parent);
|
|
200
195
|
if (!keyInParentState || options.preventInheritedStateUpdate)
|
|
201
196
|
return;
|
|
202
197
|
if (!options.preventInitStateUpdateListener) {
|
|
@@ -49,24 +49,28 @@ const addAdditionalExtend = (newExtend, element) => {
|
|
|
49
49
|
};
|
|
50
50
|
const extendizeByKey = (element, parent, key) => {
|
|
51
51
|
const { tag, extend, props, state, childExtend, childProps, on, if: condition } = element;
|
|
52
|
-
const hasComponentAttrs =
|
|
52
|
+
const hasComponentAttrs = extend || childExtend || props || state || on || condition;
|
|
53
53
|
const componentKey = key.includes("_") ? key.split("_")[0] : key.includes(".") ? key.split(".")[0] : key;
|
|
54
54
|
const extendKey = componentKey || key;
|
|
55
55
|
if (!hasComponentAttrs || childProps) {
|
|
56
56
|
return {
|
|
57
57
|
extend: extendKey,
|
|
58
|
+
tag,
|
|
58
59
|
props: { ...element }
|
|
59
60
|
};
|
|
60
61
|
} else if (!extend || extend === true) {
|
|
61
62
|
return {
|
|
62
63
|
...element,
|
|
64
|
+
tag,
|
|
63
65
|
extend: extendKey
|
|
64
66
|
};
|
|
65
67
|
} else if (extend) {
|
|
66
68
|
addAdditionalExtend(extendKey, element);
|
|
67
69
|
} else if ((0, import_utils.isFunction)(element)) {
|
|
70
|
+
console.log(element);
|
|
68
71
|
return {
|
|
69
72
|
extend: extendKey,
|
|
73
|
+
tag,
|
|
70
74
|
props: { ...(0, import_utils.exec)(element, parent) }
|
|
71
75
|
};
|
|
72
76
|
}
|
|
@@ -33,7 +33,6 @@ __export(extendUtils_exports, {
|
|
|
33
33
|
getExtendStackRegistry: () => getExtendStackRegistry,
|
|
34
34
|
getHashedExtend: () => getHashedExtend,
|
|
35
35
|
jointStacks: () => jointStacks,
|
|
36
|
-
replaceStringsWithComponents: () => replaceStringsWithComponents,
|
|
37
36
|
setHashedExtend: () => setHashedExtend
|
|
38
37
|
});
|
|
39
38
|
module.exports = __toCommonJS(extendUtils_exports);
|
|
@@ -59,25 +58,27 @@ const getExtendStackRegistry = (extend, stack) => {
|
|
|
59
58
|
}
|
|
60
59
|
return setHashedExtend(extend, stack);
|
|
61
60
|
};
|
|
62
|
-
const extractArrayExtend = (extend, stack) => {
|
|
63
|
-
extend.forEach((each) => flattenExtend(each, stack));
|
|
61
|
+
const extractArrayExtend = (extend, stack, context) => {
|
|
62
|
+
extend.forEach((each) => flattenExtend(each, stack, context));
|
|
64
63
|
return stack;
|
|
65
64
|
};
|
|
66
|
-
const deepExtend = (extend, stack) => {
|
|
65
|
+
const deepExtend = (extend, stack, context) => {
|
|
67
66
|
const extendOflattenExtend = extend.extend;
|
|
68
67
|
if (extendOflattenExtend) {
|
|
69
|
-
flattenExtend(extendOflattenExtend, stack);
|
|
68
|
+
flattenExtend(extendOflattenExtend, stack, context);
|
|
70
69
|
}
|
|
71
70
|
return stack;
|
|
72
71
|
};
|
|
73
|
-
const flattenExtend = (extend, stack) => {
|
|
72
|
+
const flattenExtend = (extend, stack, context) => {
|
|
74
73
|
if (!extend)
|
|
75
74
|
return stack;
|
|
76
75
|
if ((0, import_utils.isArray)(extend))
|
|
77
|
-
return extractArrayExtend(extend, stack);
|
|
76
|
+
return extractArrayExtend(extend, stack, context);
|
|
77
|
+
if ((0, import_utils.isString)(extend))
|
|
78
|
+
extend = fallbackStringExtend(extend, context);
|
|
78
79
|
stack.push(extend);
|
|
79
80
|
if (extend.extend)
|
|
80
|
-
deepExtend(extend, stack);
|
|
81
|
+
deepExtend(extend, stack, context);
|
|
81
82
|
return stack;
|
|
82
83
|
};
|
|
83
84
|
const deepCloneExtend = (obj) => {
|
|
@@ -121,7 +122,7 @@ const cloneAndMergeArrayExtend = (stack) => {
|
|
|
121
122
|
return deepMergeExtend(a, deepCloneExtend(c));
|
|
122
123
|
}, {});
|
|
123
124
|
};
|
|
124
|
-
const fallbackStringExtend = (extend, context, options) => {
|
|
125
|
+
const fallbackStringExtend = (extend, context, options = {}) => {
|
|
125
126
|
const COMPONENTS = context && context.components || options.components;
|
|
126
127
|
if ((0, import_utils.isString)(extend)) {
|
|
127
128
|
if (COMPONENTS && COMPONENTS[extend]) {
|
|
@@ -138,29 +139,15 @@ const fallbackStringExtend = (extend, context, options) => {
|
|
|
138
139
|
const jointStacks = (extendStack, childExtendStack) => {
|
|
139
140
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendStack.slice(1));
|
|
140
141
|
};
|
|
141
|
-
const getExtendStack = (extend) => {
|
|
142
|
+
const getExtendStack = (extend, context) => {
|
|
142
143
|
if (!extend)
|
|
143
144
|
return [];
|
|
144
145
|
if (extend.__hash)
|
|
145
146
|
return getHashedExtend(extend) || [];
|
|
146
|
-
const stack = flattenExtend(extend, []);
|
|
147
|
+
const stack = flattenExtend(extend, [], context);
|
|
147
148
|
return getExtendStackRegistry(extend, stack);
|
|
148
149
|
};
|
|
149
150
|
const getExtendMerged = (extend) => {
|
|
150
151
|
const stack = getExtendStack(extend);
|
|
151
152
|
return cloneAndMergeArrayExtend(stack);
|
|
152
153
|
};
|
|
153
|
-
const replaceStringsWithComponents = (stack, context, options) => {
|
|
154
|
-
const COMPONENTS = context && context.components || options.components;
|
|
155
|
-
return stack.map((v) => {
|
|
156
|
-
if ((0, import_utils.isString)(v)) {
|
|
157
|
-
const component = COMPONENTS[v];
|
|
158
|
-
return component;
|
|
159
|
-
}
|
|
160
|
-
if ((0, import_utils.isString)(v.extend)) {
|
|
161
|
-
v.extend = COMPONENTS[v.extend];
|
|
162
|
-
return { ...getExtendMerged(v.extend), ...v };
|
|
163
|
-
}
|
|
164
|
-
return v;
|
|
165
|
-
});
|
|
166
|
-
};
|
package/extend.js
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
jointStacks,
|
|
7
7
|
cloneAndMergeArrayExtend,
|
|
8
8
|
deepMergeExtend,
|
|
9
|
-
replaceStringsWithComponents,
|
|
10
9
|
fallbackStringExtend
|
|
11
10
|
} from './utils'
|
|
12
11
|
|
|
@@ -23,7 +22,7 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
23
22
|
|
|
24
23
|
extend = fallbackStringExtend(extend, context, options)
|
|
25
24
|
|
|
26
|
-
const extendStack = getExtendStack(extend)
|
|
25
|
+
const extendStack = getExtendStack(extend, context)
|
|
27
26
|
|
|
28
27
|
if (ENV !== 'test' || ENV !== 'development') delete element.extend
|
|
29
28
|
|
|
@@ -32,14 +31,13 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
32
31
|
element.parent = parent
|
|
33
32
|
// Assign parent attr to the element
|
|
34
33
|
if (!options.ignoreChildExtend && !(props && props.ignoreChildExtend)) {
|
|
35
|
-
childExtendStack = getExtendStack(parent.childExtend)
|
|
34
|
+
childExtendStack = getExtendStack(parent.childExtend, context)
|
|
36
35
|
|
|
37
|
-
// if (parent.childExtendRecursive && (props && !props.ignoreChildExtendRecursive)) {
|
|
38
36
|
const ignoreChildExtendRecursive = props && props.ignoreChildExtendRecursive
|
|
39
37
|
if (parent.childExtendRecursive && !ignoreChildExtendRecursive) {
|
|
40
38
|
const canExtendRecursive = element.key !== '__text'
|
|
41
39
|
if (canExtendRecursive) {
|
|
42
|
-
const childExtendRecursiveStack = getExtendStack(parent.childExtendRecursive)
|
|
40
|
+
const childExtendRecursiveStack = getExtendStack(parent.childExtendRecursive, context)
|
|
43
41
|
// add error if childExtendRecursive contains element which goes to infinite loop
|
|
44
42
|
childExtendStack = childExtendStack.concat(childExtendRecursiveStack)
|
|
45
43
|
element.childExtendRecursive = parent.childExtendRecursive
|
|
@@ -61,14 +59,15 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
61
59
|
} else if (!options.extend) return element
|
|
62
60
|
|
|
63
61
|
if (options.extend) {
|
|
64
|
-
const defaultOptionsExtend = getExtendStack(options.extend)
|
|
62
|
+
const defaultOptionsExtend = getExtendStack(options.extend, context)
|
|
65
63
|
stack = [].concat(stack, defaultOptionsExtend)
|
|
66
64
|
}
|
|
67
65
|
|
|
66
|
+
// check if array contains string extends
|
|
68
67
|
if (__ref) __ref.__extend = stack
|
|
69
|
-
|
|
70
|
-
let mergedExtend = cloneAndMergeArrayExtend(findAndReplaceStrings)
|
|
68
|
+
let mergedExtend = cloneAndMergeArrayExtend(stack)
|
|
71
69
|
|
|
70
|
+
// apply `component:` property
|
|
72
71
|
const COMPONENTS = (context && context.components) || options.components
|
|
73
72
|
const component = exec(element.component || mergedExtend.component, element)
|
|
74
73
|
if (component && COMPONENTS && COMPONENTS[component]) {
|
package/mixins/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import html from './html'
|
|
|
8
8
|
import style from './style'
|
|
9
9
|
import text from './text'
|
|
10
10
|
import state from './state'
|
|
11
|
+
import scope from './scope'
|
|
11
12
|
import registry from './registry'
|
|
12
13
|
export {
|
|
13
14
|
attr,
|
|
@@ -18,6 +19,7 @@ export {
|
|
|
18
19
|
text,
|
|
19
20
|
html,
|
|
20
21
|
state,
|
|
22
|
+
scope,
|
|
21
23
|
registry
|
|
22
24
|
}
|
|
23
25
|
export * from './registry'
|
package/mixins/registry.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
attr, classList, content,
|
|
5
5
|
data, html, state, style,
|
|
6
|
-
text
|
|
6
|
+
text, scope
|
|
7
7
|
} from '.'
|
|
8
8
|
|
|
9
9
|
export default {
|
|
@@ -15,6 +15,7 @@ export default {
|
|
|
15
15
|
data,
|
|
16
16
|
class: classList,
|
|
17
17
|
state,
|
|
18
|
+
scope,
|
|
18
19
|
|
|
19
20
|
deps: (param, el) => param || el.parent.deps,
|
|
20
21
|
|
package/mixins/scope.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isFunction, isObject } from '@domql/utils'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Apply data parameters on the DOM nodes
|
|
7
|
+
* this should only work if `showOnNode: true` is passed
|
|
8
|
+
*/
|
|
9
|
+
export default (params, element, node) => {
|
|
10
|
+
if (!isObject(params)) return
|
|
11
|
+
|
|
12
|
+
// Apply data params on node
|
|
13
|
+
for (const scopeItem in params) {
|
|
14
|
+
const value = params[scopeItem]
|
|
15
|
+
if (isFunction(value)) {
|
|
16
|
+
element.scope[scopeItem] = value.bind(element)
|
|
17
|
+
} else {
|
|
18
|
+
element.scope[scopeItem] = value
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
package/mixins/text.js
CHANGED
|
@@ -11,25 +11,12 @@ import {
|
|
|
11
11
|
* Creates a text node and appends into
|
|
12
12
|
* an original one as a child
|
|
13
13
|
*/
|
|
14
|
-
export const asd = (param, element, node) => {
|
|
15
|
-
const prop = exec(param, element)
|
|
16
|
-
if (element.tag === 'string') {
|
|
17
|
-
node.nodeValue = prop
|
|
18
|
-
} else if (param !== undefined || param !== null) {
|
|
19
|
-
if (element.__text && element.__text.text !== prop) return
|
|
20
|
-
element.__text.text = prop
|
|
21
|
-
if (element.__text.node) element.__text.node.nodeValue = prop
|
|
22
|
-
else create({ tag: 'string', text: prop }, element, '__text')
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
14
|
export default (param, element, node) => {
|
|
27
15
|
let prop = exec(param, element)
|
|
28
16
|
if (isString(prop) && prop.includes('{{')) {
|
|
29
17
|
prop = replaceLiteralsWithObjectFields(prop, element.state)
|
|
30
18
|
}
|
|
31
19
|
if (element.tag === 'string') {
|
|
32
|
-
if (element.text === prop) return
|
|
33
20
|
node.nodeValue = prop
|
|
34
21
|
} else if (param !== undefined || param !== null) {
|
|
35
22
|
if (element.__text) {
|
package/node.js
CHANGED
|
@@ -44,37 +44,36 @@ export const createNode = (element, options) => {
|
|
|
44
44
|
if (isFunction(node.setAttribute)) node.setAttribute('key', element.key)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// iterate through
|
|
48
|
-
|
|
49
|
-
// iterate through define
|
|
50
|
-
throughInitialDefine(element)
|
|
47
|
+
// iterate through define
|
|
48
|
+
throughInitialDefine(element)
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
// iterate through exec
|
|
51
|
+
throughInitialExec(element)
|
|
54
52
|
|
|
53
|
+
if (element.tag !== 'string' && element.tag !== 'fragment') {
|
|
55
54
|
// apply events
|
|
56
55
|
if (isNewNode && isObject(element.on)) applyEventsOnNode(element)
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
58
|
+
for (const param in element) {
|
|
59
|
+
const value = element[param]
|
|
60
|
+
|
|
61
|
+
if (
|
|
62
|
+
isUndefined(value) ||
|
|
63
|
+
isMethod(param) ||
|
|
64
|
+
isVariant(param) ||
|
|
65
|
+
isObject(registry[param])
|
|
66
|
+
) continue
|
|
67
|
+
|
|
68
|
+
const isElement = applyParam(param, element, options)
|
|
69
|
+
if (isElement) {
|
|
70
|
+
const { hasDefine, hasContextDefine } = isElement
|
|
71
|
+
if (element[param] && !hasDefine && !hasContextDefine) {
|
|
72
|
+
const createAsync = () => create(exec(value, element), element, param, options)
|
|
73
|
+
|
|
74
|
+
if ((element.props && element.props.lazyLoad) || options.lazyLoad) {
|
|
75
|
+
window.requestAnimationFrame(() => createAsync())
|
|
76
|
+
} else createAsync()
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.19",
|
|
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": "94b0e44e5e5a20b0a78459b3a31eb3f7afa1c7e6",
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/core": "^7.12.0"
|
|
37
37
|
}
|
package/props/create.js
CHANGED
|
@@ -15,7 +15,7 @@ const createPropsStack = (element, parent) => {
|
|
|
15
15
|
|
|
16
16
|
if (isArray(__ref.__extend)) {
|
|
17
17
|
__ref.__extend.forEach(extend => {
|
|
18
|
-
if (extend.props) propsStack.push(extend.props)
|
|
18
|
+
if (extend.props && extend.props !== props) propsStack.push(extend.props)
|
|
19
19
|
})
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -26,11 +26,14 @@ const createPropsStack = (element, parent) => {
|
|
|
26
26
|
|
|
27
27
|
export const syncProps = (props, element) => {
|
|
28
28
|
element.props = {}
|
|
29
|
-
const mergedProps = {
|
|
29
|
+
const mergedProps = {}
|
|
30
|
+
|
|
30
31
|
props.forEach(v => {
|
|
31
32
|
if (IGNORE_PROPS_PARAMS.includes(v)) return
|
|
32
33
|
const execProps = exec(v, element)
|
|
33
|
-
if
|
|
34
|
+
// TODO: check if this failing the function props merge
|
|
35
|
+
// if (isObject(execProps) && execProps.__element) return
|
|
36
|
+
// it was causing infinite loop at early days
|
|
34
37
|
element.props = deepMerge(
|
|
35
38
|
mergedProps,
|
|
36
39
|
deepClone(execProps, IGNORE_PROPS_PARAMS),
|
|
@@ -38,21 +41,35 @@ export const syncProps = (props, element) => {
|
|
|
38
41
|
)
|
|
39
42
|
})
|
|
40
43
|
element.props = mergedProps
|
|
44
|
+
|
|
45
|
+
const methods = { update: update.bind(element.props), __element: element }
|
|
46
|
+
Object.setPrototypeOf(element.props, methods)
|
|
47
|
+
|
|
41
48
|
return element.props
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
export const createProps = function (element, parent, cached) {
|
|
45
|
-
const propsStack = cached || createPropsStack(element, parent)
|
|
46
52
|
const { __ref: ref } = element
|
|
47
53
|
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
if (ref.__if) {
|
|
55
|
+
try {
|
|
56
|
+
const propsStack = cached || createPropsStack(element, parent)
|
|
57
|
+
if (propsStack.length) {
|
|
58
|
+
ref.__props = propsStack
|
|
59
|
+
syncProps(propsStack, element)
|
|
60
|
+
} else { element.props = {} }
|
|
61
|
+
} catch (e) {
|
|
62
|
+
element.props = {}
|
|
63
|
+
ref.__props = cached || []
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
element.props = {}
|
|
67
|
+
ref.__props = cached || []
|
|
54
68
|
}
|
|
55
69
|
|
|
70
|
+
const methods = { update: update.bind(element.props), __element: element }
|
|
71
|
+
Object.setPrototypeOf(element.props, methods)
|
|
72
|
+
|
|
56
73
|
return element
|
|
57
74
|
}
|
|
58
75
|
|
package/props/update.js
CHANGED
|
@@ -8,7 +8,7 @@ export const updateProps = (newProps, element, parent) => {
|
|
|
8
8
|
let propsStack = __ref.__props
|
|
9
9
|
|
|
10
10
|
const parentProps = inheritParentProps(element, parent)
|
|
11
|
-
if (parentProps) propsStack = __ref.__props = [].concat(parentProps, propsStack)
|
|
11
|
+
if (parentProps.length) propsStack = __ref.__props = [].concat(parentProps, propsStack)
|
|
12
12
|
if (newProps) propsStack = __ref.__props = [].concat(newProps, propsStack)
|
|
13
13
|
|
|
14
14
|
if (propsStack) syncProps(propsStack, element)
|
package/set.js
CHANGED
|
@@ -10,17 +10,17 @@ import { removeContent } from './mixins/content'
|
|
|
10
10
|
const set = function (params, options = {}, el) {
|
|
11
11
|
const element = el || this
|
|
12
12
|
const __contentRef = element.content && element.content.__ref
|
|
13
|
+
const lazyLoad = element.props && element.props.lazyLoad
|
|
13
14
|
|
|
14
15
|
if (__contentRef && __contentRef.__cached && deepContains(params, element.content)) {
|
|
15
16
|
console.log('is content equal')
|
|
16
17
|
return element.content.update()
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
if (options.preventContentUpdate === true) return
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!childExtend && element.childExtend) params.childExtend = element.childExtend
|
|
22
|
+
const setAsync = () => {
|
|
23
|
+
removeContent(element)
|
|
24
24
|
create(params, element, 'content', {
|
|
25
25
|
ignoreChildExtend: true,
|
|
26
26
|
...registry.defaultOptions,
|
|
@@ -29,6 +29,15 @@ const set = function (params, options = {}, el) {
|
|
|
29
29
|
})
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
if (params) {
|
|
33
|
+
const { childExtend } = params
|
|
34
|
+
if (!childExtend && element.childExtend) params.childExtend = element.childExtend
|
|
35
|
+
|
|
36
|
+
if (lazyLoad) {
|
|
37
|
+
window.requestAnimationFrame(setAsync)
|
|
38
|
+
} else setAsync()
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
return element
|
|
33
42
|
}
|
|
34
43
|
|
package/update.js
CHANGED
|
@@ -12,6 +12,7 @@ import { throughUpdatedDefine, throughUpdatedExec } from './iterate'
|
|
|
12
12
|
import { registry } from './mixins'
|
|
13
13
|
import { applyParam } from './applyParam'
|
|
14
14
|
import OPTIONS from './cache/options'
|
|
15
|
+
import { findInheritedState } from '../state/inherit'
|
|
15
16
|
|
|
16
17
|
const snapshot = {
|
|
17
18
|
snapshotId: createSnapshotId
|
|
@@ -57,10 +58,6 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
57
58
|
if (props) updateProps(props, element, parent)
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
if (!options.isForced) {
|
|
61
|
-
triggerEventOn('beforeClassAssign', element, options)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
61
|
if (!options.preventInitUpdateListener) {
|
|
65
62
|
const initUpdateReturns = triggerEventOnUpdate('initUpdate', params, element, options)
|
|
66
63
|
if (initUpdateReturns === false) return element
|
|
@@ -70,6 +67,10 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
70
67
|
const execChanges = throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS })
|
|
71
68
|
const definedChanges = throughUpdatedDefine(element)
|
|
72
69
|
|
|
70
|
+
if (!options.isForced) {
|
|
71
|
+
triggerEventOn('beforeClassAssign', element, options)
|
|
72
|
+
}
|
|
73
|
+
|
|
73
74
|
if (options.stackChanges && element.__stackChanges) {
|
|
74
75
|
const stackChanges = merge(definedChanges, merge(execChanges, overwriteChanges))
|
|
75
76
|
element.__stackChanges.push(stackChanges)
|
|
@@ -106,15 +107,15 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
106
107
|
const canUpdate = isObject(prop) && !hasDefine && !hasContextDefine && !options.preventRecursive
|
|
107
108
|
if (!canUpdate) continue
|
|
108
109
|
|
|
110
|
+
const lazyLoad = element.props.lazyLoad || options.lazyLoad
|
|
111
|
+
|
|
109
112
|
const childUpdateCall = () => update.call(prop, params[prop], {
|
|
110
113
|
...options,
|
|
111
114
|
currentSnapshot: snapshotOnCallee,
|
|
112
115
|
calleeElement
|
|
113
116
|
})
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
window.requestAnimationFrame(() => childUpdateCall())
|
|
117
|
-
} else childUpdateCall()
|
|
118
|
+
lazyLoad ? window.requestAnimationFrame(() => childUpdateCall()) : childUpdateCall()
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -171,41 +172,56 @@ const checkIfOnUpdate = (element, parent, options) => {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Inherit state updates for a given element based on the specified options.
|
|
177
|
+
*
|
|
178
|
+
* @param {Object} element - The element to inherit state updates for.
|
|
179
|
+
* @param {Object} options - Configuration options for state update inheritance.
|
|
180
|
+
* @param {boolean} [options.preventUpdateTriggerStateUpdate] - If true, prevent triggering state updates.
|
|
181
|
+
* @param {boolean} [options.isHoisted] - Whether the state is hoisted.
|
|
182
|
+
* @param {boolean} [options.execStateFunction] - Execute the state functions.
|
|
183
|
+
* @param {boolean} [options.stateFunctionOverwrite] - If true, overwrite (not merge) current state with what function returns.
|
|
184
|
+
* @param {boolean} [options.preventInheritedStateUpdate] - If true, prevent inheriting state updates.
|
|
185
|
+
* @param {boolean} [options.preventInitStateUpdateListener] - If true, prevent the 'initStateUpdated' event listener.
|
|
186
|
+
* @param {boolean} [options.preventStateUpdateListener] - If true, prevent the 'stateUpdated' event listener.
|
|
187
|
+
* @returns {boolean} - If returns false, it breaks the update function
|
|
188
|
+
*/
|
|
174
189
|
const inheritStateUpdates = (element, options) => {
|
|
175
190
|
const { __ref: ref } = element
|
|
176
191
|
const stateKey = ref.__state
|
|
177
192
|
const { parent, state } = element
|
|
193
|
+
const { preventUpdateTriggerStateUpdate, isHoisted, execStateFunction } = options
|
|
178
194
|
|
|
179
|
-
if (
|
|
195
|
+
if (preventUpdateTriggerStateUpdate) return
|
|
180
196
|
|
|
197
|
+
// If does not have own state inherit from parent
|
|
181
198
|
if (!stateKey && !ref.__hasRootState) {
|
|
182
199
|
element.state = (parent && parent.state) || {}
|
|
183
200
|
return
|
|
184
201
|
}
|
|
185
202
|
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
if (
|
|
203
|
+
// If state is function, decide execution and apply setting a current state
|
|
204
|
+
const shouldForceFunctionState = isFunction(stateKey) && !isHoisted && execStateFunction
|
|
205
|
+
if (shouldForceFunctionState) {
|
|
189
206
|
const execState = exec(stateKey, element)
|
|
190
|
-
state.set(execState, {
|
|
191
|
-
...options,
|
|
192
|
-
preventUpdate: true
|
|
193
|
-
})
|
|
207
|
+
state.set(execState, { ...options, preventUpdate: true })
|
|
194
208
|
return
|
|
195
209
|
}
|
|
196
210
|
|
|
197
|
-
|
|
198
|
-
const keyInParentState =
|
|
199
|
-
|
|
211
|
+
// If state is string, find its value in the state tree
|
|
212
|
+
const keyInParentState = findInheritedState(element, element.parent)
|
|
200
213
|
if (!keyInParentState || options.preventInheritedStateUpdate) return
|
|
201
214
|
|
|
215
|
+
// Trigger on.initStateUpdated event
|
|
202
216
|
if (!options.preventInitStateUpdateListener) {
|
|
203
217
|
const initStateReturns = triggerEventOnUpdate('initStateUpdated', keyInParentState, element, options)
|
|
204
218
|
if (initStateReturns === false) return element
|
|
205
219
|
}
|
|
206
220
|
|
|
221
|
+
// Recreate the state again
|
|
207
222
|
const newState = createStateUpdate(element, parent, options)
|
|
208
223
|
|
|
224
|
+
// Trigger on.stateUpdated event
|
|
209
225
|
if (!options.preventStateUpdateListener) {
|
|
210
226
|
triggerEventOnUpdate('stateUpdated', newState.parse(), element, options)
|
|
211
227
|
}
|
package/utils/component.js
CHANGED
|
@@ -22,7 +22,7 @@ export const addAdditionalExtend = (newExtend, element) => {
|
|
|
22
22
|
|
|
23
23
|
export const extendizeByKey = (element, parent, key) => {
|
|
24
24
|
const { tag, extend, props, state, childExtend, childProps, on, if: condition } = element
|
|
25
|
-
const hasComponentAttrs =
|
|
25
|
+
const hasComponentAttrs = extend || childExtend || props || state || on || condition
|
|
26
26
|
const componentKey = key.includes('_')
|
|
27
27
|
? key.split('_')[0]
|
|
28
28
|
: key.includes('.') ? key.split('.')[0] : key
|
|
@@ -31,18 +31,22 @@ export const extendizeByKey = (element, parent, key) => {
|
|
|
31
31
|
if (!hasComponentAttrs || childProps) {
|
|
32
32
|
return {
|
|
33
33
|
extend: extendKey,
|
|
34
|
+
tag,
|
|
34
35
|
props: { ...element }
|
|
35
36
|
}
|
|
36
37
|
} else if (!extend || extend === true) {
|
|
37
38
|
return {
|
|
38
39
|
...element,
|
|
40
|
+
tag,
|
|
39
41
|
extend: extendKey
|
|
40
42
|
}
|
|
41
43
|
} else if (extend) {
|
|
42
44
|
addAdditionalExtend(extendKey, element)
|
|
43
45
|
} else if (isFunction(element)) {
|
|
46
|
+
console.log(element)
|
|
44
47
|
return {
|
|
45
48
|
extend: extendKey,
|
|
49
|
+
tag,
|
|
46
50
|
props: { ...exec(element, parent) }
|
|
47
51
|
}
|
|
48
52
|
}
|
package/utils/extendUtils.js
CHANGED
|
@@ -26,24 +26,25 @@ export const getExtendStackRegistry = (extend, stack) => {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// stacking
|
|
29
|
-
export const extractArrayExtend = (extend, stack) => {
|
|
30
|
-
extend.forEach(each => flattenExtend(each, stack))
|
|
29
|
+
export const extractArrayExtend = (extend, stack, context) => {
|
|
30
|
+
extend.forEach(each => flattenExtend(each, stack, context))
|
|
31
31
|
return stack
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export const deepExtend = (extend, stack) => {
|
|
34
|
+
export const deepExtend = (extend, stack, context) => {
|
|
35
35
|
const extendOflattenExtend = extend.extend
|
|
36
36
|
if (extendOflattenExtend) {
|
|
37
|
-
flattenExtend(extendOflattenExtend, stack)
|
|
37
|
+
flattenExtend(extendOflattenExtend, stack, context)
|
|
38
38
|
}
|
|
39
39
|
return stack
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export const flattenExtend = (extend, stack) => {
|
|
42
|
+
export const flattenExtend = (extend, stack, context) => {
|
|
43
43
|
if (!extend) return stack
|
|
44
|
-
if (isArray(extend)) return extractArrayExtend(extend, stack)
|
|
44
|
+
if (isArray(extend)) return extractArrayExtend(extend, stack, context)
|
|
45
|
+
if (isString(extend)) extend = fallbackStringExtend(extend, context)
|
|
45
46
|
stack.push(extend)
|
|
46
|
-
if (extend.extend) deepExtend(extend, stack)
|
|
47
|
+
if (extend.extend) deepExtend(extend, stack, context)
|
|
47
48
|
return stack
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -89,7 +90,7 @@ export const cloneAndMergeArrayExtend = stack => {
|
|
|
89
90
|
}, {})
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
export const fallbackStringExtend = (extend, context, options) => {
|
|
93
|
+
export const fallbackStringExtend = (extend, context, options = {}) => {
|
|
93
94
|
const COMPONENTS = (context && context.components) || options.components
|
|
94
95
|
if (isString(extend)) {
|
|
95
96
|
if (COMPONENTS && COMPONENTS[extend]) {
|
|
@@ -114,10 +115,10 @@ export const jointStacks = (extendStack, childExtendStack) => {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
// init
|
|
117
|
-
export const getExtendStack = extend => {
|
|
118
|
+
export const getExtendStack = (extend, context) => {
|
|
118
119
|
if (!extend) return []
|
|
119
120
|
if (extend.__hash) return getHashedExtend(extend) || []
|
|
120
|
-
const stack = flattenExtend(extend, [])
|
|
121
|
+
const stack = flattenExtend(extend, [], context)
|
|
121
122
|
return getExtendStackRegistry(extend, stack)
|
|
122
123
|
}
|
|
123
124
|
|
|
@@ -126,17 +127,16 @@ export const getExtendMerged = extend => {
|
|
|
126
127
|
return cloneAndMergeArrayExtend(stack)
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
export const replaceStringsWithComponents = (stack, context, options) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
130
|
+
// export const replaceStringsWithComponents = (stack, context, options) => {
|
|
131
|
+
// const COMPONENTS = (context && context.components) || options.components
|
|
132
|
+
// return stack.map(v => {
|
|
133
|
+
// if (isString(v)) {
|
|
134
|
+
// const component = COMPONENTS[v]
|
|
135
|
+
// return component
|
|
136
|
+
// }
|
|
137
|
+
// if (isString(v.extend)) {
|
|
138
|
+
// v.extend = getExtendMerged(COMPONENTS[v.extend])
|
|
139
|
+
// }
|
|
140
|
+
// return v
|
|
141
|
+
// })
|
|
142
|
+
// }
|