@formulaxjs/tiptap 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 CHANGED
@@ -1,236 +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 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
- pnpm add @formulaxjs/tiptap
42
- pnpm add @tiptap/core
43
- ```
44
-
45
- Inside the FormulaX workspace, use the workspace package directly:
46
-
47
- ```bash
48
- pnpm install
49
- pnpm dev:tiptap
50
- ```
51
-
52
- ## Basic usage
53
-
54
- Create the FormulaX node extension and add it to the Tiptap extension list:
55
-
56
- ```ts
57
- import { Editor } from '@tiptap/core';
58
- import StarterKit from '@tiptap/starter-kit';
59
- import { createFormulaXNode } from '@formulaxjs/tiptap';
60
-
61
- const editor = new Editor({
62
- element: document.querySelector('#editor')!,
63
- extensions: [
64
- StarterKit,
65
- createFormulaXNode(),
66
- ],
67
- content: '<p>Click the toolbar button to insert a formula.</p>',
68
- });
69
- ```
70
-
71
- To open the FormulaX modal programmatically:
72
-
73
- ```ts
74
- editor.commands.openFormulaX();
75
- ```
76
-
77
- ## 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 formulaNode = createFormulaXNode(undefined, {
121
- renderer: createKityFormulaRenderer({
122
- fontSize: 44,
123
- }),
124
- });
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
- };
145
- editor?: {
146
- height?: number | string;
147
- autofocus?: boolean;
148
- assets?: Partial<KityEditorAssets>;
149
- render?: {
150
- 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
- | --- | --- | --- |
182
- | `height` | `100%` | Embedded editor height. |
183
- | `autofocus` | `true` | Whether the embedded editor should autofocus. |
184
- | `assets` | `{}` | Optional Kity runtime asset overrides. |
185
- | `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/)
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/)
package/README.zh-CN.md CHANGED
@@ -4,7 +4,7 @@
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
- pnpm add @formulaxjs/tiptap
42
- pnpm add @tiptap/core
41
+ npm install @formulaxjs/tiptap @tiptap/core
43
42
  ```
44
43
 
45
44
  在 FormulaX 工作空间内,直接使用 workspace 包:
@@ -107,37 +106,37 @@ Tiptap 节点中只保存 LaTeX 源内容:
107
106
  }
108
107
  ```
109
108
 
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 formulaNode = createFormulaXNode(undefined, {
121
- renderer: createKityFormulaRenderer({
122
- fontSize: 44,
123
- }),
124
- });
125
- ```
109
+ 节点视图会根据保存的 LaTeX 在运行时渲染 SVG。生成的 DOM 会带有 `data-formulax="true"` 和 `data-formulax-latex`,但这些渲染后的 DOM 不是持久化数据的真实来源。
110
+
111
+ ## 自定义 renderer
112
+
113
+ 该适配器支持 `renderer` 配置项。默认值是来自 `@formulaxjs/renderer-kity` 的 `createKityFormulaRenderer()`。
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
+ ```
126
125
 
127
126
  ## 配置项
128
127
 
129
128
  ```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;
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;
141
140
  updateText?: string;
142
141
  cancelText?: string;
143
142
  closeOnBackdrop?: boolean;
@@ -158,12 +157,12 @@ interface FormulaXTiptapOptions {
158
157
  | `name` | `formulaX` | 用于文档 schema 的 Tiptap 节点名。 |
159
158
  | `formulaClassName` | `formulax-math` | 渲染后公式节点使用的 CSS class。 |
160
159
  | `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 编辑器配置。 |
160
+ | `cursorStyle` | `pointer` | 渲染后公式节点的鼠标光标样式。 |
161
+ | `initialLatex` | 空字符串 | 插入新公式时的初始 LaTeX。 |
162
+ | `renderer` | `createKityFormulaRenderer()` | node view 中用于只读公式输出的 renderer。 |
163
+ | `preload` | `idle` | 控制在浏览器空闲时、宿主 hover/focus 时,或完全不预加载 FormulaX runtime。 |
164
+ | `modal` | 见下方 | 弹窗文案和关闭行为。 |
165
+ | `editor` | 见下方 | 内嵌 FormulaX 编辑器配置。 |
167
166
 
168
167
  ### Modal 配置
169
168