domql 1.5.47 → 1.5.49
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 +2 -2
- package/src/element/create.js +25 -10
- package/src/element/mixins/content.js +0 -3
- package/src/element/mixins/registry.js +2 -0
- package/src/element/node.js +2 -2
- package/src/element/state.js +57 -11
- package/src/element/update.js +10 -2
- package/src/utils/object.js +1 -1
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": "symbo.ls",
|
|
6
|
-
"version": "1.5.
|
|
6
|
+
"version": "1.5.49",
|
|
7
7
|
"repository": "https://github.com/domql/domql",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"registry": "https://registry.npmjs.org"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"source": true,
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@domql/utils": "
|
|
26
|
+
"@domql/utils": "latest",
|
|
27
27
|
"regenerator-runtime": "^0.13.5"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
package/src/element/create.js
CHANGED
|
@@ -33,6 +33,7 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
33
33
|
element = {}
|
|
34
34
|
}
|
|
35
35
|
if (element === null) return
|
|
36
|
+
if (element === true) element = { text: true }
|
|
36
37
|
|
|
37
38
|
// if element is extend
|
|
38
39
|
if (element.__hash) {
|
|
@@ -45,10 +46,12 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
45
46
|
|
|
46
47
|
// if element is STRING
|
|
47
48
|
if (isString(element) || isNumber(element)) {
|
|
49
|
+
const extendTag = element.extend && element.extend.tag
|
|
50
|
+
const childExtendTag = parent.childExtend && parent.childExtend.tag
|
|
51
|
+
const isKeyValidHTMLTag = ((nodes.body.indexOf(key) > -1) && key)
|
|
48
52
|
element = {
|
|
49
53
|
text: element,
|
|
50
|
-
tag:
|
|
51
|
-
((nodes.body.indexOf(key) > -1) && key) || 'string'
|
|
54
|
+
tag: extendTag || childExtendTag || isKeyValidHTMLTag || 'string'
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
@@ -59,21 +62,33 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
|
|
|
59
62
|
|
|
60
63
|
if (isKeyComponent(assignedKey)) {
|
|
61
64
|
const hasComponentAttrs = extend || childExtend || props || state || element.on
|
|
62
|
-
const
|
|
65
|
+
const componentKey = assignedKey.split('_')[0]
|
|
63
66
|
if (!hasComponentAttrs || childProps) {
|
|
64
67
|
parent[assignedKey] = element = {
|
|
65
|
-
extend:
|
|
66
|
-
props: {
|
|
67
|
-
fromKey: key,
|
|
68
|
-
...element
|
|
69
|
-
}
|
|
68
|
+
extend: componentKey || assignedKey,
|
|
69
|
+
props: { ...element }
|
|
70
70
|
}
|
|
71
71
|
} else if (!extend || extend === true) {
|
|
72
72
|
parent[assignedKey] = element = {
|
|
73
73
|
...element,
|
|
74
|
-
extend:
|
|
74
|
+
extend: componentKey || assignedKey
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Responsive rendering
|
|
80
|
+
// TODO: move as define plugin
|
|
81
|
+
if (assignedKey.slice(0, 1) === '@') {
|
|
82
|
+
if (props) {
|
|
83
|
+
props.display = 'none'
|
|
84
|
+
if (props[assignedKey]) props[assignedKey].display = props.display
|
|
85
|
+
else props[assignedKey] = { display: props.display || 'block' }
|
|
86
|
+
} else {
|
|
87
|
+
parent[assignedKey] = element = {
|
|
88
|
+
...element,
|
|
75
89
|
props: {
|
|
76
|
-
|
|
90
|
+
display: 'none',
|
|
91
|
+
[assignedKey]: { display: 'block' }
|
|
77
92
|
}
|
|
78
93
|
}
|
|
79
94
|
}
|
|
@@ -9,10 +9,7 @@ import { isEqualDeep } from '../../utils'
|
|
|
9
9
|
*/
|
|
10
10
|
export default (param, element, node, options) => {
|
|
11
11
|
if (param && element) {
|
|
12
|
-
const {$setStateCollection} = element
|
|
13
|
-
// console.log($setStateCollection)
|
|
14
12
|
if (param.__hash === element.content.__hash && element.content.update) {
|
|
15
|
-
// if ($setStateCollection) return
|
|
16
13
|
const { define } = element
|
|
17
14
|
element.content.update(param)
|
|
18
15
|
} else {
|
package/src/element/node.js
CHANGED
|
@@ -4,7 +4,7 @@ import create from './create'
|
|
|
4
4
|
import cacheNode from './cache'
|
|
5
5
|
import * as on from '../event/on'
|
|
6
6
|
|
|
7
|
-
import { isFunction, isObject } from '../utils'
|
|
7
|
+
import { exec, isFunction, isObject } from '../utils'
|
|
8
8
|
import {
|
|
9
9
|
throughInitialDefine,
|
|
10
10
|
throughInitialExec,
|
|
@@ -88,7 +88,7 @@ export const createNode = (element, options) => {
|
|
|
88
88
|
if (ourParam && !hasOptionsDefine) { // Check if param is in our method registry
|
|
89
89
|
if (isFunction(ourParam)) ourParam(prop, element, node, options)
|
|
90
90
|
} else if (element[param] && !hasDefined&& !hasOptionsDefine) {
|
|
91
|
-
create(prop, element, param, options) // Create element
|
|
91
|
+
create(exec(prop, element), element, param, options) // Create element
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
package/src/element/state.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { on } from '../event'
|
|
4
|
-
import { debounce, deepClone, exec,
|
|
4
|
+
import { debounce, deepClone, exec, isString, overwriteDeep } from '../utils'
|
|
5
|
+
import { is, isObject, isFunction, isObjectLike, isNot } from '@domql/utils'
|
|
5
6
|
|
|
6
7
|
export const IGNORE_STATE_PARAMS = [
|
|
7
|
-
'update', 'parse', 'clean', 'parent', '
|
|
8
|
-
'__components', '__projectSystem', '__projectState', '__projectLibrary'
|
|
8
|
+
'update', 'parse', 'clean', 'parent', '__element', '__depends', '__ref', '__root',
|
|
9
|
+
'__components', '__projectSystem', '__projectState', '__projectLibrary',
|
|
10
|
+
'projectStateUpdate', 'projectSystemUpdate'
|
|
9
11
|
]
|
|
10
12
|
|
|
11
13
|
export const parseState = function () {
|
|
@@ -29,13 +31,22 @@ export const cleanState = function () {
|
|
|
29
31
|
return state
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
export const
|
|
34
|
+
export const projectSystemUpdate = function (obj, options = {}) {
|
|
33
35
|
const state = this
|
|
36
|
+
if (!state) return
|
|
34
37
|
const rootState = (state.__element.__root || state.__element).state
|
|
35
38
|
rootState.update({ PROJECT_SYSTEM: obj }, options)
|
|
36
39
|
return state
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
export const projectStateUpdate = function (obj, options = {}) {
|
|
43
|
+
const state = this
|
|
44
|
+
if (!state) return
|
|
45
|
+
const rootState = (state.__element.__root || state.__element).state
|
|
46
|
+
rootState.update({ PROJECT_STATE: obj }, options)
|
|
47
|
+
return state
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
export const updateState = function (obj, options = {}) {
|
|
40
51
|
const state = this
|
|
41
52
|
const element = state.__element
|
|
@@ -45,8 +56,17 @@ export const updateState = function (obj, options = {}) {
|
|
|
45
56
|
const initReturns = on.initStateUpdated(element.on.initStateUpdated, element, state, obj)
|
|
46
57
|
if (initReturns === false) return
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
|
|
60
|
+
if (element.__state) {
|
|
61
|
+
if (state.parent && state.parent[element.__state]) {
|
|
62
|
+
const keyInParentState = state.parent[element.__state]
|
|
63
|
+
if (keyInParentState) {
|
|
64
|
+
return state.parent.update({ [element.__state]: obj }, options)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
overwriteDeep(state, obj, IGNORE_STATE_PARAMS)
|
|
69
|
+
}
|
|
50
70
|
|
|
51
71
|
// TODO: try debounce
|
|
52
72
|
if (!options.preventUpdate) element.update({}, options)
|
|
@@ -65,19 +85,42 @@ export const updateState = function (obj, options = {}) {
|
|
|
65
85
|
|
|
66
86
|
export default function (element, parent) {
|
|
67
87
|
let { state, __root } = element
|
|
88
|
+
|
|
89
|
+
if (isFunction(state)) state = exec(state, element)
|
|
68
90
|
|
|
91
|
+
if (is(state)('string', 'number')) {
|
|
92
|
+
element.__state = state
|
|
93
|
+
state = {}
|
|
94
|
+
}
|
|
95
|
+
if (state === true) {
|
|
96
|
+
element.__state = element.key
|
|
97
|
+
state = {}
|
|
98
|
+
}
|
|
99
|
+
|
|
69
100
|
if (!state) {
|
|
70
101
|
if (parent && parent.state) return parent.state
|
|
71
102
|
return {}
|
|
103
|
+
} else {
|
|
104
|
+
element.__hasRootState = true
|
|
72
105
|
}
|
|
73
|
-
|
|
106
|
+
|
|
74
107
|
// run `on.init`
|
|
75
108
|
if (element.on && isFunction(element.on.stateInit)) {
|
|
76
109
|
on.stateInit(element.on.stateInit, element, element.state)
|
|
77
110
|
}
|
|
111
|
+
|
|
112
|
+
if (element.__state) {
|
|
113
|
+
if (parent && parent.state && parent.state[element.__state]) {
|
|
114
|
+
const keyInParentState = parent.state[element.__state]
|
|
115
|
+
if (is(keyInParentState)('object', 'array')) {
|
|
116
|
+
state = deepClone(keyInParentState)
|
|
117
|
+
} else if (is(state)('string', 'number')) {
|
|
118
|
+
state = { value: state }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
78
122
|
|
|
79
|
-
|
|
80
|
-
|
|
123
|
+
// reference other state
|
|
81
124
|
const { __ref } = state
|
|
82
125
|
if (__ref) {
|
|
83
126
|
state = deepClone(__ref, IGNORE_STATE_PARAMS)
|
|
@@ -89,13 +132,16 @@ export default function (element, parent) {
|
|
|
89
132
|
}
|
|
90
133
|
|
|
91
134
|
element.state = state
|
|
92
|
-
state.__element = element
|
|
93
135
|
state.clean = cleanState
|
|
94
136
|
state.parse = parseState
|
|
95
137
|
state.update = updateState
|
|
96
|
-
state.systemUpdate = systemUpdate
|
|
97
138
|
state.parent = element.parent.state
|
|
139
|
+
state.__element = element
|
|
98
140
|
state.__root = __root ? __root.state : state
|
|
141
|
+
|
|
142
|
+
// editor stuff
|
|
143
|
+
state.projectSystemUpdate = projectSystemUpdate
|
|
144
|
+
state.projectStateUpdate = projectStateUpdate
|
|
99
145
|
state.__components = (state.__root || state).COMPONENTS
|
|
100
146
|
state.__projectSystem = (state.__root || state).PROJECT_SYSTEM
|
|
101
147
|
state.__projectState = (state.__root || state).PROJECT_STATE
|
package/src/element/update.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { overwrite, isFunction, isObject, isString, isNumber, createSnapshotId, merge } from '../utils'
|
|
3
|
+
import { overwrite, isFunction, isObject, isString, isNumber, createSnapshotId, merge, deepClone } from '../utils'
|
|
4
4
|
import { registry } from './mixins'
|
|
5
5
|
import { on } from '../event'
|
|
6
6
|
import { isMethod } from './methods'
|
|
@@ -8,6 +8,7 @@ import { throughUpdatedDefine, throughUpdatedExec } from './iterate'
|
|
|
8
8
|
import { appendNode } from './assign'
|
|
9
9
|
import { createNode } from './node'
|
|
10
10
|
import { updateProps } from './props'
|
|
11
|
+
import createState from './state'
|
|
11
12
|
|
|
12
13
|
const snapshot = {
|
|
13
14
|
snapshotId: createSnapshotId()
|
|
@@ -23,7 +24,7 @@ const UPDATE_DEFAULT_OPTIONS = {
|
|
|
23
24
|
|
|
24
25
|
const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
25
26
|
const element = this
|
|
26
|
-
const { define, parent, node } = element
|
|
27
|
+
const { define, parent, node, state } = element
|
|
27
28
|
|
|
28
29
|
const { currentSnapshot, calleeElement } = options
|
|
29
30
|
if (!calleeElement) {
|
|
@@ -53,6 +54,13 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
|
|
|
53
54
|
element.__ifFalsy = true
|
|
54
55
|
}
|
|
55
56
|
}
|
|
57
|
+
|
|
58
|
+
if (element.__state) {
|
|
59
|
+
const keyInParentState = parent.state[element.__state]
|
|
60
|
+
if (keyInParentState) {
|
|
61
|
+
element.state = createState(element, parent)
|
|
62
|
+
}
|
|
63
|
+
} else if (!element.__hasRootState) element.state = parent && parent.state || {}
|
|
56
64
|
|
|
57
65
|
if (!element.__ifFalsy && !options.preventPropsUpdate) updateProps(params.props, element, parent)
|
|
58
66
|
|
package/src/utils/object.js
CHANGED
|
@@ -122,7 +122,7 @@ export const clone = obj => {
|
|
|
122
122
|
/**
|
|
123
123
|
* Deep cloning of object
|
|
124
124
|
*/
|
|
125
|
-
export const deepClone = (obj, excluding = ['parent', 'node', '__element', '__root', 'context']) => {
|
|
125
|
+
export const deepClone = (obj, excluding = ['parent', 'node', '__element', 'state', '__root', 'context']) => {
|
|
126
126
|
const o = {}
|
|
127
127
|
for (const prop in obj) {
|
|
128
128
|
if (excluding.indexOf(prop) > -1) continue
|