@domql/element 2.5.200 → 3.0.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/README.md +1 -1
- package/__tests__/checkIfOnUpdate.test.js +103 -0
- package/__tests__/children.test.js +213 -0
- package/__tests__/define.test.js +75 -0
- package/__tests__/inheritStateUpdates.test.js +79 -0
- package/__tests__/renderElement.test.js +131 -0
- package/__tests__/resetElement.test.js +44 -0
- package/__tests__/set.test.js +316 -0
- package/__tests__/throughExecProps.test.js +86 -0
- package/__tests__/throughInitialDefine.test.js +104 -0
- package/__tests__/throughInitialExec.test.js +92 -0
- package/__tests__/throughUpdatedDefine.test.js +92 -0
- package/__tests__/throughUpdatedExec.test.js +110 -0
- package/__tests__/tree.test.js +15 -0
- package/__tests__/update.test.js +253 -0
- package/children.js +105 -0
- package/create.js +125 -252
- package/dist/cjs/__tests__/checkIfOnUpdate.test.js +73 -0
- package/dist/cjs/__tests__/children.test.js +177 -0
- package/dist/cjs/__tests__/define.test.js +75 -0
- package/dist/cjs/__tests__/inheritStateUpdates.test.js +62 -0
- package/dist/cjs/__tests__/renderElement.test.js +138 -0
- package/dist/cjs/__tests__/resetElement.test.js +35 -0
- package/dist/cjs/__tests__/set.test.js +256 -0
- package/dist/cjs/__tests__/throughExecProps.test.js +62 -0
- package/dist/cjs/__tests__/throughInitialDefine.test.js +79 -0
- package/dist/cjs/__tests__/throughInitialExec.test.js +73 -0
- package/dist/cjs/__tests__/throughUpdatedDefine.test.js +69 -0
- package/dist/cjs/__tests__/throughUpdatedExec.test.js +84 -0
- package/dist/cjs/__tests__/tree.test.js +11 -0
- package/dist/cjs/__tests__/update.test.js +219 -0
- package/dist/cjs/children.js +87 -0
- package/dist/cjs/create.js +79 -177
- package/dist/cjs/iterate.js +29 -13
- package/dist/cjs/methods/set.js +27 -25
- package/dist/cjs/methods/v2.js +1 -5
- package/dist/cjs/mixins/attr.js +7 -6
- package/dist/cjs/mixins/index.js +0 -4
- package/dist/cjs/mixins/registry.js +7 -67
- package/dist/cjs/mixins/scope.js +1 -1
- package/dist/cjs/mixins/state.js +3 -4
- package/dist/cjs/mixins/text.js +3 -3
- package/dist/cjs/node.js +32 -22
- package/dist/cjs/set.js +112 -40
- package/dist/cjs/update.js +119 -64
- package/dist/cjs/utils/applyParam.js +2 -2
- package/dist/cjs/utils/index.js +8 -4
- package/dist/cjs/utils/onlyResolveExtends.js +4 -7
- package/dist/esm/__tests__/checkIfOnUpdate.test.js +73 -0
- package/dist/esm/__tests__/children.test.js +177 -0
- package/dist/esm/__tests__/define.test.js +53 -0
- package/dist/esm/__tests__/inheritStateUpdates.test.js +62 -0
- package/dist/esm/__tests__/renderElement.test.js +116 -0
- package/dist/esm/__tests__/resetElement.test.js +35 -0
- package/dist/esm/__tests__/set.test.js +256 -0
- package/dist/esm/__tests__/throughExecProps.test.js +62 -0
- package/dist/esm/__tests__/throughInitialDefine.test.js +79 -0
- package/dist/esm/__tests__/throughInitialExec.test.js +73 -0
- package/dist/esm/__tests__/throughUpdatedDefine.test.js +69 -0
- package/dist/esm/__tests__/throughUpdatedExec.test.js +84 -0
- package/dist/esm/__tests__/tree.test.js +11 -0
- package/dist/esm/__tests__/update.test.js +219 -0
- package/dist/esm/children.js +81 -0
- package/dist/esm/create.js +85 -188
- package/dist/esm/iterate.js +33 -16
- package/dist/esm/methods/set.js +6 -4
- package/dist/esm/methods/v2.js +1 -5
- package/dist/esm/mixins/attr.js +8 -7
- package/dist/esm/mixins/data.js +1 -1
- package/dist/esm/mixins/index.js +0 -4
- package/dist/esm/mixins/registry.js +7 -67
- package/dist/esm/mixins/scope.js +1 -1
- package/dist/esm/mixins/state.js +4 -5
- package/dist/esm/mixins/text.js +4 -7
- package/dist/esm/node.js +23 -23
- package/dist/esm/set.js +112 -40
- package/dist/esm/update.js +122 -68
- package/dist/esm/utils/applyParam.js +2 -2
- package/dist/esm/utils/index.js +4 -3
- package/dist/esm/utils/onlyResolveExtends.js +12 -8
- package/iterate.js +44 -26
- package/methods/set.js +5 -4
- package/methods/v2.js +5 -4
- package/mixins/attr.js +13 -7
- package/mixins/classList.js +7 -2
- package/mixins/data.js +1 -1
- package/mixins/index.js +1 -6
- package/mixins/registry.js +6 -53
- package/mixins/scope.js +1 -1
- package/mixins/state.js +4 -5
- package/mixins/text.js +4 -7
- package/node.js +31 -28
- package/package.json +7 -6
- package/set.js +129 -41
- package/update.js +169 -89
- package/utils/applyParam.js +7 -4
- package/utils/index.js +1 -3
- package/utils/onlyResolveExtends.js +27 -16
- package/cache/index.js +0 -3
- package/cache/options.js +0 -4
- package/dist/cjs/cache/index.js +0 -24
- package/dist/cjs/cache/options.js +0 -26
- package/dist/cjs/extend.js +0 -81
- package/dist/cjs/methods/index.js +0 -320
- package/dist/cjs/mixins/content.js +0 -67
- package/dist/cjs/props/create.js +0 -92
- package/dist/cjs/props/ignore.js +0 -24
- package/dist/cjs/props/index.js +0 -21
- package/dist/cjs/props/inherit.js +0 -51
- package/dist/cjs/props/update.js +0 -34
- package/dist/cjs/utils/component.js +0 -74
- package/dist/cjs/utils/extendUtils.js +0 -133
- package/dist/cjs/utils/object.js +0 -171
- package/dist/cjs/utils/propEvents.js +0 -39
- package/dist/esm/cache/index.js +0 -4
- package/dist/esm/cache/options.js +0 -6
- package/dist/esm/extend.js +0 -67
- package/dist/esm/methods/index.js +0 -300
- package/dist/esm/mixins/content.js +0 -47
- package/dist/esm/props/create.js +0 -72
- package/dist/esm/props/ignore.js +0 -4
- package/dist/esm/props/index.js +0 -4
- package/dist/esm/props/inherit.js +0 -31
- package/dist/esm/props/update.js +0 -14
- package/dist/esm/utils/component.js +0 -62
- package/dist/esm/utils/extendUtils.js +0 -113
- package/dist/esm/utils/object.js +0 -151
- package/dist/esm/utils/propEvents.js +0 -19
- package/extend.js +0 -90
- package/methods/index.js +0 -317
- package/mixins/content.js +0 -55
- package/props/create.js +0 -87
- package/props/ignore.js +0 -3
- package/props/index.js +0 -6
- package/props/inherit.js +0 -35
- package/props/update.js +0 -17
- package/utils/component.js +0 -68
- package/utils/extendUtils.js +0 -134
- package/utils/object.js +0 -172
- package/utils/propEvents.js +0 -19
package/props/create.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { exec, isArray, isObject, deepClone, deepMerge } from '@domql/utils'
|
|
4
|
-
import { IGNORE_PROPS_PARAMS } from './ignore.js'
|
|
5
|
-
|
|
6
|
-
import { inheritParentProps } from './inherit.js'
|
|
7
|
-
|
|
8
|
-
const createPropsStack = (element, parent) => {
|
|
9
|
-
const { props, __ref: ref } = element
|
|
10
|
-
const propsStack = ref.__props = inheritParentProps(element, parent)
|
|
11
|
-
|
|
12
|
-
if (isObject(props)) propsStack.push(props)
|
|
13
|
-
else if (props === 'inherit' && parent.props) propsStack.push(parent.props)
|
|
14
|
-
else if (props) propsStack.push(props)
|
|
15
|
-
|
|
16
|
-
if (isArray(ref.__extend)) {
|
|
17
|
-
ref.__extend.forEach(extend => {
|
|
18
|
-
if (extend.props && extend.props !== props) propsStack.push(extend.props)
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
ref.__props = propsStack
|
|
23
|
-
|
|
24
|
-
return propsStack
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const syncProps = (props, element, opts) => {
|
|
28
|
-
element.props = {}
|
|
29
|
-
const mergedProps = {}
|
|
30
|
-
|
|
31
|
-
props.forEach(v => {
|
|
32
|
-
if (IGNORE_PROPS_PARAMS.includes(v)) return
|
|
33
|
-
let execProps
|
|
34
|
-
try {
|
|
35
|
-
execProps = exec(v, element)
|
|
36
|
-
} catch (e) { element.error(e, opts) }
|
|
37
|
-
// TODO: check if this failing the function props merge
|
|
38
|
-
// if (isObject(execProps) && execProps.__element) return
|
|
39
|
-
// it was causing infinite loop at early days
|
|
40
|
-
element.props = deepMerge(
|
|
41
|
-
mergedProps,
|
|
42
|
-
deepClone(execProps, { ignore: IGNORE_PROPS_PARAMS }),
|
|
43
|
-
IGNORE_PROPS_PARAMS
|
|
44
|
-
)
|
|
45
|
-
})
|
|
46
|
-
element.props = mergedProps
|
|
47
|
-
|
|
48
|
-
const methods = { update: update.bind(element.props), __element: element }
|
|
49
|
-
Object.setPrototypeOf(element.props, methods)
|
|
50
|
-
|
|
51
|
-
return element.props
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const createProps = function (element, parent, options) {
|
|
55
|
-
const { __ref: ref } = element
|
|
56
|
-
|
|
57
|
-
const applyProps = () => {
|
|
58
|
-
const propsStack = options.cachedProps || createPropsStack(element, parent)
|
|
59
|
-
if (propsStack.length) {
|
|
60
|
-
ref.__props = propsStack
|
|
61
|
-
syncProps(propsStack, element)
|
|
62
|
-
} else {
|
|
63
|
-
ref.__props = options.cachedProps || []
|
|
64
|
-
element.props = {}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (ref.__if) applyProps()
|
|
69
|
-
else {
|
|
70
|
-
try {
|
|
71
|
-
applyProps()
|
|
72
|
-
} catch {
|
|
73
|
-
element.props = {}
|
|
74
|
-
ref.__props = options.cachedProps || []
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const methods = { update: update.bind(element.props), __element: element }
|
|
79
|
-
Object.setPrototypeOf(element.props, methods)
|
|
80
|
-
|
|
81
|
-
return element
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function update (props, options) {
|
|
85
|
-
const element = this.__element
|
|
86
|
-
element.update({ props }, options)
|
|
87
|
-
}
|
package/props/ignore.js
DELETED
package/props/index.js
DELETED
package/props/inherit.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { exec, is, isString } from '@domql/utils'
|
|
4
|
-
|
|
5
|
-
const objectizeStringProperty = propValue => {
|
|
6
|
-
if (is(propValue)('string', 'number')) {
|
|
7
|
-
return { inheritedString: propValue }
|
|
8
|
-
}
|
|
9
|
-
return propValue
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const inheritParentProps = (element, parent) => {
|
|
13
|
-
let propsStack = []
|
|
14
|
-
const parentProps = exec(parent, parent.state).props
|
|
15
|
-
|
|
16
|
-
const matchParent = parent.props && parentProps[element.key]
|
|
17
|
-
const matchParentIsString = isString(matchParent)
|
|
18
|
-
const matchParentChildProps = parentProps && parentProps.childProps
|
|
19
|
-
|
|
20
|
-
if (matchParent) {
|
|
21
|
-
if (matchParentIsString) {
|
|
22
|
-
const inheritedStringExists = propsStack.filter(v => v.inheritedString)[0]
|
|
23
|
-
if (inheritedStringExists) inheritedStringExists.inheritedString = matchParent
|
|
24
|
-
else {
|
|
25
|
-
propsStack = [].concat(objectizeStringProperty(matchParent), propsStack)
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
propsStack.push(objectizeStringProperty(matchParent))
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (matchParentChildProps && !element?.props?.ignoreChildProps) propsStack.push(matchParentChildProps)
|
|
33
|
-
|
|
34
|
-
return propsStack
|
|
35
|
-
}
|
package/props/update.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { syncProps } from './create.js'
|
|
4
|
-
import { inheritParentProps } from './inherit.js'
|
|
5
|
-
|
|
6
|
-
export const updateProps = (newProps, element, parent) => {
|
|
7
|
-
const { __ref } = element
|
|
8
|
-
let propsStack = __ref.__props
|
|
9
|
-
|
|
10
|
-
const parentProps = inheritParentProps(element, parent)
|
|
11
|
-
if (parentProps.length) propsStack = __ref.__props = [].concat(parentProps, propsStack)
|
|
12
|
-
if (newProps) propsStack = __ref.__props = [].concat(newProps, propsStack)
|
|
13
|
-
|
|
14
|
-
if (propsStack) syncProps(propsStack, element)
|
|
15
|
-
|
|
16
|
-
return element
|
|
17
|
-
}
|
package/utils/component.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
isObject,
|
|
5
|
-
isString,
|
|
6
|
-
overwriteDeep,
|
|
7
|
-
checkIfKeyIsComponent,
|
|
8
|
-
addAdditionalExtend,
|
|
9
|
-
hasVariantProp,
|
|
10
|
-
isVariant
|
|
11
|
-
} from '@domql/utils'
|
|
12
|
-
|
|
13
|
-
import { applyExtend } from '../extend.js'
|
|
14
|
-
import { REGISTRY } from '../mixins/index.js'
|
|
15
|
-
|
|
16
|
-
export const createValidDomqlObjectFromSugar = (el, parent, key, options) => {
|
|
17
|
-
const newElem = {
|
|
18
|
-
props: {},
|
|
19
|
-
define: {}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const allowedKeys = ['data', 'state', 'attr', 'if']
|
|
23
|
-
|
|
24
|
-
for (const k in el) {
|
|
25
|
-
const value = el[k]
|
|
26
|
-
const isComponent = checkIfKeyIsComponent(k)
|
|
27
|
-
const isRegistry = REGISTRY[k]
|
|
28
|
-
if (isComponent || isRegistry || allowedKeys.includes(k)) {
|
|
29
|
-
newElem[k] = value
|
|
30
|
-
} else {
|
|
31
|
-
newElem.props[k] = value
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return newElem
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const overwriteVariant = (element, variant, variantProps) => {
|
|
38
|
-
let variantElement = element[variant]
|
|
39
|
-
if (!variantElement) return
|
|
40
|
-
const props = isObject(variantProps) ? variantProps : {}
|
|
41
|
-
if (isString(variantElement)) {
|
|
42
|
-
variantElement = {
|
|
43
|
-
extend: [{ props }, variantElement]
|
|
44
|
-
}
|
|
45
|
-
} else if (variantElement.extend) {
|
|
46
|
-
variantElement = addAdditionalExtend({ props }, variantElement)
|
|
47
|
-
}
|
|
48
|
-
const extendedVariant = applyExtend(variantElement, element.parent)
|
|
49
|
-
const { parent, ...rest } = extendedVariant
|
|
50
|
-
return overwriteDeep(element, rest) // TODO: check why string is not working
|
|
51
|
-
// return overwriteDeep(element, applyExtend(variantElement, element.parent)) // TODO: check why string is not working
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const applyVariant = (element) => {
|
|
55
|
-
const { props } = element
|
|
56
|
-
if (!hasVariantProp(element)) return element
|
|
57
|
-
const { variant } = props
|
|
58
|
-
overwriteVariant(element, `.${variant}`)
|
|
59
|
-
|
|
60
|
-
const elKeys = Object.keys(element).filter((key) => isVariant(key))
|
|
61
|
-
elKeys.forEach((variant) => {
|
|
62
|
-
const slicedVariantElementKey = variant.slice(1)
|
|
63
|
-
const variantElementProps = props[slicedVariantElementKey]
|
|
64
|
-
if (variantElementProps) overwriteVariant(element, variant, variantElementProps)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
return element
|
|
68
|
-
}
|
package/utils/extendUtils.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { isArray, isFunction, isObject, isString, deepClone } from '@domql/utils'
|
|
4
|
-
const ENV = process.env.NODE_ENV
|
|
5
|
-
|
|
6
|
-
export const generateHash = () => Math.random().toString(36).substring(2)
|
|
7
|
-
|
|
8
|
-
// hashing
|
|
9
|
-
export const extendStackRegistry = {}
|
|
10
|
-
export const extendCachedRegistry = {}
|
|
11
|
-
|
|
12
|
-
export const getHashedExtend = extend => {
|
|
13
|
-
return extendStackRegistry[extend.__hash]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const setHashedExtend = (extend, stack) => {
|
|
17
|
-
const hash = generateHash()
|
|
18
|
-
if (!isString(extend)) { extend.__hash = hash }
|
|
19
|
-
extendStackRegistry[hash] = stack
|
|
20
|
-
return stack
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const getExtendStackRegistry = (extend, stack) => {
|
|
24
|
-
if (extend.__hash) { return stack.concat(getHashedExtend(extend)) }
|
|
25
|
-
return setHashedExtend(extend, stack) // stack .concat(hashedExtend)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// stacking
|
|
29
|
-
export const extractArrayExtend = (extend, stack, context) => {
|
|
30
|
-
extend.forEach(each => flattenExtend(each, stack, context))
|
|
31
|
-
return stack
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const deepExtend = (extend, stack, context) => {
|
|
35
|
-
const extendOflattenExtend = extend.extend
|
|
36
|
-
if (extendOflattenExtend) {
|
|
37
|
-
flattenExtend(extendOflattenExtend, stack, context)
|
|
38
|
-
}
|
|
39
|
-
return stack
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const flattenExtend = (extend, stack, context) => {
|
|
43
|
-
if (!extend) return stack
|
|
44
|
-
if (isArray(extend)) return extractArrayExtend(extend, stack, context)
|
|
45
|
-
if (isString(extend)) extend = fallbackStringExtend(extend, context)
|
|
46
|
-
stack.push(extend)
|
|
47
|
-
if (extend.extend) deepExtend(extend, stack, context)
|
|
48
|
-
return stack
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const deepMergeExtend = (element, extend) => {
|
|
52
|
-
for (const e in extend) {
|
|
53
|
-
if (['parent', 'node', '__element'].indexOf(e) > -1) continue
|
|
54
|
-
const elementProp = element[e]
|
|
55
|
-
const extendProp = extend[e]
|
|
56
|
-
if (elementProp === undefined) {
|
|
57
|
-
element[e] = extendProp
|
|
58
|
-
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
59
|
-
deepMergeExtend(elementProp, extendProp)
|
|
60
|
-
} else if (isArray(elementProp) && isArray(extendProp)) {
|
|
61
|
-
element[e] = elementProp.concat(extendProp)
|
|
62
|
-
} else if (isArray(elementProp) && isObject(extendProp)) {
|
|
63
|
-
const obj = deepMergeExtend({}, elementProp)
|
|
64
|
-
element[e] = deepMergeExtend(obj, extendProp)
|
|
65
|
-
} else if (elementProp === undefined && isFunction(extendProp)) {
|
|
66
|
-
element[e] = extendProp
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return element
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const cloneAndMergeArrayExtend = stack => {
|
|
73
|
-
return stack.reduce((a, c) => {
|
|
74
|
-
return deepMergeExtend(a, deepClone(c))
|
|
75
|
-
}, {})
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export const fallbackStringExtend = (extend, context, options = {}, variant) => {
|
|
79
|
-
const COMPONENTS = (context && context.components) || options.components
|
|
80
|
-
const PAGES = (context && context.pages) || options.pages
|
|
81
|
-
if (isString(extend)) {
|
|
82
|
-
const componentExists = COMPONENTS && (
|
|
83
|
-
COMPONENTS[extend + '.' + variant] ||
|
|
84
|
-
COMPONENTS[extend] ||
|
|
85
|
-
COMPONENTS['smbls.' + extend]
|
|
86
|
-
)
|
|
87
|
-
const pageExists = PAGES && extend.startsWith('/') && PAGES[extend]
|
|
88
|
-
if (componentExists) return componentExists
|
|
89
|
-
else if (pageExists) return pageExists
|
|
90
|
-
else {
|
|
91
|
-
if (options.verbose && (ENV === 'test' || ENV === 'development')) {
|
|
92
|
-
console.warn('Extend is string but component was not found:', extend)
|
|
93
|
-
}
|
|
94
|
-
return {}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return extend
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// joint stacks
|
|
101
|
-
export const jointStacks = (extendStack, childExtendStack) => {
|
|
102
|
-
return []
|
|
103
|
-
.concat(extendStack.slice(0, 1))
|
|
104
|
-
.concat(childExtendStack.slice(0, 1))
|
|
105
|
-
.concat(extendStack.slice(1))
|
|
106
|
-
.concat(childExtendStack.slice(1))
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// init
|
|
110
|
-
export const getExtendStack = (extend, context) => {
|
|
111
|
-
if (!extend) return []
|
|
112
|
-
if (extend.__hash) return getHashedExtend(extend) || []
|
|
113
|
-
const stack = flattenExtend(extend, [], context)
|
|
114
|
-
return getExtendStackRegistry(extend, stack)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export const getExtendMerged = extend => {
|
|
118
|
-
const stack = getExtendStack(extend)
|
|
119
|
-
return cloneAndMergeArrayExtend(stack)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// export const replaceStringsWithComponents = (stack, context, options) => {
|
|
123
|
-
// const COMPONENTS = (context && context.components) || options.components
|
|
124
|
-
// return stack.map(v => {
|
|
125
|
-
// if (isString(v)) {
|
|
126
|
-
// const component = COMPONENTS[v]
|
|
127
|
-
// return component
|
|
128
|
-
// }
|
|
129
|
-
// if (isString(v.extend)) {
|
|
130
|
-
// v.extend = getExtendMerged(COMPONENTS[v.extend])
|
|
131
|
-
// }
|
|
132
|
-
// return v
|
|
133
|
-
// })
|
|
134
|
-
// }
|
package/utils/object.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { isArray, isObject, isObjectLike, joinArrays, deepClone } from '@domql/utils'
|
|
4
|
-
import { IGNORE_PROPS_PARAMS } from '../props/index.js'
|
|
5
|
-
|
|
6
|
-
// breaks server build
|
|
7
|
-
// import { IGNORE_STATE_PARAMS } from '@domql/state'
|
|
8
|
-
// import { METHODS } from '../methods'
|
|
9
|
-
|
|
10
|
-
const IGNORE_STATE_PARAMS = [
|
|
11
|
-
'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set', 'reset',
|
|
12
|
-
'replace', 'quietReplace', 'quietUpdate', 'applyReplace', 'applyFunction',
|
|
13
|
-
'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', 'root',
|
|
14
|
-
'setByPath', 'setPathCollection', 'removeByPath', 'removePathCollection', 'getByPath'
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
export const METHODS = [
|
|
18
|
-
'set',
|
|
19
|
-
'reset',
|
|
20
|
-
'update',
|
|
21
|
-
'remove',
|
|
22
|
-
'updateContent',
|
|
23
|
-
'removeContent',
|
|
24
|
-
'lookup',
|
|
25
|
-
'lookdown',
|
|
26
|
-
'lookdownAll',
|
|
27
|
-
'getRef',
|
|
28
|
-
'getPath',
|
|
29
|
-
'setNodeStyles',
|
|
30
|
-
'spotByPath',
|
|
31
|
-
'keys',
|
|
32
|
-
'parse',
|
|
33
|
-
'setProps',
|
|
34
|
-
'parseDeep',
|
|
35
|
-
'variables',
|
|
36
|
-
'if',
|
|
37
|
-
'log',
|
|
38
|
-
'nextElement',
|
|
39
|
-
'previousElement'
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
export const METHODS_EXL = joinArrays(
|
|
43
|
-
['node', 'state', 'context', 'extend', '__element'],
|
|
44
|
-
METHODS,
|
|
45
|
-
IGNORE_STATE_PARAMS,
|
|
46
|
-
IGNORE_PROPS_PARAMS
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
export const deepMerge = (element, extend, exclude = METHODS_EXL) => {
|
|
50
|
-
for (const e in extend) {
|
|
51
|
-
if (exclude.includes(e)) continue
|
|
52
|
-
const elementProp = element[e]
|
|
53
|
-
const extendProp = extend[e]
|
|
54
|
-
if (elementProp === undefined) {
|
|
55
|
-
element[e] = extendProp
|
|
56
|
-
} else if (isObjectLike(elementProp) && isObject(extendProp)) {
|
|
57
|
-
deepMerge(elementProp, extendProp)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return element
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export const clone = (obj, exclude = METHODS_EXL) => {
|
|
64
|
-
const o = {}
|
|
65
|
-
for (const e in obj) {
|
|
66
|
-
if (exclude.includes(e)) continue
|
|
67
|
-
o[e] = obj[e]
|
|
68
|
-
}
|
|
69
|
-
return o
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// export const deepClone = (obj, exclude = METHODS_EXL) => {
|
|
73
|
-
// const o = isArray(obj) ? [] : {}
|
|
74
|
-
// for (const e in obj) {
|
|
75
|
-
// if (exclude.includes(e)) continue
|
|
76
|
-
// let objProp = obj[e]
|
|
77
|
-
// if (e === 'extend' && isArray(objProp)) {
|
|
78
|
-
// objProp = mergeArray(objProp, exclude)
|
|
79
|
-
// }
|
|
80
|
-
// if (isObjectLike(objProp)) {
|
|
81
|
-
// o[e] = deepClone(objProp, exclude)
|
|
82
|
-
// } else o[e] = objProp
|
|
83
|
-
// }
|
|
84
|
-
// return o
|
|
85
|
-
// }
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Overwrites object properties with another
|
|
89
|
-
*/
|
|
90
|
-
export const overwrite = (element, params, options) => {
|
|
91
|
-
const changes = {}
|
|
92
|
-
const { __ref } = element
|
|
93
|
-
const { __exec, __cached } = __ref
|
|
94
|
-
|
|
95
|
-
for (const e in params) {
|
|
96
|
-
if (e === 'props' || e === 'state' || e === '__ref') continue
|
|
97
|
-
|
|
98
|
-
const elementProp = element[e]
|
|
99
|
-
const paramsProp = params[e]
|
|
100
|
-
|
|
101
|
-
if (paramsProp !== undefined) {
|
|
102
|
-
__cached[e] = changes[e] = elementProp
|
|
103
|
-
element[e] = paramsProp
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (options.cleanExec) delete __exec[e]
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return changes
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export const overwriteShallow = (obj, params, exclude = METHODS_EXL) => {
|
|
113
|
-
for (const e in params) {
|
|
114
|
-
if (exclude.includes(e)) continue
|
|
115
|
-
obj[e] = params[e]
|
|
116
|
-
}
|
|
117
|
-
return obj
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Overwrites DEEPly object properties with another
|
|
122
|
-
*/
|
|
123
|
-
export const overwriteDeep = (obj, params, exclude = METHODS_EXL) => {
|
|
124
|
-
for (const e in params) {
|
|
125
|
-
if (exclude.includes(e)) continue
|
|
126
|
-
const objProp = obj[e]
|
|
127
|
-
const paramsProp = params[e]
|
|
128
|
-
if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
|
|
129
|
-
overwriteDeep(objProp, paramsProp)
|
|
130
|
-
} else if (paramsProp !== undefined) {
|
|
131
|
-
obj[e] = paramsProp
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return obj
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Overwrites object properties with another
|
|
139
|
-
*/
|
|
140
|
-
export const mergeIfExisted = (a, b) => {
|
|
141
|
-
if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b)
|
|
142
|
-
return a || b
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Merges array extends
|
|
147
|
-
*/
|
|
148
|
-
export const mergeArray = (arr, exclude = ['parent', 'node', '__element', 'state', 'context', '__ref']) => {
|
|
149
|
-
return arr.reduce((a, c) => deepMerge(a, deepClone(c, { exclude })), {})
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Merges array extends
|
|
154
|
-
*/
|
|
155
|
-
export const mergeAndCloneIfArray = obj => {
|
|
156
|
-
return isArray(obj) ? mergeArray(obj) : deepClone(obj)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Overwrites object properties with another
|
|
161
|
-
*/
|
|
162
|
-
export const flattenRecursive = (param, prop, stack = []) => {
|
|
163
|
-
const objectized = mergeAndCloneIfArray(param)
|
|
164
|
-
stack.push(objectized)
|
|
165
|
-
|
|
166
|
-
const extendOfExtend = objectized[prop]
|
|
167
|
-
if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack)
|
|
168
|
-
|
|
169
|
-
delete objectized[prop]
|
|
170
|
-
|
|
171
|
-
return stack
|
|
172
|
-
}
|
package/utils/propEvents.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { isFunction, lowercaseFirstLetter } from '@domql/utils'
|
|
4
|
-
|
|
5
|
-
export const propagateEventsFromProps = (element) => {
|
|
6
|
-
const { props, on } = element
|
|
7
|
-
const eventKeysFromProps = Object.keys(props).filter(key => key.startsWith('on'))
|
|
8
|
-
eventKeysFromProps.forEach(v => {
|
|
9
|
-
const eventName = lowercaseFirstLetter(v.split('on')[1])
|
|
10
|
-
const origEvent = on[eventName]
|
|
11
|
-
const funcFromProps = props[v]
|
|
12
|
-
if (isFunction(origEvent)) {
|
|
13
|
-
on[eventName] = (...args) => {
|
|
14
|
-
const originalEventRetunrs = origEvent(...args)
|
|
15
|
-
if (originalEventRetunrs !== false) funcFromProps(...args)
|
|
16
|
-
}
|
|
17
|
-
} else on[eventName] = funcFromProps
|
|
18
|
-
})
|
|
19
|
-
}
|