@mrakomor/core 0.0.9 → 0.0.10
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/dist/blockChrome.cjs +3 -0
- package/dist/blockChrome.mjs +2 -2
- package/dist/blockInsertMenu.cjs +1 -0
- package/dist/blockInsertMenu.mjs +1 -1
- package/dist/chunk-5VPYPKGA.mjs +1 -0
- package/dist/chunk-G2QV4GOO.mjs +1 -0
- package/dist/{chunk-WX7ESURF.mjs → chunk-GDID5DFL.mjs} +1 -1
- package/dist/chunk-K2DMHAUD.mjs +1 -0
- package/dist/chunk-N4I2WZWF.mjs +1 -0
- package/dist/chunk-Q7RMVYZR.mjs +1 -0
- package/dist/chunk-T7OO472O.mjs +1 -0
- package/dist/chunk-TX4RCFPO.mjs +3 -0
- package/dist/chunk-U3MSKB3R.mjs +2 -0
- package/dist/chunk-UC7W4JIH.mjs +2 -0
- package/dist/chunk-WBTDWVEC.mjs +3 -0
- package/dist/{chunk-XQCH2FNS.mjs → chunk-YHWQV2DB.mjs} +1 -1
- package/dist/clipboard.cjs +5 -0
- package/dist/clipboard.mjs +3 -3
- package/dist/footer.cjs +2 -0
- package/dist/footer.mjs +2 -2
- package/dist/headline.cjs +4 -0
- package/dist/headline.mjs +1 -1
- package/dist/help.cjs +2 -0
- package/dist/help.mjs +2 -2
- package/dist/index.cjs +6 -0
- package/dist/index.mjs +4 -4
- package/dist/link.cjs +3 -0
- package/dist/link.mjs +2 -2
- package/dist/list.cjs +5 -0
- package/dist/list.mjs +1 -1
- package/dist/paragraph.cjs +4 -0
- package/dist/paragraph.mjs +1 -1
- package/dist/slashCommand.cjs +3 -0
- package/dist/slashCommand.mjs +1 -1
- package/dist/tooltip.cjs +2 -0
- package/dist/tooltip.mjs +2 -2
- package/dist/tts.cjs +9 -0
- package/dist/tts.mjs +3 -3
- package/package.json +68 -27
- package/dist/chunk-4NSVB4MI.mjs +0 -1
- package/dist/chunk-6XPPNCKR.mjs +0 -1
- package/dist/chunk-7UI6TZPX.mjs +0 -1
- package/dist/chunk-F67KYIDS.mjs +0 -2
- package/dist/chunk-JFLCNBDM.mjs +0 -3
- package/dist/chunk-P6HMUYFA.mjs +0 -1
- package/dist/chunk-PMR6XOZ6.mjs +0 -2
- package/dist/chunk-QWAQBTXR.mjs +0 -1
- package/dist/chunk-XVWRPXC2.mjs +0 -2
- package/dist/chunk-ZDZQ2RVJ.mjs +0 -1
package/dist/help.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';(function(){if(!(typeof document>"u")){var e="mrakomor/core/plugin/help/help.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===e});if(!t){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",e),n.textContent=`.mrakomor-help-plugin-container{display:contents}.mrakomor-help{width:420px;max-width:calc(100vw - 32px);max-height:70vh;overflow:auto;border:1px solid #e2e8f0;border-radius:12px;background:#fff;box-shadow:0 18px 40px #0f172a29,0 2px 8px #0f172a14;color:#0f172a;font-size:13px;line-height:1.45}.mrakomor-help__header{padding:16px 18px 12px;border-bottom:1px solid #eef2f6;background:linear-gradient(180deg,#fafbfc,#fff)}.mrakomor-help__title{margin:0;font-size:16px;font-weight:650;letter-spacing:-.01em}.mrakomor-help__subtitle{margin:4px 0 0;font-size:12px;color:#64748b}.mrakomor-help__body{padding:8px 10px 12px}.mrakomor-help__section+.mrakomor-help__section{margin-top:10px}.mrakomor-help__group{margin:0 0 6px;padding:0 8px;font-size:11px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:#64748b}.mrakomor-help__list{margin:0;padding:0;list-style:none}.mrakomor-help__item{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:12px;align-items:start;padding:10px 8px;border-radius:8px}.mrakomor-help__item+.mrakomor-help__item{border-top:1px solid #f1f5f9}.mrakomor-help__description{color:#334155}.mrakomor-help__keys{display:flex;flex-wrap:wrap;gap:4px;justify-content:flex-end}.mrakomor-help__kbd{display:inline-flex;align-items:center;min-height:22px;padding:2px 7px;border:1px solid #dbe2ea;border-bottom-width:2px;border-radius:6px;background:#f8fafc;color:#0f172a;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;white-space:nowrap}
|
|
2
|
+
`,document.head.appendChild(n);}}})();var me=class{next(...e){}error(...e){}complete(...e){}},te=class{#e=new Set;pipe(...e){return e.reduce((t,n)=>n(t),this)}next(...e){Array.from(this.#e).forEach(t=>{typeof t=="function"?t(...e):t.next(...e);});}error(...e){Array.from(this.#e).forEach(t=>{t?.error?.(...e),this.unsubscribe(t);});}complete(...e){Array.from(this.#e).forEach(t=>{t?.complete?.(...e),this.unsubscribe(t);});}subscribe(e){return this.#e.add(e),{unsubscribe:()=>{this.unsubscribe(e);}}}unsubscribe(e){this.#e.delete(e);}};var U=Symbol("@esmj/signals:type"),q=Symbol("@esmj/signals:name");var h=null,ne=false,he=[];function C(e){let t=h;h=null;let n=e();return h=t,n}function Xe(){ne=false;let e=ye();for(let n of e)n.get();let t=he;he=[];for(let n of t)n();}function Ye(){ne||(ne=true,queueMicrotask(Xe));}var ge=Symbol("@esmj/signals:internal observable"),x=Symbol("@esmj/signals:original function"),Je=class extends te{#e=new Set;#o=null;constructor(e){super(),this.#o=e,this.pipe(t=>{let n=t.subscribe.bind(t),o=t.unsubscribe.bind(t);return t.subscribe=r=>{n(r),this.#e.add(r);},t.unsubscribe=r=>{o(r),this.#e.delete(r);},t});}watch(e){if(typeof e.next!="function"&&(e.next=()=>C(()=>{this.#e.add(e),this.#o();}),e.next[x]=void 0),e instanceof we&&e.next[x]===void 0){let t=e.next.bind(e);e.next=()=>C(()=>{this.#e.add(e),t(),this.#o();}),e.next[x]=t;}return this.subscribe(e)}getPending(){let e=[];for(let t of this.#e){if(!t.get[x]){let n=t.get,o=n.bind(t);t.get=()=>C(()=>(this.#e.delete(t),o())),t.get[x]=n;}e.push(t);}return e}unwatch(e){return e.next=e.next[x]?e.next[x]:e.next,e.get=e.get[x]?e.get[x]:e.get,this.#e.delete(e),this.unsubscribe(e)}},B=null;function be(e){B=new Je(e);}be(()=>{Ye();});function ye(){return B.getPending()}function xe(e){return B.watch(e)}function ke(e){return B.unwatch(e)}var k=Symbol("@esmj/signals:no error"),we=class _e extends me{#e=true;#o=false;#n=null;#r=this.#p();#u=null;#l=null;#i=0;#s=new Map;#t=k;constructor(t,n){super(),this.#u=t,this.#l=n,this.debug=n?.debug,this[U]="computed",this[q]=n?.debug??null,this.get=this.get.bind(this);}#c(){for(let{unsubscribe:t}of this.#r.dependencies.values())t();this.#r.dependencies.clear();}#p(){return {dependencies:new Map,sourceRevisions:new Map,observer:this}}getRevision(){return this.#i}getDebugInfo(){return {name:this[q],dirty:this.#e,revision:this.#i,sourceDependencies:[...this.#s.keys()]}}#f(){for(let[t,n]of this.#s)if(t instanceof _e&&C(()=>t.get()),t.getRevision()!==n)return true;return false}next(){this.#e=true,this.#n[ge].next();}get(){if(this.#o)throw new Error("Cycle detected in computed signal");if(this.#n||(this.#n=E(this.#a(),this.#l)),(this.#e||this.#t!==k)&&(this.#s.size===0||this.#f()?this.#a():this.#e=false),h&&h.sourceRevisions.set(this,this.#i),this.#t!==k)throw this.#t;return this.#n.get()}peek(){if(this.#n||(this.#n=E(this.#a(),this.#l)),(this.#e||this.#t!==k)&&(this.#s.size===0||this.#f()?this.#a():this.#e=false),this.#t!==k)throw this.#t;return this.#n.peek()}#a(){this.#o=true,this.#e=false,this.#t=k,this.#c(),this.#r.sourceRevisions.clear();let t=h;h=this.#r;let n;try{n=this.#u();}catch(o){this.#t=o;}return h=t,this.#s=this.#r.sourceRevisions,this.#r.sourceRevisions=new Map,this.#o=false,n instanceof Promise&&(n=n.then(o=>{this.#t=k,this.#n.set(o);}).catch(o=>{this.#t=o;})),this.#t===k&&this.#n&&this.#n.set(n),this.#i++,n}destroy(){this.#c(),this.#s.clear(),this.#e=true,this.#t=k;}};function A(e,t){return new we(e,t)}function b(e,t){let n,{debug:o,...r}={},s=A(()=>{n?.(),n=e();},{equals:()=>false,...r});s.get(),xe(s);let i=()=>{n?.(),s.destroy(),ke(s);};return i[Symbol.dispose]=i,i[U]="effect",i[q]=o??null,i.__RX_COMPUTED__=s,i}function E(e,t={}){let n=t?.equals??Object.is,o=0,r=new te;function s(){return h&&(h.dependencies.set(r,r.subscribe(h.observer)),h.sourceRevisions.set(p,o)),e}function i(){return e}function a(u){if(!n(e,u)){e=u,o++,r.next();}return e}function c(){return o}let p={get:s,set:a,peek:i,getRevision:c,[ge]:r,[U]:"signal",[q]:t?.debug??null};return p}function V(){return Date.now().toString(32).substring(5)+Math.random().toString(32).substring(2)}var Re=Symbol("node-component"),K=Symbol("node-internal"),Ze=Symbol("keep-literal"),Y=Symbol("raw-props");var Ie=null;function T(){return Ie}function W(e){Ie=e;}function Te(e){return e?.[Re]||null}function Se(e,t){e[Re]=t;}function G(e,t={disposers:[],id:V()}){return e?.[K]?e[K]:(e&&(e[K]=t),t)}function nt(e){return e[K]}function _(e,t){let n=nt(e);n||(n=G(e)),n.disposers.push(t);}function re(e,t,n){e.has(t)||e.set(t,[]),e.get(t).push(n);}function S(e,t){let n=T();W(e);try{return t()}finally{W(n);}}var se=new Map,X=new Map,ve=new Map;function $e(e,t){let n=typeof t=="function"?t:r=>!!t?.includes(r),o=Object.create(null);for(let r of Object.keys(e)){let s=e[r];r==="children"||n(r)?o[r]=s:s?.[Ze]?o[r]=s():s!=null&&typeof s.get=="function"?o[r]=s:typeof s=="function"?o[r]=A(s):o[r]=E(s);}return o}function D(e){let t=e.componentId,n=se.get(t);if(n){se.delete(t);for(let o of n){let r=o();typeof r=="function"&&re(X,t,r);}}}function ot(e){let t=X.get(e);if(t){X.delete(e);for(let n of t)n();}}function rt(e){let t=ve.get(e);if(t){ve.delete(e);for(let n of t)n();}}function Q(e){if(!e)return;let t=G(e);if(t?.disposers?.length){for(let o of t.disposers)try{o();}catch(r){console.error("[esmj-dom] cleanupTree: disposer threw, cleanup continues",r);}t.disposers=[];}let n=Te(e);if(n&&(ot(n.componentId),rt(n.componentId)),e.childNodes){let o=e.firstChild;for(;o;){let r=o.nextSibling;Q(o),o=r;}}}function M(e){return e!=null&&typeof e=="object"&&typeof e.$constructor=="function"}function Ne(e){return typeof e=="function"&&typeof e.prototype?.render=="function"}function st(e,t,n){let o=V(),r={componentId:o,$children:n,element:null,classInstance:null,$constructor(){let s=Ne(e)?void 0:e[Y],i={...$e(t??{},s),children:n},a=T(),c={disposers:[],id:o,contexts:new Map(a?.contexts)};W(c);let p;if(Ne(e)){r.ClassConstructor=e;let f=new e(i);r.classInstance=f,typeof f.onMount=="function"&&re(se,o,()=>{f.onMount?.();}),typeof f.onUnmount=="function"&&re(X,o,()=>{f.onUnmount?.();}),p=f.render();}else p=e(i);W(a);let u=it(p);if(r.element=u,u instanceof DocumentFragment&&u.childNodes.length)for(let f of u.childNodes)G(f,c),Se(f,r);else G(u,c),u instanceof Node&&Se(u,r);return u}};return r}function ce(e,t){let n=t.$constructor();n instanceof Node&&e.appendChild(n),queueMicrotask(()=>{D(t);});}function it(e){return e instanceof Node?e:M(e)?e.$constructor():typeof e=="string"||typeof e=="number"?document.createTextNode(String(e)):document.createTextNode("")}var Ce={className:"class",htmlFor:"for"},Ee=new Set(["value","defaultValue","checked","selected","indeterminate"]),at=new Set(["srcdoc"]),lt=new Set(["href","src","action","formaction","xlink:href"]),ut=new Set(["securitypolicyviolation"]),ct=new Set(["contenteditable","draggable","spellcheck"]);function P(e){return e!=null&&typeof e=="object"&&typeof e.get=="function"&&!(e instanceof Node)}var Fe=Symbol("Fragment");function d(e,t,n){if(e===Fe){let r=document.createDocumentFragment();return ie(r,Me(n)),r}if(typeof e=="function")return st(e,t||{},n);typeof e!="string"&&(n=t,t=e,e="div"),t=t||{};let o=document.createElement(e);return t.id&&o.setAttribute("id",t.id),Z(o,t),ie(o,Me(n)),o}function oe(e,t){t instanceof DocumentFragment?e.replaceChildren(t):e.innerHTML=t??"";}function ft(e){return typeof e!="string"?false:e.replace(/[\p{White_Space}\p{Cc}]+/gu,"").toLowerCase().startsWith("javascript:")}function pt(e,t){if(typeof e!="string")return false;let n=e.toLowerCase();return at.has(n)?true:lt.has(n)&&t!==null&&t!==void 0&&ft(String(t))}function Le(e){return typeof e!="string"?e:Ce[e]?Ce[e]:e}function dt(e,t){let n=Le(e),o=typeof n=="string"?n.toLowerCase():String(n).toLowerCase();return ct.has(o)&&(t===true||t===false||t==="true"||t==="false")?String(t):t==null||t===false?null:t}function Ae(e,t,n){let o=dt(t,n);if(o===null){e.removeAttribute(t);return}if(pt(t,o)){e.removeAttribute(t),console.warn(`[esmj-dom] Blocked unsafe attribute "${String(t)}" on <${e.tagName.toLowerCase()}>`);return}e.setAttribute(t,o);}function Z(e,t){let n=T();for(let[o,r]of Reflect.ownKeys(t).map(s=>[s,t[s]]))if(o!=="id"){if(o=Le(o),o==="$ref"){typeof r=="function"?r(e):typeof r=="object"&&r!==null&&(r.current=e);continue}if(o==="$dangerouslySetInnerHTML"){if(P(r)){let s=b(()=>{S(n,()=>{oe(e,r.get());});});_(e,s);}else if(typeof r=="function"){let s=b(()=>{S(n,()=>{oe(e,r());});});_(e,s);}else oe(e,r);continue}if(o==="style"){if(P(r)){let s=b(()=>{S(n,()=>{Object.assign(e.style,r.get());});});_(e,s);}else typeof r=="object"&&r!==null?Object.assign(e.style,r):e.setAttribute("style",r);continue}if(typeof o=="string"&&o.startsWith("on")&&typeof r=="function"){let s=o.slice(2).toLowerCase();if(ut.has(s)){console.warn(`[esmj-dom] Blocked unsafe event binding "${o}" on <${e.tagName.toLowerCase()}>`);continue}e.addEventListener(s,r);continue}if(P(r)||typeof r=="function"){let s=o,i=b(()=>{S(n,()=>{let a=typeof r=="function"?r():r.get();Ee.has(s)?e[s]=a??"":Ae(e,s,a);});});_(e,i);continue}Ee.has(o)||typeof o=="symbol"?e[o]=r??"":Ae(e,o,r);}}function Me(e){return e==null?[]:Array.isArray(e)?e.flat(Number.POSITIVE_INFINITY):[e]}function ie(e,t){for(let n of t)Oe(e,n);}function Oe(e,t){if(!(t==null||t===false||t===true)){if(t instanceof Node){e.appendChild(t);return}if(typeof t=="string"||typeof t=="number"){e.appendChild(document.createTextNode(String(t)));return}if(typeof t=="function"){je(e,t);return}if(M(t)){ce(e,t);return}if(P(t)){je(e,()=>t.get());return}if(Array.isArray(t)){ie(e,t);return}e.appendChild(document.createTextNode(String(t)));}}function $(e){let t=null,n=e;return M(e)&&(t=e,n=e.$constructor()),n instanceof DocumentFragment?{nodes:Array.from(n.childNodes),instance:t}:n instanceof Node?{nodes:[n],instance:t}:n==null||n===false||n===true?{nodes:[],instance:t}:{nodes:[document.createTextNode(String(n))],instance:t}}function ee(e,t=true){for(let n of e)t&&Q(n),n.remove();}function je(e,t){let n=T(),o=document.createComment("");e.appendChild(o);let r=[],s=b(()=>{S(n,()=>{let i=t(),{nodes:a,instance:c}=$(i);ee(r),a.length&&o.after(...a),c&&queueMicrotask(()=>D(c)),r=a;});});_(e,s);}function Pe(e,t){if(typeof e=="string"&&(e=document.querySelector(e)),!e)throw new Error("mount: container not found");e instanceof DocumentFragment||(Q(e),e.innerHTML=""),M(t)?ce(e,t):t instanceof Node?e.appendChild(t):e.appendChild(document.createTextNode(String(t)));}function gt(e,t,n,o){let r=e.getRoot()?.querySelector(t);if(!r)return {container:null,dispose:null};let s=document.createElement("div");s.className=n,r.append(s);let i=Pe(s,o);return {container:s,dispose:i??null}}function De(e,t,n){return gt(e,".mrakomor-footer-end",t,n)}var F={id:"help",label:"Help",keywords:["help","shortcuts"],group:"help",order:1e4,description:"Show keyboard shortcuts and slash commands",handler:e=>{e.mrakomor.command.openHelp?.();}},bt=[{id:"block.split",group:"blocks",description:"Split the current block or insert a new line",commands:[],shortcuts:["Enter"]},{id:"block.merge",group:"blocks",description:"Merge with the previous block or outdent a list item",commands:[],shortcuts:["Backspace"]},{id:"overlay.dismiss",group:"navigation",description:"Close the open dialog, menu, or slash palette",commands:[],shortcuts:["Escape"]}];function yt(e){return e?e.charAt(0).toUpperCase()+e.slice(1):"General"}function ze(e){let t=new Map;for(let n of e){let o=n.group||"general",r=t.get(o)??[];r.push(n),t.set(o,r);}return t}function Ue(e){let t=ze(e),n=[];for(let[o,r]of t)n.push(d("section",{className:"mrakomor-help__section","data-group":o},[d("h3",{className:"mrakomor-help__group"},yt(o)),d("ul",{className:"mrakomor-help__list"},r.map(s=>d("li",{className:"mrakomor-help__item","data-help-id":s.id},[d("div",{className:"mrakomor-help__description"},s.description),d("div",{className:"mrakomor-help__keys"},[...(s.commands??[]).map(i=>d("kbd",{className:"mrakomor-help__kbd"},i)),...(s.shortcuts??[]).map(i=>d("kbd",{className:"mrakomor-help__kbd"},i))])])))]));return d("div",{className:"mrakomor-help",role:"document","aria-label":"Editor help"},[d("header",{className:"mrakomor-help__header"},[d("h2",{className:"mrakomor-help__title"},"Help"),d("p",{className:"mrakomor-help__subtitle"},"Keyboard shortcuts and slash commands")]),d("div",{className:"mrakomor-help__body"},n)])}function xt({mrakomor:e}){let t=null;function n(o={}){e.command.openDialog?.({element:o.element??null,children:Ue(e.register.help.list())},{placement:"center"});}return {registerCommands(o){o.command.openHelp=n;let r=e.register.slashActions;r&&!r.has(F.id)&&r.add(F);for(let s of bt)e.register.help.add(s);e.register.help.add({id:F.id,group:F.group,description:F.description,commands:["/help"],shortcuts:[]});},onMount(){let{dispose:o}=De(e,"mrakomor-help-plugin-container",d("button",{type:"button",className:"mrakomor-footer-action mrakomor-help-trigger","aria-label":"Open help",title:"Keyboard shortcuts and commands",onClick:r=>{n({element:r.currentTarget});}},[d("span",{className:"mrakomor-footer-action__icon","aria-hidden":"true"},"?"),"Help"]));t=o;},onUnmount(){t?.(),t=null;}}}exports.HELP_SLASH_ACTION=F;exports.buildHelpDialogContent=Ue;exports.groupHelpEntries=ze;exports.helpPlugin=xt;
|
package/dist/help.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {b}from'./chunk-
|
|
2
|
-
`,document.head.appendChild(r);}}})();var p={id:"help",label:"Help",keywords:["help","shortcuts"],group:"help",order:1e4,description:"Show keyboard shortcuts and slash commands",handler:e=>{e.mrakomor.command.openHelp?.();}},c=[{id:"block.split",group:"blocks",description:"Split the current block or insert a new line",commands:[],shortcuts:["Enter"]},{id:"block.merge",group:"blocks",description:"Merge with the previous block or outdent a list item",commands:[],shortcuts:["Backspace"]},{id:"overlay.dismiss",group:"navigation",description:"Close the open dialog, menu, or slash palette",commands:[],shortcuts:["Escape"]}];function h(e){return e?e.charAt(0).toUpperCase()+e.slice(1):"General"}function m(e){let a=new Map;for(let r of e){let t=r.group||"general",n=a.get(t)??[];n.push(r),a.set(t,n);}return a}function d(e){let a=m(e),r=[];for(let[t,n
|
|
1
|
+
import {b}from'./chunk-5VPYPKGA.mjs';import {o}from'./chunk-K2DMHAUD.mjs';(function(){if(!(typeof document>"u")){var e="mrakomor/core/plugin/help/help.css",a=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(t){return t.getAttribute("data-mrakomor-css-path")===e});if(!a){var r=document.createElement("style");r.setAttribute("data-mrakomor-css",""),r.setAttribute("data-mrakomor-css-path",e),r.textContent=`.mrakomor-help-plugin-container{display:contents}.mrakomor-help{width:420px;max-width:calc(100vw - 32px);max-height:70vh;overflow:auto;border:1px solid #e2e8f0;border-radius:12px;background:#fff;box-shadow:0 18px 40px #0f172a29,0 2px 8px #0f172a14;color:#0f172a;font-size:13px;line-height:1.45}.mrakomor-help__header{padding:16px 18px 12px;border-bottom:1px solid #eef2f6;background:linear-gradient(180deg,#fafbfc,#fff)}.mrakomor-help__title{margin:0;font-size:16px;font-weight:650;letter-spacing:-.01em}.mrakomor-help__subtitle{margin:4px 0 0;font-size:12px;color:#64748b}.mrakomor-help__body{padding:8px 10px 12px}.mrakomor-help__section+.mrakomor-help__section{margin-top:10px}.mrakomor-help__group{margin:0 0 6px;padding:0 8px;font-size:11px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:#64748b}.mrakomor-help__list{margin:0;padding:0;list-style:none}.mrakomor-help__item{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:12px;align-items:start;padding:10px 8px;border-radius:8px}.mrakomor-help__item+.mrakomor-help__item{border-top:1px solid #f1f5f9}.mrakomor-help__description{color:#334155}.mrakomor-help__keys{display:flex;flex-wrap:wrap;gap:4px;justify-content:flex-end}.mrakomor-help__kbd{display:inline-flex;align-items:center;min-height:22px;padding:2px 7px;border:1px solid #dbe2ea;border-bottom-width:2px;border-radius:6px;background:#f8fafc;color:#0f172a;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;white-space:nowrap}
|
|
2
|
+
`,document.head.appendChild(r);}}})();var p={id:"help",label:"Help",keywords:["help","shortcuts"],group:"help",order:1e4,description:"Show keyboard shortcuts and slash commands",handler:e=>{e.mrakomor.command.openHelp?.();}},c=[{id:"block.split",group:"blocks",description:"Split the current block or insert a new line",commands:[],shortcuts:["Enter"]},{id:"block.merge",group:"blocks",description:"Merge with the previous block or outdent a list item",commands:[],shortcuts:["Backspace"]},{id:"overlay.dismiss",group:"navigation",description:"Close the open dialog, menu, or slash palette",commands:[],shortcuts:["Escape"]}];function h(e){return e?e.charAt(0).toUpperCase()+e.slice(1):"General"}function m(e){let a=new Map;for(let r of e){let t=r.group||"general",n=a.get(t)??[];n.push(r),a.set(t,n);}return a}function d(e){let a=m(e),r=[];for(let[t,n]of a)r.push(o("section",{className:"mrakomor-help__section","data-group":t},[o("h3",{className:"mrakomor-help__group"},h(t)),o("ul",{className:"mrakomor-help__list"},n.map(s=>o("li",{className:"mrakomor-help__item","data-help-id":s.id},[o("div",{className:"mrakomor-help__description"},s.description),o("div",{className:"mrakomor-help__keys"},[...(s.commands??[]).map(l=>o("kbd",{className:"mrakomor-help__kbd"},l)),...(s.shortcuts??[]).map(l=>o("kbd",{className:"mrakomor-help__kbd"},l))])])))]));return o("div",{className:"mrakomor-help",role:"document","aria-label":"Editor help"},[o("header",{className:"mrakomor-help__header"},[o("h2",{className:"mrakomor-help__title"},"Help"),o("p",{className:"mrakomor-help__subtitle"},"Keyboard shortcuts and slash commands")]),o("div",{className:"mrakomor-help__body"},r)])}function u({mrakomor:e}){let a=null;function r(t={}){e.command.openDialog?.({element:t.element??null,children:d(e.register.help.list())},{placement:"center"});}return {registerCommands(t){t.command.openHelp=r;let n=e.register.slashActions;n&&!n.has(p.id)&&n.add(p);for(let s of c)e.register.help.add(s);e.register.help.add({id:p.id,group:p.group,description:p.description,commands:["/help"],shortcuts:[]});},onMount(){let{dispose:t}=b(e,"mrakomor-help-plugin-container",o("button",{type:"button",className:"mrakomor-footer-action mrakomor-help-trigger","aria-label":"Open help",title:"Keyboard shortcuts and commands",onClick:n=>{r({element:n.currentTarget});}},[o("span",{className:"mrakomor-footer-action__icon","aria-hidden":"true"},"?"),"Help"]));a=t;},onUnmount(){a?.(),a=null;}}}export{p as HELP_SLASH_ACTION,d as buildHelpDialogContent,m as groupHelpEntries,u as helpPlugin};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use strict';(function(){if(!(typeof document>"u")){var t="mrakomor/core/style/core.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.namespace-unknown-unknowncomponent{background-color:#f0f0f0;padding:12px 0;margin-bottom:8px}.mrakomor-editor:focus-visible{outline:none}.mrakomor-editor{display:flex;flex-direction:column;min-height:0}.mrakomor-editor-surface{position:relative;flex:1 1 auto;min-height:0}.mrakomor-tools-container{position:absolute;inset:0;pointer-events:none;z-index:4}.mrakomor-content{position:relative;min-height:0}.mrakomor-content:focus-visible{outline:none}
|
|
2
|
+
`,document.head.appendChild(n);}}})();var Ft=class{next(...t){}error(...t){}complete(...t){}},ct=class{#e=new Set;pipe(...t){return t.reduce((e,n)=>n(e),this)}next(...t){Array.from(this.#e).forEach(e=>{typeof e=="function"?e(...t):e.next(...t);});}error(...t){Array.from(this.#e).forEach(e=>{e?.error?.(...t),this.unsubscribe(e);});}complete(...t){Array.from(this.#e).forEach(e=>{e?.complete?.(...t),this.unsubscribe(e);});}subscribe(t){return this.#e.add(t),{unsubscribe:()=>{this.unsubscribe(t);}}}unsubscribe(t){this.#e.delete(t);}};var ve=Symbol("@esmj/signals:type"),ye=Symbol("@esmj/signals:name");var w=null,lt=false,ut=[];function H(t){let e=w;w=null;let n=t();return w=e,n}function co(){lt=false;let t=zt();for(let n of t)n.get();let e=ut;ut=[];for(let n of e)n();}function Ht(){lt||(lt=true,queueMicrotask(co));}function ft(t){ut.push(t),Ht();}var qt=Symbol("@esmj/signals:internal observable"),K=Symbol("@esmj/signals:original function"),lo=class extends ct{#e=new Set;#o=null;constructor(t){super(),this.#o=t,this.pipe(e=>{let n=e.subscribe.bind(e),o=e.unsubscribe.bind(e);return e.subscribe=r=>{n(r),this.#e.add(r);},e.unsubscribe=r=>{o(r),this.#e.delete(r);},e});}watch(t){if(typeof t.next!="function"&&(t.next=()=>H(()=>{this.#e.add(t),this.#o();}),t.next[K]=void 0),t instanceof Wt&&t.next[K]===void 0){let e=t.next.bind(t);t.next=()=>H(()=>{this.#e.add(t),e(),this.#o();}),t.next[K]=e;}return this.subscribe(t)}getPending(){let t=[];for(let e of this.#e){if(!e.get[K]){let n=e.get,o=n.bind(e);e.get=()=>H(()=>(this.#e.delete(e),o())),e.get[K]=n;}t.push(e);}return t}unwatch(t){return t.next=t.next[K]?t.next[K]:t.next,t.get=t.get[K]?t.get[K]:t.get,this.#e.delete(t),this.unsubscribe(t)}},Ie=null;function Gt(t){Ie=new lo(t);}Gt(()=>{Ht();});function zt(){return Ie.getPending()}function Vt(t){return Ie.watch(t)}function Yt(t){return Ie.unwatch(t)}var F=Symbol("@esmj/signals:no error"),Wt=class Xt extends Ft{#e=true;#o=false;#t=null;#n=this.#u();#r=null;#i=null;#c=0;#a=new Map;#s=F;constructor(e,n){super(),this.#r=e,this.#i=n,this.debug=n?.debug,this[ve]="computed",this[ye]=n?.debug??null,this.get=this.get.bind(this);}#l(){for(let{unsubscribe:e}of this.#n.dependencies.values())e();this.#n.dependencies.clear();}#u(){return {dependencies:new Map,sourceRevisions:new Map,observer:this}}getRevision(){return this.#c}getDebugInfo(){return {name:this[ye],dirty:this.#e,revision:this.#c,sourceDependencies:[...this.#a.keys()]}}#m(){for(let[e,n]of this.#a)if(e instanceof Xt&&H(()=>e.get()),e.getRevision()!==n)return true;return false}next(){this.#e=true,this.#t[qt].next();}get(){if(this.#o)throw new Error("Cycle detected in computed signal");if(this.#t||(this.#t=C(this.#f(),this.#i)),(this.#e||this.#s!==F)&&(this.#a.size===0||this.#m()?this.#f():this.#e=false),w&&w.sourceRevisions.set(this,this.#c),this.#s!==F)throw this.#s;return this.#t.get()}peek(){if(this.#t||(this.#t=C(this.#f(),this.#i)),(this.#e||this.#s!==F)&&(this.#a.size===0||this.#m()?this.#f():this.#e=false),this.#s!==F)throw this.#s;return this.#t.peek()}#f(){this.#o=true,this.#e=false,this.#s=F,this.#l(),this.#n.sourceRevisions.clear();let e=w;w=this.#n;let n;try{n=this.#r();}catch(o){this.#s=o;}return w=e,this.#a=this.#n.sourceRevisions,this.#n.sourceRevisions=new Map,this.#o=false,n instanceof Promise&&(n=n.then(o=>{this.#s=F,this.#t.set(o);}).catch(o=>{this.#s=o;})),this.#s===F&&this.#t&&this.#t.set(n),this.#c++,n}destroy(){this.#l(),this.#a.clear(),this.#e=true,this.#s=F;}};function B(t,e){return new Wt(t,e)}function D(t,e){let n,{debug:o,...r}={},s=B(()=>{n?.(),n=t();},{equals:()=>false,...r});s.get(),Vt(s);let i=()=>{n?.(),s.destroy(),Yt(s);};return i[Symbol.dispose]=i,i[ve]="effect",i[ye]=o??null,i.__RX_COMPUTED__=s,i}function C(t,e={}){let n=e?.equals??Object.is,o=0,r=new ct;function s(){return w&&(w.dependencies.set(r,r.subscribe(w.observer)),w.sourceRevisions.set(l,o)),t}function i(){return t}function a(u){if(!n(t,u)){t=u,o++,r.next();}return t}function c(){return o}let l={get:s,set:a,peek:i,getRevision:c,[qt]:r,[ve]:"signal",[ye]:e?.debug??null};return l}function Be(){return Date.now().toString(32).substring(5)+Math.random().toString(32).substring(2)}var sn=Symbol("node-component"),Me=Symbol("node-internal"),uo=Symbol("keep-literal"),Oe=Symbol("raw-props");function dt(t){return typeof t=="function"?t:t!=null&&typeof t.get=="function"?()=>t.get():()=>t}function gt(t,e){let n=t.children!==void 0?t.children:e;return Array.isArray(n)?n[0]:n}var fo=new Set(["template","script"]);function mo(t,e){let n=(t==null?"span":String(t)).trim(),o=n;fo.has(n.toLowerCase())&&(console.warn(`[esmj-dom] tagName "${t}" cannot render children in normal flow and is not supported as a reconciliation wrapper; falling back to "span".`),o="span");let r=document.createElement(o);return o==="span"&&(r.style.display="contents"),r.setAttribute(e,Be()),r}function ht(t,e,n){let o=mo(t,e);return n?.id&&o.setAttribute("id",n.id),o}function oe(t){let e=null,n=()=>e,o=s=>(e=s??null,e),r={get:n,set:o,[Symbol.toPrimitive](){return e?String(e):""}};return Object.defineProperty(r,"current",{get(){return e},set(s){o(s);},enumerable:true,configurable:false}),new Proxy(r,{get(s,i,a){if(Reflect.has(s,i))return Reflect.get(s,i,a);if(!e)return;let c=e[i];return typeof c=="function"?c.bind(e):c},set(s,i,a,c){return Reflect.has(s,i)||!e?Reflect.set(s,i,a,c):(e[i]=a,true)},has(s,i){return Reflect.has(s,i)||!!e&&i in e}})}var an=null;function $(){return an}function we(t){an=t;}function re(t){return t?.[sn]||null}function Jt(t,e){t[sn]=e;}function Le(t,e={disposers:[],id:Be()}){return t?.[Me]?t[Me]:(t&&(t[Me]=e),e)}function po(t){return t[Me]}function q(t,e){let n=po(t);n||(n=Le(t)),n.disposers.push(e);}function Se(t,e,n){t.has(e)||t.set(e,[]),t.get(e).push(n);}function G(t,e){let n=$();we(t);try{return e()}finally{we(n);}}var Te=new Map,Ce=new Map,Qt=new Map;function cn(t,e){let n=typeof e=="function"?e:r=>!!e?.includes(r),o=Object.create(null);for(let r of Object.keys(t)){let s=t[r];r==="children"||n(r)?o[r]=s:s?.[uo]?o[r]=s():s!=null&&typeof s.get=="function"?o[r]=s:typeof s=="function"?o[r]=B(s):o[r]=C(s);}return o}function se(t,e){if(t===e)return true;if(t==null||e==null||typeof t!="object"||typeof e!="object")return false;let n=Object.keys(t),o=Object.keys(e);return n.length!==o.length?false:n.every(r=>{let s=Object.getOwnPropertyDescriptor(t,r),i=Object.getOwnPropertyDescriptor(e,r);if(!s||!i)return false;let a="value"in s?s.value:s.get?.call(t),c="value"in i?i.value:i.get?.call(e);return se(a,c)})}function Et(t){return {id:Symbol("context-id"),defaultValue:t}}function yt(t,e){let n=$();n&&n.contexts.set(t.id,e);}function bt(t){let e=$();return e?.contexts?.has(t.id)?e.contexts.get(t.id):t.defaultValue}function De(t){let e=$();if(!e){console.warn("onMount called outside of a component context");return}Se(Te,e.id,t);}function Pe(t){let e=$();if(!e){console.warn("onUnmount called outside of a component context");return}Se(Ce,e.id,t);}function R(t){ft(()=>{setTimeout(t,0);});}function ie(t){let e=t.componentId,n=Te.get(e);if(n){Te.delete(e);for(let o of n){let r=o();typeof r=="function"&&Se(Ce,e,r);}}}function go(t){let e=Ce.get(t);if(e){Ce.delete(t);for(let n of e)n();}}function ho(t){let e=Qt.get(t);if(e){Qt.delete(t);for(let n of e)n();}}function ke(t){if(!t)return;let e=Le(t);if(e?.disposers?.length){for(let o of e.disposers)try{o();}catch(r){console.error("[esmj-dom] cleanupTree: disposer threw, cleanup continues",r);}e.disposers=[];}let n=re(t);if(n&&(go(n.componentId),ho(n.componentId)),t.childNodes){let o=t.firstChild;for(;o;){let r=o.nextSibling;ke(o),o=r;}}}function z(t){return t!=null&&typeof t=="object"&&typeof t.$constructor=="function"}function Zt(t){return typeof t=="function"&&typeof t.prototype?.render=="function"}function Eo(t,e,n){let o=Be(),r={componentId:o,$children:n,element:null,classInstance:null,$constructor(){let s=Zt(t)?void 0:t[Oe],i={...cn(e??{},s),children:n},a=$(),c={disposers:[],id:o,contexts:new Map(a?.contexts)};we(c);let l;if(Zt(t)){r.ClassConstructor=t;let f=new t(i);r.classInstance=f,typeof f.onMount=="function"&&Se(Te,o,()=>{f.onMount?.();}),typeof f.onUnmount=="function"&&Se(Ce,o,()=>{f.onUnmount?.();}),l=f.render();}else l=t(i);we(a);let u=yo(l);if(r.element=u,u instanceof DocumentFragment&&u.childNodes.length)for(let f of u.childNodes)Le(f,c),Jt(f,r);else Le(u,c),u instanceof Node&&Jt(u,r);return u}};return r}function xt(t,e){let n=e.$constructor();n instanceof Node&&t.appendChild(n),queueMicrotask(()=>{ie(e);});}function yo(t){return t instanceof Node?t:z(t)?t.$constructor():typeof t=="string"||typeof t=="number"?document.createTextNode(String(t)):document.createTextNode("")}var en={className:"class",htmlFor:"for"},tn=new Set(["value","defaultValue","checked","selected","indeterminate"]),bo=new Set(["srcdoc"]),xo=new Set(["href","src","action","formaction","xlink:href"]),So=new Set(["securitypolicyviolation"]),Co=new Set(["contenteditable","draggable","spellcheck"]);function xe(t){return t!=null&&typeof t=="object"&&typeof t.get=="function"&&!(t instanceof Node)}var ln=Symbol("Fragment");function E(t,e,n){if(t===ln){let r=document.createDocumentFragment();return pt(r,on(n)),r}if(typeof t=="function")return Eo(t,e||{},n);typeof t!="string"&&(n=e,e=t,t="div"),e=e||{};let o=document.createElement(t);return e.id&&o.setAttribute("id",e.id),$e(o,e),pt(o,on(n)),o}function mt(t,e){e instanceof DocumentFragment?t.replaceChildren(e):t.innerHTML=e??"";}function ko(t){return typeof t!="string"?false:t.replace(/[\p{White_Space}\p{Cc}]+/gu,"").toLowerCase().startsWith("javascript:")}function _o(t,e){if(typeof t!="string")return false;let n=t.toLowerCase();return bo.has(n)?true:xo.has(n)&&e!==null&&e!==void 0&&ko(String(e))}function un(t){return typeof t!="string"?t:en[t]?en[t]:t}function No(t,e){let n=un(t),o=typeof n=="string"?n.toLowerCase():String(n).toLowerCase();return Co.has(o)&&(e===true||e===false||e==="true"||e==="false")?String(e):e==null||e===false?null:e}function nn(t,e,n){let o=No(e,n);if(o===null){t.removeAttribute(e);return}if(_o(e,o)){t.removeAttribute(e),console.warn(`[esmj-dom] Blocked unsafe attribute "${String(e)}" on <${t.tagName.toLowerCase()}>`);return}t.setAttribute(e,o);}function $e(t,e){let n=$();for(let[o,r]of Reflect.ownKeys(e).map(s=>[s,e[s]]))if(o!=="id"){if(o=un(o),o==="$ref"){typeof r=="function"?r(t):typeof r=="object"&&r!==null&&(r.current=t);continue}if(o==="$dangerouslySetInnerHTML"){if(xe(r)){let s=D(()=>{G(n,()=>{mt(t,r.get());});});q(t,s);}else if(typeof r=="function"){let s=D(()=>{G(n,()=>{mt(t,r());});});q(t,s);}else mt(t,r);continue}if(o==="style"){if(xe(r)){let s=D(()=>{G(n,()=>{Object.assign(t.style,r.get());});});q(t,s);}else typeof r=="object"&&r!==null?Object.assign(t.style,r):t.setAttribute("style",r);continue}if(typeof o=="string"&&o.startsWith("on")&&typeof r=="function"){let s=o.slice(2).toLowerCase();if(So.has(s)){console.warn(`[esmj-dom] Blocked unsafe event binding "${o}" on <${t.tagName.toLowerCase()}>`);continue}t.addEventListener(s,r);continue}if(xe(r)||typeof r=="function"){let s=o,i=D(()=>{G(n,()=>{let a=typeof r=="function"?r():r.get();tn.has(s)?t[s]=a??"":nn(t,s,a);});});q(t,i);continue}tn.has(o)||typeof o=="symbol"?t[o]=r??"":nn(t,o,r);}}function on(t){return t==null?[]:Array.isArray(t)?t.flat(Number.POSITIVE_INFINITY):[t]}function pt(t,e){for(let n of e)fn(t,n);}function fn(t,e){if(!(e==null||e===false||e===true)){if(e instanceof Node){t.appendChild(e);return}if(typeof e=="string"||typeof e=="number"){t.appendChild(document.createTextNode(String(e)));return}if(typeof e=="function"){rn(t,e);return}if(z(e)){xt(t,e);return}if(xe(e)){rn(t,()=>e.get());return}if(Array.isArray(e)){pt(t,e);return}t.appendChild(document.createTextNode(String(e)));}}function ae(t){let e=null,n=t;return z(t)&&(e=t,n=t.$constructor()),n instanceof DocumentFragment?{nodes:Array.from(n.childNodes),instance:e}:n instanceof Node?{nodes:[n],instance:e}:n==null||n===false||n===true?{nodes:[],instance:e}:{nodes:[document.createTextNode(String(n))],instance:e}}function je(t,e=true){for(let n of t)e&&ke(n),n.remove();}function rn(t,e){let n=$(),o=document.createComment("");t.appendChild(o);let r=[],s=D(()=>{G(n,()=>{let i=e(),{nodes:a,instance:c}=ae(i);je(r),a.length&&o.after(...a),c&&queueMicrotask(()=>ie(c)),r=a;});});q(t,s);}var Ue=class{constructor(t){this.props=t;}};function mn(t,e,n,o){let{equals:r=se,tagName:s="span",...i}=o??{},a=ht(s,"data-for",i);$e(a,i);let c=$(),l=[],u=new Map,f=B(()=>t()),d=D(()=>{let h=f.get(),x=Array.isArray(h)?h:[],_=[],N=[],g=new Set;for(let b=0;b<x.length;b++){let A=x[b],v=e(A,b);if(g.has(v)){console.error(`For: duplicate key "${String(v)}" detected; ignoring later item at index ${b}`);continue}g.add(v),_.push(A),N.push(v);}let y=new Map(l.map(b=>[b.key,b])),k=[];for(let b=0;b<_.length;b++){let A=N[b],v=_[b],U=y.get(A);if(U)u.get(A).set(v),k.push(U),y.delete(A);else {let Ee=C(v,{equals:r});u.set(A,Ee);let at={...Ee,set(){}},X={key:A,nodes:[]};G(c,()=>{let ro=n(at,b),{nodes:so,instance:Kt}=ae(ro);X.nodes=so,Kt&&queueMicrotask(()=>ie(Kt));}),k.push(X);}}for(let[b,A]of y)je(A.nodes),u.delete(b);let S=null;for(let b=k.length-1;b>=0;b--){let A=k[b].nodes;for(let v=A.length-1;v>=0;v--){let U=A[v];(U.parentNode!==a||U.nextSibling!==S)&&a.insertBefore(U,S),S=U;}}l=k;});return q(a,d),a}function St(t,e,n,o){if(typeof t=="function")return mn(t,e,n,o);let{each:r,keyFn:s,equals:i,tagName:a,children:c,...l}=t??{};if(typeof s!="function")throw new Error('For: "keyFn" prop is required and must be a function');let u=dt(r),f=gt(t??{},e);return mn(u,s,f,{...l,equals:i,tagName:a})}St[Oe]=t=>t!=="each";function J(t,e){if(typeof t=="string"&&(t=document.querySelector(t)),!t)throw new Error("mount: container not found");t instanceof DocumentFragment||(ke(t),t.innerHTML=""),z(e)?xt(t,e):e instanceof Node?t.appendChild(e):t.appendChild(document.createTextNode(String(e)));}function dn(t){if(typeof t=="string"&&(t=document.querySelector(t)),!t)throw new Error("unmount: container not found");ke(t),t.innerHTML="";}function _e(t,e){let n=null;if(z(e)?(n=e.$constructor(),queueMicrotask(()=>ie(e))):e instanceof Node?n=e:n=document.createTextNode(String(e)),n instanceof HTMLElement){let o=B(()=>!!t()),r=D(()=>{n.style.display=o.get()?"":"none";});q(n,r);}return n}var L=class extends Ue{static get nodeName(){return "span"}static get style(){return "SPAN"}static match(e){return e.nodeName===this.nodeName.toUpperCase()||e.style===this.style}getState(){return {style:this.constructor.style}}render(){return E(this.constructor.nodeName,{},this.props.children)}};var ce=class extends L{static get nodeName(){return "b"}static get style(){return "BOLD"}static get LABEL(){return E("b",{},"B")}static match(e){return e.nodeName==="strong"?true:super.match(e)}};var le=class extends L{static get nodeName(){return "i"}static get style(){return "ITALIC"}static get LABEL(){return E("i",{},"I")}};var ue=class extends L{static get nodeName(){return "sub"}static get style(){return "SUBSCRIPT"}static get LABEL(){return E("sub",{},"Sub")}};var fe=class extends L{static get nodeName(){return "sup"}static get style(){return "SUPERSCRIPT"}static get LABEL(){return E("sup",{},"Sup")}};var me=class extends L{static get nodeName(){return "u"}static get style(){return "UNDERLINE"}static get LABEL(){return E("u",{},"U")}};var j=Symbol("result-key"),Ke=Symbol("stopped-event");function gn(t,e){let n=!!e.name,o=e[j]||"result",r=o.includes("."),s={error:null,context:{},[j]:o,...e,[o]:n?void 0:Q(e,o),name:t,[Ke]:false,defaultPrevented:false};return r&&(Ro(s,o),s[o]=n?void 0:Q(e,o)),s.stopPropagation=()=>{s[Ke]=true;},s.preventDefault=()=>{s.defaultPrevented=true;},s}function Q(t,e){return e===""?t:e.split(".").reduce((o,r)=>o?.[r]??void 0,t)}function Ct(t,e,n){let o=e.split("."),r=o.pop(),s=Q(t,o.join("."));return s[r]=n}function Ro(t,e){let n=e.split(".");n.pop(),n.reduce((o,r)=>o[r]=o[r]??{},t);}var Fe=class{constructor({logger:e,debug:n}={}){this._logger=e??console,this._debug=n??false,this._events=new Map,this.addListener=this.on,this.removeListener=this.off;}emit(e,n={}){let o=this.listeners(e),r=gn(e,n),s=null,i=null;this._debug&&(typeof this._debug=="function"?this._debug(e,r):this._logger.debug(`Event name: ${e}, event: ${r}`));for(let a of o){if(s&&(s=s.then(c=>(Ct(r,r[j],c??Q(r,r[j])),r[Ke]?Q(r,r[j]):a(r)))),!s){if(r[Ke])return r;i=a(r);}i instanceof Promise&&!s?s=i:Ct(r,r[j],i??Q(r,r[j]));}return s?s.then(a=>(Ct(r,r[j],a??Q(r,r[j])),r)):r}emitParallel(e,n={}){let o=this.listeners(e),r=gn(e,n);return Promise.all(o.map(async s=>await s(r))).then(s=>(r[r[j]]=s,r)).catch(s=>{throw r.error=s,s})}listeners(e){return this._events.has(e)?[...this._events.get(e)]:[]}removeAllListeners(e){return e?this.listeners(e).forEach(n=>this.off(e,n)):Array.from(this._events.keys()).forEach(n=>this.removeAllListeners(n))}_addListener(e,n,o){return this._events.has(e)||this._events.set(e,[]),this._events.get(e)[o](n),()=>{this.off(e,n);}}on(e,n){if(typeof n!="function")throw new TypeError("The listener must be a function");return this._addListener(e,n,"push")}prependListener(e,n){return this._addListener(e,n,"unshift")}_addListenerOnce(e,n,o){let r=this[o](e,s=>(r(),n(s)));}once(e,n){return this._addListenerOnce(e,n,"on")}prependOnceListener(e,n){return this._addListenerOnce(e,n,"prependListener")}off(e,n){if(this._events.has(e)){let o=this._events.get(e),r=o.indexOf(n);o.splice(r,1);}}};var m={INSERT_BLOCK_ELEMENT:"mrakomor:insert-block-component",REPLACE_BLOCK_ELEMENT:"mrakomor:replace-block-component",REMOVE_BLOCK_ELEMENT:"mrakomor:remove-block-component",MERGE_BLOCK_ELEMENT:"mrakomor:merge-block-component",INSERT_ENTITY_RANGE:"mrakomor:insert-entity-range",REMOVE_ENTITY_RANGE:"mrakomor:remove-entity-range",INSERT_INLINE_STYLE_RANGE:"mrakomor:insert-inline-style-range",KEYDOWN:"mrakomor:keydown",BEFORE_INPUT:"mrakomor:beforeinput",INPUT:"mrakomor:input",CLICK:"mrakomor:click",FOCUSIN:"mrakomor:focusin",FOCUSOUT:"mrakomor:focusout",SELECTION_CHANGE:"mrakomor:selection-change",CONTENT_CHANGE:"mrakomor:content-change",TRANSFORM_BLOCK_ELEMENT:"mrakomor:transform-block-element",MOVE_BLOCK_ELEMENT:"mrakomor:move-block-element"};function T(t){return e=>{if(!e.defaultPrevented)return t(e)}}function hn({mrakomor:t}={}){let e=t?.emitter??new Fe;function n(o,r={}){return typeof t?.emit=="function"?t.emit(o,r):e.emit(o,{...r,mrakomor:t})}return {emitter:e,command:{insertBlockElement(o,r){n(m.INSERT_BLOCK_ELEMENT,{...o,options:r});},replaceBlockElement(o,r){n(m.REPLACE_BLOCK_ELEMENT,{...o,options:r});},removeBlockElement(o,r){n(m.REMOVE_BLOCK_ELEMENT,{...o,options:r});},mergeBlockElement(o,r){n(m.MERGE_BLOCK_ELEMENT,{...o,options:r});},insertEntityRange(o,r){n(m.INSERT_ENTITY_RANGE,{...o,options:r});},removeEntityRange(o,r){n(m.REMOVE_ENTITY_RANGE,{...o,options:r});},insertInlineStyleRange(o,r){n(m.INSERT_INLINE_STYLE_RANGE,{...o,options:r});},transformBlockElement(o,r){n(m.TRANSFORM_BLOCK_ELEMENT,{...o,options:r});},moveBlockElement(o,r){n(m.MOVE_BLOCK_ELEMENT,{...o,options:r});}}}}var En=class{#e=new Set;pipe(...t){return vo(...t)(this)}next(...t){Array.from(this.#e).forEach(e=>{typeof e=="function"?e(...t):e.next(...t);});}error(...t){Array.from(this.#e).forEach(e=>{e?.error?.(...t),this.unsubscribe(e);});}complete(...t){Array.from(this.#e).forEach(e=>{e?.complete?.(...t),this.unsubscribe(e);});}subscribe(t){return this.#e.add(t),{unsubscribe:()=>{this.unsubscribe(t);}}}unsubscribe(t){this.#e.delete(t);}};function vo(...t){return e=>Array.from(t).reduce((n,o)=>o(n),e)}function yn(t){return t.map((e,n)=>({entry:e,index:n})).sort((e,n)=>{let o=e.entry.order??e.index,r=n.entry.order??n.index;return o!==r?o-r:e.index-n.index}).map(({entry:e})=>e)}var pe=class extends En{mrakomor;#e=new Map;#o=null;#t=0;#n;constructor(e,n={}){super(),this.mrakomor=e,this.#n=n.sort??yn;}normalize(e,n){throw new Error("Register subclass must implement normalize")}#r(){this.#o=null,this.next(this.list());}#i(e,n=this.#t++){let o=this.normalize(e,n);return o?(this.#e.set(o.id,o),o):null}add(e){if(Array.isArray(e)){let o=[];for(let r of e){let s=this.#i(r,this.#t++);s&&o.push(s);}return o.length&&this.#r(),o}let n=this.#i(e);return n&&this.#r(),n}get(e){return this.#e.get(e)}has(e){return this.#e.has(e)}remove(e){let n=this.#e.delete(e);return n&&this.#r(),n}list(){return this.#o??=this.#n([...this.#e.values()]),this.#o}};var Io={abortEarly:true};function Rt(t,e){if(e===void 0)return t;let n=t?.cause?.key?`${e}.${t.cause.key}`:`${e}`;return {message:`Error parsing key "${n}": ${t.message}`,cause:{key:n}}}function Bo(t,e,n){if(t.errors?.length)for(let o=0;o<t.errors.length;o++)e.push(Rt(t.errors[o],n));}function Sn(t,e,n,o){if(n!==false){let r=Rt(t.error,e);return {success:false,error:r,errors:[r]}}Bo(t,o,e);}function He(t){return t?.abortEarly!==void 0?t:Io}function kt(t,e){I(t,"_parse",(n,o,r)=>{let s=n(o,r);return !s.success&&e(o)?{success:true,data:o}:s});}var Ne=t=>typeof t=="string"||t instanceof String,_t=t=>(typeof t=="number"||t instanceof Number)&&!Number.isNaN(t),Nt=t=>t===true||t===false,Mo=t=>t instanceof Date&&!Number.isNaN(t.getTime()),wo=t=>typeof t=="function",Lo=t=>Array.isArray(t),At=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);function Cn(t,e){let n=O(At,{...e,type:"object"});n._getDescription=()=>`object({ ${Object.entries(t).map(([r,s])=>`${r}: ${s._getDescription()}`).join(", ")} })`,n._getDefinition=()=>t;let o=n;return o.derive=function(r,{when:s="always"}={}){return I(this,"_parse",(i,a,c)=>{let l=i(a,c);if(!l.success)return l;let u=r(l.data,{context:c?.context});if(!At(u)){let f={message:`derive() callback must return a plain object of overrides, got ${u===null?"null":typeof u}`};return {success:false,error:f,errors:[f]}}if(s==="missing"){let f={...l.data};for(let d in u)f[d]===void 0&&(f[d]=u[d]);return {success:true,data:f}}return {success:true,data:{...l.data,...u}}}),this},I(n,"_parse",(r,s,i)=>{let a=r(s,i),{abortEarly:c}=He(i);if(a.success===false)return a;let l={},u=[];for(let f in t){let d=t[f]._parse(a.data[f],i);if(d.success)l[f]=d.data;else {let h=Sn(d,f,c,u);if(h)return h}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:l}}),o}function vt(t){return O(Ne,{...t,type:"string"})}function It(t){return O(_t,{...t,type:"number"})}function Bt(t){return O(Nt,{...t,type:"boolean"})}function Mt(t){return O(Mo,{...t,type:"date"})}function kn(t){return O(wo,{...t,type:"function"})}function _n(t,e){let n=i=>t.includes(i),o=i=>`Invalid ${r} value. Expected ${t.map(a=>`"${a}"`).join(" | ")}, received "${i}".`,r="enum",s=O(n,{message:o,...e,type:r});return s._getDescription=()=>`enum(${t.map(i=>`"${i}"`).join(" | ")})`,s._getDefinition=()=>t,s}function Nn(t,e){let n=O(Lo,{...e,type:"array"});return n._getDescription=()=>`array(${t._getDescription()})`,n._getDefinition=()=>t,I(n,"_parse",(o,r,s)=>{let i=o(r,s),{abortEarly:a}=He(s);if(i.success===false)return i;let c=[],l=[],u=s;for(let f=0;f<i.data.length;f++){let d={...u,context:{...u?.context,index:f}},h=t._parse(i.data[f],d);if(h.success)c.push(h.data);else {let x=Sn(h,f,a,l);if(x)return x}}return l.length>0?{success:false,error:l[0],errors:l}:{success:true,data:c}}),n}function An(){return O(()=>true)}function de(t,e){return I(e,"_parse",(n,o,r)=>(o=t(o),n(o,r))),e}function Rn(t,e){let n=r=>`Invalid union value. Expected the value to match one of the schemas:${t.map((s,i)=>` ${i+1}. ${s._getDescription()}`).join(",")} but received "${typeof r}" with value: ${At(r)?JSON.stringify(r):`"${r}"`}`,o=O(()=>false,{message:n,...e,type:"union"});return o._getDefinition=()=>t,I(o,"_parse",(r,s,i)=>{let a=i,c=[];for(let d=0;d<t.length;d++){let h=t[d]._parse(s,a);if(h.success)return h;c.push(h);}let{abortEarly:l}=He(a),u={message:typeof n=="function"?n(s):n};if(l!==false)return {success:false,error:u,errors:[u]};let f=[];for(let d=0;d<c.length;d++){let h=c[d].errors;if(h?.length)for(let x=0;x<h.length;x++)h[x].cause?.key&&f.push(Rt(h[x],`branch ${d}`));}return f.length===0&&f.push(u),{success:false,error:f[0],errors:f}}),o}function vn(t,e){let n=O(o=>o===t,{message:o=>e?.message?typeof e.message=="function"?e.message(o):e.message:`Expected literal value "${t}", received "${o}"`,name:e?.name,type:"literal"});return n._getDescription=()=>`literal("${t}")`,n._getDefinition=()=>t,n}function In(t){let e=O(()=>true,{type:"contextRef"});return e._getDescription=()=>`contextRef("${t}")`,I(e,"_parse",(n,o,r)=>({success:true,data:r?.context?.[t]})),e}function Bn(t,e){return {parse(n,o){let r=t.parse(o?.context??{},o);return e(r).parse(n,o)},safeParse(n,o){let r=t.safeParse(o?.context??{},o);return r.success?e(r.data).safeParse(n,o):r}}}var Mn={boolean(t){let e=t?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return de(n=>{let o;return Ne(n)&&(o=n.toLowerCase()),o==="true"||o==="yes"||o==="on"||o==="1"||n===1?true:o==="false"||o==="no"||o==="off"||o==="0"||n===0?false:n},Bt({...t,message:e}))},number(t){let e=t?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return de(n=>{if(Nt(n))return Number(n);if(Ne(n)){let o=n.trim();if(o==="")return n;let r=Number(o);if(Number.isFinite(r))return r}return n},It({...t,message:e}))},string(t){let e=t?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return de(n=>Nt(n)||_t(n)&&Number.isFinite(n)?String(n):n,vt({...t,message:e}))},date(t){let e=t?.message??(n=>`Cannot cast "${n}" to a valid date.`);return de(n=>{let o;return Ne(n)&&(o=n.trim()),_t(n)&&Number.isFinite(n)||o?new Date(o??n):n},Mt({...t,message:e}))},json(t,e){let n=e?.message??(o=>`Cannot parse "${o}" as JSON.`);return I(t,"_parse",(o,r,s)=>{if(Ne(r))try{r=JSON.parse(r);}catch{let i={message:typeof n=="function"?n(r):n};return {success:false,error:i,errors:[i]}}return o(r,s)}),t}},wn={},p={object:Cn,string:vt,number:It,boolean:Bt,date:Mt,function:kn,enum:_n,array:Nn,any:An,preprocess:de,union:Rn,literal:vn,contextRef:In,withContext:Bn,coerce:wn,cast:Mn};function bn(t){return e=>`The value "${e}" must be type of ${t} but is type of "${typeof e}".`}function I(t,e,n){let o=t[e];t[e]=(...r)=>n(o,...r);}function O(t,{type:e="any",name:n,message:o}={}){o=o||bn(e);let r={name:n,message:o,type:e},s={_getName(){return n},_getType(){return e},_getDescription(){return this._getName()??this._getType()},_parse(i,a){let c=t(i);if(c===true)return {success:true,data:i};if(typeof c=="object"&&c?.success===true)return c;let l={message:typeof o=="function"?o(i):o};return {success:false,error:l,errors:[l]}},parse(i,a){let c=this._parse(i,a);if(!c.success)throw c=c,new Error(c.error.message,{cause:c.error.cause});return c.data},safeParse(i,a){return this._parse(i,a)},transform(i){return I(this,"_parse",(a,c,l)=>{let u=a(c,l);return u.success&&(u.data=i(u.data)),u}),this},optional(){return kt(this,i=>i===void 0),this},nullable(){return kt(this,i=>i===null),this},nullish(){return kt(this,i=>i==null),this},default(i){return I(this,"_parse",(a,c,l)=>(c===void 0&&(c=typeof i=="function"?i({context:l?.context}):i),a(c,l))),this},catch(i){return I(this,"_parse",(a,c,l)=>{let u=a(c,l);return u.success?u:{success:true,data:typeof i=="function"?i({input:c,error:u.error}):i}}),this},pipe(i){return I(this,"_parse",(a,c,l)=>{let u=a(c,l);return u.success?i._parse(u.data,l):u}),this},refine(i,{message:a,type:c,jsonSchema:l}={}){if(c&&(a=a||bn(c),e=c),l){let u=[...this._getJsonSchemaHints?.()??[],l];this._getJsonSchemaHints=()=>u;}return I(this,"_parse",(u,f,d)=>{let h=u(f,d),{abortEarly:x}=He(d);if(!h.success)return h;let _=i(h.data);if(_===true||typeof _=="object"&&_?.success===true)return h;let N={message:typeof a=="function"?a(f):a};return {success:false,error:N,errors:[N]}}),this},clone(){return {...this}}};return xn.length>0?xn.reduce((i,a)=>a(i,t,r)??i,s):s}var xn=[];var To=p.object({component:p.function(),id:p.string(),label:p.string(),keywords:p.array(p.string()),group:p.string(),order:p.number().default(({context:t})=>t?.index??0),settings:p.any().optional()});function Oo(t,e){let n=`block:${t}`;return e?.style==="UNORDERED"?`${n}:ul`:e?.style==="ORDERED"?`${n}:ol`:n}function Ln(t,e=0){let n=typeof t=="function",o=n?t:t?.component,r=n?{}:t,s=o.NAMESPACE??"",i=s.split(".").pop()||s,a=r.label||o.LABEL||i||s,c=Array.isArray(o.KEYWORDS)?o.KEYWORDS:[],l=r.keywords?.length?r.keywords.map(String):c.length?c.map(String):[a,i].filter(Boolean).map(String),u=r.settings;return To.parse({component:o,id:r.id||Oo(s,u),label:String(a),keywords:l,group:String(r.group||o.GROUP||"blocks"),...typeof r.order=="number"?{order:r.order}:{},...u?{settings:u}:{}},{context:{index:e}})}var qe=class t extends pe{#e=null;constructor(e){super(e),this.subscribe(()=>{this.#e=null;});}normalize(e,n){if(e==null)return null;try{return Ln(e,n)}catch{return null}}getByNamespace(e){return this.#o().get(e)}#o(){return this.#e??=t.buildNamespaceMap(this.list()),this.#e}static buildNamespaceMap(e){let n=new Map;for(let o of e){let r=o.component?.NAMESPACE;r&&!n.has(r)&&n.set(r,o.component);}return n}};var wt="molecule.paragraph.Paragraph";var Tn="molecule.external.ExternalComponent",On="namespace.unknown.UnknownComponent";var Dn="molecule.headline.";var Lt=Dt(),Tt=Dt(),Pn=Dt(),Do=Array.from({length:256},(t,e)=>(e<=15?"0":"")+e.toString(16));function Dt(){return Math.floor(Math.random()*16777215)}function Po(){return Tt=(Tt+1)%16777215,Tt}function V(){let t=Math.floor(Date.now()/1e3);t=parseInt(t,10)%4294967295;let e=Po(),n=String.fromCharCode(t>>24&255,t>>16&255,t>>8&255,t&255,Lt>>16&255,Lt>>8&255,Lt&255,Pn>>8&255,Pn&255,e>>16&255,e>>8&255,e&255),o="";for(let r=0;r<n.length;r++)o+=Do[n.charCodeAt(r)];return o}var Ae=Symbol("block-element"),$o=Symbol("block-element-body"),Ge=Symbol("selectable-element");function ze(t,e){let n=t;for(n?.nodeType===Node.TEXT_NODE&&(n=n.parentElement);n&&n[e]===void 0;)n=n.parentElement;return n??null}function Y(t){return t?ze(t.startContainer,Ae):null}function $n(t){return ze(t,Ae)}function jo(t){return t?ze(t.startContainer,Ge):null}function jn(t){return ze(t,Ge)}function Pt(){return window.getSelection()}function W(){let t=Pt();return t.rangeCount>0?t.getRangeAt(0).cloneRange():null}function $t(){let t=W();if(!t)return 0;t.collapse(true);let e=jo(t),n=Y(t),o=e??M(n);return ge(o,t.startContainer,t.startOffset)}function ge(t,e,n){if(!t)return 0;if(e===t){if(e.nodeType===Node.TEXT_NODE)return n;let i=0,a=t.childNodes,c=Math.min(n,a.length);for(let l=0;l<c;l++)i+=a[l].textContent.length;return i}if(e.nodeType===Node.ELEMENT_NODE&&!t.contains(e))return 0;let o=0,r=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),s=r.nextNode();for(;s;){if(s===e)return o+n;o+=s.textContent.length,s=r.nextNode();}return o}function Kn(t=W()){if(!t||t.collapsed)return null;let e=$n(t.startContainer),n=$n(t.endContainer);if(!e||!n)return null;let o=jn(t.startContainer)??M(e),r=jn(t.endContainer)??M(n);return {startBlock:e,endBlock:n,startOffset:ge(o,t.startContainer,t.startOffset),endOffset:ge(r,t.endContainer,t.endOffset)}}function Ot(t,e){let n=document.createRange();if(!t)return n;if(e<=0)return n.setStart(t,0),n.collapse(true),n;let o=0,r=[t];for(;r.length>0;){let s=r.pop();if(s.nodeType===Node.TEXT_NODE){let i=s.textContent.length;if(o+i>=e)return n.setEnd(s,e-o),n.setStart(s,e-o),n;o+=i;}else if(s.childNodes&&s.childNodes.length>0)for(let i=s.childNodes.length-1;i>=0;i--)r.push(s.childNodes[i]);}return n.setEnd(t,t.childNodes.length),n.setStart(t,t.childNodes.length),n}function ee(t,e){let n=Ot(t,e),o=Pt();o.removeAllRanges(),o.addRange(n);}function M(t){if(!t)return null;let e=Ve(t);return e?.firstElementChild??e?.firstChild}function P(t){if(!t?.[Ae])return null;let e=M(t);return e?re(e)?.classInstance:null}function Ve(t){if(!t)return null;for(let e of t.children)if(e[$o])return e;return null}function Ye(t,e,n,o=12){let r=t.getBoundingClientRect(),s=typeof e?.getBoundingClientRect=="function"?e.getBoundingClientRect():e??{left:0,top:0},i=n?.offsetHeight??40;return {x:s.left-r.left,y:s.top-r.top-i-o}}function Fn(t,e){let n=t.getBoundingClientRect(),o=e?.offsetWidth??420,r=e?.offsetHeight??320,s=16;return {x:Math.max(s,(n.width-o)/2),y:Math.max(s,(n.height-r)/2)}}var We=Et();var Xe=class extends Ue{state;element;mrakomor;constructor(e){super(e);let{state:n,observeDOMChanges:o=true}=e??{};this.state=n,this.element=null,this.mrakomor=bt(We),this._stale=false,this._observer=null,this._offInputStale=null,this._onInputMarkStale=null,this._observeDOMChanges=o;}static get NAMESPACE(){return "namespace.AbstractComponent"}static getStateSchema(){return p.object({component:p.string().default(this.NAMESPACE),properties:p.object().default({}),settings:p.object().default({})}).default({})}static getPropsSchema(){return p.object({state:this.getStateSchema(),observeDOMChanges:p.boolean().default(true)}).default({})}parseFromHTML(e){return this.constructor.getStateSchema(e).parse()}getState(){if(this._stale){let e=this.element;return this.parseFromHTML(e)}return this.state.peek()}isStale(){return this._stale}#e(){this._stale=true;}onMount(){!this.element||!this._observeDOMChanges||(this._observer=new MutationObserver(()=>{this.#e();}),this._observer.observe(this.element,{subtree:true,characterData:true,characterDataOldValue:true,childList:true,attributes:true,attributeOldValue:true}),this._onInputMarkStale=e=>{let n=e.target;n instanceof Node&&this.element?.contains(n)&&this.#e();},this.mrakomor?.emitter&&(this._offInputStale=this.mrakomor.emitter.on(m.INPUT,this._onInputMarkStale)));}onUnmount(){this._observer&&(this._observer.disconnect(),this._observer=null),this._offInputStale?.(),this._offInputStale=null,this._onInputMarkStale=null,this._stale=false;}};function te(t){return t===`
|
|
3
|
+
`||t===`\r
|
|
4
|
+
`?"":t??""}function Re({component:t,originComponent:e,properties:n,settings:o}={}){let r=n??{};return {...t?{component:t}:{},...e?{originComponent:e}:{},properties:{...r,text:r.text??"",inlineStyleRanges:r.inlineStyleRanges??[],entityRanges:r.entityRanges??[]},...o?{settings:o}:{}}}function Je(t){let e=t?.component??"";return e===wt||e.startsWith(Dn)}function jt(t,e){let n=te(t.properties.text),o=te(e.properties.text);return {state:{...t,properties:{...e.properties,...t.properties,text:n+o,inlineStyleRanges:[...t.properties.inlineStyleRanges??[],...(e.properties.inlineStyleRanges??[]).map(r=>({...r,offset:r.offset+n.length}))],entityRanges:[...t.properties.entityRanges??[],...(e.properties.entityRanges??[]).map(r=>({...r,offset:r.offset+n.length}))]},settings:{...e.settings,...t.settings}},cursor:n.length}}function zn(t,{startIndex:e,endIndex:n,startOffset:o,endOffset:r}){let s=[...t],i=s[e],a=s[n],{originalLineState:c}=Gn(i,o),{newLineState:l}=Gn(a,r),{state:u,cursor:f}=jt(c,l);return s.splice(e,n-e+1,u),{content:s,cursor:f,resultIndex:e}}function Hn(t,e){return (t??[]).filter(n=>n.offset<e).map(n=>({...n,length:Math.min(n.length,e-n.offset)}))}function qn(t,e){return (t??[]).filter(n=>n.offset+n.length>e).map(n=>({...n,offset:Math.max(0,n.offset-e),length:n.offset+n.length-Math.max(n.offset,e)}))}function Gn(t,e){let n=structuredClone(t),o=structuredClone(t);return n.properties.text=t.properties.text.slice(0,e),o.properties.text=t.properties.text.slice(e),n.properties.inlineStyleRanges=Hn(t.properties.inlineStyleRanges,e),o.properties.inlineStyleRanges=qn(t.properties.inlineStyleRanges,e),n.properties.entityRanges=Hn(t.properties.entityRanges,e),o.properties.entityRanges=qn(t.properties.entityRanges,e),o.componentId=V(),{originalLineState:n,newLineState:o}}function Vn(t,e){if(e.key!=="Enter")return false;e.preventDefault();let n=wt,o=t.mrakomor.resolveComponentConstructor(n);return t.mrakomor.command.insertBlockElement({range:W(),cursor:0,newLineState:t.mrakomor.normalizeComponentState(o.getStateSchema().parse({})),namespace:n}),true}function Yn(t,e){let n=ge(t,e.startContainer,e.startOffset),o=ge(t,e.endContainer,e.endOffset);return {offset:n,length:Math.max(0,o-n)}}function Fo(t,{style:e,offset:n,length:o}){let r=t??[],s=n+o,i=r.find(a=>a.style===e&&a.offset<=n&&a.offset+a.length>=s);return i?r.filter(a=>a!==i):[...r,{style:e,offset:n,length:o}]}function Ho(t,e){return t.offset<e.offset+e.length&&e.offset<t.offset+t.length}function qo(t,e){let n=e.offset+e.length,o=[];for(let r of t){if(!Ho(r,e)){o.push(r);continue}r.offset<e.offset&&o.push({...r,length:e.offset-r.offset});let s=r.offset+r.length;s>n&&o.push({...r,offset:n,length:s-n});}return o}function Go(t,e){let n=t??[],o=e?.length??0;if(o===0)return null;let r=e.offset??0,s=e.entity?.type,i=n.find(a=>a.offset===r&&a.length===o&&a.entity?.type===s);return i?n.filter(a=>a!==i):[...qo(n,e),e]}function Wn(t,e,{style:n,range:o}){if(!t||!e?.element||!o)return null;let r=e.read(t);if(r?.inlineStyleRanges===void 0)return null;let{offset:s,length:i}=Yn(e.element,o);return i===0?null:(e.write(t,{inlineStyleRanges:Fo(r.inlineStyleRanges??[],{style:n,offset:s,length:i})}),t)}function Xn(t,e,{state:n,namespace:o,range:r}){if(!t||!e?.element||!r)return null;let s=e.read(t);if(s?.entityRanges===void 0)return null;let i={...n,entity:{type:o,...n?.entity},...Yn(e.element,r)},a=Go(s.entityRanges??[],i);return a===null?null:(e.write(t,{entityRanges:a}),t)}var Qe=class extends Xe{static get NAMESPACE(){return "namespace.block.BlockComponent"}static get LABEL(){return ""}static get KEYWORDS(){return []}static get GROUP(){return "blocks"}isAtomic(){return false}setCursor(e){let n=()=>{if(!this.element?.isConnected)return;let o=typeof e=="number"?e:te(this.getState()?.properties?.text).length;ee(this.element,o);};n(),R(n);}onKeydown(e){}getFormattingTarget(e){return null}static toExchangeState(e){return Re({originComponent:this.NAMESPACE,properties:{...e?.properties,text:te(e?.properties?.text)},settings:e?.settings})}static fromExchangeState(e){return {properties:e?.properties,settings:e?.settings}}static appendExchangeState(e,n){return jt(e,n)}};var ne=class t extends Qe{static get NAMESPACE(){return Tn}static getStateSchema(e){return p.object({component:p.string().default(t.NAMESPACE),componentId:p.string().default(e?.getAttribute("data-componentid")||V()),properties:p.object({}).default({}),settings:p.object({}).default({})}).default({})}constructor(e){super(e),this.root=null;}getState(){return this.state.peek()}isAtomic(){return true}static appendExchangeState(){return null}onMount(){}onUnmount(){}render(){let e=this.constructor.NAMESPACE.toLowerCase().replaceAll(".","-");return E("div",{className:e,contentEditable:false,style:"position: relative;",$ref:o=>{this.element=o;},"data-state":()=>JSON.stringify(this.state.get()),"data-componentid":this.state.peek().componentId},[E("div",{$ref:o=>{this.root=o;},style:"display: block;",contentEditable:false}),E("span",{style:"position: absolute; bottom: 0; right: 0; width: 10px; height: 100%; outline: none;",contentEditable:true,[Ge]:true},document.createTextNode("\xA0"))])}onKeydown(e){e.key!=="Backspace"&&e.key!=="ArrowUp"&&e.key!=="ArrowDown"&&e.preventDefault(),Vn(this,e);}};var he=class extends ne{static get NAMESPACE(){return On}onMount(){let e=E("div",{style:"user-select: none;",contentEditable:false},()=>`Unknown component: ${this.state.get().component}`);J(this.root,e);}onUnmount(){this.root.innerHTML="";}};function zo(t,e){let n=t._getBlockElementByComponentId(e);return P(n)?.isStale?.()??false}function Jn(t){return (e,n)=>{if(!se(e,n))return false;let o=n?.componentId??e?.componentId;return !(o&&zo(t,o))}}function Qn({mrakomor:t}){let e=t.get(),n=Jn(e);return yt(We,e),De(()=>{e._onMount();}),Pe(()=>{e._onUnmount();}),E("div",{id:e._id,className:"mrakomor-editor"},[E("div",{className:"mrakomor-editor-surface"},[E("div",{className:"mrakomor-tools-container"}),E("div",{className:"mrakomor-content",contentEditable:true,style:{spellcheck:true,outline:"none"}},[St(()=>e._getContentState(),o=>o.componentId,(o,r)=>E(()=>{let s;De(()=>{s.getNodeComponent=()=>{let c=M(s);return c?re(c):null},e._setBlockElement(s,r);}),Pe(()=>{e._removeBlockElement(s);});let i=e.resolveComponent(o.get().component,o),a=e.wrapBlockElement(i);return E("div",{className:"mrakomor-block-element",[Ae]:true,$ref:c=>{s=c;}},a)}),{equals:n})])])])}function Ze(t,e,n){let o=t._getBlockElementIndex(e);if(o===-1)return false;let r=t.getContent();return r.splice(o,1,t.normalizeComponentState(n)),t._setContentState(r),true}function Zn(t,{customHook:e,applyFn:n,applyArgs:o,resolveRange:r=true}){let{mrakomor:s}=t,{blockElement:i,range:a}=t;r&&(a=a??W(),i=i??Y(a));let c=P(i),l=c?.[e]?.(t);if(t.defaultPrevented){l&&Ze(s,i,l);return}let u=c?.getFormattingTarget?.(a);if(!u)return;let f=s._getBlockElementState(i);if(!f)return;let d=n(structuredClone(f),u,{...o,range:a});d&&Ze(s,i,d);}function Vo(t){let{mrakomor:e}=t,{blockElement:n,range:o,newLineState:r,originalLineState:s,namespace:i,position:a,cursor:c}=t,l,u;if(a||(n?l=e._getBlockElementIndex(n):o&&(l=e._getBlockElementIndex(Y(o))),l===void 0||l===-1))return;u=l+1;let f=e.getContent();s&&f.splice(l,1,e.normalizeComponentState(s)),r&&(r.component=i,f.splice(u,0,e.normalizeComponentState(r))),e._setContentState(f),R(()=>{typeof c=="number"&&P(e._getBlockElements()[u])?.setCursor?.(c);});}function Yo(t){let{mrakomor:e}=t,{blockElement:n,range:o,blocks:r,cursor:s,cursorBlockIndex:i=0}=t;if(!Array.isArray(r)||r.length===0)return;let a=n??(o?Y(o):null),c=e._getBlockElementIndex(a);if(c===-1)return;let l=[...e._getContentState()];l.splice(c,1,...r.map(u=>e.normalizeComponentState(u))),e._setContentState(l),R(()=>{if(typeof s!="number")return;e._syncBlockElementsFromDom();let u=M(e._getBlockElements()[c+i]);u?.isConnected&&ee(u,s);});}function Wo(t){let{mrakomor:e,blockElement:n,namespace:o}=t,r=e._getBlockElementState(n);if(!r)return;let s=e.register.blocks.getByNamespace(r.component),i=e.register.blocks.getByNamespace(o),a=t.exchangeState??s?.toExchangeState?.(r)??Re({properties:r.properties,settings:r.settings}),c=i?.fromExchangeState?.(a)??a;Ze(e,n,{...c,component:o,componentId:V()});}function Xo(t){let{mrakomor:e,blockElement:n,targetIndex:o}=t,r=e._getBlockElementIndex(n);if(r===-1||typeof o!="number")return;let s=o>r?o-1:o;if(s===r)return;let i=[...e._getContentState()],[a]=i.splice(r,1);i.splice(s,0,a),e._setContentState(i);}function Jo(t){let{mrakomor:e,blockElement:n,range:o}=t,r=e._getBlockElementIndex(n);if(r!==-1){let s=e.getContent();s.splice(r,1),e._setContentState(s);}R(()=>{let s=Y(o);ee(M(s),0);});}function Qo(t){let{mrakomor:e,state:n,blockElement:o}=t,r=e._getBlockElementState(o);if(!r)return;let s=structuredClone(r),i=n?.offset,a=n?.length,c=n?.entity?.type;s.properties.entityRanges=(s.properties.entityRanges??[]).filter(l=>!(l?.offset===i&&l?.length===a&&l?.entity?.type===c)),Ze(e,o,s),e.command.closeDialog?.();}function Zo(t){Zn(t,{customHook:"insertEntityRange",applyFn:Xn,applyArgs:{state:t.state,namespace:t.namespace}});}function er(t){Zn(t,{customHook:"insertInlineStyleRange",applyFn:Wn,applyArgs:{style:t.style}});}function tr(t){let{mrakomor:e,blockElement:n,previousBlockElement:o}=t,r=e._getBlockElementIndex(o),s=e._getBlockElementIndex(n);if(r===-1||s===-1)return;let i=e.getContent(),a=i[s],c=i[r],l=e.register.blocks.getByNamespace(c.component),u=e.register.blocks.getByNamespace(a.component),f=t.exchangeState??u?.toExchangeState?.(a)??Re({properties:a.properties,settings:a.settings}),d=l?.appendExchangeState?.(c,f);if(!d)return;i.splice(s,1),i.splice(r,1,e.normalizeComponentState(d.state)),e._setContentState(i);let h=()=>{if(typeof d.cursor!="number")return;let x=e._getBlockElements()[r]??o,_=M(x);_?.isConnected&&ee(_,d.cursor);};h(),R(h);}function nr(t){let{mrakomor:e}=t,n=e.getRoot();if(t.relatedTarget instanceof Node&&n.contains(t.relatedTarget))return;let[r,s]=H(()=>[e.getContent(),e._getContentState()]);r.length===s.length&&r.every((a,c)=>a===s[c])||e.setContent(r);}function or(t){let e=W();return Y(e)?.getNodeComponent?.()?.classInstance?.onKeydown?.(t)}function rr(t){P(t)?.setCursor?.();}function sr(t){if(t.key!=="Backspace")return;let{mrakomor:e}=t,n=W();if(!n)return;let o=Y(n);if(!o)return;let r=Ve(o),s=o?.previousSibling,a=Ve(s)?.childNodes?.[0]?.contentEditable==="true",c=r?.childNodes?.[0]?.contentEditable==="true",l=M(o),u=!te(l?.textContent),f=n.collapsed&&(n.startOffset===0||$t()===0||u);if(!n.collapsed){let g=Kn(n);if(g&&g.startBlock!==g.endBlock){let y=e._getBlockElementIndex(g.startBlock),k=e._getBlockElementIndex(g.endBlock),S=e.getContent(),b=y>=0?S[y]:void 0,A=k>=0?S[k]:void 0;if(y>=0&&k>y&&typeof b?.properties?.text=="string"&&typeof A?.properties?.text=="string"){t.preventDefault();let{content:U,cursor:Ee,resultIndex:at}=zn(S,{startIndex:y,endIndex:k,startOffset:g.startOffset,endOffset:g.endOffset});e._setContentState(U.map(X=>e.normalizeComponentState(X))),R(()=>{let X=e._getBlockElements()[at];X&&typeof Ee=="number"&&ee(M(X),Ee);});}}return}if(!f)return;let d=e._getBlockElementIndex(o),h=s?e._getBlockElementIndex(s):-1,x=e._getBlockElementState(o),_=e._getBlockElementState(s),N=s?P(s):null;if(!s||h<0){t.preventDefault();return}if(_&&x&&Je(x)&&N&&!N.isAtomic?.()){if(u&&!Je(_)){t.preventDefault();let g=e.getContent();g.splice(d,1),e._setContentState(g),rr(s);return}t.preventDefault(),e.command.mergeBlockElement({blockElement:o,previousBlockElement:s,range:n});return}N?.isAtomic?.()&&(!a&&n.startOffset===0||o?.textContent==="\xA0"&&!c)&&(t.preventDefault(),e.command.removeBlockElement({blockElement:s,range:n})),x&&!Je(x)&&t.preventDefault();}function et(t){return {resolveComponent:e=>e===ne.NAMESPACE?ne:he,registerCommands(e){e.emitter.on(m.INSERT_BLOCK_ELEMENT,T(Vo)),e.emitter.on(m.REPLACE_BLOCK_ELEMENT,T(Yo)),e.emitter.on(m.TRANSFORM_BLOCK_ELEMENT,T(Wo)),e.emitter.on(m.MOVE_BLOCK_ELEMENT,T(Xo)),e.emitter.on(m.REMOVE_BLOCK_ELEMENT,T(Jo)),e.emitter.on(m.REMOVE_ENTITY_RANGE,T(Qo)),e.emitter.on(m.INSERT_ENTITY_RANGE,T(Zo)),e.emitter.on(m.INSERT_INLINE_STYLE_RANGE,T(er)),e.emitter.on(m.MERGE_BLOCK_ELEMENT,T(tr));},registerHandlers(e){e.emitter.on(m.FOCUSOUT,nr),e.emitter.on(m.KEYDOWN,T(or)),e.emitter.on(m.KEYDOWN,T(sr));},registerListeners(e){let n=e.getRoot(),{signal:o}=e.listenerAbortController;n.addEventListener("keydown",r=>e.emitDomEvent(m.KEYDOWN,r),{signal:o}),n.addEventListener("beforeinput",r=>e.emitDomEvent(m.BEFORE_INPUT,r),{signal:o}),n.addEventListener("input",r=>e.emitDomEvent(m.INPUT,r),{signal:o}),n.addEventListener("focusin",r=>e.emitDomEvent(m.FOCUSIN,r),{signal:o}),n.addEventListener("focusout",r=>e.emitDomEvent(m.FOCUSOUT,r),{signal:o}),n.addEventListener("click",r=>e.emitDomEvent(m.CLICK,r),{signal:o}),document.addEventListener("selectionchange",r=>e.emitDomEvent(m.SELECTION_CHANGE,r),{signal:o});}}}(function(){if(!(typeof document>"u")){var t="mrakomor/core/plugin/dialog/Dialog.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.mrakomor-dialog-container,.mrakomor-dialog-backdrop{pointer-events:all}.dialog[open]{background-color:#fff;border:1px solid black;border-radius:8px;box-shadow:0 0 5px #0000001a;padding:12px;display:flex;flex-flow:row wrap;justify-content:space-between}.dialog[open] .dialog-controls{text-align:right;width:100%}.dialog[open] .dialog-button-close{background-color:#f0f0f0;border:1px solid black;border-radius:4px;color:#000;cursor:pointer;display:inline-block;font-size:14px;margin-right:1px;padding:4px 8px;text-align:center}.dialog[open] .dialog-container{width:100%}
|
|
5
|
+
`,document.head.appendChild(n);}}})();function ir(t,e,n,o){let r=t.getRoot()?.querySelector(e);if(!r)return {container:null,dispose:null};let s=document.createElement("div");s.className=n,r.append(s);let i=J(s,o);return {container:s,dispose:i??null}}function tt(t,e,n){return ir(t,".mrakomor-tools-container",e,n)}var eo="mrakomor.dialog.Dialog";function nt({open:t,placement:e,positionX:n,positionY:o,block:r,dialogRef:s}){let i=B(()=>{let c=e.get()==="center";return {position:"absolute",zIndex:c?"9100":"9000",top:`${o.get()}px`,left:`${n.get()}px`,...c?{padding:0,background:"transparent",border:"none",boxShadow:"none",minWidth:0}:{background:"#fff",border:"1px solid #ccc",borderRadius:"4px",padding:"8px 10px",boxShadow:"0 2px 8px rgba(0,0,0,.15)",minWidth:"220px"}}}),a=B(()=>({position:"absolute",inset:"0",zIndex:"9050",background:"rgba(15, 23, 42, 0.28)",pointerEvents:"all"}));return E("span",{style:{display:"contents"}},[_e(()=>t.get()&&e.get()==="center",E("div",{className:"mrakomor-dialog-backdrop",contentEditable:false,style:a})),_e(()=>t.get(),E("div",{className:"mrakomor-dialog-container",contenteditable:false,style:i,$ref:s},()=>r.get()))])}nt.NAMESPACE=eo;function ot({mrakomor:t}){let e=null,n=C(false),o=C(false),r=C("anchor"),s=C(0),i=C(0),a=C(null),c=oe(),l=oe();function u(){o.set(false),r.set("anchor"),c.set(null),R(()=>{n.set(false);});}return {resolveComponent(f){if(f===eo)return nt},registerEvents(){m.OPEN_DIALOG="mrakomor:open-dialog",m.CLOSE_DIALOG="mrakomor:close-dialog";},registerCommands(f){f.command.openDialog=(d,h)=>{f.emit(m.OPEN_DIALOG,{...d,options:h});},f.command.closeDialog=()=>{f.emit(m.CLOSE_DIALOG);};},registerHandlers(){t.emitter.on(m.OPEN_DIALOG,({children:f,element:d,options:h={}})=>{a.set(f??E("div",{},"Empty dialog")),o.set(true),c.set(d??null),r.set(h.placement??"anchor"),R(()=>{let x=t.getRoot(),{x:_,y:N}=h.placement==="center"?Fn(x,l):Ye(x,d??{left:0,top:0},l);s.set(_),i.set(N),n.set(true);});}),t.emitter.on(m.CLOSE_DIALOG,u),t.emitter.on(m.KEYDOWN,f=>{f.key==="Escape"&&o.peek()===true&&t.command.closeDialog();}),t.emitter.on(m.CLICK,f=>{if(o.peek()!==true||n.peek()!==true)return;let d=f.target,h=l&&typeof l.contains=="function"&&l.contains(d),x=c&&typeof c.contains=="function"&&c.contains(d);!h&&!x&&t.command.closeDialog();});},onMount(){let{dispose:f}=tt(t,"mrakomor-dialog-plugin-container",E(nt,{open:o,placement:r,positionX:s,positionY:i,block:a,dialogRef:l}));e=f;},onUnmount(){e?.(),e=null;}}}function ar(){return p.object({id:p.string(),group:p.string().default("general"),description:p.string().default(""),commands:p.array(p.string()).default([]),shortcuts:p.array(p.string()).default([])}).default({})}function to(t){try{return ar().parse(t)}catch{return null}}var rt=class extends pe{constructor(e){super(e,{sort:n=>n});}normalize(e){return to(e)}};(function(){if(!(typeof document>"u")){var t="mrakomor/core/plugin/menu/Menu.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===t});if(!e){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",t),n.textContent=`.mrakomor-menu{position:absolute;z-index:9300;display:flex;flex-direction:column;gap:2px;min-width:160px;max-height:240px;overflow-y:auto;background:#1a1a1a;border-radius:6px;padding:4px;box-shadow:0 3px 10px #00000040;pointer-events:all}.mrakomor-menu__item{display:flex;align-items:center;width:100%;padding:6px 10px;border:none;border-radius:4px;background:transparent;color:#fff;cursor:pointer;font-size:13px;font-weight:600;text-align:left;transition:background .1s}.mrakomor-menu__item:hover,.mrakomor-menu__item--active{background:#ffffff26}
|
|
6
|
+
`,document.head.appendChild(n);}}})();function cr(t,e=-1){if(!t.length)return null;let n=t.map((o,r)=>E("button",{type:"button",role:"option",id:`mrakomor-menu-option-${o.id}`,className:["mrakomor-menu__item",r===e?"mrakomor-menu__item--active":""].filter(Boolean).join(" "),title:o.label,"data-id":o.id,"aria-selected":r===e?"true":"false",onMouseDown:s=>{s.preventDefault();}},o.label));return E("span",{style:"display: contents"},n)}function Ut({open:t,positionX:e,positionY:n,entries:o,highlightIndex:r,ariaLabel:s,menuRef:i}){let a=B(()=>({left:`${e.get()}px`,top:`${n.get()}px`}));return _e(()=>t.get(),E("div",{className:"mrakomor-menu",role:"listbox","aria-label":()=>s.get(),contenteditable:false,style:a,$ref:i},()=>cr(o.get(),r.get())))}function st({mrakomor:t}){let e=null,n=null,o=oe(),r=null,s=C(false),i=C(false),a=C(0),c=C(0),l=C([]),u=C(-1),f=C("Menu");function d(g){R(()=>{let y=t.getRoot();if(!y||!g)return;let k=o?.offsetHeight??200,S=y.getBoundingClientRect();if(g.top-S.top>k+8){let{x:A,y:v}=Ye(y,g,{offsetHeight:k},4);a.set(A),c.set(v);}else a.set(g.left-S.left),c.set(g.bottom-S.top+4);s.set(true);});}function h(){i.set(false),r=null,u.set(-1),l.set([]),R(()=>{s.set(false);});}function x(g){!g||!r||r(g);}function _(g){if(i.peek()!==true)return;let y=g.target?.closest?.(".mrakomor-menu__item");if(!y||!n?.contains(y))return;g.preventDefault(),g.stopPropagation();let k=y.getAttribute("data-id"),S=l.peek().find(b=>b.id===k);S&&x(S);}function N(g={}){let{entries:y=[],anchorRect:k,highlightIndex:S=-1,ariaLabel:b="Menu",onSelect:A=null}=g;l.set(y),u.set(S),f.set(b),A!==void 0&&(r=A),i.set(true),k?d(k):s.set(true);}return {registerEvents(){m.OPEN_MENU="mrakomor:open-menu",m.CLOSE_MENU="mrakomor:close-menu",m.UPDATE_MENU="mrakomor:update-menu";},registerCommands(g){g.command.openMenu=y=>{g.emit(m.OPEN_MENU,y);},g.command.updateMenu=y=>{g.emit(m.UPDATE_MENU,y);},g.command.closeMenu=()=>{g.emit(m.CLOSE_MENU);};},registerHandlers(){t.emitter.on(m.OPEN_MENU,N),t.emitter.on(m.UPDATE_MENU,N),t.emitter.on(m.CLOSE_MENU,h),t.emitter.on(m.CLICK,g=>{let y=o?.current??o;i.peek()===true&&s.peek()===true&&y&&typeof y.contains=="function"&&!y.contains(g.target)&&h();}),t.emitter.on(m.KEYDOWN,g=>{g.key==="Escape"&&i.peek()===true&&h();});},onMount(){let{container:g,dispose:y}=tt(t,"mrakomor-menu-plugin-container",E(Ut,{open:i,positionX:a,positionY:c,entries:l,highlightIndex:u,ariaLabel:f,menuRef:o}));n=g,n?.addEventListener("click",_),e=y;},onUnmount(){n?.removeEventListener("click",_),e?.(),e=null,n=null,o.current=null,r=null;}}}function lr(t){return t!=null&&typeof t=="object"&&(typeof Element>"u"?t.nodeType===1:t instanceof Element)}function no(){return p.object({root:p.any().refine(lr,{message:"root must be a DOM Element"}),id:p.string().optional(),debug:p.boolean().optional(),content:p.array(p.any()).optional(),plugins:p.array(p.function()).optional(),blockComponents:p.array(p.any().refine(t=>typeof t=="function"||t!=null&&typeof t=="object"&&typeof t.component=="function",{message:"blockComponents entry must be a constructor or registration"})).optional(),slashActions:p.array(p.any().refine(t=>t!=null&&typeof t=="object"&&typeof t.handler=="function",{message:"slashActions entry must include a handler function"})).optional(),inlineStyles:p.array(p.function()).optional(),entityRanges:p.array(p.function()).optional(),tooltip:p.any().optional()})}function oo(t){return [...t.filter(e=>e!==ot&&e!==st&&e!==et),ot,st,et]}function ur(t){no().parse(t);let e={debug:false,content:[],plugins:[],blockComponents:[],slashActions:[],inlineStyles:[ce,le,me,ue,fe],entityRanges:[],tooltip:{}},n={...e,...t,plugins:oo(t.plugins??e.plugins)},o=new it(n);return o._init(),o}var it=class{#e=V();#o;#t=[];#n=[];#r;#i=false;listenerAbortController=new AbortController;#c=C([],{debug:"content"});#a=[];command;emitter;register;constructor(e){let{root:n,id:o,content:r}=e;this.#e=o||this.#e,this.#o=n,this.#a=r,this.#n=[],this.#r={...e,plugins:oo(e.plugins??[])},this.register={blocks:new qe(this),help:new rt(this)};let{emitter:s,command:i}=hn({mrakomor:this});this.command=i,this.emitter=s;}_init(){this.#s(),this.#c=C(this._normalizeContentState(this.#a),{debug:"content"});}#s(){this.#t=this.#r.plugins.map(e=>e?.({config:this.#r,root:this.#o,mrakomor:this}))??[],this.#r=this.#t.reduce((e,n)=>n?.resolveConfig?.(e)??e,this.#r),this.register.blocks.add(this.#r.blockComponents??[]),this.#t.forEach(e=>{e?.registerEvents?.(this);}),this.#t.forEach(e=>{e?.registerCommands?.(this);}),this.#t.forEach(e=>{this.emitter.on(m.KEYDOWN,n=>e?.onKeyDown?.(n));}),this.#t.forEach(e=>{e?.registerHandlers?.(this);}),this.#t.forEach(e=>{e?.registerListeners?.(this);});}emit(e,n={}){return this.emitter.emit(e,{...n,mrakomor:this})}on(e,n){return this.emitter.on(e,n)}onChangeContent(e){return this.on(m.CONTENT_CHANGE,e)}emitDomEvent(e,n){let{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:a,key:c,isComposing:l,repeat:u,button:f,shiftKey:d,which:h,detail:x,isTrusted:_,target:N,relatedTarget:g,data:y,inputType:k}=n??{},{defaultPrevented:S}=this.emit(e,{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:a,key:c,isComposing:l,repeat:u,button:f,shiftKey:d,which:h,detail:x,isTrusted:_,target:N,relatedTarget:g,data:y,inputType:k});return S&&n?.preventDefault?.(),S}getConfig(){return {...this.#r,blockComponents:this.register.blocks.list(),slashActions:this.register.slashActions?.list()??[]}}wrapBlockElement(e){for(let n of this.#t){let o=n.wrapBlockElement?.(e);if(o)return o}return e}getRoot(){return this.#o}get _id(){return this.#e}getContent(){return this.#n.map(n=>P(n)?.getState())}setContent(e=[]){this._setContentState(this._normalizeContentState(e));}_syncBlockElementsFromDom(){let e=this.#o?.querySelector?.(".mrakomor-content");e&&(this.#n=[...e.querySelectorAll(".mrakomor-block-element")]);}_getBlockElements(){return this.#n}_getContentState(){return this.#c.get()}_setContentState(e=[]){this.#c.set(e),this.emit(m.CONTENT_CHANGE,{content:e}),R(()=>{this._syncBlockElementsFromDom();});}_normalizeContentState(e=[]){return e.map(n=>structuredClone(this.normalizeComponentState(n)))??[]}_setBlockElement(e,n=this.#n.length){this.#n.splice(n,0,e);}_removeBlockElement(e){this.#n=this.#n.filter(n=>n!==e);}#l(e){return P(e)?.state?.peek()?.componentId}#u(e){return e?this.#n.findIndex(n=>this.#l(n)===e):-1}_getBlockElementIndex(e){if(!e)return -1;let n=this.#n.indexOf(e);return n!==-1?n:this.#u(this.#l(e))}_getBlockElementByComponentId(e){let n=this.#u(e);return n===-1?null:this.#n[n]}_getBlockElementState(e){let n=this._getBlockElementIndex(e);if(n!==-1)return P(this.#n[n])?.getState()}mount(){let e=J(this.#o,E(Qn,{mrakomor:this}));return this.#i=true,e}unmount(){this.#i&&(this.#i=false,dn(this.#o));}_onUnmount(){this.listenerAbortController.abort(),this.#t.forEach(e=>{e?.onUnmount?.(this);}),this.emitter.removeAllListeners();}_onMount(){this.#t.forEach(e=>{e?.onMount?.(this);}),R(()=>{this._syncBlockElementsFromDom();});}resolveComponent(e,n){let o=this.resolveComponentConstructor(e);return o?E(o,{state:n}):E(he,{state:n})}resolveComponentConstructor(e){let n=this.register.blocks.getByNamespace(e);if(!n){for(let o of this.#t)if(n=o?.resolveComponent?.(e),n)break}return n}normalizeComponentState(e){let n="component"in e?e.component:e.entity.type;return this.resolveComponentConstructor(n)?.getStateSchema()?.parse(e)}};exports.Bold=ce;exports.Dialog=nt;exports.EVENT=m;exports.Italic=le;exports.Menu=Ut;exports.Mrakomor=it;exports.Subscript=ue;exports.Superscript=fe;exports.Underline=me;exports.createMrakomor=ur;exports.defaultMrakomorPlugin=et;exports.dialogPlugin=ot;exports.menuPlugin=st;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {a as a$6,c as c$
|
|
2
|
-
`,document.head.appendChild(n);}}})();var _=class extends o{static get nodeName(){return "span"}static get style(){return "SPAN"}static match(t){return t.nodeName===this.nodeName.toUpperCase()||t.style===this.style}getState(){return {style:this.constructor.style}}render(){return n(this.constructor.nodeName,{},this.props.children)}};var w=class extends _{static get nodeName(){return "b"}static get style(){return "BOLD"}static get LABEL(){return n("b",{},"B")}static match(t){return t.nodeName==="strong"?true:super.match(t)}};var P=class extends _{static get nodeName(){return "i"}static get style(){return "ITALIC"}static get LABEL(){return n("i",{},"I")}};var U=class extends _{static get nodeName(){return "sub"}static get style(){return "SUBSCRIPT"}static get LABEL(){return n("sub",{},"Sub")}};var K=class extends _{static get nodeName(){return "sup"}static get style(){return "SUPERSCRIPT"}static get LABEL(){return n("sup",{},"Sup")}};var z=class extends _{static get nodeName(){return "u"}static get style(){return "UNDERLINE"}static get LABEL(){return n("u",{},"U")}};var Wt=a.object({component:a.function(),id:a.string(),label:a.string(),keywords:a.array(a.string()),group:a.string(),order:a.number().default(({context:e})=>e?.index??0),settings:a.any().optional()});function qt(e,t){let n=`block:${e}`;return t?.style==="UNORDERED"?`${n}:ul`:t?.style==="ORDERED"?`${n}:ol`:n}function Pt(e,t=0){let n=typeof e=="function",o=n?e:e?.component,r=n?{}:e,s=o.NAMESPACE??"",i=s.split(".").pop()||s,m=r.label||o.LABEL||i||s,c=Array.isArray(o.KEYWORDS)?o.KEYWORDS:[],u=r.keywords?.length?r.keywords.map(String):c.length?c.map(String):[m,i].filter(Boolean).map(String),f=r.settings;return Wt.parse({component:o,id:r.id||qt(s,f),label:String(m),keywords:u,group:String(r.group||o.GROUP||"blocks"),...typeof r.order=="number"?{order:r.order}:{},...f?{settings:f}:{}},{context:{index:t}})}var Q=class e extends a$6{#o=null;constructor(t){super(t),this.subscribe(()=>{this.#o=null;});}normalize(t,n){if(t==null)return null;try{return Pt(t,n)}catch{return null}}getByNamespace(t){return this.#n().get(t)}#n(){return this.#o??=e.buildNamespaceMap(this.list()),this.#o}static buildNamespaceMap(t){let n=new Map;for(let o of t){let r=o.component?.NAMESPACE;r&&!n.has(r)&&n.set(r,o.component);}return n}};var R=class e extends a$4{static get NAMESPACE(){return c$2}static getStateSchema(t){return a.object({component:a.string().default(e.NAMESPACE),componentId:a.string().default(t?.getAttribute("data-componentid")||a$3()),properties:a.object({}).default({}),settings:a.object({}).default({})}).default({})}constructor(t){super(t),this.root=null;}getState(){return this.state.peek()}isAtomic(){return true}onMount(){}onUnmount(){}render(){let t=this.constructor.NAMESPACE.toLowerCase().replaceAll(".","-");return n("div",{className:t,contentEditable:false,style:"position: relative;",$ref:o=>{this.element=o;},"data-state":()=>JSON.stringify(this.state.get()),"data-componentid":this.state.peek().componentId},[n("div",{$ref:o=>{this.root=o;},style:"display: block;",contentEditable:false}),n("span",{style:"position: absolute; bottom: 0; right: 0; width: 10px; height: 100%; outline: none;",contentEditable:true,[d]:true},document.createTextNode("\xA0"))])}onKeydown(t){t.key!=="Backspace"&&t.key!=="ArrowUp"&&t.key!=="ArrowDown"&&t.preventDefault(),t$1(this,t);}};var G=class extends R{static get NAMESPACE(){return d$1}onMount(){let t=n("div",{style:"user-select: none;",contentEditable:false},()=>`Unknown component: ${this.state.get().component}`);q(this.root,t);}onUnmount(){this.root.innerHTML="";}};function Vt(e,t$1){for(let n of e._getBlockElements()){let o=t(n);if(o?.state?.peek()?.componentId===t$1)return o.isStale?.()??false}return false}function Ut(e){return (t,n)=>{if(!g(t,n))return false;let o=n?.componentId??t?.componentId;return !(o&&Vt(e,o))}}function Kt({mrakomor:e}){let t=e.get(),n$1=Ut(t);return i$1(a$7,t),k$1(()=>{t._onMount();}),l(()=>{t._onUnmount();}),n("div",{id:t._id,className:"mrakomor-editor"},[n("div",{className:"mrakomor-editor-surface"},[n("div",{className:"mrakomor-tools-container"}),n("div",{className:"mrakomor-content",contentEditable:true,style:{spellcheck:true,outline:"none"}},[p$2(()=>t._getContentState(),o=>o.componentId,(o,r)=>n(()=>{let s;k$1(()=>{s.getNodeComponent=()=>{let c=s$1(s);return c?f(c):null},t._setBlockElement(s,r);}),l(()=>{t._removeBlockElement(s);});let i=t.resolveComponent(o.get().component,o),m=t.wrapBlockElement(i);return n("div",{className:"mrakomor-block-element",[b$2]:true,$ref:c=>{s=c;}},m)}),{equals:n$1})])])])}function Z(e,t,n){let o=e._getBlockElementIndex(t);if(o===-1)return false;let r=e.getContent();return r.splice(o,1,e.normalizeComponentState(n)),e._setContentState(r),true}function zt(e,{customHook:t$1,applyFn:n,applyArgs:o,resolveRange:r=true}){let{mrakomor:s}=e,{blockElement:i$1,range:m}=e;r&&(m=m??i(),i$1=i$1??e$1(m));let c=t(i$1),u=c?.[t$1]?.(e);if(e.defaultPrevented){u&&Z(s,i$1,u);return}let f=c?.getFormattingTarget?.(m);if(!f)return;let g=s._getBlockElementIndex(i$1);if(g===-1)return;let h=s.getContent(),k=n(structuredClone(h[g]),f,{...o,range:m});k&&Z(s,i$1,k);}function Xt(e){let{mrakomor:t}=e,{blockElement:n,range:o,newLineState:r,originalLineState:s,namespace:i,position:m$1,cursor:c}=e,u,f;if(m$1||(n?u=t._getBlockElementIndex(n):o&&(u=t._getBlockElementIndex(e$1(o))),u===void 0||u===-1))return;f=u+1;let g=t.getContent();s&&g.splice(u,1,t.normalizeComponentState(s)),r&&(r.component=i,g.splice(f,0,t.normalizeComponentState(r))),t._setContentState(g),m(()=>{if(typeof c=="number"&&c===0){let h=s$1(t._getBlockElements()[f]);h?.isConnected&&r$1(h,c);}});}function Jt(e){let{mrakomor:t}=e,{blockElement:n,range:o,blocks:r,cursor:s,cursorBlockIndex:i=0}=e;if(!Array.isArray(r)||r.length===0)return;let m$1=n??(o?e$1(o):null),c=t._getBlockElementIndex(m$1);if(c===-1)return;let u=[...t._getContentState()];u.splice(c,1,...r.map(f=>t.normalizeComponentState(f))),t._setContentState(u),m(()=>{if(typeof s!="number")return;t._syncBlockElementsFromDom();let f=s$1(t._getBlockElements()[c+i]);f?.isConnected&&r$1(f,s);});}function Qt(e){let{mrakomor:t,blockElement:n,namespace:o}=e,r=t._getBlockElementIndex(n);if(r===-1)return;let s=t.getContent()[r];Z(t,n,{...s,component:o,componentId:a$3()});}function Zt(e){let{mrakomor:t,blockElement:n,targetIndex:o}=e,r=t._getBlockElementIndex(n);if(r===-1||typeof o!="number")return;let s=o>r?o-1:o;if(s===r)return;let i=[...t._getContentState()],[m]=i.splice(r,1);i.splice(s,0,m),t._setContentState(i);}function te(e){let{mrakomor:t,blockElement:n,range:o}=e,r=t._getBlockElementIndex(n);if(r!==-1){let s=t.getContent();s.splice(r,1),t._setContentState(s);}m(()=>{let s=e$1(o);r$1(s$1(s),0);});}function ee(e){let{mrakomor:t,state:n,blockElement:o}=e,r=t._getBlockElementIndex(o);if(r===-1)return;let s=structuredClone(t.getContent()[r]),i=n?.offset,m=n?.length,c=n?.entity?.type;s.properties.entityRanges=(s.properties.entityRanges??[]).filter(u=>!(u?.offset===i&&u?.length===m&&u?.entity?.type===c)),Z(t,o,s),t.command.closeDialog?.();}function ne(e){zt(e,{customHook:"insertEntityRange",applyFn:y,applyArgs:{state:e.state,namespace:e.namespace}});}function oe(e){zt(e,{customHook:"insertInlineStyleRange",applyFn:x,applyArgs:{style:e.style}});}function re(e){let{mrakomor:t,blockElement:n,previousBlockElement:o}=e,r=t._getBlockElementIndex(o),s=t._getBlockElementIndex(n);if(r===-1||s===-1)return;let i=t.getContent(),m$1=i[s],c=i[r];if(!k(c)||!k(m$1))return;let u=p$1(c,m$1);i.splice(s,1),i.splice(r,1,t.normalizeComponentState(u.state)),t._setContentState(i);let f=()=>{if(typeof u.cursor!="number")return;let g=t._getBlockElements()[r]??o,h=s$1(g);h?.isConnected&&r$1(h,u.cursor);};f(),m(f);}function se(e){let{mrakomor:t}=e,n=t.getRoot();if(e.relatedTarget instanceof Node&&n.contains(e.relatedTarget))return;let[r,s]=a$5(()=>[t.getContent(),t._getContentState()]);r.length===s.length&&r.every((m,c)=>m===s[c])||t.setContent(r);}function ie(e){let t=i();return e$1(t)?.getNodeComponent?.()?.classInstance?.onKeydown?.(e)}function le(e){t(e)?.setCursor?.();}function ce(e){if(e.key!=="Backspace")return;let{mrakomor:t$1}=e,n=i();if(!n)return;let o=e$1(n);if(!o)return;let r=u(o),s=o?.previousSibling,m$1=u(s)?.childNodes?.[0]?.contentEditable==="true",c=r?.childNodes?.[0]?.contentEditable==="true",u$1=s$1(o),f=!j(u$1?.textContent),g=n.collapsed&&(n.startOffset===0||j$1()===0||f);if(!n.collapsed){let E=p(n);if(E&&E.startBlock!==E.endBlock){let S=t$1._getBlockElements(),b=S.indexOf(E.startBlock),L=S.indexOf(E.endBlock),M=t$1.getContent(),it=M[b],$t=M[L];if(b>=0&&L>b&&typeof it?.properties?.text=="string"&&typeof $t?.properties?.text=="string"){e.preventDefault();let{content:Yt,cursor:ut,resultIndex:jt}=q$1(M,{startIndex:b,endIndex:L,startOffset:E.startOffset,endOffset:E.endOffset});t$1._setContentState(Yt.map(j=>t$1.normalizeComponentState(j))),m(()=>{let j=t$1._getBlockElements()[jt];j&&typeof ut=="number"&&r$1(s$1(j),ut);});}}return}if(!g)return;let h=t$1._getBlockElementIndex(o),k$1=s?t$1._getBlockElementIndex(s):-1,x=t$1.getContent(),B=h>=0?x[h]:null,A=k$1>=0?x[k$1]:null,d=s?t(s):null;if(!s||k$1<0){e.preventDefault();return}if(A&&B&&k(B)&&d&&!d.isAtomic?.()){if(f&&!k(A)){e.preventDefault(),x.splice(h,1),t$1._setContentState(x),le(s);return}e.preventDefault(),t$1.command.mergeBlockElement({blockElement:o,previousBlockElement:s,range:n});return}d?.isAtomic?.()&&(!m$1&&n.startOffset===0||o?.textContent==="\xA0"&&!c)&&(e.preventDefault(),t$1.command.removeBlockElement({blockElement:s,range:n}));}function tt(e){return {resolveComponent:t=>t===R.NAMESPACE?R:G,registerCommands(t){t.emitter.on(a$1.INSERT_BLOCK_ELEMENT,b(Xt)),t.emitter.on(a$1.REPLACE_BLOCK_ELEMENT,b(Jt)),t.emitter.on(a$1.TRANSFORM_BLOCK_ELEMENT,b(Qt)),t.emitter.on(a$1.MOVE_BLOCK_ELEMENT,b(Zt)),t.emitter.on(a$1.REMOVE_BLOCK_ELEMENT,b(te)),t.emitter.on(a$1.REMOVE_ENTITY_RANGE,b(ee)),t.emitter.on(a$1.INSERT_ENTITY_RANGE,b(ne)),t.emitter.on(a$1.INSERT_INLINE_STYLE_RANGE,b(oe)),t.emitter.on(a$1.MERGE_BLOCK_ELEMENT,b(re));},registerHandlers(t){t.emitter.on(a$1.FOCUSOUT,se),t.emitter.on(a$1.KEYDOWN,b(ie)),t.emitter.on(a$1.KEYDOWN,b(ce));},registerListeners(t){let n=t.getRoot(),{signal:o}=t.listenerAbortController;n.addEventListener("keydown",r=>t.emitDomEvent(a$1.KEYDOWN,r),{signal:o}),n.addEventListener("beforeinput",r=>t.emitDomEvent(a$1.BEFORE_INPUT,r),{signal:o}),n.addEventListener("input",r=>t.emitDomEvent(a$1.INPUT,r),{signal:o}),n.addEventListener("focusin",r=>t.emitDomEvent(a$1.FOCUSIN,r),{signal:o}),n.addEventListener("focusout",r=>t.emitDomEvent(a$1.FOCUSOUT,r),{signal:o}),n.addEventListener("click",r=>t.emitDomEvent(a$1.CLICK,r),{signal:o}),document.addEventListener("selectionchange",r=>t.emitDomEvent(a$1.SELECTION_CHANGE,r),{signal:o});}}}(function(){if(!(typeof document>"u")){var e="mrakomor/core/plugin/dialog/Dialog.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===e});if(!t){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",e),n.textContent=`.mrakomor-dialog-container,.mrakomor-dialog-backdrop{pointer-events:all}.dialog[open]{background-color:#fff;border:1px solid black;border-radius:8px;box-shadow:0 0 5px #0000001a;padding:12px;display:flex;flex-flow:row wrap;justify-content:space-between}.dialog[open] .dialog-controls{text-align:right;width:100%}.dialog[open] .dialog-button-close{background-color:#f0f0f0;border:1px solid black;border-radius:4px;color:#000;cursor:pointer;display:inline-block;font-size:14px;margin-right:1px;padding:4px 8px;text-align:center}.dialog[open] .dialog-container{width:100%}
|
|
3
|
-
`,document.head.appendChild(
|
|
4
|
-
`,document.head.appendChild(
|
|
1
|
+
import {a as a$6,c as c$2}from'./chunk-WQWE5UCN.mjs';import {a as a$4}from'./chunk-G2QV4GOO.mjs';import {a as a$7}from'./chunk-T7OO472O.mjs';import {a}from'./chunk-P7IKAZYZ.mjs';import {a as a$2}from'./chunk-5VPYPKGA.mjs';import {c as c$1,u,d as d$2,j,r as r$1,l,k,z as z$1,y}from'./chunk-TX4RCFPO.mjs';import {a as a$1,b,c}from'./chunk-B6JJAATK.mjs';export{a as EVENT}from'./chunk-B6JJAATK.mjs';import {w as w$1,v as v$1,a as a$3,t as t$1,m,d as d$1,i,e,u as u$1,s as s$1,j as j$1,p as p$1,r as r$2,b as b$2}from'./chunk-YHWQV2DB.mjs';import {o,b as b$1,t,d,f,n,r,s,p,a as a$5,j as j$2,l as l$1,m as m$1,q,g,h}from'./chunk-K2DMHAUD.mjs';(function(){if(!(typeof document>"u")){var n="mrakomor/core/style/core.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===n});if(!t){var e=document.createElement("style");e.setAttribute("data-mrakomor-css",""),e.setAttribute("data-mrakomor-css-path",n),e.textContent=`.namespace-unknown-unknowncomponent{background-color:#f0f0f0;padding:12px 0;margin-bottom:8px}.mrakomor-editor:focus-visible{outline:none}.mrakomor-editor{display:flex;flex-direction:column;min-height:0}.mrakomor-editor-surface{position:relative;flex:1 1 auto;min-height:0}.mrakomor-tools-container{position:absolute;inset:0;pointer-events:none;z-index:4}.mrakomor-content{position:relative;min-height:0}.mrakomor-content:focus-visible{outline:none}
|
|
2
|
+
`,document.head.appendChild(e);}}})();var N=class extends p{static get nodeName(){return "span"}static get style(){return "SPAN"}static match(t){return t.nodeName===this.nodeName.toUpperCase()||t.style===this.style}getState(){return {style:this.constructor.style}}render(){return o(this.constructor.nodeName,{},this.props.children)}};var T=class extends N{static get nodeName(){return "b"}static get style(){return "BOLD"}static get LABEL(){return o("b",{},"B")}static match(t){return t.nodeName==="strong"?true:super.match(t)}};var w=class extends N{static get nodeName(){return "i"}static get style(){return "ITALIC"}static get LABEL(){return o("i",{},"I")}};var P=class extends N{static get nodeName(){return "sub"}static get style(){return "SUBSCRIPT"}static get LABEL(){return o("sub",{},"Sub")}};var U=class extends N{static get nodeName(){return "sup"}static get style(){return "SUPERSCRIPT"}static get LABEL(){return o("sup",{},"Sup")}};var K=class extends N{static get nodeName(){return "u"}static get style(){return "UNDERLINE"}static get LABEL(){return o("u",{},"U")}};var jt=a.object({component:a.function(),id:a.string(),label:a.string(),keywords:a.array(a.string()),group:a.string(),order:a.number().default(({context:n})=>n?.index??0),settings:a.any().optional()});function Wt(n,t){let e=`block:${n}`;return t?.style==="UNORDERED"?`${e}:ul`:t?.style==="ORDERED"?`${e}:ol`:e}function Pt(n,t=0){let e=typeof n=="function",o=e?n:n?.component,r=e?{}:n,s=o.NAMESPACE??"",i=s.split(".").pop()||s,a=r.label||o.LABEL||i||s,l=Array.isArray(o.KEYWORDS)?o.KEYWORDS:[],p=r.keywords?.length?r.keywords.map(String):l.length?l.map(String):[a,i].filter(Boolean).map(String),g=r.settings;return jt.parse({component:o,id:r.id||Wt(s,g),label:String(a),keywords:p,group:String(r.group||o.GROUP||"blocks"),...typeof r.order=="number"?{order:r.order}:{},...g?{settings:g}:{}},{context:{index:t}})}var Q=class n extends a$6{#o=null;constructor(t){super(t),this.subscribe(()=>{this.#o=null;});}normalize(t,e){if(t==null)return null;try{return Pt(t,e)}catch{return null}}getByNamespace(t){return this.#n().get(t)}#n(){return this.#o??=n.buildNamespaceMap(this.list()),this.#o}static buildNamespaceMap(t){let e=new Map;for(let o of t){let r=o.component?.NAMESPACE;r&&!e.has(r)&&e.set(r,o.component);}return e}};var v=class n extends a$4{static get NAMESPACE(){return c$1}static getStateSchema(t){return a.object({component:a.string().default(n.NAMESPACE),componentId:a.string().default(t?.getAttribute("data-componentid")||a$3()),properties:a.object({}).default({}),settings:a.object({}).default({})}).default({})}constructor(t){super(t),this.root=null;}getState(){return this.state.peek()}isAtomic(){return true}static appendExchangeState(){return null}onMount(){}onUnmount(){}render(){let t=this.constructor.NAMESPACE.toLowerCase().replaceAll(".","-");return o("div",{className:t,contentEditable:false,style:"position: relative;",$ref:o=>{this.element=o;},"data-state":()=>JSON.stringify(this.state.get()),"data-componentid":this.state.peek().componentId},[o("div",{$ref:o=>{this.root=o;},style:"display: block;",contentEditable:false}),o("span",{style:"position: absolute; bottom: 0; right: 0; width: 10px; height: 100%; outline: none;",contentEditable:true,[d$1]:true},document.createTextNode("\xA0"))])}onKeydown(t){t.key!=="Backspace"&&t.key!=="ArrowUp"&&t.key!=="ArrowDown"&&t.preventDefault(),u(this,t);}};var z=class extends v{static get NAMESPACE(){return d$2}onMount(){let t=o("div",{style:"user-select: none;",contentEditable:false},()=>`Unknown component: ${this.state.get().component}`);r(this.root,t);}onUnmount(){this.root.innerHTML="";}};function qt(n,t){let e=n._getBlockElementByComponentId(t);return t$1(e)?.isStale?.()??false}function Ut(n){return (t,e)=>{if(!h(t,e))return false;let o=e?.componentId??t?.componentId;return !(o&&qt(n,o))}}function Kt({mrakomor:n}){let t=n.get(),e=Ut(t);return j$2(a$7,t),l$1(()=>{t._onMount();}),m$1(()=>{t._onUnmount();}),o("div",{id:t._id,className:"mrakomor-editor"},[o("div",{className:"mrakomor-editor-surface"},[o("div",{className:"mrakomor-tools-container"}),o("div",{className:"mrakomor-content",contentEditable:true,style:{spellcheck:true,outline:"none"}},[q(()=>t._getContentState(),o=>o.componentId,(o$1,r)=>o(()=>{let s;l$1(()=>{s.getNodeComponent=()=>{let l=s$1(s);return l?g(l):null},t._setBlockElement(s,r);}),m$1(()=>{t._removeBlockElement(s);});let i=t.resolveComponent(o$1.get().component,o$1),a=t.wrapBlockElement(i);return o("div",{className:"mrakomor-block-element",[b$2]:true,$ref:l=>{s=l;}},a)}),{equals:e})])])])}function Z(n,t,e){let o=n._getBlockElementIndex(t);if(o===-1)return false;let r=n.getContent();return r.splice(o,1,n.normalizeComponentState(e)),n._setContentState(r),true}function zt(n,{customHook:t,applyFn:e$1,applyArgs:o,resolveRange:r=true}){let{mrakomor:s}=n,{blockElement:i$1,range:a}=n;r&&(a=a??i(),i$1=i$1??e(a));let l=t$1(i$1),p=l?.[t]?.(n);if(n.defaultPrevented){p&&Z(s,i$1,p);return}let g=l?.getFormattingTarget?.(a);if(!g)return;let f=s._getBlockElementState(i$1);if(!f)return;let h=e$1(structuredClone(f),g,{...o,range:a});h&&Z(s,i$1,h);}function Vt(n$1){let{mrakomor:t}=n$1,{blockElement:e$1,range:o,newLineState:r,originalLineState:s,namespace:i,position:a,cursor:l}=n$1,p,g;if(a||(e$1?p=t._getBlockElementIndex(e$1):o&&(p=t._getBlockElementIndex(e(o))),p===void 0||p===-1))return;g=p+1;let f=t.getContent();s&&f.splice(p,1,t.normalizeComponentState(s)),r&&(r.component=i,f.splice(g,0,t.normalizeComponentState(r))),t._setContentState(f),n(()=>{typeof l=="number"&&t$1(t._getBlockElements()[g])?.setCursor?.(l);});}function Xt(n$1){let{mrakomor:t}=n$1,{blockElement:e$1,range:o,blocks:r,cursor:s,cursorBlockIndex:i=0}=n$1;if(!Array.isArray(r)||r.length===0)return;let a=e$1??(o?e(o):null),l=t._getBlockElementIndex(a);if(l===-1)return;let p=[...t._getContentState()];p.splice(l,1,...r.map(g=>t.normalizeComponentState(g))),t._setContentState(p),n(()=>{if(typeof s!="number")return;t._syncBlockElementsFromDom();let g=s$1(t._getBlockElements()[l+i]);g?.isConnected&&r$2(g,s);});}function Jt(n){let{mrakomor:t,blockElement:e,namespace:o}=n,r=t._getBlockElementState(e);if(!r)return;let s=t.register.blocks.getByNamespace(r.component),i=t.register.blocks.getByNamespace(o),a=n.exchangeState??s?.toExchangeState?.(r)??k({properties:r.properties,settings:r.settings}),l=i?.fromExchangeState?.(a)??a;Z(t,e,{...l,component:o,componentId:a$3()});}function Qt(n){let{mrakomor:t,blockElement:e,targetIndex:o}=n,r=t._getBlockElementIndex(e);if(r===-1||typeof o!="number")return;let s=o>r?o-1:o;if(s===r)return;let i=[...t._getContentState()],[a]=i.splice(r,1);i.splice(s,0,a),t._setContentState(i);}function Zt(n$1){let{mrakomor:t,blockElement:e$1,range:o}=n$1,r=t._getBlockElementIndex(e$1);if(r!==-1){let s=t.getContent();s.splice(r,1),t._setContentState(s);}n(()=>{let s=e(o);r$2(s$1(s),0);});}function te(n){let{mrakomor:t,state:e,blockElement:o}=n,r=t._getBlockElementState(o);if(!r)return;let s=structuredClone(r),i=e?.offset,a=e?.length,l=e?.entity?.type;s.properties.entityRanges=(s.properties.entityRanges??[]).filter(p=>!(p?.offset===i&&p?.length===a&&p?.entity?.type===l)),Z(t,o,s),t.command.closeDialog?.();}function ee(n){zt(n,{customHook:"insertEntityRange",applyFn:z$1,applyArgs:{state:n.state,namespace:n.namespace}});}function ne(n){zt(n,{customHook:"insertInlineStyleRange",applyFn:y,applyArgs:{style:n.style}});}function oe(n$1){let{mrakomor:t,blockElement:e,previousBlockElement:o}=n$1,r=t._getBlockElementIndex(o),s=t._getBlockElementIndex(e);if(r===-1||s===-1)return;let i=t.getContent(),a=i[s],l=i[r],p=t.register.blocks.getByNamespace(l.component),g=t.register.blocks.getByNamespace(a.component),f=n$1.exchangeState??g?.toExchangeState?.(a)??k({properties:a.properties,settings:a.settings}),h=p?.appendExchangeState?.(l,f);if(!h)return;i.splice(s,1),i.splice(r,1,t.normalizeComponentState(h.state)),t._setContentState(i);let C=()=>{if(typeof h.cursor!="number")return;let y=t._getBlockElements()[r]??o,B=s$1(y);B?.isConnected&&r$2(B,h.cursor);};C(),n(C);}function re(n){let{mrakomor:t}=n,e=t.getRoot();if(n.relatedTarget instanceof Node&&e.contains(n.relatedTarget))return;let[r,s]=a$5(()=>[t.getContent(),t._getContentState()]);r.length===s.length&&r.every((a,l)=>a===s[l])||t.setContent(r);}function se(n){let t=i();return e(t)?.getNodeComponent?.()?.classInstance?.onKeydown?.(n)}function ie(n){t$1(n)?.setCursor?.();}function ce(n$1){if(n$1.key!=="Backspace")return;let{mrakomor:t}=n$1,e$1=i();if(!e$1)return;let o=e(e$1);if(!o)return;let r=u$1(o),s=o?.previousSibling,a=u$1(s)?.childNodes?.[0]?.contentEditable==="true",l$1=r?.childNodes?.[0]?.contentEditable==="true",p=s$1(o),g=!j(p?.textContent),f=e$1.collapsed&&(e$1.startOffset===0||j$1()===0||g);if(!e$1.collapsed){let u=p$1(e$1);if(u&&u.startBlock!==u.endBlock){let E=t._getBlockElementIndex(u.startBlock),S=t._getBlockElementIndex(u.endBlock),b=t.getContent(),O=E>=0?b[E]:void 0,R=S>=0?b[S]:void 0;if(E>=0&&S>E&&typeof O?.properties?.text=="string"&&typeof R?.properties?.text=="string"){n$1.preventDefault();let{content:$t,cursor:pt,resultIndex:Yt}=r$1(b,{startIndex:E,endIndex:S,startOffset:u.startOffset,endOffset:u.endOffset});t._setContentState($t.map(Y=>t.normalizeComponentState(Y))),n(()=>{let Y=t._getBlockElements()[Yt];Y&&typeof pt=="number"&&r$2(s$1(Y),pt);});}}return}if(!f)return;let h=t._getBlockElementIndex(o),C=s?t._getBlockElementIndex(s):-1,y=t._getBlockElementState(o),B=t._getBlockElementState(s),A=s?t$1(s):null;if(!s||C<0){n$1.preventDefault();return}if(B&&y&&l(y)&&A&&!A.isAtomic?.()){if(g&&!l(B)){n$1.preventDefault();let u=t.getContent();u.splice(h,1),t._setContentState(u),ie(s);return}n$1.preventDefault(),t.command.mergeBlockElement({blockElement:o,previousBlockElement:s,range:e$1});return}A?.isAtomic?.()&&(!a&&e$1.startOffset===0||o?.textContent==="\xA0"&&!l$1)&&(n$1.preventDefault(),t.command.removeBlockElement({blockElement:s,range:e$1})),y&&!l(y)&&n$1.preventDefault();}function tt(n){return {resolveComponent:t=>t===v.NAMESPACE?v:z,registerCommands(t){t.emitter.on(a$1.INSERT_BLOCK_ELEMENT,b(Vt)),t.emitter.on(a$1.REPLACE_BLOCK_ELEMENT,b(Xt)),t.emitter.on(a$1.TRANSFORM_BLOCK_ELEMENT,b(Jt)),t.emitter.on(a$1.MOVE_BLOCK_ELEMENT,b(Qt)),t.emitter.on(a$1.REMOVE_BLOCK_ELEMENT,b(Zt)),t.emitter.on(a$1.REMOVE_ENTITY_RANGE,b(te)),t.emitter.on(a$1.INSERT_ENTITY_RANGE,b(ee)),t.emitter.on(a$1.INSERT_INLINE_STYLE_RANGE,b(ne)),t.emitter.on(a$1.MERGE_BLOCK_ELEMENT,b(oe));},registerHandlers(t){t.emitter.on(a$1.FOCUSOUT,re),t.emitter.on(a$1.KEYDOWN,b(se)),t.emitter.on(a$1.KEYDOWN,b(ce));},registerListeners(t){let e=t.getRoot(),{signal:o}=t.listenerAbortController;e.addEventListener("keydown",r=>t.emitDomEvent(a$1.KEYDOWN,r),{signal:o}),e.addEventListener("beforeinput",r=>t.emitDomEvent(a$1.BEFORE_INPUT,r),{signal:o}),e.addEventListener("input",r=>t.emitDomEvent(a$1.INPUT,r),{signal:o}),e.addEventListener("focusin",r=>t.emitDomEvent(a$1.FOCUSIN,r),{signal:o}),e.addEventListener("focusout",r=>t.emitDomEvent(a$1.FOCUSOUT,r),{signal:o}),e.addEventListener("click",r=>t.emitDomEvent(a$1.CLICK,r),{signal:o}),document.addEventListener("selectionchange",r=>t.emitDomEvent(a$1.SELECTION_CHANGE,r),{signal:o});}}}(function(){if(!(typeof document>"u")){var n="mrakomor/core/plugin/dialog/Dialog.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===n});if(!t){var e=document.createElement("style");e.setAttribute("data-mrakomor-css",""),e.setAttribute("data-mrakomor-css-path",n),e.textContent=`.mrakomor-dialog-container,.mrakomor-dialog-backdrop{pointer-events:all}.dialog[open]{background-color:#fff;border:1px solid black;border-radius:8px;box-shadow:0 0 5px #0000001a;padding:12px;display:flex;flex-flow:row wrap;justify-content:space-between}.dialog[open] .dialog-controls{text-align:right;width:100%}.dialog[open] .dialog-button-close{background-color:#f0f0f0;border:1px solid black;border-radius:4px;color:#000;cursor:pointer;display:inline-block;font-size:14px;margin-right:1px;padding:4px 8px;text-align:center}.dialog[open] .dialog-container{width:100%}
|
|
3
|
+
`,document.head.appendChild(e);}}})();var Gt="mrakomor.dialog.Dialog";function et({open:n,placement:t$1,positionX:e,positionY:o$1,block:r,dialogRef:s}){let i=b$1(()=>{let l=t$1.get()==="center";return {position:"absolute",zIndex:l?"9100":"9000",top:`${o$1.get()}px`,left:`${e.get()}px`,...l?{padding:0,background:"transparent",border:"none",boxShadow:"none",minWidth:0}:{background:"#fff",border:"1px solid #ccc",borderRadius:"4px",padding:"8px 10px",boxShadow:"0 2px 8px rgba(0,0,0,.15)",minWidth:"220px"}}}),a=b$1(()=>({position:"absolute",inset:"0",zIndex:"9050",background:"rgba(15, 23, 42, 0.28)",pointerEvents:"all"}));return o("span",{style:{display:"contents"}},[t(()=>n.get()&&t$1.get()==="center",o("div",{className:"mrakomor-dialog-backdrop",contentEditable:false,style:a})),t(()=>n.get(),o("div",{className:"mrakomor-dialog-container",contenteditable:false,style:i,$ref:s},()=>r.get()))])}et.NAMESPACE=Gt;function nt({mrakomor:n$1}){let t=null,e=d(false),o$1=d(false),r=d("anchor"),s=d(0),i=d(0),a=d(null),l=f(null),p=f(null);function g(){o$1.set(false),r.set("anchor"),m(),l.set(null),n(()=>{e.set(false);});}return {resolveComponent(f){if(f===Gt)return et},registerEvents(){a$1.OPEN_DIALOG="mrakomor:open-dialog",a$1.CLOSE_DIALOG="mrakomor:close-dialog";},registerCommands(f){f.command.openDialog=(h,C)=>{f.emit(a$1.OPEN_DIALOG,{...h,options:C});},f.command.closeDialog=()=>{f.emit(a$1.CLOSE_DIALOG);};},registerHandlers(){n$1.emitter.on(a$1.OPEN_DIALOG,({children:f,element:h,options:C={}})=>{a.set(f??o("div",{},"Empty dialog")),o$1.set(true),l.set(h??null),r.set(C.placement??"anchor"),n(()=>{let y=n$1.getRoot(),{x:B,y:A}=C.placement==="center"?w$1(y,p):v$1(y,h??{left:0,top:0},p);s.set(B),i.set(A),e.set(true);});}),n$1.emitter.on(a$1.CLOSE_DIALOG,g),n$1.emitter.on(a$1.KEYDOWN,f=>{f.key==="Escape"&&o$1.peek()===true&&n$1.command.closeDialog();}),n$1.emitter.on(a$1.CLICK,f=>{if(o$1.peek()!==true||e.peek()!==true)return;let h=f.target,C=p&&typeof p.contains=="function"&&p.contains(h),y=l&&typeof l.contains=="function"&&l.contains(h);!C&&!y&&n$1.command.closeDialog();});},onMount(){let{dispose:f}=a$2(n$1,"mrakomor-dialog-plugin-container",o(et,{open:o$1,placement:r,positionX:s,positionY:i,block:a,dialogRef:p}));t=f;},onUnmount(){t?.(),t=null;}}}var ot=class extends a$6{constructor(t){super(t,{sort:e=>e});}normalize(t){return c$2(t)}};(function(){if(!(typeof document>"u")){var n="mrakomor/core/plugin/menu/Menu.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(o){return o.getAttribute("data-mrakomor-css-path")===n});if(!t){var e=document.createElement("style");e.setAttribute("data-mrakomor-css",""),e.setAttribute("data-mrakomor-css-path",n),e.textContent=`.mrakomor-menu{position:absolute;z-index:9300;display:flex;flex-direction:column;gap:2px;min-width:160px;max-height:240px;overflow-y:auto;background:#1a1a1a;border-radius:6px;padding:4px;box-shadow:0 3px 10px #00000040;pointer-events:all}.mrakomor-menu__item{display:flex;align-items:center;width:100%;padding:6px 10px;border:none;border-radius:4px;background:transparent;color:#fff;cursor:pointer;font-size:13px;font-weight:600;text-align:left;transition:background .1s}.mrakomor-menu__item:hover,.mrakomor-menu__item--active{background:#ffffff26}
|
|
4
|
+
`,document.head.appendChild(e);}}})();function ae(n,t=-1){if(!n.length)return null;let e=n.map((o$1,r)=>o("button",{type:"button",role:"option",id:`mrakomor-menu-option-${o$1.id}`,className:["mrakomor-menu__item",r===t?"mrakomor-menu__item--active":""].filter(Boolean).join(" "),title:o$1.label,"data-id":o$1.id,"aria-selected":r===t?"true":"false",onMouseDown:s=>{s.preventDefault();}},o$1.label));return o("span",{style:"display: contents"},e)}function mt({open:n,positionX:t$1,positionY:e,entries:o$1,highlightIndex:r,ariaLabel:s,menuRef:i}){let a=b$1(()=>({left:`${t$1.get()}px`,top:`${e.get()}px`}));return t(()=>n.get(),o("div",{className:"mrakomor-menu",role:"listbox","aria-label":()=>s.get(),contenteditable:false,style:a,$ref:i},()=>ae(o$1.get(),r.get())))}function rt({mrakomor:n$1}){let t=null,e=null,o$1=f(null),r=null,s=d(false),i=d(false),a=d(0),l=d(0),p=d([]),g=d(-1),f$1=d("Menu");function h(u){n(()=>{let E=n$1.getRoot();if(!E||!u)return;let S=o$1?.offsetHeight??200,b=E.getBoundingClientRect();if(u.top-b.top>S+8){let{x:R,y:ut}=v$1(E,u,{offsetHeight:S},4);a.set(R),l.set(ut);}else a.set(u.left-b.left),l.set(u.bottom-b.top+4);s.set(true);});}function C(){i.set(false),r=null,g.set(-1),p.set([]),n(()=>{s.set(false);});}function y(u){!u||!r||r(u);}function B(u){if(i.peek()!==true)return;let E=u.target?.closest?.(".mrakomor-menu__item");if(!E||!e?.contains(E))return;u.preventDefault(),u.stopPropagation();let S=E.getAttribute("data-id"),b=p.peek().find(O=>O.id===S);b&&y(b);}function A(u={}){let{entries:E=[],anchorRect:S,highlightIndex:b=-1,ariaLabel:O="Menu",onSelect:R=null}=u;p.set(E),g.set(b),f$1.set(O),R!==void 0&&(r=R),i.set(true),S?h(S):s.set(true);}return {registerEvents(){a$1.OPEN_MENU="mrakomor:open-menu",a$1.CLOSE_MENU="mrakomor:close-menu",a$1.UPDATE_MENU="mrakomor:update-menu";},registerCommands(u){u.command.openMenu=E=>{u.emit(a$1.OPEN_MENU,E);},u.command.updateMenu=E=>{u.emit(a$1.UPDATE_MENU,E);},u.command.closeMenu=()=>{u.emit(a$1.CLOSE_MENU);};},registerHandlers(){n$1.emitter.on(a$1.OPEN_MENU,A),n$1.emitter.on(a$1.UPDATE_MENU,A),n$1.emitter.on(a$1.CLOSE_MENU,C),n$1.emitter.on(a$1.CLICK,u=>{let E=o$1?.current??o$1;i.peek()===true&&s.peek()===true&&E&&typeof E.contains=="function"&&!E.contains(u.target)&&C();}),n$1.emitter.on(a$1.KEYDOWN,u=>{u.key==="Escape"&&i.peek()===true&&C();});},onMount(){let{container:u,dispose:E}=a$2(n$1,"mrakomor-menu-plugin-container",o(mt,{open:i,positionX:a,positionY:l,entries:p,highlightIndex:g,ariaLabel:f$1,menuRef:o$1}));e=u,e?.addEventListener("click",B),t=E;},onUnmount(){e?.removeEventListener("click",B),t?.(),t=null,e=null,o$1.current=null,r=null;}}}function le(n){return n!=null&&typeof n=="object"&&(typeof Element>"u"?n.nodeType===1:n instanceof Element)}function Ht(){return a.object({root:a.any().refine(le,{message:"root must be a DOM Element"}),id:a.string().optional(),debug:a.boolean().optional(),content:a.array(a.any()).optional(),plugins:a.array(a.function()).optional(),blockComponents:a.array(a.any().refine(n=>typeof n=="function"||n!=null&&typeof n=="object"&&typeof n.component=="function",{message:"blockComponents entry must be a constructor or registration"})).optional(),slashActions:a.array(a.any().refine(n=>n!=null&&typeof n=="object"&&typeof n.handler=="function",{message:"slashActions entry must include a handler function"})).optional(),inlineStyles:a.array(a.function()).optional(),entityRanges:a.array(a.function()).optional(),tooltip:a.any().optional()})}function Ft(n){return [...n.filter(t=>t!==nt&&t!==rt&&t!==tt),nt,rt,tt]}function me(n){Ht().parse(n);let t={debug:false,content:[],plugins:[],blockComponents:[],slashActions:[],inlineStyles:[T,w,K,P,U],entityRanges:[],tooltip:{}},e={...t,...n,plugins:Ft(n.plugins??t.plugins)},o=new st(e);return o._init(),o}var st=class{#o=a$3();#n;#e=[];#t=[];#r;#s=false;listenerAbortController=new AbortController;#i=d([],{debug:"content"});#c=[];command;emitter;register;constructor(t){let{root:e,id:o,content:r}=t;this.#o=o||this.#o,this.#n=e,this.#c=r,this.#t=[],this.#r={...t,plugins:Ft(t.plugins??[])},this.register={blocks:new Q(this),help:new ot(this)};let{emitter:s,command:i}=c({mrakomor:this});this.command=i,this.emitter=s;}_init(){this.#m(),this.#i=d(this._normalizeContentState(this.#c),{debug:"content"});}#m(){this.#e=this.#r.plugins.map(t=>t?.({config:this.#r,root:this.#n,mrakomor:this}))??[],this.#r=this.#e.reduce((t,e)=>e?.resolveConfig?.(t)??t,this.#r),this.register.blocks.add(this.#r.blockComponents??[]),this.#e.forEach(t=>{t?.registerEvents?.(this);}),this.#e.forEach(t=>{t?.registerCommands?.(this);}),this.#e.forEach(t=>{this.emitter.on(a$1.KEYDOWN,e=>t?.onKeyDown?.(e));}),this.#e.forEach(t=>{t?.registerHandlers?.(this);}),this.#e.forEach(t=>{t?.registerListeners?.(this);});}emit(t,e={}){return this.emitter.emit(t,{...e,mrakomor:this})}on(t,e){return this.emitter.on(t,e)}onChangeContent(t){return this.on(a$1.CONTENT_CHANGE,t)}emitDomEvent(t,e){let{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:a,key:l,isComposing:p,repeat:g,button:f,shiftKey:h,which:C,detail:y,isTrusted:B,target:A,relatedTarget:u,data:E,inputType:S}=e??{},{defaultPrevented:b}=this.emit(t,{clipboardData:o,metaKey:r,altKey:s,code:i,ctrlKey:a,key:l,isComposing:p,repeat:g,button:f,shiftKey:h,which:C,detail:y,isTrusted:B,target:A,relatedTarget:u,data:E,inputType:S});return b&&e?.preventDefault?.(),b}getConfig(){return {...this.#r,blockComponents:this.register.blocks.list(),slashActions:this.register.slashActions?.list()??[]}}wrapBlockElement(t){for(let e of this.#e){let o=e.wrapBlockElement?.(t);if(o)return o}return t}getRoot(){return this.#n}get _id(){return this.#o}getContent(){return this.#t.map(e=>t$1(e)?.getState())}setContent(t=[]){this._setContentState(this._normalizeContentState(t));}_syncBlockElementsFromDom(){let t=this.#n?.querySelector?.(".mrakomor-content");t&&(this.#t=[...t.querySelectorAll(".mrakomor-block-element")]);}_getBlockElements(){return this.#t}_getContentState(){return this.#i.get()}_setContentState(t=[]){this.#i.set(t),this.emit(a$1.CONTENT_CHANGE,{content:t}),n(()=>{this._syncBlockElementsFromDom();});}_normalizeContentState(t=[]){return t.map(e=>structuredClone(this.normalizeComponentState(e)))??[]}_setBlockElement(t,e=this.#t.length){this.#t.splice(e,0,t);}_removeBlockElement(t){this.#t=this.#t.filter(e=>e!==t);}#a(t){return t$1(t)?.state?.peek()?.componentId}#l(t){return t?this.#t.findIndex(e=>this.#a(e)===t):-1}_getBlockElementIndex(t){if(!t)return -1;let e=this.#t.indexOf(t);return e!==-1?e:this.#l(this.#a(t))}_getBlockElementByComponentId(t){let e=this.#l(t);return e===-1?null:this.#t[e]}_getBlockElementState(t){let e=this._getBlockElementIndex(t);if(e!==-1)return t$1(this.#t[e])?.getState()}mount(){let t=r(this.#n,o(Kt,{mrakomor:this}));return this.#s=true,t}unmount(){this.#s&&(this.#s=false,s(this.#n));}_onUnmount(){this.listenerAbortController.abort(),this.#e.forEach(t=>{t?.onUnmount?.(this);}),this.emitter.removeAllListeners();}_onMount(){this.#e.forEach(t=>{t?.onMount?.(this);}),n(()=>{this._syncBlockElementsFromDom();});}resolveComponent(t,e){let o$1=this.resolveComponentConstructor(t);return o$1?o(o$1,{state:e}):o(z,{state:e})}resolveComponentConstructor(t){let e=this.register.blocks.getByNamespace(t);if(!e){for(let o of this.#e)if(e=o?.resolveComponent?.(t),e)break}return e}normalizeComponentState(t){let e="component"in t?t.component:t.entity.type;return this.resolveComponentConstructor(e)?.getStateSchema()?.parse(t)}};export{T as Bold,et as Dialog,w as Italic,mt as Menu,st as Mrakomor,P as Subscript,U as Superscript,K as Underline,me as createMrakomor,tt as defaultMrakomorPlugin,nt as dialogPlugin,rt as menuPlugin};
|
package/dist/link.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
'use strict';var Le=class{next(...e){}error(...e){}complete(...e){}},ue=class{#e=new Set;pipe(...e){return e.reduce((t,n)=>n(t),this)}next(...e){Array.from(this.#e).forEach(t=>{typeof t=="function"?t(...e):t.next(...e);});}error(...e){Array.from(this.#e).forEach(t=>{t?.error?.(...e),this.unsubscribe(t);});}complete(...e){Array.from(this.#e).forEach(t=>{t?.complete?.(...e),this.unsubscribe(t);});}subscribe(e){return this.#e.add(e),{unsubscribe:()=>{this.unsubscribe(e);}}}unsubscribe(e){this.#e.delete(e);}};var G=Symbol("@esmj/signals:type"),K=Symbol("@esmj/signals:name");var k=null,ce=false,fe=[];function D(e){let t=k;k=null;let n=e();return k=t,n}function Bt(){ce=false;let e=He();for(let n of e)n.get();let t=fe;fe=[];for(let n of t)n();}function Pe(){ce||(ce=true,queueMicrotask(Bt));}function de(e){fe.push(e),Pe();}var qe=Symbol("@esmj/signals:internal observable"),_=Symbol("@esmj/signals:original function"),Lt=class extends ue{#e=new Set;#r=null;constructor(e){super(),this.#r=e,this.pipe(t=>{let n=t.subscribe.bind(t),r=t.unsubscribe.bind(t);return t.subscribe=o=>{n(o),this.#e.add(o);},t.unsubscribe=o=>{r(o),this.#e.delete(o);},t});}watch(e){if(typeof e.next!="function"&&(e.next=()=>D(()=>{this.#e.add(e),this.#r();}),e.next[_]=void 0),e instanceof ze&&e.next[_]===void 0){let t=e.next.bind(e);e.next=()=>D(()=>{this.#e.add(e),t(),this.#r();}),e.next[_]=t;}return this.subscribe(e)}getPending(){let e=[];for(let t of this.#e){if(!t.get[_]){let n=t.get,r=n.bind(t);t.get=()=>D(()=>(this.#e.delete(t),r())),t.get[_]=n;}e.push(t);}return e}unwatch(e){return e.next=e.next[_]?e.next[_]:e.next,e.get=e.get[_]?e.get[_]:e.get,this.#e.delete(e),this.unsubscribe(e)}},X=null;function Fe(e){X=new Lt(e);}Fe(()=>{Pe();});function He(){return X.getPending()}function Ke(e){return X.watch(e)}function Ve(e){return X.unwatch(e)}var R=Symbol("@esmj/signals:no error"),ze=class Ue extends Le{#e=true;#r=false;#n=null;#o=this.#d();#u=null;#l=null;#i=0;#s=new Map;#t=R;constructor(t,n){super(),this.#u=t,this.#l=n,this.debug=n?.debug,this[G]="computed",this[K]=n?.debug??null,this.get=this.get.bind(this);}#c(){for(let{unsubscribe:t}of this.#o.dependencies.values())t();this.#o.dependencies.clear();}#d(){return {dependencies:new Map,sourceRevisions:new Map,observer:this}}getRevision(){return this.#i}getDebugInfo(){return {name:this[K],dirty:this.#e,revision:this.#i,sourceDependencies:[...this.#s.keys()]}}#f(){for(let[t,n]of this.#s)if(t instanceof Ue&&D(()=>t.get()),t.getRevision()!==n)return true;return false}next(){this.#e=true,this.#n[qe].next();}get(){if(this.#r)throw new Error("Cycle detected in computed signal");if(this.#n||(this.#n=T(this.#a(),this.#l)),(this.#e||this.#t!==R)&&(this.#s.size===0||this.#f()?this.#a():this.#e=false),k&&k.sourceRevisions.set(this,this.#i),this.#t!==R)throw this.#t;return this.#n.get()}peek(){if(this.#n||(this.#n=T(this.#a(),this.#l)),(this.#e||this.#t!==R)&&(this.#s.size===0||this.#f()?this.#a():this.#e=false),this.#t!==R)throw this.#t;return this.#n.peek()}#a(){this.#r=true,this.#e=false,this.#t=R,this.#c(),this.#o.sourceRevisions.clear();let t=k;k=this.#o;let n;try{n=this.#u();}catch(r){this.#t=r;}return k=t,this.#s=this.#o.sourceRevisions,this.#o.sourceRevisions=new Map,this.#r=false,n instanceof Promise&&(n=n.then(r=>{this.#t=R,this.#n.set(r);}).catch(r=>{this.#t=r;})),this.#t===R&&this.#n&&this.#n.set(n),this.#i++,n}destroy(){this.#c(),this.#s.clear(),this.#e=true,this.#t=R;}};function O(e,t){return new ze(e,t)}function v(e,t){let n,{debug:r,...o}={},i=O(()=>{n?.(),n=e();},{equals:()=>false,...o});i.get(),Ke(i);let s=()=>{n?.(),i.destroy(),Ve(i);};return s[Symbol.dispose]=s,s[G]="effect",s[K]=r??null,s.__RX_COMPUTED__=i,s}function T(e,t={}){let n=t?.equals??Object.is,r=0,o=new ue;function i(){return k&&(k.dependencies.set(o,o.subscribe(k.observer)),k.sourceRevisions.set(c,r)),e}function s(){return e}function a(u){if(!n(e,u)){e=u,r++,o.next();}return e}function l(){return r}let c={get:i,set:a,peek:s,getRevision:l,[qe]:o,[G]:"signal",[K]:t?.debug??null};return c}function Y(){return Date.now().toString(32).substring(5)+Math.random().toString(32).substring(2)}var tt=Symbol("node-component"),Q=Symbol("node-internal"),Pt=Symbol("keep-literal"),ne=Symbol("raw-props");function U(e){let t=null,n=()=>t,r=i=>(t=i??null,typeof e=="function"&&e(t),t),o={get:n,set:r,[Symbol.toPrimitive](){return t?String(t):""}};return Object.defineProperty(o,"current",{get(){return t},set(i){r(i);},enumerable:true,configurable:false}),new Proxy(o,{get(i,s,a){if(Reflect.has(i,s))return Reflect.get(i,s,a);if(!t)return;let l=t[s];return typeof l=="function"?l.bind(t):l},set(i,s,a,l){return Reflect.has(i,s)||!t?Reflect.set(i,s,a,l):(t[s]=a,true)},has(i,s){return Reflect.has(i,s)||!!t&&s in t}})}var nt=null;function I(){return nt}function Z(e){nt=e;}function ke(e){return e?.[tt]||null}function Je(e,t){e[tt]=t;}function ee(e,t={disposers:[],id:Y()}){return e?.[Q]?e[Q]:(e&&(e[Q]=t),t)}function Ht(e){return e[Q]}function $(e,t){let n=Ht(e);n||(n=ee(e)),n.disposers.push(t);}function he(e,t,n){e.has(t)||e.set(t,[]),e.get(t).push(n);}function A(e,t){let n=I();Z(e);try{return t()}finally{Z(n);}}var ge=new Map,te=new Map,We=new Map;function rt(e,t){let n=typeof t=="function"?t:o=>!!t?.includes(o),r=Object.create(null);for(let o of Object.keys(e)){let i=e[o];o==="children"||n(o)?r[o]=i:i?.[Pt]?r[o]=i():i!=null&&typeof i.get=="function"?r[o]=i:typeof i=="function"?r[o]=O(i):r[o]=T(i);}return r}function we(e){return {id:Symbol("context-id"),defaultValue:e}}function Se(e){let t=I();return t?.contexts?.has(e.id)?t.contexts.get(e.id):e.defaultValue}function oe(e){de(()=>{setTimeout(e,0);});}function J(e){let t=e.componentId,n=ge.get(t);if(n){ge.delete(t);for(let r of n){let o=r();typeof o=="function"&&he(te,t,o);}}}function Kt(e){let t=te.get(e);if(t){te.delete(e);for(let n of t)n();}}function Vt(e){let t=We.get(e);if(t){We.delete(e);for(let n of t)n();}}function Ce(e){if(!e)return;let t=ee(e);if(t?.disposers?.length){for(let r of t.disposers)try{r();}catch(o){console.error("[esmj-dom] cleanupTree: disposer threw, cleanup continues",o);}t.disposers=[];}let n=ke(e);if(n&&(Kt(n.componentId),Vt(n.componentId)),e.childNodes){let r=e.firstChild;for(;r;){let o=r.nextSibling;Ce(r),r=o;}}}function P(e){return e!=null&&typeof e=="object"&&typeof e.$constructor=="function"}function Ge(e){return typeof e=="function"&&typeof e.prototype?.render=="function"}function zt(e,t,n){let r=Y(),o={componentId:r,$children:n,element:null,classInstance:null,$constructor(){let i=Ge(e)?void 0:e[ne],s={...rt(t??{},i),children:n},a=I(),l={disposers:[],id:r,contexts:new Map(a?.contexts)};Z(l);let c;if(Ge(e)){o.ClassConstructor=e;let f=new e(s);o.classInstance=f,typeof f.onMount=="function"&&he(ge,r,()=>{f.onMount?.();}),typeof f.onUnmount=="function"&&he(te,r,()=>{f.onUnmount?.();}),c=f.render();}else c=e(s);Z(a);let u=Ut(c);if(o.element=u,u instanceof DocumentFragment&&u.childNodes.length)for(let f of u.childNodes)ee(f,l),Je(f,o);else ee(u,l),u instanceof Node&&Je(u,o);return u}};return o}function ot(e,t){let n=t.$constructor();n instanceof Node&&e.appendChild(n),queueMicrotask(()=>{J(t);});}function Ut(e){return e instanceof Node?e:P(e)?e.$constructor():typeof e=="string"||typeof e=="number"?document.createTextNode(String(e)):document.createTextNode("")}var Xe={className:"class",htmlFor:"for"},Ye=new Set(["value","defaultValue","checked","selected","indeterminate"]),Jt=new Set(["srcdoc"]),Wt=new Set(["href","src","action","formaction","xlink:href"]),Gt=new Set(["securitypolicyviolation"]),Xt=new Set(["contenteditable","draggable","spellcheck"]);function z(e){return e!=null&&typeof e=="object"&&typeof e.get=="function"&&!(e instanceof Node)}var st=Symbol("Fragment");function m(e,t,n){if(e===st){let o=document.createDocumentFragment();return me(o,Ze(n)),o}if(typeof e=="function")return zt(e,t||{},n);typeof e!="string"&&(n=t,t=e,e="div"),t=t||{};let r=document.createElement(e);return t.id&&r.setAttribute("id",t.id),se(r,t),me(r,Ze(n)),r}function pe(e,t){t instanceof DocumentFragment?e.replaceChildren(t):e.innerHTML=t??"";}function Yt(e){return typeof e!="string"?false:e.replace(/[\p{White_Space}\p{Cc}]+/gu,"").toLowerCase().startsWith("javascript:")}function Qt(e,t){if(typeof e!="string")return false;let n=e.toLowerCase();return Jt.has(n)?true:Wt.has(n)&&t!==null&&t!==void 0&&Yt(String(t))}function it(e){return typeof e!="string"?e:Xe[e]?Xe[e]:e}function Zt(e,t){let n=it(e),r=typeof n=="string"?n.toLowerCase():String(n).toLowerCase();return Xt.has(r)&&(t===true||t===false||t==="true"||t==="false")?String(t):t==null||t===false?null:t}function Qe(e,t,n){let r=Zt(t,n);if(r===null){e.removeAttribute(t);return}if(Qt(t,r)){e.removeAttribute(t),console.warn(`[esmj-dom] Blocked unsafe attribute "${String(t)}" on <${e.tagName.toLowerCase()}>`);return}e.setAttribute(t,r);}function se(e,t){let n=I();for(let[r,o]of Reflect.ownKeys(t).map(i=>[i,t[i]]))if(r!=="id"){if(r=it(r),r==="$ref"){typeof o=="function"?o(e):typeof o=="object"&&o!==null&&(o.current=e);continue}if(r==="$dangerouslySetInnerHTML"){if(z(o)){let i=v(()=>{A(n,()=>{pe(e,o.get());});});$(e,i);}else if(typeof o=="function"){let i=v(()=>{A(n,()=>{pe(e,o());});});$(e,i);}else pe(e,o);continue}if(r==="style"){if(z(o)){let i=v(()=>{A(n,()=>{Object.assign(e.style,o.get());});});$(e,i);}else typeof o=="object"&&o!==null?Object.assign(e.style,o):e.setAttribute("style",o);continue}if(typeof r=="string"&&r.startsWith("on")&&typeof o=="function"){let i=r.slice(2).toLowerCase();if(Gt.has(i)){console.warn(`[esmj-dom] Blocked unsafe event binding "${r}" on <${e.tagName.toLowerCase()}>`);continue}e.addEventListener(i,o);continue}if(z(o)||typeof o=="function"){let i=r,s=v(()=>{A(n,()=>{let a=typeof o=="function"?o():o.get();Ye.has(i)?e[i]=a??"":Qe(e,i,a);});});$(e,s);continue}Ye.has(r)||typeof r=="symbol"?e[r]=o??"":Qe(e,r,o);}}function Ze(e){return e==null?[]:Array.isArray(e)?e.flat(Number.POSITIVE_INFINITY):[e]}function me(e,t){for(let n of t)at(e,n);}function at(e,t){if(!(t==null||t===false||t===true)){if(t instanceof Node){e.appendChild(t);return}if(typeof t=="string"||typeof t=="number"){e.appendChild(document.createTextNode(String(t)));return}if(typeof t=="function"){et(e,t);return}if(P(t)){ot(e,t);return}if(z(t)){et(e,()=>t.get());return}if(Array.isArray(t)){me(e,t);return}e.appendChild(document.createTextNode(String(t)));}}function q(e){let t=null,n=e;return P(e)&&(t=e,n=e.$constructor()),n instanceof DocumentFragment?{nodes:Array.from(n.childNodes),instance:t}:n instanceof Node?{nodes:[n],instance:t}:n==null||n===false||n===true?{nodes:[],instance:t}:{nodes:[document.createTextNode(String(n))],instance:t}}function ie(e,t=true){for(let n of e)t&&Ce(n),n.remove();}function et(e,t){let n=I(),r=document.createComment("");e.appendChild(r);let o=[],i=v(()=>{A(n,()=>{let s=t(),{nodes:a,instance:l}=q(s);ie(o),a.length&&r.after(...a),l&&queueMicrotask(()=>J(l)),o=a;});});$(e,i);}var ct=class{constructor(e){this.props=e;}};var nn={abortEarly:true};function Re(e,t){if(t===void 0)return e;let n=e?.cause?.key?`${t}.${e.cause.key}`:`${t}`;return {message:`Error parsing key "${n}": ${e.message}`,cause:{key:n}}}function rn(e,t,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)t.push(Re(e.errors[r],n));}function pt(e,t,n,r){if(n!==false){let o=Re(e.error,t);return {success:false,error:o,errors:[o]}}rn(e,r,t);}function ae(e){return e?.abortEarly!==void 0?e:nn}function ve(e,t){y(e,"_parse",(n,r,o)=>{let i=n(r,o);return !i.success&&t(r)?{success:true,data:r}:i});}var W=e=>typeof e=="string"||e instanceof String,Ne=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),Ee=e=>e===true||e===false,on=e=>e instanceof Date&&!Number.isNaN(e.getTime()),sn=e=>typeof e=="function",an=e=>Array.isArray(e),_e=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function ht(e,t){let n=w(_e,{...t,type:"object"});n._getDescription=()=>`object({ ${Object.entries(e).map(([o,i])=>`${o}: ${i._getDescription()}`).join(", ")} })`,n._getDefinition=()=>e;let r=n;return r.derive=function(o,{when:i="always"}={}){return y(this,"_parse",(s,a,l)=>{let c=s(a,l);if(!c.success)return c;let u=o(c.data,{context:l?.context});if(!_e(u)){let f={message:`derive() callback must return a plain object of overrides, got ${u===null?"null":typeof u}`};return {success:false,error:f,errors:[f]}}if(i==="missing"){let f={...c.data};for(let d in u)f[d]===void 0&&(f[d]=u[d]);return {success:true,data:f}}return {success:true,data:{...c.data,...u}}}),this},y(n,"_parse",(o,i,s)=>{let a=o(i,s),{abortEarly:l}=ae(s);if(a.success===false)return a;let c={},u=[];for(let f in e){let d=e[f]._parse(a.data[f],s);if(d.success)c[f]=d.data;else {let p=pt(d,f,l,u);if(p)return p}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:c}}),r}function je(e){return w(W,{...e,type:"string"})}function $e(e){return w(Ne,{...e,type:"number"})}function Ae(e){return w(Ee,{...e,type:"boolean"})}function Me(e){return w(on,{...e,type:"date"})}function gt(e){return w(sn,{...e,type:"function"})}function mt(e,t){let n=s=>e.includes(s),r=s=>`Invalid ${o} value. Expected ${e.map(a=>`"${a}"`).join(" | ")}, received "${s}".`,o="enum",i=w(n,{message:r,...t,type:o});return i._getDescription=()=>`enum(${e.map(s=>`"${s}"`).join(" | ")})`,i._getDefinition=()=>e,i}function yt(e,t){let n=w(an,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,n._getDefinition=()=>e,y(n,"_parse",(r,o,i)=>{let s=r(o,i),{abortEarly:a}=ae(i);if(s.success===false)return s;let l=[],c=[],u=i;for(let f=0;f<s.data.length;f++){let d={...u,context:{...u?.context,index:f}},p=e._parse(s.data[f],d);if(p.success)l.push(p.data);else {let b=pt(p,f,a,c);if(b)return b}}return c.length>0?{success:false,error:c[0],errors:c}:{success:true,data:l}}),n}function bt(){return w(()=>true)}function F(e,t){return y(t,"_parse",(n,r,o)=>(r=e(r),n(r,o))),t}function xt(e,t){let n=o=>`Invalid union value. Expected the value to match one of the schemas:${e.map((i,s)=>` ${s+1}. ${i._getDescription()}`).join(",")} but received "${typeof o}" with value: ${_e(o)?JSON.stringify(o):`"${o}"`}`,r=w(()=>false,{message:n,...t,type:"union"});return r._getDefinition=()=>e,y(r,"_parse",(o,i,s)=>{let a=s,l=[];for(let d=0;d<e.length;d++){let p=e[d]._parse(i,a);if(p.success)return p;l.push(p);}let{abortEarly:c}=ae(a),u={message:typeof n=="function"?n(i):n};if(c!==false)return {success:false,error:u,errors:[u]};let f=[];for(let d=0;d<l.length;d++){let p=l[d].errors;if(p?.length)for(let b=0;b<p.length;b++)p[b].cause?.key&&f.push(Re(p[b],`branch ${d}`));}return f.length===0&&f.push(u),{success:false,error:f[0],errors:f}}),r}function kt(e,t){let n=w(r=>r===e,{message:r=>t?.message?typeof t.message=="function"?t.message(r):t.message:`Expected literal value "${e}", received "${r}"`,name:t?.name,type:"literal"});return n._getDescription=()=>`literal("${e}")`,n._getDefinition=()=>e,n}function wt(e){let t=w(()=>true,{type:"contextRef"});return t._getDescription=()=>`contextRef("${e}")`,y(t,"_parse",(n,r,o)=>({success:true,data:o?.context?.[e]})),t}function St(e,t){return {parse(n,r){let o=e.parse(r?.context??{},r);return t(o).parse(n,r)},safeParse(n,r){let o=e.safeParse(r?.context??{},r);return o.success?t(o.data).safeParse(n,r):o}}}var Ct={boolean(e){let t=e?.message??(n=>`Cannot cast "${n}" to boolean. Accepted: true/false, 1/0, yes/no, on/off.`);return F(n=>{let r;return W(n)&&(r=n.toLowerCase()),r==="true"||r==="yes"||r==="on"||r==="1"||n===1?true:r==="false"||r==="no"||r==="off"||r==="0"||n===0?false:n},Ae({...e,message:t}))},number(e){let t=e?.message??(n=>`Cannot cast "${n}" to a number. Expected a numeric string or number.`);return F(n=>{if(Ee(n))return Number(n);if(W(n)){let r=n.trim();if(r==="")return n;let o=Number(r);if(Number.isFinite(o))return o}return n},$e({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return F(n=>Ee(n)||Ne(n)&&Number.isFinite(n)?String(n):n,je({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return F(n=>{let r;return W(n)&&(r=n.trim()),Ne(n)&&Number.isFinite(n)||r?new Date(r??n):n},Me({...e,message:t}))},json(e,t){let n=t?.message??(r=>`Cannot parse "${r}" as JSON.`);return y(e,"_parse",(r,o,i)=>{if(W(o))try{o=JSON.parse(o);}catch{let s={message:typeof n=="function"?n(o):n};return {success:false,error:s,errors:[s]}}return r(o,i)}),e}},vt={},g={object:ht,string:je,number:$e,boolean:Ae,date:Me,function:gt,enum:mt,array:yt,any:bt,preprocess:F,union:xt,literal:kt,contextRef:wt,withContext:St,coerce:vt,cast:Ct};function ft(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function y(e,t,n){let r=e[t];e[t]=(...o)=>n(r,...o);}function w(e,{type:t="any",name:n,message:r}={}){r=r||ft(t);let o={name:n,message:r,type:t},i={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(s,a){let l=e(s);if(l===true)return {success:true,data:s};if(typeof l=="object"&&l?.success===true)return l;let c={message:typeof r=="function"?r(s):r};return {success:false,error:c,errors:[c]}},parse(s,a){let l=this._parse(s,a);if(!l.success)throw l=l,new Error(l.error.message,{cause:l.error.cause});return l.data},safeParse(s,a){return this._parse(s,a)},transform(s){return y(this,"_parse",(a,l,c)=>{let u=a(l,c);return u.success&&(u.data=s(u.data)),u}),this},optional(){return ve(this,s=>s===void 0),this},nullable(){return ve(this,s=>s===null),this},nullish(){return ve(this,s=>s==null),this},default(s){return y(this,"_parse",(a,l,c)=>(l===void 0&&(l=typeof s=="function"?s({context:c?.context}):s),a(l,c))),this},catch(s){return y(this,"_parse",(a,l,c)=>{let u=a(l,c);return u.success?u:{success:true,data:typeof s=="function"?s({input:l,error:u.error}):s}}),this},pipe(s){return y(this,"_parse",(a,l,c)=>{let u=a(l,c);return u.success?s._parse(u.data,c):u}),this},refine(s,{message:a,type:l,jsonSchema:c}={}){if(l&&(a=a||ft(l),t=l),c){let u=[...this._getJsonSchemaHints?.()??[],c];this._getJsonSchemaHints=()=>u;}return y(this,"_parse",(u,f,d)=>{let p=u(f,d),{abortEarly:b}=ae(d);if(!p.success)return p;let N=s(p.data);if(N===true||typeof N=="object"&&N?.success===true)return p;let C={message:typeof a=="function"?a(f):a};return {success:false,error:C,errors:[C]}}),this},clone(){return {...this}}};return dt.length>0?dt.reduce((s,a)=>a(s,e,o)??s,i):i}var dt=[];Array.from({length:256},(e,t)=>(t<=15?"0":"")+t.toString(16));var Et=Symbol("block-element"),ln=Symbol("block-element-body"),un=Symbol("selectable-element");function Te(e,t){let n=e;for(n?.nodeType===Node.TEXT_NODE&&(n=n.parentElement);n&&n[t]===void 0;)n=n.parentElement;return n??null}function cn(e){return e?Te(e.startContainer,Et):null}function _t(e){return Te(e,Et)}function fn(e){return e?Te(e.startContainer,un):null}function dn(){return window.getSelection()}function pn(){let e=dn();return e.rangeCount>0?e.getRangeAt(0).cloneRange():null}function Rt(){mn();}function gn(e,t){let n=fn(t);return n||(yn(e)??e?.childNodes?.[0]??null)}function Nt(e,t,n){if(!e)return 0;if(t===e){if(t.nodeType===Node.TEXT_NODE)return n;let s=0,a=e.childNodes,l=Math.min(n,a.length);for(let c=0;c<l;c++)s+=a[c].textContent.length;return s}if(t.nodeType===Node.ELEMENT_NODE&&!e.contains(t))return 0;let r=0,o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),i=o.nextNode();for(;i;){if(i===t)return r+n;r+=i.textContent.length,i=o.nextNode();}return r}function mn(){let e=pn();if(!e)return null;let t=cn(e),n=gn(t,e);return {start:Nt(n,e.startContainer,e.startOffset),end:Nt(n,e.endContainer,e.endOffset),element:t,selectableElement:n}}function yn(e){if(!e)return null;let t=bn(e);return t?.firstElementChild??t?.firstChild}function bn(e){if(!e)return null;for(let t of e.children)if(t[ln])return t;return null}function jt({type:e,data:t=g.any(),length:n,offset:r}={}){let o=e!=null,i=g.object({type:o?g.string().default(e):g.string(),data:t}),s=n??(o?0:void 0),a=r??(o?0:void 0);return g.object({entity:o?i.default({}):i,length:s==null?g.number():g.number().default(s),offset:a==null?g.number():g.number().default(a)})}var $t=we();var le=class extends ct{static get nodeName(){return "span"}static get NAMESPACE(){return "namespace.EntityRangeElement"}static match(t){return t?.nodeName===this.nodeName.toUpperCase()||t?.entity?.type===this.NAMESPACE}static getStateSchema(t){return g.any()}constructor(t){super(t),this.mrakomor=Se($t),this.element=U(null);}render(){return m(this.constructor.nodeName,{},this.props.children)}};(function(){if(!(typeof document>"u")){var e="mrakomor/core/plugin/linkEntity/LinkEntity.css",t=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(r){return r.getAttribute("data-mrakomor-css-path")===e});if(!t){var n=document.createElement("style");n.setAttribute("data-mrakomor-css",""),n.setAttribute("data-mrakomor-css-path",e),n.textContent=`.link-toolbar{display:flex;flex-direction:column;gap:6px}.link-toolbar__row{display:flex;align-items:center;gap:4px;min-width:0}.link-toolbar__sep{width:1px;height:18px;background:#e0e0e0;flex-shrink:0;margin:0 2px}.link-toolbar__btn{display:flex;align-items:center;justify-content:center;flex-shrink:0;background:none;border:none;cursor:pointer;padding:4px;border-radius:4px;color:#555}.link-toolbar__btn:hover{background:#f0f0f0;color:#222}.link-toolbar__btn--danger:hover{color:#d32f2f;background:#fdecea}
|
|
2
|
+
`,document.head.appendChild(n);}}})();var xn=g.preprocess(e=>String(e??"").trim(),g.string().refine(e=>e===""||/^(?:https?:|mailto:)/i.test(e)||!/^[a-z][a-z0-9+.-]*:/i.test(e),{message:"Invalid link href"}).catch(""));function At(e){return xn.parse(e)}var kn='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';var wn='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>';var B=class e extends le{static get nodeName(){return "a"}static get NAMESPACE(){return "atom.link.Link"}static getStateSchema(t){let n;if(t?.getAttribute("data-state"))try{n=JSON.parse(t.getAttribute("data-state"));}catch{}return jt({type:e.NAMESPACE,data:g.object({href:g.string().default(n?.entity?.data?.href??t?.href??"").transform(r=>At(r)),target:g.string().default(n?.entity?.data?.target??t?.target??"")}).default({}),length:n?.length??0,offset:n?.offset??0}).default({})}constructor(t){super(t),this.input=U(n=>oe(()=>{n.focus();}));}#e({entity:t,length:n,offset:r}){return m("div",{className:"link-toolbar"},[m("div",{className:"link-toolbar__row",style:{display:"flex"}},[m("button",{className:"link-toolbar__btn",title:"Copy URL",$dangerouslySetInnerHTML:kn,onClick:()=>navigator.clipboard?.writeText(t.peek()?.data?.href??"")}),m("input",{type:"text",$ref:this.input,value:t.peek()?.data?.href??"",defaultValue:t.peek()?.data?.href??"",onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),o.stopPropagation(),this.mrakomor.command.closeDialog());},onInput:o=>{let i=o.currentTarget.value;t.set({...t.peek(),data:{...t.peek()?.data,href:i}});}}),m("select",{value:t.peek()?.data?.target??"",onChange:o=>{t.set({...t.peek(),data:{...t.peek()?.data,target:o.currentTarget.value}});}},[m("option",{value:"",selected:t.peek()?.data?.target===""},""),m("option",{value:"_self",selected:t.peek()?.data?.target==="_self"},"_self"),m("option",{value:"_blank",selected:t.peek()?.data?.target==="_blank"},"_blank"),m("option",{value:"_parent",selected:t.peek()?.data?.target==="_parent"},"_parent"),m("option",{value:"_top",selected:t.peek()?.data?.target==="_top"},"_top")]),m("span",{className:"link-toolbar__sep"}),m("button",{className:"link-toolbar__btn link-toolbar__btn--danger",title:"Remove link",$dangerouslySetInnerHTML:wn,onClick:()=>{this.mrakomor.command.removeEntityRange?.({state:{entity:t.peek(),length:n.peek(),offset:r.peek()},blockElement:_t(this.element)});}})])])}onMount(){let{entity:t}=this.props;t.peek()?.data?.href||this.mrakomor.command.openDialog({element:this.element,children:this.#e(this.props)});}render(){let{entity:t,length:n,offset:r,children:o}=this.props;return m("a",{href:()=>At(t.get()?.data?.href),target:()=>t.get()?.data?.target||null,rel:()=>t.get()?.data?.target==="_blank"?"noopener noreferrer":null,$ref:this.element,onClick:i=>{i.ctrlKey||i.metaKey||oe(()=>{Rt(),this.mrakomor.command.openDialog({element:this.element,children:this.#e({entity:t,length:n,offset:r})});});},"data-state":()=>JSON.stringify({entity:t.get(),length:n.get(),offset:r.get()})},o)}};function Sn({mrakomor:e}){return {resolveConfig:t=>(t.entityRanges.push(B),t),resolveComponent:t=>{if(t===B.NAMESPACE)return B},registerHandlers(){e.register.help.add({id:"link.insert",group:"formatting",description:"Insert or edit a link on the selection",commands:[],shortcuts:["Mod+K"]});},onKeyDown(t){t.key==="k"&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e.command.insertEntityRange({namespace:B.NAMESPACE}));}}}
|
|
3
|
+
exports.LinkEntity=B;exports.linkEntityPlugin=Sn;
|
package/dist/link.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-
|
|
2
|
-
`,document.head.appendChild(t);}}})();var k=a.preprocess(r=>String(r??"").trim(),a.string().refine(r=>r===""||/^(?:https?:|mailto:)/i.test(r)||!/^[a-z][a-z0-9+.-]*:/i.test(r),{message:"Invalid link href"}).catch(""));function u(r){return k.parse(r)}var f='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';var b='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>';var i=class r extends a$1{static get nodeName(){return "a"}static get NAMESPACE(){return "atom.link.Link"}static getStateSchema(e){let t;if(e?.getAttribute("data-state"))try{t=JSON.parse(e.getAttribute("data-state"));}catch{}return b$1({type:r.NAMESPACE,data:a.object({href:a.string().default(t?.entity?.data?.href??e?.href??"").transform(a=>u(a)),target:a.string().default(t?.entity?.data?.target??e?.target??"")}).default({}),length:t?.length??0,offset:t?.offset??0}).default({})}constructor(e
|
|
1
|
+
import {a as a$1}from'./chunk-N4I2WZWF.mjs';import {b as b$1}from'./chunk-GDID5DFL.mjs';import'./chunk-T7OO472O.mjs';import {a}from'./chunk-P7IKAZYZ.mjs';import {f as f$2,k as k$1}from'./chunk-YHWQV2DB.mjs';import {f as f$1,n,o}from'./chunk-K2DMHAUD.mjs';(function(){if(!(typeof document>"u")){var r="mrakomor/core/plugin/linkEntity/LinkEntity.css",e=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(a){return a.getAttribute("data-mrakomor-css-path")===r});if(!e){var t=document.createElement("style");t.setAttribute("data-mrakomor-css",""),t.setAttribute("data-mrakomor-css-path",r),t.textContent=`.link-toolbar{display:flex;flex-direction:column;gap:6px}.link-toolbar__row{display:flex;align-items:center;gap:4px;min-width:0}.link-toolbar__sep{width:1px;height:18px;background:#e0e0e0;flex-shrink:0;margin:0 2px}.link-toolbar__btn{display:flex;align-items:center;justify-content:center;flex-shrink:0;background:none;border:none;cursor:pointer;padding:4px;border-radius:4px;color:#555}.link-toolbar__btn:hover{background:#f0f0f0;color:#222}.link-toolbar__btn--danger:hover{color:#d32f2f;background:#fdecea}
|
|
2
|
+
`,document.head.appendChild(t);}}})();var k=a.preprocess(r=>String(r??"").trim(),a.string().refine(r=>r===""||/^(?:https?:|mailto:)/i.test(r)||!/^[a-z][a-z0-9+.-]*:/i.test(r),{message:"Invalid link href"}).catch(""));function u(r){return k.parse(r)}var f='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';var b='<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/></svg>';var i=class r extends a$1{static get nodeName(){return "a"}static get NAMESPACE(){return "atom.link.Link"}static getStateSchema(e){let t;if(e?.getAttribute("data-state"))try{t=JSON.parse(e.getAttribute("data-state"));}catch{}return b$1({type:r.NAMESPACE,data:a.object({href:a.string().default(t?.entity?.data?.href??e?.href??"").transform(a=>u(a)),target:a.string().default(t?.entity?.data?.target??e?.target??"")}).default({}),length:t?.length??0,offset:t?.offset??0}).default({})}constructor(e){super(e),this.input=f$1(t=>n(()=>{t.focus();}));}#e({entity:e,length:t,offset:a}){return o("div",{className:"link-toolbar"},[o("div",{className:"link-toolbar__row",style:{display:"flex"}},[o("button",{className:"link-toolbar__btn",title:"Copy URL",$dangerouslySetInnerHTML:f,onClick:()=>navigator.clipboard?.writeText(e.peek()?.data?.href??"")}),o("input",{type:"text",$ref:this.input,value:e.peek()?.data?.href??"",defaultValue:e.peek()?.data?.href??"",onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),o.stopPropagation(),this.mrakomor.command.closeDialog());},onInput:o=>{let s=o.currentTarget.value;e.set({...e.peek(),data:{...e.peek()?.data,href:s}});}}),o("select",{value:e.peek()?.data?.target??"",onChange:o=>{e.set({...e.peek(),data:{...e.peek()?.data,target:o.currentTarget.value}});}},[o("option",{value:"",selected:e.peek()?.data?.target===""},""),o("option",{value:"_self",selected:e.peek()?.data?.target==="_self"},"_self"),o("option",{value:"_blank",selected:e.peek()?.data?.target==="_blank"},"_blank"),o("option",{value:"_parent",selected:e.peek()?.data?.target==="_parent"},"_parent"),o("option",{value:"_top",selected:e.peek()?.data?.target==="_top"},"_top")]),o("span",{className:"link-toolbar__sep"}),o("button",{className:"link-toolbar__btn link-toolbar__btn--danger",title:"Remove link",$dangerouslySetInnerHTML:b,onClick:()=>{this.mrakomor.command.removeEntityRange?.({state:{entity:e.peek(),length:t.peek(),offset:a.peek()},blockElement:f$2(this.element)});}})])])}onMount(){let{entity:e}=this.props;e.peek()?.data?.href||this.mrakomor.command.openDialog({element:this.element,children:this.#e(this.props)});}render(){let{entity:e,length:t,offset:a,children:o$1}=this.props;return o("a",{href:()=>u(e.get()?.data?.href),target:()=>e.get()?.data?.target||null,rel:()=>e.get()?.data?.target==="_blank"?"noopener noreferrer":null,$ref:this.element,onClick:s=>{s.ctrlKey||s.metaKey||n(()=>{k$1(),this.mrakomor.command.openDialog({element:this.element,children:this.#e({entity:e,length:t,offset:a})});});},"data-state":()=>JSON.stringify({entity:e.get(),length:t.get(),offset:a.get()})},o$1)}};function v({mrakomor:r}){return {resolveConfig:e=>(e.entityRanges.push(i),e),resolveComponent:e=>{if(e===i.NAMESPACE)return i},registerHandlers(){r.register.help.add({id:"link.insert",group:"formatting",description:"Insert or edit a link on the selection",commands:[],shortcuts:["Mod+K"]});},onKeyDown(e){e.key==="k"&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),r.command.insertEntityRange({namespace:i.NAMESPACE}));}}}
|
|
3
3
|
export{i as LinkEntity,v as linkEntityPlugin};
|