@univerjs/sheets-note-ui 0.18.0 → 0.19.0
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 +1 -4
- package/lib/es/index.js +1 -4
- package/lib/index.js +1 -4
- package/lib/umd/index.js +1 -4
- package/package.json +11 -11
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/sheets`),r=require(`@univerjs/sheets-note`),i=require(`rxjs`),a=require(`@univerjs/sheets-ui`),o=require(`rxjs/operators`),s=require(`@univerjs/ui`),c=require(`@univerjs/icons`),l=require(`@univerjs/design`),u=require(`react`),d=require(`react/jsx-runtime`);function f(e,t){return function(n,r){t(n,r,e)}}function p(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 m=class extends e.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let t=()=>{var t;let n=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(t=i.mainComponent)==null||t.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0,i.debounceTime)(16)).subscribe(()=>{t()}))}};m=p([f(0,(0,e.Inject)(n.SheetInterceptorService)),f(1,(0,e.Inject)(r.SheetsNoteModel)),f(2,t.IRenderManagerService),f(3,e.IUniverInstanceService)],m);const h=`SHEET_NOTE_COMPONENT`;function g(e){"@babel/helpers - typeof";return g=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},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let b=class extends e.Disposable{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,y(this,`_lastPopup`,null),y(this,`_activePopup`,void 0),y(this,`_activePopup$`,new i.BehaviorSubject(null)),y(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(t,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=t;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=t,this._activePopup$.next(t);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=t,this._activePopup$.next(t);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:h,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:t},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new e.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};b=p([f(0,s.IZenZoneService),f(1,(0,e.Inject)(a.CellPopupManagerService))],b);let x=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,y(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(t,n,r){var i,o,s;let c=(i=t[0])==null?void 0:i.range,l=this._renderManagerService.getRenderById(n),u=l==null||(o=l.with(a.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:o.skeleton;if(!u||!c)return;let d=u.getCellWithCoordByIndex(c.startRow,c.startColumn);if((((s=c.rangeType)==null?e.RANGE_TYPE.NORMAL:s)!==e.RANGE_TYPE.NORMAL||c.endColumn-c.startColumn>0||c.endRow-c.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&e.Rectangle.equals(d.mergeInfo,c))){this._sheetsNotePopupService.hidePopup();return}let f=d.actualRow,p=d.actualColumn,m=this._sheetsNoteModel.getNote(n,r,{row:f,col:p});m!=null&&m.show||(m?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:m.id,row:f,col:p}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,o.debounceTime)(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:o}=e.location,s=this._renderManagerService.getRenderById(n),c=s==null||(t=s.with(a.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:t.skeleton,l=i,u=o,d=this._sheetsNoteModel.getNote(n,r,{row:l,col:u});if(!d&&c){let{startRow:e,endRow:t,startColumn:a,endColumn:s}=c.getCellWithCoordByIndex(i,o).mergeInfo;if(e!==t||a!==s){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=a&&r.col<=s){d=r,l=r.row,u=r.col;break}}}}d!=null&&d.show||(d?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:d.id,row:l,col:u,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};x=p([f(0,(0,e.Inject)(b)),f(1,(0,e.Inject)(r.SheetsNoteModel)),f(2,(0,e.Inject)(n.SheetsSelectionsService)),f(3,a.IEditorBridgeService),f(4,t.IRenderManagerService),f(5,(0,e.Inject)(a.HoverManagerService))],x);var S=`@univerjs/sheets-note-ui`,C=`0.18.0`;const w=`sheets-note-ui.config`;Symbol(w);const T={};let E=class extends e.Disposable{constructor(t,n,r,i){super(),this._sheetsNoteModel=t,this._univerInstanceService=n,this._cellPopupManagerService=r,this._sheetsNotePopupService=i,y(this,`_noteMatrix`,new e.ObjectMatrix),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:h,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(t,n){var r;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new e.ObjectMatrix;let i=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(r=this._sheetsNoteModel.getSheetNotes(t,n))==null||r.forEach(e=>{i(t,n,e.row,e.col,e)}),this._sheetsNoteModel.change$.subscribe(e=>{if(!(e.unitId!==t||e.subUnitId!==n))switch(e.type){case`ref`:{let{unitId:t,subUnitId:n,oldNote:r,newNote:i}=e;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(t,n,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:t,subUnitId:n,oldNote:r,newNote:a}=e;i(t,n,a?a.row:r.row,a?a.col:r.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,i.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,i.of)(null):t})).subscribe(t=>{if(t){let e=this._initSheet(t.getUnitId(),t.getSheetId());return()=>{e.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new e.ObjectMatrix}))}};E=p([f(0,(0,e.Inject)(r.SheetsNoteModel)),f(1,(0,e.Inject)(e.IUniverInstanceService)),f(2,(0,e.Inject)(a.CellPopupManagerService)),f(3,(0,e.Inject)(b))],E);const D={id:`sheet.operation.add-note-popup`,type:e.CommandType.OPERATION,handler:async(t,r)=>{var i;let a=t.get(n.SheetsSelectionsService),o=t.get(b),s=t.get(e.IUniverInstanceService).getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;let c=s.getActiveSheet(),l=a.getCurrentLastSelection();if(!(l!=null&&l.primary))return!1;let{primary:u}=l;return o.showPopup({unitId:s.getUnitId(),subUnitId:c.getSheetId(),row:u.actualRow,col:u.actualColumn,temp:!1,trigger:(i=r==null?void 0:r.trigger)==null?`add-note`:i}),!0}};function O(t){let a=t.get(n.SheetsSelectionsService),o=t.get(e.IUniverInstanceService);return a.selectionMoveEnd$.pipe((0,i.map)(()=>{let e=a.getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;let i=(0,n.getSheetCommandTarget)(o);if(!i)return!1;let{actualColumn:s,actualRow:c}=e.primary;return!!t.get(r.SheetsNoteModel).getNote(i.unitId,i.subUnitId,{row:c,col:s})}))}function k(t){return{id:D.id,type:s.MenuItemType.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:(0,i.combineLatest)([(0,s.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),O(t)]).pipe((0,i.map)(([e,t])=>e||t)),disabled$:(0,a.getCurrentRangeDisable$)(t,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetEditPermission]}),commandId:D.id}}function A(e){return{id:r.SheetDeleteNoteCommand.id,type:s.MenuItemType.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:O(e).pipe((0,i.map)(e=>!e)),disabled$:(0,a.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetEditPermission]})}}function j(e){return{id:r.SheetToggleNotePopupCommand.id,type:s.MenuItemType.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:O(e).pipe((0,i.map)(e=>!e))}}const M={[s.ContextMenuPosition.MAIN_AREA]:{[s.ContextMenuGroup.OTHERS]:{order:0,[D.id]:{order:0,menuItemFactory:k},[r.SheetDeleteNoteCommand.id]:{order:0,menuItemFactory:A},[r.SheetToggleNotePopupCommand.id]:{order:0,menuItemFactory:j}}}},N=n=>{var i;let{popup:a}=n,o=(0,s.useDependency)(r.SheetsNoteModel),c=(0,s.useDependency)(e.LocaleService),f=(0,s.useDependency)(t.IRenderManagerService),p=(0,s.useDependency)(b),m=(0,s.useConfigValue)(w),h=(i=a.extraProps)==null?void 0:i.location;if(!h)return console.error(`Popup extraProps or location is undefined.`),null;let g=(0,u.useRef)(null),_=f.getRenderById(h.unitId),[v,y]=(0,u.useState)(null);(0,u.useEffect)(()=>{var t,n,r,i,a,s;let{unitId:c,subUnitId:l,row:u,col:d}=h,f=o.getNote(c,l,{row:u,col:d}),p=(t=(n=f==null?void 0:f.width)==null?m==null||(r=m.defaultNoteSize)==null?void 0:r.width:n)==null?160:t,_=(i=(a=f==null?void 0:f.height)==null?m==null||(s=m.defaultNoteSize)==null?void 0:s.height:a)==null?72:i;if(f)y(f);else{let t={id:(0,e.generateRandomId)(6),width:p,height:_,note:``};y(t),S(t)}g.current&&(g.current.style.width=`${p}px`,g.current.style.height=`${_}px`)},[h,g]),(0,u.useEffect)(()=>{if(!h||h.temp||!h.trigger||!g.current)return;let e=requestAnimationFrame(()=>{var e;(e=g.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[h]);let x=(0,s.useDependency)(e.ICommandService),S=(0,s.useDebounceFn)(e=>{if(!h)return;let{unitId:t,subUnitId:n,row:i,col:a}=h;if(!x.syncExecuteCommand(r.SheetUpdateNoteCommand.id,{unitId:t,sheetId:n,row:i,col:a,note:e})){let r=o.getNote(t,n,{noteId:e.id,row:i,col:a});r?y(r):p.hidePopup(!0)}}),C=(0,u.useCallback)(e=>{if(!v||e===v.note)return;let t={...v,note:e};y(t),S(t)},[v]),T=(0,u.useCallback)((e,t)=>{if(!v||e===v.width&&t===v.height)return;let n={...v,width:e,height:t};y(n),S(n)},[v]);return(0,d.jsx)(l.Textarea,{ref:g,"data-u-comp":`note-textarea`,className:(0,l.clsx)(`
|
|
2
|
-
univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow
|
|
3
|
-
dark:!univer-bg-gray-800
|
|
4
|
-
`),value:v==null?void 0:v.note,placeholder:c.t(`note.placeholder`),onResize:T,onValueChange:C,onWheel:e=>{document.activeElement!==g.current&&_.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})};let P=class extends e.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[h,N],[`AddNoteIcon`,c.AddNoteIcon],[`DeleteNoteIcon`,c.DeleteNoteIcon],[`HideNoteIcon`,c.HideNoteIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(M)}_initCommands(){this._commandService.registerCommand(D)}};P=p([f(0,(0,e.Inject)(s.ComponentManager)),f(1,(0,e.Inject)(s.IMenuManagerService)),f(2,e.ICommandService)],P);let F=class extends e.Plugin{constructor(t=T,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},T,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(w,a)}onStarting(){[[b],[m],[x],[P],[E]].forEach(e=>{this._injector.add(e)})}onReady(){(0,e.touchDependencies)(this._injector,[[P],[m]])}onRendered(){(0,e.touchDependencies)(this._injector,[[x],[E]])}};y(F,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),y(F,`packageName`,S),y(F,`version`,C),y(F,`type`,e.UniverInstanceType.UNIVER_SHEET),F=p([(0,e.DependentOn)(r.UniverSheetsNotePlugin),f(1,(0,e.Inject)(e.Injector)),f(2,e.IConfigService)],F),Object.defineProperty(exports,`SheetsCellContentController`,{enumerable:!0,get:function(){return m}}),exports.SheetsNote=N,Object.defineProperty(exports,`SheetsNotePopupController`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`SheetsNotePopupService`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`UniverSheetsNoteUIPlugin`,{enumerable:!0,get:function(){return F}});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/sheets`),r=require(`@univerjs/sheets-note`),i=require(`rxjs`),a=require(`@univerjs/sheets-ui`),o=require(`rxjs/operators`),s=require(`@univerjs/ui`),c=require(`@univerjs/icons`),l=require(`@univerjs/design`),u=require(`react`),d=require(`react/jsx-runtime`);function f(e,t){return function(n,r){t(n,r,e)}}function p(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 m=class extends e.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let t=()=>{var t;let n=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(t=i.mainComponent)==null||t.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0,i.debounceTime)(16)).subscribe(()=>{t()}))}};m=p([f(0,(0,e.Inject)(n.SheetInterceptorService)),f(1,(0,e.Inject)(r.SheetsNoteModel)),f(2,t.IRenderManagerService),f(3,e.IUniverInstanceService)],m);const h=`SHEET_NOTE_COMPONENT`;function g(e){"@babel/helpers - typeof";return g=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},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let b=class extends e.Disposable{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,y(this,`_lastPopup`,null),y(this,`_activePopup`,void 0),y(this,`_activePopup$`,new i.BehaviorSubject(null)),y(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(t,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=t;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=t,this._activePopup$.next(t);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=t,this._activePopup$.next(t);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:h,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:t},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new e.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};b=p([f(0,s.IZenZoneService),f(1,(0,e.Inject)(a.CellPopupManagerService))],b);let x=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,y(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(t,n,r){var i,o,s;let c=(i=t[0])==null?void 0:i.range,l=this._renderManagerService.getRenderById(n),u=l==null||(o=l.with(a.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:o.skeleton;if(!u||!c)return;let d=u.getCellWithCoordByIndex(c.startRow,c.startColumn);if((((s=c.rangeType)==null?e.RANGE_TYPE.NORMAL:s)!==e.RANGE_TYPE.NORMAL||c.endColumn-c.startColumn>0||c.endRow-c.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&e.Rectangle.equals(d.mergeInfo,c))){this._sheetsNotePopupService.hidePopup();return}let f=d.actualRow,p=d.actualColumn,m=this._sheetsNoteModel.getNote(n,r,{row:f,col:p});m!=null&&m.show||(m?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:m.id,row:f,col:p}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,o.debounceTime)(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:o}=e.location,s=this._renderManagerService.getRenderById(n),c=s==null||(t=s.with(a.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:t.skeleton,l=i,u=o,d=this._sheetsNoteModel.getNote(n,r,{row:l,col:u});if(!d&&c){let{startRow:e,endRow:t,startColumn:a,endColumn:s}=c.getCellWithCoordByIndex(i,o).mergeInfo;if(e!==t||a!==s){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=a&&r.col<=s){d=r,l=r.row,u=r.col;break}}}}d!=null&&d.show||(d?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:d.id,row:l,col:u,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};x=p([f(0,(0,e.Inject)(b)),f(1,(0,e.Inject)(r.SheetsNoteModel)),f(2,(0,e.Inject)(n.SheetsSelectionsService)),f(3,a.IEditorBridgeService),f(4,t.IRenderManagerService),f(5,(0,e.Inject)(a.HoverManagerService))],x);var S=`@univerjs/sheets-note-ui`,C=`0.19.0`;const w=`sheets-note-ui.config`;Symbol(w);const T={};let E=class extends e.Disposable{constructor(t,n,r,i){super(),this._sheetsNoteModel=t,this._univerInstanceService=n,this._cellPopupManagerService=r,this._sheetsNotePopupService=i,y(this,`_noteMatrix`,new e.ObjectMatrix),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:h,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(t,n){var r;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new e.ObjectMatrix;let i=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(r=this._sheetsNoteModel.getSheetNotes(t,n))==null||r.forEach(e=>{i(t,n,e.row,e.col,e)}),this._sheetsNoteModel.change$.subscribe(e=>{if(!(e.unitId!==t||e.subUnitId!==n))switch(e.type){case`ref`:{let{unitId:t,subUnitId:n,oldNote:r,newNote:i}=e;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(t,n,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:t,subUnitId:n,oldNote:r,newNote:a}=e;i(t,n,a?a.row:r.row,a?a.col:r.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,i.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,i.of)(null):t})).subscribe(t=>{if(t){let e=this._initSheet(t.getUnitId(),t.getSheetId());return()=>{e.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new e.ObjectMatrix}))}};E=p([f(0,(0,e.Inject)(r.SheetsNoteModel)),f(1,(0,e.Inject)(e.IUniverInstanceService)),f(2,(0,e.Inject)(a.CellPopupManagerService)),f(3,(0,e.Inject)(b))],E);const D={id:`sheet.operation.add-note-popup`,type:e.CommandType.OPERATION,handler:async(t,r)=>{var i;let a=t.get(n.SheetsSelectionsService),o=t.get(b),s=t.get(e.IUniverInstanceService).getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;let c=s.getActiveSheet(),l=a.getCurrentLastSelection();if(!(l!=null&&l.primary))return!1;let{primary:u}=l;return o.showPopup({unitId:s.getUnitId(),subUnitId:c.getSheetId(),row:u.actualRow,col:u.actualColumn,temp:!1,trigger:(i=r==null?void 0:r.trigger)==null?`add-note`:i}),!0}};function O(t){let a=t.get(n.SheetsSelectionsService),o=t.get(e.IUniverInstanceService);return a.selectionMoveEnd$.pipe((0,i.map)(()=>{let e=a.getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;let i=(0,n.getSheetCommandTarget)(o);if(!i)return!1;let{actualColumn:s,actualRow:c}=e.primary;return!!t.get(r.SheetsNoteModel).getNote(i.unitId,i.subUnitId,{row:c,col:s})}))}function k(t){return{id:D.id,type:s.MenuItemType.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:(0,i.combineLatest)([(0,s.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),O(t)]).pipe((0,i.map)(([e,t])=>e||t)),disabled$:(0,a.getCurrentRangeDisable$)(t,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetEditPermission]}),commandId:D.id}}function A(e){return{id:r.SheetDeleteNoteCommand.id,type:s.MenuItemType.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:O(e).pipe((0,i.map)(e=>!e)),disabled$:(0,a.getCurrentRangeDisable$)(e,{workbookTypes:[n.WorkbookEditablePermission],worksheetTypes:[n.WorksheetEditPermission]})}}function j(e){return{id:r.SheetToggleNotePopupCommand.id,type:s.MenuItemType.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:O(e).pipe((0,i.map)(e=>!e))}}const M={[s.ContextMenuPosition.MAIN_AREA]:{[s.ContextMenuGroup.OTHERS]:{order:0,[D.id]:{order:0,menuItemFactory:k},[r.SheetDeleteNoteCommand.id]:{order:0,menuItemFactory:A},[r.SheetToggleNotePopupCommand.id]:{order:0,menuItemFactory:j}}}},N=n=>{var i;let{popup:a}=n,o=(0,s.useDependency)(r.SheetsNoteModel),c=(0,s.useDependency)(e.LocaleService),f=(0,s.useDependency)(t.IRenderManagerService),p=(0,s.useDependency)(b),m=(0,s.useConfigValue)(w),h=(i=a.extraProps)==null?void 0:i.location;if(!h)return console.error(`Popup extraProps or location is undefined.`),null;let g=(0,u.useRef)(null),_=f.getRenderById(h.unitId),[v,y]=(0,u.useState)(null);(0,u.useEffect)(()=>{var t,n,r,i,a,s;let{unitId:c,subUnitId:l,row:u,col:d}=h,f=o.getNote(c,l,{row:u,col:d}),p=(t=(n=f==null?void 0:f.width)==null?m==null||(r=m.defaultNoteSize)==null?void 0:r.width:n)==null?160:t,_=(i=(a=f==null?void 0:f.height)==null?m==null||(s=m.defaultNoteSize)==null?void 0:s.height:a)==null?72:i;if(f)y(f);else{let t={id:(0,e.generateRandomId)(6),width:p,height:_,note:``};y(t),S(t)}g.current&&(g.current.style.width=`${p}px`,g.current.style.height=`${_}px`)},[h,g]),(0,u.useEffect)(()=>{if(!h||h.temp||!h.trigger||!g.current)return;let e=requestAnimationFrame(()=>{var e;(e=g.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[h]);let x=(0,s.useDependency)(e.ICommandService),S=(0,s.useDebounceFn)(e=>{if(!h)return;let{unitId:t,subUnitId:n,row:i,col:a}=h;if(!x.syncExecuteCommand(r.SheetUpdateNoteCommand.id,{unitId:t,sheetId:n,row:i,col:a,note:e})){let r=o.getNote(t,n,{noteId:e.id,row:i,col:a});r?y(r):p.hidePopup(!0)}}),C=(0,u.useCallback)(e=>{if(!v||e===v.note)return;let t={...v,note:e};y(t),S(t)},[v]),T=(0,u.useCallback)((e,t)=>{if(!v||e===v.width&&t===v.height)return;let n={...v,width:e,height:t};y(n),S(n)},[v]);return(0,d.jsx)(l.Textarea,{ref:g,"data-u-comp":`note-textarea`,className:(0,l.clsx)(`univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow dark:!univer-bg-gray-800`),value:v==null?void 0:v.note,placeholder:c.t(`note.placeholder`),onResize:T,onValueChange:C,onWheel:e=>{document.activeElement!==g.current&&_.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})};let P=class extends e.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[h,N],[`AddNoteIcon`,c.AddNoteIcon],[`DeleteNoteIcon`,c.DeleteNoteIcon],[`HideNoteIcon`,c.HideNoteIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(M)}_initCommands(){this._commandService.registerCommand(D)}};P=p([f(0,(0,e.Inject)(s.ComponentManager)),f(1,(0,e.Inject)(s.IMenuManagerService)),f(2,e.ICommandService)],P);let F=class extends e.Plugin{constructor(t=T,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},T,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(w,a)}onStarting(){[[b],[m],[x],[P],[E]].forEach(e=>{this._injector.add(e)})}onReady(){(0,e.touchDependencies)(this._injector,[[P],[m]])}onRendered(){(0,e.touchDependencies)(this._injector,[[x],[E]])}};y(F,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),y(F,`packageName`,S),y(F,`version`,C),y(F,`type`,e.UniverInstanceType.UNIVER_SHEET),F=p([(0,e.DependentOn)(r.UniverSheetsNotePlugin),f(1,(0,e.Inject)(e.Injector)),f(2,e.IConfigService)],F),Object.defineProperty(exports,`SheetsCellContentController`,{enumerable:!0,get:function(){return m}}),exports.SheetsNote=N,Object.defineProperty(exports,`SheetsNotePopupController`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`SheetsNotePopupService`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`UniverSheetsNoteUIPlugin`,{enumerable:!0,get:function(){return F}});
|
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,ObjectMatrix as d,Plugin as f,RANGE_TYPE as p,Rectangle as m,UniverInstanceType as h,generateRandomId as ee,merge as g,touchDependencies as _}from"@univerjs/core";import{IRenderManagerService as v}from"@univerjs/engine-render";import{INTERCEPTOR_POINT as y,SheetInterceptorService as te,SheetsSelectionsService as b,WorkbookEditablePermission as x,WorksheetEditPermission as S,getSheetCommandTarget as ne}from"@univerjs/sheets";import{SheetDeleteNoteCommand as C,SheetToggleNotePopupCommand as w,SheetUpdateNoteCommand as re,SheetsNoteModel as T,UniverSheetsNotePlugin as ie}from"@univerjs/sheets-note";import{BehaviorSubject as ae,combineLatest as oe,debounceTime as se,map as E,of as ce,switchMap as D}from"rxjs";import{CellPopupManagerService as O,HoverManagerService as le,IEditorBridgeService as ue,SheetSkeletonManagerService as k,getCurrentRangeDisable$ as A}from"@univerjs/sheets-ui";import{debounceTime as de}from"rxjs/operators";import{ComponentManager as fe,ContextMenuGroup as pe,ContextMenuPosition as me,IMenuManagerService as he,IZenZoneService as ge,MenuItemType as j,getMenuHiddenObservable as _e,useConfigValue as ve,useDebounceFn as ye,useDependency as M}from"@univerjs/ui";import{AddNoteIcon as N,DeleteNoteIcon as P,HideNoteIcon as be}from"@univerjs/icons";import{Textarea as xe,clsx as F}from"@univerjs/design";import{useCallback as I,useEffect as L,useRef as Se,useState as Ce}from"react";import{jsx as we}from"react/jsx-runtime";function R(e,t){return function(n,r){t(n,r,e)}}function z(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 B=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(h.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe(se(16)).subscribe(()=>{e()}))}};B=z([R(0,s(te)),R(1,s(T)),R(2,v),R(3,o)],B);const V=`SHEET_NOTE_COMPONENT`;function H(e){"@babel/helpers - typeof";return H=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},H(e)}function Te(e,t){if(H(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(H(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ee(e){var t=Te(e,`string`);return H(t)==`symbol`?t:t+``}function U(e,t,n){return(t=Ee(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,U(this,`_lastPopup`,null),U(this,`_activePopup`,void 0),U(this,`_activePopup$`,new ae(null)),U(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:V,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=z([R(0,ge),R(1,s(O))],W);let G=class extends n{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,U(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(k).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?p.NORMAL:a)!==p.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._sheetsNotePopupService.hidePopup();return}let u=l.actualRow,d=l.actualColumn,f=this._sheetsNoteModel.getNote(t,n,{row:u,col:d});f!=null&&f.show||(f?this._sheetsNotePopupService.showPopup({unitId:t,subUnitId:n,noteId:f.id,row:u,col:d}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(de(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,o=this._renderManagerService.getRenderById(n),s=o==null||(t=o.with(k).getSkeletonParam(r))==null?void 0:t.skeleton,c=i,l=a,u=this._sheetsNoteModel.getNote(n,r,{row:c,col:l});if(!u&&s){let{startRow:e,endRow:t,startColumn:o,endColumn:d}=s.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==d){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=d){u=r,c=r.row,l=r.col;break}}}}u!=null&&u.show||(u?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:u.id,row:c,col:l,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};G=z([R(0,s(W)),R(1,s(T)),R(2,s(b)),R(3,ue),R(4,v),R(5,s(le))],G);var De=`@univerjs/sheets-note-ui`,Oe=`0.18.0`;const K=`sheets-note-ui.config`;Symbol(K);const q={};let J=class extends n{constructor(e,t,n,r){super(),this._sheetsNoteModel=e,this._univerInstanceService=t,this._cellPopupManagerService=n,this._sheetsNotePopupService=r,U(this,`_noteMatrix`,new d),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:V,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,t){var n;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d;let r=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(n=this._sheetsNoteModel.getSheetNotes(e,t))==null||n.forEach(n=>{r(e,t,n.row,n.col,n)}),this._sheetsNoteModel.change$.subscribe(n=>{if(!(n.unitId!==e||n.subUnitId!==t))switch(n.type){case`ref`:{let{unitId:e,subUnitId:t,oldNote:r,newNote:i}=n;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,t,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:t,oldNote:i,newNote:a}=n;r(e,t,a?a.row:i.row,a?a.col:i.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(h.UNIVER_SHEET).pipe(D(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?ce(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d}))}};J=z([R(0,s(T)),R(1,s(o)),R(2,s(O)),R(3,s(W))],J);const Y={id:`sheet.operation.add-note-popup`,type:e.OPERATION,handler:async(e,t)=>{var n;let r=e.get(b),i=e.get(W),a=e.get(o).getCurrentUnitForType(h.UNIVER_SHEET);if(!a)return!1;let s=a.getActiveSheet(),c=r.getCurrentLastSelection();if(!(c!=null&&c.primary))return!1;let{primary:l}=c;return i.showPopup({unitId:a.getUnitId(),subUnitId:s.getSheetId(),row:l.actualRow,col:l.actualColumn,temp:!1,trigger:(n=t==null?void 0:t.trigger)==null?`add-note`:n}),!0}};function X(e){let t=e.get(b),n=e.get(o);return t.selectionMoveEnd$.pipe(E(()=>{let r=t.getCurrentLastSelection();if(!(r!=null&&r.primary))return!1;let i=ne(n);if(!i)return!1;let{actualColumn:a,actualRow:o}=r.primary;return!!e.get(T).getNote(i.unitId,i.subUnitId,{row:o,col:a})}))}function ke(e){return{id:Y.id,type:j.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:oe([_e(e,h.UNIVER_SHEET),X(e)]).pipe(E(([e,t])=>e||t)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]}),commandId:Y.id}}function Ae(e){return{id:C.id,type:j.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:X(e).pipe(E(e=>!e)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]})}}function je(e){return{id:w.id,type:j.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:X(e).pipe(E(e=>!e))}}const Me={[me.MAIN_AREA]:{[pe.OTHERS]:{order:0,[Y.id]:{order:0,menuItemFactory:ke},[C.id]:{order:0,menuItemFactory:Ae},[w.id]:{order:0,menuItemFactory:je}}}},Z=e=>{var t;let{popup:n}=e,r=M(T),a=M(u),o=M(v),s=M(W),c=ve(K),l=(t=n.extraProps)==null?void 0:t.location;if(!l)return console.error(`Popup extraProps or location is undefined.`),null;let d=Se(null),f=o.getRenderById(l.unitId),[p,m]=Ce(null);L(()=>{var e,t,n,i,a,o;let{unitId:s,subUnitId:u,row:f,col:p}=l,h=r.getNote(s,u,{row:f,col:p}),_=(e=(t=h==null?void 0:h.width)==null?c==null||(n=c.defaultNoteSize)==null?void 0:n.width:t)==null?160:e,v=(i=(a=h==null?void 0:h.height)==null?c==null||(o=c.defaultNoteSize)==null?void 0:o.height:a)==null?72:i;if(h)m(h);else{let e={id:ee(6),width:_,height:v,note:``};m(e),g(e)}d.current&&(d.current.style.width=`${_}px`,d.current.style.height=`${v}px`)},[l,d]),L(()=>{if(!l||l.temp||!l.trigger||!d.current)return;let e=requestAnimationFrame(()=>{var e;(e=d.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[l]);let h=M(i),g=ye(e=>{if(!l)return;let{unitId:t,subUnitId:n,row:i,col:a}=l;if(!h.syncExecuteCommand(re.id,{unitId:t,sheetId:n,row:i,col:a,note:e})){let o=r.getNote(t,n,{noteId:e.id,row:i,col:a});o?m(o):s.hidePopup(!0)}}),_=I(e=>{if(!p||e===p.note)return;let t={...p,note:e};m(t),g(t)},[p]),y=I((e,t)=>{if(!p||e===p.width&&t===p.height)return;let n={...p,width:e,height:t};m(n),g(n)},[p]);return we(xe,{ref:d,"data-u-comp":`note-textarea`,className:F(`
|
|
2
|
-
univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow
|
|
3
|
-
dark:!univer-bg-gray-800
|
|
4
|
-
`),value:p==null?void 0:p.note,placeholder:a.t(`note.placeholder`),onResize:y,onValueChange:_,onWheel:e=>{document.activeElement!==d.current&&f.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})};let Q=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[V,Z],[`AddNoteIcon`,N],[`DeleteNoteIcon`,P],[`HideNoteIcon`,be]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(Me)}_initCommands(){this._commandService.registerCommand(Y)}};Q=z([R(0,s(fe)),R(1,s(he)),R(2,i)],Q);let $=class extends f{constructor(e=q,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=g({},q,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(K,i)}onStarting(){[[W],[B],[G],[Q],[J]].forEach(e=>{this._injector.add(e)})}onReady(){_(this._injector,[[Q],[B]])}onRendered(){_(this._injector,[[G],[J]])}};U($,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),U($,`packageName`,De),U($,`version`,Oe),U($,`type`,h.UNIVER_SHEET),$=z([t(ie),R(1,s(c)),R(2,a)],$);export{B as SheetsCellContentController,Z as SheetsNote,G as SheetsNotePopupController,W as SheetsNotePopupService,$ as UniverSheetsNoteUIPlugin};
|
|
1
|
+
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,ObjectMatrix as d,Plugin as f,RANGE_TYPE as p,Rectangle as m,UniverInstanceType as h,generateRandomId as ee,merge as g,touchDependencies as _}from"@univerjs/core";import{IRenderManagerService as v}from"@univerjs/engine-render";import{INTERCEPTOR_POINT as y,SheetInterceptorService as te,SheetsSelectionsService as b,WorkbookEditablePermission as x,WorksheetEditPermission as S,getSheetCommandTarget as ne}from"@univerjs/sheets";import{SheetDeleteNoteCommand as C,SheetToggleNotePopupCommand as w,SheetUpdateNoteCommand as re,SheetsNoteModel as T,UniverSheetsNotePlugin as ie}from"@univerjs/sheets-note";import{BehaviorSubject as ae,combineLatest as oe,debounceTime as se,map as E,of as ce,switchMap as D}from"rxjs";import{CellPopupManagerService as O,HoverManagerService as le,IEditorBridgeService as ue,SheetSkeletonManagerService as k,getCurrentRangeDisable$ as A}from"@univerjs/sheets-ui";import{debounceTime as de}from"rxjs/operators";import{ComponentManager as fe,ContextMenuGroup as pe,ContextMenuPosition as me,IMenuManagerService as he,IZenZoneService as ge,MenuItemType as j,getMenuHiddenObservable as _e,useConfigValue as ve,useDebounceFn as ye,useDependency as M}from"@univerjs/ui";import{AddNoteIcon as N,DeleteNoteIcon as P,HideNoteIcon as be}from"@univerjs/icons";import{Textarea as xe,clsx as F}from"@univerjs/design";import{useCallback as I,useEffect as L,useRef as Se,useState as Ce}from"react";import{jsx as we}from"react/jsx-runtime";function R(e,t){return function(n,r){t(n,r,e)}}function z(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 B=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(h.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe(se(16)).subscribe(()=>{e()}))}};B=z([R(0,s(te)),R(1,s(T)),R(2,v),R(3,o)],B);const V=`SHEET_NOTE_COMPONENT`;function H(e){"@babel/helpers - typeof";return H=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},H(e)}function Te(e,t){if(H(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(H(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ee(e){var t=Te(e,`string`);return H(t)==`symbol`?t:t+``}function U(e,t,n){return(t=Ee(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,U(this,`_lastPopup`,null),U(this,`_activePopup`,void 0),U(this,`_activePopup$`,new ae(null)),U(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:V,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=z([R(0,ge),R(1,s(O))],W);let G=class extends n{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,U(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(k).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?p.NORMAL:a)!==p.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._sheetsNotePopupService.hidePopup();return}let u=l.actualRow,d=l.actualColumn,f=this._sheetsNoteModel.getNote(t,n,{row:u,col:d});f!=null&&f.show||(f?this._sheetsNotePopupService.showPopup({unitId:t,subUnitId:n,noteId:f.id,row:u,col:d}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(de(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,o=this._renderManagerService.getRenderById(n),s=o==null||(t=o.with(k).getSkeletonParam(r))==null?void 0:t.skeleton,c=i,l=a,u=this._sheetsNoteModel.getNote(n,r,{row:c,col:l});if(!u&&s){let{startRow:e,endRow:t,startColumn:o,endColumn:d}=s.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==d){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=d){u=r,c=r.row,l=r.col;break}}}}u!=null&&u.show||(u?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:u.id,row:c,col:l,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};G=z([R(0,s(W)),R(1,s(T)),R(2,s(b)),R(3,ue),R(4,v),R(5,s(le))],G);var De=`@univerjs/sheets-note-ui`,Oe=`0.19.0`;const K=`sheets-note-ui.config`;Symbol(K);const q={};let J=class extends n{constructor(e,t,n,r){super(),this._sheetsNoteModel=e,this._univerInstanceService=t,this._cellPopupManagerService=n,this._sheetsNotePopupService=r,U(this,`_noteMatrix`,new d),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:V,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,t){var n;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d;let r=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(n=this._sheetsNoteModel.getSheetNotes(e,t))==null||n.forEach(n=>{r(e,t,n.row,n.col,n)}),this._sheetsNoteModel.change$.subscribe(n=>{if(!(n.unitId!==e||n.subUnitId!==t))switch(n.type){case`ref`:{let{unitId:e,subUnitId:t,oldNote:r,newNote:i}=n;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,t,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:t,oldNote:i,newNote:a}=n;r(e,t,a?a.row:i.row,a?a.col:i.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(h.UNIVER_SHEET).pipe(D(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?ce(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d}))}};J=z([R(0,s(T)),R(1,s(o)),R(2,s(O)),R(3,s(W))],J);const Y={id:`sheet.operation.add-note-popup`,type:e.OPERATION,handler:async(e,t)=>{var n;let r=e.get(b),i=e.get(W),a=e.get(o).getCurrentUnitForType(h.UNIVER_SHEET);if(!a)return!1;let s=a.getActiveSheet(),c=r.getCurrentLastSelection();if(!(c!=null&&c.primary))return!1;let{primary:l}=c;return i.showPopup({unitId:a.getUnitId(),subUnitId:s.getSheetId(),row:l.actualRow,col:l.actualColumn,temp:!1,trigger:(n=t==null?void 0:t.trigger)==null?`add-note`:n}),!0}};function X(e){let t=e.get(b),n=e.get(o);return t.selectionMoveEnd$.pipe(E(()=>{let r=t.getCurrentLastSelection();if(!(r!=null&&r.primary))return!1;let i=ne(n);if(!i)return!1;let{actualColumn:a,actualRow:o}=r.primary;return!!e.get(T).getNote(i.unitId,i.subUnitId,{row:o,col:a})}))}function ke(e){return{id:Y.id,type:j.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:oe([_e(e,h.UNIVER_SHEET),X(e)]).pipe(E(([e,t])=>e||t)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]}),commandId:Y.id}}function Ae(e){return{id:C.id,type:j.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:X(e).pipe(E(e=>!e)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]})}}function je(e){return{id:w.id,type:j.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:X(e).pipe(E(e=>!e))}}const Me={[me.MAIN_AREA]:{[pe.OTHERS]:{order:0,[Y.id]:{order:0,menuItemFactory:ke},[C.id]:{order:0,menuItemFactory:Ae},[w.id]:{order:0,menuItemFactory:je}}}},Z=e=>{var t;let{popup:n}=e,r=M(T),a=M(u),o=M(v),s=M(W),c=ve(K),l=(t=n.extraProps)==null?void 0:t.location;if(!l)return console.error(`Popup extraProps or location is undefined.`),null;let d=Se(null),f=o.getRenderById(l.unitId),[p,m]=Ce(null);L(()=>{var e,t,n,i,a,o;let{unitId:s,subUnitId:u,row:f,col:p}=l,h=r.getNote(s,u,{row:f,col:p}),_=(e=(t=h==null?void 0:h.width)==null?c==null||(n=c.defaultNoteSize)==null?void 0:n.width:t)==null?160:e,v=(i=(a=h==null?void 0:h.height)==null?c==null||(o=c.defaultNoteSize)==null?void 0:o.height:a)==null?72:i;if(h)m(h);else{let e={id:ee(6),width:_,height:v,note:``};m(e),g(e)}d.current&&(d.current.style.width=`${_}px`,d.current.style.height=`${v}px`)},[l,d]),L(()=>{if(!l||l.temp||!l.trigger||!d.current)return;let e=requestAnimationFrame(()=>{var e;(e=d.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[l]);let h=M(i),g=ye(e=>{if(!l)return;let{unitId:t,subUnitId:n,row:i,col:a}=l;if(!h.syncExecuteCommand(re.id,{unitId:t,sheetId:n,row:i,col:a,note:e})){let o=r.getNote(t,n,{noteId:e.id,row:i,col:a});o?m(o):s.hidePopup(!0)}}),_=I(e=>{if(!p||e===p.note)return;let t={...p,note:e};m(t),g(t)},[p]),y=I((e,t)=>{if(!p||e===p.width&&t===p.height)return;let n={...p,width:e,height:t};m(n),g(n)},[p]);return we(xe,{ref:d,"data-u-comp":`note-textarea`,className:F(`univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow dark:!univer-bg-gray-800`),value:p==null?void 0:p.note,placeholder:a.t(`note.placeholder`),onResize:y,onValueChange:_,onWheel:e=>{document.activeElement!==d.current&&f.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})};let Q=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[V,Z],[`AddNoteIcon`,N],[`DeleteNoteIcon`,P],[`HideNoteIcon`,be]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(Me)}_initCommands(){this._commandService.registerCommand(Y)}};Q=z([R(0,s(fe)),R(1,s(he)),R(2,i)],Q);let $=class extends f{constructor(e=q,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=g({},q,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(K,i)}onStarting(){[[W],[B],[G],[Q],[J]].forEach(e=>{this._injector.add(e)})}onReady(){_(this._injector,[[Q],[B]])}onRendered(){_(this._injector,[[G],[J]])}};U($,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),U($,`packageName`,De),U($,`version`,Oe),U($,`type`,h.UNIVER_SHEET),$=z([t(ie),R(1,s(c)),R(2,a)],$);export{B as SheetsCellContentController,Z as SheetsNote,G as SheetsNotePopupController,W as SheetsNotePopupService,$ as UniverSheetsNoteUIPlugin};
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,ObjectMatrix as d,Plugin as f,RANGE_TYPE as p,Rectangle as m,UniverInstanceType as h,generateRandomId as ee,merge as g,touchDependencies as _}from"@univerjs/core";import{IRenderManagerService as v}from"@univerjs/engine-render";import{INTERCEPTOR_POINT as y,SheetInterceptorService as te,SheetsSelectionsService as b,WorkbookEditablePermission as x,WorksheetEditPermission as S,getSheetCommandTarget as ne}from"@univerjs/sheets";import{SheetDeleteNoteCommand as C,SheetToggleNotePopupCommand as w,SheetUpdateNoteCommand as re,SheetsNoteModel as T,UniverSheetsNotePlugin as ie}from"@univerjs/sheets-note";import{BehaviorSubject as ae,combineLatest as oe,debounceTime as se,map as E,of as ce,switchMap as D}from"rxjs";import{CellPopupManagerService as O,HoverManagerService as le,IEditorBridgeService as ue,SheetSkeletonManagerService as k,getCurrentRangeDisable$ as A}from"@univerjs/sheets-ui";import{debounceTime as de}from"rxjs/operators";import{ComponentManager as fe,ContextMenuGroup as pe,ContextMenuPosition as me,IMenuManagerService as he,IZenZoneService as ge,MenuItemType as j,getMenuHiddenObservable as _e,useConfigValue as ve,useDebounceFn as ye,useDependency as M}from"@univerjs/ui";import{AddNoteIcon as N,DeleteNoteIcon as P,HideNoteIcon as be}from"@univerjs/icons";import{Textarea as xe,clsx as F}from"@univerjs/design";import{useCallback as I,useEffect as L,useRef as Se,useState as Ce}from"react";import{jsx as we}from"react/jsx-runtime";function R(e,t){return function(n,r){t(n,r,e)}}function z(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 B=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(h.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe(se(16)).subscribe(()=>{e()}))}};B=z([R(0,s(te)),R(1,s(T)),R(2,v),R(3,o)],B);const V=`SHEET_NOTE_COMPONENT`;function H(e){"@babel/helpers - typeof";return H=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},H(e)}function Te(e,t){if(H(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(H(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ee(e){var t=Te(e,`string`);return H(t)==`symbol`?t:t+``}function U(e,t,n){return(t=Ee(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,U(this,`_lastPopup`,null),U(this,`_activePopup`,void 0),U(this,`_activePopup$`,new ae(null)),U(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:V,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=z([R(0,ge),R(1,s(O))],W);let G=class extends n{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,U(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(k).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?p.NORMAL:a)!==p.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._sheetsNotePopupService.hidePopup();return}let u=l.actualRow,d=l.actualColumn,f=this._sheetsNoteModel.getNote(t,n,{row:u,col:d});f!=null&&f.show||(f?this._sheetsNotePopupService.showPopup({unitId:t,subUnitId:n,noteId:f.id,row:u,col:d}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(de(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,o=this._renderManagerService.getRenderById(n),s=o==null||(t=o.with(k).getSkeletonParam(r))==null?void 0:t.skeleton,c=i,l=a,u=this._sheetsNoteModel.getNote(n,r,{row:c,col:l});if(!u&&s){let{startRow:e,endRow:t,startColumn:o,endColumn:d}=s.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==d){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=d){u=r,c=r.row,l=r.col;break}}}}u!=null&&u.show||(u?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:u.id,row:c,col:l,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};G=z([R(0,s(W)),R(1,s(T)),R(2,s(b)),R(3,ue),R(4,v),R(5,s(le))],G);var De=`@univerjs/sheets-note-ui`,Oe=`0.18.0`;const K=`sheets-note-ui.config`;Symbol(K);const q={};let J=class extends n{constructor(e,t,n,r){super(),this._sheetsNoteModel=e,this._univerInstanceService=t,this._cellPopupManagerService=n,this._sheetsNotePopupService=r,U(this,`_noteMatrix`,new d),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:V,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,t){var n;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d;let r=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(n=this._sheetsNoteModel.getSheetNotes(e,t))==null||n.forEach(n=>{r(e,t,n.row,n.col,n)}),this._sheetsNoteModel.change$.subscribe(n=>{if(!(n.unitId!==e||n.subUnitId!==t))switch(n.type){case`ref`:{let{unitId:e,subUnitId:t,oldNote:r,newNote:i}=n;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,t,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:t,oldNote:i,newNote:a}=n;r(e,t,a?a.row:i.row,a?a.col:i.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(h.UNIVER_SHEET).pipe(D(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?ce(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d}))}};J=z([R(0,s(T)),R(1,s(o)),R(2,s(O)),R(3,s(W))],J);const Y={id:`sheet.operation.add-note-popup`,type:e.OPERATION,handler:async(e,t)=>{var n;let r=e.get(b),i=e.get(W),a=e.get(o).getCurrentUnitForType(h.UNIVER_SHEET);if(!a)return!1;let s=a.getActiveSheet(),c=r.getCurrentLastSelection();if(!(c!=null&&c.primary))return!1;let{primary:l}=c;return i.showPopup({unitId:a.getUnitId(),subUnitId:s.getSheetId(),row:l.actualRow,col:l.actualColumn,temp:!1,trigger:(n=t==null?void 0:t.trigger)==null?`add-note`:n}),!0}};function X(e){let t=e.get(b),n=e.get(o);return t.selectionMoveEnd$.pipe(E(()=>{let r=t.getCurrentLastSelection();if(!(r!=null&&r.primary))return!1;let i=ne(n);if(!i)return!1;let{actualColumn:a,actualRow:o}=r.primary;return!!e.get(T).getNote(i.unitId,i.subUnitId,{row:o,col:a})}))}function ke(e){return{id:Y.id,type:j.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:oe([_e(e,h.UNIVER_SHEET),X(e)]).pipe(E(([e,t])=>e||t)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]}),commandId:Y.id}}function Ae(e){return{id:C.id,type:j.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:X(e).pipe(E(e=>!e)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]})}}function je(e){return{id:w.id,type:j.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:X(e).pipe(E(e=>!e))}}const Me={[me.MAIN_AREA]:{[pe.OTHERS]:{order:0,[Y.id]:{order:0,menuItemFactory:ke},[C.id]:{order:0,menuItemFactory:Ae},[w.id]:{order:0,menuItemFactory:je}}}},Z=e=>{var t;let{popup:n}=e,r=M(T),a=M(u),o=M(v),s=M(W),c=ve(K),l=(t=n.extraProps)==null?void 0:t.location;if(!l)return console.error(`Popup extraProps or location is undefined.`),null;let d=Se(null),f=o.getRenderById(l.unitId),[p,m]=Ce(null);L(()=>{var e,t,n,i,a,o;let{unitId:s,subUnitId:u,row:f,col:p}=l,h=r.getNote(s,u,{row:f,col:p}),_=(e=(t=h==null?void 0:h.width)==null?c==null||(n=c.defaultNoteSize)==null?void 0:n.width:t)==null?160:e,v=(i=(a=h==null?void 0:h.height)==null?c==null||(o=c.defaultNoteSize)==null?void 0:o.height:a)==null?72:i;if(h)m(h);else{let e={id:ee(6),width:_,height:v,note:``};m(e),g(e)}d.current&&(d.current.style.width=`${_}px`,d.current.style.height=`${v}px`)},[l,d]),L(()=>{if(!l||l.temp||!l.trigger||!d.current)return;let e=requestAnimationFrame(()=>{var e;(e=d.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[l]);let h=M(i),g=ye(e=>{if(!l)return;let{unitId:t,subUnitId:n,row:i,col:a}=l;if(!h.syncExecuteCommand(re.id,{unitId:t,sheetId:n,row:i,col:a,note:e})){let o=r.getNote(t,n,{noteId:e.id,row:i,col:a});o?m(o):s.hidePopup(!0)}}),_=I(e=>{if(!p||e===p.note)return;let t={...p,note:e};m(t),g(t)},[p]),y=I((e,t)=>{if(!p||e===p.width&&t===p.height)return;let n={...p,width:e,height:t};m(n),g(n)},[p]);return we(xe,{ref:d,"data-u-comp":`note-textarea`,className:F(`
|
|
2
|
-
univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow
|
|
3
|
-
dark:!univer-bg-gray-800
|
|
4
|
-
`),value:p==null?void 0:p.note,placeholder:a.t(`note.placeholder`),onResize:y,onValueChange:_,onWheel:e=>{document.activeElement!==d.current&&f.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})};let Q=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[V,Z],[`AddNoteIcon`,N],[`DeleteNoteIcon`,P],[`HideNoteIcon`,be]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(Me)}_initCommands(){this._commandService.registerCommand(Y)}};Q=z([R(0,s(fe)),R(1,s(he)),R(2,i)],Q);let $=class extends f{constructor(e=q,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=g({},q,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(K,i)}onStarting(){[[W],[B],[G],[Q],[J]].forEach(e=>{this._injector.add(e)})}onReady(){_(this._injector,[[Q],[B]])}onRendered(){_(this._injector,[[G],[J]])}};U($,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),U($,`packageName`,De),U($,`version`,Oe),U($,`type`,h.UNIVER_SHEET),$=z([t(ie),R(1,s(c)),R(2,a)],$);export{B as SheetsCellContentController,Z as SheetsNote,G as SheetsNotePopupController,W as SheetsNotePopupService,$ as UniverSheetsNoteUIPlugin};
|
|
1
|
+
import{CommandType as e,DependentOn as t,Disposable as n,DisposableCollection as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,InterceptorEffectEnum as l,LocaleService as u,ObjectMatrix as d,Plugin as f,RANGE_TYPE as p,Rectangle as m,UniverInstanceType as h,generateRandomId as ee,merge as g,touchDependencies as _}from"@univerjs/core";import{IRenderManagerService as v}from"@univerjs/engine-render";import{INTERCEPTOR_POINT as y,SheetInterceptorService as te,SheetsSelectionsService as b,WorkbookEditablePermission as x,WorksheetEditPermission as S,getSheetCommandTarget as ne}from"@univerjs/sheets";import{SheetDeleteNoteCommand as C,SheetToggleNotePopupCommand as w,SheetUpdateNoteCommand as re,SheetsNoteModel as T,UniverSheetsNotePlugin as ie}from"@univerjs/sheets-note";import{BehaviorSubject as ae,combineLatest as oe,debounceTime as se,map as E,of as ce,switchMap as D}from"rxjs";import{CellPopupManagerService as O,HoverManagerService as le,IEditorBridgeService as ue,SheetSkeletonManagerService as k,getCurrentRangeDisable$ as A}from"@univerjs/sheets-ui";import{debounceTime as de}from"rxjs/operators";import{ComponentManager as fe,ContextMenuGroup as pe,ContextMenuPosition as me,IMenuManagerService as he,IZenZoneService as ge,MenuItemType as j,getMenuHiddenObservable as _e,useConfigValue as ve,useDebounceFn as ye,useDependency as M}from"@univerjs/ui";import{AddNoteIcon as N,DeleteNoteIcon as P,HideNoteIcon as be}from"@univerjs/icons";import{Textarea as xe,clsx as F}from"@univerjs/design";import{useCallback as I,useEffect as L,useRef as Se,useState as Ce}from"react";import{jsx as we}from"react/jsx-runtime";function R(e,t){return function(n,r){t(n,r,e)}}function z(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 B=class extends n{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.CELL_CONTENT,{effect:l.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let t=this._univerInstanceService.getCurrentUnitForType(h.UNIVER_SHEET);if(!t)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n);r==null||(e=r.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe(se(16)).subscribe(()=>{e()}))}};B=z([R(0,s(te)),R(1,s(T)),R(2,v),R(3,o)],B);const V=`SHEET_NOTE_COMPONENT`;function H(e){"@babel/helpers - typeof";return H=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},H(e)}function Te(e,t){if(H(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(H(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ee(e){var t=Te(e,`string`);return H(t)==`symbol`?t:t+``}function U(e,t,n){return(t=Ee(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let W=class extends n{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,U(this,`_lastPopup`,null),U(this,`_activePopup`,void 0),U(this,`_activePopup$`,new ae(null)),U(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,t){var n;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((n=this.activePopup)==null?void 0:n.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:V,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new r;l.add(c),l.add({dispose:()=>{t==null||t()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};W=z([R(0,ge),R(1,s(O))],W);let G=class extends n{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,U(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,t,n){var r,i,a;let o=(r=e[0])==null?void 0:r.range,s=this._renderManagerService.getRenderById(t),c=s==null||(i=s.with(k).getSkeletonParam(n))==null?void 0:i.skeleton;if(!c||!o)return;let l=c.getCellWithCoordByIndex(o.startRow,o.startColumn);if((((a=o.rangeType)==null?p.NORMAL:a)!==p.NORMAL||o.endColumn-o.startColumn>0||o.endRow-o.startRow>0)&&!((l.isMerged||l.isMergedMainCell)&&m.equals(l.mergeInfo,o))){this._sheetsNotePopupService.hidePopup();return}let u=l.actualRow,d=l.actualColumn,f=this._sheetsNoteModel.getNote(t,n,{row:u,col:d});f!=null&&f.show||(f?this._sheetsNotePopupService.showPopup({unitId:t,subUnitId:n,noteId:f.id,row:u,col:d}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(de(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,o=this._renderManagerService.getRenderById(n),s=o==null||(t=o.with(k).getSkeletonParam(r))==null?void 0:t.skeleton,c=i,l=a,u=this._sheetsNoteModel.getNote(n,r,{row:c,col:l});if(!u&&s){let{startRow:e,endRow:t,startColumn:o,endColumn:d}=s.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==d){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=d){u=r,c=r.row,l=r.col;break}}}}u!=null&&u.show||(u?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:u.id,row:c,col:l,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};G=z([R(0,s(W)),R(1,s(T)),R(2,s(b)),R(3,ue),R(4,v),R(5,s(le))],G);var De=`@univerjs/sheets-note-ui`,Oe=`0.19.0`;const K=`sheets-note-ui.config`;Symbol(K);const q={};let J=class extends n{constructor(e,t,n,r){super(),this._sheetsNoteModel=e,this._univerInstanceService=t,this._cellPopupManagerService=n,this._sheetsNotePopupService=r,U(this,`_noteMatrix`,new d),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:V,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,t){var n;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d;let r=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(n=this._sheetsNoteModel.getSheetNotes(e,t))==null||n.forEach(n=>{r(e,t,n.row,n.col,n)}),this._sheetsNoteModel.change$.subscribe(n=>{if(!(n.unitId!==e||n.subUnitId!==t))switch(n.type){case`ref`:{let{unitId:e,subUnitId:t,oldNote:r,newNote:i}=n;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,t,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:t,oldNote:i,newNote:a}=n;r(e,t,a?a.row:i.row,a?a.col:i.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(h.UNIVER_SHEET).pipe(D(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?ce(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new d}))}};J=z([R(0,s(T)),R(1,s(o)),R(2,s(O)),R(3,s(W))],J);const Y={id:`sheet.operation.add-note-popup`,type:e.OPERATION,handler:async(e,t)=>{var n;let r=e.get(b),i=e.get(W),a=e.get(o).getCurrentUnitForType(h.UNIVER_SHEET);if(!a)return!1;let s=a.getActiveSheet(),c=r.getCurrentLastSelection();if(!(c!=null&&c.primary))return!1;let{primary:l}=c;return i.showPopup({unitId:a.getUnitId(),subUnitId:s.getSheetId(),row:l.actualRow,col:l.actualColumn,temp:!1,trigger:(n=t==null?void 0:t.trigger)==null?`add-note`:n}),!0}};function X(e){let t=e.get(b),n=e.get(o);return t.selectionMoveEnd$.pipe(E(()=>{let r=t.getCurrentLastSelection();if(!(r!=null&&r.primary))return!1;let i=ne(n);if(!i)return!1;let{actualColumn:a,actualRow:o}=r.primary;return!!e.get(T).getNote(i.unitId,i.subUnitId,{row:o,col:a})}))}function ke(e){return{id:Y.id,type:j.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:oe([_e(e,h.UNIVER_SHEET),X(e)]).pipe(E(([e,t])=>e||t)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]}),commandId:Y.id}}function Ae(e){return{id:C.id,type:j.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:X(e).pipe(E(e=>!e)),disabled$:A(e,{workbookTypes:[x],worksheetTypes:[S]})}}function je(e){return{id:w.id,type:j.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:X(e).pipe(E(e=>!e))}}const Me={[me.MAIN_AREA]:{[pe.OTHERS]:{order:0,[Y.id]:{order:0,menuItemFactory:ke},[C.id]:{order:0,menuItemFactory:Ae},[w.id]:{order:0,menuItemFactory:je}}}},Z=e=>{var t;let{popup:n}=e,r=M(T),a=M(u),o=M(v),s=M(W),c=ve(K),l=(t=n.extraProps)==null?void 0:t.location;if(!l)return console.error(`Popup extraProps or location is undefined.`),null;let d=Se(null),f=o.getRenderById(l.unitId),[p,m]=Ce(null);L(()=>{var e,t,n,i,a,o;let{unitId:s,subUnitId:u,row:f,col:p}=l,h=r.getNote(s,u,{row:f,col:p}),_=(e=(t=h==null?void 0:h.width)==null?c==null||(n=c.defaultNoteSize)==null?void 0:n.width:t)==null?160:e,v=(i=(a=h==null?void 0:h.height)==null?c==null||(o=c.defaultNoteSize)==null?void 0:o.height:a)==null?72:i;if(h)m(h);else{let e={id:ee(6),width:_,height:v,note:``};m(e),g(e)}d.current&&(d.current.style.width=`${_}px`,d.current.style.height=`${v}px`)},[l,d]),L(()=>{if(!l||l.temp||!l.trigger||!d.current)return;let e=requestAnimationFrame(()=>{var e;(e=d.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[l]);let h=M(i),g=ye(e=>{if(!l)return;let{unitId:t,subUnitId:n,row:i,col:a}=l;if(!h.syncExecuteCommand(re.id,{unitId:t,sheetId:n,row:i,col:a,note:e})){let o=r.getNote(t,n,{noteId:e.id,row:i,col:a});o?m(o):s.hidePopup(!0)}}),_=I(e=>{if(!p||e===p.note)return;let t={...p,note:e};m(t),g(t)},[p]),y=I((e,t)=>{if(!p||e===p.width&&t===p.height)return;let n={...p,width:e,height:t};m(n),g(n)},[p]);return we(xe,{ref:d,"data-u-comp":`note-textarea`,className:F(`univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow dark:!univer-bg-gray-800`),value:p==null?void 0:p.note,placeholder:a.t(`note.placeholder`),onResize:y,onValueChange:_,onWheel:e=>{document.activeElement!==d.current&&f.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})};let Q=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[V,Z],[`AddNoteIcon`,N],[`DeleteNoteIcon`,P],[`HideNoteIcon`,be]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(Me)}_initCommands(){this._commandService.registerCommand(Y)}};Q=z([R(0,s(fe)),R(1,s(he)),R(2,i)],Q);let $=class extends f{constructor(e=q,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=g({},q,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(K,i)}onStarting(){[[W],[B],[G],[Q],[J]].forEach(e=>{this._injector.add(e)})}onReady(){_(this._injector,[[Q],[B]])}onRendered(){_(this._injector,[[G],[J]])}};U($,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),U($,`packageName`,De),U($,`version`,Oe),U($,`type`,h.UNIVER_SHEET),$=z([t(ie),R(1,s(c)),R(2,a)],$);export{B as SheetsCellContentController,Z as SheetsNote,G as SheetsNotePopupController,W as SheetsNotePopupService,$ as UniverSheetsNoteUIPlugin};
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`@univerjs/sheets`),require(`@univerjs/sheets-note`),require(`rxjs`),require(`@univerjs/sheets-ui`),require(`rxjs/operators`),require(`@univerjs/ui`),require(`react`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-note`,`rxjs`,`@univerjs/sheets-ui`,`rxjs/operators`,`@univerjs/ui`,`react`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNoteUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsNote,e.rxjs,e.UniverSheetsUi,e.rxjs.operators,e.UniverUi,e.React,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function f(e,t){return function(n,r){t(n,r,e)}}function p(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 m=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0,a.debounceTime)(16)).subscribe(()=>{e()}))}};m=p([f(0,(0,t.Inject)(r.SheetInterceptorService)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,n.IRenderManagerService),f(3,t.IUniverInstanceService)],m);let h=`SHEET_NOTE_COMPONENT`;function g(e){"@babel/helpers - typeof";return g=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},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let b=class extends t.Disposable{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,y(this,`_lastPopup`,null),y(this,`_activePopup`,void 0),y(this,`_activePopup$`,new a.BehaviorSubject(null)),y(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:h,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new t.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};b=p([f(0,c.IZenZoneService),f(1,(0,t.Inject)(o.CellPopupManagerService))],b);let x=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,y(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,n,r){var i,a,s;let c=(i=e[0])==null?void 0:i.range,l=this._renderManagerService.getRenderById(n),u=l==null||(a=l.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:a.skeleton;if(!u||!c)return;let d=u.getCellWithCoordByIndex(c.startRow,c.startColumn);if((((s=c.rangeType)==null?t.RANGE_TYPE.NORMAL:s)!==t.RANGE_TYPE.NORMAL||c.endColumn-c.startColumn>0||c.endRow-c.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&t.Rectangle.equals(d.mergeInfo,c))){this._sheetsNotePopupService.hidePopup();return}let f=d.actualRow,p=d.actualColumn,m=this._sheetsNoteModel.getNote(n,r,{row:f,col:p});m!=null&&m.show||(m?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:m.id,row:f,col:p}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,s=this._renderManagerService.getRenderById(n),c=s==null||(t=s.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:t.skeleton,l=i,u=a,d=this._sheetsNoteModel.getNote(n,r,{row:l,col:u});if(!d&&c){let{startRow:e,endRow:t,startColumn:o,endColumn:s}=c.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==s){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=s){d=r,l=r.row,u=r.col;break}}}}d!=null&&d.show||(d?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:d.id,row:l,col:u,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};x=p([f(0,(0,t.Inject)(b)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,(0,t.Inject)(r.SheetsSelectionsService)),f(3,o.IEditorBridgeService),f(4,n.IRenderManagerService),f(5,(0,t.Inject)(o.HoverManagerService))],x);var S=`@univerjs/sheets-note-ui`,C=`0.18.0`;let w=`sheets-note-ui.config`;Symbol(w);let T={},E=class extends t.Disposable{constructor(e,n,r,i){super(),this._sheetsNoteModel=e,this._univerInstanceService=n,this._cellPopupManagerService=r,this._sheetsNotePopupService=i,y(this,`_noteMatrix`,new t.ObjectMatrix),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:h,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,n){var r;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix;let i=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(r=this._sheetsNoteModel.getSheetNotes(e,n))==null||r.forEach(t=>{i(e,n,t.row,t.col,t)}),this._sheetsNoteModel.change$.subscribe(t=>{if(!(t.unitId!==e||t.subUnitId!==n))switch(t.type){case`ref`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:i}=t;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,n,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:a}=t;i(e,n,a?a.row:r.row,a?a.col:r.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,a.of)(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix}))}};E=p([f(0,(0,t.Inject)(i.SheetsNoteModel)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(o.CellPopupManagerService)),f(3,(0,t.Inject)(b))],E);function D({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,l.useRef)(`_${j()}`);return O(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function O(e,t,n,r,i){return(0,l.createElement)(e.tag,{key:t,...k(e,n,i),...r},(A(e,n).children||[]).map((r,a)=>O(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function k(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 A(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 j(){return Math.random().toString(36).substring(2,8)}D.displayName=`UniverIcon`;let M={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:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.8813 14.4312V10.2925C10.8813 9.92522 11.1791 9.62745 11.5463 9.62745C11.9136 9.62745 12.2114 9.92522 12.2114 10.2925V14.4312C12.2112 14.7983 11.9135 15.0962 11.5463 15.0962C11.1791 15.0962 10.8814 14.7983 10.8813 14.4312Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47697 11.6968H11.5463H13.6156C13.9829 11.6968 14.2807 11.9946 14.2807 12.3618C14.2807 12.7291 13.9829 13.0269 13.6156 13.0269H9.47697C9.10981 13.0267 8.81193 12.729 8.81193 12.3618C8.81193 11.9946 9.10981 11.6969 9.47697 11.6968Z`}}]},N=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(D,Object.assign({},e,{id:`add-note-icon`,ref:t,icon:M}))});N.displayName=`AddNoteIcon`;let P={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:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47489 11.6968H13.6175C13.9847 11.6968 14.2825 11.9946 14.2825 12.3618C14.2825 12.7291 13.9847 13.0269 13.6175 13.0269H9.47489C9.10762 13.0269 8.80985 12.7291 8.80985 12.3618C8.80985 11.9946 9.10762 11.6968 9.47489 11.6968Z`}}]},F=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(D,Object.assign({},e,{id:`delete-note-icon`,ref:t,icon:P}))});F.displayName=`DeleteNoteIcon`;let I={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:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13.8743 12.6147C13.8742 12.5394 13.7749 12.2553 13.3909 11.9477C13.039 11.6659 12.5573 11.4614 12.0394 11.4614C11.5213 11.4614 11.0398 11.6666 10.6878 11.9487C10.3037 12.2565 10.2045 12.5399 10.2044 12.6147C10.2044 12.6893 10.3034 12.9737 10.6878 13.2817C11.0398 13.5636 11.5215 13.768 12.0394 13.768C12.5574 13.768 13.039 13.5635 13.3909 13.2817C13.7751 12.9739 13.8743 12.6897 13.8743 12.6147ZM15.2044 12.6147C15.2044 13.2772 14.7436 13.9027 14.223 14.3198C13.6701 14.7627 12.9019 15.0981 12.0394 15.0981C11.1768 15.0981 10.4085 14.7627 9.85577 14.3198C9.33533 13.9027 8.87433 13.2769 8.87433 12.6147C8.8744 11.9526 9.33541 11.3276 9.85577 10.9106C10.4086 10.4676 11.1767 10.1313 12.0394 10.1313C12.9018 10.1313 13.6701 10.4668 14.223 10.9096C14.7435 11.3267 15.2043 11.9523 15.2044 12.6147Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.0394 13.299C12.4172 13.299 12.7234 12.9927 12.7234 12.6149C12.7234 12.2371 12.4172 11.9308 12.0394 11.9308C11.6616 11.9308 11.3553 12.2371 11.3553 12.6149C11.3553 12.9927 11.6616 13.299 12.0394 13.299Z`}}]},L=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(D,Object.assign({},e,{id:`hide-note-icon`,ref:t,icon:I}))});L.displayName=`HideNoteIcon`;let R={id:`sheet.operation.add-note-popup`,type:t.CommandType.OPERATION,handler:async(e,n)=>{var i;let a=e.get(r.SheetsSelectionsService),o=e.get(b),s=e.get(t.IUniverInstanceService).getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;let c=s.getActiveSheet(),l=a.getCurrentLastSelection();if(!(l!=null&&l.primary))return!1;let{primary:u}=l;return o.showPopup({unitId:s.getUnitId(),subUnitId:c.getSheetId(),row:u.actualRow,col:u.actualColumn,temp:!1,trigger:(i=n==null?void 0:n.trigger)==null?`add-note`:i}),!0}};function z(e){let n=e.get(r.SheetsSelectionsService),o=e.get(t.IUniverInstanceService);return n.selectionMoveEnd$.pipe((0,a.map)(()=>{let t=n.getCurrentLastSelection();if(!(t!=null&&t.primary))return!1;let a=(0,r.getSheetCommandTarget)(o);if(!a)return!1;let{actualColumn:s,actualRow:c}=t.primary;return!!e.get(i.SheetsNoteModel).getNote(a.unitId,a.subUnitId,{row:c,col:s})}))}function B(e){return{id:R.id,type:c.MenuItemType.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:(0,a.combineLatest)([(0,c.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),z(e)]).pipe((0,a.map)(([e,t])=>e||t)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]}),commandId:R.id}}function V(e){return{id:i.SheetDeleteNoteCommand.id,type:c.MenuItemType.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:z(e).pipe((0,a.map)(e=>!e)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]})}}function H(e){return{id:i.SheetToggleNotePopupCommand.id,type:c.MenuItemType.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:z(e).pipe((0,a.map)(e=>!e))}}let U={[c.ContextMenuPosition.MAIN_AREA]:{[c.ContextMenuGroup.OTHERS]:{order:0,[R.id]:{order:0,menuItemFactory:B},[i.SheetDeleteNoteCommand.id]:{order:0,menuItemFactory:V},[i.SheetToggleNotePopupCommand.id]:{order:0,menuItemFactory:H}}}},W=e=>{var r;let{popup:a}=e,o=(0,c.useDependency)(i.SheetsNoteModel),s=(0,c.useDependency)(t.LocaleService),f=(0,c.useDependency)(n.IRenderManagerService),p=(0,c.useDependency)(b),m=(0,c.useConfigValue)(w),h=(r=a.extraProps)==null?void 0:r.location;if(!h)return console.error(`Popup extraProps or location is undefined.`),null;let g=(0,l.useRef)(null),_=f.getRenderById(h.unitId),[v,y]=(0,l.useState)(null);(0,l.useEffect)(()=>{var e,n,r,i,a,s;let{unitId:c,subUnitId:l,row:u,col:d}=h,f=o.getNote(c,l,{row:u,col:d}),p=(e=(n=f==null?void 0:f.width)==null?m==null||(r=m.defaultNoteSize)==null?void 0:r.width:n)==null?160:e,_=(i=(a=f==null?void 0:f.height)==null?m==null||(s=m.defaultNoteSize)==null?void 0:s.height:a)==null?72:i;if(f)y(f);else{let e={id:(0,t.generateRandomId)(6),width:p,height:_,note:``};y(e),S(e)}g.current&&(g.current.style.width=`${p}px`,g.current.style.height=`${_}px`)},[h,g]),(0,l.useEffect)(()=>{if(!h||h.temp||!h.trigger||!g.current)return;let e=requestAnimationFrame(()=>{var e;(e=g.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[h]);let x=(0,c.useDependency)(t.ICommandService),S=(0,c.useDebounceFn)(e=>{if(!h)return;let{unitId:t,subUnitId:n,row:r,col:a}=h;if(!x.syncExecuteCommand(i.SheetUpdateNoteCommand.id,{unitId:t,sheetId:n,row:r,col:a,note:e})){let i=o.getNote(t,n,{noteId:e.id,row:r,col:a});i?y(i):p.hidePopup(!0)}}),C=(0,l.useCallback)(e=>{if(!v||e===v.note)return;let t={...v,note:e};y(t),S(t)},[v]),T=(0,l.useCallback)((e,t)=>{if(!v||e===v.width&&t===v.height)return;let n={...v,width:e,height:t};y(n),S(n)},[v]);return(0,d.jsx)(u.Textarea,{ref:g,"data-u-comp":`note-textarea`,className:(0,u.clsx)(`
|
|
2
|
-
univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow
|
|
3
|
-
dark:!univer-bg-gray-800
|
|
4
|
-
`),value:v==null?void 0:v.note,placeholder:s.t(`note.placeholder`),onResize:T,onValueChange:C,onWheel:e=>{document.activeElement!==g.current&&_.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})},G=class extends t.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[h,W],[`AddNoteIcon`,N],[`DeleteNoteIcon`,F],[`HideNoteIcon`,L]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(U)}_initCommands(){this._commandService.registerCommand(R)}};G=p([f(0,(0,t.Inject)(c.ComponentManager)),f(1,(0,t.Inject)(c.IMenuManagerService)),f(2,t.ICommandService)],G);let K=class extends t.Plugin{constructor(e=T,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},T,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(w,a)}onStarting(){[[b],[m],[x],[G],[E]].forEach(e=>{this._injector.add(e)})}onReady(){(0,t.touchDependencies)(this._injector,[[G],[m]])}onRendered(){(0,t.touchDependencies)(this._injector,[[x],[E]])}};y(K,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),y(K,`packageName`,S),y(K,`version`,C),y(K,`type`,t.UniverInstanceType.UNIVER_SHEET),K=p([(0,t.DependentOn)(i.UniverSheetsNotePlugin),f(1,(0,t.Inject)(t.Injector)),f(2,t.IConfigService)],K),Object.defineProperty(e,`SheetsCellContentController`,{enumerable:!0,get:function(){return m}}),e.SheetsNote=W,Object.defineProperty(e,`SheetsNotePopupController`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(e,`SheetsNotePopupService`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(e,`UniverSheetsNoteUIPlugin`,{enumerable:!0,get:function(){return K}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`@univerjs/sheets`),require(`@univerjs/sheets-note`),require(`rxjs`),require(`@univerjs/sheets-ui`),require(`rxjs/operators`),require(`@univerjs/ui`),require(`react`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-note`,`rxjs`,`@univerjs/sheets-ui`,`rxjs/operators`,`@univerjs/ui`,`react`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNoteUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsNote,e.rxjs,e.UniverSheetsUi,e.rxjs.operators,e.UniverUi,e.React,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function f(e,t){return function(n,r){t(n,r,e)}}function p(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 m=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0,a.debounceTime)(16)).subscribe(()=>{e()}))}};m=p([f(0,(0,t.Inject)(r.SheetInterceptorService)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,n.IRenderManagerService),f(3,t.IUniverInstanceService)],m);let h=`SHEET_NOTE_COMPONENT`;function g(e){"@babel/helpers - typeof";return g=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},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let b=class extends t.Disposable{get activePopup(){return this._activePopup}constructor(e,t){super(),this._zenZoneService=e,this._cellPopupManagerService=t,y(this,`_lastPopup`,null),y(this,`_activePopup`,void 0),y(this,`_activePopup$`,new a.BehaviorSubject(null)),y(this,`activePopup$`,this._activePopup$.asObservable()),this._initZenVisible(),this.disposeWithMe(()=>{this._activePopup$.complete()})}_initZenVisible(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this.hidePopup()}))}dispose(){super.dispose(),this.hidePopup()}showPopup(e,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}if(this._lastPopup&&this._lastPopup.dispose(),this._zenZoneService.visible)return;this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:h,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new t.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};b=p([f(0,c.IZenZoneService),f(1,(0,t.Inject)(o.CellPopupManagerService))],b);let x=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,y(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,n,r){var i,a,s;let c=(i=e[0])==null?void 0:i.range,l=this._renderManagerService.getRenderById(n),u=l==null||(a=l.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:a.skeleton;if(!u||!c)return;let d=u.getCellWithCoordByIndex(c.startRow,c.startColumn);if((((s=c.rangeType)==null?t.RANGE_TYPE.NORMAL:s)!==t.RANGE_TYPE.NORMAL||c.endColumn-c.startColumn>0||c.endRow-c.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&t.Rectangle.equals(d.mergeInfo,c))){this._sheetsNotePopupService.hidePopup();return}let f=d.actualRow,p=d.actualColumn,m=this._sheetsNoteModel.getNote(n,r,{row:f,col:p});m!=null&&m.show||(m?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:m.id,row:f,col:p}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,s=this._renderManagerService.getRenderById(n),c=s==null||(t=s.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:t.skeleton,l=i,u=a,d=this._sheetsNoteModel.getNote(n,r,{row:l,col:u});if(!d&&c){let{startRow:e,endRow:t,startColumn:o,endColumn:s}=c.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==s){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=s){d=r,l=r.row,u=r.col;break}}}}d!=null&&d.show||(d?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:d.id,row:l,col:u,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};x=p([f(0,(0,t.Inject)(b)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,(0,t.Inject)(r.SheetsSelectionsService)),f(3,o.IEditorBridgeService),f(4,n.IRenderManagerService),f(5,(0,t.Inject)(o.HoverManagerService))],x);var S=`@univerjs/sheets-note-ui`,C=`0.19.0`;let w=`sheets-note-ui.config`;Symbol(w);let T={},E=class extends t.Disposable{constructor(e,n,r,i){super(),this._sheetsNoteModel=e,this._univerInstanceService=n,this._cellPopupManagerService=r,this._sheetsNotePopupService=i,y(this,`_noteMatrix`,new t.ObjectMatrix),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:h,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,n){var r;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix;let i=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(r=this._sheetsNoteModel.getSheetNotes(e,n))==null||r.forEach(t=>{i(e,n,t.row,t.col,t)}),this._sheetsNoteModel.change$.subscribe(t=>{if(!(t.unitId!==e||t.subUnitId!==n))switch(t.type){case`ref`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:i}=t;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,n,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:a}=t;i(e,n,a?a.row:r.row,a?a.col:r.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,a.of)(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix}))}};E=p([f(0,(0,t.Inject)(i.SheetsNoteModel)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(o.CellPopupManagerService)),f(3,(0,t.Inject)(b))],E);function D({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,l.useRef)(`_${j()}`);return O(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function O(e,t,n,r,i){return(0,l.createElement)(e.tag,{key:t,...k(e,n,i),...r},(A(e,n).children||[]).map((r,a)=>O(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function k(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 A(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 j(){return Math.random().toString(36).substring(2,8)}D.displayName=`UniverIcon`;let M={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:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.8813 14.4312V10.2925C10.8813 9.92522 11.1791 9.62745 11.5463 9.62745C11.9136 9.62745 12.2114 9.92522 12.2114 10.2925V14.4312C12.2112 14.7983 11.9135 15.0962 11.5463 15.0962C11.1791 15.0962 10.8814 14.7983 10.8813 14.4312Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47697 11.6968H11.5463H13.6156C13.9829 11.6968 14.2807 11.9946 14.2807 12.3618C14.2807 12.7291 13.9829 13.0269 13.6156 13.0269H9.47697C9.10981 13.0267 8.81193 12.729 8.81193 12.3618C8.81193 11.9946 9.10981 11.6969 9.47697 11.6968Z`}}]},N=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(D,Object.assign({},e,{id:`add-note-icon`,ref:t,icon:M}))});N.displayName=`AddNoteIcon`;let P={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:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47489 11.6968H13.6175C13.9847 11.6968 14.2825 11.9946 14.2825 12.3618C14.2825 12.7291 13.9847 13.0269 13.6175 13.0269H9.47489C9.10762 13.0269 8.80985 12.7291 8.80985 12.3618C8.80985 11.9946 9.10762 11.6968 9.47489 11.6968Z`}}]},F=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(D,Object.assign({},e,{id:`delete-note-icon`,ref:t,icon:P}))});F.displayName=`DeleteNoteIcon`;let I={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:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13.8743 12.6147C13.8742 12.5394 13.7749 12.2553 13.3909 11.9477C13.039 11.6659 12.5573 11.4614 12.0394 11.4614C11.5213 11.4614 11.0398 11.6666 10.6878 11.9487C10.3037 12.2565 10.2045 12.5399 10.2044 12.6147C10.2044 12.6893 10.3034 12.9737 10.6878 13.2817C11.0398 13.5636 11.5215 13.768 12.0394 13.768C12.5574 13.768 13.039 13.5635 13.3909 13.2817C13.7751 12.9739 13.8743 12.6897 13.8743 12.6147ZM15.2044 12.6147C15.2044 13.2772 14.7436 13.9027 14.223 14.3198C13.6701 14.7627 12.9019 15.0981 12.0394 15.0981C11.1768 15.0981 10.4085 14.7627 9.85577 14.3198C9.33533 13.9027 8.87433 13.2769 8.87433 12.6147C8.8744 11.9526 9.33541 11.3276 9.85577 10.9106C10.4086 10.4676 11.1767 10.1313 12.0394 10.1313C12.9018 10.1313 13.6701 10.4668 14.223 10.9096C14.7435 11.3267 15.2043 11.9523 15.2044 12.6147Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.0394 13.299C12.4172 13.299 12.7234 12.9927 12.7234 12.6149C12.7234 12.2371 12.4172 11.9308 12.0394 11.9308C11.6616 11.9308 11.3553 12.2371 11.3553 12.6149C11.3553 12.9927 11.6616 13.299 12.0394 13.299Z`}}]},L=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(D,Object.assign({},e,{id:`hide-note-icon`,ref:t,icon:I}))});L.displayName=`HideNoteIcon`;let R={id:`sheet.operation.add-note-popup`,type:t.CommandType.OPERATION,handler:async(e,n)=>{var i;let a=e.get(r.SheetsSelectionsService),o=e.get(b),s=e.get(t.IUniverInstanceService).getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;let c=s.getActiveSheet(),l=a.getCurrentLastSelection();if(!(l!=null&&l.primary))return!1;let{primary:u}=l;return o.showPopup({unitId:s.getUnitId(),subUnitId:c.getSheetId(),row:u.actualRow,col:u.actualColumn,temp:!1,trigger:(i=n==null?void 0:n.trigger)==null?`add-note`:i}),!0}};function z(e){let n=e.get(r.SheetsSelectionsService),o=e.get(t.IUniverInstanceService);return n.selectionMoveEnd$.pipe((0,a.map)(()=>{let t=n.getCurrentLastSelection();if(!(t!=null&&t.primary))return!1;let a=(0,r.getSheetCommandTarget)(o);if(!a)return!1;let{actualColumn:s,actualRow:c}=t.primary;return!!e.get(i.SheetsNoteModel).getNote(a.unitId,a.subUnitId,{row:c,col:s})}))}function B(e){return{id:R.id,type:c.MenuItemType.BUTTON,title:`rightClick.addNote`,icon:`AddNoteIcon`,hidden$:(0,a.combineLatest)([(0,c.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),z(e)]).pipe((0,a.map)(([e,t])=>e||t)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]}),commandId:R.id}}function V(e){return{id:i.SheetDeleteNoteCommand.id,type:c.MenuItemType.BUTTON,title:`rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:z(e).pipe((0,a.map)(e=>!e)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]})}}function H(e){return{id:i.SheetToggleNotePopupCommand.id,type:c.MenuItemType.BUTTON,title:`rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:z(e).pipe((0,a.map)(e=>!e))}}let U={[c.ContextMenuPosition.MAIN_AREA]:{[c.ContextMenuGroup.OTHERS]:{order:0,[R.id]:{order:0,menuItemFactory:B},[i.SheetDeleteNoteCommand.id]:{order:0,menuItemFactory:V},[i.SheetToggleNotePopupCommand.id]:{order:0,menuItemFactory:H}}}},W=e=>{var r;let{popup:a}=e,o=(0,c.useDependency)(i.SheetsNoteModel),s=(0,c.useDependency)(t.LocaleService),f=(0,c.useDependency)(n.IRenderManagerService),p=(0,c.useDependency)(b),m=(0,c.useConfigValue)(w),h=(r=a.extraProps)==null?void 0:r.location;if(!h)return console.error(`Popup extraProps or location is undefined.`),null;let g=(0,l.useRef)(null),_=f.getRenderById(h.unitId),[v,y]=(0,l.useState)(null);(0,l.useEffect)(()=>{var e,n,r,i,a,s;let{unitId:c,subUnitId:l,row:u,col:d}=h,f=o.getNote(c,l,{row:u,col:d}),p=(e=(n=f==null?void 0:f.width)==null?m==null||(r=m.defaultNoteSize)==null?void 0:r.width:n)==null?160:e,_=(i=(a=f==null?void 0:f.height)==null?m==null||(s=m.defaultNoteSize)==null?void 0:s.height:a)==null?72:i;if(f)y(f);else{let e={id:(0,t.generateRandomId)(6),width:p,height:_,note:``};y(e),S(e)}g.current&&(g.current.style.width=`${p}px`,g.current.style.height=`${_}px`)},[h,g]),(0,l.useEffect)(()=>{if(!h||h.temp||!h.trigger||!g.current)return;let e=requestAnimationFrame(()=>{var e;(e=g.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[h]);let x=(0,c.useDependency)(t.ICommandService),S=(0,c.useDebounceFn)(e=>{if(!h)return;let{unitId:t,subUnitId:n,row:r,col:a}=h;if(!x.syncExecuteCommand(i.SheetUpdateNoteCommand.id,{unitId:t,sheetId:n,row:r,col:a,note:e})){let i=o.getNote(t,n,{noteId:e.id,row:r,col:a});i?y(i):p.hidePopup(!0)}}),C=(0,l.useCallback)(e=>{if(!v||e===v.note)return;let t={...v,note:e};y(t),S(t)},[v]),T=(0,l.useCallback)((e,t)=>{if(!v||e===v.width&&t===v.height)return;let n={...v,width:e,height:t};y(n),S(n)},[v]);return(0,d.jsx)(u.Textarea,{ref:g,"data-u-comp":`note-textarea`,className:(0,u.clsx)(`univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow dark:!univer-bg-gray-800`),value:v==null?void 0:v.note,placeholder:s.t(`note.placeholder`),onResize:T,onValueChange:C,onWheel:e=>{document.activeElement!==g.current&&_.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})},G=class extends t.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._menuManagerService=t,this._commandService=n,this._initComponents(),this._initMenu(),this._initCommands()}_initComponents(){[[h,W],[`AddNoteIcon`,N],[`DeleteNoteIcon`,F],[`HideNoteIcon`,L]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(U)}_initCommands(){this._commandService.registerCommand(R)}};G=p([f(0,(0,t.Inject)(c.ComponentManager)),f(1,(0,t.Inject)(c.IMenuManagerService)),f(2,t.ICommandService)],G);let K=class extends t.Plugin{constructor(e=T,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},T,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(w,a)}onStarting(){[[b],[m],[x],[G],[E]].forEach(e=>{this._injector.add(e)})}onReady(){(0,t.touchDependencies)(this._injector,[[G],[m]])}onRendered(){(0,t.touchDependencies)(this._injector,[[x],[E]])}};y(K,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),y(K,`packageName`,S),y(K,`version`,C),y(K,`type`,t.UniverInstanceType.UNIVER_SHEET),K=p([(0,t.DependentOn)(i.UniverSheetsNotePlugin),f(1,(0,t.Inject)(t.Injector)),f(2,t.IConfigService)],K),Object.defineProperty(e,`SheetsCellContentController`,{enumerable:!0,get:function(){return m}}),e.SheetsNote=W,Object.defineProperty(e,`SheetsNotePopupController`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(e,`SheetsNotePopupService`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(e,`UniverSheetsNoteUIPlugin`,{enumerable:!0,get:function(){return K}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-note-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer sheets note UI plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -51,22 +51,22 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@univerjs/icons": "^1.1.1",
|
|
54
|
-
"@univerjs/core": "0.
|
|
55
|
-
"@univerjs/design": "0.
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/sheets
|
|
58
|
-
"@univerjs/sheets-
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/ui": "0.
|
|
54
|
+
"@univerjs/core": "0.19.0",
|
|
55
|
+
"@univerjs/design": "0.19.0",
|
|
56
|
+
"@univerjs/engine-render": "0.19.0",
|
|
57
|
+
"@univerjs/sheets": "0.19.0",
|
|
58
|
+
"@univerjs/sheets-note": "0.19.0",
|
|
59
|
+
"@univerjs/sheets-ui": "0.19.0",
|
|
60
|
+
"@univerjs/ui": "0.19.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"postcss": "^8.5.8",
|
|
64
64
|
"react": "18.3.1",
|
|
65
65
|
"rxjs": "^7.8.2",
|
|
66
66
|
"tailwindcss": "3.4.18",
|
|
67
|
-
"typescript": "^
|
|
68
|
-
"vitest": "^4.1.
|
|
69
|
-
"@univerjs-infra/shared": "0.
|
|
67
|
+
"typescript": "^6.0.2",
|
|
68
|
+
"vitest": "^4.1.1",
|
|
69
|
+
"@univerjs-infra/shared": "0.19.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"test": "vitest run",
|