markloom 0.5.1 → 0.7.0
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.
- package/PACKAGES.md +26 -0
- package/README.md +20 -2
- package/collab.md +60 -13
- package/dist/ai/index.cjs +5 -4
- package/dist/ai/index.d.cts +5 -4
- package/dist/ai/index.d.ts +5 -4
- package/dist/ai/index.js +4 -3
- package/dist/ai/theme.css +66 -102
- package/dist/{chunk-ZMTLSFLO.js → chunk-4Q7PAR2T.js} +5746 -1341
- package/dist/chunk-75EJ4ARB.cjs +642 -0
- package/dist/{chunk-JS527FDV.cjs → chunk-BMPCVT3B.cjs} +47 -39
- package/dist/{chunk-RLTHVQNQ.js → chunk-EFYT2223.js} +47 -39
- package/dist/chunk-HXABDVLZ.cjs +297 -0
- package/dist/{chunk-YIFOGP2D.cjs → chunk-I2LDEVLA.cjs} +499 -102
- package/dist/chunk-MQLRZQZL.js +642 -0
- package/dist/chunk-OVHASRID.cjs +4279 -0
- package/dist/chunk-PCSVBPOR.cjs +40 -0
- package/dist/{chunk-FCH7LZFI.js → chunk-PSAXWBNM.js} +450 -53
- package/dist/chunk-PZRWTLLB.cjs +858 -0
- package/dist/chunk-QO7JEZDB.js +4279 -0
- package/dist/chunk-WSJUXPAG.js +40 -0
- package/dist/{chunk-VXM7Q6P5.cjs → chunk-Y4IXQFWL.cjs} +6026 -1621
- package/dist/chunk-YLVSMDIO.js +858 -0
- package/dist/chunk-ZL6WT6OY.js +297 -0
- package/dist/client-BvvyHjhh.d.ts +250 -0
- package/dist/client-Ciy7Fa_k.d.cts +250 -0
- package/dist/collab/index.cjs +17 -4
- package/dist/collab/index.d.cts +18 -7
- package/dist/collab/index.d.ts +18 -7
- package/dist/collab/index.js +19 -6
- package/dist/{controller-DQITsFhy.d.cts → controller-CHznEhAR.d.cts} +277 -26
- package/dist/{controller-BNuuUM3E.d.ts → controller-DLqI8_jm.d.ts} +277 -26
- package/dist/index.cjs +119 -7
- package/dist/index.d.cts +138 -6
- package/dist/index.d.ts +138 -6
- package/dist/index.js +130 -18
- package/dist/io/index.cjs +1412 -0
- package/dist/io/index.d.cts +33 -0
- package/dist/io/index.d.ts +33 -0
- package/dist/io/index.js +1412 -0
- package/dist/react/index.cjs +9 -8
- package/dist/react/index.d.cts +5 -4
- package/dist/react/index.d.ts +5 -4
- package/dist/react/index.js +8 -7
- package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-CSnv8FKp.d.ts} +11 -9
- package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-DO1ygkx9.d.cts} +11 -9
- package/dist/types-BkHlmUFL.d.cts +34 -0
- package/dist/types-BkHlmUFL.d.ts +34 -0
- package/dist/versions-DNFf8zVz.d.cts +51 -0
- package/dist/versions-DOkOyh2J.d.ts +51 -0
- package/dist/view/index.cjs +259 -17
- package/dist/view/index.d.cts +277 -12
- package/dist/view/index.d.ts +277 -12
- package/dist/view/index.js +256 -14
- package/dist/view/theme.css +2093 -1577
- package/dist/word-count-BPw9G2Bg.d.ts +130 -0
- package/dist/word-count-DNLn1h_t.d.cts +130 -0
- package/io.md +38 -0
- package/package.json +25 -4
- package/dist/chunk-4JSJAHTB.js +0 -255
- package/dist/chunk-4TMHVNL6.cjs +0 -2297
- package/dist/chunk-ALZ3A5CS.cjs +0 -255
- package/dist/chunk-GQ2HHRGI.cjs +0 -16
- package/dist/chunk-LA5SBCGQ.js +0 -16
- package/dist/chunk-LEYAQNJA.js +0 -220
- package/dist/chunk-MFYF2A6U.js +0 -2297
- package/dist/chunk-YXQDCW4Y.cjs +0 -220
- package/dist/client-6KiH4kGK.d.ts +0 -144
- package/dist/client-ZRZj2nkq.d.cts +0 -144
- package/dist/comments-DlExS6f-.d.cts +0 -43
- package/dist/comments-PhnR7Gkn.d.ts +0 -43
- package/dist/step-BrvHIK7O.d.cts +0 -65
- package/dist/step-BrvHIK7O.d.ts +0 -65
|
@@ -4,16 +4,330 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
var _chunkOVHASRIDcjs = require('./chunk-OVHASRID.cjs');
|
|
7
8
|
|
|
8
|
-
var _chunk4TMHVNL6cjs = require('./chunk-4TMHVNL6.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkHXABDVLZcjs = require('./chunk-HXABDVLZ.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkPCSVBPORcjs = require('./chunk-PCSVBPOR.cjs');
|
|
19
|
+
|
|
20
|
+
// src/i18n.ts
|
|
21
|
+
var KEY = "__markloom_locale__";
|
|
22
|
+
var g = globalThis;
|
|
23
|
+
function setLocale(l) {
|
|
24
|
+
g[KEY] = l === "en" ? "en" : "zh";
|
|
25
|
+
}
|
|
26
|
+
function getLocale() {
|
|
27
|
+
return g[KEY] === "en" ? "en" : "zh";
|
|
28
|
+
}
|
|
29
|
+
var MESSAGES = {
|
|
30
|
+
// —— 块类型(斜杠菜单 / 悬停手柄 / 浮动工具条共用) ——
|
|
31
|
+
blkParagraph: ["\u6B63\u6587", "Text"],
|
|
32
|
+
blkH1: ["\u6807\u9898 1", "Heading 1"],
|
|
33
|
+
blkH2: ["\u6807\u9898 2", "Heading 2"],
|
|
34
|
+
blkH3: ["\u6807\u9898 3", "Heading 3"],
|
|
35
|
+
blkBullet: ["\u65E0\u5E8F\u5217\u8868", "Bulleted list"],
|
|
36
|
+
blkOrdered: ["\u6709\u5E8F\u5217\u8868", "Numbered list"],
|
|
37
|
+
blkTask: ["\u4EFB\u52A1\u5217\u8868", "Task list"],
|
|
38
|
+
blkQuote: ["\u5F15\u7528", "Quote"],
|
|
39
|
+
blkCallout: ["\u9AD8\u4EAE\u5757", "Callout"],
|
|
40
|
+
blkCode: ["\u4EE3\u7801\u5757", "Code block"],
|
|
41
|
+
// —— 斜杠菜单 ——
|
|
42
|
+
aiWrite: ["AI \u5199\u4F5C", "Write with AI"],
|
|
43
|
+
insTable: ["\u8868\u683C", "Table"],
|
|
44
|
+
insImage: ["\u56FE\u7247", "Image"],
|
|
45
|
+
insMath: ["\u516C\u5F0F", "Math"],
|
|
46
|
+
insAudio: ["\u97F3\u9891", "Audio"],
|
|
47
|
+
insFile: ["\u6587\u4EF6", "File"],
|
|
48
|
+
insHr: ["\u5206\u5272\u7EBF", "Divider"],
|
|
49
|
+
// —— 通用 ——
|
|
50
|
+
alignLeft: ["\u5DE6\u5BF9\u9F50", "Align left"],
|
|
51
|
+
alignCenterShort: ["\u5C45\u4E2D", "Center"],
|
|
52
|
+
alignRight: ["\u53F3\u5BF9\u9F50", "Align right"],
|
|
53
|
+
cancel: ["\u53D6\u6D88", "Cancel"],
|
|
54
|
+
ok: ["\u786E\u5B9A", "OK"],
|
|
55
|
+
confirm: ["\u786E\u8BA4", "Confirm"],
|
|
56
|
+
save: ["\u4FDD\u5B58", "Save"],
|
|
57
|
+
delete: ["\u5220\u9664", "Delete"],
|
|
58
|
+
send: ["\u53D1\u9001", "Send"],
|
|
59
|
+
apply: ["\u5E94\u7528", "Apply"],
|
|
60
|
+
insert: ["\u63D2\u5165", "Insert"],
|
|
61
|
+
comment: ["\u8BC4\u8BBA", "Comment"],
|
|
62
|
+
me: ["\u6211", "Me"],
|
|
63
|
+
// —— 浮动工具条 ——
|
|
64
|
+
bbHeading1: ["\u4E00\u7EA7\u6807\u9898", "Heading 1"],
|
|
65
|
+
bbHeading2: ["\u4E8C\u7EA7\u6807\u9898", "Heading 2"],
|
|
66
|
+
bbHeading3: ["\u4E09\u7EA7\u6807\u9898", "Heading 3"],
|
|
67
|
+
bbTask: ["\u4EFB\u52A1", "Task"],
|
|
68
|
+
bbBold: ["\u7C97\u4F53", "Bold"],
|
|
69
|
+
bbStrike: ["\u5220\u9664\u7EBF", "Strikethrough"],
|
|
70
|
+
bbItalic: ["\u659C\u4F53", "Italic"],
|
|
71
|
+
bbUnderline: ["\u4E0B\u5212\u7EBF", "Underline"],
|
|
72
|
+
bbHighlight: ["\u9AD8\u4EAE", "Highlight"],
|
|
73
|
+
mdText: ["\u6587\u672C", "text"],
|
|
74
|
+
mdSpace: ["\u7A7A\u683C", "Space"],
|
|
75
|
+
bbTextAndHeading: ["\u6B63\u6587\u4E0E\u6807\u9898", "Text and headings"],
|
|
76
|
+
bbAlignIndent: ["\u5BF9\u9F50\u4E0E\u7F29\u8FDB", "Align and indent"],
|
|
77
|
+
bbAlignCenter: ["\u5C45\u4E2D\u5BF9\u9F50", "Align center"],
|
|
78
|
+
bbIndentMore: ["\u589E\u52A0\u7F29\u8FDB", "Increase indent"],
|
|
79
|
+
bbIndentLess: ["\u51CF\u5C11\u7F29\u8FDB", "Decrease indent"],
|
|
80
|
+
bbLink: ["\u94FE\u63A5", "Link"],
|
|
81
|
+
bbInlineCode: ["\u884C\u5185\u4EE3\u7801", "Inline code"],
|
|
82
|
+
bbClear: ["\u6E05\u9664\u683C\u5F0F", "Clear formatting"],
|
|
83
|
+
bbColorHighlight: ["\u6587\u5B57\u989C\u8272\u4E0E\u9AD8\u4EAE", "Text color and highlight"],
|
|
84
|
+
bbFontColor: ["\u5B57\u4F53\u989C\u8272", "Text color"],
|
|
85
|
+
bbBgColor: ["\u80CC\u666F\u989C\u8272", "Highlight color"],
|
|
86
|
+
bbReset: ["\u6062\u590D\u9ED8\u8BA4", "Reset"],
|
|
87
|
+
bbAiContinue: ["AI \u7EED\u5199", "Continue with AI"],
|
|
88
|
+
bbContinue: ["\u7EED\u5199", "Continue"],
|
|
89
|
+
bbAiRewrite: ["AI \u6539\u5199", "Rewrite with AI"],
|
|
90
|
+
bbRewrite: ["\u6539\u5199", "Rewrite"],
|
|
91
|
+
// —— 颜色名 ——
|
|
92
|
+
colDefault: ["\u9ED8\u8BA4", "Default"],
|
|
93
|
+
colNone: ["\u65E0", "None"],
|
|
94
|
+
colGray: ["\u7070", "Gray"],
|
|
95
|
+
colDarkGray: ["\u6DF1\u7070", "Dark gray"],
|
|
96
|
+
colRed: ["\u7EA2", "Red"],
|
|
97
|
+
colOrange: ["\u6A59", "Orange"],
|
|
98
|
+
colYellow: ["\u9EC4", "Yellow"],
|
|
99
|
+
colGreen: ["\u7EFF", "Green"],
|
|
100
|
+
colBlue: ["\u84DD", "Blue"],
|
|
101
|
+
colPurple: ["\u7D2B", "Purple"],
|
|
102
|
+
colLightGray: ["\u6D45\u7070", "Light gray"],
|
|
103
|
+
colLightRed: ["\u6D45\u7EA2", "Light red"],
|
|
104
|
+
colLightOrange: ["\u6D45\u6A59", "Light orange"],
|
|
105
|
+
colLightYellow: ["\u6D45\u9EC4", "Light yellow"],
|
|
106
|
+
colLightGreen: ["\u6D45\u7EFF", "Light green"],
|
|
107
|
+
colLightBlue: ["\u6D45\u84DD", "Light blue"],
|
|
108
|
+
colLightPurple: ["\u6D45\u7D2B", "Light purple"],
|
|
109
|
+
// —— 悬停手柄 ——
|
|
110
|
+
dhMove: ["\u62D6\u62FD\u79FB\u52A8 \xB7 \u60AC\u505C\u683C\u5F0F", "Drag to move \xB7 hover for options"],
|
|
111
|
+
dhInsert: ["\u63D2\u5165\u5185\u5BB9", "Insert"],
|
|
112
|
+
dhExpand: ["\u5C55\u5F00", "Expand"],
|
|
113
|
+
dhCollapse: ["\u6298\u53E0", "Collapse"],
|
|
114
|
+
// —— 表格 ——
|
|
115
|
+
tcGrip: ["\u9009\u4E2D/\u79FB\u52A8\u8868\u683C", "Select or move table"],
|
|
116
|
+
tcInsertCol: ["\u63D2\u5165\u5217", "Insert column"],
|
|
117
|
+
tcInsertRow: ["\u63D2\u5165\u884C", "Insert row"],
|
|
118
|
+
tcColLeft: ["\u5DE6\u4FA7\u63D2\u5165\u5217", "Insert column left"],
|
|
119
|
+
tcColRight: ["\u53F3\u4FA7\u63D2\u5165\u5217", "Insert column right"],
|
|
120
|
+
tcDelCol: ["\u5220\u9664\u5217", "Delete column"],
|
|
121
|
+
tcHeaderCol: ["\u5207\u6362\u8868\u5934\u5217", "Header column"],
|
|
122
|
+
tcRowAbove: ["\u4E0A\u65B9\u63D2\u5165\u884C", "Insert row above"],
|
|
123
|
+
tcRowBelow: ["\u4E0B\u65B9\u63D2\u5165\u884C", "Insert row below"],
|
|
124
|
+
tcDelRow: ["\u5220\u9664\u884C", "Delete row"],
|
|
125
|
+
tcMerge: ["\u5408\u5E76\u5355\u5143\u683C", "Merge cells"],
|
|
126
|
+
tcSplit: ["\u62C6\u5206\u5355\u5143\u683C", "Split cell"],
|
|
127
|
+
tcBg: ["\u80CC\u666F\u8272", "Cell color"],
|
|
128
|
+
tcClearBg: ["\u6E05\u9664\u80CC\u666F", "Clear color"],
|
|
129
|
+
tcBorder: ["\u8FB9\u6846\u8272", "Border color"],
|
|
130
|
+
tcClearBorder: ["\u6E05\u9664\u8FB9\u6846", "Clear border"],
|
|
131
|
+
tcDelTable: ["\u5220\u9664\u8868\u683C", "Delete table"],
|
|
132
|
+
tcFreezeRow: ["\u51BB\u7ED3\u9996\u884C", "Freeze top row"],
|
|
133
|
+
tcUnfreezeRow: ["\u53D6\u6D88\u51BB\u7ED3\u9996\u884C", "Unfreeze top row"],
|
|
134
|
+
tcFreezeCol: ["\u51BB\u7ED3\u9996\u5217", "Freeze first column"],
|
|
135
|
+
tcUnfreezeCol: ["\u53D6\u6D88\u51BB\u7ED3\u9996\u5217", "Unfreeze first column"],
|
|
136
|
+
tcCellBgAria: ["\u5355\u5143\u683C\u80CC\u666F\u8272", "Cell color"],
|
|
137
|
+
tcCellBorderAria: ["\u5355\u5143\u683C\u8FB9\u6846\u8272", "Cell border color"],
|
|
138
|
+
// —— 图片 ——
|
|
139
|
+
imgPreview: ["\u9884\u89C8", "Preview"],
|
|
140
|
+
imgPreviewAria: ["\u9884\u89C8\u56FE\u7247", "Preview image"],
|
|
141
|
+
imgCaption: ["\u56FE\u6CE8", "Caption"],
|
|
142
|
+
imgCaptionPh: ["\u56FE\u6CE8\u2026", "Add a caption\u2026"],
|
|
143
|
+
// —— 编辑器内的弹层 ——
|
|
144
|
+
mathPh: ["E=mc^2 \u6216 \\frac{a}{b}", "E=mc^2 or \\frac{a}{b}"],
|
|
145
|
+
mathInsertAria: ["\u63D2\u5165\u516C\u5F0F", "Insert math"],
|
|
146
|
+
mathEditAria: ["\u7F16\u8F91\u516C\u5F0F", "Edit math"],
|
|
147
|
+
mathEmpty: ["\u516C\u5F0F\u4E0D\u80FD\u4E3A\u7A7A", "Enter some math first"],
|
|
148
|
+
mathClickEdit: ["\u70B9\u51FB\u7F16\u8F91\u516C\u5F0F", "Click to edit math"],
|
|
149
|
+
embed: ["\u5D4C\u5165", "Embed"],
|
|
150
|
+
embedYt: ["\u5D4C\u5165 YouTube", "Embed YouTube"],
|
|
151
|
+
embedTw: ["\u5D4C\u5165 Twitch", "Embed Twitch"],
|
|
152
|
+
embedNoLink: ["\u8BF7\u8F93\u5165\u94FE\u63A5", "Enter a link"],
|
|
153
|
+
embedBadYt: ["\u65E0\u6CD5\u8BC6\u522B YouTube \u94FE\u63A5", "That isn\u2019t a valid YouTube link"],
|
|
154
|
+
embedBadTw: ["\u65E0\u6CD5\u8BC6\u522B Twitch \u9891\u9053\u94FE\u63A5", "That isn\u2019t a valid Twitch channel link"],
|
|
155
|
+
// —— 提示框 ——
|
|
156
|
+
promptAria: ["\u8F93\u5165", "Input"],
|
|
157
|
+
promptHint: ["\u2318\u21B5 \u786E\u8BA4", "\u2318\u21B5 to confirm"],
|
|
158
|
+
linkPh: ["\u7C98\u8D34\u6216\u8F93\u5165\u94FE\u63A5", "Paste or type a link"],
|
|
159
|
+
linkAria: ["\u6DFB\u52A0\u94FE\u63A5", "Add link"],
|
|
160
|
+
// —— 目录 ——
|
|
161
|
+
tocAria: ["\u76EE\u5F55", "Outline"],
|
|
162
|
+
tocPageAria: ["\u672C\u9875\u76EE\u5F55", "On this page"],
|
|
163
|
+
tocUntitled: ["\u672A\u547D\u540D\u6807\u9898", "Untitled heading"],
|
|
164
|
+
// —— 代码块 ——
|
|
165
|
+
plainText: ["\u7EAF\u6587\u672C", "Plain text"],
|
|
166
|
+
copyCode: ["\u590D\u5236\u4EE3\u7801", "Copy code"],
|
|
167
|
+
// —— 版本 ——
|
|
168
|
+
verTitle: ["\u7248\u672C", "Versions"],
|
|
169
|
+
verEmpty: ["\u5C1A\u65E0\u5FEB\u7167 \xB7 \u2318\u21E7S", "No versions yet \xB7 \u2318\u21E7S"],
|
|
170
|
+
// —— 提及 / 日期 ——
|
|
171
|
+
profStatus: ["\u72B6\u6001", "Status"],
|
|
172
|
+
profEmail: ["\u90AE\u7BB1", "Email"],
|
|
173
|
+
calWeek: ["\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u65E5", "Mo|Tu|We|Th|Fr|Sa|Su"],
|
|
174
|
+
calMonth: ["{y}\u5E74{m}\u6708", "{name} {y}"],
|
|
175
|
+
calNow: ["\u73B0\u5728", "Now"],
|
|
176
|
+
// —— 查找替换 ——
|
|
177
|
+
searchFind: ["\u67E5\u627E", "Find"],
|
|
178
|
+
searchReplaceWith: ["\u66FF\u6362\u4E3A", "Replace with"],
|
|
179
|
+
searchPrev: ["\u4E0A\u4E00\u4E2A", "Previous"],
|
|
180
|
+
searchNext: ["\u4E0B\u4E00\u4E2A", "Next"],
|
|
181
|
+
searchReplace: ["\u66FF\u6362", "Replace"],
|
|
182
|
+
searchAll: ["\u5168\u90E8", "Replace all"],
|
|
183
|
+
close: ["\u5173\u95ED", "Close"],
|
|
184
|
+
// —— 协作 ——
|
|
185
|
+
collabUser: ["\u7528\u6237 {id}", "User {id}"],
|
|
186
|
+
collabUserCaret: ["\u7528\u6237{id}", "User {id}"],
|
|
187
|
+
collabMore: ["\u8FD8\u6709 {n} \u4EBA", "{n} more"],
|
|
188
|
+
collabConnecting: ["{name} \xB7 \u8FDE\u63A5\u4E2D\u2026", "{name} \xB7 Connecting\u2026"],
|
|
189
|
+
collabClosed: ["{name} \xB7 \u5DF2\u65AD\u5F00 \xB7 \u91CD\u8FDE\u4E2D", "{name} \xB7 Offline \xB7 Reconnecting\u2026"],
|
|
190
|
+
collabResyncing: ["{name} \xB7 \u540C\u6B65\u4E2D\u2026", "{name} \xB7 Syncing\u2026"],
|
|
191
|
+
collabConflict: ["{name} \xB7 \u540C\u6B65\u51B2\u7A81 \xB7 \u672C\u5730\u4FEE\u6539\u5DF2\u4FDD\u7559", "{name} \xB7 Sync conflict \xB7 Your changes are kept"],
|
|
192
|
+
collabAuthError: ["{name} \xB7 \u9274\u6743\u5931\u8D25", "{name} \xB7 Sign-in failed"],
|
|
193
|
+
// —— 修订 ——
|
|
194
|
+
sgTrack: ["\u8DDF\u8E2A\u4FEE\u8BA2", "Track changes"],
|
|
195
|
+
sgMarkIns: ["\u6807\u63D2\u5165", "Mark as insertion"],
|
|
196
|
+
sgMarkDel: ["\u6807\u5220\u9664", "Mark as deletion"],
|
|
197
|
+
sgCount: ["{n} \u6761", "{n} changes"],
|
|
198
|
+
sgCount1: ["{n} \u6761", "1 change"],
|
|
199
|
+
sgAccept: ["\u63A5\u53D7", "Accept"],
|
|
200
|
+
sgReject: ["\u62D2\u7EDD", "Reject"],
|
|
201
|
+
sgInsTitle: ["\u5EFA\u8BAE\u63D2\u5165", "Suggested insertion"],
|
|
202
|
+
sgDelTitle: ["\u5EFA\u8BAE\u5220\u9664", "Suggested deletion"],
|
|
203
|
+
// —— 评论栏 ——
|
|
204
|
+
cmtTitle: ["\u8BC4\u8BBA ({n})", "Comments ({n})"],
|
|
205
|
+
cmtOnlyOpen: ["\u53EA\u770B\u672A\u89E3\u51B3", "Show unresolved only"],
|
|
206
|
+
cmtShowResolved: ["\u663E\u793A\u5DF2\u89E3\u51B3", "Show resolved"],
|
|
207
|
+
cmtFilterAll: ["\u5168", "All"],
|
|
208
|
+
cmtFilterOpen: ["\u5F00", "Unresolved"],
|
|
209
|
+
cmtCollapse: ["\u6536\u8D77", "Collapse"],
|
|
210
|
+
cmtAddPh: ["\u6DFB\u52A0\u8BC4\u8BBA\u2026", "Add a comment\u2026"],
|
|
211
|
+
cmtNone: ["\u6682\u65E0\u8BC4\u8BBA", "No comments"],
|
|
212
|
+
cmtNoneOpen: ["\u6682\u65E0\u672A\u89E3\u51B3\u8BC4\u8BBA", "No unresolved comments"],
|
|
213
|
+
cmtResolved: ["\u5DF2\u89E3\u51B3", "Resolved"],
|
|
214
|
+
cmtReopen: ["\u91CD\u65B0\u6253\u5F00", "Reopen"],
|
|
215
|
+
cmtResolve: ["\u89E3\u51B3", "Resolve"],
|
|
216
|
+
cmtReplyPh: ["\u56DE\u590D\u2026", "Reply\u2026"],
|
|
217
|
+
cmtReplies: ["{n} \u6761\u56DE\u590D", "{n} more replies"],
|
|
218
|
+
cmtReply1: ["{n} \u6761\u56DE\u590D", "{n} more reply"],
|
|
219
|
+
// —— 文档内 AI 块 ——
|
|
220
|
+
aiGenerating: ["\u751F\u6210\u4E2D", "Generating"],
|
|
221
|
+
aiPending: ["\u5F85\u786E\u8BA4", "Review"],
|
|
222
|
+
aiFailed: ["\u5931\u8D25", "Failed"],
|
|
223
|
+
aiStop: ["\u505C\u6B62", "Stop"],
|
|
224
|
+
aiStopTitle: ["\u505C\u6B62\u751F\u6210", "Stop generating"],
|
|
225
|
+
aiOriginal: ["\u539F\u6587", "Original"],
|
|
226
|
+
aiPhRewrite: ["\u63CF\u8FF0\u600E\u4E48\u6539\u2026\uFF08\u56DE\u8F66\u751F\u6210\uFF09", "Describe the change\u2026 (Enter to generate)"],
|
|
227
|
+
aiPhWrite: ["\u8F93\u5165\u6307\u4EE4\uFF0C\u56DE\u8F66\u751F\u6210\u2026", "Tell AI what to write\u2026 (Enter to generate)"],
|
|
228
|
+
aiGenerate: ["\u751F\u6210", "Generate"],
|
|
229
|
+
aiNewline: ["\u6362\u884C", "new line"],
|
|
230
|
+
aiStart: ["\u5F00\u59CB\u751F\u6210", "Start generating"],
|
|
231
|
+
aiWritten: ["\u6B63\u6587\u5DF2\u5199\u5165 {n} \u5B57\u2026", "{n} characters written\u2026"],
|
|
232
|
+
aiWriting: ["\u6B63\u5728\u5199\u5165\u6B63\u6587\u2026", "Writing\u2026"],
|
|
233
|
+
aiReview: ["{n} \u5B57\u5DF2\u5199\u5165 \xB7 \u786E\u8BA4\u63D0\u4EA4 / \u4E22\u5F03\u64A4\u56DE", "{n} characters written \xB7 Accept or undo"],
|
|
234
|
+
aiReviewNoCount: ["\u4E0B\u65B9\u6DE1\u5316\u6587\u5B57\u5DF2\u5728\u6587\u6863\u4E2D", "The faded text below is already in your note"],
|
|
235
|
+
aiRetry: ["\u91CD\u8BD5", "Retry"],
|
|
236
|
+
aiRetryTitle: ["\u64A4\u56DE\u5E76\u91CD\u65B0\u751F\u6210", "Undo and try again"],
|
|
237
|
+
aiUndo: ["\u64A4\u56DE", "Undo"],
|
|
238
|
+
aiUndoTitle: ["\u6574\u7B14\u64A4\u56DE(undo)", "Undo everything AI wrote"],
|
|
239
|
+
aiAccept: ["\u786E\u8BA4", "Accept"],
|
|
240
|
+
aiAcceptTitle: ["\u63D0\u4EA4\u4E8B\u52A1", "Keep what AI wrote"],
|
|
241
|
+
aiFailHint: ["\u751F\u6210\u5931\u8D25", "Something went wrong"],
|
|
242
|
+
aiRegenTitle: ["\u91CD\u65B0\u751F\u6210", "Try again"],
|
|
243
|
+
aiDiscard: ["\u4E22\u5F03", "Discard"],
|
|
244
|
+
aiErrNoCursor: ["\u8BF7\u5148\u628A\u5149\u6807\u653E\u5728\u4E00\u6BB5\u6587\u5B57\u91CC", "Click in a paragraph first"],
|
|
245
|
+
aiErrNoText: ["\u5F53\u524D\u6BB5\u6CA1\u6709\u53EF\u6539\u5199\u7684\u6587\u5B57", "This paragraph has no text to rewrite"],
|
|
246
|
+
aiErrNoConfig: ["AI \u672A\u914D\u7F6E:\u8BF7\u8BBE\u7F6E ai.provider \u6216 ai.endpoint", "AI isn\u2019t set up: set ai.provider or ai.endpoint"],
|
|
247
|
+
// —— 渲染杂项 ——
|
|
248
|
+
fnBack: ["\u56DE\u5230\u5F15\u7528\u5904", "Back to reference"],
|
|
249
|
+
fnMissing: ["\u6CA1\u6709\u8FD9\u6761\u811A\u6CE8\u7684\u5B9A\u4E49", "This footnote has no text"],
|
|
250
|
+
fnEmpty: ["(\u7A7A\u811A\u6CE8)", "(empty footnote)"],
|
|
251
|
+
taskDone: ["\u5DF2\u5B8C\u6210", "Done"],
|
|
252
|
+
taskTodo: ["\u672A\u5B8C\u6210", "Not done"],
|
|
253
|
+
diagramEdit: ["\u70B9\u51FB\u7F16\u8F91\u6E90\u7801", "Click to edit source"],
|
|
254
|
+
diagramError: ["\u56FE\u753B\u4E0D\u51FA\u6765:{msg}", "Couldn\u2019t draw this diagram: {msg}"],
|
|
255
|
+
frontMatter: ["\u5143\u6570\u636E", "Metadata"]
|
|
256
|
+
};
|
|
257
|
+
function t(key, params) {
|
|
258
|
+
const pair = MESSAGES[key];
|
|
259
|
+
const s = getLocale() === "en" ? pair[1] : pair[0];
|
|
260
|
+
if (!params)
|
|
261
|
+
return s;
|
|
262
|
+
return s.replace(/\{(\w+)\}/g, (m, k) => k in params ? String(params[k]) : m);
|
|
263
|
+
}
|
|
12
264
|
|
|
13
265
|
// src/view/selection.ts
|
|
14
266
|
function rootEl(root) {
|
|
15
267
|
return _nullishCoalesce(root.querySelector(".markloom-doc"), () => ( root));
|
|
16
268
|
}
|
|
269
|
+
function nodeExtent(doc, nodePath = []) {
|
|
270
|
+
const n = nodePath.length === 0 ? doc : _chunkHXABDVLZcjs.nodeAt.call(void 0, doc, nodePath);
|
|
271
|
+
if (!_chunkPCSVBPORcjs.isElement.call(void 0, n) || n.children.length === 0)
|
|
272
|
+
return null;
|
|
273
|
+
return {
|
|
274
|
+
anchor: { path: _chunkHXABDVLZcjs.normalizeToLeaf.call(void 0, doc, [...nodePath, ..._chunkHXABDVLZcjs.firstLeafPath.call(void 0, n), 0]) },
|
|
275
|
+
head: { path: _chunkHXABDVLZcjs.normalizeToLeaf.call(void 0, doc, [...nodePath, ..._chunkHXABDVLZcjs.lastLeafEnd.call(void 0, n)]) }
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function docExtent(doc) {
|
|
279
|
+
return nodeExtent(doc, []);
|
|
280
|
+
}
|
|
281
|
+
var SELECT_UNIT_TYPES = ["code", "quote"];
|
|
282
|
+
function isSelectUnitType(type) {
|
|
283
|
+
return SELECT_UNIT_TYPES.includes(type);
|
|
284
|
+
}
|
|
285
|
+
function isSelectUnit(n) {
|
|
286
|
+
return _chunkPCSVBPORcjs.isElement.call(void 0, n) && isSelectUnitType(n.type);
|
|
287
|
+
}
|
|
288
|
+
function isProgressiveSelectUnit(n) {
|
|
289
|
+
if (isSelectUnit(n))
|
|
290
|
+
return true;
|
|
291
|
+
return _chunkPCSVBPORcjs.isElement.call(void 0, n) && (n.type === "table_cell" || n.type === "table");
|
|
292
|
+
}
|
|
293
|
+
function progressiveUnitPaths(doc, caretPath) {
|
|
294
|
+
const out = [];
|
|
295
|
+
for (let depth = caretPath.length - 2; depth >= 1; depth--) {
|
|
296
|
+
const p = caretPath.slice(0, depth);
|
|
297
|
+
if (isProgressiveSelectUnit(_chunkHXABDVLZcjs.nodeAt.call(void 0, doc, p)))
|
|
298
|
+
out.push(p);
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
function selectUnitPath(doc, caretPath) {
|
|
303
|
+
return _nullishCoalesce(progressiveUnitPaths(doc, caretPath)[0], () => ( null));
|
|
304
|
+
}
|
|
305
|
+
function selectionCovers(sel, extent) {
|
|
306
|
+
return pathEq(sel.anchor.path, extent.anchor.path) && pathEq(sel.head.path, extent.head.path) || pathEq(sel.anchor.path, extent.head.path) && pathEq(sel.head.path, extent.anchor.path);
|
|
307
|
+
}
|
|
308
|
+
function pathUnderUnit(path, unitPath) {
|
|
309
|
+
return unitPath.every((s, i) => path[i] === s);
|
|
310
|
+
}
|
|
311
|
+
function selectionInUnit(sel, unitPath) {
|
|
312
|
+
return pathUnderUnit(sel.anchor.path, unitPath) && pathUnderUnit(sel.head.path, unitPath);
|
|
313
|
+
}
|
|
314
|
+
function expandSelectAll(doc, sel) {
|
|
315
|
+
const whole = docExtent(doc);
|
|
316
|
+
if (!sel)
|
|
317
|
+
return whole;
|
|
318
|
+
const chain = progressiveUnitPaths(doc, sel.head.path);
|
|
319
|
+
for (const unit of chain) {
|
|
320
|
+
if (!selectionInUnit(sel, unit))
|
|
321
|
+
continue;
|
|
322
|
+
const extent = nodeExtent(doc, unit);
|
|
323
|
+
if (extent && !selectionCovers(sel, extent))
|
|
324
|
+
return extent;
|
|
325
|
+
}
|
|
326
|
+
return whole;
|
|
327
|
+
}
|
|
328
|
+
function pathEq(a, b) {
|
|
329
|
+
return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
330
|
+
}
|
|
17
331
|
function pointToDom(root, doc, pos) {
|
|
18
332
|
const path = pos.path;
|
|
19
333
|
if (path.length < 2)
|
|
@@ -22,7 +336,7 @@ function pointToDom(root, doc, pos) {
|
|
|
22
336
|
for (let i = 0; i < path.length - 1; i++) {
|
|
23
337
|
if (!domNode)
|
|
24
338
|
return null;
|
|
25
|
-
const child =
|
|
339
|
+
const child = childAt(domNode, path[i]);
|
|
26
340
|
if (!child)
|
|
27
341
|
return null;
|
|
28
342
|
domNode = child;
|
|
@@ -39,7 +353,7 @@ function domToPoint(root, doc, container, domOffset) {
|
|
|
39
353
|
const structural = node instanceof HTMLElement && node.nodeType !== 3 && !closestLeaf(node);
|
|
40
354
|
if (structural) {
|
|
41
355
|
const kids = elementChildren(node);
|
|
42
|
-
const at =
|
|
356
|
+
const at = childAt(node, domOffset);
|
|
43
357
|
if (at) {
|
|
44
358
|
node = _nullishCoalesce(deepestText(at), () => ( at));
|
|
45
359
|
charOffset = 0;
|
|
@@ -64,13 +378,13 @@ function domToPoint(root, doc, container, domOffset) {
|
|
|
64
378
|
if (node instanceof HTMLElement && (node.dataset.blockId !== void 0 || node.dataset.leaf !== void 0)) {
|
|
65
379
|
const sp = structuralParent(node);
|
|
66
380
|
if (sp)
|
|
67
|
-
segs.unshift(
|
|
381
|
+
segs.unshift(childIndex(sp, node));
|
|
68
382
|
}
|
|
69
383
|
node = parent;
|
|
70
384
|
}
|
|
71
385
|
if (segs.length === 0)
|
|
72
386
|
return null;
|
|
73
|
-
return { path:
|
|
387
|
+
return { path: _chunkHXABDVLZcjs.normalizeToLeaf.call(void 0, doc, segs.concat(charOffset)) };
|
|
74
388
|
}
|
|
75
389
|
function readSelection(root, doc) {
|
|
76
390
|
const sel = root.ownerDocument.getSelection();
|
|
@@ -78,11 +392,25 @@ function readSelection(root, doc) {
|
|
|
78
392
|
return null;
|
|
79
393
|
const anchor = domToPoint(root, doc, sel.anchorNode, sel.anchorOffset);
|
|
80
394
|
const head = domToPoint(root, doc, sel.focusNode, sel.focusOffset);
|
|
81
|
-
if (
|
|
82
|
-
return
|
|
83
|
-
|
|
395
|
+
if (anchor && head)
|
|
396
|
+
return { anchor, head };
|
|
397
|
+
if (rangeCoversSurface(sel, rootEl(root)))
|
|
398
|
+
return docExtent(doc);
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
function rangeCoversSurface(sel, top) {
|
|
402
|
+
if (!sel.rangeCount)
|
|
403
|
+
return false;
|
|
404
|
+
try {
|
|
405
|
+
const r = sel.getRangeAt(0);
|
|
406
|
+
const tr = top.ownerDocument.createRange();
|
|
407
|
+
tr.selectNodeContents(top);
|
|
408
|
+
return r.compareBoundaryPoints(Range.START_TO_START, tr) <= 0 && r.compareBoundaryPoints(Range.END_TO_END, tr) >= 0;
|
|
409
|
+
} catch (e2) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
84
412
|
}
|
|
85
|
-
function writeSelection(root, doc, selection) {
|
|
413
|
+
function writeSelection(root, doc, selection, opts) {
|
|
86
414
|
const a = pointToDom(root, doc, selection.anchor);
|
|
87
415
|
const hd = pointToDom(root, doc, selection.head);
|
|
88
416
|
if (!a || !hd)
|
|
@@ -92,12 +420,17 @@ function writeSelection(root, doc, selection) {
|
|
|
92
420
|
return;
|
|
93
421
|
const host = editableHost(a.node, root);
|
|
94
422
|
if (host && host !== root.ownerDocument.activeElement)
|
|
95
|
-
host.focus({ preventScroll:
|
|
423
|
+
host.focus({ preventScroll: !_optionalChain([opts, 'optionalAccess', _3 => _3.scroll]) });
|
|
96
424
|
const range = root.ownerDocument.createRange();
|
|
97
425
|
range.setStart(a.node, a.offset);
|
|
98
426
|
range.setEnd(hd.node, hd.offset);
|
|
99
427
|
sel.removeAllRanges();
|
|
100
428
|
sel.addRange(range);
|
|
429
|
+
if (_optionalChain([opts, 'optionalAccess', _4 => _4.scroll])) {
|
|
430
|
+
const n = a.node;
|
|
431
|
+
const el = n.nodeType === 3 ? n.parentElement : n instanceof HTMLElement ? n : null;
|
|
432
|
+
_optionalChain([el, 'optionalAccess', _5 => _5.scrollIntoView, 'optionalCall', _6 => _6({ block: "nearest", inline: "nearest" })]);
|
|
433
|
+
}
|
|
101
434
|
}
|
|
102
435
|
function editableHost(node, root) {
|
|
103
436
|
let el = node.nodeType === 3 ? node.parentElement : node;
|
|
@@ -112,18 +445,52 @@ var TRANSPARENT = /* @__PURE__ */ new Set(["TBODY", "TR", "THEAD", "TFOOT", "COL
|
|
|
112
445
|
function isTransparent(el) {
|
|
113
446
|
return TRANSPARENT.has(el.tagName) || el.dataset.pass !== void 0;
|
|
114
447
|
}
|
|
115
|
-
|
|
116
|
-
|
|
448
|
+
var BIG = 256;
|
|
449
|
+
var structureEpoch = 0;
|
|
450
|
+
var childCache = /* @__PURE__ */ new WeakMap();
|
|
451
|
+
function invalidateStructure(keep) {
|
|
452
|
+
const saved = keep ? childCache.get(keep) : void 0;
|
|
453
|
+
structureEpoch++;
|
|
454
|
+
if (keep && saved && keep.children.length === saved.n)
|
|
455
|
+
childCache.set(keep, { ...saved, epoch: structureEpoch });
|
|
456
|
+
}
|
|
457
|
+
function scanChildren(el, out) {
|
|
117
458
|
for (const c of el.children) {
|
|
118
459
|
if (!(c instanceof HTMLElement))
|
|
119
460
|
continue;
|
|
120
|
-
if (c.
|
|
461
|
+
if (c.hasAttribute("data-block-id") || c.hasAttribute("data-leaf"))
|
|
121
462
|
out.push(c);
|
|
122
463
|
else if (isTransparent(c))
|
|
123
|
-
|
|
464
|
+
scanChildren(c, out);
|
|
124
465
|
}
|
|
466
|
+
}
|
|
467
|
+
function scanFresh(el) {
|
|
468
|
+
const out = [];
|
|
469
|
+
scanChildren(el, out);
|
|
470
|
+
const n = el.children.length;
|
|
471
|
+
if (n >= BIG)
|
|
472
|
+
childCache.set(el, { epoch: structureEpoch, n, kids: out });
|
|
125
473
|
return out;
|
|
126
474
|
}
|
|
475
|
+
function elementChildren(el) {
|
|
476
|
+
const n = el.children.length;
|
|
477
|
+
if (n >= BIG) {
|
|
478
|
+
const hit = childCache.get(el);
|
|
479
|
+
if (hit && hit.epoch === structureEpoch && hit.n === n)
|
|
480
|
+
return hit.kids;
|
|
481
|
+
}
|
|
482
|
+
return scanFresh(el);
|
|
483
|
+
}
|
|
484
|
+
function childAt(el, i) {
|
|
485
|
+
const c = elementChildren(el)[i];
|
|
486
|
+
if (c && !el.contains(c))
|
|
487
|
+
return scanFresh(el)[i];
|
|
488
|
+
return c;
|
|
489
|
+
}
|
|
490
|
+
function childIndex(el, node) {
|
|
491
|
+
const i = elementChildren(el).indexOf(node);
|
|
492
|
+
return i >= 0 ? i : scanFresh(el).indexOf(node);
|
|
493
|
+
}
|
|
127
494
|
function structuralParent(node) {
|
|
128
495
|
let p = node.parentElement;
|
|
129
496
|
while (p && isTransparent(p))
|
|
@@ -171,9 +538,9 @@ function zwspFreeLen(s) {
|
|
|
171
538
|
}
|
|
172
539
|
function offsetWithinLeaf(leaf, target, domOffset) {
|
|
173
540
|
let acc = 0;
|
|
174
|
-
for (const
|
|
175
|
-
const s = _nullishCoalesce(
|
|
176
|
-
if (
|
|
541
|
+
for (const t2 of leafTextNodes(leaf)) {
|
|
542
|
+
const s = _nullishCoalesce(t2.textContent, () => ( ""));
|
|
543
|
+
if (t2 === target)
|
|
177
544
|
return acc + zwspFreeLen(s.slice(0, domOffset));
|
|
178
545
|
acc += zwspFreeLen(s);
|
|
179
546
|
}
|
|
@@ -182,17 +549,17 @@ function offsetWithinLeaf(leaf, target, domOffset) {
|
|
|
182
549
|
function locateInLeaf(leaf, charOff) {
|
|
183
550
|
const texts = leafTextNodes(leaf);
|
|
184
551
|
if (texts.length === 0) {
|
|
185
|
-
const
|
|
186
|
-
return { node: _nullishCoalesce(
|
|
552
|
+
const t2 = deepestText(leaf);
|
|
553
|
+
return { node: _nullishCoalesce(t2, () => ( leaf)), offset: 0 };
|
|
187
554
|
}
|
|
188
555
|
let off = Math.max(0, charOff);
|
|
189
556
|
let prev = null;
|
|
190
|
-
for (const
|
|
191
|
-
const s = _nullishCoalesce(
|
|
557
|
+
for (const t2 of texts) {
|
|
558
|
+
const s = _nullishCoalesce(t2.textContent, () => ( ""));
|
|
192
559
|
const len = zwspFreeLen(s);
|
|
193
560
|
if (s === "\n") {
|
|
194
561
|
if (off === 0)
|
|
195
|
-
return _nullishCoalesce(prev, () => ( { node:
|
|
562
|
+
return _nullishCoalesce(prev, () => ( { node: t2, offset: 1 }));
|
|
196
563
|
off -= len;
|
|
197
564
|
continue;
|
|
198
565
|
}
|
|
@@ -204,32 +571,32 @@ function locateInLeaf(leaf, charOff) {
|
|
|
204
571
|
seen++;
|
|
205
572
|
if (len === 0)
|
|
206
573
|
dom = s.length;
|
|
207
|
-
return { node:
|
|
574
|
+
return { node: t2, offset: dom };
|
|
208
575
|
}
|
|
209
|
-
prev = { node:
|
|
576
|
+
prev = { node: t2, offset: s.length };
|
|
210
577
|
off -= len;
|
|
211
578
|
}
|
|
212
|
-
return _nullishCoalesce(prev, () => ( { node: texts[texts.length - 1], offset: _nullishCoalesce(_optionalChain([texts, 'access',
|
|
579
|
+
return _nullishCoalesce(prev, () => ( { node: texts[texts.length - 1], offset: _nullishCoalesce(_optionalChain([texts, 'access', _7 => _7[texts.length - 1], 'access', _8 => _8.textContent, 'optionalAccess', _9 => _9.length]), () => ( 0)) }));
|
|
213
580
|
}
|
|
214
581
|
|
|
215
582
|
// src/view/ai-write.ts
|
|
216
|
-
var newId = () => _nullishCoalesce(_optionalChain([crypto, 'optionalAccess',
|
|
583
|
+
var newId = () => _nullishCoalesce(_optionalChain([crypto, 'optionalAccess', _10 => _10.randomUUID, 'optionalCall', _11 => _11()]), () => ( `ai${Math.random().toString(36).slice(2)}`));
|
|
217
584
|
function focusBlockId(ed) {
|
|
218
585
|
const sel = readSelection(ed.root, ed.doc);
|
|
219
|
-
const idx = _nullishCoalesce(_optionalChain([sel, 'optionalAccess',
|
|
586
|
+
const idx = _nullishCoalesce(_optionalChain([sel, 'optionalAccess', _12 => _12.head, 'access', _13 => _13.path, 'access', _14 => _14[0]]), () => ( Math.max(0, ed.doc.children.length - 1)));
|
|
220
587
|
const b = ed.doc.children[idx];
|
|
221
|
-
if (!b ||
|
|
588
|
+
if (!b || _chunkPCSVBPORcjs.isText.call(void 0, b) || !b.id)
|
|
222
589
|
return null;
|
|
223
590
|
return b.id;
|
|
224
591
|
}
|
|
225
592
|
function blockPlainText(doc, blockId) {
|
|
226
|
-
const b = doc.children.find((c) => !
|
|
593
|
+
const b = doc.children.find((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.id === blockId);
|
|
227
594
|
if (!b)
|
|
228
595
|
return "";
|
|
229
596
|
return collectText(b);
|
|
230
597
|
}
|
|
231
598
|
function collectText(n) {
|
|
232
|
-
if (
|
|
599
|
+
if (_chunkPCSVBPORcjs.isText.call(void 0, n))
|
|
233
600
|
return n.text;
|
|
234
601
|
return n.children.map(collectText).join("");
|
|
235
602
|
}
|
|
@@ -238,7 +605,7 @@ function emptyLike(block) {
|
|
|
238
605
|
return { type: "heading", id: block.id, attrs: { ...block.attrs }, children: [{ text: "" }] };
|
|
239
606
|
if (block.type === "code")
|
|
240
607
|
return { type: "code", id: block.id, attrs: { ...block.attrs }, children: [{ text: "" }] };
|
|
241
|
-
if (block.type === "quote"
|
|
608
|
+
if (block.type === "quote") {
|
|
242
609
|
return {
|
|
243
610
|
type: block.type,
|
|
244
611
|
id: block.id,
|
|
@@ -249,12 +616,12 @@ function emptyLike(block) {
|
|
|
249
616
|
return { type: "paragraph", id: block.id, attrs: block.attrs ? { ...block.attrs } : void 0, children: [{ text: "" }] };
|
|
250
617
|
}
|
|
251
618
|
function streamTargetId(doc, blockId) {
|
|
252
|
-
const b = doc.children.find((c) => !
|
|
619
|
+
const b = doc.children.find((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.id === blockId);
|
|
253
620
|
if (!b)
|
|
254
621
|
return blockId;
|
|
255
|
-
if (b.type === "quote"
|
|
256
|
-
const inner = b.children.find((c) => !
|
|
257
|
-
if (_optionalChain([inner, 'optionalAccess',
|
|
622
|
+
if (b.type === "quote") {
|
|
623
|
+
const inner = b.children.find((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.type === "paragraph");
|
|
624
|
+
if (_optionalChain([inner, 'optionalAccess', _15 => _15.id]))
|
|
258
625
|
return inner.id;
|
|
259
626
|
}
|
|
260
627
|
return blockId;
|
|
@@ -275,16 +642,16 @@ function startAiWrite(ed, mode, blockId) {
|
|
|
275
642
|
if (mode === "continue") {
|
|
276
643
|
const id = newId();
|
|
277
644
|
const empty = { type: "paragraph", id, children: [{ text: "" }] };
|
|
278
|
-
ed.dispatch([
|
|
645
|
+
ed.dispatch([_chunkOVHASRIDcjs.insertAfter.call(void 0, doc, focus, [empty])]);
|
|
279
646
|
targetId = id;
|
|
280
647
|
} else {
|
|
281
|
-
const block = doc.children.find((c) => !
|
|
648
|
+
const block = doc.children.find((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.id === focus);
|
|
282
649
|
if (!block)
|
|
283
650
|
throw new Error(`block not found: ${focus}`);
|
|
284
651
|
if (block.type === "table" || block.type === "image" || block.type === "embed" || block.type === "raw")
|
|
285
652
|
throw new Error(`cannot rewrite ${block.type}`);
|
|
286
653
|
const cleared = emptyLike(block);
|
|
287
|
-
ed.dispatch([
|
|
654
|
+
ed.dispatch([_chunkOVHASRIDcjs.rewriteNode.call(void 0, doc, focus, cleared)]);
|
|
288
655
|
targetId = streamTargetId(ed.doc, focus);
|
|
289
656
|
}
|
|
290
657
|
opened = true;
|
|
@@ -293,7 +660,7 @@ function startAiWrite(ed, mode, blockId) {
|
|
|
293
660
|
if (!alive || !text)
|
|
294
661
|
return;
|
|
295
662
|
setup();
|
|
296
|
-
const step =
|
|
663
|
+
const step = _chunkOVHASRIDcjs.appendText.call(void 0, ed.doc, targetId, text);
|
|
297
664
|
ed.dispatchStream([step]);
|
|
298
665
|
};
|
|
299
666
|
const finish = () => {
|
|
@@ -318,15 +685,15 @@ function precedingPlainText(doc, blockIdx) {
|
|
|
318
685
|
const parts = [];
|
|
319
686
|
for (let i = 0; i < blockIdx && i < doc.children.length; i++) {
|
|
320
687
|
const b = doc.children[i];
|
|
321
|
-
if (
|
|
688
|
+
if (_chunkPCSVBPORcjs.isText.call(void 0, b) || !b.id)
|
|
322
689
|
continue;
|
|
323
|
-
if (b.type === "image" || b.type === "table" || b.type === "embed" || b.type === "raw" ||
|
|
690
|
+
if (b.type === "image" || b.type === "table" || b.type === "embed" || b.type === "raw" || _chunkPCSVBPORcjs.isAiCompose.call(void 0, b))
|
|
324
691
|
continue;
|
|
325
|
-
if (_optionalChain([b, 'access',
|
|
692
|
+
if (_optionalChain([b, 'access', _16 => _16.attrs, 'optionalAccess', _17 => _17.aiDraft]))
|
|
326
693
|
continue;
|
|
327
|
-
const
|
|
328
|
-
if (
|
|
329
|
-
parts.push(
|
|
694
|
+
const t2 = blockPlainText(doc, b.id);
|
|
695
|
+
if (t2.trim())
|
|
696
|
+
parts.push(t2);
|
|
330
697
|
}
|
|
331
698
|
return parts.join("\n\n");
|
|
332
699
|
}
|
|
@@ -336,7 +703,7 @@ function aiInstructionFromQuery(query) {
|
|
|
336
703
|
return "";
|
|
337
704
|
return q.slice(2).trim();
|
|
338
705
|
}
|
|
339
|
-
var newAiId = () => _nullishCoalesce(_optionalChain([crypto, 'access',
|
|
706
|
+
var newAiId = () => _nullishCoalesce(_optionalChain([crypto, 'access', _18 => _18.randomUUID, 'optionalCall', _19 => _19()]), () => ( `ai${Math.random().toString(36).slice(2)}`));
|
|
340
707
|
|
|
341
708
|
// src/ai/controller.ts
|
|
342
709
|
var MarkloomAi = (_class = class {
|
|
@@ -355,7 +722,7 @@ var MarkloomAi = (_class = class {
|
|
|
355
722
|
this.opts = opts;
|
|
356
723
|
}
|
|
357
724
|
destroy() {
|
|
358
|
-
_optionalChain([this, 'access',
|
|
725
|
+
_optionalChain([this, 'access', _20 => _20.abort, 'optionalAccess', _21 => _21.abort, 'call', _22 => _22()]);
|
|
359
726
|
this.clearRaf();
|
|
360
727
|
this.streamingId = null;
|
|
361
728
|
this.pendingMd = "";
|
|
@@ -368,14 +735,14 @@ var MarkloomAi = (_class = class {
|
|
|
368
735
|
* · 空 → undo 整笔事务(等同丢弃)
|
|
369
736
|
*/
|
|
370
737
|
stop() {
|
|
371
|
-
_optionalChain([this, 'access',
|
|
738
|
+
_optionalChain([this, 'access', _23 => _23.abort, 'optionalAccess', _24 => _24.abort, 'call', _25 => _25()]);
|
|
372
739
|
this.abort = null;
|
|
373
740
|
this.clearRaf();
|
|
374
741
|
const id = this.streamingId;
|
|
375
742
|
const md = this.pendingMd;
|
|
376
743
|
this.pendingMd = "";
|
|
377
744
|
this.streamingId = null;
|
|
378
|
-
_optionalChain([this, 'access',
|
|
745
|
+
_optionalChain([this, 'access', _26 => _26.opts, 'access', _27 => _27.onBusy, 'optionalCall', _28 => _28(false)]);
|
|
379
746
|
if (!id)
|
|
380
747
|
return;
|
|
381
748
|
const ed = this.getEditor();
|
|
@@ -407,41 +774,39 @@ var MarkloomAi = (_class = class {
|
|
|
407
774
|
return;
|
|
408
775
|
const bid = focusBlockId(ed);
|
|
409
776
|
if (!bid) {
|
|
410
|
-
_optionalChain([this, 'access',
|
|
777
|
+
_optionalChain([this, 'access', _29 => _29.opts, 'access', _30 => _30.onError, 'optionalCall', _31 => _31(t("aiErrNoCursor"))]);
|
|
411
778
|
return;
|
|
412
779
|
}
|
|
413
780
|
const doc = ed.doc;
|
|
414
|
-
const idx = doc.children.findIndex((c) => !
|
|
781
|
+
const idx = doc.children.findIndex((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.id === bid);
|
|
415
782
|
if (idx < 0)
|
|
416
783
|
return;
|
|
417
784
|
const cur = doc.children[idx];
|
|
418
|
-
if (
|
|
785
|
+
if (_chunkPCSVBPORcjs.isAiCompose.call(void 0, cur))
|
|
419
786
|
return;
|
|
420
787
|
if (mode === "rewrite") {
|
|
421
788
|
if (!blockPlainText(doc, bid).trim()) {
|
|
422
|
-
_optionalChain([this, 'access',
|
|
789
|
+
_optionalChain([this, 'access', _32 => _32.opts, 'access', _33 => _33.onError, 'optionalCall', _34 => _34(t("aiErrNoText"))]);
|
|
423
790
|
return;
|
|
424
791
|
}
|
|
425
792
|
const seed = blockPlainText(doc, bid);
|
|
426
793
|
const id2 = newAiId();
|
|
427
|
-
const promptId2 = newAiId();
|
|
428
794
|
ed.dispatch(
|
|
429
795
|
[{
|
|
430
796
|
kind: "replaceNode",
|
|
431
797
|
path: [idx],
|
|
432
798
|
node: {
|
|
433
|
-
type: "
|
|
799
|
+
type: "paragraph",
|
|
434
800
|
id: id2,
|
|
435
|
-
attrs: { status: "compose", mode: "rewrite", seed },
|
|
436
|
-
children: [{
|
|
801
|
+
attrs: { aiCompose: true, status: "compose", mode: "rewrite", seed },
|
|
802
|
+
children: [{ text: "" }]
|
|
437
803
|
}
|
|
438
804
|
}],
|
|
439
|
-
{ anchor: { path: [idx, 0, 0
|
|
805
|
+
{ anchor: { path: [idx, 0, 0] }, head: { path: [idx, 0, 0] } }
|
|
440
806
|
);
|
|
441
807
|
return;
|
|
442
808
|
}
|
|
443
809
|
const id = newAiId();
|
|
444
|
-
const promptId = newAiId();
|
|
445
810
|
ed.dispatch(
|
|
446
811
|
[{
|
|
447
812
|
kind: "spliceChildren",
|
|
@@ -449,13 +814,13 @@ var MarkloomAi = (_class = class {
|
|
|
449
814
|
at: idx + 1,
|
|
450
815
|
remove: 0,
|
|
451
816
|
insert: [{
|
|
452
|
-
type: "
|
|
817
|
+
type: "paragraph",
|
|
453
818
|
id,
|
|
454
|
-
attrs: { status: "compose", mode: "continue" },
|
|
455
|
-
children: [{
|
|
819
|
+
attrs: { aiCompose: true, status: "compose", mode: "continue" },
|
|
820
|
+
children: [{ text: "" }]
|
|
456
821
|
}]
|
|
457
822
|
}],
|
|
458
|
-
{ anchor: { path: [idx + 1, 0, 0
|
|
823
|
+
{ anchor: { path: [idx + 1, 0, 0] }, head: { path: [idx + 1, 0, 0] } }
|
|
459
824
|
);
|
|
460
825
|
}
|
|
461
826
|
openFromSlash(blockIdx, query) {
|
|
@@ -464,20 +829,19 @@ var MarkloomAi = (_class = class {
|
|
|
464
829
|
return;
|
|
465
830
|
const instruction = aiInstructionFromQuery(query);
|
|
466
831
|
const id = newAiId();
|
|
467
|
-
const promptId = newAiId();
|
|
468
832
|
const off = instruction.length;
|
|
469
833
|
ed.dispatch(
|
|
470
834
|
[{
|
|
471
835
|
kind: "replaceNode",
|
|
472
836
|
path: [blockIdx],
|
|
473
837
|
node: {
|
|
474
|
-
type: "
|
|
838
|
+
type: "paragraph",
|
|
475
839
|
id,
|
|
476
|
-
attrs: { status: "compose", mode: "continue" },
|
|
477
|
-
children: [{
|
|
840
|
+
attrs: { aiCompose: true, status: "compose", mode: "continue" },
|
|
841
|
+
children: [{ text: instruction }]
|
|
478
842
|
}
|
|
479
843
|
}],
|
|
480
|
-
{ anchor: { path: [blockIdx, 0,
|
|
844
|
+
{ anchor: { path: [blockIdx, 0, off] }, head: { path: [blockIdx, 0, off] } }
|
|
481
845
|
);
|
|
482
846
|
}
|
|
483
847
|
/**
|
|
@@ -492,10 +856,10 @@ var MarkloomAi = (_class = class {
|
|
|
492
856
|
if (!found)
|
|
493
857
|
return;
|
|
494
858
|
const { path, node } = found;
|
|
495
|
-
if (_optionalChain([node, 'access',
|
|
859
|
+
if (_optionalChain([node, 'access', _35 => _35.attrs, 'optionalAccess', _36 => _36.status]) === "loading")
|
|
496
860
|
return;
|
|
497
861
|
if (this.txOpen && this.txBlockId === blockId) {
|
|
498
|
-
_optionalChain([this, 'access',
|
|
862
|
+
_optionalChain([this, 'access', _37 => _37.abort, 'optionalAccess', _38 => _38.abort, 'call', _39 => _39()]);
|
|
499
863
|
this.abort = null;
|
|
500
864
|
this.clearRaf();
|
|
501
865
|
this.streamingId = null;
|
|
@@ -506,9 +870,9 @@ var MarkloomAi = (_class = class {
|
|
|
506
870
|
if (!live)
|
|
507
871
|
return;
|
|
508
872
|
const { path: aiPath, node: aiNode } = live;
|
|
509
|
-
const mode = _optionalChain([aiNode, 'access',
|
|
873
|
+
const mode = _optionalChain([aiNode, 'access', _40 => _40.attrs, 'optionalAccess', _41 => _41.mode]) === "rewrite" ? "rewrite" : "continue";
|
|
510
874
|
const instruction = promptText(aiNode).trim();
|
|
511
|
-
const seed = typeof _optionalChain([aiNode, 'access',
|
|
875
|
+
const seed = typeof _optionalChain([aiNode, 'access', _42 => _42.attrs, 'optionalAccess', _43 => _43.seed]) === "string" ? aiNode.attrs.seed : "";
|
|
512
876
|
const blockIdx = _nullishCoalesce(aiPath[0], () => ( 0));
|
|
513
877
|
const before = precedingPlainText(ed.doc, blockIdx);
|
|
514
878
|
const ctxBody = mode === "rewrite" ? seed || "\uFF08\u65E0\u539F\u6587\uFF09" : before.trim() || "\uFF08\u5C1A\u65E0\u4E0A\u6587\uFF09";
|
|
@@ -552,7 +916,7 @@ var MarkloomAi = (_class = class {
|
|
|
552
916
|
this.streamingId = blockId;
|
|
553
917
|
this.pendingMd = "";
|
|
554
918
|
this.clearRaf();
|
|
555
|
-
_optionalChain([this, 'access',
|
|
919
|
+
_optionalChain([this, 'access', _44 => _44.opts, 'access', _45 => _45.onBusy, 'optionalCall', _46 => _46(true)]);
|
|
556
920
|
const ac = new AbortController();
|
|
557
921
|
this.abort = ac;
|
|
558
922
|
const flush = () => {
|
|
@@ -568,10 +932,10 @@ var MarkloomAi = (_class = class {
|
|
|
568
932
|
docPreview: ctxBody.slice(0, 4e3),
|
|
569
933
|
signal: ac.signal
|
|
570
934
|
},
|
|
571
|
-
(
|
|
935
|
+
(t2) => {
|
|
572
936
|
if (this.streamingId !== blockId)
|
|
573
937
|
return;
|
|
574
|
-
this.pendingMd +=
|
|
938
|
+
this.pendingMd += t2;
|
|
575
939
|
if (!this.raf) {
|
|
576
940
|
this.raf = requestAnimationFrame(() => {
|
|
577
941
|
this.raf = 0;
|
|
@@ -586,9 +950,9 @@ var MarkloomAi = (_class = class {
|
|
|
586
950
|
this.paintMd(ed, blockId, this.pendingMd, false);
|
|
587
951
|
this.patchAi(ed, blockId, { status: "preview" });
|
|
588
952
|
} catch (e) {
|
|
589
|
-
if (_optionalChain([e, 'optionalAccess',
|
|
590
|
-
const msg = _optionalChain([e, 'optionalAccess',
|
|
591
|
-
_optionalChain([this, 'access',
|
|
953
|
+
if (_optionalChain([e, 'optionalAccess', _47 => _47.name]) !== "AbortError") {
|
|
954
|
+
const msg = _optionalChain([e, 'optionalAccess', _48 => _48.message]) || String(e);
|
|
955
|
+
_optionalChain([this, 'access', _49 => _49.opts, 'access', _50 => _50.onError, 'optionalCall', _51 => _51(msg)]);
|
|
592
956
|
if (this.streamingId === blockId) {
|
|
593
957
|
this.clearRaf();
|
|
594
958
|
this.paintMd(ed, blockId, this.pendingMd, false);
|
|
@@ -599,7 +963,7 @@ var MarkloomAi = (_class = class {
|
|
|
599
963
|
if (this.streamingId === blockId) {
|
|
600
964
|
this.streamingId = null;
|
|
601
965
|
this.abort = null;
|
|
602
|
-
_optionalChain([this, 'access',
|
|
966
|
+
_optionalChain([this, 'access', _52 => _52.opts, 'access', _53 => _53.onBusy, 'optionalCall', _54 => _54(false)]);
|
|
603
967
|
}
|
|
604
968
|
}
|
|
605
969
|
}
|
|
@@ -614,13 +978,13 @@ var MarkloomAi = (_class = class {
|
|
|
614
978
|
const found = this.findAi(ed, blockId);
|
|
615
979
|
if (!found)
|
|
616
980
|
return;
|
|
617
|
-
if (_optionalChain([found, 'access',
|
|
981
|
+
if (_optionalChain([found, 'access', _55 => _55.node, 'access', _56 => _56.attrs, 'optionalAccess', _57 => _57.status]) !== "preview" && _optionalChain([found, 'access', _58 => _58.node, 'access', _59 => _59.attrs, 'optionalAccess', _60 => _60.status]) !== "error")
|
|
618
982
|
return;
|
|
619
983
|
const doc = ed.doc;
|
|
620
984
|
const steps = [];
|
|
621
985
|
for (let i = 0; i < doc.children.length; i++) {
|
|
622
986
|
const c = doc.children[i];
|
|
623
|
-
if (
|
|
987
|
+
if (_chunkPCSVBPORcjs.isText.call(void 0, c) || _optionalChain([c, 'access', _61 => _61.attrs, 'optionalAccess', _62 => _62.aiFrom]) !== blockId)
|
|
624
988
|
continue;
|
|
625
989
|
const attrs = { ..._nullishCoalesce(c.attrs, () => ( {})) };
|
|
626
990
|
delete attrs.aiDraft;
|
|
@@ -636,12 +1000,12 @@ var MarkloomAi = (_class = class {
|
|
|
636
1000
|
next.attrs = clean;
|
|
637
1001
|
steps.push({ kind: "replaceNode", path: [i], node: next });
|
|
638
1002
|
}
|
|
639
|
-
const aiIdx0 = doc.children.findIndex((c) => !
|
|
1003
|
+
const aiIdx0 = doc.children.findIndex((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.id === blockId);
|
|
640
1004
|
if (aiIdx0 >= 0)
|
|
641
1005
|
steps.push({ kind: "spliceChildren", path: [], at: aiIdx0, remove: 1, insert: [] });
|
|
642
1006
|
if (!steps.length)
|
|
643
1007
|
return;
|
|
644
|
-
const firstDraft = doc.children.findIndex((c) => !
|
|
1008
|
+
const firstDraft = doc.children.findIndex((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && _optionalChain([c, 'access', _63 => _63.attrs, 'optionalAccess', _64 => _64.aiFrom]) === blockId);
|
|
645
1009
|
let caretAt = firstDraft >= 0 ? firstDraft : Math.max(0, aiIdx0);
|
|
646
1010
|
if (firstDraft > aiIdx0)
|
|
647
1011
|
caretAt = firstDraft - 1;
|
|
@@ -663,12 +1027,12 @@ var MarkloomAi = (_class = class {
|
|
|
663
1027
|
/** 整笔撤回事务(= undo);务必不留 aiDraft 孤儿段 */
|
|
664
1028
|
discard(blockId) {
|
|
665
1029
|
if (this.streamingId === blockId) {
|
|
666
|
-
_optionalChain([this, 'access',
|
|
1030
|
+
_optionalChain([this, 'access', _65 => _65.abort, 'optionalAccess', _66 => _66.abort, 'call', _67 => _67()]);
|
|
667
1031
|
this.abort = null;
|
|
668
1032
|
this.clearRaf();
|
|
669
1033
|
this.streamingId = null;
|
|
670
1034
|
this.pendingMd = "";
|
|
671
|
-
_optionalChain([this, 'access',
|
|
1035
|
+
_optionalChain([this, 'access', _68 => _68.opts, 'access', _69 => _69.onBusy, 'optionalCall', _70 => _70(false)]);
|
|
672
1036
|
}
|
|
673
1037
|
if (this.txOpen && (this.txBlockId === blockId || !this.txBlockId)) {
|
|
674
1038
|
this.rollback();
|
|
@@ -690,7 +1054,7 @@ var MarkloomAi = (_class = class {
|
|
|
690
1054
|
const idxs = draftIndices(doc, blockId);
|
|
691
1055
|
for (let i = idxs.length - 1; i >= 0; i--)
|
|
692
1056
|
steps.push({ kind: "spliceChildren", path: [], at: idxs[i], remove: 1, insert: [] });
|
|
693
|
-
let aiIdx = doc.children.findIndex((c) => !
|
|
1057
|
+
let aiIdx = doc.children.findIndex((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.id === blockId);
|
|
694
1058
|
let shift = 0;
|
|
695
1059
|
for (const i of idxs) {
|
|
696
1060
|
if (i < aiIdx)
|
|
@@ -730,11 +1094,11 @@ var MarkloomAi = (_class = class {
|
|
|
730
1094
|
this.txBlockId = null;
|
|
731
1095
|
}
|
|
732
1096
|
findAi(ed, blockId) {
|
|
733
|
-
const path =
|
|
1097
|
+
const path = _chunkOVHASRIDcjs.pathOfId.call(void 0, ed.doc, blockId);
|
|
734
1098
|
if (!path)
|
|
735
1099
|
return null;
|
|
736
1100
|
const node = path.reduce((n, i) => n.children[i], ed.doc);
|
|
737
|
-
if (!node ||
|
|
1101
|
+
if (!node || _chunkPCSVBPORcjs.isText.call(void 0, node) || !_chunkPCSVBPORcjs.isAiCompose.call(void 0, node))
|
|
738
1102
|
return null;
|
|
739
1103
|
return { path, node };
|
|
740
1104
|
}
|
|
@@ -758,7 +1122,7 @@ var MarkloomAi = (_class = class {
|
|
|
758
1122
|
paintMd(ed, blockId, md, streaming) {
|
|
759
1123
|
const doc = ed.doc;
|
|
760
1124
|
const idxs = draftIndices(doc, blockId);
|
|
761
|
-
const aiIdx = doc.children.findIndex((c) => !
|
|
1125
|
+
const aiIdx = doc.children.findIndex((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c) && c.id === blockId);
|
|
762
1126
|
const at = idxs.length ? idxs[0] : aiIdx >= 0 ? aiIdx + 1 : -1;
|
|
763
1127
|
if (at < 0)
|
|
764
1128
|
return;
|
|
@@ -788,9 +1152,9 @@ var MarkloomAi = (_class = class {
|
|
|
788
1152
|
const src = streaming ? softCloseMd(raw) : raw;
|
|
789
1153
|
let blocks;
|
|
790
1154
|
try {
|
|
791
|
-
const tops =
|
|
1155
|
+
const tops = _chunkOVHASRIDcjs.mdToDoc.call(void 0, src).children.filter((c) => !_chunkPCSVBPORcjs.isText.call(void 0, c));
|
|
792
1156
|
blocks = tops.map((c, i) => stampDraft(c, blockId, `${blockId}_d${i}`, streaming && i === tops.length - 1));
|
|
793
|
-
} catch (
|
|
1157
|
+
} catch (e3) {
|
|
794
1158
|
blocks = [{
|
|
795
1159
|
type: "paragraph",
|
|
796
1160
|
id: `${blockId}_d0`,
|
|
@@ -877,7 +1241,7 @@ function softCloseMd(md) {
|
|
|
877
1241
|
}
|
|
878
1242
|
function stampDraft(node, aiFrom, id, streamTail = false) {
|
|
879
1243
|
const kids = node.children.map((c, i) => {
|
|
880
|
-
if (
|
|
1244
|
+
if (_chunkPCSVBPORcjs.isText.call(void 0, c))
|
|
881
1245
|
return c;
|
|
882
1246
|
return stampInner(c, `${id}_${i}`);
|
|
883
1247
|
});
|
|
@@ -888,7 +1252,7 @@ function stampDraft(node, aiFrom, id, streamTail = false) {
|
|
|
888
1252
|
}
|
|
889
1253
|
function stampInner(node, id) {
|
|
890
1254
|
const kids = node.children.map((c, i) => {
|
|
891
|
-
if (
|
|
1255
|
+
if (_chunkPCSVBPORcjs.isText.call(void 0, c))
|
|
892
1256
|
return c;
|
|
893
1257
|
return stampInner(c, `${id}_${i}`);
|
|
894
1258
|
});
|
|
@@ -903,7 +1267,7 @@ function draftIndices(doc, aiId) {
|
|
|
903
1267
|
const out = [];
|
|
904
1268
|
for (let i = 0; i < doc.children.length; i++) {
|
|
905
1269
|
const c = doc.children[i];
|
|
906
|
-
if (!
|
|
1270
|
+
if (!_chunkPCSVBPORcjs.isText.call(void 0, c) && _optionalChain([c, 'access', _71 => _71.attrs, 'optionalAccess', _72 => _72.aiFrom]) === aiId)
|
|
907
1271
|
out.push(i);
|
|
908
1272
|
}
|
|
909
1273
|
return out;
|
|
@@ -913,13 +1277,16 @@ function promptText(ai) {
|
|
|
913
1277
|
return p ? collectText2(p) : "";
|
|
914
1278
|
}
|
|
915
1279
|
function collectText2(n) {
|
|
916
|
-
if (
|
|
1280
|
+
if (_chunkPCSVBPORcjs.isText.call(void 0, n))
|
|
917
1281
|
return n.text;
|
|
918
1282
|
return n.children.map(collectText2).join("");
|
|
919
1283
|
}
|
|
920
1284
|
|
|
921
1285
|
// src/ai/stream.ts
|
|
922
1286
|
function defaultSystem(action) {
|
|
1287
|
+
if (getLocale() === "en") {
|
|
1288
|
+
return action === "rewrite" ? "You are a note-rewriting assistant. Rewrite the given text. Keep the meaning, make it clearer and smoother; no explanations, no heading prefix, no markdown code fences; output the rewritten plain text only (simple line breaks allowed). Reply in the language of the text." : "You are a note-continuation assistant. Continue naturally from the existing context. Same style, no repetition, no explanations, no heading prefix; output the continuation as plain text only (simple line breaks allowed). Reply in the language of the context.";
|
|
1289
|
+
}
|
|
923
1290
|
if (action === "rewrite") {
|
|
924
1291
|
return [
|
|
925
1292
|
"\u4F60\u662F\u7B14\u8BB0\u6539\u5199\u52A9\u624B\u3002\u6839\u636E\u7528\u6237\u7ED9\u51FA\u7684\u539F\u6587,\u8F93\u51FA\u6539\u5199\u540E\u7684\u6B63\u6587\u3002",
|
|
@@ -936,6 +1303,21 @@ function defaultSystem(action) {
|
|
|
936
1303
|
function userPrompt(action, context, docPreview) {
|
|
937
1304
|
const ctx = (context || "").slice(0, 8e3);
|
|
938
1305
|
const prev = (docPreview || "").slice(0, 4e3);
|
|
1306
|
+
if (getLocale() === "en") {
|
|
1307
|
+
if (action === "rewrite")
|
|
1308
|
+
return `Rewrite the following:
|
|
1309
|
+
|
|
1310
|
+
${ctx}`;
|
|
1311
|
+
return [
|
|
1312
|
+
prev && prev !== ctx ? `Document excerpt:
|
|
1313
|
+
${prev}
|
|
1314
|
+
|
|
1315
|
+
` : "",
|
|
1316
|
+
`Continue after this text:
|
|
1317
|
+
|
|
1318
|
+
${ctx}`
|
|
1319
|
+
].join("");
|
|
1320
|
+
}
|
|
939
1321
|
if (action === "rewrite")
|
|
940
1322
|
return `\u8BF7\u6539\u5199\u4EE5\u4E0B\u5185\u5BB9:
|
|
941
1323
|
|
|
@@ -960,7 +1342,7 @@ function completionsUrl(host) {
|
|
|
960
1342
|
}
|
|
961
1343
|
function resolveProvider(cfg) {
|
|
962
1344
|
const p = typeof cfg.provider === "function" ? cfg.provider() : cfg.provider;
|
|
963
|
-
if (!_optionalChain([p, 'optionalAccess',
|
|
1345
|
+
if (!_optionalChain([p, 'optionalAccess', _73 => _73.host]) || !_optionalChain([p, 'optionalAccess', _74 => _74.apiKey]) || !_optionalChain([p, 'optionalAccess', _75 => _75.model]))
|
|
964
1346
|
return null;
|
|
965
1347
|
return p;
|
|
966
1348
|
}
|
|
@@ -994,7 +1376,7 @@ async function readSse(res, onToken, mode) {
|
|
|
994
1376
|
if (mode === "proxy" && j.content)
|
|
995
1377
|
onToken(j.content);
|
|
996
1378
|
if (mode === "openai") {
|
|
997
|
-
const c = _optionalChain([j, 'access',
|
|
1379
|
+
const c = _optionalChain([j, 'access', _76 => _76.choices, 'optionalAccess', _77 => _77[0], 'optionalAccess', _78 => _78.delta, 'optionalAccess', _79 => _79.content]);
|
|
998
1380
|
if (c)
|
|
999
1381
|
onToken(c);
|
|
1000
1382
|
}
|
|
@@ -1012,7 +1394,7 @@ function createAiStream(cfg) {
|
|
|
1012
1394
|
return cfg.stream;
|
|
1013
1395
|
return async (input, onToken) => {
|
|
1014
1396
|
const action = input.action;
|
|
1015
|
-
const system = _optionalChain([(action === "rewrite" ? cfg.rewriteSystem : cfg.continueSystem), 'optionalAccess',
|
|
1397
|
+
const system = _optionalChain([(action === "rewrite" ? cfg.rewriteSystem : cfg.continueSystem), 'optionalAccess', _80 => _80.trim, 'call', _81 => _81()]) || defaultSystem(action);
|
|
1016
1398
|
const provider = resolveProvider(cfg);
|
|
1017
1399
|
if (cfg.endpoint) {
|
|
1018
1400
|
const res2 = await fetch(cfg.endpoint, {
|
|
@@ -1032,7 +1414,7 @@ function createAiStream(cfg) {
|
|
|
1032
1414
|
try {
|
|
1033
1415
|
const j = await res2.json();
|
|
1034
1416
|
err = j.error || err;
|
|
1035
|
-
} catch (
|
|
1417
|
+
} catch (e4) {
|
|
1036
1418
|
err = await res2.text().catch(() => err);
|
|
1037
1419
|
}
|
|
1038
1420
|
throw new Error(err || `AI ${res2.status}`);
|
|
@@ -1041,7 +1423,7 @@ function createAiStream(cfg) {
|
|
|
1041
1423
|
return;
|
|
1042
1424
|
}
|
|
1043
1425
|
if (!provider)
|
|
1044
|
-
throw new Error("
|
|
1426
|
+
throw new Error(t("aiErrNoConfig"));
|
|
1045
1427
|
const url = completionsUrl(provider.host);
|
|
1046
1428
|
const res = await fetch(url, {
|
|
1047
1429
|
method: "POST",
|
|
@@ -1081,4 +1463,19 @@ function createAiStream(cfg) {
|
|
|
1081
1463
|
|
|
1082
1464
|
|
|
1083
1465
|
|
|
1084
|
-
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
|
|
1481
|
+
exports.setLocale = setLocale; exports.getLocale = getLocale; exports.MESSAGES = MESSAGES; exports.t = t; exports.rootEl = rootEl; exports.nodeExtent = nodeExtent; exports.docExtent = docExtent; exports.SELECT_UNIT_TYPES = SELECT_UNIT_TYPES; exports.isSelectUnitType = isSelectUnitType; exports.isSelectUnit = isSelectUnit; exports.isProgressiveSelectUnit = isProgressiveSelectUnit; exports.progressiveUnitPaths = progressiveUnitPaths; exports.selectUnitPath = selectUnitPath; exports.selectionCovers = selectionCovers; exports.expandSelectAll = expandSelectAll; exports.pointToDom = pointToDom; exports.domToPoint = domToPoint; exports.readSelection = readSelection; exports.writeSelection = writeSelection; exports.invalidateStructure = invalidateStructure; exports.elementChildren = elementChildren; exports.focusBlockId = focusBlockId; exports.blockPlainText = blockPlainText; exports.startAiWrite = startAiWrite; exports.precedingPlainText = precedingPlainText; exports.aiInstructionFromQuery = aiInstructionFromQuery; exports.MarkloomAi = MarkloomAi; exports.createAiStream = createAiStream;
|