Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat: update sheets-note facade example (#5208)
wpxp123456e138b47f166f
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex e7b4e9d4be..a5336f15d1 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -42,6 +42,7 @@ import { UniverUIPlugin } from '@univerjs/ui';import { enUS, faIR, frFR, ruRU, viVN, zhCN, zhTW } from '../locales';import { UniverSheetsCustomMenuPlugin } from './custom-menu';import ImportCSVButtonPlugin from './custom-plugin/import-csv-button';+import '@univerjs/sheets/facade';import '@univerjs/ui/facade';import '@univerjs/docs-ui/facade';@@ -62,6 +63,7 @@ import '@univerjs/sheets-formula-ui/facade';import '@univerjs/sheets-table/facade';import '@univerjs/sheets-sort/facade';import '@univerjs/network/facade';+import '@univerjs/sheets-note/facade';import '../global.css';import './styles';@@ -108,7 +110,10 @@ function createNewInstance() {});univer.registerPlugin(UniverDocsUIPlugin);- univer.registerPlugin(UniverSheetsPlugin, { notExecuteFormula: true });+ univer.registerPlugin(UniverSheetsPlugin, {+ notExecuteFormula: true,+ autoHeightForMergedCells: true,+ });univer.registerPlugin(UniverSheetsUIPlugin);univer.registerPlugin(UniverSheetsNumfmtPlugin, {disableTextFormatAlert: true,diff --git a/packages/sheets-note/src/facade/f-event.ts b/packages/sheets-note/src/facade/f-event.tsindex fc19b8a627..da27fef1a0 100644--- a/packages/sheets-note/src/facade/f-event.ts+++ b/packages/sheets-note/src/facade/f-event.ts@@ -18,7 +18,7 @@ import type { ISheetNote } from '@univerjs/sheets-note';import type { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';import { FEventName } from '@univerjs/core/facade';-export interface ISheetNoteAddEventParmas {+export interface ISheetNoteAddEventParams {workbook: FWorkbook;worksheet: FWorksheet;row: number;@@ -27,7 +27,7 @@ export interface ISheetNoteAddEventParmas {cancel?: boolean;}-export interface ISheetNoteDeleteEventParmas {+export interface ISheetNoteDeleteEventParams {workbook: FWorkbook;worksheet: FWorksheet;row: number;@@ -36,7 +36,7 @@ export interface ISheetNoteDeleteEventParmas {cancel?: boolean;}-export interface ISheetNoteUpdateEventParmas {+export interface ISheetNoteUpdateEventParams {workbook: FWorkbook;worksheet: FWorksheet;row: number;@@ -46,7 +46,7 @@ export interface ISheetNoteUpdateEventParmas {cancel?: boolean;}-export interface ISheetNoteShowEventParmas {+export interface ISheetNoteShowEventParams {workbook: FWorkbook;worksheet: FWorksheet;row: number;@@ -54,7 +54,7 @@ export interface ISheetNoteShowEventParmas {cancel?: boolean;}-export interface ISheetNoteHideEventParmas {+export interface ISheetNoteHideEventParams {workbook: FWorkbook;worksheet: FWorksheet;row: number;@@ -66,17 +66,17 @@ export interface ISheetNoteHideEventParmas {* @ignore*/export interface ISheetsNoteEventParamConfig {- SheetNoteAdd: ISheetNoteAddEventParmas;- SheetNoteDelete: ISheetNoteDeleteEventParmas;- SheetNoteUpdate: ISheetNoteUpdateEventParmas;- SheetNoteShow: ISheetNoteShowEventParmas;- SheetNoteHide: ISheetNoteHideEventParmas;+ SheetNoteAdd: ISheetNoteAddEventParams;+ SheetNoteDelete: ISheetNoteDeleteEventParams;+ SheetNoteUpdate: ISheetNoteUpdateEventParams;+ SheetNoteShow: ISheetNoteShowEventParams;+ SheetNoteHide: ISheetNoteHideEventParams;- BeforeSheetNoteAdd: ISheetNoteAddEventParmas;- BeforeSheetNoteDelete: ISheetNoteDeleteEventParmas;- BeforeSheetNoteUpdate: ISheetNoteUpdateEventParmas;- BeforeSheetNoteShow: ISheetNoteShowEventParmas;- BeforeSheetNoteHide: ISheetNoteHideEventParmas;+ BeforeSheetNoteAdd: ISheetNoteAddEventParams;+ BeforeSheetNoteDelete: ISheetNoteDeleteEventParams;+ BeforeSheetNoteUpdate: ISheetNoteUpdateEventParams;+ BeforeSheetNoteShow: ISheetNoteShowEventParams;+ BeforeSheetNoteHide: ISheetNoteHideEventParams;}/**@@ -85,122 +85,157 @@ export interface ISheetsNoteEventParamConfig {interface ISheetNoteEvent {/*** Event fired when a note is added- * @see {@link ISheetNoteAddEventParmas}+ * @see {@link ISheetNoteAddEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteAdd, (params) => {* const { workbook, worksheet, row, col, note } = params;* console.log(params);* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/SheetNoteAdd: 'SheetNoteAdd';/*** Event fired when a note is deleted- * @see {@link ISheetNoteDeleteEventParmas}+ * @see {@link ISheetNoteDeleteEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteDelete, (params) => {* const { workbook, worksheet, row, col, oldNote } = params;* console.log(params);* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/SheetNoteDelete: 'SheetNoteDelete';/*** Event fired when a note is updated- * @see {@link ISheetNoteUpdateEventParmas}+ * @see {@link ISheetNoteUpdateEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteUpdate, (params) => {* const { workbook, worksheet, row, col, note, oldNote } = params;* console.log(params);* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/SheetNoteUpdate: 'SheetNoteUpdate';/*** Event fired when a note is shown- * @see {@link ISheetNoteShowEventParmas}+ * @see {@link ISheetNoteShowEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteShow, (params) => {* const { workbook, worksheet, row, col } = params;* console.log(params);* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/SheetNoteShow: 'SheetNoteShow';/*** Event fired when a note is hidden- * @see {@link ISheetNoteHideEventParmas}+ * @see {@link ISheetNoteHideEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.SheetNoteHide, (params) => {* const { workbook, worksheet, row, col } = params;* console.log(params);* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/SheetNoteHide: 'SheetNoteHide';/*** Event fired before a note is added- * @see {@link ISheetNoteAddEventParmas}+ * @see {@link ISheetNoteAddEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteAdd, (params) => {* const { workbook, worksheet, row, col, note } = params;* console.log(params);+ *+ * // Cancel the note addition operation+ * params.cancel = true;* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/BeforeSheetNoteAdd: 'BeforeSheetNoteAdd';/*** Event fired before a note is deleted- * @see {@link ISheetNoteDeleteEventParmas}+ * @see {@link ISheetNoteDeleteEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteDelete, (params) => {* const { workbook, worksheet, row, col, oldNote } = params;* console.log(params);+ *+ * // Cancel the note deletion operation+ * params.cancel = true;* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/BeforeSheetNoteDelete: 'BeforeSheetNoteDelete';/*** Event fired before a note is updated- * @see {@link ISheetNoteUpdateEventParmas}+ * @see {@link ISheetNoteUpdateEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteUpdate, (params) => {* const { workbook, worksheet, row, col, note, oldNote } = params;* console.log(params);+ *+ * // Cancel the note update operation+ * params.cancel = true;* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/BeforeSheetNoteUpdate: 'BeforeSheetNoteUpdate';/*** Event fired before a note is shown- * @see {@link ISheetNoteShowEventParmas}+ * @see {@link ISheetNoteShowEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteShow, (params) => {* const { workbook, worksheet, row, col } = params;* console.log(params);+ *+ * // Cancel the note show operation+ * params.cancel = true;* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/BeforeSheetNoteShow: 'BeforeSheetNoteShow';/*** Event fired before a note is hidden- * @see {@link ISheetNoteHideEventParmas}+ * @see {@link ISheetNoteHideEventParams}* @example* ```ts* const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetNoteHide, (params) => {* const { workbook, worksheet, row, col } = params;* console.log(params);+ *+ * // Cancel the note hide operation+ * params.cancel = true;* });+ *+ * // Remove the event listener, use `disposable.dispose()`* ```*/BeforeSheetNoteHide: 'BeforeSheetNoteHide';@@ -255,17 +290,17 @@ export class FSheetNoteEvent implements ISheetNoteEvent {* @ignore*/export interface ISheetNoteEventConfig {- SheetNoteAdd: ISheetNoteAddEventParmas;- SheetNoteDelete: ISheetNoteDeleteEventParmas;- SheetNoteUpdate: ISheetNoteUpdateEventParmas;- SheetNoteShow: ISheetNoteShowEventParmas;- SheetNoteHide: ISheetNoteHideEventParmas;+ SheetNoteAdd: ISheetNoteAddEventParams;+ SheetNoteDelete: ISheetNoteDeleteEventParams;+ SheetNoteUpdate: ISheetNoteUpdateEventParams;+ SheetNoteShow: ISheetNoteShowEventParams;+ SheetNoteHide: ISheetNoteHideEventParams;- BeforeSheetNoteAdd: ISheetNoteAddEventParmas;- BeforeSheetNoteDelete: ISheetNoteDeleteEventParmas;- BeforeSheetNoteUpdate: ISheetNoteUpdateEventParmas;- BeforeSheetNoteShow: ISheetNoteShowEventParmas;- BeforeSheetNoteHide: ISheetNoteHideEventParmas;+ BeforeSheetNoteAdd: ISheetNoteAddEventParams;+ BeforeSheetNoteDelete: ISheetNoteDeleteEventParams;+ BeforeSheetNoteUpdate: ISheetNoteUpdateEventParams;+ BeforeSheetNoteShow: ISheetNoteShowEventParams;+ BeforeSheetNoteHide: ISheetNoteHideEventParams;}FEventName.extend(FSheetNoteEvent);diff --git a/packages/sheets-note/src/facade/f-range.ts b/packages/sheets-note/src/facade/f-range.tsindex 716f85e1a3..9e661bb88c 100644--- a/packages/sheets-note/src/facade/f-range.ts+++ b/packages/sheets-note/src/facade/f-range.ts@@ -21,39 +21,51 @@ import { FRange } from '@univerjs/sheets/facade';export interface IFSheetsNoteRange {/**- * get the note of the primary cell- * @returns {Nullable<ISheetNote>} the note of the primary cell+ * Get the annotation of the top-left cell in the range+ * @returns {Nullable<ISheetNote>} The annotation of the top-left cell in the range* @example* ```ts- * const fWorkbook = univerAPI.getWorkbook();- * const fWorksheet = fWorkbook.getWorksheet();- * const fRange = fWorksheet.getRange(0, 0, 1, 1);+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const fRange = fWorksheet.getRange('A1:D10');* const note = fRange.getNote();+ * console.log(note);* ```*/getNote(): Nullable<ISheetNote>;/**- * create a new note and attach to the primary cell- * @param {ISheetNote} note the note to create- * @returns {FRange} the range+ * Create or update the annotation of the top-left cell in the range+ * @param {ISheetNote} note The annotation to create or update+ * @returns {FRange} This range for method chaining* @example* ```ts- * const fWorkbook = univerAPI.getWorkbook();- * const fWorksheet = fWorkbook.getWorksheet();- * const fRange = fWorksheet.getRange(0, 0, 1, 1);- * const note = fRange.createOrUpdateNote({});+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const fRange = fWorksheet.getRange('A1');+ * fRange.createOrUpdateNote({+ * note: 'This is a note',+ * width: 160,+ * height: 100,+ * show: true,+ * });* ```*/createOrUpdateNote(note: ISheetNote): FRange;/**- * delete the note of the primary cell- * @returns {FRange} the range+ * Delete the annotation of the top-left cell in the range+ * @returns {FRange} This range for method chaining* @example* ```ts- * const fWorkbook = univerAPI.getWorkbook();- * const fWorksheet = fWorkbook.getWorksheet();- * const fRange = fWorksheet.getRange(0, 0, 1, 1);- * fRange.deleteNote();+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const notes = fWorksheet.getNotes();+ * console.log(notes);+ *+ * if (notes.length > 0) {+ * // Delete the first note+ * const { row, col } = notes[0];+ * fWorksheet.getRange(row, col).deleteNote();+ * }* ```*/deleteNote(): FRange;@@ -76,7 +88,6 @@ export class FSheetsNoteRange extends FRange implements IFSheetsNoteRange {}deleteNote(): FRange {- const model = this._injector.get(SheetsNoteModel);this._commandService.syncExecuteCommand(RemoveNoteMutation.id,{diff --git a/packages/sheets-note/src/facade/f-worksheet.ts b/packages/sheets-note/src/facade/f-worksheet.tsindex ceaefc6b81..92898e3519 100644--- a/packages/sheets-note/src/facade/f-worksheet.ts+++ b/packages/sheets-note/src/facade/f-worksheet.ts@@ -25,7 +25,20 @@ export interface ISheetNoteInfo extends ISheetNote {export interface IFSheetsNoteWorksheet {/**- * get the note of the primary cell+ * Get all annotations in the worksheet+ * @returns {ISheetNoteInfo[]} An array of all annotations in the worksheet+ * @example+ * ```ts+ * const fWorkbook = univerAPI.getActiveWorkbook();+ * const fWorksheet = fWorkbook.getActiveSheet();+ * const notes = fWorksheet.getNotes();+ * console.log(notes);+ *+ * notes.forEach((item) => {+ * const { row, col, note } = item;+ * console.log(`Cell ${fWorksheet.getRange(row, col).getA1Notation()} has a note: ${note}`);+ * });+ * ```*/getNotes(): ISheetNoteInfo[];}