domql 1.4.5 → 1.4.8
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 +16 -12
- package/packages/emotion/index.js +3 -1
- package/src/element/create.js +20 -10
- package/src/element/createNode.js +11 -0
- package/src/element/createProps.js +17 -2
- package/src/element/proto.js +6 -0
- package/src/element/update.js +52 -17
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.4.
|
|
6
|
+
"version": "1.4.8",
|
|
7
7
|
"repository": "https://github.com/rackai/domql",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"registry": "https://registry.npmjs.org"
|
|
@@ -26,19 +26,23 @@
|
|
|
26
26
|
"regenerator-runtime": "^0.13.5"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@babel/core": "^7.
|
|
30
|
-
"@babel/
|
|
31
|
-
"babel-
|
|
32
|
-
"babel-
|
|
33
|
-
"babel-
|
|
34
|
-
"
|
|
35
|
-
"eslint": "^8.
|
|
36
|
-
"eslint-
|
|
37
|
-
"
|
|
29
|
+
"@babel/core": "^7.16.0",
|
|
30
|
+
"@babel/eslint-parser": "^7.16.3",
|
|
31
|
+
"@babel/preset-env": "^7.16.4",
|
|
32
|
+
"@parcel/babel-preset-env": "^2.0.1",
|
|
33
|
+
"babel-jest": "^27.4.4",
|
|
34
|
+
"esbuild": "^0.14.47",
|
|
35
|
+
"eslint": "^8.4.0",
|
|
36
|
+
"eslint-config-standard": "^16.0.3",
|
|
37
|
+
"eslint-plugin-import": "^2.25.3",
|
|
38
|
+
"eslint-plugin-jest": "^25.3.0",
|
|
39
|
+
"eslint-plugin-node": "^11.1.0",
|
|
40
|
+
"jest": "^27.4.4",
|
|
41
|
+
"jsdom": "^19.0.0",
|
|
38
42
|
"nodemon": "^2.0.6",
|
|
39
43
|
"np": "^7.2.0",
|
|
40
|
-
"parcel
|
|
41
|
-
"standard": "^
|
|
44
|
+
"parcel": "^2.0.1",
|
|
45
|
+
"standard": "^16.0.1"
|
|
42
46
|
},
|
|
43
47
|
"jest": {
|
|
44
48
|
"collectCoverageFrom": [
|
|
@@ -4,6 +4,7 @@ import DOM from '../../src'
|
|
|
4
4
|
import { isObjectLike, exec } from '../../src/utils'
|
|
5
5
|
import { classList } from '../../src/element/mixins'
|
|
6
6
|
import createEmotion from '@emotion/css/create-instance'
|
|
7
|
+
const ENV = process.env.NODE_ENV
|
|
7
8
|
|
|
8
9
|
const {
|
|
9
10
|
flush,
|
|
@@ -16,7 +17,7 @@ const {
|
|
|
16
17
|
css,
|
|
17
18
|
sheet,
|
|
18
19
|
cache
|
|
19
|
-
} = createEmotion({ key: '
|
|
20
|
+
} = createEmotion({ key: 'smbls' })
|
|
20
21
|
|
|
21
22
|
const style = (params, element, node) => {
|
|
22
23
|
const execPareams = exec(params, element)
|
|
@@ -33,6 +34,7 @@ const classf = (params, element, node) => {
|
|
|
33
34
|
for (const key in params) {
|
|
34
35
|
const prop = exec(params[key], element)
|
|
35
36
|
if (!prop) continue
|
|
37
|
+
if (ENV === 'test' || ENV === 'development') prop.label = key || element.key
|
|
36
38
|
const CSSed = css(prop)
|
|
37
39
|
classObjHelper[key] = CSSed
|
|
38
40
|
}
|
package/src/element/create.js
CHANGED
|
@@ -77,6 +77,16 @@ const create = (element, parent, key, options = {}) => {
|
|
|
77
77
|
// create and assign a KEY
|
|
78
78
|
element.key = assignedKey
|
|
79
79
|
|
|
80
|
+
// don't render IF in condition
|
|
81
|
+
if (isFunction(element.if)) {
|
|
82
|
+
// TODO: move as fragment
|
|
83
|
+
if (!element.if(element, element.state)) {
|
|
84
|
+
const ifFragment = cacheNode({ tag: 'fragment' })
|
|
85
|
+
element.__ifFragment = appendNode(ifFragment, parent.node)
|
|
86
|
+
element.__ifFalsy = true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
80
90
|
// set the PATH
|
|
81
91
|
if (ENV === 'test' || ENV === 'development') {
|
|
82
92
|
if (!parent.path) parent.path = []
|
|
@@ -84,7 +94,7 @@ const create = (element, parent, key, options = {}) => {
|
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
// if it already HAS A NODE
|
|
87
|
-
if (element.node) {
|
|
97
|
+
if (element.node) { // TODO: check on if
|
|
88
98
|
// console.log('hasNode!')
|
|
89
99
|
// console.groupEnd('Create:')
|
|
90
100
|
return assignNode(element, parent, assignedKey)
|
|
@@ -119,7 +129,7 @@ const create = (element, parent, key, options = {}) => {
|
|
|
119
129
|
if (!element.__root) element.__root = hasRoot ? parent : parent.__root
|
|
120
130
|
|
|
121
131
|
// apply props settings
|
|
122
|
-
createProps(element, parent)
|
|
132
|
+
if (!element.__ifFalsy) createProps(element, parent)
|
|
123
133
|
|
|
124
134
|
// run `on.init`
|
|
125
135
|
if (element.on && isFunction(element.on.init)) {
|
|
@@ -137,18 +147,18 @@ const create = (element, parent, key, options = {}) => {
|
|
|
137
147
|
// console.log(element)
|
|
138
148
|
// console.groupEnd('Create:')
|
|
139
149
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return
|
|
147
|
-
}
|
|
150
|
+
|
|
151
|
+
// console.group('create')
|
|
152
|
+
// console.log(element.path)
|
|
153
|
+
// console.log(element)
|
|
154
|
+
// console.groupEnd('create')
|
|
155
|
+
// if (parent.key === 'footer' && key === '0') debugger
|
|
148
156
|
|
|
149
157
|
// CREATE a real NODE
|
|
150
158
|
createNode(element, options)
|
|
151
159
|
|
|
160
|
+
if (element.__ifFalsy) return element
|
|
161
|
+
|
|
152
162
|
// assign NODE
|
|
153
163
|
assignNode(element, parent, key)
|
|
154
164
|
|
|
@@ -38,9 +38,13 @@ const createNode = (element, options) => {
|
|
|
38
38
|
// console.log(element)
|
|
39
39
|
// console.groupEnd('CREATE:')
|
|
40
40
|
|
|
41
|
+
// if (element.__ifFalsy) return element
|
|
42
|
+
|
|
41
43
|
if (!node) {
|
|
42
44
|
isNewNode = true
|
|
43
45
|
|
|
46
|
+
if (element.__ifFalsy) return element
|
|
47
|
+
|
|
44
48
|
if (tag === 'shadow') {
|
|
45
49
|
node = element.node = element.parent.node.attachShadow({ mode: 'open' })
|
|
46
50
|
} else node = element.node = cacheNode(element)
|
|
@@ -58,6 +62,8 @@ const createNode = (element, options) => {
|
|
|
58
62
|
if (isFunction(node.setAttribute)) node.setAttribute('key', element.key)
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
if (element.__ifFalsy) return element
|
|
66
|
+
|
|
61
67
|
// iterate through all given params
|
|
62
68
|
if (element.tag !== 'string' || element.tag !== 'fragment') {
|
|
63
69
|
// iterate through define
|
|
@@ -72,6 +78,11 @@ const createNode = (element, options) => {
|
|
|
72
78
|
for (const param in element) {
|
|
73
79
|
const prop = element[param]
|
|
74
80
|
|
|
81
|
+
// console.group('createNode')
|
|
82
|
+
// console.log(param)
|
|
83
|
+
// console.log(prop)
|
|
84
|
+
// console.groupEnd('createNode')
|
|
85
|
+
|
|
75
86
|
if (isMethod(param) || isObject(registry[param]) || prop === undefined) continue
|
|
76
87
|
|
|
77
88
|
const hasDefined = element.define && element.define[param]
|
|
@@ -9,14 +9,29 @@ const initProps = (element, parent) => {
|
|
|
9
9
|
const hasMatch = isString(props) && props.indexOf('match') > -1
|
|
10
10
|
const matchParent = parent.props && parent.props[element.key]
|
|
11
11
|
|
|
12
|
+
const objectizeStringProperty = propValue => {
|
|
13
|
+
if (isString(propValue)) return { inheritedString: propValue }
|
|
14
|
+
return propValue
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
if (isObject(props)) {
|
|
13
18
|
propsStack.push(props)
|
|
14
19
|
} else if (props === 'inherit') {
|
|
15
20
|
if (parent.props) propsStack.push(parent.props)
|
|
16
21
|
} else if (hasMatch) {
|
|
17
22
|
const hasArg = props.split(' ')
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
let matchParentValue
|
|
24
|
+
if (hasArg[1] && parent.props[hasArg[1]]) {
|
|
25
|
+
const secondArgasParentMatchProp = parent.props[hasArg[1]]
|
|
26
|
+
propsStack.push(
|
|
27
|
+
objectizeStringProperty(secondArgasParentMatchProp)
|
|
28
|
+
)
|
|
29
|
+
} else if (matchParent) {
|
|
30
|
+
propsStack.push(
|
|
31
|
+
objectizeStringProperty(matchParent)
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
propsStack.push(matchParentValue)
|
|
20
35
|
} else if (props) propsStack.push(props)
|
|
21
36
|
|
|
22
37
|
if (matchParent && props !== 'match') propsStack.push(matchParent)
|
package/src/element/proto.js
CHANGED
|
@@ -47,6 +47,12 @@ export const applyPrototype = (element, parent, options = {}) => {
|
|
|
47
47
|
const protoLength = protoStack.length
|
|
48
48
|
const childProtoLength = childProtoStack.length
|
|
49
49
|
|
|
50
|
+
// console.group('proto')
|
|
51
|
+
// console.log(protoLength)
|
|
52
|
+
// console.log(childProtoLength)
|
|
53
|
+
// console.log(element)
|
|
54
|
+
// console.groupEnd('proto')
|
|
55
|
+
|
|
50
56
|
let stack = []
|
|
51
57
|
if (protoLength && childProtoLength) {
|
|
52
58
|
stack = jointStacks(protoStack, childProtoStack)
|
package/src/element/update.js
CHANGED
|
@@ -25,11 +25,41 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
25
25
|
params = { text: params }
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
if (
|
|
29
|
-
|
|
28
|
+
if (isFunction(element.if)) {
|
|
29
|
+
// TODO: move as fragment
|
|
30
|
+
const ifPassed = element.if(element, element.state)
|
|
31
|
+
|
|
32
|
+
// console.group('updateLoop')
|
|
33
|
+
// console.log(element)
|
|
34
|
+
// console.log(element.__ifFalsy)
|
|
35
|
+
// console.log(ifPassed)
|
|
36
|
+
// console.groupEnd('updateLoop')
|
|
37
|
+
|
|
38
|
+
// if (element.__ifFalsy && ifPassed) {
|
|
39
|
+
if (ifPassed) delete element.__ifFalsy
|
|
40
|
+
|
|
41
|
+
if (element.__ifFalsy && ifPassed) {
|
|
42
|
+
createNode(element)
|
|
43
|
+
appendNode(element.node, element.__ifFragment)
|
|
44
|
+
} else if (element.node && !ifPassed) {
|
|
45
|
+
element.node.remove()
|
|
46
|
+
element.__ifFalsy = true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (element.on && isFunction(element.on.initUpdate) && !options.ignoreInitUpdate) {
|
|
51
|
+
preventUpdate = on.initUpdate(element.on.initUpdate, element, element.state)
|
|
30
52
|
}
|
|
31
53
|
|
|
32
|
-
|
|
54
|
+
// console.group('update')
|
|
55
|
+
// console.log(element.path)
|
|
56
|
+
// console.log(element)
|
|
57
|
+
// if (params.props) {
|
|
58
|
+
// console.log('INSIDE:')
|
|
59
|
+
// console.log(params.props)
|
|
60
|
+
// }
|
|
61
|
+
if (!element.__ifFalsy) updateProps(params.props, element, parent)
|
|
62
|
+
|
|
33
63
|
|
|
34
64
|
// const state = params.state || element.state
|
|
35
65
|
// element.state = createState({ state }, parent)
|
|
@@ -42,25 +72,30 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
42
72
|
const stackChanges = merge(definedChanges, merge(execChanges, overwriteChanges))
|
|
43
73
|
element.__stackChanges.push(stackChanges)
|
|
44
74
|
}
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
element.node.remove()
|
|
55
|
-
element.__ifFalsy = true
|
|
56
|
-
}
|
|
75
|
+
// const stackChanges = merge(definedChanges, merge(execChanges, overwriteChanges))
|
|
76
|
+
// if (Object.keys(stackChanges).length === 0) return
|
|
77
|
+
// else console.log(element.path, '\n\n', stackChanges)
|
|
78
|
+
|
|
79
|
+
// console.log(element.key, element.__ifFalsy)
|
|
80
|
+
if (element.__ifFalsy || options.preventRecursive) return element
|
|
81
|
+
if (!node) {
|
|
82
|
+
return
|
|
83
|
+
// return createNode(element, options)
|
|
57
84
|
}
|
|
58
85
|
|
|
59
|
-
|
|
86
|
+
// console.warn(element.key)
|
|
87
|
+
// console.groupEnd('update')
|
|
60
88
|
|
|
61
89
|
for (const param in element) {
|
|
62
90
|
const prop = element[param]
|
|
63
91
|
|
|
92
|
+
// console.group('updateLoop')
|
|
93
|
+
// console.log(param)
|
|
94
|
+
// console.log(prop)
|
|
95
|
+
// console.groupEnd('updateLoop')
|
|
96
|
+
// if (element.key === 'span' && param === 'node') debugger
|
|
97
|
+
|
|
98
|
+
if (options.preventContentUpdate && param === 'content') continue
|
|
64
99
|
if (isMethod(param) || isObject(registry[param]) || prop === undefined) continue
|
|
65
100
|
|
|
66
101
|
const hasDefined = define && define[param]
|
|
@@ -71,7 +106,7 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
71
106
|
if (ourParam) {
|
|
72
107
|
if (isFunction(ourParam)) ourParam(prop, element, node)
|
|
73
108
|
} else if (prop && isObject(prop) && !hasDefined) {
|
|
74
|
-
update.call(prop, params[prop], UPDATE_DEFAULT_OPTIONS)
|
|
109
|
+
if (!options.preventChildrenUpdate) update.call(prop, params[prop], UPDATE_DEFAULT_OPTIONS)
|
|
75
110
|
}
|
|
76
111
|
}
|
|
77
112
|
|