UNPKG

@edtr-io/plugin-text

Version:
3 lines (2 loc) 42.7 kB
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t,n,r=require("@edtr-io/plugin"),o=require("slate"),i=e(require("slate-html-serializer")),l=require("react"),a=require("@edtr-io/core"),c=require("@edtr-io/store"),u=require("is-hotkey"),s=e(u),d=require("ramda"),f=require("slate-react"),g=require("@edtr-io/plugin-rows/internal"),p=require("@edtr-io/ui"),m=require("@edtr-io/editor-ui"),v=require("@edtr-io/core/beta"),h=require("@edtr-io/math"),y=e(require("@convertkit/slate-lists")),b="@splish-me/a",k="@splish-me/color",E="@splish-me/strong",C="@splish-me/em",x="@splish-me/katex-inline",w="@splish-me/katex-block",T=function(e){return"@splish-me/h"+e},S={inlines:(t={},t[x]={isVoid:!0},t[b]={text:/.+/},t),blocks:(n={},n[w]={isVoid:!0},n)},j={document:{nodes:[{object:"block",type:"paragraph",nodes:[{object:"text"}]}]}},O=new i({rules:[{serialize:function(e,t){if("string"===e.object)return t.replace(new RegExp("[\\r\\n]","g"),"")},deserialize:function(e){if(e.tagName&&"br"===e.tagName.toLowerCase())return null;if("#text"===e.nodeName){if(e.nodeValue&&/<!--(.|\n)*?-->/.exec(e.nodeValue))return;return{object:"text",text:(e.nodeValue?e.nodeValue:"").replace(new RegExp("[\\r\\n\\t]","g"),""),marks:[]}}}},{serialize:function(e,t){if("block"===e.object&&("paragraph"===e.type||"@splish-me/p"===e.type))return l.createElement("p",null,t)},deserialize:function(e,t){if("p"===e.tagName.toLowerCase())return{object:"block",type:"paragraph",nodes:t(e.childNodes)}}},{serialize:function(e,t){if("mark"===e.object)switch(e.type){case E:return l.createElement("strong",null,t);case C:return l.createElement("em",null,t);default:return l.createElement(l.Fragment,null,t)}},deserialize:function(e,t){switch(e.tagName.toLowerCase()){case"strong":case"b":return{object:"mark",type:E,nodes:t(e.childNodes)};case"em":case"i":return{object:"mark",type:C,nodes:t(e.childNodes)};default:return}}},{serialize:function(e,t){if("inline"===e.object&&e.type===b){var n=e.data;return n?l.createElement("a",{href:n.get("href")},t):null}},deserialize:function(e,t){if("a"===e.tagName.toLowerCase()){var n=e.getAttribute("href");return{object:"inline",type:b,nodes:t(e.childNodes),data:o.Data.create({href:n||""})}}}},{serialize:function(e,t){var n=e;if("block"===n.object)for(var r=1;r<=6;r++){var o=T(r);if(n.type===o)return l.createElement("h"+r,{},t)}},deserialize:function(e,t){var n=/h([1-6])/.exec(e.tagName.toLowerCase());if(n){var r=parseInt(n[1],10);return console.log("create heading",r),{object:"block",type:T(r),nodes:t(e.childNodes)}}}},{serialize:function(e,t){if("block"===e.object)switch(e.type){case"unordered-list":return l.createElement("ul",null,t);case"ordered-list":return l.createElement("ol",null,t);case"list-item":return l.createElement("li",null,t);case"list-item-child":return l.createElement(l.Fragment,null,t)}},deserialize:function(e,t){switch(e.tagName.toLowerCase()){case"ol":return{object:"block",type:"ordered-list",nodes:t(e.childNodes)};case"ul":return{object:"block",type:"unordered-list",nodes:t(e.childNodes)};case"li":return{object:"block",type:"list-item",nodes:[{object:"block",type:"list-item-child",nodes:t(e.childNodes)}]}}}},{serialize:function(e,t){var n=e;return"block"===n.object&&n.type===w?l.createElement("katexblock",null,n.data.get("formula")):"inline"===e.object&&e.type===x?l.createElement("katexinline",null,n.data.get("formula")):void 0},deserialize:function(e,t){switch(e.tagName.toLowerCase()){case"katexblock":return{object:"block",type:w,data:{formula:e.childNodes[0].nodeValue,inline:!1},nodes:t(e.childNodes)};case"katexinline":return{object:"inline",type:x,data:{formula:e.childNodes[0].nodeValue,inline:!0},nodes:t(e.childNodes)};default:return}}},{serialize:function(e,t){if("mark"===e.object&&e.type===k){var n=e.data.get("colorIndex");return l.createElement("color",{index:n},t)}},deserialize:function(e,t){if("color"===e.tagName.toLowerCase()){var n=e.getAttribute("index");return{object:"mark",type:b,nodes:t(e.childNodes),data:o.Data.create({colorIndex:parseInt(n||"")})}}}}],defaultBlock:{type:"paragraph"}});function N(e){return O.deserialize(e,{toJSON:!1})}function D(e){var t=e.document.nodes.get(0);return""===e.document.text&&1===e.document.nodes.size&&1===e.document.getTexts().size&&void 0!==t&&"text"!==t.object&&"paragraph"===t.type}function I(){return(I=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function L(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function B(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])>=0||(o[n]=e[n]);return o}function A(e){return e.value.document.getActiveMarksAtRange(R(e))}function M(e){var t=document.getSelection();if(t){for(var n=t.toString();n.startsWith(" ");)e.moveStartForward(1),n=n.substring(1);for(;n.endsWith(" ");)e.moveEndBackward(1),n=n.substring(0,n.length-1)}}function R(e){var t=document.getSelection(),n=e.value.selection.toRange();if(t){for(var r=t.toString();r.startsWith(" ");)n=n.moveStartForward(1),r=r.substring(1);for(;r.endsWith(" ");)n=n.moveEndBackward(1),r=r.substring(0,r.length-1)}return o.Range.create(n)}var P=function(e){return e.value.document.getActiveMarksAtRange(R(e))},z=function(e){return function(t){return P(t).some((function(t){return!!t&&(void 0===e?t.type===k:t.type===k&&t.data.get("colorIndex")==e)}))}},F=function(e){return e.value.marks.toArray().filter((function(e){return e.type===k})).reduce((function(t,n){return e.removeMark(n)}),e)},q=function(e){if(z()(e)){var t=P(e).find((function(e){return!!e&&e.type===k}));return null==t?void 0:t.data.get("colorIndex")}},V=p.styled.span((function(e){var t=e.config.theme.plugins.colors.colors;return{color:t[e.colorIndex%t.length]}})),K=function(e){function t(){return e.apply(this,arguments)||this}return L(t,e),t.prototype.render=function(){var e=this.props,t=e.children;return l.createElement(V,Object.assign({config:e.config,colorIndex:e.colorIndex},e.attributes),t)},t}(l.Component),H=function(e){var t=(void 0===e?{}:e).EditorComponent,n=void 0===t?K:t;return function(e){return{renderMark:function(t,r,o){var i=e.current?e.current.config:void 0,a=t.mark;if(!i)return null;if("mark"===a.object&&a.type===k){var c=a.data.get("colorIndex");return l.createElement(n,Object.assign({config:i,colorIndex:c},t))}return o()}}}},_=p.styled.button((function(e){var t=e.config.theme;return{backgroundColor:e.active?t.active.backgroundColor:t.backgroundColor,cursor:"pointer",boxShadow:e.active?"inset 0 1px 3px 0 rgba(0,0,0,0.50)":void 0,color:e.active?t.active.color:t.color,outline:"none",height:"25px",border:"none",borderRadius:"4px",margin:"5px",padding:"0px",width:"25px","&:hover":{color:t.hoverColor}}})),J=p.styled.div((function(e){return{display:"inline-block",backgroundColor:e.color,borderRadius:" 100%",width:"19px",height:"19px",margin:"3px",verticalAlign:"middle"}}));function W(e){var t=e.config,n=t.i18n,r=t.theme.plugins.colors,o=r.colors,i=r.defaultColor;return l.createElement(l.Fragment,null,l.createElement(_,{active:!z()(e.editor),config:e.config,onClick:function(){F(e.editor).moveToEnd().focus(),e.switchControls(Pe.All),e.onChange(e.editor)},title:n.colors.resetColorTitle},l.createElement(J,{color:i})),o.map((function(t,r){return l.createElement(_,{config:e.config,key:r,active:z(r)(e.editor),onClick:function(){var t;M(e.editor),(t=r,function(e){return z(t)(e)?F(e):F(e).addMark({type:k,data:{colorIndex:t}})})(e.editor).moveToEnd().focus(),e.switchControls(Pe.All),e.onChange(e.editor)},title:n.colors.setColorTitle},l.createElement(J,{color:t}))})),l.createElement(_,{config:e.config,onClick:function(){return e.switchControls(Pe.All)},title:n.colors.closeMenuTitle},l.createElement(p.EdtrIcon,{icon:p.edtrClose})))}var U=p.styled.span({position:"relative",verticalAlign:"middle",display:"inline-block"}),$=p.styled.span({display:"flex",alignItems:"center",flexDirection:"column"}),Q=p.styled.span((function(e){var t=e.config.theme.plugins.colors,n=t.colors;return{border:"2px solid "+(void 0===e.index?t.defaultColor:n[e.index%n.length]),borderRadius:"4px",bottom:"0",width:"80%",position:"absolute"}}));function X(e){return l.createElement(U,null,l.createElement($,null,l.createElement(p.EdtrIcon,{icon:p.edtrColorText}),l.createElement(Q,{config:e.config,index:e.index})))}var Z=function(e,t){if(!t.current)return!1;var n=t.current,r=n.config,o=n.store,i=c.getParent(n.id)(o.getState());if(!i)return!1;var l=c.getDocument(i.id)(o.getState());return!!l&&l.plugin===r.blockquote},G=function(e,t){if(t.current){var n=t.current,r=n.config;if(r.blockquote){var o=r.blockquote;n.store.dispatch(c.wrap({id:n.id,document:function(e){return{plugin:o,state:e}}}))}}},Y=function(e){return A(e).some((function(e){return!!e&&"code"===e.type}))},ee=function(e){return M(e),e.toggleMark("code")},te=function(e){function t(){return e.apply(this,arguments)||this}return L(t,e),t.prototype.render=function(){var e=this.props,t=e.children;return"code"===e.mark.type?l.createElement("code",Object.assign({},e.attributes),t):null},t}(l.Component),ne=["level","children"],re=l.forwardRef((function(e,t){var n=e.level,r=e.children,o=B(e,ne);return l.createElement("h"+(n<=6&&n>=1?n:6),I({},o,{ref:t}),r)}));re.displayName="Heading";var oe=function(e){function t(){return e.apply(this,arguments)||this}return L(t,e),t.prototype.render=function(){var e=this.props,t=e.children;return l.createElement(re,Object.assign({level:e.level},e.attributes),t)},t}(l.Component),ie=function(e){return function(t){var n=T(e);return t.value.blocks.some((function(e){return!!e&&e.type===n}))}},le=function(e){return function(t){var n=T(e);return t.setBlocks(n)}},ae=function(e){return d.find((function(t){return ie(t)(e)}),[1,2,3,4,5,6])},ce=function(e){var t=(void 0===e?{}:e).EditorComponent,n=void 0===t?oe:t;return function(){return{renderBlock:function(e,t,r){var o=/@splish-me\/h([1-6])/.exec(e.node.type);if(o){var i=parseInt(o[1],10);return l.createElement(n,Object.assign({level:i},e))}return r()}}}},ue=function(e){return function(t){var n=t.value,r=n.document,o=n.startBlock;if(!o||"list-item-child"!==o.type)return!1;var i=r.getParent(o.key);return r.getParent(i.key).type===e}},se=function(e){return void 0===e&&(e="unordered-list"),function(t){return t.command("toggleList",{type:e})}};v.setDefaultPreference("katex:usevisualmath",!0);var de=function(e){var t=e.attributes,n=e.editor,r=e.readOnly,o=e.node,i=o.key,a=o.type,c=o.data,u=c.get("formula"),s=c.get("inline"),d=l.useContext(v.PreferenceContext);return l.createElement(h.MathEditor,{state:u,inline:c.get("inline"),readOnly:!e.isSelected||!n.value.selection.isCollapsed||r,visual:!0===d.getKey("katex:usevisualmath"),disableBlock:ue("ordered-list")(n.controller)||ue("unordered-list")(n.controller)||e.config.noLinebreaks,config:{i18n:e.config.i18n.math,theme:e.config.theme},onBlur:function(){n.blur()},onEditorChange:function(e){d.setKey("katex:usevisualmath",e)},onInlineChange:function(e){var t={formula:u,inline:e};if(o.isLeafBlock()){var r=n.value.document.getNextBlock(o.key);n.removeNodeByKey(o.key),r&&n.mergeNodeByKey(r.key)}else n.removeNodeByKey(o.key);e?n.insertInline({type:x,data:t}):n.insertBlock({type:w,data:t})},onChange:function(e){n.setNodeByKey(i,{type:a,data:{formula:e,inline:s}})},onMoveOutLeft:function(){n.moveToStart().moveBackward(1).focus()},onMoveOutRight:function(){n.moveToEnd().moveForward(1).focus()},onDeleteOutLeft:function(){n.delete().focus()},additionalContainerProps:t})},fe=function(e){return e.value.blocks.some((function(e){return!!e&&e.type===w}))||e.value.inlines.some((function(e){return!!e&&e.type===x}))},ge=function(e){if(e.value.selection.isExpanded){M(e);var t=document.getSelection();return e.wrapInline({type:x,data:{formula:t?t.toString():"",inline:!0}}).moveToEnd(),e.focus().moveBackward(1)}return e.insertInline({type:x,data:{formula:"",inline:!0}})},pe=function(e){var t=(void 0===e?{}:e).EditorComponent,n=void 0===t?de:t;return function(e){function t(t){var r=e.current?e.current.config:void 0;return r?l.createElement(n,Object.assign({config:r},t)):null}return{onKeyDown:function(e,t,n){var r=e;return u.isHotkey("mod+m")(r)?(r.preventDefault(),ge(t)):n()},renderInline:function(e,n,r){return e.node.type===x?t(e):r()},renderBlock:function(e,n,r){return e.node.type===w?t(e):r()}}}},me=l.createContext(void 0),ve=p.styled.input({backgroundColor:"transparent",border:"none",borderBottom:"2px solid #ffffff",color:"#ffffff","&:focus":{outline:"none",borderBottom:"2px solid rgb(70, 155, 255)"}}),he=function(e,t){return l.createElement(ve,Object.assign({},e,{ref:t}))},ye=l.forwardRef(he),be=["position"],ke=p.styled.span({padding:"0px 8px"}),Ee=p.styled.div({padding:"5px 5px 5px 10px",display:"inline-block",borderLeft:"2px solid rgba(51,51,51,0.95)",cursor:"pointer",margin:"2px","&:hover":{color:"rgb(70, 155, 255)"}});function Ce(e){var t=e.position,n=void 0===t?"below":t,r=B(e,be);return l.createElement(m.HoverOverlay,{position:n,anchor:r.anchor},l.createElement(ke,null,r.children),l.createElement(Ee,{onClick:r.onDelete},l.createElement(p.Icon,{icon:p.faTrashAlt})))}var xe=m.styled.span({margin:"0 0 0 10px"}),we=function(e){return e.value.inlines.some((function(e){return!!e&&e.type===b}))},Te=function(e){return e.unwrapInline(b)},Se=function(e){return void 0===e&&(e={href:""}),function(t){return t.value.selection.isExpanded?(M(t),t.wrapInline({type:b,data:e}).moveToEnd().focus().moveBackward(1)):t.insertText(" ").focus().moveFocusBackward(1).wrapInline({type:b,data:e}).moveToStart()}},je=function(e){var t=e.attributes,n=e.children,r=e.isSelected,o=e.node.data.get("href");return l.createElement("a",Object.assign({},t,{href:o,style:r?{textDecoration:"underline"}:void 0}),n)},Oe=function(e){var t,n=l.useContext(me),r=e.editor,o=r.value.inlines.find((function(e){return!!e&&e.type===b})),i=l.useRef(o),a=l.useState(o?o.data.get("href"):void 0),c=a[0],u=a[1],s=!e.readOnly&&we(r)&&r.value.selection.isCollapsed,d=l.useRef(s);if(l.useEffect((function(){d.current!==s&&(o&&void 0!==c&&c!==o.data.get("href")&&g(c,o,r),d.current=s)}),[s,o,c,r]),!o)return l.createElement(l.Fragment,null,e.children);if(void 0===c||(null==(t=i.current)?void 0:t.key)!==o.key){var f=o.data.get("href");u(f),i.current=o}function g(e,t,n){n.setNodeByKey(t.key,{type:t.type,data:{href:e}})}return l.createElement(l.Fragment,null,e.children,!e.readOnly&&we(r)&&r.value.selection.isCollapsed?l.createElement(Ce,{key:o.key,onDelete:function(){return Te(r).focus()},position:"below"},l.createElement(ye,{value:c,placeholder:n.link.placeholder,onChange:function(e){var t=e.target.value;u(t),g(t,o,r)},onKeyDown:function(e){"Enter"===e.key&&(e.preventDefault(),void 0!==c&&g(c,o,r),r.focus())},onBlur:function(e){var t=e.target.value;new RegExp("^([_\\-a-zA-Z0-9.]+\\.[\\w]{2,})").test(t)&&u("https://"+t)},ref:function(e){e&&(d.current||c||setTimeout((function(){r.blur(),setTimeout((function(){e.focus()}))})))}}),l.createElement("a",{target:"_blank",href:c,rel:"noopener noreferrer"},l.createElement(xe,{title:n.link.openInNewTabTitle},l.createElement(p.Icon,{icon:p.faExternalLinkAlt})))):null)},Ne=function(e){var t=void 0===e?{}:e,n=t.EditorComponent,r=void 0===n?je:n,o=t.ControlsComponent,i=void 0===o?Oe:o;return function(){return{onKeyDown:function(e,t,n){var r=e;return s("mod+k",r)?(r.preventDefault(),we(t)?Te(t):Se()(t)):n()},renderInline:function(e,t,n){return e.node.type===b?l.createElement(r,Object.assign({},e)):n()},renderEditor:function(e,t,n){var r=n();return e.readOnly?r:l.createElement(i,Object.assign({},e,{editor:t}),r)}}}},De=function(e){return A(e).some((function(e){return!!e&&e.type===E}))},Ie=function(e){return A(e).some((function(e){return!!e&&e.type===C}))},Le=function(e){return M(e),e.toggleMark(E)},Be=function(e){return M(e),e.toggleMark(C)},Ae=function(e){function t(){return e.apply(this,arguments)||this}return L(t,e),t.prototype.render=function(){var e=this.props,t=e.attributes,n=e.children;switch(e.mark.type){case E:return l.createElement("strong",Object.assign({},t),n);case C:return l.createElement("em",Object.assign({},t),n);default:return null}},t}(l.Component),Me=function(e){var t=(void 0===e?{}:e).EditorComponent,n=void 0===t?Ae:t;return function(){return{onKeyDown:function(e,t,n){var r=e;return u.isHotkey("mod+b")(r)?(r.preventDefault(),Le(t)):u.isHotkey("mod+i")(r)?(r.preventDefault(),Be(t)):n()},renderMark:function(e,t,r){var o=e.mark;return"mark"===o.object&&[E,C].includes(o.type)?l.createElement(n,Object.assign({},e)):r()}}}};function Re(e){var t=e.editor,n=e.config,r=e.pluginClosure,o=e.plugins;return l.createElement(l.Fragment,null,o.richText?l.createElement(l.Fragment,null,l.createElement(_,{config:n,active:De(t),onClick:function(){Le(t).focus(),e.onChange(t)},title:n.i18n.richText.toggleStrongTitle},l.createElement(p.EdtrIcon,{icon:p.edtrBold})),l.createElement(_,{config:n,active:Ie(t),onClick:function(){Be(t).focus(),e.onChange(t)},title:n.i18n.richText.toggleEmphasizeTitle},l.createElement(p.EdtrIcon,{icon:p.edtrItalic}))):null,o.links?l.createElement(_,{config:n,active:we(t),onClick:function(){we(t)?Te(t).focus():Se()(t),e.onChange(t)},title:n.i18n.link.toggleTitle},l.createElement(p.EdtrIcon,{icon:p.edtrLink})):null,o.headings?l.createElement(_,{config:n,active:!!ae(e.editor),onClick:function(){e.switchControls(Pe.Headings)},title:n.i18n.headings.openMenuTitle},l.createElement(p.EdtrIcon,{icon:p.edtrText})):null,o.colors?l.createElement(_,{config:n,onClick:function(){return e.switchControls(Pe.Colors)},title:n.i18n.colors.openMenuTitle},l.createElement(X,{config:e.config,index:q(t)})):null,o.lists?l.createElement(_,{config:n,onClick:function(){ue("unordered-list")(t)||ue("ordered-list")(t)||(se("unordered-list")(e.editor).focus(),e.onChange(t)),e.switchControls(Pe.Lists)},title:n.i18n.list.openMenuTitle},l.createElement(p.EdtrIcon,{icon:ue("ordered-list")(t)?p.edtrListNumbered:p.edtrListBullets})):null,n.blockquote?l.createElement(_,{config:n,active:Z(0,r),onClick:function(){Z(0,r)?(function(e,t){if(Z(0,t)){if(!t.current)return;var n=t.current,r=n.id,o=n.store;if(!n.config.blockquote)return;var i=c.getParent(r)(o.getState());if(!i)return;o.dispatch(c.unwrap({id:i.id,oldId:r}))}}(0,r),e.onChange(t)):(G(0,r),e.onChange(t))},title:n.i18n.blockquote.toggleTitle},l.createElement(p.EdtrIcon,{icon:p.edtrQuote})):null,o.math?l.createElement(_,{config:n,active:fe(t),onClick:function(){fe(t)?function(e){var t=e.value.blocks.toArray().find((function(e){return e.type===w}))||e.value.inlines.toArray().find((function(e){return e.type===x}));return t?e.removeNodeByKey(t.key):e}(t).focus():ge(t),e.onChange(t)},title:n.i18n.math.toggleTitle},l.createElement(p.EdtrIcon,{icon:p.edtrFormula})):null,o.code?l.createElement(_,{config:n,active:Y(t),onClick:function(){ee(t).focus(),e.onChange(t)},title:n.i18n.code.toggleTitle},l.createElement(p.Icon,{icon:p.faCode})):null)}var Pe,ze=function(e){function t(){return e.apply(this,arguments)||this}return L(t,e),t.prototype.render=function(){var e=this.props,t=e.children;return l.createElement("div",Object.assign({},e.attributes),t)},t}(l.Component),Fe=function(e){var t=(void 0===e?{}:e).EditorComponent,n=void 0===t?ze:t;return function(){return{renderBlock:function(e,t,r){var o=e.node;return"paragraph"===o.type||"@splish-me/p"===o.type?l.createElement(n,Object.assign({},e)):r()}}}},qe=function(e){return l.createElement(l.Fragment,null,d.times((function(t){var n=t+1,r=ie(n)(e.editor);return l.createElement(_,{key:t,config:e.config,active:r,onClick:function(){r?e.editor.setBlocks("paragraph"):le(n)(e.editor),e.editor.focus(),e.onChange(e.editor),e.switchControls(Pe.All)},title:e.config.i18n.headings.setHeadingTitle(n)},"H",n)}),3),l.createElement(_,{config:e.config,onClick:function(){return e.switchControls(Pe.All)},title:e.config.i18n.headings.closeMenuTitle},l.createElement(p.EdtrIcon,{icon:p.edtrClose})))},Ve=function(e){return l.createElement(l.Fragment,null,l.createElement(_,{config:e.config,active:ue("ordered-list")(e.editor),onClick:function(){se("ordered-list")(e.editor).focus(),e.onChange(e.editor)},title:e.config.i18n.list.toggleOrderedList},l.createElement(p.EdtrIcon,{icon:p.edtrListNumbered})),l.createElement(_,{config:e.config,active:ue("unordered-list")(e.editor),onClick:function(){se("unordered-list")(e.editor).focus(),ue("unordered-list")(e.editor)||e.switchControls(Pe.All),e.onChange(e.editor)},title:e.config.i18n.list.toggleUnorderedList},l.createElement(p.EdtrIcon,{icon:p.edtrListBullets})),l.createElement(_,{config:e.config,onClick:function(){return e.switchControls(Pe.All)},title:e.config.i18n.list.closeMenuTitle},l.createElement(p.EdtrIcon,{icon:p.edtrClose})))},Ke=["visibleControls","setVisibleControls","onChange"];function He(e){var t=e.visibleControls,n=e.setVisibleControls,r=e.onChange,o=B(e,Ke);switch(t){case Pe.All:return l.createElement(Re,Object.assign({},o,{switchControls:n,onChange:r}));case Pe.Headings:return l.createElement(qe,Object.assign({},o,{switchControls:n,onChange:r}));case Pe.Lists:return l.createElement(Ve,Object.assign({},o,{switchControls:n,onChange:r}));case Pe.Colors:return l.createElement(W,Object.assign({},o,{switchControls:n,onChange:r}))}}!function(e){e[e.All=0]="All",e[e.Headings=1]="Headings",e[e.Lists=2]="Lists",e[e.Colors=3]="Colors"}(Pe||(Pe={}));var _e=m.styled(m.EditorBottomToolbar)((function(e){return I({opacity:e.visible?1:0,transition:"500ms opacity ease-in-out"},e.isTouch?{bottom:"unset",top:0,transform:"translate(-50%, 50%)"}:{})}));function Je(e){var t=e.editor.value.selection.isCollapsed,n=l.useState(Pe.All),r=n[0],o=n[1],i=l.useState(!1),a=i[0],c=i[1];function u(){o(Pe.All),c(!0)}var s=JSON.stringify(e.editor.value.toJSON()),d=l.useRef({value:s,selectionCollapsed:t});l.useEffect((function(){var e=setTimeout(u,2500),n=d.current.value!==s;return(n||d.current.selectionCollapsed!==t)&&(d.current={value:s,selectionCollapsed:t},e&&clearTimeout(e),t&&(e=setTimeout(u,n?2500:1e3)),c(!1)),function(){clearTimeout(e)}}),[s,t]);var f=l.useCallback((function(e){return d.current=I({},d.current,{value:JSON.stringify(e.value.toJSON())}),e}),[]);return l.createElement(l.Fragment,null,!t&&l.createElement(m.HoverOverlay,{position:We()?"below":"above"},l.createElement(He,Object.assign({},e,{visibleControls:r,setVisibleControls:o,onChange:f}))),!e.readOnly&&l.createElement(_e,{isTouch:We(),visible:t&&a},a&&l.createElement(He,Object.assign({},e,{visibleControls:r,setVisibleControls:o,onChange:f}))))}function We(){return"ontouchstart"in window||navigator.maxTouchPoints>0}var Ue=function(e){return{onKeyDown:function(t,n,r){if(!e.current)return r();switch(t.key){case"]":case")":case" ":case"Enter":return function(e,t,n){var r=t.value,o=r.selection;if(o.isExpanded)return n();var i=r.focusText.text.slice(0,o.start.offset),l=/((http:\/\/|https:\/\/)?[_\-a-z0-9.]+\.(com|de|org)(:[0-9])?[/\w?%-_]*)$/g.exec(i);if(l&&0!==l.length){var a=i.length-l[0].length;if(i.length!==l[0].length&&" "!==i.slice(a-1,a))return n();var c=l[0];l[1].includes("http")||(c="https://"+c),t.moveFocusBackward(l[0].length).wrapInline({type:b,data:{href:c}}).moveToEnd().focus()}n()}(0,n,r);default:return r()}}}},$e=function(e){return{onKeyDown:function(t,n,r){var o=t;switch(o.key){case" ":return function(e,t,n,r){var o=t.value,i=o.selection;if(i.isExpanded)return n();var l=o.startBlock;if(!function(e,t,n){var r,o,i,l,a,c,u,s,d,f,g,p,m,v;if(/^\d+\.$/.test(e)){var h,y;if(ue("ordered-list")(t)||null==(h=n.current)||null==(y=h.config.enabledPlugins)||!y.lists)return;return se("ordered-list")(t)}switch(e){case"*":case"-":case"+":if(ue("unordered-list")(t)||null==(r=n.current)||null==(o=r.config.enabledPlugins)||!o.lists)return;return se("unordered-list")(t);case">":return G(0,n);case"#":return null!=(i=n.current)&&null!=(l=i.config.enabledPlugins)&&l.headings?le(1)(t):void 0;case"##":return null!=(a=n.current)&&null!=(c=a.config.enabledPlugins)&&c.headings?le(2)(t):void 0;case"###":return null!=(u=n.current)&&null!=(s=u.config.enabledPlugins)&&s.headings?le(3)(t):void 0;case"####":return null!=(d=n.current)&&null!=(f=d.config.enabledPlugins)&&f.headings?le(4)(t):void 0;case"#####":return null!=(g=n.current)&&null!=(p=g.config.enabledPlugins)&&p.headings?le(5)(t):void 0;case"######":return null!=(m=n.current)&&null!=(v=m.config.enabledPlugins)&&v.headings?le(6)(t):void 0;default:return}}(l.text.slice(0,i.start.offset).replace(/\s*/g,""),t,r))return n();e.preventDefault(),t.moveFocusToStartOfNode(l).delete()}(o,n,r,e);default:return r()}}}},Qe=p.styled.div((function(e){var t=e.config.theme;return{height:"32px",padding:"4px 8px",cursor:"pointer",backgroundColor:e.active?t.suggestions.background.highlight:t.suggestions.background.default,borderRadius:"4px","&:hover":{background:t.suggestions.background.highlight}}})),Xe=p.styled.div({padding:"10px"}),Ze=p.styled.span((function(e){var t=e.config.theme;return{color:e.highlight?t.suggestions.text.highlight:t.suggestions.text.default}}));function Ge(e){var t=l.useContext(me);return l.createElement(Xe,null,0===e.options.length?t.suggestions.noResultsMessage:e.options.map((function(t,n){var r,o=t[0].split(new RegExp("("+(r=e.currentValue,r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+")"),"i")).map((function(t){return{text:t,highlight:t.toLowerCase()===e.currentValue.toLowerCase()}}));return l.createElement(Qe,{key:n,active:n===e.selected,onMouseDown:function(){return e.onSelect(t[1])},config:e.config},o.map((function(t,n){return l.createElement(Ze,{key:n,highlight:t.highlight,config:e.config},t.text)})))})))}function Ye(e,t){if(e.current){var n=e.current.config.registry,r=t.value.document.text.replace("/",""),o=n.filter((function(e){return!r.length||(e.title||e.name).toLowerCase().startsWith(r.toLowerCase())})).map((function(e){return[e.title||e.name,e.name]})),i=n.filter((function(e){var t=e.title||e.name;return t.toLowerCase().includes(r.toLowerCase())&&!t.toLowerCase().startsWith(r.toLowerCase())})).map((function(e){return[e.title||e.name,e.name]}));return[].concat(o,i)}return[]}function et(e,t){return function(e){if(t.current){var n=t.current;n.store.dispatch(c.replace({id:n.id,plugin:e}))}}}function tt(e){return{renderEditor:function(t,n,r){var o=r();return l.createElement(nt,{editor:n,pluginClosure:e},o)},onKeyDown:function(t,n,r){if(!(["ArrowDown","ArrowUp","Enter"].includes(t.key)&&n.value.document.text.startsWith("/")&&Ye(e,n).length>0))return r();t.preventDefault()}}}function nt(e){var t=e.children,n=e.editor,r=e.pluginClosure,o=l.useState(0),i=o[0],c=o[1],u=n.value.document.text,s=Ye(r,n),d=!n.readOnly&&u.startsWith("/")&&s.length>0,f=d?s:[],g=l.useRef({showSuggestions:d,selected:i,options:f});if(g.current={showSuggestions:d,selected:i,options:f},l.useEffect((function(){f.length<i&&c(0)}),[f.length,i]),!r.current)return null;var p=r.current.config;return l.createElement(a.HotKeys,{keyMap:{DEC:"up",INC:"down",INSERT:"enter"},handlers:{DEC:function(){g.current.showSuggestions&&c((function(e){var t=g.current.options.length;return 0===t?0:(e+t-1)%t}))},INC:function(){g.current.showSuggestions&&c((function(e){var t=g.current.options.length;return 0===t?0:(e+1)%t}))},INSERT:function(){if(g.current.showSuggestions){var e=g.current.options[g.current.selected];if(!e)return;setTimeout((function(){et(0,r)(e[1])}))}}}},t,d?l.createElement(m.HoverOverlay,{position:"below"},l.createElement(Ge,{onSelect:et(0,r),options:f,currentValue:u.substr(1),selected:i,config:p})):null)}var rt={code:!0,colors:!0,headings:!0,links:!0,lists:!0,math:!0,paragraphs:!0,richText:!0,suggestions:!0};function ot(e){var t=function(e){var t,n=e.placeholder,r=void 0===n?"Write something or add elements with ⊕.":n,o=e.i18n,i=void 0===o?{}:o,a=e.theme,c=void 0===a?{}:a,s=e.blockquote,d=e.noLinebreaks,f=p.useTheme().editor,m=null!=(t=l.useContext(g.RegistryContext))?t:e.registry,v=e.plugins||rt,h=l.useMemo((function(){return[].concat(function(e){return[].concat(e.code?[(t={}.EditorComponent,n=void 0===t?te:t,function(){return{onKeyDown:function(e,t,n){var r=e;return u.isHotkey("mod+shift+´")(r)||u.isHotkey("mod+shift+`")(r)?(r.preventDefault(),ee(t)):n()},renderMark:function(e,t,r){var o=e.mark;return"mark"===o.object&&"code"===o.type?l.createElement(n,Object.assign({},e)):r()}}})]:[],e.colors?[H()]:[],e.headings?[ce()]:[],e.math?[pe()]:[],e.links?[Ne()]:[],e.lists?[function(){return y({blocks:{ordered_list:"ordered-list",unordered_list:"unordered-list",list_item:"list-item",list_item_child:"list-item-child",default:"paragraph"}})}]:[],e.paragraphs?[Fe()]:[],e.richText?[Me()]:[],e.suggestions?[tt]:[],[$e,Ue]);var t,n}(v),[(e={Component:Je,plugins:v},function(t){var n=e.Component,r=e.plugins;return{renderEditor:function(e,o,i){var a=e.readOnly;a&&o.blur();var c=t.current?t.current.config:void 0;if(!c)return null;var u=i();return l.createElement(l.Fragment,null,a?null:l.createElement(n,Object.assign({editor:o},e,{config:c,pluginClosure:t,plugins:r})),u)}}})]);var e}),[v]);return{registry:m,enabledPlugins:v,plugins:h,placeholder:r,i18n:p.merge({fallback:{blockquote:{toggleTitle:"Quote"},code:{toggleTitle:"Code"},colors:{setColorTitle:"Set color",resetColorTitle:"Reset color",openMenuTitle:"Colors",closeMenuTitle:"Close sub menu"},headings:{setHeadingTitle:function(e){return"Heading "+e},openMenuTitle:"Headings",closeMenuTitle:"Close sub menu"},link:{toggleTitle:"Link (Strg + K)",placeholder:"Enter URL",openInNewTabTitle:"Open in new tab"},list:{toggleOrderedList:"Ordered list",toggleUnorderedList:"Unordered list",openMenuTitle:"Lists",closeMenuTitle:"Close sub menu"},math:{toggleTitle:"Math formula (Strg + M)",displayBlockLabel:"Display as block",placeholder:"[formula]",editors:{visual:"visual",latex:"LaTeX",noVisualEditorAvailableMessage:"Only LaTeX editor available"},helpText:function(e){return l.createElement(l.Fragment,null,"Shortcuts:",l.createElement("br",null),l.createElement("br",null),l.createElement("p",null,"Fraction: ",l.createElement(e,null,"/")),l.createElement("p",null,"Superscript: ",l.createElement(e,null,"↑")," or ",l.createElement(e,null,"^")),l.createElement("p",null,"Subscript: ",l.createElement(e,null,"↓")," oder ",l.createElement(e,null,"_")),l.createElement("p",null,"π, α, β, γ: ",l.createElement(e,null,"pi"),", ",l.createElement(e,null,"alpha"),","," ",l.createElement(e,null,"beta"),",",l.createElement(e,null,"gamma")),l.createElement("p",null,"≤, ≥: ",l.createElement(e,null,"<="),", ",l.createElement(e,null,">=")),l.createElement("p",null,"Root: ",l.createElement(e,null,"\\sqrt"),", ",l.createElement(e,null,"\\nthroot")),l.createElement("p",null,"Math symbols: ",l.createElement(e,null,"\\<NAME>"),", e.g."," ",l.createElement(e,null,"\\neq")," (≠), ",l.createElement(e,null,"\\pm")," (±), ..."),l.createElement("p",null,"Functions: ",l.createElement(e,null,"sin"),", ",l.createElement(e,null,"cos"),","," ",l.createElement(e,null,"ln"),", ..."))}},richText:{toggleStrongTitle:"Bold (Strg + B)",toggleEmphasizeTitle:"Italic (Strg + I)"},suggestions:{noResultsMessage:"No items found"}},values:i}),theme:p.merge({fallback:{backgroundColor:"transparent",color:f.color,hoverColor:f.primary.background,active:{backgroundColor:"#b6b6b6",color:f.backgroundColor},dropDown:{backgroundColor:f.backgroundColor},suggestions:{background:{default:"transparent",highlight:f.primary.background},text:{default:f.color,highlight:f.danger.background}},plugins:{colors:{colors:["#1794c1","#469a40","#ff6703"],defaultColor:"black"}}},values:c}),blockquote:s,noLinebreaks:d}}(e.config),n=a.useScopedStore(),r=l.useRef(),i=l.useState((function(){return o.Value.fromJSON(e.state.value)})),c=i[0],s=i[1],d=l.useRef(e.state),m=l.useRef(e.state.value),v=e.focused,h=e.state;l.useEffect((function(){d.current=h,m.current!==h.value&&(s(o.Value.fromJSON(h.value)),m.current=h.value,setTimeout((function(){r.current&&v&&r.current.focus()})))}),[m,v,h]),l.useEffect((function(){r.current&&(e.focused?r.current.focus():r.current.blur())}),[e.focused]);var b=l.useRef({id:e.id,config:t,store:n});b.current={store:n,config:t,id:e.id},l.useEffect((function(){r.current&&(e.focused?setTimeout((function(){r.current&&r.current.focus()})):r.current.blur())}),[e.focused]);var k=l.useRef();void 0===k.current&&(k.current=[].concat(t.plugins.map((function(e){return e(b)})),[ct(b),ut(b)]));var E=l.useMemo((function(){return it(b)}),[b]),C=l.useMemo((function(){return lt(b,e.config.noLinebreaks)}),[b,e.config.noLinebreaks]),x=l.useCallback((function(e,t,n){if(e.target&&!t.findNode(e.target))return t;n()}),[]),w=l.useCallback((function(e){var t=e.value.toJSON();s(e.value),e.operations.filter((function(e){return void 0!==e&&"set_selection"!==e.type})).isEmpty()||(m.current=t,d.current&&d.current.set(t))}),[d]);return l.useMemo((function(){return l.createElement(me.Provider,{value:t.i18n},l.createElement(f.Editor,{ref:function(e){e&&!r.current&&(r.current=e)},onPaste:E,onKeyDown:C,onClick:x,onChange:w,placeholder:e.editable?t.placeholder:"",plugins:k.current,readOnly:!e.focused,value:c,schema:S}))}),[E,C,x,w,e.editable,t.i18n,t.placeholder,e.focused,c])}function it(e){return function(t,n,r){if(e.current){var o=e.current,i=o.id,l=o.store,a=c.getDocument(i)(l.getState());if(a){var u=a.plugin,s=c.getPlugins()(l.getState());if(c.mayInsertChild(i)(l.getState())){var d=t.clipboardData,g=function(e){for(var t=e.files,n=[],r=0;r<t.length;r++){var o=t[r];o&&n.push(o)}return n}(d),p=d.getData("text");if(g&&g.length>0)for(var m in s)if(Object.prototype.hasOwnProperty.call(s,m)){var v=s[m].onFiles;if("function"==typeof v){var h=v(g);if(void 0!==h)return void x(m,h)}}if(p)for(var y in s)if(Object.prototype.hasOwnProperty.call(s,y)){var b=s[y].onText;if("function"==typeof b){var k=b(p);if(void 0!==k)return void x(y,k)}}var E=f.getEventTransfer(t);if("html"===E.type){var C=N(E.html);return n.insertFragment(C.document),void t.preventDefault()}r()}else r()}else r()}else r();function x(e,t){if(c.mayRemoveChild(i)(l.getState())&&D(n.value))l.dispatch(c.replace({id:i,plugin:e,state:t.state}));else{var r=dt(n),o=c.getParent(i)(l.getState());if(!o)return;setTimeout((function(){r&&l.dispatch(c.insertChildAfter({parent:o.id,sibling:i,document:{plugin:u,state:ft.serialize(r)}})),l.dispatch(c.insertChildAfter({parent:o.id,sibling:i,document:{plugin:e,state:t.state}}))}))}}}}function lt(e,t){return function(n,r,i){var l=n.key,a=n;if(s("mod+z",a)||s("mod+y",a)||s("mod+shift+z",a))n.preventDefault();else if("Backspace"===l&&function(e){var t=e.value.selection,n=e.value.document.getFirstText();return t.isCollapsed&&n&&e.value.startText.key===n.key&&0===t.start.offset}(r)||"Delete"===l&&at(r)){if(n.preventDefault(),!e.current)return;var u="Backspace"===l;if(D(r.value)){var f=e.current,g=f.id,p=f.store,m=c.mayRemoveChild(g)(p.getState()),v=u?c.focusPrevious:c.focusNext;if(m){var h=c.getParent(g)(p.getState());if(!h)return;p.dispatch(v()),p.dispatch(c.removeChild({parent:h.id,child:g}))}}else{var y=e.current,b=y.id,k=y.store,E=c.mayRemoveChild(b)(k.getState()),C=c.mayInsertChild(b)(k.getState());if(!E||!C)return;var x=c.getParent(b)(k.getState());if(!x)return;var w=x.children||[],T=d.findIndex((function(e){return e.id===b}),w);if(-1===T)return;var S=c.getDocument(b)(k.getState());if(!S)return;if(u){if(T-1<0)return;var j=w[T-1],O=c.getDocument(j.id)(k.getState());if(!O)return;if(O.plugin===S.plugin)P(O.state,u),setTimeout((function(){k.dispatch(c.removeChild({parent:x.id,child:j.id}))}));else{var N=c.getFocusTree()(k.getState());if(!N)return;var I=c.findPreviousNode(N,b);if(!I)return;if(!(O=c.getDocument(I)(k.getState()))||O.plugin!==S.plugin)return;var L=P(O.state,u);k.dispatch(c.focusPrevious()),k.dispatch(c.change({id:I,state:{initial:function(){return L}}})),k.dispatch(c.removeChild({parent:x.id,child:b}))}}else{if(T+1>=w.length)return;var B=w[T+1],A=c.getDocument(B.id)(k.getState());if(!A)return;if(A.plugin===S.plugin)P(A.state,u),setTimeout((function(){k.dispatch(c.removeChild({parent:x.id,child:B.id}))}));else{var M=c.getFocusTree()(k.getState());if(!M)return;var R=c.findNextNode(M,b);if(!R)return;if(!(A=c.getDocument(R)(k.getState()))||A.plugin!==S.plugin)return;P(A.state,u),k.dispatch(c.removeChild({parent:x.id,child:B.id}))}}}}else{if(!t||"Enter"!==l)return i();n.preventDefault()}function P(e,t){var n=o.Value.fromJSON(e);return r.insertFragmentByKey(r.value.document.key,t?0:r.value.document.nodes.size,n.document),r.value.toJSON()}}}function at(e){var t=e.value.selection,n=e.value.document.getLastText();return t.isCollapsed&&n&&e.value.endText.key===n.key&&t.end.offset===e.value.endText.text.length}function ct(e){return{onKeyDown:function(t,n,r){if(s("enter",t)&&!n.value.selection.isExpanded){if(D(n.value)){if(!e.current)return;var o=e.current,i=o.id,l=o.store;if(!c.mayRemoveChild(i)(l.getState()))return;var a=st("insertChild",e);if(a){t.preventDefault();var u=c.getDocument(i)(l.getState());if(!u)return;var d=c.getParent(i)(l.getState());if(!d)return;return l.dispatch(c.insertChildAfter({parent:a.parent,sibling:a.sibling,document:{plugin:u.plugin}})),void l.dispatch(c.removeChild({parent:d.id,child:i}))}}if(""===n.value.startText.text&&1===n.value.startBlock.nodes.size){if(!e.current)return;var f=e.current,g=f.id,p=f.store,m=st("insertChild",e);if(m){t.preventDefault();var v=c.getDocument(g)(p.getState());if(!v)return;return n.delete(),void p.dispatch(c.insertChildAfter({parent:m.parent,sibling:m.sibling,document:{plugin:v.plugin}}))}}if(!e.current)return;var h=e.current,y=h.id,b=h.store;if(c.mayInsertChild(y)(b.getState())){t.preventDefault();var k=c.getDocument(y)(b.getState());if(!k)return;var E=c.getParent(y)(b.getState());if(!E)return;var C=dt(n);return void setTimeout((function(){b.dispatch(c.insertChildAfter(C?{parent:E.id,sibling:y,document:{plugin:k.plugin,state:ft.serialize(C)}}:{parent:E.id,sibling:y,document:{plugin:k.plugin}}))}))}}return r()}}}function ut(e){return{onKeyDown:function(t,n,r){var o=t.key;if("ArrowDown"===o||"ArrowUp"===o){var i=a();if(i){var l=i.getBoundingClientRect().top;setTimeout((function(){var t=a();if(t){var n=t.getBoundingClientRect().top;if(l===n){if(!e.current)return;e.current.store.dispatch(("ArrowDown"===o?c.focusNext:c.focusPrevious)())}}}))}}return r();function a(){var e=window.getSelection();return e&&e.rangeCount>0?e.getRangeAt(0):null}}}}function st(e,t){if(!t.current)return null;var n=t.current,r=n.store,o=c.getFocusPath(n.id)(r.getState());if(!o||o.length<=2)return null;var i=d.init(d.init(o)),l=d.findLastIndex((function(t){var n=c.getDocument(t)(r.getState());if(!n)return!1;var o=c.getPlugin(n.plugin)(r.getState());return!!o&&"function"==typeof o[e]}),i);return-1===l?null:{parent:o[l],sibling:o[l+1]}}function dt(e){if(!at(e)){e.value.focusBlock.type==w?(e.moveToEndOfBlock(),e.insertBlock("paragraph")):e.splitBlock(1);var t,n=e.value.document.nodes.skipUntil((function(t){return!!t&&e.value.blocks.first().key===t.key}));return n.forEach((function(t){t&&e.removeNodeByKey(t.key)})),t=n.toArray(),{document:{nodes:[].concat(t.map((function(e){return e.toJSON()})))}}}}var ft={deserialize:function(e){return{object:"value",document:{object:"document",nodes:(e||[]).map((function e(t){return function(e){return void 0!==e.children}(t)?function(t){switch(t.type){case"p":return{object:"block",type:"paragraph",nodes:t.children.map(e)};case"h":return{object:"block",type:"@splish-me/h"+t.level,nodes:t.children.map(e)};case"a":return{object:"inline",type:"@splish-me/a",data:{href:t.href},nodes:t.children.map(e)};case"math":return t.inline?{object:"inline",type:"@splish-me/katex-inline",data:{formula:t.src,inline:!0},isVoid:!0,nodes:t.children.map(e)}:{object:"block",type:"@splish-me/katex-block",data:{formula:t.src,inline:!1},isVoid:!0,nodes:t.children.map(e)};case"ordered-list":return{object:"block",type:"ordered-list",nodes:t.children.map(e)};case"unordered-list":return{object:"block",type:"unordered-list",nodes:t.children.map(e)};case"list-item":return{object:"block",type:"list-item",nodes:t.children.map(e)};case"list-item-child":return{object:"block",type:"list-item-child",nodes:t.children.map(e)}}}(t):(r=[],(n=t).em&&r.push({object:"mark",type:"@splish-me/em"}),n.strong&&r.push({object:"mark",type:"@splish-me/strong"}),n.code&&r.push({object:"mark",type:"code"}),void 0!==n.color&&r.push({object:"mark",type:"@splish-me/color",data:{colorIndex:n.color}}),{object:"text",text:n.text,marks:r});var n,r}))}}},serialize:function(e){var t=function e(t){return t?t.reduce((function(t,n){if(n.leaves)return[].concat(t,n.leaves.map((function(e){return I({},e,{object:"text"})})));var r=n.nodes?I({},n,{nodes:e(n.nodes)}):n;return[].concat(t,[r])}),[]):[]}(e&&e.document?e.document.nodes:[]);return t?t.map((function e(t){return"text"===t.object?(r={text:(n=t).text},(n.marks||[]).forEach((function(e){switch(e.type){case"@splish-me/strong":return void(r.strong=!0);case"@splish-me/em":return void(r.em=!0);case"@splish-me/color":return void(r.color=e.data.colorIndex);case"code":return void(r.code=!0)}})),r):function(t){switch(t.type){case"paragraph":return{type:"p",children:t.nodes.map(e)};case"@splish-me/h1":return{type:"h",level:1,children:t.nodes.map(e)};case"@splish-me/h2":return{type:"h",level:2,children:t.nodes.map(e)};case"@splish-me/h3":return{type:"h",level:3,children:t.nodes.map(e)};case"@splish-me/h4":return{type:"h",level:4,children:t.nodes.map(e)};case"@splish-me/h5":return{type:"h",level:5,children:t.nodes.map(e)};case"@splish-me/h6":return{type:"h",level:6,children:t.nodes.map(e)};case"@splish-me/a":return{type:"a",href:t.data.href,children:t.nodes.map(e)};case"@splish-me/katex-block":return{type:"math",src:t.data.formula,inline:!1,children:t.nodes.map(e)};case"@splish-me/katex-inline":return{type:"math",src:t.data.formula,inline:!0,children:t.nodes.map(e)};case"ordered-list":return{type:"ordered-list",children:t.nodes.map(e)};case"unordered-list":return{type:"unordered-list",children:t.nodes.map(e)};case"list-item":return{type:"list-item",children:t.nodes.map(e)};case"list-item-child":return{type:"list-item-child",children:t.nodes.map(e)}}}(t);var n,r})):[]}};exports.createTextPlugin=function(e){return{Component:ot,config:e,state:r.serializedScalar(j,ft),onKeyDown:function(){return!1},isEmpty:function(e){return D(o.Value.fromJSON(e.value))}}},exports.htmlToSlateValue=N,exports.isValueEmpty=D,exports.serializer=ft,exports.slateValueToHtml=function(e){return O.serialize(e,{render:!0})}; //# sourceMappingURL=plugin-text.cjs.production.min.js.map