@agilehub/agile-editor 1.6.0 → 1.8.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 +1 -0
- package/dist/agile-editor.css +1 -1
- package/dist/agile-editor.js +18325 -18426
- package/dist/i18n-DCR9QpaV.js +2785 -0
- package/dist/types/components/editor/index.vue.d.ts +2 -2
- package/dist/types/components/editor/smart-sheet-dialog.vue.d.ts +3 -0
- package/dist/types/components/index.d.ts +2 -1
- package/dist/types/components/index.vue.d.ts +384 -22
- package/dist/types/components/menus/button.vue.d.ts +1 -1
- package/dist/types/components/menus/toolbar/insert/bookmark.vue.d.ts +24 -0
- package/dist/types/components/menus/toolbar/insert/courseware.vue.d.ts +3 -0
- package/dist/types/components/menus/toolbar/insert/smart-sheet.vue.d.ts +3 -0
- package/dist/types/components/preview-toolbar/index.vue.d.ts +2 -2
- package/dist/types/components/toolbar/classic.vue.d.ts +19 -11
- package/dist/types/components/toolbar/ribbon.vue.d.ts +19 -11
- package/dist/types/composables/i18n.d.ts +375 -18
- package/dist/types/extensions/bookmark-transaction.d.ts +4 -0
- package/dist/types/extensions/bookmark.d.ts +8 -5
- package/dist/types/extensions/bubble-note.d.ts +1 -0
- package/dist/types/extensions/courseware/annotation-session.d.ts +4 -0
- package/dist/types/extensions/courseware/index.d.ts +49 -0
- package/dist/types/extensions/courseware/model.d.ts +20 -0
- package/dist/types/extensions/courseware/node-view.vue.d.ts +93 -0
- package/dist/types/extensions/courseware/reader.vue.d.ts +22 -0
- package/dist/types/extensions/smart-sheet/index.d.ts +47 -0
- package/dist/types/extensions/smart-sheet/model.d.ts +18 -0
- package/dist/types/extensions/smart-sheet/node-view.vue.d.ts +93 -0
- package/dist/types/extensions/smart-sheet/viewer.vue.d.ts +36 -0
- package/dist/types/i18n.d.ts +375 -18
- package/dist/types/options/config/index.d.ts +2 -0
- package/dist/types/utils/bubble-note-icon.d.ts +1 -0
- package/dist/types/utils/document-formatting.d.ts +41 -37
- package/dist/types/utils/document-import.d.ts +2 -0
- package/dist/types/utils/html-element-id.d.ts +9 -2
- package/dist/types/utils/md5.d.ts +2 -0
- package/dist/viewer-CyuLA7YS.js +97 -0
- package/docs/FORMATTING_TEMPLATES.md +253 -250
- package/docs/FORMATTING_TEMPLATE_BUSINESS_GUIDE.md +536 -0
- package/docs/README.md +1 -0
- package/docs/SECONDARY_DEVELOPMENT.md +1 -1
- package/docs/api.md +43 -0
- package/docs/configuration.md +82 -0
- package/docs/custom-components.md +1 -1
- package/docs/development.md +6 -2
- package/docs/menu-extension.md +26 -1
- package/package.json +165 -153
- /package/dist/types/components/{menus/toolbar/view/preview.vue.d.ts → editor/courseware-dialog.vue.d.ts} +0 -0
|
@@ -1,250 +1,253 @@
|
|
|
1
|
-
# 一键排版模板 JSON 与扩展指南
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
131
|
-
| `
|
|
132
|
-
| `
|
|
133
|
-
| `
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
|
142
|
-
|
|
|
143
|
-
| `
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
`
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
1
|
+
# 一键排版模板 JSON 与扩展指南
|
|
2
|
+
|
|
3
|
+
一键排版从外部传入模板数组。用户选择模板后,编辑器只修改模板中**明确声明**的版式,不修改正文文字、链接、图片资源、音视频地址或表格内容。仓库的[示例模板](../dev/formatting-templates.json)用于开发调试,不会自动成为库使用方的模板。
|
|
4
|
+
|
|
5
|
+
面向业务编辑的版式确认、参数说明和验收清单见[一键排版模板业务沟通指南](./FORMATTING_TEMPLATE_BUSINESS_GUIDE.md)。
|
|
6
|
+
|
|
7
|
+
## 1. 模板结构与接入
|
|
8
|
+
|
|
9
|
+
模板文件根节点是数组。每个模板必须包含 `id`、`name`、`description`、`rules` 四个字段;没有说明文字时,`description` 也要写为 `""`。
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
[
|
|
13
|
+
{
|
|
14
|
+
"id": "my-document",
|
|
15
|
+
"name": "我的版式",
|
|
16
|
+
"description": "设置正文和一级标题",
|
|
17
|
+
"rules": {
|
|
18
|
+
"p": {
|
|
19
|
+
"fontFamily": "SimSun, serif",
|
|
20
|
+
"fontSize": "16px",
|
|
21
|
+
"lineHeight": 1.75,
|
|
22
|
+
"textIndent": "2em",
|
|
23
|
+
"span": { "fontFamily": "SimSun, serif" },
|
|
24
|
+
"a": { "fontFamily": "SimSun, serif" },
|
|
25
|
+
"strong": { "fontFamily": "SimSun, serif" }
|
|
26
|
+
},
|
|
27
|
+
"h1": {
|
|
28
|
+
"fontSize": "28px",
|
|
29
|
+
"textAlign": "center"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
在 Vue 组件中通过 `formatting` 参数传入。`FormattingOptions`、`FormattingTemplate`、`FormattingStyle` 等类型从包入口导出。
|
|
37
|
+
|
|
38
|
+
```vue
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import { AgileEditor, type FormattingOptions } from '@agilehub/agile-editor'
|
|
41
|
+
import templates from './formatting-templates.json'
|
|
42
|
+
|
|
43
|
+
const formatting: FormattingOptions = {
|
|
44
|
+
enabled: true,
|
|
45
|
+
defaultTemplateId: 'my-document',
|
|
46
|
+
templates,
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<AgileEditor :formatting="formatting" />
|
|
52
|
+
</template>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
也可在 `app.use(useAgileEditor, { formatting })` 中提供全局配置。组件上的同名配置优先;`templates` 数组整体替换,不与全局数组拼接。接口异步返回模板时,更新响应式 `formatting` 参数即可;仅更新模板不会自动修改文档。
|
|
56
|
+
|
|
57
|
+
### `FormattingOptions` 字段
|
|
58
|
+
|
|
59
|
+
| 字段 | TypeScript 类型 | 说明 |
|
|
60
|
+
| ------------------- | --------------------------------------------- | ----------------------------------------------------------------------------- |
|
|
61
|
+
| `enabled` | `boolean`,可选 | 为 `false` 时隐藏一键排版入口;省略时显示。 |
|
|
62
|
+
| `defaultTemplateId` | `string`,可选 | 首次打开弹窗时优先选中的模板 `id`;找不到时选第一项。 |
|
|
63
|
+
| `templates` | `FormattingTemplate[]`,可选 | 可选模板数组;省略或为空时显示空状态。 |
|
|
64
|
+
|
|
65
|
+
## 2. 规则树与作用域语义
|
|
66
|
+
|
|
67
|
+
新模板的 `rules` 是一棵与 HTML 文档结构对应的元素树。`key` 使用 HTML 元素名,属性使用 camelCase 的 CSS 名称,例如 `fontFamily`、`lineHeight`、`textIndent`。
|
|
68
|
+
|
|
69
|
+
- **最外层 key 只描述对应位置上的元素**。例如 `rules.p` 只处理直接位于文档根节点下的普通段落,不处理表格、图注、列表、引用或自定义容器内部的段落。
|
|
70
|
+
- **嵌套 key 限定路径**。例如 `rules.table.caption.p` 只处理表格标题中的段落,`rules.figure.figcaption.p` 只处理图片图注中的段落。
|
|
71
|
+
- **行内 key 区分文字类型**。`span` 作用于普通行内文字,`a` 作用于已有链接文字,`strong` 作用于已有加粗文字;它们可以继续出现在 `p`、标题、表题、表头、单元格、图注和列表项中。
|
|
72
|
+
- **未声明的元素保持原样**。没有某个元素 key,就不格式化该元素;某个样式属性没有写,就不主动改写该属性。
|
|
73
|
+
- **`null` 表示清除**该属性已有的显式设置;要表示“保持原样”时省略属性即可。
|
|
74
|
+
|
|
75
|
+
模板只接受 HTML 语义字段。正文使用 `p`,表头和单元格分别使用 `th`、`td`;旧版的 `rules.paragraph`、`rules.table.cell`、`rules.heading`、`rules.contexts`、`rules.nodes` 和 `rules.image` 已移除。
|
|
76
|
+
|
|
77
|
+
示例:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"rules": {
|
|
82
|
+
"p": {
|
|
83
|
+
"fontSize": "18px",
|
|
84
|
+
"textIndent": "2em",
|
|
85
|
+
"span": { "fontFamily": "SimSun, serif" },
|
|
86
|
+
"a": { "color": "#1f4e79" },
|
|
87
|
+
"strong": { "fontWeight": "bold" }
|
|
88
|
+
},
|
|
89
|
+
"table": {
|
|
90
|
+
"th": {
|
|
91
|
+
"p": { "fontSize": "14px", "textIndent": "0" }
|
|
92
|
+
},
|
|
93
|
+
"td": {
|
|
94
|
+
"p": { "fontSize": "14px", "textIndent": "0" }
|
|
95
|
+
},
|
|
96
|
+
"caption": {
|
|
97
|
+
"p": { "fontSize": "14px", "textAlign": "center" }
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"figure": {
|
|
101
|
+
"figcaption": {
|
|
102
|
+
"p": { "fontSize": "14px", "textAlign": "center" }
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
上例中,顶层正文和表格、图注分别使用不同规则;顶层段落样式不会泄漏到表格或图注内。
|
|
110
|
+
|
|
111
|
+
## 3. 支持的元素
|
|
112
|
+
|
|
113
|
+
所有 `rules` 子项都可选。
|
|
114
|
+
|
|
115
|
+
| JSON 路径 | 值类型 | 作用范围 |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| `rules.p` | 元素规则 | 根节点下的普通段落;可包含 `span`、`a`、`strong` |
|
|
118
|
+
| `rules.h1` ~ `rules.h6` | 元素规则 | 对应级别标题;可包含 `p`、`span`、`a`、`strong` |
|
|
119
|
+
| `rules.table` | 表格规则 | 表格容器及其专用字段,见第 5 节 |
|
|
120
|
+
| `rules.table.caption` | 元素规则 | 表格标题;可包含 `p`、`span`、`a`、`strong` |
|
|
121
|
+
| `rules.table.th` | 元素规则 | 表头单元格;可包含 `p`、`span`、`a`、`strong` |
|
|
122
|
+
| `rules.table.td` | 元素规则 | 普通单元格;可包含 `p`、`span`、`a`、`strong` |
|
|
123
|
+
| `rules.figure` | 元素规则 | 图片外层 figure 容器 |
|
|
124
|
+
| `rules.figure.img` | 元素规则 | figure 内嵌图片 |
|
|
125
|
+
| `rules.figure.figcaption` | 元素规则 | 图注;可包含 `p`、`span`、`a`、`strong` |
|
|
126
|
+
| `rules.img` | 元素规则 | 行内图片 |
|
|
127
|
+
| `rules.audio` | 样式对象 | 音频播放器外层 |
|
|
128
|
+
| `rules.video` | 样式对象 | 视频播放器外层 |
|
|
129
|
+
| `rules.ol`、`rules.ul` | 列表规则 | 有序/无序列表,可包含 `li` |
|
|
130
|
+
| `rules.ol.li`、`rules.ul.li` | 元素规则 | 列表项;可包含 `p`、`span`、`a`、`strong` |
|
|
131
|
+
| `rules.li` | 元素规则 | 无列表类型上下文时的兼容列表项规则 |
|
|
132
|
+
| `rules.codeBlock` | 元素规则 | 代码块外层;可包含 `span`、`a`、`strong` |
|
|
133
|
+
| `rules.blockquote` | 元素规则 | 引用块外层;可包含 `p`、`span`、`a`、`strong` |
|
|
134
|
+
| `rules.taskItem` | 元素规则 | 任务列表项;可包含 `p`、`span`、`a`、`strong` |
|
|
135
|
+
| `rules.footnote` | 元素规则 | 脚注项;可包含 `p`、`span`、`a`、`strong` |
|
|
136
|
+
|
|
137
|
+
### 3.1 行内元素 `span`、`a`、`strong`
|
|
138
|
+
|
|
139
|
+
| 行内 key | 作用对象 | 是否创建新标记 |
|
|
140
|
+
| --- | --- | --- |
|
|
141
|
+
| `span` | 普通行内文字 | 否,只增加或更新行内样式 |
|
|
142
|
+
| `a` | 已有链接文字 | 否,保留原链接地址和链接标记 |
|
|
143
|
+
| `strong` | 已有加粗文字 | 否,保留原加粗标记 |
|
|
144
|
+
|
|
145
|
+
`span`、`a`、`strong` 是同级选择器。普通文字使用 `span`,链接文字使用 `a`,加粗文字使用 `strong`。链接中的加粗文字可以同时命中 `a` 和 `strong`;模板不会因为写了 `strong` 就把整段文字变粗,也不会因为写了 `a` 就创建新链接。
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"p": {
|
|
150
|
+
"span": { "fontFamily": "SimSun, serif", "fontSize": "18px" },
|
|
151
|
+
"a": { "fontFamily": "SimSun, serif", "fontSize": "18px", "color": "#1f4e79" },
|
|
152
|
+
"strong": { "fontFamily": "SimSun, serif", "fontSize": "18px" }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
由于编辑器 schema 中 `tableCaption` 是 `inline*`、图片节点也以 `inline*` 保存图注,模板中的 `caption.p` 和 `figcaption.p` 会折叠到对应标题/图注容器自身,`span`、`a`、`strong` 会折叠到其直属文字。这样 JSON 仍可表达 HTML 里 `caption > p > span/a/strong` 或 `figcaption > p > span/a/strong` 的意图,同时避免顶层段落规则泄漏。
|
|
158
|
+
|
|
159
|
+
## 4. 通用样式 `FormattingStyle`
|
|
160
|
+
|
|
161
|
+
每个属性类型为 `string | number | null`。字符串或数字必须是目标 CSS 属性可接受的值;`null` 表示清除已有显式设置,回到继承样式或编辑器默认值。字段名区分大小写,不能写 CSS 的连字符形式。
|
|
162
|
+
|
|
163
|
+
| 属性 | 含义 | 示例 |
|
|
164
|
+
| --- | --- | --- |
|
|
165
|
+
| `fontFamily` | 字体族及回退字体 | `"FangSong, serif"` |
|
|
166
|
+
| `fontSize` | 字号 | `"16px"`、`"16pt"` |
|
|
167
|
+
| `fontWeight` | 字重 | `"normal"`、`"bold"`、`600` |
|
|
168
|
+
| `fontStyle` | 字体样式 | `"normal"`、`"italic"` |
|
|
169
|
+
| `color` | 文字颜色 | `"#222222"` |
|
|
170
|
+
| `backgroundColor` | 背景颜色 | `"#fff4cc"` |
|
|
171
|
+
| `letterSpacing` | 字间距 | `"0.5px"` |
|
|
172
|
+
| `lineHeight` | 行高 | `1.75`、`"28pt"` |
|
|
173
|
+
| `textAlign` | 文本水平对齐 | `"left"`、`"center"`、`"right"`、`"justify"` |
|
|
174
|
+
| `textIndent` | 首行缩进 | `"2em"`、`"0"` |
|
|
175
|
+
| `textDecoration` | 文本装饰 | `"underline"`、`"none"` |
|
|
176
|
+
| `marginTop` | 上外边距或段前间距 | `"12px"` |
|
|
177
|
+
| `marginBottom` | 下外边距或段后间距 | `"8px"` |
|
|
178
|
+
| `marginLeft` | 左外边距 | `"0"` |
|
|
179
|
+
| `marginRight` | 右外边距 | `"0"` |
|
|
180
|
+
| `paddingTop` / `paddingRight` / `paddingBottom` / `paddingLeft` | 内边距 | `"8px"` |
|
|
181
|
+
| `border` / `borderColor` / `borderWidth` / `borderStyle` | 边框样式 | `"1px solid #cccccc"` |
|
|
182
|
+
| `borderRadius` | 圆角半径 | `"4px"` |
|
|
183
|
+
| `width` / `maxWidth` / `minHeight` | 容器尺寸 | `"400px"`、`"100%"` |
|
|
184
|
+
| `verticalAlign` | 垂直对齐 | `"middle"` |
|
|
185
|
+
|
|
186
|
+
校验禁止分号、花括号、尖括号、`url(...)`、`expression(...)` 和 `!important`;在浏览器中还会用 `CSS.supports` 验证 CSS 属性值。
|
|
187
|
+
|
|
188
|
+
## 5. 表格专用字段
|
|
189
|
+
|
|
190
|
+
`rules.table` 除通用样式外还接受以下兼容字段。新模板使用 `th`、`td` 和 `caption` 的元素路径;这些字段仍可用于已有模板。
|
|
191
|
+
|
|
192
|
+
| 字段 | 类型 | 说明 |
|
|
193
|
+
| --- | --- | --- |
|
|
194
|
+
| `preset` | 枚举字符串,可选 | 将已有表格设置为指定预设样式 |
|
|
195
|
+
| `themeColor` | `string`,可选 | 六位十六进制颜色,用于表格预设主题 |
|
|
196
|
+
| `shading` | `string[]`,可选 | 底纹填充位置;`[]` 表示取消预设底纹,省略表示不改原有底纹 |
|
|
197
|
+
| `cellText` | `FormattingStyle`,可选 | 旧版单元格段落样式,优先级低于 `th.p` / `td.p` |
|
|
198
|
+
| `caption` | 元素或样式规则,可选 | 表格标题;推荐写为 `caption.p` |
|
|
199
|
+
|
|
200
|
+
`preset` 取值:`plain`、`horizontal`、`header-line`、`double-line`、`vertical`、`grid`、`outline`、`header-grid`、`banded`、`bold-grid`、`columns`、`three-line`。
|
|
201
|
+
|
|
202
|
+
`shading` 可包含 `first-row`、`first-column`、`alternate-row`、`alternate-column`、`last-row`、`last-column`。设置 `preset` 会清除与预设冲突的旧边框和单元格底色覆盖;合并关系、行高、列宽及标题内容保留。
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"table": {
|
|
207
|
+
"maxWidth": "100%",
|
|
208
|
+
"preset": "three-line",
|
|
209
|
+
"themeColor": "#4472c4",
|
|
210
|
+
"shading": ["first-row", "alternate-row"],
|
|
211
|
+
"caption": {
|
|
212
|
+
"p": { "fontSize": "14px", "textAlign": "center" }
|
|
213
|
+
},
|
|
214
|
+
"th": {
|
|
215
|
+
"p": { "fontSize": "14px", "textIndent": "0" }
|
|
216
|
+
},
|
|
217
|
+
"td": {
|
|
218
|
+
"p": { "fontSize": "14px", "textIndent": "0" }
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
`table.maxWidth` 作用于表格本身,会与列宽、最小宽度同时保留;已有表格的内联宽度也会被模板中的显式 `maxWidth` 覆盖。
|
|
225
|
+
|
|
226
|
+
## 6. 图片与媒体
|
|
227
|
+
|
|
228
|
+
图片块使用 `figure`、`figure.img` 和 `figure.figcaption`;行内图片使用 `img`。图片地址、裁剪、旋转和原有媒体数据不因排版而替换。
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"figure": {
|
|
233
|
+
"textAlign": "center",
|
|
234
|
+
"img": { "maxWidth": "100%" },
|
|
235
|
+
"figcaption": {
|
|
236
|
+
"p": { "fontSize": "14px", "textAlign": "center" }
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
"img": { "maxWidth": "100%" },
|
|
240
|
+
"audio": { "maxWidth": "100%", "marginTop": "12px" },
|
|
241
|
+
"video": { "maxWidth": "100%", "marginBottom": "12px" }
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## 7. 校验、应用与排查
|
|
246
|
+
|
|
247
|
+
点击“一键排版”时校验整份 `formatting` 配置及所有模板;应用前再次校验。错误会在弹窗内显示具体字段路径,且禁用应用按钮。例如把 `fontSize` 误写为 `fontSze` 时会看到:
|
|
248
|
+
|
|
249
|
+
```text
|
|
250
|
+
模板数据不正确: formatting.templates[0].rules.p.fontSze: unknown style field
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
排版是一次可撤销的编辑操作;再次应用相同模板且文档已符合规则时,不增加无效撤销记录。编辑器在分析大文档时会分批让出主线程;分析期间若文档变化、进入只读或关闭弹窗,将取消本次操作。页面尺寸、页边距、水印、精确分页、标题序号和公文版心不属于模板规则,需要分别处理。开发回归页为 `/editor-demo/checks/document-formatting.html`。
|