@lvce-editor/virtual-dom 9.5.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 +24 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -135,9 +135,18 @@ const unwrapItemString = async item => {
135
135
  };
136
136
  const unwrapItemFile = async item => {
137
137
  // @ts-ignore
138
- const file = await item.getAsFileSystemHandle();
138
+ if (item.getAsFileSystemHandle) {
139
+ // @ts-ignore
140
+ const file = await item.getAsFileSystemHandle();
141
+ return {
142
+ kind: 'file',
143
+ type: item.type,
144
+ value: file
145
+ };
146
+ }
147
+ const file = item.getAsFile();
139
148
  return {
140
- kind: 'file',
149
+ kind: 'file-legacy',
141
150
  type: item.type,
142
151
  value: file
143
152
  };
@@ -1208,12 +1217,14 @@ const SetReferenceNodeUid = 11;
1208
1217
  const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1209
1218
  const events = getEventListenerMap(id) || eventMap;
1210
1219
  let $Current = $Element;
1220
+ let hasAppliedMutation = false;
1211
1221
  for (let patchIndex = 0; patchIndex < patches.length; patchIndex++) {
1212
1222
  const patch = patches[patchIndex];
1213
1223
  try {
1214
1224
  switch (patch.type) {
1215
1225
  case Add:
1216
1226
  add($Current, patch.nodes, events);
1227
+ hasAppliedMutation = true;
1217
1228
  break;
1218
1229
  case NavigateChild:
1219
1230
  {
@@ -1258,7 +1269,11 @@ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1258
1269
  });
1259
1270
  return;
1260
1271
  }
1261
- $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;
1262
1277
  if (!$Current) {
1263
1278
  console.error('Cannot navigate to sibling: sibling not found at index', {
1264
1279
  $Parent,
@@ -1271,15 +1286,19 @@ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1271
1286
  }
1272
1287
  case RemoveAttribute:
1273
1288
  removeAttribute($Current, patch.key);
1289
+ hasAppliedMutation = true;
1274
1290
  break;
1275
1291
  case RemoveChild:
1276
1292
  removeChild($Current, patch.index);
1293
+ hasAppliedMutation = true;
1277
1294
  break;
1278
1295
  case Replace:
1279
1296
  $Current = replace($Current, patch.nodes, events);
1297
+ hasAppliedMutation = true;
1280
1298
  break;
1281
1299
  case SetAttribute:
1282
1300
  setProp($Current, patch.key, patch.value, events);
1301
+ hasAppliedMutation = true;
1283
1302
  break;
1284
1303
  case SetReferenceNodeUid:
1285
1304
  {
@@ -1296,10 +1315,12 @@ const applyPatch = ($Element, patches, eventMap = {}, id = 0) => {
1296
1315
  // @ts-ignore
1297
1316
  $Current.replaceWith($NewNode);
1298
1317
  $Current = $NewNode;
1318
+ hasAppliedMutation = true;
1299
1319
  break;
1300
1320
  }
1301
1321
  case SetText:
1302
1322
  setText($Current, patch.value);
1323
+ hasAppliedMutation = true;
1303
1324
  break;
1304
1325
  default:
1305
1326
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "9.5.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"