domql 1.5.87 → 1.5.89

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
@@ -2,7 +2,7 @@
2
2
  "name": "domql",
3
3
  "description": "DOM rendering Javascript framework at early stage.",
4
4
  "author": "symbo.ls",
5
- "version": "1.5.87",
5
+ "version": "1.5.89",
6
6
  "repository": "https://github.com/domql/domql",
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org"
@@ -1,19 +1,19 @@
1
1
  'use strict'
2
2
 
3
- import DOM from '../../src'
3
+ // import DOM from '../../src'
4
4
  import { isObjectLike, exec, isObject, isEqualDeep } from '../../src/utils'
5
5
  import { classList } from '../../src/element/mixins'
6
6
  import createEmotion from '@emotion/css/create-instance'
7
7
  const ENV = process.env.NODE_ENV
8
8
 
9
9
  export const transformEmotionStyle = (emotion, live) => {
10
- return (params, element, node) => {
10
+ return (params, element, state) => {
11
11
  const execParams = exec(params, element)
12
12
  if (params) {
13
13
  if (isObjectLike(element.class)) element.class.elementStyle = execParams
14
14
  else element.class = { elementStyle: execParams }
15
15
  }
16
- transformEmotionClass(emotion, live)(element.class, element, node, true)
16
+ transformEmotionClass(emotion, live)(element.class, element, state, true)
17
17
  }
18
18
  }
19
19
 
@@ -35,22 +35,22 @@ export const transformEmotionClass = (emotion, live) => {
35
35
  const isEqual = isEqualDeep(__class[key], prop)
36
36
  if (!isEqual) {
37
37
  if ((ENV === 'test' || ENV === 'development') && isObject(prop)) prop.label = key || element.key
38
+
38
39
  const CSSed = emotion.css(prop)
39
40
  __class[key] = prop
40
41
  __classNames[key] = CSSed
41
42
  }
42
43
  }
43
44
  classList(__classNames, element, element.node, live)
45
+ // return element.class
44
46
  }
45
47
  }
46
48
 
47
- export const initDOMQLEmotion = (emotion, options) => {
49
+ export const transformDOMQLEmotion = (emotion, options) => {
48
50
  if (!emotion) emotion = createEmotion(options || { key: 'smbls' })
49
51
 
50
- DOM.define({
52
+ return {
51
53
  style: transformEmotionStyle(emotion),
52
54
  class: transformEmotionClass(emotion)
53
- }, {
54
- overwrite: true
55
- })
55
+ }
56
56
  }
@@ -95,8 +95,8 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
95
95
  }
96
96
 
97
97
  // assign context
98
- if (options.context && !root.context) root.context = options.context
99
- element.context = root.context
98
+ if (options.context && !root.context && !element.context) root.context = options.context
99
+ if (!element.context) element.context = parent.context || options.context || root.context
100
100
  const { context } = element
101
101
 
102
102
  if (context && context.components) {
@@ -106,7 +106,7 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
106
106
  if (isString(execExtend)) {
107
107
  if (components[execExtend]) element.extend = components[execExtend]
108
108
  else {
109
- if (ENV === 'test' || ENV === 'development') {
109
+ if ((ENV === 'test' || ENV === 'development') && options.verbose) {
110
110
  console.warn(execExtend, 'is not in library', components, element)
111
111
  console.warn('replacing with ', {})
112
112
  }
@@ -51,18 +51,12 @@ export const throughUpdatedExec = (element, options) => {
51
51
  return changes
52
52
  }
53
53
 
54
- export const throughInitialDefine = (element, options) => {
55
- const { define } = element
56
- let obj = {}
54
+ export const throughInitialDefine = (element) => {
55
+ const { define, context } = element
57
56
 
58
- if (isObject(define)) {
59
- obj = { ...define }
60
- }
61
- if (isObject(options.define)) {
62
- // console.log('==============')
63
- // console.log(options.define)
64
- obj = { ...obj, ...options.define }
65
- }
57
+ let obj = {}
58
+ if (isObject(define)) obj = { ...define }
59
+ if (isObject(context.define)) obj = { ...obj, ...context.define }
66
60
 
67
61
  for (const param in obj) {
68
62
  let prop = element[param]
@@ -78,17 +72,13 @@ export const throughInitialDefine = (element, options) => {
78
72
  return element
79
73
  }
80
74
 
81
- export const throughUpdatedDefine = (element, options) => {
82
- const { define, __exec } = element
75
+ export const throughUpdatedDefine = (element) => {
76
+ const { context, define, __exec } = element
83
77
  const changes = {}
84
- let obj = {}
85
78
 
86
- if (isObject(define)) {
87
- obj = { ...define }
88
- }
89
- if (isObject(options.define)) {
90
- obj = { ...obj, ...options.define }
91
- }
79
+ let obj = {}
80
+ if (isObject(define)) obj = { ...define }
81
+ if (isObject(context && context.define)) obj = { ...obj, ...context.define }
92
82
 
93
83
  for (const param in obj) {
94
84
  const execParam = __exec[param]
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { isFunction, isObject, isObjectLike } from '../utils'
3
+ import { isFunction, isObjectLike } from '../utils'
4
4
  import { registry, parseFilters } from './mixins'
5
5
  import root from './root'
6
6
 
@@ -63,7 +63,7 @@ export const setProps = function (param, options) {
63
63
  const element = this
64
64
  if (!param || !element.props) return
65
65
  element.update({ props: param }, options)
66
- return element.props
66
+ return element
67
67
  }
68
68
 
69
69
  export const defineSetter = (element, key, get, set) =>
@@ -73,8 +73,7 @@ export const keys = function () {
73
73
  const element = this
74
74
  const keys = []
75
75
  for (const param in element) {
76
- if (registry[param] && !parseFilters.elementKeys.includes(param))
77
- continue
76
+ if (registry[param] && !parseFilters.elementKeys.includes(param)) { continue }
78
77
  keys.push(param)
79
78
  }
80
79
  return keys
@@ -26,14 +26,12 @@ export const classify = (obj, element) => {
26
26
 
27
27
  export default (params, element, node, live) => {
28
28
  if (!params) return
29
- const { key, __className } = element // eslint-disable-line
29
+ const { key } = element // eslint-disable-line
30
30
  if (params === true) params = element.class = { key }
31
31
  if (isString(params)) params = element.class = { default: params }
32
32
  if (isObject(params)) params = classify(params, element)
33
33
  // TODO: fails on string
34
34
  const className = params.replace(/\s+/g, ' ').trim()
35
35
  node.classList = className
36
- // if (className && className !== __className) node.classList = className
37
- // element.__className = className
38
36
  return className
39
37
  }
@@ -30,7 +30,7 @@ const ENV = process.env.NODE_ENV
30
30
 
31
31
  export const createNode = (element, options) => {
32
32
  // create and assign a node
33
- let { node, tag } = element
33
+ let { node, tag, context } = element
34
34
 
35
35
  let isNewNode
36
36
 
@@ -61,7 +61,7 @@ export const createNode = (element, options) => {
61
61
  // iterate through all given params
62
62
  if (element.tag !== 'string' || element.tag !== 'fragment') {
63
63
  // iterate through define
64
- throughInitialDefine(element, options)
64
+ throughInitialDefine(element)
65
65
 
66
66
  // iterate through exec
67
67
  throughInitialExec(element)
@@ -74,14 +74,19 @@ export const createNode = (element, options) => {
74
74
 
75
75
  if (isMethod(param) || isObject(registry[param]) || prop === undefined) continue
76
76
 
77
- const hasDefined = element.define && element.define[param]
78
77
  const DOMQLProperty = registry[param]
79
- const hasOptionsDefine = options.define && options.define[param]
80
-
81
- if (DOMQLProperty && !hasOptionsDefine) { // Check if param is in our method registry
82
- if (isFunction(DOMQLProperty)) DOMQLProperty(prop, element, node, options)
83
- } else if (element[param] && !hasDefined && !hasOptionsDefine) {
84
- create(exec(prop, element), element, param, options) // Create element
78
+ const DOMQLPropertyFromContext = context.registry && context.registry[param]
79
+ const isGlobalTransformer = DOMQLPropertyFromContext || DOMQLProperty
80
+
81
+ const hasDefine = element.define && element.define[param]
82
+ const hasContextDefine = context.define && context.define[param]
83
+
84
+ // Check if param is in our method registry
85
+ if (isGlobalTransformer && !hasContextDefine) {
86
+ if (isFunction(isGlobalTransformer)) isGlobalTransformer(prop, element, node, options)
87
+ } else if (element[param] && !hasDefine && !hasContextDefine) {
88
+ // Create element
89
+ create(exec(prop, element), element, param, options)
85
90
  }
86
91
  }
87
92
  }
@@ -23,7 +23,7 @@ export const removeContentElement = function (el) {
23
23
  }
24
24
  }
25
25
 
26
- const set = function (params, options, el) {
26
+ const set = function (params, options = {}, el) {
27
27
  const element = el || this
28
28
 
29
29
  const isEqual = isEqualDeep(params, element.content)
@@ -37,7 +37,8 @@ const set = function (params, options, el) {
37
37
  create(params, element, 'content', {
38
38
  ignoreChildExtend: true,
39
39
  ...registry.defaultOptions,
40
- ...OPTIONS.create
40
+ ...OPTIONS.create,
41
+ ...options
41
42
  })
42
43
  }
43
44
 
@@ -178,11 +178,11 @@ export const createState = function (element, parent, opts) {
178
178
  // editor stuff
179
179
  state.projectSystemUpdate = projectSystemUpdate
180
180
  state.projectStateUpdate = projectStateUpdate
181
- state.__components = (state.__root || state).COMPONENTS
182
- state.__projectSystem = (state.__root || state).PROJECT_SYSTEM
183
- state.__projectState = (state.__root || state).PROJECT_STATE
184
- state.__projectComponents = (state.__root || state).PROJECT_COMPONENTS
185
- state.__projectPages = (state.__root || state).PROJECT_PAGES
181
+ state.__components = state.__root.COMPONENTS
182
+ state.__projectSystem = state.__root.PROJECT_SYSTEM
183
+ state.__projectState = state.__root.PROJECT_STATE
184
+ state.__projectComponents = state.__root.PROJECT_COMPONENTS
185
+ state.__projectPages = state.__root.PROJECT_PAGES
186
186
 
187
187
  // run `on.stateCreated`
188
188
  if (element.on && isFunction(element.on.stateCreated)) {
@@ -26,7 +26,7 @@ const UPDATE_DEFAULT_OPTIONS = {
26
26
 
27
27
  const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
28
28
  const element = this
29
- const { define, parent, node } = element
29
+ const { parent, node, context } = element
30
30
 
31
31
  const { currentSnapshot, calleeElement } = options
32
32
  if (!calleeElement) {
@@ -88,7 +88,7 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
88
88
 
89
89
  const overwriteChanges = overwrite(element, params, UPDATE_DEFAULT_OPTIONS)
90
90
  const execChanges = throughUpdatedExec(element, UPDATE_DEFAULT_OPTIONS)
91
- const definedChanges = throughUpdatedDefine(element, options)
91
+ const definedChanges = throughUpdatedDefine(element)
92
92
 
93
93
  if (options.stackChanges && element.__stackChanges) {
94
94
  const stackChanges = merge(definedChanges, merge(execChanges, overwriteChanges))
@@ -113,16 +113,16 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
113
113
  ) continue
114
114
  if (options.preventStateUpdate === 'once') options.preventStateUpdate = false
115
115
 
116
- const hasDefined = define && define[param]
117
- const ourParam = registry[param]
116
+ const DOMQLProperty = registry[param]
117
+ const DOMQLPropertyFromContext = context.registry && context.registry[param]
118
+ const isGlobalTransformer = DOMQLPropertyFromContext || DOMQLProperty
118
119
 
119
- const hasOptionsDefine = options.define && options.define[param]
120
+ const hasDefine = element.define && element.define[param]
121
+ const hasContextDefine = context.define && context.define[param]
120
122
 
121
- if (ourParam && !hasOptionsDefine) {
122
- if (isFunction(ourParam)) {
123
- ourParam(prop, element, node)
124
- }
125
- } else if (prop && isObject(prop) && !hasDefined && !hasOptionsDefine) {
123
+ if (isGlobalTransformer && !hasContextDefine) {
124
+ if (isFunction(isGlobalTransformer)) isGlobalTransformer(prop, element, node, options)
125
+ } else if (prop && isObject(prop) && !hasDefine && !hasContextDefine) {
126
126
  if (!options.preventRecursive) {
127
127
  const childUpdateCall = () => update.call(prop, params[prop], {
128
128
  ...options,