@univerjs/docs-quick-insert-ui 0.18.0 → 0.19.0-insiders.20260403-3e0e122

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,33 +1 @@
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:`
2
- univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors
3
- dark:!univer-text-gray-400
4
- `,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:`
5
- univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2
6
- univer-text-xs univer-font-semibold univer-text-gray-600
7
- dark:!univer-text-gray-300
8
- `,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)(`
9
- univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer
10
- univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none
11
- univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900
12
- univer-outline-none
13
- hover:univer-bg-gray-50
14
- dark:!univer-text-white
15
- dark:hover:!univer-bg-gray-600
16
- `,{"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)(`
17
- univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto
18
- univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2
19
- univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md
20
- dark:!univer-bg-gray-700 dark:!univer-text-white
21
- `,c.borderClassName,c.scrollbarClassName),onWheel:e=>e.stopPropagation(),children:p(t)})}const S=`docs.quick.insert.placeholder`,C=()=>(0,s.jsx)(`div`,{className:`
22
- univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white
23
- univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg
24
- `,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);const q=`doc.quick-insert.button`;let J=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:q,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))}};J=N([M(1,(0,e.Inject)(n.DocEventManagerService)),M(2,(0,e.Inject)(F)),M(3,(0,e.Inject)(n.DocCanvasPopManagerService))],J);const 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(J),g=(0,r.useDependency)(r.ILayoutService),_=(0,r.useDependency)(t.DocSelectionManagerService),v=(0,r.useObservable)(l.editPopup$),y=(0,r.useEvent)(e=>{var t;let n=h==null?void 0:h.popup;if(!n)return;let r=l.popups,i={keyword:``,menus$:(0,a.combineLatest)(r.map(e=>e.menus$)).pipe((0,a.map)(e=>e.flat()))};_.replaceDocRanges([{startOffset:n.startIndex,endOffset:n.startIndex}]),l.setInputOffset({start:n.startIndex-1,end:n.startIndex-1}),l.showPopup({popup:i,index:n.startIndex-1,unitId:(t=p==null?void 0:p.getUnitId())==null?``:t}),setTimeout(()=>{g.focus()})});return(0,s.jsx)(`div`,{className:(0,c.clsx)(`
25
- univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full
26
- univer-p-1.5 univer-shadow-sm
27
- hover:univer-bg-gray-100
28
- dark:!univer-text-gray-200
29
- dark:hover:!univer-bg-gray-700
30
- `,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:`
31
- univer-text-gray-800
32
- dark:!univer-text-gray-200
33
- `})})};Y.componentKey=q;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.18.0`;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),[[J]].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`});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.19.0-insiders.20260403-3e0e122`;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 $}});
package/lib/es/index.js CHANGED
@@ -1,33 +1 @@
1
- import{CommandType as e,DeleteDirection as t,DependentOn as n,Direction as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,IUniverInstanceService as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,RANGE_DIRECTION as p,UniverInstanceType as m,generateRandomId as h,merge as g,toDisposable as _}from"@univerjs/core";import{DocSelectionManagerService as v,DocSkeletonManagerService as y,RichTextEditingMutation as b}from"@univerjs/docs";import{BulletListCommand as ee,CutContentCommand as x,DeleteCommand as S,DeleteLeftCommand as C,DocCanvasPopManagerService as w,DocCreateTableOperation as te,DocEventManagerService as T,HorizontalLineCommand as ne,IMEInputCommand as re,InsertCommand as ie,MoveCursorOperation as ae,NodePositionConvertToCursor as oe,OrderListCommand as se,getAnchorBounding as ce}from"@univerjs/docs-ui";import{ComponentManager as le,ILayoutService as ue,IShortcutService as de,KeyCode as E,UniverUIPlugin as fe,useDependency as D,useEvent as pe,useObservable as O}from"@univerjs/ui";import{IRenderManagerService as k,ptToPixel as me}from"@univerjs/engine-render";import{BehaviorSubject as A,combineLatest as j,distinctUntilChanged as he,map as ge,of as _e,tap as M}from"rxjs";import{useEffect as N,useMemo as P,useRef as F,useState as ve}from"react";import{jsx as I,jsxs as L}from"react/jsx-runtime";import{Tooltip as ye,borderBottomClassName as be,borderClassName as xe,clsx as R,scrollbarClassName as Se}from"@univerjs/design";import{InsertDocImageCommand as Ce,UniverDocsDrawingUIPlugin as we}from"@univerjs/docs-drawing-ui";import{DividerIcon as Te,IncreaseIcon as Ee,TextIcon as De}from"@univerjs/icons";import{UniverDocsDrawingPlugin as Oe}from"@univerjs/docs-drawing";import{UniverDrawingPlugin as ke}from"@univerjs/drawing";import{UniverDrawingUIPlugin as Ae}from"@univerjs/drawing-ui";const je={id:`doc.command.delete-search-key`,type:e.COMMAND,handler:(e,t)=>{let n=e.get(o),{start:r,end:i}=t;return n.syncExecuteCommand(x.id,{segmentId:``,textRanges:[{startOffset:r,endOffset:r,collapsed:!0}],selections:[{startOffset:r,endOffset:i,collapsed:!1,direction:p.FORWARD}]})}},Me=`docs.quick.insert.keyword-input-placeholder`;function Ne(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 z=({popup:e})=>{var t,n,r,i,a,o,s,c,l,u,f;let p=D(d).t(`docQuickInsert.keywordInputPlaceholder`),m=me((t=(n=e.extraProps)==null?void 0:n.fontSize)==null?11:t),h=(r=(i=e.extraProps)==null?void 0:i.fontString)==null?`${m}px sans-serif`:r,g=(a=(o=e.extraProps)==null?void 0:o.ascent)==null?m:a,_=Math.max((s=(c=e.extraProps)==null?void 0:c.contentHeight)==null?m:s,m),v=P(()=>Ne(p,h),[h,p]);return I(`div`,{className:`
2
- univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors
3
- dark:!univer-text-gray-400
4
- `,children:I(`svg`,{width:v,height:_,viewBox:`0 0 ${v} ${_}`,style:{overflow:`visible`,display:`block`},children:I(`text`,{x:0,y:g,fill:`currentColor`,style:{font:h,fontFamily:(l=e.extraProps)==null?void 0:l.fontFamily,fontStyle:(u=e.extraProps)==null?void 0:u.fontStyle,fontWeight:(f=e.extraProps)==null?void 0:f.fontWeight},children:p})})})};z.componentKey=Me;function Pe(e){return`children`in e}function B(e){return e.flatMap(e=>Pe(e)?B(e.children):e)}function Fe(e){return B(e).length}function Ie(e){let{menus:t,focusedMenuIndex:n,focusedMenuRef:r,menuNodeMapRef:i,componentManager:a,onFocusedMenuIndexChange:o,onSelect:s}=e,c=P(()=>B(t),[t]);N(()=>{var e,t;let a=Number.isNaN(n)||(e=c[n])==null?null:e;r.current=a,a&&((t=i.current.get(a.id))==null||t.scrollIntoView({block:`nearest`}))},[c,n,r,i]);let l=F(0);l.current=0;function u(e){return e.map((t,r)=>{let c=t.icon,d=c?a.get(c):null;if(Pe(t))return L(`div`,{className:R(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&be),children:[L(`div`,{className:`
5
- univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2
6
- univer-text-xs univer-font-semibold univer-text-gray-600
7
- dark:!univer-text-gray-300
8
- `,children:[d&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(`span`,{children:t.title})]}),I(`div`,{className:`univer-grid univer-gap-1`,children:u(t.children)})]},t.id);let f=l.current,p=n===f;return l.current+=1,I(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:R(`
9
- univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer
10
- univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none
11
- univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900
12
- univer-outline-none
13
- hover:univer-bg-gray-50
14
- dark:!univer-text-white
15
- dark:hover:!univer-bg-gray-600
16
- `,{"hover:univer-bg-transparent":!p,"univer-bg-gray-50 dark:!univer-bg-gray-600":p}),onMouseEnter:()=>o(f),onMouseLeave:()=>o(NaN),onClick:()=>s(t),children:L(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(ye,{showIfEllipsis:!0,title:t.title,placement:`right`,children:I(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return I(`div`,{className:R(`
17
- univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto
18
- univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2
19
- univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md
20
- dark:!univer-bg-gray-700 dark:!univer-text-white
21
- `,xe,Se),onWheel:e=>e.stopPropagation(),children:u(t)})}const Le=`docs.quick.insert.placeholder`,V=()=>I(`div`,{className:`
22
- univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white
23
- univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg
24
- `,children:I(`span`,{children:D(d).t(`docQuickInsert.placeholder`)})});V.componentKey=Le;function H(e,t){return e.map(e=>({...e})).filter(e=>{if(`children`in e)return e.children=H(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 Re(e,t){return e.map(e=>{let n={...e};return`children`in n&&(n.children=Re(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 ze=[E.ARROW_UP,E.ARROW_DOWN,E.ENTER],U=()=>{let t=D(d),n=D(J),i=D(le),s=D(de),c=D(o),l=P(()=>h(),[]),[u,f]=ve(0),p=F(null),m=O(n.filterKeyword$,``),g=O(n.editPopup$),v=O(g==null?void 0:g.popup.menus$,[]),y=P(()=>Re(v,t),[v]),[b,ee]=ve(()=>H(y,m.toLowerCase())),x=P(()=>Fe(b),[b]),S=F(x);N(()=>{S.current=x},[x]),N(()=>{let e=requestIdleCallback(()=>{ee(H(y,m.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[y,m]);let C=e=>{n.emitMenuSelected(e),c.executeCommand(Y.id)};N(()=>{let t=new a;s.getAllShortcuts().filter(e=>e.binding&&ze.includes(e.binding)).forEach(e=>{let n=e.preconditions;e.preconditions=()=>!1,t.add(_(()=>{e.preconditions=n}))});let n={id:`quick.insert.popup.enter.${l}`,type:e.OPERATION,handler:()=>{let e=p.current;e&&C(e)}},i={id:`quick.insert.popup.move.cursor.up.${l}`,type:e.OPERATION,handler:()=>{f(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.OPERATION,handler:()=>{f(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(s.registerShortcut({priority:1e3,id:i.id,binding:E.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:r.UP}})),t.add(s.registerShortcut({priority:1e3,id:o.id,binding:E.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:r.DOWN}})),t.add(s.registerShortcut({priority:1e3,id:n.id,binding:E.ENTER,preconditions:()=>!0})),()=>{t.dispose()}},[c,l,s]),N(()=>{f(0)},[b]);let w=F(new Map);N(()=>()=>{w.current.clear()},[]);let te=b.length>0,T=(g==null?void 0:g.popup.Placeholder)||i.get(V.componentKey);return I(`div`,{className:`univer-mt-2`,children:te?I(Ie,{menus:b,focusedMenuIndex:u,focusedMenuRef:p,menuNodeMapRef:w,componentManager:i,onFocusedMenuIndexChange:f,onSelect:C}):T&&I(T,{})})};U.componentKey=`docs.quick.insert.popup`;function W(e){"@babel/helpers - typeof";return W=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},W(e)}function Be(e,t){if(W(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(W(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ve(e){var t=Be(e,`string`);return W(t)==`symbol`?t:t+``}function G(e,t,n){return(t=Ve(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function K(e,t){return function(n,r){t(n,r,e)}}function q(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 He={dispose:()=>{}};let J=class extends i{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(T)}constructor(e,t,n,r,i){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._docSelectionManagerService=i,G(this,`_popups`,new Set),G(this,`_editPopup$`,new A(void 0)),G(this,`editPopup$`,this._editPopup$.asObservable()),G(this,`_isComposing$`,new A(!1)),G(this,`isComposing$`,this._isComposing$.asObservable()),G(this,`_inputOffset$`,new A({start:0,end:0})),G(this,`inputOffset$`,this._inputOffset$.asObservable()),G(this,`filterKeyword$`,void 0),G(this,`_menuSelectedCallbacks`,new Set),G(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let a=(e,t)=>{var n;return(n=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC))==null||(n=n.getBody())==null?void 0:n.dataStream.slice(e,t)},o=``;this.filterKeyword$=this._inputOffset$.pipe(ge(e=>{var t;let n=a(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),he(),M(e=>{o=e})),this.disposeWithMe(j([this.filterKeyword$.pipe(M(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(M(e=>{if(e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;o.length<=0&&((n=this._inputPlaceholderRenderRoot)==null||n.mount())}})),this.editPopup$.pipe(M(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,n,r){let i=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!i)return r;let a=e.getOffsetConfig(),{contentBoxPointGroup:o}=new oe(a,t).getRangePointData(i,i);if(o.length===0)return r;let s=ce(o),c=s.left+a.docsLeft,l=s.top+a.docsTop;return{left:c,right:c,top:l,bottom:l+s.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,t){let n=this._renderManagerService.getRenderById(e),r=n==null?void 0:n.with(y),i=this._docSelectionManagerService.getActiveTextRange();if(!n||!r||!i)return He;let a=r.getSkeleton(),o=a.findNodeByCharIndex(i.startOffset,i.segmentId,i.segmentPage);if((o==null?void 0:o.content)!==`\r`||!o)return He;let s=n.mainComponent,c=this._getKeywordPlaceholderAnchorRect(s,a,i,t),l=this._getKeywordPlaceholderExtraProps(o),u=this._docCanvasPopupManagerService.attachPopupToRect(c,{componentKey:z.componentKey,extraProps:l,onClickOutside:()=>{u.dispose()},direction:`horizontal`},e);return u}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:U.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(je.id,{start:t,end:n}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(t=>t(e))},0)}};J=q([K(0,l(w)),K(1,l(c)),K(2,l(o)),K(3,l(k)),K(4,l(v))],J);const Ue={type:e.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(J);return t?(n.showPopup(t),!0):!1}},Y={type:e.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(J).closePopup(),!0}};let We=function(e){return e.Basic=`quick.insert.group.basic`,e.Media=`quick.insert.group.media`,e}({});const Ge={id:`quick-insert.text.menu`,title:`docQuickInsert.menu.text`,icon:`TextIcon`,keywords:[`text`]},Ke={id:se.id,title:`docQuickInsert.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},qe={id:ee.id,title:`docQuickInsert.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},Je={id:ne.id,title:`docQuickInsert.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},Ye={id:te.id,title:`docQuickInsert.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},Xe={id:Ce.id,title:`docQuickInsert.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},Ze=[{title:`docQuickInsert.group.basics`,id:We.Basic,children:[Ge,Ke,qe,Je,Ye,Xe]}],Qe=new Set([Ke.id,qe.id,Je.id,Ye.id,Xe.id]);let X=class extends i{constructor(e,t,n,r,i){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=i,this.disposeWithMe(this._shortcutService.registerShortcut({id:Y.id,binding:E.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:n,_textSelectionManagerService:i,_commandService:a}=this,o=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC);if(!(o!=null&&o.getDisabled())){if(e.id===ie.id){let t=e.params;if(n.editPopup){n.setInputOffset({start:n.inputOffset.start,end:t.range.endOffset+1});return}let r=i.getActiveTextRange();if(!r)return;let o=n.resolvePopup(t.body.dataStream);if(!o||!(!o.preconditions||o.preconditions(t)))return;n.setInputOffset({start:r.startOffset-1,end:r.startOffset}),setTimeout(()=>{a.executeCommand(Ue.id,{index:r.startOffset-1,unitId:t.unitId,popup:o})},100)}if(e.id===re.id){let t=e.params;!n.isComposing&&t.isCompositionStart&&n.setIsComposing(!0),n.isComposing&&t.isCompositionEnd&&n.setIsComposing(!1)}if(e.id===b.id){let t=e.params;if(t.isCompositionEnd){var s;let e=(s=t.textRanges)==null||(s=s[0])==null?void 0:s.endOffset;e&&n.setInputOffset({start:n.inputOffset.start,end:e})}}if(e.id===S.id){let r=e.params;if(n.editPopup&&r.direction===t.LEFT){var c;let e=(c=r.len)==null?0:c;n.setInputOffset({start:n.inputOffset.start,end:r.range.endOffset-e})}}if(e.id===ae.id){let t=e.params;(t.direction===r.LEFT||t.direction===r.RIGHT)&&n.editPopup&&a.executeCommand(Y.id)}if(e.id===C.id){let e=i.getActiveTextRange();if(!n.editPopup||!e)return;e.endOffset<=n.editPopup.anchor&&a.executeCommand(Y.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==Ge.id&&Qe.has(e.id)&&this._commandService.executeCommand(e.id)}))}};X=q([K(0,o),K(1,l(v)),K(2,l(J)),K(3,l(de)),K(4,l(c))],X);const $e=`doc.quick-insert.button`;let Z=class extends i{get popup(){return this._popup$.value}constructor(e,t,n,r){super(),this._context=e,this._docEventManagerService=t,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=r,G(this,`_popup$`,new A(null)),G(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe(j([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:$e,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))}};Z=q([K(1,l(T)),K(2,l(J)),K(3,l(w))],Z);const et=({className:e=``})=>{let t=D(J),n=D(c),r=D(k),i=O(P(()=>n.getCurrentTypeOfUnit$(m.UNIVER_DOC),[n])),a=i&&r.getRenderById(i.getUnitId()),o=a==null?void 0:a.with(Z),s=D(ue),l=D(v),u=O(t.editPopup$),d=pe(e=>{var n;let r=o==null?void 0:o.popup;if(!r)return;let a=t.popups,c={keyword:``,menus$:j(a.map(e=>e.menus$)).pipe(ge(e=>e.flat()))};l.replaceDocRanges([{startOffset:r.startIndex,endOffset:r.startIndex}]),t.setInputOffset({start:r.startIndex-1,end:r.startIndex-1}),t.showPopup({popup:c,index:r.startIndex-1,unitId:(n=i==null?void 0:i.getUnitId())==null?``:n}),setTimeout(()=>{s.focus()})});return I(`div`,{className:R(`
25
- univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full
26
- univer-p-1.5 univer-shadow-sm
27
- hover:univer-bg-gray-100
28
- dark:!univer-text-gray-200
29
- dark:hover:!univer-bg-gray-700
30
- `,xe,{"univer-bg-gray-100 dark:!univer-bg-gray-700":u,"univer-bg-white dark:!univer-bg-gray-900":!u},e),role:`button`,tabIndex:0,onClick:d,children:I(Ee,{className:`
31
- univer-text-gray-800
32
- dark:!univer-text-gray-200
33
- `})})};et.componentKey=$e;let Q=class extends i{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[je,Ue,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[U.componentKey,U],[z.componentKey,z],[V.componentKey,V],[Te.displayName,Te],[De.displayName,De],[et.componentKey,et]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:_e(Ze),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};Q=q([K(0,o),K(1,l(J)),K(2,l(le))],Q);var tt=`@univerjs/docs-quick-insert-ui`,nt=`0.18.0`;const rt=`docs-quick-insert-ui.config`;Symbol(rt);const it={};let $=class extends f{constructor(e=it,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=r;let{menu:i,...a}=g({},it,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(rt,a)}onStarting(){[[Q],[X],[J]].forEach(e=>this._injector.add(e)),this._injector.get(Q)}onRendered(){this._injector.get(X),this._injector.get(J),[[Z]].forEach(e=>{this._renderManagerSrv.registerRenderModule(m.UNIVER_DOC,e)})}};G($,`type`,m.UNIVER_DOC),G($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),G($,`packageName`,tt),G($,`version`,nt),$=q([n(Ae,ke,we,Oe,fe),K(1,l(u)),K(2,l(k)),K(3,s)],$);export{J as DocQuickInsertPopupService,X as DocQuickInsertTriggerController,Q as DocQuickInsertUIController,Me as KeywordInputPlaceholderComponentKey,Le as QuickInsertPlaceholderComponentKey,$ as UniverDocsQuickInsertUIPlugin};
1
+ import{CommandType as e,DeleteDirection as t,DependentOn as n,Direction as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,IUniverInstanceService as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,RANGE_DIRECTION as p,UniverInstanceType as m,generateRandomId as h,merge as g,toDisposable as _}from"@univerjs/core";import{DocSelectionManagerService as v,DocSkeletonManagerService as y,RichTextEditingMutation as b}from"@univerjs/docs";import{BulletListCommand as ee,CutContentCommand as x,DeleteCommand as S,DeleteLeftCommand as C,DocCanvasPopManagerService as w,DocCreateTableOperation as te,DocEventManagerService as T,HorizontalLineCommand as ne,IMEInputCommand as re,InsertCommand as ie,MoveCursorOperation as ae,NodePositionConvertToCursor as oe,OrderListCommand as se,getAnchorBounding as ce}from"@univerjs/docs-ui";import{ComponentManager as le,ILayoutService as ue,IShortcutService as de,KeyCode as E,UniverUIPlugin as fe,useDependency as D,useEvent as pe,useObservable as O}from"@univerjs/ui";import{IRenderManagerService as k,ptToPixel as me}from"@univerjs/engine-render";import{BehaviorSubject as A,combineLatest as j,distinctUntilChanged as he,map as ge,of as _e,tap as M}from"rxjs";import{useEffect as N,useMemo as P,useRef as F,useState as ve}from"react";import{jsx as I,jsxs as L}from"react/jsx-runtime";import{Tooltip as ye,borderBottomClassName as be,borderClassName as xe,clsx as R,scrollbarClassName as Se}from"@univerjs/design";import{InsertDocImageCommand as Ce,UniverDocsDrawingUIPlugin as we}from"@univerjs/docs-drawing-ui";import{DividerIcon as Te,IncreaseIcon as Ee,TextIcon as De}from"@univerjs/icons";import{UniverDocsDrawingPlugin as Oe}from"@univerjs/docs-drawing";import{UniverDrawingPlugin as ke}from"@univerjs/drawing";import{UniverDrawingUIPlugin as Ae}from"@univerjs/drawing-ui";const je={id:`doc.command.delete-search-key`,type:e.COMMAND,handler:(e,t)=>{let n=e.get(o),{start:r,end:i}=t;return n.syncExecuteCommand(x.id,{segmentId:``,textRanges:[{startOffset:r,endOffset:r,collapsed:!0}],selections:[{startOffset:r,endOffset:i,collapsed:!1,direction:p.FORWARD}]})}},Me=`docs.quick.insert.keyword-input-placeholder`;function Ne(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 z=({popup:e})=>{var t,n,r,i,a,o,s,c,l,u,f;let p=D(d).t(`docQuickInsert.keywordInputPlaceholder`),m=me((t=(n=e.extraProps)==null?void 0:n.fontSize)==null?11:t),h=(r=(i=e.extraProps)==null?void 0:i.fontString)==null?`${m}px sans-serif`:r,g=(a=(o=e.extraProps)==null?void 0:o.ascent)==null?m:a,_=Math.max((s=(c=e.extraProps)==null?void 0:c.contentHeight)==null?m:s,m),v=P(()=>Ne(p,h),[h,p]);return I(`div`,{className:`univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors dark:!univer-text-gray-400`,children:I(`svg`,{width:v,height:_,viewBox:`0 0 ${v} ${_}`,style:{overflow:`visible`,display:`block`},children:I(`text`,{x:0,y:g,fill:`currentColor`,style:{font:h,fontFamily:(l=e.extraProps)==null?void 0:l.fontFamily,fontStyle:(u=e.extraProps)==null?void 0:u.fontStyle,fontWeight:(f=e.extraProps)==null?void 0:f.fontWeight},children:p})})})};z.componentKey=Me;function Pe(e){return`children`in e}function B(e){return e.flatMap(e=>Pe(e)?B(e.children):e)}function Fe(e){return B(e).length}function Ie(e){let{menus:t,focusedMenuIndex:n,focusedMenuRef:r,menuNodeMapRef:i,componentManager:a,onFocusedMenuIndexChange:o,onSelect:s}=e,c=P(()=>B(t),[t]);N(()=>{var e,t;let a=Number.isNaN(n)||(e=c[n])==null?null:e;r.current=a,a&&((t=i.current.get(a.id))==null||t.scrollIntoView({block:`nearest`}))},[c,n,r,i]);let l=F(0);l.current=0;function u(e){return e.map((t,r)=>{let c=t.icon,d=c?a.get(c):null;if(Pe(t))return L(`div`,{className:R(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&be),children:[L(`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&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(`span`,{children:t.title})]}),I(`div`,{className:`univer-grid univer-gap-1`,children:u(t.children)})]},t.id);let f=l.current,p=n===f;return l.current+=1,I(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:R(`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":!p,"univer-bg-gray-50 dark:!univer-bg-gray-600":p}),onMouseEnter:()=>o(f),onMouseLeave:()=>o(NaN),onClick:()=>s(t),children:L(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(ye,{showIfEllipsis:!0,title:t.title,placement:`right`,children:I(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return I(`div`,{className:R(`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`,xe,Se),onWheel:e=>e.stopPropagation(),children:u(t)})}const Le=`docs.quick.insert.placeholder`,V=()=>I(`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:I(`span`,{children:D(d).t(`docQuickInsert.placeholder`)})});V.componentKey=Le;function H(e,t){return e.map(e=>({...e})).filter(e=>{if(`children`in e)return e.children=H(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 Re(e,t){return e.map(e=>{let n={...e};return`children`in n&&(n.children=Re(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 ze=[E.ARROW_UP,E.ARROW_DOWN,E.ENTER],U=()=>{let t=D(d),n=D(J),i=D(le),s=D(de),c=D(o),l=P(()=>h(),[]),[u,f]=ve(0),p=F(null),m=O(n.filterKeyword$,``),g=O(n.editPopup$),v=O(g==null?void 0:g.popup.menus$,[]),y=P(()=>Re(v,t),[v]),[b,ee]=ve(()=>H(y,m.toLowerCase())),x=P(()=>Fe(b),[b]),S=F(x);N(()=>{S.current=x},[x]),N(()=>{let e=requestIdleCallback(()=>{ee(H(y,m.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[y,m]);let C=e=>{n.emitMenuSelected(e),c.executeCommand(Y.id)};N(()=>{let t=new a;s.getAllShortcuts().filter(e=>e.binding&&ze.includes(e.binding)).forEach(e=>{let n=e.preconditions;e.preconditions=()=>!1,t.add(_(()=>{e.preconditions=n}))});let n={id:`quick.insert.popup.enter.${l}`,type:e.OPERATION,handler:()=>{let e=p.current;e&&C(e)}},i={id:`quick.insert.popup.move.cursor.up.${l}`,type:e.OPERATION,handler:()=>{f(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.OPERATION,handler:()=>{f(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(s.registerShortcut({priority:1e3,id:i.id,binding:E.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:r.UP}})),t.add(s.registerShortcut({priority:1e3,id:o.id,binding:E.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:r.DOWN}})),t.add(s.registerShortcut({priority:1e3,id:n.id,binding:E.ENTER,preconditions:()=>!0})),()=>{t.dispose()}},[c,l,s]),N(()=>{f(0)},[b]);let w=F(new Map);N(()=>()=>{w.current.clear()},[]);let te=b.length>0,T=(g==null?void 0:g.popup.Placeholder)||i.get(V.componentKey);return I(`div`,{className:`univer-mt-2`,children:te?I(Ie,{menus:b,focusedMenuIndex:u,focusedMenuRef:p,menuNodeMapRef:w,componentManager:i,onFocusedMenuIndexChange:f,onSelect:C}):T&&I(T,{})})};U.componentKey=`docs.quick.insert.popup`;function W(e){"@babel/helpers - typeof";return W=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},W(e)}function Be(e,t){if(W(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(W(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ve(e){var t=Be(e,`string`);return W(t)==`symbol`?t:t+``}function G(e,t,n){return(t=Ve(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function K(e,t){return function(n,r){t(n,r,e)}}function q(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 He={dispose:()=>{}};let J=class extends i{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(T)}constructor(e,t,n,r,i){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._docSelectionManagerService=i,G(this,`_popups`,new Set),G(this,`_editPopup$`,new A(void 0)),G(this,`editPopup$`,this._editPopup$.asObservable()),G(this,`_isComposing$`,new A(!1)),G(this,`isComposing$`,this._isComposing$.asObservable()),G(this,`_inputOffset$`,new A({start:0,end:0})),G(this,`inputOffset$`,this._inputOffset$.asObservable()),G(this,`filterKeyword$`,void 0),G(this,`_menuSelectedCallbacks`,new Set),G(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let a=(e,t)=>{var n;return(n=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC))==null||(n=n.getBody())==null?void 0:n.dataStream.slice(e,t)},o=``;this.filterKeyword$=this._inputOffset$.pipe(ge(e=>{var t;let n=a(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),he(),M(e=>{o=e})),this.disposeWithMe(j([this.filterKeyword$.pipe(M(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(M(e=>{if(e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;o.length<=0&&((n=this._inputPlaceholderRenderRoot)==null||n.mount())}})),this.editPopup$.pipe(M(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,n,r){let i=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!i)return r;let a=e.getOffsetConfig(),{contentBoxPointGroup:o}=new oe(a,t).getRangePointData(i,i);if(o.length===0)return r;let s=ce(o),c=s.left+a.docsLeft,l=s.top+a.docsTop;return{left:c,right:c,top:l,bottom:l+s.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,t){let n=this._renderManagerService.getRenderById(e),r=n==null?void 0:n.with(y),i=this._docSelectionManagerService.getActiveTextRange();if(!n||!r||!i)return He;let a=r.getSkeleton(),o=a.findNodeByCharIndex(i.startOffset,i.segmentId,i.segmentPage);if((o==null?void 0:o.content)!==`\r`||!o)return He;let s=n.mainComponent,c=this._getKeywordPlaceholderAnchorRect(s,a,i,t),l=this._getKeywordPlaceholderExtraProps(o),u=this._docCanvasPopupManagerService.attachPopupToRect(c,{componentKey:z.componentKey,extraProps:l,onClickOutside:()=>{u.dispose()},direction:`horizontal`},e);return u}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:U.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(je.id,{start:t,end:n}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(t=>t(e))},0)}};J=q([K(0,l(w)),K(1,l(c)),K(2,l(o)),K(3,l(k)),K(4,l(v))],J);const Ue={type:e.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(J);return t?(n.showPopup(t),!0):!1}},Y={type:e.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(J).closePopup(),!0}};let We=function(e){return e.Basic=`quick.insert.group.basic`,e.Media=`quick.insert.group.media`,e}({});const Ge={id:`quick-insert.text.menu`,title:`docQuickInsert.menu.text`,icon:`TextIcon`,keywords:[`text`]},Ke={id:se.id,title:`docQuickInsert.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},qe={id:ee.id,title:`docQuickInsert.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},Je={id:ne.id,title:`docQuickInsert.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},Ye={id:te.id,title:`docQuickInsert.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},Xe={id:Ce.id,title:`docQuickInsert.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},Ze=[{title:`docQuickInsert.group.basics`,id:We.Basic,children:[Ge,Ke,qe,Je,Ye,Xe]}],Qe=new Set([Ke.id,qe.id,Je.id,Ye.id,Xe.id]);let X=class extends i{constructor(e,t,n,r,i){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=i,this.disposeWithMe(this._shortcutService.registerShortcut({id:Y.id,binding:E.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:n,_textSelectionManagerService:i,_commandService:a}=this,o=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC);if(!(o!=null&&o.getDisabled())){if(e.id===ie.id){let t=e.params;if(n.editPopup){n.setInputOffset({start:n.inputOffset.start,end:t.range.endOffset+1});return}let r=i.getActiveTextRange();if(!r)return;let o=n.resolvePopup(t.body.dataStream);if(!o||!(!o.preconditions||o.preconditions(t)))return;n.setInputOffset({start:r.startOffset-1,end:r.startOffset}),setTimeout(()=>{a.executeCommand(Ue.id,{index:r.startOffset-1,unitId:t.unitId,popup:o})},100)}if(e.id===re.id){let t=e.params;!n.isComposing&&t.isCompositionStart&&n.setIsComposing(!0),n.isComposing&&t.isCompositionEnd&&n.setIsComposing(!1)}if(e.id===b.id){let t=e.params;if(t.isCompositionEnd){var s;let e=(s=t.textRanges)==null||(s=s[0])==null?void 0:s.endOffset;e&&n.setInputOffset({start:n.inputOffset.start,end:e})}}if(e.id===S.id){let r=e.params;if(n.editPopup&&r.direction===t.LEFT){var c;let e=(c=r.len)==null?0:c;n.setInputOffset({start:n.inputOffset.start,end:r.range.endOffset-e})}}if(e.id===ae.id){let t=e.params;(t.direction===r.LEFT||t.direction===r.RIGHT)&&n.editPopup&&a.executeCommand(Y.id)}if(e.id===C.id){let e=i.getActiveTextRange();if(!n.editPopup||!e)return;e.endOffset<=n.editPopup.anchor&&a.executeCommand(Y.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==Ge.id&&Qe.has(e.id)&&this._commandService.executeCommand(e.id)}))}};X=q([K(0,o),K(1,l(v)),K(2,l(J)),K(3,l(de)),K(4,l(c))],X);let Z=class extends i{get popup(){return this._popup$.value}constructor(e,t,n,r){super(),this._context=e,this._docEventManagerService=t,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=r,G(this,`_popup$`,new A(null)),G(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe(j([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:$e,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))}};Z=q([K(1,l(T)),K(2,l(J)),K(3,l(w))],Z);const $e=`doc.quick-insert.button`,et=({className:e=``})=>{let t=D(J),n=D(c),r=D(k),i=O(P(()=>n.getCurrentTypeOfUnit$(m.UNIVER_DOC),[n])),a=i&&r.getRenderById(i.getUnitId()),o=a==null?void 0:a.with(Z),s=D(ue),l=D(v),u=O(t.editPopup$),d=pe(()=>{var e;let n=o==null?void 0:o.popup;if(!n)return;let r=t.popups,a={keyword:``,menus$:j(r.map(e=>e.menus$)).pipe(ge(e=>e.flat()))};l.replaceDocRanges([{startOffset:n.startIndex,endOffset:n.startIndex}]),t.setInputOffset({start:n.startIndex-1,end:n.startIndex-1}),t.showPopup({popup:a,index:n.startIndex-1,unitId:(e=i==null?void 0:i.getUnitId())==null?``:e}),setTimeout(()=>{s.focus()})});return I(`div`,{className:R(`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`,xe,{"univer-bg-gray-100 dark:!univer-bg-gray-700":u,"univer-bg-white dark:!univer-bg-gray-900":!u},e),role:`button`,tabIndex:0,onClick:d,children:I(Ee,{className:`univer-text-gray-800 dark:!univer-text-gray-200`})})};et.componentKey=$e;let Q=class extends i{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[je,Ue,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[U.componentKey,U],[z.componentKey,z],[V.componentKey,V],[Te.displayName,Te],[De.displayName,De],[et.componentKey,et]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:_e(Ze),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};Q=q([K(0,o),K(1,l(J)),K(2,l(le))],Q);var tt=`@univerjs/docs-quick-insert-ui`,nt=`0.19.0-insiders.20260403-3e0e122`;const rt=`docs-quick-insert-ui.config`;Symbol(rt);const it={};let $=class extends f{constructor(e=it,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=r;let{menu:i,...a}=g({},it,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(rt,a)}onStarting(){[[Q],[X],[J]].forEach(e=>this._injector.add(e)),this._injector.get(Q)}onRendered(){this._injector.get(X),this._injector.get(J),[[Z]].forEach(e=>{this._renderManagerSrv.registerRenderModule(m.UNIVER_DOC,e)})}};G($,`type`,m.UNIVER_DOC),G($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),G($,`packageName`,tt),G($,`version`,nt),$=q([n(Ae,ke,we,Oe,fe),K(1,l(u)),K(2,l(k)),K(3,s)],$);export{J as DocQuickInsertPopupService,X as DocQuickInsertTriggerController,Q as DocQuickInsertUIController,Me as KeywordInputPlaceholderComponentKey,Le as QuickInsertPlaceholderComponentKey,$ as UniverDocsQuickInsertUIPlugin};
package/lib/index.js CHANGED
@@ -1,33 +1 @@
1
- import{CommandType as e,DeleteDirection as t,DependentOn as n,Direction as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,IUniverInstanceService as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,RANGE_DIRECTION as p,UniverInstanceType as m,generateRandomId as h,merge as g,toDisposable as _}from"@univerjs/core";import{DocSelectionManagerService as v,DocSkeletonManagerService as y,RichTextEditingMutation as b}from"@univerjs/docs";import{BulletListCommand as ee,CutContentCommand as x,DeleteCommand as S,DeleteLeftCommand as C,DocCanvasPopManagerService as w,DocCreateTableOperation as te,DocEventManagerService as T,HorizontalLineCommand as ne,IMEInputCommand as re,InsertCommand as ie,MoveCursorOperation as ae,NodePositionConvertToCursor as oe,OrderListCommand as se,getAnchorBounding as ce}from"@univerjs/docs-ui";import{ComponentManager as le,ILayoutService as ue,IShortcutService as de,KeyCode as E,UniverUIPlugin as fe,useDependency as D,useEvent as pe,useObservable as O}from"@univerjs/ui";import{IRenderManagerService as k,ptToPixel as me}from"@univerjs/engine-render";import{BehaviorSubject as A,combineLatest as j,distinctUntilChanged as he,map as ge,of as _e,tap as M}from"rxjs";import{useEffect as N,useMemo as P,useRef as F,useState as ve}from"react";import{jsx as I,jsxs as L}from"react/jsx-runtime";import{Tooltip as ye,borderBottomClassName as be,borderClassName as xe,clsx as R,scrollbarClassName as Se}from"@univerjs/design";import{InsertDocImageCommand as Ce,UniverDocsDrawingUIPlugin as we}from"@univerjs/docs-drawing-ui";import{DividerIcon as Te,IncreaseIcon as Ee,TextIcon as De}from"@univerjs/icons";import{UniverDocsDrawingPlugin as Oe}from"@univerjs/docs-drawing";import{UniverDrawingPlugin as ke}from"@univerjs/drawing";import{UniverDrawingUIPlugin as Ae}from"@univerjs/drawing-ui";const je={id:`doc.command.delete-search-key`,type:e.COMMAND,handler:(e,t)=>{let n=e.get(o),{start:r,end:i}=t;return n.syncExecuteCommand(x.id,{segmentId:``,textRanges:[{startOffset:r,endOffset:r,collapsed:!0}],selections:[{startOffset:r,endOffset:i,collapsed:!1,direction:p.FORWARD}]})}},Me=`docs.quick.insert.keyword-input-placeholder`;function Ne(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 z=({popup:e})=>{var t,n,r,i,a,o,s,c,l,u,f;let p=D(d).t(`docQuickInsert.keywordInputPlaceholder`),m=me((t=(n=e.extraProps)==null?void 0:n.fontSize)==null?11:t),h=(r=(i=e.extraProps)==null?void 0:i.fontString)==null?`${m}px sans-serif`:r,g=(a=(o=e.extraProps)==null?void 0:o.ascent)==null?m:a,_=Math.max((s=(c=e.extraProps)==null?void 0:c.contentHeight)==null?m:s,m),v=P(()=>Ne(p,h),[h,p]);return I(`div`,{className:`
2
- univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors
3
- dark:!univer-text-gray-400
4
- `,children:I(`svg`,{width:v,height:_,viewBox:`0 0 ${v} ${_}`,style:{overflow:`visible`,display:`block`},children:I(`text`,{x:0,y:g,fill:`currentColor`,style:{font:h,fontFamily:(l=e.extraProps)==null?void 0:l.fontFamily,fontStyle:(u=e.extraProps)==null?void 0:u.fontStyle,fontWeight:(f=e.extraProps)==null?void 0:f.fontWeight},children:p})})})};z.componentKey=Me;function Pe(e){return`children`in e}function B(e){return e.flatMap(e=>Pe(e)?B(e.children):e)}function Fe(e){return B(e).length}function Ie(e){let{menus:t,focusedMenuIndex:n,focusedMenuRef:r,menuNodeMapRef:i,componentManager:a,onFocusedMenuIndexChange:o,onSelect:s}=e,c=P(()=>B(t),[t]);N(()=>{var e,t;let a=Number.isNaN(n)||(e=c[n])==null?null:e;r.current=a,a&&((t=i.current.get(a.id))==null||t.scrollIntoView({block:`nearest`}))},[c,n,r,i]);let l=F(0);l.current=0;function u(e){return e.map((t,r)=>{let c=t.icon,d=c?a.get(c):null;if(Pe(t))return L(`div`,{className:R(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&be),children:[L(`div`,{className:`
5
- univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2
6
- univer-text-xs univer-font-semibold univer-text-gray-600
7
- dark:!univer-text-gray-300
8
- `,children:[d&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(`span`,{children:t.title})]}),I(`div`,{className:`univer-grid univer-gap-1`,children:u(t.children)})]},t.id);let f=l.current,p=n===f;return l.current+=1,I(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:R(`
9
- univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer
10
- univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none
11
- univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900
12
- univer-outline-none
13
- hover:univer-bg-gray-50
14
- dark:!univer-text-white
15
- dark:hover:!univer-bg-gray-600
16
- `,{"hover:univer-bg-transparent":!p,"univer-bg-gray-50 dark:!univer-bg-gray-600":p}),onMouseEnter:()=>o(f),onMouseLeave:()=>o(NaN),onClick:()=>s(t),children:L(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(ye,{showIfEllipsis:!0,title:t.title,placement:`right`,children:I(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return I(`div`,{className:R(`
17
- univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto
18
- univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2
19
- univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md
20
- dark:!univer-bg-gray-700 dark:!univer-text-white
21
- `,xe,Se),onWheel:e=>e.stopPropagation(),children:u(t)})}const Le=`docs.quick.insert.placeholder`,V=()=>I(`div`,{className:`
22
- univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white
23
- univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg
24
- `,children:I(`span`,{children:D(d).t(`docQuickInsert.placeholder`)})});V.componentKey=Le;function H(e,t){return e.map(e=>({...e})).filter(e=>{if(`children`in e)return e.children=H(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 Re(e,t){return e.map(e=>{let n={...e};return`children`in n&&(n.children=Re(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 ze=[E.ARROW_UP,E.ARROW_DOWN,E.ENTER],U=()=>{let t=D(d),n=D(J),i=D(le),s=D(de),c=D(o),l=P(()=>h(),[]),[u,f]=ve(0),p=F(null),m=O(n.filterKeyword$,``),g=O(n.editPopup$),v=O(g==null?void 0:g.popup.menus$,[]),y=P(()=>Re(v,t),[v]),[b,ee]=ve(()=>H(y,m.toLowerCase())),x=P(()=>Fe(b),[b]),S=F(x);N(()=>{S.current=x},[x]),N(()=>{let e=requestIdleCallback(()=>{ee(H(y,m.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[y,m]);let C=e=>{n.emitMenuSelected(e),c.executeCommand(Y.id)};N(()=>{let t=new a;s.getAllShortcuts().filter(e=>e.binding&&ze.includes(e.binding)).forEach(e=>{let n=e.preconditions;e.preconditions=()=>!1,t.add(_(()=>{e.preconditions=n}))});let n={id:`quick.insert.popup.enter.${l}`,type:e.OPERATION,handler:()=>{let e=p.current;e&&C(e)}},i={id:`quick.insert.popup.move.cursor.up.${l}`,type:e.OPERATION,handler:()=>{f(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.OPERATION,handler:()=>{f(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(s.registerShortcut({priority:1e3,id:i.id,binding:E.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:r.UP}})),t.add(s.registerShortcut({priority:1e3,id:o.id,binding:E.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:r.DOWN}})),t.add(s.registerShortcut({priority:1e3,id:n.id,binding:E.ENTER,preconditions:()=>!0})),()=>{t.dispose()}},[c,l,s]),N(()=>{f(0)},[b]);let w=F(new Map);N(()=>()=>{w.current.clear()},[]);let te=b.length>0,T=(g==null?void 0:g.popup.Placeholder)||i.get(V.componentKey);return I(`div`,{className:`univer-mt-2`,children:te?I(Ie,{menus:b,focusedMenuIndex:u,focusedMenuRef:p,menuNodeMapRef:w,componentManager:i,onFocusedMenuIndexChange:f,onSelect:C}):T&&I(T,{})})};U.componentKey=`docs.quick.insert.popup`;function W(e){"@babel/helpers - typeof";return W=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},W(e)}function Be(e,t){if(W(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(W(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ve(e){var t=Be(e,`string`);return W(t)==`symbol`?t:t+``}function G(e,t,n){return(t=Ve(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function K(e,t){return function(n,r){t(n,r,e)}}function q(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 He={dispose:()=>{}};let J=class extends i{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(T)}constructor(e,t,n,r,i){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._docSelectionManagerService=i,G(this,`_popups`,new Set),G(this,`_editPopup$`,new A(void 0)),G(this,`editPopup$`,this._editPopup$.asObservable()),G(this,`_isComposing$`,new A(!1)),G(this,`isComposing$`,this._isComposing$.asObservable()),G(this,`_inputOffset$`,new A({start:0,end:0})),G(this,`inputOffset$`,this._inputOffset$.asObservable()),G(this,`filterKeyword$`,void 0),G(this,`_menuSelectedCallbacks`,new Set),G(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let a=(e,t)=>{var n;return(n=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC))==null||(n=n.getBody())==null?void 0:n.dataStream.slice(e,t)},o=``;this.filterKeyword$=this._inputOffset$.pipe(ge(e=>{var t;let n=a(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),he(),M(e=>{o=e})),this.disposeWithMe(j([this.filterKeyword$.pipe(M(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(M(e=>{if(e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;o.length<=0&&((n=this._inputPlaceholderRenderRoot)==null||n.mount())}})),this.editPopup$.pipe(M(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,n,r){let i=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!i)return r;let a=e.getOffsetConfig(),{contentBoxPointGroup:o}=new oe(a,t).getRangePointData(i,i);if(o.length===0)return r;let s=ce(o),c=s.left+a.docsLeft,l=s.top+a.docsTop;return{left:c,right:c,top:l,bottom:l+s.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,t){let n=this._renderManagerService.getRenderById(e),r=n==null?void 0:n.with(y),i=this._docSelectionManagerService.getActiveTextRange();if(!n||!r||!i)return He;let a=r.getSkeleton(),o=a.findNodeByCharIndex(i.startOffset,i.segmentId,i.segmentPage);if((o==null?void 0:o.content)!==`\r`||!o)return He;let s=n.mainComponent,c=this._getKeywordPlaceholderAnchorRect(s,a,i,t),l=this._getKeywordPlaceholderExtraProps(o),u=this._docCanvasPopupManagerService.attachPopupToRect(c,{componentKey:z.componentKey,extraProps:l,onClickOutside:()=>{u.dispose()},direction:`horizontal`},e);return u}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:U.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(je.id,{start:t,end:n}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(t=>t(e))},0)}};J=q([K(0,l(w)),K(1,l(c)),K(2,l(o)),K(3,l(k)),K(4,l(v))],J);const Ue={type:e.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(J);return t?(n.showPopup(t),!0):!1}},Y={type:e.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(J).closePopup(),!0}};let We=function(e){return e.Basic=`quick.insert.group.basic`,e.Media=`quick.insert.group.media`,e}({});const Ge={id:`quick-insert.text.menu`,title:`docQuickInsert.menu.text`,icon:`TextIcon`,keywords:[`text`]},Ke={id:se.id,title:`docQuickInsert.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},qe={id:ee.id,title:`docQuickInsert.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},Je={id:ne.id,title:`docQuickInsert.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},Ye={id:te.id,title:`docQuickInsert.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},Xe={id:Ce.id,title:`docQuickInsert.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},Ze=[{title:`docQuickInsert.group.basics`,id:We.Basic,children:[Ge,Ke,qe,Je,Ye,Xe]}],Qe=new Set([Ke.id,qe.id,Je.id,Ye.id,Xe.id]);let X=class extends i{constructor(e,t,n,r,i){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=i,this.disposeWithMe(this._shortcutService.registerShortcut({id:Y.id,binding:E.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:n,_textSelectionManagerService:i,_commandService:a}=this,o=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC);if(!(o!=null&&o.getDisabled())){if(e.id===ie.id){let t=e.params;if(n.editPopup){n.setInputOffset({start:n.inputOffset.start,end:t.range.endOffset+1});return}let r=i.getActiveTextRange();if(!r)return;let o=n.resolvePopup(t.body.dataStream);if(!o||!(!o.preconditions||o.preconditions(t)))return;n.setInputOffset({start:r.startOffset-1,end:r.startOffset}),setTimeout(()=>{a.executeCommand(Ue.id,{index:r.startOffset-1,unitId:t.unitId,popup:o})},100)}if(e.id===re.id){let t=e.params;!n.isComposing&&t.isCompositionStart&&n.setIsComposing(!0),n.isComposing&&t.isCompositionEnd&&n.setIsComposing(!1)}if(e.id===b.id){let t=e.params;if(t.isCompositionEnd){var s;let e=(s=t.textRanges)==null||(s=s[0])==null?void 0:s.endOffset;e&&n.setInputOffset({start:n.inputOffset.start,end:e})}}if(e.id===S.id){let r=e.params;if(n.editPopup&&r.direction===t.LEFT){var c;let e=(c=r.len)==null?0:c;n.setInputOffset({start:n.inputOffset.start,end:r.range.endOffset-e})}}if(e.id===ae.id){let t=e.params;(t.direction===r.LEFT||t.direction===r.RIGHT)&&n.editPopup&&a.executeCommand(Y.id)}if(e.id===C.id){let e=i.getActiveTextRange();if(!n.editPopup||!e)return;e.endOffset<=n.editPopup.anchor&&a.executeCommand(Y.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==Ge.id&&Qe.has(e.id)&&this._commandService.executeCommand(e.id)}))}};X=q([K(0,o),K(1,l(v)),K(2,l(J)),K(3,l(de)),K(4,l(c))],X);const $e=`doc.quick-insert.button`;let Z=class extends i{get popup(){return this._popup$.value}constructor(e,t,n,r){super(),this._context=e,this._docEventManagerService=t,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=r,G(this,`_popup$`,new A(null)),G(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe(j([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:$e,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))}};Z=q([K(1,l(T)),K(2,l(J)),K(3,l(w))],Z);const et=({className:e=``})=>{let t=D(J),n=D(c),r=D(k),i=O(P(()=>n.getCurrentTypeOfUnit$(m.UNIVER_DOC),[n])),a=i&&r.getRenderById(i.getUnitId()),o=a==null?void 0:a.with(Z),s=D(ue),l=D(v),u=O(t.editPopup$),d=pe(e=>{var n;let r=o==null?void 0:o.popup;if(!r)return;let a=t.popups,c={keyword:``,menus$:j(a.map(e=>e.menus$)).pipe(ge(e=>e.flat()))};l.replaceDocRanges([{startOffset:r.startIndex,endOffset:r.startIndex}]),t.setInputOffset({start:r.startIndex-1,end:r.startIndex-1}),t.showPopup({popup:c,index:r.startIndex-1,unitId:(n=i==null?void 0:i.getUnitId())==null?``:n}),setTimeout(()=>{s.focus()})});return I(`div`,{className:R(`
25
- univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full
26
- univer-p-1.5 univer-shadow-sm
27
- hover:univer-bg-gray-100
28
- dark:!univer-text-gray-200
29
- dark:hover:!univer-bg-gray-700
30
- `,xe,{"univer-bg-gray-100 dark:!univer-bg-gray-700":u,"univer-bg-white dark:!univer-bg-gray-900":!u},e),role:`button`,tabIndex:0,onClick:d,children:I(Ee,{className:`
31
- univer-text-gray-800
32
- dark:!univer-text-gray-200
33
- `})})};et.componentKey=$e;let Q=class extends i{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[je,Ue,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[U.componentKey,U],[z.componentKey,z],[V.componentKey,V],[Te.displayName,Te],[De.displayName,De],[et.componentKey,et]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:_e(Ze),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};Q=q([K(0,o),K(1,l(J)),K(2,l(le))],Q);var tt=`@univerjs/docs-quick-insert-ui`,nt=`0.18.0`;const rt=`docs-quick-insert-ui.config`;Symbol(rt);const it={};let $=class extends f{constructor(e=it,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=r;let{menu:i,...a}=g({},it,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(rt,a)}onStarting(){[[Q],[X],[J]].forEach(e=>this._injector.add(e)),this._injector.get(Q)}onRendered(){this._injector.get(X),this._injector.get(J),[[Z]].forEach(e=>{this._renderManagerSrv.registerRenderModule(m.UNIVER_DOC,e)})}};G($,`type`,m.UNIVER_DOC),G($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),G($,`packageName`,tt),G($,`version`,nt),$=q([n(Ae,ke,we,Oe,fe),K(1,l(u)),K(2,l(k)),K(3,s)],$);export{J as DocQuickInsertPopupService,X as DocQuickInsertTriggerController,Q as DocQuickInsertUIController,Me as KeywordInputPlaceholderComponentKey,Le as QuickInsertPlaceholderComponentKey,$ as UniverDocsQuickInsertUIPlugin};
1
+ import{CommandType as e,DeleteDirection as t,DependentOn as n,Direction as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,IUniverInstanceService as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,RANGE_DIRECTION as p,UniverInstanceType as m,generateRandomId as h,merge as g,toDisposable as _}from"@univerjs/core";import{DocSelectionManagerService as v,DocSkeletonManagerService as y,RichTextEditingMutation as b}from"@univerjs/docs";import{BulletListCommand as ee,CutContentCommand as x,DeleteCommand as S,DeleteLeftCommand as C,DocCanvasPopManagerService as w,DocCreateTableOperation as te,DocEventManagerService as T,HorizontalLineCommand as ne,IMEInputCommand as re,InsertCommand as ie,MoveCursorOperation as ae,NodePositionConvertToCursor as oe,OrderListCommand as se,getAnchorBounding as ce}from"@univerjs/docs-ui";import{ComponentManager as le,ILayoutService as ue,IShortcutService as de,KeyCode as E,UniverUIPlugin as fe,useDependency as D,useEvent as pe,useObservable as O}from"@univerjs/ui";import{IRenderManagerService as k,ptToPixel as me}from"@univerjs/engine-render";import{BehaviorSubject as A,combineLatest as j,distinctUntilChanged as he,map as ge,of as _e,tap as M}from"rxjs";import{useEffect as N,useMemo as P,useRef as F,useState as ve}from"react";import{jsx as I,jsxs as L}from"react/jsx-runtime";import{Tooltip as ye,borderBottomClassName as be,borderClassName as xe,clsx as R,scrollbarClassName as Se}from"@univerjs/design";import{InsertDocImageCommand as Ce,UniverDocsDrawingUIPlugin as we}from"@univerjs/docs-drawing-ui";import{DividerIcon as Te,IncreaseIcon as Ee,TextIcon as De}from"@univerjs/icons";import{UniverDocsDrawingPlugin as Oe}from"@univerjs/docs-drawing";import{UniverDrawingPlugin as ke}from"@univerjs/drawing";import{UniverDrawingUIPlugin as Ae}from"@univerjs/drawing-ui";const je={id:`doc.command.delete-search-key`,type:e.COMMAND,handler:(e,t)=>{let n=e.get(o),{start:r,end:i}=t;return n.syncExecuteCommand(x.id,{segmentId:``,textRanges:[{startOffset:r,endOffset:r,collapsed:!0}],selections:[{startOffset:r,endOffset:i,collapsed:!1,direction:p.FORWARD}]})}},Me=`docs.quick.insert.keyword-input-placeholder`;function Ne(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 z=({popup:e})=>{var t,n,r,i,a,o,s,c,l,u,f;let p=D(d).t(`docQuickInsert.keywordInputPlaceholder`),m=me((t=(n=e.extraProps)==null?void 0:n.fontSize)==null?11:t),h=(r=(i=e.extraProps)==null?void 0:i.fontString)==null?`${m}px sans-serif`:r,g=(a=(o=e.extraProps)==null?void 0:o.ascent)==null?m:a,_=Math.max((s=(c=e.extraProps)==null?void 0:c.contentHeight)==null?m:s,m),v=P(()=>Ne(p,h),[h,p]);return I(`div`,{className:`univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors dark:!univer-text-gray-400`,children:I(`svg`,{width:v,height:_,viewBox:`0 0 ${v} ${_}`,style:{overflow:`visible`,display:`block`},children:I(`text`,{x:0,y:g,fill:`currentColor`,style:{font:h,fontFamily:(l=e.extraProps)==null?void 0:l.fontFamily,fontStyle:(u=e.extraProps)==null?void 0:u.fontStyle,fontWeight:(f=e.extraProps)==null?void 0:f.fontWeight},children:p})})})};z.componentKey=Me;function Pe(e){return`children`in e}function B(e){return e.flatMap(e=>Pe(e)?B(e.children):e)}function Fe(e){return B(e).length}function Ie(e){let{menus:t,focusedMenuIndex:n,focusedMenuRef:r,menuNodeMapRef:i,componentManager:a,onFocusedMenuIndexChange:o,onSelect:s}=e,c=P(()=>B(t),[t]);N(()=>{var e,t;let a=Number.isNaN(n)||(e=c[n])==null?null:e;r.current=a,a&&((t=i.current.get(a.id))==null||t.scrollIntoView({block:`nearest`}))},[c,n,r,i]);let l=F(0);l.current=0;function u(e){return e.map((t,r)=>{let c=t.icon,d=c?a.get(c):null;if(Pe(t))return L(`div`,{className:R(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&be),children:[L(`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&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(`span`,{children:t.title})]}),I(`div`,{className:`univer-grid univer-gap-1`,children:u(t.children)})]},t.id);let f=l.current,p=n===f;return l.current+=1,I(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:R(`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":!p,"univer-bg-gray-50 dark:!univer-bg-gray-600":p}),onMouseEnter:()=>o(f),onMouseLeave:()=>o(NaN),onClick:()=>s(t),children:L(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&I(`span`,{className:`univer-inline-flex univer-text-base`,children:I(d,{})}),I(ye,{showIfEllipsis:!0,title:t.title,placement:`right`,children:I(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return I(`div`,{className:R(`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`,xe,Se),onWheel:e=>e.stopPropagation(),children:u(t)})}const Le=`docs.quick.insert.placeholder`,V=()=>I(`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:I(`span`,{children:D(d).t(`docQuickInsert.placeholder`)})});V.componentKey=Le;function H(e,t){return e.map(e=>({...e})).filter(e=>{if(`children`in e)return e.children=H(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 Re(e,t){return e.map(e=>{let n={...e};return`children`in n&&(n.children=Re(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 ze=[E.ARROW_UP,E.ARROW_DOWN,E.ENTER],U=()=>{let t=D(d),n=D(J),i=D(le),s=D(de),c=D(o),l=P(()=>h(),[]),[u,f]=ve(0),p=F(null),m=O(n.filterKeyword$,``),g=O(n.editPopup$),v=O(g==null?void 0:g.popup.menus$,[]),y=P(()=>Re(v,t),[v]),[b,ee]=ve(()=>H(y,m.toLowerCase())),x=P(()=>Fe(b),[b]),S=F(x);N(()=>{S.current=x},[x]),N(()=>{let e=requestIdleCallback(()=>{ee(H(y,m.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[y,m]);let C=e=>{n.emitMenuSelected(e),c.executeCommand(Y.id)};N(()=>{let t=new a;s.getAllShortcuts().filter(e=>e.binding&&ze.includes(e.binding)).forEach(e=>{let n=e.preconditions;e.preconditions=()=>!1,t.add(_(()=>{e.preconditions=n}))});let n={id:`quick.insert.popup.enter.${l}`,type:e.OPERATION,handler:()=>{let e=p.current;e&&C(e)}},i={id:`quick.insert.popup.move.cursor.up.${l}`,type:e.OPERATION,handler:()=>{f(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.OPERATION,handler:()=>{f(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(s.registerShortcut({priority:1e3,id:i.id,binding:E.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:r.UP}})),t.add(s.registerShortcut({priority:1e3,id:o.id,binding:E.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:r.DOWN}})),t.add(s.registerShortcut({priority:1e3,id:n.id,binding:E.ENTER,preconditions:()=>!0})),()=>{t.dispose()}},[c,l,s]),N(()=>{f(0)},[b]);let w=F(new Map);N(()=>()=>{w.current.clear()},[]);let te=b.length>0,T=(g==null?void 0:g.popup.Placeholder)||i.get(V.componentKey);return I(`div`,{className:`univer-mt-2`,children:te?I(Ie,{menus:b,focusedMenuIndex:u,focusedMenuRef:p,menuNodeMapRef:w,componentManager:i,onFocusedMenuIndexChange:f,onSelect:C}):T&&I(T,{})})};U.componentKey=`docs.quick.insert.popup`;function W(e){"@babel/helpers - typeof";return W=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},W(e)}function Be(e,t){if(W(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(W(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ve(e){var t=Be(e,`string`);return W(t)==`symbol`?t:t+``}function G(e,t,n){return(t=Ve(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function K(e,t){return function(n,r){t(n,r,e)}}function q(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 He={dispose:()=>{}};let J=class extends i{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(T)}constructor(e,t,n,r,i){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=t,this._commandService=n,this._renderManagerService=r,this._docSelectionManagerService=i,G(this,`_popups`,new Set),G(this,`_editPopup$`,new A(void 0)),G(this,`editPopup$`,this._editPopup$.asObservable()),G(this,`_isComposing$`,new A(!1)),G(this,`isComposing$`,this._isComposing$.asObservable()),G(this,`_inputOffset$`,new A({start:0,end:0})),G(this,`inputOffset$`,this._inputOffset$.asObservable()),G(this,`filterKeyword$`,void 0),G(this,`_menuSelectedCallbacks`,new Set),G(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let a=(e,t)=>{var n;return(n=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC))==null||(n=n.getBody())==null?void 0:n.dataStream.slice(e,t)},o=``;this.filterKeyword$=this._inputOffset$.pipe(ge(e=>{var t;let n=a(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),he(),M(e=>{o=e})),this.disposeWithMe(j([this.filterKeyword$.pipe(M(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(M(e=>{if(e){var t;(t=this._inputPlaceholderRenderRoot)==null||(t=t.unmount)==null||t.dispose()}else{var n;o.length<=0&&((n=this._inputPlaceholderRenderRoot)==null||n.mount())}})),this.editPopup$.pipe(M(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,n,r){let i=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!i)return r;let a=e.getOffsetConfig(),{contentBoxPointGroup:o}=new oe(a,t).getRangePointData(i,i);if(o.length===0)return r;let s=ce(o),c=s.left+a.docsLeft,l=s.top+a.docsTop;return{left:c,right:c,top:l,bottom:l+s.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,t){let n=this._renderManagerService.getRenderById(e),r=n==null?void 0:n.with(y),i=this._docSelectionManagerService.getActiveTextRange();if(!n||!r||!i)return He;let a=r.getSkeleton(),o=a.findNodeByCharIndex(i.startOffset,i.segmentId,i.segmentPage);if((o==null?void 0:o.content)!==`\r`||!o)return He;let s=n.mainComponent,c=this._getKeywordPlaceholderAnchorRect(s,a,i,t),l=this._getKeywordPlaceholderExtraProps(o),u=this._docCanvasPopupManagerService.attachPopupToRect(c,{componentKey:z.componentKey,extraProps:l,onClickOutside:()=>{u.dispose()},direction:`horizontal`},e);return u}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:U.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(je.id,{start:t,end:n}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(t=>t(e))},0)}};J=q([K(0,l(w)),K(1,l(c)),K(2,l(o)),K(3,l(k)),K(4,l(v))],J);const Ue={type:e.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(J);return t?(n.showPopup(t),!0):!1}},Y={type:e.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(J).closePopup(),!0}};let We=function(e){return e.Basic=`quick.insert.group.basic`,e.Media=`quick.insert.group.media`,e}({});const Ge={id:`quick-insert.text.menu`,title:`docQuickInsert.menu.text`,icon:`TextIcon`,keywords:[`text`]},Ke={id:se.id,title:`docQuickInsert.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},qe={id:ee.id,title:`docQuickInsert.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},Je={id:ne.id,title:`docQuickInsert.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},Ye={id:te.id,title:`docQuickInsert.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},Xe={id:Ce.id,title:`docQuickInsert.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},Ze=[{title:`docQuickInsert.group.basics`,id:We.Basic,children:[Ge,Ke,qe,Je,Ye,Xe]}],Qe=new Set([Ke.id,qe.id,Je.id,Ye.id,Xe.id]);let X=class extends i{constructor(e,t,n,r,i){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=i,this.disposeWithMe(this._shortcutService.registerShortcut({id:Y.id,binding:E.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:n,_textSelectionManagerService:i,_commandService:a}=this,o=this._univerInstanceService.getCurrentUnitOfType(m.UNIVER_DOC);if(!(o!=null&&o.getDisabled())){if(e.id===ie.id){let t=e.params;if(n.editPopup){n.setInputOffset({start:n.inputOffset.start,end:t.range.endOffset+1});return}let r=i.getActiveTextRange();if(!r)return;let o=n.resolvePopup(t.body.dataStream);if(!o||!(!o.preconditions||o.preconditions(t)))return;n.setInputOffset({start:r.startOffset-1,end:r.startOffset}),setTimeout(()=>{a.executeCommand(Ue.id,{index:r.startOffset-1,unitId:t.unitId,popup:o})},100)}if(e.id===re.id){let t=e.params;!n.isComposing&&t.isCompositionStart&&n.setIsComposing(!0),n.isComposing&&t.isCompositionEnd&&n.setIsComposing(!1)}if(e.id===b.id){let t=e.params;if(t.isCompositionEnd){var s;let e=(s=t.textRanges)==null||(s=s[0])==null?void 0:s.endOffset;e&&n.setInputOffset({start:n.inputOffset.start,end:e})}}if(e.id===S.id){let r=e.params;if(n.editPopup&&r.direction===t.LEFT){var c;let e=(c=r.len)==null?0:c;n.setInputOffset({start:n.inputOffset.start,end:r.range.endOffset-e})}}if(e.id===ae.id){let t=e.params;(t.direction===r.LEFT||t.direction===r.RIGHT)&&n.editPopup&&a.executeCommand(Y.id)}if(e.id===C.id){let e=i.getActiveTextRange();if(!n.editPopup||!e)return;e.endOffset<=n.editPopup.anchor&&a.executeCommand(Y.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==Ge.id&&Qe.has(e.id)&&this._commandService.executeCommand(e.id)}))}};X=q([K(0,o),K(1,l(v)),K(2,l(J)),K(3,l(de)),K(4,l(c))],X);let Z=class extends i{get popup(){return this._popup$.value}constructor(e,t,n,r){super(),this._context=e,this._docEventManagerService=t,this._docQuickInsertPopupService=n,this._docCanvasPopManagerService=r,G(this,`_popup$`,new A(null)),G(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe(j([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:$e,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))}};Z=q([K(1,l(T)),K(2,l(J)),K(3,l(w))],Z);const $e=`doc.quick-insert.button`,et=({className:e=``})=>{let t=D(J),n=D(c),r=D(k),i=O(P(()=>n.getCurrentTypeOfUnit$(m.UNIVER_DOC),[n])),a=i&&r.getRenderById(i.getUnitId()),o=a==null?void 0:a.with(Z),s=D(ue),l=D(v),u=O(t.editPopup$),d=pe(()=>{var e;let n=o==null?void 0:o.popup;if(!n)return;let r=t.popups,a={keyword:``,menus$:j(r.map(e=>e.menus$)).pipe(ge(e=>e.flat()))};l.replaceDocRanges([{startOffset:n.startIndex,endOffset:n.startIndex}]),t.setInputOffset({start:n.startIndex-1,end:n.startIndex-1}),t.showPopup({popup:a,index:n.startIndex-1,unitId:(e=i==null?void 0:i.getUnitId())==null?``:e}),setTimeout(()=>{s.focus()})});return I(`div`,{className:R(`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`,xe,{"univer-bg-gray-100 dark:!univer-bg-gray-700":u,"univer-bg-white dark:!univer-bg-gray-900":!u},e),role:`button`,tabIndex:0,onClick:d,children:I(Ee,{className:`univer-text-gray-800 dark:!univer-text-gray-200`})})};et.componentKey=$e;let Q=class extends i{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[je,Ue,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[U.componentKey,U],[z.componentKey,z],[V.componentKey,V],[Te.displayName,Te],[De.displayName,De],[et.componentKey,et]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:_e(Ze),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};Q=q([K(0,o),K(1,l(J)),K(2,l(le))],Q);var tt=`@univerjs/docs-quick-insert-ui`,nt=`0.19.0-insiders.20260403-3e0e122`;const rt=`docs-quick-insert-ui.config`;Symbol(rt);const it={};let $=class extends f{constructor(e=it,t,n,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=r;let{menu:i,...a}=g({},it,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(rt,a)}onStarting(){[[Q],[X],[J]].forEach(e=>this._injector.add(e)),this._injector.get(Q)}onRendered(){this._injector.get(X),this._injector.get(J),[[Z]].forEach(e=>{this._renderManagerSrv.registerRenderModule(m.UNIVER_DOC,e)})}};G($,`type`,m.UNIVER_DOC),G($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),G($,`packageName`,tt),G($,`version`,nt),$=q([n(Ae,ke,we,Oe,fe),K(1,l(u)),K(2,l(k)),K(3,s)],$);export{J as DocQuickInsertPopupService,X as DocQuickInsertTriggerController,Q as DocQuickInsertUIController,Me as KeywordInputPlaceholderComponentKey,Le as QuickInsertPlaceholderComponentKey,$ as UniverDocsQuickInsertUIPlugin};
@@ -14,3 +14,9 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export declare const QuickInsertButtonComponentKey = "doc.quick-insert.button";
17
+ export declare const QuickInsertButton: {
18
+ ({ className }: {
19
+ className?: string;
20
+ }): import("react/jsx-runtime").JSX.Element;
21
+ componentKey: string;
22
+ };
package/lib/umd/index.js CHANGED
@@ -1,33 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/docs`),require(`@univerjs/docs-ui`),require(`@univerjs/ui`),require(`@univerjs/engine-render`),require(`rxjs`),require(`react`),require(`react/jsx-runtime`),require(`@univerjs/design`),require(`@univerjs/docs-drawing-ui`),require(`@univerjs/docs-drawing`),require(`@univerjs/drawing`),require(`@univerjs/drawing-ui`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/engine-render`,`rxjs`,`react`,`react/jsx-runtime`,`@univerjs/design`,`@univerjs/docs-drawing-ui`,`@univerjs/docs-drawing`,`@univerjs/drawing`,`@univerjs/drawing-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsQuickInsertUi={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverUi,e.UniverEngineRender,e.rxjs,e.React,e.React,e.UniverDesign,e.UniverDocsDrawingUi,e.UniverDocsDrawing,e.UniverDrawing,e.UniverDrawingUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let m={id:`doc.command.delete-search-key`,type:t.CommandType.COMMAND,handler:(e,n)=>{let i=e.get(t.ICommandService),{start:a,end:o}=n;return i.syncExecuteCommand(r.CutContentCommand.id,{segmentId:``,textRanges:[{startOffset:a,endOffset:a,collapsed:!0}],selections:[{startOffset:a,endOffset:o,collapsed:!1,direction:t.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}let _=({popup:e})=>{var n,r,o,l,u,d,f,p,m,h,_;let v=(0,i.useDependency)(t.LocaleService).t(`docQuickInsert.keywordInputPlaceholder`),y=(0,a.ptToPixel)((n=(r=e.extraProps)==null?void 0:r.fontSize)==null?11:n),b=(o=(l=e.extraProps)==null?void 0:l.fontString)==null?`${y}px sans-serif`:o,x=(u=(d=e.extraProps)==null?void 0:d.ascent)==null?y:u,S=Math.max((f=(p=e.extraProps)==null?void 0:p.contentHeight)==null?y:f,y),C=(0,s.useMemo)(()=>g(v,b),[b,v]);return(0,c.jsx)(`div`,{className:`
2
- univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors
3
- dark:!univer-text-gray-400
4
- `,children:(0,c.jsx)(`svg`,{width:C,height:S,viewBox:`0 0 ${C} ${S}`,style:{overflow:`visible`,display:`block`},children:(0,c.jsx)(`text`,{x:0,y:x,fill:`currentColor`,style:{font:b,fontFamily:(m=e.extraProps)==null?void 0:m.fontFamily,fontStyle:(h=e.extraProps)==null?void 0:h.fontStyle,fontWeight:(_=e.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:o,onSelect:u}=e,d=(0,s.useMemo)(()=>y(t),[t]);(0,s.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,s.useRef)(0);f.current=0;function p(e){return e.map((t,r)=>{let s=t.icon,d=s?a.get(s):null;if(v(t))return(0,c.jsxs)(`div`,{className:(0,l.clsx)(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&l.borderBottomClassName),children:[(0,c.jsxs)(`div`,{className:`
5
- univer-box-border univer-inline-flex univer-items-center univer-gap-2 univer-px-2
6
- univer-text-xs univer-font-semibold univer-text-gray-600
7
- dark:!univer-text-gray-300
8
- `,children:[d&&(0,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(d,{})}),(0,c.jsx)(`span`,{children:t.title})]}),(0,c.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,c.jsx)(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:(0,l.clsx)(`
9
- univer-relative univer-box-border univer-flex univer-min-h-8 univer-w-full univer-cursor-pointer
10
- univer-items-center univer-justify-between univer-gap-3 univer-rounded-md univer-border-none
11
- univer-bg-transparent univer-px-2 univer-text-left univer-text-sm univer-text-gray-900
12
- univer-outline-none
13
- hover:univer-bg-gray-50
14
- dark:!univer-text-white
15
- dark:hover:!univer-bg-gray-600
16
- `,{"hover:univer-bg-transparent":!h,"univer-bg-gray-50 dark:!univer-bg-gray-600":h}),onMouseEnter:()=>o(m),onMouseLeave:()=>o(NaN),onClick:()=>u(t),children:(0,c.jsxs)(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&(0,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(d,{})}),(0,c.jsx)(l.Tooltip,{showIfEllipsis:!0,title:t.title,placement:`right`,children:(0,c.jsx)(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return(0,c.jsx)(`div`,{className:(0,l.clsx)(`
17
- univer-box-border univer-grid univer-max-h-[360px] univer-gap-1 univer-overflow-y-auto
18
- univer-overflow-x-hidden univer-overscroll-contain univer-rounded-md univer-bg-white univer-px-2
19
- univer-py-1 univer-text-sm univer-text-gray-900 univer-shadow-md
20
- dark:!univer-bg-gray-700 dark:!univer-text-white
21
- `,l.borderClassName,l.scrollbarClassName),onWheel:e=>e.stopPropagation(),children:p(t)})}let S=`docs.quick.insert.placeholder`,C=()=>(0,c.jsx)(`div`,{className:`
22
- univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white
23
- univer-px-12 univer-py-6 univer-text-gray-400 univer-shadow-lg
24
- `,children:(0,c.jsx)(`span`,{children:(0,i.useDependency)(t.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})}let ee=[i.KeyCode.ARROW_UP,i.KeyCode.ARROW_DOWN,i.KeyCode.ENTER],E=()=>{let e=(0,i.useDependency)(t.LocaleService),n=(0,i.useDependency)(P),r=(0,i.useDependency)(i.ComponentManager),a=(0,i.useDependency)(i.IShortcutService),o=(0,i.useDependency)(t.ICommandService),l=(0,s.useMemo)(()=>(0,t.generateRandomId)(),[]),[u,d]=(0,s.useState)(0),f=(0,s.useRef)(null),p=(0,i.useObservable)(n.filterKeyword$,``),m=(0,i.useObservable)(n.editPopup$),h=(0,i.useObservable)(m==null?void 0:m.popup.menus$,[]),g=(0,s.useMemo)(()=>T(h,e),[h]),[_,v]=(0,s.useState)(()=>w(g,p.toLowerCase())),y=(0,s.useMemo)(()=>b(_),[_]),S=(0,s.useRef)(y);(0,s.useEffect)(()=>{S.current=y},[y]),(0,s.useEffect)(()=>{let e=requestIdleCallback(()=>{v(w(g,p.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[g,p]);let E=e=>{n.emitMenuSelected(e),o.executeCommand(I.id)};(0,s.useEffect)(()=>{let e=new t.DisposableCollection;a.getAllShortcuts().filter(e=>e.binding&&ee.includes(e.binding)).forEach(n=>{let r=n.preconditions;n.preconditions=()=>!1,e.add((0,t.toDisposable)(()=>{n.preconditions=r}))});let n={id:`quick.insert.popup.enter.${l}`,type:t.CommandType.OPERATION,handler:()=>{let e=f.current;e&&E(e)}},r={id:`quick.insert.popup.move.cursor.up.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e-1;return t>=0?t:S.current-1})}},s={id:`quick.insert.popup.move.cursor.down.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e+1;return t<=S.current-1?t:0})}};return e.add(o.registerCommand(r)),e.add(o.registerCommand(s)),e.add(o.registerCommand(n)),e.add(a.registerShortcut({priority:1e3,id:r.id,binding:i.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:t.Direction.UP}})),e.add(a.registerShortcut({priority:1e3,id:s.id,binding:i.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:t.Direction.DOWN}})),e.add(a.registerShortcut({priority:1e3,id:n.id,binding:i.KeyCode.ENTER,preconditions:()=>!0})),()=>{e.dispose()}},[o,l,a]),(0,s.useEffect)(()=>{d(0)},[_]);let D=(0,s.useRef)(new Map);(0,s.useEffect)(()=>()=>{D.current.clear()},[]);let O=_.length>0,k=(m==null?void 0:m.popup.Placeholder)||r.get(C.componentKey);return(0,c.jsx)(`div`,{className:`univer-mt-2`,children:O?(0,c.jsx)(x,{menus:_,focusedMenuIndex:u,focusedMenuRef:f,menuNodeMapRef:D,componentManager:r,onFocusedMenuIndexChange:d,onSelect:E}):k&&(0,c.jsx)(k,{})})};E.componentKey=`docs.quick.insert.popup`;function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e,t){return function(n,r){t(n,r,e)}}function M(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}let N={dispose:()=>{}},P=class extends t.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(r.DocEventManagerService)}constructor(e,n,r,i,a){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=r,this._renderManagerService=i,this._docSelectionManagerService=a,A(this,`_popups`,new Set),A(this,`_editPopup$`,new o.BehaviorSubject(void 0)),A(this,`editPopup$`,this._editPopup$.asObservable()),A(this,`_isComposing$`,new o.BehaviorSubject(!1)),A(this,`isComposing$`,this._isComposing$.asObservable()),A(this,`_inputOffset$`,new o.BehaviorSubject({start:0,end:0})),A(this,`inputOffset$`,this._inputOffset$.asObservable()),A(this,`filterKeyword$`,void 0),A(this,`_menuSelectedCallbacks`,new Set),A(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let s=(e,n)=>{var r;return(r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC))==null||(r=r.getBody())==null?void 0:r.dataStream.slice(e,n)},c=``;this.filterKeyword$=this._inputOffset$.pipe((0,o.map)(e=>{var t;let n=s(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),(0,o.distinctUntilChanged)(),(0,o.tap)(e=>{c=e})),this.disposeWithMe((0,o.combineLatest)([this.filterKeyword$.pipe((0,o.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,o.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,o.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,n,i){let a=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!a)return i;let o=e.getOffsetConfig(),{contentBoxPointGroup:s}=new r.NodePositionConvertToCursor(o,t).getRangePointData(a,a);if(s.length===0)return i;let c=(0,r.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,t){let r=this._renderManagerService.getRenderById(e),i=r==null?void 0:r.with(n.DocSkeletonManagerService),a=this._docSelectionManagerService.getActiveTextRange();if(!r||!i||!a)return N;let o=i.getSkeleton(),s=o.findNodeByCharIndex(a.startOffset,a.segmentId,a.segmentPage);if((s==null?void 0:s.content)!==`\r`||!s)return N;let c=r.mainComponent,l=this._getKeywordPlaceholderAnchorRect(c,o,a,t),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:E.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)}};P=M([j(0,(0,t.Inject)(r.DocCanvasPopManagerService)),j(1,(0,t.Inject)(t.IUniverInstanceService)),j(2,(0,t.Inject)(t.ICommandService)),j(3,(0,t.Inject)(a.IRenderManagerService)),j(4,(0,t.Inject)(n.DocSelectionManagerService))],P);let F={type:t.CommandType.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(P);return t?(n.showPopup(t),!0):!1}},I={type:t.CommandType.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(P).closePopup(),!0}},te=function(e){return e.Basic=`quick.insert.group.basic`,e.Media=`quick.insert.group.media`,e}({}),L={id:`quick-insert.text.menu`,title:`docQuickInsert.menu.text`,icon:`TextIcon`,keywords:[`text`]},ne={id:r.OrderListCommand.id,title:`docQuickInsert.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},R={id:r.BulletListCommand.id,title:`docQuickInsert.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},z={id:r.HorizontalLineCommand.id,title:`docQuickInsert.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},B={id:r.DocCreateTableOperation.id,title:`docQuickInsert.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},V={id:u.InsertDocImageCommand.id,title:`docQuickInsert.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},re=[{title:`docQuickInsert.group.basics`,id:te.Basic,children:[L,ne,R,z,B,V]}],ie=new Set([ne.id,R.id,z.id,B.id,V.id]),H=class extends t.Disposable{constructor(e,t,n,r,a){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=a,this.disposeWithMe(this._shortcutService.registerShortcut({id:I.id,binding:i.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:i,_textSelectionManagerService:a,_commandService:o}=this,s=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!(s!=null&&s.getDisabled())){if(e.id===r.InsertCommand.id){let t=e.params;if(i.editPopup){i.setInputOffset({start:i.inputOffset.start,end:t.range.endOffset+1});return}let n=a.getActiveTextRange();if(!n)return;let r=i.resolvePopup(t.body.dataStream);if(!r||!(!r.preconditions||r.preconditions(t)))return;i.setInputOffset({start:n.startOffset-1,end:n.startOffset}),setTimeout(()=>{o.executeCommand(F.id,{index:n.startOffset-1,unitId:t.unitId,popup:r})},100)}if(e.id===r.IMEInputCommand.id){let t=e.params;!i.isComposing&&t.isCompositionStart&&i.setIsComposing(!0),i.isComposing&&t.isCompositionEnd&&i.setIsComposing(!1)}if(e.id===n.RichTextEditingMutation.id){let t=e.params;if(t.isCompositionEnd){var c;let e=(c=t.textRanges)==null||(c=c[0])==null?void 0:c.endOffset;e&&i.setInputOffset({start:i.inputOffset.start,end:e})}}if(e.id===r.DeleteCommand.id){let n=e.params;if(i.editPopup&&n.direction===t.DeleteDirection.LEFT){var l;let e=(l=n.len)==null?0:l;i.setInputOffset({start:i.inputOffset.start,end:n.range.endOffset-e})}}if(e.id===r.MoveCursorOperation.id){let n=e.params;(n.direction===t.Direction.LEFT||n.direction===t.Direction.RIGHT)&&i.editPopup&&o.executeCommand(I.id)}if(e.id===r.DeleteLeftCommand.id){let e=a.getActiveTextRange();if(!i.editPopup||!e)return;e.endOffset<=i.editPopup.anchor&&o.executeCommand(I.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==L.id&&ie.has(e.id)&&this._commandService.executeCommand(e.id)}))}};H=M([j(0,t.ICommandService),j(1,(0,t.Inject)(n.DocSelectionManagerService)),j(2,(0,t.Inject)(P)),j(3,(0,t.Inject)(i.IShortcutService)),j(4,(0,t.Inject)(t.IUniverInstanceService))],H);function U({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,s.useRef)(`_${se()}`);return W(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...o},a)}function W(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...ae(e,n,i),...r},(oe(e,n).children||[]).map((r,a)=>W(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ae(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function oe(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function se(){return Math.random().toString(36).substring(2,8)}U.displayName=`UniverIcon`;let ce={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=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`divider-icon`,ref:t,icon:ce}))});G.displayName=`DividerIcon`;let le={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`}}]},K=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`increase-icon`,ref:t,icon:le}))});K.displayName=`IncreaseIcon`;let ue={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`]},q=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`text-icon`,ref:t,icon:ue}))});q.displayName=`TextIcon`;let J=`doc.quick-insert.button`,Y=class extends t.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,A(this,`_popup$`,new o.BehaviorSubject(null)),A(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe((0,o.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))}};Y=M([j(1,(0,t.Inject)(r.DocEventManagerService)),j(2,(0,t.Inject)(P)),j(3,(0,t.Inject)(r.DocCanvasPopManagerService))],Y);let X=({className:e=``})=>{let r=(0,i.useDependency)(P),u=(0,i.useDependency)(t.IUniverInstanceService),d=(0,i.useDependency)(a.IRenderManagerService),f=(0,i.useObservable)((0,s.useMemo)(()=>u.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC),[u])),p=f&&d.getRenderById(f.getUnitId()),m=p==null?void 0:p.with(Y),h=(0,i.useDependency)(i.ILayoutService),g=(0,i.useDependency)(n.DocSelectionManagerService),_=(0,i.useObservable)(r.editPopup$),v=(0,i.useEvent)(e=>{var t;let n=m==null?void 0:m.popup;if(!n)return;let i=r.popups,a={keyword:``,menus$:(0,o.combineLatest)(i.map(e=>e.menus$)).pipe((0,o.map)(e=>e.flat()))};g.replaceDocRanges([{startOffset:n.startIndex,endOffset:n.startIndex}]),r.setInputOffset({start:n.startIndex-1,end:n.startIndex-1}),r.showPopup({popup:a,index:n.startIndex-1,unitId:(t=f==null?void 0:f.getUnitId())==null?``:t}),setTimeout(()=>{h.focus()})});return(0,c.jsx)(`div`,{className:(0,l.clsx)(`
25
- univer-mr-1 univer-flex univer-cursor-pointer univer-items-center univer-gap-2.5 univer-rounded-full
26
- univer-p-1.5 univer-shadow-sm
27
- hover:univer-bg-gray-100
28
- dark:!univer-text-gray-200
29
- dark:hover:!univer-bg-gray-700
30
- `,l.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":_,"univer-bg-white dark:!univer-bg-gray-900":!_},e),role:`button`,tabIndex:0,onClick:v,children:(0,c.jsx)(K,{className:`
31
- univer-text-gray-800
32
- dark:!univer-text-gray-200
33
- `})})};X.componentKey=J;let Z=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[m,F,I].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[E.componentKey,E],[_.componentKey,_],[C.componentKey,C],[G.displayName,G],[q.displayName,q],[X.componentKey,X]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:(0,o.of)(re),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};Z=M([j(0,t.ICommandService),j(1,(0,t.Inject)(P)),j(2,(0,t.Inject)(i.ComponentManager))],Z);var de=`@univerjs/docs-quick-insert-ui`,fe=`0.18.0`;let Q=`docs-quick-insert-ui.config`;Symbol(Q);let pe={},$=class extends t.Plugin{constructor(e=pe,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},pe,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(Q,o)}onStarting(){[[Z],[H],[P]].forEach(e=>this._injector.add(e)),this._injector.get(Z)}onRendered(){this._injector.get(H),this._injector.get(P),[[Y]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};A($,`type`,t.UniverInstanceType.UNIVER_DOC),A($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),A($,`packageName`,de),A($,`version`,fe),$=M([(0,t.DependentOn)(p.UniverDrawingUIPlugin,f.UniverDrawingPlugin,u.UniverDocsDrawingUIPlugin,d.UniverDocsDrawingPlugin,i.UniverUIPlugin),j(1,(0,t.Inject)(t.Injector)),j(2,(0,t.Inject)(a.IRenderManagerService)),j(3,t.IConfigService)],$),Object.defineProperty(e,`DocQuickInsertPopupService`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(e,`DocQuickInsertTriggerController`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(e,`DocQuickInsertUIController`,{enumerable:!0,get:function(){return Z}}),e.KeywordInputPlaceholderComponentKey=h,e.QuickInsertPlaceholderComponentKey=S,Object.defineProperty(e,`UniverDocsQuickInsertUIPlugin`,{enumerable:!0,get:function(){return $}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/docs`),require(`@univerjs/docs-ui`),require(`@univerjs/ui`),require(`@univerjs/engine-render`),require(`rxjs`),require(`react`),require(`react/jsx-runtime`),require(`@univerjs/design`),require(`@univerjs/docs-drawing-ui`),require(`@univerjs/docs-drawing`),require(`@univerjs/drawing`),require(`@univerjs/drawing-ui`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/engine-render`,`rxjs`,`react`,`react/jsx-runtime`,`@univerjs/design`,`@univerjs/docs-drawing-ui`,`@univerjs/docs-drawing`,`@univerjs/drawing`,`@univerjs/drawing-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsQuickInsertUi={},e.UniverCore,e.UniverDocs,e.UniverDocsUi,e.UniverUi,e.UniverEngineRender,e.rxjs,e.React,e.React,e.UniverDesign,e.UniverDocsDrawingUi,e.UniverDocsDrawing,e.UniverDrawing,e.UniverDrawingUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let m={id:`doc.command.delete-search-key`,type:t.CommandType.COMMAND,handler:(e,n)=>{let i=e.get(t.ICommandService),{start:a,end:o}=n;return i.syncExecuteCommand(r.CutContentCommand.id,{segmentId:``,textRanges:[{startOffset:a,endOffset:a,collapsed:!0}],selections:[{startOffset:a,endOffset:o,collapsed:!1,direction:t.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}let _=({popup:e})=>{var n,r,o,l,u,d,f,p,m,h,_;let v=(0,i.useDependency)(t.LocaleService).t(`docQuickInsert.keywordInputPlaceholder`),y=(0,a.ptToPixel)((n=(r=e.extraProps)==null?void 0:r.fontSize)==null?11:n),b=(o=(l=e.extraProps)==null?void 0:l.fontString)==null?`${y}px sans-serif`:o,x=(u=(d=e.extraProps)==null?void 0:d.ascent)==null?y:u,S=Math.max((f=(p=e.extraProps)==null?void 0:p.contentHeight)==null?y:f,y),C=(0,s.useMemo)(()=>g(v,b),[b,v]);return(0,c.jsx)(`div`,{className:`univer-select-none univer-font-normal univer-text-gray-500 univer-transition-colors dark:!univer-text-gray-400`,children:(0,c.jsx)(`svg`,{width:C,height:S,viewBox:`0 0 ${C} ${S}`,style:{overflow:`visible`,display:`block`},children:(0,c.jsx)(`text`,{x:0,y:x,fill:`currentColor`,style:{font:b,fontFamily:(m=e.extraProps)==null?void 0:m.fontFamily,fontStyle:(h=e.extraProps)==null?void 0:h.fontStyle,fontWeight:(_=e.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:o,onSelect:u}=e,d=(0,s.useMemo)(()=>y(t),[t]);(0,s.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,s.useRef)(0);f.current=0;function p(e){return e.map((t,r)=>{let s=t.icon,d=s?a.get(s):null;if(v(t))return(0,c.jsxs)(`div`,{className:(0,l.clsx)(`univer-grid univer-gap-1 univer-py-1`,r!==e.length-1&&l.borderBottomClassName),children:[(0,c.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,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(d,{})}),(0,c.jsx)(`span`,{children:t.title})]}),(0,c.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,c.jsx)(`div`,{ref:e=>{if(e){i.current.set(t.id,e);return}i.current.delete(t.id)},role:`button`,tabIndex:-1,className:(0,l.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:()=>o(m),onMouseLeave:()=>o(NaN),onClick:()=>u(t),children:(0,c.jsxs)(`div`,{className:`univer-inline-flex univer-w-full univer-items-center univer-gap-2`,children:[d&&(0,c.jsx)(`span`,{className:`univer-inline-flex univer-text-base`,children:(0,c.jsx)(d,{})}),(0,c.jsx)(l.Tooltip,{showIfEllipsis:!0,title:t.title,placement:`right`,children:(0,c.jsx)(`span`,{className:`univer-truncate`,children:t.title})})]})},t.id)})}return(0,c.jsx)(`div`,{className:(0,l.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`,l.borderClassName,l.scrollbarClassName),onWheel:e=>e.stopPropagation(),children:p(t)})}let S=`docs.quick.insert.placeholder`,C=()=>(0,c.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,c.jsx)(`span`,{children:(0,i.useDependency)(t.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})}let ee=[i.KeyCode.ARROW_UP,i.KeyCode.ARROW_DOWN,i.KeyCode.ENTER],E=()=>{let e=(0,i.useDependency)(t.LocaleService),n=(0,i.useDependency)(P),r=(0,i.useDependency)(i.ComponentManager),a=(0,i.useDependency)(i.IShortcutService),o=(0,i.useDependency)(t.ICommandService),l=(0,s.useMemo)(()=>(0,t.generateRandomId)(),[]),[u,d]=(0,s.useState)(0),f=(0,s.useRef)(null),p=(0,i.useObservable)(n.filterKeyword$,``),m=(0,i.useObservable)(n.editPopup$),h=(0,i.useObservable)(m==null?void 0:m.popup.menus$,[]),g=(0,s.useMemo)(()=>T(h,e),[h]),[_,v]=(0,s.useState)(()=>w(g,p.toLowerCase())),y=(0,s.useMemo)(()=>b(_),[_]),S=(0,s.useRef)(y);(0,s.useEffect)(()=>{S.current=y},[y]),(0,s.useEffect)(()=>{let e=requestIdleCallback(()=>{v(w(g,p.toLowerCase()))});return()=>{cancelIdleCallback(e)}},[g,p]);let E=e=>{n.emitMenuSelected(e),o.executeCommand(I.id)};(0,s.useEffect)(()=>{let e=new t.DisposableCollection;a.getAllShortcuts().filter(e=>e.binding&&ee.includes(e.binding)).forEach(n=>{let r=n.preconditions;n.preconditions=()=>!1,e.add((0,t.toDisposable)(()=>{n.preconditions=r}))});let n={id:`quick.insert.popup.enter.${l}`,type:t.CommandType.OPERATION,handler:()=>{let e=f.current;e&&E(e)}},r={id:`quick.insert.popup.move.cursor.up.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e-1;return t>=0?t:S.current-1})}},s={id:`quick.insert.popup.move.cursor.down.${l}`,type:t.CommandType.OPERATION,handler:()=>{d(e=>{if(S.current<=0)return 0;let t=e+1;return t<=S.current-1?t:0})}};return e.add(o.registerCommand(r)),e.add(o.registerCommand(s)),e.add(o.registerCommand(n)),e.add(a.registerShortcut({priority:1e3,id:r.id,binding:i.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:t.Direction.UP}})),e.add(a.registerShortcut({priority:1e3,id:s.id,binding:i.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:t.Direction.DOWN}})),e.add(a.registerShortcut({priority:1e3,id:n.id,binding:i.KeyCode.ENTER,preconditions:()=>!0})),()=>{e.dispose()}},[o,l,a]),(0,s.useEffect)(()=>{d(0)},[_]);let D=(0,s.useRef)(new Map);(0,s.useEffect)(()=>()=>{D.current.clear()},[]);let O=_.length>0,k=(m==null?void 0:m.popup.Placeholder)||r.get(C.componentKey);return(0,c.jsx)(`div`,{className:`univer-mt-2`,children:O?(0,c.jsx)(x,{menus:_,focusedMenuIndex:u,focusedMenuRef:f,menuNodeMapRef:D,componentManager:r,onFocusedMenuIndexChange:d,onSelect:E}):k&&(0,c.jsx)(k,{})})};E.componentKey=`docs.quick.insert.popup`;function D(e){"@babel/helpers - typeof";return D=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},D(e)}function O(e,t){if(D(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(D(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function k(e){var t=O(e,`string`);return D(t)==`symbol`?t:t+``}function A(e,t,n){return(t=k(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e,t){return function(n,r){t(n,r,e)}}function M(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}let N={dispose:()=>{}},P=class extends t.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(r.DocEventManagerService)}constructor(e,n,r,i,a){super(),this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=r,this._renderManagerService=i,this._docSelectionManagerService=a,A(this,`_popups`,new Set),A(this,`_editPopup$`,new o.BehaviorSubject(void 0)),A(this,`editPopup$`,this._editPopup$.asObservable()),A(this,`_isComposing$`,new o.BehaviorSubject(!1)),A(this,`isComposing$`,this._isComposing$.asObservable()),A(this,`_inputOffset$`,new o.BehaviorSubject({start:0,end:0})),A(this,`inputOffset$`,this._inputOffset$.asObservable()),A(this,`filterKeyword$`,void 0),A(this,`_menuSelectedCallbacks`,new Set),A(this,`_inputPlaceholderRenderRoot`,null),this.disposeWithMe(this._editPopup$);let s=(e,n)=>{var r;return(r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC))==null||(r=r.getBody())==null?void 0:r.dataStream.slice(e,n)},c=``;this.filterKeyword$=this._inputOffset$.pipe((0,o.map)(e=>{var t;let n=s(e.start,e.end);return(t=n==null?void 0:n.slice(1))==null?``:t}),(0,o.distinctUntilChanged)(),(0,o.tap)(e=>{c=e})),this.disposeWithMe((0,o.combineLatest)([this.filterKeyword$.pipe((0,o.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,o.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,o.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,n,i){let a=t.findNodePositionByCharIndex(n.startOffset,!0,n.segmentId,n.segmentPage);if(!a)return i;let o=e.getOffsetConfig(),{contentBoxPointGroup:s}=new r.NodePositionConvertToCursor(o,t).getRangePointData(a,a);if(s.length===0)return i;let c=(0,r.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,t){let r=this._renderManagerService.getRenderById(e),i=r==null?void 0:r.with(n.DocSkeletonManagerService),a=this._docSelectionManagerService.getActiveTextRange();if(!r||!i||!a)return N;let o=i.getSkeleton(),s=o.findNodeByCharIndex(a.startOffset,a.segmentId,a.segmentPage);if((s==null?void 0:s.content)!==`\r`||!s)return N;let c=r.mainComponent,l=this._getKeywordPlaceholderAnchorRect(c,o,a,t),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:E.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)}};P=M([j(0,(0,t.Inject)(r.DocCanvasPopManagerService)),j(1,(0,t.Inject)(t.IUniverInstanceService)),j(2,(0,t.Inject)(t.ICommandService)),j(3,(0,t.Inject)(a.IRenderManagerService)),j(4,(0,t.Inject)(n.DocSelectionManagerService))],P);let F={type:t.CommandType.OPERATION,id:`doc.operation.show-quick-insert-popup`,handler(e,t){let n=e.get(P);return t?(n.showPopup(t),!0):!1}},I={type:t.CommandType.OPERATION,id:`doc.operation.close-quick-insert-popup`,handler(e){return e.get(P).closePopup(),!0}},te=function(e){return e.Basic=`quick.insert.group.basic`,e.Media=`quick.insert.group.media`,e}({}),L={id:`quick-insert.text.menu`,title:`docQuickInsert.menu.text`,icon:`TextIcon`,keywords:[`text`]},ne={id:r.OrderListCommand.id,title:`docQuickInsert.menu.numberedList`,icon:`OrderIcon`,keywords:[`numbered`,`list`,`ordered`]},R={id:r.BulletListCommand.id,title:`docQuickInsert.menu.bulletedList`,icon:`UnorderIcon`,keywords:[`bulleted`,`list`,`unordered`]},z={id:r.HorizontalLineCommand.id,title:`docQuickInsert.menu.divider`,icon:`DividerIcon`,keywords:[`divider`,`line`,`separate`]},B={id:r.DocCreateTableOperation.id,title:`docQuickInsert.menu.table`,icon:`GridIcon`,keywords:[`table`,`grid`,`spreadsheet`]},V={id:u.InsertDocImageCommand.id,title:`docQuickInsert.menu.image`,icon:`AdditionAndSubtractionIcon`,keywords:[`image`,`picture`,`photo`]},re=[{title:`docQuickInsert.group.basics`,id:te.Basic,children:[L,ne,R,z,B,V]}],ie=new Set([ne.id,R.id,z.id,B.id,V.id]),H=class extends t.Disposable{constructor(e,t,n,r,a){super(),this._commandService=e,this._textSelectionManagerService=t,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=a,this.disposeWithMe(this._shortcutService.registerShortcut({id:I.id,binding:i.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{let{_docQuickInsertPopupService:i,_textSelectionManagerService:a,_commandService:o}=this,s=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(!(s!=null&&s.getDisabled())){if(e.id===r.InsertCommand.id){let t=e.params;if(i.editPopup){i.setInputOffset({start:i.inputOffset.start,end:t.range.endOffset+1});return}let n=a.getActiveTextRange();if(!n)return;let r=i.resolvePopup(t.body.dataStream);if(!r||!(!r.preconditions||r.preconditions(t)))return;i.setInputOffset({start:n.startOffset-1,end:n.startOffset}),setTimeout(()=>{o.executeCommand(F.id,{index:n.startOffset-1,unitId:t.unitId,popup:r})},100)}if(e.id===r.IMEInputCommand.id){let t=e.params;!i.isComposing&&t.isCompositionStart&&i.setIsComposing(!0),i.isComposing&&t.isCompositionEnd&&i.setIsComposing(!1)}if(e.id===n.RichTextEditingMutation.id){let t=e.params;if(t.isCompositionEnd){var c;let e=(c=t.textRanges)==null||(c=c[0])==null?void 0:c.endOffset;e&&i.setInputOffset({start:i.inputOffset.start,end:e})}}if(e.id===r.DeleteCommand.id){let n=e.params;if(i.editPopup&&n.direction===t.DeleteDirection.LEFT){var l;let e=(l=n.len)==null?0:l;i.setInputOffset({start:i.inputOffset.start,end:n.range.endOffset-e})}}if(e.id===r.MoveCursorOperation.id){let n=e.params;(n.direction===t.Direction.LEFT||n.direction===t.Direction.RIGHT)&&i.editPopup&&o.executeCommand(I.id)}if(e.id===r.DeleteLeftCommand.id){let e=a.getActiveTextRange();if(!i.editPopup||!e)return;e.endOffset<=i.editPopup.anchor&&o.executeCommand(I.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(e=>{e.id!==L.id&&ie.has(e.id)&&this._commandService.executeCommand(e.id)}))}};H=M([j(0,t.ICommandService),j(1,(0,t.Inject)(n.DocSelectionManagerService)),j(2,(0,t.Inject)(P)),j(3,(0,t.Inject)(i.IShortcutService)),j(4,(0,t.Inject)(t.IUniverInstanceService))],H);function U({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,s.useRef)(`_${se()}`);return W(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...o},a)}function W(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...ae(e,n,i),...r},(oe(e,n).children||[]).map((r,a)=>W(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function ae(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function oe(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function se(){return Math.random().toString(36).substring(2,8)}U.displayName=`UniverIcon`;let ce={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=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`divider-icon`,ref:t,icon:ce}))});G.displayName=`DividerIcon`;let le={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`}}]},K=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`increase-icon`,ref:t,icon:le}))});K.displayName=`IncreaseIcon`;let ue={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`]},q=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(U,Object.assign({},e,{id:`text-icon`,ref:t,icon:ue}))});q.displayName=`TextIcon`;let J=class extends t.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,A(this,`_popup$`,new o.BehaviorSubject(null)),A(this,`popup$`,this._popup$.asObservable()),this._init()}_init(){this.disposeWithMe((0,o.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:Y,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))}};J=M([j(1,(0,t.Inject)(r.DocEventManagerService)),j(2,(0,t.Inject)(P)),j(3,(0,t.Inject)(r.DocCanvasPopManagerService))],J);let Y=`doc.quick-insert.button`,X=({className:e=``})=>{let r=(0,i.useDependency)(P),u=(0,i.useDependency)(t.IUniverInstanceService),d=(0,i.useDependency)(a.IRenderManagerService),f=(0,i.useObservable)((0,s.useMemo)(()=>u.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_DOC),[u])),p=f&&d.getRenderById(f.getUnitId()),m=p==null?void 0:p.with(J),h=(0,i.useDependency)(i.ILayoutService),g=(0,i.useDependency)(n.DocSelectionManagerService),_=(0,i.useObservable)(r.editPopup$),v=(0,i.useEvent)(()=>{var e;let t=m==null?void 0:m.popup;if(!t)return;let n=r.popups,i={keyword:``,menus$:(0,o.combineLatest)(n.map(e=>e.menus$)).pipe((0,o.map)(e=>e.flat()))};g.replaceDocRanges([{startOffset:t.startIndex,endOffset:t.startIndex}]),r.setInputOffset({start:t.startIndex-1,end:t.startIndex-1}),r.showPopup({popup:i,index:t.startIndex-1,unitId:(e=f==null?void 0:f.getUnitId())==null?``:e}),setTimeout(()=>{h.focus()})});return(0,c.jsx)(`div`,{className:(0,l.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`,l.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-700":_,"univer-bg-white dark:!univer-bg-gray-900":!_},e),role:`button`,tabIndex:0,onClick:v,children:(0,c.jsx)(K,{className:`univer-text-gray-800 dark:!univer-text-gray-200`})})};X.componentKey=Y;let Z=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._docQuickInsertPopupService=t,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[m,F,I].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initComponents(){[[E.componentKey,E],[_.componentKey,_],[C.componentKey,C],[G.displayName,G],[q.displayName,q],[X.componentKey,X]].forEach(([e,t])=>{e&&this.disposeWithMe(this._componentManager.register(e,t))}),[{keyword:`/`,menus$:(0,o.of)(re),preconditions:e=>{var t;return((t=e.range.startNodePosition)==null?void 0:t.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};Z=M([j(0,t.ICommandService),j(1,(0,t.Inject)(P)),j(2,(0,t.Inject)(i.ComponentManager))],Z);var de=`@univerjs/docs-quick-insert-ui`,fe=`0.19.0-insiders.20260403-3e0e122`;let Q=`docs-quick-insert-ui.config`;Symbol(Q);let pe={},$=class extends t.Plugin{constructor(e=pe,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerSrv=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},pe,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(Q,o)}onStarting(){[[Z],[H],[P]].forEach(e=>this._injector.add(e)),this._injector.get(Z)}onRendered(){this._injector.get(H),this._injector.get(P),[[J]].forEach(e=>{this._renderManagerSrv.registerRenderModule(t.UniverInstanceType.UNIVER_DOC,e)})}};A($,`type`,t.UniverInstanceType.UNIVER_DOC),A($,`pluginName`,`DOC_QUICK_INSERT_UI_PLUGIN`),A($,`packageName`,de),A($,`version`,fe),$=M([(0,t.DependentOn)(p.UniverDrawingUIPlugin,f.UniverDrawingPlugin,u.UniverDocsDrawingUIPlugin,d.UniverDocsDrawingPlugin,i.UniverUIPlugin),j(1,(0,t.Inject)(t.Injector)),j(2,(0,t.Inject)(a.IRenderManagerService)),j(3,t.IConfigService)],$),Object.defineProperty(e,`DocQuickInsertPopupService`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(e,`DocQuickInsertTriggerController`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(e,`DocQuickInsertUIController`,{enumerable:!0,get:function(){return Z}}),e.KeywordInputPlaceholderComponentKey=h,e.QuickInsertPlaceholderComponentKey=S,Object.defineProperty(e,`UniverDocsQuickInsertUIPlugin`,{enumerable:!0,get:function(){return $}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-quick-insert-ui",
3
- "version": "0.18.0",
3
+ "version": "0.19.0-insiders.20260403-3e0e122",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,25 +53,25 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@univerjs/icons": "^1.1.1",
56
- "@univerjs/core": "0.18.0",
57
- "@univerjs/docs": "0.18.0",
58
- "@univerjs/docs-drawing": "0.18.0",
59
- "@univerjs/design": "0.18.0",
60
- "@univerjs/docs-drawing-ui": "0.18.0",
61
- "@univerjs/docs-ui": "0.18.0",
62
- "@univerjs/engine-render": "0.18.0",
63
- "@univerjs/ui": "0.18.0",
64
- "@univerjs/drawing": "0.18.0",
65
- "@univerjs/drawing-ui": "0.18.0"
56
+ "@univerjs/core": "0.19.0-insiders.20260403-3e0e122",
57
+ "@univerjs/docs": "0.19.0-insiders.20260403-3e0e122",
58
+ "@univerjs/docs-drawing": "0.19.0-insiders.20260403-3e0e122",
59
+ "@univerjs/docs-ui": "0.19.0-insiders.20260403-3e0e122",
60
+ "@univerjs/design": "0.19.0-insiders.20260403-3e0e122",
61
+ "@univerjs/docs-drawing-ui": "0.19.0-insiders.20260403-3e0e122",
62
+ "@univerjs/drawing-ui": "0.19.0-insiders.20260403-3e0e122",
63
+ "@univerjs/drawing": "0.19.0-insiders.20260403-3e0e122",
64
+ "@univerjs/engine-render": "0.19.0-insiders.20260403-3e0e122",
65
+ "@univerjs/ui": "0.19.0-insiders.20260403-3e0e122"
66
66
  },
67
67
  "devDependencies": {
68
68
  "postcss": "^8.5.8",
69
69
  "react": "18.3.1",
70
70
  "rxjs": "^7.8.2",
71
71
  "tailwindcss": "3.4.18",
72
- "typescript": "^5.9.3",
73
- "vitest": "^4.1.0",
74
- "@univerjs-infra/shared": "0.18.0"
72
+ "typescript": "^6.0.2",
73
+ "vitest": "^4.1.1",
74
+ "@univerjs-infra/shared": "0.19.0"
75
75
  },
76
76
  "scripts": {
77
77
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
@@ -1,23 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Co., Ltd.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- interface IQuickInsertButtonProps {
17
- className?: string;
18
- }
19
- export declare const QuickInsertButton: {
20
- ({ className }: IQuickInsertButtonProps): import("react/jsx-runtime").JSX.Element;
21
- componentKey: string;
22
- };
23
- export {};