@univerjs/sheets-note-ui 0.20.1 → 0.21.0-insiders.20260424-262d69f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/cjs/index.js +789 -1
  2. package/lib/cjs/locale/ca-ES.js +13 -1
  3. package/lib/cjs/locale/en-US.js +28 -1
  4. package/lib/cjs/locale/es-ES.js +13 -1
  5. package/lib/cjs/locale/fa-IR.js +13 -1
  6. package/lib/cjs/locale/fr-FR.js +13 -1
  7. package/lib/cjs/locale/ja-JP.js +13 -1
  8. package/lib/cjs/locale/ko-KR.js +13 -1
  9. package/lib/cjs/locale/ru-RU.js +13 -1
  10. package/lib/cjs/locale/sk-SK.js +13 -1
  11. package/lib/cjs/locale/vi-VN.js +13 -1
  12. package/lib/cjs/locale/zh-CN.js +13 -1
  13. package/lib/cjs/locale/zh-TW.js +13 -1
  14. package/lib/es/index.js +764 -1
  15. package/lib/es/locale/ca-ES.js +12 -1
  16. package/lib/es/locale/en-US.js +27 -1
  17. package/lib/es/locale/es-ES.js +12 -1
  18. package/lib/es/locale/fa-IR.js +12 -1
  19. package/lib/es/locale/fr-FR.js +12 -1
  20. package/lib/es/locale/ja-JP.js +12 -1
  21. package/lib/es/locale/ko-KR.js +12 -1
  22. package/lib/es/locale/ru-RU.js +12 -1
  23. package/lib/es/locale/sk-SK.js +12 -1
  24. package/lib/es/locale/vi-VN.js +12 -1
  25. package/lib/es/locale/zh-CN.js +12 -1
  26. package/lib/es/locale/zh-TW.js +12 -1
  27. package/lib/index.js +764 -1
  28. package/lib/locale/ca-ES.js +12 -1
  29. package/lib/locale/en-US.js +27 -1
  30. package/lib/locale/es-ES.js +12 -1
  31. package/lib/locale/fa-IR.js +12 -1
  32. package/lib/locale/fr-FR.js +12 -1
  33. package/lib/locale/ja-JP.js +12 -1
  34. package/lib/locale/ko-KR.js +12 -1
  35. package/lib/locale/ru-RU.js +12 -1
  36. package/lib/locale/sk-SK.js +12 -1
  37. package/lib/locale/vi-VN.js +12 -1
  38. package/lib/locale/zh-CN.js +12 -1
  39. package/lib/locale/zh-TW.js +12 -1
  40. package/lib/umd/index.js +1 -1
  41. package/package.json +11 -11
  42. package/LICENSE +0 -176
package/lib/cjs/index.js CHANGED
@@ -1 +1,789 @@
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.20.1`;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}});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_engine_render = require("@univerjs/engine-render");
4
+ let _univerjs_sheets = require("@univerjs/sheets");
5
+ let _univerjs_sheets_note = require("@univerjs/sheets-note");
6
+ let rxjs = require("rxjs");
7
+ let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
8
+ let rxjs_operators = require("rxjs/operators");
9
+ let _univerjs_ui = require("@univerjs/ui");
10
+ let _univerjs_icons = require("@univerjs/icons");
11
+ let _univerjs_design = require("@univerjs/design");
12
+ let react = require("react");
13
+ let react_jsx_runtime = require("react/jsx-runtime");
14
+
15
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
16
+ function __decorateParam(paramIndex, decorator) {
17
+ return function(target, key) {
18
+ decorator(target, key, paramIndex);
19
+ };
20
+ }
21
+
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
24
+ function __decorate(decorators, target, key, desc) {
25
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
26
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
27
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
28
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
29
+ }
30
+
31
+ //#endregion
32
+ //#region src/controllers/sheets-cell-content.controller.ts
33
+ let SheetsCellContentController = class SheetsCellContentController extends _univerjs_core.Disposable {
34
+ constructor(_sheetInterceptorService, _sheetsNoteModel, _renderManagerService, _univerInstanceService) {
35
+ super();
36
+ this._sheetInterceptorService = _sheetInterceptorService;
37
+ this._sheetsNoteModel = _sheetsNoteModel;
38
+ this._renderManagerService = _renderManagerService;
39
+ this._univerInstanceService = _univerInstanceService;
40
+ this._initViewModelIntercept();
41
+ this._initSkeletonChange();
42
+ }
43
+ _initViewModelIntercept() {
44
+ this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
45
+ effect: _univerjs_core.InterceptorEffectEnum.Style,
46
+ handler: (cell, pos, next) => {
47
+ const { row, col, unitId, subUnitId } = pos;
48
+ if (this._sheetsNoteModel.getNote(unitId, subUnitId, {
49
+ row,
50
+ col
51
+ })) {
52
+ if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
53
+ cell.markers = {
54
+ ...cell === null || cell === void 0 ? void 0 : cell.markers,
55
+ tr: {
56
+ color: "#FFBD37",
57
+ size: 6
58
+ }
59
+ };
60
+ return next(cell);
61
+ }
62
+ return next(cell);
63
+ },
64
+ priority: 100
65
+ }));
66
+ }
67
+ _initSkeletonChange() {
68
+ const markSkeletonDirty = () => {
69
+ var _currentRender$mainCo;
70
+ const workbook = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
71
+ if (!workbook) return;
72
+ const unitId = workbook.getUnitId();
73
+ const currentRender = this._renderManagerService.getRenderById(unitId);
74
+ currentRender === null || currentRender === void 0 || (_currentRender$mainCo = currentRender.mainComponent) === null || _currentRender$mainCo === void 0 || _currentRender$mainCo.makeForceDirty();
75
+ };
76
+ this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0, rxjs.debounceTime)(16)).subscribe(() => {
77
+ markSkeletonDirty();
78
+ }));
79
+ }
80
+ };
81
+ SheetsCellContentController = __decorate([
82
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
83
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_note.SheetsNoteModel)),
84
+ __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
85
+ __decorateParam(3, _univerjs_core.IUniverInstanceService)
86
+ ], SheetsCellContentController);
87
+
88
+ //#endregion
89
+ //#region src/views/config.ts
90
+ /**
91
+ * Copyright 2023-present DreamNum Co., Ltd.
92
+ *
93
+ * Licensed under the Apache License, Version 2.0 (the "License");
94
+ * you may not use this file except in compliance with the License.
95
+ * You may obtain a copy of the License at
96
+ *
97
+ * http://www.apache.org/licenses/LICENSE-2.0
98
+ *
99
+ * Unless required by applicable law or agreed to in writing, software
100
+ * distributed under the License is distributed on an "AS IS" BASIS,
101
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102
+ * See the License for the specific language governing permissions and
103
+ * limitations under the License.
104
+ */
105
+ const SHEET_NOTE_COMPONENT = "SHEET_NOTE_COMPONENT";
106
+
107
+ //#endregion
108
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
109
+ function _typeof(o) {
110
+ "@babel/helpers - typeof";
111
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
112
+ return typeof o;
113
+ } : function(o) {
114
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
115
+ }, _typeof(o);
116
+ }
117
+
118
+ //#endregion
119
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
120
+ function toPrimitive(t, r) {
121
+ if ("object" != _typeof(t) || !t) return t;
122
+ var e = t[Symbol.toPrimitive];
123
+ if (void 0 !== e) {
124
+ var i = e.call(t, r || "default");
125
+ if ("object" != _typeof(i)) return i;
126
+ throw new TypeError("@@toPrimitive must return a primitive value.");
127
+ }
128
+ return ("string" === r ? String : Number)(t);
129
+ }
130
+
131
+ //#endregion
132
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
133
+ function toPropertyKey(t) {
134
+ var i = toPrimitive(t, "string");
135
+ return "symbol" == _typeof(i) ? i : i + "";
136
+ }
137
+
138
+ //#endregion
139
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
140
+ function _defineProperty(e, r, t) {
141
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
142
+ value: t,
143
+ enumerable: !0,
144
+ configurable: !0,
145
+ writable: !0
146
+ }) : e[r] = t, e;
147
+ }
148
+
149
+ //#endregion
150
+ //#region src/services/sheets-note-popup.service.ts
151
+ let SheetsNotePopupService = class SheetsNotePopupService extends _univerjs_core.Disposable {
152
+ get activePopup() {
153
+ return this._activePopup;
154
+ }
155
+ constructor(_zenZoneService, _cellPopupManagerService) {
156
+ super();
157
+ this._zenZoneService = _zenZoneService;
158
+ this._cellPopupManagerService = _cellPopupManagerService;
159
+ _defineProperty(this, "_lastPopup", null);
160
+ _defineProperty(this, "_activePopup", void 0);
161
+ _defineProperty(this, "_activePopup$", new rxjs.BehaviorSubject(null));
162
+ _defineProperty(this, "activePopup$", this._activePopup$.asObservable());
163
+ this._initZenVisible();
164
+ this.disposeWithMe(() => {
165
+ this._activePopup$.complete();
166
+ });
167
+ }
168
+ _initZenVisible() {
169
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
170
+ if (visible) this.hidePopup();
171
+ }));
172
+ }
173
+ dispose() {
174
+ super.dispose();
175
+ this.hidePopup();
176
+ }
177
+ showPopup(location, onHide) {
178
+ var _this$activePopup;
179
+ const { row, col, unitId, subUnitId } = location;
180
+ if (this._activePopup && row === this._activePopup.row && col === this._activePopup.col && unitId === this._activePopup.unitId && subUnitId === ((_this$activePopup = this.activePopup) === null || _this$activePopup === void 0 ? void 0 : _this$activePopup.subUnitId)) {
181
+ this._activePopup = location;
182
+ this._activePopup$.next(location);
183
+ return;
184
+ }
185
+ if (this._lastPopup) this._lastPopup.dispose();
186
+ if (this._zenZoneService.visible) return;
187
+ this._activePopup = location;
188
+ this._activePopup$.next(location);
189
+ const popupDisposable = this._cellPopupManagerService.showPopup({
190
+ unitId,
191
+ subUnitId,
192
+ row,
193
+ col
194
+ }, {
195
+ componentKey: SHEET_NOTE_COMPONENT,
196
+ onClickOutside: () => {
197
+ this.hidePopup();
198
+ },
199
+ direction: "horizontal",
200
+ extraProps: { location },
201
+ priority: 3
202
+ });
203
+ if (!popupDisposable) throw new Error("[SheetsNotePopupService]: cannot show popup!");
204
+ const disposableCollection = new _univerjs_core.DisposableCollection();
205
+ disposableCollection.add(popupDisposable);
206
+ disposableCollection.add({ dispose: () => {
207
+ onHide === null || onHide === void 0 || onHide();
208
+ } });
209
+ this._lastPopup = disposableCollection;
210
+ }
211
+ hidePopup(force) {
212
+ if (!this._activePopup) return;
213
+ if (!force && !this._activePopup.temp) return;
214
+ if (this._lastPopup) this._lastPopup.dispose();
215
+ this._lastPopup = null;
216
+ this._activePopup = null;
217
+ this._activePopup$.next(null);
218
+ }
219
+ persistPopup() {
220
+ if (!this._activePopup || !this._activePopup.temp) return;
221
+ this._activePopup = {
222
+ ...this._activePopup,
223
+ temp: false
224
+ };
225
+ this._activePopup$.next(this._activePopup);
226
+ }
227
+ };
228
+ SheetsNotePopupService = __decorate([__decorateParam(0, _univerjs_ui.IZenZoneService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellPopupManagerService))], SheetsNotePopupService);
229
+
230
+ //#endregion
231
+ //#region src/controllers/sheets-note-popup.controller.ts
232
+ let SheetsNotePopupController = class SheetsNotePopupController extends _univerjs_core.Disposable {
233
+ constructor(_sheetsNotePopupService, _sheetsNoteModel, _sheetSelectionService, _editorBridgeService, _renderManagerService, _hoverManagerService) {
234
+ super();
235
+ this._sheetsNotePopupService = _sheetsNotePopupService;
236
+ this._sheetsNoteModel = _sheetsNoteModel;
237
+ this._sheetSelectionService = _sheetSelectionService;
238
+ this._editorBridgeService = _editorBridgeService;
239
+ this._renderManagerService = _renderManagerService;
240
+ this._hoverManagerService = _hoverManagerService;
241
+ _defineProperty(this, "_isSwitchingSheet", false);
242
+ this._initSelectionUpdateListener();
243
+ this._initEditorBridge();
244
+ this._initHoverEvent();
245
+ this._initDeleteNoteListener();
246
+ }
247
+ _handleSelectionChange(selections, unitId, subUnitId) {
248
+ var _selections$, _render$with$getSkele, _range$rangeType;
249
+ const range = (_selections$ = selections[0]) === null || _selections$ === void 0 ? void 0 : _selections$.range;
250
+ const render = this._renderManagerService.getRenderById(unitId);
251
+ const skeleton = render === null || render === void 0 || (_render$with$getSkele = render.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _render$with$getSkele === void 0 ? void 0 : _render$with$getSkele.skeleton;
252
+ if (!skeleton) return;
253
+ if (!range) return;
254
+ const actualCell = skeleton.getCellWithCoordByIndex(range.startRow, range.startColumn);
255
+ if ((((_range$rangeType = range.rangeType) !== null && _range$rangeType !== void 0 ? _range$rangeType : _univerjs_core.RANGE_TYPE.NORMAL) !== _univerjs_core.RANGE_TYPE.NORMAL || range.endColumn - range.startColumn > 0 || range.endRow - range.startRow > 0) && !((actualCell.isMerged || actualCell.isMergedMainCell) && _univerjs_core.Rectangle.equals(actualCell.mergeInfo, range))) {
256
+ this._sheetsNotePopupService.hidePopup();
257
+ return;
258
+ }
259
+ const row = actualCell.actualRow;
260
+ const col = actualCell.actualColumn;
261
+ const note = this._sheetsNoteModel.getNote(unitId, subUnitId, {
262
+ row,
263
+ col
264
+ });
265
+ if (note === null || note === void 0 ? void 0 : note.show) return;
266
+ if (note) this._sheetsNotePopupService.showPopup({
267
+ unitId,
268
+ subUnitId,
269
+ noteId: note.id,
270
+ row,
271
+ col
272
+ });
273
+ else this._sheetsNotePopupService.hidePopup(true);
274
+ }
275
+ _initSelectionUpdateListener() {
276
+ this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe((selections) => {
277
+ if (this._isSwitchingSheet) return;
278
+ const current = this._sheetSelectionService.currentSelectionParam;
279
+ if (!current) return;
280
+ this._handleSelectionChange(selections, current.unitId, current.sheetId);
281
+ }));
282
+ }
283
+ _initEditorBridge() {
284
+ this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
285
+ if (visible.visible) this._sheetsNotePopupService.hidePopup(true);
286
+ }));
287
+ }
288
+ _initHoverEvent() {
289
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs_operators.debounceTime)(100)).subscribe((cell) => {
290
+ var _render$with$getSkele2;
291
+ if (!(cell === null || cell === void 0 ? void 0 : cell.location)) return;
292
+ const { unitId, subUnitId, row, col } = cell.location;
293
+ const render = this._renderManagerService.getRenderById(unitId);
294
+ const skeleton = render === null || render === void 0 || (_render$with$getSkele2 = render.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _render$with$getSkele2 === void 0 ? void 0 : _render$with$getSkele2.skeleton;
295
+ let targetRow = row;
296
+ let targetCol = col;
297
+ let note = this._sheetsNoteModel.getNote(unitId, subUnitId, {
298
+ row: targetRow,
299
+ col: targetCol
300
+ });
301
+ if (!note && skeleton) {
302
+ const { startRow, endRow, startColumn, endColumn } = skeleton.getCellWithCoordByIndex(row, col).mergeInfo;
303
+ if (startRow !== endRow || startColumn !== endColumn) {
304
+ const sheetNotes = this._sheetsNoteModel.getSheetNotes(unitId, subUnitId);
305
+ if (sheetNotes) {
306
+ for (const [_id, _note] of sheetNotes) if (_note.row >= startRow && _note.row <= endRow && _note.col >= startColumn && _note.col <= endColumn) {
307
+ note = _note;
308
+ targetRow = _note.row;
309
+ targetCol = _note.col;
310
+ break;
311
+ }
312
+ }
313
+ }
314
+ }
315
+ if (note === null || note === void 0 ? void 0 : note.show) return;
316
+ if (note) this._sheetsNotePopupService.showPopup({
317
+ unitId,
318
+ subUnitId,
319
+ noteId: note.id,
320
+ row: targetRow,
321
+ col: targetCol,
322
+ temp: true
323
+ });
324
+ else this._sheetsNotePopupService.hidePopup();
325
+ }));
326
+ }
327
+ _initDeleteNoteListener() {
328
+ this.disposeWithMe(this._sheetsNoteModel.change$.subscribe((change) => {
329
+ if (!this._sheetsNotePopupService.activePopup) return;
330
+ const { unitId, subUnitId, noteId, row, col } = this._sheetsNotePopupService.activePopup;
331
+ const { oldNote, newNote } = change;
332
+ if (newNote === null && change.unitId === unitId && change.subUnitId === subUnitId && ((oldNote === null || oldNote === void 0 ? void 0 : oldNote.id) && oldNote.id === noteId || (oldNote === null || oldNote === void 0 ? void 0 : oldNote.row) === row && oldNote.col === col)) this._sheetsNotePopupService.hidePopup(true);
333
+ }));
334
+ }
335
+ };
336
+ SheetsNotePopupController = __decorate([
337
+ __decorateParam(0, (0, _univerjs_core.Inject)(SheetsNotePopupService)),
338
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_note.SheetsNoteModel)),
339
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
340
+ __decorateParam(3, _univerjs_sheets_ui.IEditorBridgeService),
341
+ __decorateParam(4, _univerjs_engine_render.IRenderManagerService),
342
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService))
343
+ ], SheetsNotePopupController);
344
+
345
+ //#endregion
346
+ //#region package.json
347
+ var name = "@univerjs/sheets-note-ui";
348
+ var version = "0.21.0-insiders.20260424-262d69f";
349
+
350
+ //#endregion
351
+ //#region src/config/config.ts
352
+ const SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY = "sheets-note-ui.config";
353
+ const configSymbol = Symbol(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY);
354
+ const defaultPluginConfig = {};
355
+
356
+ //#endregion
357
+ //#region src/controllers/sheets-note-attachment.controller.ts
358
+ let SheetsNoteAttachmentController = class SheetsNoteAttachmentController extends _univerjs_core.Disposable {
359
+ constructor(_sheetsNoteModel, _univerInstanceService, _cellPopupManagerService, _sheetsNotePopupService) {
360
+ super();
361
+ this._sheetsNoteModel = _sheetsNoteModel;
362
+ this._univerInstanceService = _univerInstanceService;
363
+ this._cellPopupManagerService = _cellPopupManagerService;
364
+ this._sheetsNotePopupService = _sheetsNotePopupService;
365
+ _defineProperty(this, "_noteMatrix", new _univerjs_core.ObjectMatrix());
366
+ this._initNoteChangeListener();
367
+ }
368
+ _showPopup(unitId, sheetId, row, col) {
369
+ this._sheetsNotePopupService.hidePopup(true);
370
+ return this._cellPopupManagerService.showPopup({
371
+ unitId,
372
+ subUnitId: sheetId,
373
+ row,
374
+ col
375
+ }, {
376
+ componentKey: SHEET_NOTE_COMPONENT,
377
+ direction: "horizontal",
378
+ extraProps: { location: {
379
+ unitId,
380
+ subUnitId: sheetId,
381
+ row,
382
+ col
383
+ } },
384
+ priority: 3
385
+ });
386
+ }
387
+ dispose() {
388
+ super.dispose();
389
+ this._noteMatrix.forValue((_, __, disposable) => {
390
+ disposable.dispose();
391
+ });
392
+ }
393
+ _initSheet(targetUnitId, targetSheetId) {
394
+ var _this$_sheetsNoteMode;
395
+ this._noteMatrix.forValue((_, __, disposable) => {
396
+ disposable.dispose();
397
+ });
398
+ this._noteMatrix = new _univerjs_core.ObjectMatrix();
399
+ const handleNote = (unitId, sheetId, row, col, note) => {
400
+ const matrix = this._noteMatrix;
401
+ const disposable = matrix.getValue(row, col);
402
+ if (note === null || note === void 0 ? void 0 : note.show) {
403
+ if (!disposable) {
404
+ const newDisposable = this._showPopup(unitId, sheetId, row, col);
405
+ if (newDisposable) matrix.setValue(row, col, newDisposable);
406
+ }
407
+ } else if (disposable) {
408
+ disposable.dispose();
409
+ matrix.realDeleteValue(row, col);
410
+ }
411
+ };
412
+ (_this$_sheetsNoteMode = this._sheetsNoteModel.getSheetNotes(targetUnitId, targetSheetId)) === null || _this$_sheetsNoteMode === void 0 || _this$_sheetsNoteMode.forEach((note) => {
413
+ handleNote(targetUnitId, targetSheetId, note.row, note.col, note);
414
+ });
415
+ return this._sheetsNoteModel.change$.subscribe((change) => {
416
+ if (change.unitId !== targetUnitId || change.subUnitId !== targetSheetId) return;
417
+ switch (change.type) {
418
+ case "ref": {
419
+ const { unitId, subUnitId, oldNote, newNote } = change;
420
+ if (!newNote.show) return;
421
+ const matrix = this._noteMatrix;
422
+ const { row: oldRow, col: oldCol } = oldNote;
423
+ const { row: newRow, col: newCol } = newNote;
424
+ const disposable = matrix.getValue(oldRow, oldCol);
425
+ if (disposable) {
426
+ disposable.dispose();
427
+ matrix.realDeleteValue(oldRow, oldCol);
428
+ }
429
+ const newDisposable = this._showPopup(unitId, subUnitId, newRow, newCol);
430
+ if (newDisposable) matrix.setValue(newRow, newCol, newDisposable);
431
+ break;
432
+ }
433
+ case "update": {
434
+ const { unitId, subUnitId, oldNote, newNote } = change;
435
+ handleNote(unitId, subUnitId, newNote ? newNote.row : oldNote.row, newNote ? newNote.col : oldNote.col, newNote);
436
+ break;
437
+ }
438
+ default: break;
439
+ }
440
+ });
441
+ }
442
+ _initNoteChangeListener() {
443
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => {
444
+ var _workbook$activeSheet;
445
+ return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
446
+ })).subscribe((sheet) => {
447
+ if (sheet) {
448
+ const disposable = this._initSheet(sheet.getUnitId(), sheet.getSheetId());
449
+ return () => {
450
+ disposable.unsubscribe();
451
+ };
452
+ } else {
453
+ this._noteMatrix.forValue((_, __, disposable) => {
454
+ disposable.dispose();
455
+ });
456
+ this._noteMatrix = new _univerjs_core.ObjectMatrix();
457
+ }
458
+ }));
459
+ }
460
+ };
461
+ SheetsNoteAttachmentController = __decorate([
462
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_note.SheetsNoteModel)),
463
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
464
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellPopupManagerService)),
465
+ __decorateParam(3, (0, _univerjs_core.Inject)(SheetsNotePopupService))
466
+ ], SheetsNoteAttachmentController);
467
+
468
+ //#endregion
469
+ //#region src/commands/operations/add-note-popup.operation.ts
470
+ const AddNotePopupOperation = {
471
+ id: "sheet.operation.add-note-popup",
472
+ type: _univerjs_core.CommandType.OPERATION,
473
+ handler: async (accessor, params) => {
474
+ var _params$trigger;
475
+ const selectionService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
476
+ const notePopupService = accessor.get(SheetsNotePopupService);
477
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
478
+ if (!workbook) return false;
479
+ const worksheet = workbook.getActiveSheet();
480
+ const lastSelection = selectionService.getCurrentLastSelection();
481
+ if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
482
+ const { primary } = lastSelection;
483
+ notePopupService.showPopup({
484
+ unitId: workbook.getUnitId(),
485
+ subUnitId: worksheet.getSheetId(),
486
+ row: primary.actualRow,
487
+ col: primary.actualColumn,
488
+ temp: false,
489
+ trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
490
+ });
491
+ return true;
492
+ }
493
+ };
494
+
495
+ //#endregion
496
+ //#region src/menu/note.menu.ts
497
+ function getHasNote$(accessor) {
498
+ const sheetsSelectionsService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
499
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
500
+ return sheetsSelectionsService.selectionMoveEnd$.pipe((0, rxjs.map)(() => {
501
+ const selection = sheetsSelectionsService.getCurrentLastSelection();
502
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
503
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
504
+ if (!target) return false;
505
+ const { actualColumn, actualRow } = selection.primary;
506
+ const noteModel = accessor.get(_univerjs_sheets_note.SheetsNoteModel);
507
+ return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
508
+ row: actualRow,
509
+ col: actualColumn
510
+ }));
511
+ }));
512
+ }
513
+ function sheetNoteContextMenuFactory(accessor) {
514
+ return {
515
+ id: AddNotePopupOperation.id,
516
+ type: _univerjs_ui.MenuItemType.BUTTON,
517
+ title: "rightClick.addNote",
518
+ icon: "AddNoteIcon",
519
+ hidden$: (0, rxjs.combineLatest)([(0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe((0, rxjs.map)(([hidden, hasNote]) => hidden || hasNote)),
520
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
521
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
522
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
523
+ }),
524
+ commandId: AddNotePopupOperation.id
525
+ };
526
+ }
527
+ function sheetDeleteNoteMenuFactory(accessor) {
528
+ return {
529
+ id: _univerjs_sheets_note.SheetDeleteNoteCommand.id,
530
+ type: _univerjs_ui.MenuItemType.BUTTON,
531
+ title: "rightClick.deleteNote",
532
+ icon: "DeleteNoteIcon",
533
+ hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote)),
534
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
535
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
536
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
537
+ })
538
+ };
539
+ }
540
+ function sheetNoteToggleMenuFactory(accessor) {
541
+ return {
542
+ id: _univerjs_sheets_note.SheetToggleNotePopupCommand.id,
543
+ type: _univerjs_ui.MenuItemType.BUTTON,
544
+ title: "rightClick.toggleNote",
545
+ icon: "HideNoteIcon",
546
+ hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote))
547
+ };
548
+ }
549
+
550
+ //#endregion
551
+ //#region src/menu/schema.ts
552
+ const menuSchema = { [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
553
+ order: 0,
554
+ [AddNotePopupOperation.id]: {
555
+ order: 0,
556
+ menuItemFactory: sheetNoteContextMenuFactory
557
+ },
558
+ [_univerjs_sheets_note.SheetDeleteNoteCommand.id]: {
559
+ order: 0,
560
+ menuItemFactory: sheetDeleteNoteMenuFactory
561
+ },
562
+ [_univerjs_sheets_note.SheetToggleNotePopupCommand.id]: {
563
+ order: 0,
564
+ menuItemFactory: sheetNoteToggleMenuFactory
565
+ }
566
+ } } };
567
+
568
+ //#endregion
569
+ //#region src/views/note.tsx
570
+ const SheetsNote = (props) => {
571
+ var _popup$extraProps;
572
+ const { popup } = props;
573
+ const noteModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets_note.SheetsNoteModel);
574
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
575
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
576
+ const notePopupService = (0, _univerjs_ui.useDependency)(SheetsNotePopupService);
577
+ const config = (0, _univerjs_ui.useConfigValue)(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY);
578
+ const activePopup = (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.location;
579
+ if (!activePopup) {
580
+ console.error("Popup extraProps or location is undefined.");
581
+ return null;
582
+ }
583
+ const textareaRef = (0, react.useRef)(null);
584
+ const currentRender = renderManagerService.getRenderById(activePopup.unitId);
585
+ const [note, setNote] = (0, react.useState)(null);
586
+ (0, react.useEffect)(() => {
587
+ var _ref, _note$width, _config$defaultNoteSi, _ref2, _note$height, _config$defaultNoteSi2;
588
+ const { unitId, subUnitId, row, col } = activePopup;
589
+ const note = noteModel.getNote(unitId, subUnitId, {
590
+ row,
591
+ col
592
+ });
593
+ const width = (_ref = (_note$width = note === null || note === void 0 ? void 0 : note.width) !== null && _note$width !== void 0 ? _note$width : config === null || config === void 0 || (_config$defaultNoteSi = config.defaultNoteSize) === null || _config$defaultNoteSi === void 0 ? void 0 : _config$defaultNoteSi.width) !== null && _ref !== void 0 ? _ref : 160;
594
+ const height = (_ref2 = (_note$height = note === null || note === void 0 ? void 0 : note.height) !== null && _note$height !== void 0 ? _note$height : config === null || config === void 0 || (_config$defaultNoteSi2 = config.defaultNoteSize) === null || _config$defaultNoteSi2 === void 0 ? void 0 : _config$defaultNoteSi2.height) !== null && _ref2 !== void 0 ? _ref2 : 72;
595
+ if (!note) {
596
+ const initNote = {
597
+ id: (0, _univerjs_core.generateRandomId)(6),
598
+ width,
599
+ height,
600
+ note: ""
601
+ };
602
+ setNote(initNote);
603
+ updateNote(initNote);
604
+ } else setNote(note);
605
+ if (textareaRef.current) {
606
+ textareaRef.current.style.width = `${width}px`;
607
+ textareaRef.current.style.height = `${height}px`;
608
+ }
609
+ }, [activePopup, textareaRef]);
610
+ (0, react.useEffect)(() => {
611
+ if (!activePopup || activePopup.temp || !activePopup.trigger) return;
612
+ if (!textareaRef.current) return;
613
+ const focusId = requestAnimationFrame(() => {
614
+ var _textareaRef$current;
615
+ (_textareaRef$current = textareaRef.current) === null || _textareaRef$current === void 0 || _textareaRef$current.focus();
616
+ });
617
+ return () => cancelAnimationFrame(focusId);
618
+ }, [activePopup]);
619
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
620
+ const updateNote = (0, _univerjs_ui.useDebounceFn)((newNote) => {
621
+ if (!activePopup) return;
622
+ const { unitId, subUnitId, row, col } = activePopup;
623
+ if (!commandService.syncExecuteCommand(_univerjs_sheets_note.SheetUpdateNoteCommand.id, {
624
+ unitId,
625
+ sheetId: subUnitId,
626
+ row,
627
+ col,
628
+ note: newNote
629
+ })) {
630
+ const oldNote = noteModel.getNote(unitId, subUnitId, {
631
+ noteId: newNote.id,
632
+ row,
633
+ col
634
+ });
635
+ if (oldNote) setNote(oldNote);
636
+ else notePopupService.hidePopup(true);
637
+ }
638
+ });
639
+ const handleNoteChange = (0, react.useCallback)((value) => {
640
+ if (!note) return;
641
+ if (value === note.note) return;
642
+ const newNote = {
643
+ ...note,
644
+ note: value
645
+ };
646
+ setNote(newNote);
647
+ updateNote(newNote);
648
+ }, [note]);
649
+ const handleResize = (0, react.useCallback)((width, height) => {
650
+ if (!note) return;
651
+ if (width === note.width && height === note.height) return;
652
+ const newNote = {
653
+ ...note,
654
+ width,
655
+ height
656
+ };
657
+ setNote(newNote);
658
+ updateNote(newNote);
659
+ }, [note]);
660
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Textarea, {
661
+ ref: textareaRef,
662
+ "data-u-comp": "note-textarea",
663
+ className: (0, _univerjs_design.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"),
664
+ value: note === null || note === void 0 ? void 0 : note.note,
665
+ placeholder: localeService.t("note.placeholder"),
666
+ onResize: handleResize,
667
+ onValueChange: handleNoteChange,
668
+ onWheel: (e) => {
669
+ if (document.activeElement !== textareaRef.current) currentRender.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type, e.nativeEvent));
670
+ }
671
+ });
672
+ };
673
+
674
+ //#endregion
675
+ //#region src/controllers/sheets-note-ui.controller.ts
676
+ /**
677
+ * Copyright 2023-present DreamNum Co., Ltd.
678
+ *
679
+ * Licensed under the Apache License, Version 2.0 (the "License");
680
+ * you may not use this file except in compliance with the License.
681
+ * You may obtain a copy of the License at
682
+ *
683
+ * http://www.apache.org/licenses/LICENSE-2.0
684
+ *
685
+ * Unless required by applicable law or agreed to in writing, software
686
+ * distributed under the License is distributed on an "AS IS" BASIS,
687
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
688
+ * See the License for the specific language governing permissions and
689
+ * limitations under the License.
690
+ */
691
+ let SheetsNoteUIController = class SheetsNoteUIController extends _univerjs_core.Disposable {
692
+ constructor(_componentManager, _menuManagerService, _commandService) {
693
+ super();
694
+ this._componentManager = _componentManager;
695
+ this._menuManagerService = _menuManagerService;
696
+ this._commandService = _commandService;
697
+ this._initComponents();
698
+ this._initMenu();
699
+ this._initCommands();
700
+ }
701
+ _initComponents() {
702
+ [
703
+ [SHEET_NOTE_COMPONENT, SheetsNote],
704
+ ["AddNoteIcon", _univerjs_icons.AddNoteIcon],
705
+ ["DeleteNoteIcon", _univerjs_icons.DeleteNoteIcon],
706
+ ["HideNoteIcon", _univerjs_icons.HideNoteIcon]
707
+ ].forEach(([key, comp]) => {
708
+ this.disposeWithMe(this._componentManager.register(key, comp));
709
+ });
710
+ }
711
+ _initMenu() {
712
+ this._menuManagerService.mergeMenu(menuSchema);
713
+ }
714
+ _initCommands() {
715
+ this._commandService.registerCommand(AddNotePopupOperation);
716
+ }
717
+ };
718
+ SheetsNoteUIController = __decorate([
719
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
720
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IMenuManagerService)),
721
+ __decorateParam(2, _univerjs_core.ICommandService)
722
+ ], SheetsNoteUIController);
723
+
724
+ //#endregion
725
+ //#region src/plugin.ts
726
+ let UniverSheetsNoteUIPlugin = class UniverSheetsNoteUIPlugin extends _univerjs_core.Plugin {
727
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
728
+ super();
729
+ this._config = _config;
730
+ this._injector = _injector;
731
+ this._configService = _configService;
732
+ const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
733
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
734
+ this._configService.setConfig(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY, rest);
735
+ }
736
+ onStarting() {
737
+ [
738
+ [SheetsNotePopupService],
739
+ [SheetsCellContentController],
740
+ [SheetsNotePopupController],
741
+ [SheetsNoteUIController],
742
+ [SheetsNoteAttachmentController]
743
+ ].forEach((dependency) => {
744
+ this._injector.add(dependency);
745
+ });
746
+ }
747
+ onReady() {
748
+ (0, _univerjs_core.touchDependencies)(this._injector, [[SheetsNoteUIController], [SheetsCellContentController]]);
749
+ }
750
+ onRendered() {
751
+ (0, _univerjs_core.touchDependencies)(this._injector, [[SheetsNotePopupController], [SheetsNoteAttachmentController]]);
752
+ }
753
+ };
754
+ _defineProperty(UniverSheetsNoteUIPlugin, "pluginName", "SHEET_NOTE_UI_PLUGIN");
755
+ _defineProperty(UniverSheetsNoteUIPlugin, "packageName", name);
756
+ _defineProperty(UniverSheetsNoteUIPlugin, "version", version);
757
+ _defineProperty(UniverSheetsNoteUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
758
+ UniverSheetsNoteUIPlugin = __decorate([
759
+ (0, _univerjs_core.DependentOn)(_univerjs_sheets_note.UniverSheetsNotePlugin),
760
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
761
+ __decorateParam(2, _univerjs_core.IConfigService)
762
+ ], UniverSheetsNoteUIPlugin);
763
+
764
+ //#endregion
765
+ Object.defineProperty(exports, 'SheetsCellContentController', {
766
+ enumerable: true,
767
+ get: function () {
768
+ return SheetsCellContentController;
769
+ }
770
+ });
771
+ exports.SheetsNote = SheetsNote;
772
+ Object.defineProperty(exports, 'SheetsNotePopupController', {
773
+ enumerable: true,
774
+ get: function () {
775
+ return SheetsNotePopupController;
776
+ }
777
+ });
778
+ Object.defineProperty(exports, 'SheetsNotePopupService', {
779
+ enumerable: true,
780
+ get: function () {
781
+ return SheetsNotePopupService;
782
+ }
783
+ });
784
+ Object.defineProperty(exports, 'UniverSheetsNoteUIPlugin', {
785
+ enumerable: true,
786
+ get: function () {
787
+ return UniverSheetsNoteUIPlugin;
788
+ }
789
+ });