@lvce-editor/virtual-dom 9.6.0 → 9.7.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.
Files changed (2) hide show
  1. package/dist/index.js +13 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1217,12 +1217,14 @@ const SetReferenceNodeUid = 11;
1217
1217
  const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1218
1218
  const events = getEventListenerMap(id) || eventMap;
1219
1219
  let $Current = $Element;
1220
+ let hasAppliedMutation = false;
1220
1221
  for (let patchIndex = 0; patchIndex < patches.length; patchIndex++) {
1221
1222
  const patch = patches[patchIndex];
1222
1223
  try {
1223
1224
  switch (patch.type) {
1224
1225
  case Add:
1225
1226
  add($Current, patch.nodes, events);
1227
+ hasAppliedMutation = true;
1226
1228
  break;
1227
1229
  case NavigateChild:
1228
1230
  {
@@ -1267,7 +1269,11 @@ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1267
1269
  });
1268
1270
  return;
1269
1271
  }
1270
- $Current = $Parent.childNodes[patch.index];
1272
+ let $Sibling = $Parent.childNodes[patch.index];
1273
+ if (!$Sibling && !hasAppliedMutation && $Current !== $Element) {
1274
+ $Sibling = $Element.childNodes[patch.index];
1275
+ }
1276
+ $Current = $Sibling;
1271
1277
  if (!$Current) {
1272
1278
  console.error('Cannot navigate to sibling: sibling not found at index', {
1273
1279
  $Parent,
@@ -1280,15 +1286,19 @@ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1280
1286
  }
1281
1287
  case RemoveAttribute:
1282
1288
  removeAttribute($Current, patch.key);
1289
+ hasAppliedMutation = true;
1283
1290
  break;
1284
1291
  case RemoveChild:
1285
1292
  removeChild($Current, patch.index);
1293
+ hasAppliedMutation = true;
1286
1294
  break;
1287
1295
  case Replace:
1288
1296
  $Current = replace($Current, patch.nodes, events);
1297
+ hasAppliedMutation = true;
1289
1298
  break;
1290
1299
  case SetAttribute:
1291
1300
  setProp($Current, patch.key, patch.value, events);
1301
+ hasAppliedMutation = true;
1292
1302
  break;
1293
1303
  case SetReferenceNodeUid:
1294
1304
  {
@@ -1305,10 +1315,12 @@ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1305
1315
  // @ts-ignore
1306
1316
  $Current.replaceWith($NewNode);
1307
1317
  $Current = $NewNode;
1318
+ hasAppliedMutation = true;
1308
1319
  break;
1309
1320
  }
1310
1321
  case SetText:
1311
1322
  setText($Current, patch.value);
1323
+ hasAppliedMutation = true;
1312
1324
  break;
1313
1325
  default:
1314
1326
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "9.6.0",
3
+ "version": "9.7.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/virtual-dom.git"