@jvs-milkdown/crepe 1.2.13 → 1.2.14

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