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