@jvs-milkdown/crepe 1.2.13 → 1.2.14

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 (98) hide show
  1. package/lib/cjs/builder.js +41 -2
  2. package/lib/cjs/builder.js.map +1 -1
  3. package/lib/cjs/feature/block-edit/index.js +9 -2
  4. package/lib/cjs/feature/block-edit/index.js.map +1 -1
  5. package/lib/cjs/feature/code-mirror/index.js +9 -2
  6. package/lib/cjs/feature/code-mirror/index.js.map +1 -1
  7. package/lib/cjs/feature/cursor/index.js +9 -2
  8. package/lib/cjs/feature/cursor/index.js.map +1 -1
  9. package/lib/cjs/feature/image-block/index.js +9 -2
  10. package/lib/cjs/feature/image-block/index.js.map +1 -1
  11. package/lib/cjs/feature/inline-diff/index.js +1298 -0
  12. package/lib/cjs/feature/inline-diff/index.js.map +1 -0
  13. package/lib/cjs/feature/latex/index.js +9 -2
  14. package/lib/cjs/feature/latex/index.js.map +1 -1
  15. package/lib/cjs/feature/link-tooltip/index.js +9 -2
  16. package/lib/cjs/feature/link-tooltip/index.js.map +1 -1
  17. package/lib/cjs/feature/list-item/index.js +9 -2
  18. package/lib/cjs/feature/list-item/index.js.map +1 -1
  19. package/lib/cjs/feature/placeholder/index.js +9 -2
  20. package/lib/cjs/feature/placeholder/index.js.map +1 -1
  21. package/lib/cjs/feature/table/index.js +9 -2
  22. package/lib/cjs/feature/table/index.js.map +1 -1
  23. package/lib/cjs/feature/toolbar/index.js +14 -6
  24. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  25. package/lib/cjs/index.js +1255 -235
  26. package/lib/cjs/index.js.map +1 -1
  27. package/lib/esm/builder.js +41 -2
  28. package/lib/esm/builder.js.map +1 -1
  29. package/lib/esm/feature/block-edit/index.js +9 -2
  30. package/lib/esm/feature/block-edit/index.js.map +1 -1
  31. package/lib/esm/feature/code-mirror/index.js +9 -2
  32. package/lib/esm/feature/code-mirror/index.js.map +1 -1
  33. package/lib/esm/feature/cursor/index.js +9 -2
  34. package/lib/esm/feature/cursor/index.js.map +1 -1
  35. package/lib/esm/feature/image-block/index.js +9 -2
  36. package/lib/esm/feature/image-block/index.js.map +1 -1
  37. package/lib/esm/feature/inline-diff/index.js +1274 -0
  38. package/lib/esm/feature/inline-diff/index.js.map +1 -0
  39. package/lib/esm/feature/latex/index.js +9 -2
  40. package/lib/esm/feature/latex/index.js.map +1 -1
  41. package/lib/esm/feature/link-tooltip/index.js +9 -2
  42. package/lib/esm/feature/link-tooltip/index.js.map +1 -1
  43. package/lib/esm/feature/list-item/index.js +9 -2
  44. package/lib/esm/feature/list-item/index.js.map +1 -1
  45. package/lib/esm/feature/placeholder/index.js +9 -2
  46. package/lib/esm/feature/placeholder/index.js.map +1 -1
  47. package/lib/esm/feature/table/index.js +9 -2
  48. package/lib/esm/feature/table/index.js.map +1 -1
  49. package/lib/esm/feature/toolbar/index.js +14 -6
  50. package/lib/esm/feature/toolbar/index.js.map +1 -1
  51. package/lib/esm/index.js +1237 -236
  52. package/lib/esm/index.js.map +1 -1
  53. package/lib/theme/common/diff-block.css +41 -0
  54. package/lib/theme/common/inline-diff.css +142 -0
  55. package/lib/theme/common/style.css +2 -0
  56. package/lib/tsconfig.tsbuildinfo +1 -1
  57. package/lib/types/core/builder.d.ts +2 -0
  58. package/lib/types/core/builder.d.ts.map +1 -1
  59. package/lib/types/core/locale.d.ts +4 -0
  60. package/lib/types/core/locale.d.ts.map +1 -1
  61. package/lib/types/feature/diff-block/index.d.ts +10 -0
  62. package/lib/types/feature/diff-block/index.d.ts.map +1 -0
  63. package/lib/types/feature/fixed-toolbar/index.d.ts.map +1 -1
  64. package/lib/types/feature/fixed-toolbar/outline-panel.d.ts.map +1 -1
  65. package/lib/types/feature/index.d.ts +7 -1
  66. package/lib/types/feature/index.d.ts.map +1 -1
  67. package/lib/types/feature/inline-diff/change-panel.d.ts +4 -0
  68. package/lib/types/feature/inline-diff/change-panel.d.ts.map +1 -0
  69. package/lib/types/feature/inline-diff/config.d.ts +12 -0
  70. package/lib/types/feature/inline-diff/config.d.ts.map +1 -0
  71. package/lib/types/feature/inline-diff/diff-engine.d.ts +20 -0
  72. package/lib/types/feature/inline-diff/diff-engine.d.ts.map +1 -0
  73. package/lib/types/feature/inline-diff/diff-view.d.ts +2 -0
  74. package/lib/types/feature/inline-diff/diff-view.d.ts.map +1 -0
  75. package/lib/types/feature/inline-diff/doc-builder.d.ts +21 -0
  76. package/lib/types/feature/inline-diff/doc-builder.d.ts.map +1 -0
  77. package/lib/types/feature/inline-diff/index.d.ts +9 -0
  78. package/lib/types/feature/inline-diff/index.d.ts.map +1 -0
  79. package/lib/types/feature/loader.d.ts.map +1 -1
  80. package/lib/types/feature/toolbar/component.d.ts.map +1 -1
  81. package/package.json +15 -4
  82. package/src/core/builder.ts +19 -0
  83. package/src/core/locale.ts +7 -0
  84. package/src/feature/diff-block/index.ts +48 -0
  85. package/src/feature/fixed-toolbar/index.ts +58 -23
  86. package/src/feature/fixed-toolbar/outline-panel.tsx +3 -2
  87. package/src/feature/index.ts +12 -0
  88. package/src/feature/inline-diff/change-panel.ts +280 -0
  89. package/src/feature/inline-diff/config.ts +28 -0
  90. package/src/feature/inline-diff/diff-engine.ts +181 -0
  91. package/src/feature/inline-diff/diff-view.ts +2 -0
  92. package/src/feature/inline-diff/doc-builder.ts +139 -0
  93. package/src/feature/inline-diff/index.ts +514 -0
  94. package/src/feature/loader.ts +8 -0
  95. package/src/feature/toolbar/component.tsx +3 -2
  96. package/src/theme/common/diff-block.css +43 -0
  97. package/src/theme/common/inline-diff.css +148 -0
  98. package/src/theme/common/style.css +2 -0
package/lib/esm/index.js CHANGED
@@ -6,7 +6,7 @@ import { $ctx, $nodeSchema, $view, $remark, $markAttr, $markSchema, $command, $p
6
6
  import { defineComponent, shallowRef, ref, computed, h, createApp, watchEffect, watch, onUnmounted, Fragment, reactive, onMounted, onBeforeUnmount, nextTick } from 'vue';
7
7
  import { Icon } from '@jvs-milkdown/kit/component';
8
8
  import { blockConfig, block, BlockProvider } from '@jvs-milkdown/kit/plugin/block';
9
- import { commandsCtx, editorViewCtx, editorCtx, EditorStatus, schemaCtx, editorViewOptionsCtx, Editor, rootCtx, defaultValueCtx } from '@jvs-milkdown/kit/core';
9
+ import { commandsCtx, editorViewCtx, editorCtx, EditorStatus, schemaCtx, parserCtx, editorViewOptionsCtx, Editor, rootCtx, defaultValueCtx } from '@jvs-milkdown/kit/core';
10
10
  import { findNodeInSelection, findParent, nodeRule } from '@jvs-milkdown/kit/prose';
11
11
  import { NodeSelection, TextSelection, Plugin, PluginKey, EditorState, AllSelection } from '@jvs-milkdown/kit/prose/state';
12
12
  import { computePosition, flip, shift, offset } from '@floating-ui/dom';
@@ -24,6 +24,7 @@ import { codeBlockConfig, codeBlockComponent } from '@jvs-milkdown/kit/component
24
24
  import { basicSetup } from 'codemirror';
25
25
  import { dropIndicatorConfig, cursor as cursor$1 } from '@jvs-milkdown/kit/plugin/cursor';
26
26
  import { createVirtualCursor } from 'prosemirror-virtual-cursor';
27
+ import { diffBlockConfig, diffBlock } from '@jvs-milkdown/kit/component/diff-block';
27
28
  import { mergeCells, splitCell, CellSelection, selectedRect, splitCellWithType } from '@jvs-milkdown/kit/prose/tables';
28
29
  import clsx from 'clsx';
29
30
  import { toggleLinkCommand, configureLinkTooltip, linkTooltipConfig, linkTooltipPlugin } from '@jvs-milkdown/kit/component/link-tooltip';
@@ -31,6 +32,7 @@ import { Decoration, DecorationSet, EditorView } from '@jvs-milkdown/kit/prose/v
31
32
  import { inlineImageConfig, imageInlineComponent } from '@jvs-milkdown/kit/component/image-inline';
32
33
  import { Plugin as Plugin$1 } from '@jvs-milkdown/prose/state';
33
34
  import { $prose as $prose$1 } from '@jvs-milkdown/utils';
35
+ import * as Diff from 'diff';
34
36
  import { tooltipFactory, TooltipProvider } from '@jvs-milkdown/kit/plugin/tooltip';
35
37
  import { redo, undo } from '@jvs-milkdown/kit/prose/history';
36
38
  import { keymap as keymap$1 } from '@jvs-milkdown/kit/prose/keymap';
@@ -59,6 +61,8 @@ var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
59
61
  CrepeFeature2["Table"] = "table";
60
62
  CrepeFeature2["Latex"] = "latex";
61
63
  CrepeFeature2["Attachment"] = "attachment";
64
+ CrepeFeature2["InlineDiff"] = "inline-diff";
65
+ CrepeFeature2["DiffBlock"] = "diff-block";
62
66
  return CrepeFeature2;
63
67
  })(CrepeFeature || {});
64
68
  const defaultFeatures = {
@@ -73,7 +77,9 @@ const defaultFeatures = {
73
77
  ["code-mirror" /* CodeMirror */]: true,
74
78
  ["table" /* Table */]: true,
75
79
  ["latex" /* Latex */]: true,
76
- ["attachment" /* Attachment */]: true
80
+ ["attachment" /* Attachment */]: true,
81
+ ["inline-diff" /* InlineDiff */]: false,
82
+ ["diff-block" /* DiffBlock */]: true
77
83
  };
78
84
 
79
85
  const alignCenterIcon = `
@@ -809,7 +815,10 @@ const zhCN = {
809
815
  "shortcuts.hardBreak": "\u6362\u884C",
810
816
  "shortcuts.history": "\u5386\u53F2\u8BB0\u5F55",
811
817
  "shortcuts.undo": "\u64A4\u9500",
812
- "shortcuts.redo": "\u91CD\u505A"
818
+ "shortcuts.redo": "\u91CD\u505A",
819
+ // inline-diff
820
+ "inlineDiff.accept": "\u63A5\u53D7",
821
+ "inlineDiff.reject": "\u62D2\u7EDD"
813
822
  };
814
823
  const enUS = {
815
824
  "handle.add": "Add content",
@@ -951,7 +960,9 @@ const enUS = {
951
960
  "shortcuts.hardBreak": "Hard Break",
952
961
  "shortcuts.history": "History",
953
962
  "shortcuts.undo": "Undo",
954
- "shortcuts.redo": "Redo"
963
+ "shortcuts.redo": "Redo",
964
+ "inlineDiff.accept": "Accept",
965
+ "inlineDiff.reject": "Reject"
955
966
  };
956
967
  const translationsCtx = createSlice(
957
968
  {
@@ -1388,22 +1399,22 @@ function isInList(selection) {
1388
1399
  return (type == null ? void 0 : type.name) === "list_item";
1389
1400
  }
1390
1401
 
1391
- var __typeError$6 = (msg) => {
1402
+ var __typeError$7 = (msg) => {
1392
1403
  throw TypeError(msg);
1393
1404
  };
1394
- var __accessCheck$6 = (obj, member, msg) => member.has(obj) || __typeError$6("Cannot " + msg);
1395
- var __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1396
- var __privateAdd$6 = (obj, member, value) => member.has(obj) ? __typeError$6("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1397
- var __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
1405
+ var __accessCheck$7 = (obj, member, msg) => member.has(obj) || __typeError$7("Cannot " + msg);
1406
+ var __privateGet$7 = (obj, member, getter) => (__accessCheck$7(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1407
+ var __privateAdd$7 = (obj, member, value) => member.has(obj) ? __typeError$7("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1408
+ var __privateSet$7 = (obj, member, value, setter) => (__accessCheck$7(obj, member, "write to private field"), member.set(obj, value), value);
1398
1409
  var _groups, _getGroupInstance;
1399
1410
  class GroupBuilder {
1400
1411
  constructor() {
1401
- __privateAdd$6(this, _groups, []);
1412
+ __privateAdd$7(this, _groups, []);
1402
1413
  this.clear = () => {
1403
- __privateSet$6(this, _groups, []);
1414
+ __privateSet$7(this, _groups, []);
1404
1415
  return this;
1405
1416
  };
1406
- __privateAdd$6(this, _getGroupInstance, (group) => {
1417
+ __privateAdd$7(this, _getGroupInstance, (group) => {
1407
1418
  const groupInstance = {
1408
1419
  group,
1409
1420
  addItem: (key, item) => {
@@ -1425,16 +1436,16 @@ class GroupBuilder {
1425
1436
  label,
1426
1437
  items
1427
1438
  };
1428
- __privateGet$6(this, _groups).push(group);
1429
- return __privateGet$6(this, _getGroupInstance).call(this, group);
1439
+ __privateGet$7(this, _groups).push(group);
1440
+ return __privateGet$7(this, _getGroupInstance).call(this, group);
1430
1441
  };
1431
1442
  this.getGroup = (key) => {
1432
- const group = __privateGet$6(this, _groups).find((group2) => group2.key === key);
1443
+ const group = __privateGet$7(this, _groups).find((group2) => group2.key === key);
1433
1444
  if (!group) throw new Error(`Group with key ${key} not found`);
1434
- return __privateGet$6(this, _getGroupInstance).call(this, group);
1445
+ return __privateGet$7(this, _getGroupInstance).call(this, group);
1435
1446
  };
1436
1447
  this.build = () => {
1437
- return __privateGet$6(this, _groups);
1448
+ return __privateGet$7(this, _groups);
1438
1449
  };
1439
1450
  }
1440
1451
  }
@@ -3586,14 +3597,14 @@ const Menu = defineComponent({
3586
3597
  }
3587
3598
  });
3588
3599
 
3589
- var __typeError$5 = (msg) => {
3600
+ var __typeError$6 = (msg) => {
3590
3601
  throw TypeError(msg);
3591
3602
  };
3592
- var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
3593
- var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), member.get(obj));
3594
- var __privateAdd$5 = (obj, member, value) => member.has(obj) ? __typeError$5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3595
- var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
3596
- var _content$4, _app$4, _filter, _slashProvider, _activeKey, _view$1, _programmaticallyPos, _mode, _hideTimeout, _isMenuHovered, _keepOpenUntilClickOutside;
3603
+ var __accessCheck$6 = (obj, member, msg) => member.has(obj) || __typeError$6("Cannot " + msg);
3604
+ var __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), member.get(obj));
3605
+ var __privateAdd$6 = (obj, member, value) => member.has(obj) ? __typeError$6("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3606
+ var __privateSet$6 = (obj, member, value, setter) => (__accessCheck$6(obj, member, "write to private field"), member.set(obj, value), value);
3607
+ var _content$4, _app$4, _filter, _slashProvider, _activeKey, _view$2, _programmaticallyPos, _mode, _hideTimeout, _isMenuHovered, _keepOpenUntilClickOutside;
3597
3608
  const menu = slashFactory("CREPE_MENU");
3598
3609
  function configureMenu(ctx, config) {
3599
3610
  ctx.set(menu.key, {
@@ -3602,50 +3613,50 @@ function configureMenu(ctx, config) {
3602
3613
  }
3603
3614
  class MenuView {
3604
3615
  constructor(ctx, view, config) {
3605
- __privateAdd$5(this, _content$4);
3606
- __privateAdd$5(this, _app$4);
3607
- __privateAdd$5(this, _filter);
3608
- __privateAdd$5(this, _slashProvider);
3609
- __privateAdd$5(this, _activeKey);
3610
- __privateAdd$5(this, _view$1);
3611
- __privateAdd$5(this, _programmaticallyPos, null);
3612
- __privateAdd$5(this, _mode, null);
3613
- __privateAdd$5(this, _hideTimeout);
3614
- __privateAdd$5(this, _isMenuHovered, false);
3615
- __privateAdd$5(this, _keepOpenUntilClickOutside, false);
3616
+ __privateAdd$6(this, _content$4);
3617
+ __privateAdd$6(this, _app$4);
3618
+ __privateAdd$6(this, _filter);
3619
+ __privateAdd$6(this, _slashProvider);
3620
+ __privateAdd$6(this, _activeKey);
3621
+ __privateAdd$6(this, _view$2);
3622
+ __privateAdd$6(this, _programmaticallyPos, null);
3623
+ __privateAdd$6(this, _mode, null);
3624
+ __privateAdd$6(this, _hideTimeout);
3625
+ __privateAdd$6(this, _isMenuHovered, false);
3626
+ __privateAdd$6(this, _keepOpenUntilClickOutside, false);
3616
3627
  this.onHoverDelayHide = () => {
3617
- window.clearTimeout(__privateGet$5(this, _hideTimeout));
3618
- __privateSet$5(this, _hideTimeout, window.setTimeout(() => {
3619
- if (!__privateGet$5(this, _isMenuHovered) && !__privateGet$5(this, _keepOpenUntilClickOutside) && __privateGet$5(this, _programmaticallyPos) !== null) {
3628
+ window.clearTimeout(__privateGet$6(this, _hideTimeout));
3629
+ __privateSet$6(this, _hideTimeout, window.setTimeout(() => {
3630
+ if (!__privateGet$6(this, _isMenuHovered) && !__privateGet$6(this, _keepOpenUntilClickOutside) && __privateGet$6(this, _programmaticallyPos) !== null) {
3620
3631
  this.hide();
3621
3632
  }
3622
3633
  }, 150));
3623
3634
  };
3624
3635
  this.cancelHide = () => {
3625
- window.clearTimeout(__privateGet$5(this, _hideTimeout));
3636
+ window.clearTimeout(__privateGet$6(this, _hideTimeout));
3626
3637
  };
3627
3638
  this.update = (view) => {
3628
- __privateGet$5(this, _slashProvider).update(view);
3639
+ __privateGet$6(this, _slashProvider).update(view);
3629
3640
  };
3630
3641
  this.show = (pos, isClick = false, triggerElement, mode = "block") => {
3631
3642
  if (isClick) {
3632
- __privateSet$5(this, _keepOpenUntilClickOutside, true);
3643
+ __privateSet$6(this, _keepOpenUntilClickOutside, true);
3633
3644
  } else {
3634
- __privateSet$5(this, _keepOpenUntilClickOutside, false);
3645
+ __privateSet$6(this, _keepOpenUntilClickOutside, false);
3635
3646
  }
3636
- __privateSet$5(this, _programmaticallyPos, pos);
3637
- __privateSet$5(this, _mode, mode);
3638
- __privateGet$5(this, _filter).value = "";
3639
- const node = __privateGet$5(this, _view$1).state.doc.nodeAt(pos);
3647
+ __privateSet$6(this, _programmaticallyPos, pos);
3648
+ __privateSet$6(this, _mode, mode);
3649
+ __privateGet$6(this, _filter).value = "";
3650
+ const node = __privateGet$6(this, _view$2).state.doc.nodeAt(pos);
3640
3651
  if (node) {
3641
- __privateGet$5(this, _activeKey).value = getBlockKey(node);
3652
+ __privateGet$6(this, _activeKey).value = getBlockKey(node);
3642
3653
  } else {
3643
- __privateGet$5(this, _activeKey).value = "text";
3654
+ __privateGet$6(this, _activeKey).value = "text";
3644
3655
  }
3645
- __privateGet$5(this, _slashProvider).show();
3646
- __privateGet$5(this, _content$4).dataset.mode = mode;
3656
+ __privateGet$6(this, _slashProvider).show();
3657
+ __privateGet$6(this, _content$4).dataset.mode = mode;
3647
3658
  if (triggerElement) {
3648
- void computePosition(triggerElement, __privateGet$5(this, _content$4), {
3659
+ void computePosition(triggerElement, __privateGet$6(this, _content$4), {
3649
3660
  placement: "bottom-start",
3650
3661
  middleware: [
3651
3662
  flip(),
@@ -3666,7 +3677,7 @@ class MenuView {
3666
3677
  })
3667
3678
  ]
3668
3679
  }).then(({ x, y }) => {
3669
- Object.assign(__privateGet$5(this, _content$4).style, {
3680
+ Object.assign(__privateGet$6(this, _content$4).style, {
3670
3681
  left: `${x}px`,
3671
3682
  top: `${y}px`
3672
3683
  });
@@ -3674,25 +3685,25 @@ class MenuView {
3674
3685
  }
3675
3686
  };
3676
3687
  this.hide = () => {
3677
- __privateSet$5(this, _programmaticallyPos, null);
3678
- __privateSet$5(this, _mode, null);
3679
- __privateGet$5(this, _content$4).removeAttribute("data-mode");
3688
+ __privateSet$6(this, _programmaticallyPos, null);
3689
+ __privateSet$6(this, _mode, null);
3690
+ __privateGet$6(this, _content$4).removeAttribute("data-mode");
3680
3691
  this.cancelHide();
3681
- __privateGet$5(this, _slashProvider).hide();
3692
+ __privateGet$6(this, _slashProvider).hide();
3682
3693
  };
3683
3694
  this.destroy = () => {
3684
- __privateGet$5(this, _slashProvider).destroy();
3685
- __privateGet$5(this, _app$4).unmount();
3686
- __privateGet$5(this, _content$4).remove();
3695
+ __privateGet$6(this, _slashProvider).destroy();
3696
+ __privateGet$6(this, _app$4).unmount();
3697
+ __privateGet$6(this, _content$4).remove();
3687
3698
  };
3688
- __privateSet$5(this, _view$1, view);
3699
+ __privateSet$6(this, _view$2, view);
3689
3700
  const content = document.createElement("div");
3690
3701
  content.classList.add("milkdown-slash-menu");
3691
3702
  const show = ref(false);
3692
3703
  const filter = ref("");
3693
- __privateSet$5(this, _filter, filter);
3704
+ __privateSet$6(this, _filter, filter);
3694
3705
  const activeKey = ref("text");
3695
- __privateSet$5(this, _activeKey, activeKey);
3706
+ __privateSet$6(this, _activeKey, activeKey);
3696
3707
  const hide = this.hide;
3697
3708
  const app = createApp(Menu, {
3698
3709
  ctx,
@@ -3702,20 +3713,20 @@ class MenuView {
3702
3713
  hide,
3703
3714
  activeKey
3704
3715
  });
3705
- __privateSet$5(this, _app$4, app);
3716
+ __privateSet$6(this, _app$4, app);
3706
3717
  app.mount(content);
3707
- __privateSet$5(this, _content$4, content);
3708
- __privateGet$5(this, _content$4).addEventListener("pointerenter", () => {
3709
- __privateSet$5(this, _isMenuHovered, true);
3718
+ __privateSet$6(this, _content$4, content);
3719
+ __privateGet$6(this, _content$4).addEventListener("pointerenter", () => {
3720
+ __privateSet$6(this, _isMenuHovered, true);
3710
3721
  this.cancelHide();
3711
3722
  });
3712
- __privateGet$5(this, _content$4).addEventListener("pointerleave", () => {
3713
- __privateSet$5(this, _isMenuHovered, false);
3723
+ __privateGet$6(this, _content$4).addEventListener("pointerleave", () => {
3724
+ __privateSet$6(this, _isMenuHovered, false);
3714
3725
  this.onHoverDelayHide();
3715
3726
  });
3716
3727
  const self = this;
3717
- __privateSet$5(this, _slashProvider, new SlashProvider({
3718
- content: __privateGet$5(this, _content$4),
3728
+ __privateSet$6(this, _slashProvider, new SlashProvider({
3729
+ content: __privateGet$6(this, _content$4),
3719
3730
  debounce: 20,
3720
3731
  shouldShow(view2) {
3721
3732
  if (isInCodeBlock(view2.state.selection) || isInList(view2.state.selection))
@@ -3728,13 +3739,13 @@ class MenuView {
3728
3739
  if (!isSelectionAtEndOfNode(view2.state.selection)) {
3729
3740
  return false;
3730
3741
  }
3731
- const pos = __privateGet$5(self, _programmaticallyPos);
3742
+ const pos = __privateGet$6(self, _programmaticallyPos);
3732
3743
  filter.value = currentText.startsWith("/") ? currentText.slice(1) : currentText;
3733
3744
  if (typeof pos === "number") {
3734
3745
  const maxSize = view2.state.doc.nodeSize - 2;
3735
3746
  const validPos = Math.min(pos, maxSize);
3736
3747
  if (view2.state.doc.resolve(validPos).node() !== view2.state.doc.resolve(view2.state.selection.from).node()) {
3737
- __privateSet$5(self, _programmaticallyPos, null);
3748
+ __privateSet$6(self, _programmaticallyPos, null);
3738
3749
  return false;
3739
3750
  }
3740
3751
  return true;
@@ -3744,12 +3755,12 @@ class MenuView {
3744
3755
  },
3745
3756
  offset: 10
3746
3757
  }));
3747
- __privateGet$5(this, _slashProvider).onShow = () => {
3758
+ __privateGet$6(this, _slashProvider).onShow = () => {
3748
3759
  show.value = true;
3749
3760
  };
3750
- __privateGet$5(this, _slashProvider).onHide = () => {
3761
+ __privateGet$6(this, _slashProvider).onHide = () => {
3751
3762
  show.value = false;
3752
- __privateSet$5(this, _keepOpenUntilClickOutside, false);
3763
+ __privateSet$6(this, _keepOpenUntilClickOutside, false);
3753
3764
  };
3754
3765
  this.update(view);
3755
3766
  ctx.set(menuAPI.key, {
@@ -3760,10 +3771,10 @@ class MenuView {
3760
3771
  hide: () => this.hide(),
3761
3772
  onHoverDelayHide: () => this.onHoverDelayHide(),
3762
3773
  cancelHide: () => this.cancelHide(),
3763
- isProgrammatic: () => __privateGet$5(this, _programmaticallyPos) !== null,
3764
- getPos: () => __privateGet$5(this, _programmaticallyPos),
3774
+ isProgrammatic: () => __privateGet$6(this, _programmaticallyPos) !== null,
3775
+ getPos: () => __privateGet$6(this, _programmaticallyPos),
3765
3776
  isShow: () => show.value,
3766
- getMode: () => __privateGet$5(this, _mode)
3777
+ getMode: () => __privateGet$6(this, _mode)
3767
3778
  });
3768
3779
  }
3769
3780
  }
@@ -3772,7 +3783,7 @@ _app$4 = new WeakMap();
3772
3783
  _filter = new WeakMap();
3773
3784
  _slashProvider = new WeakMap();
3774
3785
  _activeKey = new WeakMap();
3775
- _view$1 = new WeakMap();
3786
+ _view$2 = new WeakMap();
3776
3787
  _programmaticallyPos = new WeakMap();
3777
3788
  _mode = new WeakMap();
3778
3789
  _hideTimeout = new WeakMap();
@@ -3931,25 +3942,25 @@ const BlockHandle = defineComponent({
3931
3942
  }
3932
3943
  });
3933
3944
 
3934
- var __typeError$4 = (msg) => {
3945
+ var __typeError$5 = (msg) => {
3935
3946
  throw TypeError(msg);
3936
3947
  };
3937
- var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
3938
- var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3939
- var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3940
- var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
3941
- var _content$3, _provider$1, _state, _app$3, _ctx, _syncIcon;
3948
+ var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
3949
+ var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3950
+ var __privateAdd$5 = (obj, member, value) => member.has(obj) ? __typeError$5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
3951
+ var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
3952
+ var _content$3, _provider$1, _state, _app$3, _ctx$1, _syncIcon;
3942
3953
  class BlockHandleView {
3943
3954
  constructor(ctx, config) {
3944
- __privateAdd$4(this, _content$3);
3945
- __privateAdd$4(this, _provider$1);
3946
- __privateAdd$4(this, _state, reactive({ icon: textIcon }));
3947
- __privateAdd$4(this, _app$3);
3948
- __privateAdd$4(this, _ctx);
3955
+ __privateAdd$5(this, _content$3);
3956
+ __privateAdd$5(this, _provider$1);
3957
+ __privateAdd$5(this, _state, reactive({ icon: textIcon }));
3958
+ __privateAdd$5(this, _app$3);
3959
+ __privateAdd$5(this, _ctx$1);
3949
3960
  this.update = () => {
3950
- __privateGet$4(this, _provider$1).update();
3951
- if (__privateGet$4(this, _provider$1).active) {
3952
- const node = __privateGet$4(this, _provider$1).active.node;
3961
+ __privateGet$5(this, _provider$1).update();
3962
+ if (__privateGet$5(this, _provider$1).active) {
3963
+ const node = __privateGet$5(this, _provider$1).active.node;
3953
3964
  let hasMediaChild = false;
3954
3965
  if (node.type.name === "paragraph") {
3955
3966
  node.content.forEach((child) => {
@@ -3961,24 +3972,24 @@ class BlockHandleView {
3961
3972
  const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
3962
3973
  const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
3963
3974
  if (isEmpty) {
3964
- __privateGet$4(this, _content$3).classList.add("empty-block");
3975
+ __privateGet$5(this, _content$3).classList.add("empty-block");
3965
3976
  } else {
3966
- __privateGet$4(this, _content$3).classList.remove("empty-block");
3977
+ __privateGet$5(this, _content$3).classList.remove("empty-block");
3967
3978
  }
3968
- __privateGet$4(this, _syncIcon).call(this, node);
3979
+ __privateGet$5(this, _syncIcon).call(this, node);
3969
3980
  } else {
3970
- __privateGet$4(this, _content$3).classList.remove("empty-block");
3971
- __privateGet$4(this, _state).icon = textIcon;
3981
+ __privateGet$5(this, _content$3).classList.remove("empty-block");
3982
+ __privateGet$5(this, _state).icon = textIcon;
3972
3983
  }
3973
3984
  };
3974
- __privateAdd$4(this, _syncIcon, (node) => {
3985
+ __privateAdd$5(this, _syncIcon, (node) => {
3975
3986
  var _a;
3976
3987
  if (node.type.name.includes("image")) {
3977
- __privateGet$4(this, _state).icon = imageIcon;
3988
+ __privateGet$5(this, _state).icon = imageIcon;
3978
3989
  return;
3979
3990
  }
3980
3991
  if (node.type.name.includes("attachment")) {
3981
- __privateGet$4(this, _state).icon = fileLinkIcon;
3992
+ __privateGet$5(this, _state).icon = fileLinkIcon;
3982
3993
  return;
3983
3994
  }
3984
3995
  switch (node.type.name) {
@@ -3993,87 +4004,87 @@ class BlockHandleView {
3993
4004
  h5Icon,
3994
4005
  h6Icon
3995
4006
  ];
3996
- __privateGet$4(this, _state).icon = (_a = headingIcons[level]) != null ? _a : textIcon;
4007
+ __privateGet$5(this, _state).icon = (_a = headingIcons[level]) != null ? _a : textIcon;
3997
4008
  break;
3998
4009
  }
3999
4010
  case "blockquote":
4000
- __privateGet$4(this, _state).icon = quoteIcon;
4011
+ __privateGet$5(this, _state).icon = quoteIcon;
4001
4012
  break;
4002
4013
  case "code_block":
4003
- __privateGet$4(this, _state).icon = codeIcon;
4014
+ __privateGet$5(this, _state).icon = codeIcon;
4004
4015
  break;
4005
4016
  case "math_display":
4006
4017
  case "math_inline":
4007
- __privateGet$4(this, _state).icon = functionsIcon;
4018
+ __privateGet$5(this, _state).icon = functionsIcon;
4008
4019
  break;
4009
4020
  case "hr":
4010
- __privateGet$4(this, _state).icon = dividerIcon;
4021
+ __privateGet$5(this, _state).icon = dividerIcon;
4011
4022
  break;
4012
4023
  case "table":
4013
- __privateGet$4(this, _state).icon = tableIcon;
4024
+ __privateGet$5(this, _state).icon = tableIcon;
4014
4025
  break;
4015
4026
  case "list_item":
4016
4027
  if (node.attrs.checked != null) {
4017
- __privateGet$4(this, _state).icon = todoListIcon;
4028
+ __privateGet$5(this, _state).icon = todoListIcon;
4018
4029
  } else {
4019
- __privateGet$4(this, _state).icon = bulletListIcon;
4030
+ __privateGet$5(this, _state).icon = bulletListIcon;
4020
4031
  }
4021
4032
  break;
4022
4033
  case "bullet_list":
4023
- __privateGet$4(this, _state).icon = bulletListIcon;
4034
+ __privateGet$5(this, _state).icon = bulletListIcon;
4024
4035
  break;
4025
4036
  case "ordered_list":
4026
- __privateGet$4(this, _state).icon = orderedListIcon;
4037
+ __privateGet$5(this, _state).icon = orderedListIcon;
4027
4038
  break;
4028
4039
  default:
4029
- __privateGet$4(this, _state).icon = textIcon;
4040
+ __privateGet$5(this, _state).icon = textIcon;
4030
4041
  }
4031
4042
  });
4032
4043
  this.destroy = () => {
4033
- __privateGet$4(this, _provider$1).destroy();
4034
- __privateGet$4(this, _content$3).remove();
4035
- __privateGet$4(this, _app$3).unmount();
4044
+ __privateGet$5(this, _provider$1).destroy();
4045
+ __privateGet$5(this, _content$3).remove();
4046
+ __privateGet$5(this, _app$3).unmount();
4036
4047
  };
4037
4048
  this.onAdd = (el) => {
4038
- const ctx = __privateGet$4(this, _ctx);
4049
+ const ctx = __privateGet$5(this, _ctx$1);
4039
4050
  const view = ctx.get(editorViewCtx);
4040
4051
  if (!view.hasFocus()) view.focus();
4041
- const active = __privateGet$4(this, _provider$1).active;
4052
+ const active = __privateGet$5(this, _provider$1).active;
4042
4053
  if (!active) return;
4043
4054
  const $pos = active.$pos;
4044
4055
  ctx.get(menuAPI.key).show($pos.pos, true, el, "list");
4045
4056
  };
4046
4057
  this.onOpenMenu = (el) => {
4047
- const ctx = __privateGet$4(this, _ctx);
4048
- const active = __privateGet$4(this, _provider$1).active;
4058
+ const ctx = __privateGet$5(this, _ctx$1);
4059
+ const active = __privateGet$5(this, _provider$1).active;
4049
4060
  if (!active) return;
4050
4061
  const $pos = active.$pos;
4051
4062
  ctx.get(menuAPI.key).show($pos.pos, true, el, "block");
4052
4063
  };
4053
4064
  this.onHoverAdd = (el) => {
4054
- const ctx = __privateGet$4(this, _ctx);
4055
- const active = __privateGet$4(this, _provider$1).active;
4065
+ const ctx = __privateGet$5(this, _ctx$1);
4066
+ const active = __privateGet$5(this, _provider$1).active;
4056
4067
  if (!active) return;
4057
4068
  const $pos = active.$pos;
4058
4069
  ctx.get(menuAPI.key).show($pos.pos, false, el, "list");
4059
4070
  };
4060
4071
  this.onLeaveAdd = () => {
4061
- const ctx = __privateGet$4(this, _ctx);
4072
+ const ctx = __privateGet$5(this, _ctx$1);
4062
4073
  ctx.get(menuAPI.key).onHoverDelayHide();
4063
4074
  };
4064
4075
  this.onHoverMenu = (el) => {
4065
- const ctx = __privateGet$4(this, _ctx);
4066
- const active = __privateGet$4(this, _provider$1).active;
4076
+ const ctx = __privateGet$5(this, _ctx$1);
4077
+ const active = __privateGet$5(this, _provider$1).active;
4067
4078
  if (!active) return;
4068
4079
  const $pos = active.$pos;
4069
4080
  ctx.get(menuAPI.key).show($pos.pos, false, el, "block");
4070
4081
  };
4071
4082
  this.onLeaveMenu = () => {
4072
- const ctx = __privateGet$4(this, _ctx);
4083
+ const ctx = __privateGet$5(this, _ctx$1);
4073
4084
  ctx.get(menuAPI.key).onHoverDelayHide();
4074
4085
  };
4075
4086
  var _a, _b, _c;
4076
- __privateSet$4(this, _ctx, ctx);
4087
+ __privateSet$5(this, _ctx$1, ctx);
4077
4088
  const content = document.createElement("div");
4078
4089
  content.classList.add("milkdown-block-handle");
4079
4090
  document.querySelectorAll(".milkdown-block-handle").forEach((el) => {
@@ -4088,14 +4099,14 @@ class BlockHandleView {
4088
4099
  onLeaveMenu: this.onLeaveMenu,
4089
4100
  addIcon: (_a = config == null ? void 0 : config.handleAddIcon) != null ? _a : plusIcon,
4090
4101
  handleIcon: (_b = config == null ? void 0 : config.handleDragIcon) != null ? _b : menuIcon,
4091
- ctx: __privateGet$4(this, _ctx),
4092
- state: __privateGet$4(this, _state)
4102
+ ctx: __privateGet$5(this, _ctx$1),
4103
+ state: __privateGet$5(this, _state)
4093
4104
  });
4094
4105
  app.mount(content);
4095
- __privateSet$4(this, _app$3, app);
4096
- __privateSet$4(this, _content$3, content);
4106
+ __privateSet$5(this, _app$3, app);
4107
+ __privateSet$5(this, _content$3, content);
4097
4108
  const blockProviderOptions = (_c = config == null ? void 0 : config.blockHandle) != null ? _c : {};
4098
- __privateSet$4(this, _provider$1, new BlockProvider({
4109
+ __privateSet$5(this, _provider$1, new BlockProvider({
4099
4110
  ctx,
4100
4111
  content,
4101
4112
  getOffset: () => 16,
@@ -4112,11 +4123,11 @@ class BlockHandleView {
4112
4123
  const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
4113
4124
  const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
4114
4125
  if (isEmpty) {
4115
- __privateGet$4(this, _content$3).classList.add("empty-block");
4126
+ __privateGet$5(this, _content$3).classList.add("empty-block");
4116
4127
  } else {
4117
- __privateGet$4(this, _content$3).classList.remove("empty-block");
4128
+ __privateGet$5(this, _content$3).classList.remove("empty-block");
4118
4129
  }
4119
- __privateGet$4(this, _syncIcon).call(this, active.node);
4130
+ __privateGet$5(this, _syncIcon).call(this, active.node);
4120
4131
  let totalDescendant = 0;
4121
4132
  active.node.descendants((node2) => {
4122
4133
  totalDescendant += node2.childCount;
@@ -4148,7 +4159,7 @@ _content$3 = new WeakMap();
4148
4159
  _provider$1 = new WeakMap();
4149
4160
  _state = new WeakMap();
4150
4161
  _app$3 = new WeakMap();
4151
- _ctx = new WeakMap();
4162
+ _ctx$1 = new WeakMap();
4152
4163
  _syncIcon = new WeakMap();
4153
4164
  function configureBlockHandle(ctx, config) {
4154
4165
  ctx.set(blockConfig.key, {
@@ -4295,6 +4306,27 @@ const cursor = (editor, config) => {
4295
4306
  editor.use($prose(() => virtualCursor));
4296
4307
  };
4297
4308
 
4309
+ const diffBlockFeature = (editor, config = {}) => {
4310
+ editor.config(crepeFeatureConfig(CrepeFeature.DiffBlock)).config((ctx) => {
4311
+ const { languages = [], theme } = config;
4312
+ const extensions = [basicSetup];
4313
+ if (theme) {
4314
+ extensions.push(theme);
4315
+ } else {
4316
+ extensions.push(oneDark);
4317
+ }
4318
+ if (config.extensions) {
4319
+ extensions.push(...config.extensions);
4320
+ }
4321
+ ctx.update(diffBlockConfig.key, (defaultConfig) => ({
4322
+ ...defaultConfig,
4323
+ extensions,
4324
+ languages: languages.length > 0 ? languages : defaultConfig.languages,
4325
+ renderLanguage: config.renderLanguage || defaultConfig.renderLanguage
4326
+ }));
4327
+ }).use(diffBlock);
4328
+ };
4329
+
4298
4330
  const listeners = /* @__PURE__ */ new Set();
4299
4331
  let _popupCount = 0;
4300
4332
  function getIsAnyPopupOpen() {
@@ -5674,7 +5706,8 @@ const Toolbar = defineComponent({
5674
5706
  containerWidth = container.clientWidth;
5675
5707
  }
5676
5708
  } else {
5677
- containerWidth = container.clientWidth;
5709
+ const view = ctx.get(editorViewCtx);
5710
+ containerWidth = view.dom.clientWidth - 32;
5678
5711
  }
5679
5712
  if (containerWidth === lastContainerWidth) {
5680
5713
  return;
@@ -9348,11 +9381,11 @@ const OutlinePanel = defineComponent({
9348
9381
  "div",
9349
9382
  {
9350
9383
  style: {
9351
- padding: "20px 16px",
9384
+ padding: "12px 16px",
9352
9385
  fontWeight: "bold",
9353
9386
  fontSize: "14px",
9354
9387
  color: "var(--crepe-color-on-surface)",
9355
- borderBottom: "1px solid var(--crepe-color-outline-variant)",
9388
+ borderBottom: "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))",
9356
9389
  display: "flex",
9357
9390
  justifyContent: "space-between",
9358
9391
  alignItems: "center"
@@ -9524,14 +9557,14 @@ const OutlinePanel = defineComponent({
9524
9557
  }
9525
9558
  });
9526
9559
 
9527
- var __typeError$3 = (msg) => {
9560
+ var __typeError$4 = (msg) => {
9528
9561
  throw TypeError(msg);
9529
9562
  };
9530
- var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
9531
- var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9532
- var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
9533
- var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
9534
- var _content$2, _app$2, _headerContent, _headerApp, _outlineContent, _outlineApp, _watcher, _selection$1, _show$1, _resizeObserver, _updateOutlineGeometry, _scrollContainers, _onDblClick, _view;
9563
+ var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
9564
+ var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9565
+ var __privateAdd$4 = (obj, member, value) => member.has(obj) ? __typeError$4("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
9566
+ var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
9567
+ var _content$2, _app$2, _headerContent, _headerApp, _outlineContent, _outlineApp, _watcher, _selection$1, _show$1, _resizeObserver$1, _updateOutlineGeometry, _scrollContainers$1, _onDblClick, _view$1, _editorContainer;
9535
9568
  const fixedToolbarConfig = $ctx(
9536
9569
  {},
9537
9570
  "fixedToolbarConfigCtx"
@@ -9539,80 +9572,90 @@ const fixedToolbarConfig = $ctx(
9539
9572
  const fixedToolbarKey = new PluginKey("MILKDOWN_FIXED_TOOLBAR");
9540
9573
  class FixedToolbarView {
9541
9574
  constructor(ctx, view) {
9542
- __privateAdd$3(this, _content$2);
9543
- __privateAdd$3(this, _app$2);
9544
- __privateAdd$3(this, _headerContent);
9545
- __privateAdd$3(this, _headerApp);
9546
- __privateAdd$3(this, _outlineContent);
9547
- __privateAdd$3(this, _outlineApp);
9548
- __privateAdd$3(this, _watcher);
9549
- __privateAdd$3(this, _selection$1);
9550
- __privateAdd$3(this, _show$1, ref(true));
9551
- __privateAdd$3(this, _resizeObserver);
9552
- __privateAdd$3(this, _updateOutlineGeometry);
9553
- __privateAdd$3(this, _scrollContainers, []);
9554
- __privateAdd$3(this, _onDblClick);
9555
- __privateAdd$3(this, _view);
9575
+ __privateAdd$4(this, _content$2);
9576
+ __privateAdd$4(this, _app$2);
9577
+ __privateAdd$4(this, _headerContent);
9578
+ __privateAdd$4(this, _headerApp);
9579
+ __privateAdd$4(this, _outlineContent);
9580
+ __privateAdd$4(this, _outlineApp);
9581
+ __privateAdd$4(this, _watcher);
9582
+ __privateAdd$4(this, _selection$1);
9583
+ __privateAdd$4(this, _show$1, ref(true));
9584
+ __privateAdd$4(this, _resizeObserver$1);
9585
+ __privateAdd$4(this, _updateOutlineGeometry);
9586
+ __privateAdd$4(this, _scrollContainers$1, []);
9587
+ __privateAdd$4(this, _onDblClick);
9588
+ __privateAdd$4(this, _view$1);
9589
+ __privateAdd$4(this, _editorContainer);
9556
9590
  this.update = (view) => {
9557
- __privateGet$3(this, _selection$1).value = view.state.selection;
9591
+ __privateGet$4(this, _selection$1).value = view.state.selection;
9558
9592
  };
9559
9593
  this.destroy = () => {
9560
- if (__privateGet$3(this, _watcher)) __privateGet$3(this, _watcher).call(this);
9561
- if (__privateGet$3(this, _onDblClick)) {
9562
- __privateGet$3(this, _view).dom.removeEventListener("dblclick", __privateGet$3(this, _onDblClick));
9594
+ if (__privateGet$4(this, _watcher)) __privateGet$4(this, _watcher).call(this);
9595
+ if (__privateGet$4(this, _onDblClick)) {
9596
+ __privateGet$4(this, _view$1).dom.removeEventListener("dblclick", __privateGet$4(this, _onDblClick));
9563
9597
  }
9564
- if (__privateGet$3(this, _resizeObserver)) __privateGet$3(this, _resizeObserver).disconnect();
9565
- window.removeEventListener("resize", __privateGet$3(this, _updateOutlineGeometry));
9566
- window.removeEventListener("scroll", __privateGet$3(this, _updateOutlineGeometry), {
9598
+ if (__privateGet$4(this, _resizeObserver$1)) __privateGet$4(this, _resizeObserver$1).disconnect();
9599
+ window.removeEventListener("resize", __privateGet$4(this, _updateOutlineGeometry));
9600
+ window.removeEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry), {
9567
9601
  capture: true
9568
9602
  });
9569
- __privateGet$3(this, _scrollContainers).forEach((el) => {
9570
- el.removeEventListener("scroll", __privateGet$3(this, _updateOutlineGeometry));
9603
+ __privateGet$4(this, _scrollContainers$1).forEach((el) => {
9604
+ el.removeEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry));
9571
9605
  });
9572
- __privateSet$3(this, _scrollContainers, []);
9573
- __privateGet$3(this, _app$2).unmount();
9574
- __privateGet$3(this, _content$2).remove();
9575
- if (__privateGet$3(this, _headerApp)) __privateGet$3(this, _headerApp).unmount();
9576
- if (__privateGet$3(this, _headerContent)) __privateGet$3(this, _headerContent).remove();
9577
- if (__privateGet$3(this, _outlineApp)) __privateGet$3(this, _outlineApp).unmount();
9578
- if (__privateGet$3(this, _outlineContent)) __privateGet$3(this, _outlineContent).remove();
9579
- };
9580
- __privateSet$3(this, _view, view);
9606
+ __privateSet$4(this, _scrollContainers$1, []);
9607
+ __privateGet$4(this, _app$2).unmount();
9608
+ __privateGet$4(this, _content$2).remove();
9609
+ if (__privateGet$4(this, _headerApp)) __privateGet$4(this, _headerApp).unmount();
9610
+ if (__privateGet$4(this, _headerContent)) __privateGet$4(this, _headerContent).remove();
9611
+ if (__privateGet$4(this, _outlineApp)) __privateGet$4(this, _outlineApp).unmount();
9612
+ if (__privateGet$4(this, _outlineContent)) __privateGet$4(this, _outlineContent).remove();
9613
+ };
9614
+ __privateSet$4(this, _view$1, view);
9581
9615
  const config = ctx.get(fixedToolbarConfig.key);
9582
9616
  const content = document.createElement("div");
9583
9617
  content.className = "milkdown-fixed-toolbar";
9584
- __privateSet$3(this, _selection$1, shallowRef(view.state.selection));
9618
+ __privateSet$4(this, _selection$1, shallowRef(view.state.selection));
9585
9619
  const app = createApp(FixedToolbarComponent, {
9586
9620
  ctx,
9587
9621
  hide: () => {
9588
9622
  },
9589
9623
  // No-op for fixed toolbar
9590
9624
  config,
9591
- selection: __privateGet$3(this, _selection$1),
9592
- show: __privateGet$3(this, _show$1)
9625
+ selection: __privateGet$4(this, _selection$1),
9626
+ show: __privateGet$4(this, _show$1)
9593
9627
  });
9594
9628
  app.mount(content);
9595
- __privateSet$3(this, _content$2, content);
9596
- __privateSet$3(this, _app$2, app);
9629
+ __privateSet$4(this, _content$2, content);
9630
+ __privateSet$4(this, _app$2, app);
9597
9631
  const root = view.dom.parentElement;
9598
9632
  if (root) {
9599
9633
  root.style.position = "relative";
9600
- root.style.transition = "padding 0.1s ease-out, background-color 0.2s ease-out";
9601
- root.prepend(__privateGet$3(this, _content$2));
9634
+ root.style.transition = "background-color 0.2s ease-out";
9635
+ root.prepend(__privateGet$4(this, _content$2));
9636
+ const editorContainer = document.createElement("div");
9637
+ editorContainer.className = "milkdown-editor-container";
9638
+ editorContainer.style.transition = "padding 0.1s ease-out";
9639
+ editorContainer.style.display = "flex";
9640
+ editorContainer.style.flexDirection = "column";
9641
+ editorContainer.style.flexGrow = "1";
9642
+ root.insertBefore(editorContainer, view.dom);
9643
+ editorContainer.appendChild(view.dom);
9644
+ __privateSet$4(this, _editorContainer, editorContainer);
9602
9645
  const headerContent = document.createElement("div");
9603
- __privateSet$3(this, _headerApp, createApp(DocumentHeader, { ctx, config }));
9604
- __privateGet$3(this, _headerApp).mount(headerContent);
9605
- __privateSet$3(this, _headerContent, headerContent);
9606
- root.insertBefore(headerContent, view.dom);
9646
+ __privateSet$4(this, _headerApp, createApp(DocumentHeader, { ctx, config }));
9647
+ __privateGet$4(this, _headerApp).mount(headerContent);
9648
+ __privateSet$4(this, _headerContent, headerContent);
9649
+ editorContainer.insertBefore(headerContent, view.dom);
9607
9650
  const outlineContent = document.createElement("div");
9608
9651
  outlineContent.style.position = "fixed";
9609
9652
  outlineContent.style.zIndex = "100";
9610
- __privateSet$3(this, _outlineApp, createApp(OutlinePanel, { ctx }));
9611
- __privateGet$3(this, _outlineApp).mount(outlineContent);
9612
- __privateSet$3(this, _outlineContent, outlineContent);
9653
+ __privateSet$4(this, _outlineApp, createApp(OutlinePanel, { ctx }));
9654
+ __privateGet$4(this, _outlineApp).mount(outlineContent);
9655
+ __privateSet$4(this, _outlineContent, outlineContent);
9613
9656
  root.appendChild(outlineContent);
9614
- __privateSet$3(this, _onDblClick, (event) => {
9615
- const view2 = __privateGet$3(this, _view);
9657
+ __privateSet$4(this, _onDblClick, (event) => {
9658
+ const view2 = __privateGet$4(this, _view$1);
9616
9659
  if (!view2.editable) return;
9617
9660
  const dom = view2.dom;
9618
9661
  const children = dom.children;
@@ -9635,21 +9678,21 @@ class FixedToolbarView {
9635
9678
  view2.dispatch(tr);
9636
9679
  view2.focus();
9637
9680
  });
9638
- view.dom.addEventListener("dblclick", __privateGet$3(this, _onDblClick));
9639
- __privateGet$3(this, _content$2).style.transition = "margin 0.1s ease-out, width 0.1s ease-out";
9681
+ view.dom.addEventListener("dblclick", __privateGet$4(this, _onDblClick));
9682
+ __privateGet$4(this, _content$2).style.transition = "margin 0.1s ease-out, width 0.1s ease-out";
9640
9683
  const viewState = ctx.get(viewMenuStateCtx.key);
9641
9684
  if (config.outlinePosition) {
9642
9685
  viewState.outlinePosition = config.outlinePosition;
9643
9686
  }
9644
- __privateSet$3(this, _updateOutlineGeometry, () => {
9687
+ __privateSet$4(this, _updateOutlineGeometry, () => {
9645
9688
  const rootRect = root.getBoundingClientRect();
9646
9689
  let outlineTop = rootRect.top;
9647
- if (__privateGet$3(this, _content$2) && __privateGet$3(this, _content$2).offsetHeight > 0) {
9648
- const toolbarRect = __privateGet$3(this, _content$2).getBoundingClientRect();
9690
+ if (__privateGet$4(this, _content$2) && __privateGet$4(this, _content$2).offsetHeight > 0) {
9691
+ const toolbarRect = __privateGet$4(this, _content$2).getBoundingClientRect();
9649
9692
  outlineTop = Math.max(outlineTop, toolbarRect.bottom);
9650
9693
  }
9651
- if (viewState.showCover && __privateGet$3(this, _headerContent)) {
9652
- const coverEl = __privateGet$3(this, _headerContent).querySelector(
9694
+ if (viewState.showCover && __privateGet$4(this, _headerContent)) {
9695
+ const coverEl = __privateGet$4(this, _headerContent).querySelector(
9653
9696
  ".milkdown-document-cover"
9654
9697
  );
9655
9698
  if (coverEl) {
@@ -9671,28 +9714,50 @@ class FixedToolbarView {
9671
9714
  outlineContent.style.right = "auto";
9672
9715
  } else {
9673
9716
  outlineContent.style.left = "auto";
9674
- outlineContent.style.right = `${window.innerWidth - rootRect.right}px`;
9717
+ let baseOffset = window.innerWidth - rootRect.right;
9718
+ let rightOffset = baseOffset;
9719
+ let hasVScroll = false;
9720
+ if (document.documentElement.scrollHeight > window.innerHeight) {
9721
+ hasVScroll = true;
9722
+ }
9723
+ let parent = root;
9724
+ while (parent && parent !== document.body) {
9725
+ const { overflowY } = getComputedStyle(parent);
9726
+ if (overflowY === "auto" || overflowY === "scroll") {
9727
+ if (parent.scrollHeight > parent.clientHeight) {
9728
+ hasVScroll = true;
9729
+ break;
9730
+ }
9731
+ }
9732
+ parent = parent.parentElement;
9733
+ }
9734
+ if (hasVScroll) {
9735
+ rightOffset = Math.max(rightOffset, 32);
9736
+ } else {
9737
+ rightOffset = Math.max(rightOffset, 0);
9738
+ }
9739
+ outlineContent.style.right = `${rightOffset}px`;
9675
9740
  }
9676
9741
  }
9677
9742
  });
9678
- __privateSet$3(this, _resizeObserver, new ResizeObserver(__privateGet$3(this, _updateOutlineGeometry)));
9679
- __privateGet$3(this, _resizeObserver).observe(root);
9680
- window.addEventListener("resize", __privateGet$3(this, _updateOutlineGeometry));
9681
- window.addEventListener("scroll", __privateGet$3(this, _updateOutlineGeometry), {
9743
+ __privateSet$4(this, _resizeObserver$1, new ResizeObserver(__privateGet$4(this, _updateOutlineGeometry)));
9744
+ __privateGet$4(this, _resizeObserver$1).observe(root);
9745
+ window.addEventListener("resize", __privateGet$4(this, _updateOutlineGeometry));
9746
+ window.addEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry), {
9682
9747
  capture: true,
9683
9748
  passive: true
9684
9749
  });
9685
9750
  let scrollerNode = root;
9686
9751
  while (scrollerNode && scrollerNode !== document) {
9687
9752
  if (scrollerNode instanceof Element) {
9688
- scrollerNode.addEventListener("scroll", __privateGet$3(this, _updateOutlineGeometry), {
9753
+ scrollerNode.addEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry), {
9689
9754
  passive: true
9690
9755
  });
9691
- __privateGet$3(this, _scrollContainers).push(scrollerNode);
9756
+ __privateGet$4(this, _scrollContainers$1).push(scrollerNode);
9692
9757
  }
9693
9758
  scrollerNode = scrollerNode.parentNode || scrollerNode.host;
9694
9759
  }
9695
- __privateSet$3(this, _watcher, watch(
9760
+ __privateSet$4(this, _watcher, watch(
9696
9761
  () => [
9697
9762
  viewState.outlineVisible,
9698
9763
  viewState.outlinePosition,
@@ -9707,41 +9772,43 @@ class FixedToolbarView {
9707
9772
  } else {
9708
9773
  root.style.backgroundColor = "";
9709
9774
  }
9710
- if (viewState.outlineVisible) {
9711
- if (viewState.outlinePosition === "left") {
9712
- root.style.paddingLeft = `${viewState.outlineWidth}px`;
9713
- root.style.paddingRight = "0";
9714
- __privateGet$3(this, _content$2).style.width = `calc(100% + ${viewState.outlineWidth}px)`;
9715
- __privateGet$3(this, _content$2).style.marginLeft = `-${viewState.outlineWidth}px`;
9716
- __privateGet$3(this, _content$2).style.marginRight = "0";
9775
+ root.style.paddingLeft = "0";
9776
+ root.style.paddingRight = "0";
9777
+ __privateGet$4(this, _content$2).style.width = "100%";
9778
+ __privateGet$4(this, _content$2).style.marginLeft = "0";
9779
+ __privateGet$4(this, _content$2).style.marginRight = "0";
9780
+ if (__privateGet$4(this, _editorContainer)) {
9781
+ if (viewState.outlineVisible) {
9782
+ if (viewState.outlinePosition === "left") {
9783
+ __privateGet$4(this, _editorContainer).style.paddingLeft = `${viewState.outlineWidth}px`;
9784
+ __privateGet$4(this, _editorContainer).style.paddingRight = "0";
9785
+ } else {
9786
+ __privateGet$4(this, _editorContainer).style.paddingLeft = "0";
9787
+ __privateGet$4(this, _editorContainer).style.paddingRight = `${viewState.outlineWidth}px`;
9788
+ }
9717
9789
  } else {
9718
- root.style.paddingLeft = "0";
9719
- root.style.paddingRight = `${viewState.outlineWidth}px`;
9720
- __privateGet$3(this, _content$2).style.width = `calc(100% + ${viewState.outlineWidth}px)`;
9721
- __privateGet$3(this, _content$2).style.marginLeft = "0";
9722
- __privateGet$3(this, _content$2).style.marginRight = `-${viewState.outlineWidth}px`;
9790
+ __privateGet$4(this, _editorContainer).style.paddingLeft = "0";
9791
+ __privateGet$4(this, _editorContainer).style.paddingRight = "0";
9723
9792
  }
9724
- } else {
9725
- root.style.paddingLeft = "0";
9726
- root.style.paddingRight = "0";
9727
- __privateGet$3(this, _content$2).style.width = "100%";
9728
- __privateGet$3(this, _content$2).style.marginLeft = "0";
9729
- __privateGet$3(this, _content$2).style.marginRight = "0";
9730
9793
  }
9731
9794
  const maxWidth = editorWidthMap[viewState.editorWidth];
9732
9795
  const isFull = maxWidth === "none";
9733
9796
  const px = isFull ? "80px" : "0";
9734
- __privateGet$3(this, _view).dom.style.maxWidth = maxWidth;
9735
- __privateGet$3(this, _view).dom.style.width = isFull ? "100%" : maxWidth;
9736
- __privateGet$3(this, _view).dom.style.margin = isFull ? "0" : "0 auto";
9737
- __privateGet$3(this, _view).dom.style.padding = `20px ${px} 36px`;
9738
- if (__privateGet$3(this, _headerContent)) {
9739
- __privateGet$3(this, _headerContent).style.margin = isFull && !viewState.showCover ? "0 auto" : "0";
9740
- __privateGet$3(this, _headerContent).style.padding = `0px`;
9797
+ __privateGet$4(this, _view$1).dom.style.maxWidth = maxWidth;
9798
+ __privateGet$4(this, _view$1).dom.style.width = isFull ? "100%" : maxWidth;
9799
+ __privateGet$4(this, _view$1).dom.style.margin = isFull ? "0" : "0 auto";
9800
+ __privateGet$4(this, _view$1).dom.style.padding = `20px ${px} 36px`;
9801
+ if (__privateGet$4(this, _headerContent)) {
9802
+ __privateGet$4(this, _headerContent).style.margin = isFull && !viewState.showCover ? "0 auto" : "0";
9803
+ __privateGet$4(this, _headerContent).style.padding = `0px`;
9741
9804
  }
9742
- nextTick(() => {
9805
+ void nextTick(() => {
9743
9806
  var _a;
9744
- (_a = __privateGet$3(this, _updateOutlineGeometry)) == null ? void 0 : _a.call(this);
9807
+ (_a = __privateGet$4(this, _updateOutlineGeometry)) == null ? void 0 : _a.call(this);
9808
+ setTimeout(() => {
9809
+ var _a2;
9810
+ (_a2 = __privateGet$4(this, _updateOutlineGeometry)) == null ? void 0 : _a2.call(this);
9811
+ }, 100);
9745
9812
  });
9746
9813
  },
9747
9814
  { immediate: true }
@@ -9758,11 +9825,12 @@ _outlineApp = new WeakMap();
9758
9825
  _watcher = new WeakMap();
9759
9826
  _selection$1 = new WeakMap();
9760
9827
  _show$1 = new WeakMap();
9761
- _resizeObserver = new WeakMap();
9828
+ _resizeObserver$1 = new WeakMap();
9762
9829
  _updateOutlineGeometry = new WeakMap();
9763
- _scrollContainers = new WeakMap();
9830
+ _scrollContainers$1 = new WeakMap();
9764
9831
  _onDblClick = new WeakMap();
9765
- _view = new WeakMap();
9832
+ _view$1 = new WeakMap();
9833
+ _editorContainer = new WeakMap();
9766
9834
  const fixedToolbarPlugin = $prose((ctx) => {
9767
9835
  return new Plugin({
9768
9836
  key: fixedToolbarKey,
@@ -9888,6 +9956,917 @@ const imageBlockConverter = $prose$1((ctx) => {
9888
9956
  });
9889
9957
  });
9890
9958
 
9959
+ const typeLabels = {
9960
+ added: "\u65B0\u589E",
9961
+ removed: "\u5220\u9664"
9962
+ };
9963
+ const typeColors = {
9964
+ added: "#4caf50",
9965
+ removed: "#c0392b"
9966
+ };
9967
+ function mountChangePanel(container, changes, onNavigate, onClose) {
9968
+ const app = createApp({
9969
+ setup() {
9970
+ const activeTab = ref("all");
9971
+ const filteredChanges = computed(() => {
9972
+ if (activeTab.value === "all") return changes;
9973
+ return changes.filter((c) => c.type === activeTab.value);
9974
+ });
9975
+ const counts = computed(() => ({
9976
+ all: changes.length,
9977
+ removed: changes.filter((c) => c.type === "removed").length,
9978
+ added: changes.filter((c) => c.type === "added").length
9979
+ }));
9980
+ function renderTab(tab, label) {
9981
+ const isActive = activeTab.value === tab;
9982
+ return h(
9983
+ "button",
9984
+ {
9985
+ style: {
9986
+ padding: "6px 10px",
9987
+ border: "none",
9988
+ background: "none",
9989
+ cursor: "pointer",
9990
+ fontSize: "12px",
9991
+ color: isActive ? "#1890ff" : "#666",
9992
+ borderBottom: isActive ? "2px solid #1890ff" : "2px solid transparent"
9993
+ },
9994
+ onClick: () => {
9995
+ activeTab.value = tab;
9996
+ }
9997
+ },
9998
+ label
9999
+ );
10000
+ }
10001
+ function renderItem(change, index) {
10002
+ const color = typeColors[change.type];
10003
+ const children = [
10004
+ h("div", { style: { marginBottom: "4px" } }, [
10005
+ h(
10006
+ "span",
10007
+ {
10008
+ style: {
10009
+ display: "inline-block",
10010
+ padding: "1px 6px",
10011
+ borderRadius: "3px",
10012
+ color: "#fff",
10013
+ fontSize: "11px",
10014
+ fontWeight: "500",
10015
+ backgroundColor: color
10016
+ }
10017
+ },
10018
+ `${index} ${typeLabels[change.type]}`
10019
+ )
10020
+ ])
10021
+ ];
10022
+ if (change.oldText) {
10023
+ children.push(
10024
+ h(
10025
+ "div",
10026
+ {
10027
+ style: {
10028
+ marginTop: "3px",
10029
+ fontSize: "12px",
10030
+ lineHeight: "1.5",
10031
+ color: "#555",
10032
+ wordBreak: "break-all"
10033
+ }
10034
+ },
10035
+ [
10036
+ h(
10037
+ "span",
10038
+ { style: { color: "#999", fontSize: "11px" } },
10039
+ "\u539F\u6587: "
10040
+ ),
10041
+ h("span", null, change.oldText)
10042
+ ]
10043
+ )
10044
+ );
10045
+ }
10046
+ if (change.newText) {
10047
+ children.push(
10048
+ h(
10049
+ "div",
10050
+ {
10051
+ style: {
10052
+ marginTop: "3px",
10053
+ fontSize: "12px",
10054
+ lineHeight: "1.5",
10055
+ wordBreak: "break-all"
10056
+ }
10057
+ },
10058
+ [
10059
+ h(
10060
+ "span",
10061
+ { style: { color: "#999", fontSize: "11px" } },
10062
+ "\u5DEE\u5F02: "
10063
+ ),
10064
+ h("span", { style: { color } }, change.newText)
10065
+ ]
10066
+ )
10067
+ );
10068
+ }
10069
+ return h(
10070
+ "div",
10071
+ {
10072
+ style: {
10073
+ padding: "8px 10px",
10074
+ borderRadius: "4px",
10075
+ marginBottom: "6px",
10076
+ background: "rgba(0,0,0,0.02)",
10077
+ border: "1px solid #eee",
10078
+ cursor: change.from > 0 ? "pointer" : "default"
10079
+ },
10080
+ onClick: () => {
10081
+ if (change.from > 0) onNavigate(change.from);
10082
+ }
10083
+ },
10084
+ children
10085
+ );
10086
+ }
10087
+ return () => h(
10088
+ "div",
10089
+ {
10090
+ style: {
10091
+ width: "100%",
10092
+ height: "100%",
10093
+ display: "flex",
10094
+ flexDirection: "column",
10095
+ backgroundColor: "var(--crepe-color-surface, #fff)",
10096
+ boxSizing: "border-box",
10097
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
10098
+ fontSize: "13px",
10099
+ color: "var(--crepe-color-on-surface, #333)",
10100
+ overflow: "hidden"
10101
+ }
10102
+ },
10103
+ [
10104
+ // Header
10105
+ h(
10106
+ "div",
10107
+ {
10108
+ style: {
10109
+ padding: "12px 16px",
10110
+ fontSize: "14px",
10111
+ fontWeight: "bold",
10112
+ borderBottom: "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))",
10113
+ color: "var(--crepe-color-on-surface, #333)",
10114
+ display: "flex",
10115
+ justifyContent: "space-between",
10116
+ alignItems: "center",
10117
+ flexShrink: 0
10118
+ }
10119
+ },
10120
+ [
10121
+ h("span", null, "\u6587\u6863\u5DEE\u5F02\u53D8\u66F4"),
10122
+ onClose ? h(
10123
+ "div",
10124
+ {
10125
+ style: {
10126
+ cursor: "pointer",
10127
+ display: "flex",
10128
+ alignItems: "center",
10129
+ justifyContent: "center",
10130
+ width: "24px",
10131
+ height: "24px",
10132
+ borderRadius: "4px",
10133
+ color: "var(--crepe-color-outline, #999)",
10134
+ transition: "background-color 0.2s, color 0.2s"
10135
+ },
10136
+ onClick: onClose,
10137
+ onMouseenter: (e) => {
10138
+ const target = e.currentTarget;
10139
+ target.style.backgroundColor = "var(--crepe-color-hover, rgba(0,0,0,0.05))";
10140
+ target.style.color = "var(--crepe-color-on-surface, #333)";
10141
+ },
10142
+ onMouseleave: (e) => {
10143
+ const target = e.currentTarget;
10144
+ target.style.backgroundColor = "transparent";
10145
+ target.style.color = "var(--crepe-color-outline, #999)";
10146
+ },
10147
+ title: "\u5173\u95ED\u5DEE\u5F02"
10148
+ },
10149
+ [
10150
+ h(
10151
+ "svg",
10152
+ {
10153
+ width: "16",
10154
+ height: "16",
10155
+ viewBox: "0 0 24 24",
10156
+ fill: "none",
10157
+ stroke: "currentColor",
10158
+ strokeWidth: "2",
10159
+ strokeLinecap: "round",
10160
+ strokeLinejoin: "round"
10161
+ },
10162
+ [
10163
+ h("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
10164
+ h("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
10165
+ ]
10166
+ )
10167
+ ]
10168
+ ) : null
10169
+ ]
10170
+ ),
10171
+ // Tabs
10172
+ h(
10173
+ "div",
10174
+ {
10175
+ style: {
10176
+ display: "flex",
10177
+ borderBottom: "1px solid #eee",
10178
+ padding: "0 8px",
10179
+ flexShrink: 0
10180
+ }
10181
+ },
10182
+ [
10183
+ renderTab("all", `\u5168\u90E8(${counts.value.all})`),
10184
+ renderTab("removed", `\u5220\u9664(${counts.value.removed})`),
10185
+ renderTab("added", `\u65B0\u589E(${counts.value.added})`)
10186
+ ]
10187
+ ),
10188
+ // List
10189
+ h(
10190
+ "div",
10191
+ {
10192
+ style: {
10193
+ flex: 1,
10194
+ overflowY: "auto",
10195
+ padding: "8px"
10196
+ }
10197
+ },
10198
+ filteredChanges.value.map(
10199
+ (change, i) => renderItem(change, i + 1)
10200
+ )
10201
+ )
10202
+ ]
10203
+ );
10204
+ }
10205
+ });
10206
+ app.mount(container);
10207
+ return app;
10208
+ }
10209
+
10210
+ const inlineDiffConfig = $ctx(
10211
+ {
10212
+ addedClass: "crepe-diff-added",
10213
+ deletedClass: "crepe-diff-deleted"
10214
+ },
10215
+ "inlineDiffConfigCtx"
10216
+ );
10217
+ const noopApi = {
10218
+ showDiff: () => {
10219
+ },
10220
+ hideDiff: () => {
10221
+ },
10222
+ isShowing: () => false
10223
+ };
10224
+ const inlineDiffApiCtx = $ctx(noopApi, "inlineDiffApiCtx");
10225
+
10226
+ function lcs(a, b, eq) {
10227
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10228
+ const m = a.length;
10229
+ const n = b.length;
10230
+ const dp = Array.from(
10231
+ { length: m + 1 },
10232
+ () => Array.from({ length: n + 1 }, () => 0)
10233
+ );
10234
+ for (let i2 = m - 1; i2 >= 0; i2--) {
10235
+ for (let j2 = n - 1; j2 >= 0; j2--) {
10236
+ const diag = (_b = (_a = dp[i2 + 1]) == null ? void 0 : _a[j2 + 1]) != null ? _b : 0;
10237
+ const down = (_d = (_c = dp[i2 + 1]) == null ? void 0 : _c[j2]) != null ? _d : 0;
10238
+ const right = (_f = (_e = dp[i2]) == null ? void 0 : _e[j2 + 1]) != null ? _f : 0;
10239
+ dp[i2][j2] = eq(a[i2], b[j2]) ? 1 + diag : Math.max(down, right);
10240
+ }
10241
+ }
10242
+ const pairs = [];
10243
+ let i = 0;
10244
+ let j = 0;
10245
+ while (i < m && j < n) {
10246
+ const down = (_h = (_g = dp[i + 1]) == null ? void 0 : _g[j]) != null ? _h : 0;
10247
+ const right = (_j = (_i = dp[i]) == null ? void 0 : _i[j + 1]) != null ? _j : 0;
10248
+ if (eq(a[i], b[j])) {
10249
+ pairs.push([i, j]);
10250
+ i++;
10251
+ j++;
10252
+ } else if (down >= right) {
10253
+ i++;
10254
+ } else {
10255
+ j++;
10256
+ }
10257
+ }
10258
+ return pairs;
10259
+ }
10260
+ function computeDiff(oldBlocks, newBlocks) {
10261
+ const result = [];
10262
+ let chunkCounter = 0;
10263
+ const pushChunk = (diffs) => {
10264
+ if (diffs.length > 0) {
10265
+ result.push({
10266
+ id: `chunk-${chunkCounter++}`,
10267
+ diffs,
10268
+ status: "pending"
10269
+ });
10270
+ }
10271
+ };
10272
+ const pairs = lcs(
10273
+ oldBlocks,
10274
+ newBlocks,
10275
+ (a, b) => a.textContent === b.textContent
10276
+ );
10277
+ let oi = 0;
10278
+ let ni = 0;
10279
+ for (const [pi, pj] of pairs) {
10280
+ const gapOld = pi - oi;
10281
+ const gapNew = pj - ni;
10282
+ const gapMax = Math.max(gapOld, gapNew);
10283
+ for (let k = 0; k < gapMax; k++) {
10284
+ const hasOld = oi + k < pi;
10285
+ const hasNew = ni + k < pj;
10286
+ const currentDiffs = [];
10287
+ if (hasOld && hasNew) {
10288
+ const oldNode2 = oldBlocks[oi + k];
10289
+ const newNode2 = newBlocks[ni + k];
10290
+ const changes = Diff.diffWordsWithSpace(
10291
+ oldNode2.textContent,
10292
+ newNode2.textContent
10293
+ );
10294
+ const parts = changes.map((c) => ({
10295
+ type: c.added ? "insert" : c.removed ? "delete" : "equal",
10296
+ value: c.value
10297
+ }));
10298
+ currentDiffs.push({ type: "removed", oldNode: oldNode2, parts });
10299
+ currentDiffs.push({ type: "added", newNode: newNode2, parts });
10300
+ } else if (hasOld) {
10301
+ currentDiffs.push({ type: "removed", oldNode: oldBlocks[oi + k] });
10302
+ } else {
10303
+ currentDiffs.push({ type: "added", newNode: newBlocks[ni + k] });
10304
+ }
10305
+ pushChunk(currentDiffs);
10306
+ }
10307
+ const oldNode = oldBlocks[pi];
10308
+ const newNode = newBlocks[pj];
10309
+ if (oldNode.textContent === newNode.textContent && oldNode.eq(newNode)) {
10310
+ pushChunk([{ type: "unchanged", oldNode, newNode }]);
10311
+ } else {
10312
+ const changes = Diff.diffWordsWithSpace(
10313
+ oldNode.textContent,
10314
+ newNode.textContent
10315
+ );
10316
+ const parts = changes.map((c) => ({
10317
+ type: c.added ? "insert" : c.removed ? "delete" : "equal",
10318
+ value: c.value
10319
+ }));
10320
+ pushChunk([
10321
+ { type: "removed", oldNode, parts },
10322
+ { type: "added", newNode, parts }
10323
+ ]);
10324
+ }
10325
+ oi = pi + 1;
10326
+ ni = pj + 1;
10327
+ }
10328
+ const trailOld = oldBlocks.length - oi;
10329
+ const trailNew = newBlocks.length - ni;
10330
+ const trailMax = Math.max(trailOld, trailNew);
10331
+ for (let k = 0; k < trailMax; k++) {
10332
+ const hasOld = oi + k < oldBlocks.length;
10333
+ const hasNew = ni + k < newBlocks.length;
10334
+ const currentDiffs = [];
10335
+ if (hasOld && hasNew) {
10336
+ const oldNode = oldBlocks[oi + k];
10337
+ const newNode = newBlocks[ni + k];
10338
+ const changes = Diff.diffWordsWithSpace(
10339
+ oldNode.textContent,
10340
+ newNode.textContent
10341
+ );
10342
+ const parts = changes.map((c) => ({
10343
+ type: c.added ? "insert" : c.removed ? "delete" : "equal",
10344
+ value: c.value
10345
+ }));
10346
+ currentDiffs.push({ type: "removed", oldNode, parts });
10347
+ currentDiffs.push({ type: "added", newNode, parts });
10348
+ } else if (hasOld) {
10349
+ currentDiffs.push({ type: "removed", oldNode: oldBlocks[oi + k] });
10350
+ } else {
10351
+ currentDiffs.push({ type: "added", newNode: newBlocks[ni + k] });
10352
+ }
10353
+ pushChunk(currentDiffs);
10354
+ }
10355
+ return result;
10356
+ }
10357
+
10358
+ function buildNewDoc(chunks, schema) {
10359
+ var _a, _b, _c, _d;
10360
+ const children = [];
10361
+ const pending = [];
10362
+ for (const chunk of chunks) {
10363
+ if (chunk.status === "accepted") {
10364
+ for (const diff of chunk.diffs) {
10365
+ if (diff.type === "added") children.push(diff.newNode);
10366
+ if (diff.type === "unchanged") children.push(diff.newNode);
10367
+ }
10368
+ } else if (chunk.status === "rejected") {
10369
+ for (const diff of chunk.diffs) {
10370
+ if (diff.type === "removed") children.push(diff.oldNode);
10371
+ if (diff.type === "unchanged") children.push(diff.oldNode);
10372
+ }
10373
+ } else {
10374
+ for (const diff of chunk.diffs) {
10375
+ if (diff.type === "unchanged") {
10376
+ children.push(diff.newNode);
10377
+ } else if (diff.type === "added") {
10378
+ pending.push({
10379
+ type: "added",
10380
+ childIndex: children.length,
10381
+ oldText: "",
10382
+ newText: (_b = (_a = diff.newNode) == null ? void 0 : _a.textContent) != null ? _b : "",
10383
+ parts: diff.parts,
10384
+ chunkId: chunk.id
10385
+ });
10386
+ children.push(diff.newNode);
10387
+ } else if (diff.type === "removed") {
10388
+ pending.push({
10389
+ type: "removed",
10390
+ childIndex: children.length,
10391
+ oldText: (_d = (_c = diff.oldNode) == null ? void 0 : _c.textContent) != null ? _d : "",
10392
+ newText: "",
10393
+ parts: diff.parts,
10394
+ chunkId: chunk.id
10395
+ });
10396
+ children.push(diff.oldNode);
10397
+ }
10398
+ }
10399
+ }
10400
+ }
10401
+ if (children.length === 0) {
10402
+ children.push(schema.node("paragraph", null, []));
10403
+ }
10404
+ const doc = schema.node("doc", null, children);
10405
+ let pos = 0;
10406
+ const positions = [];
10407
+ for (const child of children) {
10408
+ positions.push({ from: pos, to: pos + child.nodeSize });
10409
+ pos += child.nodeSize;
10410
+ }
10411
+ const changes = pending.map((pc) => {
10412
+ var _a2, _b2;
10413
+ const cp = positions[pc.childIndex];
10414
+ const inlineRanges = [];
10415
+ let offset = cp.from + 1;
10416
+ if (pc.type === "removed") {
10417
+ for (const part of (_a2 = pc.parts) != null ? _a2 : []) {
10418
+ if (part.type === "delete") {
10419
+ inlineRanges.push({ from: offset, to: offset + part.value.length });
10420
+ offset += part.value.length;
10421
+ } else if (part.type === "equal") {
10422
+ offset += part.value.length;
10423
+ }
10424
+ }
10425
+ return {
10426
+ type: "removed",
10427
+ from: cp.from,
10428
+ oldText: pc.oldText,
10429
+ newText: "",
10430
+ blockRange: { from: cp.from, to: cp.to },
10431
+ inlineRanges,
10432
+ chunkId: pc.chunkId
10433
+ };
10434
+ }
10435
+ for (const part of (_b2 = pc.parts) != null ? _b2 : []) {
10436
+ if (part.type === "insert") {
10437
+ inlineRanges.push({ from: offset, to: offset + part.value.length });
10438
+ offset += part.value.length;
10439
+ } else if (part.type === "equal") {
10440
+ offset += part.value.length;
10441
+ }
10442
+ }
10443
+ return {
10444
+ type: "added",
10445
+ from: cp.from,
10446
+ oldText: "",
10447
+ newText: pc.newText,
10448
+ blockRange: { from: cp.from, to: cp.to },
10449
+ inlineRanges,
10450
+ chunkId: pc.chunkId
10451
+ };
10452
+ });
10453
+ return { doc, changes };
10454
+ }
10455
+
10456
+ var __typeError$3 = (msg) => {
10457
+ throw TypeError(msg);
10458
+ };
10459
+ var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
10460
+ var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), member.get(obj));
10461
+ var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10462
+ var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
10463
+ var __privateMethod = (obj, member, method) => (__accessCheck$3(obj, member, "access private method"), method);
10464
+ var _ctx, _view, _isActive, _panelApp, _panelContainer, _resizeObserver, _scrollContainers, _updateGeometry, _originalEditable, _chunks, _schema, _render, _InlineDiffView_instances, scrollTo_fn, createPanel_fn, removePanel_fn;
10465
+ const inlineDiffKey = new PluginKey("CREPE_INLINE_DIFF");
10466
+ const PANEL_WIDTH = 280;
10467
+ let sharedDecorationSet = DecorationSet.empty;
10468
+ class InlineDiffView {
10469
+ constructor(ctx, view) {
10470
+ __privateAdd$3(this, _InlineDiffView_instances);
10471
+ __privateAdd$3(this, _ctx);
10472
+ __privateAdd$3(this, _view);
10473
+ __privateAdd$3(this, _isActive, false);
10474
+ __privateAdd$3(this, _panelApp, null);
10475
+ __privateAdd$3(this, _panelContainer, null);
10476
+ __privateAdd$3(this, _resizeObserver, null);
10477
+ __privateAdd$3(this, _scrollContainers, []);
10478
+ __privateAdd$3(this, _updateGeometry, null);
10479
+ __privateAdd$3(this, _originalEditable, null);
10480
+ __privateAdd$3(this, _chunks, []);
10481
+ __privateAdd$3(this, _schema, null);
10482
+ this.showDiff = (oldMarkdown, newMarkdown) => {
10483
+ if (__privateGet$3(this, _isActive)) return;
10484
+ const parser = __privateGet$3(this, _ctx).get(parserCtx);
10485
+ __privateSet$3(this, _schema, __privateGet$3(this, _view).state.schema);
10486
+ let oldDoc;
10487
+ let newDoc;
10488
+ try {
10489
+ oldDoc = parser(oldMarkdown);
10490
+ if (typeof newMarkdown === "string" && newMarkdown.trim() !== "") {
10491
+ newDoc = parser(newMarkdown);
10492
+ } else {
10493
+ newDoc = __privateGet$3(this, _view).state.doc;
10494
+ }
10495
+ } catch (e) {
10496
+ return;
10497
+ }
10498
+ const oldBlocks = [];
10499
+ const newBlocks = [];
10500
+ oldDoc.forEach((node) => oldBlocks.push(node));
10501
+ newDoc.forEach((node) => newBlocks.push(node));
10502
+ __privateSet$3(this, _chunks, computeDiff(oldBlocks, newBlocks));
10503
+ const { changes } = buildNewDoc(__privateGet$3(this, _chunks), __privateGet$3(this, _schema));
10504
+ if (changes.length === 0) {
10505
+ return;
10506
+ }
10507
+ if (!__privateGet$3(this, _originalEditable)) {
10508
+ __privateSet$3(this, _originalEditable, __privateGet$3(this, _view).someProp("editable") || (() => true));
10509
+ }
10510
+ __privateGet$3(this, _view).setProps({
10511
+ editable: () => false
10512
+ });
10513
+ __privateSet$3(this, _isActive, true);
10514
+ __privateGet$3(this, _render).call(this, true);
10515
+ };
10516
+ __privateAdd$3(this, _render, (initPanel = false) => {
10517
+ const { doc: newDocWithPos, changes } = buildNewDoc(
10518
+ __privateGet$3(this, _chunks),
10519
+ __privateGet$3(this, _schema)
10520
+ );
10521
+ const acceptText = i18n(__privateGet$3(this, _ctx), "inlineDiff.accept");
10522
+ const rejectText = i18n(__privateGet$3(this, _ctx), "inlineDiff.reject");
10523
+ const ds = buildDecorations(
10524
+ newDocWithPos,
10525
+ changes,
10526
+ (id) => this.acceptChunk(id),
10527
+ (id) => this.rejectChunk(id),
10528
+ acceptText,
10529
+ rejectText
10530
+ );
10531
+ sharedDecorationSet = ds;
10532
+ const tr = __privateGet$3(this, _view).state.tr.replaceWith(
10533
+ 0,
10534
+ __privateGet$3(this, _view).state.doc.content.size,
10535
+ newDocWithPos.content
10536
+ );
10537
+ __privateGet$3(this, _view).dispatch(tr);
10538
+ if (initPanel) {
10539
+ __privateMethod(this, _InlineDiffView_instances, createPanel_fn).call(this, changes);
10540
+ } else if (__privateGet$3(this, _panelApp)) {
10541
+ __privateMethod(this, _InlineDiffView_instances, createPanel_fn).call(this, changes);
10542
+ }
10543
+ });
10544
+ this.acceptChunk = (id) => {
10545
+ const chunk = __privateGet$3(this, _chunks).find((c) => c.id === id);
10546
+ if (chunk) {
10547
+ chunk.status = "accepted";
10548
+ const hasPending = __privateGet$3(this, _chunks).some(
10549
+ (c) => c.status === "pending" && c.diffs.some((d) => d.type !== "unchanged")
10550
+ );
10551
+ if (!hasPending) {
10552
+ this.hideDiff();
10553
+ } else {
10554
+ __privateGet$3(this, _render).call(this);
10555
+ }
10556
+ }
10557
+ };
10558
+ this.rejectChunk = (id) => {
10559
+ const chunk = __privateGet$3(this, _chunks).find((c) => c.id === id);
10560
+ if (chunk) {
10561
+ chunk.status = "rejected";
10562
+ const hasPending = __privateGet$3(this, _chunks).some(
10563
+ (c) => c.status === "pending" && c.diffs.some((d) => d.type !== "unchanged")
10564
+ );
10565
+ if (!hasPending) {
10566
+ this.hideDiff();
10567
+ } else {
10568
+ __privateGet$3(this, _render).call(this);
10569
+ }
10570
+ }
10571
+ };
10572
+ this.hideDiff = () => {
10573
+ if (!__privateGet$3(this, _isActive)) return;
10574
+ __privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
10575
+ for (const chunk of __privateGet$3(this, _chunks)) {
10576
+ if (chunk.status === "pending") {
10577
+ chunk.status = "accepted";
10578
+ }
10579
+ }
10580
+ const { doc: finalDoc } = buildNewDoc(__privateGet$3(this, _chunks), __privateGet$3(this, _schema));
10581
+ const tr = __privateGet$3(this, _view).state.tr.replaceWith(
10582
+ 0,
10583
+ __privateGet$3(this, _view).state.doc.content.size,
10584
+ finalDoc.content
10585
+ );
10586
+ sharedDecorationSet = DecorationSet.empty;
10587
+ __privateSet$3(this, _isActive, false);
10588
+ __privateSet$3(this, _chunks, []);
10589
+ __privateGet$3(this, _view).dispatch(tr);
10590
+ if (__privateGet$3(this, _originalEditable)) {
10591
+ __privateGet$3(this, _view).setProps({
10592
+ editable: __privateGet$3(this, _originalEditable)
10593
+ });
10594
+ __privateSet$3(this, _originalEditable, null);
10595
+ } else {
10596
+ __privateGet$3(this, _view).setProps({
10597
+ editable: () => true
10598
+ });
10599
+ }
10600
+ };
10601
+ this.update = (view) => {
10602
+ __privateSet$3(this, _view, view);
10603
+ };
10604
+ this.destroy = () => {
10605
+ __privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
10606
+ };
10607
+ __privateSet$3(this, _ctx, ctx);
10608
+ __privateSet$3(this, _view, view);
10609
+ const api = {
10610
+ showDiff: (oldMd, newMd) => this.showDiff(oldMd, newMd),
10611
+ hideDiff: () => this.hideDiff(),
10612
+ isShowing: () => __privateGet$3(this, _isActive)
10613
+ };
10614
+ ctx.set(inlineDiffApiCtx.key, api);
10615
+ }
10616
+ }
10617
+ _ctx = new WeakMap();
10618
+ _view = new WeakMap();
10619
+ _isActive = new WeakMap();
10620
+ _panelApp = new WeakMap();
10621
+ _panelContainer = new WeakMap();
10622
+ _resizeObserver = new WeakMap();
10623
+ _scrollContainers = new WeakMap();
10624
+ _updateGeometry = new WeakMap();
10625
+ _originalEditable = new WeakMap();
10626
+ _chunks = new WeakMap();
10627
+ _schema = new WeakMap();
10628
+ _render = new WeakMap();
10629
+ _InlineDiffView_instances = new WeakSet();
10630
+ scrollTo_fn = function(pos) {
10631
+ try {
10632
+ const view = __privateGet$3(this, _view);
10633
+ const coords = view.coordsAtPos(pos);
10634
+ let scrollTarget = view.dom;
10635
+ while (scrollTarget) {
10636
+ const { overflowY } = getComputedStyle(scrollTarget);
10637
+ if ((overflowY === "auto" || overflowY === "scroll") && scrollTarget.scrollHeight > scrollTarget.clientHeight) {
10638
+ break;
10639
+ }
10640
+ scrollTarget = scrollTarget.parentElement;
10641
+ }
10642
+ if (scrollTarget) {
10643
+ const targetRect = scrollTarget.getBoundingClientRect();
10644
+ const scrollOffset = coords.top - targetRect.top + scrollTarget.scrollTop - 60;
10645
+ scrollTarget.scrollTo({ top: scrollOffset, behavior: "smooth" });
10646
+ } else {
10647
+ window.scrollTo({
10648
+ top: coords.top + window.scrollY - 100,
10649
+ behavior: "smooth"
10650
+ });
10651
+ }
10652
+ } catch (e) {
10653
+ }
10654
+ };
10655
+ createPanel_fn = function(changes) {
10656
+ __privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
10657
+ const editorContainer = __privateGet$3(this, _view).dom.parentElement;
10658
+ if (!editorContainer) return;
10659
+ const root = editorContainer.parentElement;
10660
+ if (!root) return;
10661
+ const container = document.createElement("div");
10662
+ container.style.position = "fixed";
10663
+ container.style.zIndex = "100";
10664
+ container.style.width = `${PANEL_WIDTH}px`;
10665
+ container.style.overflow = "hidden";
10666
+ container.style.borderLeft = "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))";
10667
+ container.style.backgroundColor = "var(--crepe-color-surface, #fff)";
10668
+ root.appendChild(container);
10669
+ __privateSet$3(this, _panelContainer, container);
10670
+ editorContainer.style.paddingRight = `${PANEL_WIDTH}px`;
10671
+ __privateSet$3(this, _panelApp, mountChangePanel(
10672
+ container,
10673
+ changes,
10674
+ (from) => __privateMethod(this, _InlineDiffView_instances, scrollTo_fn).call(this, from),
10675
+ () => this.hideDiff()
10676
+ ));
10677
+ __privateSet$3(this, _updateGeometry, () => {
10678
+ const rootRect = root.getBoundingClientRect();
10679
+ let top = rootRect.top;
10680
+ const toolbar = root.querySelector(
10681
+ ".milkdown-fixed-toolbar"
10682
+ );
10683
+ if (toolbar && toolbar.offsetHeight > 0) {
10684
+ const toolbarRect = toolbar.getBoundingClientRect();
10685
+ top = Math.max(top, toolbarRect.bottom);
10686
+ }
10687
+ const coverEl = root.querySelector(
10688
+ ".milkdown-document-cover"
10689
+ );
10690
+ if (coverEl && coverEl.offsetHeight > 0) {
10691
+ top = Math.max(top, coverEl.getBoundingClientRect().bottom);
10692
+ }
10693
+ let height = window.innerHeight - top;
10694
+ if (top + height > rootRect.bottom) {
10695
+ height = Math.max(0, rootRect.bottom - top);
10696
+ }
10697
+ container.style.top = `${top}px`;
10698
+ container.style.height = `${height}px`;
10699
+ container.style.left = "auto";
10700
+ let baseOffset = window.innerWidth - rootRect.right;
10701
+ let rightOffset = baseOffset;
10702
+ let hasVScroll = false;
10703
+ if (document.documentElement.scrollHeight > window.innerHeight) {
10704
+ hasVScroll = true;
10705
+ }
10706
+ let parent = root;
10707
+ while (parent && parent !== document.body) {
10708
+ const { overflowY } = getComputedStyle(parent);
10709
+ if (overflowY === "auto" || overflowY === "scroll") {
10710
+ if (parent.scrollHeight > parent.clientHeight) {
10711
+ hasVScroll = true;
10712
+ break;
10713
+ }
10714
+ }
10715
+ parent = parent.parentElement;
10716
+ }
10717
+ if (hasVScroll) {
10718
+ rightOffset = Math.max(rightOffset, 32);
10719
+ } else {
10720
+ rightOffset = Math.max(rightOffset, 0);
10721
+ }
10722
+ container.style.right = `${rightOffset}px`;
10723
+ editorContainer.style.paddingRight = `${PANEL_WIDTH}px`;
10724
+ });
10725
+ __privateGet$3(this, _updateGeometry).call(this);
10726
+ setTimeout(() => {
10727
+ var _a;
10728
+ (_a = __privateGet$3(this, _updateGeometry)) == null ? void 0 : _a.call(this);
10729
+ }, 100);
10730
+ __privateSet$3(this, _resizeObserver, new ResizeObserver(__privateGet$3(this, _updateGeometry)));
10731
+ __privateGet$3(this, _resizeObserver).observe(root);
10732
+ window.addEventListener("resize", __privateGet$3(this, _updateGeometry));
10733
+ window.addEventListener("scroll", __privateGet$3(this, _updateGeometry), {
10734
+ capture: true,
10735
+ passive: true
10736
+ });
10737
+ let scrollerNode = root;
10738
+ while (scrollerNode && scrollerNode !== document) {
10739
+ if (scrollerNode instanceof Element) {
10740
+ scrollerNode.addEventListener("scroll", __privateGet$3(this, _updateGeometry), {
10741
+ passive: true
10742
+ });
10743
+ __privateGet$3(this, _scrollContainers).push(scrollerNode);
10744
+ }
10745
+ scrollerNode = scrollerNode.parentNode || scrollerNode.host;
10746
+ }
10747
+ };
10748
+ removePanel_fn = function() {
10749
+ if (__privateGet$3(this, _panelApp)) {
10750
+ __privateGet$3(this, _panelApp).unmount();
10751
+ __privateSet$3(this, _panelApp, null);
10752
+ }
10753
+ if (__privateGet$3(this, _panelContainer)) {
10754
+ __privateGet$3(this, _panelContainer).remove();
10755
+ __privateSet$3(this, _panelContainer, null);
10756
+ }
10757
+ if (__privateGet$3(this, _resizeObserver)) {
10758
+ __privateGet$3(this, _resizeObserver).disconnect();
10759
+ __privateSet$3(this, _resizeObserver, null);
10760
+ }
10761
+ if (__privateGet$3(this, _updateGeometry)) {
10762
+ window.removeEventListener("resize", __privateGet$3(this, _updateGeometry));
10763
+ window.removeEventListener("scroll", __privateGet$3(this, _updateGeometry), {
10764
+ capture: true
10765
+ });
10766
+ for (const container of __privateGet$3(this, _scrollContainers)) {
10767
+ container.removeEventListener("scroll", __privateGet$3(this, _updateGeometry));
10768
+ }
10769
+ __privateSet$3(this, _scrollContainers, []);
10770
+ __privateSet$3(this, _updateGeometry, null);
10771
+ }
10772
+ const editorContainer = __privateGet$3(this, _view).dom.parentElement;
10773
+ if (editorContainer) {
10774
+ editorContainer.style.paddingRight = "";
10775
+ }
10776
+ };
10777
+ function buildDecorations(doc, changes, onAccept, onReject, acceptText, rejectText) {
10778
+ const decorations = [];
10779
+ const addedWidgets = /* @__PURE__ */ new Set();
10780
+ for (const change of changes) {
10781
+ if (!addedWidgets.has(change.chunkId)) {
10782
+ addedWidgets.add(change.chunkId);
10783
+ decorations.push(
10784
+ Decoration.widget(
10785
+ change.blockRange.from,
10786
+ () => {
10787
+ const wrapper = document.createElement("div");
10788
+ wrapper.style.position = "relative";
10789
+ wrapper.style.width = "100%";
10790
+ wrapper.style.height = "0";
10791
+ wrapper.style.overflow = "visible";
10792
+ const container = document.createElement("div");
10793
+ container.className = "crepe-diff-actions";
10794
+ container.style.position = "absolute";
10795
+ container.style.right = "4px";
10796
+ container.style.top = "4px";
10797
+ container.style.zIndex = "10";
10798
+ container.style.display = "flex";
10799
+ container.style.gap = "4px";
10800
+ const btnAccept = document.createElement("button");
10801
+ btnAccept.textContent = acceptText;
10802
+ btnAccept.style.backgroundColor = "#2ea043";
10803
+ btnAccept.style.color = "white";
10804
+ btnAccept.style.border = "none";
10805
+ btnAccept.style.borderRadius = "4px";
10806
+ btnAccept.style.padding = "2px 8px";
10807
+ btnAccept.style.cursor = "pointer";
10808
+ btnAccept.style.fontSize = "12px";
10809
+ btnAccept.addEventListener("mousedown", (e) => {
10810
+ e.preventDefault();
10811
+ onAccept(change.chunkId);
10812
+ });
10813
+ const btnReject = document.createElement("button");
10814
+ btnReject.textContent = rejectText;
10815
+ btnReject.style.backgroundColor = "#f85149";
10816
+ btnReject.style.color = "white";
10817
+ btnReject.style.border = "none";
10818
+ btnReject.style.borderRadius = "4px";
10819
+ btnReject.style.padding = "2px 8px";
10820
+ btnReject.style.cursor = "pointer";
10821
+ btnReject.style.fontSize = "12px";
10822
+ btnReject.addEventListener("mousedown", (e) => {
10823
+ e.preventDefault();
10824
+ onReject(change.chunkId);
10825
+ });
10826
+ container.appendChild(btnAccept);
10827
+ container.appendChild(btnReject);
10828
+ wrapper.appendChild(container);
10829
+ return wrapper;
10830
+ },
10831
+ { side: -1 }
10832
+ )
10833
+ );
10834
+ }
10835
+ const blockCls = change.type === "added" ? "crepe-diff-added" : "crepe-diff-deleted";
10836
+ decorations.push(
10837
+ Decoration.node(change.blockRange.from, change.blockRange.to, {
10838
+ class: blockCls
10839
+ })
10840
+ );
10841
+ const inlineCls = change.type === "added" ? "crepe-diff-inline-added" : "crepe-diff-inline-deleted";
10842
+ for (const r of change.inlineRanges) {
10843
+ if (r.to > r.from) {
10844
+ decorations.push(Decoration.inline(r.from, r.to, { class: inlineCls }));
10845
+ }
10846
+ }
10847
+ }
10848
+ return DecorationSet.create(doc, decorations);
10849
+ }
10850
+ const inlineDiffPlugin = $prose((ctx) => {
10851
+ return new Plugin({
10852
+ key: inlineDiffKey,
10853
+ view: (view) => new InlineDiffView(ctx, view),
10854
+ props: {
10855
+ decorations: () => sharedDecorationSet
10856
+ }
10857
+ });
10858
+ });
10859
+ const inlineDiff = (editor, config) => {
10860
+ editor.config(crepeFeatureConfig(CrepeFeature.InlineDiff)).config((ctx) => {
10861
+ if (config) {
10862
+ ctx.update(inlineDiffConfig.key, (prev) => ({
10863
+ ...prev,
10864
+ ...config
10865
+ }));
10866
+ }
10867
+ }).use(inlineDiffApiCtx).use(inlineDiffConfig).use(inlineDiffPlugin);
10868
+ };
10869
+
9891
10870
  const blockLatexSchema = codeBlockSchema.extendSchema((prev) => {
9892
10871
  return (ctx) => {
9893
10872
  const baseSchema = prev(ctx);
@@ -10526,6 +11505,12 @@ function loadFeature(feature, editor, config) {
10526
11505
  case CrepeFeature.Attachment: {
10527
11506
  return attachment(editor, config);
10528
11507
  }
11508
+ case CrepeFeature.InlineDiff: {
11509
+ return inlineDiff(editor, config);
11510
+ }
11511
+ case CrepeFeature.DiffBlock: {
11512
+ return diffBlockFeature(editor, config);
11513
+ }
10529
11514
  }
10530
11515
  }
10531
11516
 
@@ -10582,6 +11567,22 @@ class CrepeBuilder {
10582
11567
  this.getMarkdown = () => {
10583
11568
  return __privateGet(this, _editor).action(getMarkdown());
10584
11569
  };
11570
+ /// Show inline diff between two markdown versions.
11571
+ this.showDiff = (oldMarkdown, newMarkdown) => {
11572
+ __privateGet(this, _editor).action((ctx) => {
11573
+ const api = ctx.get(inlineDiffApiCtx.key);
11574
+ api.showDiff(oldMarkdown, newMarkdown);
11575
+ });
11576
+ return this;
11577
+ };
11578
+ /// Hide inline diff and return to editing mode.
11579
+ this.hideDiff = () => {
11580
+ __privateGet(this, _editor).action((ctx) => {
11581
+ const api = ctx.get(inlineDiffApiCtx.key);
11582
+ api.hideDiff();
11583
+ });
11584
+ return this;
11585
+ };
10585
11586
  /// Register event listeners.
10586
11587
  this.on = (fn) => {
10587
11588
  if (__privateGet(this, _editor).status !== EditorStatus.Created) {