domql 1.4.7 → 1.4.10

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.10",
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
  }
@@ -12,7 +12,7 @@ import update from './update'
12
12
  import * as on from '../event/on'
13
13
  import { assignClass } from './mixins/classList'
14
14
  import { isFunction, isNumber, isString, createID, isNode } from '../utils'
15
- import { remove, lookup, log, keys, parse, parseDeep } from './methods'
15
+ import { remove, lookup, setProps, log, keys, parse, parseDeep } from './methods'
16
16
  import cacheNode from './cache'
17
17
  import { registry } from './mixins'
18
18
  // import { overwrite, clone, fillTheRest } from '../utils'
@@ -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,31 +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
- // set the PATH
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
- // 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
- // if it already HAS A NODE
96
- if (element.node) {
97
- // console.log('hasNode!')
98
- // console.groupEnd('Create:')
90
+ // if it already HAS a NODE
91
+ if (element.node && !element.__ifFalsy) { // TODO: check on if
99
92
  return assignNode(element, parent, assignedKey)
100
93
  }
101
94
 
@@ -103,6 +96,7 @@ const create = (element, parent, key, options = {}) => {
103
96
  element.set = set
104
97
  element.update = update
105
98
  element.remove = remove
99
+ element.setProps = setProps
106
100
  element.lookup = lookup
107
101
  element.parse = parse
108
102
  element.parseDeep = parseDeep
@@ -128,7 +122,7 @@ const create = (element, parent, key, options = {}) => {
128
122
  if (!element.__root) element.__root = hasRoot ? parent : parent.__root
129
123
 
130
124
  // apply props settings
131
- createProps(element, parent)
125
+ if (!element.__ifFalsy) createProps(element, parent)
132
126
 
133
127
  // run `on.init`
134
128
  if (element.on && isFunction(element.on.init)) {
@@ -138,17 +132,17 @@ const create = (element, parent, key, options = {}) => {
138
132
  // generate a CLASS name
139
133
  assignClass(element)
140
134
 
141
- // console.log('cache.props:')
142
- // console.log(cache.props)
143
- // console.log('applied props:')
144
- // console.log(element.props)
145
- // console.log('element:')
135
+ // console.group('create')
136
+ // console.log(element.path)
146
137
  // console.log(element)
147
- // console.groupEnd('Create:')
138
+ // console.groupEnd('create')
139
+ // if (parent.key === 'footer' && key === '0') debugger
148
140
 
149
141
  // CREATE a real NODE
150
142
  createNode(element, options)
151
143
 
144
+ if (element.__ifFalsy) return element
145
+
152
146
  // assign NODE
153
147
  assignNode(element, parent, key)
154
148
 
@@ -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)
@@ -12,7 +12,7 @@ import update from './update'
12
12
  import parse from './parse'
13
13
  import set from './set'
14
14
 
15
- import { lookup, remove, get, log, keys } from './methods'
15
+ import { lookup, remove, get, setProps, log, keys } from './methods'
16
16
 
17
17
  export {
18
18
  nodes,
@@ -27,6 +27,7 @@ export {
27
27
  update,
28
28
  parse,
29
29
  lookup,
30
+ setProps,
30
31
  set,
31
32
  get,
32
33
  log,
@@ -33,6 +33,13 @@ export const set = function () {
33
33
  export const update = function () {
34
34
  }
35
35
 
36
+ export const setProps = function (param) {
37
+ const element = this
38
+ if (!param || !element.props) return
39
+ element.update({ props: param })
40
+ return element.props
41
+ }
42
+
36
43
  export const defineSetter = (element, key, get, set) =>
37
44
  Object.defineProperty(element, key, { get, set })
38
45
 
@@ -90,6 +97,7 @@ export const isMethod = function (param) {
90
97
  param === 'lookup' ||
91
98
  param === 'keys' ||
92
99
  param === 'parse' ||
100
+ param === 'setProps' ||
93
101
  param === 'parseDeep' ||
94
102
  param === 'if' ||
95
103
  param === 'log'
@@ -45,6 +45,7 @@ export default {
45
45
  node: {},
46
46
  set: {},
47
47
  update: {},
48
+ setProps: {},
48
49
  remove: {},
49
50
  lookup: {},
50
51
  keys: {},
@@ -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(mergedProto, componentProto)
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
  }
@@ -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