@univerjs/docs-quick-insert-ui 0.10.12 → 0.10.13-nightly.202510290902

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/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Ce=Object.defineProperty;var _e=(r,t,e)=>t in r?Ce(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var y=(r,t,e)=>_e(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),N=require("@univerjs/docs"),_=require("@univerjs/docs-ui"),d=require("@univerjs/ui"),X=require("@univerjs/engine-render"),I=require("rxjs"),g=require("react/jsx-runtime"),M=require("@univerjs/design"),h=require("react"),re=require("@univerjs/docs-drawing-ui"),Se=require("@univerjs/docs-drawing"),ye=require("@univerjs/drawing"),Pe=require("@univerjs/drawing-ui"),ie={id:"doc.command.delete-search-key",type:o.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(o.ICommandService),{start:n,end:i}=t;return e.syncExecuteCommand(_.CutContentCommand.id,{segmentId:"",textRanges:[{startOffset:n,endOffset:n,collapsed:!0}],selections:[{startOffset:n,endOffset:i,collapsed:!1,direction:o.RANGE_DIRECTION.FORWARD}]})}},se="docs.quick.insert.keyword-input-placeholder",H=()=>{const r=d.useDependency(o.LocaleService);return g.jsx("div",{className:"univer-translate-y-1.5 univer-text-sm univer-text-gray-500",children:r.t("docQuickInsert.keywordInputPlaceholder")})};H.componentKey=se;const oe="docs.quick.insert.placeholder",L=()=>{const r=d.useDependency(o.LocaleService);return g.jsx("div",{className:"univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg",children:g.jsx("span",{children:r.t("docQuickInsert.placeholder")})})};L.componentKey=oe;function G(r,t){return r.map(e=>({...e})).filter(e=>{if("children"in e)return e.children=G(e.children,t),e.children.length>0;const n=e.keywords;return n?n.some(i=>i.includes(t)):e.title.toLowerCase().includes(t)})}function ce(r,t){return r.map(e=>{const n={...e};return"children"in n&&(n.children=ce(n.children,t)),n.title=t.t(n.title),"keywords"in n&&(n.keywords=n.keywords.concat(n.title).map(i=>i.toLowerCase())),n})}const xe=[d.KeyCode.ARROW_UP,d.KeyCode.ARROW_DOWN,d.KeyCode.ENTER],q=()=>{const r=d.useDependency(o.LocaleService),t=d.useDependency(exports.DocQuickInsertPopupService),e=d.useDependency(d.ComponentManager),n=d.useDependency(d.IShortcutService),i=d.useDependency(o.ICommandService),s=h.useMemo(()=>o.generateRandomId(),[]),[a,l]=h.useState(0),m=h.useRef(null),c=h.useRef(0);c.current=0;const u=d.useObservable(t.filterKeyword$,""),p=d.useObservable(t.editPopup$),v=d.useObservable(p==null?void 0:p.popup.menus$,[]),x=h.useMemo(()=>ce(v,r),[v]),[b,R]=h.useState(()=>G(x,u.toLowerCase()));h.useEffect(()=>{const C=requestIdleCallback(()=>{R(G(x,u.toLowerCase()))});return()=>{cancelIdleCallback(C)}},[x,u]);const O=C=>{t.emitMenuSelected(C),i.executeCommand($.id)};h.useEffect(()=>{const C=new o.DisposableCollection;n.getAllShortcuts().filter(f=>f.binding&&xe.includes(f.binding)).forEach(f=>{const k=f.preconditions;f.preconditions=()=>!1,C.add(o.toDisposable(()=>{f.preconditions=k}))});const D={id:`quick.insert.popup.enter.${s}`,type:o.CommandType.OPERATION,handler:()=>{const f=m.current;f&&O(f)}},Q={id:`quick.insert.popup.move.cursor.up.${s}`,type:o.CommandType.OPERATION,handler:()=>{l(f=>{const k=f-1;return k>=0?k:c.current-1})}},w={id:`quick.insert.popup.move.cursor.down.${s}`,type:o.CommandType.OPERATION,handler:()=>{l(f=>{const k=f+1;return k<=c.current-1?k:0})}};return C.add(i.registerCommand(Q)),C.add(i.registerCommand(w)),C.add(i.registerCommand(D)),C.add(n.registerShortcut({priority:1e3,id:Q.id,binding:d.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:o.Direction.UP}})),C.add(n.registerShortcut({priority:1e3,id:w.id,binding:d.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:o.Direction.DOWN}})),C.add(n.registerShortcut({priority:1e3,id:D.id,binding:d.KeyCode.ENTER,preconditions:()=>!0})),()=>{C.dispose()}},[]),h.useEffect(()=>{l(0)},[b]);const T=h.useRef(new Map);h.useEffect(()=>()=>{T.current.clear()},[]);function j(C){return C.map(S=>{const W=S.icon,D=W?e.get(W):null;if("children"in S)return g.jsx(M.MenuItemGroup,{title:g.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-text-xs univer-text-gray-400",children:[D&&g.jsx("span",{className:"univer-mr-2 univer-inline-flex univer-text-base",children:g.jsx(D,{})}),g.jsx("span",{children:S.title})]}),children:j(S.children)},S.id);const Q=c.current,w=a===Q;if(w){m.current=S;const f=T.current.get(S.id);f==null||f.scrollIntoView({block:"nearest"})}return c.current++,g.jsx(M.MenuItem,{ref:f=>{f&&T.current.set(S.id,f)},onMouseEnter:()=>l(Q),onMouseLeave:()=>l(Number.NaN),className:M.clsx("univer-w-[calc(220px-var(--padding-base)*2)] univer-text-sm",{"hover:univer-bg-transparent":!w,"univer-bg-gray-100 dark:!univer-bg-gray-500":w}),onClick:()=>{O(S)},children:g.jsxs("div",{className:"univer-flex univer-w-full univer-items-center univer-px-1",children:[D&&g.jsx("span",{className:"univer-mr-2 univer-inline-flex univer-text-base",children:g.jsx(D,{})}),g.jsx(M.Tooltip,{showIfEllipsis:!0,title:S.title,placement:"right",children:g.jsx("span",{className:"univer-truncate",children:S.title})})]})},S.id)})}const K=b.length>0,ee=(p==null?void 0:p.popup.Placeholder)||e.get(L.componentKey);return g.jsx("div",{className:"univer-mt-2",children:K?g.jsx(M.Menu,{wrapperClass:M.clsx("univer-max-h-[360px] univer-w-[220px] univer-overflow-y-auto univer-overflow-x-hidden",M.scrollbarClassName),children:j(b)}):ee&&g.jsx(ee,{})})};q.componentKey="docs.quick.insert.popup";var be=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},U=(r,t)=>(e,n)=>t(e,n,r);const te={dispose:()=>{}};exports.DocQuickInsertPopupService=class extends o.Disposable{constructor(e,n,i,s,a){super();y(this,"_popups",new Set);y(this,"_editPopup$",new I.BehaviorSubject(void 0));y(this,"editPopup$",this._editPopup$.asObservable());y(this,"_isComposing$",new I.BehaviorSubject(!1));y(this,"isComposing$",this._isComposing$.asObservable());y(this,"_inputOffset$",new I.BehaviorSubject({start:0,end:0}));y(this,"inputOffset$",this._inputOffset$.asObservable());y(this,"filterKeyword$");y(this,"_menuSelectedCallbacks",new Set);y(this,"_inputPlaceholderRenderRoot",null);this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=i,this._renderManagerService=s,this._docSelectionManagerService=a,this.disposeWithMe(this._editPopup$);const l=(c,u)=>{var p,v;return(v=(p=this._univerInstanceService.getCurrentUnitOfType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:p.getBody())==null?void 0:v.dataStream.slice(c,u)};let m="";this.filterKeyword$=this._inputOffset$.pipe(I.map(c=>{var p;const u=l(c.start,c.end);return(p=u==null?void 0:u.slice(1))!=null?p:""}),I.distinctUntilChanged(),I.tap(c=>{m=c})),this.disposeWithMe(I.combineLatest([this.filterKeyword$.pipe(I.tap(c=>{var u,p,v;c.length>0?(p=(u=this._inputPlaceholderRenderRoot)==null?void 0:u.unmount)==null||p.dispose():(v=this._inputPlaceholderRenderRoot)==null||v.mount()})),this.isComposing$.pipe(I.tap(c=>{var u,p,v;c?(p=(u=this._inputPlaceholderRenderRoot)==null?void 0:u.unmount)==null||p.dispose():m.length<=0&&((v=this._inputPlaceholderRenderRoot)==null||v.mount())})),this.editPopup$.pipe(I.tap(c=>{var u,p;c||((p=(u=this._inputPlaceholderRenderRoot)==null?void 0:u.unmount)==null||p.dispose(),this._inputPlaceholderRenderRoot=null)}))]).subscribe())}get popups(){return Array.from(this._popups)}get editPopup(){return this._editPopup$.value}get isComposing(){return this._isComposing$.value}setIsComposing(e){this._isComposing$.next(e)}get inputOffset(){return this._inputOffset$.value}setInputOffset(e){this._inputOffset$.next(e)}getDocEventManagerService(e){var n;return(n=this._renderManagerService.getRenderById(e))==null?void 0:n.with(_.DocEventManagerService)}resolvePopup(e){return Array.from(this._popups).find(n=>n.keyword===e)}registerPopup(e){return this._popups.add(e),()=>{this._popups.delete(e)}}_createInputPlaceholderRenderRoot(e){return{isMounted:!1,mount(){if(this.isMounted)return;this.isMounted=!0;const i=e();this.unmount={dispose:()=>{i.dispose(),this.isMounted=!1}}}}}showPopup(e){var p,v;const{popup:n,index:i,unitId:s}=e;this.closePopup();const a=this._univerInstanceService.getUnit(s),l=(v=(p=a==null?void 0:a.getBody())==null?void 0:p.paragraphs)==null?void 0:v.find(x=>x.startIndex>i);if(!l)return;const m=this.getDocEventManagerService(s),c=m==null?void 0:m.findParagraphBoundByIndex(l.startIndex);if(!c)return;this._inputPlaceholderRenderRoot=this._createInputPlaceholderRenderRoot(()=>{var K;const x=(K=this._renderManagerService.getRenderById(s))==null?void 0:K.with(N.DocSkeletonManagerService),b=this._docSelectionManagerService.getActiveTextRange();if(!x||!b)return te;const O=x.getSkeleton().findNodeByCharIndex(b.startOffset,b.segmentId,b.segmentPage);if(!((O==null?void 0:O.content)==="\r"))return te;const j=this._docCanvasPopupManagerService.attachPopupToRange({startOffset:i+1,endOffset:i+1,collapsed:!1},{componentKey:H.componentKey,onClickOutside:()=>{j.dispose()},direction:"horizontal"},s);return j}),this._inputPlaceholderRenderRoot.mount();const u=this._docCanvasPopupManagerService.attachPopupToRect(c.firstLine,{componentKey:q.componentKey,onClickOutside:()=>{this.closePopup()},direction:"bottom"},s);this._editPopup$.next({disposable:u,popup:n,anchor:i,unitId:s})}closePopup(){this.editPopup&&(this.editPopup.disposable.dispose(),this._editPopup$.next(null))}onMenuSelected(e){return this._menuSelectedCallbacks.add(e),()=>{this._menuSelectedCallbacks.delete(e)}}emitMenuSelected(e){const{start:n,end:i}=this.inputOffset;this._commandService.syncExecuteCommand(ie.id,{start:n,end:i}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(s=>s(e))},0)}};exports.DocQuickInsertPopupService=Oe([U(0,o.Inject(_.DocCanvasPopManagerService)),U(1,o.Inject(o.IUniverInstanceService)),U(2,o.Inject(o.ICommandService)),U(3,o.Inject(X.IRenderManagerService)),U(4,o.Inject(N.DocSelectionManagerService))],exports.DocQuickInsertPopupService);const ae={type:o.CommandType.OPERATION,id:"doc.operation.show-quick-insert-popup",handler(r,t){const e=r.get(exports.DocQuickInsertPopupService);return t?(e.showPopup(t),!0):!1}},$={type:o.CommandType.OPERATION,id:"doc.operation.close-quick-insert-popup",handler(r){return r.get(exports.DocQuickInsertPopupService).closePopup(),!0}},ue={id:"quick-insert.text.menu",title:"docQuickInsert.menu.text",icon:"TextIcon",keywords:["text"]},de={id:_.OrderListCommand.id,title:"docQuickInsert.menu.numberedList",icon:"OrderIcon",keywords:["numbered","list","ordered"]},pe={id:_.BulletListCommand.id,title:"docQuickInsert.menu.bulletedList",icon:"UnorderIcon",keywords:["bulleted","list","unordered"]},le={id:_.HorizontalLineCommand.id,title:"docQuickInsert.menu.divider",icon:"DividerIcon",keywords:["divider","line","separate"]},ve={id:_.DocCreateTableOperation.id,title:"docQuickInsert.menu.table",icon:"GridIcon",keywords:["table","grid","spreadsheet"]},he={id:re.InsertDocImageCommand.id,title:"docQuickInsert.menu.image",icon:"AdditionAndSubtractionIcon",keywords:["image","picture","photo"]},Me=[{title:"docQuickInsert.group.basics",id:"quick.insert.group.basic",children:[ue,de,pe,le,ve,he]}],De=new Set([de.id,pe.id,le.id,ve.id,he.id]);var ke=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},E=(r,t)=>(e,n)=>t(e,n,r);exports.DocQuickInsertTriggerController=class extends o.Disposable{constructor(t,e,n,i,s){super(),this._commandService=t,this._textSelectionManagerService=e,this._docQuickInsertPopupService=n,this._shortcutService=i,this._univerInstanceService=s,this.disposeWithMe(this._shortcutService.registerShortcut({id:$.id,binding:d.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var a,l,m;const{_docQuickInsertPopupService:e,_textSelectionManagerService:n,_commandService:i}=this,s=this._univerInstanceService.getCurrentUnitOfType(o.UniverInstanceType.UNIVER_DOC);if(!(s!=null&&s.getDisabled())){if(t.id===_.InsertCommand.id){const c=t.params;if(e.editPopup){e.setInputOffset({start:e.inputOffset.start,end:c.range.endOffset+1});return}const u=n.getActiveTextRange();if(!u)return;const p=e.resolvePopup(c.body.dataStream);if(!p||!(p.preconditions?p.preconditions(c):!0))return;e.setInputOffset({start:u.startOffset-1,end:u.startOffset}),setTimeout(()=>{i.executeCommand(ae.id,{index:u.startOffset-1,unitId:c.unitId,popup:p})},100)}if(t.id===_.IMEInputCommand.id){const c=t.params;!e.isComposing&&c.isCompositionStart&&e.setIsComposing(!0),e.isComposing&&c.isCompositionEnd&&e.setIsComposing(!1)}if(t.id===N.RichTextEditingMutation.id){const c=t.params;if(c.isCompositionEnd){const u=(l=(a=c.textRanges)==null?void 0:a[0])==null?void 0:l.endOffset;u&&e.setInputOffset({start:e.inputOffset.start,end:u})}}if(t.id===_.DeleteCommand.id){const c=t.params;if(e.editPopup&&c.direction===o.DeleteDirection.LEFT){const u=(m=c.len)!=null?m:0;e.setInputOffset({start:e.inputOffset.start,end:c.range.endOffset-u})}}if(t.id===_.MoveCursorOperation.id){const c=t.params;(c.direction===o.Direction.LEFT||c.direction===o.Direction.RIGHT)&&e.editPopup&&i.executeCommand($.id)}if(t.id===_.DeleteLeftCommand.id){const c=n.getActiveTextRange();if(!e.editPopup||!c)return;c.endOffset<=e.editPopup.anchor&&i.executeCommand($.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(t=>{t.id!==ue.id&&De.has(t.id)&&this._commandService.executeCommand(t.id)}))}};exports.DocQuickInsertTriggerController=we([E(0,o.ICommandService),E(1,o.Inject(N.DocSelectionManagerService)),E(2,o.Inject(exports.DocQuickInsertPopupService)),E(3,o.Inject(d.IShortcutService)),E(4,o.Inject(o.IUniverInstanceService))],exports.DocQuickInsertTriggerController);var P=function(){return P=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=t[i])}return r},P.apply(this,arguments)},Re=function(r,t){var e={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(e[n[i]]=r[n[i]]);return e},B=h.forwardRef(function(r,t){var e=r.icon,n=r.id,i=r.className,s=r.extend,a=Re(r,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),m=h.useRef("_".concat(Ue()));return fe(e,"".concat(n),{defIds:e.defIds,idSuffix:m.current},P({ref:t,className:l},a),s)});function fe(r,t,e,n,i){return h.createElement(r.tag,P(P({key:t},je(r,e,i)),n),(Qe(r,e).children||[]).map(function(s,a){return fe(s,"".concat(t,"-").concat(r.tag,"-").concat(a),e,void 0,i)}))}function je(r,t,e){var n=P({},r.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),r.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],l=s[1];a==="mask"&&typeof l=="string"&&(n[a]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var a=s[0],l=s[1];typeof l=="string"&&(n[a]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Qe(r,t){var e,n=t.defIds;return!n||n.length===0?r:r.tag==="defs"&&(!((e=r.children)===null||e===void 0)&&e.length)?P(P({},r),{children:r.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?P(P({},i),{attrs:P(P({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):r}function Ue(){return Math.random().toString(36).substring(2,8)}B.displayName="UniverIcon";var Ee={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.01953 3.13985C1.01953 2.77258 1.31726 2.47485 1.68453 2.47485H2.73713C3.1044 2.47485 3.40213 2.77258 3.40213 3.13985C3.40213 3.50712 3.1044 3.80485 2.73713 3.80485H1.68453C1.31726 3.80485 1.01953 3.50712 1.01953 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.17734 3.13985C4.17734 2.77258 4.47507 2.47485 4.84234 2.47485H6.94754C7.31481 2.47485 7.61254 2.77258 7.61254 3.13985C7.61254 3.50712 7.31481 3.80485 6.94754 3.80485H4.84234C4.47507 3.80485 4.17734 3.50712 4.17734 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.38775 3.13985C8.38775 2.77258 8.68548 2.47485 9.05275 2.47485H11.158C11.5252 2.47485 11.823 2.77258 11.823 3.13985C11.823 3.50712 11.5252 3.80485 11.158 3.80485H9.05275C8.68548 3.80485 8.38775 3.50712 8.38775 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.5982 3.13985C12.5982 2.77258 12.8959 2.47485 13.2632 2.47485H14.3158C14.683 2.47485 14.9808 2.77258 14.9808 3.13985C14.9808 3.50712 14.683 3.80485 14.3158 3.80485H13.2632C12.8959 3.80485 12.5982 3.50712 12.5982 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.01953 7.99972C1.01953 7.63245 1.31726 7.33472 1.68453 7.33472H14.3158C14.683 7.33472 14.9808 7.63245 14.9808 7.99972C14.9808 8.36699 14.683 8.66472 14.3158 8.66472H1.68453C1.31726 8.66472 1.01953 8.36699 1.01953 7.99972Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.68453 12.1951C1.31726 12.1951 1.01953 12.4928 1.01953 12.8601C1.01953 13.2273 1.31726 13.5251 1.68453 13.5251H2.73713C3.1044 13.5251 3.40213 13.2273 3.40213 12.8601C3.40213 12.4928 3.1044 12.1951 2.73713 12.1951H1.68453Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.84234 12.1951C4.47507 12.1951 4.17734 12.4928 4.17734 12.8601C4.17734 13.2273 4.47507 13.5251 4.84234 13.5251H6.94754C7.31481 13.5251 7.61254 13.2273 7.61254 12.8601C7.61254 12.4928 7.31481 12.1951 6.94754 12.1951H4.84234Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M9.05275 12.1951C8.68548 12.1951 8.38775 12.4928 8.38775 12.8601C8.38775 13.2273 8.68548 13.5251 9.05275 13.5251H11.158C11.5252 13.5251 11.823 13.2273 11.823 12.8601C11.823 12.4928 11.5252 12.1951 11.158 12.1951H9.05275Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M13.2632 12.1951C12.8959 12.1951 12.5982 12.4928 12.5982 12.8601C12.5982 13.2273 12.8959 13.5251 13.2632 13.5251H14.3158C14.683 13.5251 14.9808 13.2273 14.9808 12.8601C14.9808 12.4928 14.683 12.1951 14.3158 12.1951H13.2632Z"}}]},z=h.forwardRef(function(r,t){return h.createElement(B,Object.assign({},r,{id:"divider-icon",ref:t,icon:Ee}))});z.displayName="DividerIcon";var $e={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},ge=h.forwardRef(function(r,t){return h.createElement(B,Object.assign({},r,{id:"increase-icon",ref:t,icon:$e}))});ge.displayName="IncreaseIcon";var Ne={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#text-icon_clip0_1293_26)"},children:[{tag:"path",attrs:{d:"M2.22891 2.07227C1.89754 2.07227 1.62891 2.34089 1.62891 2.67227C1.62891 3.00364 1.89754 3.27227 2.22891 3.27227H6.29541V14.0056C6.29541 14.337 6.56404 14.6056 6.89541 14.6056C7.22678 14.6056 7.49541 14.337 7.49541 14.0056V3.27227H11.5622C11.8936 3.27227 12.1622 3.00364 12.1622 2.67227C12.1622 2.34089 11.8936 2.07227 11.5622 2.07227H2.22891Z"}},{tag:"path",attrs:{d:"M10.2289 6.40552C9.89754 6.40552 9.62891 6.67415 9.62891 7.00552C9.62891 7.33689 9.89754 7.60552 10.2289 7.60552H12.2954V14.0055C12.2954 14.3369 12.564 14.6055 12.8954 14.6055C13.2268 14.6055 13.4954 14.3369 13.4954 14.0055V7.60552H15.5622C15.8936 7.60552 16.1622 7.33689 16.1622 7.00552C16.1622 6.67415 15.8936 6.40552 15.5622 6.40552H10.2289Z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"text-icon_clip0_1293_26"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.9)"}}]}]}],defIds:["text-icon_clip0_1293_26"]},Y=h.forwardRef(function(r,t){return h.createElement(B,Object.assign({},r,{id:"text-icon",ref:t,icon:Ne}))});Y.displayName="TextIcon";const me="doc.quick-insert.button";var Te=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},Z=(r,t)=>(e,n)=>t(e,n,r);let A=class extends o.Disposable{constructor(t,e,n,i){super();y(this,"_popup$",new I.BehaviorSubject(null));y(this,"popup$",this._popup$.asObservable());this._context=t,this._docEventManagerService=e,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=i,this._init()}get popup(){return this._popup$.value}_init(){this.disposeWithMe(I.combineLatest([this._docEventManagerService.hoverParagraphLeftRealTime$,this._docEventManagerService.hoverParagraphRealTime$]).subscribe(([t,e])=>{var s;const n=t!=null?t:e,i=this._context.unit.getDisabled();if(!n||i){this._hideMenu(!0);return}if(n.paragraphStart===n.paragraphEnd){if(this._docQuickInsertPopupService.editPopup||n.startIndex===((s=this.popup)==null?void 0:s.startIndex))return;this._hideMenu(!0);const a=this._docCanvasPopManagerService.attachPopupToRect(n.firstLine,{componentKey:me,direction:"left-center"},this._context.unit.getUnitId());this._popup$.next({startIndex:n.startIndex,disposable:a})}else this._hideMenu(!0)}))}_hideMenu(t){this._docQuickInsertPopupService.editPopup||this.popup&&(t||this.popup.disposable.canDispose())&&(this.popup.disposable.dispose(),this._popup$.next(null))}};A=Ke([Z(1,o.Inject(_.DocEventManagerService)),Z(2,o.Inject(exports.DocQuickInsertPopupService)),Z(3,o.Inject(_.DocCanvasPopManagerService))],A);const J=({className:r=""})=>{const t=d.useDependency(exports.DocQuickInsertPopupService),e=d.useDependency(o.IUniverInstanceService),n=d.useDependency(X.IRenderManagerService),i=d.useObservable(h.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC),[e])),s=i&&n.getRenderById(i.getUnitId()),a=s==null?void 0:s.with(A),l=d.useDependency(d.ILayoutService),m=d.useDependency(N.DocSelectionManagerService),c=d.useObservable(t.editPopup$),u=d.useEvent(p=>{var R;const v=a==null?void 0:a.popup;if(!v)return;const x=t.popups,b={keyword:"",menus$:I.combineLatest(x.map(O=>O.menus$)).pipe(I.map(O=>O.flat()))};m.replaceDocRanges([{startOffset:v.startIndex,endOffset:v.startIndex}]),t.setInputOffset({start:v.startIndex-1,end:v.startIndex-1}),t.showPopup({popup:b,index:v.startIndex-1,unitId:(R=i==null?void 0:i.getUnitId())!=null?R:""}),setTimeout(()=>{l.focus()})});return g.jsx("div",{className:M.clsx("univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full univer-p-1.5 univer-shadow-sm hover:univer-bg-gray-100 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-700",M.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":c,"univer-bg-white dark:!univer-bg-gray-900":!c},r),role:"button",tabIndex:0,onClick:u,children:g.jsx(ge,{className:"univer-text-gray-800 dark:!univer-text-gray-200"})})};J.componentKey=me;var He=Object.getOwnPropertyDescriptor,Le=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},V=(r,t)=>(e,n)=>t(e,n,r);exports.DocQuickInsertUIController=class extends o.Disposable{constructor(t,e,n){super(),this._commandService=t,this._docQuickInsertPopupService=e,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[ie,ae,$].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initComponents(){[[q.componentKey,q],[H.componentKey,H],[L.componentKey,L],[z.displayName,z],[Y.displayName,Y],[J.componentKey,J]].forEach(([e,n])=>{e&&this.disposeWithMe(this._componentManager.register(e,n))}),[{keyword:"/",menus$:I.of(Me),preconditions:e=>{var n;return((n=e.range.startNodePosition)==null?void 0:n.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};exports.DocQuickInsertUIController=Le([V(0,o.ICommandService),V(1,o.Inject(exports.DocQuickInsertPopupService)),V(2,o.Inject(d.ComponentManager))],exports.DocQuickInsertUIController);const qe="docs-quick-insert-ui.config",ne={};var Ae=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,We=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ze=(r,t,e,n)=>{for(var i=n>1?void 0:n?Be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},F=(r,t)=>(e,n)=>t(e,n,r),Ie=(r,t,e)=>We(r,typeof t!="symbol"?t+"":t,e);const Ve="DOC_QUICK_INSERT_UI_PLUGIN";exports.UniverDocsQuickInsertUIPlugin=class extends o.Plugin{constructor(t=ne,e,n,i){super(),this._config=t,this._injector=e,this._renderManagerSrv=n,this._configService=i;const{menu:s,...a}=o.merge({},ne,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(qe,a)}onStarting(){[[exports.DocQuickInsertUIController],[exports.DocQuickInsertTriggerController],[exports.DocQuickInsertPopupService]].forEach(e=>this._injector.add(e)),this._injector.get(exports.DocQuickInsertUIController)}onRendered(){this._injector.get(exports.DocQuickInsertTriggerController),this._injector.get(exports.DocQuickInsertPopupService),[[A]].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}};Ie(exports.UniverDocsQuickInsertUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC);Ie(exports.UniverDocsQuickInsertUIPlugin,"pluginName",Ve);exports.UniverDocsQuickInsertUIPlugin=Ze([o.DependentOn(Pe.UniverDrawingUIPlugin,ye.UniverDrawingPlugin,re.UniverDocsDrawingUIPlugin,Se.UniverDocsDrawingPlugin,d.UniverUIPlugin),F(1,o.Inject(o.Injector)),F(2,o.Inject(X.IRenderManagerService)),F(3,o.IConfigService)],exports.UniverDocsQuickInsertUIPlugin);exports.KeywordInputPlaceholderComponentKey=se;exports.QuickInsertPlaceholderComponentKey=oe;
1
+ "use strict";var Ie=Object.defineProperty;var Ce=(r,t,e)=>t in r?Ie(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var y=(r,t,e)=>Ce(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),E=require("@univerjs/docs"),_=require("@univerjs/docs-ui"),d=require("@univerjs/ui"),J=require("@univerjs/engine-render"),I=require("rxjs"),g=require("react/jsx-runtime"),M=require("@univerjs/design"),v=require("react"),ne=require("@univerjs/docs-drawing-ui"),_e=require("@univerjs/docs-drawing"),Se=require("@univerjs/drawing"),ye=require("@univerjs/drawing-ui"),re={id:"doc.command.delete-search-key",type:o.CommandType.COMMAND,handler:(r,t)=>{const e=r.get(o.ICommandService),{start:n,end:i}=t;return e.syncExecuteCommand(_.CutContentCommand.id,{segmentId:"",textRanges:[{startOffset:n,endOffset:n,collapsed:!0}],selections:[{startOffset:n,endOffset:i,collapsed:!1,direction:o.RANGE_DIRECTION.FORWARD}]})}},ie="docs.quick.insert.keyword-input-placeholder",K=()=>{const r=d.useDependency(o.LocaleService);return g.jsx("div",{className:"univer-translate-y-1.5 univer-text-sm univer-text-gray-500",children:r.t("docQuickInsert.keywordInputPlaceholder")})};K.componentKey=ie;const se="docs.quick.insert.placeholder",H=()=>{const r=d.useDependency(o.LocaleService);return g.jsx("div",{className:"univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg",children:g.jsx("span",{children:r.t("docQuickInsert.placeholder")})})};H.componentKey=se;function F(r,t){return r.map(e=>({...e})).filter(e=>{if("children"in e)return e.children=F(e.children,t),e.children.length>0;const n=e.keywords;return n?n.some(i=>i.includes(t)):e.title.toLowerCase().includes(t)})}function oe(r,t){return r.map(e=>{const n={...e};return"children"in n&&(n.children=oe(n.children,t)),n.title=t.t(n.title),"keywords"in n&&(n.keywords=n.keywords.concat(n.title).map(i=>i.toLowerCase())),n})}const Pe=[d.KeyCode.ARROW_UP,d.KeyCode.ARROW_DOWN,d.KeyCode.ENTER],L=()=>{const r=d.useDependency(o.LocaleService),t=d.useDependency(exports.DocQuickInsertPopupService),e=d.useDependency(d.ComponentManager),n=d.useDependency(d.IShortcutService),i=d.useDependency(o.ICommandService),s=v.useMemo(()=>o.generateRandomId(),[]),[a,f]=v.useState(0),m=v.useRef(null),c=v.useRef(0);c.current=0;const u=d.useObservable(t.filterKeyword$,""),p=d.useObservable(t.editPopup$),l=d.useObservable(p==null?void 0:p.popup.menus$,[]),P=v.useMemo(()=>oe(l,r),[l]),[x,w]=v.useState(()=>F(P,u.toLowerCase()));v.useEffect(()=>{const C=requestIdleCallback(()=>{w(F(P,u.toLowerCase()))});return()=>{cancelIdleCallback(C)}},[P,u]);const b=C=>{t.emitMenuSelected(C),i.executeCommand(j.id)};v.useEffect(()=>{const C=new o.DisposableCollection;n.getAllShortcuts().filter(h=>h.binding&&Pe.includes(h.binding)).forEach(h=>{const k=h.preconditions;h.preconditions=()=>!1,C.add(o.toDisposable(()=>{h.preconditions=k}))});const D={id:`quick.insert.popup.enter.${s}`,type:o.CommandType.OPERATION,handler:()=>{const h=m.current;h&&b(h)}},$={id:`quick.insert.popup.move.cursor.up.${s}`,type:o.CommandType.OPERATION,handler:()=>{f(h=>{const k=h-1;return k>=0?k:c.current-1})}},O={id:`quick.insert.popup.move.cursor.down.${s}`,type:o.CommandType.OPERATION,handler:()=>{f(h=>{const k=h+1;return k<=c.current-1?k:0})}};return C.add(i.registerCommand($)),C.add(i.registerCommand(O)),C.add(i.registerCommand(D)),C.add(n.registerShortcut({priority:1e3,id:$.id,binding:d.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:o.Direction.UP}})),C.add(n.registerShortcut({priority:1e3,id:O.id,binding:d.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:o.Direction.DOWN}})),C.add(n.registerShortcut({priority:1e3,id:D.id,binding:d.KeyCode.ENTER,preconditions:()=>!0})),()=>{C.dispose()}},[]),v.useEffect(()=>{f(0)},[x]);const N=v.useRef(new Map);v.useEffect(()=>()=>{N.current.clear()},[]);function R(C){return C.map(S=>{const B=S.icon,D=B?e.get(B):null;if("children"in S)return g.jsx(M.MenuItemGroup,{title:g.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-text-xs univer-text-gray-400",children:[D&&g.jsx("span",{className:"univer-mr-2 univer-inline-flex univer-text-base",children:g.jsx(D,{})}),g.jsx("span",{children:S.title})]}),children:R(S.children)},S.id);const $=c.current,O=a===$;if(O){m.current=S;const h=N.current.get(S.id);h==null||h.scrollIntoView({block:"nearest"})}return c.current++,g.jsx(M.MenuItem,{ref:h=>{h&&N.current.set(S.id,h)},onMouseEnter:()=>f($),onMouseLeave:()=>f(Number.NaN),className:M.clsx("univer-w-[calc(220px-var(--padding-base)*2)] univer-text-sm",{"hover:univer-bg-transparent":!O,"univer-bg-gray-100 dark:!univer-bg-gray-500":O}),onClick:()=>{b(S)},children:g.jsxs("div",{className:"univer-flex univer-w-full univer-items-center univer-px-1",children:[D&&g.jsx("span",{className:"univer-mr-2 univer-inline-flex univer-text-base",children:g.jsx(D,{})}),g.jsx(M.Tooltip,{showIfEllipsis:!0,title:S.title,placement:"right",children:g.jsx("span",{className:"univer-truncate",children:S.title})})]})},S.id)})}const T=x.length>0,X=(p==null?void 0:p.popup.Placeholder)||e.get(H.componentKey);return g.jsx("div",{className:"univer-mt-2",children:T?g.jsx(M.Menu,{wrapperClass:M.clsx("univer-max-h-[360px] univer-w-[220px] univer-overflow-y-auto univer-overflow-x-hidden",M.scrollbarClassName),children:R(x)}):X&&g.jsx(X,{})})};L.componentKey="docs.quick.insert.popup";var xe=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},Q=(r,t)=>(e,n)=>t(e,n,r);const ee={dispose:()=>{}};exports.DocQuickInsertPopupService=class extends o.Disposable{constructor(e,n,i,s,a){super();y(this,"_popups",new Set);y(this,"_editPopup$",new I.BehaviorSubject(void 0));y(this,"editPopup$",this._editPopup$.asObservable());y(this,"_isComposing$",new I.BehaviorSubject(!1));y(this,"isComposing$",this._isComposing$.asObservable());y(this,"_inputOffset$",new I.BehaviorSubject({start:0,end:0}));y(this,"inputOffset$",this._inputOffset$.asObservable());y(this,"filterKeyword$");y(this,"_menuSelectedCallbacks",new Set);y(this,"_inputPlaceholderRenderRoot",null);this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=i,this._renderManagerService=s,this._docSelectionManagerService=a,this.disposeWithMe(this._editPopup$);const f=(c,u)=>{var p,l;return(l=(p=this._univerInstanceService.getCurrentUnitOfType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:p.getBody())==null?void 0:l.dataStream.slice(c,u)};let m="";this.filterKeyword$=this._inputOffset$.pipe(I.map(c=>{var p;const u=f(c.start,c.end);return(p=u==null?void 0:u.slice(1))!=null?p:""}),I.distinctUntilChanged(),I.tap(c=>{m=c})),this.disposeWithMe(I.combineLatest([this.filterKeyword$.pipe(I.tap(c=>{var u,p,l;c.length>0?(p=(u=this._inputPlaceholderRenderRoot)==null?void 0:u.unmount)==null||p.dispose():(l=this._inputPlaceholderRenderRoot)==null||l.mount()})),this.isComposing$.pipe(I.tap(c=>{var u,p,l;c?(p=(u=this._inputPlaceholderRenderRoot)==null?void 0:u.unmount)==null||p.dispose():m.length<=0&&((l=this._inputPlaceholderRenderRoot)==null||l.mount())})),this.editPopup$.pipe(I.tap(c=>{var u,p;c||((p=(u=this._inputPlaceholderRenderRoot)==null?void 0:u.unmount)==null||p.dispose(),this._inputPlaceholderRenderRoot=null)}))]).subscribe())}get popups(){return Array.from(this._popups)}get editPopup(){return this._editPopup$.value}get isComposing(){return this._isComposing$.value}setIsComposing(e){this._isComposing$.next(e)}get inputOffset(){return this._inputOffset$.value}setInputOffset(e){this._inputOffset$.next(e)}getDocEventManagerService(e){var n;return(n=this._renderManagerService.getRenderById(e))==null?void 0:n.with(_.DocEventManagerService)}resolvePopup(e){return Array.from(this._popups).find(n=>n.keyword===e)}registerPopup(e){return this._popups.add(e),()=>{this._popups.delete(e)}}_createInputPlaceholderRenderRoot(e){return{isMounted:!1,mount(){if(this.isMounted)return;this.isMounted=!0;const i=e();this.unmount={dispose:()=>{i.dispose(),this.isMounted=!1}}}}}showPopup(e){var p,l;const{popup:n,index:i,unitId:s}=e;this.closePopup();const a=this._univerInstanceService.getUnit(s),f=(l=(p=a==null?void 0:a.getBody())==null?void 0:p.paragraphs)==null?void 0:l.find(P=>P.startIndex>i);if(!f)return;const m=this.getDocEventManagerService(s),c=m==null?void 0:m.findParagraphBoundByIndex(f.startIndex);if(!c)return;this._inputPlaceholderRenderRoot=this._createInputPlaceholderRenderRoot(()=>{var T;const P=(T=this._renderManagerService.getRenderById(s))==null?void 0:T.with(E.DocSkeletonManagerService),x=this._docSelectionManagerService.getActiveTextRange();if(!P||!x)return ee;const b=P.getSkeleton().findNodeByCharIndex(x.startOffset,x.segmentId,x.segmentPage);if(!((b==null?void 0:b.content)==="\r"))return ee;const R=this._docCanvasPopupManagerService.attachPopupToRange({startOffset:i+1,endOffset:i+1,collapsed:!1},{componentKey:K.componentKey,onClickOutside:()=>{R.dispose()},direction:"horizontal"},s);return R}),this._inputPlaceholderRenderRoot.mount();const u=this._docCanvasPopupManagerService.attachPopupToRect(c.firstLine,{componentKey:L.componentKey,onClickOutside:()=>{this.closePopup()},direction:"bottom"},s);this._editPopup$.next({disposable:u,popup:n,anchor:i,unitId:s})}closePopup(){this.editPopup&&(this.editPopup.disposable.dispose(),this._editPopup$.next(null))}onMenuSelected(e){return this._menuSelectedCallbacks.add(e),()=>{this._menuSelectedCallbacks.delete(e)}}emitMenuSelected(e){const{start:n,end:i}=this.inputOffset;this._commandService.syncExecuteCommand(re.id,{start:n,end:i}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(s=>s(e))},0)}};exports.DocQuickInsertPopupService=be([Q(0,o.Inject(_.DocCanvasPopManagerService)),Q(1,o.Inject(o.IUniverInstanceService)),Q(2,o.Inject(o.ICommandService)),Q(3,o.Inject(J.IRenderManagerService)),Q(4,o.Inject(E.DocSelectionManagerService))],exports.DocQuickInsertPopupService);const ce={type:o.CommandType.OPERATION,id:"doc.operation.show-quick-insert-popup",handler(r,t){const e=r.get(exports.DocQuickInsertPopupService);return t?(e.showPopup(t),!0):!1}},j={type:o.CommandType.OPERATION,id:"doc.operation.close-quick-insert-popup",handler(r){return r.get(exports.DocQuickInsertPopupService).closePopup(),!0}},ae={id:"quick-insert.text.menu",title:"docQuickInsert.menu.text",icon:"TextIcon",keywords:["text"]},ue={id:_.OrderListCommand.id,title:"docQuickInsert.menu.numberedList",icon:"OrderIcon",keywords:["numbered","list","ordered"]},de={id:_.BulletListCommand.id,title:"docQuickInsert.menu.bulletedList",icon:"UnorderIcon",keywords:["bulleted","list","unordered"]},pe={id:_.HorizontalLineCommand.id,title:"docQuickInsert.menu.divider",icon:"DividerIcon",keywords:["divider","line","separate"]},le={id:_.DocCreateTableOperation.id,title:"docQuickInsert.menu.table",icon:"GridIcon",keywords:["table","grid","spreadsheet"]},he={id:ne.InsertDocImageCommand.id,title:"docQuickInsert.menu.image",icon:"AdditionAndSubtractionIcon",keywords:["image","picture","photo"]},Me=[{title:"docQuickInsert.group.basics",id:"quick.insert.group.basic",children:[ae,ue,de,pe,le,he]}],De=new Set([ue.id,de.id,pe.id,le.id,he.id]);var ke=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},U=(r,t)=>(e,n)=>t(e,n,r);exports.DocQuickInsertTriggerController=class extends o.Disposable{constructor(t,e,n,i,s){super(),this._commandService=t,this._textSelectionManagerService=e,this._docQuickInsertPopupService=n,this._shortcutService=i,this._univerInstanceService=s,this.disposeWithMe(this._shortcutService.registerShortcut({id:j.id,binding:d.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var a,f,m;const{_docQuickInsertPopupService:e,_textSelectionManagerService:n,_commandService:i}=this,s=this._univerInstanceService.getCurrentUnitOfType(o.UniverInstanceType.UNIVER_DOC);if(!(s!=null&&s.getDisabled())){if(t.id===_.InsertCommand.id){const c=t.params;if(e.editPopup){e.setInputOffset({start:e.inputOffset.start,end:c.range.endOffset+1});return}const u=n.getActiveTextRange();if(!u)return;const p=e.resolvePopup(c.body.dataStream);if(!p||!(p.preconditions?p.preconditions(c):!0))return;e.setInputOffset({start:u.startOffset-1,end:u.startOffset}),setTimeout(()=>{i.executeCommand(ce.id,{index:u.startOffset-1,unitId:c.unitId,popup:p})},100)}if(t.id===_.IMEInputCommand.id){const c=t.params;!e.isComposing&&c.isCompositionStart&&e.setIsComposing(!0),e.isComposing&&c.isCompositionEnd&&e.setIsComposing(!1)}if(t.id===E.RichTextEditingMutation.id){const c=t.params;if(c.isCompositionEnd){const u=(f=(a=c.textRanges)==null?void 0:a[0])==null?void 0:f.endOffset;u&&e.setInputOffset({start:e.inputOffset.start,end:u})}}if(t.id===_.DeleteCommand.id){const c=t.params;if(e.editPopup&&c.direction===o.DeleteDirection.LEFT){const u=(m=c.len)!=null?m:0;e.setInputOffset({start:e.inputOffset.start,end:c.range.endOffset-u})}}if(t.id===_.MoveCursorOperation.id){const c=t.params;(c.direction===o.Direction.LEFT||c.direction===o.Direction.RIGHT)&&e.editPopup&&i.executeCommand(j.id)}if(t.id===_.DeleteLeftCommand.id){const c=n.getActiveTextRange();if(!e.editPopup||!c)return;c.endOffset<=e.editPopup.anchor&&i.executeCommand(j.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(t=>{t.id!==ae.id&&De.has(t.id)&&this._commandService.executeCommand(t.id)}))}};exports.DocQuickInsertTriggerController=Oe([U(0,o.ICommandService),U(1,o.Inject(E.DocSelectionManagerService)),U(2,o.Inject(exports.DocQuickInsertPopupService)),U(3,o.Inject(d.IShortcutService)),U(4,o.Inject(o.IUniverInstanceService))],exports.DocQuickInsertTriggerController);function A({ref:r,...t}){const{icon:e,id:n,className:i,extend:s,...a}=t,f=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),m=v.useRef(`_${$e()}`);return ve(e,`${n}`,{defIds:e.defIds,idSuffix:m.current},{ref:r,className:f,...a},s)}function ve(r,t,e,n,i){return v.createElement(r.tag,{key:t,...we(r,e,i),...n},(Re(r,e).children||[]).map((s,a)=>ve(s,`${t}-${r.tag}-${a}`,e,void 0,i)))}function we(r,t,e){const n={...r.attrs};e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),r.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(([s,a])=>{s==="mask"&&typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([s,a])=>{typeof a=="string"&&(n[s]=a.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function Re(r,t){var n;const{defIds:e}=t;return!e||e.length===0?r:r.tag==="defs"&&((n=r.children)!=null&&n.length)?{...r,children:r.children.map(i=>typeof i.attrs.id=="string"&&e&&e.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:r}function $e(){return Math.random().toString(36).substring(2,8)}A.displayName="UniverIcon";const Qe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.01953 3.13985C1.01953 2.77258 1.31726 2.47485 1.68453 2.47485H2.73713C3.1044 2.47485 3.40213 2.77258 3.40213 3.13985C3.40213 3.50712 3.1044 3.80485 2.73713 3.80485H1.68453C1.31726 3.80485 1.01953 3.50712 1.01953 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.17734 3.13985C4.17734 2.77258 4.47507 2.47485 4.84234 2.47485H6.94754C7.31481 2.47485 7.61254 2.77258 7.61254 3.13985C7.61254 3.50712 7.31481 3.80485 6.94754 3.80485H4.84234C4.47507 3.80485 4.17734 3.50712 4.17734 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M8.38775 3.13985C8.38775 2.77258 8.68548 2.47485 9.05275 2.47485H11.158C11.5252 2.47485 11.823 2.77258 11.823 3.13985C11.823 3.50712 11.5252 3.80485 11.158 3.80485H9.05275C8.68548 3.80485 8.38775 3.50712 8.38775 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.5982 3.13985C12.5982 2.77258 12.8959 2.47485 13.2632 2.47485H14.3158C14.683 2.47485 14.9808 2.77258 14.9808 3.13985C14.9808 3.50712 14.683 3.80485 14.3158 3.80485H13.2632C12.8959 3.80485 12.5982 3.50712 12.5982 3.13985Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.01953 7.99972C1.01953 7.63245 1.31726 7.33472 1.68453 7.33472H14.3158C14.683 7.33472 14.9808 7.63245 14.9808 7.99972C14.9808 8.36699 14.683 8.66472 14.3158 8.66472H1.68453C1.31726 8.66472 1.01953 8.36699 1.01953 7.99972Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.68453 12.1951C1.31726 12.1951 1.01953 12.4928 1.01953 12.8601C1.01953 13.2273 1.31726 13.5251 1.68453 13.5251H2.73713C3.1044 13.5251 3.40213 13.2273 3.40213 12.8601C3.40213 12.4928 3.1044 12.1951 2.73713 12.1951H1.68453Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.84234 12.1951C4.47507 12.1951 4.17734 12.4928 4.17734 12.8601C4.17734 13.2273 4.47507 13.5251 4.84234 13.5251H6.94754C7.31481 13.5251 7.61254 13.2273 7.61254 12.8601C7.61254 12.4928 7.31481 12.1951 6.94754 12.1951H4.84234Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M9.05275 12.1951C8.68548 12.1951 8.38775 12.4928 8.38775 12.8601C8.38775 13.2273 8.68548 13.5251 9.05275 13.5251H11.158C11.5252 13.5251 11.823 13.2273 11.823 12.8601C11.823 12.4928 11.5252 12.1951 11.158 12.1951H9.05275Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M13.2632 12.1951C12.8959 12.1951 12.5982 12.4928 12.5982 12.8601C12.5982 13.2273 12.8959 13.5251 13.2632 13.5251H14.3158C14.683 13.5251 14.9808 13.2273 14.9808 12.8601C14.9808 12.4928 14.683 12.1951 14.3158 12.1951H13.2632Z"}}]},G=v.forwardRef(function(t,e){return v.createElement(A,Object.assign({},t,{id:"divider-icon",ref:e,icon:Qe}))});G.displayName="DividerIcon";const Ue={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},ge=v.forwardRef(function(t,e){return v.createElement(A,Object.assign({},t,{id:"increase-icon",ref:e,icon:Ue}))});ge.displayName="IncreaseIcon";const je={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#text-icon_clip0_1293_26)"},children:[{tag:"path",attrs:{d:"M2.22891 2.07227C1.89754 2.07227 1.62891 2.34089 1.62891 2.67227C1.62891 3.00364 1.89754 3.27227 2.22891 3.27227H6.29541V14.0056C6.29541 14.337 6.56404 14.6056 6.89541 14.6056C7.22678 14.6056 7.49541 14.337 7.49541 14.0056V3.27227H11.5622C11.8936 3.27227 12.1622 3.00364 12.1622 2.67227C12.1622 2.34089 11.8936 2.07227 11.5622 2.07227H2.22891Z"}},{tag:"path",attrs:{d:"M10.2289 6.40552C9.89754 6.40552 9.62891 6.67415 9.62891 7.00552C9.62891 7.33689 9.89754 7.60552 10.2289 7.60552H12.2954V14.0055C12.2954 14.3369 12.564 14.6055 12.8954 14.6055C13.2268 14.6055 13.4954 14.3369 13.4954 14.0055V7.60552H15.5622C15.8936 7.60552 16.1622 7.33689 16.1622 7.00552C16.1622 6.67415 15.8936 6.40552 15.5622 6.40552H10.2289Z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"text-icon_clip0_1293_26"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.9)"}}]}]}],defIds:["text-icon_clip0_1293_26"]},z=v.forwardRef(function(t,e){return v.createElement(A,Object.assign({},t,{id:"text-icon",ref:e,icon:je}))});z.displayName="TextIcon";const fe="doc.quick-insert.button";var Ee=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},W=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n,i){super();y(this,"_popup$",new I.BehaviorSubject(null));y(this,"popup$",this._popup$.asObservable());this._context=t,this._docEventManagerService=e,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=i,this._init()}get popup(){return this._popup$.value}_init(){this.disposeWithMe(I.combineLatest([this._docEventManagerService.hoverParagraphLeftRealTime$,this._docEventManagerService.hoverParagraphRealTime$]).subscribe(([t,e])=>{var s;const n=t!=null?t:e,i=this._context.unit.getDisabled();if(!n||i){this._hideMenu(!0);return}if(n.paragraphStart===n.paragraphEnd){if(this._docQuickInsertPopupService.editPopup||n.startIndex===((s=this.popup)==null?void 0:s.startIndex))return;this._hideMenu(!0);const a=this._docCanvasPopManagerService.attachPopupToRect(n.firstLine,{componentKey:fe,direction:"left-center"},this._context.unit.getUnitId());this._popup$.next({startIndex:n.startIndex,disposable:a})}else this._hideMenu(!0)}))}_hideMenu(t){this._docQuickInsertPopupService.editPopup||this.popup&&(t||this.popup.disposable.canDispose())&&(this.popup.disposable.dispose(),this._popup$.next(null))}};q=Ne([W(1,o.Inject(_.DocEventManagerService)),W(2,o.Inject(exports.DocQuickInsertPopupService)),W(3,o.Inject(_.DocCanvasPopManagerService))],q);const Y=({className:r=""})=>{const t=d.useDependency(exports.DocQuickInsertPopupService),e=d.useDependency(o.IUniverInstanceService),n=d.useDependency(J.IRenderManagerService),i=d.useObservable(v.useMemo(()=>e.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_DOC),[e])),s=i&&n.getRenderById(i.getUnitId()),a=s==null?void 0:s.with(q),f=d.useDependency(d.ILayoutService),m=d.useDependency(E.DocSelectionManagerService),c=d.useObservable(t.editPopup$),u=d.useEvent(p=>{var w;const l=a==null?void 0:a.popup;if(!l)return;const P=t.popups,x={keyword:"",menus$:I.combineLatest(P.map(b=>b.menus$)).pipe(I.map(b=>b.flat()))};m.replaceDocRanges([{startOffset:l.startIndex,endOffset:l.startIndex}]),t.setInputOffset({start:l.startIndex-1,end:l.startIndex-1}),t.showPopup({popup:x,index:l.startIndex-1,unitId:(w=i==null?void 0:i.getUnitId())!=null?w:""}),setTimeout(()=>{f.focus()})});return g.jsx("div",{className:M.clsx("univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full univer-p-1.5 univer-shadow-sm hover:univer-bg-gray-100 dark:!univer-text-gray-200 dark:hover:!univer-bg-gray-700",M.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":c,"univer-bg-white dark:!univer-bg-gray-900":!c},r),role:"button",tabIndex:0,onClick:u,children:g.jsx(ge,{className:"univer-text-gray-800 dark:!univer-text-gray-200"})})};Y.componentKey=fe;var Te=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},Z=(r,t)=>(e,n)=>t(e,n,r);exports.DocQuickInsertUIController=class extends o.Disposable{constructor(t,e,n){super(),this._commandService=t,this._docQuickInsertPopupService=e,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[re,ce,j].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initComponents(){[[L.componentKey,L],[K.componentKey,K],[H.componentKey,H],[G.displayName,G],[z.displayName,z],[Y.componentKey,Y]].forEach(([e,n])=>{e&&this.disposeWithMe(this._componentManager.register(e,n))}),[{keyword:"/",menus$:I.of(Me),preconditions:e=>{var n;return((n=e.range.startNodePosition)==null?void 0:n.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};exports.DocQuickInsertUIController=Ke([Z(0,o.ICommandService),Z(1,o.Inject(exports.DocQuickInsertPopupService)),Z(2,o.Inject(d.ComponentManager))],exports.DocQuickInsertUIController);const He="docs-quick-insert-ui.config",te={};var Le=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Ae=(r,t,e)=>t in r?Le(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Be=(r,t,e,n)=>{for(var i=n>1?void 0:n?qe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=a(i)||i);return i},V=(r,t)=>(e,n)=>t(e,n,r),me=(r,t,e)=>Ae(r,typeof t!="symbol"?t+"":t,e);const We="DOC_QUICK_INSERT_UI_PLUGIN";exports.UniverDocsQuickInsertUIPlugin=class extends o.Plugin{constructor(t=te,e,n,i){super(),this._config=t,this._injector=e,this._renderManagerSrv=n,this._configService=i;const{menu:s,...a}=o.merge({},te,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(He,a)}onStarting(){[[exports.DocQuickInsertUIController],[exports.DocQuickInsertTriggerController],[exports.DocQuickInsertPopupService]].forEach(e=>this._injector.add(e)),this._injector.get(exports.DocQuickInsertUIController)}onRendered(){this._injector.get(exports.DocQuickInsertTriggerController),this._injector.get(exports.DocQuickInsertPopupService),[[q]].forEach(t=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,t)})}};me(exports.UniverDocsQuickInsertUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC);me(exports.UniverDocsQuickInsertUIPlugin,"pluginName",We);exports.UniverDocsQuickInsertUIPlugin=Be([o.DependentOn(ye.UniverDrawingUIPlugin,Se.UniverDrawingPlugin,ne.UniverDocsDrawingUIPlugin,_e.UniverDocsDrawingPlugin,d.UniverUIPlugin),V(1,o.Inject(o.Injector)),V(2,o.Inject(J.IRenderManagerService)),V(3,o.IConfigService)],exports.UniverDocsQuickInsertUIPlugin);exports.KeywordInputPlaceholderComponentKey=ie;exports.QuickInsertPlaceholderComponentKey=se;