@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.
- package/README.md +142 -0
- package/dist/agile-editor.css +1 -1
- package/dist/agile-editor.js +7960 -6199
- package/dist/types/components/index.d.ts +4 -2
- package/dist/types/components/index.vue.d.ts +120 -0
- package/dist/types/components/preview-toolbar/annotation-shape.vue.d.ts +58 -0
- package/dist/types/components/preview-toolbar/drawing-layer.vue.d.ts +91 -0
- package/dist/types/components/preview-toolbar/geometry.d.ts +56 -0
- package/dist/types/components/preview-toolbar/index.vue.d.ts +200 -0
- package/dist/types/components/preview-toolbar/types.d.ts +48 -0
- package/dist/types/components/statusbar/countdown.vue.d.ts +19 -7
- package/dist/types/composables/i18n.d.ts +120 -0
- package/dist/types/extensions/bubble-note.d.ts +2 -0
- package/dist/types/extensions/element-style.d.ts +0 -1
- package/dist/types/i18n.d.ts +120 -0
- package/dist/types/utils/html-element-id.d.ts +9 -0
- package/dist/types/utils/html-id.d.ts +1 -0
- package/dist/types/utils/iframe.d.ts +5 -0
- package/dist/types/utils/style-target.d.ts +49 -0
- package/docs/custom-components.md +150 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -83,6 +83,147 @@ createApp(App)
|
|
|
83
83
|
|
|
84
84
|
局部导入和全局注册二选一即可。组件上的同名属性优先于全局默认配置。
|
|
85
85
|
|
|
86
|
+
## 独立预览工具栏
|
|
87
|
+
|
|
88
|
+
`AgilePreviewToolbar` 用于只读预览页面和弹框预览,提供倒计时、激光笔、缩放、画图标注、标注保存与工具栏显隐。它是一个独立组件,不依赖 `AgileEditor` 内部注入,但需要业务侧提供文档内容的 CSS 选择器作为绘制目标。
|
|
89
|
+
|
|
90
|
+
### 基础接入
|
|
91
|
+
|
|
92
|
+
```vue
|
|
93
|
+
<template>
|
|
94
|
+
<div id="preview-workspace" class="preview-workspace">
|
|
95
|
+
<article class="preview-document">
|
|
96
|
+
<!-- 文档内容 -->
|
|
97
|
+
</article>
|
|
98
|
+
|
|
99
|
+
<AgilePreviewToolbar
|
|
100
|
+
ref="previewToolbarRef"
|
|
101
|
+
drawing-target="#preview-workspace .preview-document"
|
|
102
|
+
attach="#preview-workspace"
|
|
103
|
+
:visible="toolbarVisible"
|
|
104
|
+
:layout="page.layout"
|
|
105
|
+
:zoom-level="page.zoomLevel"
|
|
106
|
+
:auto-width="page.autoWidth"
|
|
107
|
+
v-model:laser-pointer="page.laserPointer"
|
|
108
|
+
:on-annotations-save="saveAnnotations"
|
|
109
|
+
@zoom-in="zoomIn"
|
|
110
|
+
@zoom-out="zoomOut"
|
|
111
|
+
@auto-width="toggleAutoWidth"
|
|
112
|
+
@drawing-ready="restoreAnnotations"
|
|
113
|
+
@hide="toolbarVisible = false"
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<script setup lang="ts">
|
|
119
|
+
import { reactive, ref } from 'vue'
|
|
120
|
+
import {
|
|
121
|
+
AgilePreviewToolbar,
|
|
122
|
+
type PreviewAnnotationSnapshot,
|
|
123
|
+
} from '@agilehub/agile-editor'
|
|
124
|
+
import '@agilehub/agile-editor/style'
|
|
125
|
+
|
|
126
|
+
const previewToolbarRef = ref()
|
|
127
|
+
const toolbarVisible = ref(true)
|
|
128
|
+
const page = reactive({
|
|
129
|
+
layout: 'page',
|
|
130
|
+
zoomLevel: 100,
|
|
131
|
+
autoWidth: false,
|
|
132
|
+
laserPointer: false,
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
function zoomIn() {
|
|
136
|
+
page.zoomLevel = Math.min(page.zoomLevel + 10, 500)
|
|
137
|
+
page.autoWidth = false
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function zoomOut() {
|
|
141
|
+
page.zoomLevel = Math.max(page.zoomLevel - 10, 20)
|
|
142
|
+
page.autoWidth = false
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function toggleAutoWidth() {
|
|
146
|
+
page.autoWidth = !page.autoWidth
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function saveAnnotations(snapshot: PreviewAnnotationSnapshot) {
|
|
150
|
+
await businessApi.saveAnnotations(snapshot)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function restoreAnnotations() {
|
|
154
|
+
const snapshot = await businessApi.loadAnnotations()
|
|
155
|
+
previewToolbarRef.value?.restoreAnnotations(snapshot)
|
|
156
|
+
}
|
|
157
|
+
</script>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`drawing-target` 指向实际承载文档正文的元素,该元素应设置为 `position: relative`。标注使用相对正文的归一化坐标,因此滚动、缩放和窗口尺寸变化时会跟随文档内容。
|
|
161
|
+
|
|
162
|
+
### 工具栏状态
|
|
163
|
+
|
|
164
|
+
- `visible` 只控制工具栏显隐,隐藏工具栏不会清空已有标注。
|
|
165
|
+
- `layout="web"` 时隐藏缩放按钮。
|
|
166
|
+
- `laserPointer` 支持 `v-model:laser-pointer`。
|
|
167
|
+
- `drawingTarget` 未找到时,画图按钮自动禁用。
|
|
168
|
+
- 编辑器内置演示模式工具栏与独立预览工具栏不是同一个组件,退出演示模式仍使用编辑器自身工具栏。
|
|
169
|
+
|
|
170
|
+
### 画图标注
|
|
171
|
+
|
|
172
|
+
- 支持矩形、直线和自由轨迹。
|
|
173
|
+
- 矩形、直线支持实线、虚线、波浪线和 1–4px 四档线宽。
|
|
174
|
+
- 支持 TDesign 调色面板和系统预设颜色。
|
|
175
|
+
- 轨迹回到起点或与起始线段重合时自动闭合。
|
|
176
|
+
- 支持选择单条标注、删除选中、撤销、临时隐藏和清空全部。
|
|
177
|
+
- 隐藏标注只释放正文交互,不改变当前工具、选中项或标注数据。
|
|
178
|
+
|
|
179
|
+
### 标注保存与恢复
|
|
180
|
+
|
|
181
|
+
保存按钮会触发 `save-annotations` 事件,并调用 `onAnnotationsSave`。业务侧可选择事件或回调其中一种方式接入:
|
|
182
|
+
|
|
183
|
+
```vue
|
|
184
|
+
<AgilePreviewToolbar
|
|
185
|
+
ref="previewToolbarRef"
|
|
186
|
+
drawing-target=".preview-document"
|
|
187
|
+
@drawing-ready="restoreAnnotations"
|
|
188
|
+
@save-annotations="saveAnnotations"
|
|
189
|
+
/>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
组件实例提供:
|
|
193
|
+
|
|
194
|
+
| 方法 | 说明 |
|
|
195
|
+
| --- | --- |
|
|
196
|
+
| `getAnnotations()` | 获取当前标注深拷贝 |
|
|
197
|
+
| `serializeAnnotations()` | 序列化为版本化 JSON |
|
|
198
|
+
| `setAnnotations(annotations)` | 恢复或替换标注数组 |
|
|
199
|
+
| `restoreAnnotations(snapshotOrJson)` | 校验并恢复保存快照 |
|
|
200
|
+
| `clearAnnotations()` | 清空当前标注 |
|
|
201
|
+
| `saveAnnotations()` | 触发保存流程,返回 `Promise<boolean>` |
|
|
202
|
+
|
|
203
|
+
保存快照格式:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
interface PreviewAnnotationSnapshot {
|
|
207
|
+
version: 1
|
|
208
|
+
page?: {
|
|
209
|
+
width: number
|
|
210
|
+
margin: {
|
|
211
|
+
left: number
|
|
212
|
+
right: number
|
|
213
|
+
top: number
|
|
214
|
+
bottom: number
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
annotations: PreviewAnnotation[]
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
通过 `page-settings` 传入当前页面宽度和边距后,保存快照会一并记录这些信息,供业务侧按原始页面尺寸回显标注。
|
|
222
|
+
|
|
223
|
+
标注面板数量右侧提供“恢复保存时的页面设置”按钮;当前页面与快照记录不一致时会触发 `restore-annotation-page` 事件。
|
|
224
|
+
|
|
225
|
+
完整 props、事件和事件示例见 [外部组件接入](./docs/custom-components.md#独立预览工具栏)。
|
|
226
|
+
|
|
86
227
|
## 配置参数
|
|
87
228
|
|
|
88
229
|
配置优先级由高到低为:
|
|
@@ -198,6 +339,7 @@ createApp(App)
|
|
|
198
339
|
| `default` / `AgileEditor` | Vue 组件 | 编辑器主组件 |
|
|
199
340
|
| `AgileMenuButton` | Vue 组件 | 工具栏菜单按钮 |
|
|
200
341
|
| `AgileDialog` | Vue 组件 | 通用弹窗 |
|
|
342
|
+
| `AgilePreviewToolbar` | Vue 组件 | 可独立接入的预览模式工具栏 |
|
|
201
343
|
| `AgileTooltip` | Vue 组件 | 通用提示 |
|
|
202
344
|
| `useAgileEditor` | Vue 插件 | 全局注册和默认配置 |
|
|
203
345
|
| `AgileEditorOptions` | TypeScript 类型 | 编辑器配置类型 |
|