domql 1.4.6 → 1.4.9
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 +2 -1
- package/src/element/create.js +21 -28
- package/src/element/createNode.js +11 -0
- package/src/element/createProps.js +17 -2
- package/src/element/proto.js +1 -23
- 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.9",
|
|
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,
|
|
@@ -33,7 +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
|
|
36
|
-
prop.label = key
|
|
37
|
+
if (ENV === 'test' || ENV === 'development') prop.label = key || element.key
|
|
37
38
|
const CSSed = css(prop)
|
|
38
39
|
classObjHelper[key] = CSSed
|
|
39
40
|
}
|
package/src/element/create.js
CHANGED
|
@@ -44,13 +44,9 @@ const create = (element, parent, key, options = {}) => {
|
|
|
44
44
|
const assignedKey = element.key || key || createID.next().value
|
|
45
45
|
|
|
46
46
|
// if PARENT is not given
|
|
47
|
-
// if (parent === null) parent = root
|
|
48
|
-
// if (parent === undefined) parent = root
|
|
49
47
|
if (!parent) parent = root
|
|
50
48
|
if (isNode(parent)) parent = root[`${key}_parent`] = { node: parent }
|
|
51
49
|
|
|
52
|
-
// if (assignedKey === 'all') debugger
|
|
53
|
-
|
|
54
50
|
// if element is STRING
|
|
55
51
|
if (isString(element) || isNumber(element)) {
|
|
56
52
|
element = {
|
|
@@ -61,6 +57,7 @@ const create = (element, parent, key, options = {}) => {
|
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
// create PROTOtypal inheritance
|
|
60
|
+
|
|
64
61
|
applyPrototype(element, parent, options)
|
|
65
62
|
|
|
66
63
|
if (Object.keys(options).length) {
|
|
@@ -71,22 +68,27 @@ const create = (element, parent, key, options = {}) => {
|
|
|
71
68
|
// enable STATE
|
|
72
69
|
element.state = createState(element, parent)
|
|
73
70
|
|
|
74
|
-
// console.groupCollapsed('Create:', assignedKey)
|
|
75
|
-
// console.log(element)
|
|
76
|
-
|
|
77
71
|
// create and assign a KEY
|
|
78
72
|
element.key = assignedKey
|
|
79
73
|
|
|
80
|
-
//
|
|
74
|
+
// don't render IF in condition
|
|
75
|
+
if (isFunction(element.if)) {
|
|
76
|
+
// TODO: move as fragment
|
|
77
|
+
if (!element.if(element, element.state)) {
|
|
78
|
+
const ifFragment = cacheNode({ tag: 'fragment' })
|
|
79
|
+
element.__ifFragment = appendNode(ifFragment, parent.node)
|
|
80
|
+
element.__ifFalsy = true
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// set the PATH array
|
|
81
85
|
if (ENV === 'test' || ENV === 'development') {
|
|
82
86
|
if (!parent.path) parent.path = []
|
|
83
87
|
element.path = parent.path.concat(assignedKey)
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
// if it already HAS
|
|
87
|
-
if (element.node) {
|
|
88
|
-
// console.log('hasNode!')
|
|
89
|
-
// console.groupEnd('Create:')
|
|
90
|
+
// if it already HAS a NODE
|
|
91
|
+
if (element.node && !element.__ifFalsy) { // TODO: check on if
|
|
90
92
|
return assignNode(element, parent, assignedKey)
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -119,7 +121,7 @@ const create = (element, parent, key, options = {}) => {
|
|
|
119
121
|
if (!element.__root) element.__root = hasRoot ? parent : parent.__root
|
|
120
122
|
|
|
121
123
|
// apply props settings
|
|
122
|
-
createProps(element, parent)
|
|
124
|
+
if (!element.__ifFalsy) createProps(element, parent)
|
|
123
125
|
|
|
124
126
|
// run `on.init`
|
|
125
127
|
if (element.on && isFunction(element.on.init)) {
|
|
@@ -129,26 +131,17 @@ const create = (element, parent, key, options = {}) => {
|
|
|
129
131
|
// generate a CLASS name
|
|
130
132
|
assignClass(element)
|
|
131
133
|
|
|
132
|
-
// console.
|
|
133
|
-
// console.log(
|
|
134
|
-
// console.log('applied props:')
|
|
135
|
-
// console.log(element.props)
|
|
136
|
-
// console.log('element:')
|
|
134
|
+
// console.group('create')
|
|
135
|
+
// console.log(element.path)
|
|
137
136
|
// console.log(element)
|
|
138
|
-
// console.groupEnd('
|
|
139
|
-
|
|
140
|
-
// don't render IF in condition
|
|
141
|
-
if (isFunction(element.if) && !element.if(element, element.state)) {
|
|
142
|
-
// TODO: move as fragment
|
|
143
|
-
const ifFragment = cacheNode({ tag: 'fragment' })
|
|
144
|
-
element.__ifFragment = appendNode(ifFragment, parent.node)
|
|
145
|
-
element.__ifFalsy = true
|
|
146
|
-
return
|
|
147
|
-
}
|
|
137
|
+
// console.groupEnd('create')
|
|
138
|
+
// if (parent.key === 'footer' && key === '0') debugger
|
|
148
139
|
|
|
149
140
|
// CREATE a real NODE
|
|
150
141
|
createNode(element, options)
|
|
151
142
|
|
|
143
|
+
if (element.__ifFalsy) return element
|
|
144
|
+
|
|
152
145
|
// assign NODE
|
|
153
146
|
assignNode(element, parent, key)
|
|
154
147
|
|
|
@@ -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
|
@@ -12,26 +12,10 @@ export const applyPrototype = (element, parent, options = {}) => {
|
|
|
12
12
|
if (isFunction(element)) element = exec(element, parent)
|
|
13
13
|
|
|
14
14
|
const { proto } = element
|
|
15
|
-
|
|
16
|
-
// merge if proto is array
|
|
17
|
-
// const proto = mergeAndCloneIfArray(element.proto, v => {
|
|
18
|
-
// if (v.props) cache.props.push(v.props)
|
|
19
|
-
// console.log('v.propsIN_PROTO:')
|
|
20
|
-
// console.log(v.props)
|
|
21
|
-
// })
|
|
22
|
-
|
|
23
|
-
// console.log(proto)
|
|
24
15
|
const protoStack = getProtoStack(proto)
|
|
25
16
|
|
|
26
17
|
if (ENV !== 'test' || ENV !== 'development') delete element.proto
|
|
27
18
|
|
|
28
|
-
// console.log(parent.childProto)
|
|
29
|
-
|
|
30
|
-
// console.log(element)
|
|
31
|
-
// console.log(proto)
|
|
32
|
-
// console.log(protoStack)
|
|
33
|
-
// debugger
|
|
34
|
-
|
|
35
19
|
let childProtoStack = []
|
|
36
20
|
if (parent) {
|
|
37
21
|
// Assign parent attr to the element
|
|
@@ -41,9 +25,6 @@ export const applyPrototype = (element, parent, options = {}) => {
|
|
|
41
25
|
}
|
|
42
26
|
}
|
|
43
27
|
|
|
44
|
-
// console.log(proto, parent && parent.childProto)
|
|
45
|
-
// console.log(protoStack, childProtoStack)
|
|
46
|
-
|
|
47
28
|
const protoLength = protoStack.length
|
|
48
29
|
const childProtoLength = childProtoStack.length
|
|
49
30
|
|
|
@@ -67,11 +48,8 @@ export const applyPrototype = (element, parent, options = {}) => {
|
|
|
67
48
|
const component = exec(element.component || mergedProto.component, element)
|
|
68
49
|
if (component && options.components && options.components[component]) {
|
|
69
50
|
const componentProto = cloneAndMergeArrayProto(getProtoStack(options.components[component]))
|
|
70
|
-
mergedProto = deepMergeProto(
|
|
51
|
+
mergedProto = deepMergeProto(componentProto, mergedProto)
|
|
71
52
|
}
|
|
72
53
|
|
|
73
|
-
// console.log(mergedProto)
|
|
74
54
|
return deepMergeProto(element, mergedProto)
|
|
75
|
-
|
|
76
|
-
// final merging with prototype
|
|
77
55
|
}
|
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
|
|