@formulaxjs/ckeditor5 0.3.0 → 0.3.1
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 +283 -284
- package/README.zh-CN.md +50 -51
- package/dist/index.global.js +178 -40
- package/dist/index.global.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,284 +1,283 @@
|
|
|
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
|
-
- Default read-only rendering through `@formulaxjs/renderer-kity`
|
|
21
|
-
- Optional runtime preload before the first modal open
|
|
22
|
-
- Upcast and downcast support for formula markup in editor data
|
|
23
|
-
- Direct modal helper export through `openFormulaXModal`
|
|
24
|
-
|
|
25
|
-
## Compatibility
|
|
26
|
-
|
|
27
|
-
The package declares CKEditor 5 as an optional peer dependency:
|
|
28
|
-
|
|
29
|
-
```json
|
|
30
|
-
{
|
|
31
|
-
"ckeditor5": ">=42 <49"
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Inside this workspace, the demo app currently uses CKEditor 5 `46.1.1`.
|
|
36
|
-
|
|
37
|
-
## Install
|
|
38
|
-
|
|
39
|
-
When the package is published:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
pnpm
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
import {
|
|
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
|
-
data-formulax="
|
|
159
|
-
data-
|
|
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
|
-
| `
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
pnpm
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
[https://vndmea.github.io/formulaX/ckeditor5/](https://vndmea.github.io/formulaX/ckeditor5/)
|
|
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
|
+
- Default read-only rendering through `@formulaxjs/renderer-kity`
|
|
21
|
+
- Optional runtime preload before the first modal open
|
|
22
|
+
- Upcast and downcast support for formula markup in editor data
|
|
23
|
+
- Direct modal helper export through `openFormulaXModal`
|
|
24
|
+
|
|
25
|
+
## Compatibility
|
|
26
|
+
|
|
27
|
+
The package declares CKEditor 5 as an optional peer dependency:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"ckeditor5": ">=42 <49"
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Inside this workspace, the demo app currently uses CKEditor 5 `46.1.1`.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
When the package is published:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @formulaxjs/ckeditor5 ckeditor5
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Inside the FormulaX workspace, use the workspace package directly:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm install
|
|
49
|
+
pnpm dev:ckeditor5
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Basic usage
|
|
53
|
+
|
|
54
|
+
Add `FormulaX` to the CKEditor 5 plugin list and configure the toolbar item:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import {
|
|
58
|
+
ClassicEditor,
|
|
59
|
+
Essentials,
|
|
60
|
+
Paragraph,
|
|
61
|
+
} from 'ckeditor5';
|
|
62
|
+
import 'ckeditor5/ckeditor5.css';
|
|
63
|
+
|
|
64
|
+
import { FormulaX } from '@formulaxjs/ckeditor5';
|
|
65
|
+
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
66
|
+
|
|
67
|
+
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
68
|
+
licenseKey: 'GPL',
|
|
69
|
+
plugins: [
|
|
70
|
+
Essentials,
|
|
71
|
+
Paragraph,
|
|
72
|
+
FormulaX,
|
|
73
|
+
],
|
|
74
|
+
toolbar: ['formulaX'],
|
|
75
|
+
formulaX: {
|
|
76
|
+
toolbarText: 'FormulaX',
|
|
77
|
+
tooltip: 'Insert or edit formula',
|
|
78
|
+
modal: {
|
|
79
|
+
title: 'FormulaX Editor',
|
|
80
|
+
},
|
|
81
|
+
renderer: createKityFormulaRenderer({
|
|
82
|
+
fontSize: 40,
|
|
83
|
+
}),
|
|
84
|
+
editor: {
|
|
85
|
+
render: {
|
|
86
|
+
fontsize: 40,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
} as any);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
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.
|
|
94
|
+
|
|
95
|
+
## Custom model names
|
|
96
|
+
|
|
97
|
+
The default CKEditor 5 model name is `formulaX`.
|
|
98
|
+
|
|
99
|
+
If the host editor already uses that model name, pass a custom `name` in the `formulaX` config:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
103
|
+
plugins: [Essentials, Paragraph, FormulaX],
|
|
104
|
+
toolbar: ['formulaX'],
|
|
105
|
+
formulaX: {
|
|
106
|
+
name: 'inlineMath',
|
|
107
|
+
},
|
|
108
|
+
} as any);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
If CKEditor 5 detects that the configured model name is already registered, the plugin logs a `console.error` and skips registration so the editor does not silently create a conflicting schema definition.
|
|
112
|
+
|
|
113
|
+
## Programmatic opening
|
|
114
|
+
|
|
115
|
+
The plugin registers a command whose name matches `buttonName`. With the default configuration:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
editor.execute('formulaX');
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Custom button names
|
|
122
|
+
|
|
123
|
+
The default toolbar button and command name is `formulaX`.
|
|
124
|
+
|
|
125
|
+
If you customize it, keep the CKEditor 5 `toolbar` configuration aligned with the custom name:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
129
|
+
plugins: [Essentials, Paragraph, FormulaX],
|
|
130
|
+
toolbar: ['myFormulaX'],
|
|
131
|
+
formulaX: {
|
|
132
|
+
buttonName: 'myFormulaX',
|
|
133
|
+
toolbarText: 'FormulaX',
|
|
134
|
+
},
|
|
135
|
+
} as any);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Programmatic opening should use the same custom command name:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
editor.execute('myFormulaX');
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Persisted data and markup
|
|
145
|
+
|
|
146
|
+
The CKEditor 5 model stores only the formula source LaTeX:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
<formulaX latex="\\sqrt{x}" />
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
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:
|
|
153
|
+
|
|
154
|
+
```html
|
|
155
|
+
<span
|
|
156
|
+
class="formulax-math"
|
|
157
|
+
data-formulax="true"
|
|
158
|
+
data-formulax-latex="\\sqrt{x}"
|
|
159
|
+
data-latex="\\sqrt{x}"
|
|
160
|
+
contenteditable="false"
|
|
161
|
+
role="button"
|
|
162
|
+
style="cursor: pointer"
|
|
163
|
+
tabindex="0"
|
|
164
|
+
></span>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
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.
|
|
168
|
+
|
|
169
|
+
## Custom renderer
|
|
170
|
+
|
|
171
|
+
The adapter accepts a `renderer` option. By default it uses `createKityFormulaRenderer()` from `@formulaxjs/renderer-kity`.
|
|
172
|
+
|
|
173
|
+
## Options
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
interface FormulaXCKEditor5Options {
|
|
177
|
+
name?: string;
|
|
178
|
+
buttonName?: string;
|
|
179
|
+
toolbarText?: string;
|
|
180
|
+
tooltip?: string;
|
|
181
|
+
cursorStyle?: string;
|
|
182
|
+
formulaClassName?: string;
|
|
183
|
+
formulaAttributeName?: string;
|
|
184
|
+
renderer?: FormulaRenderer;
|
|
185
|
+
preload?: FormulaXEditorPreloadMode;
|
|
186
|
+
modal?: {
|
|
187
|
+
title?: string;
|
|
188
|
+
insertText?: string;
|
|
189
|
+
updateText?: string;
|
|
190
|
+
cancelText?: string;
|
|
191
|
+
closeOnBackdrop?: boolean;
|
|
192
|
+
};
|
|
193
|
+
editor?: {
|
|
194
|
+
height?: number | string;
|
|
195
|
+
autofocus?: boolean;
|
|
196
|
+
assets?: Partial<KityEditorAssets>;
|
|
197
|
+
render?: {
|
|
198
|
+
fontsize?: number;
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
| Option | Default | Description |
|
|
205
|
+
| --- | --- | --- |
|
|
206
|
+
| `name` | `formulaX` | CKEditor 5 model/schema element name used for persisted formula nodes. |
|
|
207
|
+
| `buttonName` | `formulaX` | CKEditor 5 toolbar button name and command name. |
|
|
208
|
+
| `toolbarText` | `FormulaX` | Toolbar button label. |
|
|
209
|
+
| `tooltip` | `Insert or edit formula` | Toolbar button tooltip. |
|
|
210
|
+
| `cursorStyle` | `pointer` | Cursor style applied to generated formula nodes. |
|
|
211
|
+
| `formulaClassName` | `formulax-math` | CSS class used by generated formula nodes. |
|
|
212
|
+
| `formulaAttributeName` | `data-formulax-latex` | Attribute used to persist source LaTeX. |
|
|
213
|
+
| `renderer` | `createKityFormulaRenderer()` | Renderer used for runtime SVG output in the editing view. |
|
|
214
|
+
| `preload` | `idle` | Preloads the FormulaX runtime on browser idle, on host hover/focus, or never. |
|
|
215
|
+
| `modal` | see below | Modal labels and closing behavior. |
|
|
216
|
+
| `editor` | see below | Embedded FormulaX editor options. |
|
|
217
|
+
|
|
218
|
+
### Modal options
|
|
219
|
+
|
|
220
|
+
| Option | Default | Description |
|
|
221
|
+
| --- | --- | --- |
|
|
222
|
+
| `title` | `FormulaX Editor` | Modal title. |
|
|
223
|
+
| `insertText` | `Insert` | Submit button text when inserting. |
|
|
224
|
+
| `updateText` | `Update` | Submit button text when updating. |
|
|
225
|
+
| `cancelText` | `Cancel` | Cancel button text. |
|
|
226
|
+
| `closeOnBackdrop` | `true` | Whether clicking the backdrop closes the modal. |
|
|
227
|
+
|
|
228
|
+
### Editor options
|
|
229
|
+
|
|
230
|
+
| Option | Default | Description |
|
|
231
|
+
| --- | --- | --- |
|
|
232
|
+
| `height` | `100%` | Embedded editor height. |
|
|
233
|
+
| `autofocus` | `true` | Whether the embedded editor should autofocus. |
|
|
234
|
+
| `assets` | `{}` | Optional Kity runtime asset overrides. |
|
|
235
|
+
| `render.fontsize` | `40` | Formula render font size. |
|
|
236
|
+
|
|
237
|
+
## Exported API
|
|
238
|
+
|
|
239
|
+
| Export | Description |
|
|
240
|
+
| --- | --- |
|
|
241
|
+
| `FormulaX` | CKEditor 5 plugin class. |
|
|
242
|
+
| `default` | Same as `FormulaX`. |
|
|
243
|
+
| `FormulaXCommand` | Command implementation used by the plugin. |
|
|
244
|
+
| `resolveOptions` | Resolves user options into required defaults. |
|
|
245
|
+
| `openFormulaXModal` | Opens the FormulaX modal directly. |
|
|
246
|
+
| `DEFAULT_MODEL_NAME` | Default CKEditor 5 model name. |
|
|
247
|
+
| `DEFAULT_BUTTON_NAME` | Default CKEditor 5 command and toolbar button name. |
|
|
248
|
+
| `DEFAULT_FORMULA_ATTRIBUTE` | Default LaTeX persistence attribute name. |
|
|
249
|
+
| `DEFAULT_FORMULA_CLASS` | Default CSS class for formula nodes. |
|
|
250
|
+
| `FORMULA_FLAG_ATTRIBUTE` | Attribute used to identify FormulaX nodes in editor data. |
|
|
251
|
+
|
|
252
|
+
## Development
|
|
253
|
+
|
|
254
|
+
From the repository root:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
pnpm install
|
|
258
|
+
pnpm dev:ckeditor5
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Build only this package:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
pnpm --filter @formulaxjs/ckeditor5 build
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Run package type checking:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
pnpm --filter @formulaxjs/ckeditor5 typecheck
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Demo
|
|
274
|
+
|
|
275
|
+
Local demo:
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
pnpm dev:ckeditor5
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
GitHub Pages demo:
|
|
282
|
+
|
|
283
|
+
[https://vndmea.github.io/formulaX/ckeditor5/](https://vndmea.github.io/formulaX/ckeditor5/)
|