md-editor-v3 5.4.0 → 5.4.1

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.
@@ -1275,14 +1275,30 @@ const splitHtml = (html) => {
1275
1275
  const compareHtml = (newHtml, currentHtml) => {
1276
1276
  const newNodes = splitHtml(newHtml);
1277
1277
  const currentNodes = splitHtml(currentHtml);
1278
- return newNodes.map((node, index2) => {
1279
- var _a;
1280
- return {
1281
- index: index2,
1282
- newNode: node.outerHTML,
1283
- isUpdated: ((_a = currentNodes[index2]) == null ? void 0 : _a.outerHTML) !== node.outerHTML
1284
- };
1285
- }).filter((update) => update.isUpdated);
1278
+ const updates = [];
1279
+ const deletes = [];
1280
+ newNodes.forEach((node, index2) => {
1281
+ if (!currentNodes[index2]) {
1282
+ updates.push({
1283
+ index: index2,
1284
+ newNode: node.outerHTML
1285
+ });
1286
+ } else if (currentNodes[index2].outerHTML !== node.outerHTML) {
1287
+ updates.push({
1288
+ index: index2,
1289
+ newNode: node.outerHTML
1290
+ });
1291
+ }
1292
+ });
1293
+ if (currentNodes.length > newNodes.length) {
1294
+ for (let i = newNodes.length; i < currentNodes.length; i++) {
1295
+ deletes.push(i);
1296
+ }
1297
+ }
1298
+ return {
1299
+ updates,
1300
+ deletes
1301
+ };
1286
1302
  };
1287
1303
  const UpdateOnDemand = /* @__PURE__ */ vue.defineComponent({
1288
1304
  name: "UpdateOnDemand",
@@ -1298,7 +1314,12 @@ const UpdateOnDemand = /* @__PURE__ */ vue.defineComponent({
1298
1314
  const showCodeRowNumber = vue.inject("showCodeRowNumber");
1299
1315
  const htmlContainer = vue.ref();
1300
1316
  const firstHtml = vue.ref(props.html);
1301
- const updateHtmlContent = (updates) => {
1317
+ const updateHtmlContent = (updates, deletes) => {
1318
+ if (!htmlContainer.value) return;
1319
+ deletes.reverse().forEach((index2) => {
1320
+ var _a, _b;
1321
+ (_b = (_a = htmlContainer.value) == null ? void 0 : _a.children[index2]) == null ? void 0 : _b.remove();
1322
+ });
1302
1323
  updates.forEach(({
1303
1324
  index: index2,
1304
1325
  newNode
@@ -1313,8 +1334,11 @@ const UpdateOnDemand = /* @__PURE__ */ vue.defineComponent({
1313
1334
  });
1314
1335
  };
1315
1336
  vue.watch(() => props.html, (newHtml, oldHtml) => {
1316
- const updates = compareHtml(newHtml, oldHtml || "");
1317
- updateHtmlContent(updates);
1337
+ const {
1338
+ updates,
1339
+ deletes
1340
+ } = compareHtml(newHtml, oldHtml || "");
1341
+ updateHtmlContent(updates, deletes);
1318
1342
  });
1319
1343
  return () => vue.createVNode("div", {
1320
1344
  "id": `${editorId}-preview`,
@@ -1274,14 +1274,30 @@ const splitHtml = (html) => {
1274
1274
  const compareHtml = (newHtml, currentHtml) => {
1275
1275
  const newNodes = splitHtml(newHtml);
1276
1276
  const currentNodes = splitHtml(currentHtml);
1277
- return newNodes.map((node, index) => {
1278
- var _a;
1279
- return {
1280
- index,
1281
- newNode: node.outerHTML,
1282
- isUpdated: ((_a = currentNodes[index]) == null ? void 0 : _a.outerHTML) !== node.outerHTML
1283
- };
1284
- }).filter((update) => update.isUpdated);
1277
+ const updates = [];
1278
+ const deletes = [];
1279
+ newNodes.forEach((node, index) => {
1280
+ if (!currentNodes[index]) {
1281
+ updates.push({
1282
+ index,
1283
+ newNode: node.outerHTML
1284
+ });
1285
+ } else if (currentNodes[index].outerHTML !== node.outerHTML) {
1286
+ updates.push({
1287
+ index,
1288
+ newNode: node.outerHTML
1289
+ });
1290
+ }
1291
+ });
1292
+ if (currentNodes.length > newNodes.length) {
1293
+ for (let i = newNodes.length; i < currentNodes.length; i++) {
1294
+ deletes.push(i);
1295
+ }
1296
+ }
1297
+ return {
1298
+ updates,
1299
+ deletes
1300
+ };
1285
1301
  };
1286
1302
  const UpdateOnDemand = /* @__PURE__ */ defineComponent({
1287
1303
  name: "UpdateOnDemand",
@@ -1297,7 +1313,12 @@ const UpdateOnDemand = /* @__PURE__ */ defineComponent({
1297
1313
  const showCodeRowNumber = inject("showCodeRowNumber");
1298
1314
  const htmlContainer = ref();
1299
1315
  const firstHtml = ref(props.html);
1300
- const updateHtmlContent = (updates) => {
1316
+ const updateHtmlContent = (updates, deletes) => {
1317
+ if (!htmlContainer.value) return;
1318
+ deletes.reverse().forEach((index) => {
1319
+ var _a, _b;
1320
+ (_b = (_a = htmlContainer.value) == null ? void 0 : _a.children[index]) == null ? void 0 : _b.remove();
1321
+ });
1301
1322
  updates.forEach(({
1302
1323
  index,
1303
1324
  newNode
@@ -1312,8 +1333,11 @@ const UpdateOnDemand = /* @__PURE__ */ defineComponent({
1312
1333
  });
1313
1334
  };
1314
1335
  watch(() => props.html, (newHtml, oldHtml) => {
1315
- const updates = compareHtml(newHtml, oldHtml || "");
1316
- updateHtmlContent(updates);
1336
+ const {
1337
+ updates,
1338
+ deletes
1339
+ } = compareHtml(newHtml, oldHtml || "");
1340
+ updateHtmlContent(updates, deletes);
1317
1341
  });
1318
1342
  return () => createVNode("div", {
1319
1343
  "id": `${editorId}-preview`,