@mrakomor/core 0.0.11 → 0.0.13
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.mjs +2 -2
- package/dist/blockInsertMenu.mjs +1 -1
- package/dist/chunk-2C6UDFD4.mjs +1 -0
- package/dist/chunk-4WTPDNPA.mjs +1 -0
- package/dist/chunk-5AD5MQXI.mjs +1 -0
- package/dist/{chunk-K2DMHAUD.mjs → chunk-7CJLTNHZ.mjs} +1 -1
- package/dist/{chunk-VYTSZ4S6.mjs → chunk-B2UFH244.mjs} +1 -1
- package/dist/chunk-BWK2S4UI.mjs +2 -0
- package/dist/chunk-D6K2L5O3.mjs +4 -0
- package/dist/{chunk-NR2BAMSW.mjs → chunk-DHFIX7FW.mjs} +2 -2
- package/dist/chunk-ERNLRJPB.mjs +1 -0
- package/dist/chunk-EXDY5TZH.mjs +1 -0
- package/dist/chunk-J4TTWQ6J.mjs +2 -0
- package/dist/{chunk-2VURZA2E.mjs → chunk-SG5PCGIV.mjs} +1 -1
- package/dist/chunk-ZHOZPQZH.mjs +1 -0
- package/dist/clipboard.cjs +3 -3
- package/dist/clipboard.mjs +3 -3
- package/dist/footer.cjs +3 -3
- package/dist/footer.mjs +2 -2
- package/dist/headline.cjs +2 -2
- package/dist/headline.mjs +1 -1
- package/dist/help.cjs +1 -1
- package/dist/help.mjs +2 -2
- package/dist/index.cjs +6 -6
- package/dist/index.mjs +4 -4
- package/dist/link.mjs +2 -2
- package/dist/list.cjs +3 -3
- package/dist/list.mjs +1 -1
- package/dist/paragraph.cjs +2 -2
- package/dist/paragraph.mjs +1 -1
- package/dist/slashCommand.cjs +2 -2
- package/dist/slashCommand.mjs +1 -1
- package/dist/tooltip.cjs +1 -1
- package/dist/tooltip.mjs +2 -2
- package/dist/tts.cjs +8 -8
- package/dist/tts.mjs +3 -3
- package/dist/types/Mrakomor.d.mts +230 -0
- package/dist/types/component/AbstractComponent.d.mts +69 -0
- package/dist/types/component/Editor.d.mts +8 -0
- package/dist/types/component/block/BlockComponent.d.mts +105 -0
- package/dist/types/component/block/BlockRegister.d.mts +29 -0
- package/dist/types/component/block/ExternalComponent.d.mts +42 -0
- package/dist/types/component/block/UnknownComponent.d.mts +3 -0
- package/dist/types/component/block/blockItemEquals.d.mts +6 -0
- package/dist/types/component/block/helpers.d.mts +319 -0
- package/dist/types/component/editorContext.d.mts +4 -0
- package/dist/types/component/entityRange/EntityRangeElement.d.mts +15 -0
- package/dist/types/component/inlineStyle/Bold.d.mts +4 -0
- package/dist/types/component/inlineStyle/InlineElement.d.mts +10 -0
- package/dist/types/component/inlineStyle/Italic.d.mts +4 -0
- package/dist/types/component/inlineStyle/Subscript.d.mts +4 -0
- package/dist/types/component/inlineStyle/Superscript.d.mts +4 -0
- package/dist/types/component/inlineStyle/Underline.d.mts +4 -0
- package/dist/types/component/inlineStyle/index.d.mts +5 -0
- package/dist/types/component/overlayMount.d.mts +46 -0
- package/dist/types/dom.d.mts +169 -0
- package/dist/types/emitter.d.mts +38 -0
- package/dist/types/index.d.mts +7 -0
- package/dist/types/namespaces.d.mts +17 -0
- package/dist/types/plugin/blockChrome/BlockChrome.d.mts +11 -0
- package/dist/types/plugin/blockChrome/index.d.mts +1 -0
- package/dist/types/plugin/blockInsertMenu/BlockInsertMenu.d.mts +6 -0
- package/dist/types/plugin/blockInsertMenu/index.d.mts +1 -0
- package/dist/types/plugin/clipboard/clipboardHelpers.d.mts +151 -0
- package/dist/types/plugin/clipboard/clipboardPlugin.d.mts +6 -0
- package/dist/types/plugin/clipboard/index.d.mts +1 -0
- package/dist/types/plugin/default/defaultMrakomorPlugin.d.mts +21 -0
- package/dist/types/plugin/dialog/Dialog.d.mts +23 -0
- package/dist/types/plugin/footer/footerPlugin.d.mts +7 -0
- package/dist/types/plugin/footer/index.d.mts +1 -0
- package/dist/types/plugin/headline/Headline.d.mts +29 -0
- package/dist/types/plugin/headline/index.d.mts +1 -0
- package/dist/types/plugin/help/HelpRegister.d.mts +15 -0
- package/dist/types/plugin/help/helpPlugin.d.mts +26 -0
- package/dist/types/plugin/help/helpSchema.d.mts +11 -0
- package/dist/types/plugin/help/index.d.mts +1 -0
- package/dist/types/plugin/linkEntity/LinkEntity.d.mts +37 -0
- package/dist/types/plugin/linkEntity/index.d.mts +1 -0
- package/dist/types/plugin/list/List.d.mts +61 -0
- package/dist/types/plugin/list/index.d.mts +1 -0
- package/dist/types/plugin/list/listHelpers.d.mts +166 -0
- package/dist/types/plugin/menu/Menu.d.mts +22 -0
- package/dist/types/plugin/menu/menuPlugin.d.mts +6 -0
- package/dist/types/plugin/paragraph/Paragraph.d.mts +16 -0
- package/dist/types/plugin/paragraph/index.d.mts +1 -0
- package/dist/types/plugin/slashCommand/SlashActionRegister.d.mts +12 -0
- package/dist/types/plugin/slashCommand/index.d.mts +1 -0
- package/dist/types/plugin/slashCommand/slashActionSchema.d.mts +29 -0
- package/dist/types/plugin/slashCommand/slashCommandHelpers.d.mts +77 -0
- package/dist/types/plugin/slashCommand/slashCommandPlugin.d.mts +11 -0
- package/dist/types/plugin/slashCommand/slashHelp.d.mts +12 -0
- package/dist/types/plugin/tooltip/Tooltip.d.mts +16 -0
- package/dist/types/plugin/tooltip/index.d.mts +1 -0
- package/dist/types/plugin/tts/TtsHeadline.d.mts +27 -0
- package/dist/types/plugin/tts/TtsList.d.mts +19 -0
- package/dist/types/plugin/tts/TtsParagraph.d.mts +9 -0
- package/dist/types/plugin/tts/TtsVoice.d.mts +52 -0
- package/dist/types/plugin/tts/index.d.mts +4 -0
- package/dist/types/register/Register.d.mts +50 -0
- package/dist/types/register/sortRegisterEntries.d.mts +7 -0
- package/dist/types/schema/blockContent.d.mts +34 -0
- package/dist/types/schema/blockRegister.d.mts +14 -0
- package/dist/types/schema/config.d.mts +6 -0
- package/dist/types/types.d.mts +636 -0
- package/package.json +36 -22
- package/dist/chunk-5VPYPKGA.mjs +0 -1
- package/dist/chunk-BCE45I7Q.mjs +0 -2
- package/dist/chunk-N4I2WZWF.mjs +0 -1
- package/dist/chunk-SCFD3XBH.mjs +0 -1
- package/dist/chunk-T7OO472O.mjs +0 -1
- package/dist/chunk-WQWE5UCN.mjs +0 -1
- package/dist/chunk-YO4ZA6PJ.mjs +0 -2
- package/dist/chunk-ZDMD7SRT.mjs +0 -4
package/dist/slashCommand.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var Ie=class{next(...e){}error(...e){}complete(...e){}},
|
|
1
|
+
'use strict';var Ie=class{next(...e){}error(...e){}complete(...e){}},H=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 V=Symbol("@esmj/signals:type"),q=Symbol("@esmj/signals:name");var R=null,re=false,Pe=[];function B(e){let t=R;R=null;let n=e();return R=t,n}function Ut(){re=false;let e=je();for(let n of e)n.get();let t=Pe;Pe=[];for(let n of t)n();}function Vt(){re||(re=true,queueMicrotask(Ut));}var $e=Symbol("@esmj/signals:internal observable"),T=Symbol("@esmj/signals:original function"),zt=class extends H{#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=()=>B(()=>{this.#e.add(e),this.#r();}),e.next[T]=void 0),e instanceof qe&&e.next[T]===void 0){let t=e.next.bind(e);e.next=()=>B(()=>{this.#e.add(e),t(),this.#r();}),e.next[T]=t;}return this.subscribe(e)}getPending(){let e=[];for(let t of this.#e){if(!t.get[T]){let n=t.get,r=n.bind(t);t.get=()=>B(()=>(this.#e.delete(t),r())),t.get[T]=n;}e.push(t);}return e}unwatch(e){return e.next=e.next[T]?e.next[T]:e.next,e.get=e.get[T]?e.get[T]:e.get,this.#e.delete(e),this.unsubscribe(e)}},z=null;function De(e){z=new zt(e);}De(()=>{Vt();});function je(){return z.getPending()}var w=Symbol("@esmj/signals:no error"),qe=class Ke extends Ie{#e=true;#r=false;#t=null;#o=this.#p();#s=null;#i=null;#c=0;#l=new Map;#n=w;constructor(t,n){super(),this.#s=t,this.#i=n,this.debug=n?.debug,this[V]="computed",this[q]=n?.debug??null,this.get=this.get.bind(this);}#u(){for(let{unsubscribe:t}of this.#o.dependencies.values())t();this.#o.dependencies.clear();}#p(){return {dependencies:new Map,sourceRevisions:new Map,observer:this}}getRevision(){return this.#c}getDebugInfo(){return {name:this[q],dirty:this.#e,revision:this.#c,sourceDependencies:[...this.#l.keys()]}}#f(){for(let[t,n]of this.#l)if(t instanceof Ke&&B(()=>t.get()),t.getRevision()!==n)return true;return false}next(){this.#e=true,this.#t[$e].next();}get(){if(this.#r)throw new Error("Cycle detected in computed signal");if(this.#t||(this.#t=$(this.#a(),this.#i)),(this.#e||this.#n!==w)&&(this.#l.size===0||this.#f()?this.#a():this.#e=false),R&&R.sourceRevisions.set(this,this.#c),this.#n!==w)throw this.#n;return this.#t.get()}peek(){if(this.#t||(this.#t=$(this.#a(),this.#i)),(this.#e||this.#n!==w)&&(this.#l.size===0||this.#f()?this.#a():this.#e=false),this.#n!==w)throw this.#n;return this.#t.peek()}#a(){this.#r=true,this.#e=false,this.#n=w,this.#u(),this.#o.sourceRevisions.clear();let t=R;R=this.#o;let n;try{n=this.#s();}catch(r){this.#n=r;}return R=t,this.#l=this.#o.sourceRevisions,this.#o.sourceRevisions=new Map,this.#r=false,n instanceof Promise&&(n=n.then(r=>{this.#n=w,this.#t.set(r);}).catch(r=>{this.#n=r;})),this.#n===w&&this.#t&&this.#t.set(n),this.#c++,n}destroy(){this.#u(),this.#l.clear(),this.#e=true,this.#n=w;}};function $(e,t={}){let n=t?.equals??Object.is,r=0,o=new H;function i(){return R&&(R.dependencies.set(o,o.subscribe(R.observer)),R.sourceRevisions.set(u,r)),e}function s(){return e}function l(f){if(!n(e,f)){e=f,r++,o.next();}return e}function c(){return r}let u={get:i,set:l,peek:s,getRevision:c,[$e]:o,[V]:"signal",[q]:t?.debug??null};return u}var ge=Ee(),ye=Ee(),tt=Ee(),hn=Array.from({length:256},(e,t)=>(t<=15?"0":"")+t.toString(16));function Ee(){return Math.floor(Math.random()*16777215)}function mn(){return ye=(ye+1)%16777215,ye}function Z(){let e=Math.floor(Date.now()/1e3);e=parseInt(e,10)%4294967295;let t=mn(),n=String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,e&255,ge>>16&255,ge>>8&255,ge&255,tt>>8&255,tt&255,t>>16&255,t>>8&255,t&255),r="";for(let o=0;o<n.length;o++)r+=hn[n.charCodeAt(o)];return r}var gn=Symbol("block-element");var yn=Symbol("selectable-element");function nt(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 rt(e){return e?nt(e.startContainer,gn):null}function ot(e){return e?nt(e.startContainer,yn):null}function En(){return window.getSelection()}function j(){let e=En();return e.rangeCount>0?e.getRangeAt(0).cloneRange():null}function Se(e,t,n){if(!e)return 0;if(t===e){if(t.nodeType===Node.TEXT_NODE)return n;let s=0,l=e.childNodes,c=Math.min(n,l.length);for(let u=0;u<c;u++)s+=l[u].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}var st="molecule.paragraph.Paragraph";var it="molecule.headline.";function I(e){return e===`
|
|
2
2
|
`||e===`\r
|
|
3
|
-
`?"":e??""}function at({component:e,originComponent:t,properties:n,settings:r}={}){let o=n??{},i=Array.isArray(o.items)?o.items:[{text:o.text??"",inlineStyleRanges:o.inlineStyleRanges??[],entityRanges:o.entityRanges??[]}];return {...e?{component:e}:{},...t?{originComponent:t}:{},properties:{items:i},...r?{settings:r}:{}}}function P(e){let t=e?.component??"";return t===st||t.startsWith(it)}function ut(e,t){let n=I(e.properties.text),r=I(t.properties.text);return {state:{...e,properties:{...t.properties,...e.properties,text:n+r,inlineStyleRanges:[...e.properties.inlineStyleRanges??[],...(t.properties.inlineStyleRanges??[]).map(o=>({...o,offset:o.offset+n.length}))],entityRanges:[...e.properties.entityRanges??[],...(t.properties.entityRanges??[]).map(o=>({...o,offset:o.offset+n.length}))]},settings:{...t.settings,...e.settings}},cursor:n.length}}function lt(e,t){return (e??[]).filter(n=>n.offset<t).map(n=>({...n,length:Math.min(n.length,t-n.offset)}))}function ct(e,t){return (e??[]).filter(n=>n.offset+n.length>t).map(n=>({...n,offset:Math.max(0,n.offset-t),length:n.offset+n.length-Math.max(n.offset,t)}))}function xe(e,t){let n=structuredClone(e),r=structuredClone(e);return n.properties.text=e.properties.text.slice(0,t),r.properties.text=e.properties.text.slice(t),n.properties.inlineStyleRanges=lt(e.properties.inlineStyleRanges,t),r.properties.inlineStyleRanges=ct(e.properties.inlineStyleRanges,t),n.properties.entityRanges=lt(e.properties.entityRanges,t),r.properties.entityRanges=ct(e.properties.entityRanges,t),r.componentId=Q(),{originalLineState:n,newLineState:r}}var be={INPUT:"mrakomor:input"};var ft=class{#e=new Set;pipe(...e){return Sn(...e)(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);}};function Sn(...e){return t=>Array.from(e).reduce((n,r)=>r(n),t)}function pt(e){return e.map((t,n)=>({entry:t,index:n})).sort((t,n)=>{let r=t.entry.order??t.index,o=n.entry.order??n.index;return r!==o?r-o:t.index-n.index}).map(({entry:t})=>t)}var Z=class extends ft{mrakomor;#e=new Map;#r=null;#t=0;#o;constructor(t,n={}){super(),this.mrakomor=t,this.#o=n.sort??pt;}normalize(t,n){throw new Error("Register subclass must implement normalize")}#s(){this.#r=null,this.next(this.list());}#i(t,n=this.#t++){let r=this.normalize(t,n);return r?(this.#e.set(r.id,r),r):null}add(t){if(Array.isArray(t)){let r=[];for(let o of t){let i=this.#i(o,this.#t++);i&&r.push(i);}return r.length&&this.#s(),r}let n=this.#i(t);return n&&this.#s(),n}get(t){return this.#e.get(t)}has(t){return this.#e.has(t)}remove(t){let n=this.#e.delete(t);return n&&this.#s(),n}list(){return this.#r??=this.#o([...this.#e.values()]),this.#r}};var xn={abortEarly:true};function ke(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 bn(e,t,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)t.push(ke(e.errors[r],n));}function mt(e,t,n,r){if(n!==false){let o=ke(e.error,t);return {success:false,error:o,errors:[o]}}bn(e,r,t);}function ee(e){return e?.abortEarly!==void 0?e:xn}function Ce(e,t){C(e,"_parse",(n,r,o)=>{let i=n(r,o);return !i.success&&t(r)?{success:true,data:r}:i});}var G=e=>typeof e=="string"||e instanceof String,Ne=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),Re=e=>e===true||e===false,Cn=e=>e instanceof Date&&!Number.isNaN(e.getTime()),Nn=e=>typeof e=="function",Rn=e=>Array.isArray(e),_e=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function gt(e,t){let n=_(_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 C(this,"_parse",(s,l,c)=>{let u=s(l,c);if(!u.success)return u;let f=o(u.data,{context:c?.context});if(!_e(f)){let p={message:`derive() callback must return a plain object of overrides, got ${f===null?"null":typeof f}`};return {success:false,error:p,errors:[p]}}if(i==="missing"){let p={...u.data};for(let h in f)p[h]===void 0&&(p[h]=f[h]);return {success:true,data:p}}return {success:true,data:{...u.data,...f}}}),this},C(n,"_parse",(o,i,s)=>{let l=o(i,s),{abortEarly:c}=ee(s);if(l.success===false)return l;let u={},f=[];for(let p in e){let h=e[p]._parse(l.data[p],s);if(h.success)u[p]=h.data;else {let m=mt(h,p,c,f);if(m)return m}}return f.length>0?{success:false,error:f[0],errors:f}:{success:true,data:u}}),r}function Ae(e){return _(G,{...e,type:"string"})}function Te(e){return _(Ne,{...e,type:"number"})}function we(e){return _(Re,{...e,type:"boolean"})}function Le(e){return _(Cn,{...e,type:"date"})}function yt(e){return _(Nn,{...e,type:"function"})}function Et(e,t){let n=s=>e.includes(s),r=s=>`Invalid ${o} value. Expected ${e.map(l=>`"${l}"`).join(" | ")}, received "${s}".`,o="enum",i=_(n,{message:r,...t,type:o});return i._getDescription=()=>`enum(${e.map(s=>`"${s}"`).join(" | ")})`,i._getDefinition=()=>e,i}function St(e,t){let n=_(Rn,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,n._getDefinition=()=>e,C(n,"_parse",(r,o,i)=>{let s=r(o,i),{abortEarly:l}=ee(i);if(s.success===false)return s;let c=[],u=[],f=i;for(let p=0;p<s.data.length;p++){let h={...f,context:{...f?.context,index:p}},m=e._parse(s.data[p],h);if(m.success)c.push(m.data);else {let S=mt(m,p,l,u);if(S)return S}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:c}}),n}function xt(){return _(()=>true)}function F(e,t){return C(t,"_parse",(n,r,o)=>(r=e(r),n(r,o))),t}function bt(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=_(()=>false,{message:n,...t,type:"union"});return r._getDefinition=()=>e,C(r,"_parse",(o,i,s)=>{let l=s,c=[];for(let h=0;h<e.length;h++){let m=e[h]._parse(i,l);if(m.success)return m;c.push(m);}let{abortEarly:u}=ee(l),f={message:typeof n=="function"?n(i):n};if(u!==false)return {success:false,error:f,errors:[f]};let p=[];for(let h=0;h<c.length;h++){let m=c[h].errors;if(m?.length)for(let S=0;S<m.length;S++)m[S].cause?.key&&p.push(ke(m[S],`branch ${h}`));}return p.length===0&&p.push(f),{success:false,error:p[0],errors:p}}),r}function Ct(e,t){let n=_(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 Nt(e){let t=_(()=>true,{type:"contextRef"});return t._getDescription=()=>`contextRef("${e}")`,C(t,"_parse",(n,r,o)=>({success:true,data:o?.context?.[e]})),t}function Rt(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 _t={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 G(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},we({...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(Re(n))return Number(n);if(G(n)){let r=n.trim();if(r==="")return n;let o=Number(r);if(Number.isFinite(o))return o}return n},Te({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return F(n=>Re(n)||Ne(n)&&Number.isFinite(n)?String(n):n,Ae({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return F(n=>{let r;return G(n)&&(r=n.trim()),Ne(n)&&Number.isFinite(n)||r?new Date(r??n):n},Le({...e,message:t}))},json(e,t){let n=t?.message??(r=>`Cannot parse "${r}" as JSON.`);return C(e,"_parse",(r,o,i)=>{if(G(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}},kt={},E={object:gt,string:Ae,number:Te,boolean:we,date:Le,function:yt,enum:Et,array:St,any:xt,preprocess:F,union:bt,literal:Ct,contextRef:Nt,withContext:Rt,coerce:kt,cast:_t};function dt(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function C(e,t,n){let r=e[t];e[t]=(...o)=>n(r,...o);}function _(e,{type:t="any",name:n,message:r}={}){r=r||dt(t);let o={name:n,message:r,type:t},i={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(s,l){let c=e(s);if(c===true)return {success:true,data:s};if(typeof c=="object"&&c?.success===true)return c;let u={message:typeof r=="function"?r(s):r};return {success:false,error:u,errors:[u]}},parse(s,l){let c=this._parse(s,l);if(!c.success)throw c=c,new Error(c.error.message,{cause:c.error.cause});return c.data},safeParse(s,l){return this._parse(s,l)},transform(s){return C(this,"_parse",(l,c,u)=>{let f=l(c,u);return f.success&&(f.data=s(f.data)),f}),this},optional(){return Ce(this,s=>s===void 0),this},nullable(){return Ce(this,s=>s===null),this},nullish(){return Ce(this,s=>s==null),this},default(s){return C(this,"_parse",(l,c,u)=>(c===void 0&&(c=typeof s=="function"?s({context:u?.context}):s),l(c,u))),this},catch(s){return C(this,"_parse",(l,c,u)=>{let f=l(c,u);return f.success?f:{success:true,data:typeof s=="function"?s({input:c,error:f.error}):s}}),this},pipe(s){return C(this,"_parse",(l,c,u)=>{let f=l(c,u);return f.success?s._parse(f.data,u):f}),this},refine(s,{message:l,type:c,jsonSchema:u}={}){if(c&&(l=l||dt(c),t=c),u){let f=[...this._getJsonSchemaHints?.()??[],u];this._getJsonSchemaHints=()=>f;}return C(this,"_parse",(f,p,h)=>{let m=f(p,h),{abortEarly:S}=ee(h);if(!m.success)return m;let k=s(m.data);if(k===true||typeof k=="object"&&k?.success===true)return m;let N={message:typeof l=="function"?l(p):l};return {success:false,error:N,errors:[N]}}),this},clone(){return {...this}}};return ht.length>0?ht.reduce((s,l)=>l(s,e,o)??s,i):i}var ht=[];function _n(e,t){return String(e??t).trim().toLowerCase().replace(/\s+/g,"-")||String(t)}function kn({id:e,label:t,fallback:n=0}){return e??_n(t,n)}var At=E.object({id:E.string().optional(),label:E.string().optional(),keywords:E.array(E.string()).optional(),group:E.string().optional(),order:E.number().default(({context:e})=>e?.index??0),description:E.string().optional(),handler:E.function()}).derive(e=>{let t=kn({id:e.id,label:e.label,fallback:e.order}),n=String(e.label??e.id??`Action ${e.order}`),r=e.keywords?.length?e.keywords.map(String):[n,t];return {id:t,label:n,keywords:r,group:e.group??"actions",...e.description!=null&&e.description!==""?{description:String(e.description)}:{}}});var te=class extends Z{normalize(t,n){if(!t||typeof t.handler!="function")return null;try{return At.parse(t,{context:{index:n}})}catch{return null}}};function Tt(e,t){let n=e._getBlockElementState(t);return n?structuredClone(n):null}function An(e,t){let n=e._getBlockElementByComponentId(t.baselineState?.componentId);return n||(e._getBlockElementIndex(t.blockElement)!==-1&&t.blockElement?.isConnected,t.blockElement)}function wt(e){return e==null||e===""||/\s/.test(e)}function Lt(e,t){if(typeof e!="string"||t<1)return null;let n=e.slice(0,t),r=-1;for(let o=n.length-1;o>=0;o--){let i=n[o];if(i==="/"){let s=o===0?null:n[o-1];if(s===null||/\s/.test(s)){r=o;break}return null}if(!/[\w]/.test(i))return null}return r<0?null:{slashStart:r,slashEnd:t,query:n.slice(r+1)}}function vt(e,t){if(!e)return null;let n=t.inputType??"",r=t.data??null;return n==="insertText"||n==="insertCompositionText"||n==="insertReplacementText"?r==null||r===""?e:/\s/.test(r)||!/^[\w]+$/.test(r)?null:{...e,query:e.query+r,slashEnd:e.slashEnd+r.length}:n==="deleteContentBackward"||n==="deleteContentForward"||n==="deleteByCut"||n==="deleteByDrag"?e.slashEnd<=e.slashStart+1?null:{...e,query:e.query.slice(0,-1),slashEnd:e.slashEnd-1}:n==="insertFromPaste"||n==="insertFromDrop"?null:e}function ve(e){return typeof e?.handler=="function"}function Mt(e,t){let n=String(t??"").trim().toLowerCase();return n?e.filter(r=>String(r.label??"").toLowerCase().includes(n)?true:(r.keywords??[]).some(i=>String(i).toLowerCase().includes(n))):e.slice()}function Bt(e,t,n,r){let{originalLineState:o}=xe(e,t),i=r&&P(r)?r:e,{newLineState:s}=xe(i,n);return {beforeState:o,afterState:s}}function Ot(e,t){let n=e._getBlockElementState(t);return n&&P(n)?n:null}function Tn(e,t=null){let n=e?.component,r=n?.NAMESPACE;if(!n||!r)return null;let o=I(t?.properties?.text??""),i=t?.properties?.inlineStyleRanges??[],s=t?.properties?.entityRanges??[],l={componentId:Q(),component:r,...e.settings?{settings:e.settings}:{}},c=at({properties:{text:o,inlineStyleRanges:i,entityRanges:s},settings:e.settings});return n.getStateSchema().parse({...n.fromExchangeState(c),...l})}function It(e,t){if(!ve(t))return;let{mrakomor:n,blockElement:r,slashStart:o,slashEnd:i,baselineState:s}=e;if(!s||!P(s)){t.handler(e);return}let l=Ot(n,r),{beforeState:c,afterState:u}=Bt(s,o,i,l),{state:f}=ut(c,u),p=I(c.properties?.text).length;n.command.replaceBlockElement({blockElement:r,blocks:[n.normalizeComponentState(f)],cursor:p}),t.handler(e);}function Pt(e,t){let{mrakomor:n,blockElement:r,slashStart:o,slashEnd:i,baselineState:s}=e,l=t?.component?.NAMESPACE;if(!l||!s||!P(s))return;let c=Ot(n,r),{beforeState:u,afterState:f}=Bt(s,o,i,c),p=I(u.properties?.text),h=I(f.properties?.text),m=!p&&!h,S=Tn(t,m?null:f);if(S){if(m){n.command.replaceBlockElement({blockElement:r,blocks:[S],cursor:0});return}n.command.insertBlockElement({blockElement:r,namespace:l,originalLineState:u,newLineState:S,cursor:0});}}function $t(e,t){return {mrakomor:e,blockElement:An(e,t),query:t.query,slashStart:t.slashStart,slashEnd:t.slashEnd,baselineState:t.baselineState,range:j()}}function Dt(){return E.object({id:E.string(),group:E.string().default("general"),description:E.string().default(""),commands:E.array(E.string()).default([]),shortcuts:E.array(E.string()).default([])}).default({})}function wn(e){return `/${(e.keywords?.[0]??e.label??e.id).toLowerCase()}`}function jt(e){return Dt().parse({id:e.id,group:e.group,description:e.description??e.label,commands:[wn(e)],shortcuts:[]})}var Ln={id:"slash.open",group:"blocks",description:"Open the slash command menu",commands:["/"],shortcuts:[]};function Ft(e){let t=e.register.slashActions;if(t)for(let n of t.list())e.register.help.add(jt(n));}function vn({mrakomor:e}){e.register.slashActions=new te(e);let t=null,n=null,r=[],o=0,i=false;function s(a){return Mt([...e.register.blocks.list(),...e.register.slashActions.list()],a)}function l(){i=false,t=null,n=null,r=[],o=0,e.command.closeMenu?.();}function c(a){if(!t||!a)return;let d=$t(e,t);ve(a)?It(d,a):Pt(d,a),l();}function u(a){if(!t)return;a&&(n=a),r=s(t.query),o=0;let d=i;i=true;let g={entries:r,anchorRect:n??void 0,highlightIndex:o,ariaLabel:"Slash commands",onSelect:c};d?e.command.updateMenu?.(g):e.command.openMenu?.(g);}function f(a,d,g,b,y){t={blockElement:a,slashStart:d,slashEnd:g,query:b,baselineState:Tt(e,a)},u(y);}function p(){let a=j();if(!a?.collapsed)return null;let d=rt(a),g=ot(a);if(!d||!g)return null;let b=g.textContent??"",y=Se(g,a.startContainer,a.startOffset);return {blockElement:d,selectable:g,text:b,cursor:y}}function h(a){let g=j()?.getBoundingClientRect?.();return (!g||g.width===0&&g.height===0)&&(g=a.getBoundingClientRect()),g}function m(a){return P(e._getBlockElementState(a))}function S(a){let d=Lt(a.text,a.cursor);if(!d){i&&l();return}f(a.blockElement,d.slashStart,d.slashEnd,d.query,h(a.selectable));}function k(){let a=p();if(!a||!m(a.blockElement)||a.cursor<1||a.text[a.cursor-1]!=="/")return false;let d=a.cursor-1,g=d===0?null:a.text[d-1];return wt(g)?(f(a.blockElement,d,d+1,"",h(a.selectable)),true):false}function N(a){let d=a.data??null,g=a.inputType??"";if(!t){if(d!=="/")return;k();return}if(g==="insertCompositionText"||g==="insertFromPaste"||g==="insertFromDrop"){let x=p();if(!x||x.blockElement!==t.blockElement){l();return}S(x);return}let b=g===""&&d!=null?{inputType:"insertText",data:d}:a,y=vt(t,b);if(!y){l();return}t=y,u();}return {resolveConfig(a){return e.register.slashActions.add(a.slashActions??[]),Ft(e),a},registerCommands(){e.register.help.add(Ln),Ft(e);},onKeyDown(a){if(i){if(a.key==="ArrowDown"){if(a.preventDefault(),!r.length)return;o=(o+1)%r.length,e.command.updateMenu?.({entries:r,highlightIndex:o,ariaLabel:"Slash commands",onSelect:c});return}if(a.key==="ArrowUp"){if(a.preventDefault(),!r.length)return;o=(o-1+r.length)%r.length,e.command.updateMenu?.({entries:r,highlightIndex:o,ariaLabel:"Slash commands",onSelect:c});return}if(a.key==="Enter"){a.preventDefault(),a.stopPropagation?.();let d=r[o];d&&c(d);return}a.key==="Escape"&&(a.preventDefault(),l());}},registerHandlers(){e.emitter.on(be.INPUT,N),e.emitter.on(be.CLOSE_MENU,()=>{i=false,t=null,n=null,r=[],o=0;});}}}exports.slashCommandPlugin=vn;
|
|
3
|
+
`?"":e??""}function at({component:e,originComponent:t,properties:n,settings:r}={}){let o=n??{},i=Array.isArray(o.items)?o.items:[{text:o.text??"",inlineStyleRanges:o.inlineStyleRanges??[],entityRanges:o.entityRanges??[]}];return {...e?{component:e}:{},...t?{originComponent:t}:{},properties:{items:i},...r?{settings:r}:{}}}function P(e){let t=e?.component??"";return t===st||t.startsWith(it)}function ut(e,t){let n=I(e.properties.text),r=I(t.properties.text);return {state:{...e,properties:{...t.properties,...e.properties,text:n+r,inlineStyleRanges:[...e.properties.inlineStyleRanges??[],...(t.properties.inlineStyleRanges??[]).map(o=>({...o,offset:o.offset+n.length}))],entityRanges:[...e.properties.entityRanges??[],...(t.properties.entityRanges??[]).map(o=>({...o,offset:o.offset+n.length}))]},settings:{...t.settings,...e.settings}},cursor:n.length}}function lt(e,t){return (e??[]).filter(n=>n.offset<t).map(n=>({...n,length:Math.min(n.length,t-n.offset)}))}function ct(e,t){return (e??[]).filter(n=>n.offset+n.length>t).map(n=>({...n,offset:Math.max(0,n.offset-t),length:n.offset+n.length-Math.max(n.offset,t)}))}function xe(e,t){let n=structuredClone(e),r=structuredClone(e);return n.properties.text=e.properties.text.slice(0,t),r.properties.text=e.properties.text.slice(t),n.properties.inlineStyleRanges=lt(e.properties.inlineStyleRanges,t),r.properties.inlineStyleRanges=ct(e.properties.inlineStyleRanges,t),n.properties.entityRanges=lt(e.properties.entityRanges,t),r.properties.entityRanges=ct(e.properties.entityRanges,t),r.componentId=Z(),{originalLineState:n,newLineState:r}}var be={INPUT:"mrakomor:input"};function ft(e){return e.map((t,n)=>({entry:t,index:n})).sort((t,n)=>{let r=t.entry.order??t.index,o=n.entry.order??n.index;return r!==o?r-o:t.index-n.index}).map(({entry:t})=>t)}var ee=class extends H{mrakomor;#e=new Map;#r=null;#t=0;#o;constructor(t,n={}){super(),this.mrakomor=t,this.#o=n.sort??ft;}normalize(t,n){throw new Error("Register subclass must implement normalize")}#s(){this.#r=null,this.next(this.list());}#i(t,n=this.#t++){let r=this.normalize(t,n);return r?(this.#e.set(r.id,r),r):null}add(t){if(Array.isArray(t)){let r=[];for(let o of t){let i=this.#i(o,this.#t++);i&&r.push(i);}return r.length&&this.#s(),r}let n=this.#i(t);return n&&this.#s(),n}get(t){return this.#e.get(t)}has(t){return this.#e.has(t)}remove(t){let n=this.#e.delete(t);return n&&this.#s(),n}list(){return this.#r??=this.#o([...this.#e.values()]),this.#r}};var Sn={abortEarly:true};function ke(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 xn(e,t,n){if(e.errors?.length)for(let r=0;r<e.errors.length;r++)t.push(ke(e.errors[r],n));}function ht(e,t,n,r){if(n!==false){let o=ke(e.error,t);return {success:false,error:o,errors:[o]}}xn(e,r,t);}function te(e){return e?.abortEarly!==void 0?e:Sn}function Ce(e,t){C(e,"_parse",(n,r,o)=>{let i=n(r,o);return !i.success&&t(r)?{success:true,data:r}:i});}var U=e=>typeof e=="string"||e instanceof String,Ne=e=>(typeof e=="number"||e instanceof Number)&&!Number.isNaN(e),Re=e=>e===true||e===false,bn=e=>e instanceof Date&&!Number.isNaN(e.getTime()),Cn=e=>typeof e=="function",Nn=e=>Array.isArray(e),_e=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function mt(e,t){let n=_(_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 C(this,"_parse",(s,l,c)=>{let u=s(l,c);if(!u.success)return u;let f=o(u.data,{context:c?.context});if(!_e(f)){let p={message:`derive() callback must return a plain object of overrides, got ${f===null?"null":typeof f}`};return {success:false,error:p,errors:[p]}}if(i==="missing"){let p={...u.data};for(let h in f)p[h]===void 0&&(p[h]=f[h]);return {success:true,data:p}}return {success:true,data:{...u.data,...f}}}),this},C(n,"_parse",(o,i,s)=>{let l=o(i,s),{abortEarly:c}=te(s);if(l.success===false)return l;let u={},f=[];for(let p in e){let h=e[p]._parse(l.data[p],s);if(h.success)u[p]=h.data;else {let m=ht(h,p,c,f);if(m)return m}}return f.length>0?{success:false,error:f[0],errors:f}:{success:true,data:u}}),r}function Ae(e){return _(U,{...e,type:"string"})}function Te(e){return _(Ne,{...e,type:"number"})}function we(e){return _(Re,{...e,type:"boolean"})}function Le(e){return _(bn,{...e,type:"date"})}function gt(e){return _(Cn,{...e,type:"function"})}function yt(e,t){let n=s=>e.includes(s),r=s=>`Invalid ${o} value. Expected ${e.map(l=>`"${l}"`).join(" | ")}, received "${s}".`,o="enum",i=_(n,{message:r,...t,type:o});return i._getDescription=()=>`enum(${e.map(s=>`"${s}"`).join(" | ")})`,i._getDefinition=()=>e,i}function Et(e,t){let n=_(Nn,{...t,type:"array"});return n._getDescription=()=>`array(${e._getDescription()})`,n._getDefinition=()=>e,C(n,"_parse",(r,o,i)=>{let s=r(o,i),{abortEarly:l}=te(i);if(s.success===false)return s;let c=[],u=[],f=i;for(let p=0;p<s.data.length;p++){let h={...f,context:{...f?.context,index:p}},m=e._parse(s.data[p],h);if(m.success)c.push(m.data);else {let S=ht(m,p,l,u);if(S)return S}}return u.length>0?{success:false,error:u[0],errors:u}:{success:true,data:c}}),n}function St(){return _(()=>true)}function F(e,t){return C(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=_(()=>false,{message:n,...t,type:"union"});return r._getDefinition=()=>e,C(r,"_parse",(o,i,s)=>{let l=s,c=[];for(let h=0;h<e.length;h++){let m=e[h]._parse(i,l);if(m.success)return m;c.push(m);}let{abortEarly:u}=te(l),f={message:typeof n=="function"?n(i):n};if(u!==false)return {success:false,error:f,errors:[f]};let p=[];for(let h=0;h<c.length;h++){let m=c[h].errors;if(m?.length)for(let S=0;S<m.length;S++)m[S].cause?.key&&p.push(ke(m[S],`branch ${h}`));}return p.length===0&&p.push(f),{success:false,error:p[0],errors:p}}),r}function bt(e,t){let n=_(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 Ct(e){let t=_(()=>true,{type:"contextRef"});return t._getDescription=()=>`contextRef("${e}")`,C(t,"_parse",(n,r,o)=>({success:true,data:o?.context?.[e]})),t}function Nt(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 Rt={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 U(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},we({...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(Re(n))return Number(n);if(U(n)){let r=n.trim();if(r==="")return n;let o=Number(r);if(Number.isFinite(o))return o}return n},Te({...e,message:t}))},string(e){let t=e?.message??(n=>`Cannot cast "${n}" to string. Expected a string, number, or boolean.`);return F(n=>Re(n)||Ne(n)&&Number.isFinite(n)?String(n):n,Ae({...e,message:t}))},date(e){let t=e?.message??(n=>`Cannot cast "${n}" to a valid date.`);return F(n=>{let r;return U(n)&&(r=n.trim()),Ne(n)&&Number.isFinite(n)||r?new Date(r??n):n},Le({...e,message:t}))},json(e,t){let n=t?.message??(r=>`Cannot parse "${r}" as JSON.`);return C(e,"_parse",(r,o,i)=>{if(U(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}},_t={},E={object:mt,string:Ae,number:Te,boolean:we,date:Le,function:gt,enum:yt,array:Et,any:St,preprocess:F,union:xt,literal:bt,contextRef:Ct,withContext:Nt,coerce:_t,cast:Rt};function pt(e){return t=>`The value "${t}" must be type of ${e} but is type of "${typeof t}".`}function C(e,t,n){let r=e[t];e[t]=(...o)=>n(r,...o);}function _(e,{type:t="any",name:n,message:r}={}){r=r||pt(t);let o={name:n,message:r,type:t},i={_getName(){return n},_getType(){return t},_getDescription(){return this._getName()??this._getType()},_parse(s,l){let c=e(s);if(c===true)return {success:true,data:s};if(typeof c=="object"&&c?.success===true)return c;let u={message:typeof r=="function"?r(s):r};return {success:false,error:u,errors:[u]}},parse(s,l){let c=this._parse(s,l);if(!c.success)throw c=c,new Error(c.error.message,{cause:c.error.cause});return c.data},safeParse(s,l){return this._parse(s,l)},transform(s){return C(this,"_parse",(l,c,u)=>{let f=l(c,u);return f.success&&(f.data=s(f.data)),f}),this},optional(){return Ce(this,s=>s===void 0),this},nullable(){return Ce(this,s=>s===null),this},nullish(){return Ce(this,s=>s==null),this},default(s){return C(this,"_parse",(l,c,u)=>(c===void 0&&(c=typeof s=="function"?s({context:u?.context}):s),l(c,u))),this},catch(s){return C(this,"_parse",(l,c,u)=>{let f=l(c,u);return f.success?f:{success:true,data:typeof s=="function"?s({input:c,error:f.error}):s}}),this},pipe(s){return C(this,"_parse",(l,c,u)=>{let f=l(c,u);return f.success?s._parse(f.data,u):f}),this},refine(s,{message:l,type:c,jsonSchema:u}={}){if(c&&(l=l||pt(c),t=c),u){let f=[...this._getJsonSchemaHints?.()??[],u];this._getJsonSchemaHints=()=>f;}return C(this,"_parse",(f,p,h)=>{let m=f(p,h),{abortEarly:S}=te(h);if(!m.success)return m;let k=s(m.data);if(k===true||typeof k=="object"&&k?.success===true)return m;let N={message:typeof l=="function"?l(p):l};return {success:false,error:N,errors:[N]}}),this},clone(){return {...this}}};return dt.length>0?dt.reduce((s,l)=>l(s,e,o)??s,i):i}var dt=[];function Rn(e,t){return String(e??t).trim().toLowerCase().replace(/\s+/g,"-")||String(t)}function _n({id:e,label:t,fallback:n=0}){return e??Rn(t,n)}var kt=E.object({id:E.string().optional(),label:E.string().optional(),keywords:E.array(E.string()).optional(),group:E.string().optional(),order:E.number().default(({context:e})=>e?.index??0),description:E.string().optional(),handler:E.function()}).derive(e=>{let t=_n({id:e.id,label:e.label,fallback:e.order}),n=String(e.label??e.id??`Action ${e.order}`),r=e.keywords?.length?e.keywords.map(String):[n,t];return {id:t,label:n,keywords:r,group:e.group??"actions",...e.description!=null&&e.description!==""?{description:String(e.description)}:{}}});var ne=class extends ee{normalize(t,n){if(!t||typeof t.handler!="function")return null;try{return kt.parse(t,{context:{index:n}})}catch{return null}}};function At(e,t){let n=e._getBlockElementState(t);return n?structuredClone(n):null}function kn(e,t){let n=e._getBlockElementByComponentId(t.baselineState?.componentId);return n||(e._getBlockElementIndex(t.blockElement)!==-1&&t.blockElement?.isConnected,t.blockElement)}function Tt(e){return e==null||e===""||/\s/.test(e)}function wt(e,t){if(typeof e!="string"||t<1)return null;let n=e.slice(0,t),r=-1;for(let o=n.length-1;o>=0;o--){let i=n[o];if(i==="/"){let s=o===0?null:n[o-1];if(s===null||/\s/.test(s)){r=o;break}return null}if(!/[\w]/.test(i))return null}return r<0?null:{slashStart:r,slashEnd:t,query:n.slice(r+1)}}function Lt(e,t){if(!e)return null;let n=t.inputType??"",r=t.data??null;return n==="insertText"||n==="insertCompositionText"||n==="insertReplacementText"?r==null||r===""?e:/\s/.test(r)||!/^[\w]+$/.test(r)?null:{...e,query:e.query+r,slashEnd:e.slashEnd+r.length}:n==="deleteContentBackward"||n==="deleteContentForward"||n==="deleteByCut"||n==="deleteByDrag"?e.slashEnd<=e.slashStart+1?null:{...e,query:e.query.slice(0,-1),slashEnd:e.slashEnd-1}:n==="insertFromPaste"||n==="insertFromDrop"?null:e}function ve(e){return typeof e?.handler=="function"}function vt(e,t){let n=String(t??"").trim().toLowerCase();return n?e.filter(r=>String(r.label??"").toLowerCase().includes(n)?true:(r.keywords??[]).some(i=>String(i).toLowerCase().includes(n))):e.slice()}function Bt(e,t,n,r){let{originalLineState:o}=xe(e,t),i=r&&P(r)?r:e,{newLineState:s}=xe(i,n);return {beforeState:o,afterState:s}}function Mt(e,t){let n=e._getBlockElementState(t);return n&&P(n)?n:null}function An(e,t=null){let n=e?.component,r=n?.NAMESPACE;if(!n||!r)return null;let o=I(t?.properties?.text??""),i=t?.properties?.inlineStyleRanges??[],s=t?.properties?.entityRanges??[],l={componentId:Z(),component:r,...e.settings?{settings:e.settings}:{}},c=at({properties:{text:o,inlineStyleRanges:i,entityRanges:s},settings:e.settings});return n.getStateSchema().parse({...n.fromExchangeState(c),...l})}function Ot(e,t){if(!ve(t))return;let{mrakomor:n,blockElement:r,slashStart:o,slashEnd:i,baselineState:s}=e;if(!s||!P(s)){t.handler(e);return}let l=Mt(n,r),{beforeState:c,afterState:u}=Bt(s,o,i,l),{state:f}=ut(c,u),p=I(c.properties?.text).length;n.command.replaceBlockElement({blockElement:r,blocks:[n.normalizeComponentState(f)],cursor:p}),t.handler(e);}function It(e,t){let{mrakomor:n,blockElement:r,slashStart:o,slashEnd:i,baselineState:s}=e,l=t?.component?.NAMESPACE;if(!l||!s||!P(s))return;let c=Mt(n,r),{beforeState:u,afterState:f}=Bt(s,o,i,c),p=I(u.properties?.text),h=I(f.properties?.text),m=!p&&!h,S=An(t,m?null:f);if(S){if(m){n.command.replaceBlockElement({blockElement:r,blocks:[S],cursor:0});return}n.command.insertBlockElement({blockElement:r,namespace:l,originalLineState:u,newLineState:S,cursor:0});}}function Pt(e,t){return {mrakomor:e,blockElement:kn(e,t),query:t.query,slashStart:t.slashStart,slashEnd:t.slashEnd,baselineState:t.baselineState,range:j()}}function $t(){return E.object({id:E.string(),group:E.string().default("general"),description:E.string().default(""),commands:E.array(E.string()).default([]),shortcuts:E.array(E.string()).default([])}).default({})}function Tn(e){return `/${(e.keywords?.[0]??e.label??e.id).toLowerCase()}`}function Dt(e){return $t().parse({id:e.id,group:e.group,description:e.description??e.label,commands:[Tn(e)],shortcuts:[]})}var wn={id:"slash.open",group:"blocks",description:"Open the slash command menu",commands:["/"],shortcuts:[]};function jt(e){let t=e.register.slashActions;if(t)for(let n of t.list())e.register.help.add(Dt(n));}function Ln({mrakomor:e}){e.register.slashActions=new ne(e);let t=null,n=null,r=[],o=0,i=false;function s(a){return vt([...e.register.blocks.list(),...e.register.slashActions.list()],a)}function l(){i=false,t=null,n=null,r=[],o=0,e.command.closeMenu?.();}function c(a){if(!t||!a)return;let d=Pt(e,t);ve(a)?Ot(d,a):It(d,a),l();}function u(a){if(!t)return;a&&(n=a),r=s(t.query),o=0;let d=i;i=true;let g={entries:r,anchorRect:n??void 0,highlightIndex:o,ariaLabel:"Slash commands",onSelect:c};d?e.command.updateMenu?.(g):e.command.openMenu?.(g);}function f(a,d,g,b,y){t={blockElement:a,slashStart:d,slashEnd:g,query:b,baselineState:At(e,a)},u(y);}function p(){let a=j();if(!a?.collapsed)return null;let d=rt(a),g=ot(a);if(!d||!g)return null;let b=g.textContent??"",y=Se(g,a.startContainer,a.startOffset);return {blockElement:d,selectable:g,text:b,cursor:y}}function h(a){let g=j()?.getBoundingClientRect?.();return (!g||g.width===0&&g.height===0)&&(g=a.getBoundingClientRect()),g}function m(a){return P(e._getBlockElementState(a))}function S(a){let d=wt(a.text,a.cursor);if(!d){i&&l();return}f(a.blockElement,d.slashStart,d.slashEnd,d.query,h(a.selectable));}function k(){let a=p();if(!a||!m(a.blockElement)||a.cursor<1||a.text[a.cursor-1]!=="/")return false;let d=a.cursor-1,g=d===0?null:a.text[d-1];return Tt(g)?(f(a.blockElement,d,d+1,"",h(a.selectable)),true):false}function N(a){let d=a.data??null,g=a.inputType??"";if(!t){if(d!=="/")return;k();return}if(g==="insertCompositionText"||g==="insertFromPaste"||g==="insertFromDrop"){let x=p();if(!x||x.blockElement!==t.blockElement){l();return}S(x);return}let b=g===""&&d!=null?{inputType:"insertText",data:d}:a,y=Lt(t,b);if(!y){l();return}t=y,u();}return {resolveConfig(a){return e.register.slashActions.add(a.slashActions??[]),jt(e),a},registerCommands(){e.register.help.add(wn),jt(e);},onKeyDown(a){if(i){if(a.key==="ArrowDown"){if(a.preventDefault(),!r.length)return;o=(o+1)%r.length,e.command.updateMenu?.({entries:r,highlightIndex:o,ariaLabel:"Slash commands",onSelect:c});return}if(a.key==="ArrowUp"){if(a.preventDefault(),!r.length)return;o=(o-1+r.length)%r.length,e.command.updateMenu?.({entries:r,highlightIndex:o,ariaLabel:"Slash commands",onSelect:c});return}if(a.key==="Enter"){a.preventDefault(),a.stopPropagation?.();let d=r[o];d&&c(d);return}a.key==="Escape"&&(a.preventDefault(),l());}},registerHandlers(){e.emitter.on(be.INPUT,N),e.emitter.on(be.CLOSE_MENU,()=>{i=false,t=null,n=null,r=[],o=0;});}}}exports.slashCommandPlugin=Ln;
|
package/dist/slashCommand.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a as a$2,b}from'./chunk-
|
|
1
|
+
import {a as a$2,b}from'./chunk-EXDY5TZH.mjs';import {a}from'./chunk-P7IKAZYZ.mjs';import {q,v as v$1,j as j$1,x,k as k$1}from'./chunk-D6K2L5O3.mjs';import {a as a$1}from'./chunk-B6JJAATK.mjs';import {k,e,g,p,a as a$3}from'./chunk-4WTPDNPA.mjs';import'./chunk-7CJLTNHZ.mjs';function X(e,t){return String(e??t).trim().toLowerCase().replace(/\s+/g,"-")||String(t)}function Z({id:e,label:t,fallback:n=0}){return e??X(t,n)}var O=a.object({id:a.string().optional(),label:a.string().optional(),keywords:a.array(a.string()).optional(),group:a.string().optional(),order:a.number().default(({context:e})=>e?.index??0),description:a.string().optional(),handler:a.function()}).derive(e=>{let t=Z({id:e.id,label:e.label,fallback:e.order}),n=String(e.label??e.id??`Action ${e.order}`),l=e.keywords?.length?e.keywords.map(String):[n,t];return {id:t,label:n,keywords:l,group:e.group??"actions",...e.description!=null&&e.description!==""?{description:String(e.description)}:{}}});var A=class extends a$2{normalize(t,n){if(!t||typeof t.handler!="function")return null;try{return O.parse(t,{context:{index:n}})}catch{return null}}};function N(e,t){let n=e._getBlockElementState(t);return n?structuredClone(n):null}function ee(e,t){let n=e._getBlockElementByComponentId(t.baselineState?.componentId);return n||(e._getBlockElementIndex(t.blockElement)!==-1&&t.blockElement?.isConnected,t.blockElement)}function H(e){return e==null||e===""||/\s/.test(e)}function z(e,t){if(typeof e!="string"||t<1)return null;let n=e.slice(0,t),l=-1;for(let o=n.length-1;o>=0;o--){let a=n[o];if(a==="/"){let c=o===0?null:n[o-1];if(c===null||/\s/.test(c)){l=o;break}return null}if(!/[\w]/.test(a))return null}return l<0?null:{slashStart:l,slashEnd:t,query:n.slice(l+1)}}function U(e,t){if(!e)return null;let n=t.inputType??"",l=t.data??null;return n==="insertText"||n==="insertCompositionText"||n==="insertReplacementText"?l==null||l===""?e:/\s/.test(l)||!/^[\w]+$/.test(l)?null:{...e,query:e.query+l,slashEnd:e.slashEnd+l.length}:n==="deleteContentBackward"||n==="deleteContentForward"||n==="deleteByCut"||n==="deleteByDrag"?e.slashEnd<=e.slashStart+1?null:{...e,query:e.query.slice(0,-1),slashEnd:e.slashEnd-1}:n==="insertFromPaste"||n==="insertFromDrop"?null:e}function L(e){return typeof e?.handler=="function"}function $(e,t){let n=String(t??"").trim().toLowerCase();return n?e.filter(l=>String(l.label??"").toLowerCase().includes(n)?true:(l.keywords??[]).some(a=>String(a).toLowerCase().includes(n))):e.slice()}function j(e,t,n,l){let{originalLineState:o}=x(e,t),a=l&&q(l)?l:e,{newLineState:c}=x(a,n);return {beforeState:o,afterState:c}}function K(e,t){let n=e._getBlockElementState(t);return n&&q(n)?n:null}function te(e,t=null){let n=e?.component,l=n?.NAMESPACE;if(!n||!l)return null;let o=j$1(t?.properties?.text??""),a=t?.properties?.inlineStyleRanges??[],c=t?.properties?.entityRanges??[],u={componentId:a$3(),component:l,...e.settings?{settings:e.settings}:{}},p=k$1({properties:{text:o,inlineStyleRanges:a,entityRanges:c},settings:e.settings});return n.getStateSchema().parse({...n.fromExchangeState(p),...u})}function V(e,t){if(!L(t))return;let{mrakomor:n,blockElement:l,slashStart:o,slashEnd:a,baselineState:c}=e;if(!c||!q(c)){t.handler(e);return}let u=K(n,l),{beforeState:p,afterState:d}=j(c,o,a,u),{state:h}=v$1(p,d),S=j$1(p.properties?.text).length;n.command.replaceBlockElement({blockElement:l,blocks:[n.normalizeComponentState(h)],cursor:S}),t.handler(e);}function Y(e,t){let{mrakomor:n,blockElement:l,slashStart:o,slashEnd:a,baselineState:c}=e,u=t?.component?.NAMESPACE;if(!u||!c||!q(c))return;let p=K(n,l),{beforeState:d,afterState:h}=j(c,o,a,p),S=j$1(d.properties?.text),C=j$1(h.properties?.text),k=!S&&!C,E=te(t,k?null:h);if(E){if(k){n.command.replaceBlockElement({blockElement:l,blocks:[E],cursor:0});return}n.command.insertBlockElement({blockElement:l,namespace:u,originalLineState:d,newLineState:E,cursor:0});}}function v(e,t){return {mrakomor:e,blockElement:ee(e,t),query:t.query,slashStart:t.slashStart,slashEnd:t.slashEnd,baselineState:t.baselineState,range:k()}}function ne(e){return `/${(e.keywords?.[0]??e.label??e.id).toLowerCase()}`}function G(e){return b().parse({id:e.id,group:e.group,description:e.description??e.label,commands:[ne(e)],shortcuts:[]})}var re={id:"slash.open",group:"blocks",description:"Open the slash command menu",commands:["/"],shortcuts:[]};function J(e){let t=e.register.slashActions;if(t)for(let n of t.list())e.register.help.add(G(n));}function le({mrakomor:e$1}){e$1.register.slashActions=new A(e$1);let t=null,n=null,l=[],o=0,a=false;function c(r){return $([...e$1.register.blocks.list(),...e$1.register.slashActions.list()],r)}function u(){a=false,t=null,n=null,l=[],o=0,e$1.command.closeMenu?.();}function p$1(r){if(!t||!r)return;let s=v(e$1,t);L(r)?V(s,r):Y(s,r),u();}function d(r){if(!t)return;r&&(n=r),l=c(t.query),o=0;let s=a;a=true;let i={entries:l,anchorRect:n??void 0,highlightIndex:o,ariaLabel:"Slash commands",onSelect:p$1};s?e$1.command.updateMenu?.(i):e$1.command.openMenu?.(i);}function h(r,s,i,y,g){t={blockElement:r,slashStart:s,slashEnd:i,query:y,baselineState:N(e$1,r)},d(g);}function S(){let r=k();if(!r?.collapsed)return null;let s=e(r),i=g(r);if(!s||!i)return null;let y=i.textContent??"",g$1=p(i,r.startContainer,r.startOffset);return {blockElement:s,selectable:i,text:y,cursor:g$1}}function C(r){let i=k()?.getBoundingClientRect?.();return (!i||i.width===0&&i.height===0)&&(i=r.getBoundingClientRect()),i}function k$1(r){return q(e$1._getBlockElementState(r))}function E(r){let s=z(r.text,r.cursor);if(!s){a&&u();return}h(r.blockElement,s.slashStart,s.slashEnd,s.query,C(r.selectable));}function Q(){let r=S();if(!r||!k$1(r.blockElement)||r.cursor<1||r.text[r.cursor-1]!=="/")return false;let s=r.cursor-1,i=s===0?null:r.text[s-1];return H(i)?(h(r.blockElement,s,s+1,"",C(r.selectable)),true):false}function W(r){let s=r.data??null,i=r.inputType??"";if(!t){if(s!=="/")return;Q();return}if(i==="insertCompositionText"||i==="insertFromPaste"||i==="insertFromDrop"){let B=S();if(!B||B.blockElement!==t.blockElement){u();return}E(B);return}let y=i===""&&s!=null?{inputType:"insertText",data:s}:r,g=U(t,y);if(!g){u();return}t=g,d();}return {resolveConfig(r){return e$1.register.slashActions.add(r.slashActions??[]),J(e$1),r},registerCommands(){e$1.register.help.add(re),J(e$1);},onKeyDown(r){if(a){if(r.key==="ArrowDown"){if(r.preventDefault(),!l.length)return;o=(o+1)%l.length,e$1.command.updateMenu?.({entries:l,highlightIndex:o,ariaLabel:"Slash commands",onSelect:p$1});return}if(r.key==="ArrowUp"){if(r.preventDefault(),!l.length)return;o=(o-1+l.length)%l.length,e$1.command.updateMenu?.({entries:l,highlightIndex:o,ariaLabel:"Slash commands",onSelect:p$1});return}if(r.key==="Enter"){r.preventDefault(),r.stopPropagation?.();let s=l[o];s&&p$1(s);return}r.key==="Escape"&&(r.preventDefault(),u());}},registerHandlers(){e$1.emitter.on(a$1.INPUT,W),e$1.emitter.on(a$1.CLOSE_MENU,()=>{a=false,t=null,n=null,l=[],o=0;});}}}export{le as slashCommandPlugin};
|
package/dist/tooltip.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use strict';(function(){if(!(typeof document>"u")){var e="mrakomor/core/plugin/tooltip/Tooltip.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-tooltip{position:absolute;z-index:9100;display:flex;flex-direction:row;align-items:center;gap:2px;background:#1a1a1a;border-radius:6px;padding:4px 6px;box-shadow:0 3px 10px #00000040;pointer-events:all;white-space:nowrap}.mrakomor-tooltip__btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;border-radius:4px;color:#fff;cursor:pointer;font-size:13px;font-weight:600;min-width:28px;min-height:28px;padding:0 6px;transition:background .1s}.mrakomor-tooltip__btn:hover{background:#ffffff26}.mrakomor-tooltip__btn--active{background:#ffffff40;color:#7dd3fc}.mrakomor-tooltip__separator{width:1px;height:18px;background:#fff3;margin:0 4px;flex-shrink:0}
|
|
2
|
-
`,document.head.appendChild(n);}}})();var Pe=class{next(...e){}error(...e){}complete(...e){}},de=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 W=Symbol("@esmj/signals:type"),G=Symbol("@esmj/signals:name");var _=null,ge=false,me=[];function j(e){let t=_;_=null;let n=e();return _=t,n}function Nt(){ge=false;let e=$e();for(let n of e)n.get();let t=me;me=[];for(let n of t)n();}function je(){ge||(ge=true,queueMicrotask(Nt));}function he(e){me.push(e),je();}var De=Symbol("@esmj/signals:internal observable"),w=Symbol("@esmj/signals:original function"),Tt=class extends de{#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=()=>j(()=>{this.#e.add(e),this.#o();}),e.next[w]=void 0),e instanceof qe&&e.next[w]===void 0){let t=e.next.bind(e);e.next=()=>j(()=>{this.#e.add(e),t(),this.#o();}),e.next[w]=t;}return this.subscribe(e)}getPending(){let e=[];for(let t of this.#e){if(!t.get[w]){let n=t.get,o=n.bind(t);t.get=()=>j(()=>(this.#e.delete(t),o())),t.get[w]=n;}e.push(t);}return e}unwatch(e){return e.next=e.next[w]?e.next[w]:e.next,e.get=e.get[w]?e.get[w]:e.get,this.#e.delete(e),this.unsubscribe(e)}},X=null;function Fe(e){X=new Tt(e);}Fe(()=>{je();});function $e(){return X.getPending()}function Ke(e){return X.watch(e)}function Ge(e){return X.unwatch(e)}var O=Symbol("@esmj/signals:no error"),qe=class Ve extends Pe{#e=true;#o=false;#n=null;#r=this.#p();#u=null;#c=null;#i=0;#s=new Map;#t=O;constructor(t,n){super(),this.#u=t,this.#c=n,this.debug=n?.debug,this[W]="computed",this[G]=n?.debug??null,this.get=this.get.bind(this);}#a(){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[G],dirty:this.#e,revision:this.#i,sourceDependencies:[...this.#s.keys()]}}#f(){for(let[t,n]of this.#s)if(t instanceof Ve&&j(()=>t.get()),t.getRevision()!==n)return true;return false}next(){this.#e=true,this.#n[De].next();}get(){if(this.#o)throw new Error("Cycle detected in computed signal");if(this.#n||(this.#n=k(this.#l(),this.#c)),(this.#e||this.#t!==O)&&(this.#s.size===0||this.#f()?this.#l():this.#e=false),_&&_.sourceRevisions.set(this,this.#i),this.#t!==O)throw this.#t;return this.#n.get()}peek(){if(this.#n||(this.#n=k(this.#l(),this.#c)),(this.#e||this.#t!==O)&&(this.#s.size===0||this.#f()?this.#l():this.#e=false),this.#t!==O)throw this.#t;return this.#n.peek()}#l(){this.#o=true,this.#e=false,this.#t=O,this.#a(),this.#r.sourceRevisions.clear();let t=_;_=this.#r;let n;try{n=this.#u();}catch(o){this.#t=o;}return _=t,this.#s=this.#r.sourceRevisions,this.#r.sourceRevisions=new Map,this.#o=false,n instanceof Promise&&(n=n.then(o=>{this.#t=O,this.#n.set(o);}).catch(o=>{this.#t=o;})),this.#t===O&&this.#n&&this.#n.set(n),this.#i++,n}destroy(){this.#a(),this.#s.clear(),this.#e=true,this.#t=O;}};function A(e,t){return new qe(e,t)}function L(e,t){let n,{debug:o,...r}={},s=A(()=>{n?.(),n=e();},{equals:()=>false,...r});s.get(),Ke(s);let i=()=>{n?.(),s.destroy(),Ge(s);};return i[Symbol.dispose]=i,i[W]="effect",i[G]=o??null,i.__RX_COMPUTED__=s,i}function k(e,t={}){let n=t?.equals??Object.is,o=0,r=new de;function s(){return _&&(_.dependencies.set(r,r.subscribe(_.observer)),_.sourceRevisions.set(f,o)),e}function i(){return e}function l(d){if(!n(e,d)){e=d,o++,r.next();}return e}function c(){return o}let f={get:s,set:l,peek:i,getRevision:c,[De]:r,[W]:"signal",[G]:t?.debug??null};return f}function z(){return Date.now().toString(32).substring(5)+Math.random().toString(32).substring(2)}var Ze=Symbol("node-component"),J=Symbol("node-internal"),et=Symbol("keep-literal"),oe=Symbol("raw-props");function xe(e){let t=()=>e;return t[et]=true,t}function Re(e){let t=null,n=()=>t,o=s=>(t=s??null,t),r={get:n,set:o,[Symbol.toPrimitive](){return t?String(t):""}};return Object.defineProperty(r,"current",{get(){return t},set(s){o(s);},enumerable:true,configurable:false}),new Proxy(r,{get(s,i,l){if(Reflect.has(s,i))return Reflect.get(s,i,l);if(!t)return;let c=t[i];return typeof c=="function"?c.bind(t):c},set(s,i,l,c){return Reflect.has(s,i)||!t?Reflect.set(s,i,l,c):(t[i]=l,true)},has(s,i){return Reflect.has(s,i)||!!t&&i in t}})}var tt=null;function D(){return tt}function Q(e){tt=e;}function re(e){return e?.[Ze]||null}function He(e,t){e[Ze]=t;}function Z(e,t={disposers:[],id:z()}){return e?.[J]?e[J]:(e&&(e[J]=t),t)}function Lt(e){return e[J]}function v(e,t){let n=Lt(e);n||(n=Z(e)),n.disposers.push(t);}function ee(e,t,n){e.has(t)||e.set(t,[]),e.get(t).push(n);}function B(e,t){let n=D();Q(e);try{return t()}finally{Q(n);}}var te=new Map,ne=new Map,Ue=new Map;function nt(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?.[et]?o[r]=s():s!=null&&typeof s.get=="function"?o[r]=s:typeof s=="function"?o[r]=A(s):o[r]=k(s);}return o}function Ne(e){let t=D();if(!t){console.warn("onMount called outside of a component context");return}ee(te,t.id,e);}function ie(e){he(()=>{setTimeout(e,0);});}function $(e){let t=e.componentId,n=te.get(t);if(n){te.delete(t);for(let o of n){let r=o();typeof r=="function"&&ee(ne,t,r);}}}function At(e){let t=ne.get(e);if(t){ne.delete(e);for(let n of t)n();}}function wt(e){let t=Ue.get(e);if(t){Ue.delete(e);for(let n of t)n();}}function le(e){if(!e)return;let t=Z(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=re(e);if(n&&(At(n.componentId),wt(n.componentId)),e.childNodes){let o=e.firstChild;for(;o;){let r=o.nextSibling;le(o),o=r;}}}function P(e){return e!=null&&typeof e=="object"&&typeof e.$constructor=="function"}function Ye(e){return typeof e=="function"&&typeof e.prototype?.render=="function"}function Ot(e,t,n){let o=z(),r={componentId:o,$children:n,element:null,classInstance:null,$constructor(){let s=Ye(e)?void 0:e[oe],i={...nt(t??{},s),children:n},l=D(),c={disposers:[],id:o,contexts:new Map(l?.contexts)};Q(c);let f;if(Ye(e)){r.ClassConstructor=e;let E=new e(i);r.classInstance=E,typeof E.onMount=="function"&&ee(te,o,()=>{E.onMount?.();}),typeof E.onUnmount=="function"&&ee(ne,o,()=>{E.onUnmount?.();}),f=E.render();}else f=e(i);Q(l);let d=vt(f);if(r.element=d,d instanceof DocumentFragment&&d.childNodes.length)for(let E of d.childNodes)Z(E,c),He(E,r);else Z(d,c),d instanceof Node&&He(d,r);return d}};return r}function Te(e,t){let n=t.$constructor();n instanceof Node&&e.appendChild(n),queueMicrotask(()=>{$(t);});}function vt(e){return e instanceof Node?e:P(e)?e.$constructor():typeof e=="string"||typeof e=="number"?document.createTextNode(String(e)):document.createTextNode("")}var We={className:"class",htmlFor:"for"},Xe=new Set(["value","defaultValue","checked","selected","indeterminate"]),Mt=new Set(["srcdoc"]),It=new Set(["href","src","action","formaction","xlink:href"]),Bt=new Set(["securitypolicyviolation"]),Pt=new Set(["contenteditable","draggable","spellcheck"]);function V(e){return e!=null&&typeof e=="object"&&typeof e.get=="function"&&!(e instanceof Node)}var ot=Symbol("Fragment");function M(e,t,n){if(e===ot){let r=document.createDocumentFragment();return Ee(r,Je(n)),r}if(typeof e=="function")return Ot(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),ce(o,t),Ee(o,Je(n)),o}function ye(e,t){t instanceof DocumentFragment?e.replaceChildren(t):e.innerHTML=t??"";}function jt(e){return typeof e!="string"?false:e.replace(/[\p{White_Space}\p{Cc}]+/gu,"").toLowerCase().startsWith("javascript:")}function Dt(e,t){if(typeof e!="string")return false;let n=e.toLowerCase();return Mt.has(n)?true:It.has(n)&&t!==null&&t!==void 0&&jt(String(t))}function rt(e){return typeof e!="string"?e:We[e]?We[e]:e}function Ft(e,t){let n=rt(e),o=typeof n=="string"?n.toLowerCase():String(n).toLowerCase();return Pt.has(o)&&(t===true||t===false||t==="true"||t==="false")?String(t):t==null||t===false?null:t}function ze(e,t,n){let o=Ft(t,n);if(o===null){e.removeAttribute(t);return}if(Dt(t,o)){e.removeAttribute(t),console.warn(`[esmj-dom] Blocked unsafe attribute "${String(t)}" on <${e.tagName.toLowerCase()}>`);return}e.setAttribute(t,o);}function ce(e,t){let n=D();for(let[o,r]of Reflect.ownKeys(t).map(s=>[s,t[s]]))if(o!=="id"){if(o=rt(o),o==="$ref"){typeof r=="function"?r(e):typeof r=="object"&&r!==null&&(r.current=e);continue}if(o==="$dangerouslySetInnerHTML"){if(V(r)){let s=L(()=>{B(n,()=>{ye(e,r.get());});});v(e,s);}else if(typeof r=="function"){let s=L(()=>{B(n,()=>{ye(e,r());});});v(e,s);}else ye(e,r);continue}if(o==="style"){if(V(r)){let s=L(()=>{B(n,()=>{Object.assign(e.style,r.get());});});v(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(Bt.has(s)){console.warn(`[esmj-dom] Blocked unsafe event binding "${o}" on <${e.tagName.toLowerCase()}>`);continue}e.addEventListener(s,r);continue}if(V(r)||typeof r=="function"){let s=o,i=L(()=>{B(n,()=>{let l=typeof r=="function"?r():r.get();Xe.has(s)?e[s]=l??"":ze(e,s,l);});});v(e,i);continue}Xe.has(o)||typeof o=="symbol"?e[o]=r??"":ze(e,o,r);}}function Je(e){return e==null?[]:Array.isArray(e)?e.flat(Number.POSITIVE_INFINITY):[e]}function Ee(e,t){for(let n of t)st(e,n);}function st(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"){Qe(e,t);return}if(P(t)){Te(e,t);return}if(V(t)){Qe(e,()=>t.get());return}if(Array.isArray(t)){Ee(e,t);return}e.appendChild(document.createTextNode(String(t)));}}function K(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 ue(e,t=true){for(let n of e)t&&le(n),n.remove();}function Qe(e,t){let n=D(),o=document.createComment("");e.appendChild(o);let r=[],s=L(()=>{B(n,()=>{let i=t(),{nodes:l,instance:c}=K(i);ue(r),l.length&&o.after(...l),c&&queueMicrotask(()=>$(c)),r=l;});});v(e,s);}function _e(e,t){if(typeof e=="string"&&(e=document.querySelector(e)),!e)throw new Error("mount: container not found");e instanceof DocumentFragment||(le(e),e.innerHTML=""),P(t)?Te(e,t):t instanceof Node?e.appendChild(t):e.appendChild(document.createTextNode(String(t)));}function ct(e,t){let n=null;if(P(t)?(n=t.$constructor(),queueMicrotask(()=>$(t))):t instanceof Node?n=t:n=document.createTextNode(String(t)),n instanceof HTMLElement){let o=A(()=>!!e()),r=L(()=>{n.style.display=o.get()?"":"none";});v(n,r);}return n}Array.from({length:256},(e,t)=>(t<=15?"0":"")+t.toString(16));var at=Symbol("block-element"),Gt=Symbol("block-element-body"),ae=Symbol("selectable-element");function Ae(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 we(e){return e?Ae(e.startContainer,at):null}function ft(e){return e?Ae(e.startContainer,ae):null}function Oe(e){return Ae(e,ae)}function qt(e){return e?e[ae]!==void 0?[e]:[...e.children].filter(t=>t[ae]!==void 0):[]}function Vt(e,t){return t?qt(e).indexOf(t):-1}function pt(e,t){let n=ft(t);return !n||!e?.contains(n)?null:{element:n,index:Vt(e,n)}}function dt(){return window.getSelection()}function fe(){let e=dt();return e.rangeCount>0?e.getRangeAt(0).cloneRange():null}var ke=null;function ve(){ke=Me();}function gt(){ke&&Ie(ke);}function Ht(e,t){let n=ft(t);return n||(U(e)??e?.childNodes?.[0]??null)}function H(e,t,n){if(!e)return 0;if(t===e){if(t.nodeType===Node.TEXT_NODE)return n;let i=0,l=e.childNodes,c=Math.min(n,l.length);for(let f=0;f<c;f++)i+=l[f].textContent.length;return i}if(t.nodeType===Node.ELEMENT_NODE&&!e.contains(t))return 0;let o=0,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=r.nextNode();for(;s;){if(s===t)return o+n;o+=s.textContent.length,s=r.nextNode();}return o}function Me(){let e=fe();if(!e)return null;let t=we(e),n=Ht(t,e);return {start:H(n,e.startContainer,e.startOffset),end:H(n,e.endContainer,e.endOffset),element:t,selectableElement:n}}function Ie(e){if(!e)return;let{start:t,end:n,element:o,selectableElement:r}=e,s=r?.isConnected&&r||U(o)||o?.childNodes?.[0];if(!s)return;let i=ut(s,t),l=ut(s,n),c=document.createRange();c.setStart(i.startContainer,i.startOffset),c.setEnd(l.endContainer,l.endOffset);let f=dt();f.removeAllRanges(),f.addRange(c);}function ut(e,t){let n=document.createRange();if(!e)return n;if(t<=0)return n.setStart(e,0),n.collapse(true),n;let o=0,r=[e];for(;r.length>0;){let s=r.pop();if(s.nodeType===Node.TEXT_NODE){let i=s.textContent.length;if(o+i>=t)return n.setEnd(s,t-o),n.setStart(s,t-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(e,e.childNodes.length),n.setStart(e,e.childNodes.length),n}function U(e){if(!e)return null;let t=Ut(e);return t?.firstElementChild??t?.firstChild}function mt(e){if(!e?.[at])return null;let t=U(e);return t?re(t)?.classInstance:null}function Ut(e){if(!e)return null;for(let t of e.children)if(t[Gt])return t;return null}function ht(e,t,n,o=12){let r=e.getBoundingClientRect(),s=typeof t?.getBoundingClientRect=="function"?t.getBoundingClientRect():t??{left:0,top:0},i=n?.offsetHeight??40;return {x:s.left-r.left,y:s.top-r.top-i-o}}function yt(e,t,n){let o=e._getBlockElementState(t);if(!o)return null;let r=e.register.blocks.getByNamespace(o.component);if(!r)return null;let s=r.toExchangeState(o)?.properties?.items??[];if(!s.length)return null;let i=U(t),l=pt(i,n),c=l?.element??i??t,f=l?.index??0,d=s[f];return d?{Constructor:r,current:o,element:c,itemIndex:f,item:d}:null}function Et(e,t){let n=H(e,t.startContainer,t.startOffset),o=H(e,t.endContainer,t.endOffset);return {offset:n,length:Math.max(0,o-n)}}function Yt(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=_e(s,o);return {container:s,dispose:i??null}}function St(e,t,n){return Yt(e,".mrakomor-tools-container",t,n)}var N={KEYDOWN:"mrakomor:keydown",CLICK:"mrakomor:click",SELECTION_CHANGE:"mrakomor:selection-change"};function bt({mrakomor:e,open:t,tooltipElement:n}){let o=k(0),r=k(0),s=k([]),i=null,l=null;function c(){t.set(false),i=null,l=null;}Ne(()=>{let d=e.emitter.on(N.OPEN_TOOLTIP,({element:p,actions:g})=>{i=p,l=Me(),s.set(g??[]),t.set(true),ie(()=>{let{x:y,y:R}=ht(e.getRoot(),p,n);o.set(y),r.set(R);});}),E=e.emitter.on(N.CLOSE_TOOLTIP,c),a=e.emitter.on(N.KEYDOWN,()=>{t.peek()===true&&c();}),S=e.emitter.on(N.CLICK,p=>{if(t.peek()!==true||!n.current||!i)return;let g=p.target;if(!(g instanceof Node)){c();return}n.current.contains(g)||i.contains(g)||g instanceof Element&&g.contains(n.current)||c();});return ()=>{d(),E(),a(),S();}});let f=A(()=>({left:`${o.get()}px`,top:`${r.get()}px`}));return ct(()=>t.get(),M("div",{className:"mrakomor-tooltip",contenteditable:false,style:f,$ref:n},()=>Wt(s.get(),e,l)))}function Wt(e,t,n){if(!e.length)return null;let o=null,r=[];for(let s of e){o!==null&&s.group!==o&&r.push(M("span",{className:"mrakomor-tooltip__separator"})),o=s.group;let i=s.label,l=typeof i=="string"?i:typeof i=="function"?M(i,{}):i;r.push(M("button",{type:"button",className:["mrakomor-tooltip__btn",s.active?.()?"mrakomor-tooltip__btn--active":""].filter(Boolean).join(" "),title:s.title??"",onClick:c=>{c.preventDefault(),Ie(n),s.onAction(t);}},l));}return M("span",{style:"display: contents"},r)}function Xt({mrakomor:e}){let n=false,o=null,r=k(false),s=Re();function i(){let a=e.getConfig();return {inlineStyles:a.inlineStyles,entityRanges:a.entityRanges,blockTransforms:e.register.blocks.list()}}function l(a,S){let p=yt(e,a,S);if(!p)return null;let{element:g,item:y}=p;return y.inlineStyleRanges===void 0&&y.entityRanges===void 0?null:[{element:g,inlineStyleRanges:y.inlineStyleRanges??[],entityRanges:y.entityRanges??[]}]}function c(a,S,p,g){let y=[],R=e.getConfig()?.inlineStyles??[],C=e.getConfig()?.entityRanges??[],x=(S?.length?S:[{element:p,inlineStyleRanges:[],entityRanges:[]}]).map(u=>{let{offset:m,length:h}=Et(u.element??p,g);return {item:u,selStart:m,selEnd:m+h}});for(let u of a.inlineStyles){let m=typeof u=="string"?u:u.style,h=R.find(I=>I.style===m);if(!h)continue;let T=x.some(({item:I,selStart:pe,selEnd:Y})=>(I.inlineStyleRanges??[]).some(F=>F.style===m&&F.offset<Y&&F.offset+F.length>pe));y.push({label:h.LABEL??m,title:m.charAt(0)+m.slice(1).toLowerCase(),group:"inline",active:()=>T,onAction:I=>{ve(),I.command.insertInlineStyleRange({style:h.style}),ie(()=>{gt();});}});}for(let u of a.entityRanges){let m=typeof u=="string"?u:u.NAMESPACE,h=C.find(T=>T.NAMESPACE===m);h&&y.push({label:h.LABEL??"\u{1F517}",title:h.NAMESPACE,group:"inline",active:()=>false,onAction:T=>{ve(),T.command.insertEntityRange({namespace:h.NAMESPACE,blockElement:p});}});}return y}function f(a){return {label:a.LABEL??a.NAMESPACE,title:a.LABEL??a.NAMESPACE,group:"transform",active:()=>true,onAction:()=>{}}}function d(a,S,p,g){let y=[],R=new Set;for(let C of a.blockTransforms){let b=typeof C=="string"?C:C?.component?.NAMESPACE??C?.NAMESPACE;if(!b||R.has(b)||(R.add(b),b===p.NAMESPACE))continue;let x=e.resolveComponentConstructor(b);x&&y.push({label:x.LABEL??b,title:`Convert to ${x.LABEL??b}`,group:"transform",active:()=>false,onAction:u=>{u.command.transformBlockElement({blockElement:S,namespace:b,range:g});}});}return y}function E(){if(n)return;let a=window.getSelection(),S=e.getRoot();if(!a||a.rangeCount===0){e.command.closeTooltip();return}let p=fe();if(!S.contains(p.commonAncestorContainer)){e.command.closeTooltip();return}if(p.startContainer===s.current&&r.peek()===true)return;let g=we(p);if(!g){e.command.closeTooltip();return}let y=mt(g),R=e._getBlockElementState(g);if(!y||!R){e.command.closeTooltip();return}let C=y.constructor;if(p.collapsed){e.command.closeTooltip();return}let b=Oe(p.startContainer),x=Oe(p.endContainer);if(!b||!x||b!==x){e.command.closeTooltip();return}let u=i(),m=l(g,p),h=[f(C),...d(u,g,C,p),...c(u,m,g,p)];if(h.length===0){e.command.closeTooltip();return}e.command.openTooltip({element:g,actions:h});}return {registerEvents(){N.OPEN_TOOLTIP="mrakomor:open-tooltip",N.CLOSE_TOOLTIP="mrakomor:close-tooltip";},registerCommands(a){a.command.openTooltip=(S,p)=>{a.emit(N.OPEN_TOOLTIP,{...S,options:p});},a.command.closeTooltip=S=>{a.emit(N.CLOSE_TOOLTIP,{options:S});};},registerListeners(){e.emitter.on(N.SELECTION_CHANGE,E),N.OPEN_DIALOG&&e.emitter.on(N.OPEN_DIALOG,()=>{n=true,r.peek()===true&&e.command.closeTooltip();}),N.CLOSE_DIALOG&&e.emitter.on(N.CLOSE_DIALOG,()=>{n=false;});},onMount(){let{dispose:a}=St(e,"mrakomor-tooltip-plugin-container",M(bt,{mrakomor:xe(e),tooltipElement:s,open:r}));o=a;},onUnmount(){o?.(),o=null;}}}exports.Tooltip=bt;exports.tooltipPlugin=Xt;
|
|
2
|
+
`,document.head.appendChild(n);}}})();var je=class{next(...e){}error(...e){}complete(...e){}},de=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 X=Symbol("@esmj/signals:type"),G=Symbol("@esmj/signals:name");var k=null,ge=false,me=[];function j(e){let t=k;k=null;let n=e();return k=t,n}function Nt(){ge=false;let e=Ke();for(let n of e)n.get();let t=me;me=[];for(let n of t)n();}function De(){ge||(ge=true,queueMicrotask(Nt));}function he(e){me.push(e),De();}var Fe=Symbol("@esmj/signals:internal observable"),w=Symbol("@esmj/signals:original function"),Tt=class extends de{#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=()=>j(()=>{this.#e.add(e),this.#o();}),e.next[w]=void 0),e instanceof Ve&&e.next[w]===void 0){let t=e.next.bind(e);e.next=()=>j(()=>{this.#e.add(e),t(),this.#o();}),e.next[w]=t;}return this.subscribe(e)}getPending(){let e=[];for(let t of this.#e){if(!t.get[w]){let n=t.get,o=n.bind(t);t.get=()=>j(()=>(this.#e.delete(t),o())),t.get[w]=n;}e.push(t);}return e}unwatch(e){return e.next=e.next[w]?e.next[w]:e.next,e.get=e.get[w]?e.get[w]:e.get,this.#e.delete(e),this.unsubscribe(e)}},z=null;function $e(e){z=new Tt(e);}$e(()=>{De();});function Ke(){return z.getPending()}function Ge(e){return z.watch(e)}function qe(e){return z.unwatch(e)}var O=Symbol("@esmj/signals:no error"),Ve=class He extends je{#e=true;#o=false;#n=null;#r=this.#p();#u=null;#c=null;#i=0;#s=new Map;#t=O;constructor(t,n){super(),this.#u=t,this.#c=n,this.debug=n?.debug,this[X]="computed",this[G]=n?.debug??null,this.get=this.get.bind(this);}#a(){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[G],dirty:this.#e,revision:this.#i,sourceDependencies:[...this.#s.keys()]}}#f(){for(let[t,n]of this.#s)if(t instanceof He&&j(()=>t.get()),t.getRevision()!==n)return true;return false}next(){this.#e=true,this.#n[Fe].next();}get(){if(this.#o)throw new Error("Cycle detected in computed signal");if(this.#n||(this.#n=_(this.#l(),this.#c)),(this.#e||this.#t!==O)&&(this.#s.size===0||this.#f()?this.#l():this.#e=false),k&&k.sourceRevisions.set(this,this.#i),this.#t!==O)throw this.#t;return this.#n.get()}peek(){if(this.#n||(this.#n=_(this.#l(),this.#c)),(this.#e||this.#t!==O)&&(this.#s.size===0||this.#f()?this.#l():this.#e=false),this.#t!==O)throw this.#t;return this.#n.peek()}#l(){this.#o=true,this.#e=false,this.#t=O,this.#a(),this.#r.sourceRevisions.clear();let t=k;k=this.#r;let n;try{n=this.#u();}catch(o){this.#t=o;}return k=t,this.#s=this.#r.sourceRevisions,this.#r.sourceRevisions=new Map,this.#o=false,n instanceof Promise&&(n=n.then(o=>{this.#t=O,this.#n.set(o);}).catch(o=>{this.#t=o;})),this.#t===O&&this.#n&&this.#n.set(n),this.#i++,n}destroy(){this.#a(),this.#s.clear(),this.#e=true,this.#t=O;}};function L(e,t){return new Ve(e,t)}function A(e,t){let n,{debug:o,...r}={},s=L(()=>{n?.(),n=e();},{equals:()=>false,...r});s.get(),Ge(s);let i=()=>{n?.(),s.destroy(),qe(s);};return i[Symbol.dispose]=i,i[X]="effect",i[G]=o??null,i.__RX_COMPUTED__=s,i}function _(e,t={}){let n=t?.equals??Object.is,o=0,r=new de;function s(){return k&&(k.dependencies.set(r,r.subscribe(k.observer)),k.sourceRevisions.set(f,o)),e}function i(){return e}function l(d){if(!n(e,d)){e=d,o++,r.next();}return e}function c(){return o}let f={get:s,set:l,peek:i,getRevision:c,[Fe]:r,[X]:"signal",[G]:t?.debug??null};return f}function J(){return Date.now().toString(32).substring(5)+Math.random().toString(32).substring(2)}var et=Symbol("node-component"),Q=Symbol("node-internal"),tt=Symbol("keep-literal"),re=Symbol("raw-props");function xe(e){let t=()=>e;return t[tt]=true,t}function Re(e){let t=null,n=()=>t,o=s=>(t=s??null,t),r={get:n,set:o,[Symbol.toPrimitive](){return t?String(t):""}};return Object.defineProperty(r,"current",{get(){return t},set(s){o(s);},enumerable:true,configurable:false}),new Proxy(r,{get(s,i,l){if(Reflect.has(s,i))return Reflect.get(s,i,l);if(!t)return;let c=t[i];return typeof c=="function"?c.bind(t):c},set(s,i,l,c){return Reflect.has(s,i)||!t?Reflect.set(s,i,l,c):(t[i]=l,true)},has(s,i){return Reflect.has(s,i)||!!t&&i in t}})}var nt=null;function D(){return nt}function Z(e){nt=e;}function se(e){return e?.[et]||null}function Ue(e,t){e[et]=t;}function ee(e,t={disposers:[],id:J()}){return e?.[Q]?e[Q]:(e&&(e[Q]=t),t)}function At(e){return e[Q]}function v(e,t){let n=At(e);n||(n=ee(e)),n.disposers.push(t);}function te(e,t,n){e.has(t)||e.set(t,[]),e.get(t).push(n);}function B(e,t){let n=D();Z(e);try{return t()}finally{Z(n);}}var ne=new Map,oe=new Map,Ye=new Map;function ot(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?.[tt]?o[r]=s():s!=null&&typeof s.get=="function"?o[r]=s:typeof s=="function"?o[r]=L(s):o[r]=_(s);}return o}function Ne(e){let t=D();if(!t){console.warn("onMount called outside of a component context");return}te(ne,t.id,e);}function H(e){he(()=>{setTimeout(e,0);});}function $(e){let t=e.componentId,n=ne.get(t);if(n){ne.delete(t);for(let o of n){let r=o();typeof r=="function"&&te(oe,t,r);}}}function Lt(e){let t=oe.get(e);if(t){oe.delete(e);for(let n of t)n();}}function wt(e){let t=Ye.get(e);if(t){Ye.delete(e);for(let n of t)n();}}function le(e){if(!e)return;let t=ee(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=se(e);if(n&&(Lt(n.componentId),wt(n.componentId)),e.childNodes){let o=e.firstChild;for(;o;){let r=o.nextSibling;le(o),o=r;}}}function P(e){return e!=null&&typeof e=="object"&&typeof e.$constructor=="function"}function We(e){return typeof e=="function"&&typeof e.prototype?.render=="function"}function Ot(e,t,n){let o=J(),r={componentId:o,$children:n,element:null,classInstance:null,$constructor(){let s=We(e)?void 0:e[re],i={...ot(t??{},s),children:n},l=D(),c={disposers:[],id:o,contexts:new Map(l?.contexts)};Z(c);let f;if(We(e)){r.ClassConstructor=e;let E=new e(i);r.classInstance=E,typeof E.onMount=="function"&&te(ne,o,()=>{E.onMount?.();}),typeof E.onUnmount=="function"&&te(oe,o,()=>{E.onUnmount?.();}),f=E.render();}else f=e(i);Z(l);let d=vt(f);if(r.element=d,d instanceof DocumentFragment&&d.childNodes.length)for(let E of d.childNodes)ee(E,c),Ue(E,r);else ee(d,c),d instanceof Node&&Ue(d,r);return d}};return r}function Te(e,t){let n=t.$constructor();n instanceof Node&&e.appendChild(n),queueMicrotask(()=>{$(t);});}function vt(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"},ze=new Set(["value","defaultValue","checked","selected","indeterminate"]),Mt=new Set(["srcdoc"]),It=new Set(["href","src","action","formaction","xlink:href"]),Bt=new Set(["securitypolicyviolation"]),Pt=new Set(["contenteditable","draggable","spellcheck"]);function V(e){return e!=null&&typeof e=="object"&&typeof e.get=="function"&&!(e instanceof Node)}var rt=Symbol("Fragment");function M(e,t,n){if(e===rt){let r=document.createDocumentFragment();return Ee(r,Qe(n)),r}if(typeof e=="function")return Ot(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),ce(o,t),Ee(o,Qe(n)),o}function ye(e,t){t instanceof DocumentFragment?e.replaceChildren(t):e.innerHTML=t??"";}function jt(e){return typeof e!="string"?false:e.replace(/[\p{White_Space}\p{Cc}]+/gu,"").toLowerCase().startsWith("javascript:")}function Dt(e,t){if(typeof e!="string")return false;let n=e.toLowerCase();return Mt.has(n)?true:It.has(n)&&t!==null&&t!==void 0&&jt(String(t))}function st(e){return typeof e!="string"?e:Xe[e]?Xe[e]:e}function Ft(e,t){let n=st(e),o=typeof n=="string"?n.toLowerCase():String(n).toLowerCase();return Pt.has(o)&&(t===true||t===false||t==="true"||t==="false")?String(t):t==null||t===false?null:t}function Je(e,t,n){let o=Ft(t,n);if(o===null){e.removeAttribute(t);return}if(Dt(t,o)){e.removeAttribute(t),console.warn(`[esmj-dom] Blocked unsafe attribute "${String(t)}" on <${e.tagName.toLowerCase()}>`);return}e.setAttribute(t,o);}function ce(e,t){let n=D();for(let[o,r]of Reflect.ownKeys(t).map(s=>[s,t[s]]))if(o!=="id"){if(o=st(o),o==="$ref"){typeof r=="function"?r(e):typeof r=="object"&&r!==null&&(r.current=e);continue}if(o==="$dangerouslySetInnerHTML"){if(V(r)){let s=A(()=>{B(n,()=>{ye(e,r.get());});});v(e,s);}else if(typeof r=="function"){let s=A(()=>{B(n,()=>{ye(e,r());});});v(e,s);}else ye(e,r);continue}if(o==="style"){if(V(r)){let s=A(()=>{B(n,()=>{Object.assign(e.style,r.get());});});v(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(Bt.has(s)){console.warn(`[esmj-dom] Blocked unsafe event binding "${o}" on <${e.tagName.toLowerCase()}>`);continue}e.addEventListener(s,r);continue}if(V(r)||typeof r=="function"){let s=o,i=A(()=>{B(n,()=>{let l=typeof r=="function"?r():r.get();ze.has(s)?e[s]=l??"":Je(e,s,l);});});v(e,i);continue}ze.has(o)||typeof o=="symbol"?e[o]=r??"":Je(e,o,r);}}function Qe(e){return e==null?[]:Array.isArray(e)?e.flat(Number.POSITIVE_INFINITY):[e]}function Ee(e,t){for(let n of t)it(e,n);}function it(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"){Ze(e,t);return}if(P(t)){Te(e,t);return}if(V(t)){Ze(e,()=>t.get());return}if(Array.isArray(t)){Ee(e,t);return}e.appendChild(document.createTextNode(String(t)));}}function K(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 ue(e,t=true){for(let n of e)t&&le(n),n.remove();}function Ze(e,t){let n=D(),o=document.createComment("");e.appendChild(o);let r=[],s=A(()=>{B(n,()=>{let i=t(),{nodes:l,instance:c}=K(i);ue(r),l.length&&o.after(...l),c&&queueMicrotask(()=>$(c)),r=l;});});v(e,s);}function ke(e,t){if(typeof e=="string"&&(e=document.querySelector(e)),!e)throw new Error("mount: container not found");e instanceof DocumentFragment||(le(e),e.innerHTML=""),P(t)?Te(e,t):t instanceof Node?e.appendChild(t):e.appendChild(document.createTextNode(String(t)));}function ut(e,t){let n=null;if(P(t)?(n=t.$constructor(),queueMicrotask(()=>$(t))):t instanceof Node?n=t:n=document.createTextNode(String(t)),n instanceof HTMLElement){let o=L(()=>!!e()),r=A(()=>{n.style.display=o.get()?"":"none";});v(n,r);}return n}Array.from({length:256},(e,t)=>(t<=15?"0":"")+t.toString(16));var ft=Symbol("block-element"),Gt=Symbol("block-element-body"),ae=Symbol("selectable-element");function Le(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 we(e){return e?Le(e.startContainer,ft):null}function pt(e){return e?Le(e.startContainer,ae):null}function Oe(e){return Le(e,ae)}function qt(e){return e?e[ae]!==void 0?[e]:[...e.children].filter(t=>t[ae]!==void 0):[]}function Vt(e,t){return t?qt(e).indexOf(t):-1}function dt(e,t){let n=pt(t);return !n||!e?.contains(n)?null:{element:n,index:Vt(e,n)}}function gt(){return window.getSelection()}function fe(){let e=gt();return e.rangeCount>0?e.getRangeAt(0).cloneRange():null}var _e=null;function ve(){_e=Me();}function mt(){_e&&Ie(_e);}function Ht(e,t){let n=pt(t);return n||(Y(e)??e?.childNodes?.[0]??null)}function U(e,t,n){if(!e)return 0;if(t===e){if(t.nodeType===Node.TEXT_NODE)return n;let i=0,l=e.childNodes,c=Math.min(n,l.length);for(let f=0;f<c;f++)i+=l[f].textContent.length;return i}if(t.nodeType===Node.ELEMENT_NODE&&!e.contains(t))return 0;let o=0,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=r.nextNode();for(;s;){if(s===t)return o+n;o+=s.textContent.length,s=r.nextNode();}return o}function Me(){let e=fe();if(!e)return null;let t=we(e),n=Ht(t,e);return {start:U(n,e.startContainer,e.startOffset),end:U(n,e.endContainer,e.endOffset),element:t,selectableElement:n}}function Ie(e){if(!e)return;let{start:t,end:n,element:o,selectableElement:r}=e,s=r?.isConnected&&r||Y(o)||o?.childNodes?.[0];if(!s)return;let i=at(s,t),l=at(s,n),c=document.createRange();c.setStart(i.startContainer,i.startOffset),c.setEnd(l.endContainer,l.endOffset);let f=gt();f.removeAllRanges(),f.addRange(c);}function at(e,t){let n=document.createRange();if(!e)return n;if(t<=0)return n.setStart(e,0),n.collapse(true),n;let o=0,r=[e];for(;r.length>0;){let s=r.pop();if(s.nodeType===Node.TEXT_NODE){let i=s.textContent.length;if(o+i>=t)return n.setEnd(s,t-o),n.setStart(s,t-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(e,e.childNodes.length),n.setStart(e,e.childNodes.length),n}function Y(e){if(!e)return null;let t=Ut(e);return t?.firstElementChild??t?.firstChild}function Be(e){if(!e?.[ft])return null;let t=Y(e);return t?se(t)?.classInstance:null}function Ut(e){if(!e)return null;for(let t of e.children)if(t[Gt])return t;return null}function ht(e,t,n,o=12){let r=e.getBoundingClientRect(),s=typeof t?.getBoundingClientRect=="function"?t.getBoundingClientRect():t??{left:0,top:0},i=n?.offsetHeight??40;return {x:s.left-r.left,y:s.top-r.top-i-o}}function yt(e,t,n){let o=e._getBlockElementState(t);if(!o)return null;let r=e.register.blocks.getByNamespace(o.component);if(!r)return null;let s=r.toExchangeState(o)?.properties?.items??[];if(!s.length)return null;let i=Y(t),l=dt(i,n),c=l?.element??i??t,f=l?.index??0,d=s[f];return d?{Constructor:r,current:o,element:c,itemIndex:f,item:d}:null}function Et(e,t){let n=U(e,t.startContainer,t.startOffset),o=U(e,t.endContainer,t.endOffset);return {offset:n,length:Math.max(0,o-n)}}function Yt(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=ke(s,o);return {container:s,dispose:i??null}}function St(e,t,n){return Yt(e,".mrakomor-tools-container",t,n)}var N={KEYDOWN:"mrakomor:keydown",CLICK:"mrakomor:click",SELECTION_CHANGE:"mrakomor:selection-change"};function bt({mrakomor:e,open:t,tooltipElement:n}){let o=_(0),r=_(0),s=_([]),i=null,l=null;function c(){t.set(false),i=null,l=null;}Ne(()=>{let d=e.emitter.on(N.OPEN_TOOLTIP,({element:p,actions:g})=>{i=p,l=Me(),s.set(g??[]),t.set(true),H(()=>{let{x:y,y:R}=ht(e.getRoot(),p,n);o.set(y),r.set(R);});}),E=e.emitter.on(N.CLOSE_TOOLTIP,c),a=e.emitter.on(N.KEYDOWN,()=>{t.peek()===true&&c();}),S=e.emitter.on(N.CLICK,p=>{if(t.peek()!==true||!n.current||!i)return;let g=p.target;if(!(g instanceof Node)){c();return}n.current.contains(g)||i.contains(g)||g instanceof Element&&g.contains(n.current)||c();});return ()=>{d(),E(),a(),S();}});let f=L(()=>({left:`${o.get()}px`,top:`${r.get()}px`}));return ut(()=>t.get(),M("div",{className:"mrakomor-tooltip",contenteditable:false,style:f,$ref:n},()=>Wt(s.get(),e,l)))}function Wt(e,t,n){if(!e.length)return null;let o=null,r=[];for(let s of e){o!==null&&s.group!==o&&r.push(M("span",{className:"mrakomor-tooltip__separator"})),o=s.group;let i=s.label,l=typeof i=="string"?i:typeof i=="function"?M(i,{}):i;r.push(M("button",{type:"button",className:["mrakomor-tooltip__btn",s.active?.()?"mrakomor-tooltip__btn--active":""].filter(Boolean).join(" "),title:s.title??"",onClick:c=>{c.preventDefault(),Ie(n),s.onAction(t);}},l));}return M("span",{style:"display: contents"},r)}function Xt({mrakomor:e}){let n=false,o=null,r=_(false),s=Re();function i(){let a=e.getConfig();return {inlineStyles:a.inlineStyles,entityRanges:a.entityRanges,blockTransforms:e.register.blocks.list()}}function l(a,S){let p=yt(e,a,S);if(!p)return null;let{element:g,item:y}=p;return y.inlineStyleRanges===void 0&&y.entityRanges===void 0?null:[{element:g,inlineStyleRanges:y.inlineStyleRanges??[],entityRanges:y.entityRanges??[]}]}function c(a,S,p,g){let y=[],R=e.getConfig()?.inlineStyles??[],C=e.getConfig()?.entityRanges??[],x=(S?.length?S:[{element:p,inlineStyleRanges:[],entityRanges:[]}]).map(u=>{let{offset:m,length:h}=Et(u.element??p,g);return {item:u,selStart:m,selEnd:m+h}});for(let u of a.inlineStyles){let m=typeof u=="string"?u:u.style,h=R.find(I=>I.style===m);if(!h)continue;let T=x.some(({item:I,selStart:pe,selEnd:W})=>(I.inlineStyleRanges??[]).some(F=>F.style===m&&F.offset<W&&F.offset+F.length>pe));y.push({label:h.LABEL??m,title:m.charAt(0)+m.slice(1).toLowerCase(),group:"inline",active:()=>T,onAction:I=>{ve(),I.command.insertInlineStyleRange({style:h.style}),H(()=>{mt();});}});}for(let u of a.entityRanges){let m=typeof u=="string"?u:u.NAMESPACE,h=C.find(T=>T.NAMESPACE===m);h&&y.push({label:h.LABEL??"\u{1F517}",title:h.NAMESPACE,group:"inline",active:()=>false,onAction:T=>{ve(),T.command.insertEntityRange({namespace:h.NAMESPACE,blockElement:p});}});}return y}function f(a){return {label:a.LABEL??a.NAMESPACE,title:a.LABEL??a.NAMESPACE,group:"transform",active:()=>true,onAction:()=>{}}}function d(a,S,p,g){let y=[],R=new Set;for(let C of a.blockTransforms){let b=typeof C=="string"?C:C?.component?.NAMESPACE??C?.NAMESPACE;if(!b||R.has(b)||(R.add(b),b===p.NAMESPACE))continue;let x=e.resolveComponentConstructor(b);x&&y.push({label:x.LABEL??b,title:`Convert to ${x.LABEL??b}`,group:"transform",active:()=>false,onAction:u=>{u.command.transformBlockElement({blockElement:S,namespace:b,range:g});}});}return y}function E(){if(n)return;let a=window.getSelection(),S=e.getRoot();if(!a||a.rangeCount===0){e.command.closeTooltip();return}let p=fe();if(!S.contains(p.commonAncestorContainer)){e.command.closeTooltip();return}if(p.startContainer===s.current&&r.peek()===true)return;let g=we(p);if(!g){e.command.closeTooltip();return}let y=Be(g),R=e._getBlockElementState(g);if(!y||!R){e.command.closeTooltip();return}let C=y.constructor;if(p.collapsed){e.command.closeTooltip();return}let b=Oe(p.startContainer),x=Oe(p.endContainer);if(!b||!x||b!==x){e.command.closeTooltip();return}let u=i(),m=l(g,p),h=[f(C),...d(u,g,C,p),...c(u,m,g,p)];if(h.length===0){e.command.closeTooltip();return}e.command.openTooltip({element:g,actions:h});}return {registerEvents(){N.OPEN_TOOLTIP="mrakomor:open-tooltip",N.CLOSE_TOOLTIP="mrakomor:close-tooltip";},registerCommands(a){a.command.openTooltip=(S,p)=>{a.emit(N.OPEN_TOOLTIP,{...S,options:p});},a.command.closeTooltip=S=>{a.emit(N.CLOSE_TOOLTIP,{options:S});};},registerListeners(){e.emitter.on(N.SELECTION_CHANGE,E),N.OPEN_DIALOG&&e.emitter.on(N.OPEN_DIALOG,()=>{n=true,r.peek()===true&&e.command.closeTooltip();}),N.CLOSE_DIALOG&&e.emitter.on(N.CLOSE_DIALOG,()=>{n=false;});},onMount(){let{dispose:a}=St(e,"mrakomor-tooltip-plugin-container",M(bt,{mrakomor:xe(e),tooltipElement:s,open:r}));o=a;},onUnmount(){o?.(),o=null;}}}exports.Tooltip=bt;exports.tooltipPlugin=Xt;
|
package/dist/tooltip.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-
|
|
2
|
-
`,document.head.appendChild(i);}}})();function V({mrakomor:t
|
|
1
|
+
import {a as a$1}from'./chunk-ERNLRJPB.mjs';import {o as o$1,B}from'./chunk-D6K2L5O3.mjs';import {a}from'./chunk-B6JJAATK.mjs';import {q,x,s,k,e as e$1,v,h,m as m$1,n}from'./chunk-4WTPDNPA.mjs';import {e,m,o,c,u,p,g,f}from'./chunk-7CJLTNHZ.mjs';(function(){if(!(typeof document>"u")){var t="mrakomor/core/plugin/tooltip/Tooltip.css",m=Array.prototype.some.call(document.head.querySelectorAll("style[data-mrakomor-css-path]"),function(u){return u.getAttribute("data-mrakomor-css-path")===t});if(!m){var i=document.createElement("style");i.setAttribute("data-mrakomor-css",""),i.setAttribute("data-mrakomor-css-path",t),i.textContent=`.mrakomor-tooltip{position:absolute;z-index:9100;display:flex;flex-direction:row;align-items:center;gap:2px;background:#1a1a1a;border-radius:6px;padding:4px 6px;box-shadow:0 3px 10px #00000040;pointer-events:all;white-space:nowrap}.mrakomor-tooltip__btn{display:inline-flex;align-items:center;justify-content:center;background:transparent;border:none;border-radius:4px;color:#fff;cursor:pointer;font-size:13px;font-weight:600;min-width:28px;min-height:28px;padding:0 6px;transition:background .1s}.mrakomor-tooltip__btn:hover{background:#ffffff26}.mrakomor-tooltip__btn--active{background:#ffffff40;color:#7dd3fc}.mrakomor-tooltip__separator{width:1px;height:18px;background:#fff3;margin:0 4px;flex-shrink:0}
|
|
2
|
+
`,document.head.appendChild(i);}}})();function V({mrakomor:t,open:m$1,tooltipElement:i}){let u$1=e(0),y=e(0),f=e([]),p$1=null,C=null;function E(){m$1.set(false),p$1=null,C=null;}m(()=>{let v=t.emitter.on(a.OPEN_TOOLTIP,({element:n,actions:o$1})=>{p$1=n,C=q(),f.set(o$1??[]),m$1.set(true),o(()=>{let{x:s,y:S}=x(t.getRoot(),n,i);u$1.set(s),y.set(S);});}),R=t.emitter.on(a.CLOSE_TOOLTIP,E),e=t.emitter.on(a.KEYDOWN,()=>{m$1.peek()===true&&E();}),r=t.emitter.on(a.CLICK,n=>{if(m$1.peek()!==true||!i.current||!p$1)return;let o=n.target;if(!(o instanceof Node)){E();return}i.current.contains(o)||p$1.contains(o)||o instanceof Element&&o.contains(i.current)||E();});return ()=>{v(),R(),e(),r();}});let _=c(()=>({left:`${u$1.get()}px`,top:`${y.get()}px`}));return u(()=>m$1.get(),p("div",{className:"mrakomor-tooltip",contenteditable:false,style:_,$ref:i},()=>J(f.get(),t,C)))}function J(t,m,i){if(!t.length)return null;let u=null,y=[];for(let f of t){u!==null&&f.group!==u&&y.push(p("span",{className:"mrakomor-tooltip__separator"})),u=f.group;let p$1=f.label,C=typeof p$1=="string"?p$1:typeof p$1=="function"?p(p$1,{}):p$1;y.push(p("button",{type:"button",className:["mrakomor-tooltip__btn",f.active?.()?"mrakomor-tooltip__btn--active":""].filter(Boolean).join(" "),title:f.title??"",onClick:E=>{E.preventDefault(),s(i),f.onAction(m);}},C));}return p("span",{style:"display: contents"},y)}function Q({mrakomor:t}){let i=false,u=null,y=e(false),f$1=g(null);function p$1(){let e=t.getConfig();return {inlineStyles:e.inlineStyles,entityRanges:e.entityRanges,blockTransforms:t.register.blocks.list()}}function C(e,r){let n=o$1(t,e,r);if(!n)return null;let{element:o,item:s}=n;return s.inlineStyleRanges===void 0&&s.entityRanges===void 0?null:[{element:o,inlineStyleRanges:s.inlineStyleRanges??[],entityRanges:s.entityRanges??[]}]}function E(e,r,n$1,o$1){let s=[],S=t.getConfig()?.inlineStyles??[],b=t.getConfig()?.entityRanges??[],A=(r?.length?r:[{element:n$1,inlineStyleRanges:[],entityRanges:[]}]).map(l=>{let{offset:d,length:a}=B(l.element??n$1,o$1);return {item:l,selStart:d,selEnd:d+a}});for(let l of e.inlineStyles){let d=typeof l=="string"?l:l.style,a=S.find(T=>T.style===d);if(!a)continue;let L=A.some(({item:T,selStart:W,selEnd:X})=>(T.inlineStyleRanges??[]).some(x=>x.style===d&&x.offset<X&&x.offset+x.length>W));s.push({label:a.LABEL??d,title:d.charAt(0)+d.slice(1).toLowerCase(),group:"inline",active:()=>L,onAction:T=>{m$1(),T.command.insertInlineStyleRange({style:a.style}),o(()=>{n();});}});}for(let l of e.entityRanges){let d=typeof l=="string"?l:l.NAMESPACE,a=b.find(L=>L.NAMESPACE===d);a&&s.push({label:a.LABEL??"\u{1F517}",title:a.NAMESPACE,group:"inline",active:()=>false,onAction:L=>{m$1(),L.command.insertEntityRange({namespace:a.NAMESPACE,blockElement:n$1});}});}return s}function _(e){return {label:e.LABEL??e.NAMESPACE,title:e.LABEL??e.NAMESPACE,group:"transform",active:()=>true,onAction:()=>{}}}function v$1(e,r,n,o){let s=[],S=new Set;for(let b of e.blockTransforms){let g=typeof b=="string"?b:b?.component?.NAMESPACE??b?.NAMESPACE;if(!g||S.has(g)||(S.add(g),g===n.NAMESPACE))continue;let A=t.resolveComponentConstructor(g);A&&s.push({label:A.LABEL??g,title:`Convert to ${A.LABEL??g}`,group:"transform",active:()=>false,onAction:l=>{l.command.transformBlockElement({blockElement:r,namespace:g,range:o});}});}return s}function R(){if(i)return;let e=window.getSelection(),r=t.getRoot();if(!e||e.rangeCount===0){t.command.closeTooltip();return}let n=k();if(!r.contains(n.commonAncestorContainer)){t.command.closeTooltip();return}if(n.startContainer===f$1.current&&y.peek()===true)return;let o=e$1(n);if(!o){t.command.closeTooltip();return}let s=v(o),S=t._getBlockElementState(o);if(!s||!S){t.command.closeTooltip();return}let b=s.constructor;if(n.collapsed){t.command.closeTooltip();return}let g=h(n.startContainer),A=h(n.endContainer);if(!g||!A||g!==A){t.command.closeTooltip();return}let l=p$1(),d=C(o,n),a=[_(b),...v$1(l,o,b,n),...E(l,d,o,n)];if(a.length===0){t.command.closeTooltip();return}t.command.openTooltip({element:o,actions:a});}return {registerEvents(){a.OPEN_TOOLTIP="mrakomor:open-tooltip",a.CLOSE_TOOLTIP="mrakomor:close-tooltip";},registerCommands(e){e.command.openTooltip=(r,n)=>{e.emit(a.OPEN_TOOLTIP,{...r,options:n});},e.command.closeTooltip=r=>{e.emit(a.CLOSE_TOOLTIP,{options:r});};},registerListeners(){t.emitter.on(a.SELECTION_CHANGE,R),a.OPEN_DIALOG&&t.emitter.on(a.OPEN_DIALOG,()=>{i=true,y.peek()===true&&t.command.closeTooltip();}),a.CLOSE_DIALOG&&t.emitter.on(a.CLOSE_DIALOG,()=>{i=false;});},onMount(){let{dispose:e}=a$1(t,"mrakomor-tooltip-plugin-container",p(V,{mrakomor:f(t),tooltipElement:f$1,open:y}));u=e;},onUnmount(){u?.(),u=null;}}}export{V as Tooltip,Q as tooltipPlugin};
|