@domql/element 2.31.37 → 2.32.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/set.js CHANGED
@@ -11,12 +11,20 @@ import { triggerEventOn, triggerEventOnUpdate } from '@domql/event'
11
11
  export const resetElement = async (params, element, options) => {
12
12
  if (!options.preventRemove) removeContent(element, options)
13
13
  const { __ref: ref } = element
14
- await create(params, element, ref.contentElementKey || 'content', {
15
- ignoreChildExtend: true,
16
- ...registry.defaultOptions,
17
- ...OPTIONS.create,
18
- ...options
19
- })
14
+ const contentElementKey = setContentKey(element, options)
15
+ const { __cached } = ref
16
+ const newContent = await create(
17
+ params,
18
+ element,
19
+ ref.contentElementKey || 'content',
20
+ {
21
+ ignoreChildExtend: true,
22
+ ...registry.defaultOptions,
23
+ ...OPTIONS.create,
24
+ ...options
25
+ }
26
+ )
27
+ __cached[contentElementKey] = newContent
20
28
  }
21
29
 
22
30
  export const reset = async (options) => {
@@ -31,7 +39,9 @@ export const reset = async (options) => {
31
39
 
32
40
  export const set = async function (params, options = {}, el) {
33
41
  const element = el || this
34
- // const { __ref: ref } = element
42
+ const { __ref: ref } = element
43
+
44
+ // console.warn(params)
35
45
 
36
46
  if (
37
47
  options.preventContentUpdate ||
@@ -43,36 +53,40 @@ export const set = async function (params, options = {}, el) {
43
53
  if (options.routerContentElement !== options.lastElement.content) return
44
54
  }
45
55
 
46
- // const contentKey = setContentKey(element, options)
47
- // const content = element[contentKey]
48
- // const __contentRef = content && content.__ref
56
+ const contentKey = setContentKey(element, options)
57
+ const content = element[contentKey]
58
+ const __contentRef = content && content.__ref
49
59
  const lazyLoad = element.props && element.props.lazyLoad
50
60
 
51
61
  const hasCollection =
52
- element.$collection || element.$stateCollection || element.$propsCollection
62
+ element.$collection ||
63
+ element.$stateCollection ||
64
+ element.$propsCollection ||
65
+ element.props?.children
53
66
  if (options.preventContentUpdate === true && !hasCollection) return
54
67
 
55
68
  // console.log(deepClone(params), deepClone(content))
56
69
  // console.log(deepContains(params, content))
57
70
 
58
- // if (
59
- // ref.__noCollectionDifference ||
60
- // (__contentRef && __contentRef.__cached && deepContains(params, content))
61
- // ) {
62
- // // if (!options.preventBeforeUpdateListener && !options.preventListeners) {
63
- // // const beforeUpdateReturns = await triggerEventOnUpdate(
64
- // // 'beforeUpdate',
65
- // // params,
66
- // // element,
67
- // // options
68
- // // )
69
- // // if (beforeUpdateReturns === false) return element
70
- // // }
71
- // // if (content?.update) await content.update()
72
- // // if (!options.preventUpdateListener)
73
- // // await triggerEventOn('update', element, options)
74
- // return
75
- // }
71
+ if (
72
+ !options.forceReset &&
73
+ (ref.__noCollectionDifference ||
74
+ (__contentRef && __contentRef.__cached && deepContains(params, content)))
75
+ ) {
76
+ if (!options.preventBeforeUpdateListener && !options.preventListeners) {
77
+ const beforeUpdateReturns = await triggerEventOnUpdate(
78
+ 'beforeUpdate',
79
+ params,
80
+ element,
81
+ options
82
+ )
83
+ if (beforeUpdateReturns === false) return element
84
+ }
85
+ if (content?.update) await content.update({}, options)
86
+ if (!options.preventUpdateListener)
87
+ await triggerEventOn('update', element, options)
88
+ return
89
+ }
76
90
 
77
91
  if (params) {
78
92
  let { childExtend, props } = params
@@ -85,6 +99,7 @@ export const set = async function (params, options = {}, el) {
85
99
  props.childProps = element.props.childProps
86
100
  props.ignoreChildProps = true
87
101
  }
102
+ // TODO: check for fragment and ignore if these attrs ^
88
103
 
89
104
  // console.warn('setting content', ref.path)
90
105
 
package/update.js CHANGED
@@ -70,9 +70,9 @@ export const update = async function (params = {}, opts) {
70
70
  element,
71
71
  options
72
72
  )
73
- if (snapshotHasUpdated) return
73
+ if (snapshotHasUpdated) return false
74
74
 
75
- if (checkIfStorm(element, options)) return
75
+ if (checkIfStorm(element, options)) return false
76
76
 
77
77
  if (!options.preventListeners)
78
78
  await triggerEventOn('eventStart', element, options)
@@ -84,7 +84,7 @@ export const update = async function (params = {}, opts) {
84
84
  preventInheritAtCurrentState &&
85
85
  preventInheritAtCurrentState.__element === element
86
86
  )
87
- return
87
+ return false
88
88
  if (!excludes) merge(options, UPDATE_DEFAULT_OPTIONS)
89
89
 
90
90
  if (isString(params) || isNumber(params)) {
@@ -92,17 +92,17 @@ export const update = async function (params = {}, opts) {
92
92
  }
93
93
 
94
94
  const inheritState = await inheritStateUpdates(element, options)
95
- if (inheritState === false) return
95
+ if (inheritState === false) return false
96
96
 
97
97
  const ifFails = checkIfOnUpdate(element, parent, options)
98
- if (ifFails) return
98
+ if (ifFails) return false
99
99
 
100
100
  if (ref.__if && !options.preventPropsUpdate) {
101
101
  const hasParentProps =
102
102
  parent.props && (parent.props[key] || parent.props.childProps)
103
103
  const hasFunctionInProps = ref.__props.filter((v) => isFunction(v))
104
104
  const props = params.props || hasParentProps || hasFunctionInProps.length
105
- if (props) updateProps(props, element, parent)
105
+ if (props) updateProps(props, element, parent, options)
106
106
  }
107
107
 
108
108
  if (!options.preventBeforeUpdateListener && !options.preventListeners) {
@@ -119,9 +119,9 @@ export const update = async function (params = {}, opts) {
119
119
  overwriteDeep(element, params, { exclude: METHODS_EXL })
120
120
 
121
121
  // exec updates
122
- throughExecProps(element)
122
+ throughExecProps(element, options)
123
123
  await throughUpdatedExec(element, { ignore: UPDATE_DEFAULT_OPTIONS })
124
- await throughUpdatedDefine(element)
124
+ await throughUpdatedDefine(element, options)
125
125
 
126
126
  if (!options.isForced && !options.preventListeners) {
127
127
  await triggerEventOn('beforeClassAssign', element, options)
@@ -129,8 +129,13 @@ export const update = async function (params = {}, opts) {
129
129
 
130
130
  if (!ref.__if) return false
131
131
  if (!node) {
132
+ // if (!node || !document.body.contains(node)) {
132
133
  // return createNode(element, options)
133
- return
134
+ return false
135
+ }
136
+
137
+ if (element.tag !== 'fragment' && !document.body.contains(node)) {
138
+ // console.log(element, node)
134
139
  }
135
140
 
136
141
  const {
@@ -5,7 +5,13 @@ import { REGISTRY } from '../mixins/index.js'
5
5
 
6
6
  export const applyParam = async (param, element, options) => {
7
7
  const { node, context, __ref: ref } = element
8
- const prop = await exec(element[param], element)
8
+ const prop = await exec(
9
+ element[param],
10
+ element,
11
+ element.state,
12
+ element.context,
13
+ options
14
+ )
9
15
 
10
16
  const { onlyUpdate } = options
11
17