@univerjs/sheets-note 0.17.0 → 0.18.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.
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  import { Disposable, IResourceManagerService, IUniverInstanceService } from '@univerjs/core';
2
17
  import { SheetInterceptorService } from '@univerjs/sheets';
3
18
  import { SheetsNoteModel } from '../models/sheets-note.model';
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
  import { Disposable, ICommandService } from '@univerjs/core';
2
17
  export declare class SheetsNoteController extends Disposable {
3
18
  private readonly _commandService;
@@ -1,5 +1,20 @@
1
- import { ISheetNote } from '@univerjs/sheets-note';
2
- import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ISheetNote } from '@univerjs/sheets-note';
17
+ import type { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
3
18
  export interface ISheetNoteAddEventParams {
4
19
  workbook: FWorkbook;
5
20
  worksheet: FWorksheet;
@@ -1,5 +1,20 @@
1
- import { Nullable } from '@univerjs/core';
2
- import { ISheetNote } from '@univerjs/sheets-note';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { Nullable } from '@univerjs/core';
17
+ import type { ISheetNote } from '@univerjs/sheets-note';
3
18
  import { FRange } from '@univerjs/sheets/facade';
4
19
  /**
5
20
  * @ignore
@@ -1,4 +1,19 @@
1
- import { Injector } from '@univerjs/core';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { Injector } from '@univerjs/core';
2
17
  import { FUniver } from '@univerjs/core/facade';
3
18
  /**
4
19
  * @ignore
@@ -1,4 +1,19 @@
1
- import { ISheetNote } from '@univerjs/sheets-note';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { ISheetNote } from '@univerjs/sheets-note';
2
17
  import { FWorksheet } from '@univerjs/sheets/facade';
3
18
  /**
4
19
  * @ignore
@@ -1,5 +1,21 @@
1
- import { Nullable, Disposable } from '@univerjs/core';
2
- import { ISheetLocationBase } from '@univerjs/sheets';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { Nullable } from '@univerjs/core';
17
+ import type { ISheetLocationBase } from '@univerjs/sheets';
18
+ import { Disposable } from '@univerjs/core';
3
19
  export interface ISheetNote {
4
20
  id: string;
5
21
  row: number;
@@ -24,16 +40,16 @@ export type ISheetNoteChange = {
24
40
  export declare class SheetsNoteModel extends Disposable {
25
41
  private _notesMap;
26
42
  private readonly _change$;
27
- readonly change$: import('rxjs').Observable<ISheetNoteChange>;
43
+ readonly change$: import("rxjs").Observable<ISheetNoteChange>;
28
44
  private _ensureNotesMap;
29
45
  private _getNoteByPosition;
30
46
  private _getNoteById;
31
47
  private _getNoteByParams;
32
- getSheetShowNotes$(unitId: string, subUnitId: string): import('rxjs').Observable<{
48
+ getSheetShowNotes$(unitId: string, subUnitId: string): import("rxjs").Observable<{
33
49
  loc: ISheetLocationBase;
34
50
  note: ISheetNote;
35
51
  }[]>;
36
- getCellNoteChange$(unitId: string, subUnitId: string, row: number, col: number): import('rxjs').Observable<ISheetNoteChange>;
52
+ getCellNoteChange$(unitId: string, subUnitId: string, row: number, col: number): import("rxjs").Observable<ISheetNoteChange>;
37
53
  updateNote(unitId: string, subUnitId: string, row: number, col: number, note: Partial<ISheetNote>, silent?: boolean): void;
38
54
  removeNote(unitId: string, subUnitId: string, params: {
39
55
  noteId?: string;
@@ -1,4 +1,19 @@
1
- import { IUniverSheetsNoteConfig } from './config/config';
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IUniverSheetsNoteConfig } from './config/config';
2
17
  import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
3
18
  export declare class UniverSheetsNotePlugin extends Plugin {
4
19
  private readonly _config;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(S,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@univerjs/core/facade"),require("@univerjs/sheets-note"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core/facade","@univerjs/sheets-note","@univerjs/sheets/facade","@univerjs/core","@univerjs/sheets"],f):(S=typeof globalThis<"u"?globalThis:S||self,f(S.UniverSheetsNoteFacade={},S.UniverCoreFacade,S.UniverSheetsNote,S.UniverSheetsFacade,S.UniverCore,S.UniverSheets))})(this,(function(S,f,s,w,N,m){"use strict";class p{get SheetNoteAdd(){return"SheetNoteAdd"}get SheetNoteDelete(){return"SheetNoteDelete"}get SheetNoteUpdate(){return"SheetNoteUpdate"}get SheetNoteShow(){return"SheetNoteShow"}get SheetNoteHide(){return"SheetNoteHide"}get BeforeSheetNoteAdd(){return"BeforeSheetNoteAdd"}get BeforeSheetNoteDelete(){return"BeforeSheetNoteDelete"}get BeforeSheetNoteUpdate(){return"BeforeSheetNoteUpdate"}get BeforeSheetNoteShow(){return"BeforeSheetNoteShow"}get BeforeSheetNoteHide(){return"BeforeSheetNoteHide"}}f.FEventName.extend(p);class I extends w.FRange{createOrUpdateNote(d){return this._commandService.syncExecuteCommand(s.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:d}),this}deleteNote(){return this._commandService.syncExecuteCommand(s.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(s.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),{row:this.getRow(),col:this.getColumn()})}}w.FRange.extend(I);class U extends f.FUniver{_initialize(d){const g=d.get(N.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd,()=>d.get(s.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&!e.oldNote&&e.newNote){const{unitId:n,subUnitId:r,newNote:t}=e,o=this.getSheetTarget(n,r);if(!o)return;const{workbook:c,worksheet:i}=o;this.fireEvent(this.Event.SheetNoteAdd,{workbook:c,worksheet:i,row:t.row,col:t.col,note:t})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteDelete,()=>d.get(s.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&!e.newNote){const{unitId:n,subUnitId:r,oldNote:t}=e,o=this.getSheetTarget(n,r);if(!o)return;const{workbook:c,worksheet:i}=o;this.fireEvent(this.Event.SheetNoteDelete,{workbook:c,worksheet:i,row:t.row,col:t.col,oldNote:t})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteUpdate,()=>d.get(s.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.newNote){const{unitId:n,subUnitId:r,oldNote:t,newNote:o}=e,c=this.getSheetTarget(n,r);if(!c)return;const{workbook:i,worksheet:l}=c;this.fireEvent(this.Event.SheetNoteUpdate,{workbook:i,worksheet:l,row:o.row,col:o.col,note:o,oldNote:t})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteShow,()=>d.get(s.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.newNote&&!e.oldNote.show&&e.newNote.show){const{unitId:n,subUnitId:r,newNote:t}=e,o=this.getSheetTarget(n,r);if(!o)return;const{workbook:c,worksheet:i}=o;this.fireEvent(this.Event.SheetNoteShow,{workbook:c,worksheet:i,row:t.row,col:t.col})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteHide,()=>d.get(s.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.newNote&&e.oldNote.show&&!e.newNote.show){const{unitId:n,subUnitId:r,newNote:t}=e,o=this.getSheetTarget(n,r);if(!o)return;const{workbook:c,worksheet:i}=o;this.fireEvent(this.Event.SheetNoteHide,{workbook:c,worksheet:i,row:t.row,col:t.col})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>g.beforeCommandExecuted(h=>{if(h.id===s.SheetUpdateNoteCommand.id){const{unitId:e,sheetId:n,row:r,col:t,note:o}=h.params,c=this.getSheetTarget(e,n);if(!c||d.get(s.SheetsNoteModel).getNote(e,n,{noteId:o.id,row:r,col:t}))return;const{workbook:u,worksheet:a}=c;if(this.fireEvent(this.Event.BeforeSheetNoteAdd,{workbook:u,worksheet:a,row:r,col:t,note:o}))throw new N.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>g.beforeCommandExecuted(h=>{if(h.id===s.SheetDeleteNoteCommand.id){const{unitId:e,sheetId:n,row:r,col:t}=h.params,o=this.getSheetTarget(e,n);if(!o||r===void 0||t===void 0)return;const i=d.get(s.SheetsNoteModel).getNote(e,n,{row:r,col:t});if(!i)return;const{workbook:l,worksheet:u}=o;if(this.fireEvent(this.Event.BeforeSheetNoteDelete,{workbook:l,worksheet:u,row:r,col:t,oldNote:i}))throw new N.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>g.beforeCommandExecuted(h=>{if(h.id===s.SheetUpdateNoteCommand.id){const{unitId:e,sheetId:n,row:r,col:t,note:o}=h.params,c=this.getSheetTarget(e,n);if(!c)return;const l=d.get(s.SheetsNoteModel).getNote(e,n,{row:r,col:t});if(!l)return;const{workbook:u,worksheet:a}=c;if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,{workbook:u,worksheet:a,row:r,col:t,note:o,oldNote:l}))throw new N.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>g.beforeCommandExecuted(h=>{if(h.id===s.SheetToggleNotePopupCommand.id){const e=m.getSheetCommandTarget(d.get(N.IUniverInstanceService));if(!e)return;const{unitId:n,subUnitId:r}=e,t=this.getUniverSheet(n);if(!t)return;const o=t.getSheetBySheetId(r);if(!o)return;const i=d.get(m.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return;const l=d.get(s.SheetsNoteModel),{actualColumn:u,actualRow:a}=i.primary,v=l.getNote(n,r,{row:a,col:u});if(!v||v.show)return;if(this.fireEvent(this.Event.BeforeSheetNoteShow,{workbook:t,worksheet:o,row:a,col:u}))throw new N.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>g.beforeCommandExecuted(h=>{if(h.id===s.SheetToggleNotePopupCommand.id){const e=m.getSheetCommandTarget(d.get(N.IUniverInstanceService));if(!e)return;const{unitId:n,subUnitId:r}=e,t=this.getUniverSheet(n);if(!t)return;const o=t.getSheetBySheetId(r);if(!o)return;const i=d.get(m.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return;const l=d.get(s.SheetsNoteModel),{actualColumn:u,actualRow:a}=i.primary,v=l.getNote(n,r,{row:a,col:u});if(!v||!v.show)return;if(this.fireEvent(this.Event.BeforeSheetNoteHide,{workbook:t,worksheet:o,row:a,col:u}))throw new N.CanceledError}})))}}f.FUniver.extend(U);class k extends w.FWorksheet{getNotes(){const g=this._injector.get(s.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId());return g?Array.from(g.values()).map(h=>({...h})):[]}}w.FWorksheet.extend(k),S.FSheetNoteEvent=p,S.FSheetsNoteRangeMixin=I,S.FSheetsNoteWorksheet=k,S.FUniverSheetNoteMixin=U,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core/facade`),require(`@univerjs/sheets-note`),require(`@univerjs/sheets/facade`),require(`@univerjs/core`),require(`@univerjs/sheets`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core/facade`,`@univerjs/sheets-note`,`@univerjs/sheets/facade`,`@univerjs/core`,`@univerjs/sheets`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNoteFacade={},e.UniverCoreFacade,e.UniverSheetsNote,e.UniverSheetsFacade,e.UniverCore,e.UniverSheets))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=class{get SheetNoteAdd(){return`SheetNoteAdd`}get SheetNoteDelete(){return`SheetNoteDelete`}get SheetNoteUpdate(){return`SheetNoteUpdate`}get SheetNoteShow(){return`SheetNoteShow`}get SheetNoteHide(){return`SheetNoteHide`}get BeforeSheetNoteAdd(){return`BeforeSheetNoteAdd`}get BeforeSheetNoteDelete(){return`BeforeSheetNoteDelete`}get BeforeSheetNoteUpdate(){return`BeforeSheetNoteUpdate`}get BeforeSheetNoteShow(){return`BeforeSheetNoteShow`}get BeforeSheetNoteHide(){return`BeforeSheetNoteHide`}};t.FEventName.extend(o);var s=class extends r.FRange{createOrUpdateNote(e){return this._commandService.syncExecuteCommand(n.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:e}),this}deleteNote(){return this._commandService.syncExecuteCommand(n.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(n.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),{row:this.getRow(),col:this.getColumn()})}};r.FRange.extend(s);var c=class extends t.FUniver{_initialize(e){let t=e.get(i.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteAdd,()=>e.get(n.SheetsNoteModel).change$.subscribe(e=>{if(e.type===`update`&&!e.oldNote&&e.newNote){let{unitId:t,subUnitId:n,newNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i;this.fireEvent(this.Event.SheetNoteAdd,{workbook:a,worksheet:o,row:r.row,col:r.col,note:r})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteDelete,()=>e.get(n.SheetsNoteModel).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&!e.newNote){let{unitId:t,subUnitId:n,oldNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i;this.fireEvent(this.Event.SheetNoteDelete,{workbook:a,worksheet:o,row:r.row,col:r.col,oldNote:r})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteUpdate,()=>e.get(n.SheetsNoteModel).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&e.newNote){let{unitId:t,subUnitId:n,oldNote:r,newNote:i}=e,a=this.getSheetTarget(t,n);if(!a)return;let{workbook:o,worksheet:s}=a;this.fireEvent(this.Event.SheetNoteUpdate,{workbook:o,worksheet:s,row:i.row,col:i.col,note:i,oldNote:r})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteShow,()=>e.get(n.SheetsNoteModel).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&e.newNote&&!e.oldNote.show&&e.newNote.show){let{unitId:t,subUnitId:n,newNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i;this.fireEvent(this.Event.SheetNoteShow,{workbook:a,worksheet:o,row:r.row,col:r.col})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.SheetNoteHide,()=>e.get(n.SheetsNoteModel).change$.subscribe(e=>{if(e.type===`update`&&e.oldNote&&e.newNote&&e.oldNote.show&&!e.newNote.show){let{unitId:t,subUnitId:n,newNote:r}=e,i=this.getSheetTarget(t,n);if(!i)return;let{workbook:a,worksheet:o}=i;this.fireEvent(this.Event.SheetNoteHide,{workbook:a,worksheet:o,row:r.row,col:r.col})}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetUpdateNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s,note:c}=t.params,l=this.getSheetTarget(r,a);if(!l||e.get(n.SheetsNoteModel).getNote(r,a,{noteId:c.id,row:o,col:s}))return;let{workbook:u,worksheet:d}=l;if(this.fireEvent(this.Event.BeforeSheetNoteAdd,{workbook:u,worksheet:d,row:o,col:s,note:c}))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetDeleteNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s}=t.params,c=this.getSheetTarget(r,a);if(!c||o===void 0||s===void 0)return;let l=e.get(n.SheetsNoteModel).getNote(r,a,{row:o,col:s});if(!l)return;let{workbook:u,worksheet:d}=c;if(this.fireEvent(this.Event.BeforeSheetNoteDelete,{workbook:u,worksheet:d,row:o,col:s,oldNote:l}))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetUpdateNoteCommand.id){let{unitId:r,sheetId:a,row:o,col:s,note:c}=t.params,l=this.getSheetTarget(r,a);if(!l)return;let u=e.get(n.SheetsNoteModel).getNote(r,a,{row:o,col:s});if(!u)return;let{workbook:d,worksheet:f}=l;if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,{workbook:d,worksheet:f,row:o,col:s,note:c,oldNote:u}))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetToggleNotePopupCommand.id){let t=(0,a.getSheetCommandTarget)(e.get(i.IUniverInstanceService));if(!t)return;let{unitId:r,subUnitId:o}=t,s=this.getUniverSheet(r);if(!s)return;let c=s.getSheetBySheetId(o);if(!c)return;let l=e.get(a.SheetsSelectionsService).getCurrentLastSelection();if(!(l!=null&&l.primary))return;let u=e.get(n.SheetsNoteModel),{actualColumn:d,actualRow:f}=l.primary,p=u.getNote(r,o,{row:f,col:d});if(!p||p.show)return;if(this.fireEvent(this.Event.BeforeSheetNoteShow,{workbook:s,worksheet:c,row:f,col:d}))throw new i.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>t.beforeCommandExecuted(t=>{if(t.id===n.SheetToggleNotePopupCommand.id){let t=(0,a.getSheetCommandTarget)(e.get(i.IUniverInstanceService));if(!t)return;let{unitId:r,subUnitId:o}=t,s=this.getUniverSheet(r);if(!s)return;let c=s.getSheetBySheetId(o);if(!c)return;let l=e.get(a.SheetsSelectionsService).getCurrentLastSelection();if(!(l!=null&&l.primary))return;let u=e.get(n.SheetsNoteModel),{actualColumn:d,actualRow:f}=l.primary,p=u.getNote(r,o,{row:f,col:d});if(!p||!p.show)return;if(this.fireEvent(this.Event.BeforeSheetNoteHide,{workbook:s,worksheet:c,row:f,col:d}))throw new i.CanceledError}})))}};t.FUniver.extend(c);var l=class extends r.FWorksheet{getNotes(){let e=this._injector.get(n.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId());return e?Array.from(e.values()).map(e=>({...e})):[]}};r.FWorksheet.extend(l),e.FSheetNoteEvent=o,e.FSheetsNoteRangeMixin=s,e.FSheetsNoteWorksheet=l,e.FUniverSheetNoteMixin=c});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(u,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],c):(u=typeof globalThis<"u"?globalThis:u||self,c(u.UniverSheetsNote={},u.UniverCore,u.UniverSheets,u.rxjs))})(this,(function(u,c,g,M){"use strict";var X=Object.defineProperty;var Z=(u,c,g)=>c in u?X(u,c,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[c]=g;var f=(u,c,g)=>Z(u,typeof c!="symbol"?c+"":c,g);class m extends c.Disposable{constructor(){super(...arguments);f(this,"_notesMap",new Map);f(this,"_change$",new M.Subject);f(this,"change$",this._change$.asObservable())}_ensureNotesMap(t,e){let n=this._notesMap.get(t);n||(n=new Map,this._notesMap.set(t,n));let o=n.get(e);return o||(o=new Map,n.set(e,o)),o}_getNoteByPosition(t,e,n,o){const s=this._ensureNotesMap(t,e);for(const[r,d]of s)if(d.row===n&&d.col===o)return d}_getNoteById(t,e,n){return this._ensureNotesMap(t,e).get(n)}_getNoteByParams(t,e,n){const{noteId:o,row:s,col:r}=n;return o?this._getNoteById(t,e,o):s!==void 0&&r!==void 0?this._getNoteByPosition(t,e,s,r):null}getSheetShowNotes$(t,e){return this._change$.pipe(M.filter(({unitId:n,subUnitId:o})=>n===t&&o===e),M.map(()=>{const n=this._ensureNotesMap(t,e),o=[];for(const[s,r]of n)r.show&&o.push({loc:{row:r.row,col:r.col,unitId:t,subUnitId:e},note:r});return o}))}getCellNoteChange$(t,e,n,o){return this._change$.pipe(M.filter(({unitId:s,subUnitId:r,oldNote:d})=>s!==t||r!==e||!d?!1:d.row===n&&d.col===o),M.map(s=>s))}updateNote(t,e,n,o,s,r){const d=this._getNoteByParams(t,e,{noteId:s==null?void 0:s.id,row:n,col:o}),h=this._ensureNotesMap(t,e),l={...s,id:(d==null?void 0:d.id)||s.id||c.generateRandomId(6),row:n,col:o};h.set(l.id,l),this._change$.next({unitId:t,subUnitId:e,oldNote:d,type:"update",newNote:l,silent:r})}removeNote(t,e,n){const{noteId:o,row:s,col:r,silent:d}=n,h=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!h)return;this._ensureNotesMap(t,e).delete(h.id),this._change$.next({unitId:t,subUnitId:e,oldNote:h,type:"update",newNote:null,silent:d})}toggleNotePopup(t,e,n){const{noteId:o,row:s,col:r,silent:d}=n,h=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!h)return;const l=this._ensureNotesMap(t,e),p={...h,show:!h.show};l.set(p.id,p),this._change$.next({unitId:t,subUnitId:e,oldNote:h,type:"update",newNote:p,silent:d})}updateNotePosition(t,e,n){const{noteId:o,row:s,col:r,newRow:d,newCol:h,silent:l}=n,p=this._getNoteByParams(t,e,{noteId:o,row:s,col:r});if(!p)return;const _=this._ensureNotesMap(t,e),N={...p,row:d,col:h};_.set(N.id,N),this._change$.next({unitId:t,subUnitId:e,oldNote:p,type:"ref",newNote:N,silent:l})}getNote(t,e,n){return this._getNoteByParams(t,e,n)}getNotes(){return this._notesMap}getUnitNotes(t){return this._notesMap.get(t)}getSheetNotes(t,e){const n=this._notesMap.get(t);if(n)return n.get(e)}deleteUnitNotes(t){this._notesMap.delete(t)}}const S={id:"sheet.mutation.update-note",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,row:n,col:o,note:s,silent:r}=i;return a.get(m).updateNote(t,e,n,o,s,r),!0}},v={id:"sheet.mutation.remove-note",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,silent:r}=i;return a.get(m).removeNote(t,e,{noteId:n,row:o,col:s,silent:r}),!0}},I={id:"sheet.mutation.toggle-note-popup",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,silent:r}=i;return a.get(m).toggleNotePopup(t,e,{noteId:n,row:o,col:s,silent:r}),!0}},w={id:"sheet.mutation.update-note-position",type:c.CommandType.MUTATION,handler:(a,i)=>{const{unitId:t,sheetId:e,noteId:n,row:o,col:s,newPosition:r,silent:d}=i;return a.get(m).updateNotePosition(t,e,{noteId:n,row:o,col:s,newRow:r.row,newCol:r.col,silent:d}),!0}},E={id:"sheet.command.delete-note",type:c.CommandType.COMMAND,handler:a=>{const i=g.getSheetCommandTarget(a.get(c.IUniverInstanceService));if(!i)return!1;const e=a.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const n=a.get(m),{unitId:o,subUnitId:s}=i,{actualColumn:r,actualRow:d}=e.primary,h=n.getNote(o,s,{row:d,col:r});if(!h)return!1;const l=a.get(c.ICommandService),p=a.get(c.IUndoRedoService),_={id:v.id,params:{unitId:o,sheetId:s,noteId:h.id}},N={id:S.id,params:{unitId:o,sheetId:s,row:d,col:r,note:{...h}}};return l.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:o,redoMutations:[_],undoMutations:[N]}),!0):!1}},O={id:"sheet.command.toggle-note-popup",type:c.CommandType.COMMAND,handler:a=>{const i=g.getSheetCommandTarget(a.get(c.IUniverInstanceService));if(!i)return!1;const e=a.get(g.SheetsSelectionsService).getCurrentLastSelection();if(!(e!=null&&e.primary))return!1;const n=a.get(m),{unitId:o,subUnitId:s}=i,{actualColumn:r,actualRow:d}=e.primary,h=n.getNote(o,s,{row:d,col:r});if(!h)return!1;const l=a.get(c.ICommandService),p=a.get(c.IUndoRedoService),_={id:I.id,params:{unitId:o,sheetId:s,noteId:h.id}},N={id:I.id,params:{unitId:o,sheetId:s,noteId:h.id}};return l.syncExecuteCommand(_.id,_.params)?(p.pushUndoRedo({unitID:o,redoMutations:[_],undoMutations:[N]}),!0):!1}},b={id:"sheet.command.update-note",type:c.CommandType.COMMAND,handler:(a,i)=>{const t=g.getSheetCommandTarget(a.get(c.IUniverInstanceService),i);if(!t)return!1;const e=a.get(c.ICommandService),n=a.get(c.IUndoRedoService),o=a.get(m),{unitId:s,subUnitId:r}=t,{row:d,col:h,note:l}=i,p=o.getNote(s,r,{noteId:l.id,row:d,col:h}),_={id:S.id,params:{unitId:s,sheetId:r,row:d,col:h,note:l}},N=[];if(p){const T={id:S.id,params:{unitId:s,sheetId:r,row:d,col:h,note:{...p}}};N.push(T)}else{const T={id:v.id,params:{unitId:s,sheetId:r,row:d,col:h}};N.push(T)}return e.syncExecuteCommand(_.id,_.params)?(n.pushUndoRedo({unitID:s,redoMutations:[_],undoMutations:N}),!0):!1}},D="SHEET_NOTE_PLUGIN";var B=Object.getOwnPropertyDescriptor,L=(a,i,t,e)=>{for(var n=e>1?void 0:e?B(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},C=(a,i)=>(t,e)=>i(t,e,a);u.SheetsNoteResourceController=class extends c.Disposable{constructor(i,t,e,n){super(),this._resourceManagerService=i,this._univerInstanceService=t,this._sheetInterceptorService=e,this._sheetsNoteModel=n,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){const i=e=>{const n=this._sheetsNoteModel.getUnitNotes(e);if(!n)return"";const o={};return n.forEach((s,r)=>{const d={};s.forEach(h=>{const{row:l,col:p}=h;d[l]||(d[l]={}),d[l][p]=h}),Object.keys(d).length>0&&(o[r]=d)}),JSON.stringify(o)},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:D,businesses:[c.UniverInstanceType.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._sheetsNoteModel.deleteUnitNotes(e)},onLoad:(e,n)=>{Object.entries(n).forEach(([o,s])=>{Object.entries(s).forEach(([r,d])=>{Object.entries(d).forEach(([h,l])=>{this._sheetsNoteModel.updateNote(e,o,Number(r),Number(h),l)})})})}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId||this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_SHEET).getUnitId(),o=e.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(c.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!n||!o)return{redos:[],undos:[]};const s=this._sheetsNoteModel.getSheetNotes(n,o);if(!s)return{redos:[],undos:[]};const r=[],d=[];return s.forEach(h=>{r.push({id:v.id,params:{unitId:n,sheetId:o,noteId:h.id,row:h.row,col:h.col}}),d.push({id:S.id,params:{unitId:n,sheetId:o,row:h.row,col:h.col,note:h}})}),{redos:r,undos:d}}else if(i.id===g.CopySheetCommand.id){const e=i.params,{unitId:n,subUnitId:o,targetSubUnitId:s}=e;if(!n||!o||!s)return{redos:[],undos:[]};const r=this._sheetsNoteModel.getSheetNotes(n,o);if(!r)return{redos:[],undos:[]};const d=[],h=[];return r.forEach(l=>{const p={...l,id:c.generateRandomId(6)};d.push({id:S.id,params:{unitId:n,sheetId:s,row:p.row,col:p.col,note:p}}),h.push({id:v.id,params:{unitId:n,sheetId:s,noteId:p.id,row:p.row,col:p.col}})}),{redos:d,undos:h}}return{redos:[],undos:[]}}}))}},u.SheetsNoteResourceController=L([C(0,c.IResourceManagerService),C(1,c.IUniverInstanceService),C(2,c.Inject(g.SheetInterceptorService)),C(3,c.Inject(m))],u.SheetsNoteResourceController);const $={name:"@univerjs/sheets-note",version:"0.17.0"},H="sheets-note.config",j={};var J=Object.getOwnPropertyDescriptor,q=(a,i,t,e)=>{for(var n=e>1?void 0:e?J(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},R=(a,i)=>(t,e)=>i(t,e,a);let U=class extends c.Disposable{constructor(i,t,e,n){super();f(this,"_disposableMap",new Map);f(this,"_watcherMap",new Map);f(this,"_handleRangeChange",(i,t,e,n,o,s,r)=>s?{redos:[{id:w.id,params:{unitId:i,sheetId:t,noteId:e.id,newPosition:{row:s.startRow,col:s.startColumn},silent:r}}],undos:[{id:w.id,params:{unitId:i,sheetId:t,noteId:e.id,newPosition:{row:n,col:o},note:e,silent:r}}]}:{redos:[{id:v.id,params:{unitId:i,sheetId:t,noteId:e.id}}],undos:[{id:S.id,params:{unitId:i,sheetId:t,row:n,col:o,note:e}}]});this._refRangeService=i,this._sheetsNoteModel=t,this._selectionManagerService=e,this._commandService=n,this._initData(),this._initRefRange()}_getIdWithUnitId(i,t,e,n){return`${i}-${t}-${e}-${n}`}_register(i,t,e,n,o){const s={startColumn:o,endColumn:o,startRow:n,endRow:n};this._disposableMap.set(this._getIdWithUnitId(i,t,n,o),this._refRangeService.registerRefRange(s,r=>{const d=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,r,{selectionManagerService:this._selectionManagerService}),h=Array.isArray(d)?d[0]:d;return h&&h.startColumn===s.startColumn&&h.startRow===s.startRow?{undos:[],redos:[]}:this._handleRangeChange(i,t,e,n,o,h,!1)},i,t))}_watch(i,t,e,n,o){const s={startColumn:o,endColumn:o,startRow:n,endRow:n};this._watcherMap.set(this._getIdWithUnitId(i,t,n,o),this._refRangeService.watchRange(i,t,s,(r,d)=>{const{redos:h}=this._handleRangeChange(i,t,e,r.startRow,r.startColumn,d,!0);c.sequenceExecuteAsync(h,this._commandService,{onlyLocal:!0})},!0))}_unwatch(i,t,e,n){var s;const o=this._getIdWithUnitId(i,t,e,n);(s=this._watcherMap.get(o))==null||s.dispose(),this._watcherMap.delete(o)}_unregister(i,t,e,n){var s;const o=this._getIdWithUnitId(i,t,e,n);(s=this._disposableMap.get(o))==null||s.dispose(),this._disposableMap.delete(o)}_initData(){const i=this._sheetsNoteModel.getNotes();for(const[t,e]of i)for(const[n,o]of e)o.forEach(s=>{this._register(t,n,s,s.row,s.col),this._watch(t,n,s,s.row,s.col)})}_initRefRange(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(i=>{switch(i.type){case"update":{const{unitId:t,subUnitId:e,oldNote:n,newNote:o}=i,s=o?o.row:n.row,r=o?o.col:n.col,d=this._getIdWithUnitId(t,e,s,r);o?this._disposableMap.has(d)||(this._register(t,e,o,s,r),this._watch(t,e,o,s,r)):(this._unregister(t,e,s,r),this._unwatch(t,e,s,r));break}case"ref":{const{unitId:t,subUnitId:e,oldNote:n,newNote:o,silent:s}=i,{row:r,col:d}=n,{row:h,col:l}=o;this._unregister(t,e,r,d),s||(this._unwatch(t,e,r,d),this._watch(t,e,o,h,l)),this._register(t,e,o,h,l);break}}}))}};U=q([R(0,c.Inject(g.RefRangeService)),R(1,c.Inject(m)),R(2,c.Inject(g.SheetsSelectionsService)),R(3,c.ICommandService)],U);var G=Object.getOwnPropertyDescriptor,V=(a,i,t,e)=>{for(var n=e>1?void 0:e?G(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},z=(a,i)=>(t,e)=>i(t,e,a);let y=class extends c.Disposable{constructor(a){super(),this._commandService=a,this._initialize()}_initialize(){[w,I,S,v,E,O,b].forEach(a=>{this.disposeWithMe(this._commandService.registerCommand(a))})}};y=V([z(0,c.ICommandService)],y);var F=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Y=(a,i,t)=>i in a?F(a,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[i]=t,Q=(a,i,t,e)=>{for(var n=e>1?void 0:e?K(i,t):i,o=a.length-1,s;o>=0;o--)(s=a[o])&&(n=s(n)||n);return n},A=(a,i)=>(t,e)=>i(t,e,a),P=(a,i,t)=>Y(a,typeof i!="symbol"?i+"":i,t);u.UniverSheetsNotePlugin=class extends c.Plugin{constructor(i=j,t,e){super(),this._config=i,this._configService=t,this._injector=e;const{...n}=c.merge({},j,this._config);this._configService.setConfig(H,n)}onStarting(){[[m],[y],[u.SheetsNoteResourceController],[U]].forEach(i=>{this._injector.add(i)}),c.touchDependencies(this._injector,[[m],[y],[u.SheetsNoteResourceController]])}onReady(){c.touchDependencies(this._injector,[[U]])}},P(u.UniverSheetsNotePlugin,"pluginName",D),P(u.UniverSheetsNotePlugin,"packageName",$.name),P(u.UniverSheetsNotePlugin,"version",$.version),P(u.UniverSheetsNotePlugin,"type",c.UniverInstanceType.UNIVER_SHEET),u.UniverSheetsNotePlugin=Q([c.DependentOn(g.UniverSheetsPlugin),A(1,c.IConfigService),A(2,c.Inject(c.Injector))],u.UniverSheetsNotePlugin),u.RemoveNoteMutation=v,u.SheetDeleteNoteCommand=E,u.SheetToggleNotePopupCommand=O,u.SheetUpdateNoteCommand=b,u.SheetsNoteModel=m,u.ToggleNotePopupMutation=I,u.UpdateNoteMutation=S,u.UpdateNotePositionMutation=w,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`rxjs`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNote={},e.UniverCore,e.UniverSheets,e.rxjs))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function i(e){"@babel/helpers - typeof";return i=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},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class extends t.Disposable{constructor(...e){super(...e),s(this,`_notesMap`,new Map),s(this,`_change$`,new r.Subject),s(this,`change$`,this._change$.asObservable())}_ensureNotesMap(e,t){let n=this._notesMap.get(e);n||(n=new Map,this._notesMap.set(e,n));let r=n.get(t);return r||(r=new Map,n.set(t,r)),r}_getNoteByPosition(e,t,n,r){let i=this._ensureNotesMap(e,t);for(let[e,t]of i)if(t.row===n&&t.col===r)return t}_getNoteById(e,t,n){return this._ensureNotesMap(e,t).get(n)}_getNoteByParams(e,t,n){let{noteId:r,row:i,col:a}=n;return r?this._getNoteById(e,t,r):i!==void 0&&a!==void 0?this._getNoteByPosition(e,t,i,a):null}getSheetShowNotes$(e,t){return this._change$.pipe((0,r.filter)(({unitId:n,subUnitId:r})=>n===e&&r===t),(0,r.map)(()=>{let n=this._ensureNotesMap(e,t),r=[];for(let[i,a]of n)a.show&&r.push({loc:{row:a.row,col:a.col,unitId:e,subUnitId:t},note:a});return r}))}getCellNoteChange$(e,t,n,i){return this._change$.pipe((0,r.filter)(({unitId:r,subUnitId:a,oldNote:o})=>r!==e||a!==t||!o?!1:o.row===n&&o.col===i),(0,r.map)(e=>e))}updateNote(e,n,r,i,a,o){let s=this._getNoteByParams(e,n,{noteId:a==null?void 0:a.id,row:r,col:i}),c=this._ensureNotesMap(e,n),l={...a,id:(s==null?void 0:s.id)||a.id||(0,t.generateRandomId)(6),row:r,col:i};c.set(l.id,l),this._change$.next({unitId:e,subUnitId:n,oldNote:s,type:`update`,newNote:l,silent:o})}removeNote(e,t,n){let{noteId:r,row:i,col:a,silent:o}=n,s=this._getNoteByParams(e,t,{noteId:r,row:i,col:a});s&&(this._ensureNotesMap(e,t).delete(s.id),this._change$.next({unitId:e,subUnitId:t,oldNote:s,type:`update`,newNote:null,silent:o}))}toggleNotePopup(e,t,n){let{noteId:r,row:i,col:a,silent:o}=n,s=this._getNoteByParams(e,t,{noteId:r,row:i,col:a});if(!s)return;let c=this._ensureNotesMap(e,t),l={...s,show:!s.show};c.set(l.id,l),this._change$.next({unitId:e,subUnitId:t,oldNote:s,type:`update`,newNote:l,silent:o})}updateNotePosition(e,t,n){let{noteId:r,row:i,col:a,newRow:o,newCol:s,silent:c}=n,l=this._getNoteByParams(e,t,{noteId:r,row:i,col:a});if(!l)return;let u=this._ensureNotesMap(e,t),d={...l,row:o,col:s};u.set(d.id,d),this._change$.next({unitId:e,subUnitId:t,oldNote:l,type:`ref`,newNote:d,silent:c})}getNote(e,t,n){return this._getNoteByParams(e,t,n)}getNotes(){return this._notesMap}getUnitNotes(e){return this._notesMap.get(e)}getSheetNotes(e,t){let n=this._notesMap.get(e);if(n)return n.get(t)}deleteUnitNotes(e){this._notesMap.delete(e)}};let l={id:`sheet.mutation.update-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,row:i,col:a,note:o,silent:s}=t;return e.get(c).updateNote(n,r,i,a,o,s),!0}},u={id:`sheet.mutation.remove-note`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).removeNote(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},d={id:`sheet.mutation.toggle-note-popup`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,silent:s}=t;return e.get(c).toggleNotePopup(n,r,{noteId:i,row:a,col:o,silent:s}),!0}},f={id:`sheet.mutation.update-note-position`,type:t.CommandType.MUTATION,handler:(e,t)=>{let{unitId:n,sheetId:r,noteId:i,row:a,col:o,newPosition:s,silent:l}=t;return e.get(c).updateNotePosition(n,r,{noteId:i,row:a,col:o,newRow:s.row,newCol:s.col,silent:l}),!0}},p={id:`sheet.command.delete-note`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:d,actualRow:f}=i.primary,p=a.getNote(o,s,{row:f,col:d});if(!p)return!1;let m=e.get(t.ICommandService),h=e.get(t.IUndoRedoService),g={id:u.id,params:{unitId:o,sheetId:s,noteId:p.id}},_={id:l.id,params:{unitId:o,sheetId:s,row:f,col:d,note:{...p}}};return m.syncExecuteCommand(g.id,g.params)?(h.pushUndoRedo({unitID:o,redoMutations:[g],undoMutations:[_]}),!0):!1}},m={id:`sheet.command.toggle-note-popup`,type:t.CommandType.COMMAND,handler:e=>{let r=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService));if(!r)return!1;let i=e.get(n.SheetsSelectionsService).getCurrentLastSelection();if(!(i!=null&&i.primary))return!1;let a=e.get(c),{unitId:o,subUnitId:s}=r,{actualColumn:l,actualRow:u}=i.primary,f=a.getNote(o,s,{row:u,col:l});if(!f)return!1;let p=e.get(t.ICommandService),m=e.get(t.IUndoRedoService),h={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}},g={id:d.id,params:{unitId:o,sheetId:s,noteId:f.id}};return p.syncExecuteCommand(h.id,h.params)?(m.pushUndoRedo({unitID:o,redoMutations:[h],undoMutations:[g]}),!0):!1}},h={id:`sheet.command.update-note`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r);if(!i)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(c),{unitId:d,subUnitId:f}=i,{row:p,col:m,note:h}=r,g=s.getNote(d,f,{noteId:h.id,row:p,col:m}),_={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:h}},v=[];if(g){let e={id:l.id,params:{unitId:d,sheetId:f,row:p,col:m,note:{...g}}};v.push(e)}else{let e={id:u.id,params:{unitId:d,sheetId:f,row:p,col:m}};v.push(e)}return a.syncExecuteCommand(_.id,_.params)?(o.pushUndoRedo({unitID:d,redoMutations:[_],undoMutations:v}),!0):!1}},g=`SHEET_NOTE_PLUGIN`;function _(e,t){return function(n,r){t(n,r,e)}}function v(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 y=class extends t.Disposable{constructor(e,t,n,r){super(),this._resourceManagerService=e,this._univerInstanceService=t,this._sheetInterceptorService=n,this._sheetsNoteModel=r,this._initSnapshot(),this._initSheetChange()}_initSnapshot(){let e=e=>{let t=this._sheetsNoteModel.getUnitNotes(e);if(!t)return``;let n={};return t.forEach((e,t)=>{let r={};e.forEach(e=>{let{row:t,col:n}=e;r[t]||(r[t]={}),r[t][n]=e}),Object.keys(r).length>0&&(n[t]=r)}),JSON.stringify(n)},n=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:g,businesses:[t.UniverInstanceType.UNIVER_SHEET],toJson:t=>e(t),parseJson:e=>n(e),onUnLoad:e=>{this._sheetsNoteModel.deleteUnitNotes(e)},onLoad:(e,t)=>{Object.entries(t).forEach(([t,n])=>{Object.entries(n).forEach(([n,r])=>{Object.entries(r).forEach(([r,i])=>{this._sheetsNoteModel.updateNote(e,t,Number(n),Number(r),i)})})})}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===n.RemoveSheetCommand.id){var r;let n=e.params,i=n.unitId||this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getUnitId(),a=n.subUnitId||((r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:r.getSheetId());if(!i||!a)return{redos:[],undos:[]};let o=this._sheetsNoteModel.getSheetNotes(i,a);if(!o)return{redos:[],undos:[]};let s=[],c=[];return o.forEach(e=>{s.push({id:u.id,params:{unitId:i,sheetId:a,noteId:e.id,row:e.row,col:e.col}}),c.push({id:l.id,params:{unitId:i,sheetId:a,row:e.row,col:e.col,note:e}})}),{redos:s,undos:c}}else if(e.id===n.CopySheetCommand.id){let{unitId:n,subUnitId:r,targetSubUnitId:i}=e.params;if(!n||!r||!i)return{redos:[],undos:[]};let a=this._sheetsNoteModel.getSheetNotes(n,r);if(!a)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{let r={...e,id:(0,t.generateRandomId)(6)};o.push({id:l.id,params:{unitId:n,sheetId:i,row:r.row,col:r.col,note:r}}),s.push({id:u.id,params:{unitId:n,sheetId:i,noteId:r.id,row:r.row,col:r.col}})}),{redos:o,undos:s}}return{redos:[],undos:[]}}}))}};y=v([_(0,t.IResourceManagerService),_(1,t.IUniverInstanceService),_(2,(0,t.Inject)(n.SheetInterceptorService)),_(3,(0,t.Inject)(c))],y);var b=`@univerjs/sheets-note`,x=`0.18.0`;let S=`sheets-note.config`;Symbol(S);let C={},w=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._sheetsNoteModel=t,this._selectionManagerService=n,this._commandService=r,s(this,`_disposableMap`,new Map),s(this,`_watcherMap`,new Map),s(this,`_handleRangeChange`,(e,t,n,r,i,a,o)=>a?{redos:[{id:f.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:a.startRow,col:a.startColumn},silent:o}}],undos:[{id:f.id,params:{unitId:e,sheetId:t,noteId:n.id,newPosition:{row:r,col:i},note:n,silent:o}}]}:{redos:[{id:u.id,params:{unitId:e,sheetId:t,noteId:n.id}}],undos:[{id:l.id,params:{unitId:e,sheetId:t,row:r,col:i,note:n}}]}),this._initData(),this._initRefRange()}_getIdWithUnitId(e,t,n,r){return`${e}-${t}-${n}-${r}`}_register(e,t,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._disposableMap.set(this._getIdWithUnitId(e,t,i,a),this._refRangeService.registerRefRange(o,s=>{let c=(0,n.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(o,s,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===o.startColumn&&l.startRow===o.startRow?{undos:[],redos:[]}:this._handleRangeChange(e,t,r,i,a,l,!1)},e,t))}_watch(e,n,r,i,a){let o={startColumn:a,endColumn:a,startRow:i,endRow:i};this._watcherMap.set(this._getIdWithUnitId(e,n,i,a),this._refRangeService.watchRange(e,n,o,(i,a)=>{let{redos:o}=this._handleRangeChange(e,n,r,i.startRow,i.startColumn,a,!0);(0,t.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unwatch(e,t,n,r){var i;let a=this._getIdWithUnitId(e,t,n,r);(i=this._watcherMap.get(a))==null||i.dispose(),this._watcherMap.delete(a)}_unregister(e,t,n,r){var i;let a=this._getIdWithUnitId(e,t,n,r);(i=this._disposableMap.get(a))==null||i.dispose(),this._disposableMap.delete(a)}_initData(){let e=this._sheetsNoteModel.getNotes();for(let[t,n]of e)for(let[e,r]of n)r.forEach(n=>{this._register(t,e,n,n.row,n.col),this._watch(t,e,n,n.row,n.col)})}_initRefRange(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{switch(e.type){case`update`:{let{unitId:t,subUnitId:n,oldNote:r,newNote:i}=e,a=i?i.row:r.row,o=i?i.col:r.col,s=this._getIdWithUnitId(t,n,a,o);i?this._disposableMap.has(s)||(this._register(t,n,i,a,o),this._watch(t,n,i,a,o)):(this._unregister(t,n,a,o),this._unwatch(t,n,a,o));break}case`ref`:{let{unitId:t,subUnitId:n,oldNote:r,newNote:i,silent:a}=e,{row:o,col:s}=r,{row:c,col:l}=i;this._unregister(t,n,o,s),a||(this._unwatch(t,n,o,s),this._watch(t,n,i,c,l)),this._register(t,n,i,c,l);break}}}))}};w=v([_(0,(0,t.Inject)(n.RefRangeService)),_(1,(0,t.Inject)(c)),_(2,(0,t.Inject)(n.SheetsSelectionsService)),_(3,t.ICommandService)],w);let T=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._initialize()}_initialize(){[f,d,l,u,p,m,h].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};T=v([_(0,t.ICommandService)],T);let E=class extends t.Plugin{constructor(e=C,n,r){super(),this._config=e,this._configService=n,this._injector=r;let{...i}=(0,t.merge)({},C,this._config);this._configService.setConfig(S,i)}onStarting(){[[c],[T],[y],[w]].forEach(e=>{this._injector.add(e)}),(0,t.touchDependencies)(this._injector,[[c],[T],[y]])}onReady(){(0,t.touchDependencies)(this._injector,[[w]])}};s(E,`pluginName`,g),s(E,`packageName`,b),s(E,`version`,x),s(E,`type`,t.UniverInstanceType.UNIVER_SHEET),E=v([(0,t.DependentOn)(n.UniverSheetsPlugin),_(1,t.IConfigService),_(2,(0,t.Inject)(t.Injector))],E),e.RemoveNoteMutation=u,e.SheetDeleteNoteCommand=p,e.SheetToggleNotePopupCommand=m,e.SheetUpdateNoteCommand=h,e.SheetsNoteModel=c,Object.defineProperty(e,`SheetsNoteResourceController`,{enumerable:!0,get:function(){return y}}),e.ToggleNotePopupMutation=d,Object.defineProperty(e,`UniverSheetsNotePlugin`,{enumerable:!0,get:function(){return E}}),e.UpdateNoteMutation=l,e.UpdateNotePositionMutation=f});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-note",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "private": false,
5
5
  "description": "Univer sheets note base plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,22 +56,26 @@
56
56
  "rxjs": ">=7.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@univerjs/core": "0.17.0",
60
- "@univerjs/sheets": "0.17.0"
59
+ "@univerjs/core": "0.18.0",
60
+ "@univerjs/sheets": "0.18.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "rxjs": "^7.8.2",
64
64
  "typescript": "^5.9.3",
65
- "vite": "^7.3.1",
66
- "vitest": "^4.0.18",
67
- "@univerjs-infra/shared": "0.17.0"
65
+ "vitest": "^4.1.0",
66
+ "@univerjs-infra/shared": "0.18.0",
67
+ "@univerjs/engine-formula": "0.18.0",
68
+ "@univerjs/engine-render": "0.18.0",
69
+ "@univerjs/network": "0.18.0"
68
70
  },
69
71
  "scripts": {
70
72
  "test": "vitest run",
71
73
  "test:watch": "vitest",
72
74
  "coverage": "vitest run --coverage",
73
75
  "typecheck": "tsc --noEmit",
74
- "build": "univer-cli build"
76
+ "build:bundle": "univer-cli build",
77
+ "build:types": "tsc -p tsconfig.node.json",
78
+ "build": "pnpm run build:bundle && pnpm run build:types"
75
79
  },
76
80
  "module": "./lib/es/index.js"
77
81
  }