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