@formulaxjs/tinymce 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
@@ -58,16 +58,32 @@ Register the FormulaX TinyMCE plugin before calling `tinymce.init`:
58
58
  import tinymce from 'tinymce';
59
59
  import { registerFormulaXTinyMcePlugin } from '@formulaxjs/tinymce';
60
60
 
61
- registerFormulaXTinyMcePlugin(tinymce, {
62
- toolbarText: 'FormulaX',
63
- tooltip: 'Insert or edit formula',
61
+ registerFormulaXTinyMcePlugin(tinymce, {
62
+ pluginName: 'formulax', // TinyMCE plugin id used in the plugins list
63
+ buttonName: 'formulax', // toolbar button id used in the toolbar string
64
+ menuItemName: 'formulax', // menu item id if you also expose the action in menus
65
+ toolbarText: 'FormulaX',
66
+ tooltip: 'Insert or edit formula',
67
+ cursorStyle: 'pointer', // cursor applied to generated formula nodes
68
+ formulaClassName: 'formulax-math', // DOM class written on formula wrappers
69
+ formulaAttributeName: 'data-formulax-latex', // attribute that stores source LaTeX
70
+ initialLatex: '\\sqrt{x}', // default LaTeX for newly inserted formulas
71
+ preload: 'idle', // 'idle' | 'hover' | false
64
72
  modal: {
65
73
  title: 'FormulaX Editor',
74
+ insertText: 'Insert',
75
+ updateText: 'Update',
76
+ cancelText: 'Cancel',
77
+ width: '1100px',
78
+ height: 'auto',
79
+ closeOnBackdrop: true,
66
80
  },
67
81
  editor: {
82
+ // forwarded to the embedded FormulaX editor instance
68
83
  locale: 'zh_CN', // optional, defaults to en_US
69
- height: '100%',
84
+ height: 320,
70
85
  autofocus: true,
86
+ assets: {},
71
87
  render: { fontsize: 40 },
72
88
  },
73
89
  });
@@ -168,7 +184,7 @@ registerFormulaXTinyMcePlugin(tinymce, {
168
184
  ## Options
169
185
 
170
186
  ```ts
171
- interface FormulaXTinyMceOptions {
187
+ interface FormulaXTinyMceOptions {
172
188
  pluginName?: string;
173
189
  buttonName?: string;
174
190
  menuItemName?: string;
@@ -177,13 +193,13 @@ interface FormulaXTinyMceOptions {
177
193
  cursorStyle?: string;
178
194
  formulaClassName?: string;
179
195
  formulaAttributeName?: string;
180
- renderer?: FormulaRenderer;
181
- preload?: FormulaXEditorPreloadMode;
182
- initialLatex?: string;
183
- modal?: FormulaXModalOptions;
184
- editor?: FormulaXEditorOptions;
185
- }
186
- ```
196
+ renderer?: FormulaRenderer;
197
+ preload?: FormulaXEditorPreloadMode;
198
+ initialLatex?: string;
199
+ modal?: FormulaXModalOptions;
200
+ editor?: Omit<FormulaXEditorOptions, 'initialLatex'>;
201
+ }
202
+ ```
187
203
 
188
204
  | Option | Default | Description |
189
205
  | --- | --- | --- |
package/README.zh-CN.md CHANGED
@@ -58,16 +58,32 @@ pnpm dev:tinymce
58
58
  import tinymce from 'tinymce';
59
59
  import { registerFormulaXTinyMcePlugin } from '@formulaxjs/tinymce';
60
60
 
61
- registerFormulaXTinyMcePlugin(tinymce, {
62
- toolbarText: 'FormulaX',
63
- tooltip: '插入或编辑公式',
61
+ registerFormulaXTinyMcePlugin(tinymce, {
62
+ pluginName: 'formulax', // TinyMCE 插件名,需要和 plugins 配置一致
63
+ buttonName: 'formulax', // 工具栏按钮名,需要和 toolbar 配置一致
64
+ menuItemName: 'formulax', // 如果菜单里也要出现该操作,可复用这个标识
65
+ toolbarText: 'FormulaX',
66
+ tooltip: '插入或编辑公式',
67
+ cursorStyle: 'pointer', // 应用于公式节点的鼠标样式
68
+ formulaClassName: 'formulax-math', // 公式外层 DOM class
69
+ formulaAttributeName: 'data-formulax-latex', // 保存源 LaTeX 的属性名
70
+ initialLatex: '\\sqrt{x}', // 新插入公式的默认内容
71
+ preload: 'idle', // 'idle' | 'hover' | false
64
72
  modal: {
65
73
  title: 'FormulaX 公式编辑器',
74
+ insertText: 'Insert',
75
+ updateText: 'Update',
76
+ cancelText: 'Cancel',
77
+ width: '1100px',
78
+ height: 'auto',
79
+ closeOnBackdrop: true,
66
80
  },
67
81
  editor: {
82
+ // 这些配置会透传给内嵌的 FormulaX 编辑器
68
83
  locale: 'zh_CN', // 可选,默认 en_US
69
- height: '100%',
84
+ height: 320,
70
85
  autofocus: true,
86
+ assets: {},
71
87
  render: { fontsize: 40 },
72
88
  },
73
89
  });
@@ -168,7 +184,7 @@ registerFormulaXTinyMcePlugin(tinymce, {
168
184
  ## 配置项
169
185
 
170
186
  ```ts
171
- interface FormulaXTinyMceOptions {
187
+ interface FormulaXTinyMceOptions {
172
188
  pluginName?: string;
173
189
  buttonName?: string;
174
190
  menuItemName?: string;
@@ -177,13 +193,13 @@ interface FormulaXTinyMceOptions {
177
193
  cursorStyle?: string;
178
194
  formulaClassName?: string;
179
195
  formulaAttributeName?: string;
180
- renderer?: FormulaRenderer;
181
- preload?: FormulaXEditorPreloadMode;
182
- initialLatex?: string;
183
- modal?: FormulaXModalOptions;
184
- editor?: FormulaXEditorOptions;
185
- }
186
- ```
196
+ renderer?: FormulaRenderer;
197
+ preload?: FormulaXEditorPreloadMode;
198
+ initialLatex?: string;
199
+ modal?: FormulaXModalOptions;
200
+ editor?: Omit<FormulaXEditorOptions, 'initialLatex'>;
201
+ }
202
+ ```
187
203
 
188
204
  | 配置项 | 默认值 | 说明 |
189
205
  | --- | --- | --- |
@@ -0,0 +1,125 @@
1
+ import { FormulaDoc } from '@formulaxjs/core';
2
+ import { CreateFormulaMarkupOptions, FormulaRenderer } from '@formulaxjs/renderer';
3
+ export { DEFAULT_FORMULA_ATTRIBUTE, DEFAULT_FORMULA_CLASS, FORMULA_FLAG_ATTRIBUTE, findFormulaElement, getFormulaLatexFromElement, isFormulaElement, replaceFormulaElement } from '@formulaxjs/renderer';
4
+ import { FormulaXEditorPreloadMode, FormulaXEditorOptions } from '@formulaxjs/editor';
5
+
6
+ declare function createTinyMceFormulaMarkup(latex: string, options?: CreateFormulaMarkupOptions): string;
7
+ declare function parseTinyMceFormulaMarkup(latex: string): FormulaDoc;
8
+ declare function serializeTinyMceFormulaMarkup(doc: FormulaDoc, options?: CreateFormulaMarkupOptions): string;
9
+
10
+ interface TinyMceLike {
11
+ PluginManager?: {
12
+ add: (name: string, callback: (editor: TinyMceEditorLike, pluginUrl?: string) => unknown) => void;
13
+ };
14
+ majorVersion?: string | number;
15
+ minorVersion?: string | number;
16
+ }
17
+ interface TinyMceEditorLike {
18
+ id?: string;
19
+ insertContent: (content: string) => void;
20
+ addCommand: (name: string, callback: (...args: unknown[]) => void) => void;
21
+ execCommand: (name: string, ui?: boolean, value?: unknown) => void;
22
+ on: (name: string, callback: (event: any) => void) => void;
23
+ off?: (name: string, callback: (event: any) => void) => void;
24
+ ui?: {
25
+ registry?: {
26
+ addButton?: (name: string, config: Record<string, unknown>) => void;
27
+ addMenuItem?: (name: string, config: Record<string, unknown>) => void;
28
+ addIcon?: (name: string, svg: string) => void;
29
+ };
30
+ };
31
+ selection?: {
32
+ getNode?: () => HTMLElement;
33
+ getRng?: () => Range;
34
+ setRng?: (range: Range) => void;
35
+ select?: (node: HTMLElement) => void;
36
+ collapse?: (toStart?: boolean) => void;
37
+ };
38
+ undoManager?: {
39
+ transact?: (callback: () => void) => void;
40
+ add?: () => void;
41
+ };
42
+ dom?: {
43
+ encode?: (value: string) => string;
44
+ decode?: (value: string) => string;
45
+ };
46
+ schema?: {
47
+ addValidElements?: (validElements: string) => void;
48
+ };
49
+ getDoc?: () => Document;
50
+ getWin?: () => Window;
51
+ getBody?: () => HTMLElement;
52
+ focus?: () => void;
53
+ nodeChanged?: () => void;
54
+ dispatch?: (name: string, args?: Record<string, unknown>) => void;
55
+ fire?: (name: string, args?: Record<string, unknown>) => void;
56
+ }
57
+ interface FormulaXTinyMceOptions {
58
+ pluginName?: string;
59
+ buttonName?: string;
60
+ menuItemName?: string;
61
+ toolbarText?: string;
62
+ tooltip?: string;
63
+ cursorStyle?: string;
64
+ formulaClassName?: string;
65
+ formulaAttributeName?: string;
66
+ renderer?: FormulaRenderer;
67
+ preload?: FormulaXEditorPreloadMode;
68
+ modal?: FormulaXModalOptions;
69
+ initialLatex?: string;
70
+ editor?: Omit<FormulaXEditorOptions, 'initialLatex'>;
71
+ }
72
+ interface FormulaXModalOptions {
73
+ title?: string;
74
+ insertText?: string;
75
+ updateText?: string;
76
+ cancelText?: string;
77
+ width?: string;
78
+ height?: string;
79
+ closeOnBackdrop?: boolean;
80
+ }
81
+ interface RequiredFormulaXTinyMceOptions {
82
+ pluginName: string;
83
+ buttonName: string;
84
+ menuItemName: string;
85
+ toolbarText: string;
86
+ tooltip: string;
87
+ cursorStyle: string;
88
+ formulaClassName: string;
89
+ formulaAttributeName: string;
90
+ initialLatex: string;
91
+ renderer: FormulaRenderer;
92
+ preload: FormulaXEditorPreloadMode;
93
+ modal: Required<FormulaXModalOptions>;
94
+ editor: Required<Omit<FormulaXEditorOptions, 'initialLatex'>>;
95
+ }
96
+ interface FormulaXModalOpenOptions {
97
+ editor: TinyMceEditorLike;
98
+ target?: HTMLElement | null;
99
+ initialLatex?: string;
100
+ options: RequiredFormulaXTinyMceOptions;
101
+ }
102
+
103
+ interface TinyMceCompat {
104
+ major: number;
105
+ insertContent: (html: string) => void;
106
+ dispatchEvent: (name: string, detail?: Record<string, unknown>) => void;
107
+ getSelectedFormulaElement: () => HTMLElement | null;
108
+ getEditorDocument: () => Document;
109
+ getEditorWindow: () => Window;
110
+ getEditorBody: () => HTMLElement | null;
111
+ focus: () => void;
112
+ }
113
+ declare function getTinyMceMajorVersion(tinymce?: TinyMceLike): number;
114
+ declare function createTinyMceCompat(editor: TinyMceEditorLike, tinymce?: TinyMceLike): TinyMceCompat;
115
+ declare function warnUnsupportedTinyMceVersion(tinymce?: TinyMceLike): void;
116
+
117
+ declare function resolveOptions(options?: FormulaXTinyMceOptions): RequiredFormulaXTinyMceOptions;
118
+ declare function registerFormulaXTinyMcePlugin(tinymce: TinyMceLike, options?: FormulaXTinyMceOptions): void;
119
+
120
+ interface OpenFormulaXModalResult {
121
+ close: () => void;
122
+ }
123
+ declare function openFormulaXOverlayModal(input: FormulaXModalOpenOptions): OpenFormulaXModalResult;
124
+
125
+ export { type FormulaXModalOpenOptions, type FormulaXModalOptions, type FormulaXTinyMceOptions, type RequiredFormulaXTinyMceOptions, type TinyMceEditorLike, type TinyMceLike, createTinyMceCompat, createTinyMceFormulaMarkup, getTinyMceMajorVersion, openFormulaXOverlayModal, parseTinyMceFormulaMarkup, registerFormulaXTinyMcePlugin, resolveOptions, serializeTinyMceFormulaMarkup, warnUnsupportedTinyMceVersion };
@@ -0,0 +1,125 @@
1
+ import { FormulaDoc } from '@formulaxjs/core';
2
+ import { CreateFormulaMarkupOptions, FormulaRenderer } from '@formulaxjs/renderer';
3
+ export { DEFAULT_FORMULA_ATTRIBUTE, DEFAULT_FORMULA_CLASS, FORMULA_FLAG_ATTRIBUTE, findFormulaElement, getFormulaLatexFromElement, isFormulaElement, replaceFormulaElement } from '@formulaxjs/renderer';
4
+ import { FormulaXEditorPreloadMode, FormulaXEditorOptions } from '@formulaxjs/editor';
5
+
6
+ declare function createTinyMceFormulaMarkup(latex: string, options?: CreateFormulaMarkupOptions): string;
7
+ declare function parseTinyMceFormulaMarkup(latex: string): FormulaDoc;
8
+ declare function serializeTinyMceFormulaMarkup(doc: FormulaDoc, options?: CreateFormulaMarkupOptions): string;
9
+
10
+ interface TinyMceLike {
11
+ PluginManager?: {
12
+ add: (name: string, callback: (editor: TinyMceEditorLike, pluginUrl?: string) => unknown) => void;
13
+ };
14
+ majorVersion?: string | number;
15
+ minorVersion?: string | number;
16
+ }
17
+ interface TinyMceEditorLike {
18
+ id?: string;
19
+ insertContent: (content: string) => void;
20
+ addCommand: (name: string, callback: (...args: unknown[]) => void) => void;
21
+ execCommand: (name: string, ui?: boolean, value?: unknown) => void;
22
+ on: (name: string, callback: (event: any) => void) => void;
23
+ off?: (name: string, callback: (event: any) => void) => void;
24
+ ui?: {
25
+ registry?: {
26
+ addButton?: (name: string, config: Record<string, unknown>) => void;
27
+ addMenuItem?: (name: string, config: Record<string, unknown>) => void;
28
+ addIcon?: (name: string, svg: string) => void;
29
+ };
30
+ };
31
+ selection?: {
32
+ getNode?: () => HTMLElement;
33
+ getRng?: () => Range;
34
+ setRng?: (range: Range) => void;
35
+ select?: (node: HTMLElement) => void;
36
+ collapse?: (toStart?: boolean) => void;
37
+ };
38
+ undoManager?: {
39
+ transact?: (callback: () => void) => void;
40
+ add?: () => void;
41
+ };
42
+ dom?: {
43
+ encode?: (value: string) => string;
44
+ decode?: (value: string) => string;
45
+ };
46
+ schema?: {
47
+ addValidElements?: (validElements: string) => void;
48
+ };
49
+ getDoc?: () => Document;
50
+ getWin?: () => Window;
51
+ getBody?: () => HTMLElement;
52
+ focus?: () => void;
53
+ nodeChanged?: () => void;
54
+ dispatch?: (name: string, args?: Record<string, unknown>) => void;
55
+ fire?: (name: string, args?: Record<string, unknown>) => void;
56
+ }
57
+ interface FormulaXTinyMceOptions {
58
+ pluginName?: string;
59
+ buttonName?: string;
60
+ menuItemName?: string;
61
+ toolbarText?: string;
62
+ tooltip?: string;
63
+ cursorStyle?: string;
64
+ formulaClassName?: string;
65
+ formulaAttributeName?: string;
66
+ renderer?: FormulaRenderer;
67
+ preload?: FormulaXEditorPreloadMode;
68
+ modal?: FormulaXModalOptions;
69
+ initialLatex?: string;
70
+ editor?: Omit<FormulaXEditorOptions, 'initialLatex'>;
71
+ }
72
+ interface FormulaXModalOptions {
73
+ title?: string;
74
+ insertText?: string;
75
+ updateText?: string;
76
+ cancelText?: string;
77
+ width?: string;
78
+ height?: string;
79
+ closeOnBackdrop?: boolean;
80
+ }
81
+ interface RequiredFormulaXTinyMceOptions {
82
+ pluginName: string;
83
+ buttonName: string;
84
+ menuItemName: string;
85
+ toolbarText: string;
86
+ tooltip: string;
87
+ cursorStyle: string;
88
+ formulaClassName: string;
89
+ formulaAttributeName: string;
90
+ initialLatex: string;
91
+ renderer: FormulaRenderer;
92
+ preload: FormulaXEditorPreloadMode;
93
+ modal: Required<FormulaXModalOptions>;
94
+ editor: Required<Omit<FormulaXEditorOptions, 'initialLatex'>>;
95
+ }
96
+ interface FormulaXModalOpenOptions {
97
+ editor: TinyMceEditorLike;
98
+ target?: HTMLElement | null;
99
+ initialLatex?: string;
100
+ options: RequiredFormulaXTinyMceOptions;
101
+ }
102
+
103
+ interface TinyMceCompat {
104
+ major: number;
105
+ insertContent: (html: string) => void;
106
+ dispatchEvent: (name: string, detail?: Record<string, unknown>) => void;
107
+ getSelectedFormulaElement: () => HTMLElement | null;
108
+ getEditorDocument: () => Document;
109
+ getEditorWindow: () => Window;
110
+ getEditorBody: () => HTMLElement | null;
111
+ focus: () => void;
112
+ }
113
+ declare function getTinyMceMajorVersion(tinymce?: TinyMceLike): number;
114
+ declare function createTinyMceCompat(editor: TinyMceEditorLike, tinymce?: TinyMceLike): TinyMceCompat;
115
+ declare function warnUnsupportedTinyMceVersion(tinymce?: TinyMceLike): void;
116
+
117
+ declare function resolveOptions(options?: FormulaXTinyMceOptions): RequiredFormulaXTinyMceOptions;
118
+ declare function registerFormulaXTinyMcePlugin(tinymce: TinyMceLike, options?: FormulaXTinyMceOptions): void;
119
+
120
+ interface OpenFormulaXModalResult {
121
+ close: () => void;
122
+ }
123
+ declare function openFormulaXOverlayModal(input: FormulaXModalOpenOptions): OpenFormulaXModalResult;
124
+
125
+ export { type FormulaXModalOpenOptions, type FormulaXModalOptions, type FormulaXTinyMceOptions, type RequiredFormulaXTinyMceOptions, type TinyMceEditorLike, type TinyMceLike, createTinyMceCompat, createTinyMceFormulaMarkup, getTinyMceMajorVersion, openFormulaXOverlayModal, parseTinyMceFormulaMarkup, registerFormulaXTinyMcePlugin, resolveOptions, serializeTinyMceFormulaMarkup, warnUnsupportedTinyMceVersion };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formulaxjs/tinymce",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "require": "./dist/index.cjs"
28
28
  }
29
29
  },
30
- "unpkg": "./dist/browser/index.global.js",
30
+ "unpkg": "./dist/index.global.js",
31
31
  "files": [
32
32
  "dist"
33
33
  ],
@@ -35,10 +35,10 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@formulaxjs/core": "0.1.0",
39
- "@formulaxjs/editor": "0.4.0",
40
- "@formulaxjs/renderer": "0.2.0",
41
- "@formulaxjs/renderer-kity": "0.3.0"
38
+ "@formulaxjs/core": "0.1.1",
39
+ "@formulaxjs/editor": "0.4.1",
40
+ "@formulaxjs/renderer-kity": "0.3.1",
41
+ "@formulaxjs/renderer": "0.2.1"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "tinymce": ">=5 <9"