@jvs-milkdown/crepe 1.2.13 → 1.2.15

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