md-editor-v3 5.4.0-4 → 5.4.0-5

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.
@@ -2895,7 +2895,8 @@ const Content = /* @__PURE__ */ vue.defineComponent({
2895
2895
  "sanitizeMermaid": props2.sanitizeMermaid,
2896
2896
  "codeFoldable": props2.codeFoldable,
2897
2897
  "autoFoldThreshold": props2.autoFoldThreshold,
2898
- "onRemount": props2.onRemount
2898
+ "onRemount": props2.onRemount,
2899
+ "htmlUpdateOnDemand": props2.htmlUpdateOnDemand
2899
2900
  }, null)]), props2.catalogVisible && vue.createVNode(MdCatalog.MdCatalog, {
2900
2901
  "theme": props2.theme,
2901
2902
  "class": `${config.prefix}-catalog-editor ${config.prefix}-catalog-${props2.catalogLayout}`,
@@ -3239,7 +3240,8 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
3239
3240
  (_a = props2.onRemount) == null ? void 0 : _a.call(props2);
3240
3241
  ctx.emit("onRemount");
3241
3242
  },
3242
- "catalogLayout": props2.catalogLayout
3243
+ "catalogLayout": props2.catalogLayout,
3244
+ "htmlUpdateOnDemand": props2.htmlUpdateOnDemand
3243
3245
  }, null), props2.footers.length > 0 && vue.createVNode(Footer, {
3244
3246
  "modelValue": props2.modelValue,
3245
3247
  "footers": props2.footers,
@@ -1185,6 +1185,9 @@ const contentPreviewProps = {
1185
1185
  },
1186
1186
  onRemount: {
1187
1187
  type: Function
1188
+ },
1189
+ htmlUpdateOnDemand: {
1190
+ type: Boolean
1188
1191
  }
1189
1192
  };
1190
1193
  const contentProps = {
@@ -1267,6 +1270,68 @@ const contentProps = {
1267
1270
  type: String
1268
1271
  }
1269
1272
  };
1273
+ const splitHtml = (html) => {
1274
+ const parser = new DOMParser();
1275
+ const doc = parser.parseFromString(html, "text/html");
1276
+ return Array.from(doc.body.children);
1277
+ };
1278
+ const compareHtml = (newHtml, currentHtml) => {
1279
+ const newNodes = splitHtml(newHtml);
1280
+ const currentNodes = splitHtml(currentHtml);
1281
+ return newNodes.map((node, index2) => {
1282
+ var _a;
1283
+ return {
1284
+ index: index2,
1285
+ newNode: node.outerHTML,
1286
+ isUpdated: ((_a = currentNodes[index2]) == null ? void 0 : _a.outerHTML) !== node.outerHTML
1287
+ };
1288
+ }).filter((update) => update.isUpdated);
1289
+ };
1290
+ const UpdateOnDemand = /* @__PURE__ */ vue.defineComponent({
1291
+ name: "UpdateOnDemand",
1292
+ props: {
1293
+ html: {
1294
+ type: String,
1295
+ required: true
1296
+ }
1297
+ },
1298
+ setup(props) {
1299
+ const editorId = vue.inject("editorId");
1300
+ const previewTheme = vue.inject("previewTheme");
1301
+ const showCodeRowNumber = vue.inject("showCodeRowNumber");
1302
+ const htmlContainer = vue.ref(null);
1303
+ const updateHtmlContent = (updates) => {
1304
+ updates.forEach(({
1305
+ index: index2,
1306
+ newNode
1307
+ }) => {
1308
+ var _a, _b;
1309
+ const targetNode = (_a = htmlContainer.value) == null ? void 0 : _a.children[index2];
1310
+ if (targetNode) {
1311
+ targetNode.outerHTML = newNode;
1312
+ } else {
1313
+ (_b = htmlContainer.value) == null ? void 0 : _b.insertAdjacentHTML("beforeend", newNode);
1314
+ }
1315
+ });
1316
+ };
1317
+ vue.watch(() => props.html, (newHtml, oldHtml) => {
1318
+ const updates = compareHtml(newHtml, oldHtml || "");
1319
+ updateHtmlContent(updates);
1320
+ }, {
1321
+ immediate: true
1322
+ });
1323
+ vue.onMounted(() => {
1324
+ if (htmlContainer.value) {
1325
+ htmlContainer.value.innerHTML = props.html;
1326
+ }
1327
+ });
1328
+ return () => vue.createVNode("div", {
1329
+ "id": `${editorId}-preview`,
1330
+ "class": [`${config.prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${config.prefix}-scrn`],
1331
+ "ref": htmlContainer
1332
+ }, null);
1333
+ }
1334
+ });
1270
1335
  const ContentPreview = /* @__PURE__ */ vue.defineComponent({
1271
1336
  name: "ContentPreview",
1272
1337
  props: contentPreviewProps,
@@ -1287,7 +1352,10 @@ const ContentPreview = /* @__PURE__ */ vue.defineComponent({
1287
1352
  "id": `${editorId}-preview-wrapper`,
1288
1353
  "class": `${config.prefix}-preview-wrapper`,
1289
1354
  "key": "content-preview-wrapper"
1290
- }, [vue.createVNode("div", {
1355
+ }, [props.htmlUpdateOnDemand ? vue.createVNode(UpdateOnDemand, {
1356
+ "key": key.value,
1357
+ "html": html.value
1358
+ }, null) : vue.createVNode("div", {
1291
1359
  "key": key.value,
1292
1360
  "id": `${editorId}-preview`,
1293
1361
  "class": [`${config.prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${config.prefix}-scrn`],
@@ -1938,6 +2006,13 @@ const mdPreviewProps = {
1938
2006
  onRemount: {
1939
2007
  type: Function,
1940
2008
  default: void 0
2009
+ },
2010
+ /**
2011
+ * 是否同单层对比,选择性的更新变化的html,流式内容推荐(AI吐字之类的)
2012
+ */
2013
+ htmlUpdateOnDemand: {
2014
+ type: Boolean,
2015
+ default: false
1941
2016
  }
1942
2017
  };
1943
2018
  const editorProps = {
@@ -2316,7 +2391,8 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
2316
2391
  var _a;
2317
2392
  (_a = props.onRemount) == null ? void 0 : _a.call(props);
2318
2393
  ctx.emit("onRemount");
2319
- }
2394
+ },
2395
+ "htmlUpdateOnDemand": props.htmlUpdateOnDemand
2320
2396
  }, null)]);
2321
2397
  };
2322
2398
  }
@@ -2894,7 +2894,8 @@ const Content = /* @__PURE__ */ defineComponent({
2894
2894
  "sanitizeMermaid": props2.sanitizeMermaid,
2895
2895
  "codeFoldable": props2.codeFoldable,
2896
2896
  "autoFoldThreshold": props2.autoFoldThreshold,
2897
- "onRemount": props2.onRemount
2897
+ "onRemount": props2.onRemount,
2898
+ "htmlUpdateOnDemand": props2.htmlUpdateOnDemand
2898
2899
  }, null)]), props2.catalogVisible && createVNode(MdCatalog, {
2899
2900
  "theme": props2.theme,
2900
2901
  "class": `${prefix}-catalog-editor ${prefix}-catalog-${props2.catalogLayout}`,
@@ -3238,7 +3239,8 @@ const Editor = /* @__PURE__ */ defineComponent({
3238
3239
  (_a = props2.onRemount) == null ? void 0 : _a.call(props2);
3239
3240
  ctx.emit("onRemount");
3240
3241
  },
3241
- "catalogLayout": props2.catalogLayout
3242
+ "catalogLayout": props2.catalogLayout,
3243
+ "htmlUpdateOnDemand": props2.htmlUpdateOnDemand
3242
3244
  }, null), props2.footers.length > 0 && createVNode(Footer, {
3243
3245
  "modelValue": props2.modelValue,
3244
3246
  "footers": props2.footers,
@@ -1184,6 +1184,9 @@ const contentPreviewProps = {
1184
1184
  },
1185
1185
  onRemount: {
1186
1186
  type: Function
1187
+ },
1188
+ htmlUpdateOnDemand: {
1189
+ type: Boolean
1187
1190
  }
1188
1191
  };
1189
1192
  const contentProps = {
@@ -1266,6 +1269,68 @@ const contentProps = {
1266
1269
  type: String
1267
1270
  }
1268
1271
  };
1272
+ const splitHtml = (html) => {
1273
+ const parser = new DOMParser();
1274
+ const doc = parser.parseFromString(html, "text/html");
1275
+ return Array.from(doc.body.children);
1276
+ };
1277
+ const compareHtml = (newHtml, currentHtml) => {
1278
+ const newNodes = splitHtml(newHtml);
1279
+ const currentNodes = splitHtml(currentHtml);
1280
+ return newNodes.map((node, index) => {
1281
+ var _a;
1282
+ return {
1283
+ index,
1284
+ newNode: node.outerHTML,
1285
+ isUpdated: ((_a = currentNodes[index]) == null ? void 0 : _a.outerHTML) !== node.outerHTML
1286
+ };
1287
+ }).filter((update) => update.isUpdated);
1288
+ };
1289
+ const UpdateOnDemand = /* @__PURE__ */ defineComponent({
1290
+ name: "UpdateOnDemand",
1291
+ props: {
1292
+ html: {
1293
+ type: String,
1294
+ required: true
1295
+ }
1296
+ },
1297
+ setup(props) {
1298
+ const editorId = inject("editorId");
1299
+ const previewTheme = inject("previewTheme");
1300
+ const showCodeRowNumber = inject("showCodeRowNumber");
1301
+ const htmlContainer = ref(null);
1302
+ const updateHtmlContent = (updates) => {
1303
+ updates.forEach(({
1304
+ index,
1305
+ newNode
1306
+ }) => {
1307
+ var _a, _b;
1308
+ const targetNode = (_a = htmlContainer.value) == null ? void 0 : _a.children[index];
1309
+ if (targetNode) {
1310
+ targetNode.outerHTML = newNode;
1311
+ } else {
1312
+ (_b = htmlContainer.value) == null ? void 0 : _b.insertAdjacentHTML("beforeend", newNode);
1313
+ }
1314
+ });
1315
+ };
1316
+ watch(() => props.html, (newHtml, oldHtml) => {
1317
+ const updates = compareHtml(newHtml, oldHtml || "");
1318
+ updateHtmlContent(updates);
1319
+ }, {
1320
+ immediate: true
1321
+ });
1322
+ onMounted(() => {
1323
+ if (htmlContainer.value) {
1324
+ htmlContainer.value.innerHTML = props.html;
1325
+ }
1326
+ });
1327
+ return () => createVNode("div", {
1328
+ "id": `${editorId}-preview`,
1329
+ "class": [`${prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${prefix}-scrn`],
1330
+ "ref": htmlContainer
1331
+ }, null);
1332
+ }
1333
+ });
1269
1334
  const ContentPreview = /* @__PURE__ */ defineComponent({
1270
1335
  name: "ContentPreview",
1271
1336
  props: contentPreviewProps,
@@ -1286,7 +1351,10 @@ const ContentPreview = /* @__PURE__ */ defineComponent({
1286
1351
  "id": `${editorId}-preview-wrapper`,
1287
1352
  "class": `${prefix}-preview-wrapper`,
1288
1353
  "key": "content-preview-wrapper"
1289
- }, [createVNode("div", {
1354
+ }, [props.htmlUpdateOnDemand ? createVNode(UpdateOnDemand, {
1355
+ "key": key.value,
1356
+ "html": html.value
1357
+ }, null) : createVNode("div", {
1290
1358
  "key": key.value,
1291
1359
  "id": `${editorId}-preview`,
1292
1360
  "class": [`${prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${prefix}-scrn`],
@@ -1937,6 +2005,13 @@ const mdPreviewProps = {
1937
2005
  onRemount: {
1938
2006
  type: Function,
1939
2007
  default: void 0
2008
+ },
2009
+ /**
2010
+ * 是否同单层对比,选择性的更新变化的html,流式内容推荐(AI吐字之类的)
2011
+ */
2012
+ htmlUpdateOnDemand: {
2013
+ type: Boolean,
2014
+ default: false
1940
2015
  }
1941
2016
  };
1942
2017
  const editorProps = {
@@ -2315,7 +2390,8 @@ const MdPreview = /* @__PURE__ */ defineComponent({
2315
2390
  var _a;
2316
2391
  (_a = props.onRemount) == null ? void 0 : _a.call(props);
2317
2392
  ctx.emit("onRemount");
2318
- }
2393
+ },
2394
+ "htmlUpdateOnDemand": props.htmlUpdateOnDemand
2319
2395
  }, null)]);
2320
2396
  };
2321
2397
  }
@@ -245,6 +245,7 @@ declare const Editor: import("vue").DefineComponent<{
245
245
  readonly sanitizeMermaid: (h: string) => Promise<string>;
246
246
  readonly codeFoldable: boolean;
247
247
  readonly autoFoldThreshold: number;
248
+ readonly htmlUpdateOnDemand: boolean;
248
249
  readonly onChange: import("./type").ChangeEvent | undefined;
249
250
  readonly onSave: import("./type").SaveEvent | undefined;
250
251
  readonly onUploadImg: import("./type").UploadImgEvent | undefined;
@@ -514,6 +515,7 @@ declare const Editor: import("vue").DefineComponent<{
514
515
  readonly sanitizeMermaid: (h: string) => Promise<string>;
515
516
  readonly codeFoldable: boolean;
516
517
  readonly autoFoldThreshold: number;
518
+ readonly htmlUpdateOnDemand: boolean;
517
519
  readonly onChange: import("./type").ChangeEvent | undefined;
518
520
  readonly onSave: import("./type").SaveEvent | undefined;
519
521
  readonly onUploadImg: import("./type").UploadImgEvent | undefined;
@@ -614,5 +616,6 @@ declare const Editor: import("vue").DefineComponent<{
614
616
  sanitizeMermaid: (h: string) => Promise<string>;
615
617
  codeFoldable: boolean;
616
618
  autoFoldThreshold: number;
619
+ htmlUpdateOnDemand: boolean;
617
620
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
618
621
  export default Editor;
@@ -20,6 +20,7 @@ declare const ContentPreview: import("vue").DefineComponent<{
20
20
  readonly sanitizeMermaid: ((h: string) => Promise<string>) | undefined;
21
21
  readonly codeFoldable: boolean | undefined;
22
22
  readonly autoFoldThreshold: number | undefined;
23
+ readonly htmlUpdateOnDemand: boolean | undefined;
23
24
  }, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
24
25
  readonly previewOnly: boolean;
25
26
  readonly onChange: (v: string) => void;
@@ -38,6 +39,7 @@ declare const ContentPreview: import("vue").DefineComponent<{
38
39
  readonly sanitizeMermaid: ((h: string) => Promise<string>) | undefined;
39
40
  readonly codeFoldable: boolean | undefined;
40
41
  readonly autoFoldThreshold: number | undefined;
42
+ readonly htmlUpdateOnDemand: boolean | undefined;
41
43
  }> & Readonly<{}>, {
42
44
  previewOnly: boolean;
43
45
  onChange: (v: string) => void;
@@ -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;
@@ -32,6 +32,7 @@ declare const _default: import("vue").DefineComponent<{
32
32
  readonly sanitizeMermaid: ((h: string) => Promise<string>) | undefined;
33
33
  readonly codeFoldable: boolean | undefined;
34
34
  readonly autoFoldThreshold: number | undefined;
35
+ readonly htmlUpdateOnDemand: boolean | undefined;
35
36
  readonly autofocus: boolean | undefined;
36
37
  readonly catalogVisible: boolean | undefined;
37
38
  readonly readonly: boolean | undefined;
@@ -70,6 +71,7 @@ declare const _default: import("vue").DefineComponent<{
70
71
  readonly sanitizeMermaid: ((h: string) => Promise<string>) | undefined;
71
72
  readonly codeFoldable: boolean | undefined;
72
73
  readonly autoFoldThreshold: number | undefined;
74
+ readonly htmlUpdateOnDemand: boolean | undefined;
73
75
  readonly autofocus: boolean | undefined;
74
76
  readonly catalogVisible: boolean | undefined;
75
77
  readonly readonly: boolean | undefined;
@@ -68,6 +68,9 @@ export declare const contentPreviewProps: {
68
68
  onRemount: {
69
69
  type: PropType<() => void>;
70
70
  };
71
+ htmlUpdateOnDemand: {
72
+ type: PropType<boolean>;
73
+ };
71
74
  };
72
75
  export declare const contentProps: {
73
76
  updateModelValue: {
@@ -208,5 +211,8 @@ export declare const contentProps: {
208
211
  onRemount: {
209
212
  type: PropType<() => void>;
210
213
  };
214
+ htmlUpdateOnDemand: {
215
+ type: PropType<boolean>;
216
+ };
211
217
  };
212
218
  export type ContentProps = Readonly<LooseRequired<Readonly<ExtractPropTypes<typeof contentProps>>>>;
@@ -229,6 +229,13 @@ export declare const mdPreviewProps: {
229
229
  type: PropType<() => void>;
230
230
  default: undefined;
231
231
  };
232
+ /**
233
+ * 是否同单层对比,选择性的更新变化的html,流式内容推荐(AI吐字之类的)
234
+ */
235
+ htmlUpdateOnDemand: {
236
+ type: PropType<boolean>;
237
+ default: boolean;
238
+ };
232
239
  };
233
240
  export declare const editorProps: {
234
241
  /**
@@ -740,6 +747,13 @@ export declare const editorProps: {
740
747
  type: PropType<() => void>;
741
748
  default: undefined;
742
749
  };
750
+ /**
751
+ * 是否同单层对比,选择性的更新变化的html,流式内容推荐(AI吐字之类的)
752
+ */
753
+ htmlUpdateOnDemand: {
754
+ type: PropType<boolean>;
755
+ default: boolean;
756
+ };
743
757
  };
744
758
  export declare const mdPreviewEmits: EditorEmits;
745
759
  export declare const editorEmits: EditorEmits;
@@ -225,6 +225,7 @@ declare const MdPreview: import("vue").DefineComponent<{
225
225
  readonly sanitizeMermaid: (h: string) => Promise<string>;
226
226
  readonly codeFoldable: boolean;
227
227
  readonly autoFoldThreshold: number;
228
+ readonly htmlUpdateOnDemand: boolean;
228
229
  readonly onChange: import("../MdEditor/type").ChangeEvent | undefined;
229
230
  readonly onHtmlChanged: import("../MdEditor/type").HtmlChangedEvent | undefined;
230
231
  readonly onGetCatalog: import("../MdEditor/type").GetCatalogEvent | undefined;
@@ -458,6 +459,7 @@ declare const MdPreview: import("vue").DefineComponent<{
458
459
  readonly sanitizeMermaid: (h: string) => Promise<string>;
459
460
  readonly codeFoldable: boolean;
460
461
  readonly autoFoldThreshold: number;
462
+ readonly htmlUpdateOnDemand: boolean;
461
463
  readonly onChange: import("../MdEditor/type").ChangeEvent | undefined;
462
464
  readonly onHtmlChanged: import("../MdEditor/type").HtmlChangedEvent | undefined;
463
465
  readonly onGetCatalog: import("../MdEditor/type").GetCatalogEvent | undefined;
@@ -506,5 +508,6 @@ declare const MdPreview: import("vue").DefineComponent<{
506
508
  sanitizeMermaid: (h: string) => Promise<string>;
507
509
  codeFoldable: boolean;
508
510
  autoFoldThreshold: number;
511
+ htmlUpdateOnDemand: boolean;
509
512
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
510
513
  export default MdPreview;