@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
@@ -0,0 +1,1298 @@
1
+ 'use strict';
2
+
3
+ var core = require('@jvs-milkdown/kit/core');
4
+ var state = require('@jvs-milkdown/kit/prose/state');
5
+ var view = require('@jvs-milkdown/kit/prose/view');
6
+ var utils = require('@jvs-milkdown/kit/utils');
7
+ var ctx = require('@jvs-milkdown/kit/ctx');
8
+ var vue = require('vue');
9
+ var Diff = require('diff');
10
+
11
+ function _interopNamespaceDefault(e) {
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var Diff__namespace = /*#__PURE__*/_interopNamespaceDefault(Diff);
29
+
30
+ const zhCN = {
31
+ // block handle
32
+ "handle.add": "\u63D2\u5165\u5185\u5BB9",
33
+ "handle.menu": "\u70B9\u51FB\u6253\u5F00\u83DC\u5355",
34
+ "handle.drag": "\u62D6\u62FD\u79FB\u52A8\u4F4D\u7F6E",
35
+ // placeholder
36
+ "placeholder.text": "\u8F93\u5165\u6B63\u6587\u6216 '/' \u5FEB\u901F\u63D2\u5165\u5185\u5BB9",
37
+ // toolbar
38
+ "toolbar.heading": "\u6807\u9898",
39
+ "toolbar.formatting": "\u683C\u5F0F",
40
+ "toolbar.function": "\u529F\u80FD",
41
+ "toolbar.formatPainter": "\u683C\u5F0F\u5237",
42
+ // menu bar
43
+ "menuBar.file": "\u6587\u4EF6",
44
+ "menuBar.edit": "\u7F16\u8F91",
45
+ "menuBar.view": "\u89C6\u56FE",
46
+ "menuBar.insert": "\u63D2\u5165",
47
+ "menuBar.format": "\u683C\u5F0F",
48
+ // view menu
49
+ "view.outline": "\u5927\u7EB2\u9762\u677F",
50
+ "view.outlineLeft": "\u5728\u5DE6\u4FA7\u663E\u793A",
51
+ "view.outlineRight": "\u5728\u53F3\u4FA7\u663E\u793A",
52
+ "view.docBackground": "\u6587\u6863\u80CC\u666F\u8272",
53
+ "view.title": "\u663E\u793A\u6807\u9898",
54
+ "view.cover": "\u663E\u793A\u5C01\u9762",
55
+ "view.editorWidth": "\u5185\u5BB9\u5BBD\u5EA6",
56
+ "view.widthDefault": "\u9ED8\u8BA4",
57
+ "view.widthWide": "\u8F83\u5BBD",
58
+ "view.widthFull": "\u5168\u5BBD",
59
+ // code-mirror
60
+ "codeMirror.searchPlaceholder": "\u641C\u7D22\u8BED\u8A00",
61
+ "codeMirror.noResultText": "\u65E0\u7ED3\u679C",
62
+ "codeMirror.previewToggleOptionEdit": "\u7F16\u8F91",
63
+ "codeMirror.previewToggleOptionHide": "\u9690\u85CF",
64
+ "codeMirror.previewLabel": "\u9884\u89C8",
65
+ "codeMirror.wrapText": "\u81EA\u52A8\u6362\u884C",
66
+ // link-tooltip
67
+ "linkTooltip.pasteLink": "\u7C98\u8D34\u94FE\u63A5...",
68
+ // image-block
69
+ "imageBlock.inlineUploadButton": "\u4E0A\u4F20",
70
+ "imageBlock.inlineUploadPlaceholder": "\u6216\u7C98\u8D34\u94FE\u63A5",
71
+ "imageBlock.blockUploadButton": "\u4E0A\u4F20\u6587\u4EF6",
72
+ "imageBlock.blockUploadPlaceholder": "\u6216\u7C98\u8D34\u94FE\u63A5",
73
+ "imageBlock.blockCaptionPlaceholder": "\u5199\u4E0B\u56FE\u7247\u63CF\u8FF0...",
74
+ "imageBlock.blockConfirmButton": "\u786E\u5B9A",
75
+ // attachment-block
76
+ "attachmentBlock.uploadButton": "\u4E0A\u4F20\u6587\u4EF6",
77
+ "attachmentBlock.uploadPlaceholderText": "\u6216\u70B9\u51FB\u4E0A\u4F20",
78
+ "attachmentBlock.download": "\u4E0B\u8F7D",
79
+ // menu categories
80
+ "menu.group.text": "\u6B63\u6587",
81
+ "menu.group.block": "\u6BB5\u843D",
82
+ "menu.group.list": "\u5217\u8868",
83
+ "menu.group.advanced": "\u9AD8\u7EA7",
84
+ // menu items
85
+ "menu.item.text": "\u666E\u901A\u6587\u672C",
86
+ "menu.item.h1": "\u6807\u9898 1",
87
+ "menu.item.h2": "\u6807\u9898 2",
88
+ "menu.item.h3": "\u6807\u9898 3",
89
+ "menu.item.h4": "\u6807\u9898 4",
90
+ "menu.item.h5": "\u6807\u9898 5",
91
+ "menu.item.h6": "\u6807\u9898 6",
92
+ "menu.item.quote": "\u5F15\u7528",
93
+ "menu.item.divider": "\u5206\u5272\u7EBF",
94
+ "menu.item.bulletList": "\u65E0\u5E8F\u5217\u8868",
95
+ "menu.item.orderedList": "\u6709\u5E8F\u5217\u8868",
96
+ "menu.item.taskList": "\u4EFB\u52A1\u5217\u8868",
97
+ "menu.item.image": "\u56FE\u7247",
98
+ "menu.item.attachment": "\u89C6\u9891\u6216\u6587\u4EF6",
99
+ "menu.item.code": "\u4EE3\u7801\u5757",
100
+ "menu.item.table": "\u8868\u683C",
101
+ "menu.item.math": "\u516C\u5F0F",
102
+ "menu.item.bold": "\u52A0\u7C97",
103
+ "menu.item.italic": "\u659C\u4F53",
104
+ "menu.item.strikethrough": "\u5220\u9664\u7EBF",
105
+ "menu.item.underline": "\u4E0B\u5212\u7EBF",
106
+ "menu.item.highlight": "\u9AD8\u4EAE",
107
+ "menu.item.lineCode": "\u884C\u5185\u4EE3\u7801",
108
+ "menu.item.link": "\u94FE\u63A5",
109
+ // menu tooltips
110
+ "menu.tooltip.text": "\u666E\u901A\u6587\u672C (Ctrl+Alt+0)",
111
+ "menu.tooltip.h1": "\u6807\u9898 1 (Ctrl+Alt+1)\nMarkdown: # \u7A7A\u683C",
112
+ "menu.tooltip.h2": "\u6807\u9898 2 (Ctrl+Alt+2)\nMarkdown: ## \u7A7A\u683C",
113
+ "menu.tooltip.h3": "\u6807\u9898 3 (Ctrl+Alt+3)\nMarkdown: ### \u7A7A\u683C",
114
+ "menu.tooltip.h4": "\u6807\u9898 4 (Ctrl+Alt+4)\nMarkdown: #### \u7A7A\u683C",
115
+ "menu.tooltip.h5": "\u6807\u9898 5 (Ctrl+Alt+5)\nMarkdown: ##### \u7A7A\u683C",
116
+ "menu.tooltip.h6": "\u6807\u9898 6 (Ctrl+Alt+6)\nMarkdown: ###### \u7A7A\u683C",
117
+ "menu.tooltip.quote": "\u5F15\u7528 (Ctrl+Shift+9)\nMarkdown: > \u7A7A\u683C",
118
+ "menu.tooltip.divider": "\u5206\u5272\u7EBF\nMarkdown: --- \u7A7A\u683C",
119
+ "menu.tooltip.bulletList": "\u65E0\u5E8F\u5217\u8868 (Ctrl+Shift+8)\nMarkdown: - \u7A7A\u683C \u6216 * \u7A7A\u683C",
120
+ "menu.tooltip.orderedList": "\u6709\u5E8F\u5217\u8868 (Ctrl+Shift+7)\nMarkdown: 1. \u7A7A\u683C",
121
+ "menu.tooltip.taskList": "\u4EFB\u52A1\u5217\u8868\nMarkdown: - [ ] \u7A7A\u683C",
122
+ "menu.tooltip.image": "\u56FE\u7247\nMarkdown: ![alt](url)",
123
+ "menu.tooltip.code": "\u4EE3\u7801\u5757 (Ctrl+Shift+\\)\nMarkdown: ``` \u56DE\u8F66",
124
+ "menu.tooltip.table": "\u8868\u683C\nMarkdown: | | |",
125
+ "menu.tooltip.math": "\u516C\u5F0F\nMarkdown: $$ \u56DE\u8F66",
126
+ // custom block menu items
127
+ "customMenu.indentAndAlign": "\u7F29\u8FDB\u548C\u5BF9\u9F50",
128
+ "customMenu.color": "\u989C\u8272",
129
+ "customMenu.cut": "\u526A\u5207",
130
+ "customMenu.copy": "\u590D\u5236",
131
+ "customMenu.delete": "\u5220\u9664",
132
+ "customMenu.addBelow": "\u5728\u4E0B\u65B9\u6DFB\u52A0",
133
+ "customMenu.alignLeft": "\u5DE6\u5BF9\u9F50",
134
+ "customMenu.alignCenter": "\u5C45\u4E2D\u5BF9\u9F50",
135
+ "customMenu.alignRight": "\u53F3\u5BF9\u9F50",
136
+ "customMenu.increaseIndent": "\u589E\u52A0\u7F29\u8FDB",
137
+ "customMenu.decreaseIndent": "\u51CF\u5C11\u7F29\u8FDB",
138
+ "customMenu.textColor": "\u5B57\u4F53\u989C\u8272",
139
+ "customMenu.bgColor": "\u80CC\u666F\u989C\u8272",
140
+ "customMenu.restoreDefault": "\u6062\u590D\u9ED8\u8BA4",
141
+ "customMenu.colorDefault": "\u9ED8\u8BA4",
142
+ "customMenu.colorRed": "\u7EA2\u8272",
143
+ "customMenu.colorOrange": "\u6A59\u8272",
144
+ "customMenu.colorYellow": "\u9EC4\u8272",
145
+ "customMenu.colorGreen": "\u7EFF\u8272",
146
+ "customMenu.colorBlue": "\u84DD\u8272",
147
+ "customMenu.colorPurple": "\u7D2B\u8272",
148
+ "customMenu.colorGray": "\u7070\u8272",
149
+ "customMenu.insertTable": "\u63D2\u5165\u652F\u6301\u5BCC\u6587\u672C\u7684\u8868\u683C",
150
+ "customMenu.fontDefault": "\u9ED8\u8BA4",
151
+ "font.fangSong": "\u4EFF\u5B8B",
152
+ "font.stFangsong": "\u534E\u6587\u4EFF\u5B8B",
153
+ "font.stSong": "\u534E\u6587\u5B8B\u4F53",
154
+ "font.stKaiti": "\u534E\u6587\u6977\u4F53",
155
+ "font.simSun": "\u5B8B\u4F53",
156
+ "font.microsoftYaHei": "\u5FAE\u8F6F\u96C5\u9ED1",
157
+ "font.kaiTi": "\u6977\u4F53",
158
+ "font.simHei": "\u9ED1\u4F53",
159
+ // latex
160
+ "latex.escToExit": "\u6309 ESC \u5B8C\u6210\u8F93\u5165",
161
+ "latex.helpDoc": "\u67E5\u770B\u5E2E\u52A9\u6587\u6863",
162
+ "latex.emptyPlaceholder": "\u6DFB\u52A0 LaTeX \u516C\u5F0F",
163
+ "latex.inputPlaceholder": "\u8BF7\u8F93\u5165\u516C\u5F0F",
164
+ // shortcuts
165
+ "shortcuts.title": "\u952E\u76D8\u5FEB\u6377\u952E",
166
+ "shortcuts.formatting": "\u6587\u672C\u683C\u5F0F",
167
+ "shortcuts.bold": "\u52A0\u7C97",
168
+ "shortcuts.italic": "\u659C\u4F53",
169
+ "shortcuts.underline": "\u4E0B\u5212\u7EBF",
170
+ "shortcuts.strikethrough": "\u5220\u9664\u7EBF",
171
+ "shortcuts.inlineCode": "\u884C\u5185\u4EE3\u7801",
172
+ "shortcuts.highlight": "\u9AD8\u4EAE",
173
+ "shortcuts.paragraph": "\u6BB5\u843D",
174
+ "shortcuts.heading": "\u6807\u9898",
175
+ "shortcuts.block": "\u5757\u7EA7\u5143\u7D20",
176
+ "shortcuts.codeBlock": "\u4EE3\u7801\u5757",
177
+ "shortcuts.blockquote": "\u5F15\u7528",
178
+ "shortcuts.orderedList": "\u6709\u5E8F\u5217\u8868",
179
+ "shortcuts.bulletList": "\u65E0\u5E8F\u5217\u8868",
180
+ "shortcuts.indent": "\u589E\u52A0\u7F29\u8FDB",
181
+ "shortcuts.outdent": "\u51CF\u5C11\u7F29\u8FDB",
182
+ "shortcuts.hardBreak": "\u6362\u884C",
183
+ "shortcuts.history": "\u5386\u53F2\u8BB0\u5F55",
184
+ "shortcuts.undo": "\u64A4\u9500",
185
+ "shortcuts.redo": "\u91CD\u505A",
186
+ // inline-diff
187
+ "inlineDiff.accept": "\u63A5\u53D7",
188
+ "inlineDiff.reject": "\u62D2\u7EDD"
189
+ };
190
+ const enUS = {
191
+ "handle.add": "Add content",
192
+ "handle.menu": "Open menu",
193
+ "handle.drag": "Drag to move",
194
+ "placeholder.text": "Type '/' to use slash menu",
195
+ "toolbar.heading": "Heading",
196
+ "toolbar.formatting": "Formatting",
197
+ "toolbar.function": "Function",
198
+ "toolbar.formatPainter": "Format Painter",
199
+ "menuBar.file": "File",
200
+ "menuBar.edit": "Edit",
201
+ "menuBar.view": "View",
202
+ "menuBar.insert": "Insert",
203
+ "menuBar.format": "Format",
204
+ "view.outline": "Outline Panel",
205
+ "view.outlineLeft": "Show on Left",
206
+ "view.outlineRight": "Show on Right",
207
+ "view.docBackground": "Document Background",
208
+ "view.title": "Show Title",
209
+ "view.cover": "Show Cover",
210
+ "view.editorWidth": "Content Width",
211
+ "view.widthDefault": "Default",
212
+ "view.widthWide": "Wide",
213
+ "view.widthFull": "Full Width",
214
+ "codeMirror.searchPlaceholder": "Search language",
215
+ "codeMirror.noResultText": "No result",
216
+ "codeMirror.previewToggleOptionEdit": "Edit",
217
+ "codeMirror.previewToggleOptionHide": "Hide",
218
+ "codeMirror.previewLabel": "Preview",
219
+ "codeMirror.wrapText": "Wrap",
220
+ "linkTooltip.pasteLink": "Paste link...",
221
+ "imageBlock.inlineUploadButton": "Upload",
222
+ "imageBlock.inlineUploadPlaceholder": "or paste link",
223
+ "imageBlock.blockUploadButton": "Upload file",
224
+ "imageBlock.blockUploadPlaceholder": "or paste link",
225
+ "imageBlock.blockCaptionPlaceholder": "Write Image Caption",
226
+ "imageBlock.blockConfirmButton": "Confirm",
227
+ "attachmentBlock.uploadButton": "Upload file",
228
+ "attachmentBlock.uploadPlaceholderText": "or click to upload",
229
+ "attachmentBlock.download": "Download",
230
+ "menu.group.text": "Text",
231
+ "menu.group.block": "Block",
232
+ "menu.group.list": "List",
233
+ "menu.group.advanced": "Advanced",
234
+ "menu.item.text": "Text",
235
+ "menu.item.h1": "Heading 1",
236
+ "menu.item.h2": "Heading 2",
237
+ "menu.item.h3": "Heading 3",
238
+ "menu.item.h4": "Heading 4",
239
+ "menu.item.h5": "Heading 5",
240
+ "menu.item.h6": "Heading 6",
241
+ "menu.item.quote": "Quote",
242
+ "menu.item.divider": "Divider",
243
+ "menu.item.bulletList": "Bullet List",
244
+ "menu.item.orderedList": "Ordered List",
245
+ "menu.item.taskList": "Task List",
246
+ "menu.item.image": "Image",
247
+ "menu.item.attachment": "Video or File",
248
+ "menu.item.code": "Code",
249
+ "menu.item.table": "Table",
250
+ "menu.item.math": "Math",
251
+ "menu.item.bold": "Bold",
252
+ "menu.item.italic": "Italic",
253
+ "menu.item.strikethrough": "Strikethrough",
254
+ "menu.item.underline": "Underline",
255
+ "menu.item.highlight": "Highlight",
256
+ "menu.item.lineCode": "Inline Code",
257
+ "menu.item.link": "Link",
258
+ "menu.tooltip.text": "Text (Ctrl+Alt+0)",
259
+ "menu.tooltip.h1": "Heading 1 (Ctrl+Alt+1)\nMarkdown: # Space",
260
+ "menu.tooltip.h2": "Heading 2 (Ctrl+Alt+2)\nMarkdown: ## Space",
261
+ "menu.tooltip.h3": "Heading 3 (Ctrl+Alt+3)\nMarkdown: ### Space",
262
+ "menu.tooltip.h4": "Heading 4 (Ctrl+Alt+4)\nMarkdown: #### Space",
263
+ "menu.tooltip.h5": "Heading 5 (Ctrl+Alt+5)\nMarkdown: ##### Space",
264
+ "menu.tooltip.h6": "Heading 6 (Ctrl+Alt+6)\nMarkdown: ###### Space",
265
+ "menu.tooltip.quote": "Quote (Ctrl+Shift+9)\nMarkdown: > Space",
266
+ "menu.tooltip.divider": "Divider\nMarkdown: --- Space",
267
+ "menu.tooltip.bulletList": "Bullet List (Ctrl+Shift+8)\nMarkdown: - Space or * Space",
268
+ "menu.tooltip.orderedList": "Ordered List (Ctrl+Shift+7)\nMarkdown: 1. Space",
269
+ "menu.tooltip.taskList": "Task List\nMarkdown: - [ ] Space",
270
+ "menu.tooltip.image": "Image\nMarkdown: ![alt](url)",
271
+ "menu.tooltip.code": "Code Block (Ctrl+Shift+\\)\nMarkdown: ``` Enter",
272
+ "menu.tooltip.table": "Table\nMarkdown: | | |",
273
+ "menu.tooltip.math": "Math\nMarkdown: $$ Enter",
274
+ "customMenu.indentAndAlign": "Indent & Align",
275
+ "customMenu.color": "Color",
276
+ "customMenu.cut": "Cut",
277
+ "customMenu.copy": "Copy",
278
+ "customMenu.delete": "Delete",
279
+ "customMenu.addBelow": "Add below",
280
+ "customMenu.alignLeft": "Align Left",
281
+ "customMenu.alignCenter": "Align Center",
282
+ "customMenu.alignRight": "Align Right",
283
+ "customMenu.increaseIndent": "Increase Indent",
284
+ "customMenu.decreaseIndent": "Decrease Indent",
285
+ "customMenu.textColor": "Text Color",
286
+ "customMenu.bgColor": "Background Color",
287
+ "customMenu.restoreDefault": "Restore Default",
288
+ "customMenu.colorDefault": "Default",
289
+ "customMenu.colorRed": "Red",
290
+ "customMenu.colorOrange": "Orange",
291
+ "customMenu.colorYellow": "Yellow",
292
+ "customMenu.colorGreen": "Green",
293
+ "customMenu.colorBlue": "Blue",
294
+ "customMenu.colorPurple": "Purple",
295
+ "customMenu.colorGray": "Gray",
296
+ "customMenu.insertTable": "Insert Table",
297
+ "customMenu.fontDefault": "Default",
298
+ "font.fangSong": "FangSong",
299
+ "font.stFangsong": "STFangsong",
300
+ "font.stSong": "STSong",
301
+ "font.stKaiti": "STKaiti",
302
+ "font.simSun": "SimSun",
303
+ "font.microsoftYaHei": "Microsoft YaHei",
304
+ "font.kaiTi": "KaiTi",
305
+ "font.simHei": "SimHei",
306
+ "latex.escToExit": "Press ESC to finish",
307
+ "latex.helpDoc": "Help Doc",
308
+ "latex.emptyPlaceholder": "Add LaTeX",
309
+ "latex.inputPlaceholder": "Please enter formula",
310
+ "shortcuts.title": "Keyboard Shortcuts",
311
+ "shortcuts.formatting": "Text Formatting",
312
+ "shortcuts.bold": "Bold",
313
+ "shortcuts.italic": "Italic",
314
+ "shortcuts.underline": "Underline",
315
+ "shortcuts.strikethrough": "Strikethrough",
316
+ "shortcuts.inlineCode": "Inline Code",
317
+ "shortcuts.highlight": "Highlight",
318
+ "shortcuts.paragraph": "Paragraph",
319
+ "shortcuts.heading": "Heading",
320
+ "shortcuts.block": "Block Elements",
321
+ "shortcuts.codeBlock": "Code Block",
322
+ "shortcuts.blockquote": "Blockquote",
323
+ "shortcuts.orderedList": "Ordered List",
324
+ "shortcuts.bulletList": "Bullet List",
325
+ "shortcuts.indent": "Indent",
326
+ "shortcuts.outdent": "Outdent",
327
+ "shortcuts.hardBreak": "Hard Break",
328
+ "shortcuts.history": "History",
329
+ "shortcuts.undo": "Undo",
330
+ "shortcuts.redo": "Redo",
331
+ "inlineDiff.accept": "Accept",
332
+ "inlineDiff.reject": "Reject"
333
+ };
334
+ const translationsCtx = ctx.createSlice(
335
+ {
336
+ "zh-CN": zhCN,
337
+ "en-US": enUS
338
+ },
339
+ "translationsCtx"
340
+ );
341
+ const localeCtx = ctx.createSlice("zh-CN", "localeCtx");
342
+ function i18n(ctx, key) {
343
+ var _a, _b, _c, _d, _e;
344
+ const translations = ctx.get(translationsCtx);
345
+ const locale = ctx.get(localeCtx);
346
+ return (_e = (_d = (_c = (_a = translations[locale]) == null ? void 0 : _a[key]) != null ? _c : (_b = translations["zh-CN"]) == null ? void 0 : _b[key]) != null ? _d : enUS[key]) != null ? _e : key;
347
+ }
348
+
349
+ ctx.createSlice([], "FeaturesCtx");
350
+ ctx.createSlice({}, "CrepeCtx");
351
+ function useCrepeFeatures(ctx) {
352
+ return ctx.use("FeaturesCtx");
353
+ }
354
+ function crepeFeatureConfig(feature) {
355
+ return (ctx) => {
356
+ useCrepeFeatures(ctx).update((features) => {
357
+ if (features.includes(feature)) {
358
+ return features;
359
+ }
360
+ return [...features, feature];
361
+ });
362
+ };
363
+ }
364
+
365
+ var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
366
+ CrepeFeature2["CodeMirror"] = "code-mirror";
367
+ CrepeFeature2["ListItem"] = "list-item";
368
+ CrepeFeature2["LinkTooltip"] = "link-tooltip";
369
+ CrepeFeature2["Cursor"] = "cursor";
370
+ CrepeFeature2["ImageBlock"] = "image-block";
371
+ CrepeFeature2["BlockEdit"] = "block-edit";
372
+ CrepeFeature2["Toolbar"] = "toolbar";
373
+ CrepeFeature2["FixedToolbar"] = "fixed-toolbar";
374
+ CrepeFeature2["Placeholder"] = "placeholder";
375
+ CrepeFeature2["Table"] = "table";
376
+ CrepeFeature2["Latex"] = "latex";
377
+ CrepeFeature2["Attachment"] = "attachment";
378
+ CrepeFeature2["InlineDiff"] = "inline-diff";
379
+ CrepeFeature2["DiffBlock"] = "diff-block";
380
+ return CrepeFeature2;
381
+ })(CrepeFeature || {});
382
+
383
+ const typeLabels = {
384
+ added: "\u65B0\u589E",
385
+ removed: "\u5220\u9664"
386
+ };
387
+ const typeColors = {
388
+ added: "#4caf50",
389
+ removed: "#c0392b"
390
+ };
391
+ function mountChangePanel(container, changes, onNavigate, onClose) {
392
+ const app = vue.createApp({
393
+ setup() {
394
+ const activeTab = vue.ref("all");
395
+ const filteredChanges = vue.computed(() => {
396
+ if (activeTab.value === "all") return changes;
397
+ return changes.filter((c) => c.type === activeTab.value);
398
+ });
399
+ const counts = vue.computed(() => ({
400
+ all: changes.length,
401
+ removed: changes.filter((c) => c.type === "removed").length,
402
+ added: changes.filter((c) => c.type === "added").length
403
+ }));
404
+ function renderTab(tab, label) {
405
+ const isActive = activeTab.value === tab;
406
+ return vue.h(
407
+ "button",
408
+ {
409
+ style: {
410
+ padding: "6px 10px",
411
+ border: "none",
412
+ background: "none",
413
+ cursor: "pointer",
414
+ fontSize: "12px",
415
+ color: isActive ? "#1890ff" : "#666",
416
+ borderBottom: isActive ? "2px solid #1890ff" : "2px solid transparent"
417
+ },
418
+ onClick: () => {
419
+ activeTab.value = tab;
420
+ }
421
+ },
422
+ label
423
+ );
424
+ }
425
+ function renderItem(change, index) {
426
+ const color = typeColors[change.type];
427
+ const children = [
428
+ vue.h("div", { style: { marginBottom: "4px" } }, [
429
+ vue.h(
430
+ "span",
431
+ {
432
+ style: {
433
+ display: "inline-block",
434
+ padding: "1px 6px",
435
+ borderRadius: "3px",
436
+ color: "#fff",
437
+ fontSize: "11px",
438
+ fontWeight: "500",
439
+ backgroundColor: color
440
+ }
441
+ },
442
+ `${index} ${typeLabels[change.type]}`
443
+ )
444
+ ])
445
+ ];
446
+ if (change.oldText) {
447
+ children.push(
448
+ vue.h(
449
+ "div",
450
+ {
451
+ style: {
452
+ marginTop: "3px",
453
+ fontSize: "12px",
454
+ lineHeight: "1.5",
455
+ color: "#555",
456
+ wordBreak: "break-all"
457
+ }
458
+ },
459
+ [
460
+ vue.h(
461
+ "span",
462
+ { style: { color: "#999", fontSize: "11px" } },
463
+ "\u539F\u6587: "
464
+ ),
465
+ vue.h("span", null, change.oldText)
466
+ ]
467
+ )
468
+ );
469
+ }
470
+ if (change.newText) {
471
+ children.push(
472
+ vue.h(
473
+ "div",
474
+ {
475
+ style: {
476
+ marginTop: "3px",
477
+ fontSize: "12px",
478
+ lineHeight: "1.5",
479
+ wordBreak: "break-all"
480
+ }
481
+ },
482
+ [
483
+ vue.h(
484
+ "span",
485
+ { style: { color: "#999", fontSize: "11px" } },
486
+ "\u5DEE\u5F02: "
487
+ ),
488
+ vue.h("span", { style: { color } }, change.newText)
489
+ ]
490
+ )
491
+ );
492
+ }
493
+ return vue.h(
494
+ "div",
495
+ {
496
+ style: {
497
+ padding: "8px 10px",
498
+ borderRadius: "4px",
499
+ marginBottom: "6px",
500
+ background: "rgba(0,0,0,0.02)",
501
+ border: "1px solid #eee",
502
+ cursor: change.from > 0 ? "pointer" : "default"
503
+ },
504
+ onClick: () => {
505
+ if (change.from > 0) onNavigate(change.from);
506
+ }
507
+ },
508
+ children
509
+ );
510
+ }
511
+ return () => vue.h(
512
+ "div",
513
+ {
514
+ style: {
515
+ width: "100%",
516
+ height: "100%",
517
+ display: "flex",
518
+ flexDirection: "column",
519
+ backgroundColor: "var(--crepe-color-surface, #fff)",
520
+ boxSizing: "border-box",
521
+ fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
522
+ fontSize: "13px",
523
+ color: "var(--crepe-color-on-surface, #333)",
524
+ overflow: "hidden"
525
+ }
526
+ },
527
+ [
528
+ // Header
529
+ vue.h(
530
+ "div",
531
+ {
532
+ style: {
533
+ padding: "12px 16px",
534
+ fontSize: "14px",
535
+ fontWeight: "bold",
536
+ borderBottom: "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))",
537
+ color: "var(--crepe-color-on-surface, #333)",
538
+ display: "flex",
539
+ justifyContent: "space-between",
540
+ alignItems: "center",
541
+ flexShrink: 0
542
+ }
543
+ },
544
+ [
545
+ vue.h("span", null, "\u6587\u6863\u5DEE\u5F02\u53D8\u66F4"),
546
+ onClose ? vue.h(
547
+ "div",
548
+ {
549
+ style: {
550
+ cursor: "pointer",
551
+ display: "flex",
552
+ alignItems: "center",
553
+ justifyContent: "center",
554
+ width: "24px",
555
+ height: "24px",
556
+ borderRadius: "4px",
557
+ color: "var(--crepe-color-outline, #999)",
558
+ transition: "background-color 0.2s, color 0.2s"
559
+ },
560
+ onClick: onClose,
561
+ onMouseenter: (e) => {
562
+ const target = e.currentTarget;
563
+ target.style.backgroundColor = "var(--crepe-color-hover, rgba(0,0,0,0.05))";
564
+ target.style.color = "var(--crepe-color-on-surface, #333)";
565
+ },
566
+ onMouseleave: (e) => {
567
+ const target = e.currentTarget;
568
+ target.style.backgroundColor = "transparent";
569
+ target.style.color = "var(--crepe-color-outline, #999)";
570
+ },
571
+ title: "\u5173\u95ED\u5DEE\u5F02"
572
+ },
573
+ [
574
+ vue.h(
575
+ "svg",
576
+ {
577
+ width: "16",
578
+ height: "16",
579
+ viewBox: "0 0 24 24",
580
+ fill: "none",
581
+ stroke: "currentColor",
582
+ strokeWidth: "2",
583
+ strokeLinecap: "round",
584
+ strokeLinejoin: "round"
585
+ },
586
+ [
587
+ vue.h("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
588
+ vue.h("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
589
+ ]
590
+ )
591
+ ]
592
+ ) : null
593
+ ]
594
+ ),
595
+ // Tabs
596
+ vue.h(
597
+ "div",
598
+ {
599
+ style: {
600
+ display: "flex",
601
+ borderBottom: "1px solid #eee",
602
+ padding: "0 8px",
603
+ flexShrink: 0
604
+ }
605
+ },
606
+ [
607
+ renderTab("all", `\u5168\u90E8(${counts.value.all})`),
608
+ renderTab("removed", `\u5220\u9664(${counts.value.removed})`),
609
+ renderTab("added", `\u65B0\u589E(${counts.value.added})`)
610
+ ]
611
+ ),
612
+ // List
613
+ vue.h(
614
+ "div",
615
+ {
616
+ style: {
617
+ flex: 1,
618
+ overflowY: "auto",
619
+ padding: "8px"
620
+ }
621
+ },
622
+ filteredChanges.value.map(
623
+ (change, i) => renderItem(change, i + 1)
624
+ )
625
+ )
626
+ ]
627
+ );
628
+ }
629
+ });
630
+ app.mount(container);
631
+ return app;
632
+ }
633
+
634
+ const inlineDiffConfig = utils.$ctx(
635
+ {
636
+ addedClass: "crepe-diff-added",
637
+ deletedClass: "crepe-diff-deleted"
638
+ },
639
+ "inlineDiffConfigCtx"
640
+ );
641
+ const noopApi = {
642
+ showDiff: () => {
643
+ },
644
+ hideDiff: () => {
645
+ },
646
+ isShowing: () => false
647
+ };
648
+ const inlineDiffApiCtx = utils.$ctx(noopApi, "inlineDiffApiCtx");
649
+
650
+ function lcs(a, b, eq) {
651
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
652
+ const m = a.length;
653
+ const n = b.length;
654
+ const dp = Array.from(
655
+ { length: m + 1 },
656
+ () => Array.from({ length: n + 1 }, () => 0)
657
+ );
658
+ for (let i2 = m - 1; i2 >= 0; i2--) {
659
+ for (let j2 = n - 1; j2 >= 0; j2--) {
660
+ const diag = (_b = (_a = dp[i2 + 1]) == null ? void 0 : _a[j2 + 1]) != null ? _b : 0;
661
+ const down = (_d = (_c = dp[i2 + 1]) == null ? void 0 : _c[j2]) != null ? _d : 0;
662
+ const right = (_f = (_e = dp[i2]) == null ? void 0 : _e[j2 + 1]) != null ? _f : 0;
663
+ dp[i2][j2] = eq(a[i2], b[j2]) ? 1 + diag : Math.max(down, right);
664
+ }
665
+ }
666
+ const pairs = [];
667
+ let i = 0;
668
+ let j = 0;
669
+ while (i < m && j < n) {
670
+ const down = (_h = (_g = dp[i + 1]) == null ? void 0 : _g[j]) != null ? _h : 0;
671
+ const right = (_j = (_i = dp[i]) == null ? void 0 : _i[j + 1]) != null ? _j : 0;
672
+ if (eq(a[i], b[j])) {
673
+ pairs.push([i, j]);
674
+ i++;
675
+ j++;
676
+ } else if (down >= right) {
677
+ i++;
678
+ } else {
679
+ j++;
680
+ }
681
+ }
682
+ return pairs;
683
+ }
684
+ function computeDiff(oldBlocks, newBlocks) {
685
+ const result = [];
686
+ let chunkCounter = 0;
687
+ const pushChunk = (diffs) => {
688
+ if (diffs.length > 0) {
689
+ result.push({
690
+ id: `chunk-${chunkCounter++}`,
691
+ diffs,
692
+ status: "pending"
693
+ });
694
+ }
695
+ };
696
+ const pairs = lcs(
697
+ oldBlocks,
698
+ newBlocks,
699
+ (a, b) => a.textContent === b.textContent
700
+ );
701
+ let oi = 0;
702
+ let ni = 0;
703
+ for (const [pi, pj] of pairs) {
704
+ const gapOld = pi - oi;
705
+ const gapNew = pj - ni;
706
+ const gapMax = Math.max(gapOld, gapNew);
707
+ for (let k = 0; k < gapMax; k++) {
708
+ const hasOld = oi + k < pi;
709
+ const hasNew = ni + k < pj;
710
+ const currentDiffs = [];
711
+ if (hasOld && hasNew) {
712
+ const oldNode2 = oldBlocks[oi + k];
713
+ const newNode2 = newBlocks[ni + k];
714
+ const changes = Diff__namespace.diffWordsWithSpace(
715
+ oldNode2.textContent,
716
+ newNode2.textContent
717
+ );
718
+ const parts = changes.map((c) => ({
719
+ type: c.added ? "insert" : c.removed ? "delete" : "equal",
720
+ value: c.value
721
+ }));
722
+ currentDiffs.push({ type: "removed", oldNode: oldNode2, parts });
723
+ currentDiffs.push({ type: "added", newNode: newNode2, parts });
724
+ } else if (hasOld) {
725
+ currentDiffs.push({ type: "removed", oldNode: oldBlocks[oi + k] });
726
+ } else {
727
+ currentDiffs.push({ type: "added", newNode: newBlocks[ni + k] });
728
+ }
729
+ pushChunk(currentDiffs);
730
+ }
731
+ const oldNode = oldBlocks[pi];
732
+ const newNode = newBlocks[pj];
733
+ if (oldNode.textContent === newNode.textContent && oldNode.eq(newNode)) {
734
+ pushChunk([{ type: "unchanged", oldNode, newNode }]);
735
+ } else {
736
+ const changes = Diff__namespace.diffWordsWithSpace(
737
+ oldNode.textContent,
738
+ newNode.textContent
739
+ );
740
+ const parts = changes.map((c) => ({
741
+ type: c.added ? "insert" : c.removed ? "delete" : "equal",
742
+ value: c.value
743
+ }));
744
+ pushChunk([
745
+ { type: "removed", oldNode, parts },
746
+ { type: "added", newNode, parts }
747
+ ]);
748
+ }
749
+ oi = pi + 1;
750
+ ni = pj + 1;
751
+ }
752
+ const trailOld = oldBlocks.length - oi;
753
+ const trailNew = newBlocks.length - ni;
754
+ const trailMax = Math.max(trailOld, trailNew);
755
+ for (let k = 0; k < trailMax; k++) {
756
+ const hasOld = oi + k < oldBlocks.length;
757
+ const hasNew = ni + k < newBlocks.length;
758
+ const currentDiffs = [];
759
+ if (hasOld && hasNew) {
760
+ const oldNode = oldBlocks[oi + k];
761
+ const newNode = newBlocks[ni + k];
762
+ const changes = Diff__namespace.diffWordsWithSpace(
763
+ oldNode.textContent,
764
+ newNode.textContent
765
+ );
766
+ const parts = changes.map((c) => ({
767
+ type: c.added ? "insert" : c.removed ? "delete" : "equal",
768
+ value: c.value
769
+ }));
770
+ currentDiffs.push({ type: "removed", oldNode, parts });
771
+ currentDiffs.push({ type: "added", newNode, parts });
772
+ } else if (hasOld) {
773
+ currentDiffs.push({ type: "removed", oldNode: oldBlocks[oi + k] });
774
+ } else {
775
+ currentDiffs.push({ type: "added", newNode: newBlocks[ni + k] });
776
+ }
777
+ pushChunk(currentDiffs);
778
+ }
779
+ return result;
780
+ }
781
+
782
+ function buildNewDoc(chunks, schema) {
783
+ var _a, _b, _c, _d;
784
+ const children = [];
785
+ const pending = [];
786
+ for (const chunk of chunks) {
787
+ if (chunk.status === "accepted") {
788
+ for (const diff of chunk.diffs) {
789
+ if (diff.type === "added") children.push(diff.newNode);
790
+ if (diff.type === "unchanged") children.push(diff.newNode);
791
+ }
792
+ } else if (chunk.status === "rejected") {
793
+ for (const diff of chunk.diffs) {
794
+ if (diff.type === "removed") children.push(diff.oldNode);
795
+ if (diff.type === "unchanged") children.push(diff.oldNode);
796
+ }
797
+ } else {
798
+ for (const diff of chunk.diffs) {
799
+ if (diff.type === "unchanged") {
800
+ children.push(diff.newNode);
801
+ } else if (diff.type === "added") {
802
+ pending.push({
803
+ type: "added",
804
+ childIndex: children.length,
805
+ oldText: "",
806
+ newText: (_b = (_a = diff.newNode) == null ? void 0 : _a.textContent) != null ? _b : "",
807
+ parts: diff.parts,
808
+ chunkId: chunk.id
809
+ });
810
+ children.push(diff.newNode);
811
+ } else if (diff.type === "removed") {
812
+ pending.push({
813
+ type: "removed",
814
+ childIndex: children.length,
815
+ oldText: (_d = (_c = diff.oldNode) == null ? void 0 : _c.textContent) != null ? _d : "",
816
+ newText: "",
817
+ parts: diff.parts,
818
+ chunkId: chunk.id
819
+ });
820
+ children.push(diff.oldNode);
821
+ }
822
+ }
823
+ }
824
+ }
825
+ if (children.length === 0) {
826
+ children.push(schema.node("paragraph", null, []));
827
+ }
828
+ const doc = schema.node("doc", null, children);
829
+ let pos = 0;
830
+ const positions = [];
831
+ for (const child of children) {
832
+ positions.push({ from: pos, to: pos + child.nodeSize });
833
+ pos += child.nodeSize;
834
+ }
835
+ const changes = pending.map((pc) => {
836
+ var _a2, _b2;
837
+ const cp = positions[pc.childIndex];
838
+ const inlineRanges = [];
839
+ let offset = cp.from + 1;
840
+ if (pc.type === "removed") {
841
+ for (const part of (_a2 = pc.parts) != null ? _a2 : []) {
842
+ if (part.type === "delete") {
843
+ inlineRanges.push({ from: offset, to: offset + part.value.length });
844
+ offset += part.value.length;
845
+ } else if (part.type === "equal") {
846
+ offset += part.value.length;
847
+ }
848
+ }
849
+ return {
850
+ type: "removed",
851
+ from: cp.from,
852
+ oldText: pc.oldText,
853
+ newText: "",
854
+ blockRange: { from: cp.from, to: cp.to },
855
+ inlineRanges,
856
+ chunkId: pc.chunkId
857
+ };
858
+ }
859
+ for (const part of (_b2 = pc.parts) != null ? _b2 : []) {
860
+ if (part.type === "insert") {
861
+ inlineRanges.push({ from: offset, to: offset + part.value.length });
862
+ offset += part.value.length;
863
+ } else if (part.type === "equal") {
864
+ offset += part.value.length;
865
+ }
866
+ }
867
+ return {
868
+ type: "added",
869
+ from: cp.from,
870
+ oldText: "",
871
+ newText: pc.newText,
872
+ blockRange: { from: cp.from, to: cp.to },
873
+ inlineRanges,
874
+ chunkId: pc.chunkId
875
+ };
876
+ });
877
+ return { doc, changes };
878
+ }
879
+
880
+ var __typeError = (msg) => {
881
+ throw TypeError(msg);
882
+ };
883
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
884
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), member.get(obj));
885
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
886
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
887
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
888
+ var _ctx, _view, _isActive, _panelApp, _panelContainer, _resizeObserver, _scrollContainers, _updateGeometry, _originalEditable, _chunks, _schema, _render, _InlineDiffView_instances, scrollTo_fn, createPanel_fn, removePanel_fn;
889
+ const inlineDiffKey = new state.PluginKey("CREPE_INLINE_DIFF");
890
+ const PANEL_WIDTH = 280;
891
+ let sharedDecorationSet = view.DecorationSet.empty;
892
+ class InlineDiffView {
893
+ constructor(ctx, view$1) {
894
+ __privateAdd(this, _InlineDiffView_instances);
895
+ __privateAdd(this, _ctx);
896
+ __privateAdd(this, _view);
897
+ __privateAdd(this, _isActive, false);
898
+ __privateAdd(this, _panelApp, null);
899
+ __privateAdd(this, _panelContainer, null);
900
+ __privateAdd(this, _resizeObserver, null);
901
+ __privateAdd(this, _scrollContainers, []);
902
+ __privateAdd(this, _updateGeometry, null);
903
+ __privateAdd(this, _originalEditable, null);
904
+ __privateAdd(this, _chunks, []);
905
+ __privateAdd(this, _schema, null);
906
+ this.showDiff = (oldMarkdown, newMarkdown) => {
907
+ if (__privateGet(this, _isActive)) return;
908
+ const parser = __privateGet(this, _ctx).get(core.parserCtx);
909
+ __privateSet(this, _schema, __privateGet(this, _view).state.schema);
910
+ let oldDoc;
911
+ let newDoc;
912
+ try {
913
+ oldDoc = parser(oldMarkdown);
914
+ if (typeof newMarkdown === "string" && newMarkdown.trim() !== "") {
915
+ newDoc = parser(newMarkdown);
916
+ } else {
917
+ newDoc = __privateGet(this, _view).state.doc;
918
+ }
919
+ } catch (e) {
920
+ return;
921
+ }
922
+ const oldBlocks = [];
923
+ const newBlocks = [];
924
+ oldDoc.forEach((node) => oldBlocks.push(node));
925
+ newDoc.forEach((node) => newBlocks.push(node));
926
+ __privateSet(this, _chunks, computeDiff(oldBlocks, newBlocks));
927
+ const { changes } = buildNewDoc(__privateGet(this, _chunks), __privateGet(this, _schema));
928
+ if (changes.length === 0) {
929
+ return;
930
+ }
931
+ if (!__privateGet(this, _originalEditable)) {
932
+ __privateSet(this, _originalEditable, __privateGet(this, _view).someProp("editable") || (() => true));
933
+ }
934
+ __privateGet(this, _view).setProps({
935
+ editable: () => false
936
+ });
937
+ __privateSet(this, _isActive, true);
938
+ __privateGet(this, _render).call(this, true);
939
+ };
940
+ __privateAdd(this, _render, (initPanel = false) => {
941
+ const { doc: newDocWithPos, changes } = buildNewDoc(
942
+ __privateGet(this, _chunks),
943
+ __privateGet(this, _schema)
944
+ );
945
+ const acceptText = i18n(__privateGet(this, _ctx), "inlineDiff.accept");
946
+ const rejectText = i18n(__privateGet(this, _ctx), "inlineDiff.reject");
947
+ const ds = buildDecorations(
948
+ newDocWithPos,
949
+ changes,
950
+ (id) => this.acceptChunk(id),
951
+ (id) => this.rejectChunk(id),
952
+ acceptText,
953
+ rejectText
954
+ );
955
+ sharedDecorationSet = ds;
956
+ const tr = __privateGet(this, _view).state.tr.replaceWith(
957
+ 0,
958
+ __privateGet(this, _view).state.doc.content.size,
959
+ newDocWithPos.content
960
+ );
961
+ __privateGet(this, _view).dispatch(tr);
962
+ if (initPanel) {
963
+ __privateMethod(this, _InlineDiffView_instances, createPanel_fn).call(this, changes);
964
+ } else if (__privateGet(this, _panelApp)) {
965
+ __privateMethod(this, _InlineDiffView_instances, createPanel_fn).call(this, changes);
966
+ }
967
+ });
968
+ this.acceptChunk = (id) => {
969
+ const chunk = __privateGet(this, _chunks).find((c) => c.id === id);
970
+ if (chunk) {
971
+ chunk.status = "accepted";
972
+ const hasPending = __privateGet(this, _chunks).some(
973
+ (c) => c.status === "pending" && c.diffs.some((d) => d.type !== "unchanged")
974
+ );
975
+ if (!hasPending) {
976
+ this.hideDiff();
977
+ } else {
978
+ __privateGet(this, _render).call(this);
979
+ }
980
+ }
981
+ };
982
+ this.rejectChunk = (id) => {
983
+ const chunk = __privateGet(this, _chunks).find((c) => c.id === id);
984
+ if (chunk) {
985
+ chunk.status = "rejected";
986
+ const hasPending = __privateGet(this, _chunks).some(
987
+ (c) => c.status === "pending" && c.diffs.some((d) => d.type !== "unchanged")
988
+ );
989
+ if (!hasPending) {
990
+ this.hideDiff();
991
+ } else {
992
+ __privateGet(this, _render).call(this);
993
+ }
994
+ }
995
+ };
996
+ this.hideDiff = () => {
997
+ if (!__privateGet(this, _isActive)) return;
998
+ __privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
999
+ for (const chunk of __privateGet(this, _chunks)) {
1000
+ if (chunk.status === "pending") {
1001
+ chunk.status = "accepted";
1002
+ }
1003
+ }
1004
+ const { doc: finalDoc } = buildNewDoc(__privateGet(this, _chunks), __privateGet(this, _schema));
1005
+ const tr = __privateGet(this, _view).state.tr.replaceWith(
1006
+ 0,
1007
+ __privateGet(this, _view).state.doc.content.size,
1008
+ finalDoc.content
1009
+ );
1010
+ sharedDecorationSet = view.DecorationSet.empty;
1011
+ __privateSet(this, _isActive, false);
1012
+ __privateSet(this, _chunks, []);
1013
+ __privateGet(this, _view).dispatch(tr);
1014
+ if (__privateGet(this, _originalEditable)) {
1015
+ __privateGet(this, _view).setProps({
1016
+ editable: __privateGet(this, _originalEditable)
1017
+ });
1018
+ __privateSet(this, _originalEditable, null);
1019
+ } else {
1020
+ __privateGet(this, _view).setProps({
1021
+ editable: () => true
1022
+ });
1023
+ }
1024
+ };
1025
+ this.update = (view) => {
1026
+ __privateSet(this, _view, view);
1027
+ };
1028
+ this.destroy = () => {
1029
+ __privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
1030
+ };
1031
+ __privateSet(this, _ctx, ctx);
1032
+ __privateSet(this, _view, view$1);
1033
+ const api = {
1034
+ showDiff: (oldMd, newMd) => this.showDiff(oldMd, newMd),
1035
+ hideDiff: () => this.hideDiff(),
1036
+ isShowing: () => __privateGet(this, _isActive)
1037
+ };
1038
+ ctx.set(inlineDiffApiCtx.key, api);
1039
+ }
1040
+ }
1041
+ _ctx = new WeakMap();
1042
+ _view = new WeakMap();
1043
+ _isActive = new WeakMap();
1044
+ _panelApp = new WeakMap();
1045
+ _panelContainer = new WeakMap();
1046
+ _resizeObserver = new WeakMap();
1047
+ _scrollContainers = new WeakMap();
1048
+ _updateGeometry = new WeakMap();
1049
+ _originalEditable = new WeakMap();
1050
+ _chunks = new WeakMap();
1051
+ _schema = new WeakMap();
1052
+ _render = new WeakMap();
1053
+ _InlineDiffView_instances = new WeakSet();
1054
+ scrollTo_fn = function(pos) {
1055
+ try {
1056
+ const view = __privateGet(this, _view);
1057
+ const coords = view.coordsAtPos(pos);
1058
+ let scrollTarget = view.dom;
1059
+ while (scrollTarget) {
1060
+ const { overflowY } = getComputedStyle(scrollTarget);
1061
+ if ((overflowY === "auto" || overflowY === "scroll") && scrollTarget.scrollHeight > scrollTarget.clientHeight) {
1062
+ break;
1063
+ }
1064
+ scrollTarget = scrollTarget.parentElement;
1065
+ }
1066
+ if (scrollTarget) {
1067
+ const targetRect = scrollTarget.getBoundingClientRect();
1068
+ const scrollOffset = coords.top - targetRect.top + scrollTarget.scrollTop - 60;
1069
+ scrollTarget.scrollTo({ top: scrollOffset, behavior: "smooth" });
1070
+ } else {
1071
+ window.scrollTo({
1072
+ top: coords.top + window.scrollY - 100,
1073
+ behavior: "smooth"
1074
+ });
1075
+ }
1076
+ } catch (e) {
1077
+ }
1078
+ };
1079
+ createPanel_fn = function(changes) {
1080
+ __privateMethod(this, _InlineDiffView_instances, removePanel_fn).call(this);
1081
+ const editorContainer = __privateGet(this, _view).dom.parentElement;
1082
+ if (!editorContainer) return;
1083
+ const root = editorContainer.parentElement;
1084
+ if (!root) return;
1085
+ const container = document.createElement("div");
1086
+ container.style.position = "fixed";
1087
+ container.style.zIndex = "100";
1088
+ container.style.width = `${PANEL_WIDTH}px`;
1089
+ container.style.overflow = "hidden";
1090
+ container.style.borderLeft = "1px solid var(--crepe-color-outline-variant, color-mix(in srgb, var(--crepe-color-outline, #ddd), transparent 80%))";
1091
+ container.style.backgroundColor = "var(--crepe-color-surface, #fff)";
1092
+ root.appendChild(container);
1093
+ __privateSet(this, _panelContainer, container);
1094
+ editorContainer.style.paddingRight = `${PANEL_WIDTH}px`;
1095
+ __privateSet(this, _panelApp, mountChangePanel(
1096
+ container,
1097
+ changes,
1098
+ (from) => __privateMethod(this, _InlineDiffView_instances, scrollTo_fn).call(this, from),
1099
+ () => this.hideDiff()
1100
+ ));
1101
+ __privateSet(this, _updateGeometry, () => {
1102
+ const rootRect = root.getBoundingClientRect();
1103
+ let top = rootRect.top;
1104
+ const toolbar = root.querySelector(
1105
+ ".milkdown-fixed-toolbar"
1106
+ );
1107
+ if (toolbar && toolbar.offsetHeight > 0) {
1108
+ const toolbarRect = toolbar.getBoundingClientRect();
1109
+ top = Math.max(top, toolbarRect.bottom);
1110
+ }
1111
+ const coverEl = root.querySelector(
1112
+ ".milkdown-document-cover"
1113
+ );
1114
+ if (coverEl && coverEl.offsetHeight > 0) {
1115
+ top = Math.max(top, coverEl.getBoundingClientRect().bottom);
1116
+ }
1117
+ let height = window.innerHeight - top;
1118
+ if (top + height > rootRect.bottom) {
1119
+ height = Math.max(0, rootRect.bottom - top);
1120
+ }
1121
+ container.style.top = `${top}px`;
1122
+ container.style.height = `${height}px`;
1123
+ container.style.left = "auto";
1124
+ let baseOffset = window.innerWidth - rootRect.right;
1125
+ let rightOffset = baseOffset;
1126
+ let hasVScroll = false;
1127
+ if (document.documentElement.scrollHeight > window.innerHeight) {
1128
+ hasVScroll = true;
1129
+ }
1130
+ let parent = root;
1131
+ while (parent && parent !== document.body) {
1132
+ const { overflowY } = getComputedStyle(parent);
1133
+ if (overflowY === "auto" || overflowY === "scroll") {
1134
+ if (parent.scrollHeight > parent.clientHeight) {
1135
+ hasVScroll = true;
1136
+ break;
1137
+ }
1138
+ }
1139
+ parent = parent.parentElement;
1140
+ }
1141
+ if (hasVScroll) {
1142
+ rightOffset = Math.max(rightOffset, 32);
1143
+ } else {
1144
+ rightOffset = Math.max(rightOffset, 0);
1145
+ }
1146
+ container.style.right = `${rightOffset}px`;
1147
+ editorContainer.style.paddingRight = `${PANEL_WIDTH}px`;
1148
+ });
1149
+ __privateGet(this, _updateGeometry).call(this);
1150
+ setTimeout(() => {
1151
+ var _a;
1152
+ (_a = __privateGet(this, _updateGeometry)) == null ? void 0 : _a.call(this);
1153
+ }, 100);
1154
+ __privateSet(this, _resizeObserver, new ResizeObserver(__privateGet(this, _updateGeometry)));
1155
+ __privateGet(this, _resizeObserver).observe(root);
1156
+ window.addEventListener("resize", __privateGet(this, _updateGeometry));
1157
+ window.addEventListener("scroll", __privateGet(this, _updateGeometry), {
1158
+ capture: true,
1159
+ passive: true
1160
+ });
1161
+ let scrollerNode = root;
1162
+ while (scrollerNode && scrollerNode !== document) {
1163
+ if (scrollerNode instanceof Element) {
1164
+ scrollerNode.addEventListener("scroll", __privateGet(this, _updateGeometry), {
1165
+ passive: true
1166
+ });
1167
+ __privateGet(this, _scrollContainers).push(scrollerNode);
1168
+ }
1169
+ scrollerNode = scrollerNode.parentNode || scrollerNode.host;
1170
+ }
1171
+ };
1172
+ removePanel_fn = function() {
1173
+ if (__privateGet(this, _panelApp)) {
1174
+ __privateGet(this, _panelApp).unmount();
1175
+ __privateSet(this, _panelApp, null);
1176
+ }
1177
+ if (__privateGet(this, _panelContainer)) {
1178
+ __privateGet(this, _panelContainer).remove();
1179
+ __privateSet(this, _panelContainer, null);
1180
+ }
1181
+ if (__privateGet(this, _resizeObserver)) {
1182
+ __privateGet(this, _resizeObserver).disconnect();
1183
+ __privateSet(this, _resizeObserver, null);
1184
+ }
1185
+ if (__privateGet(this, _updateGeometry)) {
1186
+ window.removeEventListener("resize", __privateGet(this, _updateGeometry));
1187
+ window.removeEventListener("scroll", __privateGet(this, _updateGeometry), {
1188
+ capture: true
1189
+ });
1190
+ for (const container of __privateGet(this, _scrollContainers)) {
1191
+ container.removeEventListener("scroll", __privateGet(this, _updateGeometry));
1192
+ }
1193
+ __privateSet(this, _scrollContainers, []);
1194
+ __privateSet(this, _updateGeometry, null);
1195
+ }
1196
+ const editorContainer = __privateGet(this, _view).dom.parentElement;
1197
+ if (editorContainer) {
1198
+ editorContainer.style.paddingRight = "";
1199
+ }
1200
+ };
1201
+ function buildDecorations(doc, changes, onAccept, onReject, acceptText, rejectText) {
1202
+ const decorations = [];
1203
+ const addedWidgets = /* @__PURE__ */ new Set();
1204
+ for (const change of changes) {
1205
+ if (!addedWidgets.has(change.chunkId)) {
1206
+ addedWidgets.add(change.chunkId);
1207
+ decorations.push(
1208
+ view.Decoration.widget(
1209
+ change.blockRange.from,
1210
+ () => {
1211
+ const wrapper = document.createElement("div");
1212
+ wrapper.style.position = "relative";
1213
+ wrapper.style.width = "100%";
1214
+ wrapper.style.height = "0";
1215
+ wrapper.style.overflow = "visible";
1216
+ const container = document.createElement("div");
1217
+ container.className = "crepe-diff-actions";
1218
+ container.style.position = "absolute";
1219
+ container.style.right = "4px";
1220
+ container.style.top = "4px";
1221
+ container.style.zIndex = "10";
1222
+ container.style.display = "flex";
1223
+ container.style.gap = "4px";
1224
+ const btnAccept = document.createElement("button");
1225
+ btnAccept.textContent = acceptText;
1226
+ btnAccept.style.backgroundColor = "#2ea043";
1227
+ btnAccept.style.color = "white";
1228
+ btnAccept.style.border = "none";
1229
+ btnAccept.style.borderRadius = "4px";
1230
+ btnAccept.style.padding = "2px 8px";
1231
+ btnAccept.style.cursor = "pointer";
1232
+ btnAccept.style.fontSize = "12px";
1233
+ btnAccept.addEventListener("mousedown", (e) => {
1234
+ e.preventDefault();
1235
+ onAccept(change.chunkId);
1236
+ });
1237
+ const btnReject = document.createElement("button");
1238
+ btnReject.textContent = rejectText;
1239
+ btnReject.style.backgroundColor = "#f85149";
1240
+ btnReject.style.color = "white";
1241
+ btnReject.style.border = "none";
1242
+ btnReject.style.borderRadius = "4px";
1243
+ btnReject.style.padding = "2px 8px";
1244
+ btnReject.style.cursor = "pointer";
1245
+ btnReject.style.fontSize = "12px";
1246
+ btnReject.addEventListener("mousedown", (e) => {
1247
+ e.preventDefault();
1248
+ onReject(change.chunkId);
1249
+ });
1250
+ container.appendChild(btnAccept);
1251
+ container.appendChild(btnReject);
1252
+ wrapper.appendChild(container);
1253
+ return wrapper;
1254
+ },
1255
+ { side: -1 }
1256
+ )
1257
+ );
1258
+ }
1259
+ const blockCls = change.type === "added" ? "crepe-diff-added" : "crepe-diff-deleted";
1260
+ decorations.push(
1261
+ view.Decoration.node(change.blockRange.from, change.blockRange.to, {
1262
+ class: blockCls
1263
+ })
1264
+ );
1265
+ const inlineCls = change.type === "added" ? "crepe-diff-inline-added" : "crepe-diff-inline-deleted";
1266
+ for (const r of change.inlineRanges) {
1267
+ if (r.to > r.from) {
1268
+ decorations.push(view.Decoration.inline(r.from, r.to, { class: inlineCls }));
1269
+ }
1270
+ }
1271
+ }
1272
+ return view.DecorationSet.create(doc, decorations);
1273
+ }
1274
+ const inlineDiffPlugin = utils.$prose((ctx) => {
1275
+ return new state.Plugin({
1276
+ key: inlineDiffKey,
1277
+ view: (view) => new InlineDiffView(ctx, view),
1278
+ props: {
1279
+ decorations: () => sharedDecorationSet
1280
+ }
1281
+ });
1282
+ });
1283
+ const inlineDiff = (editor, config) => {
1284
+ editor.config(crepeFeatureConfig(CrepeFeature.InlineDiff)).config((ctx) => {
1285
+ if (config) {
1286
+ ctx.update(inlineDiffConfig.key, (prev) => ({
1287
+ ...prev,
1288
+ ...config
1289
+ }));
1290
+ }
1291
+ }).use(inlineDiffApiCtx).use(inlineDiffConfig).use(inlineDiffPlugin);
1292
+ };
1293
+
1294
+ exports.inlineDiff = inlineDiff;
1295
+ exports.inlineDiffApiCtx = inlineDiffApiCtx;
1296
+ exports.inlineDiffKey = inlineDiffKey;
1297
+ exports.inlineDiffPlugin = inlineDiffPlugin;
1298
+ //# sourceMappingURL=index.js.map