@agilehub/agile-editor 1.5.0 → 1.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.
Files changed (33) hide show
  1. package/README.md +142 -0
  2. package/dist/agile-editor.css +1 -1
  3. package/dist/agile-editor.js +7300 -5262
  4. package/dist/types/components/editor/index.vue.d.ts +2 -2
  5. package/dist/types/components/index.d.ts +4 -2
  6. package/dist/types/components/index.vue.d.ts +151 -5
  7. package/dist/types/components/menus/toolbar/insert/bookmark.vue.d.ts +24 -0
  8. package/dist/types/components/preview-toolbar/annotation-shape.vue.d.ts +58 -0
  9. package/dist/types/components/preview-toolbar/drawing-layer.vue.d.ts +91 -0
  10. package/dist/types/components/preview-toolbar/geometry.d.ts +56 -0
  11. package/dist/types/components/preview-toolbar/index.vue.d.ts +200 -0
  12. package/dist/types/components/preview-toolbar/types.d.ts +48 -0
  13. package/dist/types/components/statusbar/countdown.vue.d.ts +19 -7
  14. package/dist/types/components/toolbar/classic.vue.d.ts +16 -8
  15. package/dist/types/components/toolbar/ribbon.vue.d.ts +16 -8
  16. package/dist/types/composables/i18n.d.ts +144 -3
  17. package/dist/types/extensions/bookmark.d.ts +8 -5
  18. package/dist/types/extensions/bubble-note.d.ts +2 -0
  19. package/dist/types/extensions/element-style.d.ts +0 -1
  20. package/dist/types/i18n.d.ts +144 -3
  21. package/dist/types/options/config/index.d.ts +2 -0
  22. package/dist/types/utils/html-element-id.d.ts +9 -0
  23. package/dist/types/utils/html-id.d.ts +1 -0
  24. package/dist/types/utils/iframe.d.ts +5 -0
  25. package/dist/types/utils/style-target.d.ts +49 -0
  26. package/docs/SECONDARY_DEVELOPMENT.md +1 -1
  27. package/docs/api.md +43 -0
  28. package/docs/configuration.md +57 -0
  29. package/docs/custom-components.md +150 -0
  30. package/docs/development.md +6 -2
  31. package/docs/menu-extension.md +26 -1
  32. package/package.json +25 -15
  33. package/dist/types/components/menus/toolbar/view/preview.vue.d.ts +0 -3
@@ -92,7 +92,8 @@ export declare const i18n: import("vue-i18n").I18n<{
92
92
  page: string;
93
93
  view: string;
94
94
  export: string;
95
- copyediting: string;
95
+ extension: string;
96
+ enhancement: string;
96
97
  };
97
98
  base: {
98
99
  align: {
@@ -355,12 +356,18 @@ export declare const i18n: import("vue-i18n").I18n<{
355
356
  mention: string;
356
357
  bookmark: {
357
358
  text: string;
359
+ title: string;
360
+ "edit-title": string;
361
+ note: string;
358
362
  set: string;
359
363
  ok: string;
364
+ confirm: string;
365
+ cancel: string;
360
366
  textName: string;
361
367
  placeholder: string;
362
368
  show: string;
363
369
  actions: string;
370
+ edit: string;
364
371
  delete: string;
365
372
  emptyError: string;
366
373
  };
@@ -1094,6 +1101,45 @@ export declare const i18n: import("vue-i18n").I18n<{
1094
1101
  preview: {
1095
1102
  title: string;
1096
1103
  disable: string;
1104
+ drawing: {
1105
+ title: string;
1106
+ hiddenTitle: string;
1107
+ tools: {
1108
+ title: string;
1109
+ rectangle: string;
1110
+ line: string;
1111
+ path: string;
1112
+ };
1113
+ color: {
1114
+ title: string;
1115
+ custom: string;
1116
+ };
1117
+ width: {
1118
+ title: string;
1119
+ thin: string;
1120
+ default: string;
1121
+ thick: string;
1122
+ extraThick: string;
1123
+ };
1124
+ strokeStyles: {
1125
+ title: string;
1126
+ solid: string;
1127
+ dashed: string;
1128
+ wavy: string;
1129
+ };
1130
+ select: string;
1131
+ deleteSelected: string;
1132
+ undo: string;
1133
+ save: string;
1134
+ saving: string;
1135
+ saved: string;
1136
+ hideAnnotations: string;
1137
+ showAnnotations: string;
1138
+ restorePage: string;
1139
+ clearAll: string;
1140
+ confirmClear: string;
1141
+ count: string;
1142
+ };
1097
1143
  countdown: {
1098
1144
  title: string;
1099
1145
  select: string;
@@ -1118,6 +1164,7 @@ export declare const i18n: import("vue-i18n").I18n<{
1118
1164
  remaining: string;
1119
1165
  };
1120
1166
  laserPointer: string;
1167
+ hideToolbar: string;
1121
1168
  };
1122
1169
  fullscreen: {
1123
1170
  title: string;
@@ -1312,7 +1359,8 @@ export declare const i18n: import("vue-i18n").I18n<{
1312
1359
  page: string;
1313
1360
  view: string;
1314
1361
  export: string;
1315
- copyediting: string;
1362
+ extension: string;
1363
+ enhancement: string;
1316
1364
  };
1317
1365
  base: {
1318
1366
  align: {
@@ -1575,12 +1623,18 @@ export declare const i18n: import("vue-i18n").I18n<{
1575
1623
  mention: string;
1576
1624
  bookmark: {
1577
1625
  text: string;
1626
+ title: string;
1627
+ "edit-title": string;
1628
+ note: string;
1578
1629
  set: string;
1579
1630
  ok: string;
1631
+ confirm: string;
1632
+ cancel: string;
1580
1633
  textName: string;
1581
1634
  placeholder: string;
1582
1635
  show: string;
1583
1636
  actions: string;
1637
+ edit: string;
1584
1638
  delete: string;
1585
1639
  emptyError: string;
1586
1640
  };
@@ -2319,6 +2373,45 @@ export declare const i18n: import("vue-i18n").I18n<{
2319
2373
  preview: {
2320
2374
  title: string;
2321
2375
  disable: string;
2376
+ drawing: {
2377
+ title: string;
2378
+ hiddenTitle: string;
2379
+ tools: {
2380
+ title: string;
2381
+ rectangle: string;
2382
+ line: string;
2383
+ path: string;
2384
+ };
2385
+ color: {
2386
+ title: string;
2387
+ custom: string;
2388
+ };
2389
+ width: {
2390
+ title: string;
2391
+ thin: string;
2392
+ default: string;
2393
+ thick: string;
2394
+ extraThick: string;
2395
+ };
2396
+ strokeStyles: {
2397
+ title: string;
2398
+ solid: string;
2399
+ dashed: string;
2400
+ wavy: string;
2401
+ };
2402
+ select: string;
2403
+ deleteSelected: string;
2404
+ undo: string;
2405
+ save: string;
2406
+ saving: string;
2407
+ saved: string;
2408
+ hideAnnotations: string;
2409
+ showAnnotations: string;
2410
+ restorePage: string;
2411
+ clearAll: string;
2412
+ confirmClear: string;
2413
+ count: string;
2414
+ };
2322
2415
  countdown: {
2323
2416
  title: string;
2324
2417
  select: string;
@@ -2343,6 +2436,7 @@ export declare const i18n: import("vue-i18n").I18n<{
2343
2436
  remaining: string;
2344
2437
  };
2345
2438
  laserPointer: string;
2439
+ hideToolbar: string;
2346
2440
  };
2347
2441
  fullscreen: {
2348
2442
  title: string;
@@ -2524,7 +2618,8 @@ export declare const i18n: import("vue-i18n").I18n<{
2524
2618
  page: string;
2525
2619
  view: string;
2526
2620
  export: string;
2527
- copyediting: string;
2621
+ extension: string;
2622
+ enhancement: string;
2528
2623
  };
2529
2624
  base: {
2530
2625
  align: {
@@ -2787,12 +2882,18 @@ export declare const i18n: import("vue-i18n").I18n<{
2787
2882
  mention: string;
2788
2883
  bookmark: {
2789
2884
  text: string;
2885
+ title: string;
2886
+ "edit-title": string;
2887
+ note: string;
2790
2888
  set: string;
2791
2889
  ok: string;
2890
+ confirm: string;
2891
+ cancel: string;
2792
2892
  textName: string;
2793
2893
  placeholder: string;
2794
2894
  show: string;
2795
2895
  actions: string;
2896
+ edit: string;
2796
2897
  delete: string;
2797
2898
  emptyError: string;
2798
2899
  };
@@ -3531,6 +3632,45 @@ export declare const i18n: import("vue-i18n").I18n<{
3531
3632
  preview: {
3532
3633
  title: string;
3533
3634
  disable: string;
3635
+ drawing: {
3636
+ title: string;
3637
+ hiddenTitle: string;
3638
+ tools: {
3639
+ title: string;
3640
+ rectangle: string;
3641
+ line: string;
3642
+ path: string;
3643
+ };
3644
+ color: {
3645
+ title: string;
3646
+ custom: string;
3647
+ };
3648
+ width: {
3649
+ title: string;
3650
+ thin: string;
3651
+ default: string;
3652
+ thick: string;
3653
+ extraThick: string;
3654
+ };
3655
+ strokeStyles: {
3656
+ title: string;
3657
+ solid: string;
3658
+ dashed: string;
3659
+ wavy: string;
3660
+ };
3661
+ select: string;
3662
+ deleteSelected: string;
3663
+ undo: string;
3664
+ save: string;
3665
+ saving: string;
3666
+ saved: string;
3667
+ hideAnnotations: string;
3668
+ showAnnotations: string;
3669
+ restorePage: string;
3670
+ clearAll: string;
3671
+ confirmClear: string;
3672
+ count: string;
3673
+ };
3534
3674
  countdown: {
3535
3675
  title: string;
3536
3676
  select: string;
@@ -3555,6 +3695,7 @@ export declare const i18n: import("vue-i18n").I18n<{
3555
3695
  remaining: string;
3556
3696
  };
3557
3697
  laserPointer: string;
3698
+ hideToolbar: string;
3558
3699
  };
3559
3700
  fullscreen: {
3560
3701
  title: string;
@@ -1,10 +1,12 @@
1
1
  import type { FormattingOptions } from '../../utils/document-formatting';
2
+ export declare const additionalToolbarMenus: string[];
2
3
  declare const _default: {
3
4
  editorKey: string;
4
5
  locale: string;
5
6
  theme: string;
6
7
  skin: string;
7
8
  height: string;
9
+ preview: boolean;
8
10
  fullscreenZIndex: number;
9
11
  dicts: {
10
12
  fonts: ({
@@ -0,0 +1,9 @@
1
+ import type { EditorState } from '@tiptap/pm/state';
2
+ export declare const nodeTypesWithOwnId: Set<string>;
3
+ export declare const nodeTypesWithoutHtmlId: Set<string>;
4
+ export declare const htmlIdNodeTypes: string[];
5
+ export declare const htmlIdMarkTypes: string[];
6
+ export declare const ensureHtmlElementIds: (state: EditorState, range?: {
7
+ from: number;
8
+ to: number;
9
+ }) => import("@tiptap/pm/state").Transaction;
@@ -0,0 +1 @@
1
+ export declare const createHtmlId: () => string;
@@ -0,0 +1,5 @@
1
+ export declare const disableIframeAutoplay: (value: string) => string;
2
+ export declare const normalizeIframeDimensions: (width: unknown, maxWidth: number) => {
3
+ width: number;
4
+ height: number;
5
+ };
@@ -0,0 +1,49 @@
1
+ import type { Mark, Node as ProseMirrorNode } from '@tiptap/pm/model';
2
+ export type StyleTargetBase = {
3
+ value: string;
4
+ label: string;
5
+ depth: number;
6
+ };
7
+ export type StyleTarget = StyleTargetBase & ({
8
+ kind: 'text';
9
+ } | {
10
+ kind: 'node';
11
+ position: number;
12
+ nodeType: string;
13
+ } | {
14
+ kind: 'mark';
15
+ markName: string;
16
+ styleAttribute: string;
17
+ from: number;
18
+ to: number;
19
+ } | {
20
+ kind: 'imageChild';
21
+ position: number;
22
+ attribute: 'imageStyle' | 'captionStyle';
23
+ });
24
+ export declare const nodeTagNames: Record<string, string>;
25
+ export declare const styleableNodeTypes: string[];
26
+ export declare const getNodeTargetLabel: (node: {
27
+ type: {
28
+ name: string;
29
+ };
30
+ attrs?: Record<string, unknown>;
31
+ }) => string;
32
+ type InlineMarkConfig = {
33
+ label: string;
34
+ styleAttribute: string;
35
+ };
36
+ export declare const spanMarkNames: Set<string>;
37
+ export declare const inlineMarkConfigs: Record<string, InlineMarkConfig>;
38
+ export declare const styleableMarkTypes: string[];
39
+ export declare const globalStyleMarkTypes: string[];
40
+ export declare const inlineMarkNames: Set<string>;
41
+ export declare const hasStyleSpanMark: (marks: readonly Mark[]) => boolean;
42
+ export declare const stripBubbleNoteDecorationStyles: (styleText: string) => string;
43
+ export declare const createBubbleNoteEditableStyle: (attrs: {
44
+ lineType?: string;
45
+ lineColor?: string;
46
+ inlineStyle?: string;
47
+ }) => string;
48
+ export declare const getInlineMarkTargets: (textNode: ProseMirrorNode | undefined, doc: ProseMirrorNode, from: number, depth: number) => StyleTarget[];
49
+ export {};
@@ -527,7 +527,7 @@ function onCreated({ editor }: { editor: Editor }): void {
527
527
  | ----------------------------------------------------------------------- | -------------------------------------------------------------------- |
528
528
  | `toolbar_base` | 开始工具栏追加业务组件 |
529
529
  | `toolbar_insert` | 插入工具栏追加业务组件,本例使用此插槽 |
530
- | `toolbar_table`、`toolbar_tools`、`toolbar_view`、`toolbar_copyediting` | 对应工具栏追加组件;所属菜单需要启用 |
530
+ | `toolbar_table`、`toolbar_tools`、`toolbar_view`、`toolbar_review` | 对应工具栏追加组件;所属菜单需要启用 |
531
531
  | `toolbar_actions` | 工具栏操作区域 |
532
532
  | `bubble_menu` | 编辑器浮动菜单中的自定义内容;受浮动菜单显示条件约束,不是常驻工具栏 |
533
533
  | `AgileMenuButton` | 菜单按钮,使用 `@menu-click` 执行操作 |
package/docs/api.md CHANGED
@@ -51,6 +51,7 @@ const slice = editor.state.doc.slice(from, to)
51
51
  | --- | --- | --- |
52
52
  | `saveContent(showMessage = true)` | `boolean` | 调用业务侧 `onSave`;只读模式不保存 |
53
53
  | `setReadOnly(readOnly = true)` | `boolean` | 动态切换只读状态 |
54
+ | `setPreview(preview = true)` | `boolean` | 动态切换内容预览模式,自动只读并隐藏工具栏 |
54
55
 
55
56
  保存回调参数和返回值见 [完整配置](./configuration.md#保存文档)。
56
57
 
@@ -86,6 +87,48 @@ editorRef.value.setPage({
86
87
  })
87
88
  ```
88
89
 
90
+ ## 书签
91
+
92
+ Word 导入的书签会保留为 `<a id="...">`,编辑器内部创建的书签会渲染为
93
+ `<bookmark bookmarkName="...">`。下面这些方法同时支持两种形式。
94
+
95
+ 编辑器界面可在“插入 → 插入书签”中新增备注书签。点击编辑区中的书签会显示
96
+ 备注、编辑和删除操作;备注型书签删除时会同时移除备注文字,导入书签或普通
97
+ 定位书签删除时只移除标记,原正文保留。
98
+
99
+ 书签正文不可直接在编辑区输入、删除、剪切或修改格式。所有变更必须通过书签
100
+ 编辑弹窗、书签删除按钮或对应的组件 API 完成。
101
+
102
+ | 方法 | 参数 | 返回值 | 说明 |
103
+ | --- | --- | --- | --- |
104
+ | `getAllBookmarks()` | 无 | `{ bookmarkRowId, bookmarkRowName, bookmarkRowText }[]` | 获取文档中的去重书签列表 |
105
+ | `focusBookmark(name)` | 书签名称 | `boolean` | 滚动到书签并移动光标 |
106
+ | `setBookmark(name)` | 书签名称 | `boolean` | 为当前选区添加书签 |
107
+ | `deleteBookmark(name)` | 书签名称 | `boolean` | 删除书签标记,保留原文字 |
108
+
109
+ ```ts
110
+ const bookmarks = editorRef.value.getAllBookmarks()
111
+
112
+ // 例如 DOCX 中的书签名可能是 bookmark-_Toc16808
113
+ editorRef.value.focusBookmark(bookmarks[0].bookmarkRowName)
114
+ ```
115
+
116
+ `bookmarkRowText` 是用于导航展示的可读文字。DOCX 导入书签会返回对应章节标题,
117
+ 例如 `第一章 养老金融的兴起与发展`。
118
+
119
+ 需要在编辑区显示书签标记时设置:
120
+
121
+ ```ts
122
+ const options = {
123
+ page: {
124
+ showBookmark: true,
125
+ },
126
+ }
127
+ ```
128
+
129
+ `showBookmark` 只控制编辑器书签标记的显示。DOCX 导入的锚点包含章节正文,
130
+ 其文字不会因关闭该选项而隐藏。
131
+
89
132
  ## Tiptap 实例
90
133
 
91
134
  | 方法 | 返回值 | 说明 |
@@ -38,6 +38,7 @@
38
38
  | `theme` | `'light'` | `'light'`、`'dark'`、`'auto'` |
39
39
  | `skin` | `'default'` | `'default'` 或 `'modern'` |
40
40
  | `height` | `'100%'` | 父容器必须具有明确高度 |
41
+ | `preview` | `false` | 内容预览模式,自动只读并隐藏编辑工具栏 |
41
42
  | `fullscreenZIndex` | `10` | 全屏层级 |
42
43
  | `dicts` | 内置字典 | 字体、颜色、字号、页面预设等 |
43
44
  | `toolbar` | 对象 | 工具栏模式、菜单和操作区 |
@@ -54,6 +55,62 @@
54
55
  | `diagrams` | 对象 | 绘图配置 |
55
56
  | `echarts` | 对象 | 图表配置 |
56
57
 
58
+ ## 内容预览
59
+
60
+ 通过顶层 `preview` 属性可以直接进入预览状态:
61
+
62
+ ```vue
63
+ <AgileEditor
64
+ :preview="true"
65
+ :document="{ content: html }"
66
+ />
67
+ ```
68
+
69
+ 开启后会自动:
70
+
71
+ - 设置编辑器为只读。
72
+ - 添加预览模式布局。
73
+ - 隐藏开始、插入、表格、工具等编辑工具栏。
74
+ - 保留阅读态气泡注释等只读交互。
75
+
76
+ 运行时可通过组件方法切换:
77
+
78
+ ```ts
79
+ editorRef.value.setPreview(true)
80
+ editorRef.value.setPreview(false)
81
+ ```
82
+
83
+ 业务端不需要再手动修改 `getPage().preview.enabled`。
84
+
85
+ 预览参数和编辑态工具配置是分开的。编辑态需要隐藏部分辅助功能时,仍通过
86
+ `document` 和 `page` 配置:
87
+
88
+ ```ts
89
+ const editorOptions = {
90
+ preview: false,
91
+ document: {
92
+ autofocus: false,
93
+ enableBubbleMenu: false,
94
+ enableBlockMenu: false,
95
+ },
96
+ page: {
97
+ showBookmark: false,
98
+ showBreakMarks: false,
99
+ showLineNumber: false,
100
+ showToc: false,
101
+ showAI: false,
102
+ },
103
+ }
104
+ ```
105
+
106
+ 这些配置只描述编辑态。`preview: true` 时编辑器会在内部派生预览状态并临时隐藏
107
+ 相关工具,但不会修改上述业务配置;调用 `setPreview(false)` 后会按原配置恢复。
108
+ 因此进入预览时只需要:
109
+
110
+ ```vue
111
+ <AgileEditor :preview="true" :document="{ content: html }" />
112
+ ```
113
+
57
114
  ## 文档参数
58
115
 
59
116
  ```js
@@ -21,6 +21,7 @@
21
21
  import {
22
22
  AgileDialog,
23
23
  AgileMenuButton,
24
+ AgilePreviewToolbar,
24
25
  AgileTooltip,
25
26
  } from '@agilehub/agile-editor'
26
27
  ```
@@ -29,10 +30,159 @@ import {
29
30
  | --- | --- | --- |
30
31
  | `AgileMenuButton` | 工具栏按钮 | 是 |
31
32
  | `AgileDialog` | 统一弹窗外壳 | 否 |
33
+ | `AgilePreviewToolbar` | 预览模式底部工具栏 | 否 |
32
34
  | `AgileTooltip` | 统一提示 | 否 |
33
35
 
34
36
  `useAgileEditor` 全局注册只负责主编辑器组件,不会自动全局注册上述辅助组件。业务项目需要显式 import。
35
37
 
38
+ ## 独立预览工具栏
39
+
40
+ `AgilePreviewToolbar` 不读取编辑器内部状态。业务侧通过 props 传入当前预览状态,并在事件中更新自己的状态:
41
+
42
+ 该组件面向只读预览页面和预览弹框,右侧按钮用于隐藏工具栏。编辑器不再内置旧“演示模式”工具栏;业务端使用 `preview` 或 `setPreview()` 进入内容预览后,可按需组合 `AgilePreviewToolbar`。
43
+
44
+ ```vue
45
+ <template>
46
+ <div id="business-preview" ref="workspace" class="preview-workspace">
47
+ <DocumentContent />
48
+ <AgilePreviewToolbar
49
+ floating
50
+ attach="#business-preview"
51
+ drawing-target="#business-preview .business-document"
52
+ :visible="page.toolbarVisible"
53
+ :layout="page.layout"
54
+ :zoom-level="page.zoomLevel"
55
+ :auto-width="page.autoWidth"
56
+ v-model:laser-pointer="page.laserPointer"
57
+ @zoom-in="zoomIn"
58
+ @zoom-out="zoomOut"
59
+ @auto-width="toggleAutoWidth"
60
+ @countdown-exit="exitPreview"
61
+ @hide="page.toolbarVisible = false"
62
+ />
63
+ </div>
64
+ </template>
65
+
66
+ <script setup lang="ts">
67
+ import { reactive } from 'vue'
68
+ import { AgilePreviewToolbar } from '@agilehub/agile-editor'
69
+
70
+ const page = reactive({
71
+ layout: 'page' as 'page' | 'web',
72
+ zoomLevel: 100,
73
+ autoWidth: false,
74
+ laserPointer: false,
75
+ toolbarVisible: true,
76
+ })
77
+
78
+ function zoomIn() {
79
+ page.zoomLevel = Math.min(page.zoomLevel + 10, 500)
80
+ page.autoWidth = false
81
+ }
82
+
83
+ function zoomOut() {
84
+ page.zoomLevel = Math.max(page.zoomLevel - 10, 20)
85
+ page.autoWidth = false
86
+ }
87
+
88
+ function toggleAutoWidth() {
89
+ page.autoWidth = !page.autoWidth
90
+ }
91
+
92
+ function exitPreview() {
93
+ // 由业务系统关闭预览页面或预览容器
94
+ }
95
+ </script>
96
+ ```
97
+
98
+ 主要 props:
99
+
100
+ | Prop | 类型 / 默认值 | 说明 |
101
+ | --- | --- | --- |
102
+ | `layout` | `'page' \| 'web'`,`'page'` | `web` 布局下不显示缩放按钮 |
103
+ | `zoomLevel` | `number`,`100` | 控制缩放按钮何时禁用 |
104
+ | `minZoom` / `maxZoom` | `number`,`20` / `500` | 缩放范围 |
105
+ | `autoWidth` | `boolean`,`false` | 控制最佳宽度按钮状态 |
106
+ | `laserPointer` | `boolean`,`false` | 激光笔状态,支持 `v-model:laser-pointer` |
107
+ | `floating` | `boolean`,`true` | 是否浮在父容器底部居中 |
108
+ | `visible` | `boolean`,`true` | 是否显示工具栏;隐藏时绘制层和已有标注仍保留 |
109
+ | `attach` | CSS 选择器或函数 | 倒计时和提示弹层挂载节点;默认 `body` |
110
+ | `drawingTarget` | CSS 选择器或 `HTMLElement` | 标注层挂载的文档内容容器;容器应使用 `position: relative` |
111
+ | `drawingColor` | `string`,`'#E34D59'` | 新标注默认颜色 |
112
+ | `drawingWidth` | `number`,`2` | 新标注默认线宽,支持 1–4px |
113
+ | `pageSettings` | `{ width, margin }` | 当前预览页面宽度和四边边距,会随标注快照保存 |
114
+ | `onAnnotationsSave` | `(snapshot) => void \| Promise<void>` | 点击保存按钮时调用的业务保存回调 |
115
+
116
+ 主要事件:
117
+
118
+ | 事件 | 参数 | 说明 |
119
+ | --- | --- | --- |
120
+ | `zoom-in` / `zoom-out` | 无 | 请求放大或缩小 |
121
+ | `auto-width` | 无 | 请求切换最佳宽度 |
122
+ | `update:laser-pointer` / `laser-pointer-change` | `boolean` | 激光笔状态变化 |
123
+ | `countdown-change` | 倒计时文本 | 倒计时显示内容变化 |
124
+ | `countdown-exit` | 无 | 倒计时结束并选择退出预览 |
125
+ | `hide` | 无 | 隐藏预览工具栏,不结束预览状态 |
126
+ | `draw-tool-change` | `PreviewDrawTool \| null` | 当前绘制或选择工具变化 |
127
+ | `stroke-style-change` | `PreviewStrokeStyle` | 当前线型变化 |
128
+ | `drawing-color-change` | CSS 颜色字符串 | 新标注使用的颜色变化 |
129
+ | `drawing-width-change` | `number` | 新标注使用的线宽变化,范围 1–4px |
130
+ | `annotation-add` | `PreviewAnnotation` | 新增一条标注 |
131
+ | `annotation-delete` | `annotationId` | 删除单条标注 |
132
+ | `annotations-undo` | 无 | 撤回上一条标注操作 |
133
+ | `annotations-clear` | 无 | 清空全部标注 |
134
+ | `annotations-change` | `PreviewAnnotation[]` | 标注集合因新增、删除、清空或撤销发生变化 |
135
+ | `annotations-visibility-change` | `boolean` | 临时隐藏或恢复显示全部标注 |
136
+ | `save-annotations` | `PreviewAnnotationSnapshot` | 请求保存当前标注快照 |
137
+ | `restore-annotation-page` | `PreviewPageSettings` | 请求恢复标注保存时的页面宽度和边距 |
138
+ | `drawing-ready` | 无 | 绘制层已挂载,可以调用实例方法恢复标注 |
139
+ | `selection-change` | `annotationId \| null` | 当前选中的标注变化 |
140
+
141
+ 组件只负责交互和展示,不直接修改编辑器或业务页面状态。需要与 `AgileEditor.getPage()` 联动时,由业务层把页面状态作为 props 传入并处理对应事件。
142
+
143
+ 绘制层使用相对文档内容的归一化坐标,因此滚动和页面缩放时会与正文同步移动。标注默认只存在于当前预览实例,不会写入编辑器 HTML;需要持久化时,业务侧可监听 `annotation-add`、`annotation-delete` 和 `annotations-clear` 事件。
144
+
145
+ 组件实例提供以下标注保存方法:
146
+
147
+ | 方法 | 说明 |
148
+ | --- | --- |
149
+ | `getAnnotations()` | 获取当前标注数组的深拷贝 |
150
+ | `serializeAnnotations()` | 序列化为带版本号的 JSON 字符串 |
151
+ | `setAnnotations(annotations)` | 恢复或替换当前标注 |
152
+ | `restoreAnnotations(snapshotOrJson)` | 校验并恢复保存快照 |
153
+ | `clearAnnotations()` | 清空当前标注并保留可撤销历史 |
154
+ | `saveAnnotations()` | 触发保存事件和 `onAnnotationsSave` 回调,返回 `Promise<boolean>` |
155
+
156
+ 保存快照结构:
157
+
158
+ ```ts
159
+ interface PreviewAnnotationSnapshot {
160
+ version: 1
161
+ page?: {
162
+ width: number
163
+ margin: {
164
+ left: number
165
+ right: number
166
+ top: number
167
+ bottom: number
168
+ }
169
+ }
170
+ annotations: PreviewAnnotation[]
171
+ }
172
+ ```
173
+
174
+ 业务侧可通过 `page-settings` 传入当前页面尺寸。保存时该信息会写入 `snapshot.page`,恢复标注时可据此还原原页面宽度和边距。
175
+
176
+ 业务恢复示例:
177
+
178
+ ```ts
179
+ const snapshot = toolbarRef.value.serializeAnnotations()
180
+ await businessApi.save(snapshot)
181
+
182
+ const saved = await businessApi.load()
183
+ toolbarRef.value.restoreAnnotations(saved)
184
+ ```
185
+
36
186
  ## 接入业务面板
37
187
 
38
188
  编辑器外部可以放置自己的 Vue 面板,通过 `created` 事件拿到 Editor:
@@ -21,8 +21,12 @@ npm run dev
21
21
  ```
22
22
 
23
23
  - 默认端口:`9000`
24
- - Vite `base`:`/editor-demo`
25
- - 访问地址:`http://localhost:9000/editor-demo`
24
+ - Vite `base`:`/editor`
25
+ - 本机访问:`http://localhost:9000/editor`
26
+ - 局域网访问:启动后使用终端输出的 `Network` 地址,例如
27
+ `http://192.168.3.237:9000/editor`
28
+
29
+ 开发服务默认监听 `0.0.0.0`,同一局域网内的设备可直接访问 `Network` 地址。
26
30
 
27
31
  开发入口链路:
28
32
 
@@ -112,12 +112,37 @@ const editor = shallowRef<Editor>()
112
112
  | `toolbar_table` | “表格”工具栏 |
113
113
  | `toolbar_tools` | “工具”工具栏 |
114
114
  | `toolbar_view` | “视图”工具栏 |
115
- | `toolbar_copyediting` | “审阅/校对”工具栏 |
115
+ | `toolbar_review` | “审阅”工具栏,对应 `review` 菜单 |
116
+ | `toolbar_extension` | “扩展”工具栏,可通过 `extension` 菜单启用 |
117
+ | `toolbar_enhancement` | “增强”工具栏,可通过 `enhancement` 菜单启用 |
116
118
  | `toolbar_actions` | 工具栏右侧操作区 |
117
119
  | `bubble_menu` | 选区或节点浮动菜单 |
118
120
 
119
121
  插槽对应的菜单必须在 `toolbar.menus` 中启用。
120
122
 
123
+ ```vue
124
+ <AgileEditor
125
+ :toolbar="{
126
+ menus: ['base', 'insert', 'extension', 'enhancement'],
127
+ }"
128
+ >
129
+ <template #toolbar_extension="{ toolbarMode }">
130
+ <AgileMenuButton
131
+ ico="block-add"
132
+ text="扩展能力"
133
+ :data-toolbar-mode="toolbarMode"
134
+ />
135
+ </template>
136
+ <template #toolbar_enhancement="{ toolbarMode }">
137
+ <AgileMenuButton
138
+ ico="ai"
139
+ text="增强能力"
140
+ :data-toolbar-mode="toolbarMode"
141
+ />
142
+ </template>
143
+ </AgileEditor>
144
+ ```
145
+
121
146
  ### 按钮打开业务弹窗
122
147
 
123
148
  ```vue