md-editor-v3 5.4.0-4 → 5.4.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.
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -1267,13 +1267,68 @@ const contentProps = {
|
|
|
1267
1267
|
type: String
|
|
1268
1268
|
}
|
|
1269
1269
|
};
|
|
1270
|
+
const splitHtml = (html) => {
|
|
1271
|
+
const parser = new DOMParser();
|
|
1272
|
+
const doc = parser.parseFromString(html, "text/html");
|
|
1273
|
+
return Array.from(doc.body.children);
|
|
1274
|
+
};
|
|
1275
|
+
const compareHtml = (newHtml, currentHtml) => {
|
|
1276
|
+
const newNodes = splitHtml(newHtml);
|
|
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);
|
|
1286
|
+
};
|
|
1287
|
+
const UpdateOnDemand = /* @__PURE__ */ vue.defineComponent({
|
|
1288
|
+
name: "UpdateOnDemand",
|
|
1289
|
+
props: {
|
|
1290
|
+
html: {
|
|
1291
|
+
type: String,
|
|
1292
|
+
required: true
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
setup(props) {
|
|
1296
|
+
const editorId = vue.inject("editorId");
|
|
1297
|
+
const previewTheme = vue.inject("previewTheme");
|
|
1298
|
+
const showCodeRowNumber = vue.inject("showCodeRowNumber");
|
|
1299
|
+
const htmlContainer = vue.ref();
|
|
1300
|
+
const firstHtml = vue.ref(props.html);
|
|
1301
|
+
const updateHtmlContent = (updates) => {
|
|
1302
|
+
updates.forEach(({
|
|
1303
|
+
index: index2,
|
|
1304
|
+
newNode
|
|
1305
|
+
}) => {
|
|
1306
|
+
var _a, _b;
|
|
1307
|
+
const targetNode = (_a = htmlContainer.value) == null ? void 0 : _a.children[index2];
|
|
1308
|
+
if (targetNode) {
|
|
1309
|
+
targetNode.outerHTML = newNode;
|
|
1310
|
+
} else {
|
|
1311
|
+
(_b = htmlContainer.value) == null ? void 0 : _b.insertAdjacentHTML("beforeend", newNode);
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
};
|
|
1315
|
+
vue.watch(() => props.html, (newHtml, oldHtml) => {
|
|
1316
|
+
const updates = compareHtml(newHtml, oldHtml || "");
|
|
1317
|
+
updateHtmlContent(updates);
|
|
1318
|
+
});
|
|
1319
|
+
return () => vue.createVNode("div", {
|
|
1320
|
+
"id": `${editorId}-preview`,
|
|
1321
|
+
"class": [`${config.prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${config.prefix}-scrn`],
|
|
1322
|
+
"innerHTML": firstHtml.value,
|
|
1323
|
+
"ref": htmlContainer
|
|
1324
|
+
}, null);
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1270
1327
|
const ContentPreview = /* @__PURE__ */ vue.defineComponent({
|
|
1271
1328
|
name: "ContentPreview",
|
|
1272
1329
|
props: contentPreviewProps,
|
|
1273
1330
|
setup(props) {
|
|
1274
1331
|
const editorId = vue.inject("editorId");
|
|
1275
|
-
const previewTheme = vue.inject("previewTheme");
|
|
1276
|
-
const showCodeRowNumber = vue.inject("showCodeRowNumber");
|
|
1277
1332
|
const {
|
|
1278
1333
|
html,
|
|
1279
1334
|
key
|
|
@@ -1287,11 +1342,9 @@ const ContentPreview = /* @__PURE__ */ vue.defineComponent({
|
|
|
1287
1342
|
"id": `${editorId}-preview-wrapper`,
|
|
1288
1343
|
"class": `${config.prefix}-preview-wrapper`,
|
|
1289
1344
|
"key": "content-preview-wrapper"
|
|
1290
|
-
}, [vue.createVNode(
|
|
1345
|
+
}, [vue.createVNode(UpdateOnDemand, {
|
|
1291
1346
|
"key": key.value,
|
|
1292
|
-
"
|
|
1293
|
-
"class": [`${config.prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${config.prefix}-scrn`],
|
|
1294
|
-
"innerHTML": html.value
|
|
1347
|
+
"html": html.value
|
|
1295
1348
|
}, null)]), !props.previewOnly && props.setting.htmlPreview && vue.createVNode("div", {
|
|
1296
1349
|
"id": `${editorId}-html-wrapper`,
|
|
1297
1350
|
"class": `${config.prefix}-preview-wrapper`,
|
package/lib/es/chunks/index.mjs
CHANGED
|
@@ -1266,13 +1266,68 @@ const contentProps = {
|
|
|
1266
1266
|
type: String
|
|
1267
1267
|
}
|
|
1268
1268
|
};
|
|
1269
|
+
const splitHtml = (html) => {
|
|
1270
|
+
const parser = new DOMParser();
|
|
1271
|
+
const doc = parser.parseFromString(html, "text/html");
|
|
1272
|
+
return Array.from(doc.body.children);
|
|
1273
|
+
};
|
|
1274
|
+
const compareHtml = (newHtml, currentHtml) => {
|
|
1275
|
+
const newNodes = splitHtml(newHtml);
|
|
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);
|
|
1285
|
+
};
|
|
1286
|
+
const UpdateOnDemand = /* @__PURE__ */ defineComponent({
|
|
1287
|
+
name: "UpdateOnDemand",
|
|
1288
|
+
props: {
|
|
1289
|
+
html: {
|
|
1290
|
+
type: String,
|
|
1291
|
+
required: true
|
|
1292
|
+
}
|
|
1293
|
+
},
|
|
1294
|
+
setup(props) {
|
|
1295
|
+
const editorId = inject("editorId");
|
|
1296
|
+
const previewTheme = inject("previewTheme");
|
|
1297
|
+
const showCodeRowNumber = inject("showCodeRowNumber");
|
|
1298
|
+
const htmlContainer = ref();
|
|
1299
|
+
const firstHtml = ref(props.html);
|
|
1300
|
+
const updateHtmlContent = (updates) => {
|
|
1301
|
+
updates.forEach(({
|
|
1302
|
+
index,
|
|
1303
|
+
newNode
|
|
1304
|
+
}) => {
|
|
1305
|
+
var _a, _b;
|
|
1306
|
+
const targetNode = (_a = htmlContainer.value) == null ? void 0 : _a.children[index];
|
|
1307
|
+
if (targetNode) {
|
|
1308
|
+
targetNode.outerHTML = newNode;
|
|
1309
|
+
} else {
|
|
1310
|
+
(_b = htmlContainer.value) == null ? void 0 : _b.insertAdjacentHTML("beforeend", newNode);
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
};
|
|
1314
|
+
watch(() => props.html, (newHtml, oldHtml) => {
|
|
1315
|
+
const updates = compareHtml(newHtml, oldHtml || "");
|
|
1316
|
+
updateHtmlContent(updates);
|
|
1317
|
+
});
|
|
1318
|
+
return () => createVNode("div", {
|
|
1319
|
+
"id": `${editorId}-preview`,
|
|
1320
|
+
"class": [`${prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${prefix}-scrn`],
|
|
1321
|
+
"innerHTML": firstHtml.value,
|
|
1322
|
+
"ref": htmlContainer
|
|
1323
|
+
}, null);
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1269
1326
|
const ContentPreview = /* @__PURE__ */ defineComponent({
|
|
1270
1327
|
name: "ContentPreview",
|
|
1271
1328
|
props: contentPreviewProps,
|
|
1272
1329
|
setup(props) {
|
|
1273
1330
|
const editorId = inject("editorId");
|
|
1274
|
-
const previewTheme = inject("previewTheme");
|
|
1275
|
-
const showCodeRowNumber = inject("showCodeRowNumber");
|
|
1276
1331
|
const {
|
|
1277
1332
|
html,
|
|
1278
1333
|
key
|
|
@@ -1286,11 +1341,9 @@ const ContentPreview = /* @__PURE__ */ defineComponent({
|
|
|
1286
1341
|
"id": `${editorId}-preview-wrapper`,
|
|
1287
1342
|
"class": `${prefix}-preview-wrapper`,
|
|
1288
1343
|
"key": "content-preview-wrapper"
|
|
1289
|
-
}, [createVNode(
|
|
1344
|
+
}, [createVNode(UpdateOnDemand, {
|
|
1290
1345
|
"key": key.value,
|
|
1291
|
-
"
|
|
1292
|
-
"class": [`${prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${prefix}-scrn`],
|
|
1293
|
-
"innerHTML": html.value
|
|
1346
|
+
"html": html.value
|
|
1294
1347
|
}, null)]), !props.previewOnly && props.setting.htmlPreview && createVNode("div", {
|
|
1295
1348
|
"id": `${editorId}-html-wrapper`,
|
|
1296
1349
|
"class": `${prefix}-preview-wrapper`,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const UpdateOnDemand: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
|
+
html: {
|
|
3
|
+
type: StringConstructor;
|
|
4
|
+
required: true;
|
|
5
|
+
};
|
|
6
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
7
|
+
html: {
|
|
8
|
+
type: StringConstructor;
|
|
9
|
+
required: true;
|
|
10
|
+
};
|
|
11
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
12
|
+
export default UpdateOnDemand;
|