@domql/element 2.5.16 → 2.5.18
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 +41 -35
- package/dist/cjs/create.js +50 -40
- 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/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 +2 -2
- package/dist/cjs/utils/extendUtils.js +12 -27
- package/extend.js +7 -8
- package/mixins/index.js +2 -0
- package/mixins/registry.js +2 -1
- package/mixins/scope.js +21 -0
- 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 +2 -2
- package/utils/extendUtils.js +24 -26
package/create.js
CHANGED
|
@@ -64,8 +64,10 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
64
64
|
|
|
65
65
|
applyComponentFromContext(element, parent, options)
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
if (!ref.__skipCreate) {
|
|
68
|
+
// create EXTEND inheritance
|
|
69
|
+
applyExtend(element, parent, options)
|
|
70
|
+
}
|
|
69
71
|
|
|
70
72
|
// create and assign a KEY
|
|
71
73
|
element.key = key
|
|
@@ -81,8 +83,18 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
81
83
|
|
|
82
84
|
addMethods(element, parent)
|
|
83
85
|
|
|
86
|
+
createScope(element, parent)
|
|
87
|
+
|
|
84
88
|
createState(element, parent)
|
|
89
|
+
if (element.scope === 'state') element.scope = element.state
|
|
90
|
+
|
|
91
|
+
createIfConditionFlag(element, parent)
|
|
92
|
+
|
|
93
|
+
// apply props settings
|
|
94
|
+
createProps(element, parent)
|
|
95
|
+
if (element.scope === 'props' || element.scope === true) element.scope = element.props
|
|
85
96
|
|
|
97
|
+
// recatch if it passess props again
|
|
86
98
|
createIfConditionFlag(element, parent)
|
|
87
99
|
|
|
88
100
|
// if it already HAS a NODE
|
|
@@ -90,9 +102,6 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
90
102
|
return assignNode(element, parent, key)
|
|
91
103
|
}
|
|
92
104
|
|
|
93
|
-
// apply props settings
|
|
94
|
-
createProps(element, parent)
|
|
95
|
-
|
|
96
105
|
// apply variants
|
|
97
106
|
applyVariant(element, parent)
|
|
98
107
|
|
|
@@ -233,6 +242,11 @@ const applyContext = (element, parent, options) => {
|
|
|
233
242
|
if (!element.context) element.context = parent.context || options.context || ROOT.context
|
|
234
243
|
}
|
|
235
244
|
|
|
245
|
+
const createScope = (element, parent) => {
|
|
246
|
+
const { __ref: ref } = element
|
|
247
|
+
if (!element.scope) element.scope = parent.scope || ref.__root.scope || {}
|
|
248
|
+
}
|
|
249
|
+
|
|
236
250
|
const createIfConditionFlag = (element, parent) => {
|
|
237
251
|
const { __ref: ref } = element
|
|
238
252
|
|
|
@@ -287,20 +301,13 @@ const addCaching = (element, parent) => {
|
|
|
287
301
|
}
|
|
288
302
|
|
|
289
303
|
const onlyResolveExtends = (element, parent, key, options) => {
|
|
290
|
-
const { __ref } = element
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
// if (!element.props) element.props = {}
|
|
294
|
-
|
|
295
|
-
// Copy-paste of addCaching()
|
|
296
|
-
{
|
|
297
|
-
const { __ref: ref } = element
|
|
298
|
-
const { __ref: parentRef } = parent // eslint-disable-line
|
|
304
|
+
const { __ref: ref } = element
|
|
305
|
+
if (!ref.__skipCreate) {
|
|
306
|
+
element.tag = detectTag(element)
|
|
299
307
|
|
|
300
|
-
//
|
|
301
|
-
// TODO: do we need this at all?
|
|
302
|
-
// if (!element.transform) element.transform = {}
|
|
308
|
+
// if (!element.props) element.props = {}
|
|
303
309
|
|
|
310
|
+
// Copy-paste of addCaching()
|
|
304
311
|
// enable CACHING
|
|
305
312
|
if (!ref.__cached) ref.__cached = {}
|
|
306
313
|
if (!ref.__defineCache) ref.__defineCache = {}
|
|
@@ -324,29 +331,28 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
324
331
|
// Add __root element property
|
|
325
332
|
// const hasRoot = parent && parent.key === ':root'
|
|
326
333
|
// if (!ref.__root) ref.__root = hasRoot ? element : parentRef.__root
|
|
327
|
-
}
|
|
328
334
|
|
|
329
|
-
|
|
335
|
+
addMethods(element, parent)
|
|
330
336
|
|
|
331
|
-
|
|
337
|
+
createState(element, parent)
|
|
332
338
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
// Borrowed from createIfConditionFlag()
|
|
340
|
+
if (isFunction(element.if)) {
|
|
341
|
+
const ifPassed = element.if(element, element.state)
|
|
342
|
+
if (!ifPassed) {
|
|
343
|
+
// const ifFragment = cacheNode({ tag: 'fragment' })
|
|
344
|
+
// ref.__ifFragment = appendNode(ifFragment, parent.node)
|
|
345
|
+
delete ref.__if
|
|
346
|
+
} else ref.__if = true
|
|
341
347
|
} else ref.__if = true
|
|
342
|
-
|
|
343
|
-
/// ///
|
|
348
|
+
/// ///
|
|
344
349
|
|
|
345
|
-
|
|
350
|
+
if (element.node && ref.__if) { parent[key || element.key] = element } // Borrowed from assignNode()
|
|
346
351
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
352
|
+
createProps(element, parent)
|
|
353
|
+
if (!element.props) element.props = {}
|
|
354
|
+
applyVariant(element, parent)
|
|
355
|
+
}
|
|
350
356
|
|
|
351
357
|
if (element.tag !== 'string' && element.tag !== 'fragment') {
|
|
352
358
|
throughInitialDefine(element)
|
|
@@ -365,7 +371,7 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
365
371
|
element.context.define[k]
|
|
366
372
|
const optionsHasDefine = options.define && options.define[k]
|
|
367
373
|
|
|
368
|
-
if (registry[k] && !optionsHasDefine) {
|
|
374
|
+
if (!ref.__skipCreate && registry[k] && !optionsHasDefine) {
|
|
369
375
|
continue
|
|
370
376
|
} else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
|
|
371
377
|
create(exec(element[k], element), element, k, options)
|
package/dist/cjs/create.js
CHANGED
|
@@ -60,7 +60,9 @@ const create = (element, parent, key, options = import_options.default.create ||
|
|
|
60
60
|
ref.__initialProps = (0, import_utils.deepClone)(element.props, []);
|
|
61
61
|
applyContext(element, parent, options);
|
|
62
62
|
(0, import_component.applyComponentFromContext)(element, parent, options);
|
|
63
|
-
(
|
|
63
|
+
if (!ref.__skipCreate) {
|
|
64
|
+
(0, import_extend.applyExtend)(element, parent, options);
|
|
65
|
+
}
|
|
64
66
|
element.key = key;
|
|
65
67
|
if (options.onlyResolveExtends) {
|
|
66
68
|
return onlyResolveExtends(element, parent, key, options);
|
|
@@ -68,12 +70,18 @@ const create = (element, parent, key, options = import_options.default.create ||
|
|
|
68
70
|
replaceOptions(element, parent, options);
|
|
69
71
|
addCaching(element, parent);
|
|
70
72
|
(0, import_set.addMethods)(element, parent);
|
|
73
|
+
createScope(element, parent);
|
|
71
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;
|
|
72
81
|
createIfConditionFlag(element, parent);
|
|
73
82
|
if (element.node && ref.__if) {
|
|
74
83
|
return (0, import_render.assignNode)(element, parent, key);
|
|
75
84
|
}
|
|
76
|
-
(0, import_props.createProps)(element, parent);
|
|
77
85
|
(0, import_component.applyVariant)(element, parent);
|
|
78
86
|
const onInit = (0, import_event.triggerEventOn)("init", element, options);
|
|
79
87
|
if (onInit === false)
|
|
@@ -180,6 +188,11 @@ const applyContext = (element, parent, options) => {
|
|
|
180
188
|
if (!element.context)
|
|
181
189
|
element.context = parent.context || options.context || import_tree.ROOT.context;
|
|
182
190
|
};
|
|
191
|
+
const createScope = (element, parent) => {
|
|
192
|
+
const { __ref: ref } = element;
|
|
193
|
+
if (!element.scope)
|
|
194
|
+
element.scope = parent.scope || ref.__root.scope || {};
|
|
195
|
+
};
|
|
183
196
|
const createIfConditionFlag = (element, parent) => {
|
|
184
197
|
const { __ref: ref } = element;
|
|
185
198
|
if ((0, import_utils.isFunction)(element.if)) {
|
|
@@ -226,46 +239,43 @@ const addCaching = (element, parent) => {
|
|
|
226
239
|
}
|
|
227
240
|
};
|
|
228
241
|
const onlyResolveExtends = (element, parent, key, options) => {
|
|
229
|
-
const { __ref } = element;
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (!
|
|
235
|
-
|
|
236
|
-
if (!
|
|
237
|
-
|
|
238
|
-
if (!
|
|
239
|
-
|
|
240
|
-
if (!
|
|
241
|
-
|
|
242
|
-
if (!
|
|
243
|
-
|
|
244
|
-
if (!
|
|
245
|
-
|
|
246
|
-
if (!
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (!ifPassed) {
|
|
257
|
-
delete ref.__if;
|
|
242
|
+
const { __ref: ref } = element;
|
|
243
|
+
if (!ref.__skipCreate) {
|
|
244
|
+
element.tag = (0, import_render.detectTag)(element);
|
|
245
|
+
if (!ref.__cached)
|
|
246
|
+
ref.__cached = {};
|
|
247
|
+
if (!ref.__defineCache)
|
|
248
|
+
ref.__defineCache = {};
|
|
249
|
+
if (!ref.__exec)
|
|
250
|
+
ref.__exec = {};
|
|
251
|
+
if (!ref.__class)
|
|
252
|
+
ref.__class = {};
|
|
253
|
+
if (!ref.__classNames)
|
|
254
|
+
ref.__classNames = {};
|
|
255
|
+
if (!ref.__attr)
|
|
256
|
+
ref.__attr = {};
|
|
257
|
+
if (!ref.__changes)
|
|
258
|
+
ref.__changes = [];
|
|
259
|
+
if (!ref.__children)
|
|
260
|
+
ref.__children = [];
|
|
261
|
+
(0, import_set.addMethods)(element, parent);
|
|
262
|
+
(0, import_state.createState)(element, parent);
|
|
263
|
+
if ((0, import_utils.isFunction)(element.if)) {
|
|
264
|
+
const ifPassed = element.if(element, element.state);
|
|
265
|
+
if (!ifPassed) {
|
|
266
|
+
delete ref.__if;
|
|
267
|
+
} else
|
|
268
|
+
ref.__if = true;
|
|
258
269
|
} else
|
|
259
270
|
ref.__if = true;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
271
|
+
if (element.node && ref.__if) {
|
|
272
|
+
parent[key || element.key] = element;
|
|
273
|
+
}
|
|
274
|
+
(0, import_props.createProps)(element, parent);
|
|
275
|
+
if (!element.props)
|
|
276
|
+
element.props = {};
|
|
277
|
+
(0, import_component.applyVariant)(element, parent);
|
|
264
278
|
}
|
|
265
|
-
(0, import_props.createProps)(element, parent);
|
|
266
|
-
if (!element.props)
|
|
267
|
-
element.props = {};
|
|
268
|
-
(0, import_component.applyVariant)(element, parent);
|
|
269
279
|
if (element.tag !== "string" && element.tag !== "fragment") {
|
|
270
280
|
(0, import_iterate.throughInitialDefine)(element);
|
|
271
281
|
(0, import_iterate.throughInitialExec)(element);
|
|
@@ -275,7 +285,7 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
275
285
|
const hasDefine = element.define && element.define[k];
|
|
276
286
|
const contextHasDefine = element.context && element.context.define && element.context.define[k];
|
|
277
287
|
const optionsHasDefine = options.define && options.define[k];
|
|
278
|
-
if (import_mixins.registry[k] && !optionsHasDefine) {
|
|
288
|
+
if (!ref.__skipCreate && import_mixins.registry[k] && !optionsHasDefine) {
|
|
279
289
|
continue;
|
|
280
290
|
} else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
|
|
281
291
|
create((0, import_utils.exec)(element[k], element), element, k, options);
|
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/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) {
|
|
@@ -48,8 +48,8 @@ const addAdditionalExtend = (newExtend, element) => {
|
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
50
|
const extendizeByKey = (element, parent, key) => {
|
|
51
|
-
const {
|
|
52
|
-
const hasComponentAttrs =
|
|
51
|
+
const { extend, props, state, childExtend, childProps, on, if: condition } = element;
|
|
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) {
|
|
@@ -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,11 +122,9 @@ 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
|
-
console.log("extend", extend);
|
|
128
|
-
console.log(COMPONENTS[extend]);
|
|
129
128
|
if (COMPONENTS && COMPONENTS[extend]) {
|
|
130
129
|
return COMPONENTS[extend];
|
|
131
130
|
} else {
|
|
@@ -140,29 +139,15 @@ const fallbackStringExtend = (extend, context, options) => {
|
|
|
140
139
|
const jointStacks = (extendStack, childExtendStack) => {
|
|
141
140
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendStack.slice(1));
|
|
142
141
|
};
|
|
143
|
-
const getExtendStack = (extend) => {
|
|
142
|
+
const getExtendStack = (extend, context) => {
|
|
144
143
|
if (!extend)
|
|
145
144
|
return [];
|
|
146
145
|
if (extend.__hash)
|
|
147
146
|
return getHashedExtend(extend) || [];
|
|
148
|
-
const stack = flattenExtend(extend, []);
|
|
147
|
+
const stack = flattenExtend(extend, [], context);
|
|
149
148
|
return getExtendStackRegistry(extend, stack);
|
|
150
149
|
};
|
|
151
150
|
const getExtendMerged = (extend) => {
|
|
152
151
|
const stack = getExtendStack(extend);
|
|
153
152
|
return cloneAndMergeArrayExtend(stack);
|
|
154
153
|
};
|
|
155
|
-
const replaceStringsWithComponents = (stack, context, options) => {
|
|
156
|
-
const COMPONENTS = context && context.components || options.components;
|
|
157
|
-
return stack.map((v) => {
|
|
158
|
-
if ((0, import_utils.isString)(v)) {
|
|
159
|
-
const component = COMPONENTS[v];
|
|
160
|
-
return component;
|
|
161
|
-
}
|
|
162
|
-
if ((0, import_utils.isString)(v.extend)) {
|
|
163
|
-
v.extend = COMPONENTS[v.extend];
|
|
164
|
-
return { ...getExtendMerged(v.extend), ...v };
|
|
165
|
-
}
|
|
166
|
-
return v;
|
|
167
|
-
});
|
|
168
|
-
};
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.18",
|
|
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": "4aeead0b153d4cd5430694ecf45a5d3052f9f9f5",
|
|
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
|
@@ -21,8 +21,8 @@ export const addAdditionalExtend = (newExtend, element) => {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const extendizeByKey = (element, parent, key) => {
|
|
24
|
-
const {
|
|
25
|
-
const hasComponentAttrs =
|
|
24
|
+
const { extend, props, state, childExtend, childProps, on, if: condition } = element
|
|
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
|
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,11 +90,9 @@ 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
|
-
console.log('extend', extend)
|
|
96
|
-
console.log(COMPONENTS[extend])
|
|
97
96
|
if (COMPONENTS && COMPONENTS[extend]) {
|
|
98
97
|
return COMPONENTS[extend]
|
|
99
98
|
} else {
|
|
@@ -116,10 +115,10 @@ export const jointStacks = (extendStack, childExtendStack) => {
|
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
// init
|
|
119
|
-
export const getExtendStack = extend => {
|
|
118
|
+
export const getExtendStack = (extend, context) => {
|
|
120
119
|
if (!extend) return []
|
|
121
120
|
if (extend.__hash) return getHashedExtend(extend) || []
|
|
122
|
-
const stack = flattenExtend(extend, [])
|
|
121
|
+
const stack = flattenExtend(extend, [], context)
|
|
123
122
|
return getExtendStackRegistry(extend, stack)
|
|
124
123
|
}
|
|
125
124
|
|
|
@@ -128,17 +127,16 @@ export const getExtendMerged = extend => {
|
|
|
128
127
|
return cloneAndMergeArrayExtend(stack)
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
export const replaceStringsWithComponents = (stack, context, options) => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
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
|
+
// }
|