@formulaxjs/tiptap 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.
- package/README.md +212 -207
- package/README.zh-CN.md +71 -66
- package/dist/base.css +47 -0
- package/dist/canvg-runtime-UR3JNX5Q.js +2759 -0
- package/dist/canvg-runtime-UR3JNX5Q.js.map +1 -0
- package/dist/chunk-OCSSWPUX.js +3407 -0
- package/dist/chunk-OCSSWPUX.js.map +1 -0
- package/dist/images/scrollbar/custom/bar-bg.png +0 -0
- package/dist/images/scrollbar/custom/bar.png +0 -0
- package/dist/images/scrollbar/custom/bg.png +0 -0
- package/dist/images/scrollbar/custom/bottom.png +0 -0
- package/dist/images/scrollbar/custom/btn.png +0 -0
- package/dist/images/scrollbar/custom/down.png +0 -0
- package/dist/images/scrollbar/custom/top.png +0 -0
- package/dist/images/scrollbar/custom/up.png +0 -0
- package/dist/images/scrollbar/edit/bar-bg.png +0 -0
- package/dist/images/scrollbar/edit/bar-left.png +0 -0
- package/dist/images/scrollbar/edit/bar-right.png +0 -0
- package/dist/images/scrollbar/edit/thumb-bg.png +0 -0
- package/dist/images/scrollbar/edit/thumb-left.png +0 -0
- package/dist/images/scrollbar/edit/thumb-right.png +0 -0
- package/dist/images/toolbar/btn.png +0 -0
- package/dist/index.cjs +24075 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +2385 -2241
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +3768 -21
- package/dist/index.js.map +1 -1
- package/dist/install-XGCSWTLU.js +5464 -0
- package/dist/install-XGCSWTLU.js.map +1 -0
- package/dist/install-XVTKACEN.js +1349 -0
- package/dist/install-XVTKACEN.js.map +1 -0
- package/dist/other.png +0 -0
- package/dist/scrollbar.css +78 -0
- package/dist/start-MBLTNR2Q.js +4926 -0
- package/dist/start-MBLTNR2Q.js.map +1 -0
- package/dist/ui.css +625 -0
- package/package.json +9 -4
- /package/dist/{KF_AMS_BB-5QF7FUSO.woff → KF_AMS_BB.woff} +0 -0
- /package/dist/{KF_AMS_CAL-NXRNLAZN.woff → KF_AMS_CAL.woff} +0 -0
- /package/dist/{KF_AMS_FRAK-CO33WWN4.woff → KF_AMS_FRAK.woff} +0 -0
- /package/dist/{KF_AMS_MAIN-25QJVAWY.woff → KF_AMS_MAIN.woff} +0 -0
- /package/dist/{KF_AMS_ROMAN-243BR7HH.woff → KF_AMS_ROMAN.woff} +0 -0
- /package/dist/{btn-5DANP6JY.png → btn.png} +0 -0
- /package/dist/{editor-JT5KLVXX.css → editor.css} +0 -0
- /package/dist/{other-OMWJFGL5.png → images/toolbar/other.png} +0 -0
package/README.md
CHANGED
|
@@ -1,73 +1,76 @@
|
|
|
1
|
-
# @formulaxjs/tiptap
|
|
2
|
-
|
|
3
|
-
English | [简体中文](
|
|
4
|
-
|
|
5
|
-
Tiptap integration adapter for FormulaX.
|
|
6
|
-
|
|
7
|
-
`@formulaxjs/tiptap` provides a FormulaX inline node extension for Tiptap and a modal-based formula editing flow. The extension persists only LaTeX in the document model and renders formula output at runtime through the shared FormulaX renderer interface.
|
|
8
|
-
|
|
9
|
-
> Status: experimental. Public APIs may change before the first stable release.
|
|
10
|
-
|
|
11
|
-
## Features
|
|
12
|
-
|
|
13
|
-
- Tiptap node extension export through `FormulaXNode`
|
|
14
|
-
- Extension factory export through `createFormulaXNode`
|
|
15
|
-
- `openFormulaX` command for toolbar buttons or programmatic opening
|
|
16
|
-
- Double-click editing for existing formulas
|
|
17
|
-
- Persist only LaTeX in node attrs
|
|
18
|
-
- Runtime SVG rendering in the node view
|
|
19
|
-
- Default read-only rendering through `@formulaxjs/renderer-kity`
|
|
20
|
-
- Optional runtime preload before the first modal open
|
|
21
|
-
- Modal helper export through `openFormulaXTiptapModal`
|
|
22
|
-
- Compatible peer dependency range for Tiptap 2 and 3
|
|
23
|
-
|
|
24
|
-
## Compatibility
|
|
25
|
-
|
|
26
|
-
The package declares `@tiptap/core` as an optional peer dependency:
|
|
27
|
-
|
|
28
|
-
```json
|
|
29
|
-
{
|
|
30
|
-
"@tiptap/core": ">=2 <4"
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
The workspace demo can switch between Tiptap 2 and 3 for compatibility verification.
|
|
35
|
-
|
|
36
|
-
## Install
|
|
37
|
-
|
|
38
|
-
When the package is published:
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pnpm
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
import
|
|
58
|
-
import
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
# @formulaxjs/tiptap
|
|
2
|
+
|
|
3
|
+
English | [简体中文](https://github.com/vndmea/formulaX/blob/main/packages/tiptap/README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Tiptap integration adapter for FormulaX.
|
|
6
|
+
|
|
7
|
+
`@formulaxjs/tiptap` provides a FormulaX inline node extension for Tiptap and a modal-based formula editing flow. The extension persists only LaTeX in the document model and renders formula output at runtime through the shared FormulaX renderer interface.
|
|
8
|
+
|
|
9
|
+
> Status: experimental. Public APIs may change before the first stable release.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Tiptap node extension export through `FormulaXNode`
|
|
14
|
+
- Extension factory export through `createFormulaXNode`
|
|
15
|
+
- `openFormulaX` command for toolbar buttons or programmatic opening
|
|
16
|
+
- Double-click editing for existing formulas
|
|
17
|
+
- Persist only LaTeX in node attrs
|
|
18
|
+
- Runtime SVG rendering in the node view
|
|
19
|
+
- Default read-only rendering through `@formulaxjs/renderer-kity`
|
|
20
|
+
- Optional runtime preload before the first modal open
|
|
21
|
+
- Modal helper export through `openFormulaXTiptapModal`
|
|
22
|
+
- Compatible peer dependency range for Tiptap 2 and 3
|
|
23
|
+
|
|
24
|
+
## Compatibility
|
|
25
|
+
|
|
26
|
+
The package declares `@tiptap/core` as an optional peer dependency:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"@tiptap/core": ">=2 <4"
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The workspace demo can switch between Tiptap 2 and 3 for compatibility verification.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
When the package is published:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install @formulaxjs/tiptap @tiptap/core
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Inside the FormulaX workspace, use the workspace package directly:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm install
|
|
48
|
+
pnpm dev:tiptap
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Basic usage
|
|
52
|
+
|
|
53
|
+
Create the FormulaX node extension and add it to the Tiptap extension list:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { Editor } from '@tiptap/core';
|
|
57
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
58
|
+
import { createFormulaXNode } from '@formulaxjs/tiptap';
|
|
59
|
+
|
|
61
60
|
const editor = new Editor({
|
|
62
61
|
element: document.querySelector('#editor')!,
|
|
63
62
|
extensions: [
|
|
64
63
|
StarterKit,
|
|
65
|
-
createFormulaXNode(
|
|
64
|
+
createFormulaXNode(undefined, {
|
|
65
|
+
editor: {
|
|
66
|
+
locale: 'zh_CN', // optional, defaults to en_US
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
66
69
|
],
|
|
67
70
|
content: '<p>Click the toolbar button to insert a formula.</p>',
|
|
68
71
|
});
|
|
69
72
|
```
|
|
70
|
-
|
|
73
|
+
|
|
71
74
|
To open the FormulaX modal programmatically:
|
|
72
75
|
|
|
73
76
|
```ts
|
|
@@ -75,162 +78,164 @@ editor.commands.openFormulaX();
|
|
|
75
78
|
```
|
|
76
79
|
|
|
77
80
|
## Custom node names
|
|
78
|
-
|
|
79
|
-
The default Tiptap node name is `formulaX`.
|
|
80
|
-
|
|
81
|
-
If the host editor already uses that name, pass a custom `name` when creating the extension:
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
const editor = new Editor({
|
|
85
|
-
element: document.querySelector('#editor')!,
|
|
86
|
-
extensions: [
|
|
87
|
-
StarterKit,
|
|
88
|
-
createFormulaXNode(undefined, {
|
|
89
|
-
name: 'inlineMath',
|
|
90
|
-
}),
|
|
91
|
-
],
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
If Tiptap detects that the configured node name is already registered, the extension logs a `console.warn` message so you can rename it before the schema collides.
|
|
96
|
-
|
|
97
|
-
## Persisted data
|
|
98
|
-
|
|
99
|
-
The Tiptap node stores only the LaTeX source:
|
|
100
|
-
|
|
101
|
-
```json
|
|
102
|
-
{
|
|
103
|
-
"type": "formulaX",
|
|
104
|
-
"attrs": {
|
|
105
|
-
"latex": "\\sqrt{x}"
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
The node view renders formula SVG at runtime from the stored LaTeX. Generated DOM markup includes `data-formulax="true"` and `data-formulax-latex`, but that rendered DOM is not the persisted source of truth.
|
|
111
|
-
|
|
112
|
-
## Custom renderer
|
|
113
|
-
|
|
114
|
-
The adapter accepts a `renderer` option. By default it uses `createKityFormulaRenderer()` from `@formulaxjs/renderer-kity`.
|
|
115
|
-
|
|
116
|
-
```ts
|
|
117
|
-
import { createFormulaXNode } from '@formulaxjs/tiptap';
|
|
118
|
-
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
119
|
-
|
|
120
|
-
const
|
|
81
|
+
|
|
82
|
+
The default Tiptap node name is `formulaX`.
|
|
83
|
+
|
|
84
|
+
If the host editor already uses that name, pass a custom `name` when creating the extension:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
const editor = new Editor({
|
|
88
|
+
element: document.querySelector('#editor')!,
|
|
89
|
+
extensions: [
|
|
90
|
+
StarterKit,
|
|
91
|
+
createFormulaXNode(undefined, {
|
|
92
|
+
name: 'inlineMath',
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
If Tiptap detects that the configured node name is already registered, the extension logs a `console.warn` message so you can rename it before the schema collides.
|
|
99
|
+
|
|
100
|
+
## Persisted data
|
|
101
|
+
|
|
102
|
+
The Tiptap node stores only the LaTeX source:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"type": "formulaX",
|
|
107
|
+
"attrs": {
|
|
108
|
+
"latex": "\\sqrt{x}"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The node view renders formula SVG at runtime from the stored LaTeX. Generated DOM markup includes `data-formulax="true"` and `data-formulax-latex`, but that rendered DOM is not the persisted source of truth.
|
|
114
|
+
|
|
115
|
+
## Custom renderer
|
|
116
|
+
|
|
117
|
+
The adapter accepts a `renderer` option. By default it uses `createKityFormulaRenderer()` from `@formulaxjs/renderer-kity`.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { createFormulaXNode } from '@formulaxjs/tiptap';
|
|
121
|
+
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
122
|
+
|
|
123
|
+
const formulaXNode = createFormulaXNode(undefined, {
|
|
121
124
|
renderer: createKityFormulaRenderer({
|
|
122
125
|
fontSize: 44,
|
|
123
126
|
}),
|
|
124
127
|
});
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
## Options
|
|
128
|
-
|
|
129
|
-
```ts
|
|
130
|
-
interface FormulaXTiptapOptions {
|
|
131
|
-
name?: string;
|
|
132
|
-
formulaClassName?: string;
|
|
133
|
-
formulaAttributeName?: string;
|
|
134
|
-
cursorStyle?: string;
|
|
135
|
-
initialLatex?: string;
|
|
136
|
-
renderer?: FormulaRenderer;
|
|
137
|
-
preload?: FormulaXEditorPreloadMode;
|
|
138
|
-
modal?: {
|
|
139
|
-
title?: string;
|
|
140
|
-
insertText?: string;
|
|
141
|
-
updateText?: string;
|
|
142
|
-
cancelText?: string;
|
|
143
|
-
closeOnBackdrop?: boolean;
|
|
144
|
-
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Options
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
interface FormulaXTiptapOptions {
|
|
134
|
+
name?: string;
|
|
135
|
+
formulaClassName?: string;
|
|
136
|
+
formulaAttributeName?: string;
|
|
137
|
+
cursorStyle?: string;
|
|
138
|
+
initialLatex?: string;
|
|
139
|
+
renderer?: FormulaRenderer;
|
|
140
|
+
preload?: FormulaXEditorPreloadMode;
|
|
141
|
+
modal?: {
|
|
142
|
+
title?: string;
|
|
143
|
+
insertText?: string;
|
|
144
|
+
updateText?: string;
|
|
145
|
+
cancelText?: string;
|
|
146
|
+
closeOnBackdrop?: boolean;
|
|
147
|
+
};
|
|
145
148
|
editor?: {
|
|
146
149
|
height?: number | string;
|
|
147
150
|
autofocus?: boolean;
|
|
151
|
+
locale?: FormulaXLocale;
|
|
148
152
|
assets?: Partial<KityEditorAssets>;
|
|
149
153
|
render?: {
|
|
150
154
|
fontsize?: number;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
| Option | Default | Description |
|
|
157
|
-
| --- | --- | --- |
|
|
158
|
-
| `name` | `formulaX` | Tiptap node name used in the document schema. |
|
|
159
|
-
| `formulaClassName` | `formulax-math` | CSS class used by rendered formula nodes. |
|
|
160
|
-
| `formulaAttributeName` | `data-formulax-latex` | Attribute used in rendered DOM for the source LaTeX. |
|
|
161
|
-
| `cursorStyle` | `pointer` | Cursor style applied to rendered formula nodes. |
|
|
162
|
-
| `initialLatex` | empty string | Initial LaTeX when inserting a new formula. |
|
|
163
|
-
| `renderer` | `createKityFormulaRenderer()` | Renderer used for read-only formula output in the node view. |
|
|
164
|
-
| `preload` | `idle` | Preloads the FormulaX runtime on browser idle, on host hover/focus, or never. |
|
|
165
|
-
| `modal` | see below | Modal labels and closing behavior. |
|
|
166
|
-
| `editor` | see below | Embedded FormulaX editor options. |
|
|
167
|
-
|
|
168
|
-
### Modal options
|
|
169
|
-
|
|
170
|
-
| Option | Default | Description |
|
|
171
|
-
| --- | --- | --- |
|
|
172
|
-
| `title` | `FormulaX Editor` | Modal title. |
|
|
173
|
-
| `insertText` | `Insert` | Submit button text when inserting. |
|
|
174
|
-
| `updateText` | `Update` | Submit button text when updating. |
|
|
175
|
-
| `cancelText` | `Cancel` | Cancel button text. |
|
|
176
|
-
| `closeOnBackdrop` | `true` | Whether clicking the backdrop closes the modal. |
|
|
177
|
-
|
|
178
|
-
### Editor options
|
|
179
|
-
|
|
180
|
-
| Option | Default | Description |
|
|
181
|
-
| --- | --- | --- |
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
| Option | Default | Description |
|
|
161
|
+
| --- | --- | --- |
|
|
162
|
+
| `name` | `formulaX` | Tiptap node name used in the document schema. |
|
|
163
|
+
| `formulaClassName` | `formulax-math` | CSS class used by rendered formula nodes. |
|
|
164
|
+
| `formulaAttributeName` | `data-formulax-latex` | Attribute used in rendered DOM for the source LaTeX. |
|
|
165
|
+
| `cursorStyle` | `pointer` | Cursor style applied to rendered formula nodes. |
|
|
166
|
+
| `initialLatex` | empty string | Initial LaTeX when inserting a new formula. |
|
|
167
|
+
| `renderer` | `createKityFormulaRenderer()` | Renderer used for read-only formula output in the node view. |
|
|
168
|
+
| `preload` | `idle` | Preloads the FormulaX runtime on browser idle, on host hover/focus, or never. |
|
|
169
|
+
| `modal` | see below | Modal labels and closing behavior. |
|
|
170
|
+
| `editor` | see below | Embedded FormulaX editor options. |
|
|
171
|
+
|
|
172
|
+
### Modal options
|
|
173
|
+
|
|
174
|
+
| Option | Default | Description |
|
|
175
|
+
| --- | --- | --- |
|
|
176
|
+
| `title` | `FormulaX Editor` | Modal title. |
|
|
177
|
+
| `insertText` | `Insert` | Submit button text when inserting. |
|
|
178
|
+
| `updateText` | `Update` | Submit button text when updating. |
|
|
179
|
+
| `cancelText` | `Cancel` | Cancel button text. |
|
|
180
|
+
| `closeOnBackdrop` | `true` | Whether clicking the backdrop closes the modal. |
|
|
181
|
+
|
|
182
|
+
### Editor options
|
|
183
|
+
|
|
184
|
+
| Option | Default | Description |
|
|
185
|
+
| --- | --- | --- |
|
|
182
186
|
| `height` | `100%` | Embedded editor height. |
|
|
183
187
|
| `autofocus` | `true` | Whether the embedded editor should autofocus. |
|
|
188
|
+
| `locale` | `en_US` | Localizes the modal defaults and the embedded Kity runtime UI. |
|
|
184
189
|
| `assets` | `{}` | Optional Kity runtime asset overrides. |
|
|
185
190
|
| `render.fontsize` | `40` | Formula render font size. |
|
|
186
|
-
|
|
187
|
-
## Exported API
|
|
188
|
-
|
|
189
|
-
| Export | Description |
|
|
190
|
-
| --- | --- |
|
|
191
|
-
| `FormulaXNode` | Default FormulaX Tiptap node extension. |
|
|
192
|
-
| `createFormulaXNode` | Creates a FormulaX node extension, optionally with custom options. |
|
|
193
|
-
| `resolveOptions` | Resolves user options into required defaults. |
|
|
194
|
-
| `openFormulaXTiptapModal` | Opens the FormulaX modal directly. |
|
|
195
|
-
| `FORMULAX_NODE_NAME` | Default Tiptap node name. |
|
|
196
|
-
| `createFormulaXPayload` | Parses LaTeX into a FormulaX document. |
|
|
197
|
-
| `serializeFormulaXPayload` | Serializes a FormulaX document back to LaTeX. |
|
|
198
|
-
|
|
199
|
-
## Development
|
|
200
|
-
|
|
201
|
-
From the repository root:
|
|
202
|
-
|
|
203
|
-
```bash
|
|
204
|
-
pnpm install
|
|
205
|
-
pnpm dev:tiptap
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
Build only this package:
|
|
209
|
-
|
|
210
|
-
```bash
|
|
211
|
-
pnpm --filter @formulaxjs/tiptap build
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Run package tests:
|
|
215
|
-
|
|
216
|
-
```bash
|
|
217
|
-
pnpm --filter @formulaxjs/tiptap test
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
Run package type checking:
|
|
221
|
-
|
|
222
|
-
```bash
|
|
223
|
-
pnpm --filter @formulaxjs/tiptap typecheck
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
## Demo
|
|
227
|
-
|
|
228
|
-
Local demo:
|
|
229
|
-
|
|
230
|
-
```bash
|
|
231
|
-
pnpm dev:tiptap
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
GitHub Pages demo:
|
|
235
|
-
|
|
236
|
-
[https://vndmea.github.io/formulaX/tiptap/](https://vndmea.github.io/formulaX/tiptap/)
|
|
191
|
+
|
|
192
|
+
## Exported API
|
|
193
|
+
|
|
194
|
+
| Export | Description |
|
|
195
|
+
| --- | --- |
|
|
196
|
+
| `FormulaXNode` | Default FormulaX Tiptap node extension. |
|
|
197
|
+
| `createFormulaXNode` | Creates a FormulaX node extension, optionally with custom options. |
|
|
198
|
+
| `resolveOptions` | Resolves user options into required defaults. |
|
|
199
|
+
| `openFormulaXTiptapModal` | Opens the FormulaX modal directly. |
|
|
200
|
+
| `FORMULAX_NODE_NAME` | Default Tiptap node name. |
|
|
201
|
+
| `createFormulaXPayload` | Parses LaTeX into a FormulaX document. |
|
|
202
|
+
| `serializeFormulaXPayload` | Serializes a FormulaX document back to LaTeX. |
|
|
203
|
+
|
|
204
|
+
## Development
|
|
205
|
+
|
|
206
|
+
From the repository root:
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
pnpm install
|
|
210
|
+
pnpm dev:tiptap
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Build only this package:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
pnpm --filter @formulaxjs/tiptap build
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Run package tests:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pnpm --filter @formulaxjs/tiptap test
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Run package type checking:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
pnpm --filter @formulaxjs/tiptap typecheck
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Demo
|
|
232
|
+
|
|
233
|
+
Local demo:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
pnpm dev:tiptap
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
GitHub Pages demo:
|
|
240
|
+
|
|
241
|
+
[https://vndmea.github.io/formulaX/tiptap/](https://vndmea.github.io/formulaX/tiptap/)
|
package/README.zh-CN.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @formulaxjs/tiptap
|
|
2
2
|
|
|
3
|
-
[English](
|
|
3
|
+
[English](https://github.com/vndmea/formulaX/blob/main/packages/tiptap/README.md) | 简体中文
|
|
4
4
|
|
|
5
5
|
FormulaX 的 Tiptap 集成适配器。
|
|
6
6
|
|
|
7
|
-
`@formulaxjs/tiptap` 提供了一个 FormulaX 行内节点扩展和基于弹窗的公式编辑流程。该扩展在文档模型中只持久化 LaTeX,并通过共享的 FormulaX renderer 接口在运行时渲染公式展示结果。
|
|
7
|
+
`@formulaxjs/tiptap` 提供了一个 FormulaX 行内节点扩展和基于弹窗的公式编辑流程。该扩展在文档模型中只持久化 LaTeX,并通过共享的 FormulaX renderer 接口在运行时渲染公式展示结果。
|
|
8
8
|
|
|
9
9
|
> 状态:实验阶段。在首个稳定版本发布前,公共 API 仍可能调整。
|
|
10
10
|
|
|
@@ -13,13 +13,13 @@ FormulaX 的 Tiptap 集成适配器。
|
|
|
13
13
|
- 通过 `FormulaXNode` 导出 Tiptap 节点扩展
|
|
14
14
|
- 通过 `createFormulaXNode` 导出扩展工厂函数
|
|
15
15
|
- 提供 `openFormulaX` 命令,便于接工具栏按钮或代码中主动打开
|
|
16
|
-
- 支持双击编辑已有公式
|
|
17
|
-
- 节点 attrs 中仅持久化 LaTeX
|
|
18
|
-
- 在 node view 中运行时渲染 SVG
|
|
19
|
-
- 默认通过 `@formulaxjs/renderer-kity` 完成只读渲染
|
|
20
|
-
- 支持在首次打开弹窗前预加载 runtime
|
|
21
|
-
- 直接导出弹窗工具函数 `openFormulaXTiptapModal`
|
|
22
|
-
- 兼容 Tiptap 2 和 3 的 peer dependency 范围
|
|
16
|
+
- 支持双击编辑已有公式
|
|
17
|
+
- 节点 attrs 中仅持久化 LaTeX
|
|
18
|
+
- 在 node view 中运行时渲染 SVG
|
|
19
|
+
- 默认通过 `@formulaxjs/renderer-kity` 完成只读渲染
|
|
20
|
+
- 支持在首次打开弹窗前预加载 runtime
|
|
21
|
+
- 直接导出弹窗工具函数 `openFormulaXTiptapModal`
|
|
22
|
+
- 兼容 Tiptap 2 和 3 的 peer dependency 范围
|
|
23
23
|
|
|
24
24
|
## 兼容性
|
|
25
25
|
|
|
@@ -38,8 +38,7 @@ FormulaX 的 Tiptap 集成适配器。
|
|
|
38
38
|
包发布后可使用:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
|
|
42
|
-
pnpm add @tiptap/core
|
|
41
|
+
npm install @formulaxjs/tiptap @tiptap/core
|
|
43
42
|
```
|
|
44
43
|
|
|
45
44
|
在 FormulaX 工作空间内,直接使用 workspace 包:
|
|
@@ -58,23 +57,27 @@ import { Editor } from '@tiptap/core';
|
|
|
58
57
|
import StarterKit from '@tiptap/starter-kit';
|
|
59
58
|
import { createFormulaXNode } from '@formulaxjs/tiptap';
|
|
60
59
|
|
|
61
|
-
const editor = new Editor({
|
|
62
|
-
element: document.querySelector('#editor')!,
|
|
63
|
-
extensions: [
|
|
64
|
-
StarterKit,
|
|
65
|
-
createFormulaXNode(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
editor.commands.openFormulaX();
|
|
75
|
-
```
|
|
60
|
+
const editor = new Editor({
|
|
61
|
+
element: document.querySelector('#editor')!,
|
|
62
|
+
extensions: [
|
|
63
|
+
StarterKit,
|
|
64
|
+
createFormulaXNode(undefined, {
|
|
65
|
+
editor: {
|
|
66
|
+
locale: 'zh_CN', // 可选,默认 en_US
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
content: '<p>点击工具栏按钮插入公式。</p>',
|
|
71
|
+
});
|
|
72
|
+
```
|
|
76
73
|
|
|
77
|
-
|
|
74
|
+
如果要在代码中主动打开 FormulaX 弹窗:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
editor.commands.openFormulaX();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 自定义节点名称
|
|
78
81
|
|
|
79
82
|
默认的 Tiptap 节点名是 `formulaX`。
|
|
80
83
|
|
|
@@ -107,47 +110,48 @@ Tiptap 节点中只保存 LaTeX 源内容:
|
|
|
107
110
|
}
|
|
108
111
|
```
|
|
109
112
|
|
|
110
|
-
节点视图会根据保存的 LaTeX 在运行时渲染 SVG。生成的 DOM 会带有 `data-formulax="true"` 和 `data-formulax-latex`,但这些渲染后的 DOM 不是持久化数据的真实来源。
|
|
111
|
-
|
|
112
|
-
## 自定义 renderer
|
|
113
|
-
|
|
114
|
-
该适配器支持 `renderer` 配置项。默认值是来自 `@formulaxjs/renderer-kity` 的 `createKityFormulaRenderer()`。
|
|
115
|
-
|
|
116
|
-
```ts
|
|
117
|
-
import { createFormulaXNode } from '@formulaxjs/tiptap';
|
|
118
|
-
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
119
|
-
|
|
120
|
-
const
|
|
113
|
+
节点视图会根据保存的 LaTeX 在运行时渲染 SVG。生成的 DOM 会带有 `data-formulax="true"` 和 `data-formulax-latex`,但这些渲染后的 DOM 不是持久化数据的真实来源。
|
|
114
|
+
|
|
115
|
+
## 自定义 renderer
|
|
116
|
+
|
|
117
|
+
该适配器支持 `renderer` 配置项。默认值是来自 `@formulaxjs/renderer-kity` 的 `createKityFormulaRenderer()`。
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { createFormulaXNode } from '@formulaxjs/tiptap';
|
|
121
|
+
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
122
|
+
|
|
123
|
+
const formulaXNode = createFormulaXNode(undefined, {
|
|
121
124
|
renderer: createKityFormulaRenderer({
|
|
122
125
|
fontSize: 44,
|
|
123
126
|
}),
|
|
124
127
|
});
|
|
125
|
-
```
|
|
128
|
+
```
|
|
126
129
|
|
|
127
130
|
## 配置项
|
|
128
131
|
|
|
129
132
|
```ts
|
|
130
|
-
interface FormulaXTiptapOptions {
|
|
131
|
-
name?: string;
|
|
132
|
-
formulaClassName?: string;
|
|
133
|
-
formulaAttributeName?: string;
|
|
134
|
-
cursorStyle?: string;
|
|
135
|
-
initialLatex?: string;
|
|
136
|
-
renderer?: FormulaRenderer;
|
|
137
|
-
preload?: FormulaXEditorPreloadMode;
|
|
138
|
-
modal?: {
|
|
139
|
-
title?: string;
|
|
140
|
-
insertText?: string;
|
|
133
|
+
interface FormulaXTiptapOptions {
|
|
134
|
+
name?: string;
|
|
135
|
+
formulaClassName?: string;
|
|
136
|
+
formulaAttributeName?: string;
|
|
137
|
+
cursorStyle?: string;
|
|
138
|
+
initialLatex?: string;
|
|
139
|
+
renderer?: FormulaRenderer;
|
|
140
|
+
preload?: FormulaXEditorPreloadMode;
|
|
141
|
+
modal?: {
|
|
142
|
+
title?: string;
|
|
143
|
+
insertText?: string;
|
|
141
144
|
updateText?: string;
|
|
142
145
|
cancelText?: string;
|
|
143
146
|
closeOnBackdrop?: boolean;
|
|
144
147
|
};
|
|
145
|
-
editor?: {
|
|
146
|
-
height?: number | string;
|
|
147
|
-
autofocus?: boolean;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
editor?: {
|
|
149
|
+
height?: number | string;
|
|
150
|
+
autofocus?: boolean;
|
|
151
|
+
locale?: FormulaXLocale;
|
|
152
|
+
assets?: Partial<KityEditorAssets>;
|
|
153
|
+
render?: {
|
|
154
|
+
fontsize?: number;
|
|
151
155
|
};
|
|
152
156
|
};
|
|
153
157
|
}
|
|
@@ -158,12 +162,12 @@ interface FormulaXTiptapOptions {
|
|
|
158
162
|
| `name` | `formulaX` | 用于文档 schema 的 Tiptap 节点名。 |
|
|
159
163
|
| `formulaClassName` | `formulax-math` | 渲染后公式节点使用的 CSS class。 |
|
|
160
164
|
| `formulaAttributeName` | `data-formulax-latex` | 渲染后 DOM 中保存 LaTeX 源内容的属性名。 |
|
|
161
|
-
| `cursorStyle` | `pointer` | 渲染后公式节点的鼠标光标样式。 |
|
|
162
|
-
| `initialLatex` | 空字符串 | 插入新公式时的初始 LaTeX。 |
|
|
163
|
-
| `renderer` | `createKityFormulaRenderer()` | node view 中用于只读公式输出的 renderer。 |
|
|
164
|
-
| `preload` | `idle` | 控制在浏览器空闲时、宿主 hover/focus 时,或完全不预加载 FormulaX runtime。 |
|
|
165
|
-
| `modal` | 见下方 | 弹窗文案和关闭行为。 |
|
|
166
|
-
| `editor` | 见下方 | 内嵌 FormulaX 编辑器配置。 |
|
|
165
|
+
| `cursorStyle` | `pointer` | 渲染后公式节点的鼠标光标样式。 |
|
|
166
|
+
| `initialLatex` | 空字符串 | 插入新公式时的初始 LaTeX。 |
|
|
167
|
+
| `renderer` | `createKityFormulaRenderer()` | node view 中用于只读公式输出的 renderer。 |
|
|
168
|
+
| `preload` | `idle` | 控制在浏览器空闲时、宿主 hover/focus 时,或完全不预加载 FormulaX runtime。 |
|
|
169
|
+
| `modal` | 见下方 | 弹窗文案和关闭行为。 |
|
|
170
|
+
| `editor` | 见下方 | 内嵌 FormulaX 编辑器配置。 |
|
|
167
171
|
|
|
168
172
|
### Modal 配置
|
|
169
173
|
|
|
@@ -179,10 +183,11 @@ interface FormulaXTiptapOptions {
|
|
|
179
183
|
|
|
180
184
|
| 配置项 | 默认值 | 说明 |
|
|
181
185
|
| --- | --- | --- |
|
|
182
|
-
| `height` | `100%` | 内嵌编辑器高度。 |
|
|
183
|
-
| `autofocus` | `true` | 内嵌编辑器是否自动聚焦。 |
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
186
|
+
| `height` | `100%` | 内嵌编辑器高度。 |
|
|
187
|
+
| `autofocus` | `true` | 内嵌编辑器是否自动聚焦。 |
|
|
188
|
+
| `locale` | `en_US` | 同时切换弹窗默认文案和内嵌 Kity runtime UI。 |
|
|
189
|
+
| `assets` | `{}` | 可选的 Kity runtime 资源覆盖配置。 |
|
|
190
|
+
| `render.fontsize` | `40` | 公式渲染字号。 |
|
|
186
191
|
|
|
187
192
|
## 导出 API
|
|
188
193
|
|