@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 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
- - Modal helper export through `openFormulaXTiptapModal`
20
- - Compatible peer dependency range for Tiptap 2 and 3
21
-
22
- ## Compatibility
23
-
24
- The package declares `@tiptap/core` as an optional peer dependency:
25
-
26
- ```json
27
- {
28
- "@tiptap/core": ">=2 <4"
29
- }
30
- ```
31
-
32
- The workspace demo can switch between Tiptap 2 and 3 for compatibility verification.
33
-
34
- ## Install
35
-
36
- When the package is published:
37
-
38
- ```bash
39
- pnpm add @formulaxjs/tiptap
40
- pnpm add @tiptap/core
41
- ```
42
-
43
- Inside the FormulaX workspace, use the workspace package directly:
44
-
45
- ```bash
46
- pnpm install
47
- pnpm dev:tiptap
48
- ```
49
-
50
- ## Basic usage
51
-
52
- Create the FormulaX node extension and add it to the Tiptap extension list:
53
-
54
- ```ts
55
- import { Editor } from '@tiptap/core';
56
- import StarterKit from '@tiptap/starter-kit';
57
- import { createFormulaXNode } from '@formulaxjs/tiptap';
58
-
59
- const editor = new Editor({
60
- element: document.querySelector('#editor')!,
61
- extensions: [
62
- StarterKit,
63
- createFormulaXNode(),
64
- ],
65
- content: '<p>Click the toolbar button to insert a formula.</p>',
66
- });
67
- ```
68
-
69
- To open the FormulaX modal programmatically:
70
-
71
- ```ts
72
- editor.commands.openFormulaX();
73
- ```
74
-
75
- ## Custom node names
76
-
77
- The default Tiptap node name is `formulaX`.
78
-
79
- If the host editor already uses that name, pass a custom `name` when creating the extension:
80
-
81
- ```ts
82
- const editor = new Editor({
83
- element: document.querySelector('#editor')!,
84
- extensions: [
85
- StarterKit,
86
- createFormulaXNode(undefined, {
87
- name: 'inlineMath',
88
- }),
89
- ],
90
- });
91
- ```
92
-
93
- 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.
94
-
95
- ## Persisted data
96
-
97
- The Tiptap node stores only the LaTeX source:
98
-
99
- ```json
100
- {
101
- "type": "formulaX",
102
- "attrs": {
103
- "latex": "\\sqrt{x}"
104
- }
105
- }
106
- ```
107
-
108
- 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.
109
-
110
- ## Options
111
-
112
- ```ts
113
- interface FormulaXTiptapOptions {
114
- name?: string;
115
- formulaClassName?: string;
116
- formulaAttributeName?: string;
117
- cursorStyle?: string;
118
- initialLatex?: string;
119
- modal?: {
120
- title?: string;
121
- insertText?: string;
122
- updateText?: string;
123
- cancelText?: string;
124
- closeOnBackdrop?: boolean;
125
- };
126
- editor?: {
127
- height?: number | string;
128
- autofocus?: boolean;
129
- assets?: Partial<KityEditorAssets>;
130
- render?: {
131
- fontsize?: number;
132
- };
133
- };
134
- }
135
- ```
136
-
137
- | Option | Default | Description |
138
- | --- | --- | --- |
139
- | `name` | `formulaX` | Tiptap node name used in the document schema. |
140
- | `formulaClassName` | `formulax-math` | CSS class used by rendered formula nodes. |
141
- | `formulaAttributeName` | `data-formulax-latex` | Attribute used in rendered DOM for the source LaTeX. |
142
- | `cursorStyle` | `pointer` | Cursor style applied to rendered formula nodes. |
143
- | `initialLatex` | empty string | Initial LaTeX when inserting a new formula. |
144
- | `modal` | see below | Modal labels and closing behavior. |
145
- | `editor` | see below | Embedded FormulaX editor options. |
146
-
147
- ### Modal options
148
-
149
- | Option | Default | Description |
150
- | --- | --- | --- |
151
- | `title` | `FormulaX Editor` | Modal title. |
152
- | `insertText` | `Insert` | Submit button text when inserting. |
153
- | `updateText` | `Update` | Submit button text when updating. |
154
- | `cancelText` | `Cancel` | Cancel button text. |
155
- | `closeOnBackdrop` | `true` | Whether clicking the backdrop closes the modal. |
156
-
157
- ### Editor options
158
-
159
- | Option | Default | Description |
160
- | --- | --- | --- |
161
- | `height` | `100%` | Embedded editor height. |
162
- | `autofocus` | `true` | Whether the embedded editor should autofocus. |
163
- | `assets` | `{}` | Optional Kity runtime asset overrides. |
164
- | `render.fontsize` | `40` | Formula render font size. |
165
-
166
- ## Exported API
167
-
168
- | Export | Description |
169
- | --- | --- |
170
- | `FormulaXNode` | Default FormulaX Tiptap node extension. |
171
- | `createFormulaXNode` | Creates a FormulaX node extension, optionally with custom options. |
172
- | `resolveOptions` | Resolves user options into required defaults. |
173
- | `openFormulaXTiptapModal` | Opens the FormulaX modal directly. |
174
- | `FORMULAX_NODE_NAME` | Default Tiptap node name. |
175
- | `createFormulaXPayload` | Parses LaTeX into a FormulaX document. |
176
- | `serializeFormulaXPayload` | Serializes a FormulaX document back to LaTeX. |
177
-
178
- ## Development
179
-
180
- From the repository root:
181
-
182
- ```bash
183
- pnpm install
184
- pnpm dev:tiptap
185
- ```
186
-
187
- Build only this package:
188
-
189
- ```bash
190
- pnpm --filter @formulaxjs/tiptap build
191
- ```
192
-
193
- Run package tests:
194
-
195
- ```bash
196
- pnpm --filter @formulaxjs/tiptap test
197
- ```
198
-
199
- Run package type checking:
200
-
201
- ```bash
202
- pnpm --filter @formulaxjs/tiptap typecheck
203
- ```
204
-
205
- ## Demo
206
-
207
- Local demo:
208
-
209
- ```bash
210
- pnpm dev:tiptap
211
- ```
212
-
213
- GitHub Pages demo:
214
-
215
- [https://vndmea.github.io/formulaX/tiptap/](https://vndmea.github.io/formulaX/tiptap/)
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/)