| 1 |
var j=(r,e,n)=>{if(!e.has(r))throw TypeError("Cannot "+n)};var p=(r,e,n)=>(j(r,e,"read from private field"),n?n.call(r):e.get(r)),R=(r,e,n)=>{if(e.has(r))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(r):e.set(r,n)},v=(r,e,n,u)=>(j(r,e,"write to private field"),u?u.call(r,n):e.set(r,n),n);import{d as K,i as _,a as X}from"./index6.js?ver=2.10.0";import{bT as Y,az as Z,b3 as f,ba as V,b9 as g,b6 as ee,b5 as te,bU as C,b7 as z,b4 as O}from"./vendor.js?ver=2.10.0";import{t as se,h as re,a as ne,b as ae,q as ue,d as le,f as oe,g as de,o as me,i as pe}from"./todoList.js?ver=2.10.0";import{L as b,i as he,j as q,q as ce,k as ie,F as ye,n as Ie,T as ve,o as be,J as we,p as xe,Q as Me,t as Le}from"./milkdown.js?ver=2.10.0";import"./vue.js?ver=2.10.0";import"./dayjs.js?ver=2.10.0";import"./fcom-utils.js?ver=2.10.0";function W(r){const{$from:e,$to:n}=r.selection,{pos:u}=e,{pos:m}=n;return r=r.deleteRange(u-e.node().content.size,m),r}function ke(r,e,n=null){const{from:u,to:m}=r.selection;return r.setBlockType(u,m,e,n)}function $e(r,e,n=null){const{$from:u,$to:m}=r.selection,o=u.blockRange(m),h=o&&Y(o,e,n);return h?r.wrap(o,h):null}function Te(r,e,n=null){const u=e.createAndFill(n);return u?r.replaceSelectionWith(u):null}function D(r,e=null){return(n,u)=>{if(u){const m=ke(W(n.tr),r,e);u(m.scrollIntoView())}return!0}}function P(r,e=null){return(n,u)=>{const m=$e(W(n.tr),r,e);return m?(u&&u(m.scrollIntoView()),!0):!1}}function U(r,e=null){return(n,u)=>{const m=Te(W(n.tr),r,e);return m?(u&&u(m.scrollIntoView()),!0):!1}}var L,G;class Be{constructor(){R(this,L,void 0);R(this,G,void 0);v(this,L,[]),this.clear=()=>(v(this,L,[]),this),v(this,G,e=>{const n={group:e,addItem:(u,m)=>{const o={key:u,...m};return e.items.push(o),n},clear:()=>(e.items=[],n)};return n}),this.addGroup=(e,n)=>{const m={key:e,label:n,items:[]};return p(this,L).push(m),p(this,G).call(this,m)},this.getGroup=e=>{const n=p(this,L).find(u=>u.key===e);if(!n)throw new Error(`Group with key ${e} not found`);return p(this,G).call(this,n)},this.build=()=>p(this,L)}}L=new WeakMap,G=new WeakMap;function c(r){return window.fluentComAdmin.i18n[r]||r}typeof crypto<"u"&&!crypto.randomUUID&&(crypto.randomUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(r){const e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)})});function Re(r,e){var o,h,y,x,H,B,A,S,M,$,E;const n=new Be;n.addGroup("text",(e==null?void 0:e.slashMenuTextGroupLabel)??c("Text")).addItem("text",{label:(e==null?void 0:e.slashMenuTextGroupLabel)??c("Text"),icon:((o=e==null?void 0:e.slashMenuTextIcon)==null?void 0:o.call(e))??se,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;D(he.type(a))(t,s)}}).addItem("h2",{label:(e==null?void 0:e.slashMenuH2Label)??c("Heading 2"),icon:((h=e==null?void 0:e.slashMenuH2Icon)==null?void 0:h.call(e))??re,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;D(q.type(a),{level:2})(t,s)}}).addItem("h3",{label:(e==null?void 0:e.slashMenuH3Label)??c("Heading 3"),icon:((y=e==null?void 0:e.slashMenuH3Icon)==null?void 0:y.call(e))??ne,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;D(q.type(a),{level:3})(t,s)}}).addItem("h4",{label:(e==null?void 0:e.slashMenuH4Label)??c("Heading 4"),icon:((x=e==null?void 0:e.slashMenuH4Icon)==null?void 0:x.call(e))??ae,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;D(q.type(a),{level:4})(t,s)}}).addItem("quote",{label:(e==null?void 0:e.slashMenuQuoteLabel)??c("Quote"),icon:((H=e==null?void 0:e.slashMenuQuoteIcon)==null?void 0:H.call(e))??ue,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;P(ce.type(a))(t,s)}}).addItem("code",{label:(e==null?void 0:e.slashMenuCodeBlockLabel)??c("Code"),icon:((B=e==null?void 0:e.slashMenuCodeBlockIcon)==null?void 0:B.call(e))??le,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;U(ie.type(a))(t,s)}}).addItem("divider",{label:(e==null?void 0:e.slashMenuDividerLabel)??c("Divider"),icon:((A=e==null?void 0:e.slashMenuDividerIcon)==null?void 0:A.call(e))??oe,onRun:a=>{const d=a.get(b);U(ye.type(a))(d.state,d.dispatch);const{state:s}=d,t=Z.near(s.doc.resolve(s.selection.to));d.dispatch(s.tr.setSelection(t).scrollIntoView()),d.focus()}}),n.addGroup("list",(e==null?void 0:e.slashMenuListGroupLabel)??c("List")).addItem("bullet-list",{label:(e==null?void 0:e.slashMenuBulletListLabel)??c("Bullet List"),icon:((S=e==null?void 0:e.slashMenuBulletListIcon)==null?void 0:S.call(e))??de,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;P(Ie.type(a))(t,s)}}).addItem("ordered-list",{label:(e==null?void 0:e.slashMenuOrderedListLabel)??c("Ordered List"),icon:((M=e==null?void 0:e.slashMenuOrderedListIcon)==null?void 0:M.call(e))??me,onRun:a=>{const d=a.get(b),{dispatch:s,state:t}=d;P(ve.type(a))(t,s)}}),(e==null?void 0:e.hasImageBlock)!==!1&&n.addGroup("media",(e==null?void 0:e.slashMenuMediaGroupLabel)??c("Media")).addItem("image",{label:(e==null?void 0:e.slashMenuImageLabel)??c("Image"),icon:(($=e==null?void 0:e.slashMenuImageIcon)==null?void 0:$.call(e))??pe,onRun:a=>{if(e!=null&&e.canAddImage&&!e.canAddImage())return;const d=a.get(b),{dispatch:s,state:t}=d;U(be.type(a))(t,s)}}),(E=e==null?void 0:e.buildMenu)==null||E.call(e,n);let u=n.build();r&&(u=u.map(a=>{const d=a.items.filter(s=>s.label.toLowerCase().includes(r.toLowerCase()));return{...a,items:d}}).filter(a=>a.items.length>0));const m=u.flatMap(a=>a.items);return m.forEach((a,d)=>{Object.assign(a,{index:d})}),u.reduce((a,d)=>{const s=a+d.items.length;return Object.assign(d,{range:[a,s]}),s},0),{groups:u,size:m.length}}const F=({show:r,hide:e,ctx:n,filter:u,config:m})=>{const{groups:o,size:h}=V(()=>Re(u,m),[u]),y=g(),[x,H]=ee(0),B=V(()=>y.current.getRootNode(),[y]),A=te({x:-999,y:-999}),S=C(s=>{const t=A.current;if(!t)return;const{x:l,y:I}=s;t.x=l,t.y=I},[]);z(()=>{h===0&&r&&(e==null||e())},[h,r]);const M=C((s,t)=>{H(l=>{const I=typeof s=="function"?s(l):s;return t==null||t(I),I})},[]),$=C(s=>{const t=y.current.querySelector(`[data-index="${s}"]`),l=y.current.querySelector(".menu-groups");!t||!l||(l.scrollTop=t.offsetTop-l.offsetTop)},[]),E=C(s=>{const t=o.flatMap(l=>l.items).at(s);t&&n&&t.onRun(n),e==null||e()},[o]),a=C(s=>{if(s.key==="Escape"){s.preventDefault(),e==null||e();return}if(s.key==="ArrowDown")return s.preventDefault(),M(t=>t<h-1?t+1:t,$);if(s.key==="ArrowUp")return s.preventDefault(),M(t=>t<=0?t:t-1,$);if(s.key==="ArrowLeft")return s.preventDefault(),M(t=>{const l=o.find(T=>T.range[0]<=t&&T.range[1]>t);if(!l)return t;const I=o[o.indexOf(l)-1];return I?I.range[1]-1:t},$);if(s.key==="ArrowRight")return s.preventDefault(),M(t=>{const l=o.find(T=>T.range[0]<=t&&T.range[1]>t);if(!l)return t;const I=o[o.indexOf(l)+1];return I?I.range[0]:t},$);s.key==="Enter"&&(s.preventDefault(),E(x))},[e,o,x]),d=C(s=>t=>{const l=A.current;if(!l)return;const{x:I,y:T}=t;I===l.x&&T===l.y||M(s)},[]);return z(()=>(r?B.addEventListener("keydown",a,{capture:!0}):B.removeEventListener("keydown",a,{capture:!0}),()=>{B.removeEventListener("keydown",a,{capture:!0})}),[r,a]),O` |
| 23 |
`};F.props={ctx:Object,config:Object,show:Boolean,filter:String,hide:Function};const Q=f(F),N=we("CREPE_MENU"),J=xe({show:()=>{},hide:()=>{}},"menuAPICtx");K("milkdown-slash-menu",Q);function Ce(r,e){r.set(N.key,{view:n=>new Ge(r,n,e)})}var i,w,k;class Ge{constructor(e,n,u){R(this,i,void 0);R(this,w,void 0);R(this,k,void 0);v(this,k,null),this.update=o=>{p(this,w).update(o)},this.show=o=>{v(this,k,o),p(this,i).filter="",p(this,w).show()},this.hide=()=>{v(this,k,null),p(this,w).hide()},this.destroy=()=>{p(this,w).destroy(),p(this,i).remove()},v(this,i,new Q),p(this,i).hide=this.hide,p(this,i).ctx=e,p(this,i).config=u;const m=this;v(this,w,new Me({content:p(this,i),debounce:20,shouldShow(o){if(_(o.state.selection)||X(o.state.selection))return!1;const h=this.getContent(o,x=>["paragraph","heading"].includes(x.type.name));if(h==null)return!1;const y=p(m,k);return p(m,i).filter=h.startsWith("/")?h.slice(1):h,typeof y=="number"?o.state.doc.resolve(y).node()!==o.state.doc.resolve(o.state.selection.from).node()?(v(m,k,null),!1):!0:!!h.startsWith("/")},offset:10})),p(this,w).onShow=()=>{p(this,i).show=!0},p(this,w).onHide=()=>{p(this,i).show=!1},this.update(n),e.set(J.key,{show:o=>this.show(o),hide:()=>this.hide()})}}i=new WeakMap,w=new WeakMap,k=new WeakMap;const Ue=(r,e)=>{r.config(n=>Ce(n,e)).use(J).use(Le).use(N)};export{Ue as defineFeature}; |