markloom 0.3.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/README.md +125 -0
- package/dist/ai/index.cjs +19 -0
- package/dist/ai/index.d.cts +10 -0
- package/dist/ai/index.d.ts +10 -0
- package/dist/ai/index.js +19 -0
- package/dist/ai/theme.css +304 -0
- package/dist/chunk-2X6AF7XH.cjs +9030 -0
- package/dist/chunk-7Q6AXLF2.cjs +1076 -0
- package/dist/chunk-GUPMZI6Q.js +1076 -0
- package/dist/chunk-HA6XHJUD.cjs +218 -0
- package/dist/chunk-ITVAR2UM.js +218 -0
- package/dist/chunk-J3QWW6CN.js +2305 -0
- package/dist/chunk-UCNEQGMY.js +9030 -0
- package/dist/chunk-VVFIQLVR.cjs +2305 -0
- package/dist/comments-USjT1wYN.d.cts +105 -0
- package/dist/comments-USjT1wYN.d.ts +105 -0
- package/dist/controller-Dm4uLD3I.d.ts +507 -0
- package/dist/controller-cE9iEYp3.d.cts +507 -0
- package/dist/index.cjs +424 -0
- package/dist/index.d.cts +184 -0
- package/dist/index.d.ts +184 -0
- package/dist/index.js +424 -0
- package/dist/react/index.cjs +45 -0
- package/dist/react/index.d.cts +22 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/index.js +45 -0
- package/dist/view/index.cjs +368 -0
- package/dist/view/index.d.cts +155 -0
- package/dist/view/index.d.ts +155 -0
- package/dist/view/index.js +368 -0
- package/dist/view/theme.css +2627 -0
- package/package.json +89 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import { E as ElementNode, S as Step, g as Selection, M as Mark, P as Path, N as Node, H as History, d as CommentThread, C as CommentAuthor } from './comments-USjT1wYN.cjs';
|
|
2
|
+
import * as preact from 'preact';
|
|
3
|
+
import { ComponentChild } from 'preact';
|
|
4
|
+
|
|
5
|
+
interface MentionCandidate {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
kind?: 'person' | 'date';
|
|
9
|
+
date?: string;
|
|
10
|
+
}
|
|
11
|
+
interface MentionHost {
|
|
12
|
+
root: HTMLElement;
|
|
13
|
+
doc: () => ElementNode;
|
|
14
|
+
dispatch: (steps: Step[], selectionAfter?: Selection) => void;
|
|
15
|
+
sel: () => Selection | null;
|
|
16
|
+
mentionSource?: () => ((query: string) => MentionCandidate[]) | undefined;
|
|
17
|
+
}
|
|
18
|
+
declare class MentionMenu {
|
|
19
|
+
private root;
|
|
20
|
+
private host;
|
|
21
|
+
private overlay;
|
|
22
|
+
private open;
|
|
23
|
+
private query;
|
|
24
|
+
private active;
|
|
25
|
+
private list;
|
|
26
|
+
private trigger;
|
|
27
|
+
constructor(root: HTMLElement, host: MentionHost);
|
|
28
|
+
destroy(): void;
|
|
29
|
+
private reevaluate;
|
|
30
|
+
private onKeyDown;
|
|
31
|
+
private apply;
|
|
32
|
+
private close;
|
|
33
|
+
private paint;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface NodeViewCtx {
|
|
37
|
+
node: ElementNode;
|
|
38
|
+
text: string;
|
|
39
|
+
key: number | string;
|
|
40
|
+
}
|
|
41
|
+
interface NodeView {
|
|
42
|
+
render: (ctx: NodeViewCtx) => ComponentChild;
|
|
43
|
+
langs?: () => string[];
|
|
44
|
+
}
|
|
45
|
+
type AtomSelectCtx = {
|
|
46
|
+
exclusiveId?: string | null;
|
|
47
|
+
rangeIds?: ReadonlySet<string>;
|
|
48
|
+
};
|
|
49
|
+
declare function atomIsSelected(id: string | undefined, ctx?: AtomSelectCtx | null): boolean;
|
|
50
|
+
interface RenderOpts {
|
|
51
|
+
slug?: () => (text: string) => string;
|
|
52
|
+
nodeViews?: {
|
|
53
|
+
code?: NodeView;
|
|
54
|
+
};
|
|
55
|
+
placeholder?: string;
|
|
56
|
+
markTags?: Record<string, string>;
|
|
57
|
+
markProps?: Record<string, (mark: Mark) => Record<string, unknown>>;
|
|
58
|
+
blockRenderers?: Record<string, BlockRenderer>;
|
|
59
|
+
renderMath?: (latex: string, display: boolean) => string | null;
|
|
60
|
+
invisibleCharacters?: boolean;
|
|
61
|
+
commentState?: {
|
|
62
|
+
resolved: Set<string>;
|
|
63
|
+
activeId: string | null;
|
|
64
|
+
};
|
|
65
|
+
atomSelect?: AtomSelectCtx | null;
|
|
66
|
+
}
|
|
67
|
+
declare const defaultBlockTag: Record<string, string>;
|
|
68
|
+
declare const defaultMarkTag: Record<string, string>;
|
|
69
|
+
declare function renderImage(spec: ElementNode, key: number | string, atomSelect?: AtomSelectCtx | null): ComponentChild;
|
|
70
|
+
declare function safeCssValue(v: string): string;
|
|
71
|
+
declare function textStyleCss(attrs: Record<string, unknown> | undefined): string;
|
|
72
|
+
declare function renderEmbed(spec: ElementNode, key: number | string, atomSelect?: AtomSelectCtx | null): ComponentChild;
|
|
73
|
+
declare function youtubeId(url: string): string | null;
|
|
74
|
+
declare function twitchChannel(url: string): string | null;
|
|
75
|
+
declare function renderCode(spec: ElementNode, key: number | string, ctx: BlockRenderCtx): ComponentChild;
|
|
76
|
+
declare function renderTable(spec: ElementNode, key: number | string, ctx: BlockRenderCtx): ComponentChild;
|
|
77
|
+
declare function renderHr(spec: ElementNode, key: number | string, ctx: BlockRenderCtx): ComponentChild;
|
|
78
|
+
declare const defaultBlockRenderers: Record<string, BlockRenderer>;
|
|
79
|
+
declare function renderDoc(doc: ElementNode, opts?: RenderOpts): preact.VNode<preact.ClassAttributes<HTMLElement> & {
|
|
80
|
+
class: string;
|
|
81
|
+
'data-loom': boolean;
|
|
82
|
+
}>;
|
|
83
|
+
declare function renderToHtml(doc: ElementNode, opts?: RenderOpts): string;
|
|
84
|
+
|
|
85
|
+
interface InputResult {
|
|
86
|
+
steps: Step[];
|
|
87
|
+
selection: Selection;
|
|
88
|
+
}
|
|
89
|
+
type Intent = 'insertText' | 'insertParagraph' | 'insertLineBreak' | 'deleteBackward' | 'deleteForward';
|
|
90
|
+
declare function caret(path: Path): Selection;
|
|
91
|
+
declare function leafText(doc: ElementNode, leafPath: Path): string;
|
|
92
|
+
declare function wordBoundaryBack(text: string, offset: number): number | null;
|
|
93
|
+
declare function wordBoundaryFwd(text: string, offset: number): number | null;
|
|
94
|
+
declare function lineBoundaryBack(text: string, offset: number): number | null;
|
|
95
|
+
declare function lineBoundaryFwd(text: string, offset: number): number | null;
|
|
96
|
+
declare function isAtom(block: Node): boolean;
|
|
97
|
+
declare function isOpaque(block: Node): boolean;
|
|
98
|
+
declare function mapInput(doc: ElementNode, intent: Intent, data: string, sel: Selection, newId: () => string, rules?: BlockInputRule[], pendingMarks?: Mark[] | null): InputResult | null;
|
|
99
|
+
declare function wrapList(block: ElementNode, blockIdx: number, newId: () => string, rest: string, tail: Node[], ordered: boolean, start?: number): InputResult;
|
|
100
|
+
type BlockKind = 'paragraph' | 'heading1' | 'heading2' | 'heading3' | 'quote' | 'callout' | 'bullet' | 'ordered' | 'task' | 'code';
|
|
101
|
+
declare const CALLOUT_VARIANTS: readonly ["info", "warn", "success", "danger"];
|
|
102
|
+
type CalloutVariant = typeof CALLOUT_VARIANTS[number];
|
|
103
|
+
declare function calloutVariantFromQuery(q: string): CalloutVariant;
|
|
104
|
+
declare function blockTransform(block: ElementNode, blockIdx: number, kind: BlockKind, newId: () => string, extra?: {
|
|
105
|
+
variant?: CalloutVariant;
|
|
106
|
+
}): InputResult;
|
|
107
|
+
declare function setCalloutVariant(doc: ElementNode, path: Path, variant: CalloutVariant): InputResult | null;
|
|
108
|
+
declare function cycleCalloutVariant(doc: ElementNode, path: Path): InputResult | null;
|
|
109
|
+
declare function setAlign(doc: ElementNode, sel: Selection, align: 'left' | 'center' | 'right' | 'justify'): InputResult | null;
|
|
110
|
+
declare function marksAtCaret(doc: ElementNode, path: Path): Mark[];
|
|
111
|
+
declare function toggleMarkList(marks: Mark[], name: string, attrs?: Record<string, unknown>): Mark[];
|
|
112
|
+
declare function toggleMark(doc: ElementNode, sel: Selection, markName: string, attrs?: Record<string, unknown>): InputResult | null;
|
|
113
|
+
type TextStylePatch = {
|
|
114
|
+
color?: string | null;
|
|
115
|
+
backgroundColor?: string | null;
|
|
116
|
+
fontFamily?: string | null;
|
|
117
|
+
fontSize?: string | null;
|
|
118
|
+
};
|
|
119
|
+
declare function mergeTextStyleAttrs(attrs: Record<string, unknown> | undefined, patch: TextStylePatch): Record<string, unknown> | null;
|
|
120
|
+
declare function setTextStyle(doc: ElementNode, sel: Selection, patch: TextStylePatch): InputResult | null;
|
|
121
|
+
declare function serializeSelection(doc: ElementNode, sel: Selection): string;
|
|
122
|
+
declare function mapPaste(doc: ElementNode, sel: Selection, md: string, newId: () => string): InputResult | null;
|
|
123
|
+
declare function mapPasteBlocks(doc: ElementNode, sel: Selection, frag: ElementNode[], newId: () => string): InputResult | null;
|
|
124
|
+
declare function indentItem(doc: ElementNode, sel: Selection, newId: () => string): InputResult | null;
|
|
125
|
+
declare function outdentItem(doc: ElementNode, sel: Selection, newId: () => string): InputResult | null;
|
|
126
|
+
|
|
127
|
+
interface BlockRenderCtx {
|
|
128
|
+
renderChild: (node: ElementNode['children'][number], key: number) => ComponentChild;
|
|
129
|
+
slug?: (text: string) => string;
|
|
130
|
+
codeView?: NodeView;
|
|
131
|
+
atomSelect?: AtomSelectCtx | null;
|
|
132
|
+
}
|
|
133
|
+
type BlockRenderer = (spec: ElementNode, key: number | string, ctx: BlockRenderCtx) => ComponentChild;
|
|
134
|
+
interface InputRuleCtx {
|
|
135
|
+
doc: ElementNode;
|
|
136
|
+
block: ElementNode;
|
|
137
|
+
blockPath: number[];
|
|
138
|
+
parentPath: number[];
|
|
139
|
+
leafPath: number[];
|
|
140
|
+
leafIdx: number;
|
|
141
|
+
leafText: string;
|
|
142
|
+
offset: number;
|
|
143
|
+
marker: string;
|
|
144
|
+
trigger: string;
|
|
145
|
+
rest: string;
|
|
146
|
+
newId: () => string;
|
|
147
|
+
}
|
|
148
|
+
interface BlockInputRule {
|
|
149
|
+
match: (ctx: InputRuleCtx) => InputResult | null;
|
|
150
|
+
}
|
|
151
|
+
interface KeymapCtx {
|
|
152
|
+
doc: ElementNode;
|
|
153
|
+
sel: Selection | null;
|
|
154
|
+
markSel: Selection | null;
|
|
155
|
+
promptLink?: () => string | null;
|
|
156
|
+
}
|
|
157
|
+
type KeymapResult = InputResult | {
|
|
158
|
+
history: 'undo' | 'redo';
|
|
159
|
+
} | {
|
|
160
|
+
pendingToggle: string;
|
|
161
|
+
attrs?: Record<string, unknown>;
|
|
162
|
+
} | null;
|
|
163
|
+
type KeymapCommand = (ctx: KeymapCtx) => KeymapResult;
|
|
164
|
+
interface SlashCommand {
|
|
165
|
+
label: string;
|
|
166
|
+
/** 过滤匹配(与 label 一起参与 query 过滤) */
|
|
167
|
+
hint: string;
|
|
168
|
+
section?: string;
|
|
169
|
+
icon?: string;
|
|
170
|
+
/** 应用时回调;query 是去掉首 `/` 后的全文(如 `ai 写长一点`) */
|
|
171
|
+
run: (ctx: {
|
|
172
|
+
blockIdx: number;
|
|
173
|
+
query: string;
|
|
174
|
+
doc: ElementNode;
|
|
175
|
+
dispatch: DecorationHost['dispatch'];
|
|
176
|
+
}) => void;
|
|
177
|
+
}
|
|
178
|
+
interface DecorationHost {
|
|
179
|
+
root: HTMLElement;
|
|
180
|
+
doc: () => ElementNode;
|
|
181
|
+
dispatch: (steps: Step[], selectionAfter?: Selection) => void;
|
|
182
|
+
sel: () => Selection | null;
|
|
183
|
+
markSel: () => Selection | null;
|
|
184
|
+
insertImage: (blockIdx: number) => void;
|
|
185
|
+
insertMath?: (blockIdx: number) => void;
|
|
186
|
+
insertEmbed?: (blockIdx: number, kind: 'youtube' | 'twitch' | 'audio' | 'file') => void;
|
|
187
|
+
insertBelow: (blockIdx: number) => void;
|
|
188
|
+
langs: () => string[];
|
|
189
|
+
mentionSource: () => ((query: string) => MentionCandidate[]) | undefined;
|
|
190
|
+
promptLink?: () => string | null;
|
|
191
|
+
beginComment?: () => void;
|
|
192
|
+
slashCommands?: () => SlashCommand[] | undefined;
|
|
193
|
+
/** 格式栏 AI 续写/改写(Editor 在 opts.ai 时自动注入) */
|
|
194
|
+
openAi?: (mode: 'continue' | 'rewrite') => void;
|
|
195
|
+
/** 斜杠 /ai(Editor 在 opts.ai 时自动注入) */
|
|
196
|
+
openAiSlash?: (ctx: {
|
|
197
|
+
blockIdx: number;
|
|
198
|
+
query: string;
|
|
199
|
+
}) => void;
|
|
200
|
+
}
|
|
201
|
+
type DecorationFactory = (host: DecorationHost) => {
|
|
202
|
+
destroy: () => void;
|
|
203
|
+
};
|
|
204
|
+
type PasteRule = (md: string) => string;
|
|
205
|
+
interface Extension {
|
|
206
|
+
name: string;
|
|
207
|
+
marks?: {
|
|
208
|
+
name: string;
|
|
209
|
+
tag: string;
|
|
210
|
+
props?: (mark: Mark) => Record<string, unknown>;
|
|
211
|
+
}[];
|
|
212
|
+
blocks?: {
|
|
213
|
+
type: string;
|
|
214
|
+
render: BlockRenderer;
|
|
215
|
+
}[];
|
|
216
|
+
keymap?: Record<string, KeymapCommand>;
|
|
217
|
+
inputRules?: BlockInputRule[];
|
|
218
|
+
pasteRules?: PasteRule[];
|
|
219
|
+
decorations?: DecorationFactory[];
|
|
220
|
+
}
|
|
221
|
+
interface Resolved {
|
|
222
|
+
markTags: Record<string, string>;
|
|
223
|
+
markProps: Record<string, (mark: Mark) => Record<string, unknown>>;
|
|
224
|
+
blockRenderers: Record<string, BlockRenderer>;
|
|
225
|
+
keymap: Record<string, KeymapCommand>;
|
|
226
|
+
inputRules: BlockInputRule[];
|
|
227
|
+
pasteRules: PasteRule[];
|
|
228
|
+
decorationFactories: DecorationFactory[];
|
|
229
|
+
}
|
|
230
|
+
declare function resolve(extensions: Extension[]): Resolved;
|
|
231
|
+
|
|
232
|
+
/** OpenAI-compatible 供应商配置(xAI / OpenAI / 智谱 …) */
|
|
233
|
+
type AiProvider = {
|
|
234
|
+
host: string;
|
|
235
|
+
apiKey: string;
|
|
236
|
+
model: string;
|
|
237
|
+
};
|
|
238
|
+
type AiConfig = {
|
|
239
|
+
/**
|
|
240
|
+
* 供应商。可函数(读最新设置)。
|
|
241
|
+
* 配了 endpoint 时仍会把 provider 转给代理。
|
|
242
|
+
*/
|
|
243
|
+
provider?: AiProvider | (() => AiProvider | null | undefined);
|
|
244
|
+
/**
|
|
245
|
+
* 浏览器代理路径(如 Vite 插件 `/api/ai/stream`)。
|
|
246
|
+
* 有则走代理协议;无则直连 provider.host 的 chat/completions(需 CORS)。
|
|
247
|
+
*/
|
|
248
|
+
endpoint?: string;
|
|
249
|
+
/** 完全自定义流;设了则忽略 provider/endpoint */
|
|
250
|
+
stream?: AiStreamFn;
|
|
251
|
+
continueSystem?: string;
|
|
252
|
+
rewriteSystem?: string;
|
|
253
|
+
onError?: (message: string) => void;
|
|
254
|
+
onBusy?: (busy: boolean) => void;
|
|
255
|
+
};
|
|
256
|
+
/** 由 AiConfig 生成默认 stream(代理或直连 OpenAI-compatible) */
|
|
257
|
+
declare function createAiStream(cfg: AiConfig): AiStreamFn;
|
|
258
|
+
|
|
259
|
+
type AiWriteMode = 'continue' | 'rewrite';
|
|
260
|
+
interface AiWriteSession {
|
|
261
|
+
readonly mode: AiWriteMode;
|
|
262
|
+
readonly blockId: string;
|
|
263
|
+
/** 灌一段 token(可多次)。会话结束后勿再调。 */
|
|
264
|
+
push: (text: string) => void;
|
|
265
|
+
/** 正常结束 */
|
|
266
|
+
done: () => void;
|
|
267
|
+
/** 中止(保留已写入内容,仍可一次 undo) */
|
|
268
|
+
abort: () => void;
|
|
269
|
+
readonly alive: boolean;
|
|
270
|
+
}
|
|
271
|
+
/** 光标所在顶层块 id;无选区/无 id → null */
|
|
272
|
+
declare function focusBlockId(ed: Editor): string | null;
|
|
273
|
+
/** 顶层块纯文本(块内文本叶拼接) */
|
|
274
|
+
declare function blockPlainText(doc: ElementNode, blockId: string): string;
|
|
275
|
+
declare function startAiWrite(ed: Editor, mode: AiWriteMode, blockId?: string): AiWriteSession;
|
|
276
|
+
|
|
277
|
+
interface MentionProfile {
|
|
278
|
+
id: string;
|
|
279
|
+
name: string;
|
|
280
|
+
avatar?: string;
|
|
281
|
+
title?: string;
|
|
282
|
+
department?: string;
|
|
283
|
+
email?: string;
|
|
284
|
+
status?: string;
|
|
285
|
+
}
|
|
286
|
+
interface MentionPopoversHost {
|
|
287
|
+
root: HTMLElement;
|
|
288
|
+
profile?: (id: string) => MentionProfile | null | undefined;
|
|
289
|
+
/** 改时间:本地 ISO 到秒 `YYYY-MM-DDTHH:mm:ss` */
|
|
290
|
+
onDateChange?: (path: number[], nextIso: string) => void;
|
|
291
|
+
}
|
|
292
|
+
declare class MentionPopovers {
|
|
293
|
+
private host;
|
|
294
|
+
private overlay;
|
|
295
|
+
private mode;
|
|
296
|
+
constructor(host: MentionPopoversHost);
|
|
297
|
+
destroy(): void;
|
|
298
|
+
close: () => void;
|
|
299
|
+
openPerson(profile: MentionProfile, anchor: DOMRect): void;
|
|
300
|
+
openDate(iso: string, path: number[], anchor: DOMRect): void;
|
|
301
|
+
private onDocDown;
|
|
302
|
+
private onKey;
|
|
303
|
+
private paint;
|
|
304
|
+
private placePop;
|
|
305
|
+
private paintPerson;
|
|
306
|
+
private paintDateTime;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
interface EditorOptions {
|
|
310
|
+
onChange?: (doc: ElementNode) => void;
|
|
311
|
+
slug?: () => (text: string) => string;
|
|
312
|
+
nodeViews?: {
|
|
313
|
+
code?: NodeView;
|
|
314
|
+
};
|
|
315
|
+
promptLink?: () => string | null;
|
|
316
|
+
placeholder?: string;
|
|
317
|
+
editable?: boolean;
|
|
318
|
+
onImage?: (file: File) => Promise<string>;
|
|
319
|
+
mentionSource?: (query: string) => MentionCandidate[];
|
|
320
|
+
mentionProfile?: (id: string) => MentionProfile | null | undefined;
|
|
321
|
+
renderMath?: (latex: string, display: boolean) => string | null;
|
|
322
|
+
invisibleCharacters?: boolean;
|
|
323
|
+
comments?: {
|
|
324
|
+
threads?: CommentThread[];
|
|
325
|
+
author?: () => CommentAuthor;
|
|
326
|
+
onChange?: (threads: CommentThread[]) => void;
|
|
327
|
+
};
|
|
328
|
+
toc?: boolean | {
|
|
329
|
+
open?: boolean;
|
|
330
|
+
};
|
|
331
|
+
extensions?: Extension[];
|
|
332
|
+
slashCommands?: SlashCommand[] | (() => SlashCommand[] | undefined);
|
|
333
|
+
/**
|
|
334
|
+
* AI 写作(一等公民,类 vite 配置)。传 true 或 AiConfig 即启用:
|
|
335
|
+
* 斜杠 /ai、格式栏续写/改写、文档内卡片、默认流式客户端 全内置。
|
|
336
|
+
* 应用只配 provider / endpoint。
|
|
337
|
+
*/
|
|
338
|
+
ai?: boolean | AiConfig;
|
|
339
|
+
}
|
|
340
|
+
declare class Editor {
|
|
341
|
+
root: HTMLElement;
|
|
342
|
+
history: History;
|
|
343
|
+
private composing;
|
|
344
|
+
private composeBase;
|
|
345
|
+
private pendingMarks;
|
|
346
|
+
private opts;
|
|
347
|
+
private resolved;
|
|
348
|
+
private invisible;
|
|
349
|
+
private tableControls;
|
|
350
|
+
private imageControls;
|
|
351
|
+
private commentPanel;
|
|
352
|
+
private tocPanel;
|
|
353
|
+
private mentionPops;
|
|
354
|
+
private decorations;
|
|
355
|
+
/** AI 一等公民(opts.ai):斜杠 / 格式栏 / 卡片全内置 */
|
|
356
|
+
private aiCtl;
|
|
357
|
+
constructor(root: HTMLElement, doc: ElementNode, opts?: EditorOptions);
|
|
358
|
+
destroy(): void;
|
|
359
|
+
/** AI 控制器(opts.ai 启用时);应用工具栏可 ed.ai?.openAtFocus / stop */
|
|
360
|
+
get ai(): LoomAi | null;
|
|
361
|
+
openAi(mode: 'continue' | 'rewrite'): void;
|
|
362
|
+
stopAi(): void;
|
|
363
|
+
get doc(): ElementNode;
|
|
364
|
+
setEditable(editable: boolean): void;
|
|
365
|
+
setInvisibleCharacters(visible: boolean): void;
|
|
366
|
+
get invisibleCharacters(): boolean;
|
|
367
|
+
get comments(): CommentThread[];
|
|
368
|
+
setComments(threads: CommentThread[]): void;
|
|
369
|
+
private get readonly();
|
|
370
|
+
private draw;
|
|
371
|
+
private syncPlaceholder;
|
|
372
|
+
dispatch(steps: Step[], selectionAfter?: Selection): void;
|
|
373
|
+
dispatchStream(steps: Step[], selectionAfter?: Selection): void;
|
|
374
|
+
/** 回退一笔 history(AI 事务 discard = undo 整笔) */
|
|
375
|
+
undo(): boolean;
|
|
376
|
+
redo(): boolean;
|
|
377
|
+
/** 续写:当前块后插空段并流式灌入 */
|
|
378
|
+
aiContinue(blockId?: string): AiWriteSession;
|
|
379
|
+
/** 改写:清空当前块再流式回填 */
|
|
380
|
+
aiRewrite(blockId?: string): AiWriteSession;
|
|
381
|
+
private onCompositionStart;
|
|
382
|
+
private onClick;
|
|
383
|
+
private onTaskCheck;
|
|
384
|
+
private openMentionPop;
|
|
385
|
+
private setMentionDate;
|
|
386
|
+
private onBeforeInput;
|
|
387
|
+
/** caret 是否在 type=ai 块内;是则返该块,否则 null */
|
|
388
|
+
private aiBlockAt;
|
|
389
|
+
private aiBlockGuard;
|
|
390
|
+
private codeEdge;
|
|
391
|
+
private codeBlockGuard;
|
|
392
|
+
private atomControls;
|
|
393
|
+
private atomAtEdge;
|
|
394
|
+
private atomAt;
|
|
395
|
+
private onEdgeVisualLine;
|
|
396
|
+
private atomAtEdgeVertical;
|
|
397
|
+
private atomSelectGuard;
|
|
398
|
+
private atomBlockGuard;
|
|
399
|
+
private neighborCaret;
|
|
400
|
+
private isCodeBlock;
|
|
401
|
+
private inListItem;
|
|
402
|
+
private codeBoundaryDelete;
|
|
403
|
+
private wordLineDelete;
|
|
404
|
+
private onCompositionEnd;
|
|
405
|
+
private onKeyDown;
|
|
406
|
+
private markSel;
|
|
407
|
+
private onCopy;
|
|
408
|
+
private onCut;
|
|
409
|
+
private onPaste;
|
|
410
|
+
private insertImageFile;
|
|
411
|
+
private insertImageUrl;
|
|
412
|
+
private slashInsertImage;
|
|
413
|
+
private slashInsertMath;
|
|
414
|
+
private slashInsertEmbed;
|
|
415
|
+
private editMathAtom;
|
|
416
|
+
private isEmptyTopPara;
|
|
417
|
+
private insertBelow;
|
|
418
|
+
private straddlesAtom;
|
|
419
|
+
private isAtomBlock;
|
|
420
|
+
private tableCaret;
|
|
421
|
+
private tabInTable;
|
|
422
|
+
private arrowInTable;
|
|
423
|
+
private onFocusIn;
|
|
424
|
+
private onFocusOut;
|
|
425
|
+
}
|
|
426
|
+
declare function chord(e: KeyboardEvent): string;
|
|
427
|
+
declare function diffSpan(a: string, b: string): {
|
|
428
|
+
at: number;
|
|
429
|
+
remove: number;
|
|
430
|
+
insert: string;
|
|
431
|
+
} | null;
|
|
432
|
+
|
|
433
|
+
/** host 注入的流式通道(不绑具体模型/HTTP) */
|
|
434
|
+
type AiStreamInput = {
|
|
435
|
+
action: AiPromptMode;
|
|
436
|
+
context: string;
|
|
437
|
+
docPreview?: string;
|
|
438
|
+
signal?: AbortSignal;
|
|
439
|
+
};
|
|
440
|
+
type AiStreamFn = (input: AiStreamInput, onToken: (text: string) => void) => Promise<void>;
|
|
441
|
+
type LoomAiOpts = {
|
|
442
|
+
stream: AiStreamFn;
|
|
443
|
+
onError?: (message: string) => void;
|
|
444
|
+
onBusy?: (busy: boolean) => void;
|
|
445
|
+
};
|
|
446
|
+
type AiPromptMode = 'continue' | 'rewrite';
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* loom/ai — 一笔完整事务:
|
|
450
|
+
*
|
|
451
|
+
* begin (dispatch) 插入真·顶层段落(aiDraft) + loading
|
|
452
|
+
* stream (amend) token 追加到真段落,随时可见
|
|
453
|
+
* accept (amend) 去掉淡化标记 + 拆掉指令壳 —— 仍同一笔 undo
|
|
454
|
+
* discard (undo) 整笔撤回,文档回到 run 之前
|
|
455
|
+
*
|
|
456
|
+
* 段落从第一 pen 起就在 doc 里,不是影子预览;淡化只是事务未提交的视觉态。
|
|
457
|
+
*/
|
|
458
|
+
declare class LoomAi {
|
|
459
|
+
private getEditor;
|
|
460
|
+
private opts;
|
|
461
|
+
private abort;
|
|
462
|
+
private streamingId;
|
|
463
|
+
/** 当前 AI 写事务是否打开(begin 后 ~ accept/discard) */
|
|
464
|
+
private txOpen;
|
|
465
|
+
private txBlockId;
|
|
466
|
+
private raf;
|
|
467
|
+
/** 流式累积的 Markdown 源(每帧物化成真·富文本块做预览) */
|
|
468
|
+
private pendingMd;
|
|
469
|
+
constructor(getEditor: () => Editor | null, opts: LoomAiOpts);
|
|
470
|
+
destroy(): void;
|
|
471
|
+
/**
|
|
472
|
+
* 停止生成:
|
|
473
|
+
* · 已有正文 → 留在事务内,进入 preview(可确认/可 undo 整笔)
|
|
474
|
+
* · 空 → undo 整笔事务(等同丢弃)
|
|
475
|
+
*/
|
|
476
|
+
stop(): void;
|
|
477
|
+
private clearRaf;
|
|
478
|
+
get busy(): boolean;
|
|
479
|
+
/** 是否有未提交的 AI 写事务 */
|
|
480
|
+
get pending(): boolean;
|
|
481
|
+
openAtFocus(mode: AiPromptMode): void;
|
|
482
|
+
openFromSlash(blockIdx: number, query: string): void;
|
|
483
|
+
/**
|
|
484
|
+
* begin 事务:dispatch 一次插入真段落;
|
|
485
|
+
* 之后 token / 状态 / accept 全走 amend,一笔 undo 整回退。
|
|
486
|
+
*/
|
|
487
|
+
run(blockId: string): Promise<void>;
|
|
488
|
+
/**
|
|
489
|
+
* 提交事务:正文已在文档里 —— 去掉淡化 + 拆指令壳。
|
|
490
|
+
* 走 amend,与 begin/stream 同一笔 undo。
|
|
491
|
+
*/
|
|
492
|
+
accept(blockId: string): void;
|
|
493
|
+
/** 整笔撤回事务(= undo) */
|
|
494
|
+
discard(blockId: string): void;
|
|
495
|
+
act(blockId: string, action: string): void;
|
|
496
|
+
private rollback;
|
|
497
|
+
private findAi;
|
|
498
|
+
/** 事务内改 ai attrs(永远 amend) */
|
|
499
|
+
private patchAi;
|
|
500
|
+
/**
|
|
501
|
+
* 累积 Markdown → 物化顶层真块(heading/list/code/quote/marks…)。
|
|
502
|
+
* streaming 时 softClose 未闭合 fence/marks,末块带 aiStream 光标。
|
|
503
|
+
*/
|
|
504
|
+
private paintMd;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export { diffSpan as $, type AiConfig as A, type BlockInputRule as B, CALLOUT_VARIANTS as C, type DecorationFactory as D, type EditorOptions as E, type MentionPopoversHost as F, type MentionProfile as G, type NodeViewCtx as H, type InputResult as I, type Resolved as J, type KeymapCommand as K, LoomAi as L, type MentionCandidate as M, type NodeView as N, atomIsSelected as O, type PasteRule as P, blockTransform as Q, type RenderOpts as R, type SlashCommand as S, type TextStylePatch as T, calloutVariantFromQuery as U, caret as V, chord as W, cycleCalloutVariant as X, defaultBlockRenderers as Y, defaultBlockTag as Z, defaultMarkTag as _, type AiPromptMode as a, indentItem as a0, isAtom as a1, isOpaque as a2, leafText as a3, lineBoundaryBack as a4, lineBoundaryFwd as a5, mapInput as a6, mapPaste as a7, mapPasteBlocks as a8, marksAtCaret as a9, mergeTextStyleAttrs as aa, outdentItem as ab, renderCode as ac, renderDoc as ad, renderEmbed as ae, renderHr as af, renderImage as ag, renderTable as ah, renderToHtml as ai, resolve as aj, safeCssValue as ak, serializeSelection as al, setAlign as am, setCalloutVariant as an, setTextStyle as ao, textStyleCss as ap, toggleMark as aq, toggleMarkList as ar, twitchChannel as as, wordBoundaryBack as at, wordBoundaryFwd as au, wrapList as av, youtubeId as aw, type AiProvider as b, type AiStreamFn as c, type AiStreamInput as d, type AiWriteMode as e, type AiWriteSession as f, type LoomAiOpts as g, blockPlainText as h, createAiStream as i, focusBlockId as j, Editor as k, type Extension as l, type AtomSelectCtx as m, type BlockKind as n, type BlockRenderCtx as o, type BlockRenderer as p, type CalloutVariant as q, type DecorationHost as r, startAiWrite as s, type InputRuleCtx as t, type Intent as u, type KeymapCtx as v, type KeymapResult as w, type MentionHost as x, MentionMenu as y, MentionPopovers as z };
|