@domql/element 2.3.117 → 2.4.0
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/LICENSE +1 -1
- package/applyParam.js +25 -0
- package/create.js +314 -0
- package/define.js +13 -0
- package/dist/cjs/applyParam.js +41 -0
- package/dist/cjs/create.js +262 -0
- package/dist/cjs/define.js +34 -0
- package/dist/cjs/extend.js +87 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/iterate.js +108 -0
- package/dist/cjs/node.js +85 -0
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/set.js +58 -0
- package/dist/cjs/tree.js +31 -0
- package/dist/cjs/update.js +223 -0
- package/extend.js +87 -0
- package/index.js +15 -5
- package/iterate.js +94 -0
- package/node.js +84 -0
- package/package.json +31 -9
- package/set.js +31 -0
- package/tree.js +11 -0
- package/update.js +225 -0
package/LICENSE
CHANGED
package/applyParam.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isFunction } from '@domql/utils'
|
|
4
|
+
import { registry } from './mixins'
|
|
5
|
+
|
|
6
|
+
export const applyParam = (param, element, options) => {
|
|
7
|
+
const { node, context } = element
|
|
8
|
+
const prop = element[param]
|
|
9
|
+
|
|
10
|
+
const DOMQLProperty = registry[param]
|
|
11
|
+
const DOMQLPropertyFromContext = context && context.registry && context.registry[param]
|
|
12
|
+
const isGlobalTransformer = DOMQLPropertyFromContext || DOMQLProperty
|
|
13
|
+
|
|
14
|
+
const hasDefine = element.define && element.define[param]
|
|
15
|
+
const hasContextDefine = context && context.define && context.define[param]
|
|
16
|
+
|
|
17
|
+
if (isGlobalTransformer && !hasContextDefine) {
|
|
18
|
+
if (isFunction(isGlobalTransformer)) {
|
|
19
|
+
isGlobalTransformer(prop, element, node, options)
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { hasDefine, hasContextDefine }
|
|
25
|
+
}
|
package/create.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isObject, isFunction, isString, exec, is, isNode, isUndefined, createKey } from '@domql/utils'
|
|
4
|
+
import { ROOT } from './tree'
|
|
5
|
+
import { TAGS } from '@domql/registry'
|
|
6
|
+
import { triggerEventOn } from '@domql/event'
|
|
7
|
+
import { appendNode, assignNode } from '@domql/render'
|
|
8
|
+
import { assignClass } from '@domql/classlist'
|
|
9
|
+
import { cacheNode, detectTag } from '@domql/node'
|
|
10
|
+
import { createState } from '@domql/state'
|
|
11
|
+
|
|
12
|
+
import { isMethod } from './methods'
|
|
13
|
+
|
|
14
|
+
import { createProps } from './props'
|
|
15
|
+
|
|
16
|
+
import createNode from './node'
|
|
17
|
+
import { applyExtend } from './extend'
|
|
18
|
+
import { registry } from './mixins'
|
|
19
|
+
import { throughInitialExec } from './iterate'
|
|
20
|
+
import OPTIONS from './cache/options'
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
applyComponentFromContext,
|
|
24
|
+
applyKeyComponentAsExtend,
|
|
25
|
+
applyVariant,
|
|
26
|
+
checkIfKeyIsComponent,
|
|
27
|
+
isVariant
|
|
28
|
+
} from './utils/component'
|
|
29
|
+
import { addMethods } from './methods/set'
|
|
30
|
+
|
|
31
|
+
const ENV = process.env.NODE_ENV
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creating a domQL element using passed parameters
|
|
35
|
+
*/
|
|
36
|
+
const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
37
|
+
if (options && !OPTIONS.create) {
|
|
38
|
+
OPTIONS.create = options
|
|
39
|
+
OPTIONS.create.context = element.context || options.context
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// if ELEMENT is not given
|
|
43
|
+
if (element === undefined) {
|
|
44
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
45
|
+
console.warn(key, 'element is undefined in', parent && parent.__ref && parent.__ref.path)
|
|
46
|
+
}
|
|
47
|
+
element = {}
|
|
48
|
+
}
|
|
49
|
+
if (isString(key) && key.slice(0, 2 === '__')) {
|
|
50
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
51
|
+
console.warn(key, 'seems like to be in __ref')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (element === null) return
|
|
55
|
+
if (element === true) element = { text: true }
|
|
56
|
+
|
|
57
|
+
// if element is extend
|
|
58
|
+
if (element.__hash) {
|
|
59
|
+
element = { extend: element }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// if PARENT is not given
|
|
63
|
+
if (!parent) parent = ROOT
|
|
64
|
+
if (isNode(parent)) {
|
|
65
|
+
parent = ROOT[`${key}_parent`] = { key: ':root', node: parent }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// if element is STRING
|
|
69
|
+
if (checkIfPrimitive(element)) {
|
|
70
|
+
element = applyValueAsText(element, parent, key)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// define KEY
|
|
74
|
+
const assignedKey = (element.key || key || createKey()).toString()
|
|
75
|
+
|
|
76
|
+
if (checkIfKeyIsComponent(assignedKey)) {
|
|
77
|
+
element = applyKeyComponentAsExtend(element, parent, assignedKey)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// TODO: move as define plugins
|
|
81
|
+
// Responsive rendering
|
|
82
|
+
if (checkIfMedia(assignedKey)) {
|
|
83
|
+
element = applyMediaProps(element, parent, assignedKey)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (element.__ref) element.__ref.origin = element
|
|
87
|
+
else element.__ref = { origin: element } // eslint-disable-line
|
|
88
|
+
const __ref = element.__ref
|
|
89
|
+
|
|
90
|
+
// assign context
|
|
91
|
+
applyContext(element, parent, options)
|
|
92
|
+
const { context } = element
|
|
93
|
+
|
|
94
|
+
if (context && context.components) {
|
|
95
|
+
applyComponentFromContext(element, parent, options)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// create EXTEND inheritance
|
|
99
|
+
applyExtend(element, parent, options)
|
|
100
|
+
|
|
101
|
+
// create and assign a KEY
|
|
102
|
+
element.key = assignedKey
|
|
103
|
+
|
|
104
|
+
// Only resolve extends, skip everything else
|
|
105
|
+
if (options.onlyResolveExtends) {
|
|
106
|
+
return resolveExtends(element, parent, options)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Object.keys(options).length) {
|
|
110
|
+
registry.defaultOptions = options
|
|
111
|
+
if (options.ignoreChildExtend) delete options.ignoreChildExtend
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
addCaching(element, parent)
|
|
115
|
+
|
|
116
|
+
addMethods(element, parent)
|
|
117
|
+
|
|
118
|
+
// enable STATE
|
|
119
|
+
element.state = createState(element, parent)
|
|
120
|
+
|
|
121
|
+
// don't render IF in condition
|
|
122
|
+
checkIf(element, parent)
|
|
123
|
+
|
|
124
|
+
// if it already HAS a NODE
|
|
125
|
+
if (element.node && __ref.__if) { // TODO: check on if
|
|
126
|
+
return assignNode(element, parent, assignedKey)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// apply props settings
|
|
130
|
+
if (__ref.__if) createProps(element, parent)
|
|
131
|
+
|
|
132
|
+
// apply variants
|
|
133
|
+
applyVariant(element, parent)
|
|
134
|
+
|
|
135
|
+
// run `on.init`
|
|
136
|
+
const initReturns = triggerEventOn('init', element, options)
|
|
137
|
+
if (initReturns === false) return element
|
|
138
|
+
|
|
139
|
+
// run `on.beforeClassAssign`
|
|
140
|
+
triggerEventOn('beforeClassAssign', element, options)
|
|
141
|
+
|
|
142
|
+
// generate a CLASS name
|
|
143
|
+
assignClass(element)
|
|
144
|
+
|
|
145
|
+
renderElement(element, parent, options)
|
|
146
|
+
|
|
147
|
+
if (parent.__ref && parent.__ref.__children) parent.__ref.__children.push(element.key)
|
|
148
|
+
|
|
149
|
+
triggerEventOn('complete', element, options)
|
|
150
|
+
|
|
151
|
+
return element
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const renderElement = (element, parent, options) => {
|
|
155
|
+
const { __ref: ref, key } = element
|
|
156
|
+
|
|
157
|
+
// CREATE a real NODE
|
|
158
|
+
createNode(element, options)
|
|
159
|
+
|
|
160
|
+
if (!ref.__if) return element
|
|
161
|
+
|
|
162
|
+
// assign NODE
|
|
163
|
+
assignNode(element, parent, key)
|
|
164
|
+
|
|
165
|
+
// run `on.renderRouter`
|
|
166
|
+
triggerEventOn('renderRouter', element, options)
|
|
167
|
+
|
|
168
|
+
// run `on.render`
|
|
169
|
+
triggerEventOn('render', element, options)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const checkIfPrimitive = (element) => {
|
|
173
|
+
return is(element)('string', 'number')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const applyValueAsText = (element, parent, key) => {
|
|
177
|
+
const extendTag = element.extend && element.extend.tag
|
|
178
|
+
const childExtendTag = parent.childExtend && parent.childExtend.tag
|
|
179
|
+
const isKeyValidHTMLTag = ((TAGS.body.indexOf(key) > -1) && key)
|
|
180
|
+
return {
|
|
181
|
+
text: element,
|
|
182
|
+
tag: extendTag || childExtendTag || isKeyValidHTMLTag || 'string'
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const applyContext = (element, parent, options) => {
|
|
187
|
+
if (options.context && !ROOT.context && !element.context) ROOT.context = options.context
|
|
188
|
+
if (!element.context) element.context = parent.context || options.context || ROOT.context
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const checkIf = (element, parent) => {
|
|
192
|
+
const { __ref: ref } = element
|
|
193
|
+
|
|
194
|
+
if (isFunction(element.if)) {
|
|
195
|
+
// TODO: move as fragment
|
|
196
|
+
const ifPassed = element.if(element, element.state)
|
|
197
|
+
if (!ifPassed) {
|
|
198
|
+
const ifFragment = cacheNode({ tag: 'fragment' })
|
|
199
|
+
ref.__ifFragment = appendNode(ifFragment, parent.node)
|
|
200
|
+
delete ref.__if
|
|
201
|
+
} else ref.__if = true
|
|
202
|
+
} else ref.__if = true
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const addCaching = (element, parent) => {
|
|
206
|
+
const { __ref: ref } = element
|
|
207
|
+
let { __ref: parentRef } = parent
|
|
208
|
+
|
|
209
|
+
// enable TRANSFORM in data
|
|
210
|
+
if (!element.transform) element.transform = {}
|
|
211
|
+
|
|
212
|
+
// enable CACHING
|
|
213
|
+
if (!ref.__cached) ref.__cached = {}
|
|
214
|
+
if (!ref.__defineCache) ref.__defineCache = {}
|
|
215
|
+
|
|
216
|
+
// enable EXEC
|
|
217
|
+
if (!ref.__exec) ref.__exec = {}
|
|
218
|
+
|
|
219
|
+
// enable CLASS CACHING
|
|
220
|
+
if (!ref.__class) ref.__class = {}
|
|
221
|
+
if (!ref.__classNames) ref.__classNames = {}
|
|
222
|
+
|
|
223
|
+
// enable CLASS CACHING
|
|
224
|
+
if (!ref.__attr) ref.__attr = {}
|
|
225
|
+
|
|
226
|
+
// enable CHANGES storing
|
|
227
|
+
if (!ref.__changes) ref.__changes = []
|
|
228
|
+
|
|
229
|
+
// enable CHANGES storing
|
|
230
|
+
if (!ref.__children) ref.__children = []
|
|
231
|
+
|
|
232
|
+
// Add _root element property
|
|
233
|
+
const hasRoot = parent && parent.key === ':root'
|
|
234
|
+
if (!ref.__root) ref.__root = hasRoot ? element : parentRef.__root
|
|
235
|
+
|
|
236
|
+
// set the PATH array
|
|
237
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
238
|
+
if (!parentRef) parentRef = parent.ref = {}
|
|
239
|
+
if (!parentRef.__path) parentRef.__path = []
|
|
240
|
+
ref.__path = parentRef.__path.concat(element.key)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const resolveExtends = (element, parent, options) => {
|
|
245
|
+
const { __ref } = element
|
|
246
|
+
element.tag = detectTag(element)
|
|
247
|
+
|
|
248
|
+
if (!__ref.__exec) __ref.__exec = {}
|
|
249
|
+
if (!__ref.__attr) __ref.__attr = {}
|
|
250
|
+
|
|
251
|
+
if (!element.props) element.props = {}
|
|
252
|
+
if (!element.state) element.state = {}
|
|
253
|
+
|
|
254
|
+
createState(element, parent, { skipApplyMethods: true })
|
|
255
|
+
createProps(element, parent)
|
|
256
|
+
applyVariant(element, parent)
|
|
257
|
+
|
|
258
|
+
throughInitialExec(element, options.propsExcludedFromExec)
|
|
259
|
+
|
|
260
|
+
for (const param in element) {
|
|
261
|
+
const prop = element[param]
|
|
262
|
+
if (
|
|
263
|
+
isUndefined(prop) ||
|
|
264
|
+
isMethod(param) ||
|
|
265
|
+
isObject(registry[param]) ||
|
|
266
|
+
isVariant(param)
|
|
267
|
+
) continue
|
|
268
|
+
|
|
269
|
+
const hasDefined = element.define && element.define[param]
|
|
270
|
+
const ourParam = registry[param]
|
|
271
|
+
const hasOptionsDefine = options.define && options.define[param]
|
|
272
|
+
if (ourParam && !hasOptionsDefine) continue
|
|
273
|
+
else if (element[param] && !hasDefined && !hasOptionsDefine) {
|
|
274
|
+
create(exec(prop, element), element, param, options)
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
delete element.parent
|
|
279
|
+
delete element.update
|
|
280
|
+
delete element.__element
|
|
281
|
+
|
|
282
|
+
// added by createProps
|
|
283
|
+
delete element.props.update
|
|
284
|
+
delete element.props.__element
|
|
285
|
+
|
|
286
|
+
// added by createState
|
|
287
|
+
delete element.state.__element
|
|
288
|
+
delete element.state.__element
|
|
289
|
+
if (!options.keepRef) delete element.__ref
|
|
290
|
+
|
|
291
|
+
return element
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const checkIfMedia = (key) => key.slice(0, 1) === '@'
|
|
295
|
+
|
|
296
|
+
const applyMediaProps = (element, parent, key) => {
|
|
297
|
+
const { props } = element
|
|
298
|
+
if (props) {
|
|
299
|
+
props.display = 'none'
|
|
300
|
+
if (props[key]) props[key].display = props.display
|
|
301
|
+
else props[key] = { display: props.display || 'block' }
|
|
302
|
+
return element
|
|
303
|
+
} else {
|
|
304
|
+
return {
|
|
305
|
+
...element,
|
|
306
|
+
props: {
|
|
307
|
+
display: 'none',
|
|
308
|
+
[key]: { display: 'block' }
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export default create
|
package/define.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { report } from '@domql/report'
|
|
4
|
+
import { registry } from './mixins'
|
|
5
|
+
|
|
6
|
+
export default (params, options = {}) => {
|
|
7
|
+
const { overwrite } = options
|
|
8
|
+
for (const param in params) {
|
|
9
|
+
if (registry[param] && !overwrite) {
|
|
10
|
+
report('OverwriteToBuiltin', param)
|
|
11
|
+
} else registry[param] = params[param]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 applyParam_exports = {};
|
|
20
|
+
__export(applyParam_exports, {
|
|
21
|
+
applyParam: () => applyParam
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(applyParam_exports);
|
|
24
|
+
var import_utils = require("@domql/utils");
|
|
25
|
+
var import_mixins = require("./mixins");
|
|
26
|
+
const applyParam = (param, element, options) => {
|
|
27
|
+
const { node, context } = element;
|
|
28
|
+
const prop = element[param];
|
|
29
|
+
const DOMQLProperty = import_mixins.registry[param];
|
|
30
|
+
const DOMQLPropertyFromContext = context && context.registry && context.registry[param];
|
|
31
|
+
const isGlobalTransformer = DOMQLPropertyFromContext || DOMQLProperty;
|
|
32
|
+
const hasDefine = element.define && element.define[param];
|
|
33
|
+
const hasContextDefine = context && context.define && context.define[param];
|
|
34
|
+
if (isGlobalTransformer && !hasContextDefine) {
|
|
35
|
+
if ((0, import_utils.isFunction)(isGlobalTransformer)) {
|
|
36
|
+
isGlobalTransformer(prop, element, node, options);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { hasDefine, hasContextDefine };
|
|
41
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var create_exports = {};
|
|
30
|
+
__export(create_exports, {
|
|
31
|
+
default: () => create_default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(create_exports);
|
|
34
|
+
var import_utils = require("@domql/utils");
|
|
35
|
+
var import_tree = require("./tree");
|
|
36
|
+
var import_registry = require("@domql/registry");
|
|
37
|
+
var import_event = require("@domql/event");
|
|
38
|
+
var import_render = require("@domql/render");
|
|
39
|
+
var import_classlist = require("@domql/classlist");
|
|
40
|
+
var import_node = require("@domql/node");
|
|
41
|
+
var import_state = require("@domql/state");
|
|
42
|
+
var import_methods = require("./methods");
|
|
43
|
+
var import_props = require("./props");
|
|
44
|
+
var import_node2 = __toESM(require("./node"), 1);
|
|
45
|
+
var import_extend = require("./extend");
|
|
46
|
+
var import_mixins = require("./mixins");
|
|
47
|
+
var import_iterate = require("./iterate");
|
|
48
|
+
var import_options = __toESM(require("./cache/options"), 1);
|
|
49
|
+
var import_component = require("./utils/component");
|
|
50
|
+
var import_set = require("./methods/set");
|
|
51
|
+
const ENV = "development";
|
|
52
|
+
const create = (element, parent, key, options = import_options.default.create || {}) => {
|
|
53
|
+
if (options && !import_options.default.create) {
|
|
54
|
+
import_options.default.create = options;
|
|
55
|
+
import_options.default.create.context = element.context || options.context;
|
|
56
|
+
}
|
|
57
|
+
if (element === void 0) {
|
|
58
|
+
if (ENV === "test" || ENV === "development") {
|
|
59
|
+
console.warn(key, "element is undefined in", parent && parent.__ref && parent.__ref.path);
|
|
60
|
+
}
|
|
61
|
+
element = {};
|
|
62
|
+
}
|
|
63
|
+
if ((0, import_utils.isString)(key) && key.slice(0, 2 === "__")) {
|
|
64
|
+
if (ENV === "test" || ENV === "development") {
|
|
65
|
+
console.warn(key, "seems like to be in __ref");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (element === null)
|
|
69
|
+
return;
|
|
70
|
+
if (element === true)
|
|
71
|
+
element = { text: true };
|
|
72
|
+
if (element.__hash) {
|
|
73
|
+
element = { extend: element };
|
|
74
|
+
}
|
|
75
|
+
if (!parent)
|
|
76
|
+
parent = import_tree.ROOT;
|
|
77
|
+
if ((0, import_utils.isNode)(parent)) {
|
|
78
|
+
parent = import_tree.ROOT[`${key}_parent`] = { key: ":root", node: parent };
|
|
79
|
+
}
|
|
80
|
+
if (checkIfPrimitive(element)) {
|
|
81
|
+
element = applyValueAsText(element, parent, key);
|
|
82
|
+
}
|
|
83
|
+
const assignedKey = (element.key || key || (0, import_utils.createKey)()).toString();
|
|
84
|
+
if ((0, import_component.checkIfKeyIsComponent)(assignedKey)) {
|
|
85
|
+
element = (0, import_component.applyKeyComponentAsExtend)(element, parent, assignedKey);
|
|
86
|
+
}
|
|
87
|
+
if (checkIfMedia(assignedKey)) {
|
|
88
|
+
element = applyMediaProps(element, parent, assignedKey);
|
|
89
|
+
}
|
|
90
|
+
if (element.__ref)
|
|
91
|
+
element.__ref.origin = element;
|
|
92
|
+
else
|
|
93
|
+
element.__ref = { origin: element };
|
|
94
|
+
const __ref = element.__ref;
|
|
95
|
+
applyContext(element, parent, options);
|
|
96
|
+
const { context } = element;
|
|
97
|
+
if (context && context.components) {
|
|
98
|
+
(0, import_component.applyComponentFromContext)(element, parent, options);
|
|
99
|
+
}
|
|
100
|
+
(0, import_extend.applyExtend)(element, parent, options);
|
|
101
|
+
element.key = assignedKey;
|
|
102
|
+
if (options.onlyResolveExtends) {
|
|
103
|
+
return resolveExtends(element, parent, options);
|
|
104
|
+
}
|
|
105
|
+
if (Object.keys(options).length) {
|
|
106
|
+
import_mixins.registry.defaultOptions = options;
|
|
107
|
+
if (options.ignoreChildExtend)
|
|
108
|
+
delete options.ignoreChildExtend;
|
|
109
|
+
}
|
|
110
|
+
addCaching(element, parent);
|
|
111
|
+
(0, import_set.addMethods)(element, parent);
|
|
112
|
+
element.state = (0, import_state.createState)(element, parent);
|
|
113
|
+
checkIf(element, parent);
|
|
114
|
+
if (element.node && __ref.__if) {
|
|
115
|
+
return (0, import_render.assignNode)(element, parent, assignedKey);
|
|
116
|
+
}
|
|
117
|
+
if (__ref.__if)
|
|
118
|
+
(0, import_props.createProps)(element, parent);
|
|
119
|
+
(0, import_component.applyVariant)(element, parent);
|
|
120
|
+
const initReturns = (0, import_event.triggerEventOn)("init", element, options);
|
|
121
|
+
if (initReturns === false)
|
|
122
|
+
return element;
|
|
123
|
+
(0, import_event.triggerEventOn)("beforeClassAssign", element, options);
|
|
124
|
+
(0, import_classlist.assignClass)(element);
|
|
125
|
+
renderElement(element, parent, options);
|
|
126
|
+
if (parent.__ref && parent.__ref.__children)
|
|
127
|
+
parent.__ref.__children.push(element.key);
|
|
128
|
+
(0, import_event.triggerEventOn)("complete", element, options);
|
|
129
|
+
return element;
|
|
130
|
+
};
|
|
131
|
+
const renderElement = (element, parent, options) => {
|
|
132
|
+
const { __ref: ref, key } = element;
|
|
133
|
+
(0, import_node2.default)(element, options);
|
|
134
|
+
if (!ref.__if)
|
|
135
|
+
return element;
|
|
136
|
+
(0, import_render.assignNode)(element, parent, key);
|
|
137
|
+
(0, import_event.triggerEventOn)("renderRouter", element, options);
|
|
138
|
+
(0, import_event.triggerEventOn)("render", element, options);
|
|
139
|
+
};
|
|
140
|
+
const checkIfPrimitive = (element) => {
|
|
141
|
+
return (0, import_utils.is)(element)("string", "number");
|
|
142
|
+
};
|
|
143
|
+
const applyValueAsText = (element, parent, key) => {
|
|
144
|
+
const extendTag = element.extend && element.extend.tag;
|
|
145
|
+
const childExtendTag = parent.childExtend && parent.childExtend.tag;
|
|
146
|
+
const isKeyValidHTMLTag = import_registry.TAGS.body.indexOf(key) > -1 && key;
|
|
147
|
+
return {
|
|
148
|
+
text: element,
|
|
149
|
+
tag: extendTag || childExtendTag || isKeyValidHTMLTag || "string"
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const applyContext = (element, parent, options) => {
|
|
153
|
+
if (options.context && !import_tree.ROOT.context && !element.context)
|
|
154
|
+
import_tree.ROOT.context = options.context;
|
|
155
|
+
if (!element.context)
|
|
156
|
+
element.context = parent.context || options.context || import_tree.ROOT.context;
|
|
157
|
+
};
|
|
158
|
+
const checkIf = (element, parent) => {
|
|
159
|
+
const { __ref: ref } = element;
|
|
160
|
+
if ((0, import_utils.isFunction)(element.if)) {
|
|
161
|
+
const ifPassed = element.if(element, element.state);
|
|
162
|
+
if (!ifPassed) {
|
|
163
|
+
const ifFragment = (0, import_node.cacheNode)({ tag: "fragment" });
|
|
164
|
+
ref.__ifFragment = (0, import_render.appendNode)(ifFragment, parent.node);
|
|
165
|
+
delete ref.__if;
|
|
166
|
+
} else
|
|
167
|
+
ref.__if = true;
|
|
168
|
+
} else
|
|
169
|
+
ref.__if = true;
|
|
170
|
+
};
|
|
171
|
+
const addCaching = (element, parent) => {
|
|
172
|
+
const { __ref: ref } = element;
|
|
173
|
+
let { __ref: parentRef } = parent;
|
|
174
|
+
if (!element.transform)
|
|
175
|
+
element.transform = {};
|
|
176
|
+
if (!ref.__cached)
|
|
177
|
+
ref.__cached = {};
|
|
178
|
+
if (!ref.__defineCache)
|
|
179
|
+
ref.__defineCache = {};
|
|
180
|
+
if (!ref.__exec)
|
|
181
|
+
ref.__exec = {};
|
|
182
|
+
if (!ref.__class)
|
|
183
|
+
ref.__class = {};
|
|
184
|
+
if (!ref.__classNames)
|
|
185
|
+
ref.__classNames = {};
|
|
186
|
+
if (!ref.__attr)
|
|
187
|
+
ref.__attr = {};
|
|
188
|
+
if (!ref.__changes)
|
|
189
|
+
ref.__changes = [];
|
|
190
|
+
if (!ref.__children)
|
|
191
|
+
ref.__children = [];
|
|
192
|
+
const hasRoot = parent && parent.key === ":root";
|
|
193
|
+
if (!ref.__root)
|
|
194
|
+
ref.__root = hasRoot ? element : parentRef.__root;
|
|
195
|
+
if (ENV === "test" || ENV === "development") {
|
|
196
|
+
if (!parentRef)
|
|
197
|
+
parentRef = parent.ref = {};
|
|
198
|
+
if (!parentRef.__path)
|
|
199
|
+
parentRef.__path = [];
|
|
200
|
+
ref.__path = parentRef.__path.concat(element.key);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const resolveExtends = (element, parent, options) => {
|
|
204
|
+
const { __ref } = element;
|
|
205
|
+
element.tag = (0, import_node.detectTag)(element);
|
|
206
|
+
if (!__ref.__exec)
|
|
207
|
+
__ref.__exec = {};
|
|
208
|
+
if (!__ref.__attr)
|
|
209
|
+
__ref.__attr = {};
|
|
210
|
+
if (!element.props)
|
|
211
|
+
element.props = {};
|
|
212
|
+
if (!element.state)
|
|
213
|
+
element.state = {};
|
|
214
|
+
(0, import_state.createState)(element, parent, { skipApplyMethods: true });
|
|
215
|
+
(0, import_props.createProps)(element, parent);
|
|
216
|
+
(0, import_component.applyVariant)(element, parent);
|
|
217
|
+
(0, import_iterate.throughInitialExec)(element, options.propsExcludedFromExec);
|
|
218
|
+
for (const param in element) {
|
|
219
|
+
const prop = element[param];
|
|
220
|
+
if ((0, import_utils.isUndefined)(prop) || (0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || (0, import_component.isVariant)(param))
|
|
221
|
+
continue;
|
|
222
|
+
const hasDefined = element.define && element.define[param];
|
|
223
|
+
const ourParam = import_mixins.registry[param];
|
|
224
|
+
const hasOptionsDefine = options.define && options.define[param];
|
|
225
|
+
if (ourParam && !hasOptionsDefine)
|
|
226
|
+
continue;
|
|
227
|
+
else if (element[param] && !hasDefined && !hasOptionsDefine) {
|
|
228
|
+
create((0, import_utils.exec)(prop, element), element, param, options);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
delete element.parent;
|
|
232
|
+
delete element.update;
|
|
233
|
+
delete element.__element;
|
|
234
|
+
delete element.props.update;
|
|
235
|
+
delete element.props.__element;
|
|
236
|
+
delete element.state.__element;
|
|
237
|
+
delete element.state.__element;
|
|
238
|
+
if (!options.keepRef)
|
|
239
|
+
delete element.__ref;
|
|
240
|
+
return element;
|
|
241
|
+
};
|
|
242
|
+
const checkIfMedia = (key) => key.slice(0, 1) === "@";
|
|
243
|
+
const applyMediaProps = (element, parent, key) => {
|
|
244
|
+
const { props } = element;
|
|
245
|
+
if (props) {
|
|
246
|
+
props.display = "none";
|
|
247
|
+
if (props[key])
|
|
248
|
+
props[key].display = props.display;
|
|
249
|
+
else
|
|
250
|
+
props[key] = { display: props.display || "block" };
|
|
251
|
+
return element;
|
|
252
|
+
} else {
|
|
253
|
+
return {
|
|
254
|
+
...element,
|
|
255
|
+
props: {
|
|
256
|
+
display: "none",
|
|
257
|
+
[key]: { display: "block" }
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var create_default = create;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 define_exports = {};
|
|
20
|
+
__export(define_exports, {
|
|
21
|
+
default: () => define_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(define_exports);
|
|
24
|
+
var import_report = require("@domql/report");
|
|
25
|
+
var import_mixins = require("./mixins");
|
|
26
|
+
var define_default = (params, options = {}) => {
|
|
27
|
+
const { overwrite } = options;
|
|
28
|
+
for (const param in params) {
|
|
29
|
+
if (import_mixins.registry[param] && !overwrite) {
|
|
30
|
+
(0, import_report.report)("OverwriteToBuiltin", param);
|
|
31
|
+
} else
|
|
32
|
+
import_mixins.registry[param] = params[param];
|
|
33
|
+
}
|
|
34
|
+
};
|