@jvs-milkdown/crepe 1.2.12 → 1.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) 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 +10 -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 +10 -3
  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 +10 -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 +10 -2
  22. package/lib/cjs/feature/table/index.js.map +1 -1
  23. package/lib/cjs/feature/toolbar/index.js +134 -12
  24. package/lib/cjs/feature/toolbar/index.js.map +1 -1
  25. package/lib/cjs/index.js +1410 -241
  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 +10 -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 +10 -3
  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 +10 -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 +10 -2
  48. package/lib/esm/feature/table/index.js.map +1 -1
  49. package/lib/esm/feature/toolbar/index.js +134 -12
  50. package/lib/esm/feature/toolbar/index.js.map +1 -1
  51. package/lib/esm/index.js +1392 -242
  52. package/lib/esm/index.js.map +1 -1
  53. package/lib/theme/common/diff-block.css +41 -0
  54. package/lib/theme/common/inline-diff.css +142 -0
  55. package/lib/theme/common/style.css +2 -0
  56. package/lib/theme/common/table.css +4 -4
  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/document-header.d.ts.map +1 -1
  65. package/lib/types/feature/fixed-toolbar/index.d.ts.map +1 -1
  66. package/lib/types/feature/fixed-toolbar/menu-bar.d.ts.map +1 -1
  67. package/lib/types/feature/fixed-toolbar/outline-panel.d.ts.map +1 -1
  68. package/lib/types/feature/index.d.ts +7 -1
  69. package/lib/types/feature/index.d.ts.map +1 -1
  70. package/lib/types/feature/inline-diff/change-panel.d.ts +4 -0
  71. package/lib/types/feature/inline-diff/change-panel.d.ts.map +1 -0
  72. package/lib/types/feature/inline-diff/config.d.ts +12 -0
  73. package/lib/types/feature/inline-diff/config.d.ts.map +1 -0
  74. package/lib/types/feature/inline-diff/diff-engine.d.ts +20 -0
  75. package/lib/types/feature/inline-diff/diff-engine.d.ts.map +1 -0
  76. package/lib/types/feature/inline-diff/diff-view.d.ts +2 -0
  77. package/lib/types/feature/inline-diff/diff-view.d.ts.map +1 -0
  78. package/lib/types/feature/inline-diff/doc-builder.d.ts +21 -0
  79. package/lib/types/feature/inline-diff/doc-builder.d.ts.map +1 -0
  80. package/lib/types/feature/inline-diff/index.d.ts +9 -0
  81. package/lib/types/feature/inline-diff/index.d.ts.map +1 -0
  82. package/lib/types/feature/loader.d.ts.map +1 -1
  83. package/lib/types/feature/toolbar/component.d.ts.map +1 -1
  84. package/lib/types/feature/toolbar/index.d.ts.map +1 -1
  85. package/lib/types/icons/remove.d.ts +1 -1
  86. package/lib/types/icons/remove.d.ts.map +1 -1
  87. package/lib/types/utils/fixed-toolbar-popup-state.d.ts +7 -0
  88. package/lib/types/utils/fixed-toolbar-popup-state.d.ts.map +1 -0
  89. package/package.json +15 -4
  90. package/src/core/builder.ts +19 -0
  91. package/src/core/locale.ts +7 -0
  92. package/src/feature/diff-block/index.ts +48 -0
  93. package/src/feature/fixed-toolbar/index.ts +97 -25
  94. package/src/feature/fixed-toolbar/menu-bar.tsx +13 -2
  95. package/src/feature/fixed-toolbar/outline-panel.tsx +3 -2
  96. package/src/feature/fixed-toolbar/shortcut-help-modal.tsx +1 -1
  97. package/src/feature/fixed-toolbar/view-menu-state.ts +1 -1
  98. package/src/feature/image-block/index.ts +1 -1
  99. package/src/feature/index.ts +12 -0
  100. package/src/feature/inline-diff/change-panel.ts +280 -0
  101. package/src/feature/inline-diff/config.ts +28 -0
  102. package/src/feature/inline-diff/diff-engine.ts +181 -0
  103. package/src/feature/inline-diff/diff-view.ts +2 -0
  104. package/src/feature/inline-diff/doc-builder.ts +139 -0
  105. package/src/feature/inline-diff/index.ts +514 -0
  106. package/src/feature/loader.ts +8 -0
  107. package/src/feature/toolbar/component.tsx +97 -9
  108. package/src/feature/toolbar/index.ts +33 -0
  109. package/src/icons/remove.ts +1 -0
  110. package/src/theme/common/diff-block.css +43 -0
  111. package/src/theme/common/inline-diff.css +148 -0
  112. package/src/theme/common/style.css +2 -0
  113. package/src/theme/common/table.css +4 -4
  114. package/src/utils/fixed-toolbar-popup-state.ts +27 -0
package/lib/cjs/index.js CHANGED
@@ -26,6 +26,7 @@ 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');
29
30
  var tables = require('@jvs-milkdown/kit/prose/tables');
30
31
  var clsx = require('clsx');
31
32
  var linkTooltip$1 = require('@jvs-milkdown/kit/component/link-tooltip');
@@ -33,6 +34,7 @@ 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 = `
@@ -441,6 +466,7 @@ const removeIcon = `
441
466
  >
442
467
  <path
443
468
  d="M7.30775 20.4997C6.81058 20.4997 6.385 20.3227 6.031 19.9687C5.677 19.6147 5.5 19.1892 5.5 18.692V5.99973H5.25C5.0375 5.99973 4.85942 5.92782 4.71575 5.78398C4.57192 5.64015 4.5 5.46198 4.5 5.24948C4.5 5.03682 4.57192 4.85873 4.71575 4.71523C4.85942 4.57157 5.0375 4.49973 5.25 4.49973H9C9 4.2549 9.08625 4.04624 9.25875 3.87374C9.43108 3.7014 9.63967 3.61523 9.8845 3.61523H14.1155C14.3603 3.61523 14.5689 3.7014 14.7413 3.87374C14.9138 4.04624 15 4.2549 15 4.49973H18.75C18.9625 4.49973 19.1406 4.57165 19.2843 4.71548C19.4281 4.85932 19.5 5.03748 19.5 5.24998C19.5 5.46265 19.4281 5.64073 19.2843 5.78423C19.1406 5.9279 18.9625 5.99973 18.75 5.99973H18.5V18.692C18.5 19.1892 18.323 19.6147 17.969 19.9687C17.615 20.3227 17.1894 20.4997 16.6923 20.4997H7.30775ZM17 5.99973H7V18.692C7 18.7818 7.02883 18.8556 7.0865 18.9132C7.14417 18.9709 7.21792 18.9997 7.30775 18.9997H16.6923C16.7821 18.9997 16.8558 18.9709 16.9135 18.9132C16.9712 18.8556 17 18.7818 17 18.692V5.99973ZM10.1543 16.9997C10.3668 16.9997 10.5448 16.9279 10.6885 16.7842C10.832 16.6404 10.9037 16.4622 10.9037 16.2497V8.74973C10.9037 8.53723 10.8318 8.35907 10.688 8.21523C10.5443 8.07157 10.3662 7.99973 10.1535 7.99973C9.941 7.99973 9.76292 8.07157 9.61925 8.21523C9.47575 8.35907 9.404 8.53723 9.404 8.74973V16.2497C9.404 16.4622 9.47583 16.6404 9.6195 16.7842C9.76333 16.9279 9.94158 16.9997 10.1543 16.9997ZM13.8465 16.9997C14.059 16.9997 14.2371 16.9279 14.3807 16.7842C14.5243 16.6404 14.596 16.4622 14.596 16.2497V8.74973C14.596 8.53723 14.5242 8.35907 14.3805 8.21523C14.2367 8.07157 14.0584 7.99973 13.8458 7.99973C13.6333 7.99973 13.4552 8.07157 13.3115 8.21523C13.168 8.35907 13.0962 8.53723 13.0962 8.74973V16.2497C13.0962 16.4622 13.1682 16.6404 13.312 16.7842C13.4557 16.9279 13.6338 16.9997 13.8465 16.9997Z"
469
+ fill="#363B4C"
444
470
  />
445
471
  </svg>
446
472
  `;
@@ -810,7 +836,10 @@ const zhCN = {
810
836
  "shortcuts.hardBreak": "\u6362\u884C",
811
837
  "shortcuts.history": "\u5386\u53F2\u8BB0\u5F55",
812
838
  "shortcuts.undo": "\u64A4\u9500",
813
- "shortcuts.redo": "\u91CD\u505A"
839
+ "shortcuts.redo": "\u91CD\u505A",
840
+ // inline-diff
841
+ "inlineDiff.accept": "\u63A5\u53D7",
842
+ "inlineDiff.reject": "\u62D2\u7EDD"
814
843
  };
815
844
  const enUS = {
816
845
  "handle.add": "Add content",
@@ -952,7 +981,9 @@ const enUS = {
952
981
  "shortcuts.hardBreak": "Hard Break",
953
982
  "shortcuts.history": "History",
954
983
  "shortcuts.undo": "Undo",
955
- "shortcuts.redo": "Redo"
984
+ "shortcuts.redo": "Redo",
985
+ "inlineDiff.accept": "Accept",
986
+ "inlineDiff.reject": "Reject"
956
987
  };
957
988
  const translationsCtx = ctx.createSlice(
958
989
  {
@@ -1389,22 +1420,22 @@ function isInList(selection) {
1389
1420
  return (type == null ? void 0 : type.name) === "list_item";
1390
1421
  }
1391
1422
 
1392
- var __typeError$6 = (msg) => {
1423
+ var __typeError$7 = (msg) => {
1393
1424
  throw TypeError(msg);
1394
1425
  };
1395
- var __accessCheck$6 = (obj, member, msg) => member.has(obj) || __typeError$6("Cannot " + msg);
1396
- var __privateGet$6 = (obj, member, getter) => (__accessCheck$6(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1397
- 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);
1398
- 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);
1399
1430
  var _groups, _getGroupInstance;
1400
1431
  class GroupBuilder {
1401
1432
  constructor() {
1402
- __privateAdd$6(this, _groups, []);
1433
+ __privateAdd$7(this, _groups, []);
1403
1434
  this.clear = () => {
1404
- __privateSet$6(this, _groups, []);
1435
+ __privateSet$7(this, _groups, []);
1405
1436
  return this;
1406
1437
  };
1407
- __privateAdd$6(this, _getGroupInstance, (group) => {
1438
+ __privateAdd$7(this, _getGroupInstance, (group) => {
1408
1439
  const groupInstance = {
1409
1440
  group,
1410
1441
  addItem: (key, item) => {
@@ -1426,16 +1457,16 @@ class GroupBuilder {
1426
1457
  label,
1427
1458
  items
1428
1459
  };
1429
- __privateGet$6(this, _groups).push(group);
1430
- return __privateGet$6(this, _getGroupInstance).call(this, group);
1460
+ __privateGet$7(this, _groups).push(group);
1461
+ return __privateGet$7(this, _getGroupInstance).call(this, group);
1431
1462
  };
1432
1463
  this.getGroup = (key) => {
1433
- const group = __privateGet$6(this, _groups).find((group2) => group2.key === key);
1464
+ const group = __privateGet$7(this, _groups).find((group2) => group2.key === key);
1434
1465
  if (!group) throw new Error(`Group with key ${key} not found`);
1435
- return __privateGet$6(this, _getGroupInstance).call(this, group);
1466
+ return __privateGet$7(this, _getGroupInstance).call(this, group);
1436
1467
  };
1437
1468
  this.build = () => {
1438
- return __privateGet$6(this, _groups);
1469
+ return __privateGet$7(this, _groups);
1439
1470
  };
1440
1471
  }
1441
1472
  }
@@ -3587,14 +3618,14 @@ const Menu = vue.defineComponent({
3587
3618
  }
3588
3619
  });
3589
3620
 
3590
- var __typeError$5 = (msg) => {
3621
+ var __typeError$6 = (msg) => {
3591
3622
  throw TypeError(msg);
3592
3623
  };
3593
- var __accessCheck$5 = (obj, member, msg) => member.has(obj) || __typeError$5("Cannot " + msg);
3594
- var __privateGet$5 = (obj, member, getter) => (__accessCheck$5(obj, member, "read from private field"), member.get(obj));
3595
- 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);
3596
- var __privateSet$5 = (obj, member, value, setter) => (__accessCheck$5(obj, member, "write to private field"), member.set(obj, value), value);
3597
- 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;
3598
3629
  const menu = slash.slashFactory("CREPE_MENU");
3599
3630
  function configureMenu(ctx, config) {
3600
3631
  ctx.set(menu.key, {
@@ -3603,50 +3634,50 @@ function configureMenu(ctx, config) {
3603
3634
  }
3604
3635
  class MenuView {
3605
3636
  constructor(ctx, view, config) {
3606
- __privateAdd$5(this, _content$4);
3607
- __privateAdd$5(this, _app$4);
3608
- __privateAdd$5(this, _filter);
3609
- __privateAdd$5(this, _slashProvider);
3610
- __privateAdd$5(this, _activeKey);
3611
- __privateAdd$5(this, _view$1);
3612
- __privateAdd$5(this, _programmaticallyPos, null);
3613
- __privateAdd$5(this, _mode, null);
3614
- __privateAdd$5(this, _hideTimeout);
3615
- __privateAdd$5(this, _isMenuHovered, false);
3616
- __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);
3617
3648
  this.onHoverDelayHide = () => {
3618
- window.clearTimeout(__privateGet$5(this, _hideTimeout));
3619
- __privateSet$5(this, _hideTimeout, window.setTimeout(() => {
3620
- 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) {
3621
3652
  this.hide();
3622
3653
  }
3623
3654
  }, 150));
3624
3655
  };
3625
3656
  this.cancelHide = () => {
3626
- window.clearTimeout(__privateGet$5(this, _hideTimeout));
3657
+ window.clearTimeout(__privateGet$6(this, _hideTimeout));
3627
3658
  };
3628
3659
  this.update = (view) => {
3629
- __privateGet$5(this, _slashProvider).update(view);
3660
+ __privateGet$6(this, _slashProvider).update(view);
3630
3661
  };
3631
3662
  this.show = (pos, isClick = false, triggerElement, mode = "block") => {
3632
3663
  if (isClick) {
3633
- __privateSet$5(this, _keepOpenUntilClickOutside, true);
3664
+ __privateSet$6(this, _keepOpenUntilClickOutside, true);
3634
3665
  } else {
3635
- __privateSet$5(this, _keepOpenUntilClickOutside, false);
3666
+ __privateSet$6(this, _keepOpenUntilClickOutside, false);
3636
3667
  }
3637
- __privateSet$5(this, _programmaticallyPos, pos);
3638
- __privateSet$5(this, _mode, mode);
3639
- __privateGet$5(this, _filter).value = "";
3640
- 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);
3641
3672
  if (node) {
3642
- __privateGet$5(this, _activeKey).value = getBlockKey(node);
3673
+ __privateGet$6(this, _activeKey).value = getBlockKey(node);
3643
3674
  } else {
3644
- __privateGet$5(this, _activeKey).value = "text";
3675
+ __privateGet$6(this, _activeKey).value = "text";
3645
3676
  }
3646
- __privateGet$5(this, _slashProvider).show();
3647
- __privateGet$5(this, _content$4).dataset.mode = mode;
3677
+ __privateGet$6(this, _slashProvider).show();
3678
+ __privateGet$6(this, _content$4).dataset.mode = mode;
3648
3679
  if (triggerElement) {
3649
- void dom.computePosition(triggerElement, __privateGet$5(this, _content$4), {
3680
+ void dom.computePosition(triggerElement, __privateGet$6(this, _content$4), {
3650
3681
  placement: "bottom-start",
3651
3682
  middleware: [
3652
3683
  dom.flip(),
@@ -3667,7 +3698,7 @@ class MenuView {
3667
3698
  })
3668
3699
  ]
3669
3700
  }).then(({ x, y }) => {
3670
- Object.assign(__privateGet$5(this, _content$4).style, {
3701
+ Object.assign(__privateGet$6(this, _content$4).style, {
3671
3702
  left: `${x}px`,
3672
3703
  top: `${y}px`
3673
3704
  });
@@ -3675,25 +3706,25 @@ class MenuView {
3675
3706
  }
3676
3707
  };
3677
3708
  this.hide = () => {
3678
- __privateSet$5(this, _programmaticallyPos, null);
3679
- __privateSet$5(this, _mode, null);
3680
- __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");
3681
3712
  this.cancelHide();
3682
- __privateGet$5(this, _slashProvider).hide();
3713
+ __privateGet$6(this, _slashProvider).hide();
3683
3714
  };
3684
3715
  this.destroy = () => {
3685
- __privateGet$5(this, _slashProvider).destroy();
3686
- __privateGet$5(this, _app$4).unmount();
3687
- __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();
3688
3719
  };
3689
- __privateSet$5(this, _view$1, view);
3720
+ __privateSet$6(this, _view$2, view);
3690
3721
  const content = document.createElement("div");
3691
3722
  content.classList.add("milkdown-slash-menu");
3692
3723
  const show = vue.ref(false);
3693
3724
  const filter = vue.ref("");
3694
- __privateSet$5(this, _filter, filter);
3725
+ __privateSet$6(this, _filter, filter);
3695
3726
  const activeKey = vue.ref("text");
3696
- __privateSet$5(this, _activeKey, activeKey);
3727
+ __privateSet$6(this, _activeKey, activeKey);
3697
3728
  const hide = this.hide;
3698
3729
  const app = vue.createApp(Menu, {
3699
3730
  ctx,
@@ -3703,20 +3734,20 @@ class MenuView {
3703
3734
  hide,
3704
3735
  activeKey
3705
3736
  });
3706
- __privateSet$5(this, _app$4, app);
3737
+ __privateSet$6(this, _app$4, app);
3707
3738
  app.mount(content);
3708
- __privateSet$5(this, _content$4, content);
3709
- __privateGet$5(this, _content$4).addEventListener("pointerenter", () => {
3710
- __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);
3711
3742
  this.cancelHide();
3712
3743
  });
3713
- __privateGet$5(this, _content$4).addEventListener("pointerleave", () => {
3714
- __privateSet$5(this, _isMenuHovered, false);
3744
+ __privateGet$6(this, _content$4).addEventListener("pointerleave", () => {
3745
+ __privateSet$6(this, _isMenuHovered, false);
3715
3746
  this.onHoverDelayHide();
3716
3747
  });
3717
3748
  const self = this;
3718
- __privateSet$5(this, _slashProvider, new slash.SlashProvider({
3719
- content: __privateGet$5(this, _content$4),
3749
+ __privateSet$6(this, _slashProvider, new slash.SlashProvider({
3750
+ content: __privateGet$6(this, _content$4),
3720
3751
  debounce: 20,
3721
3752
  shouldShow(view2) {
3722
3753
  if (isInCodeBlock(view2.state.selection) || isInList(view2.state.selection))
@@ -3729,13 +3760,13 @@ class MenuView {
3729
3760
  if (!isSelectionAtEndOfNode(view2.state.selection)) {
3730
3761
  return false;
3731
3762
  }
3732
- const pos = __privateGet$5(self, _programmaticallyPos);
3763
+ const pos = __privateGet$6(self, _programmaticallyPos);
3733
3764
  filter.value = currentText.startsWith("/") ? currentText.slice(1) : currentText;
3734
3765
  if (typeof pos === "number") {
3735
3766
  const maxSize = view2.state.doc.nodeSize - 2;
3736
3767
  const validPos = Math.min(pos, maxSize);
3737
3768
  if (view2.state.doc.resolve(validPos).node() !== view2.state.doc.resolve(view2.state.selection.from).node()) {
3738
- __privateSet$5(self, _programmaticallyPos, null);
3769
+ __privateSet$6(self, _programmaticallyPos, null);
3739
3770
  return false;
3740
3771
  }
3741
3772
  return true;
@@ -3745,12 +3776,12 @@ class MenuView {
3745
3776
  },
3746
3777
  offset: 10
3747
3778
  }));
3748
- __privateGet$5(this, _slashProvider).onShow = () => {
3779
+ __privateGet$6(this, _slashProvider).onShow = () => {
3749
3780
  show.value = true;
3750
3781
  };
3751
- __privateGet$5(this, _slashProvider).onHide = () => {
3782
+ __privateGet$6(this, _slashProvider).onHide = () => {
3752
3783
  show.value = false;
3753
- __privateSet$5(this, _keepOpenUntilClickOutside, false);
3784
+ __privateSet$6(this, _keepOpenUntilClickOutside, false);
3754
3785
  };
3755
3786
  this.update(view);
3756
3787
  ctx.set(menuAPI.key, {
@@ -3761,10 +3792,10 @@ class MenuView {
3761
3792
  hide: () => this.hide(),
3762
3793
  onHoverDelayHide: () => this.onHoverDelayHide(),
3763
3794
  cancelHide: () => this.cancelHide(),
3764
- isProgrammatic: () => __privateGet$5(this, _programmaticallyPos) !== null,
3765
- getPos: () => __privateGet$5(this, _programmaticallyPos),
3795
+ isProgrammatic: () => __privateGet$6(this, _programmaticallyPos) !== null,
3796
+ getPos: () => __privateGet$6(this, _programmaticallyPos),
3766
3797
  isShow: () => show.value,
3767
- getMode: () => __privateGet$5(this, _mode)
3798
+ getMode: () => __privateGet$6(this, _mode)
3768
3799
  });
3769
3800
  }
3770
3801
  }
@@ -3773,7 +3804,7 @@ _app$4 = new WeakMap();
3773
3804
  _filter = new WeakMap();
3774
3805
  _slashProvider = new WeakMap();
3775
3806
  _activeKey = new WeakMap();
3776
- _view$1 = new WeakMap();
3807
+ _view$2 = new WeakMap();
3777
3808
  _programmaticallyPos = new WeakMap();
3778
3809
  _mode = new WeakMap();
3779
3810
  _hideTimeout = new WeakMap();
@@ -3932,25 +3963,25 @@ const BlockHandle = vue.defineComponent({
3932
3963
  }
3933
3964
  });
3934
3965
 
3935
- var __typeError$4 = (msg) => {
3966
+ var __typeError$5 = (msg) => {
3936
3967
  throw TypeError(msg);
3937
3968
  };
3938
- var __accessCheck$4 = (obj, member, msg) => member.has(obj) || __typeError$4("Cannot " + msg);
3939
- var __privateGet$4 = (obj, member, getter) => (__accessCheck$4(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
3940
- 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);
3941
- var __privateSet$4 = (obj, member, value, setter) => (__accessCheck$4(obj, member, "write to private field"), member.set(obj, value), value);
3942
- 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;
3943
3974
  class BlockHandleView {
3944
3975
  constructor(ctx, config) {
3945
- __privateAdd$4(this, _content$3);
3946
- __privateAdd$4(this, _provider$1);
3947
- __privateAdd$4(this, _state, vue.reactive({ icon: textIcon }));
3948
- __privateAdd$4(this, _app$3);
3949
- __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);
3950
3981
  this.update = () => {
3951
- __privateGet$4(this, _provider$1).update();
3952
- if (__privateGet$4(this, _provider$1).active) {
3953
- 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;
3954
3985
  let hasMediaChild = false;
3955
3986
  if (node.type.name === "paragraph") {
3956
3987
  node.content.forEach((child) => {
@@ -3962,24 +3993,24 @@ class BlockHandleView {
3962
3993
  const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
3963
3994
  const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
3964
3995
  if (isEmpty) {
3965
- __privateGet$4(this, _content$3).classList.add("empty-block");
3996
+ __privateGet$5(this, _content$3).classList.add("empty-block");
3966
3997
  } else {
3967
- __privateGet$4(this, _content$3).classList.remove("empty-block");
3998
+ __privateGet$5(this, _content$3).classList.remove("empty-block");
3968
3999
  }
3969
- __privateGet$4(this, _syncIcon).call(this, node);
4000
+ __privateGet$5(this, _syncIcon).call(this, node);
3970
4001
  } else {
3971
- __privateGet$4(this, _content$3).classList.remove("empty-block");
3972
- __privateGet$4(this, _state).icon = textIcon;
4002
+ __privateGet$5(this, _content$3).classList.remove("empty-block");
4003
+ __privateGet$5(this, _state).icon = textIcon;
3973
4004
  }
3974
4005
  };
3975
- __privateAdd$4(this, _syncIcon, (node) => {
4006
+ __privateAdd$5(this, _syncIcon, (node) => {
3976
4007
  var _a;
3977
4008
  if (node.type.name.includes("image")) {
3978
- __privateGet$4(this, _state).icon = imageIcon;
4009
+ __privateGet$5(this, _state).icon = imageIcon;
3979
4010
  return;
3980
4011
  }
3981
4012
  if (node.type.name.includes("attachment")) {
3982
- __privateGet$4(this, _state).icon = fileLinkIcon;
4013
+ __privateGet$5(this, _state).icon = fileLinkIcon;
3983
4014
  return;
3984
4015
  }
3985
4016
  switch (node.type.name) {
@@ -3994,87 +4025,87 @@ class BlockHandleView {
3994
4025
  h5Icon,
3995
4026
  h6Icon
3996
4027
  ];
3997
- __privateGet$4(this, _state).icon = (_a = headingIcons[level]) != null ? _a : textIcon;
4028
+ __privateGet$5(this, _state).icon = (_a = headingIcons[level]) != null ? _a : textIcon;
3998
4029
  break;
3999
4030
  }
4000
4031
  case "blockquote":
4001
- __privateGet$4(this, _state).icon = quoteIcon;
4032
+ __privateGet$5(this, _state).icon = quoteIcon;
4002
4033
  break;
4003
4034
  case "code_block":
4004
- __privateGet$4(this, _state).icon = codeIcon;
4035
+ __privateGet$5(this, _state).icon = codeIcon;
4005
4036
  break;
4006
4037
  case "math_display":
4007
4038
  case "math_inline":
4008
- __privateGet$4(this, _state).icon = functionsIcon;
4039
+ __privateGet$5(this, _state).icon = functionsIcon;
4009
4040
  break;
4010
4041
  case "hr":
4011
- __privateGet$4(this, _state).icon = dividerIcon;
4042
+ __privateGet$5(this, _state).icon = dividerIcon;
4012
4043
  break;
4013
4044
  case "table":
4014
- __privateGet$4(this, _state).icon = tableIcon;
4045
+ __privateGet$5(this, _state).icon = tableIcon;
4015
4046
  break;
4016
4047
  case "list_item":
4017
4048
  if (node.attrs.checked != null) {
4018
- __privateGet$4(this, _state).icon = todoListIcon;
4049
+ __privateGet$5(this, _state).icon = todoListIcon;
4019
4050
  } else {
4020
- __privateGet$4(this, _state).icon = bulletListIcon;
4051
+ __privateGet$5(this, _state).icon = bulletListIcon;
4021
4052
  }
4022
4053
  break;
4023
4054
  case "bullet_list":
4024
- __privateGet$4(this, _state).icon = bulletListIcon;
4055
+ __privateGet$5(this, _state).icon = bulletListIcon;
4025
4056
  break;
4026
4057
  case "ordered_list":
4027
- __privateGet$4(this, _state).icon = orderedListIcon;
4058
+ __privateGet$5(this, _state).icon = orderedListIcon;
4028
4059
  break;
4029
4060
  default:
4030
- __privateGet$4(this, _state).icon = textIcon;
4061
+ __privateGet$5(this, _state).icon = textIcon;
4031
4062
  }
4032
4063
  });
4033
4064
  this.destroy = () => {
4034
- __privateGet$4(this, _provider$1).destroy();
4035
- __privateGet$4(this, _content$3).remove();
4036
- __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();
4037
4068
  };
4038
4069
  this.onAdd = (el) => {
4039
- const ctx = __privateGet$4(this, _ctx);
4070
+ const ctx = __privateGet$5(this, _ctx$1);
4040
4071
  const view = ctx.get(core.editorViewCtx);
4041
4072
  if (!view.hasFocus()) view.focus();
4042
- const active = __privateGet$4(this, _provider$1).active;
4073
+ const active = __privateGet$5(this, _provider$1).active;
4043
4074
  if (!active) return;
4044
4075
  const $pos = active.$pos;
4045
4076
  ctx.get(menuAPI.key).show($pos.pos, true, el, "list");
4046
4077
  };
4047
4078
  this.onOpenMenu = (el) => {
4048
- const ctx = __privateGet$4(this, _ctx);
4049
- 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;
4050
4081
  if (!active) return;
4051
4082
  const $pos = active.$pos;
4052
4083
  ctx.get(menuAPI.key).show($pos.pos, true, el, "block");
4053
4084
  };
4054
4085
  this.onHoverAdd = (el) => {
4055
- const ctx = __privateGet$4(this, _ctx);
4056
- 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;
4057
4088
  if (!active) return;
4058
4089
  const $pos = active.$pos;
4059
4090
  ctx.get(menuAPI.key).show($pos.pos, false, el, "list");
4060
4091
  };
4061
4092
  this.onLeaveAdd = () => {
4062
- const ctx = __privateGet$4(this, _ctx);
4093
+ const ctx = __privateGet$5(this, _ctx$1);
4063
4094
  ctx.get(menuAPI.key).onHoverDelayHide();
4064
4095
  };
4065
4096
  this.onHoverMenu = (el) => {
4066
- const ctx = __privateGet$4(this, _ctx);
4067
- 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;
4068
4099
  if (!active) return;
4069
4100
  const $pos = active.$pos;
4070
4101
  ctx.get(menuAPI.key).show($pos.pos, false, el, "block");
4071
4102
  };
4072
4103
  this.onLeaveMenu = () => {
4073
- const ctx = __privateGet$4(this, _ctx);
4104
+ const ctx = __privateGet$5(this, _ctx$1);
4074
4105
  ctx.get(menuAPI.key).onHoverDelayHide();
4075
4106
  };
4076
4107
  var _a, _b, _c;
4077
- __privateSet$4(this, _ctx, ctx);
4108
+ __privateSet$5(this, _ctx$1, ctx);
4078
4109
  const content = document.createElement("div");
4079
4110
  content.classList.add("milkdown-block-handle");
4080
4111
  document.querySelectorAll(".milkdown-block-handle").forEach((el) => {
@@ -4089,14 +4120,14 @@ class BlockHandleView {
4089
4120
  onLeaveMenu: this.onLeaveMenu,
4090
4121
  addIcon: (_a = config == null ? void 0 : config.handleAddIcon) != null ? _a : plusIcon,
4091
4122
  handleIcon: (_b = config == null ? void 0 : config.handleDragIcon) != null ? _b : menuIcon,
4092
- ctx: __privateGet$4(this, _ctx),
4093
- state: __privateGet$4(this, _state)
4123
+ ctx: __privateGet$5(this, _ctx$1),
4124
+ state: __privateGet$5(this, _state)
4094
4125
  });
4095
4126
  app.mount(content);
4096
- __privateSet$4(this, _app$3, app);
4097
- __privateSet$4(this, _content$3, content);
4127
+ __privateSet$5(this, _app$3, app);
4128
+ __privateSet$5(this, _content$3, content);
4098
4129
  const blockProviderOptions = (_c = config == null ? void 0 : config.blockHandle) != null ? _c : {};
4099
- __privateSet$4(this, _provider$1, new block.BlockProvider({
4130
+ __privateSet$5(this, _provider$1, new block.BlockProvider({
4100
4131
  ctx,
4101
4132
  content,
4102
4133
  getOffset: () => 16,
@@ -4113,11 +4144,11 @@ class BlockHandleView {
4113
4144
  const isMedia = node.type.name.includes("image") || node.type.name.includes("attachment") || node.type.name === "hr" || node.type.name.includes("math") || hasMediaChild;
4114
4145
  const isEmpty = node.textContent.length === 0 && node.content.size <= 2 && !isMedia;
4115
4146
  if (isEmpty) {
4116
- __privateGet$4(this, _content$3).classList.add("empty-block");
4147
+ __privateGet$5(this, _content$3).classList.add("empty-block");
4117
4148
  } else {
4118
- __privateGet$4(this, _content$3).classList.remove("empty-block");
4149
+ __privateGet$5(this, _content$3).classList.remove("empty-block");
4119
4150
  }
4120
- __privateGet$4(this, _syncIcon).call(this, active.node);
4151
+ __privateGet$5(this, _syncIcon).call(this, active.node);
4121
4152
  let totalDescendant = 0;
4122
4153
  active.node.descendants((node2) => {
4123
4154
  totalDescendant += node2.childCount;
@@ -4149,7 +4180,7 @@ _content$3 = new WeakMap();
4149
4180
  _provider$1 = new WeakMap();
4150
4181
  _state = new WeakMap();
4151
4182
  _app$3 = new WeakMap();
4152
- _ctx = new WeakMap();
4183
+ _ctx$1 = new WeakMap();
4153
4184
  _syncIcon = new WeakMap();
4154
4185
  function configureBlockHandle(ctx, config) {
4155
4186
  ctx.set(block.blockConfig.key, {
@@ -4296,6 +4327,50 @@ const cursor = (editor, config) => {
4296
4327
  editor.use(utils.$prose(() => virtualCursor));
4297
4328
  };
4298
4329
 
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
+ };
4350
+
4351
+ const listeners = /* @__PURE__ */ new Set();
4352
+ let _popupCount = 0;
4353
+ function getIsAnyPopupOpen() {
4354
+ return _popupCount > 0;
4355
+ }
4356
+ function addPopupChangeListener(fn) {
4357
+ listeners.add(fn);
4358
+ return () => listeners.delete(fn);
4359
+ }
4360
+ function incrementPopupCount() {
4361
+ const wasZero = _popupCount === 0;
4362
+ _popupCount++;
4363
+ if (wasZero) {
4364
+ listeners.forEach((fn) => fn());
4365
+ }
4366
+ }
4367
+ function decrementPopupCount() {
4368
+ _popupCount = Math.max(0, _popupCount - 1);
4369
+ if (_popupCount === 0) {
4370
+ listeners.forEach((fn) => fn());
4371
+ }
4372
+ }
4373
+
4299
4374
  const remarkHighlightMarkPlugin = utils.$remark(
4300
4375
  "remarkHighlightMark",
4301
4376
  () => function() {
@@ -5392,6 +5467,8 @@ const Toolbar = vue.defineComponent({
5392
5467
  const {
5393
5468
  marks: savedMarks,
5394
5469
  align: savedAlign,
5470
+ blockType: savedBlockType,
5471
+ blockAttrs: savedBlockAttrs,
5395
5472
  isPersistent
5396
5473
  } = formatPainterState.value;
5397
5474
  let applied = false;
@@ -5413,6 +5490,30 @@ const Toolbar = vue.defineComponent({
5413
5490
  }
5414
5491
  );
5415
5492
  }
5493
+ if (savedBlockType) {
5494
+ curState.doc.nodesBetween(
5495
+ curSelection.from,
5496
+ curSelection.to,
5497
+ (node, pos) => {
5498
+ if (node.type.name === "paragraph") {
5499
+ tr.setNodeMarkup(
5500
+ pos,
5501
+ curState.schema.nodes[savedBlockType],
5502
+ {
5503
+ ...savedBlockAttrs,
5504
+ ...savedAlign ? { align: savedAlign } : {}
5505
+ }
5506
+ );
5507
+ } else if (node.type.name === "heading" && savedBlockAttrs) {
5508
+ tr.setNodeMarkup(pos, null, {
5509
+ ...node.attrs,
5510
+ ...savedBlockAttrs,
5511
+ ...savedAlign ? { align: savedAlign } : {}
5512
+ });
5513
+ }
5514
+ }
5515
+ );
5516
+ }
5416
5517
  dispatch(tr);
5417
5518
  applied = true;
5418
5519
  } else {
@@ -5445,6 +5546,22 @@ const Toolbar = vue.defineComponent({
5445
5546
  });
5446
5547
  }
5447
5548
  }
5549
+ if (savedBlockType) {
5550
+ const pos = curSelection.$from.before(curSelection.$from.depth);
5551
+ const node = curState.doc.nodeAt(pos);
5552
+ if (node && node.type.name === "paragraph") {
5553
+ tr.setNodeMarkup(pos, curState.schema.nodes[savedBlockType], {
5554
+ ...savedBlockAttrs,
5555
+ ...savedAlign ? { align: savedAlign } : {}
5556
+ });
5557
+ } else if (node && node.type.name === "heading" && savedBlockAttrs) {
5558
+ tr.setNodeMarkup(pos, null, {
5559
+ ...node.attrs,
5560
+ ...savedBlockAttrs,
5561
+ ...savedAlign ? { align: savedAlign } : {}
5562
+ });
5563
+ }
5564
+ }
5448
5565
  tr.setStoredMarks(savedMarks);
5449
5566
  dispatch(tr);
5450
5567
  applied = true;
@@ -5493,7 +5610,22 @@ const Toolbar = vue.defineComponent({
5493
5610
  }
5494
5611
  }
5495
5612
  align = foundAlign;
5496
- formatPainterState.value = { marks, align, isPersistent };
5613
+ let blockType = null;
5614
+ let blockAttrs = null;
5615
+ {
5616
+ const parent = selection.$from.parent;
5617
+ if (parent.type.name === "heading") {
5618
+ blockType = "heading";
5619
+ blockAttrs = { level: parent.attrs.level };
5620
+ }
5621
+ }
5622
+ formatPainterState.value = {
5623
+ marks,
5624
+ align,
5625
+ blockType,
5626
+ blockAttrs,
5627
+ isPersistent
5628
+ };
5497
5629
  document.removeEventListener("pointerup", formatPainterHandler);
5498
5630
  setTimeout(() => {
5499
5631
  document.addEventListener("pointerup", formatPainterHandler);
@@ -5546,6 +5678,13 @@ const Toolbar = vue.defineComponent({
5546
5678
  const showOverflowMenu = vue.ref(false);
5547
5679
  const overflowMenuPos = vue.ref({ top: 0 });
5548
5680
  const cachedWidths = /* @__PURE__ */ new Map();
5681
+ const anyFixedPopup = vue.computed(
5682
+ () => !!isFixed && (showBlockMenu.value || showAlignMenu.value || showColorMenu.value || showFontFamilyMenu.value || showFontSizeMenu.value || showTableMenu.value || showOverflowMenu.value)
5683
+ );
5684
+ vue.watch(anyFixedPopup, (val) => {
5685
+ if (val) incrementPopupCount();
5686
+ else decrementPopupCount();
5687
+ });
5549
5688
  const getMenuLeftPos = (rect, menuWidth) => {
5550
5689
  let left = rect.left;
5551
5690
  if (left + menuWidth > window.innerWidth) {
@@ -5588,7 +5727,8 @@ const Toolbar = vue.defineComponent({
5588
5727
  containerWidth = container.clientWidth;
5589
5728
  }
5590
5729
  } else {
5591
- containerWidth = container.clientWidth;
5730
+ const view = ctx.get(core.editorViewCtx);
5731
+ containerWidth = view.dom.clientWidth - 32;
5592
5732
  }
5593
5733
  if (containerWidth === lastContainerWidth) {
5594
5734
  return;
@@ -5782,6 +5922,7 @@ const Toolbar = vue.defineComponent({
5782
5922
  if (hideFontFamilyTimer) clearTimeout(hideFontFamilyTimer);
5783
5923
  if (hideFontSizeTimer) clearTimeout(hideFontSizeTimer);
5784
5924
  if (hideTableTimer) clearTimeout(hideTableTimer);
5925
+ if (anyFixedPopup.value) decrementPopupCount();
5785
5926
  });
5786
5927
  let overflowResizeObserver = null;
5787
5928
  let overflowSetupDone = false;
@@ -6220,13 +6361,11 @@ const Toolbar = vue.defineComponent({
6220
6361
  });
6221
6362
  }
6222
6363
  });
6223
- const nonHeadingGroups = toolbarGroupInfo.value.filter(
6224
- (group) => {
6225
- if (group.key === "heading") return false;
6226
- if (props.isFixed && group.key === "function") return false;
6227
- return true;
6228
- }
6229
- );
6364
+ const nonHeadingGroups = toolbarGroupInfo.value.filter((group) => {
6365
+ if (group.key === "heading") return false;
6366
+ if (props.isFixed && group.key === "function") return false;
6367
+ return true;
6368
+ });
6230
6369
  const isSectionOverflowed = (idx) => idx >= overflowVisibleCount.value;
6231
6370
  const hasOverflow = overflowVisibleCount.value < totalSectionCount.value;
6232
6371
  return /* @__PURE__ */ vue.h(
@@ -7522,7 +7661,7 @@ const createViewMenuState = () => vue.reactive({
7522
7661
  outlineVisible: false,
7523
7662
  outlinePosition: "left",
7524
7663
  outlineWidth: 250,
7525
- documentBackground: null,
7664
+ documentBackground: "#FFFFFF",
7526
7665
  showTitle: false,
7527
7666
  showCover: false,
7528
7667
  coverUrl: "",
@@ -7622,10 +7761,15 @@ const MenuBar = vue.defineComponent({
7622
7761
  vue.onUnmounted(() => {
7623
7762
  document.removeEventListener("click", closeMenu);
7624
7763
  if (rafId) cancelAnimationFrame(rafId);
7764
+ if (showMenu.value) decrementPopupCount();
7765
+ });
7766
+ vue.watch(showMenu, (val) => {
7767
+ if (val) incrementPopupCount();
7768
+ else decrementPopupCount();
7625
7769
  });
7626
7770
  const viewState = vue.computed(() => props.ctx.get(viewMenuStateCtx.key));
7627
7771
  const bgColors = [
7628
- { name: "\u9ED8\u8BA4", value: null },
7772
+ { name: "\u767D\u8272", value: "#FFFFFF" },
7629
7773
  { name: "\u6D45\u7070", value: "#F7F7F5" },
7630
7774
  { name: "\u6D45\u68D5", value: "#F4EEDB" },
7631
7775
  { name: "\u6D45\u6A59", value: "#FBECDD" },
@@ -8113,7 +8257,7 @@ const rightGroups = [
8113
8257
  titleKey: "shortcuts.history",
8114
8258
  items: [
8115
8259
  { labelKey: "shortcuts.undo", keys: ["Mod+z"] },
8116
- { labelKey: "shortcuts.redo", keys: ["Mod+y", "Shift+Mod+z"] }
8260
+ { labelKey: "shortcuts.redo", keys: ["Mod+y", "Shift+Mod+Z"] }
8117
8261
  ]
8118
8262
  }
8119
8263
  ];
@@ -9258,11 +9402,11 @@ const OutlinePanel = vue.defineComponent({
9258
9402
  "div",
9259
9403
  {
9260
9404
  style: {
9261
- padding: "20px 16px",
9405
+ padding: "12px 16px",
9262
9406
  fontWeight: "bold",
9263
9407
  fontSize: "14px",
9264
9408
  color: "var(--crepe-color-on-surface)",
9265
- 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%))",
9266
9410
  display: "flex",
9267
9411
  justifyContent: "space-between",
9268
9412
  alignItems: "center"
@@ -9434,14 +9578,14 @@ const OutlinePanel = vue.defineComponent({
9434
9578
  }
9435
9579
  });
9436
9580
 
9437
- var __typeError$3 = (msg) => {
9581
+ var __typeError$4 = (msg) => {
9438
9582
  throw TypeError(msg);
9439
9583
  };
9440
- var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
9441
- var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9442
- 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);
9443
- var __privateSet$3 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
9444
- var _content$2, _app$2, _headerContent, _headerApp, _outlineContent, _outlineApp, _watcher, _selection$1, _show$1, _resizeObserver, _updateOutlineGeometry, _scrollContainers, _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;
9445
9589
  const fixedToolbarConfig = utils.$ctx(
9446
9590
  {},
9447
9591
  "fixedToolbarConfigCtx"
@@ -9449,88 +9593,127 @@ const fixedToolbarConfig = utils.$ctx(
9449
9593
  const fixedToolbarKey = new state.PluginKey("MILKDOWN_FIXED_TOOLBAR");
9450
9594
  class FixedToolbarView {
9451
9595
  constructor(ctx, view) {
9452
- __privateAdd$3(this, _content$2);
9453
- __privateAdd$3(this, _app$2);
9454
- __privateAdd$3(this, _headerContent);
9455
- __privateAdd$3(this, _headerApp);
9456
- __privateAdd$3(this, _outlineContent);
9457
- __privateAdd$3(this, _outlineApp);
9458
- __privateAdd$3(this, _watcher);
9459
- __privateAdd$3(this, _selection$1);
9460
- __privateAdd$3(this, _show$1, vue.ref(true));
9461
- __privateAdd$3(this, _resizeObserver);
9462
- __privateAdd$3(this, _updateOutlineGeometry);
9463
- __privateAdd$3(this, _scrollContainers, []);
9464
- __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);
9465
9611
  this.update = (view) => {
9466
- __privateGet$3(this, _selection$1).value = view.state.selection;
9612
+ __privateGet$4(this, _selection$1).value = view.state.selection;
9467
9613
  };
9468
9614
  this.destroy = () => {
9469
- if (__privateGet$3(this, _watcher)) __privateGet$3(this, _watcher).call(this);
9470
- if (__privateGet$3(this, _resizeObserver)) __privateGet$3(this, _resizeObserver).disconnect();
9471
- window.removeEventListener("resize", __privateGet$3(this, _updateOutlineGeometry));
9472
- window.removeEventListener("scroll", __privateGet$3(this, _updateOutlineGeometry), {
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));
9618
+ }
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), {
9473
9622
  capture: true
9474
9623
  });
9475
- __privateGet$3(this, _scrollContainers).forEach((el) => {
9476
- el.removeEventListener("scroll", __privateGet$3(this, _updateOutlineGeometry));
9624
+ __privateGet$4(this, _scrollContainers$1).forEach((el) => {
9625
+ el.removeEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry));
9477
9626
  });
9478
- __privateSet$3(this, _scrollContainers, []);
9479
- __privateGet$3(this, _app$2).unmount();
9480
- __privateGet$3(this, _content$2).remove();
9481
- if (__privateGet$3(this, _headerApp)) __privateGet$3(this, _headerApp).unmount();
9482
- if (__privateGet$3(this, _headerContent)) __privateGet$3(this, _headerContent).remove();
9483
- if (__privateGet$3(this, _outlineApp)) __privateGet$3(this, _outlineApp).unmount();
9484
- if (__privateGet$3(this, _outlineContent)) __privateGet$3(this, _outlineContent).remove();
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();
9485
9634
  };
9486
- __privateSet$3(this, _view, view);
9635
+ __privateSet$4(this, _view$1, view);
9487
9636
  const config = ctx.get(fixedToolbarConfig.key);
9488
9637
  const content = document.createElement("div");
9489
9638
  content.className = "milkdown-fixed-toolbar";
9490
- __privateSet$3(this, _selection$1, vue.shallowRef(view.state.selection));
9639
+ __privateSet$4(this, _selection$1, vue.shallowRef(view.state.selection));
9491
9640
  const app = vue.createApp(FixedToolbarComponent, {
9492
9641
  ctx,
9493
9642
  hide: () => {
9494
9643
  },
9495
9644
  // No-op for fixed toolbar
9496
9645
  config,
9497
- selection: __privateGet$3(this, _selection$1),
9498
- show: __privateGet$3(this, _show$1)
9646
+ selection: __privateGet$4(this, _selection$1),
9647
+ show: __privateGet$4(this, _show$1)
9499
9648
  });
9500
9649
  app.mount(content);
9501
- __privateSet$3(this, _content$2, content);
9502
- __privateSet$3(this, _app$2, app);
9650
+ __privateSet$4(this, _content$2, content);
9651
+ __privateSet$4(this, _app$2, app);
9503
9652
  const root = view.dom.parentElement;
9504
9653
  if (root) {
9505
9654
  root.style.position = "relative";
9506
- root.style.transition = "padding 0.1s ease-out, background-color 0.2s ease-out";
9507
- 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);
9508
9666
  const headerContent = document.createElement("div");
9509
- __privateSet$3(this, _headerApp, vue.createApp(DocumentHeader, { ctx, config }));
9510
- __privateGet$3(this, _headerApp).mount(headerContent);
9511
- __privateSet$3(this, _headerContent, headerContent);
9512
- 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);
9513
9671
  const outlineContent = document.createElement("div");
9514
9672
  outlineContent.style.position = "fixed";
9515
9673
  outlineContent.style.zIndex = "100";
9516
- __privateSet$3(this, _outlineApp, vue.createApp(OutlinePanel, { ctx }));
9517
- __privateGet$3(this, _outlineApp).mount(outlineContent);
9518
- __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);
9519
9677
  root.appendChild(outlineContent);
9520
- __privateGet$3(this, _content$2).style.transition = "margin 0.1s ease-out, width 0.1s ease-out";
9678
+ __privateSet$4(this, _onDblClick, (event) => {
9679
+ const view2 = __privateGet$4(this, _view$1);
9680
+ if (!view2.editable) return;
9681
+ const dom = view2.dom;
9682
+ const children = dom.children;
9683
+ if (children.length === 0) return;
9684
+ const lastChild = children[children.length - 1];
9685
+ if (!lastChild) return;
9686
+ const lastRect = lastChild.getBoundingClientRect();
9687
+ if (event.clientY <= lastRect.bottom) return;
9688
+ const { doc } = view2.state;
9689
+ const lastNode = doc.lastChild;
9690
+ if (!lastNode) return;
9691
+ if (lastNode.type.name === "paragraph" && lastNode.content.size === 0)
9692
+ return;
9693
+ const paragraphType = view2.state.schema.nodes["paragraph"];
9694
+ if (!paragraphType) return;
9695
+ const pos = doc.content.size;
9696
+ const tr = view2.state.tr.insert(pos, paragraphType.create());
9697
+ const sel = state.TextSelection.create(tr.doc, pos + 1);
9698
+ tr.setSelection(sel);
9699
+ view2.dispatch(tr);
9700
+ view2.focus();
9701
+ });
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";
9521
9704
  const viewState = ctx.get(viewMenuStateCtx.key);
9522
9705
  if (config.outlinePosition) {
9523
9706
  viewState.outlinePosition = config.outlinePosition;
9524
9707
  }
9525
- __privateSet$3(this, _updateOutlineGeometry, () => {
9708
+ __privateSet$4(this, _updateOutlineGeometry, () => {
9526
9709
  const rootRect = root.getBoundingClientRect();
9527
9710
  let outlineTop = rootRect.top;
9528
- if (__privateGet$3(this, _content$2) && __privateGet$3(this, _content$2).offsetHeight > 0) {
9529
- 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();
9530
9713
  outlineTop = Math.max(outlineTop, toolbarRect.bottom);
9531
9714
  }
9532
- if (viewState.showCover && __privateGet$3(this, _headerContent)) {
9533
- const coverEl = __privateGet$3(this, _headerContent).querySelector(
9715
+ if (viewState.showCover && __privateGet$4(this, _headerContent)) {
9716
+ const coverEl = __privateGet$4(this, _headerContent).querySelector(
9534
9717
  ".milkdown-document-cover"
9535
9718
  );
9536
9719
  if (coverEl) {
@@ -9552,28 +9735,50 @@ class FixedToolbarView {
9552
9735
  outlineContent.style.right = "auto";
9553
9736
  } else {
9554
9737
  outlineContent.style.left = "auto";
9555
- 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`;
9556
9761
  }
9557
9762
  }
9558
9763
  });
9559
- __privateSet$3(this, _resizeObserver, new ResizeObserver(__privateGet$3(this, _updateOutlineGeometry)));
9560
- __privateGet$3(this, _resizeObserver).observe(root);
9561
- window.addEventListener("resize", __privateGet$3(this, _updateOutlineGeometry));
9562
- 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), {
9563
9768
  capture: true,
9564
9769
  passive: true
9565
9770
  });
9566
9771
  let scrollerNode = root;
9567
9772
  while (scrollerNode && scrollerNode !== document) {
9568
9773
  if (scrollerNode instanceof Element) {
9569
- scrollerNode.addEventListener("scroll", __privateGet$3(this, _updateOutlineGeometry), {
9774
+ scrollerNode.addEventListener("scroll", __privateGet$4(this, _updateOutlineGeometry), {
9570
9775
  passive: true
9571
9776
  });
9572
- __privateGet$3(this, _scrollContainers).push(scrollerNode);
9777
+ __privateGet$4(this, _scrollContainers$1).push(scrollerNode);
9573
9778
  }
9574
9779
  scrollerNode = scrollerNode.parentNode || scrollerNode.host;
9575
9780
  }
9576
- __privateSet$3(this, _watcher, vue.watch(
9781
+ __privateSet$4(this, _watcher, vue.watch(
9577
9782
  () => [
9578
9783
  viewState.outlineVisible,
9579
9784
  viewState.outlinePosition,
@@ -9588,41 +9793,43 @@ class FixedToolbarView {
9588
9793
  } else {
9589
9794
  root.style.backgroundColor = "";
9590
9795
  }
9591
- if (viewState.outlineVisible) {
9592
- if (viewState.outlinePosition === "left") {
9593
- root.style.paddingLeft = `${viewState.outlineWidth}px`;
9594
- root.style.paddingRight = "0";
9595
- __privateGet$3(this, _content$2).style.width = `calc(100% + ${viewState.outlineWidth}px)`;
9596
- __privateGet$3(this, _content$2).style.marginLeft = `-${viewState.outlineWidth}px`;
9597
- __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
+ }
9598
9810
  } else {
9599
- root.style.paddingLeft = "0";
9600
- root.style.paddingRight = `${viewState.outlineWidth}px`;
9601
- __privateGet$3(this, _content$2).style.width = `calc(100% + ${viewState.outlineWidth}px)`;
9602
- __privateGet$3(this, _content$2).style.marginLeft = "0";
9603
- __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";
9604
9813
  }
9605
- } else {
9606
- root.style.paddingLeft = "0";
9607
- root.style.paddingRight = "0";
9608
- __privateGet$3(this, _content$2).style.width = "100%";
9609
- __privateGet$3(this, _content$2).style.marginLeft = "0";
9610
- __privateGet$3(this, _content$2).style.marginRight = "0";
9611
9814
  }
9612
9815
  const maxWidth = editorWidthMap[viewState.editorWidth];
9613
9816
  const isFull = maxWidth === "none";
9614
9817
  const px = isFull ? "80px" : "0";
9615
- __privateGet$3(this, _view).dom.style.maxWidth = maxWidth;
9616
- __privateGet$3(this, _view).dom.style.width = isFull ? "100%" : maxWidth;
9617
- __privateGet$3(this, _view).dom.style.margin = isFull ? "0" : "0 auto";
9618
- __privateGet$3(this, _view).dom.style.padding = `20px ${px} 0`;
9619
- if (__privateGet$3(this, _headerContent)) {
9620
- __privateGet$3(this, _headerContent).style.margin = isFull && !viewState.showCover ? "0 auto" : "0";
9621
- __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`;
9622
9825
  }
9623
- vue.nextTick(() => {
9826
+ void vue.nextTick(() => {
9624
9827
  var _a;
9625
- (_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);
9626
9833
  });
9627
9834
  },
9628
9835
  { immediate: true }
@@ -9639,10 +9846,12 @@ _outlineApp = new WeakMap();
9639
9846
  _watcher = new WeakMap();
9640
9847
  _selection$1 = new WeakMap();
9641
9848
  _show$1 = new WeakMap();
9642
- _resizeObserver = new WeakMap();
9849
+ _resizeObserver$1 = new WeakMap();
9643
9850
  _updateOutlineGeometry = new WeakMap();
9644
- _scrollContainers = new WeakMap();
9645
- _view = new WeakMap();
9851
+ _scrollContainers$1 = new WeakMap();
9852
+ _onDblClick = new WeakMap();
9853
+ _view$1 = new WeakMap();
9854
+ _editorContainer = new WeakMap();
9646
9855
  const fixedToolbarPlugin = utils.$prose((ctx) => {
9647
9856
  return new state.Plugin({
9648
9857
  key: fixedToolbarKey,
@@ -9763,10 +9972,921 @@ const imageBlockConverter = utils$1.$prose((ctx) => {
9763
9972
  const r = replacements[i];
9764
9973
  tr.replaceWith(r.from, r.to, r.blocks);
9765
9974
  }
9766
- return tr;
9975
+ return tr.setMeta("addToHistory", false);
9976
+ }
9977
+ });
9978
+ });
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
9767
10877
  }
9768
10878
  });
9769
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
+ };
9770
10890
 
9771
10891
  const blockLatexSchema = commonmark.codeBlockSchema.extendSchema((prev) => {
9772
10892
  return (ctx) => {
@@ -10244,7 +11364,7 @@ var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Ca
10244
11364
  var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
10245
11365
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10246
11366
  var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
10247
- var _tooltipProvider, _content, _app, _selection, _show, _mousePressed;
11367
+ var _tooltipProvider, _content, _app, _selection, _show, _mousePressed, _removePopupListener, _onDocumentMouseUp;
10248
11368
  const toolbarTooltip = tooltip.tooltipFactory("CREPE_TOOLBAR");
10249
11369
  class ToolbarView {
10250
11370
  constructor(ctx, view, config) {
@@ -10254,11 +11374,18 @@ class ToolbarView {
10254
11374
  __privateAdd$1(this, _selection);
10255
11375
  __privateAdd$1(this, _show, vue.ref(false));
10256
11376
  __privateAdd$1(this, _mousePressed, false);
11377
+ __privateAdd$1(this, _removePopupListener);
11378
+ __privateAdd$1(this, _onDocumentMouseUp);
10257
11379
  this.update = (view, prevState) => {
10258
11380
  __privateGet$1(this, _tooltipProvider).update(view, prevState);
10259
11381
  __privateGet$1(this, _selection).value = view.state.selection;
10260
11382
  };
10261
11383
  this.destroy = () => {
11384
+ var _a;
11385
+ (_a = __privateGet$1(this, _removePopupListener)) == null ? void 0 : _a.call(this);
11386
+ if (__privateGet$1(this, _onDocumentMouseUp)) {
11387
+ document.removeEventListener("mouseup", __privateGet$1(this, _onDocumentMouseUp));
11388
+ }
10262
11389
  __privateGet$1(this, _tooltipProvider).destroy();
10263
11390
  __privateGet$1(this, _app).unmount();
10264
11391
  __privateGet$1(this, _content).remove();
@@ -10288,12 +11415,23 @@ class ToolbarView {
10288
11415
  this.update(view);
10289
11416
  }, 0);
10290
11417
  });
11418
+ const onDocumentMouseUp = () => {
11419
+ if (__privateGet$1(this, _mousePressed)) {
11420
+ __privateSet$1(this, _mousePressed, false);
11421
+ setTimeout(() => {
11422
+ this.update(view);
11423
+ }, 0);
11424
+ }
11425
+ };
11426
+ document.addEventListener("mouseup", onDocumentMouseUp);
11427
+ __privateSet$1(this, _onDocumentMouseUp, onDocumentMouseUp);
10291
11428
  __privateSet$1(this, _tooltipProvider, new tooltip.TooltipProvider({
10292
11429
  content: __privateGet$1(this, _content),
10293
11430
  debounce: 20,
10294
11431
  offset: 10,
10295
11432
  shouldShow: (view2) => {
10296
11433
  if (__privateGet$1(this, _mousePressed)) return false;
11434
+ if (getIsAnyPopupOpen()) return false;
10297
11435
  const { doc, selection } = view2.state;
10298
11436
  const { empty, from, to } = selection;
10299
11437
  const isEmptyTextBlock = !doc.textBetween(from, to).length && selection instanceof state.TextSelection;
@@ -10313,6 +11451,13 @@ class ToolbarView {
10313
11451
  __privateGet$1(this, _tooltipProvider).onHide = () => {
10314
11452
  __privateGet$1(this, _show).value = false;
10315
11453
  };
11454
+ __privateSet$1(this, _removePopupListener, addPopupChangeListener(() => {
11455
+ if (getIsAnyPopupOpen()) {
11456
+ __privateGet$1(this, _tooltipProvider).hide();
11457
+ } else {
11458
+ __privateGet$1(this, _tooltipProvider).update(view);
11459
+ }
11460
+ }));
10316
11461
  this.update(view);
10317
11462
  }
10318
11463
  }
@@ -10322,6 +11467,8 @@ _app = new WeakMap();
10322
11467
  _selection = new WeakMap();
10323
11468
  _show = new WeakMap();
10324
11469
  _mousePressed = new WeakMap();
11470
+ _removePopupListener = new WeakMap();
11471
+ _onDocumentMouseUp = new WeakMap();
10325
11472
  const toolbar = (editor, config) => {
10326
11473
  editor.config(crepeFeatureConfig(CrepeFeature.Toolbar)).config((ctx) => {
10327
11474
  ctx.set(toolbarTooltip.key, {
@@ -10379,6 +11526,12 @@ function loadFeature(feature, editor, config) {
10379
11526
  case CrepeFeature.Attachment: {
10380
11527
  return attachment(editor, config);
10381
11528
  }
11529
+ case CrepeFeature.InlineDiff: {
11530
+ return inlineDiff(editor, config);
11531
+ }
11532
+ case CrepeFeature.DiffBlock: {
11533
+ return diffBlockFeature(editor, config);
11534
+ }
10382
11535
  }
10383
11536
  }
10384
11537
 
@@ -10435,6 +11588,22 @@ class CrepeBuilder {
10435
11588
  this.getMarkdown = () => {
10436
11589
  return __privateGet(this, _editor).action(utils.getMarkdown());
10437
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
+ };
10438
11607
  /// Register event listeners.
10439
11608
  this.on = (fn) => {
10440
11609
  if (__privateGet(this, _editor).status !== core.EditorStatus.Created) {