@univerjs/docs-quick-insert-ui 0.20.1 → 0.21.0-insiders.20260422-d7fcb4d

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.
Files changed (42) hide show
  1. package/lib/cjs/index.js +1083 -1
  2. package/lib/cjs/locale/ca-ES.js +18 -1
  3. package/lib/cjs/locale/en-US.js +33 -1
  4. package/lib/cjs/locale/es-ES.js +18 -1
  5. package/lib/cjs/locale/fa-IR.js +18 -1
  6. package/lib/cjs/locale/fr-FR.js +18 -1
  7. package/lib/cjs/locale/ja-JP.js +18 -1
  8. package/lib/cjs/locale/ko-KR.js +18 -1
  9. package/lib/cjs/locale/ru-RU.js +18 -1
  10. package/lib/cjs/locale/sk-SK.js +18 -1
  11. package/lib/cjs/locale/vi-VN.js +18 -1
  12. package/lib/cjs/locale/zh-CN.js +18 -1
  13. package/lib/cjs/locale/zh-TW.js +18 -1
  14. package/lib/es/index.js +1057 -1
  15. package/lib/es/locale/ca-ES.js +17 -1
  16. package/lib/es/locale/en-US.js +32 -1
  17. package/lib/es/locale/es-ES.js +17 -1
  18. package/lib/es/locale/fa-IR.js +17 -1
  19. package/lib/es/locale/fr-FR.js +17 -1
  20. package/lib/es/locale/ja-JP.js +17 -1
  21. package/lib/es/locale/ko-KR.js +17 -1
  22. package/lib/es/locale/ru-RU.js +17 -1
  23. package/lib/es/locale/sk-SK.js +17 -1
  24. package/lib/es/locale/vi-VN.js +17 -1
  25. package/lib/es/locale/zh-CN.js +17 -1
  26. package/lib/es/locale/zh-TW.js +17 -1
  27. package/lib/index.js +1057 -1
  28. package/lib/locale/ca-ES.js +17 -1
  29. package/lib/locale/en-US.js +32 -1
  30. package/lib/locale/es-ES.js +17 -1
  31. package/lib/locale/fa-IR.js +17 -1
  32. package/lib/locale/fr-FR.js +17 -1
  33. package/lib/locale/ja-JP.js +17 -1
  34. package/lib/locale/ko-KR.js +17 -1
  35. package/lib/locale/ru-RU.js +17 -1
  36. package/lib/locale/sk-SK.js +17 -1
  37. package/lib/locale/vi-VN.js +17 -1
  38. package/lib/locale/zh-CN.js +17 -1
  39. package/lib/locale/zh-TW.js +17 -1
  40. package/lib/umd/index.js +1 -1
  41. package/package.json +14 -14
  42. package/LICENSE +0 -176
package/lib/cjs/index.js CHANGED
@@ -1 +1,1083 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/docs`),n=require(`@univerjs/docs-ui`),r=require(`@univerjs/ui`),i=require(`@univerjs/engine-render`),a=require(`rxjs`),o=require(`react`),s=require(`react/jsx-runtime`),c=require(`@univerjs/design`),l=require(`@univerjs/docs-drawing-ui`),u=require(`@univerjs/icons`),d=require(`@univerjs/docs-drawing`),f=require(`@univerjs/drawing`),p=require(`@univerjs/drawing-ui`);const m={id:`doc.command.delete-search-key`,type:e.CommandType.COMMAND,handler:(t,r)=>{let i=t.get(e.ICommandService),{start:a,end:o}=r;return i.syncExecuteCommand(n.CutContentCommand.id,{segmentId:``,textRanges:[{startOffset:a,endOffset:a,collapsed:!0}],selections:[{startOffset:a,endOffset:o,collapsed:!1,direction:e.RANGE_DIRECTION.FORWARD}]})}},h=`docs.quick.insert.keyword-input-placeholder`;function g(e,t){if(typeof document>`u`)return e.length*11;let n=document.createElement(`canvas`).getContext(`2d`);return n?(n.font=t,Math.ceil(n.measureText(e).width)):e.length*11}const _=({popup:t})=>{var n,a,c,l,u,d,f,p,m,h,_;let v=(0,r.useDependency)(e.LocaleService).t(`docQuickInsert.keywordInputPlaceholder`),y=(0,i.ptToPixel)((n=(a=t.extraProps)==null?void 0:a.fontSize)==null?11:n),b=(c=(l=t.extraProps)==null?void 0:l.fontString)==null?`${y}px sans-serif`:c,x=(u=(d=t.extraProps)==null?void 0:d.ascent)==null?y:u,S=Math.max((f=(p=t.extraProps)==null?void 0:p.contentHeight)==null?y:f,y),C=(0,o.useMemo)(()=>g(v,b),[b,v]);return(0,s.jsx)(`div`,{className:`univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors dark:!univer-text-gray-400`,children:(0,s.jsx)(`svg`,{width:C,height:S,viewBox:`0 0 ${C} ${S}`,style:{overflow:`visible`,display:`block`},children:(0,s.jsx)(`text`,{x:0,y:x,fill:`currentColor`,style:{font:b,fontFamily:(m=t.extraProps)==null?void 0:m.fontFamily,fontStyle:(h=t.extraProps)==null?void 0:h.fontStyle,fontWeight:(_=t.extraProps)==null?void 0:_.fontWeight},children:v})})})};_.componentKey=h;function v(e){return`children`in e}function y(e){return e.flatMap(e=>v(e)?y(e.children):e)}function b(e){return y(e).length}function x(e){let{menus:t,focusedMenuIndex:n,focusedMenuRef:r,menuNodeMapRef:i,componentManager:a,onFocusedMenuIndexChange:l,onSelect:u}=e,d=(0,o.useMemo)(()=>y(t),[t]);(0,o.useEffect)(()=>{var e,t;let a=Number.isNaN(n)||(e=d[n])==null?null:e;r.current=a,a&&((t=i.current.get(a.id))==null||t.scrollIntoView({block:`nearest`}))},[d,n,r,i]);let f=(0,o.useRef)(0);f.current=0;function p(e){return e.map((t,r)=>{let o=t.icon,d=o?a.get(o):null;if(v(t))return(0,s.jsxs)(`div`,{className:(0,c.clsx)(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&c.borderBottomClassName),children:[(0,s.jsxs)(`div`,{className:`univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2 univer-text-xs univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-300`,children:[d&&(0,s.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,s.jsx)(d,{})}),(0,s.jsx)(`span`,{children:t.title})]}),(0,s.jsx)(`div`,{className:`univer-grid univer-gap-1`,children:p(t.children)})]},t.id);let m=f.current,h=n===m;return f.current+=1,(0,s.jsx)(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:(0,c.clsx)(`univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900 univer-outline-none hover:univer-bg-gray-50 dark:!univer-text-white dark:hover:!univer-bg-gray-600`,{"hover:univer-bg-transparent":!h,"univer-bg-gray-50 dark:!univer-bg-gray-600":h}),onMouseEnter:()=>l(m),onMouseLeave:()=>l(NaN),onClick:()=>u(t),children:(0,s.jsxs)(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&(0,s.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,s.jsx)(d,{})}),(0,s.jsx)(c.Tooltip,{showIfEllipsis:!0,title:t.title,placement:`right`,children:(0,s.jsx)(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return(0,s.jsx)(`div`,{className:(0,c.clsx)(`univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2 univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white`,c.borderClassName,c.scrollbarClassName),onWheel:e=>e.stopPropagation(),children:p(t)})}const S=`docs.quick.insert.placeholder`,C=()=>(0,s.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:(0,s.jsx)(`span`,{children:(0,r.useDependency)(e.LocaleService).t(`docQuickInsert.placeholder`)})});C.componentKey=S;function w(e,t){return e.map(e=>({...e})).filter(e=>{if(`children`in e)return e.children=w(e.children,t),e.children.length>0;let n=e.keywords;return n?n.some(e=>e.includes(t)):e.title.toLowerCase().includes(t)})}function T(e,t){return e.map(e=>{let n={...e};return`children`in n&&(n.children=T(n.children,t)),n.title=t.t(n.title),`keywords`in n&&(n.keywords=n.keywords.concat(n.title).map(e=>e.toLowerCase())),n})}const E=[r.KeyCode.ARROW_UP,r.KeyCode.ARROW_DOWN,r.KeyCode.ENTER],D=()=>{let t=(0,r.useDependency)(e.LocaleService),n=(0,r.useDependency)(F),i=(0,r.useDependency)(r.ComponentManager),a=(0,r.useDependency)(r.IShortcutService),c=(0,r.useDependency)(e.ICommandService),l=(0,o.useMemo)(()=>(0,e.generateRandomId)(),[]),[u,d]=(0,o.useState)(0),f=(0,o.useRef)(null),p=(0,r.useObservable)(n.filterKeyword$,``),m=(0,r.useObservable)(n.editPopup$),h=(0,r.useObservable)(m==null?void 0:m.popup.menus$,[]),g=(0,o.useMemo)(()=>T(h,t),[h]),[_,v]=(0,o.useState)(()=>w(g,p.toLowerCase())),y=(0,o.useMemo)(()=>b(_),[_]),S=(0,o.useRef)(y);(0,o.useEffect)(()=>{S.current=y},[y]),(0,o.useEffect)(()=>{let e=requestIdleCallback(()=>{v(w(g,p.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[g,p]);let D=e=>{n.emitMenuSelected(e),c.executeCommand(L.id)};(0,o.useEffect)(()=>{let t=new e.DisposableCollection;a.getAllShortcuts().filter(e=>e.binding&&E.includes(e.binding)).forEach(n=>{let r=n.preconditions;n.preconditions=()=>!1,t.add((0,e.toDisposable)(()=>{n.preconditions=r}))});let n={id:`quick.insert.popup.enter.${l}`,type:e.CommandType.OPERATION,handler:()=>{let e=f.current;e&&D(e)}},i={id:`quick.insert.popup.move.cursor.up.${l}`,type:e.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e-1;return t>=0?t:S.current-1})}},o={id:`quick.insert.popup.move.cursor.down.${l}`,type:e.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e+1;return t<=S.current-1?t:0})}};return t.add(c.registerCommand(i)),t.add(c.registerCommand(o)),t.add(c.registerCommand(n)),t.add(a.registerShortcut({priority:1e3,id:i.id,binding:r.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:e.Direction.UP}})),t.add(a.registerShortcut({priority:1e3,id:o.id,binding:r.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:e.Direction.DOWN}})),t.add(a.registerShortcut({priority:1e3,id:n.id,binding:r.KeyCode.ENTER,preconditions:()=>!0})),()=>{t.dispose()}},[c,l,a]),(0,o.useEffect)(()=>{d(0)},[_]);let O=(0,o.useRef)(new Map);(0,o.useEffect)(()=>()=>{O.current.clear()},[]);let k=_.length>0,A=(m==null?void 0:m.popup.Placeholder)||i.get(C.componentKey);return(0,s.jsx)(`div`,{className:`univer-mt-2`,children:k?(0,s.jsx)(x,{menus:_,focusedMenuIndex:u,focusedMenuRef:f,menuNodeMapRef:O,componentManager:i,onFocusedMenuIndexChange:d,onSelect:D}):A&&(0,s.jsx)(A,{})})};D.componentKey=`docs.quick.insert.popup`;function O(e){"@babel/helpers - typeof";return O=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},O(e)}function k(e,t){if(O(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(O(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function A(e){var t=k(e,`string`);return O(t)==`symbol`?t:t+``}function j(e,t,n){return(t=A(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e,t){return function(n,r){t(n,r,e)}}function N(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const P={dispose:()=>{}};let F=class extends e.Disposable{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 t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(n.DocEventManagerService)}constructor(t,n,r,i,o){super(),this._docCanvasPopupManagerService=t,this._univerInstanceService=n,this._commandService=r,this._renderManagerService=i,this._docSelectionManagerService=o,j(this,`_popups`,new Set),j(this,`_editPopup$`,new a.BehaviorSubject(void 0)),j(this,`editPopup$`,this._editPopup$.asObservable()),j(this,`_isComposing$`,new a.BehaviorSubject(!1)),j(this,`isComposing$`,this._isComposing$.asObservable()),j(this,`_inputOffset$`,new a.BehaviorSubject({start:0,end:0})),j(this,`inputOffset$`,this._inputOffset$.asObservable()),j(this,`filterKeyword$`,void 0),j(this,`_menuSelectedCallbacks`,new Set),j(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let s=(t,n)=>{var r;return(r=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_DOC))==null||(r=r.getBody())==null?void 0:r.dataStream.slice(t,n)},c=``;this.filterKeyword$=this._inputOffset$.pipe((0,a.map)(e=>{var t;let n=s(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),(0,a.distinctUntilChanged)(),(0,a.tap)(e=>{c=e})),this.disposeWithMe((0,a.combineLatest)([this.filterKeyword$.pipe((0,a.tap)(e=>{if(e.length>0){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;(n=this._inputPlaceholderRenderRoot)==null||n.mount()}})),this.isComposing$.pipe((0,a.tap)(e=>{if(e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;c.length<=0&&((n=this._inputPlaceholderRenderRoot)==null||n.mount())}})),this.editPopup$.pipe((0,a.tap)(e=>{if(!e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose(),this._inputPlaceholderRenderRoot=null}}))]).subscribe())}resolvePopup(e){return Array.from(this._popups).find(t=>t.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;let t=e();this.unmount={dispose:()=>{t.dispose(),this.isMounted=!1}}}}}_getParagraphBound(e,t){var n,r;let i=this._univerInstanceService.getUnit(e),a=i==null||(n=i.getBody())==null||(n=n.paragraphs)==null?void 0:n.find(e=>e.startIndex>t);if(!a)return null;let o=this.getDocEventManagerService(e);return(r=o==null?void 0:o.findParagraphBoundByIndex(a.startIndex))==null?null:r}_getKeywordPlaceholderAnchorRect(e,t,r,i){let a=t.findNodePositionByCharIndex(r.startOffset,!0,r.segmentId,r.segmentPage);if(!a)return i;let o=e.getOffsetConfig(),{contentBoxPointGroup:s}=new n.NodePositionConvertToCursor(o,t).getRangePointData(a,a);if(s.length===0)return i;let c=(0,n.getAnchorBounding)(s),l=c.left+o.docsLeft,u=c.top+o.docsTop;return{left:l,right:l,top:u,bottom:u+c.height}}_getKeywordPlaceholderExtraProps(e){var t,n,r,i,a,o,s,c,l,u,d,f,p;return{fontSize:(t=e.ts)==null?void 0:t.fs,fontString:(n=e.fontStyle)==null?void 0:n.fontString,fontFamily:(r=(i=(a=e.fontStyle)==null?void 0:a.fontFamily)==null?(o=e.ts)==null?void 0:o.ff:i)==null?void 0:r,fontStyle:(s=e.ts)!=null&&s.it?`italic`:`normal`,fontWeight:(c=e.ts)!=null&&c.bl?`bold`:`normal`,ascent:(l=e.bBox)==null?void 0:l.ba,contentHeight:((u=(d=e.bBox)==null?void 0:d.ba)==null?0:u)+((f=(p=e.bBox)==null?void 0:p.bd)==null?0:f)||void 0}}_mountInputPlaceholder(e,n){let r=this._renderManagerService.getRenderById(e),i=r==null?void 0:r.with(t.DocSkeletonManagerService),a=this._docSelectionManagerService.getActiveTextRange();if(!r||!i||!a)return P;let o=i.getSkeleton(),s=o.findNodeByCharIndex(a.startOffset,a.segmentId,a.segmentPage);if((s==null?void 0:s.content)!==`\r`||!s)return P;let c=r.mainComponent,l=this._getKeywordPlaceholderAnchorRect(c,o,a,n),u=this._getKeywordPlaceholderExtraProps(s),d=this._docCanvasPopupManagerService.attachPopupToRect(l,{componentKey:_.componentKey,extraProps:u,onClickOutside:()=>{d.dispose()},direction:`horizontal`},e);return d}showPopup(e){let{popup:t,index:n,unitId:r}=e;this.closePopup();let i=this._getParagraphBound(r,n);if(!i)return;this._inputPlaceholderRenderRoot=this._createInputPlaceholderRenderRoot(()=>this._mountInputPlaceholder(r,i.firstLine)),this._inputPlaceholderRenderRoot.mount();let a=this._docCanvasPopupManagerService.attachPopupToRect(i.firstLine,{componentKey:D.componentKey,onClickOutside:()=>{this.closePopup()},direction:`bottom`},r);this._editPopup$.next({disposable:a,popup:t,anchor:n,unitId:r})}closePopup(){this.editPopup&&(this.editPopup.disposable.dispose(),this._editPopup$.next(null))}onMenuSelected(e){return this._menuSelectedCallbacks.add(e),()=>{this._menuSelectedCallbacks.delete(e)}}emitMenuSelected(e){let{start:t,end:n}=this.inputOffset;this._commandService.syncExecuteCommand(m.id,{start:t,end:n}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(t=>t(e))},0)}};F=N([M(0,(0,e.Inject)(n.DocCanvasPopManagerService)),M(1,(0,e.Inject)(e.IUniverInstanceService)),M(2,(0,e.Inject)(e.ICommandService)),M(3,(0,e.Inject)(i.IRenderManagerService)),M(4,(0,e.Inject)(t.DocSelectionManagerService))],F);const I={type:e.CommandType.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(F);return t?(n.showPopup(t),!0):!1}},L={type:e.CommandType.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(F).closePopup(),!0}};let ee=function(e){return e.Basic=`quick.insert.group.basic`,e.Media=`quick.insert.group.media`,e}({});const R={id:`quick-insert.text.menu`,title:`docQuickInsert.menu.text`,icon:`TextIcon`,keywords:[`text`]},z={id:n.OrderListCommand.id,title:`docQuickInsert.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},B={id:n.BulletListCommand.id,title:`docQuickInsert.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},V={id:n.HorizontalLineCommand.id,title:`docQuickInsert.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},H={id:n.DocCreateTableOperation.id,title:`docQuickInsert.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},U={id:l.InsertDocImageCommand.id,title:`docQuickInsert.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},W=[{title:`docQuickInsert.group.basics`,id:ee.Basic,children:[R,z,B,V,H,U]}],G=new Set([z.id,B.id,V.id,H.id,U.id]);let K=class extends e.Disposable{constructor(e,t,n,i,a){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=i,this._univerInstanceService=a,this.disposeWithMe(this._shortcutService.registerShortcut({id:L.id,binding:r.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{let{_docQuickInsertPopupService:i,_textSelectionManagerService:a,_commandService:o}=this,s=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_DOC);if(!(s!=null&&s.getDisabled())){if(r.id===n.InsertCommand.id){let e=r.params;if(i.editPopup){i.setInputOffset({start:i.inputOffset.start,end:e.range.endOffset+1});return}let t=a.getActiveTextRange();if(!t)return;let n=i.resolvePopup(e.body.dataStream);if(!n||!(!n.preconditions||n.preconditions(e)))return;i.setInputOffset({start:t.startOffset-1,end:t.startOffset}),setTimeout(()=>{o.executeCommand(I.id,{index:t.startOffset-1,unitId:e.unitId,popup:n})},100)}if(r.id===n.IMEInputCommand.id){let e=r.params;!i.isComposing&&e.isCompositionStart&&i.setIsComposing(!0),i.isComposing&&e.isCompositionEnd&&i.setIsComposing(!1)}if(r.id===t.RichTextEditingMutation.id){let e=r.params;if(e.isCompositionEnd){var c;let t=(c=e.textRanges)==null||(c=c[0])==null?void 0:c.endOffset;t&&i.setInputOffset({start:i.inputOffset.start,end:t})}}if(r.id===n.DeleteCommand.id){let t=r.params;if(i.editPopup&&t.direction===e.DeleteDirection.LEFT){var l;let e=(l=t.len)==null?0:l;i.setInputOffset({start:i.inputOffset.start,end:t.range.endOffset-e})}}if(r.id===n.MoveCursorOperation.id){let t=r.params;(t.direction===e.Direction.LEFT||t.direction===e.Direction.RIGHT)&&i.editPopup&&o.executeCommand(L.id)}if(r.id===n.DeleteLeftCommand.id){let e=a.getActiveTextRange();if(!i.editPopup||!e)return;e.endOffset<=i.editPopup.anchor&&o.executeCommand(L.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==R.id&&G.has(e.id)&&this._commandService.executeCommand(e.id)}))}};K=N([M(0,e.ICommandService),M(1,(0,e.Inject)(t.DocSelectionManagerService)),M(2,(0,e.Inject)(F)),M(3,(0,e.Inject)(r.IShortcutService)),M(4,(0,e.Inject)(e.IUniverInstanceService))],K);let q=class extends e.Disposable{get popup(){return this._popup$.value}constructor(e,t,n,r){super(),this._context=e,this._docEventManagerService=t,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=r,j(this,`_popup$`,new a.BehaviorSubject(null)),j(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe((0,a.combineLatest)([this._docEventManagerService.hoverParagraphLeftRealTime$,this._docEventManagerService.hoverParagraphRealTime$]).subscribe(([e,t])=>{let n=e==null?t:e,r=this._context.unit.getDisabled();if(!n||r){this._hideMenu(!0);return}if(n.paragraphStart===n.paragraphEnd){var i;if(this._docQuickInsertPopupService.editPopup||n.startIndex===((i=this.popup)==null?void 0:i.startIndex))return;this._hideMenu(!0);let e=this._docCanvasPopManagerService.attachPopupToRect(n.firstLine,{componentKey:J,direction:`left-center`},this._context.unit.getUnitId());this._popup$.next({startIndex:n.startIndex,disposable:e})}else this._hideMenu(!0)}))}_hideMenu(e){this._docQuickInsertPopupService.editPopup||this.popup&&(e||this.popup.disposable.canDispose())&&(this.popup.disposable.dispose(),this._popup$.next(null))}};q=N([M(1,(0,e.Inject)(n.DocEventManagerService)),M(2,(0,e.Inject)(F)),M(3,(0,e.Inject)(n.DocCanvasPopManagerService))],q);const J=`doc.quick-insert.button`,Y=({className:n=``})=>{let l=(0,r.useDependency)(F),d=(0,r.useDependency)(e.IUniverInstanceService),f=(0,r.useDependency)(i.IRenderManagerService),p=(0,r.useObservable)((0,o.useMemo)(()=>d.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_DOC),[d])),m=p&&f.getRenderById(p.getUnitId()),h=m==null?void 0:m.with(q),g=(0,r.useDependency)(r.ILayoutService),_=(0,r.useDependency)(t.DocSelectionManagerService),v=(0,r.useObservable)(l.editPopup$),y=(0,r.useEvent)(()=>{var e;let t=h==null?void 0:h.popup;if(!t)return;let n=l.popups,r={keyword:``,menus$:(0,a.combineLatest)(n.map(e=>e.menus$)).pipe((0,a.map)(e=>e.flat()))};_.replaceDocRanges([{startOffset:t.startIndex,endOffset:t.startIndex}]),l.setInputOffset({start:t.startIndex-1,end:t.startIndex-1}),l.showPopup({popup:r,index:t.startIndex-1,unitId:(e=p==null?void 0:p.getUnitId())==null?``:e}),setTimeout(()=>{g.focus()})});return(0,s.jsx)(`div`,{className:(0,c.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`,c.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":v,"univer-bg-white dark:!univer-bg-gray-900":!v},n),role:`button`,tabIndex:0,onClick:y,children:(0,s.jsx)(u.IncreaseIcon,{className:`univer-text-gray-800 dark:!univer-text-gray-200`})})};Y.componentKey=J;let X=class extends e.Disposable{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[m,I,L].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[D.componentKey,D],[_.componentKey,_],[C.componentKey,C],[u.DividerIcon.displayName,u.DividerIcon],[u.TextIcon.displayName,u.TextIcon],[Y.componentKey,Y]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:(0,a.of)(W),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};X=N([M(0,e.ICommandService),M(1,(0,e.Inject)(F)),M(2,(0,e.Inject)(r.ComponentManager))],X);var te=`@univerjs/docs-quick-insert-ui`,ne=`0.20.1`;const Z=`docs-quick-insert-ui.config`;Symbol(Z);const Q={};let $=class extends e.Plugin{constructor(t=Q,n,r,i){super(),this._config=t,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,e.merge)({},Q,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(Z,o)}onStarting(){[[X],[K],[F]].forEach(e=>this._injector.add(e)),this._injector.get(X)}onRendered(){this._injector.get(K),this._injector.get(F),[[q]].forEach(t=>{this._renderManagerSrv.registerRenderModule(e.UniverInstanceType.UNIVER_DOC,t)})}};j($,`type`,e.UniverInstanceType.UNIVER_DOC),j($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),j($,`packageName`,te),j($,`version`,ne),$=N([(0,e.DependentOn)(p.UniverDrawingUIPlugin,f.UniverDrawingPlugin,l.UniverDocsDrawingUIPlugin,d.UniverDocsDrawingPlugin,r.UniverUIPlugin),M(1,(0,e.Inject)(e.Injector)),M(2,(0,e.Inject)(i.IRenderManagerService)),M(3,e.IConfigService)],$),Object.defineProperty(exports,`DocQuickInsertPopupService`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`DocQuickInsertTriggerController`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`DocQuickInsertUIController`,{enumerable:!0,get:function(){return X}}),exports.KeywordInputPlaceholderComponentKey=h,exports.QuickInsertPlaceholderComponentKey=S,Object.defineProperty(exports,`UniverDocsQuickInsertUIPlugin`,{enumerable:!0,get:function(){return $}});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_docs = require("@univerjs/docs");
4
+ let _univerjs_docs_ui = require("@univerjs/docs-ui");
5
+ let _univerjs_ui = require("@univerjs/ui");
6
+ let _univerjs_engine_render = require("@univerjs/engine-render");
7
+ let rxjs = require("rxjs");
8
+ let react = require("react");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ let _univerjs_design = require("@univerjs/design");
11
+ let _univerjs_docs_drawing_ui = require("@univerjs/docs-drawing-ui");
12
+ let _univerjs_icons = require("@univerjs/icons");
13
+ let _univerjs_docs_drawing = require("@univerjs/docs-drawing");
14
+ let _univerjs_drawing = require("@univerjs/drawing");
15
+ let _univerjs_drawing_ui = require("@univerjs/drawing-ui");
16
+
17
+ //#region src/commands/commands/doc-quick-insert.command.ts
18
+ const DeleteSearchKeyCommand = {
19
+ id: "doc.command.delete-search-key",
20
+ type: _univerjs_core.CommandType.COMMAND,
21
+ handler: (accessor, params) => {
22
+ const commandService = accessor.get(_univerjs_core.ICommandService);
23
+ const { start, end } = params;
24
+ return commandService.syncExecuteCommand(_univerjs_docs_ui.CutContentCommand.id, {
25
+ segmentId: "",
26
+ textRanges: [{
27
+ startOffset: start,
28
+ endOffset: start,
29
+ collapsed: true
30
+ }],
31
+ selections: [{
32
+ startOffset: start,
33
+ endOffset: end,
34
+ collapsed: false,
35
+ direction: _univerjs_core.RANGE_DIRECTION.FORWARD
36
+ }]
37
+ });
38
+ }
39
+ };
40
+
41
+ //#endregion
42
+ //#region src/views/KeywordInputPlaceholder.tsx
43
+ const KeywordInputPlaceholderComponentKey = "docs.quick.insert.keyword-input-placeholder";
44
+ const DEFAULT_FONT_SIZE = 11;
45
+ function measureTextWidth(text, font) {
46
+ if (typeof document === "undefined") return text.length * DEFAULT_FONT_SIZE;
47
+ const context = document.createElement("canvas").getContext("2d");
48
+ if (!context) return text.length * DEFAULT_FONT_SIZE;
49
+ context.font = font;
50
+ return Math.ceil(context.measureText(text).width);
51
+ }
52
+ const KeywordInputPlaceholder = ({ popup }) => {
53
+ var _popup$extraProps$fon, _popup$extraProps, _popup$extraProps$fon2, _popup$extraProps2, _popup$extraProps$asc, _popup$extraProps3, _popup$extraProps$con, _popup$extraProps4, _popup$extraProps5, _popup$extraProps6, _popup$extraProps7;
54
+ const placeholder = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService).t("docQuickInsert.keywordInputPlaceholder");
55
+ const fontSizePx = (0, _univerjs_engine_render.ptToPixel)((_popup$extraProps$fon = (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.fontSize) !== null && _popup$extraProps$fon !== void 0 ? _popup$extraProps$fon : DEFAULT_FONT_SIZE);
56
+ const fontString = (_popup$extraProps$fon2 = (_popup$extraProps2 = popup.extraProps) === null || _popup$extraProps2 === void 0 ? void 0 : _popup$extraProps2.fontString) !== null && _popup$extraProps$fon2 !== void 0 ? _popup$extraProps$fon2 : `${fontSizePx}px sans-serif`;
57
+ const ascent = (_popup$extraProps$asc = (_popup$extraProps3 = popup.extraProps) === null || _popup$extraProps3 === void 0 ? void 0 : _popup$extraProps3.ascent) !== null && _popup$extraProps$asc !== void 0 ? _popup$extraProps$asc : fontSizePx;
58
+ const contentHeight = Math.max((_popup$extraProps$con = (_popup$extraProps4 = popup.extraProps) === null || _popup$extraProps4 === void 0 ? void 0 : _popup$extraProps4.contentHeight) !== null && _popup$extraProps$con !== void 0 ? _popup$extraProps$con : fontSizePx, fontSizePx);
59
+ const textWidth = (0, react.useMemo)(() => measureTextWidth(placeholder, fontString), [fontString, placeholder]);
60
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
61
+ className: "univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors dark:!univer-text-gray-400",
62
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
63
+ width: textWidth,
64
+ height: contentHeight,
65
+ viewBox: `0 0 ${textWidth} ${contentHeight}`,
66
+ style: {
67
+ overflow: "visible",
68
+ display: "block"
69
+ },
70
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("text", {
71
+ x: 0,
72
+ y: ascent,
73
+ fill: "currentColor",
74
+ style: {
75
+ font: fontString,
76
+ fontFamily: (_popup$extraProps5 = popup.extraProps) === null || _popup$extraProps5 === void 0 ? void 0 : _popup$extraProps5.fontFamily,
77
+ fontStyle: (_popup$extraProps6 = popup.extraProps) === null || _popup$extraProps6 === void 0 ? void 0 : _popup$extraProps6.fontStyle,
78
+ fontWeight: (_popup$extraProps7 = popup.extraProps) === null || _popup$extraProps7 === void 0 ? void 0 : _popup$extraProps7.fontWeight
79
+ },
80
+ children: placeholder
81
+ })
82
+ })
83
+ });
84
+ };
85
+ KeywordInputPlaceholder.componentKey = KeywordInputPlaceholderComponentKey;
86
+
87
+ //#endregion
88
+ //#region src/views/QuickInsertMenu.tsx
89
+ function isMenuGroup(menu) {
90
+ return "children" in menu;
91
+ }
92
+ function flattenMenuItems(menus) {
93
+ return menus.flatMap((menu) => {
94
+ if (isMenuGroup(menu)) return flattenMenuItems(menu.children);
95
+ return menu;
96
+ });
97
+ }
98
+ function getQuickInsertMenuLeafCount(menus) {
99
+ return flattenMenuItems(menus).length;
100
+ }
101
+ function QuickInsertMenu(props) {
102
+ const { menus, focusedMenuIndex, focusedMenuRef, menuNodeMapRef, componentManager, onFocusedMenuIndexChange, onSelect } = props;
103
+ const flatMenus = (0, react.useMemo)(() => flattenMenuItems(menus), [menus]);
104
+ (0, react.useEffect)(() => {
105
+ var _flatMenus$focusedMen, _menuNodeMapRef$curre;
106
+ const focusedMenu = Number.isNaN(focusedMenuIndex) ? null : (_flatMenus$focusedMen = flatMenus[focusedMenuIndex]) !== null && _flatMenus$focusedMen !== void 0 ? _flatMenus$focusedMen : null;
107
+ focusedMenuRef.current = focusedMenu;
108
+ if (!focusedMenu) return;
109
+ (_menuNodeMapRef$curre = menuNodeMapRef.current.get(focusedMenu.id)) === null || _menuNodeMapRef$curre === void 0 || _menuNodeMapRef$curre.scrollIntoView({ block: "nearest" });
110
+ }, [
111
+ flatMenus,
112
+ focusedMenuIndex,
113
+ focusedMenuRef,
114
+ menuNodeMapRef
115
+ ]);
116
+ const itemIndexRef = (0, react.useRef)(0);
117
+ itemIndexRef.current = 0;
118
+ function renderMenus(currentMenus) {
119
+ return currentMenus.map((menu, index) => {
120
+ const iconKey = menu.icon;
121
+ const Icon = iconKey ? componentManager.get(iconKey) : null;
122
+ if (isMenuGroup(menu)) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
123
+ className: (0, _univerjs_design.clsx)("univer-grid univer-gap-1 univer-py-1", index !== currentMenus.length - 1 && _univerjs_design.borderBottomClassName),
124
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
125
+ className: "univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2 univer-text-xs univer-font-semibold univer-text-gray-600 dark:!univer-text-gray-300",
126
+ children: [Icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
127
+ className: "univer-inline-flex univer-text-base",
128
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {})
129
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: menu.title })]
130
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
131
+ className: "univer-grid univer-gap-1",
132
+ children: renderMenus(menu.children)
133
+ })]
134
+ }, menu.id);
135
+ const currentMenuIndex = itemIndexRef.current;
136
+ const isFocused = focusedMenuIndex === currentMenuIndex;
137
+ itemIndexRef.current += 1;
138
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
139
+ ref: (node) => {
140
+ if (node) {
141
+ menuNodeMapRef.current.set(menu.id, node);
142
+ return;
143
+ }
144
+ menuNodeMapRef.current.delete(menu.id);
145
+ },
146
+ role: "button",
147
+ tabIndex: -1,
148
+ className: (0, _univerjs_design.clsx)("univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900 univer-outline-none hover:univer-bg-gray-50 dark:!univer-text-white dark:hover:!univer-bg-gray-600", {
149
+ "hover:univer-bg-transparent": !isFocused,
150
+ "univer-bg-gray-50 dark:!univer-bg-gray-600": isFocused
151
+ }),
152
+ onMouseEnter: () => onFocusedMenuIndexChange(currentMenuIndex),
153
+ onMouseLeave: () => onFocusedMenuIndexChange(NaN),
154
+ onClick: () => onSelect(menu),
155
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
156
+ className: "univer-inline-flex univer-w-full univer-items-center univer-gap-2",
157
+ children: [Icon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
158
+ className: "univer-inline-flex univer-text-base",
159
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {})
160
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
161
+ showIfEllipsis: true,
162
+ title: menu.title,
163
+ placement: "right",
164
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
165
+ className: "univer-truncate",
166
+ children: menu.title
167
+ })
168
+ })]
169
+ })
170
+ }, menu.id);
171
+ });
172
+ }
173
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
174
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2 univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md dark:!univer-bg-gray-700 dark:!univer-text-white", _univerjs_design.borderClassName, _univerjs_design.scrollbarClassName),
175
+ onWheel: (event) => event.stopPropagation(),
176
+ children: renderMenus(menus)
177
+ });
178
+ }
179
+
180
+ //#endregion
181
+ //#region src/views/QuickInsertPlaceholder.tsx
182
+ /**
183
+ * Copyright 2023-present DreamNum Co., Ltd.
184
+ *
185
+ * Licensed under the Apache License, Version 2.0 (the "License");
186
+ * you may not use this file except in compliance with the License.
187
+ * You may obtain a copy of the License at
188
+ *
189
+ * http://www.apache.org/licenses/LICENSE-2.0
190
+ *
191
+ * Unless required by applicable law or agreed to in writing, software
192
+ * distributed under the License is distributed on an "AS IS" BASIS,
193
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
194
+ * See the License for the specific language governing permissions and
195
+ * limitations under the License.
196
+ */
197
+ const QuickInsertPlaceholderComponentKey = "docs.quick.insert.placeholder";
198
+ const QuickInsertPlaceholder = () => {
199
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
200
+ 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",
201
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService).t("docQuickInsert.placeholder") })
202
+ });
203
+ };
204
+ QuickInsertPlaceholder.componentKey = QuickInsertPlaceholderComponentKey;
205
+
206
+ //#endregion
207
+ //#region src/views/QuickInsertPopup.tsx
208
+ function filterMenusByKeyword(menus, keyword) {
209
+ return menus.map((menu) => ({ ...menu })).filter((menu) => {
210
+ if ("children" in menu) {
211
+ menu.children = filterMenusByKeyword(menu.children, keyword);
212
+ return menu.children.length > 0;
213
+ }
214
+ const keywords = menu.keywords;
215
+ if (keywords) return keywords.some((word) => word.includes(keyword));
216
+ return menu.title.toLowerCase().includes(keyword);
217
+ });
218
+ }
219
+ function translateMenus(menus, localeService) {
220
+ return menus.map((_menu) => {
221
+ const menu = { ..._menu };
222
+ if ("children" in menu) menu.children = translateMenus(menu.children, localeService);
223
+ menu.title = localeService.t(menu.title);
224
+ if ("keywords" in menu) menu.keywords = menu.keywords.concat(menu.title).map((word) => word.toLowerCase());
225
+ return menu;
226
+ });
227
+ }
228
+ const interceptKeys = [
229
+ _univerjs_ui.KeyCode.ARROW_UP,
230
+ _univerjs_ui.KeyCode.ARROW_DOWN,
231
+ _univerjs_ui.KeyCode.ENTER
232
+ ];
233
+ const QuickInsertPopup = () => {
234
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
235
+ const docQuickInsertPopupService = (0, _univerjs_ui.useDependency)(DocQuickInsertPopupService);
236
+ const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
237
+ const shortcutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IShortcutService);
238
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
239
+ const id = (0, react.useMemo)(() => (0, _univerjs_core.generateRandomId)(), []);
240
+ const [focusedMenuIndex, setFocusedMenuIndex] = (0, react.useState)(0);
241
+ const focusedMenuRef = (0, react.useRef)(null);
242
+ const filterKeyword = (0, _univerjs_ui.useObservable)(docQuickInsertPopupService.filterKeyword$, "");
243
+ const currentPopup = (0, _univerjs_ui.useObservable)(docQuickInsertPopupService.editPopup$);
244
+ const menus = (0, _univerjs_ui.useObservable)(currentPopup === null || currentPopup === void 0 ? void 0 : currentPopup.popup.menus$, []);
245
+ const translatedMenus = (0, react.useMemo)(() => {
246
+ return translateMenus(menus, localeService);
247
+ }, [menus]);
248
+ const [filteredMenus, setFilteredMenus] = (0, react.useState)(() => {
249
+ return filterMenusByKeyword(translatedMenus, filterKeyword.toLowerCase());
250
+ });
251
+ const filteredMenuCount = (0, react.useMemo)(() => getQuickInsertMenuLeafCount(filteredMenus), [filteredMenus]);
252
+ const filteredMenuCountRef = (0, react.useRef)(filteredMenuCount);
253
+ (0, react.useEffect)(() => {
254
+ filteredMenuCountRef.current = filteredMenuCount;
255
+ }, [filteredMenuCount]);
256
+ (0, react.useEffect)(() => {
257
+ const id = requestIdleCallback(() => {
258
+ setFilteredMenus(filterMenusByKeyword(translatedMenus, filterKeyword.toLowerCase()));
259
+ });
260
+ return () => {
261
+ cancelIdleCallback(id);
262
+ };
263
+ }, [translatedMenus, filterKeyword]);
264
+ const handleMenuSelect = (menu) => {
265
+ docQuickInsertPopupService.emitMenuSelected(menu);
266
+ commandService.executeCommand(CloseQuickInsertPopupOperation.id);
267
+ };
268
+ (0, react.useEffect)(() => {
269
+ /** Use up or down to navigate the focused menu instead of moving the cursor in documents. */
270
+ const disposableCollection = new _univerjs_core.DisposableCollection();
271
+ shortcutService.getAllShortcuts().filter((item) => item.binding && interceptKeys.includes(item.binding)).forEach((item) => {
272
+ const rawPreconditions = item.preconditions;
273
+ item.preconditions = () => false;
274
+ disposableCollection.add((0, _univerjs_core.toDisposable)(() => {
275
+ item.preconditions = rawPreconditions;
276
+ }));
277
+ });
278
+ const enterCommand = {
279
+ id: `quick.insert.popup.enter.${id}`,
280
+ type: _univerjs_core.CommandType.OPERATION,
281
+ handler: () => {
282
+ const menu = focusedMenuRef.current;
283
+ if (menu) handleMenuSelect(menu);
284
+ }
285
+ };
286
+ const moveCursorUpCommand = {
287
+ id: `quick.insert.popup.move.cursor.up.${id}`,
288
+ type: _univerjs_core.CommandType.OPERATION,
289
+ handler: () => {
290
+ setFocusedMenuIndex((index) => {
291
+ if (filteredMenuCountRef.current <= 0) return 0;
292
+ const nextIndex = index - 1;
293
+ return nextIndex >= 0 ? nextIndex : filteredMenuCountRef.current - 1;
294
+ });
295
+ }
296
+ };
297
+ const moveCursorDownCommand = {
298
+ id: `quick.insert.popup.move.cursor.down.${id}`,
299
+ type: _univerjs_core.CommandType.OPERATION,
300
+ handler: () => {
301
+ setFocusedMenuIndex((index) => {
302
+ if (filteredMenuCountRef.current <= 0) return 0;
303
+ const nextIndex = index + 1;
304
+ return nextIndex <= filteredMenuCountRef.current - 1 ? nextIndex : 0;
305
+ });
306
+ }
307
+ };
308
+ disposableCollection.add(commandService.registerCommand(moveCursorUpCommand));
309
+ disposableCollection.add(commandService.registerCommand(moveCursorDownCommand));
310
+ disposableCollection.add(commandService.registerCommand(enterCommand));
311
+ disposableCollection.add(shortcutService.registerShortcut({
312
+ priority: 1e3,
313
+ id: moveCursorUpCommand.id,
314
+ binding: _univerjs_ui.KeyCode.ARROW_UP,
315
+ preconditions: () => true,
316
+ staticParameters: { direction: _univerjs_core.Direction.UP }
317
+ }));
318
+ disposableCollection.add(shortcutService.registerShortcut({
319
+ priority: 1e3,
320
+ id: moveCursorDownCommand.id,
321
+ binding: _univerjs_ui.KeyCode.ARROW_DOWN,
322
+ preconditions: () => true,
323
+ staticParameters: { direction: _univerjs_core.Direction.DOWN }
324
+ }));
325
+ disposableCollection.add(shortcutService.registerShortcut({
326
+ priority: 1e3,
327
+ id: enterCommand.id,
328
+ binding: _univerjs_ui.KeyCode.ENTER,
329
+ preconditions: () => true
330
+ }));
331
+ return () => {
332
+ disposableCollection.dispose();
333
+ };
334
+ }, [
335
+ commandService,
336
+ id,
337
+ shortcutService
338
+ ]);
339
+ (0, react.useEffect)(() => {
340
+ setFocusedMenuIndex(0);
341
+ }, [filteredMenus]);
342
+ const menuNodeMapRef = (0, react.useRef)(/* @__PURE__ */ new Map());
343
+ (0, react.useEffect)(() => {
344
+ return () => {
345
+ menuNodeMapRef.current.clear();
346
+ };
347
+ }, []);
348
+ const hasMenus = filteredMenus.length > 0;
349
+ const Placeholder = (currentPopup === null || currentPopup === void 0 ? void 0 : currentPopup.popup.Placeholder) || componentManager.get(QuickInsertPlaceholder.componentKey);
350
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
351
+ className: "univer-mt-2",
352
+ children: hasMenus ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuickInsertMenu, {
353
+ menus: filteredMenus,
354
+ focusedMenuIndex,
355
+ focusedMenuRef,
356
+ menuNodeMapRef,
357
+ componentManager,
358
+ onFocusedMenuIndexChange: setFocusedMenuIndex,
359
+ onSelect: handleMenuSelect
360
+ }) : Placeholder && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Placeholder, {})
361
+ });
362
+ };
363
+ QuickInsertPopup.componentKey = "docs.quick.insert.popup";
364
+
365
+ //#endregion
366
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
367
+ function _typeof(o) {
368
+ "@babel/helpers - typeof";
369
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
370
+ return typeof o;
371
+ } : function(o) {
372
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
373
+ }, _typeof(o);
374
+ }
375
+
376
+ //#endregion
377
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
378
+ function toPrimitive(t, r) {
379
+ if ("object" != _typeof(t) || !t) return t;
380
+ var e = t[Symbol.toPrimitive];
381
+ if (void 0 !== e) {
382
+ var i = e.call(t, r || "default");
383
+ if ("object" != _typeof(i)) return i;
384
+ throw new TypeError("@@toPrimitive must return a primitive value.");
385
+ }
386
+ return ("string" === r ? String : Number)(t);
387
+ }
388
+
389
+ //#endregion
390
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
391
+ function toPropertyKey(t) {
392
+ var i = toPrimitive(t, "string");
393
+ return "symbol" == _typeof(i) ? i : i + "";
394
+ }
395
+
396
+ //#endregion
397
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
398
+ function _defineProperty(e, r, t) {
399
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
400
+ value: t,
401
+ enumerable: !0,
402
+ configurable: !0,
403
+ writable: !0
404
+ }) : e[r] = t, e;
405
+ }
406
+
407
+ //#endregion
408
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
409
+ function __decorateParam(paramIndex, decorator) {
410
+ return function(target, key) {
411
+ decorator(target, key, paramIndex);
412
+ };
413
+ }
414
+
415
+ //#endregion
416
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
417
+ function __decorate(decorators, target, key, desc) {
418
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
419
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
420
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
421
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
422
+ }
423
+
424
+ //#endregion
425
+ //#region src/services/doc-quick-insert-popup.service.ts
426
+ const noopDisposable = { dispose: () => {} };
427
+ let DocQuickInsertPopupService = class DocQuickInsertPopupService extends _univerjs_core.Disposable {
428
+ get popups() {
429
+ return Array.from(this._popups);
430
+ }
431
+ get editPopup() {
432
+ return this._editPopup$.value;
433
+ }
434
+ get isComposing() {
435
+ return this._isComposing$.value;
436
+ }
437
+ setIsComposing(isComposing) {
438
+ this._isComposing$.next(isComposing);
439
+ }
440
+ get inputOffset() {
441
+ return this._inputOffset$.value;
442
+ }
443
+ setInputOffset(offset) {
444
+ this._inputOffset$.next(offset);
445
+ }
446
+ getDocEventManagerService(unitId) {
447
+ var _this$_renderManagerS;
448
+ return (_this$_renderManagerS = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(_univerjs_docs_ui.DocEventManagerService);
449
+ }
450
+ constructor(_docCanvasPopupManagerService, _univerInstanceService, _commandService, _renderManagerService, _docSelectionManagerService) {
451
+ super();
452
+ this._docCanvasPopupManagerService = _docCanvasPopupManagerService;
453
+ this._univerInstanceService = _univerInstanceService;
454
+ this._commandService = _commandService;
455
+ this._renderManagerService = _renderManagerService;
456
+ this._docSelectionManagerService = _docSelectionManagerService;
457
+ _defineProperty(this, "_popups", /* @__PURE__ */ new Set());
458
+ _defineProperty(this, "_editPopup$", new rxjs.BehaviorSubject(void 0));
459
+ _defineProperty(this, "editPopup$", this._editPopup$.asObservable());
460
+ _defineProperty(this, "_isComposing$", new rxjs.BehaviorSubject(false));
461
+ _defineProperty(this, "isComposing$", this._isComposing$.asObservable());
462
+ _defineProperty(this, "_inputOffset$", new rxjs.BehaviorSubject({
463
+ start: 0,
464
+ end: 0
465
+ }));
466
+ _defineProperty(this, "inputOffset$", this._inputOffset$.asObservable());
467
+ _defineProperty(this, "filterKeyword$", void 0);
468
+ _defineProperty(this, "_menuSelectedCallbacks", /* @__PURE__ */ new Set());
469
+ _defineProperty(this, "_inputPlaceholderRenderRoot", null);
470
+ this.disposeWithMe(this._editPopup$);
471
+ const getBodySlice = (start, end) => {
472
+ var _this$_univerInstance;
473
+ return (_this$_univerInstance = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getBody()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.dataStream.slice(start, end);
474
+ };
475
+ let lastFilterKeyword = "";
476
+ this.filterKeyword$ = this._inputOffset$.pipe((0, rxjs.map)((offset) => {
477
+ var _slice$slice;
478
+ const slice = getBodySlice(offset.start, offset.end);
479
+ return (_slice$slice = slice === null || slice === void 0 ? void 0 : slice.slice(1)) !== null && _slice$slice !== void 0 ? _slice$slice : "";
480
+ }), (0, rxjs.distinctUntilChanged)(), (0, rxjs.tap)((filterKeyword) => {
481
+ lastFilterKeyword = filterKeyword;
482
+ }));
483
+ this.disposeWithMe((0, rxjs.combineLatest)([
484
+ this.filterKeyword$.pipe((0, rxjs.tap)((filterKeyword) => {
485
+ if (filterKeyword.length > 0) {
486
+ var _this$_inputPlacehold;
487
+ (_this$_inputPlacehold = this._inputPlaceholderRenderRoot) === null || _this$_inputPlacehold === void 0 || (_this$_inputPlacehold = _this$_inputPlacehold.unmount) === null || _this$_inputPlacehold === void 0 || _this$_inputPlacehold.dispose();
488
+ } else {
489
+ var _this$_inputPlacehold2;
490
+ (_this$_inputPlacehold2 = this._inputPlaceholderRenderRoot) === null || _this$_inputPlacehold2 === void 0 || _this$_inputPlacehold2.mount();
491
+ }
492
+ })),
493
+ this.isComposing$.pipe((0, rxjs.tap)((isComposing) => {
494
+ if (isComposing) {
495
+ var _this$_inputPlacehold3;
496
+ (_this$_inputPlacehold3 = this._inputPlaceholderRenderRoot) === null || _this$_inputPlacehold3 === void 0 || (_this$_inputPlacehold3 = _this$_inputPlacehold3.unmount) === null || _this$_inputPlacehold3 === void 0 || _this$_inputPlacehold3.dispose();
497
+ } else {
498
+ var _this$_inputPlacehold4;
499
+ lastFilterKeyword.length <= 0 && ((_this$_inputPlacehold4 = this._inputPlaceholderRenderRoot) === null || _this$_inputPlacehold4 === void 0 || _this$_inputPlacehold4.mount());
500
+ }
501
+ })),
502
+ this.editPopup$.pipe((0, rxjs.tap)((popup) => {
503
+ if (!popup) {
504
+ var _this$_inputPlacehold5;
505
+ (_this$_inputPlacehold5 = this._inputPlaceholderRenderRoot) === null || _this$_inputPlacehold5 === void 0 || (_this$_inputPlacehold5 = _this$_inputPlacehold5.unmount) === null || _this$_inputPlacehold5 === void 0 || _this$_inputPlacehold5.dispose();
506
+ this._inputPlaceholderRenderRoot = null;
507
+ }
508
+ }))
509
+ ]).subscribe());
510
+ }
511
+ resolvePopup(keyword) {
512
+ return Array.from(this._popups).find((popup) => popup.keyword === keyword);
513
+ }
514
+ registerPopup(popup) {
515
+ this._popups.add(popup);
516
+ return () => {
517
+ this._popups.delete(popup);
518
+ };
519
+ }
520
+ _createInputPlaceholderRenderRoot(mount) {
521
+ return {
522
+ isMounted: false,
523
+ mount() {
524
+ if (this.isMounted) return;
525
+ this.isMounted = true;
526
+ const unmount = mount();
527
+ this.unmount = { dispose: () => {
528
+ unmount.dispose();
529
+ this.isMounted = false;
530
+ } };
531
+ }
532
+ };
533
+ }
534
+ _getParagraphBound(unitId, index) {
535
+ var _currentDoc$getBody, _docEventManagerServi;
536
+ const currentDoc = this._univerInstanceService.getUnit(unitId);
537
+ const paragraph = currentDoc === null || currentDoc === void 0 || (_currentDoc$getBody = currentDoc.getBody()) === null || _currentDoc$getBody === void 0 || (_currentDoc$getBody = _currentDoc$getBody.paragraphs) === null || _currentDoc$getBody === void 0 ? void 0 : _currentDoc$getBody.find((p) => p.startIndex > index);
538
+ if (!paragraph) return null;
539
+ const docEventManagerService = this.getDocEventManagerService(unitId);
540
+ return (_docEventManagerServi = docEventManagerService === null || docEventManagerService === void 0 ? void 0 : docEventManagerService.findParagraphBoundByIndex(paragraph.startIndex)) !== null && _docEventManagerServi !== void 0 ? _docEventManagerServi : null;
541
+ }
542
+ _getKeywordPlaceholderAnchorRect(document, skeleton, activeRange, fallbackRect) {
543
+ const startPosition = skeleton.findNodePositionByCharIndex(activeRange.startOffset, true, activeRange.segmentId, activeRange.segmentPage);
544
+ if (!startPosition) return fallbackRect;
545
+ const documentOffsetConfig = document.getOffsetConfig();
546
+ const { contentBoxPointGroup } = new _univerjs_docs_ui.NodePositionConvertToCursor(documentOffsetConfig, skeleton).getRangePointData(startPosition, startPosition);
547
+ if (contentBoxPointGroup.length === 0) return fallbackRect;
548
+ const anchor = (0, _univerjs_docs_ui.getAnchorBounding)(contentBoxPointGroup);
549
+ const left = anchor.left + documentOffsetConfig.docsLeft;
550
+ const top = anchor.top + documentOffsetConfig.docsTop;
551
+ return {
552
+ left,
553
+ right: left,
554
+ top,
555
+ bottom: top + anchor.height
556
+ };
557
+ }
558
+ _getKeywordPlaceholderExtraProps(curGlyph) {
559
+ var _curGlyph$ts, _curGlyph$fontStyle, _ref, _curGlyph$fontStyle$f, _curGlyph$fontStyle2, _curGlyph$ts2, _curGlyph$ts3, _curGlyph$ts4, _curGlyph$bBox, _curGlyph$bBox$ba, _curGlyph$bBox2, _curGlyph$bBox$bd, _curGlyph$bBox3;
560
+ return {
561
+ fontSize: (_curGlyph$ts = curGlyph.ts) === null || _curGlyph$ts === void 0 ? void 0 : _curGlyph$ts.fs,
562
+ fontString: (_curGlyph$fontStyle = curGlyph.fontStyle) === null || _curGlyph$fontStyle === void 0 ? void 0 : _curGlyph$fontStyle.fontString,
563
+ fontFamily: (_ref = (_curGlyph$fontStyle$f = (_curGlyph$fontStyle2 = curGlyph.fontStyle) === null || _curGlyph$fontStyle2 === void 0 ? void 0 : _curGlyph$fontStyle2.fontFamily) !== null && _curGlyph$fontStyle$f !== void 0 ? _curGlyph$fontStyle$f : (_curGlyph$ts2 = curGlyph.ts) === null || _curGlyph$ts2 === void 0 ? void 0 : _curGlyph$ts2.ff) !== null && _ref !== void 0 ? _ref : void 0,
564
+ fontStyle: ((_curGlyph$ts3 = curGlyph.ts) === null || _curGlyph$ts3 === void 0 ? void 0 : _curGlyph$ts3.it) ? "italic" : "normal",
565
+ fontWeight: ((_curGlyph$ts4 = curGlyph.ts) === null || _curGlyph$ts4 === void 0 ? void 0 : _curGlyph$ts4.bl) ? "bold" : "normal",
566
+ ascent: (_curGlyph$bBox = curGlyph.bBox) === null || _curGlyph$bBox === void 0 ? void 0 : _curGlyph$bBox.ba,
567
+ contentHeight: ((_curGlyph$bBox$ba = (_curGlyph$bBox2 = curGlyph.bBox) === null || _curGlyph$bBox2 === void 0 ? void 0 : _curGlyph$bBox2.ba) !== null && _curGlyph$bBox$ba !== void 0 ? _curGlyph$bBox$ba : 0) + ((_curGlyph$bBox$bd = (_curGlyph$bBox3 = curGlyph.bBox) === null || _curGlyph$bBox3 === void 0 ? void 0 : _curGlyph$bBox3.bd) !== null && _curGlyph$bBox$bd !== void 0 ? _curGlyph$bBox$bd : 0) || void 0
568
+ };
569
+ }
570
+ _mountInputPlaceholder(unitId, fallbackRect) {
571
+ const currentRender = this._renderManagerService.getRenderById(unitId);
572
+ const docSkeletonManagerService = currentRender === null || currentRender === void 0 ? void 0 : currentRender.with(_univerjs_docs.DocSkeletonManagerService);
573
+ const activeRange = this._docSelectionManagerService.getActiveTextRange();
574
+ if (!currentRender || !docSkeletonManagerService || !activeRange) return noopDisposable;
575
+ const skeleton = docSkeletonManagerService.getSkeleton();
576
+ const curGlyph = skeleton.findNodeByCharIndex(activeRange.startOffset, activeRange.segmentId, activeRange.segmentPage);
577
+ if (!((curGlyph === null || curGlyph === void 0 ? void 0 : curGlyph.content) === "\r") || !curGlyph) return noopDisposable;
578
+ const document = currentRender.mainComponent;
579
+ const placeholderAnchorRect = this._getKeywordPlaceholderAnchorRect(document, skeleton, activeRange, fallbackRect);
580
+ const extraProps = this._getKeywordPlaceholderExtraProps(curGlyph);
581
+ const disposable = this._docCanvasPopupManagerService.attachPopupToRect(placeholderAnchorRect, {
582
+ componentKey: KeywordInputPlaceholder.componentKey,
583
+ extraProps,
584
+ onClickOutside: () => {
585
+ disposable.dispose();
586
+ },
587
+ direction: "horizontal"
588
+ }, unitId);
589
+ return disposable;
590
+ }
591
+ showPopup(options) {
592
+ const { popup, index, unitId } = options;
593
+ this.closePopup();
594
+ const paragraphBound = this._getParagraphBound(unitId, index);
595
+ if (!paragraphBound) return;
596
+ this._inputPlaceholderRenderRoot = this._createInputPlaceholderRenderRoot(() => this._mountInputPlaceholder(unitId, paragraphBound.firstLine));
597
+ this._inputPlaceholderRenderRoot.mount();
598
+ const disposable = this._docCanvasPopupManagerService.attachPopupToRect(paragraphBound.firstLine, {
599
+ componentKey: QuickInsertPopup.componentKey,
600
+ onClickOutside: () => {
601
+ this.closePopup();
602
+ },
603
+ direction: "bottom"
604
+ }, unitId);
605
+ this._editPopup$.next({
606
+ disposable,
607
+ popup,
608
+ anchor: index,
609
+ unitId
610
+ });
611
+ }
612
+ closePopup() {
613
+ if (this.editPopup) {
614
+ this.editPopup.disposable.dispose();
615
+ this._editPopup$.next(null);
616
+ }
617
+ }
618
+ onMenuSelected(callback) {
619
+ this._menuSelectedCallbacks.add(callback);
620
+ return () => {
621
+ this._menuSelectedCallbacks.delete(callback);
622
+ };
623
+ }
624
+ emitMenuSelected(menu) {
625
+ const { start, end } = this.inputOffset;
626
+ this._commandService.syncExecuteCommand(DeleteSearchKeyCommand.id, {
627
+ start,
628
+ end
629
+ });
630
+ setTimeout(() => {
631
+ this._menuSelectedCallbacks.forEach((callback) => callback(menu));
632
+ }, 0);
633
+ }
634
+ };
635
+ DocQuickInsertPopupService = __decorate([
636
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocCanvasPopManagerService)),
637
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
638
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.ICommandService)),
639
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_render.IRenderManagerService)),
640
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))
641
+ ], DocQuickInsertPopupService);
642
+
643
+ //#endregion
644
+ //#region src/commands/operations/quick-insert-popup.operation.ts
645
+ const ShowQuickInsertPopupOperation = {
646
+ type: _univerjs_core.CommandType.OPERATION,
647
+ id: "doc.operation.show-quick-insert-popup",
648
+ handler(accessor, params) {
649
+ const docQuickInsertPopupService = accessor.get(DocQuickInsertPopupService);
650
+ if (!params) return false;
651
+ docQuickInsertPopupService.showPopup(params);
652
+ return true;
653
+ }
654
+ };
655
+ const CloseQuickInsertPopupOperation = {
656
+ type: _univerjs_core.CommandType.OPERATION,
657
+ id: "doc.operation.close-quick-insert-popup",
658
+ handler(accessor) {
659
+ accessor.get(DocQuickInsertPopupService).closePopup();
660
+ return true;
661
+ }
662
+ };
663
+
664
+ //#endregion
665
+ //#region src/menu/menu.ts
666
+ let QuickInsertMenuGroup = /* @__PURE__ */ function(QuickInsertMenuGroup) {
667
+ QuickInsertMenuGroup["Basic"] = "quick.insert.group.basic";
668
+ QuickInsertMenuGroup["Media"] = "quick.insert.group.media";
669
+ return QuickInsertMenuGroup;
670
+ }({});
671
+ const textMenu = {
672
+ id: "quick-insert.text.menu",
673
+ title: "docQuickInsert.menu.text",
674
+ icon: "TextIcon",
675
+ keywords: ["text"]
676
+ };
677
+ const numberedListMenu = {
678
+ id: _univerjs_docs_ui.OrderListCommand.id,
679
+ title: "docQuickInsert.menu.numberedList",
680
+ icon: "OrderIcon",
681
+ keywords: [
682
+ "numbered",
683
+ "list",
684
+ "ordered"
685
+ ]
686
+ };
687
+ const bulletedListMenu = {
688
+ id: _univerjs_docs_ui.BulletListCommand.id,
689
+ title: "docQuickInsert.menu.bulletedList",
690
+ icon: "UnorderIcon",
691
+ keywords: [
692
+ "bulleted",
693
+ "list",
694
+ "unordered"
695
+ ]
696
+ };
697
+ const dividerMenu = {
698
+ id: _univerjs_docs_ui.HorizontalLineCommand.id,
699
+ title: "docQuickInsert.menu.divider",
700
+ icon: "DividerIcon",
701
+ keywords: [
702
+ "divider",
703
+ "line",
704
+ "separate"
705
+ ]
706
+ };
707
+ const tableMenu = {
708
+ id: _univerjs_docs_ui.DocCreateTableOperation.id,
709
+ title: "docQuickInsert.menu.table",
710
+ icon: "GridIcon",
711
+ keywords: [
712
+ "table",
713
+ "grid",
714
+ "spreadsheet"
715
+ ]
716
+ };
717
+ const imageMenu = {
718
+ id: _univerjs_docs_drawing_ui.InsertDocImageCommand.id,
719
+ title: "docQuickInsert.menu.image",
720
+ icon: "AdditionAndSubtractionIcon",
721
+ keywords: [
722
+ "image",
723
+ "picture",
724
+ "photo"
725
+ ]
726
+ };
727
+ const builtInMenus = [{
728
+ title: "docQuickInsert.group.basics",
729
+ id: QuickInsertMenuGroup.Basic,
730
+ children: [
731
+ textMenu,
732
+ numberedListMenu,
733
+ bulletedListMenu,
734
+ dividerMenu,
735
+ tableMenu,
736
+ imageMenu
737
+ ]
738
+ }];
739
+ const builtInMenuCommandIds = new Set([
740
+ numberedListMenu.id,
741
+ bulletedListMenu.id,
742
+ dividerMenu.id,
743
+ tableMenu.id,
744
+ imageMenu.id
745
+ ]);
746
+
747
+ //#endregion
748
+ //#region src/controllers/doc-quick-insert-trigger.controller.ts
749
+ let DocQuickInsertTriggerController = class DocQuickInsertTriggerController extends _univerjs_core.Disposable {
750
+ constructor(_commandService, _textSelectionManagerService, _docQuickInsertPopupService, _shortcutService, _univerInstanceService) {
751
+ super();
752
+ this._commandService = _commandService;
753
+ this._textSelectionManagerService = _textSelectionManagerService;
754
+ this._docQuickInsertPopupService = _docQuickInsertPopupService;
755
+ this._shortcutService = _shortcutService;
756
+ this._univerInstanceService = _univerInstanceService;
757
+ this.disposeWithMe(this._shortcutService.registerShortcut({
758
+ id: CloseQuickInsertPopupOperation.id,
759
+ binding: _univerjs_ui.KeyCode.ESC,
760
+ preconditions: () => Boolean(this._docQuickInsertPopupService.editPopup),
761
+ priority: 1e3
762
+ }));
763
+ this._initTrigger();
764
+ this._initMenuHandler();
765
+ }
766
+ _initTrigger() {
767
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
768
+ const { _docQuickInsertPopupService, _textSelectionManagerService, _commandService } = this;
769
+ const documentDataModel = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_DOC);
770
+ if (documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getDisabled()) return;
771
+ if (commandInfo.id === _univerjs_docs_ui.InsertCommand.id) {
772
+ const params = commandInfo.params;
773
+ if (_docQuickInsertPopupService.editPopup) {
774
+ _docQuickInsertPopupService.setInputOffset({
775
+ start: _docQuickInsertPopupService.inputOffset.start,
776
+ end: params.range.endOffset + 1
777
+ });
778
+ return;
779
+ }
780
+ const activeRange = _textSelectionManagerService.getActiveTextRange();
781
+ if (!activeRange) return;
782
+ const popup = _docQuickInsertPopupService.resolvePopup(params.body.dataStream);
783
+ if (!popup) return;
784
+ if (!(popup.preconditions ? popup.preconditions(params) : true)) return;
785
+ _docQuickInsertPopupService.setInputOffset({
786
+ start: activeRange.startOffset - 1,
787
+ end: activeRange.startOffset
788
+ });
789
+ setTimeout(() => {
790
+ _commandService.executeCommand(ShowQuickInsertPopupOperation.id, {
791
+ index: activeRange.startOffset - 1,
792
+ unitId: params.unitId,
793
+ popup
794
+ });
795
+ }, 100);
796
+ }
797
+ if (commandInfo.id === _univerjs_docs_ui.IMEInputCommand.id) {
798
+ const params = commandInfo.params;
799
+ if (!_docQuickInsertPopupService.isComposing && params.isCompositionStart) _docQuickInsertPopupService.setIsComposing(true);
800
+ if (_docQuickInsertPopupService.isComposing && params.isCompositionEnd) _docQuickInsertPopupService.setIsComposing(false);
801
+ }
802
+ if (commandInfo.id === _univerjs_docs.RichTextEditingMutation.id) {
803
+ const params = commandInfo.params;
804
+ if (params.isCompositionEnd) {
805
+ var _params$textRanges;
806
+ const endOffset = (_params$textRanges = params.textRanges) === null || _params$textRanges === void 0 || (_params$textRanges = _params$textRanges[0]) === null || _params$textRanges === void 0 ? void 0 : _params$textRanges.endOffset;
807
+ if (endOffset) _docQuickInsertPopupService.setInputOffset({
808
+ start: _docQuickInsertPopupService.inputOffset.start,
809
+ end: endOffset
810
+ });
811
+ }
812
+ }
813
+ if (commandInfo.id === _univerjs_docs_ui.DeleteCommand.id) {
814
+ const params = commandInfo.params;
815
+ if (_docQuickInsertPopupService.editPopup && params.direction === _univerjs_core.DeleteDirection.LEFT) {
816
+ var _params$len;
817
+ const len = (_params$len = params.len) !== null && _params$len !== void 0 ? _params$len : 0;
818
+ _docQuickInsertPopupService.setInputOffset({
819
+ start: _docQuickInsertPopupService.inputOffset.start,
820
+ end: params.range.endOffset - len
821
+ });
822
+ }
823
+ }
824
+ if (commandInfo.id === _univerjs_docs_ui.MoveCursorOperation.id) {
825
+ const params = commandInfo.params;
826
+ if (params.direction === _univerjs_core.Direction.LEFT || params.direction === _univerjs_core.Direction.RIGHT) _docQuickInsertPopupService.editPopup && _commandService.executeCommand(CloseQuickInsertPopupOperation.id);
827
+ }
828
+ if (commandInfo.id === _univerjs_docs_ui.DeleteLeftCommand.id) {
829
+ const activeRange = _textSelectionManagerService.getActiveTextRange();
830
+ if (!_docQuickInsertPopupService.editPopup || !activeRange) return;
831
+ if (activeRange.endOffset <= _docQuickInsertPopupService.editPopup.anchor) _commandService.executeCommand(CloseQuickInsertPopupOperation.id);
832
+ }
833
+ }));
834
+ }
835
+ _initMenuHandler() {
836
+ this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected((menu) => {
837
+ if (menu.id === textMenu.id) return;
838
+ if (builtInMenuCommandIds.has(menu.id)) this._commandService.executeCommand(menu.id);
839
+ }));
840
+ }
841
+ };
842
+ DocQuickInsertTriggerController = __decorate([
843
+ __decorateParam(0, _univerjs_core.ICommandService),
844
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
845
+ __decorateParam(2, (0, _univerjs_core.Inject)(DocQuickInsertPopupService)),
846
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_ui.IShortcutService)),
847
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
848
+ ], DocQuickInsertTriggerController);
849
+
850
+ //#endregion
851
+ //#region src/menu/doc-quick-insert-menu.controller.ts
852
+ let DocQuickInsertMenuController = class DocQuickInsertMenuController extends _univerjs_core.Disposable {
853
+ get popup() {
854
+ return this._popup$.value;
855
+ }
856
+ constructor(_context, _docEventManagerService, _docQuickInsertPopupService, _docCanvasPopManagerService) {
857
+ super();
858
+ this._context = _context;
859
+ this._docEventManagerService = _docEventManagerService;
860
+ this._docQuickInsertPopupService = _docQuickInsertPopupService;
861
+ this._docCanvasPopManagerService = _docCanvasPopManagerService;
862
+ _defineProperty(this, "_popup$", new rxjs.BehaviorSubject(null));
863
+ _defineProperty(this, "popup$", this._popup$.asObservable());
864
+ this._init();
865
+ }
866
+ _init() {
867
+ this.disposeWithMe((0, rxjs.combineLatest)([this._docEventManagerService.hoverParagraphLeftRealTime$, this._docEventManagerService.hoverParagraphRealTime$]).subscribe(([left, paragraph]) => {
868
+ const p = left !== null && left !== void 0 ? left : paragraph;
869
+ const isDisabled = this._context.unit.getDisabled();
870
+ if (!p || isDisabled) {
871
+ this._hideMenu(true);
872
+ return;
873
+ }
874
+ if (p.paragraphStart === p.paragraphEnd) {
875
+ var _this$popup;
876
+ if (this._docQuickInsertPopupService.editPopup || p.startIndex === ((_this$popup = this.popup) === null || _this$popup === void 0 ? void 0 : _this$popup.startIndex)) return;
877
+ this._hideMenu(true);
878
+ const disposable = this._docCanvasPopManagerService.attachPopupToRect(p.firstLine, {
879
+ componentKey: QuickInsertButtonComponentKey,
880
+ direction: "left-center"
881
+ }, this._context.unit.getUnitId());
882
+ this._popup$.next({
883
+ startIndex: p.startIndex,
884
+ disposable
885
+ });
886
+ } else this._hideMenu(true);
887
+ }));
888
+ }
889
+ _hideMenu(force) {
890
+ if (this._docQuickInsertPopupService.editPopup) return;
891
+ if (this.popup && (force || this.popup.disposable.canDispose())) {
892
+ this.popup.disposable.dispose();
893
+ this._popup$.next(null);
894
+ }
895
+ }
896
+ };
897
+ DocQuickInsertMenuController = __decorate([
898
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocEventManagerService)),
899
+ __decorateParam(2, (0, _univerjs_core.Inject)(DocQuickInsertPopupService)),
900
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocCanvasPopManagerService))
901
+ ], DocQuickInsertMenuController);
902
+
903
+ //#endregion
904
+ //#region src/views/QuickInsertButton.tsx
905
+ const QuickInsertButtonComponentKey = "doc.quick-insert.button";
906
+ const QuickInsertButton = ({ className = "" }) => {
907
+ const docQuickInsertPopupService = (0, _univerjs_ui.useDependency)(DocQuickInsertPopupService);
908
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
909
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
910
+ const currentDoc = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_DOC), [univerInstanceService]));
911
+ const currentUnit = currentDoc && renderManagerService.getRenderById(currentDoc.getUnitId());
912
+ const docQuickInsertMenuController = currentUnit === null || currentUnit === void 0 ? void 0 : currentUnit.with(DocQuickInsertMenuController);
913
+ const layoutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
914
+ const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
915
+ const editPopup = (0, _univerjs_ui.useObservable)(docQuickInsertPopupService.editPopup$);
916
+ const onClick = (0, _univerjs_ui.useEvent)(() => {
917
+ var _currentDoc$getUnitId;
918
+ const p = docQuickInsertMenuController === null || docQuickInsertMenuController === void 0 ? void 0 : docQuickInsertMenuController.popup;
919
+ if (!p) return;
920
+ const allPopups = docQuickInsertPopupService.popups;
921
+ const popup = {
922
+ keyword: "",
923
+ menus$: (0, rxjs.combineLatest)(allPopups.map((p) => p.menus$)).pipe((0, rxjs.map)((menusCollection) => menusCollection.flat()))
924
+ };
925
+ docSelectionManagerService.replaceDocRanges([{
926
+ startOffset: p.startIndex,
927
+ endOffset: p.startIndex
928
+ }]);
929
+ docQuickInsertPopupService.setInputOffset({
930
+ start: p.startIndex - 1,
931
+ end: p.startIndex - 1
932
+ });
933
+ docQuickInsertPopupService.showPopup({
934
+ popup,
935
+ index: p.startIndex - 1,
936
+ unitId: (_currentDoc$getUnitId = currentDoc === null || currentDoc === void 0 ? void 0 : currentDoc.getUnitId()) !== null && _currentDoc$getUnitId !== void 0 ? _currentDoc$getUnitId : ""
937
+ });
938
+ setTimeout(() => {
939
+ layoutService.focus();
940
+ });
941
+ });
942
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
943
+ className: (0, _univerjs_design.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", _univerjs_design.borderClassName, {
944
+ "univer-bg-gray-100 dark:!univer-bg-gray-700": editPopup,
945
+ "univer-bg-white dark:!univer-bg-gray-900": !editPopup
946
+ }, className),
947
+ role: "button",
948
+ tabIndex: 0,
949
+ onClick,
950
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.IncreaseIcon, { className: "univer-text-gray-800 dark:!univer-text-gray-200" })
951
+ });
952
+ };
953
+ QuickInsertButton.componentKey = QuickInsertButtonComponentKey;
954
+
955
+ //#endregion
956
+ //#region src/controllers/doc-quick-insert-ui.controller.ts
957
+ let DocQuickInsertUIController = class DocQuickInsertUIController extends _univerjs_core.Disposable {
958
+ constructor(_commandService, _docQuickInsertPopupService, _componentManager) {
959
+ super();
960
+ this._commandService = _commandService;
961
+ this._docQuickInsertPopupService = _docQuickInsertPopupService;
962
+ this._componentManager = _componentManager;
963
+ this._initCommands();
964
+ this._initComponents();
965
+ this._initMenus();
966
+ }
967
+ _initCommands() {
968
+ [
969
+ DeleteSearchKeyCommand,
970
+ ShowQuickInsertPopupOperation,
971
+ CloseQuickInsertPopupOperation
972
+ ].forEach((operation) => {
973
+ this.disposeWithMe(this._commandService.registerCommand(operation));
974
+ });
975
+ }
976
+ _initComponents() {
977
+ [
978
+ [QuickInsertPopup.componentKey, QuickInsertPopup],
979
+ [KeywordInputPlaceholder.componentKey, KeywordInputPlaceholder],
980
+ [QuickInsertPlaceholder.componentKey, QuickInsertPlaceholder],
981
+ [_univerjs_icons.DividerIcon.displayName, _univerjs_icons.DividerIcon],
982
+ [_univerjs_icons.TextIcon.displayName, _univerjs_icons.TextIcon],
983
+ [QuickInsertButton.componentKey, QuickInsertButton]
984
+ ].forEach(([key, comp]) => {
985
+ if (key) this.disposeWithMe(this._componentManager.register(key, comp));
986
+ });
987
+ [{
988
+ keyword: "/",
989
+ menus$: (0, rxjs.of)(builtInMenus),
990
+ preconditions: (params) => {
991
+ var _startNodePosition;
992
+ return ((_startNodePosition = params.range.startNodePosition) === null || _startNodePosition === void 0 ? void 0 : _startNodePosition.glyph) === 0;
993
+ }
994
+ }].forEach((popup) => {
995
+ this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(popup));
996
+ });
997
+ }
998
+ _initMenus() {}
999
+ };
1000
+ DocQuickInsertUIController = __decorate([
1001
+ __decorateParam(0, _univerjs_core.ICommandService),
1002
+ __decorateParam(1, (0, _univerjs_core.Inject)(DocQuickInsertPopupService)),
1003
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
1004
+ ], DocQuickInsertUIController);
1005
+
1006
+ //#endregion
1007
+ //#region package.json
1008
+ var name = "@univerjs/docs-quick-insert-ui";
1009
+ var version = "0.21.0-insiders.20260422-d7fcb4d";
1010
+
1011
+ //#endregion
1012
+ //#region src/config/config.ts
1013
+ const DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY = "docs-quick-insert-ui.config";
1014
+ const configSymbol = Symbol(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY);
1015
+ const defaultPluginConfig = {};
1016
+
1017
+ //#endregion
1018
+ //#region src/plugin.ts
1019
+ let UniverDocsQuickInsertUIPlugin = class UniverDocsQuickInsertUIPlugin extends _univerjs_core.Plugin {
1020
+ constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
1021
+ super();
1022
+ this._config = _config;
1023
+ this._injector = _injector;
1024
+ this._renderManagerSrv = _renderManagerSrv;
1025
+ this._configService = _configService;
1026
+ const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
1027
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
1028
+ this._configService.setConfig(DOCS_QUICK_INSERT_UI_PLUGIN_CONFIG_KEY, rest);
1029
+ }
1030
+ onStarting() {
1031
+ [
1032
+ [DocQuickInsertUIController],
1033
+ [DocQuickInsertTriggerController],
1034
+ [DocQuickInsertPopupService]
1035
+ ].forEach((dependency) => this._injector.add(dependency));
1036
+ this._injector.get(DocQuickInsertUIController);
1037
+ }
1038
+ onRendered() {
1039
+ this._injector.get(DocQuickInsertTriggerController);
1040
+ this._injector.get(DocQuickInsertPopupService);
1041
+ [[DocQuickInsertMenuController]].forEach((m) => {
1042
+ this._renderManagerSrv.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_DOC, m);
1043
+ });
1044
+ }
1045
+ };
1046
+ _defineProperty(UniverDocsQuickInsertUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_DOC);
1047
+ _defineProperty(UniverDocsQuickInsertUIPlugin, "pluginName", "DOC_QUICK_INSERT_UI_PLUGIN");
1048
+ _defineProperty(UniverDocsQuickInsertUIPlugin, "packageName", name);
1049
+ _defineProperty(UniverDocsQuickInsertUIPlugin, "version", version);
1050
+ UniverDocsQuickInsertUIPlugin = __decorate([
1051
+ (0, _univerjs_core.DependentOn)(_univerjs_drawing_ui.UniverDrawingUIPlugin, _univerjs_drawing.UniverDrawingPlugin, _univerjs_docs_drawing_ui.UniverDocsDrawingUIPlugin, _univerjs_docs_drawing.UniverDocsDrawingPlugin, _univerjs_ui.UniverUIPlugin),
1052
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
1053
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_render.IRenderManagerService)),
1054
+ __decorateParam(3, _univerjs_core.IConfigService)
1055
+ ], UniverDocsQuickInsertUIPlugin);
1056
+
1057
+ //#endregion
1058
+ Object.defineProperty(exports, 'DocQuickInsertPopupService', {
1059
+ enumerable: true,
1060
+ get: function () {
1061
+ return DocQuickInsertPopupService;
1062
+ }
1063
+ });
1064
+ Object.defineProperty(exports, 'DocQuickInsertTriggerController', {
1065
+ enumerable: true,
1066
+ get: function () {
1067
+ return DocQuickInsertTriggerController;
1068
+ }
1069
+ });
1070
+ Object.defineProperty(exports, 'DocQuickInsertUIController', {
1071
+ enumerable: true,
1072
+ get: function () {
1073
+ return DocQuickInsertUIController;
1074
+ }
1075
+ });
1076
+ exports.KeywordInputPlaceholderComponentKey = KeywordInputPlaceholderComponentKey;
1077
+ exports.QuickInsertPlaceholderComponentKey = QuickInsertPlaceholderComponentKey;
1078
+ Object.defineProperty(exports, 'UniverDocsQuickInsertUIPlugin', {
1079
+ enumerable: true,
1080
+ get: function () {
1081
+ return UniverDocsQuickInsertUIPlugin;
1082
+ }
1083
+ });