domql 1.5.18 → 1.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/emotion/index.js +21 -12
- package/src/element/create.js +10 -1
- package/src/element/mixins/attr.js +3 -0
- package/src/element/mixins/content.js +4 -1
- package/src/element/mixins/html.js +1 -1
- package/src/element/mixins/registry.js +4 -2
- package/src/element/mixins/state.js +0 -1
- package/src/element/mixins/text.js +18 -1
- package/src/element/set.js +3 -4
- package/src/element/state.js +6 -2
- package/src/element/update.js +17 -10
- package/src/utils/object.js +8 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "DOM rendering Javascript framework at early stage.",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "rackai",
|
|
6
|
-
"version": "1.5.
|
|
6
|
+
"version": "1.5.19",
|
|
7
7
|
"repository": "https://github.com/rackai/domql",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"registry": "https://registry.npmjs.org"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import DOM from '../../src'
|
|
4
|
-
import { isObjectLike, exec, isObject, isEqualDeep } from '../../src/utils'
|
|
4
|
+
import { isObjectLike, exec, isObject, isEqualDeep, memoize } from '../../src/utils'
|
|
5
5
|
import { classList } from '../../src/element/mixins'
|
|
6
6
|
import createEmotion from '@emotion/css/create-instance'
|
|
7
7
|
const ENV = process.env.NODE_ENV
|
|
@@ -26,23 +26,32 @@ export const initEmotion = (container, options) => {
|
|
|
26
26
|
if (isObjectLike(element.class)) element.class.elementStyle = execPareams
|
|
27
27
|
else element.class = { elementStyle: execPareams }
|
|
28
28
|
}
|
|
29
|
-
classf(element.class, element, node)
|
|
29
|
+
classf(element.class, element, node, true)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const classf = (params, element, node) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
const classf = (params, element, node, flag) => {
|
|
33
|
+
if (element.style && !flag) return
|
|
34
|
+
const { __class, __classNames } = element
|
|
35
|
+
if (!isObjectLike(params)) return
|
|
36
|
+
|
|
37
|
+
for (const key in params) {
|
|
38
|
+
const prop = exec(params[key], element)
|
|
39
|
+
|
|
40
|
+
if (!prop) {
|
|
41
|
+
delete __class[key]
|
|
42
|
+
delete __classNames[key] = CSSed
|
|
43
|
+
continue
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const isEqual = isEqualDeep(__class[key], prop)
|
|
47
|
+
if (!isEqual) {
|
|
40
48
|
if ((ENV === 'test' || ENV === 'development') && isObject(prop)) prop.label = key || element.key
|
|
41
49
|
const CSSed = css(prop)
|
|
42
|
-
|
|
50
|
+
__class[key] = prop
|
|
51
|
+
__classNames[key] = CSSed
|
|
43
52
|
}
|
|
44
|
-
classList(classObjHelper, element, node)
|
|
45
53
|
}
|
|
54
|
+
classList(__classNames, element, node)
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
DOM.define({
|
package/src/element/create.js
CHANGED
|
@@ -24,7 +24,11 @@ const ENV = process.env.NODE_ENV
|
|
|
24
24
|
*/
|
|
25
25
|
const create = (element, parent, key, options = {}) => {
|
|
26
26
|
// if ELEMENT is not given
|
|
27
|
-
if (element === undefined)
|
|
27
|
+
if (element === undefined) {
|
|
28
|
+
if (ENV === 'test' || ENV === 'development')
|
|
29
|
+
console.warn(key, 'element is undefined in', parent && parent.path)
|
|
30
|
+
element = {}
|
|
31
|
+
}
|
|
28
32
|
if (element === null) return
|
|
29
33
|
|
|
30
34
|
// if element is extend
|
|
@@ -97,6 +101,10 @@ const create = (element, parent, key, options = {}) => {
|
|
|
97
101
|
|
|
98
102
|
// enable CLASS CACHING
|
|
99
103
|
if (!element.__class) element.__class = {}
|
|
104
|
+
if (!element.__classNames) element.__classNames = {}
|
|
105
|
+
|
|
106
|
+
// enable CLASS CACHING
|
|
107
|
+
if (!element.__attr) element.__attr = {}
|
|
100
108
|
|
|
101
109
|
// enable CHANGES storing
|
|
102
110
|
if (!element.__changes) element.__changes = []
|
|
@@ -129,6 +137,7 @@ const create = (element, parent, key, options = {}) => {
|
|
|
129
137
|
element.log = log
|
|
130
138
|
}
|
|
131
139
|
|
|
140
|
+
|
|
132
141
|
// enable STATE
|
|
133
142
|
element.state = createState(element, parent)
|
|
134
143
|
|
|
@@ -6,13 +6,16 @@ import { exec, report } from '../../utils'
|
|
|
6
6
|
* Recursively add attributes to a DOM node
|
|
7
7
|
*/
|
|
8
8
|
export default (params, element, node) => {
|
|
9
|
+
const { __attr } = element
|
|
9
10
|
if (params) {
|
|
10
11
|
if (!(typeof params === 'object')) report('HTMLInvalidAttr', params)
|
|
11
12
|
for (const attr in params) {
|
|
12
13
|
// if (!node) node = element.node
|
|
13
14
|
const val = exec(params[attr], element)
|
|
15
|
+
if (__attr[attr] === val) return
|
|
14
16
|
if (val && node.setAttribute) node.setAttribute(attr, val)
|
|
15
17
|
else if (node.removeAttribute) node.removeAttribute(attr)
|
|
18
|
+
__attr[attr] = val
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import set from '../set'
|
|
4
|
+
import { isEqualDeep } from '../../utils'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Appends anything as content
|
|
@@ -8,9 +9,11 @@ import set from '../set'
|
|
|
8
9
|
*/
|
|
9
10
|
export default (param, element, node, options) => {
|
|
10
11
|
if (param && element) {
|
|
12
|
+
const {$setStateCollection} = element
|
|
13
|
+
// console.log($setStateCollection)
|
|
11
14
|
if (param.__hash === element.content.__hash && element.content.update) {
|
|
15
|
+
// if ($setStateCollection) return
|
|
12
16
|
const { define } = element
|
|
13
|
-
// if (define && !define.$setStateCollection)
|
|
14
17
|
element.content.update(param)
|
|
15
18
|
} else {
|
|
16
19
|
set.call(element, param, options)
|
|
@@ -8,7 +8,7 @@ import { exec } from '../../utils'
|
|
|
8
8
|
*/
|
|
9
9
|
export default (param, element, node) => {
|
|
10
10
|
const prop = exec(param, element)
|
|
11
|
-
if (prop
|
|
11
|
+
if (prop !== element.__html) {
|
|
12
12
|
// const parser = new window.DOMParser()
|
|
13
13
|
// param = parser.parseFromString(param, 'text/html')
|
|
14
14
|
if (node.nodeName === 'SVG') node.textContent = prop
|
|
@@ -42,9 +42,11 @@ export default {
|
|
|
42
42
|
__ifFalsy: {},
|
|
43
43
|
__text: {},
|
|
44
44
|
__element: {},
|
|
45
|
-
__class: {},
|
|
46
45
|
__html: {},
|
|
46
|
+
__class: {},
|
|
47
47
|
__className: {},
|
|
48
|
+
__classNames: {},
|
|
49
|
+
__attr: {},
|
|
48
50
|
key: {},
|
|
49
51
|
tag: {},
|
|
50
52
|
parent: {},
|
|
@@ -62,5 +64,5 @@ export default {
|
|
|
62
64
|
parseDeep: {},
|
|
63
65
|
on: {},
|
|
64
66
|
component: {},
|
|
65
|
-
context: {}
|
|
67
|
+
context: {},
|
|
66
68
|
}
|
|
@@ -7,11 +7,28 @@ import { exec } from '../../utils'
|
|
|
7
7
|
* Creates a text node and appends into
|
|
8
8
|
* an original one as a child
|
|
9
9
|
*/
|
|
10
|
+
export const asd = (param, element, node) => {
|
|
11
|
+
const prop = exec(param, element)
|
|
12
|
+
if (element.tag === 'string') {
|
|
13
|
+
node.nodeValue = prop
|
|
14
|
+
}
|
|
15
|
+
else if (param !== undefined || param !== null) {
|
|
16
|
+
if (element.__text && element.__text.text !== prop) return
|
|
17
|
+
element.__text.text = prop
|
|
18
|
+
if (element.__text.node) element.__text.node.nodeValue = prop
|
|
19
|
+
else create({ tag: 'string', text: prop }, element, '__text')
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
export default (param, element, node) => {
|
|
11
24
|
const prop = exec(param, element)
|
|
12
|
-
if (element.tag === 'string')
|
|
25
|
+
if (element.tag === 'string') {
|
|
26
|
+
if (element.text === prop) return
|
|
27
|
+
node.nodeValue = prop
|
|
28
|
+
}
|
|
13
29
|
else if (param !== undefined || param !== null) {
|
|
14
30
|
if (element.__text) {
|
|
31
|
+
if (element.__text.text === prop) return
|
|
15
32
|
element.__text.text = prop
|
|
16
33
|
if (element.__text.node) element.__text.node.nodeValue = prop
|
|
17
34
|
} else create({ tag: 'string', text: prop }, element, '__text')
|
package/src/element/set.js
CHANGED
|
@@ -26,10 +26,10 @@ const set = function (params, options, el) {
|
|
|
26
26
|
const element = el || this
|
|
27
27
|
|
|
28
28
|
const isEqual = isEqualDeep(params, element.content)
|
|
29
|
+
console.error(isEqual)
|
|
30
|
+
console.log(element.path)
|
|
31
|
+
// console.error(params)
|
|
29
32
|
if (isEqual && element.content.__cached) return element
|
|
30
|
-
|
|
31
|
-
// console.group(element.key)
|
|
32
|
-
// console.log(isEqual, params, element.content)
|
|
33
33
|
removeContentElement(element)
|
|
34
34
|
|
|
35
35
|
if (params) {
|
|
@@ -40,7 +40,6 @@ const set = function (params, options, el) {
|
|
|
40
40
|
...registry.defaultOptions
|
|
41
41
|
})
|
|
42
42
|
}
|
|
43
|
-
// console.groupEnd(element.key)
|
|
44
43
|
|
|
45
44
|
return element
|
|
46
45
|
}
|
package/src/element/state.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import { update } from '.'
|
|
3
4
|
import { on } from '../event'
|
|
4
|
-
import { deepClone, exec, isFunction, isObject, overwriteDeep } from '../utils'
|
|
5
|
+
import { debounce, deepClone, exec, isFunction, isObject, overwriteDeep } from '../utils'
|
|
5
6
|
|
|
6
7
|
export const IGNORE_STATE_PARAMS = ['update', 'parse', 'clean', 'parent', '__element', '__depends', '__ref']
|
|
7
8
|
|
|
@@ -37,7 +38,10 @@ export const updateState = function (obj, options = {}) {
|
|
|
37
38
|
|
|
38
39
|
overwriteDeep(state, obj, IGNORE_STATE_PARAMS)
|
|
39
40
|
|
|
40
|
-
if (!options.preventUpdate) element
|
|
41
|
+
if (!options.preventUpdate) debounce(element, update, 150)({}, {
|
|
42
|
+
preventStateUpdate: 'once',
|
|
43
|
+
...options
|
|
44
|
+
})
|
|
41
45
|
|
|
42
46
|
if (state.__depends) {
|
|
43
47
|
for (const el in state.__depends) {
|
package/src/element/update.js
CHANGED
|
@@ -11,6 +11,8 @@ import { createNode } from '.'
|
|
|
11
11
|
import { updateProps } from './props'
|
|
12
12
|
import createState from './state'
|
|
13
13
|
|
|
14
|
+
import { measure } from '@domql/performance'
|
|
15
|
+
|
|
14
16
|
const UPDATE_DEFAULT_OPTIONS = {
|
|
15
17
|
stackChanges: false,
|
|
16
18
|
cleanExec: true,
|
|
@@ -62,26 +64,31 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
62
64
|
on.initUpdate(element.on.initUpdate, element, element.state)
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
|
|
66
67
|
for (const param in element) {
|
|
67
68
|
const prop = element[param]
|
|
68
69
|
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
if (
|
|
71
|
+
options.preventDefineUpdate === true || options.preventDefineUpdate === param ||
|
|
72
|
+
options.preventContentUpdate && param === 'content' ||
|
|
73
|
+
options.preventStateUpdate && param === 'state' ||
|
|
74
|
+
isMethod(param) || isObject(registry[param]) || prop === undefined
|
|
75
|
+
) continue
|
|
76
|
+
if (options.preventStateUpdate === 'once') options.preventStateUpdate = false
|
|
72
77
|
|
|
73
78
|
const hasDefined = define && define[param]
|
|
74
79
|
const ourParam = registry[param]
|
|
75
80
|
|
|
76
|
-
if (options.preventContentUpdate && param === 'content') console.log(param)
|
|
77
|
-
|
|
78
81
|
if (ourParam) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
if (isFunction(ourParam)) {
|
|
83
|
+
// console.log(param)
|
|
84
|
+
ourParam(prop, element, node)
|
|
85
|
+
}
|
|
82
86
|
} else if (prop && isObject(prop) && !hasDefined) {
|
|
83
87
|
if (!options.preventRecursive) {
|
|
84
|
-
update.call(prop, params[prop],
|
|
88
|
+
const callChildUpdate = () => update.call(prop, params[prop], options)
|
|
89
|
+
if (element.props.lazyLoad || options.lazyLoad) {
|
|
90
|
+
window.requestAnimationFrame(() => callChildUpdate())
|
|
91
|
+
} else callChildUpdate()
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
94
|
}
|
package/src/utils/object.js
CHANGED
|
@@ -16,6 +16,14 @@ export const memoize = (fn) => {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export const debounce = (element, func, timeout = 300) => {
|
|
20
|
+
let timer;
|
|
21
|
+
return (...args) => {
|
|
22
|
+
clearTimeout(timer);
|
|
23
|
+
timer = setTimeout(() => { func.apply(element, args) }, timeout);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
export const isTagRegistered = arg => nodes.body.indexOf(arg)
|
|
20
28
|
|
|
21
29
|
export const isObject = arg => {
|