domql 1.3.3 → 1.4.1

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.3.3",
6
+ "version": "1.4.1",
7
7
  "repository": "https://github.com/rackai/domql",
8
8
  "publishConfig": {
9
9
  "registry": "https://registry.npmjs.org"
@@ -29,16 +29,16 @@
29
29
  "@babel/core": "^7.10.4",
30
30
  "@babel/preset-env": "^7.10.4",
31
31
  "babel-eslint": "^10.0.3",
32
- "babel-jest": "^27.0.2",
32
+ "babel-jest": "^28.1.0",
33
33
  "babel-preset-env": "^1.7.0",
34
34
  "coveralls": "^3.0.5",
35
35
  "eslint": "^8.10.0",
36
36
  "eslint-plugin-jest": "^26.1.0",
37
- "jest": "^27.0.6",
37
+ "jest": "^28.1.0",
38
38
  "nodemon": "^2.0.6",
39
39
  "np": "^7.2.0",
40
40
  "parcel-bundler": "^1.12.4",
41
- "standard": "^16.0.1"
41
+ "standard": "^17.0.0"
42
42
  },
43
43
  "jest": {
44
44
  "collectCoverageFrom": [
@@ -32,6 +32,7 @@ const classf = (params, element, node) => {
32
32
  const classObjHelper = {}
33
33
  for (const key in params) {
34
34
  const prop = exec(params[key], element)
35
+ if (!prop) continue
35
36
  const CSSed = css(prop)
36
37
  classObjHelper[key] = CSSed
37
38
  }
@@ -14,6 +14,7 @@ import { assignClass } from './mixins/classList'
14
14
  import { isFunction, isNumber, isString, createID, isNode } from '../utils'
15
15
  import { remove, lookup, log, keys, parse, parseDeep } from './methods'
16
16
  import cacheNode from './cache'
17
+ import { registry } from './mixins'
17
18
  // import { overwrite, clone, fillTheRest } from '../utils'
18
19
 
19
20
  const ENV = process.env.NODE_ENV
@@ -26,6 +27,31 @@ const create = (element, parent, key, options = {}) => {
26
27
  if (element === undefined) element = {}
27
28
  if (element === null) return
28
29
 
30
+ if (Object.keys(options).length) {
31
+ registry.defaultOptions = options
32
+ if (options.ignoreChildProto) delete options.ignoreChildProto
33
+ }
34
+
35
+ // if element is proto
36
+ if (element.__hash) {
37
+ element = { proto: element }
38
+ }
39
+
40
+ // if KEY is PROTO
41
+ if (options.components) {
42
+ const { components } = options
43
+
44
+ const k = element.key || key
45
+ const keyIsProto = isString(k) && k.charAt(0) === k.charAt(0).toUpperCase()
46
+ let component
47
+ if (keyIsProto) component = key
48
+
49
+ // if proto comes from library as string
50
+ const fromLibrary = component || isString(element.proto) ? element.proto : element.component
51
+ const isInLibrary = components[fromLibrary]
52
+ if (isInLibrary) element = { proto: isInLibrary, props: element }
53
+ }
54
+
29
55
  // define KEY
30
56
  const assignedKey = element.key || key || createID.next().value
31
57
 
@@ -71,14 +97,6 @@ const create = (element, parent, key, options = {}) => {
71
97
  return assignNode(element, parent, assignedKey)
72
98
  }
73
99
 
74
- // run `on.init`
75
- if (element.on && isFunction(element.on.init)) {
76
- on.init(element.on.init, element, element.state)
77
- }
78
-
79
- // generate a CLASS name
80
- assignClass(element)
81
-
82
100
  // assign METHODS
83
101
  element.set = set
84
102
  element.update = update
@@ -110,6 +128,14 @@ const create = (element, parent, key, options = {}) => {
110
128
  // apply props settings
111
129
  createProps(element, parent)
112
130
 
131
+ // run `on.init`
132
+ if (element.on && isFunction(element.on.init)) {
133
+ on.init(element.on.init, element, element.state)
134
+ }
135
+
136
+ // generate a CLASS name
137
+ assignClass(element)
138
+
113
139
  // console.log('cache.props:')
114
140
  // console.log(cache.props)
115
141
  // console.log('applied props:')
@@ -128,7 +154,7 @@ const create = (element, parent, key, options = {}) => {
128
154
  }
129
155
 
130
156
  // CREATE a real NODE
131
- createNode(element)
157
+ createNode(element, options)
132
158
 
133
159
  // assign NODE
134
160
  assignNode(element, parent, key)
@@ -28,7 +28,7 @@ const ENV = process.env.NODE_ENV
28
28
  // }
29
29
  // })
30
30
 
31
- const createNode = (element) => {
31
+ const createNode = (element, options) => {
32
32
  // create and assign a node
33
33
  let { node, tag } = element
34
34
 
@@ -78,9 +78,9 @@ const createNode = (element) => {
78
78
  const ourParam = registry[param]
79
79
 
80
80
  if (ourParam) { // Check if param is in our method registry
81
- if (isFunction(ourParam)) ourParam(prop, element, node)
81
+ if (isFunction(ourParam)) ourParam(prop, element, node, options)
82
82
  } else if (element[param] && !hasDefined) {
83
- create(prop, element, param) // Create element
83
+ create(prop, element, param, options) // Create element
84
84
  }
85
85
  }
86
86
  }
@@ -1,15 +1,25 @@
1
1
  'use strict'
2
2
 
3
- import { deepClone, deepMerge, exec, isArray } from '../utils'
3
+ import { deepClone, deepMerge, exec, isArray, isObject, isString } from '../utils'
4
4
 
5
5
  const initProps = (element, parent) => {
6
+ const { props } = element
6
7
  const propsStack = []
7
8
 
8
- if (element.props === 'inherit') {
9
- if (parent && parent.props) propsStack.push(parent.props)
10
- } else if (element.props === 'match') {
11
- if (parent && parent.props) propsStack.push(parent.props[element.key])
12
- } else if (element.props) propsStack.push(element.props)
9
+ const hasMatch = isString(props) && props.indexOf('match') > -1
10
+ const matchParent = parent.props && parent.props[element.key]
11
+
12
+ if (isObject(props)) {
13
+ propsStack.push(props)
14
+ } else if (props === 'inherit') {
15
+ if (parent.props) propsStack.push(parent.props)
16
+ } else if (hasMatch) {
17
+ 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)
20
+ } else if (props) propsStack.push(props)
21
+
22
+ if (matchParent && props !== 'match') propsStack.push(matchParent)
13
23
 
14
24
  if (isArray(element.__proto)) {
15
25
  element.__proto.map(proto => {
@@ -6,12 +6,12 @@ import set from '../set'
6
6
  * Appends anything as content
7
7
  * an original one as a child
8
8
  */
9
- export default (param, element, node) => {
9
+ export default (param, element, node, options) => {
10
10
  if (param && element) {
11
11
  if (param.__hash === element.content.__hash && element.content.update) {
12
12
  element.content.update(param)
13
13
  } else {
14
- set.call(element, param)
14
+ set.call(element, param, options)
15
15
  }
16
16
  }
17
17
  }
@@ -51,5 +51,6 @@ export default {
51
51
  log: {},
52
52
  parse: {},
53
53
  parseDeep: {},
54
- on: {}
54
+ on: {},
55
+ component: {}
55
56
  }
@@ -54,7 +54,12 @@ export const applyPrototype = (element, parent, options = {}) => {
54
54
  stack = protoStack
55
55
  } else if (childProtoLength) {
56
56
  stack = childProtoStack
57
- } else return element
57
+ } else if (!options.proto) return element
58
+
59
+ if (options.proto) {
60
+ const defaultOptionsProto = getProtoStack(options.proto)
61
+ stack = [].concat(stack, defaultOptionsProto)
62
+ }
58
63
 
59
64
  element.__proto = stack
60
65
  const mergedProto = cloneAndMergeArrayProto(stack)
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import create from './create'
4
+ import { registry } from './mixins'
4
5
 
5
6
  const removeContentElement = (params, element) => {
6
7
  if (params && element.content) {
@@ -18,7 +19,7 @@ const removeContentElement = (params, element) => {
18
19
  }
19
20
  }
20
21
 
21
- const set = function (params, enter, leave) {
22
+ const set = function (params, options) {
22
23
  const element = this
23
24
 
24
25
  removeContentElement(params, element)
@@ -27,7 +28,8 @@ const set = function (params, enter, leave) {
27
28
  const { childProto } = params
28
29
  if (!childProto && element.childProto) params.childProto = element.childProto
29
30
  create(params, element, 'content', {
30
- ignoreChildProto: true
31
+ ignoreChildProto: true,
32
+ ...registry.defaultOptions
31
33
  })
32
34
  }
33
35
 
@@ -19,16 +19,13 @@ export const setHashedProto = (proto, stack) => {
19
19
  const hash = generateHash()
20
20
  proto.__hash = hash
21
21
  protoStackRegistry[hash] = stack
22
- return protoStackRegistry[hash]
22
+ return stack
23
23
  }
24
24
 
25
25
  export const getProtoStackRegistry = (proto, stack) => {
26
- if (proto.__hash) {
26
+ if (proto.__hash)
27
27
  return stack.concat(getHashedProto(proto))
28
- } else {
29
- setHashedProto(proto, stack)
30
- }
31
- return stack // .concat(hashedProto)
28
+ return setHashedProto(proto, stack) // stack .concat(hashedProto)
32
29
  }
33
30
 
34
31
  // stacking