@formulaxjs/ckeditor5 0.1.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/LICENSE +35 -0
- package/README.md +249 -0
- package/README.zh-CN.md +249 -0
- package/dist/KF_AMS_BB-5QF7FUSO.woff +0 -0
- package/dist/KF_AMS_CAL-NXRNLAZN.woff +0 -0
- package/dist/KF_AMS_FRAK-CO33WWN4.woff +0 -0
- package/dist/KF_AMS_MAIN-25QJVAWY.woff +0 -0
- package/dist/KF_AMS_ROMAN-243BR7HH.woff +0 -0
- package/dist/btn-5DANP6JY.png +0 -0
- package/dist/editor-JT5KLVXX.css +3 -0
- package/dist/index.cjs +434 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.global.js +62561 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +425 -0
- package/dist/index.js.map +1 -0
- package/dist/other-OMWJFGL5.png +0 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 FormulaX Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Legacy KityFormula Code
|
|
26
|
+
|
|
27
|
+
Portions of FormulaX, specifically within the `@formulaxjs/kity-runtime` package,
|
|
28
|
+
contain code adapted from [KityFormula](https://github.com/BaiduFE/kityformula)
|
|
29
|
+
by Baidu FEX Team, originally released under the MIT License.
|
|
30
|
+
|
|
31
|
+
KityFormula-related code in FormulaX is retained under the same MIT License
|
|
32
|
+
and is subject to the copyright notice above.
|
|
33
|
+
|
|
34
|
+
For details on the original KityFormula project, see:
|
|
35
|
+
https://github.com/BaiduFE/kityformula
|
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# @formulaxjs/ckeditor5
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
CKEditor 5 integration adapter for FormulaX.
|
|
6
|
+
|
|
7
|
+
`@formulaxjs/ckeditor5` provides a CKEditor 5 plugin that opens the FormulaX editor in a modal for inserting and updating inline formulas inside CKEditor 5 content.
|
|
8
|
+
|
|
9
|
+
> Status: experimental. Public APIs may change before the first stable release.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- CKEditor 5 plugin export through `FormulaX`
|
|
14
|
+
- Toolbar button registration driven by CKEditor 5 `componentFactory`
|
|
15
|
+
- Programmatic opening through `editor.execute('formulaX')`
|
|
16
|
+
- Insert and update formulas as inline widget objects
|
|
17
|
+
- Double-click editing for existing formulas
|
|
18
|
+
- Persist only LaTeX source in the CKEditor 5 model
|
|
19
|
+
- Runtime SVG rendering in the editing view
|
|
20
|
+
- Upcast and downcast support for formula markup in editor data
|
|
21
|
+
- Direct modal helper export through `openFormulaXModal`
|
|
22
|
+
|
|
23
|
+
## Compatibility
|
|
24
|
+
|
|
25
|
+
The package declares CKEditor 5 as an optional peer dependency:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"ckeditor5": ">=42 <49"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Inside this workspace, the demo app currently uses CKEditor 5 `46.1.1`.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
When the package is published:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pnpm add @formulaxjs/ckeditor5
|
|
41
|
+
pnpm add ckeditor5
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Inside the FormulaX workspace, use the workspace package directly:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm install
|
|
48
|
+
pnpm dev:ckeditor5
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Basic usage
|
|
52
|
+
|
|
53
|
+
Add `FormulaX` to the CKEditor 5 plugin list and configure the toolbar item:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import {
|
|
57
|
+
ClassicEditor,
|
|
58
|
+
Essentials,
|
|
59
|
+
Paragraph,
|
|
60
|
+
} from 'ckeditor5';
|
|
61
|
+
import 'ckeditor5/ckeditor5.css';
|
|
62
|
+
|
|
63
|
+
import { FormulaX } from '@formulaxjs/ckeditor5';
|
|
64
|
+
|
|
65
|
+
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
66
|
+
licenseKey: 'GPL',
|
|
67
|
+
plugins: [
|
|
68
|
+
Essentials,
|
|
69
|
+
Paragraph,
|
|
70
|
+
FormulaX,
|
|
71
|
+
],
|
|
72
|
+
toolbar: ['formulaX'],
|
|
73
|
+
formulaX: {
|
|
74
|
+
toolbarText: 'FormulaX',
|
|
75
|
+
tooltip: 'Insert or edit formula',
|
|
76
|
+
modal: {
|
|
77
|
+
title: 'FormulaX Editor',
|
|
78
|
+
},
|
|
79
|
+
editor: {
|
|
80
|
+
render: {
|
|
81
|
+
fontsize: 40,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
} as any);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Then users can click the `FormulaX` toolbar button to insert a formula. Existing formulas can be updated by double-clicking them, or by selecting them and executing the same command again.
|
|
89
|
+
|
|
90
|
+
## Programmatic opening
|
|
91
|
+
|
|
92
|
+
The plugin registers a command whose name matches `buttonName`. With the default configuration:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
editor.execute('formulaX');
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Custom button names
|
|
99
|
+
|
|
100
|
+
The default toolbar button and command name is `formulaX`.
|
|
101
|
+
|
|
102
|
+
If you customize it, keep the CKEditor 5 `toolbar` configuration aligned with the custom name:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
106
|
+
plugins: [Essentials, Paragraph, FormulaX],
|
|
107
|
+
toolbar: ['myFormulaX'],
|
|
108
|
+
formulaX: {
|
|
109
|
+
buttonName: 'myFormulaX',
|
|
110
|
+
toolbarText: 'FormulaX',
|
|
111
|
+
},
|
|
112
|
+
} as any);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Programmatic opening should use the same custom command name:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
editor.execute('myFormulaX');
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Persisted data and markup
|
|
122
|
+
|
|
123
|
+
The CKEditor 5 model stores only the formula source LaTeX:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
<formulaX latex="\\sqrt{x}" />
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
When editor data is downcast to HTML, generated formula nodes are marked with `data-formulax="true"` and store the source LaTeX in `data-formulax-latex` by default:
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<span
|
|
133
|
+
class="formulax-math"
|
|
134
|
+
data-formulax="true"
|
|
135
|
+
data-formulax-latex="\\sqrt{x}"
|
|
136
|
+
data-latex="\\sqrt{x}"
|
|
137
|
+
contenteditable="false"
|
|
138
|
+
role="button"
|
|
139
|
+
style="cursor: pointer"
|
|
140
|
+
tabindex="0"
|
|
141
|
+
></span>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The editing view renders formula SVG at runtime from the persisted LaTeX. The exact rendered inner HTML is internal and may evolve. Consumers should rely on the plugin and exported options rather than hard-coding the full markup shape.
|
|
145
|
+
|
|
146
|
+
## Options
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
interface FormulaXCKEditor5Options {
|
|
150
|
+
buttonName?: string;
|
|
151
|
+
toolbarText?: string;
|
|
152
|
+
tooltip?: string;
|
|
153
|
+
cursorStyle?: string;
|
|
154
|
+
formulaClassName?: string;
|
|
155
|
+
formulaAttributeName?: string;
|
|
156
|
+
modal?: {
|
|
157
|
+
title?: string;
|
|
158
|
+
insertText?: string;
|
|
159
|
+
updateText?: string;
|
|
160
|
+
cancelText?: string;
|
|
161
|
+
closeOnBackdrop?: boolean;
|
|
162
|
+
};
|
|
163
|
+
editor?: {
|
|
164
|
+
height?: number | string;
|
|
165
|
+
autofocus?: boolean;
|
|
166
|
+
assets?: Partial<KityEditorAssets>;
|
|
167
|
+
render?: {
|
|
168
|
+
fontsize?: number;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| Option | Default | Description |
|
|
175
|
+
| --- | --- | --- |
|
|
176
|
+
| `buttonName` | `formulaX` | CKEditor 5 toolbar button name and command name. |
|
|
177
|
+
| `toolbarText` | `FormulaX` | Toolbar button label. |
|
|
178
|
+
| `tooltip` | `Insert or edit formula` | Toolbar button tooltip. |
|
|
179
|
+
| `cursorStyle` | `pointer` | Cursor style applied to generated formula nodes. |
|
|
180
|
+
| `formulaClassName` | `formulax-math` | CSS class used by generated formula nodes. |
|
|
181
|
+
| `formulaAttributeName` | `data-formulax-latex` | Attribute used to persist source LaTeX. |
|
|
182
|
+
| `modal` | see below | Modal labels and closing behavior. |
|
|
183
|
+
| `editor` | see below | Embedded FormulaX editor options. |
|
|
184
|
+
|
|
185
|
+
### Modal options
|
|
186
|
+
|
|
187
|
+
| Option | Default | Description |
|
|
188
|
+
| --- | --- | --- |
|
|
189
|
+
| `title` | `FormulaX Editor` | Modal title. |
|
|
190
|
+
| `insertText` | `Insert` | Submit button text when inserting. |
|
|
191
|
+
| `updateText` | `Update` | Submit button text when updating. |
|
|
192
|
+
| `cancelText` | `Cancel` | Cancel button text. |
|
|
193
|
+
| `closeOnBackdrop` | `true` | Whether clicking the backdrop closes the modal. |
|
|
194
|
+
|
|
195
|
+
### Editor options
|
|
196
|
+
|
|
197
|
+
| Option | Default | Description |
|
|
198
|
+
| --- | --- | --- |
|
|
199
|
+
| `height` | `100%` | Embedded editor height. |
|
|
200
|
+
| `autofocus` | `true` | Whether the embedded editor should autofocus. |
|
|
201
|
+
| `assets` | `{}` | Optional Kity runtime asset overrides. |
|
|
202
|
+
| `render.fontsize` | `40` | Formula render font size. |
|
|
203
|
+
|
|
204
|
+
## Exported API
|
|
205
|
+
|
|
206
|
+
| Export | Description |
|
|
207
|
+
| --- | --- |
|
|
208
|
+
| `FormulaX` | CKEditor 5 plugin class. |
|
|
209
|
+
| `default` | Same as `FormulaX`. |
|
|
210
|
+
| `FormulaXCommand` | Command implementation used by the plugin. |
|
|
211
|
+
| `resolveOptions` | Resolves user options into required defaults. |
|
|
212
|
+
| `openFormulaXModal` | Opens the FormulaX modal directly. |
|
|
213
|
+
| `DEFAULT_BUTTON_NAME` | Default CKEditor 5 command and toolbar button name. |
|
|
214
|
+
| `DEFAULT_FORMULA_ATTRIBUTE` | Default LaTeX persistence attribute name. |
|
|
215
|
+
| `DEFAULT_FORMULA_CLASS` | Default CSS class for formula nodes. |
|
|
216
|
+
| `FORMULA_FLAG_ATTRIBUTE` | Attribute used to identify FormulaX nodes in editor data. |
|
|
217
|
+
|
|
218
|
+
## Development
|
|
219
|
+
|
|
220
|
+
From the repository root:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pnpm install
|
|
224
|
+
pnpm dev:ckeditor5
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Build only this package:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pnpm --filter @formulaxjs/ckeditor5 build
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Run package type checking:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
pnpm --filter @formulaxjs/ckeditor5 typecheck
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Demo
|
|
240
|
+
|
|
241
|
+
Local demo:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
pnpm dev:ckeditor5
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
GitHub Pages demo:
|
|
248
|
+
|
|
249
|
+
[https://vndmea.github.io/formulaX/ckeditor5/](https://vndmea.github.io/formulaX/ckeditor5/)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# @formulaxjs/ckeditor5
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
FormulaX 的 CKEditor 5 集成适配器。
|
|
6
|
+
|
|
7
|
+
`@formulaxjs/ckeditor5` 提供了一个 CKEditor 5 插件,会以弹窗形式打开 FormulaX 编辑器,用于在 CKEditor 5 内容中插入和更新行内公式。
|
|
8
|
+
|
|
9
|
+
> 状态:实验阶段。在首个稳定版本发布前,公共 API 仍可能调整。
|
|
10
|
+
|
|
11
|
+
## 功能特性
|
|
12
|
+
|
|
13
|
+
- 通过 `FormulaX` 导出 CKEditor 5 插件
|
|
14
|
+
- 基于 CKEditor 5 `componentFactory` 注册工具栏按钮
|
|
15
|
+
- 通过 `editor.execute('formulaX')` 在代码中主动打开
|
|
16
|
+
- 将公式作为行内 widget object 插入和更新
|
|
17
|
+
- 支持双击编辑已有公式
|
|
18
|
+
- 在 CKEditor 5 model 中仅持久化 LaTeX 源内容
|
|
19
|
+
- 在 editing view 中运行时渲染 SVG
|
|
20
|
+
- 支持在编辑器数据中对公式 markup 进行 upcast 和 downcast
|
|
21
|
+
- 直接导出弹窗工具函数 `openFormulaXModal`
|
|
22
|
+
|
|
23
|
+
## 兼容性
|
|
24
|
+
|
|
25
|
+
该包将 CKEditor 5 声明为可选 peer dependency:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"ckeditor5": ">=42 <49"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
当前工作空间中的 demo 使用的是 CKEditor 5 `46.1.1`。
|
|
34
|
+
|
|
35
|
+
## 安装
|
|
36
|
+
|
|
37
|
+
包发布后可使用:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pnpm add @formulaxjs/ckeditor5
|
|
41
|
+
pnpm add ckeditor5
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
在 FormulaX 工作空间内,直接使用 workspace 包:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm install
|
|
48
|
+
pnpm dev:ckeditor5
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 基础使用
|
|
52
|
+
|
|
53
|
+
将 `FormulaX` 加入 CKEditor 5 的插件列表,并配置对应的工具栏项:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import {
|
|
57
|
+
ClassicEditor,
|
|
58
|
+
Essentials,
|
|
59
|
+
Paragraph,
|
|
60
|
+
} from 'ckeditor5';
|
|
61
|
+
import 'ckeditor5/ckeditor5.css';
|
|
62
|
+
|
|
63
|
+
import { FormulaX } from '@formulaxjs/ckeditor5';
|
|
64
|
+
|
|
65
|
+
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
66
|
+
licenseKey: 'GPL',
|
|
67
|
+
plugins: [
|
|
68
|
+
Essentials,
|
|
69
|
+
Paragraph,
|
|
70
|
+
FormulaX,
|
|
71
|
+
],
|
|
72
|
+
toolbar: ['formulaX'],
|
|
73
|
+
formulaX: {
|
|
74
|
+
toolbarText: 'FormulaX',
|
|
75
|
+
tooltip: '插入或编辑公式',
|
|
76
|
+
modal: {
|
|
77
|
+
title: 'FormulaX 公式编辑器',
|
|
78
|
+
},
|
|
79
|
+
editor: {
|
|
80
|
+
render: {
|
|
81
|
+
fontsize: 40,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
} as any);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
之后用户可以点击 `FormulaX` 工具栏按钮插入公式。已有公式可以通过双击更新,也可以先选中后再次执行同一个命令进行更新。
|
|
89
|
+
|
|
90
|
+
## 代码中主动打开
|
|
91
|
+
|
|
92
|
+
插件注册的命令名与 `buttonName` 保持一致。默认配置下可直接调用:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
editor.execute('formulaX');
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 自定义按钮名称
|
|
99
|
+
|
|
100
|
+
默认的工具栏按钮名和命令名都是 `formulaX`。
|
|
101
|
+
|
|
102
|
+
如果自定义它,需要确保 CKEditor 5 的 `toolbar` 配置与自定义名称保持一致:
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
106
|
+
plugins: [Essentials, Paragraph, FormulaX],
|
|
107
|
+
toolbar: ['myFormulaX'],
|
|
108
|
+
formulaX: {
|
|
109
|
+
buttonName: 'myFormulaX',
|
|
110
|
+
toolbarText: 'FormulaX',
|
|
111
|
+
},
|
|
112
|
+
} as any);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
代码中主动打开时,也要使用同一个自定义命令名:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
editor.execute('myFormulaX');
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 持久化数据与 markup
|
|
122
|
+
|
|
123
|
+
CKEditor 5 的 model 层只保存公式的 LaTeX 源内容:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
<formulaX latex="\\sqrt{x}" />
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
当编辑器数据 downcast 为 HTML 时,生成的公式节点默认会通过 `data-formulax="true"` 标记,并将 LaTeX 源内容保存在 `data-formulax-latex` 中:
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<span
|
|
133
|
+
class="formulax-math"
|
|
134
|
+
data-formulax="true"
|
|
135
|
+
data-formulax-latex="\\sqrt{x}"
|
|
136
|
+
data-latex="\\sqrt{x}"
|
|
137
|
+
contenteditable="false"
|
|
138
|
+
role="button"
|
|
139
|
+
style="cursor: pointer"
|
|
140
|
+
tabindex="0"
|
|
141
|
+
></span>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
编辑态中的 SVG 由持久化的 LaTeX 在运行时生成。用于渲染公式的内部 HTML 结构属于实现细节,后续可能演进。业务侧应优先依赖插件能力和导出的配置项,而不是写死完整 markup 结构。
|
|
145
|
+
|
|
146
|
+
## 配置项
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
interface FormulaXCKEditor5Options {
|
|
150
|
+
buttonName?: string;
|
|
151
|
+
toolbarText?: string;
|
|
152
|
+
tooltip?: string;
|
|
153
|
+
cursorStyle?: string;
|
|
154
|
+
formulaClassName?: string;
|
|
155
|
+
formulaAttributeName?: string;
|
|
156
|
+
modal?: {
|
|
157
|
+
title?: string;
|
|
158
|
+
insertText?: string;
|
|
159
|
+
updateText?: string;
|
|
160
|
+
cancelText?: string;
|
|
161
|
+
closeOnBackdrop?: boolean;
|
|
162
|
+
};
|
|
163
|
+
editor?: {
|
|
164
|
+
height?: number | string;
|
|
165
|
+
autofocus?: boolean;
|
|
166
|
+
assets?: Partial<KityEditorAssets>;
|
|
167
|
+
render?: {
|
|
168
|
+
fontsize?: number;
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| 配置项 | 默认值 | 说明 |
|
|
175
|
+
| --- | --- | --- |
|
|
176
|
+
| `buttonName` | `formulaX` | CKEditor 5 的工具栏按钮名,同时也是命令名。 |
|
|
177
|
+
| `toolbarText` | `FormulaX` | 工具栏按钮显示文本。 |
|
|
178
|
+
| `tooltip` | `Insert or edit formula` | 工具栏按钮 tooltip。 |
|
|
179
|
+
| `cursorStyle` | `pointer` | 应用于生成公式节点的鼠标光标样式。 |
|
|
180
|
+
| `formulaClassName` | `formulax-math` | 生成的公式节点 CSS class。 |
|
|
181
|
+
| `formulaAttributeName` | `data-formulax-latex` | 用于保存 LaTeX 源内容的属性。 |
|
|
182
|
+
| `modal` | 见下方 | 弹窗文案和关闭行为。 |
|
|
183
|
+
| `editor` | 见下方 | 内嵌 FormulaX 编辑器配置。 |
|
|
184
|
+
|
|
185
|
+
### Modal 配置
|
|
186
|
+
|
|
187
|
+
| 配置项 | 默认值 | 说明 |
|
|
188
|
+
| --- | --- | --- |
|
|
189
|
+
| `title` | `FormulaX Editor` | 弹窗标题。 |
|
|
190
|
+
| `insertText` | `Insert` | 插入公式时的提交按钮文本。 |
|
|
191
|
+
| `updateText` | `Update` | 更新公式时的提交按钮文本。 |
|
|
192
|
+
| `cancelText` | `Cancel` | 取消按钮文本。 |
|
|
193
|
+
| `closeOnBackdrop` | `true` | 点击遮罩层时是否关闭弹窗。 |
|
|
194
|
+
|
|
195
|
+
### Editor 配置
|
|
196
|
+
|
|
197
|
+
| 配置项 | 默认值 | 说明 |
|
|
198
|
+
| --- | --- | --- |
|
|
199
|
+
| `height` | `100%` | 内嵌编辑器高度。 |
|
|
200
|
+
| `autofocus` | `true` | 内嵌编辑器是否自动聚焦。 |
|
|
201
|
+
| `assets` | `{}` | 可选的 Kity runtime 资源覆盖配置。 |
|
|
202
|
+
| `render.fontsize` | `40` | 公式渲染字号。 |
|
|
203
|
+
|
|
204
|
+
## 导出 API
|
|
205
|
+
|
|
206
|
+
| 导出 | 说明 |
|
|
207
|
+
| --- | --- |
|
|
208
|
+
| `FormulaX` | CKEditor 5 插件类。 |
|
|
209
|
+
| `default` | 与 `FormulaX` 相同。 |
|
|
210
|
+
| `FormulaXCommand` | 插件内部使用的命令实现。 |
|
|
211
|
+
| `resolveOptions` | 将用户配置与默认配置合并为完整配置。 |
|
|
212
|
+
| `openFormulaXModal` | 直接打开 FormulaX 弹窗。 |
|
|
213
|
+
| `DEFAULT_BUTTON_NAME` | 默认的 CKEditor 5 命令名和工具栏按钮名。 |
|
|
214
|
+
| `DEFAULT_FORMULA_ATTRIBUTE` | 默认的 LaTeX 持久化属性名。 |
|
|
215
|
+
| `DEFAULT_FORMULA_CLASS` | 默认的公式节点 CSS class。 |
|
|
216
|
+
| `FORMULA_FLAG_ATTRIBUTE` | 用于在编辑器数据中识别 FormulaX 节点的属性。 |
|
|
217
|
+
|
|
218
|
+
## 开发
|
|
219
|
+
|
|
220
|
+
在仓库根目录执行:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pnpm install
|
|
224
|
+
pnpm dev:ckeditor5
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
仅构建该包:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pnpm --filter @formulaxjs/ckeditor5 build
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
运行该包类型检查:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
pnpm --filter @formulaxjs/ckeditor5 typecheck
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Demo
|
|
240
|
+
|
|
241
|
+
本地 demo:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
pnpm dev:ckeditor5
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
GitHub Pages demo:
|
|
248
|
+
|
|
249
|
+
[https://vndmea.github.io/formulaX/ckeditor5/](https://vndmea.github.io/formulaX/ckeditor5/)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|