@miliastry/quasar 1.1.0 → 1.2.0

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.
@@ -97,44 +97,7 @@ function morphNodes(parent: Node, newParent: Node): void {
97
97
  newNode.nodeType === 1 &&
98
98
  (oldNode as Element).tagName === (newNode as Element).tagName
99
99
  ) {
100
- const oldEl = oldNode as Element
101
- const newEl = newNode as Element
102
-
103
- // Preserve interactive runtime states (such as <details open> for spoilerboxes and boxes)
104
- if (oldEl.tagName === 'DETAILS' && oldEl.hasAttribute('open')) {
105
- newEl.setAttribute('open', '')
106
- }
107
- if (oldEl.classList.contains('open')) {
108
- newEl.classList.add('open')
109
- }
110
- if (oldEl.classList.contains('is-open')) {
111
- newEl.classList.add('is-open')
112
- }
113
-
114
- // Sync attributes in-place.
115
- //
116
- // `attributes` se recorre por índice: `Array.from` asignaba un array
117
- // por elemento y por sentido, dos por pareja morfada, y esto corre
118
- // sobre la ventana cambiada en cada pulsación.
119
- const newAttrs = newEl.attributes
120
- for (let i = 0; i < newAttrs.length; i++) {
121
- const attr = newAttrs[i]
122
- if (oldEl.getAttribute(attr.name) !== attr.value) {
123
- oldEl.setAttribute(attr.name, attr.value)
124
- }
125
- }
126
- // Hacia atrás: quitar un atributo compacta la colección viva, y
127
- // recorrerla hacia delante mientras se borra se salta el siguiente.
128
- const oldAttrs = oldEl.attributes
129
- for (let i = oldAttrs.length - 1; i >= 0; i--) {
130
- const name = oldAttrs[i].name
131
- if (!newEl.hasAttribute(name)) {
132
- oldEl.removeAttribute(name)
133
- }
134
- }
135
-
136
- // Morph child nodes recursively
137
- morphNodes(oldEl, newEl)
100
+ morphElement(oldNode as Element, newNode as Element)
138
101
  } else {
139
102
  // Different tag or nodeType: replace node
140
103
  oldNode.parentNode!.replaceChild(newNode.cloneNode(true), oldNode)
@@ -142,3 +105,46 @@ function morphNodes(parent: Node, newParent: Node): void {
142
105
  }
143
106
  }
144
107
  }
108
+
109
+ /**
110
+ * Reconcile two HTML elements of the same tag in-place.
111
+ * Syncs attributes, preserves interactive states (<details open>, .open classes),
112
+ * and recursively morphs child nodes.
113
+ */
114
+ export function morphElement(oldEl: Element, newEl: Element): void {
115
+ // Preserve interactive runtime states (such as <details open> for spoilerboxes and boxes)
116
+ if (oldEl.tagName === 'DETAILS' && oldEl.hasAttribute('open')) {
117
+ newEl.setAttribute('open', '')
118
+ }
119
+ if (oldEl.classList.contains('open')) {
120
+ newEl.classList.add('open')
121
+ }
122
+ if (oldEl.classList.contains('is-open')) {
123
+ newEl.classList.add('is-open')
124
+ }
125
+
126
+ // Sync attributes in-place.
127
+ //
128
+ // `attributes` se recorre por índice: `Array.from` asignaba un array
129
+ // por elemento y por sentido, dos por pareja morfada, y esto corre
130
+ // sobre la ventana cambiada en cada pulsación.
131
+ const newAttrs = newEl.attributes
132
+ for (let i = 0; i < newAttrs.length; i++) {
133
+ const attr = newAttrs[i]
134
+ if (oldEl.getAttribute(attr.name) !== attr.value) {
135
+ oldEl.setAttribute(attr.name, attr.value)
136
+ }
137
+ }
138
+ // Hacia atrás: quitar un atributo compacta la colección viva, y
139
+ // recorrerla hacia delante mientras se borra se salta el siguiente.
140
+ const oldAttrs = oldEl.attributes
141
+ for (let i = oldAttrs.length - 1; i >= 0; i--) {
142
+ const name = oldAttrs[i].name
143
+ if (!newEl.hasAttribute(name)) {
144
+ oldEl.removeAttribute(name)
145
+ }
146
+ }
147
+
148
+ // Morph child nodes recursively
149
+ morphNodes(oldEl, newEl)
150
+ }