@univerjs/sheets-note 0.7.0-beta.1

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.
@@ -0,0 +1,218 @@
1
+ import { ISheetNote } from '@univerjs/sheets-note';
2
+ import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
3
+ export interface ISheetNoteAddEventParmas {
4
+ workbook: FWorkbook;
5
+ worksheet: FWorksheet;
6
+ row: number;
7
+ col: number;
8
+ note: ISheetNote;
9
+ cancel?: boolean;
10
+ }
11
+ export interface ISheetNoteDeleteEventParmas {
12
+ workbook: FWorkbook;
13
+ worksheet: FWorksheet;
14
+ row: number;
15
+ col: number;
16
+ oldNote: ISheetNote;
17
+ cancel?: boolean;
18
+ }
19
+ export interface ISheetNoteUpdateEventParmas {
20
+ workbook: FWorkbook;
21
+ worksheet: FWorksheet;
22
+ row: number;
23
+ col: number;
24
+ note: ISheetNote;
25
+ oldNote: ISheetNote;
26
+ cancel?: boolean;
27
+ }
28
+ export interface ISheetNoteShowEventParmas {
29
+ workbook: FWorkbook;
30
+ worksheet: FWorksheet;
31
+ row: number;
32
+ col: number;
33
+ cancel?: boolean;
34
+ }
35
+ export interface ISheetNoteHideEventParmas {
36
+ workbook: FWorkbook;
37
+ worksheet: FWorksheet;
38
+ row: number;
39
+ col: number;
40
+ cancel?: boolean;
41
+ }
42
+ /**
43
+ * @ignore
44
+ */
45
+ export interface ISheetsNoteEventParamConfig {
46
+ SheetNoteAdd: ISheetNoteAddEventParmas;
47
+ SheetNoteDelete: ISheetNoteDeleteEventParmas;
48
+ SheetNoteUpdate: ISheetNoteUpdateEventParmas;
49
+ SheetNoteShow: ISheetNoteShowEventParmas;
50
+ SheetNoteHide: ISheetNoteHideEventParmas;
51
+ BeforeSheetNoteAdd: ISheetNoteAddEventParmas;
52
+ BeforeSheetNoteDelete: ISheetNoteDeleteEventParmas;
53
+ BeforeSheetNoteUpdate: ISheetNoteUpdateEventParmas;
54
+ BeforeSheetNoteShow: ISheetNoteShowEventParmas;
55
+ BeforeSheetNoteHide: ISheetNoteHideEventParmas;
56
+ }
57
+ /**
58
+ * @ignore
59
+ */
60
+ interface ISheetNoteEvent {
61
+ /**
62
+ * Event fired when a note is added
63
+ * @see {@link ISheetNoteAddEventParmas}
64
+ * @example
65
+ * ```ts
66
+ * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteAdd, (params) => {
67
+ * const { workbook, worksheet, row, col, note } = params;
68
+ * console.log(params);
69
+ * });
70
+ * ```
71
+ */
72
+ SheetNoteAdd: 'SheetNoteAdd';
73
+ /**
74
+ * Event fired when a note is deleted
75
+ * @see {@link ISheetNoteDeleteEventParmas}
76
+ * @example
77
+ * ```ts
78
+ * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteDelete, (params) => {
79
+ * const { workbook, worksheet, row, col, oldNote } = params;
80
+ * console.log(params);
81
+ * });
82
+ * ```
83
+ */
84
+ SheetNoteDelete: 'SheetNoteDelete';
85
+ /**
86
+ * Event fired when a note is updated
87
+ * @see {@link ISheetNoteUpdateEventParmas}
88
+ * @example
89
+ * ```ts
90
+ * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteUpdate, (params) => {
91
+ * const { workbook, worksheet, row, col, note, oldNote } = params;
92
+ * console.log(params);
93
+ * });
94
+ * ```
95
+ */
96
+ SheetNoteUpdate: 'SheetNoteUpdate';
97
+ /**
98
+ * Event fired when a note is shown
99
+ * @see {@link ISheetNoteShowEventParmas}
100
+ * @example
101
+ * ```ts
102
+ * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteShow, (params) => {
103
+ * const { workbook, worksheet, row, col } = params;
104
+ * console.log(params);
105
+ * });
106
+ * ```
107
+ */
108
+ SheetNoteShow: 'SheetNoteShow';
109
+ /**
110
+ * Event fired when a note is hidden
111
+ * @see {@link ISheetNoteHideEventParmas}
112
+ * @example
113
+ * ```ts
114
+ * const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteHide, (params) => {
115
+ * const { workbook, worksheet, row, col } = params;
116
+ * console.log(params);
117
+ * });
118
+ * ```
119
+ */
120
+ SheetNoteHide: 'SheetNoteHide';
121
+ /**
122
+ * Event fired before a note is added
123
+ * @see {@link ISheetNoteAddEventParmas}
124
+ * @example
125
+ * ```ts
126
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteAdd, (params) => {
127
+ * const { workbook, worksheet, row, col, note } = params;
128
+ * console.log(params);
129
+ * });
130
+ * ```
131
+ */
132
+ BeforeSheetNoteAdd: 'BeforeSheetNoteAdd';
133
+ /**
134
+ * Event fired before a note is deleted
135
+ * @see {@link ISheetNoteDeleteEventParmas}
136
+ * @example
137
+ * ```ts
138
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteDelete, (params) => {
139
+ * const { workbook, worksheet, row, col, oldNote } = params;
140
+ * console.log(params);
141
+ * });
142
+ * ```
143
+ */
144
+ BeforeSheetNoteDelete: 'BeforeSheetNoteDelete';
145
+ /**
146
+ * Event fired before a note is updated
147
+ * @see {@link ISheetNoteUpdateEventParmas}
148
+ * @example
149
+ * ```ts
150
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteUpdate, (params) => {
151
+ * const { workbook, worksheet, row, col, note, oldNote } = params;
152
+ * console.log(params);
153
+ * });
154
+ * ```
155
+ */
156
+ BeforeSheetNoteUpdate: 'BeforeSheetNoteUpdate';
157
+ /**
158
+ * Event fired before a note is shown
159
+ * @see {@link ISheetNoteShowEventParmas}
160
+ * @example
161
+ * ```ts
162
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteShow, (params) => {
163
+ * const { workbook, worksheet, row, col } = params;
164
+ * console.log(params);
165
+ * });
166
+ * ```
167
+ */
168
+ BeforeSheetNoteShow: 'BeforeSheetNoteShow';
169
+ /**
170
+ * Event fired before a note is hidden
171
+ * @see {@link ISheetNoteHideEventParmas}
172
+ * @example
173
+ * ```ts
174
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteHide, (params) => {
175
+ * const { workbook, worksheet, row, col } = params;
176
+ * console.log(params);
177
+ * });
178
+ * ```
179
+ */
180
+ BeforeSheetNoteHide: 'BeforeSheetNoteHide';
181
+ }
182
+ /**
183
+ * @ignore
184
+ */
185
+ export declare class FSheetNoteEvent implements ISheetNoteEvent {
186
+ get SheetNoteAdd(): 'SheetNoteAdd';
187
+ get SheetNoteDelete(): 'SheetNoteDelete';
188
+ get SheetNoteUpdate(): 'SheetNoteUpdate';
189
+ get SheetNoteShow(): 'SheetNoteShow';
190
+ get SheetNoteHide(): 'SheetNoteHide';
191
+ get BeforeSheetNoteAdd(): 'BeforeSheetNoteAdd';
192
+ get BeforeSheetNoteDelete(): 'BeforeSheetNoteDelete';
193
+ get BeforeSheetNoteUpdate(): 'BeforeSheetNoteUpdate';
194
+ get BeforeSheetNoteShow(): 'BeforeSheetNoteShow';
195
+ get BeforeSheetNoteHide(): 'BeforeSheetNoteHide';
196
+ }
197
+ /**
198
+ * @ignore
199
+ */
200
+ export interface ISheetNoteEventConfig {
201
+ SheetNoteAdd: ISheetNoteAddEventParmas;
202
+ SheetNoteDelete: ISheetNoteDeleteEventParmas;
203
+ SheetNoteUpdate: ISheetNoteUpdateEventParmas;
204
+ SheetNoteShow: ISheetNoteShowEventParmas;
205
+ SheetNoteHide: ISheetNoteHideEventParmas;
206
+ BeforeSheetNoteAdd: ISheetNoteAddEventParmas;
207
+ BeforeSheetNoteDelete: ISheetNoteDeleteEventParmas;
208
+ BeforeSheetNoteUpdate: ISheetNoteUpdateEventParmas;
209
+ BeforeSheetNoteShow: ISheetNoteShowEventParmas;
210
+ BeforeSheetNoteHide: ISheetNoteHideEventParmas;
211
+ }
212
+ declare module '@univerjs/core/facade' {
213
+ interface FEventName extends ISheetNoteEvent {
214
+ }
215
+ interface IEventParamConfig extends ISheetNoteEventConfig {
216
+ }
217
+ }
218
+ export {};
@@ -0,0 +1,51 @@
1
+ import { Nullable } from '@univerjs/core';
2
+ import { ISheetNote } from '@univerjs/sheets-note';
3
+ import { FRange } from '@univerjs/sheets/facade';
4
+ export interface IFSheetsNoteRange {
5
+ /**
6
+ * get the note of the primary cell
7
+ * @returns {Nullable<ISheetNote>} the note of the primary cell
8
+ * @example
9
+ * ```ts
10
+ * const fWorkbook = univerAPI.getWorkbook();
11
+ * const fWorksheet = fWorkbook.getWorksheet();
12
+ * const fRange = fWorksheet.getRange(0, 0, 1, 1);
13
+ * const note = fRange.getNote();
14
+ * ```
15
+ */
16
+ getNote(): Nullable<ISheetNote>;
17
+ /**
18
+ * create a new note and attach to the primary cell
19
+ * @param {ISheetNote} note the note to create
20
+ * @returns {FRange} the range
21
+ * @example
22
+ * ```ts
23
+ * const fWorkbook = univerAPI.getWorkbook();
24
+ * const fWorksheet = fWorkbook.getWorksheet();
25
+ * const fRange = fWorksheet.getRange(0, 0, 1, 1);
26
+ * const note = fRange.createOrUpdateNote({});
27
+ * ```
28
+ */
29
+ createOrUpdateNote(note: ISheetNote): FRange;
30
+ /**
31
+ * delete the note of the primary cell
32
+ * @returns {FRange} the range
33
+ * @example
34
+ * ```ts
35
+ * const fWorkbook = univerAPI.getWorkbook();
36
+ * const fWorksheet = fWorkbook.getWorksheet();
37
+ * const fRange = fWorksheet.getRange(0, 0, 1, 1);
38
+ * fRange.deleteNote();
39
+ * ```
40
+ */
41
+ deleteNote(): FRange;
42
+ }
43
+ export declare class FSheetsNoteRange extends FRange implements IFSheetsNoteRange {
44
+ createOrUpdateNote(note: ISheetNote): FRange;
45
+ deleteNote(): FRange;
46
+ getNote(): Nullable<ISheetNote>;
47
+ }
48
+ declare module '@univerjs/sheets/facade' {
49
+ interface IRange extends FSheetsNoteRange {
50
+ }
51
+ }
@@ -0,0 +1,14 @@
1
+ import { Injector } from '@univerjs/core';
2
+ import { FUniver } from '@univerjs/core/facade';
3
+ /**
4
+ * @ignore
5
+ */
6
+ export interface IFUniverSheetNoteMixin {
7
+ }
8
+ export declare class FUniverSheetNoteMixin extends FUniver implements IFUniverSheetNoteMixin {
9
+ _initialize(injector: Injector): void;
10
+ }
11
+ declare module '@univerjs/core/facade' {
12
+ interface FUniver extends IFUniverSheetNoteMixin {
13
+ }
14
+ }
@@ -0,0 +1,19 @@
1
+ import { ISheetNote } from '@univerjs/sheets-note';
2
+ import { FWorksheet } from '@univerjs/sheets/facade';
3
+ export interface ISheetNoteInfo extends ISheetNote {
4
+ row: number;
5
+ col: number;
6
+ }
7
+ export interface IFSheetsNoteWorksheet {
8
+ /**
9
+ * get the note of the primary cell
10
+ */
11
+ getNotes(): ISheetNoteInfo[];
12
+ }
13
+ export declare class FSheetsNoteWorksheet extends FWorksheet implements IFSheetsNoteWorksheet {
14
+ getNotes(): ISheetNoteInfo[];
15
+ }
16
+ declare module '@univerjs/sheets/facade' {
17
+ interface IWorksheet extends FSheetsNoteWorksheet {
18
+ }
19
+ }
@@ -0,0 +1,23 @@
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 './f-event';
17
+ import './f-range';
18
+ import './f-univer';
19
+ import './f-worksheet';
20
+ export * from './f-event';
21
+ export * from './f-range';
22
+ export * from './f-univer';
23
+ export * from './f-worksheet';
@@ -0,0 +1,20 @@
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
+ export { UniverSheetsNotePlugin } from './plugin';
17
+ export * from './models/sheets-note.model';
18
+ export * from './controllers/sheets-note-resource.controller';
19
+ export * from './commands/mutations/note.mutation';
20
+ export * from './commands/commands/note.command';
@@ -0,0 +1,46 @@
1
+ import { Nullable, Disposable, ObjectMatrix } from '@univerjs/core';
2
+ import { ISheetLocationBase } from '@univerjs/sheets';
3
+ export interface ISheetNote {
4
+ width: number;
5
+ height: number;
6
+ note: string;
7
+ show?: boolean;
8
+ }
9
+ export type ISheetNoteChange = {
10
+ unitId: string;
11
+ sheetId: string;
12
+ row: number;
13
+ col: number;
14
+ silent?: boolean;
15
+ } & ({
16
+ type: 'update';
17
+ note: Nullable<ISheetNote>;
18
+ oldNote: Nullable<ISheetNote>;
19
+ } | {
20
+ type: 'ref';
21
+ newPosition: {
22
+ row: number;
23
+ col: number;
24
+ };
25
+ note: ISheetNote;
26
+ });
27
+ export declare class SheetsNoteModel extends Disposable {
28
+ private _noteMatrix;
29
+ private readonly _change$;
30
+ readonly change$: import('rxjs').Observable<ISheetNoteChange>;
31
+ private _ensureNoteMatrix;
32
+ getSheetShowNotes$(unitId: string, sheetId: string): import('rxjs').Observable<{
33
+ loc: ISheetLocationBase;
34
+ note: ISheetNote;
35
+ }[]>;
36
+ getCellNoteChange$(unitId: string, sheetId: string, row: number, col: number): import('rxjs').Observable<Nullable<ISheetNote>>;
37
+ updateNote(unitId: string, sheetId: string, row: number, col: number, note: ISheetNote, silent?: boolean): void;
38
+ removeNote(unitId: string, sheetId: string, row: number, col: number, silent?: boolean): void;
39
+ toggleNotePopup(unitId: string, sheetId: string, row: number, col: number, silent?: boolean): void;
40
+ updateNotePosition(unitId: string, sheetId: string, row: number, col: number, newRow: number, newCol: number, silent?: boolean): void;
41
+ getNote(unitId: string, sheetId: string, row: number, col: number): Nullable<ISheetNote>;
42
+ getUnitNotes(unitId: string): Map<string, ObjectMatrix<ISheetNote>> | undefined;
43
+ getSheetNotes(unitId: string, sheetId: string): ObjectMatrix<ISheetNote> | undefined;
44
+ getNotes(): Map<string, Map<string, ObjectMatrix<ISheetNote>>>;
45
+ deleteUnitNotes(unitId: string): void;
46
+ }
@@ -0,0 +1,11 @@
1
+ import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
2
+ export declare const PLUGIN_NAME = "SHEET_NOTE_PLUGIN";
3
+ export declare class UniverSheetsNotePlugin extends Plugin {
4
+ private readonly _configService;
5
+ protected readonly _injector: Injector;
6
+ static pluginName: string;
7
+ static type: UniverInstanceType;
8
+ constructor(_configService: IConfigService, _injector: Injector);
9
+ onStarting(): void;
10
+ onReady(): void;
11
+ }
@@ -0,0 +1 @@
1
+ (function(a,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("@univerjs/core/facade"),require("@univerjs/sheets-note"),require("@univerjs/sheets/facade"),require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core/facade","@univerjs/sheets-note","@univerjs/sheets/facade","@univerjs/core"],m):(a=typeof globalThis<"u"?globalThis:a||self,m(a.UniverSheetsNoteFacade={},a.UniverCoreFacade,a.UniverSheetsNote,a.UniverSheetsFacade,a.UniverCore))})(this,function(a,m,h,f,g){"use strict";class w{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"}}m.FEventName.extend(w);class E extends f.FRange{createOrUpdateNote(c){return this._commandService.syncExecuteCommand(h.UpdateNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn(),note:c}),this}deleteNote(){return this._injector.get(h.SheetsNoteModel),this._commandService.syncExecuteCommand(h.RemoveNoteMutation.id,{unitId:this.getUnitId(),sheetId:this.getSheetId(),row:this.getRow(),col:this.getColumn()}),this}getNote(){return this._injector.get(h.SheetsNoteModel).getNote(this.getUnitId(),this.getSheetId(),this.getRow(),this.getColumn())}}f.FRange.extend(E);class I extends m.FUniver{_initialize(c){this.registerEventHandler(this.Event.SheetNoteAdd,()=>c.get(h.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&!e.oldNote&&e.note){const{unitId:d,sheetId:t,row:o,col:i,note:r,oldNote:s}=e,n=this.getSheetTarget(d,t);if(!n)return;const{workbook:S,worksheet:l}=n;this.fireEvent(this.Event.SheetNoteAdd,{workbook:S,worksheet:l,row:o,col:i,note:r})}})),this.registerEventHandler(this.Event.SheetNoteDelete,()=>c.get(h.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&!e.note){const{unitId:d,sheetId:t,row:o,col:i,note:r,oldNote:s}=e,n=this.getSheetTarget(d,t);if(!n)return;const{workbook:S,worksheet:l}=n;this.fireEvent(this.Event.SheetNoteDelete,{workbook:S,worksheet:l,row:o,col:i,oldNote:s})}})),this.registerEventHandler(this.Event.SheetNoteUpdate,()=>c.get(h.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note){const{unitId:d,sheetId:t,row:o,col:i,note:r,oldNote:s}=e,n=this.getSheetTarget(d,t);if(!n)return;const{workbook:S,worksheet:l}=n;this.fireEvent(this.Event.SheetNoteUpdate,{workbook:S,worksheet:l,row:o,col:i,note:r,oldNote:s})}})),this.registerEventHandler(this.Event.SheetNoteShow,()=>c.get(h.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note&&!e.oldNote.show&&e.note.show){const{unitId:d,sheetId:t,row:o,col:i}=e,r=this.getSheetTarget(d,t);if(!r)return;const{workbook:s,worksheet:n}=r;this.fireEvent(this.Event.SheetNoteShow,{workbook:s,worksheet:n,row:o,col:i})}})),this.registerEventHandler(this.Event.SheetNoteHide,()=>c.get(h.SheetsNoteModel).change$.subscribe(e=>{if(e.type==="update"&&e.oldNote&&e.note&&e.oldNote.show&&!e.note.show){const{unitId:d,sheetId:t,row:o,col:i}=e,r=this.getSheetTarget(d,t);if(!r)return;const{workbook:s,worksheet:n}=r;this.fireEvent(this.Event.SheetNoteHide,{workbook:s,worksheet:n,row:o,col:i})}})),this.registerEventHandler(this.Event.BeforeSheetNoteAdd,()=>c.get(g.ICommandService).beforeCommandExecuted(e=>{if(e.id===h.SheetUpdateNoteCommand.id){const d=c.get(h.SheetsNoteModel),{unitId:t,sheetId:o,row:i,col:r,note:s}=e.params;if(d.getNote(t,o,i,r))return;const S=this.getSheetTarget(t,o);if(!S)return;const{workbook:l,worksheet:v}=S;if(this.fireEvent(this.Event.BeforeSheetNoteAdd,{workbook:l,worksheet:v,row:i,col:r,note:s}))throw new g.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteDelete,()=>c.get(g.ICommandService).beforeCommandExecuted(e=>{if(e.id===h.SheetDeleteNoteCommand.id){const d=c.get(h.SheetsNoteModel),{unitId:t,sheetId:o,row:i,col:r}=e.params,s=d.getNote(t,o,i,r);if(!s)return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:S,worksheet:l}=n;if(this.fireEvent(this.Event.BeforeSheetNoteDelete,{workbook:S,worksheet:l,row:i,col:r,oldNote:s}))throw new g.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteUpdate,()=>c.get(g.ICommandService).beforeCommandExecuted(e=>{if(e.id===h.SheetUpdateNoteCommand.id){const d=c.get(h.SheetsNoteModel),{unitId:t,sheetId:o,row:i,col:r,note:s}=e.params,n=d.getNote(t,o,i,r);if(!n)return;const S=this.getSheetTarget(t,o);if(!S)return;const{workbook:l,worksheet:v}=S;if(this.fireEvent(this.Event.BeforeSheetNoteUpdate,{workbook:l,worksheet:v,row:i,col:r,note:s,oldNote:n}))throw new g.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteShow,()=>c.get(g.ICommandService).beforeCommandExecuted(e=>{if(e.id===h.SheetToggleNotePopupCommand.id){const d=c.get(h.SheetsNoteModel),{unitId:t,sheetId:o,row:i,col:r}=e.params,s=d.getNote(t,o,i,r);if(s!=null&&s.show)return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:S,worksheet:l}=n;if(this.fireEvent(this.Event.BeforeSheetNoteShow,{workbook:S,worksheet:l,row:i,col:r}))throw new g.CanceledError}})),this.registerEventHandler(this.Event.BeforeSheetNoteHide,()=>c.get(g.ICommandService).beforeCommandExecuted(e=>{if(e.id===h.SheetToggleNotePopupCommand.id){const d=c.get(h.SheetsNoteModel),{unitId:t,sheetId:o,row:i,col:r}=e.params,s=d.getNote(t,o,i,r);if(!(s!=null&&s.show))return;const n=this.getSheetTarget(t,o);if(!n)return;const{workbook:S,worksheet:l}=n;if(this.fireEvent(this.Event.BeforeSheetNoteHide,{workbook:S,worksheet:l,row:i,col:r}))throw new g.CanceledError}}))}}m.FUniver.extend(I);class k extends f.FWorksheet{getNotes(){const u=this._injector.get(h.SheetsNoteModel).getSheetNotes(this.getWorkbook().getUnitId(),this.getSheetId()),e=[];return u==null||u.forValue((d,t,o)=>{e.push({...o,row:d,col:t})}),e}}f.FWorksheet.extend(k),a.FSheetNoteEvent=w,a.FSheetsNoteRange=E,a.FSheetsNoteWorksheet=k,a.FUniverSheetNoteMixin=I,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ (function(u,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],a):(u=typeof globalThis<"u"?globalThis:u||self,a(u.UniverSheetsNote={},u.UniverCore,u.UniverSheets,u.rxjs))})(this,function(u,a,l,_){"use strict";var H=Object.defineProperty;var z=(u,a,l)=>a in u?H(u,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):u[a]=l;var p=(u,a,l)=>z(u,typeof a!="symbol"?a+"":a,l);class m extends a.Disposable{constructor(){super(...arguments);p(this,"_noteMatrix",new Map);p(this,"_change$",new _.Subject);p(this,"change$",this._change$.asObservable())}_ensureNoteMatrix(e,t){let n=this._noteMatrix.get(e);n||(n=new Map,this._noteMatrix.set(e,n));let s=n.get(t);return s||(s=new a.ObjectMatrix,n.set(t,s)),s}getSheetShowNotes$(e,t){return this._change$.pipe(_.filter(({unitId:n,sheetId:s})=>n===e&&s===t),_.map(()=>{const n=this._ensureNoteMatrix(e,t),s=[];return n.forValue((i,h,c)=>{c.show&&s.push({loc:{row:i,col:h,unitId:e,subUnitId:t},note:c})}),s}))}getCellNoteChange$(e,t,n,s){return this._change$.pipe(_.filter(({unitId:i,sheetId:h,row:c,col:d})=>i===e&&h===t&&c===n&&d===s),_.map(({note:i})=>i))}updateNote(e,t,n,s,i,h){const c=this._ensureNoteMatrix(e,t),d=c.getValue(n,s);c.setValue(n,s,i),this._change$.next({unitId:e,sheetId:t,row:n,col:s,type:"update",note:i,oldNote:d,silent:h})}removeNote(e,t,n,s,i){const h=this._ensureNoteMatrix(e,t),c=h.getValue(n,s);h.realDeleteValue(n,s),this._change$.next({unitId:e,sheetId:t,row:n,col:s,type:"update",note:null,oldNote:c,silent:i})}toggleNotePopup(e,t,n,s,i){const h=this._ensureNoteMatrix(e,t),c=h.getValue(n,s);if(c){c.show=!c.show;const d={...c,show:c.show};h.setValue(n,s,d),this._change$.next({unitId:e,sheetId:t,row:n,col:s,type:"update",note:d,oldNote:c,silent:i})}}updateNotePosition(e,t,n,s,i,h,c){const d=this._ensureNoteMatrix(e,t),g=d.getValue(n,s);g&&(d.realDeleteValue(n,s),d.setValue(i,h,g),this._change$.next({unitId:e,sheetId:t,row:n,col:s,type:"ref",newPosition:{row:i,col:h},note:g,silent:c}))}getNote(e,t,n,s){return this._ensureNoteMatrix(e,t).getValue(n,s)}getUnitNotes(e){return this._noteMatrix.get(e)}getSheetNotes(e,t){const n=this._noteMatrix.get(e);if(n)return n.get(t)}getNotes(){return this._noteMatrix}deleteUnitNotes(e){this._noteMatrix.delete(e)}}const N={id:"sheet.mutation.update-note",type:a.CommandType.MUTATION,handler:(r,o)=>{const{unitId:e,sheetId:t,row:n,col:s,note:i,silent:h}=o;return r.get(m).updateNote(e,t,n,s,i,h),!0}},v={id:"sheet.mutation.remove-note",type:a.CommandType.MUTATION,handler:(r,o)=>{const{unitId:e,sheetId:t,row:n,col:s,silent:i}=o;return r.get(m).removeNote(e,t,n,s,i),!0}},I={id:"sheet.mutation.toggle-note-popup",type:a.CommandType.MUTATION,handler:(r,o)=>{const{unitId:e,sheetId:t,row:n,col:s,silent:i}=o;return r.get(m).toggleNotePopup(e,t,n,s,i),!0}},S={id:"sheet.mutation.update-note-position",type:a.CommandType.MUTATION,handler:(r,o)=>{const{unitId:e,sheetId:t,row:n,col:s,newPosition:i,silent:h}=o;return r.get(m).updateNotePosition(e,t,n,s,i.row,i.col,h),!0}};var b=Object.getOwnPropertyDescriptor,$=(r,o,e,t)=>{for(var n=t>1?void 0:t?b(o,e):o,s=r.length-1,i;s>=0;s--)(i=r[s])&&(n=i(n)||n);return n},f=(r,o)=>(e,t)=>o(e,t,r);let M=class extends a.Disposable{constructor(o,e,t,n){super();p(this,"_disposableMap",new Map);p(this,"_watcherMap",new Map);p(this,"_handleRangeChange",(o,e,t,n,s,i,h)=>i?{redos:[{id:S.id,params:{unitId:o,sheetId:e,row:n,col:s,newPosition:{row:i.startRow,col:i.startColumn},silent:h}}],undos:[{id:S.id,params:{unitId:o,sheetId:e,row:i.startRow,col:i.startColumn,newPosition:{row:n,col:s},note:t,silent:h}}]}:{redos:[{id:v.id,params:{unitId:o,sheetId:e,row:n,col:s}}],undos:[{id:N.id,params:{unitId:o,sheetId:e,row:n,col:s,note:t}}]});this._refRangeService=o,this._sheetsNoteModel=e,this._selectionManagerService=t,this._commandService=n,this._initData(),this._initRefRange()}_getIdWithUnitId(o,e,t,n){return`${o}-${e}-${t}-${n}`}_register(o,e,t,n,s){const i={startColumn:s,endColumn:s,startRow:n,endRow:n};this._disposableMap.set(this._getIdWithUnitId(o,e,n,s),this._refRangeService.registerRefRange(i,h=>{const c=l.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(i,h,{selectionManagerService:this._selectionManagerService}),d=Array.isArray(c)?c[0]:c;return d&&d.startColumn===i.startColumn&&d.startRow===i.startRow?{undos:[],redos:[]}:this._handleRangeChange(o,e,t,n,s,d,!1)},o,e))}_watch(o,e,t,n,s){const i={startColumn:s,endColumn:s,startRow:n,endRow:n};this._watcherMap.set(this._getIdWithUnitId(o,e,n,s),this._refRangeService.watchRange(o,e,i,(h,c)=>{const{redos:d}=this._handleRangeChange(o,e,t,h.startRow,h.startColumn,c,!0);a.sequenceExecuteAsync(d,this._commandService,{onlyLocal:!0})},!0))}_unwatch(o,e,t,n){var i;const s=this._getIdWithUnitId(o,e,t,n);(i=this._watcherMap.get(s))==null||i.dispose(),this._watcherMap.delete(s)}_unregister(o,e,t,n){var i;const s=this._getIdWithUnitId(o,e,t,n);(i=this._disposableMap.get(s))==null||i.dispose(),this._disposableMap.delete(s)}_initData(){const o=this._sheetsNoteModel.getNotes();for(const[e,t]of o)for(const[n,s]of t)s.forValue((i,h,c)=>(c&&(this._register(e,n,c,i,h),this._watch(e,n,c,i,h)),!0))}_initRefRange(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(o=>{switch(o.type){case"update":{const{unitId:e,sheetId:t,row:n,col:s,note:i}=o,h=this._getIdWithUnitId(e,t,n,s);i?this._disposableMap.has(h)||(this._register(e,t,i,n,s),this._watch(e,t,i,n,s)):(this._unregister(e,t,n,s),this._unwatch(e,t,n,s));break}case"ref":{const{unitId:e,sheetId:t,row:n,col:s,newPosition:i,note:h,silent:c}=o;this._unregister(e,t,n,s),c||(this._unwatch(e,t,n,s),this._watch(e,t,h,i.row,i.col)),this._register(e,t,h,i.row,i.col);break}}}))}};M=$([f(0,a.Inject(l.RefRangeService)),f(1,a.Inject(m)),f(2,a.Inject(l.SheetsSelectionsService)),f(3,a.ICommandService)],M);var D=Object.getOwnPropertyDescriptor,j=(r,o,e,t)=>{for(var n=t>1?void 0:t?D(o,e):o,s=r.length-1,i;s>=0;s--)(i=r[s])&&(n=i(n)||n);return n},w=(r,o)=>(e,t)=>o(e,t,r);u.SheetsNoteResourceController=class extends a.Disposable{constructor(o,e,t){super(),this._resourceManagerService=o,this._univerInstanceService=e,this._sheetsNoteModel=t,this._initSnapshot()}_initSnapshot(){const o=t=>{const n=this._sheetsNoteModel.getUnitNotes(t);if(!n)return"";const s={};return n.forEach((i,h)=>{const c={};i.forValue((d,g,q)=>{c[d]||(c[d]={}),c[d][g]=q}),Object.keys(c).length>0&&(s[h]=c)}),JSON.stringify(s)},e=t=>{if(!t)return{};try{return JSON.parse(t)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:T,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:t=>o(t),parseJson:t=>e(t),onUnLoad:t=>{this._sheetsNoteModel.deleteUnitNotes(t)},onLoad:(t,n)=>{Object.entries(n).forEach(([s,i])=>{Object.entries(i).forEach(([h,c])=>{Object.entries(c).forEach(([d,g])=>{this._sheetsNoteModel.updateNote(t,s,Number(h),Number(d),g)})})})}}))}},u.SheetsNoteResourceController=j([w(0,a.IResourceManagerService),w(1,a.IUniverInstanceService),w(2,a.Inject(m))],u.SheetsNoteResourceController);const y={id:"sheet.command.delete-note",type:a.CommandType.COMMAND,handler:(r,o)=>{const e=r.get(a.IUniverInstanceService),t=l.getSheetCommandTarget(e);if(!t)return!1;const s=r.get(l.SheetsSelectionsService).getCurrentLastSelection();if(!(s!=null&&s.primary))return!1;const{actualColumn:i,actualRow:h}=s.primary;return r.get(a.ICommandService).executeCommand(v.id,{unitId:t.unitId,sheetId:t.subUnitId,row:h,col:i})}},P={id:"sheet.command.toggle-note-popup",type:a.CommandType.COMMAND,handler:(r,o)=>{const e=r.get(a.IUniverInstanceService),t=l.getSheetCommandTarget(e);if(!t)return!1;const s=r.get(l.SheetsSelectionsService).getCurrentLastSelection();if(!(s!=null&&s.primary))return!1;const{actualColumn:i,actualRow:h}=s.primary;return r.get(a.ICommandService).executeCommand(I.id,{unitId:t.unitId,sheetId:t.subUnitId,row:h,col:i})}},R={id:"sheet.command.update-note",type:a.CommandType.COMMAND,handler:(r,o)=>r.get(a.ICommandService).syncExecuteCommand(N.id,o)};var x=Object.getOwnPropertyDescriptor,E=(r,o,e,t)=>{for(var n=t>1?void 0:t?x(o,e):o,s=r.length-1,i;s>=0;s--)(i=r[s])&&(n=i(n)||n);return n},V=(r,o)=>(e,t)=>o(e,t,r);let C=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._initialize()}_initialize(){[S,I,N,v,y,P,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};C=E([V(0,a.ICommandService)],C);var A=Object.defineProperty,W=Object.getOwnPropertyDescriptor,L=(r,o,e)=>o in r?A(r,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[o]=e,J=(r,o,e,t)=>{for(var n=t>1?void 0:t?W(o,e):o,s=r.length-1,i;s>=0;s--)(i=r[s])&&(n=i(n)||n);return n},U=(r,o)=>(e,t)=>o(e,t,r),O=(r,o,e)=>L(r,typeof o!="symbol"?o+"":o,e);const T="SHEET_NOTE_PLUGIN";u.UniverSheetsNotePlugin=class extends a.Plugin{constructor(o,e){super(),this._configService=o,this._injector=e}onStarting(){[[m],[C],[u.SheetsNoteResourceController],[M]].forEach(o=>{this._injector.add(o)}),a.touchDependencies(this._injector,[[m],[C],[u.SheetsNoteResourceController]])}onReady(){a.touchDependencies(this._injector,[[M]])}},O(u.UniverSheetsNotePlugin,"pluginName",T),O(u.UniverSheetsNotePlugin,"type",a.UniverInstanceType.UNIVER_SHEET),u.UniverSheetsNotePlugin=J([a.DependentOn(l.UniverSheetsPlugin),U(0,a.IConfigService),U(1,a.Inject(a.Injector))],u.UniverSheetsNotePlugin),u.RemoveNoteMutation=v,u.SheetDeleteNoteCommand=y,u.SheetToggleNotePopupCommand=P,u.SheetUpdateNoteCommand=R,u.SheetsNoteModel=m,u.ToggleNotePopupMutation=I,u.UpdateNoteMutation=N,u.UpdateNotePositionMutation=S,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@univerjs/sheets-note",
3
+ "version": "0.7.0-beta.1",
4
+ "private": false,
5
+ "description": "Univer sheets note base plugin",
6
+ "author": "DreamNum <developer@univer.ai>",
7
+ "license": "Apache-2.0",
8
+ "funding": {
9
+ "type": "opencollective",
10
+ "url": "https://opencollective.com/univer"
11
+ },
12
+ "homepage": "https://univer.ai",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/dream-num/univer"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/dream-num/univer/issues"
19
+ },
20
+ "keywords": [],
21
+ "exports": {
22
+ ".": {
23
+ "import": "./lib/es/index.js",
24
+ "require": "./lib/cjs/index.js",
25
+ "types": "./lib/types/index.d.ts"
26
+ },
27
+ "./*": {
28
+ "import": "./lib/es/*",
29
+ "require": "./lib/cjs/*",
30
+ "types": "./lib/types/index.d.ts"
31
+ },
32
+ "./facade": {
33
+ "import": "./lib/es/facade.js",
34
+ "require": "./lib/cjs/facade.js",
35
+ "types": "./lib/types/facade/index.d.ts"
36
+ },
37
+ "./lib/facade": {
38
+ "import": "./lib/es/facade.js",
39
+ "require": "./lib/cjs/facade.js",
40
+ "types": "./lib/types/facade/index.d.ts"
41
+ },
42
+ "./lib/*": "./lib/*"
43
+ },
44
+ "main": "./lib/es/index.js",
45
+ "types": "./lib/types/index.d.ts",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "directories": {
50
+ "lib": "lib"
51
+ },
52
+ "files": [
53
+ "lib"
54
+ ],
55
+ "peerDependencies": {
56
+ "rxjs": ">=7.0.0"
57
+ },
58
+ "dependencies": {
59
+ "@univerjs/core": "0.7.0-beta.1",
60
+ "@univerjs/sheets": "0.7.0-beta.1"
61
+ },
62
+ "devDependencies": {
63
+ "rxjs": "^7.8.1",
64
+ "typescript": "^5.8.3",
65
+ "vite": "^6.3.5",
66
+ "vitest": "^3.1.3",
67
+ "@univerjs-infra/shared": "0.7.0-beta.1"
68
+ },
69
+ "scripts": {
70
+ "test": "vitest run",
71
+ "test:watch": "vitest",
72
+ "coverage": "vitest run --coverage",
73
+ "lint:types": "tsc --noEmit",
74
+ "build": "univer-cli build"
75
+ },
76
+ "module": "./lib/es/index.js"
77
+ }