@norio-office/rich-text 0.8.2 → 0.8.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/types.d.ts CHANGED
@@ -1,11 +1,17 @@
1
+ import { CollaborationPresence } from './collaboration-presence';
1
2
  import { JSONContent } from '@tiptap/core';
2
3
  import { RichTextAiEditorAdapter } from './ai/bridge';
3
4
  import { NordoxResourceResolver, PackNordoxOptions, RichTextAssetPackaging, UnpackedNordox } from './nordox';
4
5
  import { RichTextEditorExportItemKey, RichTextEditorCode, RichTextEditorFeatureItemKey, RichTextEditorInsertMenuItemKey, RichTextEditorOutlinePlacement, RichTextEditorToolbarActionKey } from './feature-codes';
6
+ export type { CollaborationPresence, CollaborationPresenceMember } from './collaboration-presence';
5
7
  export type { RichTextEditorExportItemKey, RichTextEditorCode, RichTextEditorFeatureCode, RichTextEditorFeatureItemKey, RichTextEditorInsertMenuItemKey, RichTextEditorOutlinePlacement, RichTextEditorToolbarActionKey, } from './feature-codes';
6
8
  export type RichTextEditorProps = {
7
9
  modelValue?: JSONContent | null;
8
10
  documentName?: string;
11
+ /** Show the file icon and editable name row. Defaults to true. */
12
+ showFileHeader?: boolean;
13
+ /** Host-owned status and members; hidden unless enabled is true. */
14
+ collaborationPresence?: CollaborationPresence | null;
9
15
  mode?: 'edit' | 'preview';
10
16
  assetPackaging?: RichTextAssetPackaging | null;
11
17
  showToolbar?: boolean;
@@ -37,6 +43,10 @@ export type RichTextEditorProps = {
37
43
  onMentionSearch?: RichTextEditorMentionProvider | null;
38
44
  };
39
45
  export type RichTextEditorMessages = Partial<Record<string, string>>;
46
+ export type RichTextEditorFileNameChangePayload = {
47
+ fileName: string;
48
+ previousFileName: string;
49
+ };
40
50
  export type RichTextEditorWatermarkOptions = {
41
51
  text: string;
42
52
  color?: string;
@@ -250,6 +260,8 @@ export type RichTextEditorOutlineState = {
250
260
  };
251
261
  export type RichTextEditorOutlineChangeHandler = (state: RichTextEditorOutlineState) => void;
252
262
  export type RichTextEditorInstance = {
263
+ getFileName: () => string;
264
+ setFileName: (fileName: string) => void;
253
265
  exportPdf: () => Promise<Blob | null>;
254
266
  exportImage: (options?: RichTextEditorImageExportOptions) => Promise<Blob | null>;
255
267
  exportHtml: () => string | null;
@@ -0,0 +1,50 @@
1
+ # 文件标题栏 / File header
2
+
3
+ 富文本标题栏与 Word 的文件栏保持相同用法:图标、当前文件名、点击名称编辑,以及独立的显示开关。默认显示;`showToolbar` 只控制正文工具栏,不控制文件栏。
4
+
5
+ ```vue
6
+ <script setup lang="ts">
7
+ import { ref } from 'vue'
8
+ import { RichTextEditor, type RichTextEditorInstance, type RichTextEditorFileNameChangePayload } from '@norio-office/rich-text'
9
+ import '@norio-office/rich-text/style.css'
10
+
11
+ const editor = ref<RichTextEditorInstance | null>(null)
12
+ const content = ref({ type: 'doc', content: [{ type: 'paragraph' }] })
13
+ const name = ref('项目说明.json')
14
+ const showFileHeader = ref(true)
15
+ function onNameChange(event: RichTextEditorFileNameChangePayload) {
16
+ console.log(event.previousFileName, event.fileName)
17
+ // 将新名称保存至业务文件元数据;协作时广播给其他客户端。
18
+ }
19
+ function rename() { editor.value?.setFileName('项目说明(修订).json') }
20
+ function readName() { return editor.value?.getFileName() }
21
+ </script>
22
+
23
+ <template>
24
+ <RichTextEditor ref="editor" v-model="content" v-model:document-name="name"
25
+ :show-file-header="showFileHeader" @file-name-change="onNameChange" />
26
+ </template>
27
+ ```
28
+
29
+ | 接口 | 语义 |
30
+ | --- | --- |
31
+ | `documentName?: string` | 初始名称及后续宿主更新;未设置或空白时使用“未命名文档”。支持 `v-model:documentName`。 |
32
+ | `showFileHeader?: boolean` | 默认 `true`。`false` 隐藏整行图标和名称;不影响名称和导出。 |
33
+ | `getFileName(): string` | 读取当前名称。 |
34
+ | `setFileName(name: string): void` | 同步更新当前名称。去除首尾空白,空值、非字符串、超过 255 个字符会抛错,原名称不变。隐藏及预览模式也可调用。 |
35
+ | `update:documentName` | 名称变化时同步发出字符串,可绑定 Vue `v-model`。 |
36
+ | `file-name-change` | 名称实际变化后按顺序异步通知 `{ fileName, previousFileName }`;首次挂载和设置相同名称不通知。 |
37
+
38
+ 编辑模式点击名称开始修改,Enter 或失焦提交,Escape 取消;输入法组词期间的 Enter 不提交。切换预览、隐藏标题栏或宿主更新名称时,旧草稿取消。预览模式显示静态名称;演示模式隐藏标题栏。
39
+
40
+ 名称是独立文件元数据,不写入 `getJSON()` / 正文 `v-model`,不进入正文撤销记录。宿主需持久化名称;组件本身不调用文件重命名接口。协作宿主可以使用独立 Y.Map 同步名称,并将其回传为 `documentName`,不要放进正文撤销管理器。集成平台已按这个方式接入,改名同步到同房间客户端,并用于平台保存及导出文件名。
41
+
42
+ `exportNordox()` 使用调用时的当前名称作为 manifest 标题;其他实例导出接口返回 Blob/HTML,下载文件名由宿主根据 `getFileName()` 设置。`openNordox()` 仍只替换正文;如需使用导入包名称,打开成功后读取返回的 `manifest.title` 并调用 `setFileName()`。
43
+
44
+ ## English
45
+
46
+ The file header shows a shared document icon and an editable file name. It is enabled by default and is independent of `showToolbar`. Set `showFileHeader` to `false` to hide the entire row. Preview displays a static name; presentation hides the header.
47
+
48
+ Use `documentName` / `v-model:documentName`, or `getFileName()` and `setFileName(name)`. Names are trimmed and must contain 1–255 characters; invalid imperative updates throw without changing the current name. Enter/blur commits, Escape cancels, and IME Enter does not commit. External updates, hiding the header and switching to preview cancel the draft.
49
+
50
+ `update:documentName` synchronously supplies the new string. `file-name-change` reports ordered asynchronous `{ fileName, previousFileName }` transitions, excluding initial mount and unchanged values. Names are host-owned metadata, separate from body JSON and undo history. Persist and synchronize them separately. `.nordox` exports capture the current name as their manifest title; use `getFileName()` for download names. `openNordox()` changes body content only; hosts can apply its returned manifest title explicitly.
package/docs/usage.md CHANGED
@@ -18,6 +18,11 @@ import { RichTextEditor } from '@norio-office/rich-text'
18
18
  - export to PDF, image, and HTML through instance methods
19
19
  - external upload integration for image, video, and file insertion
20
20
  - typed public instance API for Vue `ref` usage
21
+ - file icon and editable document name, with an independent header visibility switch
22
+
23
+ ## File header
24
+
25
+ Set `documentName` (or `v-model:documentName`) to supply the file name. The header is shown by default; `:show-file-header="false"` hides the whole row. Use `getFileName()` / `setFileName(name)` on the component ref and handle `file-name-change` to persist name metadata. Preview displays a read-only name. See the bilingual [file header guide](file-header.md) for examples, validation and collaboration integration.
21
26
 
22
27
  ## Mention
23
28
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@norio-office/rich-text",
3
- "version": "0.8.2",
4
- "description": "A reusable Vue 3 rich text editor component built with Tiptap 3.",
3
+ "version": "0.8.3",
4
+ "description": "一个基于tiptap 的富文本编辑器",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
7
7
  "module": "./dist/index.js",