formula-composer 0.0.0-stage → 0.1.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/LICENSE +22 -0
- package/README.md +122 -2
- package/angular/esm2020/formula-composer-tinymce-angular.mjs +4 -0
- package/angular/esm2020/lib/formula-composer.directive.mjs +52 -0
- package/angular/esm2020/lib/formula-composer.module.mjs +21 -0
- package/angular/esm2020/lib/init.mjs +9 -0
- package/angular/esm2020/lib/provide.mjs +11 -0
- package/angular/esm2020/public-api.mjs +8 -0
- package/angular/fesm2015/formula-composer-tinymce-angular.mjs +99 -0
- package/angular/fesm2020/formula-composer-tinymce-angular.mjs +101 -0
- package/angular/formula-composer-tinymce-angular.d.ts +5 -0
- package/angular/lib/formula-composer.directive.d.ts +22 -0
- package/angular/lib/formula-composer.module.d.ts +15 -0
- package/angular/lib/init.d.ts +23 -0
- package/angular/lib/provide.d.ts +10 -0
- package/angular/package.json +10 -0
- package/angular/public-api.d.ts +5 -0
- package/dist/editor-ui/catalog-types.d.ts +30 -0
- package/dist/editor-ui/catalog.generated.d.ts +2 -0
- package/dist/editor-ui/commands.d.ts +44 -0
- package/dist/editor-ui/dom.d.ts +8 -0
- package/dist/editor-ui/editor.d.ts +86 -0
- package/dist/editor-ui/icons.d.ts +5 -0
- package/dist/editor-ui/index.d.ts +9 -0
- package/dist/editor-ui/index.js +119 -0
- package/dist/editor-ui/modal.d.ts +81 -0
- package/dist/editor-ui/periodic.d.ts +8 -0
- package/dist/editor-ui/pickers.d.ts +23 -0
- package/dist/editor-ui/popover.d.ts +24 -0
- package/dist/editor-ui/special-chars.generated.d.ts +10 -0
- package/dist/editor-ui/strings.d.ts +48 -0
- package/dist/editor-ui/styles.d.ts +3 -0
- package/dist/editor-ui/toolbar.d.ts +47 -0
- package/dist/integration/content.d.ts +52 -0
- package/dist/integration/controller.d.ts +76 -0
- package/dist/integration/index.d.ts +3 -0
- package/dist/integration/index.js +1 -0
- package/dist/integration/options.d.ts +46 -0
- package/dist/math-core/a11y.d.ts +3 -0
- package/dist/math-core/caret-speech.d.ts +3 -0
- package/dist/math-core/editor.d.ts +212 -0
- package/dist/math-core/functions.d.ts +8 -0
- package/dist/math-core/history.d.ts +16 -0
- package/dist/math-core/index.d.ts +17 -0
- package/dist/math-core/index.js +3 -0
- package/dist/math-core/latex/parse.d.ts +11 -0
- package/dist/math-core/latex/serialize.d.ts +4 -0
- package/dist/math-core/latex/symbols.d.ts +32 -0
- package/dist/math-core/mathml.d.ts +33 -0
- package/dist/math-core/model.d.ts +69 -0
- package/dist/math-core/safe-xml.d.ts +7 -0
- package/dist/math-core/sanitize.d.ts +6 -0
- package/dist/math-core/tree-index.d.ts +26 -0
- package/dist/math-core/xml.d.ts +21 -0
- package/dist/renderer/alphanumerics.d.ts +3 -0
- package/dist/renderer/attributes.d.ts +10 -0
- package/dist/renderer/core.d.ts +13 -0
- package/dist/renderer/image.d.ts +29 -0
- package/dist/renderer/index.d.ts +22 -0
- package/dist/renderer/index.js +9 -0
- package/dist/renderer/layout.d.ts +14 -0
- package/dist/renderer/styles.d.ts +9 -0
- package/dist/renderer/view.d.ts +30 -0
- package/dist/renderer/vnode.d.ts +25 -0
- package/dist/tinymce/browser/plugin.min.js +129 -0
- package/dist/tinymce/compat.d.ts +24 -0
- package/dist/tinymce/index.d.ts +5 -0
- package/dist/tinymce/index.js +1 -0
- package/dist/tinymce/init.d.ts +22 -0
- package/dist/tinymce/plugin.d.ts +30 -0
- package/dist/tinymce/tinymce-types.d.ts +127 -0
- package/dist/tinymce-react/editor.d.ts +19 -0
- package/dist/tinymce-react/index.d.ts +3 -0
- package/dist/tinymce-react/index.js +1 -0
- package/dist/tinymce-react/init.d.ts +23 -0
- package/editor-ui/package.json +6 -0
- package/images/edit-formula.png +0 -0
- package/images/editor-content.png +0 -0
- package/integration/package.json +6 -0
- package/math-core/package.json +6 -0
- package/package.json +101 -4
- package/react/package.json +6 -0
- package/renderer/package.json +6 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ButtonApi, TinyEditor } from './tinymce-types.js';
|
|
2
|
+
/** Holds a pasted formula image's `src` while TinyMCE 5 parses the paste; the `data-mce-` prefix keeps it out of saved HTML. */
|
|
3
|
+
export declare const PARKED_SRC_ATTRIBUTE = "data-mce-sw-src";
|
|
4
|
+
/** TinyMCE 5 is the only supported major without the `editor.options` registry. */
|
|
5
|
+
export declare function isTinyMCE5(editor: TinyEditor): boolean;
|
|
6
|
+
/** Registers an object init option. TinyMCE 5 has no option registry and reads init options as given. */
|
|
7
|
+
export declare function registerObjectOption(editor: TinyEditor, name: string): void;
|
|
8
|
+
/** An init option: `editor.options` on TinyMCE 6+, `editor.getParam` on TinyMCE 5. */
|
|
9
|
+
export declare function readOption(editor: TinyEditor, name: string): unknown;
|
|
10
|
+
/** Whether the selection can be edited: `selection.isEditable()`, or on TinyMCE 5 the nearest `contenteditable` inside the body. */
|
|
11
|
+
export declare function isSelectionEditable(editor: TinyEditor): boolean;
|
|
12
|
+
/** Enables or disables a toolbar button or menu item: `setEnabled` on TinyMCE 6+, `setDisabled` on TinyMCE 5. */
|
|
13
|
+
export declare function setControlEnabled(api: ButtonApi, enabled: boolean): void;
|
|
14
|
+
/** Moves the `src` of each formula image to {@link PARKED_SRC_ATTRIBUTE}. */
|
|
15
|
+
export declare function parkFormulaSources(html: string, isFormula: (node: unknown) => boolean): string;
|
|
16
|
+
/**
|
|
17
|
+
* Keeps formula images (SVG `data:` images) intact on TinyMCE 5, which TinyMCE 6+ does by itself:
|
|
18
|
+
* - TinyMCE 5's image scanner turns every `data:` image into a blob, and garbles data URIs that are not base64;
|
|
19
|
+
* - its paste plugin removes pasted `data:` images unless `paste_data_images` is on.
|
|
20
|
+
* Formula images are left out of the scanner, and a pasted formula's `src` is parked while the paste is parsed.
|
|
21
|
+
* TinyMCE runs attribute filters after every node filter, so the `src` comes back after the paste plugin's `img` filter.
|
|
22
|
+
* Register after the `BeforeSetContent` handler that converts content for editing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function protectFormulaImages(editor: TinyEditor, isFormula: (node: unknown) => boolean): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type ContentContext, DEFAULT_IMAGE_CLASS, DEFAULT_MATHML_ATTRIBUTE, type FormulaComposerOptions, type ParsedFormula, type ResolvedOptions, type SaveMode, type SylarWirisOptions, formulaImageAttributes, isFormulaImage, readFormula, resolveOptions, toEditingHtml, toSavedHtml, } from '../integration/index';
|
|
2
|
+
export { BUTTON_NAME, type FormulaComposerInstance, ICON_NAME, LEGACY_BUTTON_NAME, LEGACY_OPTION_NAME, LEGACY_PLUGIN_NAME, MENU_ITEM_NAME, OPTION_NAME, PLUGIN_NAME, type SylarWirisInstance, globalTinyMCE, isTinyMCEGlobal, registerFormulaComposer, registerSylarWiris, setupFormulaComposer, setupSylarWiris, } from './plugin.js';
|
|
3
|
+
export { type ToolbarGroup, type ToolbarSetting, appendFormulaButton, appendFormulaPlugin, readFormulaOptions, withFormulaComposer } from './init.js';
|
|
4
|
+
export type { TinyEditor, TinyMCEGlobal } from './tinymce-types.js';
|
|
5
|
+
export { upgradeMathElements } from '../renderer/index';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DEFAULT_IMAGE_CLASS as pn,DEFAULT_MATHML_ATTRIBUTE as mn,formulaImageAttributes as fn,isFormulaImage as gn,readFormula as yn,resolveOptions as dn,toEditingHtml as En,toSavedHtml as An}from"../integration/index.js";import{FORMULA_ICON_SVG as D,FormulaController as W,resolveOptions as Y}from"../integration/index.js";var m="data-mce-sw-src";function k(n){return n.options===void 0}function A(n,t){n.options?.register(t,{processor:"object",default:{}})}function f(n,t){return n.options?n.options.get(t):n.getParam?.(t)}function h(n){let t=n.getBody(),e=n.selection.getNode();if(!t?.contains(e))return!1;for(let o=e;o!==null&&o!==t;o=o.parentElement){let s=o.getAttribute("contenteditable");if(s==="false")return!1;if(s==="true")return!0}return!0}function T(n){let{selection:t}=n;return t.isEditable?t.isEditable():h(n)}function _(n,t){n.setEnabled?n.setEnabled(t):n.setDisabled?.(!t)}function j(n,t){let e=document.createElement("template");e.innerHTML=n;let o=!1;for(let s of Array.from(e.content.querySelectorAll("img"))){let l=s.getAttribute("src");l===null||!t(s)||(s.setAttribute(m,l),s.removeAttribute("src"),o=!0)}return o?e.innerHTML:n}function H(n){for(let t of n)t.attr("src",t.attr(m)??null),t.attr(m,null)}function F(n,t){k(n)&&(n.on("PreInit",()=>{n.editorUpload?.addFilter(e=>!t(e)),n.parser?.addAttributeFilter(m,H)}),n.on("BeforeSetContent",e=>{e.paste!==!0||typeof e.content!="string"||(e.content=j(e.content,t))}))}var i="formulacomposer",a="formulaComposer",S="formulaComposer",u="formulaComposer",g="formula-composer",y="sylarwiris",c="sylarMathType",p="sylarWiris",z={internalAttributePrefix:"data-mce-",staleAttribute:"data-mce-sw-stale",imageAttributes:{"data-mce-resize":"false"}},$=2;function K(n){return{uiDocument:document,isRtl:()=>f(n,"directionality")==="rtl",canEdit:()=>n.initialized&&!n.mode.isReadOnly()&&T(n),getSelectedNode:()=>n.selection.getNode(),getSelectionRange:()=>n.selection.getRng(),saveSelection:()=>n.selection.getBookmark($,!0),insertFormula:(t,e)=>{e!==null&&n.selection.moveToBookmark(e),n.insertContent(n.dom.createHTML("img",t))},updateFormula:(t,e)=>{n.undoManager.transact(()=>n.dom.setAttribs(t,e)),t.isConnected&&n.selection.select(t),n.nodeChanged()},removeFormula:t=>{n.undoManager.transact(()=>n.dom.remove(t)),n.nodeChanged()},replaceText:(t,e,o,s)=>{n.undoManager.transact(()=>{t.replaceData(e,o-e,s),n.selection.setCursorLocation(t,e+s.length)}),n.nodeChanged()},selectFormula:t=>n.selection.select(t),getContentRoot:()=>n.initialized?n.getBody():null,refreshFormulas:t=>{let e=!n.isDirty()&&!n.undoManager.hasUndo();n.undoManager.ignore(()=>{for(let[o,s]of t)n.dom.setAttribs(o,s)}),e&&(n.undoManager.clear(),n.undoManager.add(),n.setDirty(!1))},focus:()=>n.focus()}}function b(n,t){let e=f(n,t);return typeof e=="object"&&e!==null?{...e}:{}}function C(n){A(n,u),A(n,p);let t={...b(n,p),...b(n,u)},e=Y(t,f(n,"language")),o=new W(K(n),{options:e,conventions:z}),s=()=>o.open(),l=r=>{let E=()=>_(r,!n.mode.isReadOnly()&&T(n));return n.on("NodeChange",E),n.initialized&&E(),()=>n.off("NodeChange",E)};n.ui.registry.addIcon(g,D);for(let r of[a,c])n.ui.registry.addButton(r,{icon:g,tooltip:o.strings.insertFormula,onAction:s,onSetup:l});for(let r of[S,c])n.ui.registry.addMenuItem(r,{icon:g,text:o.strings.menuItem,onAction:s,onSetup:l});return n.on("BeforeSetContent",r=>{typeof r.content!="string"||r.format==="raw"||(r.content=o.toEditingHtml(r.content,!1))}),F(n,r=>o.isFormula(r)),n.on("PastePreProcess",r=>{r.content=o.toEditingHtml(r.content,!0)}),n.on("GetContent",r=>{typeof r.content!="string"||r.selection===!0||r.format!==void 0&&r.format!=="html"||(r.content=o.toSavedHtml(r.content))}),n.on("dblclick",r=>{o.isFormula(r.target)&&(r.preventDefault(),o.editFormula(r.target))}),n.on("init",()=>o.refreshStaleImages()),n.on("remove",()=>o.destroy()),{options:e,open:s,isOpen:()=>o.isOpen()}}function G(n){if(typeof n!="object"||n===null||!("PluginManager"in n))return!1;let t=n.PluginManager;return typeof t=="object"&&t!==null&&"add"in t&&typeof t.add=="function"}function M(){let n=Reflect.get(globalThis,"tinymce");return G(n)?n:null}var I=new WeakSet,x=new WeakMap;function V(n){let t=x.get(n);if(t)return t;let e=C(n);return x.set(n,e),e}function d(n){if(!I.has(n)){I.add(n);for(let t of[i,y])n.PluginManager.add(t,V)}}var q=C,X=d;var J="formulacomposer",L=[a,c],Q=[i,y];function O(n){return n.every(t=>typeof t=="string")}function v(n){return n.every(t=>typeof t=="object"&&t!==null&&"items"in t&&Array.isArray(t.items))}function P(n){return n.split(/[\s|]+/).some(t=>L.includes(t))}function B(n){return n.some(t=>Q.includes(t))}function N(n){if(typeof n=="string")return P(n)?n:`${n} | ${a}`;if(!Array.isArray(n)||n.length===0)return n;if(O(n)){if(n.some(P))return n;let t=n[n.length-1]??"";return[...n.slice(0,-1),`${t} | ${a}`]}return v(n)?n.some(t=>t.items.some(e=>L.includes(e)))?n:[...n,{name:J,items:[a]}]:n}function R(n){if(Array.isArray(n))return B(n)?n:[...n,i];let t=(n??"").split(/[\s,]+/).filter(e=>e.length>0);return B(t)?n??i:[...t,i].join(" ")}function w(n,t){let e=Reflect.get(n,t);return typeof e=="object"&&e!==null?e:{}}function U(n){return{...w(n,p),...w(n,u)}}function Z(n){return typeof n=="string"||Array.isArray(n)&&O(n)?n:void 0}function nn(n){return typeof n=="boolean"||typeof n=="string"||Array.isArray(n)&&(O(n)||v(n))?N(n):n}function tn(n,t={}){let e=Reflect.get(n,"setup");return{...n,plugins:R(Z(Reflect.get(n,"plugins"))),toolbar:nn(Reflect.get(n,"toolbar")),[u]:{...t,...U(n)},setup:o=>{let s=M();s&&d(s),typeof e=="function"&&Reflect.apply(e,void 0,[o])}}}import{upgradeMathElements as Nn}from"../renderer/index.js";export{a as BUTTON_NAME,pn as DEFAULT_IMAGE_CLASS,mn as DEFAULT_MATHML_ATTRIBUTE,g as ICON_NAME,c as LEGACY_BUTTON_NAME,p as LEGACY_OPTION_NAME,y as LEGACY_PLUGIN_NAME,S as MENU_ITEM_NAME,u as OPTION_NAME,i as PLUGIN_NAME,N as appendFormulaButton,R as appendFormulaPlugin,fn as formulaImageAttributes,M as globalTinyMCE,gn as isFormulaImage,G as isTinyMCEGlobal,yn as readFormula,U as readFormulaOptions,d as registerFormulaComposer,X as registerSylarWiris,dn as resolveOptions,C as setupFormulaComposer,q as setupSylarWiris,En as toEditingHtml,An as toSavedHtml,Nn as upgradeMathElements,tn as withFormulaComposer};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FormulaComposerOptions } from '../integration/index';
|
|
2
|
+
/** TinyMCE `toolbar` option shapes that framework integrations pass through. */
|
|
3
|
+
export interface ToolbarGroup {
|
|
4
|
+
name?: string;
|
|
5
|
+
items: string[];
|
|
6
|
+
}
|
|
7
|
+
export type ToolbarSetting = boolean | string | string[] | ToolbarGroup[];
|
|
8
|
+
/**
|
|
9
|
+
* Appends the formula button to an explicit toolbar, unless the current or legacy button is already there.
|
|
10
|
+
* `undefined`/`true` (TinyMCE default toolbar) and `false` are returned unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export declare function appendFormulaButton(toolbar: ToolbarSetting | undefined): ToolbarSetting | undefined;
|
|
13
|
+
/** Adds the `formulacomposer` plugin to a TinyMCE `plugins` option, unless the current or legacy name is already there. */
|
|
14
|
+
export declare function appendFormulaPlugin(plugins: string | string[] | undefined): string | string[];
|
|
15
|
+
/** The Formula Composer options already in TinyMCE init options; `formulaComposer` wins over the legacy `sylarWiris`. */
|
|
16
|
+
export declare function readFormulaOptions(init: object): FormulaComposerOptions;
|
|
17
|
+
/**
|
|
18
|
+
* Adds Formula Composer to TinyMCE init options of any TinyMCE major or framework wrapper, keeping the caller's type:
|
|
19
|
+
* registers the bundled plugin before TinyMCE loads plugins, enables it, adds the toolbar button and merges
|
|
20
|
+
* `options` under the `formulaComposer` key (init wins).
|
|
21
|
+
*/
|
|
22
|
+
export declare function withFormulaComposer<T extends object>(init: T, options?: FormulaComposerOptions): T;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ResolvedOptions } from '../integration/index';
|
|
2
|
+
import type { TinyEditor, TinyMCEGlobal } from './tinymce-types.js';
|
|
3
|
+
export declare const PLUGIN_NAME = "formulacomposer";
|
|
4
|
+
export declare const BUTTON_NAME = "formulaComposer";
|
|
5
|
+
export declare const MENU_ITEM_NAME = "formulaComposer";
|
|
6
|
+
export declare const OPTION_NAME = "formulaComposer";
|
|
7
|
+
export declare const ICON_NAME = "formula-composer";
|
|
8
|
+
/** Names from before the rename to Formula Composer, still registered so existing configurations keep working. */
|
|
9
|
+
export declare const LEGACY_PLUGIN_NAME = "sylarwiris";
|
|
10
|
+
export declare const LEGACY_BUTTON_NAME = "sylarMathType";
|
|
11
|
+
export declare const LEGACY_OPTION_NAME = "sylarWiris";
|
|
12
|
+
export interface FormulaComposerInstance {
|
|
13
|
+
readonly options: ResolvedOptions;
|
|
14
|
+
/** Opens the editor for the selected formula, the `$$latex$$` at the caret, or a new formula. */
|
|
15
|
+
open(): void;
|
|
16
|
+
isOpen(): boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Wires Formula Composer into one TinyMCE editor (INT-001..025). */
|
|
19
|
+
export declare function setupFormulaComposer(editor: TinyEditor): FormulaComposerInstance;
|
|
20
|
+
export declare function isTinyMCEGlobal(value: unknown): value is TinyMCEGlobal;
|
|
21
|
+
/** The page's `window.tinymce`, when loaded. */
|
|
22
|
+
export declare function globalTinyMCE(): TinyMCEGlobal | null;
|
|
23
|
+
/** Registers the `formulacomposer` plugin (and its legacy `sylarwiris` name) with a TinyMCE 5.10+, 6.x, 7.x or 8.x global. Safe to call repeatedly. */
|
|
24
|
+
export declare function registerFormulaComposer(tinymce: TinyMCEGlobal): void;
|
|
25
|
+
/** @deprecated Use {@link setupFormulaComposer}. */
|
|
26
|
+
export declare const setupSylarWiris: typeof setupFormulaComposer;
|
|
27
|
+
/** @deprecated Use {@link registerFormulaComposer}. */
|
|
28
|
+
export declare const registerSylarWiris: typeof registerFormulaComposer;
|
|
29
|
+
/** @deprecated Use {@link FormulaComposerInstance}. */
|
|
30
|
+
export type SylarWirisInstance = FormulaComposerInstance;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The subset of the TinyMCE editor API used by the plugin. Declared structurally so one build serves
|
|
3
|
+
* TinyMCE 5.10, 6.x, 7.x and 8.x, whose published typings differ. Members that only some majors have
|
|
4
|
+
* are optional and read through the helpers in `compat.ts`.
|
|
5
|
+
*/
|
|
6
|
+
export interface ContentEventArgs {
|
|
7
|
+
content: unknown;
|
|
8
|
+
format?: string;
|
|
9
|
+
selection?: boolean;
|
|
10
|
+
initial?: boolean;
|
|
11
|
+
load?: boolean;
|
|
12
|
+
set?: boolean;
|
|
13
|
+
get?: boolean;
|
|
14
|
+
/** Set when the content comes from a paste. */
|
|
15
|
+
paste?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface PasteEventArgs {
|
|
18
|
+
content: string;
|
|
19
|
+
internal?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface EditorEventMap {
|
|
22
|
+
PreInit: unknown;
|
|
23
|
+
init: unknown;
|
|
24
|
+
remove: unknown;
|
|
25
|
+
NodeChange: unknown;
|
|
26
|
+
SwitchMode: unknown;
|
|
27
|
+
BeforeSetContent: ContentEventArgs;
|
|
28
|
+
GetContent: ContentEventArgs;
|
|
29
|
+
PastePreProcess: PasteEventArgs;
|
|
30
|
+
dblclick: MouseEvent;
|
|
31
|
+
}
|
|
32
|
+
export type EditorEventName = keyof EditorEventMap;
|
|
33
|
+
export type EditorEventHandler<K extends EditorEventName> = (event: EditorEventMap[K]) => void;
|
|
34
|
+
export interface ButtonApi {
|
|
35
|
+
/** TinyMCE 6+. */
|
|
36
|
+
setEnabled?(state: boolean): void;
|
|
37
|
+
/** TinyMCE 5. */
|
|
38
|
+
setDisabled?(state: boolean): void;
|
|
39
|
+
}
|
|
40
|
+
export interface ButtonSpec {
|
|
41
|
+
icon?: string;
|
|
42
|
+
text?: string;
|
|
43
|
+
tooltip?: string;
|
|
44
|
+
onAction: (api: ButtonApi) => void;
|
|
45
|
+
onSetup?: (api: ButtonApi) => (api: ButtonApi) => void;
|
|
46
|
+
}
|
|
47
|
+
export interface MenuItemSpec {
|
|
48
|
+
icon?: string;
|
|
49
|
+
text: string;
|
|
50
|
+
onAction: (api: ButtonApi) => void;
|
|
51
|
+
onSetup?: (api: ButtonApi) => (api: ButtonApi) => void;
|
|
52
|
+
}
|
|
53
|
+
/** A node of TinyMCE's HTML parser tree. */
|
|
54
|
+
export interface ParserNode {
|
|
55
|
+
attr(name: string): string | undefined;
|
|
56
|
+
attr(name: string, value: string | null): unknown;
|
|
57
|
+
}
|
|
58
|
+
export interface OptionSpec {
|
|
59
|
+
processor: 'object' | 'string' | 'boolean';
|
|
60
|
+
default?: unknown;
|
|
61
|
+
}
|
|
62
|
+
export interface TinyEditor {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly initialized: boolean;
|
|
65
|
+
/** TinyMCE 6+. */
|
|
66
|
+
options?: {
|
|
67
|
+
register(name: string, spec: OptionSpec): void;
|
|
68
|
+
get(name: string): unknown;
|
|
69
|
+
};
|
|
70
|
+
/** TinyMCE 5: reads an init option. */
|
|
71
|
+
getParam?(name: string): unknown;
|
|
72
|
+
/** TinyMCE's HTML parser, available from `PreInit`. */
|
|
73
|
+
parser?: {
|
|
74
|
+
addAttributeFilter(name: string, callback: (nodes: ParserNode[]) => void): void;
|
|
75
|
+
};
|
|
76
|
+
/** TinyMCE's image upload scanner, available from `PreInit`. */
|
|
77
|
+
editorUpload?: {
|
|
78
|
+
addFilter(filter: (img: HTMLImageElement) => boolean): void;
|
|
79
|
+
};
|
|
80
|
+
ui: {
|
|
81
|
+
registry: {
|
|
82
|
+
addButton(name: string, spec: ButtonSpec): void;
|
|
83
|
+
addMenuItem(name: string, spec: MenuItemSpec): void;
|
|
84
|
+
addIcon(name: string, svg: string): void;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
mode: {
|
|
88
|
+
isReadOnly(): boolean;
|
|
89
|
+
};
|
|
90
|
+
selection: {
|
|
91
|
+
getNode(): Element;
|
|
92
|
+
getRng(): Range;
|
|
93
|
+
select(node: Node): void;
|
|
94
|
+
setCursorLocation(node: Node, offset: number): void;
|
|
95
|
+
/** Not in TinyMCE 5. */
|
|
96
|
+
isEditable?(): boolean;
|
|
97
|
+
getBookmark(type?: number, normalized?: boolean): unknown;
|
|
98
|
+
moveToBookmark(bookmark: unknown): void;
|
|
99
|
+
};
|
|
100
|
+
dom: {
|
|
101
|
+
createHTML(name: string, attrs: Readonly<Record<string, string>>): string;
|
|
102
|
+
setAttribs(element: Element, attrs: Readonly<Record<string, string | null>>): void;
|
|
103
|
+
remove(node: Node): void;
|
|
104
|
+
/** Not in TinyMCE 5. */
|
|
105
|
+
isEditable?(node: Node | null | undefined): boolean;
|
|
106
|
+
};
|
|
107
|
+
undoManager: {
|
|
108
|
+
transact(callback: () => void): unknown;
|
|
109
|
+
ignore(callback: () => void): void;
|
|
110
|
+
clear(): void;
|
|
111
|
+
add(): unknown;
|
|
112
|
+
hasUndo(): boolean;
|
|
113
|
+
};
|
|
114
|
+
on<K extends EditorEventName>(name: K, handler: EditorEventHandler<K>): unknown;
|
|
115
|
+
off<K extends EditorEventName>(name: K, handler: EditorEventHandler<K>): unknown;
|
|
116
|
+
insertContent(content: string): void;
|
|
117
|
+
getBody(): HTMLElement | null;
|
|
118
|
+
focus(): void;
|
|
119
|
+
nodeChanged(): void;
|
|
120
|
+
isDirty(): boolean;
|
|
121
|
+
setDirty(state: boolean): void;
|
|
122
|
+
}
|
|
123
|
+
export interface TinyMCEGlobal {
|
|
124
|
+
PluginManager: {
|
|
125
|
+
add(name: string, factory: (editor: TinyEditor, url: string) => unknown): void;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Editor } from '@tinymce/tinymce-react';
|
|
2
|
+
import { type ComponentProps, type ReactElement, type ReactNode } from 'react';
|
|
3
|
+
import type { FormulaComposerOptions } from '../tinymce/index';
|
|
4
|
+
export interface FormulaComposerProviderProps {
|
|
5
|
+
/** App-wide defaults for every `<FormulaComposerEditor>` below this provider. */
|
|
6
|
+
config: FormulaComposerOptions;
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function FormulaComposerProvider({ config, children }: FormulaComposerProviderProps): ReactElement;
|
|
10
|
+
/** The props of the installed `@tinymce/tinymce-react` `<Editor>`, plus `formulaComposer`. */
|
|
11
|
+
export interface FormulaComposerEditorProps extends ComponentProps<typeof Editor> {
|
|
12
|
+
/** Options for this editor. Read when the editor initialises; remount it (for example with a `key`) to apply changes. */
|
|
13
|
+
formulaComposer?: FormulaComposerOptions;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The stock `@tinymce/tinymce-react` `<Editor>` with Formula Composer added: the plugin, the toolbar button
|
|
17
|
+
* (in `toolbar` or `init.toolbar`) and its options, merged as provider defaults < `formulaComposer` < `init.formulaComposer`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function FormulaComposerEditor({ formulaComposer, init, plugins, toolbar, ...props }: FormulaComposerEditorProps): ReactElement;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { FormulaComposerEditor, type FormulaComposerEditorProps, FormulaComposerProvider, type FormulaComposerProviderProps } from './editor.js';
|
|
2
|
+
export { type TinyMCEInit, type TinyMCEPlugins, type TinyMCEToolbar, appendToolbarButton, withFormulaComposer } from './init.js';
|
|
3
|
+
export { type FormulaComposerOptions, type SaveMode, upgradeMathElements } from '../tinymce/index';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Editor as T}from"@tinymce/tinymce-react";import{createContext as E,createElement as a,useContext as F,useMemo as m}from"react";import{appendFormulaButton as c,withFormulaComposer as f}from"../tinymce/index.js";function n(o){return c(o)}function p(o={},r={}){return f(o,r)}var x={},u=E(x);function P({config:o,children:r}){return a(u.Provider,{value:o},r)}function s(o){return Array.isArray(o)?o:(o??"").split(/[\s,]+/).filter(r=>r.length>0)}function b({formulaComposer:o,init:r,plugins:t,toolbar:e,...l}){let i=F(u),C=m(()=>{let y=t===void 0?r:{...r,plugins:[...s(r?.plugins),...s(t)]};return p(y,{...i,...o})},[r,t,i,o]),d=m(()=>e===void 0?void 0:n(e),[e]);return a(T,{...l,init:C,toolbar:d})}import{upgradeMathElements as j}from"../tinymce/index.js";export{b as FormulaComposerEditor,P as FormulaComposerProvider,n as appendToolbarButton,j as upgradeMathElements,p as withFormulaComposer};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Editor } from '@tinymce/tinymce-react';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import { type FormulaComposerOptions } from '../tinymce/index';
|
|
4
|
+
/** TinyMCE init options as accepted by `<Editor init>` of the installed `@tinymce/tinymce-react`. */
|
|
5
|
+
export type TinyMCEInit = NonNullable<ComponentProps<typeof Editor>['init']>;
|
|
6
|
+
export type TinyMCEToolbar = TinyMCEInit['toolbar'];
|
|
7
|
+
export type TinyMCEPlugins = TinyMCEInit['plugins'];
|
|
8
|
+
/**
|
|
9
|
+
* Appends the formula button to an explicit toolbar. `undefined`/`true` (TinyMCE default toolbar)
|
|
10
|
+
* and `false` are returned unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export declare function appendToolbarButton(toolbar: string): string;
|
|
13
|
+
export declare function appendToolbarButton(toolbar: string[]): string[];
|
|
14
|
+
export declare function appendToolbarButton(toolbar: TinyMCEToolbar): TinyMCEToolbar;
|
|
15
|
+
/**
|
|
16
|
+
* Adds Formula Composer to TinyMCE init options: registers the bundled plugin before TinyMCE loads plugins,
|
|
17
|
+
* enables it, adds the toolbar button and merges `options` under the `formulaComposer` key (init wins).
|
|
18
|
+
*
|
|
19
|
+
* Init objects typed for the installed `@tinymce-react` get that type back. Any other init object (for
|
|
20
|
+
* example a shared config typed as a plain object, or with parts that depend on a condition) keeps its own type.
|
|
21
|
+
*/
|
|
22
|
+
export declare function withFormulaComposer(init?: TinyMCEInit, options?: FormulaComposerOptions): TinyMCEInit;
|
|
23
|
+
export declare function withFormulaComposer<T extends object>(init: T, options?: FormulaComposerOptions): T;
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,103 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formula-composer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Math and chemistry equation editor for TinyMCE 5-8, with React and Angular integrations. Saves formulas as MathML.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"math",
|
|
7
|
+
"equation",
|
|
8
|
+
"equation-editor",
|
|
9
|
+
"formula",
|
|
10
|
+
"mathml",
|
|
11
|
+
"latex",
|
|
12
|
+
"chemistry",
|
|
13
|
+
"tinymce",
|
|
14
|
+
"tinymce-plugin",
|
|
15
|
+
"react",
|
|
16
|
+
"angular"
|
|
17
|
+
],
|
|
18
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/tinymce/index.js",
|
|
21
|
+
"module": "./dist/tinymce/index.js",
|
|
22
|
+
"types": "./dist/tinymce/index.d.ts",
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./dist/tinymce/browser/*"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/tinymce/index.d.ts",
|
|
29
|
+
"default": "./dist/tinymce/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./react": {
|
|
32
|
+
"types": "./dist/tinymce-react/index.d.ts",
|
|
33
|
+
"default": "./dist/tinymce-react/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./angular": {
|
|
36
|
+
"types": "./angular/formula-composer-tinymce-angular.d.ts",
|
|
37
|
+
"esm2020": "./angular/esm2020/formula-composer-tinymce-angular.mjs",
|
|
38
|
+
"es2020": "./angular/fesm2020/formula-composer-tinymce-angular.mjs",
|
|
39
|
+
"es2015": "./angular/fesm2015/formula-composer-tinymce-angular.mjs",
|
|
40
|
+
"node": "./angular/fesm2015/formula-composer-tinymce-angular.mjs",
|
|
41
|
+
"default": "./angular/fesm2020/formula-composer-tinymce-angular.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./renderer": {
|
|
44
|
+
"types": "./dist/renderer/index.d.ts",
|
|
45
|
+
"default": "./dist/renderer/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./math-core": {
|
|
48
|
+
"types": "./dist/math-core/index.d.ts",
|
|
49
|
+
"default": "./dist/math-core/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./editor-ui": {
|
|
52
|
+
"types": "./dist/editor-ui/index.d.ts",
|
|
53
|
+
"default": "./dist/editor-ui/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./integration": {
|
|
56
|
+
"types": "./dist/integration/index.d.ts",
|
|
57
|
+
"default": "./dist/integration/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./browser/*": "./dist/tinymce/browser/*",
|
|
60
|
+
"./package.json": "./package.json"
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"dist",
|
|
64
|
+
"images",
|
|
65
|
+
"angular",
|
|
66
|
+
"react",
|
|
67
|
+
"renderer",
|
|
68
|
+
"math-core",
|
|
69
|
+
"editor-ui",
|
|
70
|
+
"integration"
|
|
71
|
+
],
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"tslib": "^2.3.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@tinymce/tinymce-react": ">=3.0.0",
|
|
77
|
+
"react": ">=16.14.0",
|
|
78
|
+
"@angular/common": ">=13.0.0",
|
|
79
|
+
"@angular/core": ">=13.0.0",
|
|
80
|
+
"@tinymce/tinymce-angular": ">=5.0.0",
|
|
81
|
+
"tinymce": ">=5.10.0"
|
|
82
|
+
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@tinymce/tinymce-react": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"react": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@angular/common": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
93
|
+
"@angular/core": {
|
|
94
|
+
"optional": true
|
|
95
|
+
},
|
|
96
|
+
"@tinymce/tinymce-angular": {
|
|
97
|
+
"optional": true
|
|
98
|
+
},
|
|
99
|
+
"tinymce": {
|
|
100
|
+
"optional": true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|