@@ -592,6 +592,9 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof win
592
592
let insertionPoint = oldParent . firstChild ;
593
593
let newChild ;
594
594
595
+ newParent . children ;
596
+ oldParent . children ;
597
+
595
598
// run through all the new content
596
599
while ( nextNewChild ) {
597
600
@@ -1205,68 +1208,82 @@ function executeMorphdom(rootFromElement, rootToElement, modifiedFieldElements,
1205
1208
childComponents . forEach ( ( childComponent ) => {
1206
1209
childComponentMap . set ( childComponent . element , childComponent ) ;
1207
1210
} ) ;
1208
- Idiomorph . morph ( rootFromElement , rootToElement , {
1209
- beforeNodeMorphed : ( fromEl , toEl ) => {
1210
- if ( ! ( fromEl instanceof Element ) || ! ( toEl instanceof Element ) ) {
1211
- return true ;
1212
- }
1213
- if ( fromEl === rootFromElement ) {
1214
- return true ;
1215
- }
1216
- if ( fromEl . hasAttribute ( 'data-live-id' ) ) {
1217
- if ( fromEl . getAttribute ( 'data-live-id' ) !== toEl . getAttribute ( 'data-live-id' ) ) {
1218
- for ( const child of fromEl . children ) {
1219
- child . setAttribute ( 'parent-live-id-changed' , '' ) ;
1211
+ Idiomorph . morph ( rootFromElement , rootToElement , { callbacks : {
1212
+ beforeNodeMorphed : ( fromEl , toEl ) => {
1213
+ if ( ! ( fromEl instanceof Element ) || ! ( toEl instanceof Element ) ) {
1214
+ return true ;
1215
+ }
1216
+ if ( fromEl === rootFromElement ) {
1217
+ return true ;
1218
+ }
1219
+ let idChanged = false ;
1220
+ if ( fromEl . hasAttribute ( 'data-live-id' ) ) {
1221
+ if ( fromEl . getAttribute ( 'data-live-id' ) !== toEl . getAttribute ( 'data-live-id' ) ) {
1222
+ for ( const child of fromEl . children ) {
1223
+ child . setAttribute ( 'parent-live-id-changed' , '' ) ;
1224
+ }
1225
+ idChanged = true ;
1220
1226
}
1221
1227
}
1222
- }
1223
- if ( fromEl instanceof HTMLElement && toEl instanceof HTMLElement ) {
1224
- if ( typeof fromEl . __x !== 'undefined' ) {
1225
- if ( ! window . Alpine ) {
1226
- throw new Error ( 'Unable to access Alpine.js though the global window.Alpine variable. Please make sure Alpine.js is loaded before Symfony UX LiveComponent.' ) ;
1228
+ if ( fromEl instanceof HTMLElement && toEl instanceof HTMLElement ) {
1229
+ if ( typeof fromEl . __x !== 'undefined' ) {
1230
+ if ( ! window . Alpine ) {
1231
+ throw new Error ( 'Unable to access Alpine.js though the global window.Alpine variable. Please make sure Alpine.js is loaded before Symfony UX LiveComponent.' ) ;
1232
+ }
1233
+ if ( typeof window . Alpine . morph !== 'function' ) {
1234
+ throw new Error ( 'Unable to access Alpine.js morph function. Please make sure the Alpine.js Morph plugin is installed and loaded, see https://alpinejs.dev/plugins/morph for more information.' ) ;
1235
+ }
1236
+ window . Alpine . morph ( fromEl . __x , toEl ) ;
1227
1237
}
1228
- if ( typeof window . Alpine . morph !== 'function' ) {
1229
- throw new Error ( 'Unable to access Alpine.js morph function. Please make sure the Alpine.js Morph plugin is installed and loaded, see https://alpinejs.dev/plugins/morph for more information.' ) ;
1238
+ if ( childComponentMap . has ( fromEl ) ) {
1239
+ const childComponent = childComponentMap . get ( fromEl ) ;
1240
+ return ! childComponent . updateFromNewElementFromParentRender ( toEl ) && idChanged ;
1241
+ }
1242
+ if ( externalMutationTracker . wasElementAdded ( fromEl ) ) {
1243
+ fromEl . insertAdjacentElement ( 'afterend' , toEl ) ;
1244
+ return false ;
1245
+ }
1246
+ if ( modifiedFieldElements . includes ( fromEl ) ) {
1247
+ setValueOnElement ( toEl , getElementValue ( fromEl ) ) ;
1248
+ }
1249
+ const elementChanges = externalMutationTracker . getChangedElement ( fromEl ) ;
1250
+ if ( elementChanges ) {
1251
+ elementChanges . applyToElement ( toEl ) ;
1252
+ }
1253
+ if ( fromEl . nodeName . toUpperCase ( ) !== 'OPTION' && fromEl . isEqualNode ( toEl ) ) {
1254
+ const normalizedFromEl = cloneHTMLElement ( fromEl ) ;
1255
+ normalizeAttributesForComparison ( normalizedFromEl ) ;
1256
+ const normalizedToEl = cloneHTMLElement ( toEl ) ;
1257
+ normalizeAttributesForComparison ( normalizedToEl ) ;
1258
+ if ( normalizedFromEl . isEqualNode ( normalizedToEl ) ) {
1259
+ return false ;
1260
+ }
1230
1261
}
1231
- window . Alpine . morph ( fromEl . __x , toEl ) ;
1232
- }
1233
- if ( childComponentMap . has ( fromEl ) ) {
1234
- const childComponent = childComponentMap . get ( fromEl ) ;
1235
- childComponent . updateFromNewElementFromParentRender ( toEl ) ;
1236
- return false ;
1237
1262
}
1238
- if ( modifiedFieldElements . includes ( fromEl ) ) {
1239
- setValueOnElement ( toEl , getElementValue ( fromEl ) ) ;
1263
+ if ( fromEl . hasAttribute ( 'parent-live-id-changed' ) ) {
1264
+ fromEl . removeAttribute ( 'parent-live-id-changed' ) ;
1265
+ return true ;
1240
1266
}
1241
- const elementChanges = externalMutationTracker . getChangedElement ( fromEl ) ;
1242
- if ( elementChanges ) {
1243
- elementChanges . applyToElement ( toEl ) ;
1267
+ return ! fromEl . hasAttribute ( 'data-live-ignore' ) ;
1268
+ } ,
1269
+ beforeNodeRemoved ( node ) {
1270
+ if ( ! ( node instanceof HTMLElement ) ) {
1271
+ return true ;
1244
1272
}
1245
- if ( fromEl . nodeName . toUpperCase ( ) !== 'OPTION' && fromEl . isEqualNode ( toEl ) ) {
1246
- const normalizedFromEl = cloneHTMLElement ( fromEl ) ;
1247
- normalizeAttributesForComparison ( normalizedFromEl ) ;
1248
- const normalizedToEl = cloneHTMLElement ( toEl ) ;
1249
- normalizeAttributesForComparison ( normalizedToEl ) ;
1250
- if ( normalizedFromEl . isEqualNode ( normalizedToEl ) ) {
1251
- return false ;
1252
- }
1273
+ if ( externalMutationTracker . wasElementAdded ( node ) ) {
1274
+ return false ;
1253
1275
}
1254
- }
1255
- if ( fromEl . hasAttribute ( 'parent-live-id-changed' ) ) {
1256
- fromEl . removeAttribute ( 'parent-live-id-changed' ) ;
1257
- return true ;
1258
- }
1259
- return ! fromEl . hasAttribute ( 'data-live-ignore' ) ;
1260
- } ,
1261
- beforeNodeRemoved ( node ) {
1262
- if ( ! ( node instanceof HTMLElement ) ) {
1263
- return true ;
1264
- }
1265
- if ( externalMutationTracker . wasElementAdded ( node ) ) {
1266
- return false ;
1267
- }
1268
- return ! node . hasAttribute ( 'data-live-ignore' ) ;
1269
- } ,
1276
+ return ! node . hasAttribute ( 'data-live-ignore' ) ;
1277
+ } ,
1278
+ } } ) ;
1279
+ childComponentMap . forEach ( ( childComponent , element ) => {
1280
+ var _a ;
1281
+ const childComponentInResult = findChildComponent ( ( _a = childComponent . id ) !== null && _a !== void 0 ? _a : '' , rootFromElement ) ;
1282
+ if ( null === childComponentInResult || element === childComponentInResult ) {
1283
+ return ;
1284
+ }
1285
+ childComponentInResult === null || childComponentInResult === void 0 ? void 0 : childComponentInResult . replaceWith ( element ) ;
1286
+ childComponent . updateFromNewElementFromParentRender ( childComponentInResult ) ;
1270
1287
} ) ;
1271
1288
}
1272
1289
0 commit comments