@formulaxjs/tiptap 0.2.2 → 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 +235 -215
- package/README.zh-CN.md +235 -215
- 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 +86 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +17394 -15746
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +90 -63
- package/dist/index.js.map +1 -1
- package/dist/other-OMWJFGL5.png +0 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,215 +1,235 @@
|
|
|
1
|
-
# @formulaxjs/tiptap
|
|
2
|
-
|
|
3
|
-
English | [简体中文](./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.
|
|
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
|
-
-
|
|
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
|
-
pnpm
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
import
|
|
57
|
-
import
|
|
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
|
-
```bash
|
|
210
|
-
pnpm
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
1
|
+
# @formulaxjs/tiptap
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./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
|
+
|
|
60
|
+
const editor = new Editor({
|
|
61
|
+
element: document.querySelector('#editor')!,
|
|
62
|
+
extensions: [
|
|
63
|
+
StarterKit,
|
|
64
|
+
createFormulaXNode(),
|
|
65
|
+
],
|
|
66
|
+
content: '<p>Click the toolbar button to insert a formula.</p>',
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
To open the FormulaX modal programmatically:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
editor.commands.openFormulaX();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Custom node names
|
|
77
|
+
|
|
78
|
+
The default Tiptap node name is `formulaX`.
|
|
79
|
+
|
|
80
|
+
If the host editor already uses that name, pass a custom `name` when creating the extension:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const editor = new Editor({
|
|
84
|
+
element: document.querySelector('#editor')!,
|
|
85
|
+
extensions: [
|
|
86
|
+
StarterKit,
|
|
87
|
+
createFormulaXNode(undefined, {
|
|
88
|
+
name: 'inlineMath',
|
|
89
|
+
}),
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
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.
|
|
95
|
+
|
|
96
|
+
## Persisted data
|
|
97
|
+
|
|
98
|
+
The Tiptap node stores only the LaTeX source:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"type": "formulaX",
|
|
103
|
+
"attrs": {
|
|
104
|
+
"latex": "\\sqrt{x}"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
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.
|
|
110
|
+
|
|
111
|
+
## Custom renderer
|
|
112
|
+
|
|
113
|
+
The adapter accepts a `renderer` option. By default it uses `createKityFormulaRenderer()` from `@formulaxjs/renderer-kity`.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { createFormulaXNode } from '@formulaxjs/tiptap';
|
|
117
|
+
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
118
|
+
|
|
119
|
+
const formulaNode = createFormulaXNode(undefined, {
|
|
120
|
+
renderer: createKityFormulaRenderer({
|
|
121
|
+
fontSize: 44,
|
|
122
|
+
}),
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Options
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
interface FormulaXTiptapOptions {
|
|
130
|
+
name?: string;
|
|
131
|
+
formulaClassName?: string;
|
|
132
|
+
formulaAttributeName?: string;
|
|
133
|
+
cursorStyle?: string;
|
|
134
|
+
initialLatex?: string;
|
|
135
|
+
renderer?: FormulaRenderer;
|
|
136
|
+
preload?: FormulaXEditorPreloadMode;
|
|
137
|
+
modal?: {
|
|
138
|
+
title?: string;
|
|
139
|
+
insertText?: string;
|
|
140
|
+
updateText?: string;
|
|
141
|
+
cancelText?: string;
|
|
142
|
+
closeOnBackdrop?: boolean;
|
|
143
|
+
};
|
|
144
|
+
editor?: {
|
|
145
|
+
height?: number | string;
|
|
146
|
+
autofocus?: boolean;
|
|
147
|
+
assets?: Partial<KityEditorAssets>;
|
|
148
|
+
render?: {
|
|
149
|
+
fontsize?: number;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Option | Default | Description |
|
|
156
|
+
| --- | --- | --- |
|
|
157
|
+
| `name` | `formulaX` | Tiptap node name used in the document schema. |
|
|
158
|
+
| `formulaClassName` | `formulax-math` | CSS class used by rendered formula nodes. |
|
|
159
|
+
| `formulaAttributeName` | `data-formulax-latex` | Attribute used in rendered DOM for the source LaTeX. |
|
|
160
|
+
| `cursorStyle` | `pointer` | Cursor style applied to rendered formula nodes. |
|
|
161
|
+
| `initialLatex` | empty string | Initial LaTeX when inserting a new formula. |
|
|
162
|
+
| `renderer` | `createKityFormulaRenderer()` | Renderer used for read-only formula output in the node view. |
|
|
163
|
+
| `preload` | `idle` | Preloads the FormulaX runtime on browser idle, on host hover/focus, or never. |
|
|
164
|
+
| `modal` | see below | Modal labels and closing behavior. |
|
|
165
|
+
| `editor` | see below | Embedded FormulaX editor options. |
|
|
166
|
+
|
|
167
|
+
### Modal options
|
|
168
|
+
|
|
169
|
+
| Option | Default | Description |
|
|
170
|
+
| --- | --- | --- |
|
|
171
|
+
| `title` | `FormulaX Editor` | Modal title. |
|
|
172
|
+
| `insertText` | `Insert` | Submit button text when inserting. |
|
|
173
|
+
| `updateText` | `Update` | Submit button text when updating. |
|
|
174
|
+
| `cancelText` | `Cancel` | Cancel button text. |
|
|
175
|
+
| `closeOnBackdrop` | `true` | Whether clicking the backdrop closes the modal. |
|
|
176
|
+
|
|
177
|
+
### Editor options
|
|
178
|
+
|
|
179
|
+
| Option | Default | Description |
|
|
180
|
+
| --- | --- | --- |
|
|
181
|
+
| `height` | `100%` | Embedded editor height. |
|
|
182
|
+
| `autofocus` | `true` | Whether the embedded editor should autofocus. |
|
|
183
|
+
| `assets` | `{}` | Optional Kity runtime asset overrides. |
|
|
184
|
+
| `render.fontsize` | `40` | Formula render font size. |
|
|
185
|
+
|
|
186
|
+
## Exported API
|
|
187
|
+
|
|
188
|
+
| Export | Description |
|
|
189
|
+
| --- | --- |
|
|
190
|
+
| `FormulaXNode` | Default FormulaX Tiptap node extension. |
|
|
191
|
+
| `createFormulaXNode` | Creates a FormulaX node extension, optionally with custom options. |
|
|
192
|
+
| `resolveOptions` | Resolves user options into required defaults. |
|
|
193
|
+
| `openFormulaXTiptapModal` | Opens the FormulaX modal directly. |
|
|
194
|
+
| `FORMULAX_NODE_NAME` | Default Tiptap node name. |
|
|
195
|
+
| `createFormulaXPayload` | Parses LaTeX into a FormulaX document. |
|
|
196
|
+
| `serializeFormulaXPayload` | Serializes a FormulaX document back to LaTeX. |
|
|
197
|
+
|
|
198
|
+
## Development
|
|
199
|
+
|
|
200
|
+
From the repository root:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
pnpm install
|
|
204
|
+
pnpm dev:tiptap
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Build only this package:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
pnpm --filter @formulaxjs/tiptap build
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Run package tests:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
pnpm --filter @formulaxjs/tiptap test
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Run package type checking:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pnpm --filter @formulaxjs/tiptap typecheck
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Demo
|
|
226
|
+
|
|
227
|
+
Local demo:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pnpm dev:tiptap
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
GitHub Pages demo:
|
|
234
|
+
|
|
235
|
+
[https://vndmea.github.io/formulaX/tiptap/](https://vndmea.github.io/formulaX/tiptap/)
|