@domql/element 2.5.47 → 2.5.48
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 +9 -6
- package/dist/cjs/create.js +5 -6
- package/dist/cjs/node.js +1 -1
- package/dist/cjs/update.js +1 -1
- package/dist/cjs/{applyParam.js → utils/applyParam.js} +1 -1
- package/dist/cjs/utils/component.js +30 -0
- package/dist/cjs/{onlyResolveExtends.js → utils/onlyResolveExtends.js} +9 -9
- package/node.js +1 -1
- package/package.json +2 -2
- package/update.js +1 -1
- package/{applyParam.js → utils/applyParam.js} +1 -1
- package/utils/component.js +32 -3
- package/{onlyResolveExtends.js → utils/onlyResolveExtends.js} +7 -7
package/create.js
CHANGED
|
@@ -79,7 +79,7 @@ const create = (element, parent, key, options = OPTIONS.create || {}, attachOpti
|
|
|
79
79
|
return onlyResolveExtends(element, parent, key, options)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
switchDefaultOptions(element, parent, options)
|
|
83
83
|
|
|
84
84
|
addCaching(element, parent)
|
|
85
85
|
|
|
@@ -196,7 +196,7 @@ const addRef = (element, parent) => {
|
|
|
196
196
|
return element.__ref
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
const
|
|
199
|
+
const switchDefaultOptions = (element, parent, options) => {
|
|
200
200
|
if (Object.keys(options).length) {
|
|
201
201
|
registry.defaultOptions = options
|
|
202
202
|
if (options.ignoreChildExtend) delete options.ignoreChildExtend
|
|
@@ -228,9 +228,7 @@ const renderElement = (element, parent, options, attachOptions) => {
|
|
|
228
228
|
triggerEventOn('render', element, options)
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
const checkIfPrimitive = (element) =>
|
|
232
|
-
return is(element)('string', 'number')
|
|
233
|
-
}
|
|
231
|
+
const checkIfPrimitive = (element) => is(element)('string', 'number')
|
|
234
232
|
|
|
235
233
|
const applyValueAsText = (element, parent, key) => {
|
|
236
234
|
const extendTag = element.extend && element.extend.tag
|
|
@@ -243,12 +241,17 @@ const applyValueAsText = (element, parent, key) => {
|
|
|
243
241
|
}
|
|
244
242
|
|
|
245
243
|
const applyContext = (element, parent, options) => {
|
|
246
|
-
|
|
244
|
+
const forcedOptionsContext = options.context && !ROOT.context && !element.context
|
|
245
|
+
if (forcedOptionsContext) ROOT.context = options.context
|
|
246
|
+
|
|
247
|
+
// inherit from parent or root
|
|
247
248
|
if (!element.context) element.context = parent.context || options.context || ROOT.context
|
|
248
249
|
}
|
|
249
250
|
|
|
251
|
+
// Create scope - shared object across the elements to the own or the nearest parent
|
|
250
252
|
const createScope = (element, parent) => {
|
|
251
253
|
const { __ref: ref } = element
|
|
254
|
+
// If the element doesn't have a scope, initialize it using the parent's scope or the root's scope.
|
|
252
255
|
if (!element.scope) element.scope = parent.scope || ref.__root.scope || {}
|
|
253
256
|
}
|
|
254
257
|
|
package/dist/cjs/create.js
CHANGED
|
@@ -67,7 +67,7 @@ const create = (element, parent, key, options = import_options.default.create ||
|
|
|
67
67
|
if (options.onlyResolveExtends) {
|
|
68
68
|
return onlyResolveExtends(element, parent, key, options);
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
switchDefaultOptions(element, parent, options);
|
|
71
71
|
addCaching(element, parent);
|
|
72
72
|
(0, import_set.addMethods)(element, parent);
|
|
73
73
|
createScope(element, parent);
|
|
@@ -150,7 +150,7 @@ const addRef = (element, parent) => {
|
|
|
150
150
|
element.__ref = { origin: element };
|
|
151
151
|
return element.__ref;
|
|
152
152
|
};
|
|
153
|
-
const
|
|
153
|
+
const switchDefaultOptions = (element, parent, options) => {
|
|
154
154
|
if (Object.keys(options).length) {
|
|
155
155
|
import_mixins.registry.defaultOptions = options;
|
|
156
156
|
if (options.ignoreChildExtend)
|
|
@@ -172,9 +172,7 @@ const renderElement = (element, parent, options, attachOptions) => {
|
|
|
172
172
|
(0, import_event.triggerEventOn)("renderRouter", element, options);
|
|
173
173
|
(0, import_event.triggerEventOn)("render", element, options);
|
|
174
174
|
};
|
|
175
|
-
const checkIfPrimitive = (element) =>
|
|
176
|
-
return (0, import_utils.is)(element)("string", "number");
|
|
177
|
-
};
|
|
175
|
+
const checkIfPrimitive = (element) => (0, import_utils.is)(element)("string", "number");
|
|
178
176
|
const applyValueAsText = (element, parent, key) => {
|
|
179
177
|
const extendTag = element.extend && element.extend.tag;
|
|
180
178
|
const childExtendTag = parent.childExtend && parent.childExtend.tag;
|
|
@@ -185,7 +183,8 @@ const applyValueAsText = (element, parent, key) => {
|
|
|
185
183
|
};
|
|
186
184
|
};
|
|
187
185
|
const applyContext = (element, parent, options) => {
|
|
188
|
-
|
|
186
|
+
const forcedOptionsContext = options.context && !import_tree.ROOT.context && !element.context;
|
|
187
|
+
if (forcedOptionsContext)
|
|
189
188
|
import_tree.ROOT.context = options.context;
|
|
190
189
|
if (!element.context)
|
|
191
190
|
element.context = parent.context || options.context || import_tree.ROOT.context;
|
package/dist/cjs/node.js
CHANGED
|
@@ -39,7 +39,7 @@ var import_methods = require("./methods");
|
|
|
39
39
|
var import_create = __toESM(require("./create"), 1);
|
|
40
40
|
var import_iterate = require("./iterate");
|
|
41
41
|
var import_mixins = require("./mixins");
|
|
42
|
-
var import_applyParam = require("./applyParam");
|
|
42
|
+
var import_applyParam = require("./utils/applyParam");
|
|
43
43
|
var import_utils2 = require("./utils");
|
|
44
44
|
const ENV = "development";
|
|
45
45
|
const createNode = (element, options) => {
|
package/dist/cjs/update.js
CHANGED
|
@@ -40,7 +40,7 @@ var import_utils2 = require("./utils");
|
|
|
40
40
|
var import_create = __toESM(require("./create"), 1);
|
|
41
41
|
var import_iterate = require("./iterate");
|
|
42
42
|
var import_mixins = require("./mixins");
|
|
43
|
-
var import_applyParam = require("./applyParam");
|
|
43
|
+
var import_applyParam = require("./utils/applyParam");
|
|
44
44
|
var import_options = __toESM(require("./cache/options"), 1);
|
|
45
45
|
const snapshot = {
|
|
46
46
|
snapshotId: import_utils.createSnapshotId
|
|
@@ -22,7 +22,7 @@ __export(applyParam_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(applyParam_exports);
|
|
24
24
|
var import_utils = require("@domql/utils");
|
|
25
|
-
var import_mixins = require("
|
|
25
|
+
var import_mixins = require("../mixins");
|
|
26
26
|
const applyParam = (param, element, options) => {
|
|
27
27
|
const { node, context, __ref: ref } = element;
|
|
28
28
|
const prop = element[param];
|
|
@@ -23,6 +23,8 @@ __export(component_exports, {
|
|
|
23
23
|
applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
|
|
24
24
|
applyVariant: () => applyVariant,
|
|
25
25
|
checkIfKeyIsComponent: () => checkIfKeyIsComponent,
|
|
26
|
+
checkIfKeyIsProperty: () => checkIfKeyIsProperty,
|
|
27
|
+
createValidDomqlObjectFromSugar: () => createValidDomqlObjectFromSugar,
|
|
26
28
|
extendizeByKey: () => extendizeByKey,
|
|
27
29
|
hasVariantProp: () => hasVariantProp,
|
|
28
30
|
isVariant: () => isVariant,
|
|
@@ -32,6 +34,7 @@ module.exports = __toCommonJS(component_exports);
|
|
|
32
34
|
var import_utils = require("@domql/utils");
|
|
33
35
|
var import_extend = require("../extend");
|
|
34
36
|
const ENV = "development";
|
|
37
|
+
const DOMQL_BUILTINS = ["extend", "childExtend", "childExtendRecursive", "define", "props", "state", "on", "if", "attr", "key", "tag"];
|
|
35
38
|
const checkIfKeyIsComponent = (key) => {
|
|
36
39
|
const isFirstKeyString = (0, import_utils.isString)(key);
|
|
37
40
|
if (!isFirstKeyString)
|
|
@@ -39,6 +42,13 @@ const checkIfKeyIsComponent = (key) => {
|
|
|
39
42
|
const firstCharKey = key.slice(0, 1);
|
|
40
43
|
return /^[A-Z]*$/.test(firstCharKey);
|
|
41
44
|
};
|
|
45
|
+
const checkIfKeyIsProperty = (key) => {
|
|
46
|
+
const isFirstKeyString = (0, import_utils.isString)(key);
|
|
47
|
+
if (!isFirstKeyString)
|
|
48
|
+
return;
|
|
49
|
+
const firstCharKey = key.slice(0, 1);
|
|
50
|
+
return /^[a-z]*$/.test(firstCharKey);
|
|
51
|
+
};
|
|
42
52
|
const addAdditionalExtend = (newExtend, element) => {
|
|
43
53
|
const { extend: elementExtend } = element;
|
|
44
54
|
const originalArray = (0, import_utils.isArray)(elementExtend) ? elementExtend : [elementExtend];
|
|
@@ -46,6 +56,26 @@ const addAdditionalExtend = (newExtend, element) => {
|
|
|
46
56
|
const extend = (0, import_utils.joinArrays)(receivedArray, originalArray);
|
|
47
57
|
return { ...element, extend };
|
|
48
58
|
};
|
|
59
|
+
const replaceOnKeys = (key) => key.replace(/on\w+/g, (match) => match.substring(2));
|
|
60
|
+
const createValidDomqlObjectFromSugar = (el) => {
|
|
61
|
+
const newElem = {
|
|
62
|
+
props: {},
|
|
63
|
+
on: {}
|
|
64
|
+
};
|
|
65
|
+
for (const k in el) {
|
|
66
|
+
const prop = el[k];
|
|
67
|
+
const isEvent = prop.startsWith("on");
|
|
68
|
+
const isMethod = prop.startsWith("$");
|
|
69
|
+
if (isEvent) {
|
|
70
|
+
const onKey = replaceOnKeys(prop);
|
|
71
|
+
newElem.on[onKey] = prop;
|
|
72
|
+
} else if (!isMethod && checkIfKeyIsProperty(k)) {
|
|
73
|
+
if (!DOMQL_BUILTINS.includes(k))
|
|
74
|
+
newElem.props[k] = prop;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return newElem;
|
|
78
|
+
};
|
|
49
79
|
const extendizeByKey = (element, parent, key) => {
|
|
50
80
|
const { context, tag, extend, props, attr, state, childExtend, childProps, on, if: condition } = element;
|
|
51
81
|
const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr;
|
|
@@ -22,15 +22,15 @@ __export(onlyResolveExtends_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(onlyResolveExtends_exports);
|
|
24
24
|
var import_utils = require("@domql/utils");
|
|
25
|
-
var import__ = require("
|
|
26
|
-
var import_mixins = require("
|
|
27
|
-
var
|
|
28
|
-
var import_methods = require("
|
|
29
|
-
var import_set = require("
|
|
25
|
+
var import__ = require("..");
|
|
26
|
+
var import_mixins = require("../mixins");
|
|
27
|
+
var import__2 = require(".");
|
|
28
|
+
var import_methods = require("../methods");
|
|
29
|
+
var import_set = require("../methods/set");
|
|
30
30
|
var import_state = require("@domql/state");
|
|
31
31
|
var import_render = require("@domql/render");
|
|
32
|
-
var import_props = require("
|
|
33
|
-
var import_iterate = require("
|
|
32
|
+
var import_props = require("../props");
|
|
33
|
+
var import_iterate = require("../iterate");
|
|
34
34
|
const onlyResolveExtends = (element, parent, key, options) => {
|
|
35
35
|
const { __ref } = element;
|
|
36
36
|
element.tag = (0, import_render.detectTag)(element);
|
|
@@ -68,13 +68,13 @@ const onlyResolveExtends = (element, parent, key, options) => {
|
|
|
68
68
|
parent[key || element.key] = element;
|
|
69
69
|
}
|
|
70
70
|
(0, import_props.createProps)(element, parent);
|
|
71
|
-
(0,
|
|
71
|
+
(0, import__2.applyVariant)(element, parent);
|
|
72
72
|
if (element.tag !== "string" && element.tag !== "fragment") {
|
|
73
73
|
(0, import_iterate.throughInitialDefine)(element);
|
|
74
74
|
(0, import_iterate.throughInitialExec)(element);
|
|
75
75
|
for (const param in element) {
|
|
76
76
|
const prop = element[param];
|
|
77
|
-
if ((0, import_utils.isUndefined)(prop) || (0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || (0,
|
|
77
|
+
if ((0, import_utils.isUndefined)(prop) || (0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || (0, import__2.isVariant)(param))
|
|
78
78
|
continue;
|
|
79
79
|
const hasDefine = element.define && element.define[param];
|
|
80
80
|
const contextHasDefine = element.context && element.context.define && element.context.define[param];
|
package/node.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
throughInitialExec
|
|
13
13
|
} from './iterate'
|
|
14
14
|
import { registry } from './mixins'
|
|
15
|
-
import { applyParam } from './applyParam'
|
|
15
|
+
import { applyParam } from './utils/applyParam'
|
|
16
16
|
import { isVariant } from './utils'
|
|
17
17
|
// import { defineSetter } from './methods'
|
|
18
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.48",
|
|
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": "68ea5ab143d09bdb009664526b638e7c804480c6",
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/core": "^7.12.0"
|
|
37
37
|
}
|
package/update.js
CHANGED
|
@@ -23,7 +23,7 @@ import { METHODS_EXL, isVariant } from './utils'
|
|
|
23
23
|
import create from './create'
|
|
24
24
|
import { throughUpdatedDefine, throughUpdatedExec } from './iterate'
|
|
25
25
|
import { registry } from './mixins'
|
|
26
|
-
import { applyParam } from './applyParam'
|
|
26
|
+
import { applyParam } from './utils/applyParam'
|
|
27
27
|
import OPTIONS from './cache/options'
|
|
28
28
|
|
|
29
29
|
const snapshot = {
|
package/utils/component.js
CHANGED
|
@@ -4,12 +4,20 @@ import { exec, isArray, isFunction, isObject, isString, joinArrays, overwriteDee
|
|
|
4
4
|
import { applyExtend } from '../extend'
|
|
5
5
|
const ENV = process.env.NODE_ENV
|
|
6
6
|
|
|
7
|
+
const DOMQL_BUILTINS = ['extend', 'childExtend', 'childExtendRecursive', 'define', 'props', 'state', 'on', 'if', 'attr', 'key', 'tag']
|
|
8
|
+
|
|
7
9
|
export const checkIfKeyIsComponent = (key) => {
|
|
8
10
|
const isFirstKeyString = isString(key)
|
|
9
11
|
if (!isFirstKeyString) return
|
|
10
12
|
const firstCharKey = key.slice(0, 1)
|
|
11
13
|
return /^[A-Z]*$/.test(firstCharKey)
|
|
12
14
|
}
|
|
15
|
+
export const checkIfKeyIsProperty = (key) => {
|
|
16
|
+
const isFirstKeyString = isString(key)
|
|
17
|
+
if (!isFirstKeyString) return
|
|
18
|
+
const firstCharKey = key.slice(0, 1)
|
|
19
|
+
return /^[a-z]*$/.test(firstCharKey)
|
|
20
|
+
}
|
|
13
21
|
|
|
14
22
|
export const addAdditionalExtend = (newExtend, element) => {
|
|
15
23
|
const { extend: elementExtend } = element
|
|
@@ -19,16 +27,37 @@ export const addAdditionalExtend = (newExtend, element) => {
|
|
|
19
27
|
return { ...element, extend }
|
|
20
28
|
}
|
|
21
29
|
|
|
30
|
+
const replaceOnKeys = key => key.replace(/on\w+/g, match => match.substring(2))
|
|
31
|
+
|
|
32
|
+
export const createValidDomqlObjectFromSugar = el => {
|
|
33
|
+
const newElem = {
|
|
34
|
+
props: {},
|
|
35
|
+
on: {}
|
|
36
|
+
}
|
|
37
|
+
for (const k in el) {
|
|
38
|
+
const prop = el[k]
|
|
39
|
+
const isEvent = prop.startsWith('on')
|
|
40
|
+
const isMethod = prop.startsWith('$')
|
|
41
|
+
if (isEvent) {
|
|
42
|
+
const onKey = replaceOnKeys(prop)
|
|
43
|
+
newElem.on[onKey] = prop
|
|
44
|
+
} else if (!isMethod && checkIfKeyIsProperty(k)) {
|
|
45
|
+
if (!DOMQL_BUILTINS.includes(k)) newElem.props[k] = prop
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return newElem
|
|
49
|
+
}
|
|
50
|
+
|
|
22
51
|
export const extendizeByKey = (element, parent, key) => {
|
|
23
52
|
const { context, tag, extend, props, attr, state, childExtend, childProps, on, if: condition } = element
|
|
24
53
|
const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr
|
|
25
54
|
|
|
26
55
|
const extendFromKey = key.includes('+')
|
|
27
|
-
? key.split('+')
|
|
56
|
+
? key.split('+') // get array of componentKeys
|
|
28
57
|
: key.includes('_')
|
|
29
|
-
? key.split('_')[0]
|
|
58
|
+
? key.split('_')[0] // get component key split _
|
|
30
59
|
: key.includes('.')
|
|
31
|
-
? key.split('.')[0]
|
|
60
|
+
? key.split('.')[0] // get component key split .
|
|
32
61
|
: [key]
|
|
33
62
|
|
|
34
63
|
const isExtendKeyComponent = context?.components[extendFromKey]
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { exec, isFunction, isObject, isUndefined } from '@domql/utils'
|
|
4
|
-
import { create } from '
|
|
5
|
-
import { registry } from '
|
|
6
|
-
import { applyVariant, isVariant } from '
|
|
7
|
-
import { isMethod } from '
|
|
8
|
-
import { addMethods } from '
|
|
4
|
+
import { create } from '..'
|
|
5
|
+
import { registry } from '../mixins'
|
|
6
|
+
import { applyVariant, isVariant } from '.'
|
|
7
|
+
import { isMethod } from '../methods'
|
|
8
|
+
import { addMethods } from '../methods/set'
|
|
9
9
|
import { createState } from '@domql/state'
|
|
10
10
|
import { detectTag } from '@domql/render'
|
|
11
|
-
import { createProps } from '
|
|
12
|
-
import { throughInitialDefine, throughInitialExec } from '
|
|
11
|
+
import { createProps } from '../props'
|
|
12
|
+
import { throughInitialDefine, throughInitialExec } from '../iterate'
|
|
13
13
|
|
|
14
14
|
export const onlyResolveExtends = (element, parent, key, options) => {
|
|
15
15
|
const { __ref } = element
|