@univerjs/docs-quick-insert-ui 0.6.7 → 0.6.9
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 +5 -5
- package/lib/es/index.js +397 -344
- package/lib/index.css +1 -1
- package/lib/index.js +646 -0
- package/lib/locale/en-US.js +18 -0
- package/lib/locale/fa-IR.js +18 -0
- package/lib/locale/fr-FR.js +18 -0
- package/lib/locale/ru-RU.js +18 -0
- package/lib/locale/vi-VN.js +18 -0
- package/lib/locale/zh-CN.js +18 -0
- package/lib/locale/zh-TW.js +18 -0
- package/lib/types/controllers/doc-quick-insert-trigger.controller.d.ts +3 -2
- package/lib/types/services/doc-quick-insert-popup.service.d.ts +9 -1
- package/lib/umd/index.js +5 -5
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ce=Object.defineProperty;var ae=(i,t,e)=>t in i?ce(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var S=(i,t,e)=>ae(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),ue=require("@univerjs/docs-drawing"),de=require("@univerjs/drawing"),le=require("@univerjs/drawing-ui"),l=require("@univerjs/ui"),N=require("@univerjs/docs"),P=require("@univerjs/docs-ui"),pe=require("@univerjs/engine-render"),y=require("rxjs"),f=require("react/jsx-runtime"),D=require("@univerjs/design"),v=require("react"),F={id:"doc.command.delete-search-key",type:s.CommandType.COMMAND,handler:(i,t)=>{const e=i.get(s.ICommandService),{start:n,end:r}=t;return e.syncExecuteCommand(P.CutContentCommand.id,{segmentId:"",textRanges:[{startOffset:n,endOffset:n,collapsed:!0}],selections:[{startOffset:n,endOffset:r,collapsed:!1,direction:s.RANGE_DIRECTION.FORWARD}]})}},G="docs.quick.insert.keyword-input-placeholder",Q=()=>{const i=l.useDependency(s.LocaleService);return f.jsx("div",{className:"univer-translate-y-1.5 univer-text-sm univer-text-gray-500",children:i.t("docQuickInsert.keywordInputPlaceholder")})};Q.componentKey=G;const Z="docs.quick.insert.placeholder",U=()=>{const i=l.useDependency(s.LocaleService);return f.jsx("div",{className:`
|
|
2
2
|
univer-flex univer-h-full univer-items-center univer-justify-center univer-rounded-lg univer-bg-white
|
|
3
3
|
univer-px-12 univer-py-6 univer-text-gray-400
|
|
4
|
-
`,children:
|
|
4
|
+
`,children:f.jsx("span",{children:i.t("docQuickInsert.placeholder")})})};U.componentKey=Z;function H(i,t){return i.map(e=>({...e})).filter(e=>{if("children"in e)return e.children=H(e.children,t),e.children.length>0;const n=e.keywords;return n?n.some(r=>r.includes(t)):e.title.toLowerCase().includes(t)})}function J(i,t){return i.map(e=>{const n={...e};return"children"in n&&(n.children=J(n.children,t)),n.title=t.t(n.title),"keywords"in n&&(n.keywords=n.keywords.concat(n.title).map(r=>r.toLowerCase())),n})}const fe=[l.KeyCode.ARROW_UP,l.KeyCode.ARROW_DOWN,l.KeyCode.ENTER],E=()=>{const i=l.useDependency(s.LocaleService),t=l.useDependency(exports.DocQuickInsertPopupService),e=l.useDependency(l.ComponentManager),n=l.useDependency(l.IShortcutService),r=l.useDependency(s.ICommandService),o=v.useMemo(()=>s.generateRandomId(),[]),[u,p]=v.useState(0),h=v.useRef(null),c=v.useRef(0);c.current=0;const a=l.useObservable(t.filterKeyword$,""),d=l.useObservable(t.editPopup$),m=l.useObservable(d==null?void 0:d.popup.menus$,[]),b=v.useMemo(()=>J(m,i),[m]),[T,se]=v.useState(()=>H(b,a.toLowerCase()));v.useEffect(()=>{const g=requestIdleCallback(()=>{se(H(b,a.toLowerCase()))});return()=>{cancelIdleCallback(g)}},[b,a]);const W=g=>{t.emitMenuSelected(g),r.executeCommand(j.id)};v.useEffect(()=>{const g=new s.DisposableCollection;n.getAllShortcuts().filter(I=>I.binding&&fe.includes(I.binding)).forEach(I=>{const x=I.preconditions;I.preconditions=()=>!1,g.add(s.toDisposable(()=>{I.preconditions=x}))});const O={id:`quick.insert.popup.enter.${o}`,type:s.CommandType.OPERATION,handler:()=>{const I=h.current;I&&W(I)}},M={id:`quick.insert.popup.move.cursor.up.${o}`,type:s.CommandType.OPERATION,handler:()=>{p(I=>{const x=I-1;return x>=0?x:c.current-1})}},k={id:`quick.insert.popup.move.cursor.down.${o}`,type:s.CommandType.OPERATION,handler:()=>{p(I=>{const x=I+1;return x<=c.current-1?x:0})}};return g.add(r.registerCommand(M)),g.add(r.registerCommand(k)),g.add(r.registerCommand(O)),g.add(n.registerShortcut({priority:1e3,id:M.id,binding:l.KeyCode.ARROW_UP,preconditions:()=>!0,staticParameters:{direction:s.Direction.UP}})),g.add(n.registerShortcut({priority:1e3,id:k.id,binding:l.KeyCode.ARROW_DOWN,preconditions:()=>!0,staticParameters:{direction:s.Direction.DOWN}})),g.add(n.registerShortcut({priority:1e3,id:O.id,binding:l.KeyCode.ENTER,preconditions:()=>!0})),()=>{g.dispose()}},[]),v.useEffect(()=>{p(0)},[T]);function B(g){return g.map(_=>{const $=_.icon,O=$?e.get($):null;if("children"in _)return f.jsx(D.MenuItemGroup,{title:f.jsxs("div",{className:`
|
|
5
5
|
univer-mb-2 univer-flex univer-items-center univer-text-xs univer-text-gray-400
|
|
6
|
-
`,children:[
|
|
7
|
-
univer-rounded-lg univer-border univer-border-solid univer-border-gray-100
|
|
6
|
+
`,children:[O&&f.jsx("span",{className:"univer-mr-2 univer-inline-flex univer-text-base",children:f.jsx(O,{})}),f.jsx("span",{children:_.title})]}),children:B(_.children)},_.id);const M=c.current,k=u===M;return k&&(h.current=_),c.current++,f.jsx(D.MenuItem,{onMouseEnter:()=>p(M),onMouseLeave:()=>p(Number.NaN),className:D.clsx("univer-w-[calc(220px-var(--padding-base)*2)] univer-text-sm",{"hover:univer-bg-transparent":!k,"univer-bg-gray-100":k}),onClick:()=>{W(_)},children:f.jsxs("div",{className:"univer-flex univer-w-full univer-items-center univer-px-1",children:[O&&f.jsx("span",{className:"univer-mr-2 univer-inline-flex univer-text-base",children:f.jsx(O,{})}),f.jsx(D.Tooltip,{showIfEllipsis:!0,title:_.title,placement:"right",children:f.jsx("span",{className:"univer-truncate",children:_.title})})]})},_.id)})}const oe=T.length>0,z=(d==null?void 0:d.popup.Placeholder)||e.get(U.componentKey);return f.jsx("div",{className:D.clsx(`
|
|
7
|
+
univer-rounded-lg univer-border univer-border-solid univer-border-gray-100 univer-bg-white
|
|
8
8
|
univer-shadow-[0_0_10px_0_rgba(0,0,0,0.1)]
|
|
9
|
-
`),children:oe?p.jsx("div",{className:"univer-max-h-[360px] univer-w-[220px] univer-overflow-y-auto",children:p.jsx(k.Menu,{children:W(U)})}):z&&p.jsx(z,{})})};j.componentKey="docs.quick.insert.popup";var pe=Object.getOwnPropertyDescriptor,fe=(r,t,e,n)=>{for(var i=n>1?void 0:n?pe(t,e):t,s=r.length-1,c;s>=0;s--)(c=r[s])&&(i=c(i)||i);return i},E=(r,t)=>(e,n)=>t(e,n,r);exports.DocQuickInsertPopupService=class extends o.Disposable{constructor(e,n,i){super();I(this,"_popups",new Set);I(this,"_editPopup$",new y.BehaviorSubject(void 0));I(this,"editPopup$",this._editPopup$.asObservable());I(this,"_inputOffset$",new y.BehaviorSubject({start:0,end:0}));I(this,"inputOffset$",this._inputOffset$.asObservable());I(this,"filterKeyword$");I(this,"_menuSelectedCallbacks",new Set);I(this,"_inputPlaceholderRenderRoot",null);this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=i,this.disposeWithMe(this._editPopup$);const s=(c,d)=>{var u,l;return(l=(u=this._univerInstanceService.getCurrentUnitOfType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:u.getBody())==null?void 0:l.dataStream.slice(c,d)};this.filterKeyword$=this._inputOffset$.pipe(y.map(c=>{var u;const d=s(c.start,c.end);return(u=d==null?void 0:d.slice(1))!=null?u:""}),y.distinctUntilChanged()),this.disposeWithMe(y.combineLatest([this.filterKeyword$.pipe(y.tap(c=>{var d,u,l;c.length>0?(u=(d=this._inputPlaceholderRenderRoot)==null?void 0:d.unmount)==null||u.dispose():(l=this._inputPlaceholderRenderRoot)==null||l.mount()})),this.editPopup$.pipe(y.tap(c=>{var d,u;c||(u=(d=this._inputPlaceholderRenderRoot)==null?void 0:d.unmount)==null||u.dispose()}))]).subscribe())}get editPopup(){return this._editPopup$.value}get inputOffset(){return this._inputOffset$.value}setInputOffset(e){this._inputOffset$.next(e)}resolvePopup(e){return Array.from(this._popups).find(n=>n.keyword===e)}registerPopup(e){return this._popups.add(e),()=>{this._popups.delete(e)}}_createInputPlaceholderRenderRoot(e){return{mount(){this.unmount=e()}}}showPopup(e){const{popup:n,index:i,unitId:s}=e;this.closePopup();const c=this._docCanvasPopupManagerService.attachPopupToRange({startOffset:i,endOffset:i,collapsed:!0},{componentKey:j.componentKey,onClickOutside:()=>{this.closePopup()},direction:"bottom"},s);this._inputPlaceholderRenderRoot=this._createInputPlaceholderRenderRoot(()=>{const d=this._docCanvasPopupManagerService.attachPopupToRange({startOffset:i+1,endOffset:i+1,collapsed:!1},{componentKey:w.componentKey,onClickOutside:()=>{d.dispose()},direction:"horizontal"},s);return d}),this._inputPlaceholderRenderRoot.mount(),this._editPopup$.next({disposable:c,popup:n,anchor:i,unitId:s})}closePopup(){this.editPopup&&(this.editPopup.disposable.dispose(),this._editPopup$.next(null))}onMenuSelected(e){return this._menuSelectedCallbacks.add(e),()=>{this._menuSelectedCallbacks.delete(e)}}emitMenuSelected(e){const{start:n,end:i}=this.inputOffset;this._commandService.syncExecuteCommand(V.id,{start:n,end:i}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(s=>s(e))},0)}};exports.DocQuickInsertPopupService=fe([E(0,o.Inject(C.DocCanvasPopManagerService)),E(1,o.Inject(o.IUniverInstanceService)),E(2,o.Inject(o.ICommandService))],exports.DocQuickInsertPopupService);const J={type:o.CommandType.OPERATION,id:"doc.operation.show-quick-insert-popup",handler(r,t){const e=r.get(exports.DocQuickInsertPopupService);return t?(e.showPopup(t),!0):!1}},D={type:o.CommandType.OPERATION,id:"doc.operation.close-quick-insert-popup",handler(r){return r.get(exports.DocQuickInsertPopupService).closePopup(),!0}},X={id:"quick-insert.text.menu",title:"docQuickInsert.menu.text",icon:"TextSingle",keywords:["text"]},Y={id:C.OrderListCommand.id,title:"docQuickInsert.menu.numberedList",icon:"OrderSingle",keywords:["numbered","list","ordered"]},ee={id:C.BulletListCommand.id,title:"docQuickInsert.menu.bulletedList",icon:"UnorderSingle",keywords:["bulleted","list","unordered"]},te={id:C.HorizontalLineCommand.id,title:"docQuickInsert.menu.divider",icon:"DividerSingle",keywords:["divider","line","separate"]},ve=[{title:"docQuickInsert.group.basics",id:"quick.insert.group.basic",children:[X,Y,ee,te]}],he=new Set([Y.id,ee.id,te.id]);var me=Object.getOwnPropertyDescriptor,ge=(r,t,e,n)=>{for(var i=n>1?void 0:n?me(t,e):t,s=r.length-1,c;s>=0;s--)(c=r[s])&&(i=c(i)||i);return i},M=(r,t)=>(e,n)=>t(e,n,r);exports.DocQuickInsertTriggerController=class extends o.Disposable{constructor(t,e,n,i){super(),this._commandService=t,this._textSelectionManagerService=e,this._docQuickInsertPopupService=n,this._shortcutService=i,this.disposeWithMe(this._shortcutService.registerShortcut({id:D.id,binding:a.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var s,c,d;const{_docQuickInsertPopupService:e,_textSelectionManagerService:n,_commandService:i}=this;if(t.id===C.InsertCommand.id){const u=t.params;if(e.editPopup){e.setInputOffset({start:e.inputOffset.start,end:u.range.endOffset+1});return}const l=n.getActiveTextRange();if(!l)return;const _=e.resolvePopup(u.body.dataStream);if(!_||!(_.preconditions?_.preconditions(u):!0))return;e.setInputOffset({start:l.startOffset-1,end:l.startOffset}),setTimeout(()=>{i.executeCommand(J.id,{index:l.startOffset-1,unitId:u.unitId,popup:_})},100)}if(t.id===B.RichTextEditingMutation.id){const u=t.params;if(u.isCompositionEnd){const l=(c=(s=u.textRanges)==null?void 0:s[0])==null?void 0:c.endOffset;l&&e.setInputOffset({start:e.inputOffset.start,end:l})}}if(t.id===C.DeleteCommand.id){const u=t.params;if(e.editPopup&&u.direction===o.DeleteDirection.LEFT){const l=(d=u.len)!=null?d:0;e.setInputOffset({start:e.inputOffset.start,end:u.range.endOffset-l})}}if(t.id===C.MoveCursorOperation.id){const u=t.params;(u.direction===o.Direction.LEFT||u.direction===o.Direction.RIGHT)&&e.editPopup&&i.executeCommand(D.id)}if(t.id===C.DeleteLeftCommand.id){const u=n.getActiveTextRange();if(!e.editPopup||!u)return;u.endOffset<=e.editPopup.anchor&&i.executeCommand(D.id)}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(t=>{t.id!==X.id&&he.has(t.id)&&this._commandService.executeCommand(t.id)}))}};exports.DocQuickInsertTriggerController=ge([M(0,o.ICommandService),M(1,o.Inject(B.DocSelectionManagerService)),M(2,o.Inject(exports.DocQuickInsertPopupService)),M(3,o.Inject(a.IShortcutService))],exports.DocQuickInsertTriggerController);var m=function(){return m=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=t[i])}return r},m.apply(this,arguments)},Ie=function(r,t){var e={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&t.indexOf(n)<0&&(e[n]=r[n]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(r);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(r,n[i])&&(e[n[i]]=r[n[i]]);return e},q=f.forwardRef(function(r,t){var e=r.icon,n=r.id,i=r.className,s=r.extend,c=Ie(r,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),u=f.useRef("_".concat(ye()));return ne(e,"".concat(n),{defIds:e.defIds,idSuffix:u.current},m({ref:t,className:d},c),s)});function ne(r,t,e,n,i){return f.createElement(r.tag,m(m({key:t},Ce(r,e,i)),n),(_e(r,e).children||[]).map(function(s,c){return ne(s,"".concat(t,"-").concat(r.tag,"-").concat(c),e,void 0,i)}))}function Ce(r,t,e){var n=m({},r.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),r.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(s){var c=s[0],d=s[1];c==="mask"&&typeof d=="string"&&(n[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var c=s[0],d=s[1];typeof d=="string"&&(n[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function _e(r,t){var e,n=t.defIds;return!n||n.length===0?r:r.tag==="defs"&&(!((e=r.children)===null||e===void 0)&&e.length)?m(m({},r),{children:r.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?m(m({},i),{attrs:m(m({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):r}function ye(){return Math.random().toString(36).substring(2,8)}q.displayName="UniverIcon";var Se={tag:"svg",attrs:{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.13985 3.40213 3.50712 3.1044 3.80485 2.73713 3.80485H1.68453C1.31726 3.80485 1.01953 3.50712 1.01953 3.13985zM4.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.13985 7.61254 3.50712 7.31481 3.80485 6.94754 3.80485H4.84234C4.47507 3.80485 4.17734 3.50712 4.17734 3.13985zM8.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.13985 11.823 3.50712 11.5252 3.80485 11.158 3.80485H9.05275C8.68548 3.80485 8.38775 3.50712 8.38775 3.13985zM12.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.13985 14.9808 3.50712 14.683 3.80485 14.3158 3.80485H13.2632C12.8959 3.80485 12.5982 3.50712 12.5982 3.13985zM1.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.99972 14.9808 8.36699 14.683 8.66472 14.3158 8.66472H1.68453C1.31726 8.66472 1.01953 8.36699 1.01953 7.99972zM1.68453 12.1951C1.31726 12.1951 1.01953 12.4928 1.01953 12.8601 1.01953 13.2273 1.31726 13.5251 1.68453 13.5251H2.73713C3.1044 13.5251 3.40213 13.2273 3.40213 12.8601 3.40213 12.4928 3.1044 12.1951 2.73713 12.1951H1.68453zM4.84234 12.1951C4.47507 12.1951 4.17734 12.4928 4.17734 12.8601 4.17734 13.2273 4.47507 13.5251 4.84234 13.5251H6.94754C7.31481 13.5251 7.61254 13.2273 7.61254 12.8601 7.61254 12.4928 7.31481 12.1951 6.94754 12.1951H4.84234zM9.05275 12.1951C8.68548 12.1951 8.38775 12.4928 8.38775 12.8601 8.38775 13.2273 8.68548 13.5251 9.05275 13.5251H11.158C11.5252 13.5251 11.823 13.2273 11.823 12.8601 11.823 12.4928 11.5252 12.1951 11.158 12.1951H9.05275zM13.2632 12.1951C12.8959 12.1951 12.5982 12.4928 12.5982 12.8601 12.5982 13.2273 12.8959 13.5251 13.2632 13.5251H14.3158C14.683 13.5251 14.9808 13.2273 14.9808 12.8601 14.9808 12.4928 14.683 12.1951 14.3158 12.1951H13.2632z"}}]},K=f.forwardRef(function(r,t){return f.createElement(q,Object.assign({},r,{id:"divider-single",ref:t,icon:Se}))});K.displayName="DividerSingle";var Pe={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.66695 1.33496C2.29968 1.33496 2.00195 1.63269 2.00195 1.99996V3.64439C2.00195 4.01166 2.29968 4.30939 2.66695 4.30939C3.03422 4.30939 3.33195 4.01166 3.33195 3.64439V2.66496H7.33521V13.335H5.3337C4.96643 13.335 4.6687 13.6327 4.6687 14C4.6687 14.3672 4.96643 14.665 5.3337 14.665H10.667C11.0343 14.665 11.332 14.3672 11.332 14C11.332 13.6327 11.0343 13.335 10.667 13.335H8.66521V2.66496H12.6686V3.64439C12.6686 4.01166 12.9664 4.30939 13.3336 4.30939C13.7009 4.30939 13.9986 4.01166 13.9986 3.64439V1.99996C13.9986 1.63269 13.7009 1.33496 13.3336 1.33496H2.66695Z"}}]},H=f.forwardRef(function(r,t){return f.createElement(q,Object.assign({},r,{id:"text-single",ref:t,icon:Pe}))});H.displayName="TextSingle";var Oe=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,s=r.length-1,c;s>=0;s--)(c=r[s])&&(i=c(i)||i);return i},T=(r,t)=>(e,n)=>t(e,n,r);exports.DocQuickInsertUIController=class extends o.Disposable{constructor(t,e,n){super(),this._commandService=t,this._docQuickInsertPopupService=e,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[V,J,D].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initComponents(){[[j.componentKey,j],[w.componentKey,w],[R.componentKey,R],[K.displayName,K],[H.displayName,H]].forEach(([e,n])=>{e&&this.disposeWithMe(this._componentManager.register(e,n))}),[{keyword:"/",menus$:y.of(ve),preconditions:e=>{var n;return((n=e.range.startNodePosition)==null?void 0:n.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};exports.DocQuickInsertUIController=xe([T(0,o.ICommandService),T(1,o.Inject(exports.DocQuickInsertPopupService)),T(2,o.Inject(a.ComponentManager))],exports.DocQuickInsertUIController);var be=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,De=(r,t,e)=>t in r?be(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Me=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,c;s>=0;s--)(c=r[s])&&(i=c(i)||i);return i},we=(r,t)=>(e,n)=>t(e,n,r),re=(r,t,e)=>De(r,typeof t!="symbol"?t+"":t,e);const Re="DOC_QUICK_INSERT_UI_PLUGIN";exports.UniverDocsQuickInsertUIPlugin=class extends o.Plugin{constructor(t){super(),this._injector=t}onStarting(){[[exports.DocQuickInsertUIController],[exports.DocQuickInsertTriggerController],[exports.DocQuickInsertPopupService]].forEach(e=>this._injector.add(e)),this._injector.get(exports.DocQuickInsertUIController)}onRendered(){this._injector.get(exports.DocQuickInsertTriggerController),this._injector.get(exports.DocQuickInsertPopupService)}};re(exports.UniverDocsQuickInsertUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC);re(exports.UniverDocsQuickInsertUIPlugin,"pluginName",Re);exports.UniverDocsQuickInsertUIPlugin=Me([o.DependentOn(ae.UniverDrawingUIPlugin,de.UniverDrawingPlugin,ue.UniverDocsDrawingPlugin,a.UniverUIPlugin),we(0,o.Inject(o.Injector))],exports.UniverDocsQuickInsertUIPlugin);exports.KeywordInputPlaceholderComponentKey=F;exports.QuickInsertPlaceholderComponentKey=G;
|
|
9
|
+
`),children:oe?f.jsx("div",{className:"univer-max-h-[360px] univer-w-[220px] univer-overflow-y-auto",children:f.jsx(D.Menu,{children:B(T)})}):z&&f.jsx(z,{})})};E.componentKey="docs.quick.insert.popup";var ve=Object.getOwnPropertyDescriptor,he=(i,t,e,n)=>{for(var r=n>1?void 0:n?ve(t,e):t,o=i.length-1,u;o>=0;o--)(u=i[o])&&(r=u(r)||r);return r},w=(i,t)=>(e,n)=>t(e,n,i);const V={dispose:()=>{}};exports.DocQuickInsertPopupService=class extends s.Disposable{constructor(e,n,r,o,u){super();S(this,"_popups",new Set);S(this,"_editPopup$",new y.BehaviorSubject(void 0));S(this,"editPopup$",this._editPopup$.asObservable());S(this,"_isComposing$",new y.BehaviorSubject(!1));S(this,"isComposing$",this._isComposing$.asObservable());S(this,"_inputOffset$",new y.BehaviorSubject({start:0,end:0}));S(this,"inputOffset$",this._inputOffset$.asObservable());S(this,"filterKeyword$");S(this,"_menuSelectedCallbacks",new Set);S(this,"_inputPlaceholderRenderRoot",null);this._docCanvasPopupManagerService=e,this._univerInstanceService=n,this._commandService=r,this._renderManagerService=o,this._docSelectionManagerService=u,this.disposeWithMe(this._editPopup$);const p=(c,a)=>{var d,m;return(m=(d=this._univerInstanceService.getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC))==null?void 0:d.getBody())==null?void 0:m.dataStream.slice(c,a)};let h="";this.filterKeyword$=this._inputOffset$.pipe(y.map(c=>{var d;const a=p(c.start,c.end);return(d=a==null?void 0:a.slice(1))!=null?d:""}),y.distinctUntilChanged(),y.tap(c=>{h=c})),this.disposeWithMe(y.combineLatest([this.filterKeyword$.pipe(y.tap(c=>{var a,d,m;c.length>0?(d=(a=this._inputPlaceholderRenderRoot)==null?void 0:a.unmount)==null||d.dispose():(m=this._inputPlaceholderRenderRoot)==null||m.mount()})),this.isComposing$.pipe(y.tap(c=>{var a,d,m;c?(d=(a=this._inputPlaceholderRenderRoot)==null?void 0:a.unmount)==null||d.dispose():h.length<=0&&((m=this._inputPlaceholderRenderRoot)==null||m.mount())})),this.editPopup$.pipe(y.tap(c=>{var a,d;c||((d=(a=this._inputPlaceholderRenderRoot)==null?void 0:a.unmount)==null||d.dispose(),this._inputPlaceholderRenderRoot=null)}))]).subscribe())}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)}resolvePopup(e){return Array.from(this._popups).find(n=>n.keyword===e)}registerPopup(e){return this._popups.add(e),()=>{this._popups.delete(e)}}_createInputPlaceholderRenderRoot(e){return{isMounted:!1,mount(){if(this.isMounted)return;this.isMounted=!0;const r=e();this.unmount={dispose:()=>{r.dispose(),this.isMounted=!1}}}}}showPopup(e){const{popup:n,index:r,unitId:o}=e;this.closePopup(),this._inputPlaceholderRenderRoot=this._createInputPlaceholderRenderRoot(()=>{var b;const p=(b=this._renderManagerService.getRenderById(o))==null?void 0:b.with(N.DocSkeletonManagerService),h=this._docSelectionManagerService.getActiveTextRange();if(!p||!h)return V;const a=p.getSkeleton().findNodeByCharIndex(h.startOffset,h.segmentId,h.segmentPage);if(!((a==null?void 0:a.content)==="\r"))return V;const m=this._docCanvasPopupManagerService.attachPopupToRange({startOffset:r+1,endOffset:r+1,collapsed:!1},{componentKey:Q.componentKey,onClickOutside:()=>{m.dispose()},direction:"horizontal"},o);return m}),this._inputPlaceholderRenderRoot.mount();const u=this._docCanvasPopupManagerService.attachPopupToRange({startOffset:r,endOffset:r,collapsed:!0},{componentKey:E.componentKey,onClickOutside:()=>{this.closePopup()},direction:"bottom"},o);this._editPopup$.next({disposable:u,popup:n,anchor:r,unitId:o})}closePopup(){this.editPopup&&(this.editPopup.disposable.dispose(),this._editPopup$.next(null))}onMenuSelected(e){return this._menuSelectedCallbacks.add(e),()=>{this._menuSelectedCallbacks.delete(e)}}emitMenuSelected(e){const{start:n,end:r}=this.inputOffset;this._commandService.syncExecuteCommand(F.id,{start:n,end:r}),setTimeout(()=>{this._menuSelectedCallbacks.forEach(o=>o(e))},0)}};exports.DocQuickInsertPopupService=he([w(0,s.Inject(P.DocCanvasPopManagerService)),w(1,s.Inject(s.IUniverInstanceService)),w(2,s.Inject(s.ICommandService)),w(3,s.Inject(pe.IRenderManagerService)),w(4,s.Inject(N.DocSelectionManagerService))],exports.DocQuickInsertPopupService);const X={type:s.CommandType.OPERATION,id:"doc.operation.show-quick-insert-popup",handler(i,t){const e=i.get(exports.DocQuickInsertPopupService);return t?(e.showPopup(t),!0):!1}},j={type:s.CommandType.OPERATION,id:"doc.operation.close-quick-insert-popup",handler(i){return i.get(exports.DocQuickInsertPopupService).closePopup(),!0}},Y={id:"quick-insert.text.menu",title:"docQuickInsert.menu.text",icon:"TextSingle",keywords:["text"]},ee={id:P.OrderListCommand.id,title:"docQuickInsert.menu.numberedList",icon:"OrderSingle",keywords:["numbered","list","ordered"]},te={id:P.BulletListCommand.id,title:"docQuickInsert.menu.bulletedList",icon:"UnorderSingle",keywords:["bulleted","list","unordered"]},ne={id:P.HorizontalLineCommand.id,title:"docQuickInsert.menu.divider",icon:"DividerSingle",keywords:["divider","line","separate"]},me=[{title:"docQuickInsert.group.basics",id:"quick.insert.group.basic",children:[Y,ee,te,ne]}],ge=new Set([ee.id,te.id,ne.id]);var Ie=Object.getOwnPropertyDescriptor,Ce=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ie(t,e):t,o=i.length-1,u;o>=0;o--)(u=i[o])&&(r=u(r)||r);return r},R=(i,t)=>(e,n)=>t(e,n,i);exports.DocQuickInsertTriggerController=class extends s.Disposable{constructor(t,e,n,r,o){super(),this._commandService=t,this._textSelectionManagerService=e,this._docQuickInsertPopupService=n,this._shortcutService=r,this._univerInstanceService=o,this.disposeWithMe(this._shortcutService.registerShortcut({id:j.id,binding:l.KeyCode.ESC,preconditions:()=>!!this._docQuickInsertPopupService.editPopup,priority:1e3})),this._initTrigger(),this._initMenuHandler()}_initTrigger(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var u,p,h;const{_docQuickInsertPopupService:e,_textSelectionManagerService:n,_commandService:r}=this,o=this._univerInstanceService.getCurrentUnitOfType(s.UniverInstanceType.UNIVER_DOC);if(!(o!=null&&o.getDisabled())){if(t.id===P.InsertCommand.id){const c=t.params;if(e.editPopup){e.setInputOffset({start:e.inputOffset.start,end:c.range.endOffset+1});return}const a=n.getActiveTextRange();if(!a)return;const d=e.resolvePopup(c.body.dataStream);if(!d||!(d.preconditions?d.preconditions(c):!0))return;e.setInputOffset({start:a.startOffset-1,end:a.startOffset}),setTimeout(()=>{r.executeCommand(X.id,{index:a.startOffset-1,unitId:c.unitId,popup:d})},100)}if(t.id===P.IMEInputCommand.id){const c=t.params;!e.isComposing&&c.isCompositionStart&&e.setIsComposing(!0),e.isComposing&&c.isCompositionEnd&&e.setIsComposing(!1)}if(t.id===N.RichTextEditingMutation.id){const c=t.params;if(c.isCompositionEnd){const a=(p=(u=c.textRanges)==null?void 0:u[0])==null?void 0:p.endOffset;a&&e.setInputOffset({start:e.inputOffset.start,end:a})}}if(t.id===P.DeleteCommand.id){const c=t.params;if(e.editPopup&&c.direction===s.DeleteDirection.LEFT){const a=(h=c.len)!=null?h:0;e.setInputOffset({start:e.inputOffset.start,end:c.range.endOffset-a})}}if(t.id===P.MoveCursorOperation.id){const c=t.params;(c.direction===s.Direction.LEFT||c.direction===s.Direction.RIGHT)&&e.editPopup&&r.executeCommand(j.id)}if(t.id===P.DeleteLeftCommand.id){const c=n.getActiveTextRange();if(!e.editPopup||!c)return;c.endOffset<=e.editPopup.anchor&&r.executeCommand(j.id)}}}))}_initMenuHandler(){this.disposeWithMe(this._docQuickInsertPopupService.onMenuSelected(t=>{t.id!==Y.id&&ge.has(t.id)&&this._commandService.executeCommand(t.id)}))}};exports.DocQuickInsertTriggerController=Ce([R(0,s.ICommandService),R(1,s.Inject(N.DocSelectionManagerService)),R(2,s.Inject(exports.DocQuickInsertPopupService)),R(3,s.Inject(l.IShortcutService)),R(4,s.Inject(s.IUniverInstanceService))],exports.DocQuickInsertTriggerController);var C=function(){return C=Object.assign||function(i){for(var t,e=1,n=arguments.length;e<n;e++){t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(i[r]=t[r])}return i},C.apply(this,arguments)},_e=function(i,t){var e={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.indexOf(n)<0&&(e[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,n=Object.getOwnPropertySymbols(i);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(i,n[r])&&(e[n[r]]=i[n[r]]);return e},A=v.forwardRef(function(i,t){var e=i.icon,n=i.id,r=i.className,o=i.extend,u=_e(i,["icon","id","className","extend"]),p="univerjs-icon univerjs-icon-".concat(n," ").concat(r||"").trim(),h=v.useRef("_".concat(Pe()));return ie(e,"".concat(n),{defIds:e.defIds,idSuffix:h.current},C({ref:t,className:p},u),o)});function ie(i,t,e,n,r){return v.createElement(i.tag,C(C({key:t},Se(i,e,r)),n),(ye(i,e).children||[]).map(function(o,u){return ie(o,"".concat(t,"-").concat(i.tag,"-").concat(u),e,void 0,r)}))}function Se(i,t,e){var n=C({},i.attrs);e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),i.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(o){var u=o[0],p=o[1];u==="mask"&&typeof p=="string"&&(n[u]=p.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var r=t.defIds;return!r||r.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var u=o[0],p=o[1];typeof p=="string"&&(n[u]=p.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function ye(i,t){var e,n=t.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?C(C({},i),{children:i.children.map(function(r){return typeof r.attrs.id=="string"&&n&&n.indexOf(r.attrs.id)>-1?C(C({},r),{attrs:C(C({},r.attrs),{id:r.attrs.id+t.idSuffix})}):r})}):i}function Pe(){return Math.random().toString(36).substring(2,8)}A.displayName="UniverIcon";var Oe={tag:"svg",attrs:{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.13985 3.40213 3.50712 3.1044 3.80485 2.73713 3.80485H1.68453C1.31726 3.80485 1.01953 3.50712 1.01953 3.13985zM4.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.13985 7.61254 3.50712 7.31481 3.80485 6.94754 3.80485H4.84234C4.47507 3.80485 4.17734 3.50712 4.17734 3.13985zM8.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.13985 11.823 3.50712 11.5252 3.80485 11.158 3.80485H9.05275C8.68548 3.80485 8.38775 3.50712 8.38775 3.13985zM12.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.13985 14.9808 3.50712 14.683 3.80485 14.3158 3.80485H13.2632C12.8959 3.80485 12.5982 3.50712 12.5982 3.13985zM1.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.99972 14.9808 8.36699 14.683 8.66472 14.3158 8.66472H1.68453C1.31726 8.66472 1.01953 8.36699 1.01953 7.99972zM1.68453 12.1951C1.31726 12.1951 1.01953 12.4928 1.01953 12.8601 1.01953 13.2273 1.31726 13.5251 1.68453 13.5251H2.73713C3.1044 13.5251 3.40213 13.2273 3.40213 12.8601 3.40213 12.4928 3.1044 12.1951 2.73713 12.1951H1.68453zM4.84234 12.1951C4.47507 12.1951 4.17734 12.4928 4.17734 12.8601 4.17734 13.2273 4.47507 13.5251 4.84234 13.5251H6.94754C7.31481 13.5251 7.61254 13.2273 7.61254 12.8601 7.61254 12.4928 7.31481 12.1951 6.94754 12.1951H4.84234zM9.05275 12.1951C8.68548 12.1951 8.38775 12.4928 8.38775 12.8601 8.38775 13.2273 8.68548 13.5251 9.05275 13.5251H11.158C11.5252 13.5251 11.823 13.2273 11.823 12.8601 11.823 12.4928 11.5252 12.1951 11.158 12.1951H9.05275zM13.2632 12.1951C12.8959 12.1951 12.5982 12.4928 12.5982 12.8601 12.5982 13.2273 12.8959 13.5251 13.2632 13.5251H14.3158C14.683 13.5251 14.9808 13.2273 14.9808 12.8601 14.9808 12.4928 14.683 12.1951 14.3158 12.1951H13.2632z"}}]},q=v.forwardRef(function(i,t){return v.createElement(A,Object.assign({},i,{id:"divider-single",ref:t,icon:Oe}))});q.displayName="DividerSingle";var xe={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.66695 1.33496C2.29968 1.33496 2.00195 1.63269 2.00195 1.99996V3.64439C2.00195 4.01166 2.29968 4.30939 2.66695 4.30939C3.03422 4.30939 3.33195 4.01166 3.33195 3.64439V2.66496H7.33521V13.335H5.3337C4.96643 13.335 4.6687 13.6327 4.6687 14C4.6687 14.3672 4.96643 14.665 5.3337 14.665H10.667C11.0343 14.665 11.332 14.3672 11.332 14C11.332 13.6327 11.0343 13.335 10.667 13.335H8.66521V2.66496H12.6686V3.64439C12.6686 4.01166 12.9664 4.30939 13.3336 4.30939C13.7009 4.30939 13.9986 4.01166 13.9986 3.64439V1.99996C13.9986 1.63269 13.7009 1.33496 13.3336 1.33496H2.66695Z"}}]},L=v.forwardRef(function(i,t){return v.createElement(A,Object.assign({},i,{id:"text-single",ref:t,icon:xe}))});L.displayName="TextSingle";var be=Object.getOwnPropertyDescriptor,ke=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,o=i.length-1,u;o>=0;o--)(u=i[o])&&(r=u(r)||r);return r},K=(i,t)=>(e,n)=>t(e,n,i);exports.DocQuickInsertUIController=class extends s.Disposable{constructor(t,e,n){super(),this._commandService=t,this._docQuickInsertPopupService=e,this._componentManager=n,this._initCommands(),this._initComponents(),this._initMenus()}_initCommands(){[F,X,j].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initComponents(){[[E.componentKey,E],[Q.componentKey,Q],[U.componentKey,U],[q.displayName,q],[L.displayName,L]].forEach(([e,n])=>{e&&this.disposeWithMe(this._componentManager.register(e,n))}),[{keyword:"/",menus$:y.of(me),preconditions:e=>{var n;return((n=e.range.startNodePosition)==null?void 0:n.glyph)===0}}].forEach(e=>{this.disposeWithMe(this._docQuickInsertPopupService.registerPopup(e))})}_initMenus(){}};exports.DocQuickInsertUIController=ke([K(0,s.ICommandService),K(1,s.Inject(exports.DocQuickInsertPopupService)),K(2,s.Inject(l.ComponentManager))],exports.DocQuickInsertUIController);var De=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,we=(i,t,e)=>t in i?De(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Re=(i,t,e,n)=>{for(var r=n>1?void 0:n?Me(t,e):t,o=i.length-1,u;o>=0;o--)(u=i[o])&&(r=u(r)||r);return r},je=(i,t)=>(e,n)=>t(e,n,i),re=(i,t,e)=>we(i,typeof t!="symbol"?t+"":t,e);const Qe="DOC_QUICK_INSERT_UI_PLUGIN";exports.UniverDocsQuickInsertUIPlugin=class extends s.Plugin{constructor(t){super(),this._injector=t}onStarting(){[[exports.DocQuickInsertUIController],[exports.DocQuickInsertTriggerController],[exports.DocQuickInsertPopupService]].forEach(e=>this._injector.add(e)),this._injector.get(exports.DocQuickInsertUIController)}onRendered(){this._injector.get(exports.DocQuickInsertTriggerController),this._injector.get(exports.DocQuickInsertPopupService)}};re(exports.UniverDocsQuickInsertUIPlugin,"type",s.UniverInstanceType.UNIVER_DOC);re(exports.UniverDocsQuickInsertUIPlugin,"pluginName",Qe);exports.UniverDocsQuickInsertUIPlugin=Re([s.DependentOn(le.UniverDrawingUIPlugin,de.UniverDrawingPlugin,ue.UniverDocsDrawingPlugin,l.UniverUIPlugin),je(0,s.Inject(s.Injector))],exports.UniverDocsQuickInsertUIPlugin);exports.KeywordInputPlaceholderComponentKey=G;exports.QuickInsertPlaceholderComponentKey=Z;
|