@4399ywkf/editor 0.9.1 → 0.9.3
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/dist/{DocView-R4E7QINT.js → DocView-YBRD4V4E.js} +6 -5
- package/dist/DocView-YBRD4V4E.js.map +1 -0
- package/dist/chunk-4MQS76M2.js +51666 -0
- package/dist/chunk-4MQS76M2.js.map +1 -0
- package/dist/chunk-ABMZOL26.js +116 -0
- package/dist/chunk-ABMZOL26.js.map +1 -0
- package/dist/{chunk-QMYT5WXO.js → chunk-MGSVKKK7.js} +2 -2
- package/dist/{chunk-QMYT5WXO.js.map → chunk-MGSVKKK7.js.map} +1 -1
- package/dist/chunk-UD6MDBTN.js +1192 -0
- package/dist/chunk-UD6MDBTN.js.map +1 -0
- package/dist/{code-types-Dqmit3xx.d.ts → code-types-BTrUO25D.d.ts} +9 -1
- package/dist/diagram-canvas-22ANCGUV.js +261 -0
- package/dist/diagram-canvas-22ANCGUV.js.map +1 -0
- package/dist/doc-runtime.js +45 -7
- package/dist/doc-runtime.js.map +1 -1
- package/dist/doc.d.ts +526 -54
- package/dist/doc.js +4 -3
- package/dist/doc.js.map +1 -1
- package/dist/docx.js +115 -13
- package/dist/docx.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/pdf.d.ts +2 -2
- package/dist/plugins/ai.js +1 -1
- package/dist/pptx.d.ts +2 -2
- package/dist/{registry-BQ5T1Yko.d.ts → registry-ByvNr_Fa.d.ts} +1 -1
- package/dist/sheet.d.ts +3 -3
- package/dist/style.css +1049 -6047
- package/package.json +21 -5
- package/dist/DocView-R4E7QINT.js.map +0 -1
- package/dist/chunk-OGRGQQ3D.js +0 -23747
- package/dist/chunk-OGRGQQ3D.js.map +0 -1
- package/dist/chunk-ZY5KLA7T.js +0 -258
- package/dist/chunk-ZY5KLA7T.js.map +0 -1
package/dist/doc.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, RefObject, useEffect, HTMLAttributes } from 'react';
|
|
3
|
-
import { JSONContent, Editor, NodeWithPos, Extension as Extension$1, Node as Node$1 } from '@tiptap/react';
|
|
3
|
+
import { JSONContent, Editor as Editor$1, NodeWithPos, Extension as Extension$1, Node as Node$1 } from '@tiptap/react';
|
|
4
4
|
import * as _tiptap_core from '@tiptap/core';
|
|
5
|
-
import { Extensions, JSONContent as JSONContent$1, Extension } from '@tiptap/core';
|
|
5
|
+
import { Editor, Extensions, JSONContent as JSONContent$1, Extension, Node as Node$2 } from '@tiptap/core';
|
|
6
6
|
import { Doc } from 'yjs';
|
|
7
|
-
import { C as ContentFormat, a as CodeBlockOptions, b as CodeHighlighter } from './code-types-
|
|
8
|
-
export { c as CodeBlockAttrs, d as CodeGroupAttrs, H as HighlightResult, e as HighlightToken, S as ShikiTheme } from './code-types-
|
|
7
|
+
import { C as ContentFormat, a as CodeBlockOptions, b as CodeHighlighter } from './code-types-BTrUO25D.js';
|
|
8
|
+
export { c as CodeBlockAttrs, d as CodeGroupAttrs, H as HighlightResult, e as HighlightToken, S as ShikiTheme } from './code-types-BTrUO25D.js';
|
|
9
9
|
import { CodeBlockOptions as CodeBlockOptions$1 } from '@tiptap/extension-code-block';
|
|
10
10
|
import { UseFloatingOptions, UseDismissProps, AutoUpdateOptions } from '@floating-ui/react';
|
|
11
11
|
import { Selection, Transaction } from '@tiptap/pm/state';
|
|
@@ -16,6 +16,28 @@ import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
|
16
16
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
|
17
17
|
import 'shiki';
|
|
18
18
|
|
|
19
|
+
type ViewMode = "edit" | "read";
|
|
20
|
+
/** 谁触发的切换:用户(顶栏、快捷键、工具条)切换后弹提示,宿主改受控值不弹 */
|
|
21
|
+
type ViewModeSource = "user" | "host";
|
|
22
|
+
interface ViewModeContextValue {
|
|
23
|
+
mode: ViewMode;
|
|
24
|
+
/** 有没有编辑权限;没有就不显示切换 */
|
|
25
|
+
canEdit: boolean;
|
|
26
|
+
setMode: (mode: ViewMode, source?: ViewModeSource) => void;
|
|
27
|
+
}
|
|
28
|
+
declare const useViewMode: () => ViewModeContextValue;
|
|
29
|
+
/** 切换后的提示(飞书 module 719431) */
|
|
30
|
+
declare const VIEW_MODE_TOAST: Record<ViewMode, string>;
|
|
31
|
+
|
|
32
|
+
type DocWidthMode = "standard" | "large" | "full";
|
|
33
|
+
/** 默认 / 较宽两档的正文宽度(飞书 module 366107 `p2={large:1020,standard:820}`) */
|
|
34
|
+
declare const DOC_WIDTHS: Record<Exclude<DocWidthMode, "full">, number>;
|
|
35
|
+
interface WidthModeContextValue {
|
|
36
|
+
mode: DocWidthMode;
|
|
37
|
+
setMode: (mode: DocWidthMode) => void;
|
|
38
|
+
}
|
|
39
|
+
declare const useWidthMode: () => WidthModeContextValue;
|
|
40
|
+
|
|
19
41
|
/**
|
|
20
42
|
* 包消费者通过 `<EditorConfigProvider>` 注入业务侧能力。
|
|
21
43
|
*
|
|
@@ -117,10 +139,167 @@ declare const detectMediaKind: (file: {
|
|
|
117
139
|
}) => MediaKind;
|
|
118
140
|
/** 合并业务配置 + 默认值,拿到指定类型的 size 上限。 */
|
|
119
141
|
declare const resolveMaxSize: (kind: MediaKind, config: EditorUploadConfig | null | undefined) => number;
|
|
142
|
+
/** @人 下拉里的一个人。文档里只存 id 和当时的名字(label),飞书同样只存 uid */
|
|
143
|
+
interface MentionUser {
|
|
144
|
+
id: string;
|
|
145
|
+
name: string;
|
|
146
|
+
avatar?: string;
|
|
147
|
+
/** 名字下面的说明,比如部门或职位 */
|
|
148
|
+
description?: string;
|
|
149
|
+
}
|
|
150
|
+
/** @文档 下拉里的一篇文档。文档里存 id、当时的标题和链接(飞书 mention_doc 存 token/title/raw_url) */
|
|
151
|
+
interface MentionDoc {
|
|
152
|
+
id: string;
|
|
153
|
+
title: string;
|
|
154
|
+
/** 点击后打开的地址 */
|
|
155
|
+
url: string;
|
|
156
|
+
/** 文档类型,宿主自定,比如 doc / sheet / wiki;只用来挑图标、给宿主回传 */
|
|
157
|
+
docType?: string;
|
|
158
|
+
/** 标题下面的说明,比如所在空间、更新时间 */
|
|
159
|
+
description?: string;
|
|
160
|
+
}
|
|
161
|
+
interface EditorMentionConfig {
|
|
162
|
+
/**
|
|
163
|
+
* 按输入的关键字查人。query 为空时返回推荐名单(比如最近联系人)。
|
|
164
|
+
* 不配置时 @ 列表里没有人。
|
|
165
|
+
*/
|
|
166
|
+
fetchUsers?: (query: string) => Promise<MentionUser[]>;
|
|
167
|
+
/** 点文档里的 @某人(编辑和只读都会触发),宿主可以打开个人主页、名片等 */
|
|
168
|
+
onMentionClick?: (user: {
|
|
169
|
+
id: string;
|
|
170
|
+
label: string;
|
|
171
|
+
}, event: MouseEvent) => void;
|
|
172
|
+
/**
|
|
173
|
+
* @文档:按关键字搜文档,query 为空时返回推荐(比如最近访问)。
|
|
174
|
+
* 不配置时 @ 列表里没有文档。人和文档都没配置时输入 @ 不弹列表。
|
|
175
|
+
*/
|
|
176
|
+
searchDocs?: (query: string) => Promise<MentionDoc[]>;
|
|
177
|
+
/** 点文档里的 @文档。不配置时在新标签页打开 url */
|
|
178
|
+
onDocClick?: (doc: {
|
|
179
|
+
id: string;
|
|
180
|
+
title: string;
|
|
181
|
+
url: string;
|
|
182
|
+
docType: string | null;
|
|
183
|
+
}, event: MouseEvent) => void;
|
|
184
|
+
/**
|
|
185
|
+
* 给被 @ 的人发通知。配置了,@ 列表底部才有「同时发送通知」勾选(默认勾上,记在本地)。
|
|
186
|
+
* 选人后提示「{名字} 将收到通知」+「撤销」,8 秒内没撤销、这个 @ 还在文档里才调用;@ 自己不通知。
|
|
187
|
+
* 抛错时提示「发送通知失败,请重试」。
|
|
188
|
+
*/
|
|
189
|
+
notifyUser?: (params: MentionNotifyParams) => Promise<void> | void;
|
|
190
|
+
/**
|
|
191
|
+
* 批量查 @文档 的最新标题和访问权限,返回 `{[id]: 状态}`,查不到的可以不返回。
|
|
192
|
+
* 编辑器就绪后查一次全文,插入一篇、鼠标移到一篇上时再查那一篇。
|
|
193
|
+
* 新标题只改显示,不改文档内容(飞书同样只存插入时的标题)。
|
|
194
|
+
*/
|
|
195
|
+
resolveDocs?: (ids: string[]) => Promise<Record<string, MentionDocState | null | undefined>>;
|
|
196
|
+
}
|
|
197
|
+
/** 发 @人 通知时交给宿主的信息 */
|
|
198
|
+
interface MentionNotifyParams {
|
|
199
|
+
user: {
|
|
200
|
+
id: string;
|
|
201
|
+
name: string;
|
|
202
|
+
};
|
|
203
|
+
/** 这一次 @ 的 id(插入时生成,存在节点的 mentionId 上),可以用来去重、跳回原文 */
|
|
204
|
+
mentionId: string;
|
|
205
|
+
/** @ 所在段落的纯文本,通知里可以带上 */
|
|
206
|
+
context: string;
|
|
207
|
+
}
|
|
208
|
+
/** 一篇 @文档 的最新状态 */
|
|
209
|
+
interface MentionDocState {
|
|
210
|
+
/** 最新标题;空或不传就沿用文档里存的 */
|
|
211
|
+
title?: string;
|
|
212
|
+
/**
|
|
213
|
+
* 当前用户能不能看(飞书 mention_doc 的权限码):
|
|
214
|
+
* - readable:正常显示(默认);
|
|
215
|
+
* - apply:没权限但可以申请,深灰显示,点击照常打开;
|
|
216
|
+
* - denied:没权限也不能申请,浅灰显示,悬停提示「暂无权限访问该文档,权限申请已被关闭」,点击不打开。
|
|
217
|
+
*/
|
|
218
|
+
access?: "readable" | "apply" | "denied";
|
|
219
|
+
}
|
|
220
|
+
/** 网页的标题、图标、封面和摘要,标题视图和卡片视图用(飞书 bookmark 字段) */
|
|
221
|
+
interface LinkPreview {
|
|
222
|
+
title?: string;
|
|
223
|
+
/** 网站图标地址 */
|
|
224
|
+
icon?: string;
|
|
225
|
+
/** 封面图地址 */
|
|
226
|
+
cover?: string;
|
|
227
|
+
/** 摘要,超过 1000 字会截断 */
|
|
228
|
+
summary?: string;
|
|
229
|
+
}
|
|
230
|
+
interface EditorLinkConfig {
|
|
231
|
+
/**
|
|
232
|
+
* 抓取网页信息(一般由宿主后端抓 Open Graph / <title>)。抓不到返回 null。
|
|
233
|
+
* 配置后粘贴链接时「显示为」面板才有「标题视图」「卡片视图」,斜杠菜单才有「网页卡片」。
|
|
234
|
+
*/
|
|
235
|
+
unfurl: (url: string) => Promise<LinkPreview | null>;
|
|
236
|
+
}
|
|
237
|
+
/** 文件块预览时交给宿主的文件信息 */
|
|
238
|
+
interface FilePreviewInfo {
|
|
239
|
+
src: string;
|
|
240
|
+
name: string;
|
|
241
|
+
size: number;
|
|
242
|
+
mimeType: string;
|
|
243
|
+
/** 预览区域高度(px),宽度铺满正文 */
|
|
244
|
+
height: number;
|
|
245
|
+
}
|
|
246
|
+
interface EditorFileConfig {
|
|
247
|
+
/**
|
|
248
|
+
* 文件「预览视图」的渲染入口:宿主可以接自己的预览服务(Office 在线预览、PdfView、PptxView……)。
|
|
249
|
+
* 返回 null / undefined 时用内置预览:PDF 走浏览器内置阅读器,图片、音视频走原生标签,纯文本走 iframe,
|
|
250
|
+
* 其它类型提示「无法预览,请下载到本地查看」。
|
|
251
|
+
*/
|
|
252
|
+
renderPreview?: (file: FilePreviewInfo) => ReactNode | null | undefined;
|
|
253
|
+
/**
|
|
254
|
+
* `renderPreview` 能预览的扩展名(如 ["docx", "xlsx", "pptx"])。新上传的这类文件小于 10MB 时默认用预览视图
|
|
255
|
+
* (飞书:能预览的文档小于 10MB 默认预览)。不配就只有 PDF、纯文本算「能预览的文档」。
|
|
256
|
+
*/
|
|
257
|
+
previewTypes?: string[];
|
|
258
|
+
}
|
|
259
|
+
/** 投票的一个投票人(实名投票时宿主返回) */
|
|
260
|
+
interface PollVoter {
|
|
261
|
+
id: string;
|
|
262
|
+
name: string;
|
|
263
|
+
avatar?: string;
|
|
264
|
+
/** 投票时间(毫秒时间戳),投票详情里显示 */
|
|
265
|
+
votedAt?: number;
|
|
266
|
+
}
|
|
267
|
+
/** 一个投票当前的票数(飞书票数存在后端,不在文档里) */
|
|
268
|
+
interface PollVotes {
|
|
269
|
+
/** 每个选项的票数,key 是选项 id */
|
|
270
|
+
counts: Record<string, number>;
|
|
271
|
+
/** 投票人数(多选时一个人可以投多项) */
|
|
272
|
+
userCount: number;
|
|
273
|
+
/** 当前用户投了哪些选项,没投过是空数组 */
|
|
274
|
+
myChoice: string[];
|
|
275
|
+
/** 实名投票时每个选项的投票人;匿名投票不要返回 */
|
|
276
|
+
voters?: Record<string, PollVoter[]>;
|
|
277
|
+
}
|
|
278
|
+
/** 投票的票数读写入口。配置了斜杠菜单才有「投票」 */
|
|
279
|
+
interface EditorPollConfig {
|
|
280
|
+
/** 读一个投票(pollId 是投票块里的 id)当前的票数 */
|
|
281
|
+
getVotes: (pollId: string) => Promise<PollVotes>;
|
|
282
|
+
/** 当前用户投票,返回投完之后的票数。投票后不能改(飞书「投票后不可修改」) */
|
|
283
|
+
vote: (pollId: string, optionIds: string[]) => Promise<PollVotes>;
|
|
284
|
+
/** 订阅别人投票带来的变化,返回取消订阅函数;不配就只在打开和投票后刷新 */
|
|
285
|
+
subscribe?: (pollId: string, onChange: (votes: PollVotes) => void) => () => void;
|
|
286
|
+
}
|
|
287
|
+
/** 按钮里交给宿主执行的操作(飞书按钮的「创建副本」「关注文档更新」) */
|
|
288
|
+
interface EditorButtonConfig {
|
|
289
|
+
/** 「创建副本」:复制当前文档。配置了,按钮的执行操作里才有这一项 */
|
|
290
|
+
duplicatePage?: () => void;
|
|
291
|
+
/** 「关注文档更新」。配置了,按钮的执行操作里才有这一项 */
|
|
292
|
+
followPage?: () => void;
|
|
293
|
+
}
|
|
120
294
|
interface EditorConfig {
|
|
295
|
+
button?: EditorButtonConfig;
|
|
296
|
+
poll?: EditorPollConfig;
|
|
121
297
|
collab?: EditorCollabConfig;
|
|
298
|
+
file?: EditorFileConfig;
|
|
122
299
|
user?: EditorUserConfig;
|
|
123
300
|
upload?: EditorUploadConfig;
|
|
301
|
+
mention?: EditorMentionConfig;
|
|
302
|
+
link?: EditorLinkConfig;
|
|
124
303
|
}
|
|
125
304
|
interface EditorConfigProviderProps {
|
|
126
305
|
config: EditorConfig;
|
|
@@ -130,6 +309,115 @@ declare function EditorConfigProvider({ config, children, }: EditorConfigProvide
|
|
|
130
309
|
/** 拿到当前注入的编辑器业务配置;未注入时返回 null。 */
|
|
131
310
|
declare const useEditorConfig: () => EditorConfig | null;
|
|
132
311
|
|
|
312
|
+
/**
|
|
313
|
+
* 只读(分享给外部只读访问)守卫,照飞书(证据见组件规格 §57):
|
|
314
|
+
*
|
|
315
|
+
* - 没有编辑权限(`readOnly`)时,本地发起的文档改动一律拒绝。协同同步进来的远端改动、编辑器内部带
|
|
316
|
+
* `ALLOW_IN_READ_ONLY` 标记的改动(宿主换 content)、只给节点补标识的改动(UniqueID 的 id、目录的 data-toc-id)放行。各组件自己也关掉了编辑入口,这里兜底:
|
|
317
|
+
* 只读访问者连着协同房间时,任何漏网的改动都不会写进共享文档。
|
|
318
|
+
* - 不可编辑时不能把块拖出去(飞书给访问者根本不加载 Draggable 模块)。
|
|
319
|
+
* - 文档权限 `permissions`(飞书 PERM_ACTION_TYPE 的 copy / download(export) / print,所有者可关):
|
|
320
|
+
* - 复制关了:⌘C / 剪切被拦,提示「复制失败,所有者关闭了文档的复制功能」;正文右键菜单屏蔽;
|
|
321
|
+
* - 下载关了:各处下载按钮不出(组件读 getDocPermissions);
|
|
322
|
+
* - 打印关了:⌘P 吞掉,打印出来是空白(见 print-document)。
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
interface DocPermissions {
|
|
326
|
+
/** 复制正文 / 代码;默认 true */
|
|
327
|
+
copy: boolean;
|
|
328
|
+
/** 下载图片、视频、音频、附件、流程图;默认 true */
|
|
329
|
+
download: boolean;
|
|
330
|
+
/** 打印;默认 true */
|
|
331
|
+
print: boolean;
|
|
332
|
+
}
|
|
333
|
+
declare const DEFAULT_DOC_PERMISSIONS: DocPermissions;
|
|
334
|
+
/** 当前文档权限;没装守卫时全开 */
|
|
335
|
+
declare function getDocPermissions(editor: Editor | null | undefined): DocPermissions;
|
|
336
|
+
|
|
337
|
+
type EditorVisualTheme = "notion" | "feishu";
|
|
338
|
+
/** 用到的 antd token 子集(antd `theme.useToken().token` / `theme.getDesignToken()` 都满足) */
|
|
339
|
+
interface AntdTokenLike {
|
|
340
|
+
colorPrimary: string;
|
|
341
|
+
colorPrimaryBg: string;
|
|
342
|
+
colorPrimaryBgHover: string;
|
|
343
|
+
colorPrimaryBorder: string;
|
|
344
|
+
colorPrimaryBorderHover: string;
|
|
345
|
+
colorPrimaryHover: string;
|
|
346
|
+
colorPrimaryActive: string;
|
|
347
|
+
colorPrimaryTextHover: string;
|
|
348
|
+
colorPrimaryText: string;
|
|
349
|
+
colorPrimaryTextActive: string;
|
|
350
|
+
colorBgContainer: string;
|
|
351
|
+
colorBgElevated: string;
|
|
352
|
+
colorText: string;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* 编辑器自己的表面 token:块、浮层、菜单项。组件样式只读这些,不直接写死某一家的数值。
|
|
356
|
+
*/
|
|
357
|
+
interface EditorSurfaceToken {
|
|
358
|
+
/** 正文色 */
|
|
359
|
+
colorText: string;
|
|
360
|
+
/** 编辑区底色 */
|
|
361
|
+
colorBgPage: string;
|
|
362
|
+
/** 代码类块(代码块、代码分组)的圆角 */
|
|
363
|
+
blockRadius: number;
|
|
364
|
+
/** 卡片类块(提示框、书签、附件、嵌入等)的圆角 */
|
|
365
|
+
cardRadius: number;
|
|
366
|
+
/** 块内分隔线(参数行之间、标题栏下面) */
|
|
367
|
+
dividerColor: string;
|
|
368
|
+
/** 行内代码底色 / 描边 */
|
|
369
|
+
inlineCodeBg: string;
|
|
370
|
+
inlineCodeBorder: string;
|
|
371
|
+
/** 块描边;`transparent` 表示不画线框 */
|
|
372
|
+
blockBorderColor: string;
|
|
373
|
+
/** 悬停 / 选中(NodeSelection)时块的描边 */
|
|
374
|
+
blockHoverBorderColor: string;
|
|
375
|
+
blockSelectedBorderColor: string;
|
|
376
|
+
/** 代码块 / 代码分组底色与标题栏底色 */
|
|
377
|
+
codeBg: string;
|
|
378
|
+
codeHeaderBg: string;
|
|
379
|
+
/** 代码块、代码分组标题栏下面那条分隔线 */
|
|
380
|
+
codeDividerColor: string;
|
|
381
|
+
/** 带颜色的提示框要不要描边(Notion 只铺底色) */
|
|
382
|
+
calloutBordered: boolean;
|
|
383
|
+
/** 表格线、标题行底色 */
|
|
384
|
+
tableBorderColor: string;
|
|
385
|
+
tableHeaderBg: string;
|
|
386
|
+
/** 表格外框圆角;0 = 直角(飞书) */
|
|
387
|
+
tableRadius: number;
|
|
388
|
+
/** 浮层(菜单、下拉、工具条、卡片)的底色、圆角、阴影、描边 */
|
|
389
|
+
floatBg: string;
|
|
390
|
+
floatRadius: number;
|
|
391
|
+
floatShadow: string;
|
|
392
|
+
floatBorderColor: string;
|
|
393
|
+
/** 菜单项圆角与悬停底色 */
|
|
394
|
+
itemRadius: number;
|
|
395
|
+
itemHoverBg: string;
|
|
396
|
+
/** 块内小按钮(复制、换行、语言切换)悬停底色 */
|
|
397
|
+
controlHoverBg: string;
|
|
398
|
+
/** 卡片类块(书签、附件卡片、嵌入、投票…)的描边与悬停底色 */
|
|
399
|
+
cardBorderColor: string;
|
|
400
|
+
cardHoverBg: string;
|
|
401
|
+
/** 块悬停时浮出的小工具条(视图切换、下载…)圆角;底色 / 阴影 / 描边同浮层 */
|
|
402
|
+
toolbarRadius: number;
|
|
403
|
+
/** 输入框、按钮圆角 */
|
|
404
|
+
inputRadius: number;
|
|
405
|
+
/** 强调色:选中项文字、主按钮、输入框聚焦描边 */
|
|
406
|
+
accentColor: string;
|
|
407
|
+
/** 次要 / 更次要的文字(说明、站点名、占位) */
|
|
408
|
+
textSecondary: string;
|
|
409
|
+
textTertiary: string;
|
|
410
|
+
}
|
|
411
|
+
interface ResolvedEditorTheme {
|
|
412
|
+
visualTheme: EditorVisualTheme;
|
|
413
|
+
isDark: boolean;
|
|
414
|
+
surface: EditorSurfaceToken;
|
|
415
|
+
}
|
|
416
|
+
declare function resolveEditorTheme(token: AntdTokenLike, options?: {
|
|
417
|
+
visualTheme?: EditorVisualTheme;
|
|
418
|
+
isDarkMode?: boolean;
|
|
419
|
+
}): ResolvedEditorTheme;
|
|
420
|
+
|
|
133
421
|
interface NotionEditorProps {
|
|
134
422
|
room: string;
|
|
135
423
|
placeholder?: string;
|
|
@@ -148,7 +436,7 @@ interface NotionEditorProps {
|
|
|
148
436
|
contentFormat?: ContentFormat;
|
|
149
437
|
/**
|
|
150
438
|
* 代码块高亮配置(Shiki 主题 / 语言别名 / 额外语言注册)。默认 github-light /
|
|
151
|
-
* github-dark
|
|
439
|
+
* github-dark 随编辑器深浅色(宿主 antd 主题)切换,语言按需加载,无需配置即可用。
|
|
152
440
|
*/
|
|
153
441
|
codeBlock?: CodeBlockOptions;
|
|
154
442
|
/**
|
|
@@ -158,6 +446,39 @@ interface NotionEditorProps {
|
|
|
158
446
|
* 扩展集与编辑态完全一致,保证自定义节点(图片/视频/附件/分栏/表格等)渲染像素一致。
|
|
159
447
|
*/
|
|
160
448
|
readOnly?: boolean;
|
|
449
|
+
/**
|
|
450
|
+
* 文档权限(分享只读等):所有者可以关掉访问者的复制 / 下载 / 打印,照飞书。默认全开。
|
|
451
|
+
* - `copy: false`:⌘C / 剪切被拦并提示,正文右键菜单屏蔽,代码块「复制」按钮不出;
|
|
452
|
+
* - `download: false`:图片 / 视频 / 音频 / 附件 / 流程图的下载入口都不出;
|
|
453
|
+
* - `print: false`:⌘P 吞掉,打印出来是空白。
|
|
454
|
+
*/
|
|
455
|
+
permissions?: Partial<DocPermissions>;
|
|
456
|
+
/**
|
|
457
|
+
* 编辑 / 阅读模式(飞书顶栏的模式切换)。只对有编辑权限(readOnly=false)的人生效:
|
|
458
|
+
* - `defaultViewMode`:初始模式,默认 "edit";飞书按人按文档记住上次的模式,宿主在 `onViewModeChange` 里自己存、下次传回来;
|
|
459
|
+
* - `viewMode`:受控用法,传了就以它为准;
|
|
460
|
+
* - `onViewModeChange`:用户在顶栏切换、按快捷键(阅读时按 E 进编辑,⌃⌥V / ⇧Alt+V 进阅读)、点阅读工具条「编辑」时回调。
|
|
461
|
+
* 阅读模式就是不可编辑:文字能选能复制,编辑用的手柄、工具条、菜单都不出现。
|
|
462
|
+
*/
|
|
463
|
+
defaultViewMode?: ViewMode;
|
|
464
|
+
viewMode?: ViewMode;
|
|
465
|
+
onViewModeChange?: (mode: ViewMode) => void;
|
|
466
|
+
/**
|
|
467
|
+
* 页宽(飞书「页宽设置」):默认 820、较宽 1020、全宽,都是正文本身的宽度。
|
|
468
|
+
* - `defaultWidthMode`:初始页宽;不传时看文档页头上存的 widthMode(旧文档的宽屏),都没有就是默认;
|
|
469
|
+
* - `widthMode`:受控用法;
|
|
470
|
+
* - `onWidthModeChange`:用户在顶栏「页宽设置」里切换时回调。飞书按窗口记在文档设置里、不写进文档,宿主自己存。
|
|
471
|
+
* 宿主在外层定义的 `--doc-content-width` 仍然优先于默认档。
|
|
472
|
+
*/
|
|
473
|
+
defaultWidthMode?: DocWidthMode;
|
|
474
|
+
widthMode?: DocWidthMode;
|
|
475
|
+
onWidthModeChange?: (mode: DocWidthMode) => void;
|
|
476
|
+
/**
|
|
477
|
+
* 视觉风格:`"notion"`(默认,无线框、暖灰底、柔和阴影)或 `"feishu"`(线框、小圆角)。
|
|
478
|
+
* 颜色、深浅色跟着宿主 antd 主题(ConfigProvider / antd-style ThemeProvider)走。
|
|
479
|
+
* 浮层挂在 body 上,所以一个页面只用一种视觉风格。
|
|
480
|
+
*/
|
|
481
|
+
visualTheme?: EditorVisualTheme;
|
|
161
482
|
/**
|
|
162
483
|
* 隐藏包内置顶部工具条(undo/redo、主题切换、协同用户,含底部分隔线)。
|
|
163
484
|
* 业务方页面自带头部(如 wiki 编辑页的面包屑 + 操作区)时开启,
|
|
@@ -169,7 +490,7 @@ interface NotionEditorProps {
|
|
|
169
490
|
* (如写进 zustand store,发布时用 editor.getHTML()/getJSON() 取正文)。
|
|
170
491
|
* 每次 editor 重建(如 room 切换触发 remount)都会带新实例再次回调。
|
|
171
492
|
*/
|
|
172
|
-
onEditorReady?: (editor: Editor) => void;
|
|
493
|
+
onEditorReady?: (editor: Editor$1) => void;
|
|
173
494
|
/**
|
|
174
495
|
* 追加的 tiptap 扩展,挂在包内置扩展集之后。
|
|
175
496
|
*
|
|
@@ -178,6 +499,12 @@ interface NotionEditorProps {
|
|
|
178
499
|
* 否则各端 schema 不一致,yjs 同步会出现内容被判为非法而丢弃。
|
|
179
500
|
*/
|
|
180
501
|
extensions?: Extensions;
|
|
502
|
+
/**
|
|
503
|
+
* 显示飞书式的文档页头(标题 + 图标 + 封面)。默认关:很多宿主页面自带标题栏,
|
|
504
|
+
* 打开以后会在文档最前面自动补一个页头节点,标题就存在文档内容里(getJSON 里的 pageHeader)。
|
|
505
|
+
* 关着的时候,文档里已有的页头照常显示,只是不会自动补。
|
|
506
|
+
*/
|
|
507
|
+
pageHeader?: boolean;
|
|
181
508
|
}
|
|
182
509
|
interface EditorProviderProps {
|
|
183
510
|
/**
|
|
@@ -195,6 +522,16 @@ interface EditorProviderProps {
|
|
|
195
522
|
codeBlock?: CodeBlockOptions;
|
|
196
523
|
/** 只读模式,详见 NotionEditorProps.readOnly */
|
|
197
524
|
readOnly?: boolean;
|
|
525
|
+
/** 文档权限,详见 NotionEditorProps.permissions */
|
|
526
|
+
permissions?: Partial<DocPermissions>;
|
|
527
|
+
/** 编辑 / 阅读模式,详见 NotionEditorProps */
|
|
528
|
+
defaultViewMode?: ViewMode;
|
|
529
|
+
viewMode?: ViewMode;
|
|
530
|
+
onViewModeChange?: (mode: ViewMode) => void;
|
|
531
|
+
/** 页宽,详见 NotionEditorProps */
|
|
532
|
+
defaultWidthMode?: DocWidthMode;
|
|
533
|
+
widthMode?: DocWidthMode;
|
|
534
|
+
onWidthModeChange?: (mode: DocWidthMode) => void;
|
|
198
535
|
/** 隐藏包内置顶部工具条,详见 NotionEditorProps.hideHeader */
|
|
199
536
|
hideHeader?: boolean;
|
|
200
537
|
/**
|
|
@@ -205,7 +542,7 @@ interface EditorProviderProps {
|
|
|
205
542
|
*/
|
|
206
543
|
embedded?: boolean;
|
|
207
544
|
/** editor 实例就绪回调,详见 NotionEditorProps.onEditorReady */
|
|
208
|
-
onEditorReady?: (editor: Editor) => void;
|
|
545
|
+
onEditorReady?: (editor: Editor$1) => void;
|
|
209
546
|
/**
|
|
210
547
|
* 追加的 tiptap 扩展,挂在包内置扩展集之后。
|
|
211
548
|
*
|
|
@@ -214,6 +551,8 @@ interface EditorProviderProps {
|
|
|
214
551
|
* 否则各端 schema 不一致,yjs 同步会出现内容被判为非法而丢弃。
|
|
215
552
|
*/
|
|
216
553
|
extensions?: Extensions;
|
|
554
|
+
/** 文档页头,详见 NotionEditorProps.pageHeader */
|
|
555
|
+
pageHeader?: boolean;
|
|
217
556
|
}
|
|
218
557
|
/**
|
|
219
558
|
* Loading spinner component shown while connecting to the notion server
|
|
@@ -232,11 +571,18 @@ declare function EditorProvider(props: EditorProviderProps): react.JSX.Element;
|
|
|
232
571
|
/**
|
|
233
572
|
* Full editor with all necessary providers, ready to use with just a room ID
|
|
234
573
|
*/
|
|
235
|
-
declare function NotionEditor({ room, placeholder, content, contentFormat, codeBlock, readOnly, hideHeader, onEditorReady, extensions, }: NotionEditorProps): react.JSX.Element;
|
|
574
|
+
declare function NotionEditor({ room, placeholder, content, contentFormat, codeBlock, readOnly, hideHeader, onEditorReady, extensions, pageHeader, defaultViewMode, viewMode, onViewModeChange, defaultWidthMode, widthMode, onWidthModeChange, visualTheme, permissions, }: NotionEditorProps): react.JSX.Element;
|
|
236
575
|
/**
|
|
237
576
|
* Internal component that handles the editor loading state
|
|
238
577
|
*/
|
|
239
|
-
declare function NotionEditorContent({ placeholder, content, contentFormat, codeBlock, readOnly, hideHeader, onEditorReady, extensions, }: {
|
|
578
|
+
declare function NotionEditorContent({ placeholder, content, contentFormat, codeBlock, readOnly, permissions, hideHeader, onEditorReady, extensions, pageHeader, defaultViewMode, viewMode, onViewModeChange, defaultWidthMode, widthMode, onWidthModeChange, }: {
|
|
579
|
+
pageHeader?: boolean;
|
|
580
|
+
defaultViewMode?: ViewMode;
|
|
581
|
+
viewMode?: ViewMode;
|
|
582
|
+
onViewModeChange?: (mode: ViewMode) => void;
|
|
583
|
+
defaultWidthMode?: DocWidthMode;
|
|
584
|
+
widthMode?: DocWidthMode;
|
|
585
|
+
onWidthModeChange?: (mode: DocWidthMode) => void;
|
|
240
586
|
placeholder?: string;
|
|
241
587
|
content?: string | JSONContent;
|
|
242
588
|
/** 内容格式,详见 NotionEditorProps.contentFormat */
|
|
@@ -244,8 +590,9 @@ declare function NotionEditorContent({ placeholder, content, contentFormat, code
|
|
|
244
590
|
/** 代码块高亮配置,详见 NotionEditorProps.codeBlock */
|
|
245
591
|
codeBlock?: CodeBlockOptions;
|
|
246
592
|
readOnly?: boolean;
|
|
593
|
+
permissions?: Partial<DocPermissions>;
|
|
247
594
|
hideHeader?: boolean;
|
|
248
|
-
onEditorReady?: (editor: Editor) => void;
|
|
595
|
+
onEditorReady?: (editor: Editor$1) => void;
|
|
249
596
|
/**
|
|
250
597
|
* 追加的 tiptap 扩展,挂在包内置扩展集之后。
|
|
251
598
|
*
|
|
@@ -264,6 +611,10 @@ interface ArticleViewerProps {
|
|
|
264
611
|
codeBlock?: CodeBlockOptions;
|
|
265
612
|
/** 空内容时的占位文案,默认空(viewer 一般不显示占位) */
|
|
266
613
|
placeholder?: string;
|
|
614
|
+
/** 视觉风格,详见 NotionEditorProps.visualTheme */
|
|
615
|
+
visualTheme?: EditorVisualTheme;
|
|
616
|
+
/** 文档权限(复制 / 下载 / 打印),详见 NotionEditorProps.permissions */
|
|
617
|
+
permissions?: Partial<DocPermissions>;
|
|
267
618
|
}
|
|
268
619
|
/**
|
|
269
620
|
* 文章只读展示组件。
|
|
@@ -275,7 +626,20 @@ interface ArticleViewerProps {
|
|
|
275
626
|
*
|
|
276
627
|
* 用法:<ArticleViewer content={articleContent} />
|
|
277
628
|
*/
|
|
278
|
-
declare function ArticleViewer({ content, contentFormat, codeBlock, placeholder }: ArticleViewerProps): react.JSX.Element;
|
|
629
|
+
declare function ArticleViewer({ content, contentFormat, codeBlock, placeholder, visualTheme, permissions, }: ArticleViewerProps): react.JSX.Element;
|
|
630
|
+
|
|
631
|
+
interface EditorThemeStyleProps {
|
|
632
|
+
/** 视觉风格,默认 Notion */
|
|
633
|
+
visualTheme?: EditorVisualTheme;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* 按宿主 antd 主题注入编辑器的全局样式,并在 `<html>` 上标 `data-tt-appearance` / `data-tt-theme`
|
|
637
|
+
* (浮层挂在 body 上,所以只能标在根上;一个页面只用一种视觉主题)。
|
|
638
|
+
* 运行时样式本身不读这两个属性:深浅色、视觉风格在拼样式时就定了(深色规则只在深色时输出)。
|
|
639
|
+
* 标出来是给静态 style.css(深色挂 `[data-tt-appearance="dark"]`)、验收脚本和宿主用的。
|
|
640
|
+
* 同一页面多个编辑器会注入相同内容,emotion 按内容去重。
|
|
641
|
+
*/
|
|
642
|
+
declare function EditorThemeStyle({ visualTheme }: EditorThemeStyleProps): react.JSX.Element;
|
|
279
643
|
|
|
280
644
|
/** 只用到 Editor 的这几个面,避免把 @tiptap/core 的 Editor 类型绑死在签名里 */
|
|
281
645
|
interface EditorLike {
|
|
@@ -339,6 +703,11 @@ interface CalloutAttrs {
|
|
|
339
703
|
id?: string | null;
|
|
340
704
|
type: CalloutType;
|
|
341
705
|
title: string | null;
|
|
706
|
+
/** 飞书外观;null 跟随 type 预设,emoji 为 "" 表示不显示 */
|
|
707
|
+
emoji?: string | null;
|
|
708
|
+
backgroundColor?: string | null;
|
|
709
|
+
borderColor?: string | null;
|
|
710
|
+
textColor?: string | null;
|
|
342
711
|
}
|
|
343
712
|
interface DetailsAttrs {
|
|
344
713
|
id?: string | null;
|
|
@@ -404,10 +773,10 @@ declare function UserProvider({ children }: {
|
|
|
404
773
|
}): react.JSX.Element;
|
|
405
774
|
declare const useUser: () => UserContextValue;
|
|
406
775
|
|
|
407
|
-
declare function useTiptapEditor(providedEditor?: Editor | null): {
|
|
408
|
-
editor: Editor | null;
|
|
409
|
-
editorState?: Editor["state"];
|
|
410
|
-
canCommand?: Editor["can"];
|
|
776
|
+
declare function useTiptapEditor(providedEditor?: Editor$1 | null): {
|
|
777
|
+
editor: Editor$1 | null;
|
|
778
|
+
editorState?: Editor$1["state"];
|
|
779
|
+
canCommand?: Editor$1["can"];
|
|
411
780
|
};
|
|
412
781
|
|
|
413
782
|
declare module "@tiptap/core" {
|
|
@@ -432,7 +801,7 @@ interface UiState {
|
|
|
432
801
|
}
|
|
433
802
|
declare const UiState: Extension<UiState, any>;
|
|
434
803
|
|
|
435
|
-
declare function useUiEditorState(editor: Editor | null): UiState;
|
|
804
|
+
declare function useUiEditorState(editor: Editor$1 | null): UiState;
|
|
436
805
|
|
|
437
806
|
declare const HIDE_FLOATING_META = "hideFloatingToolbar";
|
|
438
807
|
/**
|
|
@@ -445,8 +814,8 @@ declare const HIDE_FLOATING_META = "hideFloatingToolbar";
|
|
|
445
814
|
* - Exposes helpers to set selections with the meta flag
|
|
446
815
|
*/
|
|
447
816
|
declare function useFloatingToolbarVisibility(params: {
|
|
448
|
-
editor: Editor | null;
|
|
449
|
-
isSelectionValid: (editor: Editor, selection: Editor["state"]["selection"]) => boolean;
|
|
817
|
+
editor: Editor$1 | null;
|
|
818
|
+
isSelectionValid: (editor: Editor$1, selection: Editor$1["state"]["selection"]) => boolean;
|
|
450
819
|
extraHideWhen?: boolean;
|
|
451
820
|
}): {
|
|
452
821
|
shouldShow: boolean;
|
|
@@ -456,12 +825,12 @@ declare function useFloatingToolbarVisibility(params: {
|
|
|
456
825
|
* @param editor
|
|
457
826
|
* @param pos
|
|
458
827
|
*/
|
|
459
|
-
declare const selectNodeAndHideFloating: (editor: Editor, pos: number) => void;
|
|
828
|
+
declare const selectNodeAndHideFloating: (editor: Editor$1, pos: number) => void;
|
|
460
829
|
/**
|
|
461
830
|
* Mark “hide floating” on the next relevant transaction (no selection change needed)
|
|
462
831
|
* @param editor
|
|
463
832
|
*/
|
|
464
|
-
declare const markHideFloatingOnNext: (editor: Editor) => void;
|
|
833
|
+
declare const markHideFloatingOnNext: (editor: Editor$1) => void;
|
|
465
834
|
|
|
466
835
|
type RectState = Omit<DOMRect, "toJSON">;
|
|
467
836
|
interface ElementRectOptions {
|
|
@@ -495,21 +864,30 @@ interface CursorVisibilityOptions {
|
|
|
495
864
|
/**
|
|
496
865
|
* The Tiptap editor instance
|
|
497
866
|
*/
|
|
498
|
-
editor?: Editor | null;
|
|
867
|
+
editor?: Editor$1 | null;
|
|
499
868
|
/**
|
|
500
869
|
* Reference to the toolbar element that may obscure the cursor
|
|
501
870
|
*/
|
|
502
871
|
overlayHeight?: number;
|
|
872
|
+
/**
|
|
873
|
+
* Only scroll while the overlay is actually shown (e.g. the mobile toolbar).
|
|
874
|
+
* @default true
|
|
875
|
+
*/
|
|
876
|
+
enabled?: boolean;
|
|
503
877
|
}
|
|
504
878
|
/**
|
|
505
879
|
* Custom hook that ensures the cursor remains visible when typing in a Tiptap editor.
|
|
506
880
|
* Automatically scrolls the window when the cursor would be hidden by the toolbar.
|
|
507
881
|
*
|
|
882
|
+
* 只在用户编辑(文档或选区变了)和窗口高度变化(软键盘弹出)时检查;页面自己重排
|
|
883
|
+
* (代码分组切标签、折叠、图片加载)不算 —— 否则光标在视口外时会被拉到光标那里。
|
|
884
|
+
*
|
|
508
885
|
* @param options.editor The Tiptap editor instance
|
|
509
886
|
* @param options.overlayHeight Toolbar height to account for
|
|
887
|
+
* @param options.enabled Whether to keep the cursor visible at all
|
|
510
888
|
* @returns The bounding rect of the body
|
|
511
889
|
*/
|
|
512
|
-
declare function useCursorVisibility({ editor, overlayHeight, }: CursorVisibilityOptions): RectState;
|
|
890
|
+
declare function useCursorVisibility({ editor, overlayHeight, enabled, }: CursorVisibilityOptions): RectState;
|
|
513
891
|
|
|
514
892
|
interface FloatingElementReturn {
|
|
515
893
|
/**
|
|
@@ -560,7 +938,7 @@ interface MenuNavigationOptions<T> {
|
|
|
560
938
|
/**
|
|
561
939
|
* The Tiptap editor instance, if using with a Tiptap editor.
|
|
562
940
|
*/
|
|
563
|
-
editor?: Editor | null;
|
|
941
|
+
editor?: Editor$1 | null;
|
|
564
942
|
/**
|
|
565
943
|
* Reference to the container element for handling keyboard events.
|
|
566
944
|
*/
|
|
@@ -707,7 +1085,7 @@ declare const getUrlParam: (param: string) => string | null;
|
|
|
707
1085
|
* @param editor The Tiptap editor instance
|
|
708
1086
|
* @returns The display name of the current node
|
|
709
1087
|
*/
|
|
710
|
-
declare const getNodeDisplayName: (editor: Editor | null) => string;
|
|
1088
|
+
declare const getNodeDisplayName: (editor: Editor$1 | null) => string;
|
|
711
1089
|
/**
|
|
712
1090
|
* Removes empty paragraph nodes from content
|
|
713
1091
|
*/
|
|
@@ -729,18 +1107,18 @@ declare function getElementOverflowPosition(targetElement: Element, containerEle
|
|
|
729
1107
|
/**
|
|
730
1108
|
* Checks if the current selection is valid for a given editor
|
|
731
1109
|
*/
|
|
732
|
-
declare const isSelectionValid: (editor: Editor | null, selection?: Selection, excludedNodeTypes?: string[]) => boolean;
|
|
1110
|
+
declare const isSelectionValid: (editor: Editor$1 | null, selection?: Selection, excludedNodeTypes?: string[]) => boolean;
|
|
733
1111
|
/**
|
|
734
1112
|
* Checks if the current text selection is valid for editing
|
|
735
1113
|
* - Not empty
|
|
736
1114
|
* - Not a code block
|
|
737
1115
|
* - Not a node selection
|
|
738
1116
|
*/
|
|
739
|
-
declare const isTextSelectionValid: (editor: Editor | null) => boolean;
|
|
1117
|
+
declare const isTextSelectionValid: (editor: Editor$1 | null) => boolean;
|
|
740
1118
|
/**
|
|
741
1119
|
* Gets the bounding rect of the current selection in the editor.
|
|
742
1120
|
*/
|
|
743
|
-
declare const getSelectionBoundingRect: (editor: Editor) => DOMRect | null;
|
|
1121
|
+
declare const getSelectionBoundingRect: (editor: Editor$1) => DOMRect | null;
|
|
744
1122
|
/**
|
|
745
1123
|
* Generates a deterministic avatar URL from a user name
|
|
746
1124
|
*/
|
|
@@ -791,20 +1169,20 @@ declare const parseShortcutKeys: (props: {
|
|
|
791
1169
|
* @param editor - The editor instance
|
|
792
1170
|
* @returns boolean indicating if the mark exists in the schema
|
|
793
1171
|
*/
|
|
794
|
-
declare const isMarkInSchema: (markName: string, editor: Editor | null) => boolean;
|
|
1172
|
+
declare const isMarkInSchema: (markName: string, editor: Editor$1 | null) => boolean;
|
|
795
1173
|
/**
|
|
796
1174
|
* Checks if a node exists in the editor schema
|
|
797
1175
|
* @param nodeName - The name of the node to check
|
|
798
1176
|
* @param editor - The editor instance
|
|
799
1177
|
* @returns boolean indicating if the node exists in the schema
|
|
800
1178
|
*/
|
|
801
|
-
declare const isNodeInSchema: (nodeName: string, editor: Editor | null) => boolean;
|
|
1179
|
+
declare const isNodeInSchema: (nodeName: string, editor: Editor$1 | null) => boolean;
|
|
802
1180
|
/**
|
|
803
1181
|
* Moves the focus to the next node in the editor
|
|
804
1182
|
* @param editor - The editor instance
|
|
805
1183
|
* @returns boolean indicating if the focus was moved
|
|
806
1184
|
*/
|
|
807
|
-
declare function focusNextNode(editor: Editor): boolean;
|
|
1185
|
+
declare function focusNextNode(editor: Editor$1): boolean;
|
|
808
1186
|
/**
|
|
809
1187
|
* Checks if a value is a valid number (not null, undefined, or NaN)
|
|
810
1188
|
* @param value - The value to check
|
|
@@ -817,14 +1195,14 @@ declare function isValidPosition(pos: number | null | undefined): pos is number;
|
|
|
817
1195
|
* @param extensionNames - A single extension name or an array of names to check
|
|
818
1196
|
* @returns True if at least one of the extensions is available, false otherwise
|
|
819
1197
|
*/
|
|
820
|
-
declare function isExtensionAvailable(editor: Editor | null, extensionNames: string | string[]): boolean;
|
|
1198
|
+
declare function isExtensionAvailable(editor: Editor$1 | null, extensionNames: string | string[]): boolean;
|
|
821
1199
|
/**
|
|
822
1200
|
* Finds a node at the specified position with error handling
|
|
823
1201
|
* @param editor The Tiptap editor instance
|
|
824
1202
|
* @param position The position in the document to find the node
|
|
825
1203
|
* @returns The node at the specified position, or null if not found
|
|
826
1204
|
*/
|
|
827
|
-
declare function findNodeAtPosition(editor: Editor, position: number): Node | null;
|
|
1205
|
+
declare function findNodeAtPosition(editor: Editor$1, position: number): Node | null;
|
|
828
1206
|
/**
|
|
829
1207
|
* Finds the position and instance of a node in the document
|
|
830
1208
|
* @param props Object containing editor, node (optional), and nodePos (optional)
|
|
@@ -834,7 +1212,7 @@ declare function findNodeAtPosition(editor: Editor, position: number): Node | nu
|
|
|
834
1212
|
* @returns An object with the position and node, or null if not found
|
|
835
1213
|
*/
|
|
836
1214
|
declare function findNodePosition(props: {
|
|
837
|
-
editor: Editor | null;
|
|
1215
|
+
editor: Editor$1 | null;
|
|
838
1216
|
node?: Node | null;
|
|
839
1217
|
nodePos?: number | null;
|
|
840
1218
|
}): {
|
|
@@ -848,7 +1226,7 @@ declare function findNodePosition(props: {
|
|
|
848
1226
|
* @param nodeTypeNames List of node type names to match against
|
|
849
1227
|
* @param checkAncestorNodes Whether to check ancestor node types up the depth chain
|
|
850
1228
|
*/
|
|
851
|
-
declare function isNodeTypeSelected(editor: Editor | null, nodeTypeNames?: string[], checkAncestorNodes?: boolean): boolean;
|
|
1229
|
+
declare function isNodeTypeSelected(editor: Editor$1 | null, nodeTypeNames?: string[], checkAncestorNodes?: boolean): boolean;
|
|
852
1230
|
/**
|
|
853
1231
|
* Check whether the current selection is fully within nodes
|
|
854
1232
|
* whose type names are in the provided `types` list.
|
|
@@ -856,7 +1234,7 @@ declare function isNodeTypeSelected(editor: Editor | null, nodeTypeNames?: strin
|
|
|
856
1234
|
* - NodeSelection → checks the selected node.
|
|
857
1235
|
* - Text/AllSelection → ensures all textblocks within [from, to) are allowed.
|
|
858
1236
|
*/
|
|
859
|
-
declare function selectionWithinConvertibleTypes(editor: Editor, types?: string[]): boolean;
|
|
1237
|
+
declare function selectionWithinConvertibleTypes(editor: Editor$1, types?: string[]): boolean;
|
|
860
1238
|
/**
|
|
861
1239
|
* Handles image upload with progress tracking and abort capability
|
|
862
1240
|
* @param file The file to upload
|
|
@@ -901,7 +1279,7 @@ declare function updateNodesAttr<A extends string = string, V = unknown>(tr: Tra
|
|
|
901
1279
|
* If the selection is not empty, it does nothing.
|
|
902
1280
|
* @param editor The Tiptap editor instance
|
|
903
1281
|
*/
|
|
904
|
-
declare function selectCurrentBlockContent(editor: Editor): void;
|
|
1282
|
+
declare function selectCurrentBlockContent(editor: Editor$1): void;
|
|
905
1283
|
/**
|
|
906
1284
|
* Retrieves all nodes of specified types from the current selection.
|
|
907
1285
|
* @param selection The current editor selection
|
|
@@ -913,12 +1291,12 @@ declare function getSelectedNodesOfType(selection: Selection, allowedNodeTypes:
|
|
|
913
1291
|
* Clamps a value between min and max bounds
|
|
914
1292
|
*/
|
|
915
1293
|
declare function clamp(value: number, min: number, max: number): number;
|
|
916
|
-
declare function getSelectedBlockNodes(editor: Editor): Node[];
|
|
1294
|
+
declare function getSelectedBlockNodes(editor: Editor$1): Node[];
|
|
917
1295
|
|
|
918
1296
|
/**
|
|
919
1297
|
* Helper function to check if there's content above the current position
|
|
920
1298
|
*/
|
|
921
|
-
declare function hasContentAbove(editor: Editor | null): {
|
|
1299
|
+
declare function hasContentAbove(editor: Editor$1 | null): {
|
|
922
1300
|
hasContent: boolean;
|
|
923
1301
|
content: string;
|
|
924
1302
|
};
|
|
@@ -928,7 +1306,7 @@ declare function hasContentAbove(editor: Editor | null): {
|
|
|
928
1306
|
* @returns The position of the node in the selection or null if not found
|
|
929
1307
|
*/
|
|
930
1308
|
declare function findSelectionPosition(params: {
|
|
931
|
-
editor: Editor;
|
|
1309
|
+
editor: Editor$1;
|
|
932
1310
|
node?: Node | null;
|
|
933
1311
|
nodePos?: number | null;
|
|
934
1312
|
}): number | null;
|
|
@@ -979,7 +1357,7 @@ interface FloatingElementProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
979
1357
|
/**
|
|
980
1358
|
* The Tiptap editor instance to attach to.
|
|
981
1359
|
*/
|
|
982
|
-
editor?: Editor | null;
|
|
1360
|
+
editor?: Editor$1 | null;
|
|
983
1361
|
/**
|
|
984
1362
|
* Controls whether the floating element should be visible.
|
|
985
1363
|
* @default undefined
|
|
@@ -1008,7 +1386,7 @@ interface FloatingElementProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
1008
1386
|
* Only used if referenceElement is not provided.
|
|
1009
1387
|
* @default getSelectionBoundingRect
|
|
1010
1388
|
*/
|
|
1011
|
-
getBoundingClientRect?: (editor: Editor) => DOMRect | null;
|
|
1389
|
+
getBoundingClientRect?: (editor: Editor$1) => DOMRect | null;
|
|
1012
1390
|
/**
|
|
1013
1391
|
* Whether to close the floating element when Escape key is pressed.
|
|
1014
1392
|
* @default true
|
|
@@ -1072,13 +1450,15 @@ interface PasteDropMediaOptions {
|
|
|
1072
1450
|
onError?: (error: Error) => void;
|
|
1073
1451
|
/** 外链转存的全程进度(下载 / 上传 / 完成),按 url 聚合。 */
|
|
1074
1452
|
onRehostProgress?: (event: PasteDropRehostProgressEvent) => void;
|
|
1453
|
+
/** 宿主能预览的文件扩展名(EditorConfig.file.previewTypes),决定新上传文件的默认视图 */
|
|
1454
|
+
filePreviewTypes?: string[];
|
|
1075
1455
|
}
|
|
1076
1456
|
/**
|
|
1077
1457
|
* 统一入口:插入进度占位 → 上传(带进度/取消)→ 成功替换为真实节点 / 失败移除 / 取消 abort。
|
|
1078
1458
|
* 同时被 plugin(paste/drop)和 addCommands(slash 菜单 / 工具栏)调用。
|
|
1079
1459
|
* insertPos 传区间时占位直接替换该区间(浮动菜单「替换」用:占位顶掉原节点,失败可撤销找回)。
|
|
1080
1460
|
*/
|
|
1081
|
-
declare const runMediaUpload: (editor: Editor, file: File, insertPos: number | {
|
|
1461
|
+
declare const runMediaUpload: (editor: Editor$1, file: File, insertPos: number | {
|
|
1082
1462
|
from: number;
|
|
1083
1463
|
to: number;
|
|
1084
1464
|
}, options: PasteDropMediaOptions) => void;
|
|
@@ -1135,6 +1515,17 @@ declare module "@tiptap/react" {
|
|
|
1135
1515
|
*/
|
|
1136
1516
|
declare const Audio: Node$1<AudioOptions, any>;
|
|
1137
1517
|
|
|
1518
|
+
/**
|
|
1519
|
+
* 文件块的 schema 层,不依赖 React。
|
|
1520
|
+
*
|
|
1521
|
+
* 块级 atom:通用文件(pdf / doc / zip 等)。attrs 对照飞书 `file:{name, size, mimeType, token}` + 视图:
|
|
1522
|
+
* - viewType:card(默认)/ preview,飞书文件块外层 view 块的 view_type;文本视图是另一个行内节点 fileInline;
|
|
1523
|
+
* - previewHeight:预览视图的高度(px),宽度铺满正文。
|
|
1524
|
+
*
|
|
1525
|
+
* 序列化为 <a data-type="file-attachment" data-size data-mime href download>name</a>,
|
|
1526
|
+
* 没 NodeView 的环境(如纯阅读视图)也能显示成可点击链接。
|
|
1527
|
+
*/
|
|
1528
|
+
|
|
1138
1529
|
interface FileAttachmentOptions {
|
|
1139
1530
|
HTMLAttributes: Record<string, unknown>;
|
|
1140
1531
|
}
|
|
@@ -1143,20 +1534,22 @@ interface FileAttachmentAttrs {
|
|
|
1143
1534
|
name: string;
|
|
1144
1535
|
size?: number;
|
|
1145
1536
|
mimeType?: string;
|
|
1537
|
+
viewType?: "card" | "preview";
|
|
1538
|
+
previewHeight?: number;
|
|
1146
1539
|
}
|
|
1147
|
-
declare module "@tiptap/
|
|
1540
|
+
declare module "@tiptap/core" {
|
|
1148
1541
|
interface Commands<ReturnType> {
|
|
1149
1542
|
fileAttachment: {
|
|
1150
1543
|
setFileAttachment: (options: FileAttachmentAttrs) => ReturnType;
|
|
1151
1544
|
};
|
|
1152
1545
|
}
|
|
1153
1546
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
*/
|
|
1159
|
-
declare const
|
|
1547
|
+
|
|
1548
|
+
type FileView = "inline" | "card" | "preview";
|
|
1549
|
+
|
|
1550
|
+
declare const FileAttachment: _tiptap_core.Node<FileAttachmentOptions, any>;
|
|
1551
|
+
/** 文本视图的文件 */
|
|
1552
|
+
declare const FileInline: _tiptap_core.Node<any, any>;
|
|
1160
1553
|
|
|
1161
1554
|
/**
|
|
1162
1555
|
* 临时占位节点:拖拽/粘贴上传过程中显示进度,上传完成由 runMediaUpload 替换为
|
|
@@ -1164,8 +1557,13 @@ declare const FileAttachment: Node$1<FileAttachmentOptions, any>;
|
|
|
1164
1557
|
*/
|
|
1165
1558
|
declare const MediaUploadPlaceholder: Node$1<any, any>;
|
|
1166
1559
|
|
|
1560
|
+
/**
|
|
1561
|
+
* 分栏(columns / column)的 schema 层,不依赖 React,Node 测试可以直接 new Editor()。
|
|
1562
|
+
* NodeView 在 column-node-extension.ts 里挂上去。
|
|
1563
|
+
*/
|
|
1564
|
+
|
|
1167
1565
|
type ColumnLayout = "column" | "sidebar-left" | "sidebar-right" | "three-column";
|
|
1168
|
-
declare module "@tiptap/
|
|
1566
|
+
declare module "@tiptap/core" {
|
|
1169
1567
|
interface Commands<ReturnType> {
|
|
1170
1568
|
columns: {
|
|
1171
1569
|
/** 插入分栏:layout 决定列数(three-column→3,其余→2)与比例 */
|
|
@@ -1178,18 +1576,25 @@ declare module "@tiptap/react" {
|
|
|
1178
1576
|
* 不依赖选区);不给则回退到选区所在 columns。
|
|
1179
1577
|
*/
|
|
1180
1578
|
unsetColumns: (pos?: number) => ReturnType;
|
|
1579
|
+
/** 在 pos 处的分栏末尾加一列(飞书「添加列」),新列宽度取当前平均值;已到 10 列时返回 false */
|
|
1580
|
+
addColumn: (pos: number) => ReturnType;
|
|
1581
|
+
/** 平均分布 pos 处分栏的列宽(飞书「平均分布」) */
|
|
1582
|
+
distributeColumns: (pos: number) => ReturnType;
|
|
1583
|
+
/** 直接写入 pos 处分栏的列宽比例,长度必须等于列数;会归一化 */
|
|
1584
|
+
setColumnRatios: (pos: number, ratios: number[]) => ReturnType;
|
|
1181
1585
|
};
|
|
1182
1586
|
}
|
|
1183
1587
|
}
|
|
1184
|
-
declare const Column: Node$
|
|
1185
|
-
|
|
1588
|
+
declare const Column: Node$2<any, any>;
|
|
1589
|
+
|
|
1590
|
+
declare const Columns: _tiptap_core.Node<any, any>;
|
|
1186
1591
|
|
|
1187
1592
|
type MediaKindForButton = "video" | "audio" | "file";
|
|
1188
1593
|
interface MediaUploadButtonProps extends Omit<ButtonProps, "type"> {
|
|
1189
1594
|
/** 决定 accept / icon / 目标节点 / aria-label */
|
|
1190
1595
|
kind: MediaKindForButton;
|
|
1191
1596
|
/** 编辑器实例;不传则走 useTiptapEditor 默认(EditorContext) */
|
|
1192
|
-
editor?: Editor | null;
|
|
1597
|
+
editor?: Editor$1 | null;
|
|
1193
1598
|
/** 按钮文本,不传只显示图标 */
|
|
1194
1599
|
text?: string;
|
|
1195
1600
|
/** 节点不在 schema 时是否隐藏(默认 false:始终显示但 disabled) */
|
|
@@ -1213,4 +1618,71 @@ declare const MediaUploadButton: react.ForwardRefExoticComponent<MediaUploadButt
|
|
|
1213
1618
|
*/
|
|
1214
1619
|
declare function pickFile(accept: string, multiple?: boolean): Promise<File[]>;
|
|
1215
1620
|
|
|
1216
|
-
|
|
1621
|
+
/**
|
|
1622
|
+
* 打印文档,照飞书 print_control(chunk dx_22490,模块 240651;证据见组件规格 §43):
|
|
1623
|
+
*
|
|
1624
|
+
* 1. 弹「文档打印中」(不自动消失),开 10 分钟超时;
|
|
1625
|
+
* 2. 在页面外的隐藏 iframe 里(宽 1200,left -1300)写 `<!DOCTYPE html>`,`<title>` 抄 `document.title`;
|
|
1626
|
+
* 3. 抄过去页面上所有 `<style>`(CSS-in-JS 的规则从 sheet 里逐条抄)和 `<link rel=stylesheet>`,
|
|
1627
|
+
* 再加 `body{print-color-adjust: exact}`;
|
|
1628
|
+
* 4. 克隆正文,包一层 `.print`(打印专用样式都挂在它下面);嵌入网页换成原链接,画布换成图片;
|
|
1629
|
+
* 5. 等图片和字体加载完,再等 1 秒,调 iframe 的 print();打印对话框关了就删掉 iframe;
|
|
1630
|
+
* 6. 超时或出错提示「打印超时,请稍后重试」。
|
|
1631
|
+
*
|
|
1632
|
+
* 折叠的内容照飞书保持折叠(克隆的是当前界面)。宽表格不缩放,超出部分截掉(飞书的自适应缩放只在服务端导出 PDF 里)。
|
|
1633
|
+
*/
|
|
1634
|
+
|
|
1635
|
+
interface PrintOptions {
|
|
1636
|
+
/** 测试用:不真的弹打印对话框,准备好以后把 iframe 交给回调 */
|
|
1637
|
+
onReady?: (frame: HTMLIFrameElement) => void;
|
|
1638
|
+
}
|
|
1639
|
+
/** 打印正文;正在打印时再调不重复开 */
|
|
1640
|
+
declare function printDocument(editor: Editor, options?: PrintOptions): Promise<boolean>;
|
|
1641
|
+
|
|
1642
|
+
/**
|
|
1643
|
+
* 字数统计,照飞书主包 module 634260 `k(e)`(证据见组件规格 §52):
|
|
1644
|
+
*
|
|
1645
|
+
* - 字符数:去掉空白(和 `|`)后的 UTF-16 长度(`e.replace(/[\n|\s]/g,"").length`,所以一个 emoji 算 2);
|
|
1646
|
+
* - 字数:空白、`|`、`—` 是分隔;非 ASCII 且不是带重音的拉丁字母(中文、全角标点、全角数字、西里尔、希腊…)
|
|
1647
|
+
* 每个字算 1;一串 ASCII / 拉丁字母算 1 个词(`Hello, world!` = 2,`don't` = 1,`2024年10月` = 4);
|
|
1648
|
+
* emoji 并进当前这串(`hi😀` = 1)。
|
|
1649
|
+
*
|
|
1650
|
+
* 统计哪些文字(module 684869):从根往下走一遍,标题、段落、列表、待办、引用、代码、表格 / 高亮块 / 分栏里的文字、
|
|
1651
|
+
* 图片图注都算;文件、嵌入、流程图、投票这类块算 0。块与块之间用换行隔开。
|
|
1652
|
+
* 飞书给列表项前面拼了「- 」(每项多算 1 个词)、图注末尾不换行(和下一块首词粘在一起),这两个是它的副作用,不照抄。
|
|
1653
|
+
*/
|
|
1654
|
+
|
|
1655
|
+
interface WordCount {
|
|
1656
|
+
wordCount: number;
|
|
1657
|
+
charCount: number;
|
|
1658
|
+
}
|
|
1659
|
+
declare function countText(text: string): WordCount;
|
|
1660
|
+
declare function countDocument(doc: Node): WordCount;
|
|
1661
|
+
declare function countRange(doc: Node, from: number, to: number): WordCount;
|
|
1662
|
+
|
|
1663
|
+
/**
|
|
1664
|
+
* 顶栏的模式切换(飞书 docs_mode_switch_dropdown_btn):按钮是当前模式的图标 + 名字 + ▾,点开往左下出菜单,
|
|
1665
|
+
* 每项图标 + 名字 + 说明,当前项打勾;悬停提示带快捷键。只给有编辑权限的人看。
|
|
1666
|
+
*
|
|
1667
|
+
* 编辑器顶栏里不用传参(读编辑器的模式);宿主隐藏了顶栏、想放进自己的头部时,传 `mode` / `onChange`,
|
|
1668
|
+
* 再把同一个 mode 作为 `<NotionEditor viewMode>` 传给编辑器。
|
|
1669
|
+
*/
|
|
1670
|
+
declare function ViewModeSwitch(props?: {
|
|
1671
|
+
mode?: ViewMode;
|
|
1672
|
+
onChange?: (mode: ViewMode) => void;
|
|
1673
|
+
}): react.JSX.Element | null;
|
|
1674
|
+
|
|
1675
|
+
/**
|
|
1676
|
+
* 页宽设置(飞书「···」更多菜单里的 DOCX_WIDTH_MODE,module 785625 / 947449):
|
|
1677
|
+
* 弹层顶上一行「为当前窗口选择合适页宽」,下面三张卡片「默认 / 较宽 / 全宽」,每张是四条线画的示意图 + 名字,当前项高亮。
|
|
1678
|
+
* 我们顶栏没有「···」菜单,做成顶栏上的一个按钮。
|
|
1679
|
+
*
|
|
1680
|
+
* 编辑器顶栏里不用传参;宿主隐藏了顶栏、放进自己的头部时传 `mode` / `onChange`,
|
|
1681
|
+
* 再把同一个 mode 作为 `<NotionEditor widthMode>` 传给编辑器。
|
|
1682
|
+
*/
|
|
1683
|
+
declare function WidthModeMenu(props?: {
|
|
1684
|
+
mode?: DocWidthMode;
|
|
1685
|
+
onChange?: (mode: DocWidthMode) => void;
|
|
1686
|
+
}): react.JSX.Element;
|
|
1687
|
+
|
|
1688
|
+
export { type ApiParamAttrs, ApiParamExtension, ArticleViewer, type ArticleViewerProps, Audio, ButtonProps, type CalloutAttrs, CalloutExtension, type CalloutType, CodeBlockExtension, CodeBlockOptions, CodeGroupExtension, CollabContext, type CollabContextValue, CollabProvider, type CollabProviderLike, Column, type ColumnLayout, Columns, ContentFormat, DEFAULT_DOC_PERMISSIONS, DEFAULT_MAX_FILE_SIZES, DOC_WIDTHS, type DetailsAttrs, DetailsExtension, type DocPermissions, type DocWidthMode, DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, type EditorButtonConfig, type EditorCollabConfig, type EditorConfig, EditorConfigProvider, type EditorConfigProviderProps, EditorContentArea, type EditorFileConfig, type EditorLinkConfig, type EditorMentionConfig, type EditorPollConfig, type EditorProviderProps, type EditorSurfaceToken, EditorThemeStyle, type EditorThemeStyleProps, type EditorUploadConfig, type EditorUserConfig, type EditorVisualTheme, FileAttachment, type FileAttachmentAttrs, FileInline, type FilePreviewInfo, type FileView, FloatingElement, HIDE_FLOATING_META, type LinkPreview, LoadingSpinner, MAC_SYMBOLS, MAX_FILE_SIZE, type MediaKind, type MediaKindForButton, MediaUploadButton, type MediaUploadButtonProps, MediaUploadPlaceholder, type MentionDoc, type MentionDocState, type MentionNotifyParams, type MentionUser, NotionEditor, NotionEditorContent, EditorProvider as NotionEditorInner, type NotionEditorProps, type OverflowPosition, type ParsedContent, PasteDropMedia, type PasteDropMediaOptions, type PasteDropMediaUploadFn, type PasteDropRehostProgressEvent, type PollVoter, type PollVotes, Popover, PopoverContent, PopoverTrigger, type PrintOptions, type RehostProgressEvent, type RenderHighlightedHTMLOptions, type ResolvedEditorTheme, SR_ONLY, Separator, Spacer, Toolbar, ToolbarGroup, ToolbarSeparator, UiState, UiState as UiStateType, type User, UserContext, type UserContextValue, UserProvider, VIEW_MODE_TOAST, Video, type ViewMode, ViewModeSwitch, WidthModeMenu, type WordCount, clamp, cn, countDocument, countRange, countText, defaultUiState, detectMediaKind, findNodeAtPosition, findNodePosition, findSelectionPosition, focusNextNode, formatShortcutKey, getAvatar, getDocPermissions, getEditorMarkdown, getElementOverflowPosition, getNodeDisplayName, getSelectedBlockNodes, getSelectedNodesOfType, getSelectionBoundingRect, getUrlParam, handleImageUpload, hasContentAbove, isAllowedUri, isExtensionAvailable, isMac, isMarkInSchema, isNodeInSchema, isNodeTypeSelected, isSelectionValid, isTextSelectionValid, isValidPosition, markHideFloatingOnNext, parseEditorContent, parseShortcutKeys, pickFile, printDocument, removeEmptyParagraphs, renderHighlightedHTML, resolveEditorTheme, resolveMaxSize, runMediaUpload, sanitizeUrl, selectCurrentBlockContent, selectNodeAndHideFloating, selectionWithinConvertibleTypes, serializeEditorMarkdown, updateNodesAttr, useCollab, useCollaboration, useComposedRef, useCursorVisibility, useEditorConfig, useElementRect, useFloatingElement, useFloatingToolbarVisibility, useIsBreakpoint, useIsomorphicLayoutEffect, useMenuNavigation, useOnClickOutside, useScrolling, useThrottledCallback, useTiptapEditor, useUiEditorState, useUiEditorState as useUiEditorStateDefault, useUnmount, useUser, useViewMode, useWidthMode, useWindowSize };
|