@domql/element 3.1.2 → 3.2.7

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.
Files changed (135) hide show
  1. package/README.md +4 -6
  2. package/children.js +45 -18
  3. package/create.js +58 -46
  4. package/define.js +1 -1
  5. package/dist/cjs/children.js +43 -13
  6. package/dist/cjs/create.js +57 -27
  7. package/dist/cjs/define.js +1 -1
  8. package/dist/cjs/event/animationFrame.js +96 -0
  9. package/dist/cjs/event/can.js +28 -0
  10. package/dist/cjs/event/index.js +20 -0
  11. package/dist/cjs/event/on.js +84 -0
  12. package/dist/cjs/event/store.js +27 -0
  13. package/dist/cjs/extend.js +88 -0
  14. package/dist/cjs/index.js +9 -6
  15. package/dist/cjs/iterate.js +89 -33
  16. package/dist/cjs/methods/set.js +5 -0
  17. package/dist/cjs/methods/v2.js +1 -1
  18. package/dist/cjs/mixins/attr.js +3 -2
  19. package/dist/cjs/mixins/classList.js +11 -1
  20. package/dist/cjs/mixins/content.js +72 -0
  21. package/dist/cjs/mixins/html.js +1 -2
  22. package/dist/cjs/mixins/registry.js +2 -2
  23. package/dist/cjs/mixins/scope.js +1 -1
  24. package/dist/cjs/mixins/state.js +4 -4
  25. package/dist/cjs/mixins/style.js +11 -2
  26. package/dist/cjs/mixins/text.js +9 -5
  27. package/dist/cjs/node.js +22 -19
  28. package/dist/cjs/render/append.js +72 -0
  29. package/dist/cjs/render/cache.js +80 -0
  30. package/dist/cjs/render/create.js +25 -0
  31. package/dist/cjs/render/index.js +20 -0
  32. package/dist/cjs/set.js +33 -40
  33. package/dist/cjs/update.js +100 -69
  34. package/dist/cjs/utils/applyParam.js +7 -7
  35. package/dist/cjs/utils/extendUtils.js +132 -0
  36. package/dist/cjs/utils/index.js +2 -0
  37. package/dist/cjs/utils/propEvents.js +56 -0
  38. package/dist/esm/children.js +44 -14
  39. package/dist/esm/create.js +58 -27
  40. package/dist/esm/define.js +1 -1
  41. package/dist/esm/event/animationFrame.js +76 -0
  42. package/dist/esm/event/can.js +8 -0
  43. package/dist/esm/event/index.js +3 -0
  44. package/dist/esm/event/on.js +64 -0
  45. package/dist/esm/event/store.js +7 -0
  46. package/dist/esm/extend.js +74 -0
  47. package/dist/esm/index.js +8 -6
  48. package/dist/esm/iterate.js +90 -35
  49. package/dist/esm/methods/set.js +10 -0
  50. package/dist/esm/methods/v2.js +1 -1
  51. package/dist/esm/mixins/attr.js +4 -3
  52. package/dist/esm/mixins/classList.js +11 -1
  53. package/dist/esm/mixins/content.js +52 -0
  54. package/dist/esm/mixins/html.js +1 -2
  55. package/dist/esm/mixins/registry.js +1 -1
  56. package/dist/esm/mixins/scope.js +1 -1
  57. package/dist/esm/mixins/state.js +5 -5
  58. package/dist/esm/mixins/style.js +12 -3
  59. package/dist/esm/mixins/text.js +10 -6
  60. package/dist/esm/node.js +22 -19
  61. package/dist/esm/render/append.js +52 -0
  62. package/dist/esm/render/cache.js +60 -0
  63. package/dist/esm/render/create.js +5 -0
  64. package/dist/esm/render/index.js +3 -0
  65. package/dist/esm/set.js +34 -41
  66. package/dist/esm/update.js +100 -71
  67. package/dist/esm/utils/applyParam.js +8 -8
  68. package/dist/esm/utils/extendUtils.js +119 -0
  69. package/dist/esm/utils/index.js +1 -0
  70. package/dist/esm/utils/propEvents.js +36 -0
  71. package/dist/iife/index.js +4718 -0
  72. package/extend.js +95 -0
  73. package/index.js +9 -6
  74. package/iterate.js +100 -38
  75. package/node.js +25 -23
  76. package/package.json +44 -20
  77. package/set.js +28 -32
  78. package/update.js +111 -82
  79. package/__tests__/checkIfOnUpdate.test.js +0 -103
  80. package/__tests__/children.test.js +0 -213
  81. package/__tests__/define.test.js +0 -75
  82. package/__tests__/inheritStateUpdates.test.js +0 -79
  83. package/__tests__/renderElement.test.js +0 -131
  84. package/__tests__/resetElement.test.js +0 -44
  85. package/__tests__/set.test.js +0 -316
  86. package/__tests__/throughExecProps.test.js +0 -86
  87. package/__tests__/throughInitialDefine.test.js +0 -104
  88. package/__tests__/throughInitialExec.test.js +0 -92
  89. package/__tests__/throughUpdatedDefine.test.js +0 -92
  90. package/__tests__/throughUpdatedExec.test.js +0 -110
  91. package/__tests__/tree.test.js +0 -15
  92. package/__tests__/update.test.js +0 -256
  93. package/dist/cjs/__tests__/checkIfOnUpdate.test.js +0 -73
  94. package/dist/cjs/__tests__/children.test.js +0 -177
  95. package/dist/cjs/__tests__/define.test.js +0 -75
  96. package/dist/cjs/__tests__/inheritStateUpdates.test.js +0 -62
  97. package/dist/cjs/__tests__/renderElement.test.js +0 -138
  98. package/dist/cjs/__tests__/resetElement.test.js +0 -35
  99. package/dist/cjs/__tests__/set.test.js +0 -256
  100. package/dist/cjs/__tests__/throughExecProps.test.js +0 -62
  101. package/dist/cjs/__tests__/throughInitialDefine.test.js +0 -79
  102. package/dist/cjs/__tests__/throughInitialExec.test.js +0 -73
  103. package/dist/cjs/__tests__/throughUpdatedDefine.test.js +0 -69
  104. package/dist/cjs/__tests__/throughUpdatedExec.test.js +0 -84
  105. package/dist/cjs/__tests__/tree.test.js +0 -11
  106. package/dist/cjs/__tests__/update.test.js +0 -222
  107. package/dist/cjs/package.json +0 -4
  108. package/dist/esm/__tests__/checkIfOnUpdate.test.js +0 -73
  109. package/dist/esm/__tests__/children.test.js +0 -177
  110. package/dist/esm/__tests__/define.test.js +0 -53
  111. package/dist/esm/__tests__/inheritStateUpdates.test.js +0 -62
  112. package/dist/esm/__tests__/renderElement.test.js +0 -116
  113. package/dist/esm/__tests__/resetElement.test.js +0 -35
  114. package/dist/esm/__tests__/set.test.js +0 -256
  115. package/dist/esm/__tests__/throughExecProps.test.js +0 -62
  116. package/dist/esm/__tests__/throughInitialDefine.test.js +0 -79
  117. package/dist/esm/__tests__/throughInitialExec.test.js +0 -73
  118. package/dist/esm/__tests__/throughUpdatedDefine.test.js +0 -69
  119. package/dist/esm/__tests__/throughUpdatedExec.test.js +0 -84
  120. package/dist/esm/__tests__/tree.test.js +0 -11
  121. package/dist/esm/__tests__/update.test.js +0 -222
  122. package/methods/set.js +0 -63
  123. package/methods/v2.js +0 -83
  124. package/mixins/attr.js +0 -32
  125. package/mixins/classList.js +0 -54
  126. package/mixins/data.js +0 -26
  127. package/mixins/html.js +0 -21
  128. package/mixins/index.js +0 -23
  129. package/mixins/registry.js +0 -46
  130. package/mixins/scope.js +0 -23
  131. package/mixins/state.js +0 -19
  132. package/mixins/style.js +0 -16
  133. package/mixins/text.js +0 -26
  134. package/utils/applyParam.js +0 -34
  135. package/utils/index.js +0 -3
package/README.md CHANGED
@@ -9,12 +9,10 @@ import DOM from 'domql'
9
9
 
10
10
  const Poster = {
11
11
  extends: [Link, Img],
12
- props: {
13
- boxSize: [100, 200],
14
- borderRadius: 12,
15
- padding: 16,
16
- background: '#fff'
17
- }
12
+ boxSize: [100, 200],
13
+ borderRadius: 12,
14
+ padding: 16,
15
+ background: '#fff'
18
16
  }
19
17
 
20
18
  DOM.create(Poster, document.body)
package/children.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  concatAddExtends,
5
5
  deepClone,
6
- execPromise,
6
+ exec,
7
7
  getChildStateInKey,
8
8
  isArray,
9
9
  isDefined,
@@ -16,21 +16,43 @@ import {
16
16
  matchesComponentNaming
17
17
  } from '@domql/utils'
18
18
 
19
+ const shallowChildrenEqual = (a, b) => {
20
+ if (a === b) return true
21
+ if (!a || !b) return false
22
+ if (isArray(a) && isArray(b)) {
23
+ if (a.length !== b.length) return false
24
+ for (let i = 0; i < a.length; i++) {
25
+ if (a[i] !== b[i]) return false
26
+ }
27
+ return true
28
+ }
29
+ if (isObject(a) && isObject(b)) {
30
+ const keysA = Object.keys(a)
31
+ const keysB = Object.keys(b)
32
+ if (keysA.length !== keysB.length) return false
33
+ for (let i = 0; i < keysA.length; i++) {
34
+ const key = keysA[i]
35
+ if (a[key] !== b[key]) return false
36
+ }
37
+ return true
38
+ }
39
+ return a === b
40
+ }
41
+
19
42
  /**
20
43
  * Apply data parameters on the DOM nodes
21
44
  * this should only work if `showOnNode: true` is passed
22
45
  */
23
- export async function setChildren (param, element, opts) {
46
+ export function setChildren (param, element, opts) {
24
47
  let { children, __ref: ref, state } = element
25
48
 
26
49
  let { childrenAs } = element.props || {}
27
- children =
28
- (await execPromise(param, element, state)) ||
29
- (await execPromise(children, element, state))
50
+ let execParam = exec(param, element, state)
51
+ let execChildren = exec(children, element, state)
52
+ children = execParam || execChildren
30
53
 
31
54
  if (children) {
32
55
  if (isState(children)) children = children.parse()
33
-
34
56
  if (isString(children) || isNumber(children)) {
35
57
  if (children === 'state') children = state.parse()
36
58
  else {
@@ -58,36 +80,41 @@ export async function setChildren (param, element, opts) {
58
80
 
59
81
  if (!children || isNot(children)('array', 'object')) return
60
82
 
61
- if (isArray(children) && children.find(v => v?.$$typeof)) {
62
- const filterReact = children.filter(v => !v?.$$typeof)
63
- if (filterReact.length !== children.length) {
64
- const extractedReactComponents = children.filter(v => v?.$$typeof)
65
- element.call('renderReact', extractedReactComponents, element)
83
+ if (isArray(children) && children.some(v => v?.$$typeof)) {
84
+ const filterReact = []
85
+ const reactComponents = []
86
+ for (let i = 0; i < children.length; i++) {
87
+ if (children[i]?.$$typeof) reactComponents.push(children[i])
88
+ else filterReact.push(children[i])
89
+ }
90
+ if (reactComponents.length) {
91
+ element.call('renderReact', reactComponents, element)
66
92
  }
67
93
  children = filterReact
68
94
  }
69
95
 
96
+ let cloned
70
97
  if (ref.__childrenCache) {
71
- const equals =
72
- JSON.stringify(children) === JSON.stringify(ref.__childrenCache) // make smarter diff
73
- if (equals) {
98
+ if (shallowChildrenEqual(children, ref.__childrenCache)) {
74
99
  ref.__noChildrenDifference = true
75
100
  } else {
76
- ref.__childrenCache = deepClone(children)
101
+ cloned = deepClone(children)
102
+ ref.__childrenCache = cloned
77
103
  delete ref.__noChildrenDifference
78
104
  }
79
105
  } else {
80
- ref.__childrenCache = deepClone(children)
106
+ cloned = deepClone(children)
107
+ ref.__childrenCache = cloned
81
108
  }
82
109
 
83
110
  if (isObject(children) || isArray(children)) {
84
- children = deepClone(children)
111
+ children = cloned || deepClone(children)
85
112
  }
86
113
 
87
114
  const content = { tag: 'fragment' }
88
115
 
89
116
  for (const key in children) {
90
- const value = Object.hasOwnProperty.call(children, key) && children[key]
117
+ const value = Object.prototype.hasOwnProperty.call(children, key) && children[key]
91
118
  if (isDefined(value) && value !== null && value !== false) {
92
119
  content[key] = isObjectLike(value)
93
120
  ? childrenAs
package/create.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  isUndefined,
10
10
  detectInfiniteLoop,
11
11
  propertizeElement,
12
+ pickupElementFromProps,
12
13
  createElement,
13
14
  applyExtends,
14
15
  createScope,
@@ -19,21 +20,44 @@ import {
19
20
  createRoot
20
21
  } from '@domql/utils'
21
22
 
22
- import { applyAnimationFrame, triggerEventOn } from '@domql/event'
23
- import { assignNode } from '@domql/render'
23
+ import { applyAnimationFrame, triggerEventOn } from './event/index.js'
24
+ import { assignNode } from './render/index.js'
24
25
  import { createState } from '@domql/state'
25
26
 
26
27
  import { REGISTRY } from './mixins/index.js'
27
28
  import { addMethods } from './methods/set.js'
28
29
  import { assignKeyAsClassname } from './mixins/classList.js'
29
30
  import { throughInitialExec, throughInitialDefine } from './iterate.js'
31
+ import { filterAttributesByTagName } from 'attrs-in-props'
32
+
33
+ const EXCLUDED_ATTRS = new Set(['class', 'style'])
34
+
35
+ const applyPropsAsAttrs = (element) => {
36
+ const { tag, props, context } = element
37
+ if (!tag || !props) return
38
+
39
+ const autoAttrs = filterAttributesByTagName(tag, props, context?.cssPropsRegistry)
40
+ const filtered = {}
41
+ for (const key in autoAttrs) {
42
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key]
43
+ }
44
+ let hasFiltered = false
45
+ for (const _k in filtered) { hasFiltered = true; break } // eslint-disable-line
46
+ if (!hasFiltered) return
47
+
48
+ if (!element.attr) {
49
+ element.attr = filtered
50
+ } else if (typeof element.attr === 'object') {
51
+ element.attr = { ...filtered, ...element.attr }
52
+ }
53
+ }
30
54
 
31
55
  const ENV = process.env.NODE_ENV
32
56
 
33
57
  /**
34
58
  * Creating a DOMQL element using passed parameters
35
59
  */
36
- export const create = async (
60
+ export const create = (
37
61
  props,
38
62
  parentEl,
39
63
  passedKey,
@@ -51,27 +75,31 @@ export const create = async (
51
75
 
52
76
  applyExtends(element, parent, options)
53
77
 
54
- propertizeElement.call(element, element)
55
-
56
- await triggerEventOn('start', element, options)
57
-
58
78
  if (options.onlyResolveExtends) {
59
79
  return onlyResolveExtends(element, parent, key, options)
60
80
  }
61
81
 
82
+ propertizeElement.call(element, element)
83
+
84
+ triggerEventOn('start', element, options)
85
+
62
86
  resetOptions(element, parent, options)
63
87
 
64
88
  addMethods(element, parent, options)
65
89
 
66
90
  createScope(element, parent)
67
91
 
68
- await createState(element, parent)
92
+ createState(element, parent)
69
93
  if (element.scope === 'state') element.scope = element.state
70
94
 
71
95
  createIfConditionFlag(element, parent)
72
96
 
73
97
  // apply props settings
74
98
  initProps(element, parent, options)
99
+ // Re-pickup component-named properties that entered props via childProps/inheritParentProps
100
+ pickupElementFromProps.call(element, element, { cachedKeys: [] })
101
+ // Populate element.attr from props matching the tag's HTML spec
102
+ applyPropsAsAttrs(element)
75
103
  if (element.scope === 'props' || element.scope === true) {
76
104
  element.scope = element.props
77
105
  }
@@ -87,7 +115,7 @@ export const create = async (
87
115
  // apply variants
88
116
  // applyVariant(element, parent)
89
117
 
90
- const onInit = await triggerEventOn('init', element, options)
118
+ const onInit = triggerEventOn('init', element, options)
91
119
  if (onInit === false) return element
92
120
 
93
121
  triggerEventOn('beforeClassAssign', element, options)
@@ -95,11 +123,11 @@ export const create = async (
95
123
  // generate a CLASS name
96
124
  assignKeyAsClassname(element)
97
125
 
98
- await renderElement(element, parent, options, attachOptions)
126
+ renderElement(element, parent, options, attachOptions)
99
127
 
100
128
  addElementIntoParentChildren(element, parent)
101
129
 
102
- await triggerEventOn('complete', element, options)
130
+ triggerEventOn('complete', element, options)
103
131
 
104
132
  return element
105
133
  }
@@ -112,7 +140,9 @@ const cacheOptions = options => {
112
140
  }
113
141
 
114
142
  const resetOptions = (element, parent, options) => {
115
- if (Object.keys(options).length) {
143
+ let hasKeys = false
144
+ for (const _k in options) { hasKeys = true; break } // eslint-disable-line
145
+ if (hasKeys) {
116
146
  OPTIONS.defaultOptions = options
117
147
  if (options.ignoreChildExtends) delete options.ignoreChildExtends
118
148
  }
@@ -124,8 +154,9 @@ const addElementIntoParentChildren = (element, parent) => {
124
154
  }
125
155
  }
126
156
 
157
+ let _uniqIdCounter = 1
127
158
  const visitedElements = new WeakMap()
128
- const renderElement = async (element, parent, options, attachOptions) => {
159
+ const renderElement = (element, parent, options, attachOptions) => {
129
160
  if (visitedElements.has(element)) {
130
161
  if (ENV === 'test' || ENV === 'development') {
131
162
  console.warn('Cyclic rendering detected:', element.__ref.path)
@@ -136,19 +167,19 @@ const renderElement = async (element, parent, options, attachOptions) => {
136
167
 
137
168
  const { __ref: ref, key } = element
138
169
 
139
- const createNestedChild = async () => {
170
+ const createNestedChild = () => {
140
171
  const isInfiniteLoopDetected = detectInfiniteLoop(ref.path)
141
172
  if (ref.__uniqId || isInfiniteLoopDetected) return
142
- await createNode(element, options)
143
- ref.__uniqId = Math.random()
173
+ createNode(element, options)
174
+ ref.__uniqId = _uniqIdCounter++
144
175
  }
145
176
 
146
177
  // CREATE a real NODE
147
178
  if (ENV === 'test' || ENV === 'development') {
148
- await createNestedChild()
179
+ createNestedChild()
149
180
  } else {
150
181
  try {
151
- await createNestedChild()
182
+ createNestedChild()
152
183
  } catch (e) {
153
184
  const path = ref.path
154
185
  if (path.includes('ComponentsGrid')) {
@@ -182,17 +213,17 @@ const renderElement = async (element, parent, options, attachOptions) => {
182
213
  applyAnimationFrame(element, options)
183
214
 
184
215
  // run `on.render`
185
- await triggerEventOn('render', element, options)
216
+ triggerEventOn('render', element, options)
186
217
  // triggerEventOn('render', element, options).then(() => {})
187
218
 
188
219
  // run `on.renderRouter`
189
- await triggerEventOn('renderRouter', element, options)
220
+ triggerEventOn('renderRouter', element, options)
190
221
 
191
222
  // run `on.done`
192
- await triggerEventOn('done', element, options)
223
+ triggerEventOn('done', element, options)
193
224
 
194
225
  // run `on.done`
195
- await triggerEventOn('create', element, options)
226
+ triggerEventOn('create', element, options)
196
227
  }
197
228
 
198
229
  const onlyResolveExtends = (element, parent, key, options) => {
@@ -209,6 +240,8 @@ const onlyResolveExtends = (element, parent, key, options) => {
209
240
 
210
241
  // apply props settings
211
242
  initProps(element, parent, options)
243
+ // Re-pickup component-named properties that entered props via childProps/inheritParentProps
244
+ pickupElementFromProps.call(element, element, { cachedKeys: [] })
212
245
  if (element.scope === 'props' || element.scope === true) {
213
246
  element.scope = element.props
214
247
  }
@@ -235,10 +268,9 @@ const onlyResolveExtends = (element, parent, key, options) => {
235
268
  continue
236
269
  }
237
270
 
238
- const hasDefine = element.define && element.define[k]
239
- const contextHasDefine =
240
- element.context && element.context.define && element.context.define[k]
241
- const optionsHasDefine = options.define && options.define[k]
271
+ const hasDefine = element.define?.[k]
272
+ const contextHasDefine = element.context?.define?.[k]
273
+ const optionsHasDefine = options.define?.[k]
242
274
 
243
275
  if (!ref.__skipCreate && REGISTRY[k] && !optionsHasDefine) {
244
276
  continue
@@ -267,24 +299,4 @@ const onlyResolveExtends = (element, parent, key, options) => {
267
299
  return element
268
300
  }
269
301
 
270
- // const checkIfMedia = (key) => key.slice(0, 1) === '@'
271
-
272
- // const applyMediaProps = (element, parent, key) => {
273
- // const { props } = element
274
- // if (props) {
275
- // props.display = 'none'
276
- // if (props[key]) props[key].display = props.display
277
- // else props[key] = { display: props.display || 'block' }
278
- // return element
279
- // } else {
280
- // return {
281
- // ...element,
282
- // props: {
283
- // display: 'none',
284
- // [key]: { display: 'block' }
285
- // }
286
- // }
287
- // }
288
- // }
289
-
290
302
  export default create
package/define.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { report } from '@domql/report'
4
- import { REGISTRY } from './mixins'
4
+ import { REGISTRY } from './mixins/index.js'
5
5
 
6
6
  export default (params, options = {}) => {
7
7
  const { overwrite } = options
@@ -23,10 +23,34 @@ __export(children_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(children_exports);
25
25
  var import_utils = require("@domql/utils");
26
- async function setChildren(param, element, opts) {
26
+ const shallowChildrenEqual = (a, b) => {
27
+ if (a === b) return true;
28
+ if (!a || !b) return false;
29
+ if ((0, import_utils.isArray)(a) && (0, import_utils.isArray)(b)) {
30
+ if (a.length !== b.length) return false;
31
+ for (let i = 0; i < a.length; i++) {
32
+ if (a[i] !== b[i]) return false;
33
+ }
34
+ return true;
35
+ }
36
+ if ((0, import_utils.isObject)(a) && (0, import_utils.isObject)(b)) {
37
+ const keysA = Object.keys(a);
38
+ const keysB = Object.keys(b);
39
+ if (keysA.length !== keysB.length) return false;
40
+ for (let i = 0; i < keysA.length; i++) {
41
+ const key = keysA[i];
42
+ if (a[key] !== b[key]) return false;
43
+ }
44
+ return true;
45
+ }
46
+ return a === b;
47
+ };
48
+ function setChildren(param, element, opts) {
27
49
  let { children, __ref: ref, state } = element;
28
50
  let { childrenAs } = element.props || {};
29
- children = await (0, import_utils.execPromise)(param, element, state) || await (0, import_utils.execPromise)(children, element, state);
51
+ let execParam = (0, import_utils.exec)(param, element, state);
52
+ let execChildren = (0, import_utils.exec)(children, element, state);
53
+ children = execParam || execChildren;
30
54
  if (children) {
31
55
  if ((0, import_utils.isState)(children)) children = children.parse();
32
56
  if ((0, import_utils.isString)(children) || (0, import_utils.isNumber)(children)) {
@@ -53,31 +77,37 @@ async function setChildren(param, element, opts) {
53
77
  }
54
78
  }
55
79
  if (!children || (0, import_utils.isNot)(children)("array", "object")) return;
56
- if ((0, import_utils.isArray)(children) && children.find((v) => v == null ? void 0 : v.$$typeof)) {
57
- const filterReact = children.filter((v) => !(v == null ? void 0 : v.$$typeof));
58
- if (filterReact.length !== children.length) {
59
- const extractedReactComponents = children.filter((v) => v == null ? void 0 : v.$$typeof);
60
- element.call("renderReact", extractedReactComponents, element);
80
+ if ((0, import_utils.isArray)(children) && children.some((v) => v?.$$typeof)) {
81
+ const filterReact = [];
82
+ const reactComponents = [];
83
+ for (let i = 0; i < children.length; i++) {
84
+ if (children[i]?.$$typeof) reactComponents.push(children[i]);
85
+ else filterReact.push(children[i]);
86
+ }
87
+ if (reactComponents.length) {
88
+ element.call("renderReact", reactComponents, element);
61
89
  }
62
90
  children = filterReact;
63
91
  }
92
+ let cloned;
64
93
  if (ref.__childrenCache) {
65
- const equals = JSON.stringify(children) === JSON.stringify(ref.__childrenCache);
66
- if (equals) {
94
+ if (shallowChildrenEqual(children, ref.__childrenCache)) {
67
95
  ref.__noChildrenDifference = true;
68
96
  } else {
69
- ref.__childrenCache = (0, import_utils.deepClone)(children);
97
+ cloned = (0, import_utils.deepClone)(children);
98
+ ref.__childrenCache = cloned;
70
99
  delete ref.__noChildrenDifference;
71
100
  }
72
101
  } else {
73
- ref.__childrenCache = (0, import_utils.deepClone)(children);
102
+ cloned = (0, import_utils.deepClone)(children);
103
+ ref.__childrenCache = cloned;
74
104
  }
75
105
  if ((0, import_utils.isObject)(children) || (0, import_utils.isArray)(children)) {
76
- children = (0, import_utils.deepClone)(children);
106
+ children = cloned || (0, import_utils.deepClone)(children);
77
107
  }
78
108
  const content = { tag: "fragment" };
79
109
  for (const key in children) {
80
- const value = Object.hasOwnProperty.call(children, key) && children[key];
110
+ const value = Object.prototype.hasOwnProperty.call(children, key) && children[key];
81
111
  if ((0, import_utils.isDefined)(value) && value !== null && value !== false) {
82
112
  content[key] = (0, import_utils.isObjectLike)(value) ? childrenAs ? { [childrenAs]: value } : value : childrenAs ? { [childrenAs]: childrenAs === "state" ? { value } : { text: value } } : { text: value };
83
113
  }
@@ -25,33 +25,57 @@ module.exports = __toCommonJS(create_exports);
25
25
  var import_node = require("./node.js");
26
26
  var import_tree = require("./tree.js");
27
27
  var import_utils = require("@domql/utils");
28
- var import_event = require("@domql/event");
29
- var import_render = require("@domql/render");
28
+ var import_event = require("./event/index.js");
29
+ var import_render = require("./render/index.js");
30
30
  var import_state = require("@domql/state");
31
31
  var import_mixins = require("./mixins/index.js");
32
32
  var import_set = require("./methods/set.js");
33
33
  var import_classList = require("./mixins/classList.js");
34
34
  var import_iterate = require("./iterate.js");
35
- const ENV = "development";
36
- const create = async (props, parentEl, passedKey, options = import_utils.OPTIONS.create || {}, attachOptions) => {
35
+ var import_attrs_in_props = require("attrs-in-props");
36
+ const EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
37
+ const applyPropsAsAttrs = (element) => {
38
+ const { tag, props, context } = element;
39
+ if (!tag || !props) return;
40
+ const autoAttrs = (0, import_attrs_in_props.filterAttributesByTagName)(tag, props, context?.cssPropsRegistry);
41
+ const filtered = {};
42
+ for (const key in autoAttrs) {
43
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key];
44
+ }
45
+ let hasFiltered = false;
46
+ for (const _k in filtered) {
47
+ hasFiltered = true;
48
+ break;
49
+ }
50
+ if (!hasFiltered) return;
51
+ if (!element.attr) {
52
+ element.attr = filtered;
53
+ } else if (typeof element.attr === "object") {
54
+ element.attr = { ...filtered, ...element.attr };
55
+ }
56
+ };
57
+ const ENV = process.env.NODE_ENV;
58
+ const create = (props, parentEl, passedKey, options = import_utils.OPTIONS.create || {}, attachOptions) => {
37
59
  cacheOptions(options);
38
60
  const element = (0, import_utils.createElement)(props, parentEl, passedKey, options, import_tree.ROOT);
39
61
  if (!element) return;
40
62
  const { key, parent, __ref: ref } = element;
41
63
  (0, import_utils.createRoot)(element, parent);
42
64
  (0, import_utils.applyExtends)(element, parent, options);
43
- import_utils.propertizeElement.call(element, element);
44
- await (0, import_event.triggerEventOn)("start", element, options);
45
65
  if (options.onlyResolveExtends) {
46
66
  return onlyResolveExtends(element, parent, key, options);
47
67
  }
68
+ import_utils.propertizeElement.call(element, element);
69
+ (0, import_event.triggerEventOn)("start", element, options);
48
70
  resetOptions(element, parent, options);
49
71
  (0, import_set.addMethods)(element, parent, options);
50
72
  (0, import_utils.createScope)(element, parent);
51
- await (0, import_state.createState)(element, parent);
73
+ (0, import_state.createState)(element, parent);
52
74
  if (element.scope === "state") element.scope = element.state;
53
75
  (0, import_utils.createIfConditionFlag)(element, parent);
54
76
  (0, import_utils.initProps)(element, parent, options);
77
+ import_utils.pickupElementFromProps.call(element, element, { cachedKeys: [] });
78
+ applyPropsAsAttrs(element);
55
79
  if (element.scope === "props" || element.scope === true) {
56
80
  element.scope = element.props;
57
81
  }
@@ -59,13 +83,13 @@ const create = async (props, parentEl, passedKey, options = import_utils.OPTIONS
59
83
  if (element.node) {
60
84
  if (ref.__if) return (0, import_render.assignNode)(element, parent, key, attachOptions);
61
85
  }
62
- const onInit = await (0, import_event.triggerEventOn)("init", element, options);
86
+ const onInit = (0, import_event.triggerEventOn)("init", element, options);
63
87
  if (onInit === false) return element;
64
88
  (0, import_event.triggerEventOn)("beforeClassAssign", element, options);
65
89
  (0, import_classList.assignKeyAsClassname)(element);
66
- await renderElement(element, parent, options, attachOptions);
90
+ renderElement(element, parent, options, attachOptions);
67
91
  addElementIntoParentChildren(element, parent);
68
- await (0, import_event.triggerEventOn)("complete", element, options);
92
+ (0, import_event.triggerEventOn)("complete", element, options);
69
93
  return element;
70
94
  };
71
95
  const cacheOptions = (options) => {
@@ -75,7 +99,12 @@ const cacheOptions = (options) => {
75
99
  }
76
100
  };
77
101
  const resetOptions = (element, parent, options) => {
78
- if (Object.keys(options).length) {
102
+ let hasKeys = false;
103
+ for (const _k in options) {
104
+ hasKeys = true;
105
+ break;
106
+ }
107
+ if (hasKeys) {
79
108
  import_utils.OPTIONS.defaultOptions = options;
80
109
  if (options.ignoreChildExtends) delete options.ignoreChildExtends;
81
110
  }
@@ -85,9 +114,9 @@ const addElementIntoParentChildren = (element, parent) => {
85
114
  parent.__ref.__children.push(element.key);
86
115
  }
87
116
  };
117
+ let _uniqIdCounter = 1;
88
118
  const visitedElements = /* @__PURE__ */ new WeakMap();
89
- const renderElement = async (element, parent, options, attachOptions) => {
90
- var _a, _b, _c;
119
+ const renderElement = (element, parent, options, attachOptions) => {
91
120
  if (visitedElements.has(element)) {
92
121
  if (ENV === "test" || ENV === "development") {
93
122
  console.warn("Cyclic rendering detected:", element.__ref.path);
@@ -95,17 +124,17 @@ const renderElement = async (element, parent, options, attachOptions) => {
95
124
  }
96
125
  visitedElements.set(element, true);
97
126
  const { __ref: ref, key } = element;
98
- const createNestedChild = async () => {
127
+ const createNestedChild = () => {
99
128
  const isInfiniteLoopDetected = (0, import_utils.detectInfiniteLoop)(ref.path);
100
129
  if (ref.__uniqId || isInfiniteLoopDetected) return;
101
- await (0, import_node.createNode)(element, options);
102
- ref.__uniqId = Math.random();
130
+ (0, import_node.createNode)(element, options);
131
+ ref.__uniqId = _uniqIdCounter++;
103
132
  };
104
133
  if (ENV === "test" || ENV === "development") {
105
- await createNestedChild();
134
+ createNestedChild();
106
135
  } else {
107
136
  try {
108
- await createNestedChild();
137
+ createNestedChild();
109
138
  } catch (e) {
110
139
  const path = ref.path;
111
140
  if (path.includes("ComponentsGrid")) {
@@ -114,14 +143,14 @@ const renderElement = async (element, parent, options, attachOptions) => {
114
143
  if (path.includes("demoComponent")) {
115
144
  path.splice(0, path.indexOf("demoComponent") + 1);
116
145
  }
117
- const isDemoComponent = (_b = (_a = element.lookup((el) => el.state.key)) == null ? void 0 : _a.state) == null ? void 0 : _b.key;
146
+ const isDemoComponent = element.lookup((el) => el.state.key)?.state?.key;
118
147
  element.warn(
119
148
  "Error happened in:",
120
149
  isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
121
150
  );
122
151
  element.verbose();
123
152
  element.error(e, options);
124
- if ((_c = element.on) == null ? void 0 : _c.error) {
153
+ if (element.on?.error) {
125
154
  element.on.error(e, element, element.state, element.context, options);
126
155
  }
127
156
  }
@@ -132,10 +161,10 @@ const renderElement = async (element, parent, options, attachOptions) => {
132
161
  }
133
162
  (0, import_render.assignNode)(element, parent, key, attachOptions);
134
163
  (0, import_event.applyAnimationFrame)(element, options);
135
- await (0, import_event.triggerEventOn)("render", element, options);
136
- await (0, import_event.triggerEventOn)("renderRouter", element, options);
137
- await (0, import_event.triggerEventOn)("done", element, options);
138
- await (0, import_event.triggerEventOn)("create", element, options);
164
+ (0, import_event.triggerEventOn)("render", element, options);
165
+ (0, import_event.triggerEventOn)("renderRouter", element, options);
166
+ (0, import_event.triggerEventOn)("done", element, options);
167
+ (0, import_event.triggerEventOn)("create", element, options);
139
168
  };
140
169
  const onlyResolveExtends = (element, parent, key, options) => {
141
170
  const { __ref: ref } = element;
@@ -145,6 +174,7 @@ const onlyResolveExtends = (element, parent, key, options) => {
145
174
  if (element.scope === "state") element.scope = element.state;
146
175
  (0, import_utils.createIfConditionFlag)(element, parent);
147
176
  (0, import_utils.initProps)(element, parent, options);
177
+ import_utils.pickupElementFromProps.call(element, element, { cachedKeys: [] });
148
178
  if (element.scope === "props" || element.scope === true) {
149
179
  element.scope = element.props;
150
180
  }
@@ -160,9 +190,9 @@ const onlyResolveExtends = (element, parent, key, options) => {
160
190
  if ((0, import_utils.isUndefined)(element[k]) || (0, import_utils.isMethod)(k, element) || (0, import_utils.isObject)(import_mixins.REGISTRY[k])) {
161
191
  continue;
162
192
  }
163
- const hasDefine = element.define && element.define[k];
164
- const contextHasDefine = element.context && element.context.define && element.context.define[k];
165
- const optionsHasDefine = options.define && options.define[k];
193
+ const hasDefine = element.define?.[k];
194
+ const contextHasDefine = element.context?.define?.[k];
195
+ const optionsHasDefine = options.define?.[k];
166
196
  if (!ref.__skipCreate && import_mixins.REGISTRY[k] && !optionsHasDefine) {
167
197
  continue;
168
198
  } else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
@@ -22,7 +22,7 @@ __export(define_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(define_exports);
24
24
  var import_report = require("@domql/report");
25
- var import_mixins = require("./mixins");
25
+ var import_mixins = require("./mixins/index.js");
26
26
  var define_default = (params, options = {}) => {
27
27
  const { overwrite } = options;
28
28
  for (const param in params) {