@wangeditor-next/plugin-formula 2.0.8 → 6.1.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.
Files changed (41) hide show
  1. package/dist/basic-modules/src/modules/header/parse-elem-html.d.ts +2 -2
  2. package/dist/core/src/config/interface.d.ts +30 -2
  3. package/dist/core/src/editor/dom-editor.d.ts +1 -0
  4. package/dist/core/src/editor/interface.d.ts +16 -3
  5. package/dist/core/src/index.d.ts +4 -2
  6. package/dist/core/src/render/helper.d.ts +1 -2
  7. package/dist/core/src/to-html/index.d.ts +12 -0
  8. package/dist/editor/src/Boot.d.ts +2 -2
  9. package/dist/index.js +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +1 -1
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/list-module/src/locale/en.d.ts +3 -0
  14. package/dist/list-module/src/locale/zh-CN.d.ts +3 -0
  15. package/dist/list-module/src/module/custom-types.d.ts +13 -0
  16. package/dist/list-module/src/module/helpers.d.ts +14 -4
  17. package/dist/list-module/src/module/html-transform.d.ts +10 -0
  18. package/dist/list-module/src/module/menu/BaseMenu.d.ts +2 -2
  19. package/dist/list-module/src/module/outline-actions.d.ts +9 -0
  20. package/dist/list-module/src/module/parse-elem-html.d.ts +1 -2
  21. package/dist/list-module/src/module/plugin.d.ts +1 -1
  22. package/dist/list-module/src/utils/maps.d.ts +2 -1
  23. package/dist/table-module/src/locale/en.d.ts +13 -0
  24. package/dist/table-module/src/locale/zh-CN.d.ts +13 -0
  25. package/dist/table-module/src/module/cell-selection.d.ts +11 -0
  26. package/dist/table-module/src/module/column-resize.d.ts +3 -3
  27. package/dist/table-module/src/module/custom-types.d.ts +1 -0
  28. package/dist/table-module/src/module/helpers.d.ts +5 -0
  29. package/dist/table-module/src/module/menu/CellProperty.d.ts +5 -3
  30. package/dist/table-module/src/module/menu/TableProperty.d.ts +21 -7
  31. package/dist/table-module/src/module/render-elem/selection-overlay.d.ts +21 -0
  32. package/dist/table-module/src/module/row-resize.d.ts +2 -2
  33. package/dist/table-module/src/module/weak-maps.d.ts +3 -2
  34. package/dist/video-module/src/constants/svg.d.ts +3 -0
  35. package/dist/video-module/src/locale/en.d.ts +3 -0
  36. package/dist/video-module/src/locale/zh-CN.d.ts +3 -0
  37. package/dist/video-module/src/module/alignment.d.ts +10 -0
  38. package/dist/video-module/src/module/custom-types.d.ts +2 -1
  39. package/dist/video-module/src/module/menu/VideoAlignMenu.d.ts +18 -0
  40. package/dist/video-module/src/module/menu/index.d.ts +13 -0
  41. package/package.json +4 -4
@@ -5,7 +5,7 @@
5
5
  import { IDomEditor } from '@wangeditor-next/core';
6
6
  import { Descendant } from 'slate';
7
7
  import { DOMElement } from '../../utils/dom';
8
- import { Header1Element, Header2Element, Header3Element, Header4Element, Header5Element } from './custom-types';
8
+ import { Header1Element, Header2Element, Header3Element, Header4Element, Header5Element, Header6Element } from './custom-types';
9
9
  export declare const parseHeader1HtmlConf: {
10
10
  selector: string;
11
11
  parseElemHtml: (elem: DOMElement, children: Descendant[], editor: IDomEditor) => Header1Element;
@@ -28,5 +28,5 @@ export declare const parseHeader5HtmlConf: {
28
28
  };
29
29
  export declare const parseHeader6HtmlConf: {
30
30
  selector: string;
31
- parseElemHtml: (elem: DOMElement, children: Descendant[], editor: IDomEditor) => Header5Element;
31
+ parseElemHtml: (elem: DOMElement, children: Descendant[], editor: IDomEditor) => Header6Element;
32
32
  };
@@ -2,13 +2,41 @@
2
2
  * @description config interface
3
3
  * @author wangfupeng
4
4
  */
5
- import type { ImageElement } from 'packages/basic-modules/src/modules/image/custom-types';
6
- import type { VideoElement } from 'packages/video-module/src/module/custom-types';
7
5
  import type { Descendant, Node, NodeEntry, Range } from 'slate';
8
6
  import type { IDomEditor } from '../editor/interface';
9
7
  import type { IMenuGroup } from '../menus/interface';
10
8
  import type { IUploadConfig } from '../upload/interface';
11
9
  import type { DOMElement } from '../utils/dom';
10
+ type EmptyText = {
11
+ text: '';
12
+ };
13
+ type ImageElement = {
14
+ type: 'image';
15
+ src: string;
16
+ alt?: string;
17
+ href?: string;
18
+ width?: string;
19
+ height?: string;
20
+ style?: {
21
+ width?: string;
22
+ height?: string;
23
+ };
24
+ children: EmptyText[];
25
+ };
26
+ type VideoElement = {
27
+ type: 'video';
28
+ key?: string;
29
+ src: string;
30
+ poster?: string;
31
+ align?: 'left' | 'center' | 'right';
32
+ width?: string;
33
+ height?: string;
34
+ style?: {
35
+ width?: string;
36
+ height?: string;
37
+ };
38
+ children: EmptyText[];
39
+ };
12
40
  interface IHoverbarConf {
13
41
  [key: string]: {
14
42
  match?: (editor: IDomEditor, n: Node) => boolean;
@@ -109,6 +109,7 @@ export declare const DomEditor: {
109
109
  getNodeType(node: Node): string;
110
110
  checkNodeType(node: Node, type: string): boolean;
111
111
  getNodesStr(nodes: Node[]): string;
112
+ getSelectedVoidNode(editor: IDomEditor): Element | null;
112
113
  getSelectedElems(editor: IDomEditor): Element[];
113
114
  getSelectedNodeByType(editor: IDomEditor, type: string): Node | null;
114
115
  getSelectedTextNode(editor: IDomEditor): Node | null;
@@ -2,15 +2,28 @@
2
2
  * @description editor interface
3
3
  * @author wangfupeng
4
4
  */
5
- import { NodeEntryWithContext } from '@wangeditor-next/table-module/src/utils';
6
5
  import ee from 'event-emitter';
7
- import { Ancestor, Editor, Element, Location, Node } from 'slate';
6
+ import { Ancestor, Editor, Element, Location, Node, NodeEntry } from 'slate';
8
7
  import { AlertType, IEditorConfig, IMenuConfig, ISingleMenuConfig } from '../config/interface';
9
8
  import { IPositionStyle } from '../menus/interface';
10
9
  import { DOMElement } from '../utils/dom';
11
10
  export type ElementWithId = Element & {
12
11
  id: string;
13
12
  };
13
+ export type TableSelectionEntry = [
14
+ NodeEntry<Element & {
15
+ type: unknown;
16
+ rowSpan?: number;
17
+ colSpan?: number;
18
+ hidden?: boolean;
19
+ }>,
20
+ {
21
+ rtl: number;
22
+ ltr: number;
23
+ ttb: number;
24
+ btt: number;
25
+ }
26
+ ];
14
27
  type MoveOptions = Parameters<Editor['move']>[0];
15
28
  export type getMenuConfigReturnType<K> = K extends keyof IMenuConfig ? IMenuConfig[K] : ISingleMenuConfig;
16
29
  /**
@@ -59,7 +72,7 @@ export interface IDomEditor extends Editor {
59
72
  move(distance: number, reverse?: boolean): void;
60
73
  moveReverse: (distance: number) => void;
61
74
  restoreSelection: () => void;
62
- getTableSelection?: () => NodeEntryWithContext[][] | null;
75
+ getTableSelection?: () => TableSelectionEntry[][] | null;
63
76
  getSelectionPosition: () => Partial<IPositionStyle>;
64
77
  getNodePosition: (node: Node) => Partial<IPositionStyle>;
65
78
  isSelectedAll: () => boolean;
@@ -7,11 +7,12 @@ import type { IDomEditor } from './editor/interface';
7
7
  import type { IRegisterMenuConf } from './menus/index';
8
8
  import type { IParseElemHtmlConf, IPreParseHtmlConf, ParseStyleHtmlFnType } from './parse-html/index';
9
9
  import type { IRenderElemConf, RenderStyleFnType } from './render/index';
10
- import type { IElemToHtmlConf, styleToHtmlFnType } from './to-html/index';
10
+ import type { HtmlTransformFnType, IElemToHtmlConf, styleToHtmlFnType } from './to-html/index';
11
11
  import createUploaderRuntime from './upload/createUploader';
12
12
  import type { IUploadConfig } from './upload/interface';
13
13
  export * from './create/index';
14
- export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
14
+ export type { ClassStylePolicy, IClassStyleUnsupportedPayload, IEditorConfig, ISingleMenuConfig, IToolbarConfig, IUploadImageConfig, IUploadVideoConfig, StyleClassTokenType, TextStyleMode, } from './config/interface';
15
+ export { EditorEvents } from './config/interface';
15
16
  export * from './config/style-mode';
16
17
  export * from './editor/dom-editor';
17
18
  export * from './editor/interface';
@@ -35,6 +36,7 @@ export interface IModuleConf {
35
36
  renderStyle: RenderStyleFnType;
36
37
  renderElems: Array<IRenderElemConf>;
37
38
  styleToHtml: styleToHtmlFnType;
39
+ htmlTransform?: HtmlTransformFnType;
38
40
  elemsToHtml: Array<IElemToHtmlConf>;
39
41
  preParseHtml: Array<IPreParseHtmlConf>;
40
42
  parseStyleHtml: ParseStyleHtmlFnType;
@@ -2,6 +2,5 @@
2
2
  * @description formats helper
3
3
  * @author wangfupeng
4
4
  */
5
- import { ElementType } from 'packages/custom-types';
6
- export declare function genElemId(type: ElementType, id: string): string;
5
+ export declare function genElemId(type: string, id: string): string;
7
6
  export declare function genTextId(id: string): string;
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { Descendant, Element as SlateElement } from 'slate';
6
6
  import { IDomEditor } from '../editor/interface';
7
+ import type { INodeToHtmlOptions } from './node2html';
7
8
  export type styleToHtmlFnType = (node: Descendant, elemHtml: string, editor?: IDomEditor) => string;
8
9
  export declare const STYLE_TO_HTML_FN_LIST: styleToHtmlFnType[];
9
10
  /**
@@ -11,6 +12,17 @@ export declare const STYLE_TO_HTML_FN_LIST: styleToHtmlFnType[];
11
12
  * @param fn 处理 toHtml 文本样式的函数
12
13
  */
13
14
  export declare function registerStyleToHtmlHandler(fn: styleToHtmlFnType): void;
15
+ /**
16
+ * Transform the HTML fragments of the document's top-level nodes.
17
+ *
18
+ * Element serializers intentionally stay node-local. Modules that need
19
+ * neighboring blocks to produce valid HTML (for example semantic lists) use
20
+ * this hook after every node has been serialized.
21
+ */
22
+ export type HtmlTransformFnType = (htmlList: string[], nodes: Descendant[], editor: IDomEditor, options: INodeToHtmlOptions) => string[];
23
+ export declare const HTML_TRANSFORM_HANDLER_LIST: HtmlTransformFnType[];
24
+ export declare function registerHtmlTransformHandler(fn: HtmlTransformFnType): void;
25
+ export declare function transformHtml(htmlList: string[], nodes: Descendant[], editor: IDomEditor, options?: INodeToHtmlOptions): string[];
14
26
  interface IElemToHtmlRes {
15
27
  html: string;
16
28
  prefix?: string;
@@ -2,9 +2,8 @@
2
2
  * @description Editor View class
3
3
  * @author wangfupeng
4
4
  */
5
- import type { IEditorConfig, IElemToHtmlConf, IModuleConf, IParseElemHtmlConf, IPreParseHtmlConf, IRegisterMenuConf, IRenderElemConf, IToolbarConfig, ParseStyleHtmlFnType, RenderStyleFnType, styleToHtmlFnType } from '@wangeditor-next/core';
5
+ import type { HtmlTransformFnType, IEditorConfig, IElemToHtmlConf, IModuleConf, IParseElemHtmlConf, IPreParseHtmlConf, IRegisterMenuConf, IRenderElemConf, ISingleMenuConfig, IToolbarConfig, ParseStyleHtmlFnType, RenderStyleFnType, styleToHtmlFnType } from '@wangeditor-next/core';
6
6
  import { IDomEditor } from '@wangeditor-next/core';
7
- import type { ISingleMenuConfig } from 'packages/core/src/config/interface';
8
7
  type PluginType = <T extends IDomEditor>(editor: T) => T;
9
8
  declare class Boot {
10
9
  constructor();
@@ -23,6 +22,7 @@ declare class Boot {
23
22
  static registerRenderStyle(fn: RenderStyleFnType): void;
24
23
  static registerElemToHtml(elemToHtmlConf: IElemToHtmlConf): void;
25
24
  static registerStyleToHtml(fn: styleToHtmlFnType): void;
25
+ static registerHtmlTransform(fn: HtmlTransformFnType): void;
26
26
  static registerPreParseHtml(preParseHtmlConf: IPreParseHtmlConf): void;
27
27
  static registerParseElemHtml(parseElemHtmlConf: IParseElemHtmlConf): void;
28
28
  static registerParseStyleHtml(fn: ParseStyleHtmlFnType): void;
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;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}}]}});
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 this.style.display="inline-block",this.style.maxWidth="100%",t.style.display="inline-block",t.style.maxWidth="100%",this.appendChild(t),this.span=t,t},n.prototype.render=function(e){var n=this.ensureSpan();t.render(e,n,{throwOnError:!1,output:"htmlAndMathml"});var o=n.querySelector(".katex-error");o&&(o.style.whiteSpace="normal",o.style.overflowWrap="anywhere",o.style.wordBreak="break-word")},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 d={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 f(){const t="undefined"!=typeof window?window:{};return a(t,d),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=f(),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 y(...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 v(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=f(),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=(S="focus",function(...t){if(void 0===t[0]){for(let t=0;t<this.length;t+=1)x.indexOf(S)<0&&(S in this[t]?this[t][S]():h(this[t]).trigger(S));return this}return this.on(S,...t)});var S;E&&(h.fn.append=E),v&&(h.fn.html=v),m&&(h.fn.val=m),y&&(h.fn.on=y),L&&(h.fn.focus=L),g&&(h.fn.is=g),b&&(h.fn.parents=b),w&&(h.fn.find=w);function T(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 T("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 d=this.$content;d.html(""),d.append(s),d.append(u);var f=this.getValue(t);return a.val(f),setTimeout(function(){a.focus()}),d[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 k(){return T("w-e-insert-formula")}var N=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=k(),this.buttonId=k()}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 d=this.$content;return d.html(""),d.append(s),d.append(u),a.val(""),setTimeout(function(){a.focus()}),d[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",maxWidth:"100%",overflowX:"auto",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 N}},{key:"editFormula",factory:function(){return new O}}]}});
2
2
  //# sourceMappingURL=index.js.map