@agilehub/agile-editor 1.5.0 → 1.6.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.
@@ -1107,6 +1107,45 @@ export declare const useI18n: () => import("vue-i18n").Composer<{
1107
1107
  preview: {
1108
1108
  title: string;
1109
1109
  disable: string;
1110
+ drawing: {
1111
+ title: string;
1112
+ hiddenTitle: string;
1113
+ tools: {
1114
+ title: string;
1115
+ rectangle: string;
1116
+ line: string;
1117
+ path: string;
1118
+ };
1119
+ color: {
1120
+ title: string;
1121
+ custom: string;
1122
+ };
1123
+ width: {
1124
+ title: string;
1125
+ thin: string;
1126
+ default: string;
1127
+ thick: string;
1128
+ extraThick: string;
1129
+ };
1130
+ strokeStyles: {
1131
+ title: string;
1132
+ solid: string;
1133
+ dashed: string;
1134
+ wavy: string;
1135
+ };
1136
+ select: string;
1137
+ deleteSelected: string;
1138
+ undo: string;
1139
+ save: string;
1140
+ saving: string;
1141
+ saved: string;
1142
+ hideAnnotations: string;
1143
+ showAnnotations: string;
1144
+ restorePage: string;
1145
+ clearAll: string;
1146
+ confirmClear: string;
1147
+ count: string;
1148
+ };
1110
1149
  countdown: {
1111
1150
  title: string;
1112
1151
  select: string;
@@ -1131,6 +1170,7 @@ export declare const useI18n: () => import("vue-i18n").Composer<{
1131
1170
  remaining: string;
1132
1171
  };
1133
1172
  laserPointer: string;
1173
+ hideToolbar: string;
1134
1174
  };
1135
1175
  fullscreen: {
1136
1176
  title: string;
@@ -2332,6 +2372,45 @@ export declare const useI18n: () => import("vue-i18n").Composer<{
2332
2372
  preview: {
2333
2373
  title: string;
2334
2374
  disable: string;
2375
+ drawing: {
2376
+ title: string;
2377
+ hiddenTitle: string;
2378
+ tools: {
2379
+ title: string;
2380
+ rectangle: string;
2381
+ line: string;
2382
+ path: string;
2383
+ };
2384
+ color: {
2385
+ title: string;
2386
+ custom: string;
2387
+ };
2388
+ width: {
2389
+ title: string;
2390
+ thin: string;
2391
+ default: string;
2392
+ thick: string;
2393
+ extraThick: string;
2394
+ };
2395
+ strokeStyles: {
2396
+ title: string;
2397
+ solid: string;
2398
+ dashed: string;
2399
+ wavy: string;
2400
+ };
2401
+ select: string;
2402
+ deleteSelected: string;
2403
+ undo: string;
2404
+ save: string;
2405
+ saving: string;
2406
+ saved: string;
2407
+ hideAnnotations: string;
2408
+ showAnnotations: string;
2409
+ restorePage: string;
2410
+ clearAll: string;
2411
+ confirmClear: string;
2412
+ count: string;
2413
+ };
2335
2414
  countdown: {
2336
2415
  title: string;
2337
2416
  select: string;
@@ -2356,6 +2435,7 @@ export declare const useI18n: () => import("vue-i18n").Composer<{
2356
2435
  remaining: string;
2357
2436
  };
2358
2437
  laserPointer: string;
2438
+ hideToolbar: string;
2359
2439
  };
2360
2440
  fullscreen: {
2361
2441
  title: string;
@@ -3544,6 +3624,45 @@ export declare const useI18n: () => import("vue-i18n").Composer<{
3544
3624
  preview: {
3545
3625
  title: string;
3546
3626
  disable: string;
3627
+ drawing: {
3628
+ title: string;
3629
+ hiddenTitle: string;
3630
+ tools: {
3631
+ title: string;
3632
+ rectangle: string;
3633
+ line: string;
3634
+ path: string;
3635
+ };
3636
+ color: {
3637
+ title: string;
3638
+ custom: string;
3639
+ };
3640
+ width: {
3641
+ title: string;
3642
+ thin: string;
3643
+ default: string;
3644
+ thick: string;
3645
+ extraThick: string;
3646
+ };
3647
+ strokeStyles: {
3648
+ title: string;
3649
+ solid: string;
3650
+ dashed: string;
3651
+ wavy: string;
3652
+ };
3653
+ select: string;
3654
+ deleteSelected: string;
3655
+ undo: string;
3656
+ save: string;
3657
+ saving: string;
3658
+ saved: string;
3659
+ hideAnnotations: string;
3660
+ showAnnotations: string;
3661
+ restorePage: string;
3662
+ clearAll: string;
3663
+ confirmClear: string;
3664
+ count: string;
3665
+ };
3547
3666
  countdown: {
3548
3667
  title: string;
3549
3668
  select: string;
@@ -3568,6 +3687,7 @@ export declare const useI18n: () => import("vue-i18n").Composer<{
3568
3687
  remaining: string;
3569
3688
  };
3570
3689
  laserPointer: string;
3690
+ hideToolbar: string;
3571
3691
  };
3572
3692
  fullscreen: {
3573
3693
  title: string;
@@ -1,4 +1,6 @@
1
1
  import { Mark } from '@tiptap/core';
2
+ export declare const normalizeBubbleNoteLineType: (value: any) => any;
3
+ export declare const normalizeBubbleNoteLineColor: (value: any) => string;
2
4
  export declare const normalizeBubbleNoteReferenceUrl: (value: any) => string;
3
5
  declare const _default: Mark<any, any>;
4
6
  export default _default;
@@ -1,4 +1,3 @@
1
1
  import { Extension } from '@tiptap/core';
2
- export declare const styleableNodeTypes: string[];
3
2
  declare const _default: Extension<any, any>;
4
3
  export default _default;
@@ -1094,6 +1094,45 @@ export declare const i18n: import("vue-i18n").I18n<{
1094
1094
  preview: {
1095
1095
  title: string;
1096
1096
  disable: string;
1097
+ drawing: {
1098
+ title: string;
1099
+ hiddenTitle: string;
1100
+ tools: {
1101
+ title: string;
1102
+ rectangle: string;
1103
+ line: string;
1104
+ path: string;
1105
+ };
1106
+ color: {
1107
+ title: string;
1108
+ custom: string;
1109
+ };
1110
+ width: {
1111
+ title: string;
1112
+ thin: string;
1113
+ default: string;
1114
+ thick: string;
1115
+ extraThick: string;
1116
+ };
1117
+ strokeStyles: {
1118
+ title: string;
1119
+ solid: string;
1120
+ dashed: string;
1121
+ wavy: string;
1122
+ };
1123
+ select: string;
1124
+ deleteSelected: string;
1125
+ undo: string;
1126
+ save: string;
1127
+ saving: string;
1128
+ saved: string;
1129
+ hideAnnotations: string;
1130
+ showAnnotations: string;
1131
+ restorePage: string;
1132
+ clearAll: string;
1133
+ confirmClear: string;
1134
+ count: string;
1135
+ };
1097
1136
  countdown: {
1098
1137
  title: string;
1099
1138
  select: string;
@@ -1118,6 +1157,7 @@ export declare const i18n: import("vue-i18n").I18n<{
1118
1157
  remaining: string;
1119
1158
  };
1120
1159
  laserPointer: string;
1160
+ hideToolbar: string;
1121
1161
  };
1122
1162
  fullscreen: {
1123
1163
  title: string;
@@ -2319,6 +2359,45 @@ export declare const i18n: import("vue-i18n").I18n<{
2319
2359
  preview: {
2320
2360
  title: string;
2321
2361
  disable: string;
2362
+ drawing: {
2363
+ title: string;
2364
+ hiddenTitle: string;
2365
+ tools: {
2366
+ title: string;
2367
+ rectangle: string;
2368
+ line: string;
2369
+ path: string;
2370
+ };
2371
+ color: {
2372
+ title: string;
2373
+ custom: string;
2374
+ };
2375
+ width: {
2376
+ title: string;
2377
+ thin: string;
2378
+ default: string;
2379
+ thick: string;
2380
+ extraThick: string;
2381
+ };
2382
+ strokeStyles: {
2383
+ title: string;
2384
+ solid: string;
2385
+ dashed: string;
2386
+ wavy: string;
2387
+ };
2388
+ select: string;
2389
+ deleteSelected: string;
2390
+ undo: string;
2391
+ save: string;
2392
+ saving: string;
2393
+ saved: string;
2394
+ hideAnnotations: string;
2395
+ showAnnotations: string;
2396
+ restorePage: string;
2397
+ clearAll: string;
2398
+ confirmClear: string;
2399
+ count: string;
2400
+ };
2322
2401
  countdown: {
2323
2402
  title: string;
2324
2403
  select: string;
@@ -2343,6 +2422,7 @@ export declare const i18n: import("vue-i18n").I18n<{
2343
2422
  remaining: string;
2344
2423
  };
2345
2424
  laserPointer: string;
2425
+ hideToolbar: string;
2346
2426
  };
2347
2427
  fullscreen: {
2348
2428
  title: string;
@@ -3531,6 +3611,45 @@ export declare const i18n: import("vue-i18n").I18n<{
3531
3611
  preview: {
3532
3612
  title: string;
3533
3613
  disable: string;
3614
+ drawing: {
3615
+ title: string;
3616
+ hiddenTitle: string;
3617
+ tools: {
3618
+ title: string;
3619
+ rectangle: string;
3620
+ line: string;
3621
+ path: string;
3622
+ };
3623
+ color: {
3624
+ title: string;
3625
+ custom: string;
3626
+ };
3627
+ width: {
3628
+ title: string;
3629
+ thin: string;
3630
+ default: string;
3631
+ thick: string;
3632
+ extraThick: string;
3633
+ };
3634
+ strokeStyles: {
3635
+ title: string;
3636
+ solid: string;
3637
+ dashed: string;
3638
+ wavy: string;
3639
+ };
3640
+ select: string;
3641
+ deleteSelected: string;
3642
+ undo: string;
3643
+ save: string;
3644
+ saving: string;
3645
+ saved: string;
3646
+ hideAnnotations: string;
3647
+ showAnnotations: string;
3648
+ restorePage: string;
3649
+ clearAll: string;
3650
+ confirmClear: string;
3651
+ count: string;
3652
+ };
3534
3653
  countdown: {
3535
3654
  title: string;
3536
3655
  select: string;
@@ -3555,6 +3674,7 @@ export declare const i18n: import("vue-i18n").I18n<{
3555
3674
  remaining: string;
3556
3675
  };
3557
3676
  laserPointer: string;
3677
+ hideToolbar: string;
3558
3678
  };
3559
3679
  fullscreen: {
3560
3680
  title: string;
@@ -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 {};
@@ -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
+ 该组件面向只读预览页面和预览弹框,右侧按钮用于隐藏工具栏。编辑器内置的演示模式工具栏是另一套组件,右侧按钮用于退出演示模式,两者用途和交互不同。
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:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilehub/agile-editor",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Rich text editor based on Vue 3 and Tiptap 3",
5
5
  "author": "lytdev <lytdev@outlook.com>",
6
6
  "keywords": [
@@ -18,7 +18,7 @@
18
18
  "web office",
19
19
  "word editor"
20
20
  ],
21
- "license": "Apache 2.0",
21
+ "license": "Apache-2.0",
22
22
  "repository": {
23
23
  "type": "git",
24
24
  "url": "https://github.com/lytdev/agile-editor.git"
@@ -43,6 +43,7 @@
43
43
  },
44
44
  "scripts": {
45
45
  "build": "vue-tsc --noEmit && vite build && vue-tsc -p tsconfig.types.json",
46
+ "test:style-target": "node --test tests/style-target.test.mjs tests/style-schema.test.mjs tests/iframe.test.mjs",
46
47
  "typecheck": "vue-tsc --noEmit",
47
48
  "dev": "vite --port 9000 --open --force",
48
49
  "format": "oxfmt --write .",
@@ -52,7 +53,7 @@
52
53
  "prepublishOnly": "npm run build"
53
54
  },
54
55
  "dependencies": {
55
- "@agilehub/docx-converter": "1.2.0",
56
+ "@agilehub/docx-converter": "1.2.1",
56
57
  "@agilehub/latex-formula": "1.2.0",
57
58
  "@eslint/object-schema": "3.0.5",
58
59
  "@floating-ui/dom": "1.8.0",