@domql/element 2.3.154 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/cache/index.js +3 -0
- package/create.js +21 -35
- 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/index.js +2 -12
- package/iterate.js +1 -1
- package/methods/index.js +165 -0
- package/methods/set.js +41 -0
- package/{methods.js → methods/v2.js} +1 -7
- package/mixins/attr.js +23 -0
- package/mixins/classList.js +48 -0
- package/{remove.js → mixins/content.js} +19 -2
- package/mixins/data.js +21 -0
- package/mixins/html.js +20 -0
- package/mixins/index.js +23 -0
- package/mixins/registry.js +66 -0
- package/mixins/state.js +20 -0
- package/mixins/style.js +14 -0
- package/mixins/text.js +41 -0
- package/node.js +2 -2
- package/package.json +14 -6
- package/props/create.js +60 -0
- package/props/ignore.js +3 -0
- package/props/index.js +6 -0
- package/props/inherit.js +34 -0
- package/props/update.js +17 -0
- package/set.js +4 -6
- package/test/create.test.js +61 -0
- package/test/set.test.js +13 -0
- package/test/update.test.js +13 -0
- package/tree.js +11 -0
- package/update.js +5 -7
- package/utils/component.js +112 -0
- package/utils/extendUtils.js +118 -0
- package/utils/index.js +5 -0
- package/utils/object.js +141 -0
- package/parse.js +0 -17
- /package/{options.js → cache/options.js} +0 -0
package/methods/index.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isDefined, isFunction, isObjectLike, isProduction } from '@domql/utils'
|
|
4
|
+
import { TREE } from '../tree'
|
|
5
|
+
import { parseFilters, registry } from '../mixins'
|
|
6
|
+
|
|
7
|
+
// TODO: update these files
|
|
8
|
+
export const spotByPath = function (path) {
|
|
9
|
+
const element = this
|
|
10
|
+
const arr = [].concat(path)
|
|
11
|
+
let active = TREE[arr[0]]
|
|
12
|
+
|
|
13
|
+
if (!arr || !arr.length) return console.log(arr, 'on', element.key, 'is undefined')
|
|
14
|
+
|
|
15
|
+
while (active.key === arr[0]) {
|
|
16
|
+
arr.shift()
|
|
17
|
+
if (!arr.length) break
|
|
18
|
+
active = active[arr[0]]
|
|
19
|
+
if (!active) return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return active
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// TODO: update these files
|
|
26
|
+
export const lookup = function (key) {
|
|
27
|
+
const element = this
|
|
28
|
+
let { parent } = element
|
|
29
|
+
|
|
30
|
+
while (parent.key !== key) {
|
|
31
|
+
if (parent[key]) return parent[key]
|
|
32
|
+
parent = parent.parent
|
|
33
|
+
if (!parent) return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return parent
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const remove = function (params) {
|
|
40
|
+
const element = this
|
|
41
|
+
if (isFunction(element.node.remove)) element.node.remove()
|
|
42
|
+
else if (!isProduction()) {
|
|
43
|
+
console.warn('This item cant be removed')
|
|
44
|
+
element.log()
|
|
45
|
+
}
|
|
46
|
+
delete element.parent[element.key]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const get = function (param) {
|
|
50
|
+
const element = this
|
|
51
|
+
return element[param]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const setProps = function (param, options) {
|
|
55
|
+
const element = this
|
|
56
|
+
if (!param || !element.props) return
|
|
57
|
+
element.update({ props: param }, options)
|
|
58
|
+
return element
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// export const set = function () {
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
// export const update = function () {
|
|
65
|
+
// }
|
|
66
|
+
|
|
67
|
+
export const defineSetter = (element, key, get, set) =>
|
|
68
|
+
Object.defineProperty(element, key, { get, set })
|
|
69
|
+
|
|
70
|
+
export const keys = function () {
|
|
71
|
+
const element = this
|
|
72
|
+
const keys = []
|
|
73
|
+
for (const param in element) {
|
|
74
|
+
if (registry[param] && !parseFilters.elementKeys.includes(param)) { continue }
|
|
75
|
+
keys.push(param)
|
|
76
|
+
}
|
|
77
|
+
return keys
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const parse = function (excl = []) {
|
|
81
|
+
const element = this
|
|
82
|
+
const obj = {}
|
|
83
|
+
const keyList = keys.call(element)
|
|
84
|
+
keyList.forEach(v => {
|
|
85
|
+
if (excl.includes(v)) return
|
|
86
|
+
let val = element[v]
|
|
87
|
+
if (v === 'state') {
|
|
88
|
+
if (element.__ref && element.__ref.__hasRootState) return
|
|
89
|
+
if (isFunction(val && val.parse)) val = val.parse()
|
|
90
|
+
} else if (v === 'props') {
|
|
91
|
+
const { __element, update, ...props } = element[v]
|
|
92
|
+
obj[v] = props
|
|
93
|
+
} else if (isDefined(val)) obj[v] = val
|
|
94
|
+
})
|
|
95
|
+
return obj
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const parseDeep = function (excl = []) {
|
|
99
|
+
const element = this
|
|
100
|
+
const obj = parse.call(element, excl)
|
|
101
|
+
for (const v in obj) {
|
|
102
|
+
if (excl.includes(v)) return
|
|
103
|
+
if (isObjectLike(obj[v])) { obj[v] = parseDeep.call(obj[v], excl) }
|
|
104
|
+
}
|
|
105
|
+
return obj
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const log = function (...args) {
|
|
109
|
+
const element = this
|
|
110
|
+
const { __ref } = element
|
|
111
|
+
console.group(element.key)
|
|
112
|
+
if (args.length) {
|
|
113
|
+
args.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
|
|
114
|
+
} else {
|
|
115
|
+
console.log(__ref.path)
|
|
116
|
+
const keys = element.keys()
|
|
117
|
+
keys.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
|
|
118
|
+
}
|
|
119
|
+
console.groupEnd(element.key)
|
|
120
|
+
return element
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const nextElement = function () {
|
|
124
|
+
const element = this
|
|
125
|
+
const { key, parent } = element
|
|
126
|
+
const { __children } = parent.__ref
|
|
127
|
+
|
|
128
|
+
const currentIndex = __children.indexOf(key)
|
|
129
|
+
const nextChild = __children[currentIndex + 1]
|
|
130
|
+
|
|
131
|
+
return parent[nextChild]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const previousElement = function (el) {
|
|
135
|
+
const element = el || this
|
|
136
|
+
const { key, parent } = element
|
|
137
|
+
const { __children } = parent.__ref
|
|
138
|
+
|
|
139
|
+
if (!__children) return
|
|
140
|
+
|
|
141
|
+
const currentIndex = __children.indexOf(key)
|
|
142
|
+
return parent[__children[currentIndex - 1]]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const METHODS = [
|
|
146
|
+
'set',
|
|
147
|
+
'update',
|
|
148
|
+
'remove',
|
|
149
|
+
'updateContent',
|
|
150
|
+
'removeContent',
|
|
151
|
+
'lookup',
|
|
152
|
+
'spotByPath',
|
|
153
|
+
'keys',
|
|
154
|
+
'parse',
|
|
155
|
+
'setProps',
|
|
156
|
+
'parseDeep',
|
|
157
|
+
'if',
|
|
158
|
+
'log',
|
|
159
|
+
'nextElement',
|
|
160
|
+
'previousElement'
|
|
161
|
+
]
|
|
162
|
+
|
|
163
|
+
export const isMethod = function (param) {
|
|
164
|
+
return METHODS.includes(param)
|
|
165
|
+
}
|
package/methods/set.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isDevelopment } from '@domql/utils'
|
|
4
|
+
|
|
5
|
+
import set from '../set'
|
|
6
|
+
import update from '../update'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
lookup,
|
|
10
|
+
setProps,
|
|
11
|
+
remove,
|
|
12
|
+
spotByPath,
|
|
13
|
+
log,
|
|
14
|
+
keys,
|
|
15
|
+
parse,
|
|
16
|
+
parseDeep,
|
|
17
|
+
nextElement,
|
|
18
|
+
previousElement
|
|
19
|
+
} from './'
|
|
20
|
+
|
|
21
|
+
import { removeContent, updateContent } from '../mixins/content'
|
|
22
|
+
|
|
23
|
+
export const addMethods = (element, parent) => {
|
|
24
|
+
const proto = {
|
|
25
|
+
set: set.bind(element),
|
|
26
|
+
update: update.bind(element),
|
|
27
|
+
remove: remove.bind(element),
|
|
28
|
+
updateContent: updateContent.bind(element),
|
|
29
|
+
removeContent: removeContent.bind(element),
|
|
30
|
+
setProps: setProps.bind(element),
|
|
31
|
+
lookup: lookup.bind(element),
|
|
32
|
+
spotByPath: spotByPath.bind(element),
|
|
33
|
+
parse: parse.bind(element),
|
|
34
|
+
parseDeep: parseDeep.bind(element),
|
|
35
|
+
keys: keys.bind(element),
|
|
36
|
+
nextElement: nextElement.bind(element),
|
|
37
|
+
previousElement: previousElement.bind(element)
|
|
38
|
+
}
|
|
39
|
+
if (isDevelopment()) proto.log = log.bind(element)
|
|
40
|
+
Object.setPrototypeOf(element, proto)
|
|
41
|
+
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { isDefined, isFunction, isObjectLike } from '@domql/utils'
|
|
4
|
-
import { parseFilters, registry } from '
|
|
5
|
-
|
|
6
|
-
export const set = function () {
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const update = function () {
|
|
10
|
-
}
|
|
4
|
+
import { parseFilters, registry } from '../mixins'
|
|
11
5
|
|
|
12
6
|
export const defineSetter = (element, key, get, set) =>
|
|
13
7
|
Object.defineProperty(element, key, { get, set })
|
package/mixins/attr.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { exec, isNot } from '@domql/utils'
|
|
4
|
+
import { report } from '@domql/report'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Recursively add attributes to a DOM node
|
|
8
|
+
*/
|
|
9
|
+
export default (params, element, node) => {
|
|
10
|
+
const { __ref } = element
|
|
11
|
+
const { __attr } = __ref
|
|
12
|
+
if (isNot('object')) report('HTMLInvalidAttr', params)
|
|
13
|
+
if (params) {
|
|
14
|
+
for (const attr in params) {
|
|
15
|
+
const val = exec(params[attr], element)
|
|
16
|
+
// if (__attr[attr] === val) return
|
|
17
|
+
if (val && node.setAttribute) node.setAttribute(attr, val)
|
|
18
|
+
else if (node.removeAttribute) node.removeAttribute(attr)
|
|
19
|
+
__attr[attr] = val
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
console.groupEnd(params, __attr)
|
|
23
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { exec, isObject, isString } from '@domql/utils'
|
|
4
|
+
|
|
5
|
+
export const assignClass = (element) => {
|
|
6
|
+
const { key } = element
|
|
7
|
+
if (element.class === true) element.class = key
|
|
8
|
+
else if (!element.class && typeof key === 'string' && key.charAt(0) === '_' && key.charAt(1) !== '_') {
|
|
9
|
+
element.class = key.slice(1)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// stringifies class object
|
|
14
|
+
export const classify = (obj, element) => {
|
|
15
|
+
let className = ''
|
|
16
|
+
for (const item in obj) {
|
|
17
|
+
const param = obj[item]
|
|
18
|
+
if (typeof param === 'boolean' && param) className += ` ${item}`
|
|
19
|
+
else if (typeof param === 'string') className += ` ${param}`
|
|
20
|
+
else if (typeof param === 'function') {
|
|
21
|
+
className += ` ${exec(param, element)}`
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return className
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const classList = (params, element) => {
|
|
28
|
+
if (!params) return
|
|
29
|
+
const { key } = element
|
|
30
|
+
if (params === true) params = element.class = { key }
|
|
31
|
+
if (isString(params)) params = element.class = { default: params }
|
|
32
|
+
if (isObject(params)) params = classify(params, element)
|
|
33
|
+
// TODO: fails on string
|
|
34
|
+
const className = params.replace(/\s+/g, ' ').trim()
|
|
35
|
+
if (element.ref) element.ref.class = className // TODO: this check is NOT needed in new DOMQL
|
|
36
|
+
return className
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// LEGACY (still needed in old domql)
|
|
40
|
+
export const applyClassListOnNode = (params, element, node) => {
|
|
41
|
+
const className = classList(params, element)
|
|
42
|
+
node.classList = className
|
|
43
|
+
return className
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default (params, element, node) => {
|
|
47
|
+
applyClassListOnNode(params, element, node)
|
|
48
|
+
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { isFunction } from '@domql/utils'
|
|
4
|
+
import set from '../set'
|
|
4
5
|
|
|
5
|
-
export const
|
|
6
|
+
export const updateContent = function (params, options) {
|
|
6
7
|
const element = this
|
|
7
8
|
|
|
8
9
|
if (!element.content) return
|
|
9
10
|
if (element.content.update) element.content.update(params, options)
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export const
|
|
13
|
+
export const removeContent = function (el) {
|
|
13
14
|
const element = el || this
|
|
14
15
|
const { __ref } = element
|
|
15
16
|
|
|
@@ -28,3 +29,19 @@ export const removeContentElement = function (el) {
|
|
|
28
29
|
delete element.content
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Appends anything as content
|
|
35
|
+
* an original one as a child
|
|
36
|
+
*/
|
|
37
|
+
export const setContent = (param, element, node, options) => {
|
|
38
|
+
if (param && element) {
|
|
39
|
+
if (element.content.update) {
|
|
40
|
+
element.content.update({}, options)
|
|
41
|
+
} else {
|
|
42
|
+
set.call(element, param, options)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default setContent
|
package/mixins/data.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { exec, isObject } from '@domql/utils'
|
|
4
|
+
import { report } from '@domql/report'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Apply data parameters on the DOM nodes
|
|
8
|
+
* this should only work if `showOnNode: true` is passed
|
|
9
|
+
*/
|
|
10
|
+
export default (params, element, node) => {
|
|
11
|
+
if (params && params.showOnNode) {
|
|
12
|
+
if (!isObject(params)) report('HTMLInvalidData', params)
|
|
13
|
+
|
|
14
|
+
// Apply data params on node
|
|
15
|
+
for (const dataset in params) {
|
|
16
|
+
if (dataset !== 'showOnNode') {
|
|
17
|
+
node.dataset[dataset] = exec(params[dataset], element)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
package/mixins/html.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { exec } from '@domql/utils'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Appends raw HTML as content
|
|
7
|
+
* an original one as a child
|
|
8
|
+
*/
|
|
9
|
+
export default (param, element, node) => {
|
|
10
|
+
const prop = exec(param, element)
|
|
11
|
+
const { __ref } = element
|
|
12
|
+
if (prop !== __ref.__html) {
|
|
13
|
+
// const parser = new window.DOMParser()
|
|
14
|
+
// param = parser.parseFromString(param, 'text/html')
|
|
15
|
+
if (node.nodeName === 'SVG') node.textContent = prop
|
|
16
|
+
else node.innerHTML = prop
|
|
17
|
+
|
|
18
|
+
__ref.__html = prop
|
|
19
|
+
}
|
|
20
|
+
}
|
package/mixins/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import attr from './attr'
|
|
4
|
+
import classList from './classList'
|
|
5
|
+
import content from './content'
|
|
6
|
+
import data from './data'
|
|
7
|
+
import html from './html'
|
|
8
|
+
import style from './style'
|
|
9
|
+
import text from './text'
|
|
10
|
+
import state from './state'
|
|
11
|
+
import registry from './registry'
|
|
12
|
+
export {
|
|
13
|
+
attr,
|
|
14
|
+
classList,
|
|
15
|
+
content,
|
|
16
|
+
data,
|
|
17
|
+
style,
|
|
18
|
+
text,
|
|
19
|
+
html,
|
|
20
|
+
state,
|
|
21
|
+
registry
|
|
22
|
+
}
|
|
23
|
+
export * from './registry'
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
attr, classList, content,
|
|
5
|
+
data, html, state, style,
|
|
6
|
+
text
|
|
7
|
+
} from '.'
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
attr,
|
|
11
|
+
style,
|
|
12
|
+
text,
|
|
13
|
+
html,
|
|
14
|
+
content,
|
|
15
|
+
data,
|
|
16
|
+
class: classList,
|
|
17
|
+
state,
|
|
18
|
+
|
|
19
|
+
extend: {},
|
|
20
|
+
childExtend: {},
|
|
21
|
+
childExtendRecursive: {},
|
|
22
|
+
props: {},
|
|
23
|
+
path: {},
|
|
24
|
+
if: {},
|
|
25
|
+
define: {},
|
|
26
|
+
transform: {},
|
|
27
|
+
__ref: {},
|
|
28
|
+
__hash: {},
|
|
29
|
+
__text: {},
|
|
30
|
+
nextElement: {},
|
|
31
|
+
previousElement: {},
|
|
32
|
+
key: {},
|
|
33
|
+
tag: {},
|
|
34
|
+
query: {},
|
|
35
|
+
parent: {},
|
|
36
|
+
node: {},
|
|
37
|
+
set: {},
|
|
38
|
+
update: {},
|
|
39
|
+
setProps: {},
|
|
40
|
+
remove: {},
|
|
41
|
+
updateContent: {},
|
|
42
|
+
removeContent: {},
|
|
43
|
+
lookup: {},
|
|
44
|
+
spotByPath: {},
|
|
45
|
+
keys: {},
|
|
46
|
+
log: {},
|
|
47
|
+
parse: {},
|
|
48
|
+
parseDeep: {},
|
|
49
|
+
on: {},
|
|
50
|
+
component: {},
|
|
51
|
+
context: {},
|
|
52
|
+
$setStateCollection: {},
|
|
53
|
+
$setCollection: {},
|
|
54
|
+
$setPropsCollection: {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// List of keys for .parse() and .parseDeep() to include in the result.
|
|
58
|
+
// Keys not in the array are excluded.
|
|
59
|
+
export const parseFilters = {
|
|
60
|
+
elementKeys: [
|
|
61
|
+
'tag', 'text', 'style', 'attr', 'class', 'state', 'props',
|
|
62
|
+
'data', 'content', 'html', 'on', 'key'
|
|
63
|
+
],
|
|
64
|
+
propsKeys: ['__element', 'update'],
|
|
65
|
+
stateKeys: []
|
|
66
|
+
}
|
package/mixins/state.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { IGNORE_STATE_PARAMS } from '@domql/state'
|
|
4
|
+
import { exec, isObject } from '@domql/utils'
|
|
5
|
+
|
|
6
|
+
export const state = (params, element, node) => {
|
|
7
|
+
const state = exec(params, element)
|
|
8
|
+
|
|
9
|
+
if (isObject(state)) {
|
|
10
|
+
for (const param in state) {
|
|
11
|
+
if (IGNORE_STATE_PARAMS.includes(param)) continue
|
|
12
|
+
if (!state.hasOwnProperty(param)) continue
|
|
13
|
+
element.state[param] = exec(state[param], element)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return element
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default state
|
package/mixins/style.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isObject, map } from '@domql/utils'
|
|
4
|
+
import { report } from '@domql/report'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Recursively add styles to a DOM node
|
|
8
|
+
*/
|
|
9
|
+
export default (params, element, node) => {
|
|
10
|
+
if (params) {
|
|
11
|
+
if (isObject(params)) map(node.style, params, element)
|
|
12
|
+
else report('HTMLInvalidStyles', params)
|
|
13
|
+
}
|
|
14
|
+
}
|
package/mixins/text.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { create } from '..'
|
|
4
|
+
import {
|
|
5
|
+
exec,
|
|
6
|
+
isString,
|
|
7
|
+
replaceLiteralsWithObjectFields
|
|
8
|
+
} from '@domql/utils'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a text node and appends into
|
|
12
|
+
* an original one as a child
|
|
13
|
+
*/
|
|
14
|
+
export const asd = (param, element, node) => {
|
|
15
|
+
const prop = exec(param, element)
|
|
16
|
+
if (element.tag === 'string') {
|
|
17
|
+
node.nodeValue = prop
|
|
18
|
+
} else if (param !== undefined || param !== null) {
|
|
19
|
+
if (element.__text && element.__text.text !== prop) return
|
|
20
|
+
element.__text.text = prop
|
|
21
|
+
if (element.__text.node) element.__text.node.nodeValue = prop
|
|
22
|
+
else create({ tag: 'string', text: prop }, element, '__text')
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default (param, element, node) => {
|
|
27
|
+
let prop = exec(param, element)
|
|
28
|
+
if (isString(prop) && prop.includes('{{')) {
|
|
29
|
+
prop = replaceLiteralsWithObjectFields(prop, element.state)
|
|
30
|
+
}
|
|
31
|
+
if (element.tag === 'string') {
|
|
32
|
+
if (element.text === prop) return
|
|
33
|
+
node.nodeValue = prop
|
|
34
|
+
} else if (param !== undefined || param !== null) {
|
|
35
|
+
if (element.__text) {
|
|
36
|
+
if (element.__text.text === prop) return
|
|
37
|
+
element.__text.text = prop
|
|
38
|
+
if (element.__text.node) element.__text.node.nodeValue = prop
|
|
39
|
+
} else create({ tag: 'string', text: prop }, element, '__text')
|
|
40
|
+
}
|
|
41
|
+
}
|
package/node.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { exec, isFunction, isObject, isUndefined } from '@domql/utils'
|
|
4
4
|
import { applyEventsOnNode, triggerEventOn } from '@domql/event'
|
|
5
|
-
import { isMethod } from '
|
|
5
|
+
import { isMethod } from './methods'
|
|
6
6
|
import { cacheNode } from '@domql/node'
|
|
7
7
|
|
|
8
8
|
import create from './create'
|
|
@@ -66,7 +66,7 @@ export const createNode = (element, options) => {
|
|
|
66
66
|
isVariant(param) ||
|
|
67
67
|
isObject(registry[param])
|
|
68
68
|
) continue
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
const isElement = applyParam(param, element, options)
|
|
71
71
|
if (isElement) {
|
|
72
72
|
const { hasDefine, hasContextDefine } = isElement
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
7
7
|
"main": "index.js",
|
|
8
|
-
"exports":
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"kalduna": "./index.js",
|
|
11
|
+
"default": "./dist/cjs/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
9
14
|
"source": "index.js",
|
|
10
15
|
"files": [
|
|
16
|
+
"*/**.js",
|
|
11
17
|
"*.js",
|
|
12
18
|
"dist"
|
|
13
19
|
],
|
|
@@ -19,11 +25,13 @@
|
|
|
19
25
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
20
26
|
},
|
|
21
27
|
"dependencies": {
|
|
22
|
-
"@domql/
|
|
23
|
-
"@domql/
|
|
24
|
-
"@domql/
|
|
28
|
+
"@domql/event": "latest",
|
|
29
|
+
"@domql/node": "^2.3.125",
|
|
30
|
+
"@domql/render": "^2.4.0",
|
|
31
|
+
"@domql/state": "latest",
|
|
32
|
+
"@domql/utils": "latest"
|
|
25
33
|
},
|
|
26
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "aab9993c65cc91165a2a9bc00a8117a217dc7565",
|
|
27
35
|
"devDependencies": {
|
|
28
36
|
"@babel/core": "^7.12.0"
|
|
29
37
|
}
|
package/props/create.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { exec, isArray, isObject, deepClone, deepMerge } from '@domql/utils'
|
|
4
|
+
import { IGNORE_PROPS_PARAMS } from './ignore'
|
|
5
|
+
|
|
6
|
+
import { inheritParentProps } from './inherit'
|
|
7
|
+
|
|
8
|
+
const createPropsStack = (element, parent) => {
|
|
9
|
+
const { props, __ref } = element
|
|
10
|
+
const propsStack = __ref.__props = inheritParentProps(element, parent)
|
|
11
|
+
|
|
12
|
+
if (isObject(props)) propsStack.push(props)
|
|
13
|
+
else if (props === 'inherit' && parent.props) propsStack.push(parent.props)
|
|
14
|
+
else if (props) propsStack.push(props)
|
|
15
|
+
|
|
16
|
+
if (isArray(__ref.__extend)) {
|
|
17
|
+
__ref.__extend.forEach(extend => {
|
|
18
|
+
if (extend.props) propsStack.push(extend.props)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
__ref.__props = propsStack
|
|
23
|
+
|
|
24
|
+
return propsStack
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const syncProps = (props, element) => {
|
|
28
|
+
element.props = {}
|
|
29
|
+
const mergedProps = { update, __element: element }
|
|
30
|
+
props.forEach(v => {
|
|
31
|
+
if (IGNORE_PROPS_PARAMS.includes(v)) return
|
|
32
|
+
const execProps = exec(v, element)
|
|
33
|
+
if (isObject(execProps) && execProps.__element) return
|
|
34
|
+
element.props = deepMerge(
|
|
35
|
+
mergedProps,
|
|
36
|
+
deepClone(execProps, IGNORE_PROPS_PARAMS),
|
|
37
|
+
IGNORE_PROPS_PARAMS
|
|
38
|
+
)
|
|
39
|
+
})
|
|
40
|
+
element.props = mergedProps
|
|
41
|
+
return element.props
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const createProps = function (element, parent, cached) {
|
|
45
|
+
const propsStack = cached || createPropsStack(element, parent)
|
|
46
|
+
const { __ref } = element
|
|
47
|
+
|
|
48
|
+
if (propsStack.length) {
|
|
49
|
+
__ref.__props = propsStack
|
|
50
|
+
syncProps(propsStack, element)
|
|
51
|
+
element.props.update = update
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return element
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function update (props, options) {
|
|
58
|
+
const element = this.__element
|
|
59
|
+
element.update({ props }, options)
|
|
60
|
+
}
|
package/props/ignore.js
ADDED