@wangeditor-next/plugin-formula 2.0.5 → 2.0.7

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
@@ -22,11 +22,14 @@ pnpm add @wangeditor-next/plugin-formula
22
22
  ```js
23
23
  import { Boot, IEditorConfig, IToolbarConfig } from '@wangeditor-next/editor'
24
24
  import formulaModule from '@wangeditor-next/plugin-formula'
25
+ import 'katex/dist/katex.min.css'
25
26
 
26
27
  // 注册。要在创建编辑器之前注册,且只能注册一次,不可重复注册。
27
28
  Boot.registerModule(formulaModule)
28
29
  ```
29
30
 
31
+ 需要确保页面引入 KaTeX 样式,否则公式会退化为未排版状态。
32
+
30
33
  ### 配置
31
34
 
32
35
  ```js
@@ -13,6 +13,9 @@ declare const _default: {
13
13
  };
14
14
  codeBlock: {
15
15
  title: string;
16
+ copy: string;
17
+ copied: string;
18
+ copyFailed: string;
16
19
  };
17
20
  color: {
18
21
  color: string;
@@ -13,6 +13,9 @@ declare const _default: {
13
13
  };
14
14
  codeBlock: {
15
15
  title: string;
16
+ copy: string;
17
+ copied: string;
18
+ copyFailed: string;
16
19
  };
17
20
  color: {
18
21
  color: string;
@@ -5,5 +5,8 @@
5
5
  import CodeBlockMenu from './CodeBlockMenu';
6
6
  export declare const codeBlockMenuConf: {
7
7
  key: string;
8
+ config: {
9
+ showCopyButton: boolean;
10
+ };
8
11
  factory(): CodeBlockMenu;
9
12
  };
@@ -5,7 +5,7 @@
5
5
  import { IDomEditor } from '@wangeditor-next/core';
6
6
  import { Element as SlateElement } from 'slate';
7
7
  import { VNode } from 'snabbdom';
8
- declare function renderPre(_elemNode: SlateElement, children: VNode[] | null, _editor: IDomEditor): VNode;
8
+ declare function renderPre(elemNode: SlateElement, children: VNode[] | null, editor: IDomEditor): VNode;
9
9
  declare function renderCode(_elemNode: SlateElement, children: VNode[] | null, _editor: IDomEditor): VNode;
10
10
  export declare const renderPreConf: {
11
11
  type: string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @description indent target matcher
3
+ */
4
+ export declare function isIndentTargetElement(node: unknown): boolean;
@@ -18,6 +18,7 @@ interface IHoverbarConf {
18
18
  export type AlertType = 'success' | 'info' | 'warning' | 'error';
19
19
  export type TextStyleMode = 'inline' | 'class';
20
20
  export type ClassStylePolicy = 'preserve-data' | 'fallback-inline' | 'strict';
21
+ export type TableWidthExportMode = 'adaptive' | 'explicit';
21
22
  export type StyleClassTokenType = 'color' | 'bgColor' | 'fontSize' | 'fontFamily' | 'textAlign' | 'lineHeight' | 'indent';
22
23
  export interface IClassStyleUnsupportedPayload {
23
24
  type: string;
@@ -88,12 +89,14 @@ interface IEmotionConfig {
88
89
  }
89
90
  interface IInsertTableConfig {
90
91
  minWidth: number;
92
+ minRowHeight: number;
91
93
  tableHeader: {
92
94
  selected: boolean;
93
95
  };
94
96
  tableFullWidth: {
95
97
  selected: boolean;
96
98
  };
99
+ widthExportMode: TableWidthExportMode;
97
100
  }
98
101
  interface IInsertTableColConfig {
99
102
  insertPosition: 'before' | 'after';
@@ -118,6 +121,9 @@ interface ICodeLangConfig {
118
121
  selected?: boolean;
119
122
  }[];
120
123
  }
124
+ interface ICodeBlockConfig {
125
+ showCopyButton?: boolean;
126
+ }
121
127
  export interface IMenuConfig {
122
128
  bold: ISingleMenuConfig;
123
129
  underline: ISingleMenuConfig;
@@ -153,7 +159,7 @@ export interface IMenuConfig {
153
159
  editLink: ILinkConfig;
154
160
  unLink: ISingleMenuConfig;
155
161
  viewLink: ISingleMenuConfig;
156
- codeBlock: ISingleMenuConfig;
162
+ codeBlock: ICodeBlockConfig;
157
163
  blockquote: ISingleMenuConfig;
158
164
  headerSelect: ISingleMenuConfig;
159
165
  header1: ISingleMenuConfig;
@@ -2,7 +2,7 @@
2
2
  * @description 绑定 node 的关系
3
3
  * @author wangfupeng
4
4
  */
5
- import { Node, Ancestor } from 'slate';
5
+ import { Ancestor, Node } from 'slate';
6
6
  import { IDomEditor } from '../editor/interface';
7
7
  /**
8
8
  * createEditor 未传递 selector 时,绑定 node 的关系( NODE_TO_PARENT, NODE_TO_INDEX 等 )
@@ -2,9 +2,9 @@
2
2
  * @description create toolbar
3
3
  * @author wangfupeng
4
4
  */
5
+ import { IToolbarConfig } from '../config/interface';
5
6
  import { IDomEditor } from '../editor/interface';
6
7
  import Toolbar from '../menus/bar/Toolbar';
7
- import { IToolbarConfig } from '../config/interface';
8
8
  import { DOMElement } from '../utils/dom';
9
9
  interface ICreateOption {
10
10
  selector: string | DOMElement;
@@ -25,6 +25,7 @@ export interface IDomEditor extends Editor {
25
25
  alert: (info: string, type: AlertType) => void;
26
26
  handleTab: () => void;
27
27
  getHtml: () => string;
28
+ getHtmlWithId?: (idKey?: string) => string;
28
29
  getText: () => string;
29
30
  getSelectionText: () => string;
30
31
  getElemsByTypePrefix: (typePrefix: string) => ElementWithId[];
@@ -69,5 +70,6 @@ export interface IDomEditor extends Editor {
69
70
  emit: (type: string, ...args: any[]) => void;
70
71
  undo?: () => void;
71
72
  redo?: () => void;
73
+ clearHistory?: () => void;
72
74
  }
73
75
  export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description slate 插件 - history
3
+ */
4
+ import { Editor } from 'slate';
5
+ import { HistoryEditor } from 'slate-history';
6
+ import { IDomEditor } from '../interface';
7
+ export declare const withHistory: <T extends Editor>(editor: T) => T & IDomEditor & HistoryEditor;
@@ -3,8 +3,8 @@
3
3
  * @author wangfupeng
4
4
  */
5
5
  import { Dom7Array } from '../../utils/dom';
6
- import { IBarItem } from './index';
7
6
  import { ISelectMenu } from '../interface';
7
+ import { IBarItem } from './index';
8
8
  declare class BarItemSelect implements IBarItem {
9
9
  readonly $elem: Dom7Array;
10
10
  private readonly $button;
@@ -2,9 +2,9 @@
2
2
  * @description bar item
3
3
  * @author wangfupeng
4
4
  */
5
- import { Dom7Array } from '../../utils/dom';
6
- import { IButtonMenu, ISelectMenu, IDropPanelMenu, IModalMenu, IMenuGroup } from '../interface';
7
5
  import { IDomEditor } from '../../editor/interface';
6
+ import { Dom7Array } from '../../utils/dom';
7
+ import { IButtonMenu, IDropPanelMenu, IMenuGroup, IModalMenu, ISelectMenu } from '../interface';
8
8
  import GroupButton from './GroupButton';
9
9
  type MenuType = IButtonMenu | ISelectMenu | IDropPanelMenu | IModalMenu;
10
10
  export interface IBarItem {
@@ -2,13 +2,11 @@
2
2
  * @description dropPanel class
3
3
  * @author wangfupeng
4
4
  */
5
- import { IDomEditor } from '../../editor/interface';
6
5
  import { Dom7Array } from '../../utils/dom';
7
6
  import PanelAndModal from './BaseClass';
8
7
  declare class DropPanel extends PanelAndModal {
9
8
  type: string;
10
9
  readonly $elem: Dom7Array;
11
- constructor(editor: IDomEditor);
12
10
  genSelfElem(): Dom7Array | null;
13
11
  }
14
12
  export default DropPanel;
@@ -2,10 +2,10 @@
2
2
  * @description modal class
3
3
  * @author wangfupeng
4
4
  */
5
+ import { IDomEditor } from '../../editor/interface';
5
6
  import { Dom7Array, DOMElement } from '../../utils/dom';
6
7
  import { IPositionStyle } from '../interface';
7
8
  import PanelAndModal from './BaseClass';
8
- import { IDomEditor } from '../../editor/interface';
9
9
  declare class Modal extends PanelAndModal {
10
10
  type: string;
11
11
  readonly $elem: Dom7Array;
@@ -2,7 +2,7 @@
2
2
  * @description slate node to vnode
3
3
  * @author wangfupeng
4
4
  */
5
- import { Node, Ancestor } from 'slate';
5
+ import { Ancestor, Node } from 'slate';
6
6
  import { VNode } from 'snabbdom';
7
7
  import { IDomEditor } from '../editor/interface';
8
8
  /**
@@ -2,8 +2,8 @@
2
2
  * @description 生成 text vnode
3
3
  * @author wangfupeng
4
4
  */
5
- import { Text as SlateText, Ancestor } from 'slate';
5
+ import { Ancestor, Text as SlateText } from 'slate';
6
6
  import { VNode } from 'snabbdom';
7
7
  import { IDomEditor } from '../../editor/interface';
8
- declare function genTextVnode(leafNode: SlateText, isLast: boolean | undefined, textNode: SlateText, parent: Ancestor, editor: IDomEditor): VNode;
8
+ declare function genTextVnode(leafNode: SlateText, textNode: SlateText, parent: Ancestor, editor: IDomEditor, isLast?: boolean): VNode;
9
9
  export default genTextVnode;
@@ -4,16 +4,16 @@
4
4
  */
5
5
  import handleBeforeInput from './beforeInput';
6
6
  import handleOnBlur from './blur';
7
- import handleOnFocus from './focus';
8
7
  import handleOnClick from './click';
9
- import { handleCompositionStart, handleCompositionEnd, handleCompositionUpdate } from './composition';
10
- import handleOnKeydown from './keydown';
11
- import handleKeypress from './keypress';
8
+ import { handleCompositionEnd, handleCompositionStart, handleCompositionUpdate } from './composition';
12
9
  import handleOnCopy from './copy';
13
10
  import handleOnCut from './cut';
14
- import handleOnPaste from './paste';
15
- import { handleOnDragover, handleOnDragstart, handleOnDragend } from './drag';
11
+ import { handleOnDragend, handleOnDragover, handleOnDragstart } from './drag';
16
12
  import handleOnDrop from './drop';
13
+ import handleOnFocus from './focus';
14
+ import handleOnKeydown from './keydown';
15
+ import handleKeypress from './keypress';
16
+ import handleOnPaste from './paste';
17
17
  declare const eventConf: {
18
18
  beforeinput: typeof handleBeforeInput;
19
19
  blur: typeof handleOnBlur;
@@ -4,5 +4,6 @@
4
4
  */
5
5
  import { Element } from 'slate';
6
6
  import { IDomEditor } from '../editor/interface';
7
- declare function elemToHtml(elemNode: Element, editor: IDomEditor): string;
7
+ import type { INodeToHtmlOptions } from './node2html';
8
+ declare function elemToHtml(elemNode: Element, editor: IDomEditor, options?: INodeToHtmlOptions): string;
8
9
  export default elemToHtml;
@@ -3,6 +3,10 @@
3
3
  * @author wangfupeng
4
4
  */
5
5
  import { Descendant } from 'slate';
6
- import { IDomEditor } from '../editor/interface';
7
- declare function node2html(node: Descendant, editor: IDomEditor): string;
6
+ import type { IDomEditor } from '../editor/interface';
7
+ export interface INodeToHtmlOptions {
8
+ includeId?: boolean;
9
+ idKey?: string;
10
+ }
11
+ declare function node2html(node: Descendant, editor: IDomEditor, options?: INodeToHtmlOptions): string;
8
12
  export default node2html;
@@ -4,5 +4,6 @@
4
4
  */
5
5
  import { Text } from 'slate';
6
6
  import { IDomEditor } from '../editor/interface';
7
- declare function textToHtml(textNode: Text, editor: IDomEditor): string;
7
+ import type { INodeToHtmlOptions } from './node2html';
8
+ declare function textToHtml(textNode: Text, editor: IDomEditor, _options?: INodeToHtmlOptions): string;
8
9
  export default textToHtml;
@@ -2,11 +2,13 @@
2
2
  * @description gen uploader
3
3
  * @author wangfupeng
4
4
  */
5
- import type Uppy from '@uppy/core';
6
5
  import type { IDomEditor } from '../editor/interface';
7
6
  import type { IUploadAdapter, IUploadConfig, IUploader } from './interface';
8
7
  type IUploadConfigWithAdapter = IUploadConfig & {
9
8
  uploadAdapter: IUploadAdapter;
10
9
  };
11
- declare function createUploader<T extends IUploadConfig>(config: T, editor?: IDomEditor): T extends IUploadConfigWithAdapter ? IUploader : Uppy;
10
+ type IDefaultUploader = IUploader & {
11
+ [key: string]: any;
12
+ };
13
+ declare function createUploader<T extends IUploadConfig>(config: T, editor?: IDomEditor): T extends IUploadConfigWithAdapter ? IUploader : IDefaultUploader;
12
14
  export default createUploader;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("katex"),require("@wangeditor-next/editor"),require("snabbdom")):"function"==typeof define&&define.amd?define(["katex","@wangeditor-next/editor","snabbdom"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).WangEditorFormulaPlugin=e(t.katex,t.editor,t.snabbdom)}(this,function(t,e,n){"use strict";var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)};function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,i=n.call(t),l=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)l.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return l}"function"==typeof SuppressedError&&SuppressedError,function(){if(void 0!==window.Reflect&&void 0!==window.customElements&&!window.customElements.polyfillWrapFlushCallback){var t=HTMLElement,e=function(){return Reflect.construct(t,[],this.constructor)};window.HTMLElement=e,HTMLElement.prototype=t.prototype,HTMLElement.prototype.constructor=HTMLElement,Object.setPrototypeOf(HTMLElement,t)}}();var i=function(e){function n(){var t=e.call(this)||this,n=t.attachShadow({mode:"open"}),o=n.ownerDocument.createElement("span");return o.style.display="inline-block",n.appendChild(o),t.span=o,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,e),Object.defineProperty(n,"observedAttributes",{get:function(){return["data-value"]},enumerable:!1,configurable:!0}),n.prototype.attributeChangedCallback=function(t,e,n){if("data-value"===t){if(e===n)return;this.render(n||"")}},n.prototype.render=function(e){t.render(e,this.span,{throwOnError:!1,output:"mathml"})},n}(HTMLElement);window.customElements.get("w-e-formula-card")||window.customElements.define("w-e-formula-card",i),e.i18nAddResources("en",{formula:{formula:"Formula",placeholder:"Use LateX syntax",insert:"Insert formula",edit:"Edit formula",ok:"OK"}}),e.i18nAddResources("zh-CN",{formula:{formula:"公式",placeholder:"使用 LateX 语法",insert:"插入公式",edit:"编辑公式",ok:"确定"}});var l={type:"formula",elemToHtml:function(t,e){var n=t.value;return'<span data-w-e-type="formula" data-w-e-is-void data-w-e-is-inline data-value="'.concat(void 0===n?"":n,'"></span>')}};function s(t){return null!==t&&"object"==typeof t&&"constructor"in t&&t.constructor===Object}function a(t={},e={}){Object.keys(e).forEach(n=>{void 0===t[n]?t[n]=e[n]:s(e[n])&&s(t[n])&&Object.keys(e[n]).length>0&&a(t[n],e[n])})}const u={body:{},addEventListener(){},removeEventListener(){},activeElement:{blur(){},nodeName:""},querySelector:()=>null,querySelectorAll:()=>[],getElementById:()=>null,createEvent:()=>({initEvent(){}}),createElement:()=>({children:[],childNodes:[],style:{},setAttribute(){},getElementsByTagName:()=>[]}),createElementNS:()=>({}),importNode:()=>null,location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""}};function c(){const t="undefined"!=typeof document?document:{};return a(t,u),t}const f={document:u,navigator:{userAgent:""},location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""},history:{replaceState(){},pushState(){},go(){},back(){}},CustomEvent:function(){return this},addEventListener(){},removeEventListener(){},getComputedStyle:()=>({getPropertyValue:()=>""}),Image(){},Date(){},screen:{},setTimeout(){},clearTimeout(){},matchMedia:()=>({}),requestAnimationFrame:t=>"undefined"==typeof setTimeout?(t(),null):setTimeout(t,0),cancelAnimationFrame(t){"undefined"!=typeof setTimeout&&clearTimeout(t)}};function d(){const t="undefined"!=typeof window?window:{};return a(t,f),t}class p extends Array{constructor(t){"number"==typeof t?super(t):(super(...t||[]),function(t){const e=t.__proto__;Object.defineProperty(t,"__proto__",{get:()=>e,set(t){e.__proto__=t}})}(this))}}function h(t,e){const n=d(),o=c();let r=[];if(!e&&t instanceof p)return t;if(!t)return new p(r);if("string"==typeof t){const n=t.trim();if(n.indexOf("<")>=0&&n.indexOf(">")>=0){let t="div";0===n.indexOf("<li")&&(t="ul"),0===n.indexOf("<tr")&&(t="tbody"),0!==n.indexOf("<td")&&0!==n.indexOf("<th")||(t="tr"),0===n.indexOf("<tbody")&&(t="table"),0===n.indexOf("<option")&&(t="select");const e=o.createElement(t);e.innerHTML=n;for(let t=0;t<e.childNodes.length;t+=1)r.push(e.childNodes[t])}else r=function(t,e){if("string"!=typeof t)return[t];const n=[],o=e.querySelectorAll(t);for(let t=0;t<o.length;t+=1)n.push(o[t]);return n}(t.trim(),e||o)}else if(t.nodeType||t===n||t===o)r.push(t);else if(Array.isArray(t)){if(t instanceof p)return t;r=t}return new p(function(t){const e=[];for(let n=0;n<t.length;n+=1)-1===e.indexOf(t[n])&&e.push(t[n]);return e}(r))}function m(t){if(void 0===t){const t=this[0];if(!t)return;if(t.multiple&&"select"===t.nodeName.toLowerCase()){const e=[];for(let n=0;n<t.selectedOptions.length;n+=1)e.push(t.selectedOptions[n].value);return e}return t.value}for(let e=0;e<this.length;e+=1){const n=this[e];if(Array.isArray(t)&&n.multiple&&"select"===n.nodeName.toLowerCase())for(let e=0;e<n.options.length;e+=1)n.options[e].selected=t.indexOf(n.options[e].value)>=0;else n.value=t}return this}function v(...t){let[e,n,o,r]=t;function i(t){const e=t.target;if(!e)return;const r=t.target.dom7EventData||[];if(r.indexOf(t)<0&&r.unshift(t),h(e).is(n))o.apply(e,r);else{const t=h(e).parents();for(let e=0;e<t.length;e+=1)h(t[e]).is(n)&&o.apply(t[e],r)}}function l(t){const e=t&&t.target&&t.target.dom7EventData||[];e.indexOf(t)<0&&e.unshift(t),o.apply(this,e)}"function"==typeof t[1]&&([e,o,r]=t,n=void 0),r||(r=!1);const s=e.split(" ");let a;for(let t=0;t<this.length;t+=1){const e=this[t];if(n)for(a=0;a<s.length;a+=1){const t=s[a];e.dom7LiveListeners||(e.dom7LiveListeners={}),e.dom7LiveListeners[t]||(e.dom7LiveListeners[t]=[]),e.dom7LiveListeners[t].push({listener:o,proxyListener:i}),e.addEventListener(t,i,r)}else for(a=0;a<s.length;a+=1){const t=s[a];e.dom7Listeners||(e.dom7Listeners={}),e.dom7Listeners[t]||(e.dom7Listeners[t]=[]),e.dom7Listeners[t].push({listener:o,proxyListener:l}),e.addEventListener(t,l,r)}}return this}function y(t){if(void 0===t)return this[0]?this[0].innerHTML:null;for(let e=0;e<this.length;e+=1)this[e].innerHTML=t;return this}function g(t){const e=d(),n=c(),o=this[0];let r,i;if(!o||void 0===t)return!1;if("string"==typeof t){if(o.matches)return o.matches(t);if(o.webkitMatchesSelector)return o.webkitMatchesSelector(t);if(o.msMatchesSelector)return o.msMatchesSelector(t);for(r=h(t),i=0;i<r.length;i+=1)if(r[i]===o)return!0;return!1}if(t===n)return o===n;if(t===e)return o===e;if(t.nodeType||t instanceof p){for(r=t.nodeType?[t]:t,i=0;i<r.length;i+=1)if(r[i]===o)return!0;return!1}return!1}function E(...t){let e;const n=c();for(let o=0;o<t.length;o+=1){e=t[o];for(let t=0;t<this.length;t+=1)if("string"==typeof e){const o=n.createElement("div");for(o.innerHTML=e;o.firstChild;)this[t].appendChild(o.firstChild)}else if(e instanceof p)for(let n=0;n<e.length;n+=1)this[t].appendChild(e[n]);else this[t].appendChild(e)}return this}function b(t){const e=[];for(let n=0;n<this.length;n+=1){let o=this[n].parentNode;for(;o;)t?h(o).is(t)&&e.push(o):e.push(o),o=o.parentNode}return h(e)}function w(t){const e=[];for(let n=0;n<this.length;n+=1){const o=this[n].querySelectorAll(t);for(let t=0;t<o.length;t+=1)e.push(o[t])}return h(e)}h.fn=p.prototype;const x="resize scroll".split(" ");const L=(T="focus",function(...t){if(void 0===t[0]){for(let t=0;t<this.length;t+=1)x.indexOf(T)<0&&(T in this[t]?this[t][T]():h(this[t]).trigger(T));return this}return this.on(T,...t)});var T;E&&(h.fn.append=E),y&&(h.fn.html=y),m&&(h.fn.val=m),v&&(h.fn.on=v),L&&(h.fn.focus=L),g&&(h.fn.is=g),b&&(h.fn.parents=b),w&&(h.fn.find=w);function S(t){return"".concat(t,"-").concat(((t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&n[t]];return e})())}function M(){return S("w-e-insert-formula")}var O=function(){function t(){this.title=e.t("formula.edit"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M864 0a160 160 0 0 1 128 256l-64 64-224-224 64-64c26.752-20.096 59.968-32 96-32zM64 736l-64 288 288-64 592-592-224-224L64 736z m651.584-372.416l-448 448-55.168-55.168 448-448 55.168 55.168z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=300,this.$content=null,this.textareaId=M(),this.buttonId=M()}return t.prototype.getSelectedElem=function(t){var n=e.DomEditor.getSelectedNodeByType(t,"formula");return null==n?null:n},t.prototype.getValue=function(t){var e=this.getSelectedElem(t);return e&&e.value||""},t.prototype.isActive=function(t){return!1},t.prototype.exec=function(t,e){},t.prototype.isDisabled=function(t){var n=t.selection;return null==n||(!!e.SlateRange.isExpanded(n)||null==this.getSelectedElem(t))},t.prototype.getModalPositionNode=function(t){return this.getSelectedElem(t)},t.prototype.getModalContentElem=function(t){var n=this,o=this.textareaId,i=this.buttonId,l=r(e.genModalTextareaElems(e.t("formula.formula"),o,e.t("formula.placeholder")),2),s=l[0],a=h(l[1]),u=r(e.genModalButtonElems(i,e.t("formula.ok")),1)[0];if(null==this.$content){var c=h("<div></div>");c.on("click","#".concat(i),function(e){e.preventDefault();var r=c.find("#".concat(o)).val().trim();n.updateFormula(t,r),t.hidePanelOrModal()}),this.$content=c}var f=this.$content;f.html(""),f.append(s),f.append(u);var d=this.getValue(t);return a.val(d),setTimeout(function(){a.focus()}),f[0]},t.prototype.updateFormula=function(t,n){if(n&&(t.restoreSelection(),!this.isDisabled(t))){var o=this.getSelectedElem(t);if(null!=o){var r=e.DomEditor.findPath(t,o),i={value:n};e.SlateTransforms.setNodes(t,i,{at:r})}}},t}();function N(){return S("w-e-insert-formula")}var k=function(){function t(){this.title=e.t("formula.insert"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M941.6 734.72L985.984 640H1024l-64 384H0v-74.24l331.552-391.2L0 227.008V0h980L1024 256h-34.368l-18.72-38.88C935.584 143.744 909.024 128 832 128H169.984l353.056 353.056L225.632 832H768c116 0 146.656-41.568 173.6-97.28z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=300,this.$content=null,this.textareaId=N(),this.buttonId=N()}return t.prototype.getValue=function(t){return""},t.prototype.isActive=function(t){return!1},t.prototype.exec=function(t,e){},t.prototype.isDisabled=function(t){var n=t.selection;if(null==n)return!0;if(e.SlateRange.isExpanded(n))return!0;var o=e.DomEditor.getSelectedElems(t);return!!o.some(function(e){return t.isVoid(e)})||!!o.some(function(t){return"pre"===e.DomEditor.getNodeType(t)})},t.prototype.getModalPositionNode=function(t){return null},t.prototype.getModalContentElem=function(t){var n=this,o=this.textareaId,i=this.buttonId,l=r(e.genModalTextareaElems(e.t("formula.formula"),o,e.t("formula.placeholder")),2),s=l[0],a=h(l[1]),u=r(e.genModalButtonElems(i,e.t("formula.ok")),1)[0];if(null==this.$content){var c=h("<div></div>");c.on("click","#".concat(i),function(e){e.preventDefault();var r=c.find("#".concat(o)).val().trim();n.insertFormula(t,r),t.hidePanelOrModal()}),this.$content=c}var f=this.$content;return f.html(""),f.append(s),f.append(u),a.val(""),setTimeout(function(){a.focus()}),f[0]},t.prototype.insertFormula=function(t,e){if(e&&(t.restoreSelection(),!this.isDisabled(t))){var n={type:"formula",value:e,children:[{text:""}]};t.insertNode(n)}},t}();return{editorPlugin:function(t){var n=t.isInline,o=t.isVoid,r=t;return r.isInline=function(t){return"formula"===e.DomEditor.getNodeType(t)||n(t)},r.isVoid=function(t){return"formula"===e.DomEditor.getNodeType(t)||o(t)},r},renderElems:[{type:"formula",renderElem:function(t,o,r){var i=e.DomEditor.isNodeSelected(r,t),l=t.value,s=void 0===l?"":l,a=n.h("w-e-formula-card",{dataset:{value:s}},null);return n.h("div",{className:"w-e-textarea-formula-container",props:{contentEditable:!1},style:{display:"inline-block",marginLeft:"3px",marginRight:"3px",border:i?"2px solid var(--w-e-textarea-selected-border-color)":"2px solid transparent",borderRadius:"3px",padding:"3px 3px"}},[a])}}],elemsToHtml:[l],parseElemsHtml:[{selector:'span[data-w-e-type="formula"]',parseElemHtml:function(t,e,n){return{type:"formula",value:t.getAttribute("data-value")||"",children:[{text:""}]}}}],menus:[{key:"insertFormula",factory:function(){return new k}},{key:"editFormula",factory:function(){return new O}}]}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("katex"),require("@wangeditor-next/editor"),require("snabbdom")):"function"==typeof define&&define.amd?define(["katex","@wangeditor-next/editor","snabbdom"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).WangEditorFormulaPlugin=e(t.katex,t.editor,t.snabbdom)}(this,function(t,e,n){"use strict";var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)};function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,i=n.call(t),l=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)l.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return l}"function"==typeof SuppressedError&&SuppressedError,function(){if(void 0!==window.Reflect&&void 0!==window.customElements&&!window.customElements.polyfillWrapFlushCallback){var t=HTMLElement,e=function(){return Reflect.construct(t,[],this.constructor)};window.HTMLElement=e,HTMLElement.prototype=t.prototype,HTMLElement.prototype.constructor=HTMLElement,Object.setPrototypeOf(HTMLElement,t)}}();var i=function(e){function n(){var t=e.call(this)||this;return t.span=null,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,e),Object.defineProperty(n,"observedAttributes",{get:function(){return["data-value"]},enumerable:!1,configurable:!0}),n.prototype.attributeChangedCallback=function(t,e,n){if("data-value"===t){if(e===n)return;this.render(n||"")}},n.prototype.ensureSpan=function(){if(this.span)return this.span;var t=(this.ownerDocument||window.document).createElement("span");return t.style.display="inline-block",this.appendChild(t),this.span=t,t},n.prototype.render=function(e){var n=this.ensureSpan();t.render(e,n,{throwOnError:!1,output:"htmlAndMathml"})},n}(HTMLElement);window.customElements.get("w-e-formula-card")||window.customElements.define("w-e-formula-card",i),e.i18nAddResources("en",{formula:{formula:"Formula",placeholder:"Use LateX syntax",insert:"Insert formula",edit:"Edit formula",ok:"OK"}}),e.i18nAddResources("zh-CN",{formula:{formula:"公式",placeholder:"使用 LateX 语法",insert:"插入公式",edit:"编辑公式",ok:"确定"}});var l={type:"formula",elemToHtml:function(t,e){var n=t.value;return'<span data-w-e-type="formula" data-w-e-is-void data-w-e-is-inline data-value="'.concat(void 0===n?"":n,'"></span>')}};function s(t){return null!==t&&"object"==typeof t&&"constructor"in t&&t.constructor===Object}function a(t={},e={}){Object.keys(e).forEach(n=>{void 0===t[n]?t[n]=e[n]:s(e[n])&&s(t[n])&&Object.keys(e[n]).length>0&&a(t[n],e[n])})}const u={body:{},addEventListener(){},removeEventListener(){},activeElement:{blur(){},nodeName:""},querySelector:()=>null,querySelectorAll:()=>[],getElementById:()=>null,createEvent:()=>({initEvent(){}}),createElement:()=>({children:[],childNodes:[],style:{},setAttribute(){},getElementsByTagName:()=>[]}),createElementNS:()=>({}),importNode:()=>null,location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""}};function c(){const t="undefined"!=typeof document?document:{};return a(t,u),t}const f={document:u,navigator:{userAgent:""},location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""},history:{replaceState(){},pushState(){},go(){},back(){}},CustomEvent:function(){return this},addEventListener(){},removeEventListener(){},getComputedStyle:()=>({getPropertyValue:()=>""}),Image(){},Date(){},screen:{},setTimeout(){},clearTimeout(){},matchMedia:()=>({}),requestAnimationFrame:t=>"undefined"==typeof setTimeout?(t(),null):setTimeout(t,0),cancelAnimationFrame(t){"undefined"!=typeof setTimeout&&clearTimeout(t)}};function d(){const t="undefined"!=typeof window?window:{};return a(t,f),t}class p extends Array{constructor(t){"number"==typeof t?super(t):(super(...t||[]),function(t){const e=t.__proto__;Object.defineProperty(t,"__proto__",{get:()=>e,set(t){e.__proto__=t}})}(this))}}function h(t,e){const n=d(),o=c();let r=[];if(!e&&t instanceof p)return t;if(!t)return new p(r);if("string"==typeof t){const n=t.trim();if(n.indexOf("<")>=0&&n.indexOf(">")>=0){let t="div";0===n.indexOf("<li")&&(t="ul"),0===n.indexOf("<tr")&&(t="tbody"),0!==n.indexOf("<td")&&0!==n.indexOf("<th")||(t="tr"),0===n.indexOf("<tbody")&&(t="table"),0===n.indexOf("<option")&&(t="select");const e=o.createElement(t);e.innerHTML=n;for(let t=0;t<e.childNodes.length;t+=1)r.push(e.childNodes[t])}else r=function(t,e){if("string"!=typeof t)return[t];const n=[],o=e.querySelectorAll(t);for(let t=0;t<o.length;t+=1)n.push(o[t]);return n}(t.trim(),e||o)}else if(t.nodeType||t===n||t===o)r.push(t);else if(Array.isArray(t)){if(t instanceof p)return t;r=t}return new p(function(t){const e=[];for(let n=0;n<t.length;n+=1)-1===e.indexOf(t[n])&&e.push(t[n]);return e}(r))}function m(t){if(void 0===t){const t=this[0];if(!t)return;if(t.multiple&&"select"===t.nodeName.toLowerCase()){const e=[];for(let n=0;n<t.selectedOptions.length;n+=1)e.push(t.selectedOptions[n].value);return e}return t.value}for(let e=0;e<this.length;e+=1){const n=this[e];if(Array.isArray(t)&&n.multiple&&"select"===n.nodeName.toLowerCase())for(let e=0;e<n.options.length;e+=1)n.options[e].selected=t.indexOf(n.options[e].value)>=0;else n.value=t}return this}function v(...t){let[e,n,o,r]=t;function i(t){const e=t.target;if(!e)return;const r=t.target.dom7EventData||[];if(r.indexOf(t)<0&&r.unshift(t),h(e).is(n))o.apply(e,r);else{const t=h(e).parents();for(let e=0;e<t.length;e+=1)h(t[e]).is(n)&&o.apply(t[e],r)}}function l(t){const e=t&&t.target&&t.target.dom7EventData||[];e.indexOf(t)<0&&e.unshift(t),o.apply(this,e)}"function"==typeof t[1]&&([e,o,r]=t,n=void 0),r||(r=!1);const s=e.split(" ");let a;for(let t=0;t<this.length;t+=1){const e=this[t];if(n)for(a=0;a<s.length;a+=1){const t=s[a];e.dom7LiveListeners||(e.dom7LiveListeners={}),e.dom7LiveListeners[t]||(e.dom7LiveListeners[t]=[]),e.dom7LiveListeners[t].push({listener:o,proxyListener:i}),e.addEventListener(t,i,r)}else for(a=0;a<s.length;a+=1){const t=s[a];e.dom7Listeners||(e.dom7Listeners={}),e.dom7Listeners[t]||(e.dom7Listeners[t]=[]),e.dom7Listeners[t].push({listener:o,proxyListener:l}),e.addEventListener(t,l,r)}}return this}function y(t){if(void 0===t)return this[0]?this[0].innerHTML:null;for(let e=0;e<this.length;e+=1)this[e].innerHTML=t;return this}function g(t){const e=d(),n=c(),o=this[0];let r,i;if(!o||void 0===t)return!1;if("string"==typeof t){if(o.matches)return o.matches(t);if(o.webkitMatchesSelector)return o.webkitMatchesSelector(t);if(o.msMatchesSelector)return o.msMatchesSelector(t);for(r=h(t),i=0;i<r.length;i+=1)if(r[i]===o)return!0;return!1}if(t===n)return o===n;if(t===e)return o===e;if(t.nodeType||t instanceof p){for(r=t.nodeType?[t]:t,i=0;i<r.length;i+=1)if(r[i]===o)return!0;return!1}return!1}function E(...t){let e;const n=c();for(let o=0;o<t.length;o+=1){e=t[o];for(let t=0;t<this.length;t+=1)if("string"==typeof e){const o=n.createElement("div");for(o.innerHTML=e;o.firstChild;)this[t].appendChild(o.firstChild)}else if(e instanceof p)for(let n=0;n<e.length;n+=1)this[t].appendChild(e[n]);else this[t].appendChild(e)}return this}function b(t){const e=[];for(let n=0;n<this.length;n+=1){let o=this[n].parentNode;for(;o;)t?h(o).is(t)&&e.push(o):e.push(o),o=o.parentNode}return h(e)}function w(t){const e=[];for(let n=0;n<this.length;n+=1){const o=this[n].querySelectorAll(t);for(let t=0;t<o.length;t+=1)e.push(o[t])}return h(e)}h.fn=p.prototype;const x="resize scroll".split(" ");const L=(T="focus",function(...t){if(void 0===t[0]){for(let t=0;t<this.length;t+=1)x.indexOf(T)<0&&(T in this[t]?this[t][T]():h(this[t]).trigger(T));return this}return this.on(T,...t)});var T;E&&(h.fn.append=E),y&&(h.fn.html=y),m&&(h.fn.val=m),v&&(h.fn.on=v),L&&(h.fn.focus=L),g&&(h.fn.is=g),b&&(h.fn.parents=b),w&&(h.fn.find=w);function S(t){return"".concat(t,"-").concat(((t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[63&n[t]];return e})())}function M(){return S("w-e-insert-formula")}var O=function(){function t(){this.title=e.t("formula.edit"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M864 0a160 160 0 0 1 128 256l-64 64-224-224 64-64c26.752-20.096 59.968-32 96-32zM64 736l-64 288 288-64 592-592-224-224L64 736z m651.584-372.416l-448 448-55.168-55.168 448-448 55.168 55.168z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=300,this.$content=null,this.textareaId=M(),this.buttonId=M()}return t.prototype.getSelectedElem=function(t){var n=e.DomEditor.getSelectedNodeByType(t,"formula");return null==n?null:n},t.prototype.getValue=function(t){var e=this.getSelectedElem(t);return e&&e.value||""},t.prototype.isActive=function(t){return!1},t.prototype.exec=function(t,e){},t.prototype.isDisabled=function(t){var n=t.selection;return null==n||(!!e.SlateRange.isExpanded(n)||null==this.getSelectedElem(t))},t.prototype.getModalPositionNode=function(t){return this.getSelectedElem(t)},t.prototype.getModalContentElem=function(t){var n=this,o=this.textareaId,i=this.buttonId,l=r(e.genModalTextareaElems(e.t("formula.formula"),o,e.t("formula.placeholder")),2),s=l[0],a=h(l[1]),u=r(e.genModalButtonElems(i,e.t("formula.ok")),1)[0];if(null==this.$content){var c=h("<div></div>");c.on("click","#".concat(i),function(e){e.preventDefault();var r=c.find("#".concat(o)).val().trim();n.updateFormula(t,r),t.hidePanelOrModal()}),this.$content=c}var f=this.$content;f.html(""),f.append(s),f.append(u);var d=this.getValue(t);return a.val(d),setTimeout(function(){a.focus()}),f[0]},t.prototype.updateFormula=function(t,n){if(n&&(t.restoreSelection(),!this.isDisabled(t))){var o=this.getSelectedElem(t);if(null!=o){var r=e.DomEditor.findPath(t,o),i={value:n};e.SlateTransforms.setNodes(t,i,{at:r})}}},t}();function N(){return S("w-e-insert-formula")}var A=function(){function t(){this.title=e.t("formula.insert"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M941.6 734.72L985.984 640H1024l-64 384H0v-74.24l331.552-391.2L0 227.008V0h980L1024 256h-34.368l-18.72-38.88C935.584 143.744 909.024 128 832 128H169.984l353.056 353.056L225.632 832H768c116 0 146.656-41.568 173.6-97.28z"></path></svg>',this.tag="button",this.showModal=!0,this.modalWidth=300,this.$content=null,this.textareaId=N(),this.buttonId=N()}return t.prototype.getValue=function(t){return""},t.prototype.isActive=function(t){return!1},t.prototype.exec=function(t,e){},t.prototype.isDisabled=function(t){var n=t.selection;if(null==n)return!0;if(e.SlateRange.isExpanded(n))return!0;var o=e.DomEditor.getSelectedElems(t);return!!o.some(function(e){return t.isVoid(e)})||!!o.some(function(t){return"pre"===e.DomEditor.getNodeType(t)})},t.prototype.getModalPositionNode=function(t){return null},t.prototype.getModalContentElem=function(t){var n=this,o=this.textareaId,i=this.buttonId,l=r(e.genModalTextareaElems(e.t("formula.formula"),o,e.t("formula.placeholder")),2),s=l[0],a=h(l[1]),u=r(e.genModalButtonElems(i,e.t("formula.ok")),1)[0];if(null==this.$content){var c=h("<div></div>");c.on("click","#".concat(i),function(e){e.preventDefault();var r=c.find("#".concat(o)).val().trim();n.insertFormula(t,r),t.hidePanelOrModal()}),this.$content=c}var f=this.$content;return f.html(""),f.append(s),f.append(u),a.val(""),setTimeout(function(){a.focus()}),f[0]},t.prototype.insertFormula=function(t,e){if(e&&(t.restoreSelection(),!this.isDisabled(t))){var n={type:"formula",value:e,children:[{text:""}]};t.insertNode(n)}},t}();return{editorPlugin:function(t){var n=t.isInline,o=t.isVoid,r=t;return r.isInline=function(t){return"formula"===e.DomEditor.getNodeType(t)||n(t)},r.isVoid=function(t){return"formula"===e.DomEditor.getNodeType(t)||o(t)},r},renderElems:[{type:"formula",renderElem:function(t,o,r){var i=e.DomEditor.isNodeSelected(r,t),l=t.value,s=void 0===l?"":l,a=n.h("w-e-formula-card",{dataset:{value:s}},null);return n.h("div",{className:"w-e-textarea-formula-container",props:{contentEditable:!1},style:{display:"inline-block",marginLeft:"3px",marginRight:"3px",border:i?"2px solid var(--w-e-textarea-selected-border-color)":"2px solid transparent",borderRadius:"3px",padding:"3px 3px"}},[a])}}],elemsToHtml:[l],parseElemsHtml:[{selector:'span[data-w-e-type="formula"]',parseElemHtml:function(t,e,n){return{type:"formula",value:t.getAttribute("data-value")||"",children:[{text:""}]}}}],menus:[{key:"insertFormula",factory:function(){return new A}},{key:"editFormula",factory:function(){return new O}}]}});
2
2
  //# sourceMappingURL=index.js.map