domql 1.4.7 → 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 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.7",
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.10.4",
30
- "@babel/preset-env": "^7.10.4",
31
- "babel-eslint": "^10.0.3",
32
- "babel-jest": "^28.1.0",
33
- "babel-preset-env": "^1.7.0",
34
- "coveralls": "^3.0.5",
35
- "eslint": "^8.10.0",
36
- "eslint-plugin-jest": "^26.1.0",
37
- "jest": "^28.1.0",
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-bundler": "^1.12.4",
41
- "standard": "^17.0.0"
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 || element.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
  }
@@ -77,23 +77,24 @@ 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 = []
83
93
  element.path = parent.path.concat(assignedKey)
84
94
  }
85
95
 
86
- // don't render IF in condition
87
- if (isFunction(element.if) && !element.if(element, element.state)) {
88
- // TODO: move as fragment
89
- const ifFragment = cacheNode({ tag: 'fragment' })
90
- element.__ifFragment = appendNode(ifFragment, parent.node)
91
- element.__ifFalsy = true
92
- return
93
- }
94
-
95
96
  // if it already HAS A NODE
96
- if (element.node) {
97
+ if (element.node) { // TODO: check on if
97
98
  // console.log('hasNode!')
98
99
  // console.groupEnd('Create:')
99
100
  return assignNode(element, parent, assignedKey)
@@ -128,7 +129,7 @@ const create = (element, parent, key, options = {}) => {
128
129
  if (!element.__root) element.__root = hasRoot ? parent : parent.__root
129
130
 
130
131
  // apply props settings
131
- createProps(element, parent)
132
+ if (!element.__ifFalsy) createProps(element, parent)
132
133
 
133
134
  // run `on.init`
134
135
  if (element.on && isFunction(element.on.init)) {
@@ -146,9 +147,18 @@ const create = (element, parent, key, options = {}) => {
146
147
  // console.log(element)
147
148
  // console.groupEnd('Create:')
148
149
 
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
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
- if (hasArg[1] && parent.props[hasArg[1]]) propsStack.push(parent.props[hasArg[1]])
19
- else if (matchParent) propsStack.push(matchParent)
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)
@@ -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)
@@ -25,15 +25,41 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
25
25
  params = { text: params }
26
26
  }
27
27
 
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
+
28
50
  if (element.on && isFunction(element.on.initUpdate) && !options.ignoreInitUpdate) {
29
51
  preventUpdate = on.initUpdate(element.on.initUpdate, element, element.state)
30
52
  }
31
53
 
54
+ // console.group('update')
55
+ // console.log(element.path)
56
+ // console.log(element)
32
57
  // if (params.props) {
33
- // console.log('INSIDE:')
34
- // console.log(params.props)
58
+ // console.log('INSIDE:')
59
+ // console.log(params.props)
35
60
  // }
36
- updateProps(params.props, element, parent)
61
+ if (!element.__ifFalsy) updateProps(params.props, element, parent)
62
+
37
63
 
38
64
  // const state = params.state || element.state
39
65
  // element.state = createState({ state }, parent)
@@ -50,24 +76,25 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
50
76
  // if (Object.keys(stackChanges).length === 0) return
51
77
  // else console.log(element.path, '\n\n', stackChanges)
52
78
 
53
- if (isFunction(element.if)) {
54
- // TODO: move as fragment
55
- const ifPassed = element.if(element, element.state)
56
- if (element.__ifFalsy && ifPassed) {
57
- createNode(element)
58
- appendNode(element.node, element.__ifFragment)
59
- delete element.__ifFalsy
60
- } else if (element.node && !ifPassed) {
61
- element.node.remove()
62
- element.__ifFalsy = true
63
- }
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)
64
84
  }
65
85
 
66
- if (!node || options.preventRecursive) return
86
+ // console.warn(element.key)
87
+ // console.groupEnd('update')
67
88
 
68
89
  for (const param in element) {
69
90
  const prop = element[param]
70
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
+
71
98
  if (options.preventContentUpdate && param === 'content') continue
72
99
  if (isMethod(param) || isObject(registry[param]) || prop === undefined) continue
73
100