@univerjs/sheets-note-ui 1.0.0-alpha.1 → 1.0.0-alpha.3

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.
package/lib/cjs/index.js CHANGED
@@ -6,8 +6,8 @@ let _univerjs_sheets_note = require("@univerjs/sheets-note");
6
6
  let rxjs = require("rxjs");
7
7
  let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
8
8
  let rxjs_operators = require("rxjs/operators");
9
- let _univerjs_icons = require("@univerjs/icons");
10
9
  let _univerjs_ui = require("@univerjs/ui");
10
+ let _univerjs_icons = require("@univerjs/icons");
11
11
  let _univerjs_design = require("@univerjs/design");
12
12
  let react = require("react");
13
13
  let react_jsx_runtime = require("react/jsx-runtime");
@@ -334,10 +334,110 @@ SheetsNotePopupController = __decorate([
334
334
  __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService))
335
335
  ], SheetsNotePopupController);
336
336
 
337
+ //#endregion
338
+ //#region src/commands/operations/add-note-popup.operation.ts
339
+ const AddNotePopupOperation = {
340
+ id: "sheet.operation.add-note-popup",
341
+ type: _univerjs_core.CommandType.OPERATION,
342
+ handler: async (accessor, params) => {
343
+ var _params$trigger;
344
+ const selectionService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
345
+ const notePopupService = accessor.get(SheetsNotePopupService);
346
+ const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
347
+ if (!workbook) return false;
348
+ const worksheet = workbook.getActiveSheet();
349
+ const lastSelection = selectionService.getCurrentLastSelection();
350
+ if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
351
+ const { primary } = lastSelection;
352
+ notePopupService.showPopup({
353
+ unitId: workbook.getUnitId(),
354
+ subUnitId: worksheet.getSheetId(),
355
+ row: primary.actualRow,
356
+ col: primary.actualColumn,
357
+ temp: false,
358
+ trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
359
+ });
360
+ return true;
361
+ }
362
+ };
363
+
364
+ //#endregion
365
+ //#region src/menu/note.menu.ts
366
+ function getHasNote$(accessor) {
367
+ const sheetsSelectionsService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
368
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
369
+ return sheetsSelectionsService.selectionMoveEnd$.pipe((0, rxjs.map)(() => {
370
+ const selection = sheetsSelectionsService.getCurrentLastSelection();
371
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
372
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
373
+ if (!target) return false;
374
+ const { actualColumn, actualRow } = selection.primary;
375
+ const noteModel = accessor.get(_univerjs_sheets_note.SheetsNoteModel);
376
+ return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
377
+ row: actualRow,
378
+ col: actualColumn
379
+ }));
380
+ }));
381
+ }
382
+ function sheetNoteContextMenuFactory(accessor) {
383
+ return {
384
+ id: AddNotePopupOperation.id,
385
+ type: _univerjs_ui.MenuItemType.BUTTON,
386
+ title: "sheets-note-ui.rightClick.addNote",
387
+ icon: "AddNoteIcon",
388
+ hidden$: (0, rxjs.combineLatest)([(0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe((0, rxjs.map)(([hidden, hasNote]) => hidden || hasNote)),
389
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
390
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
391
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
392
+ }),
393
+ commandId: AddNotePopupOperation.id
394
+ };
395
+ }
396
+ function sheetDeleteNoteMenuFactory(accessor) {
397
+ return {
398
+ id: _univerjs_sheets_note.SheetDeleteNoteCommand.id,
399
+ type: _univerjs_ui.MenuItemType.BUTTON,
400
+ title: "sheets-note-ui.rightClick.deleteNote",
401
+ icon: "DeleteNoteIcon",
402
+ hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote)),
403
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
404
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
405
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
406
+ })
407
+ };
408
+ }
409
+ function sheetNoteToggleMenuFactory(accessor) {
410
+ return {
411
+ id: _univerjs_sheets_note.SheetToggleNotePopupCommand.id,
412
+ type: _univerjs_ui.MenuItemType.BUTTON,
413
+ title: "sheets-note-ui.rightClick.toggleNote",
414
+ icon: "HideNoteIcon",
415
+ hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote))
416
+ };
417
+ }
418
+
419
+ //#endregion
420
+ //#region src/menu/schema.ts
421
+ const menuSchema = { [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
422
+ order: 0,
423
+ [AddNotePopupOperation.id]: {
424
+ order: 0,
425
+ menuItemFactory: sheetNoteContextMenuFactory
426
+ },
427
+ [_univerjs_sheets_note.SheetDeleteNoteCommand.id]: {
428
+ order: 0,
429
+ menuItemFactory: sheetDeleteNoteMenuFactory
430
+ },
431
+ [_univerjs_sheets_note.SheetToggleNotePopupCommand.id]: {
432
+ order: 0,
433
+ menuItemFactory: sheetNoteToggleMenuFactory
434
+ }
435
+ } } };
436
+
337
437
  //#endregion
338
438
  //#region package.json
339
439
  var name = "@univerjs/sheets-note-ui";
340
- var version = "1.0.0-alpha.1";
440
+ var version = "1.0.0-alpha.3";
341
441
 
342
442
  //#endregion
343
443
  //#region src/config/config.ts
@@ -361,8 +461,17 @@ const SheetsNote = (props) => {
361
461
  return null;
362
462
  }
363
463
  const textareaRef = (0, react.useRef)(null);
464
+ const initialWidthRef = (0, react.useRef)(null);
364
465
  const currentRender = renderManagerService.getRenderById(activePopup.unitId);
365
466
  const [note, setNote] = (0, react.useState)(null);
467
+ const applyResizeOffset = (0, react.useCallback)((width) => {
468
+ const textarea = textareaRef.current;
469
+ if (!textarea) return;
470
+ if (localeService.getDirection() === "rtl" && initialWidthRef.current != null) {
471
+ const offset = initialWidthRef.current - width;
472
+ textarea.style.transform = offset ? `translateX(${offset}px)` : "";
473
+ } else textarea.style.transform = "";
474
+ }, [localeService]);
366
475
  (0, react.useEffect)(() => {
367
476
  var _ref, _note$width, _config$defaultNoteSi, _ref2, _note$height, _config$defaultNoteSi2;
368
477
  const { unitId, subUnitId, row, col } = activePopup;
@@ -383,8 +492,10 @@ const SheetsNote = (props) => {
383
492
  updateNote(initNote);
384
493
  } else setNote(note);
385
494
  if (textareaRef.current) {
495
+ initialWidthRef.current = width;
386
496
  textareaRef.current.style.width = `${width}px`;
387
497
  textareaRef.current.style.height = `${height}px`;
498
+ textareaRef.current.style.transform = "";
388
499
  }
389
500
  }, [activePopup, textareaRef]);
390
501
  (0, react.useEffect)(() => {
@@ -428,6 +539,7 @@ const SheetsNote = (props) => {
428
539
  }, [note]);
429
540
  const handleResize = (0, react.useCallback)((width, height) => {
430
541
  if (!note) return;
542
+ applyResizeOffset(width);
431
543
  if (width === note.width && height === note.height) return;
432
544
  const newNote = {
433
545
  ...note,
@@ -436,7 +548,7 @@ const SheetsNote = (props) => {
436
548
  };
437
549
  setNote(newNote);
438
550
  updateNote(newNote);
439
- }, [note]);
551
+ }, [applyResizeOffset, note]);
440
552
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Textarea, {
441
553
  ref: textareaRef,
442
554
  "data-u-comp": "note-textarea",
@@ -603,106 +715,6 @@ SheetsNoteAttachmentController = __decorate([
603
715
  __decorateParam(3, (0, _univerjs_core.Inject)(SheetsNotePopupService))
604
716
  ], SheetsNoteAttachmentController);
605
717
 
606
- //#endregion
607
- //#region src/commands/operations/add-note-popup.operation.ts
608
- const AddNotePopupOperation = {
609
- id: "sheet.operation.add-note-popup",
610
- type: _univerjs_core.CommandType.OPERATION,
611
- handler: async (accessor, params) => {
612
- var _params$trigger;
613
- const selectionService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
614
- const notePopupService = accessor.get(SheetsNotePopupService);
615
- const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
616
- if (!workbook) return false;
617
- const worksheet = workbook.getActiveSheet();
618
- const lastSelection = selectionService.getCurrentLastSelection();
619
- if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
620
- const { primary } = lastSelection;
621
- notePopupService.showPopup({
622
- unitId: workbook.getUnitId(),
623
- subUnitId: worksheet.getSheetId(),
624
- row: primary.actualRow,
625
- col: primary.actualColumn,
626
- temp: false,
627
- trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
628
- });
629
- return true;
630
- }
631
- };
632
-
633
- //#endregion
634
- //#region src/menu/note.menu.ts
635
- function getHasNote$(accessor) {
636
- const sheetsSelectionsService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
637
- const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
638
- return sheetsSelectionsService.selectionMoveEnd$.pipe((0, rxjs.map)(() => {
639
- const selection = sheetsSelectionsService.getCurrentLastSelection();
640
- if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
641
- const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
642
- if (!target) return false;
643
- const { actualColumn, actualRow } = selection.primary;
644
- const noteModel = accessor.get(_univerjs_sheets_note.SheetsNoteModel);
645
- return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
646
- row: actualRow,
647
- col: actualColumn
648
- }));
649
- }));
650
- }
651
- function sheetNoteContextMenuFactory(accessor) {
652
- return {
653
- id: AddNotePopupOperation.id,
654
- type: _univerjs_ui.MenuItemType.BUTTON,
655
- title: "sheets-note-ui.rightClick.addNote",
656
- icon: "AddNoteIcon",
657
- hidden$: (0, rxjs.combineLatest)([(0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe((0, rxjs.map)(([hidden, hasNote]) => hidden || hasNote)),
658
- disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
659
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
660
- worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
661
- }),
662
- commandId: AddNotePopupOperation.id
663
- };
664
- }
665
- function sheetDeleteNoteMenuFactory(accessor) {
666
- return {
667
- id: _univerjs_sheets_note.SheetDeleteNoteCommand.id,
668
- type: _univerjs_ui.MenuItemType.BUTTON,
669
- title: "sheets-note-ui.rightClick.deleteNote",
670
- icon: "DeleteNoteIcon",
671
- hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote)),
672
- disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
673
- workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
674
- worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
675
- })
676
- };
677
- }
678
- function sheetNoteToggleMenuFactory(accessor) {
679
- return {
680
- id: _univerjs_sheets_note.SheetToggleNotePopupCommand.id,
681
- type: _univerjs_ui.MenuItemType.BUTTON,
682
- title: "sheets-note-ui.rightClick.toggleNote",
683
- icon: "HideNoteIcon",
684
- hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote))
685
- };
686
- }
687
-
688
- //#endregion
689
- //#region src/menu/schema.ts
690
- const menuSchema = { [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
691
- order: 0,
692
- [AddNotePopupOperation.id]: {
693
- order: 0,
694
- menuItemFactory: sheetNoteContextMenuFactory
695
- },
696
- [_univerjs_sheets_note.SheetDeleteNoteCommand.id]: {
697
- order: 0,
698
- menuItemFactory: sheetDeleteNoteMenuFactory
699
- },
700
- [_univerjs_sheets_note.SheetToggleNotePopupCommand.id]: {
701
- order: 0,
702
- menuItemFactory: sheetNoteToggleMenuFactory
703
- }
704
- } } };
705
-
706
718
  //#endregion
707
719
  //#region src/controllers/ui.controller.ts
708
720
  /**
@@ -798,6 +810,7 @@ Object.defineProperty(exports, 'SheetsNotePopupService', {
798
810
  return SheetsNotePopupService;
799
811
  }
800
812
  });
813
+ exports.SheetsNoteUIMenuSchema = menuSchema;
801
814
  Object.defineProperty(exports, 'UniverSheetsNoteUIPlugin', {
802
815
  enumerable: true,
803
816
  get: function () {
package/lib/es/index.js CHANGED
@@ -5,8 +5,8 @@ import { SheetDeleteNoteCommand, SheetToggleNotePopupCommand, SheetUpdateNoteCom
5
5
  import { BehaviorSubject, combineLatest, debounceTime, map, of, switchMap } from "rxjs";
6
6
  import { CellPopupManagerService, HoverManagerService, IEditorBridgeService, SheetSkeletonManagerService, getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
7
7
  import { debounceTime as debounceTime$1 } from "rxjs/operators";
8
- import { AddNoteIcon, DeleteNoteIcon, HideNoteIcon } from "@univerjs/icons";
9
8
  import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IconManager, MenuItemType, getMenuHiddenObservable, useConfigValue, useDebounceFn, useDependency } from "@univerjs/ui";
9
+ import { AddNoteIcon, DeleteNoteIcon, HideNoteIcon } from "@univerjs/icons";
10
10
  import { Textarea, clsx } from "@univerjs/design";
11
11
  import { useCallback, useEffect, useRef, useState } from "react";
12
12
  import { jsx } from "react/jsx-runtime";
@@ -333,10 +333,110 @@ SheetsNotePopupController = __decorate([
333
333
  __decorateParam(5, Inject(HoverManagerService))
334
334
  ], SheetsNotePopupController);
335
335
 
336
+ //#endregion
337
+ //#region src/commands/operations/add-note-popup.operation.ts
338
+ const AddNotePopupOperation = {
339
+ id: "sheet.operation.add-note-popup",
340
+ type: CommandType.OPERATION,
341
+ handler: async (accessor, params) => {
342
+ var _params$trigger;
343
+ const selectionService = accessor.get(SheetsSelectionsService);
344
+ const notePopupService = accessor.get(SheetsNotePopupService);
345
+ const workbook = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
346
+ if (!workbook) return false;
347
+ const worksheet = workbook.getActiveSheet();
348
+ const lastSelection = selectionService.getCurrentLastSelection();
349
+ if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
350
+ const { primary } = lastSelection;
351
+ notePopupService.showPopup({
352
+ unitId: workbook.getUnitId(),
353
+ subUnitId: worksheet.getSheetId(),
354
+ row: primary.actualRow,
355
+ col: primary.actualColumn,
356
+ temp: false,
357
+ trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
358
+ });
359
+ return true;
360
+ }
361
+ };
362
+
363
+ //#endregion
364
+ //#region src/menu/note.menu.ts
365
+ function getHasNote$(accessor) {
366
+ const sheetsSelectionsService = accessor.get(SheetsSelectionsService);
367
+ const univerInstanceService = accessor.get(IUniverInstanceService);
368
+ return sheetsSelectionsService.selectionMoveEnd$.pipe(map(() => {
369
+ const selection = sheetsSelectionsService.getCurrentLastSelection();
370
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
371
+ const target = getSheetCommandTarget(univerInstanceService);
372
+ if (!target) return false;
373
+ const { actualColumn, actualRow } = selection.primary;
374
+ const noteModel = accessor.get(SheetsNoteModel);
375
+ return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
376
+ row: actualRow,
377
+ col: actualColumn
378
+ }));
379
+ }));
380
+ }
381
+ function sheetNoteContextMenuFactory(accessor) {
382
+ return {
383
+ id: AddNotePopupOperation.id,
384
+ type: MenuItemType.BUTTON,
385
+ title: "sheets-note-ui.rightClick.addNote",
386
+ icon: "AddNoteIcon",
387
+ hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe(map(([hidden, hasNote]) => hidden || hasNote)),
388
+ disabled$: getCurrentRangeDisable$(accessor, {
389
+ workbookTypes: [WorkbookEditablePermission],
390
+ worksheetTypes: [WorksheetEditPermission]
391
+ }),
392
+ commandId: AddNotePopupOperation.id
393
+ };
394
+ }
395
+ function sheetDeleteNoteMenuFactory(accessor) {
396
+ return {
397
+ id: SheetDeleteNoteCommand.id,
398
+ type: MenuItemType.BUTTON,
399
+ title: "sheets-note-ui.rightClick.deleteNote",
400
+ icon: "DeleteNoteIcon",
401
+ hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote)),
402
+ disabled$: getCurrentRangeDisable$(accessor, {
403
+ workbookTypes: [WorkbookEditablePermission],
404
+ worksheetTypes: [WorksheetEditPermission]
405
+ })
406
+ };
407
+ }
408
+ function sheetNoteToggleMenuFactory(accessor) {
409
+ return {
410
+ id: SheetToggleNotePopupCommand.id,
411
+ type: MenuItemType.BUTTON,
412
+ title: "sheets-note-ui.rightClick.toggleNote",
413
+ icon: "HideNoteIcon",
414
+ hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote))
415
+ };
416
+ }
417
+
418
+ //#endregion
419
+ //#region src/menu/schema.ts
420
+ const menuSchema = { [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.OTHERS]: {
421
+ order: 0,
422
+ [AddNotePopupOperation.id]: {
423
+ order: 0,
424
+ menuItemFactory: sheetNoteContextMenuFactory
425
+ },
426
+ [SheetDeleteNoteCommand.id]: {
427
+ order: 0,
428
+ menuItemFactory: sheetDeleteNoteMenuFactory
429
+ },
430
+ [SheetToggleNotePopupCommand.id]: {
431
+ order: 0,
432
+ menuItemFactory: sheetNoteToggleMenuFactory
433
+ }
434
+ } } };
435
+
336
436
  //#endregion
337
437
  //#region package.json
338
438
  var name = "@univerjs/sheets-note-ui";
339
- var version = "1.0.0-alpha.1";
439
+ var version = "1.0.0-alpha.3";
340
440
 
341
441
  //#endregion
342
442
  //#region src/config/config.ts
@@ -360,8 +460,17 @@ const SheetsNote = (props) => {
360
460
  return null;
361
461
  }
362
462
  const textareaRef = useRef(null);
463
+ const initialWidthRef = useRef(null);
363
464
  const currentRender = renderManagerService.getRenderById(activePopup.unitId);
364
465
  const [note, setNote] = useState(null);
466
+ const applyResizeOffset = useCallback((width) => {
467
+ const textarea = textareaRef.current;
468
+ if (!textarea) return;
469
+ if (localeService.getDirection() === "rtl" && initialWidthRef.current != null) {
470
+ const offset = initialWidthRef.current - width;
471
+ textarea.style.transform = offset ? `translateX(${offset}px)` : "";
472
+ } else textarea.style.transform = "";
473
+ }, [localeService]);
365
474
  useEffect(() => {
366
475
  var _ref, _note$width, _config$defaultNoteSi, _ref2, _note$height, _config$defaultNoteSi2;
367
476
  const { unitId, subUnitId, row, col } = activePopup;
@@ -382,8 +491,10 @@ const SheetsNote = (props) => {
382
491
  updateNote(initNote);
383
492
  } else setNote(note);
384
493
  if (textareaRef.current) {
494
+ initialWidthRef.current = width;
385
495
  textareaRef.current.style.width = `${width}px`;
386
496
  textareaRef.current.style.height = `${height}px`;
497
+ textareaRef.current.style.transform = "";
387
498
  }
388
499
  }, [activePopup, textareaRef]);
389
500
  useEffect(() => {
@@ -427,6 +538,7 @@ const SheetsNote = (props) => {
427
538
  }, [note]);
428
539
  const handleResize = useCallback((width, height) => {
429
540
  if (!note) return;
541
+ applyResizeOffset(width);
430
542
  if (width === note.width && height === note.height) return;
431
543
  const newNote = {
432
544
  ...note,
@@ -435,7 +547,7 @@ const SheetsNote = (props) => {
435
547
  };
436
548
  setNote(newNote);
437
549
  updateNote(newNote);
438
- }, [note]);
550
+ }, [applyResizeOffset, note]);
439
551
  return /* @__PURE__ */ jsx(Textarea, {
440
552
  ref: textareaRef,
441
553
  "data-u-comp": "note-textarea",
@@ -602,106 +714,6 @@ SheetsNoteAttachmentController = __decorate([
602
714
  __decorateParam(3, Inject(SheetsNotePopupService))
603
715
  ], SheetsNoteAttachmentController);
604
716
 
605
- //#endregion
606
- //#region src/commands/operations/add-note-popup.operation.ts
607
- const AddNotePopupOperation = {
608
- id: "sheet.operation.add-note-popup",
609
- type: CommandType.OPERATION,
610
- handler: async (accessor, params) => {
611
- var _params$trigger;
612
- const selectionService = accessor.get(SheetsSelectionsService);
613
- const notePopupService = accessor.get(SheetsNotePopupService);
614
- const workbook = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
615
- if (!workbook) return false;
616
- const worksheet = workbook.getActiveSheet();
617
- const lastSelection = selectionService.getCurrentLastSelection();
618
- if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
619
- const { primary } = lastSelection;
620
- notePopupService.showPopup({
621
- unitId: workbook.getUnitId(),
622
- subUnitId: worksheet.getSheetId(),
623
- row: primary.actualRow,
624
- col: primary.actualColumn,
625
- temp: false,
626
- trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
627
- });
628
- return true;
629
- }
630
- };
631
-
632
- //#endregion
633
- //#region src/menu/note.menu.ts
634
- function getHasNote$(accessor) {
635
- const sheetsSelectionsService = accessor.get(SheetsSelectionsService);
636
- const univerInstanceService = accessor.get(IUniverInstanceService);
637
- return sheetsSelectionsService.selectionMoveEnd$.pipe(map(() => {
638
- const selection = sheetsSelectionsService.getCurrentLastSelection();
639
- if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
640
- const target = getSheetCommandTarget(univerInstanceService);
641
- if (!target) return false;
642
- const { actualColumn, actualRow } = selection.primary;
643
- const noteModel = accessor.get(SheetsNoteModel);
644
- return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
645
- row: actualRow,
646
- col: actualColumn
647
- }));
648
- }));
649
- }
650
- function sheetNoteContextMenuFactory(accessor) {
651
- return {
652
- id: AddNotePopupOperation.id,
653
- type: MenuItemType.BUTTON,
654
- title: "sheets-note-ui.rightClick.addNote",
655
- icon: "AddNoteIcon",
656
- hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe(map(([hidden, hasNote]) => hidden || hasNote)),
657
- disabled$: getCurrentRangeDisable$(accessor, {
658
- workbookTypes: [WorkbookEditablePermission],
659
- worksheetTypes: [WorksheetEditPermission]
660
- }),
661
- commandId: AddNotePopupOperation.id
662
- };
663
- }
664
- function sheetDeleteNoteMenuFactory(accessor) {
665
- return {
666
- id: SheetDeleteNoteCommand.id,
667
- type: MenuItemType.BUTTON,
668
- title: "sheets-note-ui.rightClick.deleteNote",
669
- icon: "DeleteNoteIcon",
670
- hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote)),
671
- disabled$: getCurrentRangeDisable$(accessor, {
672
- workbookTypes: [WorkbookEditablePermission],
673
- worksheetTypes: [WorksheetEditPermission]
674
- })
675
- };
676
- }
677
- function sheetNoteToggleMenuFactory(accessor) {
678
- return {
679
- id: SheetToggleNotePopupCommand.id,
680
- type: MenuItemType.BUTTON,
681
- title: "sheets-note-ui.rightClick.toggleNote",
682
- icon: "HideNoteIcon",
683
- hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote))
684
- };
685
- }
686
-
687
- //#endregion
688
- //#region src/menu/schema.ts
689
- const menuSchema = { [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.OTHERS]: {
690
- order: 0,
691
- [AddNotePopupOperation.id]: {
692
- order: 0,
693
- menuItemFactory: sheetNoteContextMenuFactory
694
- },
695
- [SheetDeleteNoteCommand.id]: {
696
- order: 0,
697
- menuItemFactory: sheetDeleteNoteMenuFactory
698
- },
699
- [SheetToggleNotePopupCommand.id]: {
700
- order: 0,
701
- menuItemFactory: sheetNoteToggleMenuFactory
702
- }
703
- } } };
704
-
705
717
  //#endregion
706
718
  //#region src/controllers/ui.controller.ts
707
719
  /**
@@ -779,4 +791,4 @@ UniverSheetsNoteUIPlugin = __decorate([
779
791
  ], UniverSheetsNoteUIPlugin);
780
792
 
781
793
  //#endregion
782
- export { SheetsCellContentController, SheetsNotePopupController, SheetsNotePopupService, UniverSheetsNoteUIPlugin };
794
+ export { SheetsCellContentController, SheetsNotePopupController, SheetsNotePopupService, menuSchema as SheetsNoteUIMenuSchema, UniverSheetsNoteUIPlugin };
package/lib/index.js CHANGED
@@ -5,8 +5,8 @@ import { SheetDeleteNoteCommand, SheetToggleNotePopupCommand, SheetUpdateNoteCom
5
5
  import { BehaviorSubject, combineLatest, debounceTime, map, of, switchMap } from "rxjs";
6
6
  import { CellPopupManagerService, HoverManagerService, IEditorBridgeService, SheetSkeletonManagerService, getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
7
7
  import { debounceTime as debounceTime$1 } from "rxjs/operators";
8
- import { AddNoteIcon, DeleteNoteIcon, HideNoteIcon } from "@univerjs/icons";
9
8
  import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IconManager, MenuItemType, getMenuHiddenObservable, useConfigValue, useDebounceFn, useDependency } from "@univerjs/ui";
9
+ import { AddNoteIcon, DeleteNoteIcon, HideNoteIcon } from "@univerjs/icons";
10
10
  import { Textarea, clsx } from "@univerjs/design";
11
11
  import { useCallback, useEffect, useRef, useState } from "react";
12
12
  import { jsx } from "react/jsx-runtime";
@@ -333,10 +333,110 @@ SheetsNotePopupController = __decorate([
333
333
  __decorateParam(5, Inject(HoverManagerService))
334
334
  ], SheetsNotePopupController);
335
335
 
336
+ //#endregion
337
+ //#region src/commands/operations/add-note-popup.operation.ts
338
+ const AddNotePopupOperation = {
339
+ id: "sheet.operation.add-note-popup",
340
+ type: CommandType.OPERATION,
341
+ handler: async (accessor, params) => {
342
+ var _params$trigger;
343
+ const selectionService = accessor.get(SheetsSelectionsService);
344
+ const notePopupService = accessor.get(SheetsNotePopupService);
345
+ const workbook = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
346
+ if (!workbook) return false;
347
+ const worksheet = workbook.getActiveSheet();
348
+ const lastSelection = selectionService.getCurrentLastSelection();
349
+ if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
350
+ const { primary } = lastSelection;
351
+ notePopupService.showPopup({
352
+ unitId: workbook.getUnitId(),
353
+ subUnitId: worksheet.getSheetId(),
354
+ row: primary.actualRow,
355
+ col: primary.actualColumn,
356
+ temp: false,
357
+ trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
358
+ });
359
+ return true;
360
+ }
361
+ };
362
+
363
+ //#endregion
364
+ //#region src/menu/note.menu.ts
365
+ function getHasNote$(accessor) {
366
+ const sheetsSelectionsService = accessor.get(SheetsSelectionsService);
367
+ const univerInstanceService = accessor.get(IUniverInstanceService);
368
+ return sheetsSelectionsService.selectionMoveEnd$.pipe(map(() => {
369
+ const selection = sheetsSelectionsService.getCurrentLastSelection();
370
+ if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
371
+ const target = getSheetCommandTarget(univerInstanceService);
372
+ if (!target) return false;
373
+ const { actualColumn, actualRow } = selection.primary;
374
+ const noteModel = accessor.get(SheetsNoteModel);
375
+ return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
376
+ row: actualRow,
377
+ col: actualColumn
378
+ }));
379
+ }));
380
+ }
381
+ function sheetNoteContextMenuFactory(accessor) {
382
+ return {
383
+ id: AddNotePopupOperation.id,
384
+ type: MenuItemType.BUTTON,
385
+ title: "sheets-note-ui.rightClick.addNote",
386
+ icon: "AddNoteIcon",
387
+ hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe(map(([hidden, hasNote]) => hidden || hasNote)),
388
+ disabled$: getCurrentRangeDisable$(accessor, {
389
+ workbookTypes: [WorkbookEditablePermission],
390
+ worksheetTypes: [WorksheetEditPermission]
391
+ }),
392
+ commandId: AddNotePopupOperation.id
393
+ };
394
+ }
395
+ function sheetDeleteNoteMenuFactory(accessor) {
396
+ return {
397
+ id: SheetDeleteNoteCommand.id,
398
+ type: MenuItemType.BUTTON,
399
+ title: "sheets-note-ui.rightClick.deleteNote",
400
+ icon: "DeleteNoteIcon",
401
+ hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote)),
402
+ disabled$: getCurrentRangeDisable$(accessor, {
403
+ workbookTypes: [WorkbookEditablePermission],
404
+ worksheetTypes: [WorksheetEditPermission]
405
+ })
406
+ };
407
+ }
408
+ function sheetNoteToggleMenuFactory(accessor) {
409
+ return {
410
+ id: SheetToggleNotePopupCommand.id,
411
+ type: MenuItemType.BUTTON,
412
+ title: "sheets-note-ui.rightClick.toggleNote",
413
+ icon: "HideNoteIcon",
414
+ hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote))
415
+ };
416
+ }
417
+
418
+ //#endregion
419
+ //#region src/menu/schema.ts
420
+ const menuSchema = { [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.OTHERS]: {
421
+ order: 0,
422
+ [AddNotePopupOperation.id]: {
423
+ order: 0,
424
+ menuItemFactory: sheetNoteContextMenuFactory
425
+ },
426
+ [SheetDeleteNoteCommand.id]: {
427
+ order: 0,
428
+ menuItemFactory: sheetDeleteNoteMenuFactory
429
+ },
430
+ [SheetToggleNotePopupCommand.id]: {
431
+ order: 0,
432
+ menuItemFactory: sheetNoteToggleMenuFactory
433
+ }
434
+ } } };
435
+
336
436
  //#endregion
337
437
  //#region package.json
338
438
  var name = "@univerjs/sheets-note-ui";
339
- var version = "1.0.0-alpha.1";
439
+ var version = "1.0.0-alpha.3";
340
440
 
341
441
  //#endregion
342
442
  //#region src/config/config.ts
@@ -360,8 +460,17 @@ const SheetsNote = (props) => {
360
460
  return null;
361
461
  }
362
462
  const textareaRef = useRef(null);
463
+ const initialWidthRef = useRef(null);
363
464
  const currentRender = renderManagerService.getRenderById(activePopup.unitId);
364
465
  const [note, setNote] = useState(null);
466
+ const applyResizeOffset = useCallback((width) => {
467
+ const textarea = textareaRef.current;
468
+ if (!textarea) return;
469
+ if (localeService.getDirection() === "rtl" && initialWidthRef.current != null) {
470
+ const offset = initialWidthRef.current - width;
471
+ textarea.style.transform = offset ? `translateX(${offset}px)` : "";
472
+ } else textarea.style.transform = "";
473
+ }, [localeService]);
365
474
  useEffect(() => {
366
475
  var _ref, _note$width, _config$defaultNoteSi, _ref2, _note$height, _config$defaultNoteSi2;
367
476
  const { unitId, subUnitId, row, col } = activePopup;
@@ -382,8 +491,10 @@ const SheetsNote = (props) => {
382
491
  updateNote(initNote);
383
492
  } else setNote(note);
384
493
  if (textareaRef.current) {
494
+ initialWidthRef.current = width;
385
495
  textareaRef.current.style.width = `${width}px`;
386
496
  textareaRef.current.style.height = `${height}px`;
497
+ textareaRef.current.style.transform = "";
387
498
  }
388
499
  }, [activePopup, textareaRef]);
389
500
  useEffect(() => {
@@ -427,6 +538,7 @@ const SheetsNote = (props) => {
427
538
  }, [note]);
428
539
  const handleResize = useCallback((width, height) => {
429
540
  if (!note) return;
541
+ applyResizeOffset(width);
430
542
  if (width === note.width && height === note.height) return;
431
543
  const newNote = {
432
544
  ...note,
@@ -435,7 +547,7 @@ const SheetsNote = (props) => {
435
547
  };
436
548
  setNote(newNote);
437
549
  updateNote(newNote);
438
- }, [note]);
550
+ }, [applyResizeOffset, note]);
439
551
  return /* @__PURE__ */ jsx(Textarea, {
440
552
  ref: textareaRef,
441
553
  "data-u-comp": "note-textarea",
@@ -602,106 +714,6 @@ SheetsNoteAttachmentController = __decorate([
602
714
  __decorateParam(3, Inject(SheetsNotePopupService))
603
715
  ], SheetsNoteAttachmentController);
604
716
 
605
- //#endregion
606
- //#region src/commands/operations/add-note-popup.operation.ts
607
- const AddNotePopupOperation = {
608
- id: "sheet.operation.add-note-popup",
609
- type: CommandType.OPERATION,
610
- handler: async (accessor, params) => {
611
- var _params$trigger;
612
- const selectionService = accessor.get(SheetsSelectionsService);
613
- const notePopupService = accessor.get(SheetsNotePopupService);
614
- const workbook = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
615
- if (!workbook) return false;
616
- const worksheet = workbook.getActiveSheet();
617
- const lastSelection = selectionService.getCurrentLastSelection();
618
- if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
619
- const { primary } = lastSelection;
620
- notePopupService.showPopup({
621
- unitId: workbook.getUnitId(),
622
- subUnitId: worksheet.getSheetId(),
623
- row: primary.actualRow,
624
- col: primary.actualColumn,
625
- temp: false,
626
- trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
627
- });
628
- return true;
629
- }
630
- };
631
-
632
- //#endregion
633
- //#region src/menu/note.menu.ts
634
- function getHasNote$(accessor) {
635
- const sheetsSelectionsService = accessor.get(SheetsSelectionsService);
636
- const univerInstanceService = accessor.get(IUniverInstanceService);
637
- return sheetsSelectionsService.selectionMoveEnd$.pipe(map(() => {
638
- const selection = sheetsSelectionsService.getCurrentLastSelection();
639
- if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
640
- const target = getSheetCommandTarget(univerInstanceService);
641
- if (!target) return false;
642
- const { actualColumn, actualRow } = selection.primary;
643
- const noteModel = accessor.get(SheetsNoteModel);
644
- return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
645
- row: actualRow,
646
- col: actualColumn
647
- }));
648
- }));
649
- }
650
- function sheetNoteContextMenuFactory(accessor) {
651
- return {
652
- id: AddNotePopupOperation.id,
653
- type: MenuItemType.BUTTON,
654
- title: "sheets-note-ui.rightClick.addNote",
655
- icon: "AddNoteIcon",
656
- hidden$: combineLatest([getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe(map(([hidden, hasNote]) => hidden || hasNote)),
657
- disabled$: getCurrentRangeDisable$(accessor, {
658
- workbookTypes: [WorkbookEditablePermission],
659
- worksheetTypes: [WorksheetEditPermission]
660
- }),
661
- commandId: AddNotePopupOperation.id
662
- };
663
- }
664
- function sheetDeleteNoteMenuFactory(accessor) {
665
- return {
666
- id: SheetDeleteNoteCommand.id,
667
- type: MenuItemType.BUTTON,
668
- title: "sheets-note-ui.rightClick.deleteNote",
669
- icon: "DeleteNoteIcon",
670
- hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote)),
671
- disabled$: getCurrentRangeDisable$(accessor, {
672
- workbookTypes: [WorkbookEditablePermission],
673
- worksheetTypes: [WorksheetEditPermission]
674
- })
675
- };
676
- }
677
- function sheetNoteToggleMenuFactory(accessor) {
678
- return {
679
- id: SheetToggleNotePopupCommand.id,
680
- type: MenuItemType.BUTTON,
681
- title: "sheets-note-ui.rightClick.toggleNote",
682
- icon: "HideNoteIcon",
683
- hidden$: getHasNote$(accessor).pipe(map((hasNote) => !hasNote))
684
- };
685
- }
686
-
687
- //#endregion
688
- //#region src/menu/schema.ts
689
- const menuSchema = { [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.OTHERS]: {
690
- order: 0,
691
- [AddNotePopupOperation.id]: {
692
- order: 0,
693
- menuItemFactory: sheetNoteContextMenuFactory
694
- },
695
- [SheetDeleteNoteCommand.id]: {
696
- order: 0,
697
- menuItemFactory: sheetDeleteNoteMenuFactory
698
- },
699
- [SheetToggleNotePopupCommand.id]: {
700
- order: 0,
701
- menuItemFactory: sheetNoteToggleMenuFactory
702
- }
703
- } } };
704
-
705
717
  //#endregion
706
718
  //#region src/controllers/ui.controller.ts
707
719
  /**
@@ -779,4 +791,4 @@ UniverSheetsNoteUIPlugin = __decorate([
779
791
  ], UniverSheetsNoteUIPlugin);
780
792
 
781
793
  //#endregion
782
- export { SheetsCellContentController, SheetsNotePopupController, SheetsNotePopupService, UniverSheetsNoteUIPlugin };
794
+ export { SheetsCellContentController, SheetsNotePopupController, SheetsNotePopupService, menuSchema as SheetsNoteUIMenuSchema, UniverSheetsNoteUIPlugin };
@@ -17,5 +17,6 @@ import './global.css';
17
17
  export type { IUniverSheetsNoteUIConfig } from './config/config';
18
18
  export { SheetsCellContentController } from './controllers/sheets-cell-content.controller';
19
19
  export { SheetsNotePopupController } from './controllers/sheets-note-popup.controller';
20
+ export { menuSchema as SheetsNoteUIMenuSchema } from './menu/schema';
20
21
  export { UniverSheetsNoteUIPlugin } from './plugin';
21
22
  export { SheetsNotePopupService } from './services/sheets-note-popup.service';
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-note"),require("rxjs"),require("@univerjs/sheets-ui"),require("rxjs/operators"),require("react"),require("@univerjs/ui"),require("@univerjs/design"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-note`,`rxjs`,`@univerjs/sheets-ui`,`rxjs/operators`,`react`,`@univerjs/ui`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNoteUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsNote,e.rxjs,e.UniverSheetsUi,e.rxjs.operators,e.React,e.UniverUi,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function f(e,t){return function(n,r){t(n,r,e)}}function p(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let m=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0,a.debounceTime)(16)).subscribe(()=>{e()}))}};m=p([f(0,(0,t.Inject)(r.SheetInterceptorService)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,n.IRenderManagerService),f(3,t.IUniverInstanceService)],m);let h=`SHEET_NOTE_COMPONENT`;function g(e){"@babel/helpers - typeof";return g=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let b=class extends t.Disposable{get activePopup(){return this._activePopup}constructor(e){super(),this._cellPopupManagerService=e,y(this,`_lastPopup`,null),y(this,`_activePopup`,void 0),y(this,`_activePopup$`,new a.BehaviorSubject(null)),y(this,`activePopup$`,this._activePopup$.asObservable()),this.disposeWithMe(()=>{this._activePopup$.complete()})}dispose(){super.dispose(),this.hidePopup()}showPopup(e,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}this._lastPopup&&this._lastPopup.dispose(),this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:h,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new t.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};b=p([f(0,(0,t.Inject)(o.CellPopupManagerService))],b);let x=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,y(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,n,r){var i,a,s;let c=(i=e[0])==null?void 0:i.range,l=this._renderManagerService.getRenderById(n),u=l==null||(a=l.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:a.skeleton;if(!u||!c)return;let d=u.getCellWithCoordByIndex(c.startRow,c.startColumn);if((((s=c.rangeType)==null?t.RANGE_TYPE.NORMAL:s)!==t.RANGE_TYPE.NORMAL||c.endColumn-c.startColumn>0||c.endRow-c.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&t.Rectangle.equals(d.mergeInfo,c))){this._sheetsNotePopupService.hidePopup();return}let f=d.actualRow,p=d.actualColumn,m=this._sheetsNoteModel.getNote(n,r,{row:f,col:p});m!=null&&m.show||(m?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:m.id,row:f,col:p}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,s=this._renderManagerService.getRenderById(n),c=s==null||(t=s.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:t.skeleton,l=i,u=a,d=this._sheetsNoteModel.getNote(n,r,{row:l,col:u});if(!d&&c){let{startRow:e,endRow:t,startColumn:o,endColumn:s}=c.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==s){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=s){d=r,l=r.row,u=r.col;break}}}}d!=null&&d.show||(d?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:d.id,row:l,col:u,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};x=p([f(0,(0,t.Inject)(b)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,(0,t.Inject)(r.SheetsSelectionsService)),f(3,o.IEditorBridgeService),f(4,n.IRenderManagerService),f(5,(0,t.Inject)(o.HoverManagerService))],x);var S=`@univerjs/sheets-note-ui`,C=`1.0.0-alpha.1`;let w=`sheets-note-ui.config`,T={};function E({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,c.useRef)(`_${A()}`);return D(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:s,...o},a)}function D(e,t,n,r,i){return(0,c.createElement)(e.tag,{key:t,...O(e,n,i),...r},(k(e,n).children||[]).map((r,a)=>D(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function O(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function k(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function A(){return Math.random().toString(36).substring(2,8)}E.displayName=`UniverIcon`;let j={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.8813 14.4312V10.2925C10.8813 9.92522 11.1791 9.62745 11.5463 9.62745C11.9136 9.62745 12.2114 9.92522 12.2114 10.2925V14.4312C12.2112 14.7983 11.9135 15.0962 11.5463 15.0962C11.1791 15.0962 10.8814 14.7983 10.8813 14.4312Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47697 11.6968H11.5463H13.6156C13.9829 11.6968 14.2807 11.9946 14.2807 12.3618C14.2807 12.7291 13.9829 13.0269 13.6156 13.0269H9.47697C9.10981 13.0267 8.81193 12.729 8.81193 12.3618C8.81193 11.9946 9.10981 11.6969 9.47697 11.6968Z`}}]},M=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(E,Object.assign({},e,{id:`add-note-icon`,ref:t,icon:j}))});M.displayName=`AddNoteIcon`;let N={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47489 11.6968H13.6175C13.9847 11.6968 14.2825 11.9946 14.2825 12.3618C14.2825 12.7291 13.9847 13.0269 13.6175 13.0269H9.47489C9.10762 13.0269 8.80985 12.7291 8.80985 12.3618C8.80985 11.9946 9.10762 11.6968 9.47489 11.6968Z`}}]},P=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(E,Object.assign({},e,{id:`delete-note-icon`,ref:t,icon:N}))});P.displayName=`DeleteNoteIcon`;let F={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13.8743 12.6147C13.8742 12.5394 13.7749 12.2553 13.3909 11.9477C13.039 11.6659 12.5573 11.4614 12.0394 11.4614C11.5213 11.4614 11.0398 11.6666 10.6878 11.9487C10.3037 12.2565 10.2045 12.5399 10.2044 12.6147C10.2044 12.6893 10.3034 12.9737 10.6878 13.2817C11.0398 13.5636 11.5215 13.768 12.0394 13.768C12.5574 13.768 13.039 13.5635 13.3909 13.2817C13.7751 12.9739 13.8743 12.6897 13.8743 12.6147ZM15.2044 12.6147C15.2044 13.2772 14.7436 13.9027 14.223 14.3198C13.6701 14.7627 12.9019 15.0981 12.0394 15.0981C11.1768 15.0981 10.4085 14.7627 9.85577 14.3198C9.33533 13.9027 8.87433 13.2769 8.87433 12.6147C8.8744 11.9526 9.33541 11.3276 9.85577 10.9106C10.4086 10.4676 11.1767 10.1313 12.0394 10.1313C12.9018 10.1313 13.6701 10.4668 14.223 10.9096C14.7435 11.3267 15.2043 11.9523 15.2044 12.6147Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.0394 13.299C12.4172 13.299 12.7234 12.9927 12.7234 12.6149C12.7234 12.2371 12.4172 11.9308 12.0394 11.9308C11.6616 11.9308 11.3553 12.2371 11.3553 12.6149C11.3553 12.9927 11.6616 13.299 12.0394 13.299Z`}}]},I=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(E,Object.assign({},e,{id:`hide-note-icon`,ref:t,icon:F}))});I.displayName=`HideNoteIcon`;let L=e=>{var r;let{popup:a}=e,o=(0,l.useDependency)(i.SheetsNoteModel),s=(0,l.useDependency)(t.LocaleService),f=(0,l.useDependency)(n.IRenderManagerService),p=(0,l.useDependency)(b),m=(0,l.useConfigValue)(w),h=(r=a.extraProps)==null?void 0:r.location;if(!h)return console.error(`Popup extraProps or location is undefined.`),null;let g=(0,c.useRef)(null),_=f.getRenderById(h.unitId),[v,y]=(0,c.useState)(null);(0,c.useEffect)(()=>{var e,n,r,i,a,s;let{unitId:c,subUnitId:l,row:u,col:d}=h,f=o.getNote(c,l,{row:u,col:d}),p=(e=(n=f==null?void 0:f.width)==null?m==null||(r=m.defaultNoteSize)==null?void 0:r.width:n)==null?160:e,_=(i=(a=f==null?void 0:f.height)==null?m==null||(s=m.defaultNoteSize)==null?void 0:s.height:a)==null?72:i;if(f)y(f);else{let e={id:(0,t.generateRandomId)(6),width:p,height:_,note:``};y(e),S(e)}g.current&&(g.current.style.width=`${p}px`,g.current.style.height=`${_}px`)},[h,g]),(0,c.useEffect)(()=>{if(!h||h.temp||!h.trigger||!g.current)return;let e=requestAnimationFrame(()=>{var e;(e=g.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[h]);let x=(0,l.useDependency)(t.ICommandService),S=(0,l.useDebounceFn)(e=>{if(!h)return;let{unitId:t,subUnitId:n,row:r,col:a}=h;if(!x.syncExecuteCommand(i.SheetUpdateNoteCommand.id,{unitId:t,sheetId:n,row:r,col:a,note:e})){let i=o.getNote(t,n,{noteId:e.id,row:r,col:a});i?y(i):p.hidePopup(!0)}}),C=(0,c.useCallback)(e=>{if(!v||e===v.note)return;let t={...v,note:e};y(t),S(t)},[v]),T=(0,c.useCallback)((e,t)=>{if(!v||e===v.width&&t===v.height)return;let n={...v,width:e,height:t};y(n),S(n)},[v]);return(0,d.jsx)(u.Textarea,{ref:g,"data-u-comp":`note-textarea`,className:(0,u.clsx)(`univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow dark:!univer-bg-gray-800`),value:v==null?void 0:v.note,placeholder:s.t(`sheets-note-ui.note.placeholder`),onResize:T,onValueChange:C,onWheel:e=>{document.activeElement!==g.current&&_.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})},R=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[h,L]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({AddNoteIcon:M,DeleteNoteIcon:P,HideNoteIcon:I}))}};R=p([f(0,(0,t.Inject)(l.ComponentManager)),f(1,(0,t.Inject)(l.IconManager))],R);let z=class extends t.Disposable{constructor(e,n,r,i){super(),this._sheetsNoteModel=e,this._univerInstanceService=n,this._cellPopupManagerService=r,this._sheetsNotePopupService=i,y(this,`_noteMatrix`,new t.ObjectMatrix),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:h,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,n){var r;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix;let i=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(r=this._sheetsNoteModel.getSheetNotes(e,n))==null||r.forEach(t=>{i(e,n,t.row,t.col,t)}),this._sheetsNoteModel.change$.subscribe(t=>{if(!(t.unitId!==e||t.subUnitId!==n))switch(t.type){case`ref`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:i}=t;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,n,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:a}=t;i(e,n,a?a.row:r.row,a?a.col:r.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,a.of)(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix}))}};z=p([f(0,(0,t.Inject)(i.SheetsNoteModel)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(o.CellPopupManagerService)),f(3,(0,t.Inject)(b))],z);let B={id:`sheet.operation.add-note-popup`,type:t.CommandType.OPERATION,handler:async(e,n)=>{var i;let a=e.get(r.SheetsSelectionsService),o=e.get(b),s=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;let c=s.getActiveSheet(),l=a.getCurrentLastSelection();if(!(l!=null&&l.primary))return!1;let{primary:u}=l;return o.showPopup({unitId:s.getUnitId(),subUnitId:c.getSheetId(),row:u.actualRow,col:u.actualColumn,temp:!1,trigger:(i=n==null?void 0:n.trigger)==null?`add-note`:i}),!0}};function V(e){let n=e.get(r.SheetsSelectionsService),o=e.get(t.IUniverInstanceService);return n.selectionMoveEnd$.pipe((0,a.map)(()=>{let t=n.getCurrentLastSelection();if(!(t!=null&&t.primary))return!1;let a=(0,r.getSheetCommandTarget)(o);if(!a)return!1;let{actualColumn:s,actualRow:c}=t.primary;return!!e.get(i.SheetsNoteModel).getNote(a.unitId,a.subUnitId,{row:c,col:s})}))}function H(e){return{id:B.id,type:l.MenuItemType.BUTTON,title:`sheets-note-ui.rightClick.addNote`,icon:`AddNoteIcon`,hidden$:(0,a.combineLatest)([(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),V(e)]).pipe((0,a.map)(([e,t])=>e||t)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]}),commandId:B.id}}function U(e){return{id:i.SheetDeleteNoteCommand.id,type:l.MenuItemType.BUTTON,title:`sheets-note-ui.rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:V(e).pipe((0,a.map)(e=>!e)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]})}}function W(e){return{id:i.SheetToggleNotePopupCommand.id,type:l.MenuItemType.BUTTON,title:`sheets-note-ui.rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:V(e).pipe((0,a.map)(e=>!e))}}let G={[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{order:0,[B.id]:{order:0,menuItemFactory:H},[i.SheetDeleteNoteCommand.id]:{order:0,menuItemFactory:U},[i.SheetToggleNotePopupCommand.id]:{order:0,menuItemFactory:W}}}},K=class extends t.Disposable{constructor(e,t){super(),this._menuManagerService=e,this._commandService=t,this._initMenu(),this._initCommands()}_initMenu(){this._menuManagerService.mergeMenu(G)}_initCommands(){this._commandService.registerCommand(B)}};K=p([f(0,(0,t.Inject)(l.IMenuManagerService)),f(1,t.ICommandService)],K);let q=class extends t.Plugin{constructor(e=T,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},T,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(w,a)}onStarting(){this._injector.add([R]),this._injector.get(R),[[b],[m],[x],[K],[z]].forEach(e=>{this._injector.add(e)})}onReady(){(0,t.touchDependencies)(this._injector,[[K],[m]])}onRendered(){(0,t.touchDependencies)(this._injector,[[x],[z]])}};y(q,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),y(q,`packageName`,S),y(q,`version`,C),y(q,`type`,t.UniverInstanceType.UNIVER_SHEET),q=p([(0,t.DependentOn)(i.UniverSheetsNotePlugin),f(1,(0,t.Inject)(t.Injector)),f(2,t.IConfigService)],q),Object.defineProperty(e,"SheetsCellContentController",{enumerable:!0,get:function(){return m}}),Object.defineProperty(e,"SheetsNotePopupController",{enumerable:!0,get:function(){return x}}),Object.defineProperty(e,"SheetsNotePopupService",{enumerable:!0,get:function(){return b}}),Object.defineProperty(e,"UniverSheetsNoteUIPlugin",{enumerable:!0,get:function(){return q}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("@univerjs/sheets-note"),require("rxjs"),require("@univerjs/sheets-ui"),require("rxjs/operators"),require("@univerjs/ui"),require("react"),require("@univerjs/design"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets`,`@univerjs/sheets-note`,`rxjs`,`@univerjs/sheets-ui`,`rxjs/operators`,`@univerjs/ui`,`react`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNoteUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheets,e.UniverSheetsNote,e.rxjs,e.UniverSheetsUi,e.rxjs.operators,e.UniverUi,e.React,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function f(e,t){return function(n,r){t(n,r,e)}}function p(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let m=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._sheetsNoteModel=t,this._renderManagerService=n,this._univerInstanceService=r,this._initViewModelIntercept(),this._initSkeletonChange()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(r.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t;return this._sheetsNoteModel.getNote(a,o,{row:r,col:i})?((!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,tr:{color:`#FFBD37`,size:6}},n(e)):n(e)},priority:100}))}_initSkeletonChange(){let e=()=>{var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!n)return;let r=n.getUnitId(),i=this._renderManagerService.getRenderById(r);i==null||(e=i.mainComponent)==null||e.makeForceDirty()};this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0,a.debounceTime)(16)).subscribe(()=>{e()}))}};m=p([f(0,(0,t.Inject)(r.SheetInterceptorService)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,n.IRenderManagerService),f(3,t.IUniverInstanceService)],m);let h=`SHEET_NOTE_COMPONENT`;function g(e){"@babel/helpers - typeof";return g=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},g(e)}function _(e,t){if(g(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(g(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function v(e){var t=_(e,`string`);return g(t)==`symbol`?t:t+``}function y(e,t,n){return(t=v(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let b=class extends t.Disposable{get activePopup(){return this._activePopup}constructor(e){super(),this._cellPopupManagerService=e,y(this,`_lastPopup`,null),y(this,`_activePopup`,void 0),y(this,`_activePopup$`,new a.BehaviorSubject(null)),y(this,`activePopup$`,this._activePopup$.asObservable()),this.disposeWithMe(()=>{this._activePopup$.complete()})}dispose(){super.dispose(),this.hidePopup()}showPopup(e,n){var r;let{row:i,col:a,unitId:o,subUnitId:s}=e;if(this._activePopup&&i===this._activePopup.row&&a===this._activePopup.col&&o===this._activePopup.unitId&&s===((r=this.activePopup)==null?void 0:r.subUnitId)){this._activePopup=e,this._activePopup$.next(e);return}this._lastPopup&&this._lastPopup.dispose(),this._activePopup=e,this._activePopup$.next(e);let c=this._cellPopupManagerService.showPopup({unitId:o,subUnitId:s,row:i,col:a},{componentKey:h,onClickOutside:()=>{this.hidePopup()},direction:`horizontal`,extraProps:{location:e},priority:3});if(!c)throw Error(`[SheetsNotePopupService]: cannot show popup!`);let l=new t.DisposableCollection;l.add(c),l.add({dispose:()=>{n==null||n()}}),this._lastPopup=l}hidePopup(e){this._activePopup&&(!e&&!this._activePopup.temp||(this._lastPopup&&this._lastPopup.dispose(),this._lastPopup=null,this._activePopup=null,this._activePopup$.next(null)))}persistPopup(){!this._activePopup||!this._activePopup.temp||(this._activePopup={...this._activePopup,temp:!1},this._activePopup$.next(this._activePopup))}};b=p([f(0,(0,t.Inject)(o.CellPopupManagerService))],b);let x=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetsNotePopupService=e,this._sheetsNoteModel=t,this._sheetSelectionService=n,this._editorBridgeService=r,this._renderManagerService=i,this._hoverManagerService=a,y(this,`_isSwitchingSheet`,!1),this._initSelectionUpdateListener(),this._initEditorBridge(),this._initHoverEvent(),this._initDeleteNoteListener()}_handleSelectionChange(e,n,r){var i,a,s;let c=(i=e[0])==null?void 0:i.range,l=this._renderManagerService.getRenderById(n),u=l==null||(a=l.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:a.skeleton;if(!u||!c)return;let d=u.getCellWithCoordByIndex(c.startRow,c.startColumn);if((((s=c.rangeType)==null?t.RANGE_TYPE.NORMAL:s)!==t.RANGE_TYPE.NORMAL||c.endColumn-c.startColumn>0||c.endRow-c.startRow>0)&&!((d.isMerged||d.isMergedMainCell)&&t.Rectangle.equals(d.mergeInfo,c))){this._sheetsNotePopupService.hidePopup();return}let f=d.actualRow,p=d.actualColumn,m=this._sheetsNoteModel.getNote(n,r,{row:f,col:p});m!=null&&m.show||(m?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:m.id,row:f,col:p}):this._sheetsNotePopupService.hidePopup(!0))}_initSelectionUpdateListener(){this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe(e=>{if(this._isSwitchingSheet)return;let t=this._sheetSelectionService.currentSelectionParam;t&&this._handleSelectionChange(e,t.unitId,t.sheetId)}))}_initEditorBridge(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible&&this._sheetsNotePopupService.hidePopup(!0)}))}_initHoverEvent(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{var t;if(!(e!=null&&e.location))return;let{unitId:n,subUnitId:r,row:i,col:a}=e.location,s=this._renderManagerService.getRenderById(n),c=s==null||(t=s.with(o.SheetSkeletonManagerService).getSkeletonParam(r))==null?void 0:t.skeleton,l=i,u=a,d=this._sheetsNoteModel.getNote(n,r,{row:l,col:u});if(!d&&c){let{startRow:e,endRow:t,startColumn:o,endColumn:s}=c.getCellWithCoordByIndex(i,a).mergeInfo;if(e!==t||o!==s){let i=this._sheetsNoteModel.getSheetNotes(n,r);if(i){for(let[n,r]of i)if(r.row>=e&&r.row<=t&&r.col>=o&&r.col<=s){d=r,l=r.row,u=r.col;break}}}}d!=null&&d.show||(d?this._sheetsNotePopupService.showPopup({unitId:n,subUnitId:r,noteId:d.id,row:l,col:u,temp:!0}):this._sheetsNotePopupService.hidePopup())}))}_initDeleteNoteListener(){this.disposeWithMe(this._sheetsNoteModel.change$.subscribe(e=>{if(!this._sheetsNotePopupService.activePopup)return;let{unitId:t,subUnitId:n,noteId:r,row:i,col:a}=this._sheetsNotePopupService.activePopup,{oldNote:o,newNote:s}=e;s===null&&e.unitId===t&&e.subUnitId===n&&(o!=null&&o.id&&o.id===r||(o==null?void 0:o.row)===i&&o.col===a)&&this._sheetsNotePopupService.hidePopup(!0)}))}};x=p([f(0,(0,t.Inject)(b)),f(1,(0,t.Inject)(i.SheetsNoteModel)),f(2,(0,t.Inject)(r.SheetsSelectionsService)),f(3,o.IEditorBridgeService),f(4,n.IRenderManagerService),f(5,(0,t.Inject)(o.HoverManagerService))],x);let S={id:`sheet.operation.add-note-popup`,type:t.CommandType.OPERATION,handler:async(e,n)=>{var i;let a=e.get(r.SheetsSelectionsService),o=e.get(b),s=e.get(t.IUniverInstanceService).getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;let c=s.getActiveSheet(),l=a.getCurrentLastSelection();if(!(l!=null&&l.primary))return!1;let{primary:u}=l;return o.showPopup({unitId:s.getUnitId(),subUnitId:c.getSheetId(),row:u.actualRow,col:u.actualColumn,temp:!1,trigger:(i=n==null?void 0:n.trigger)==null?`add-note`:i}),!0}};function C(e){let n=e.get(r.SheetsSelectionsService),o=e.get(t.IUniverInstanceService);return n.selectionMoveEnd$.pipe((0,a.map)(()=>{let t=n.getCurrentLastSelection();if(!(t!=null&&t.primary))return!1;let a=(0,r.getSheetCommandTarget)(o);if(!a)return!1;let{actualColumn:s,actualRow:c}=t.primary;return!!e.get(i.SheetsNoteModel).getNote(a.unitId,a.subUnitId,{row:c,col:s})}))}function w(e){return{id:S.id,type:c.MenuItemType.BUTTON,title:`sheets-note-ui.rightClick.addNote`,icon:`AddNoteIcon`,hidden$:(0,a.combineLatest)([(0,c.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),C(e)]).pipe((0,a.map)(([e,t])=>e||t)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]}),commandId:S.id}}function T(e){return{id:i.SheetDeleteNoteCommand.id,type:c.MenuItemType.BUTTON,title:`sheets-note-ui.rightClick.deleteNote`,icon:`DeleteNoteIcon`,hidden$:C(e).pipe((0,a.map)(e=>!e)),disabled$:(0,o.getCurrentRangeDisable$)(e,{workbookTypes:[r.WorkbookEditablePermission],worksheetTypes:[r.WorksheetEditPermission]})}}function E(e){return{id:i.SheetToggleNotePopupCommand.id,type:c.MenuItemType.BUTTON,title:`sheets-note-ui.rightClick.toggleNote`,icon:`HideNoteIcon`,hidden$:C(e).pipe((0,a.map)(e=>!e))}}let D={[c.ContextMenuPosition.MAIN_AREA]:{[c.ContextMenuGroup.OTHERS]:{order:0,[S.id]:{order:0,menuItemFactory:w},[i.SheetDeleteNoteCommand.id]:{order:0,menuItemFactory:T},[i.SheetToggleNotePopupCommand.id]:{order:0,menuItemFactory:E}}}};var O=`@univerjs/sheets-note-ui`,k=`1.0.0-alpha.3`;let A=`sheets-note-ui.config`,j={};function M({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,l.useRef)(`_${I()}`);return N(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function N(e,t,n,r,i){return(0,l.createElement)(e.tag,{key:t,...P(e,n,i),...r},(F(e,n).children||[]).map((r,a)=>N(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function P(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function F(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function I(){return Math.random().toString(36).substring(2,8)}M.displayName=`UniverIcon`;let L={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.8813 14.4312V10.2925C10.8813 9.92522 11.1791 9.62745 11.5463 9.62745C11.9136 9.62745 12.2114 9.92522 12.2114 10.2925V14.4312C12.2112 14.7983 11.9135 15.0962 11.5463 15.0962C11.1791 15.0962 10.8814 14.7983 10.8813 14.4312Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47697 11.6968H11.5463H13.6156C13.9829 11.6968 14.2807 11.9946 14.2807 12.3618C14.2807 12.7291 13.9829 13.0269 13.6156 13.0269H9.47697C9.10981 13.0267 8.81193 12.729 8.81193 12.3618C8.81193 11.9946 9.10981 11.6969 9.47697 11.6968Z`}}]},R=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(M,Object.assign({},e,{id:`add-note-icon`,ref:t,icon:L}))});R.displayName=`AddNoteIcon`;let z={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.47489 11.6968H13.6175C13.9847 11.6968 14.2825 11.9946 14.2825 12.3618C14.2825 12.7291 13.9847 13.0269 13.6175 13.0269H9.47489C9.10762 13.0269 8.80985 12.7291 8.80985 12.3618C8.80985 11.9946 9.10762 11.6968 9.47489 11.6968Z`}}]},B=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(M,Object.assign({},e,{id:`delete-note-icon`,ref:t,icon:z}))});B.displayName=`DeleteNoteIcon`;let V={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M12.8481 8.00049V3.87451C12.8481 3.13737 12.2503 2.5398 11.5132 2.53955H4.48682C3.74952 2.53955 3.15186 3.13721 3.15186 3.87451V12.1255C3.15186 12.8628 3.74952 13.4604 4.48682 13.4604H6.99951L7.1333 13.4741C7.43655 13.536 7.66454 13.804 7.66455 14.1255C7.66455 14.447 7.43655 14.715 7.1333 14.7769L6.99951 14.7905H4.48682C3.01498 14.7905 1.82178 13.5973 1.82178 12.1255V3.87451C1.82178 2.40267 3.01498 1.20947 4.48682 1.20947H11.5132C12.9848 1.20972 14.1772 2.40283 14.1772 3.87451V8.00049C14.177 8.36738 13.8801 8.6643 13.5132 8.66455C13.1461 8.66455 12.8484 8.36754 12.8481 8.00049Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M10.1463 4.53859L10.2801 4.55226C10.5832 4.61419 10.8113 4.8822 10.8113 5.20363C10.8113 5.52506 10.5832 5.79306 10.2801 5.85499L10.1463 5.86867H5.85331C5.48604 5.86867 5.18827 5.5709 5.18827 5.20363C5.18827 4.83636 5.48604 4.53859 5.85331 4.53859H10.1463Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.11307 7.33497L8.24686 7.34865C8.54984 7.41069 8.77811 7.67869 8.77811 8.00001C8.77811 8.32134 8.54984 8.58933 8.24686 8.65138L8.11307 8.66505H5.85331C5.48604 8.66505 5.18827 8.36728 5.18827 8.00001C5.18827 7.63274 5.48604 7.33497 5.85331 7.33497H8.11307Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.98319 10.1314L7.11698 10.145C7.42003 10.207 7.64823 10.475 7.64823 10.7964C7.64823 11.1178 7.42003 11.3858 7.11698 11.4478L6.98319 11.4614H5.85331C5.48604 11.4614 5.18827 11.1637 5.18827 10.7964C5.18827 10.4291 5.48604 10.1314 5.85331 10.1314H6.98319Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M13.8743 12.6147C13.8742 12.5394 13.7749 12.2553 13.3909 11.9477C13.039 11.6659 12.5573 11.4614 12.0394 11.4614C11.5213 11.4614 11.0398 11.6666 10.6878 11.9487C10.3037 12.2565 10.2045 12.5399 10.2044 12.6147C10.2044 12.6893 10.3034 12.9737 10.6878 13.2817C11.0398 13.5636 11.5215 13.768 12.0394 13.768C12.5574 13.768 13.039 13.5635 13.3909 13.2817C13.7751 12.9739 13.8743 12.6897 13.8743 12.6147ZM15.2044 12.6147C15.2044 13.2772 14.7436 13.9027 14.223 14.3198C13.6701 14.7627 12.9019 15.0981 12.0394 15.0981C11.1768 15.0981 10.4085 14.7627 9.85577 14.3198C9.33533 13.9027 8.87433 13.2769 8.87433 12.6147C8.8744 11.9526 9.33541 11.3276 9.85577 10.9106C10.4086 10.4676 11.1767 10.1313 12.0394 10.1313C12.9018 10.1313 13.6701 10.4668 14.223 10.9096C14.7435 11.3267 15.2043 11.9523 15.2044 12.6147Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M12.0394 13.299C12.4172 13.299 12.7234 12.9927 12.7234 12.6149C12.7234 12.2371 12.4172 11.9308 12.0394 11.9308C11.6616 11.9308 11.3553 12.2371 11.3553 12.6149C11.3553 12.9927 11.6616 13.299 12.0394 13.299Z`}}]},H=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(M,Object.assign({},e,{id:`hide-note-icon`,ref:t,icon:V}))});H.displayName=`HideNoteIcon`;let U=e=>{var r;let{popup:a}=e,o=(0,c.useDependency)(i.SheetsNoteModel),s=(0,c.useDependency)(t.LocaleService),f=(0,c.useDependency)(n.IRenderManagerService),p=(0,c.useDependency)(b),m=(0,c.useConfigValue)(A),h=(r=a.extraProps)==null?void 0:r.location;if(!h)return console.error(`Popup extraProps or location is undefined.`),null;let g=(0,l.useRef)(null),_=(0,l.useRef)(null),v=f.getRenderById(h.unitId),[y,x]=(0,l.useState)(null),S=(0,l.useCallback)(e=>{let t=g.current;if(t)if(s.getDirection()===`rtl`&&_.current!=null){let n=_.current-e;t.style.transform=n?`translateX(${n}px)`:``}else t.style.transform=``},[s]);(0,l.useEffect)(()=>{var e,n,r,i,a,s;let{unitId:c,subUnitId:l,row:u,col:d}=h,f=o.getNote(c,l,{row:u,col:d}),p=(e=(n=f==null?void 0:f.width)==null?m==null||(r=m.defaultNoteSize)==null?void 0:r.width:n)==null?160:e,v=(i=(a=f==null?void 0:f.height)==null?m==null||(s=m.defaultNoteSize)==null?void 0:s.height:a)==null?72:i;if(f)x(f);else{let e={id:(0,t.generateRandomId)(6),width:p,height:v,note:``};x(e),w(e)}g.current&&(_.current=p,g.current.style.width=`${p}px`,g.current.style.height=`${v}px`,g.current.style.transform=``)},[h,g]),(0,l.useEffect)(()=>{if(!h||h.temp||!h.trigger||!g.current)return;let e=requestAnimationFrame(()=>{var e;(e=g.current)==null||e.focus()});return()=>cancelAnimationFrame(e)},[h]);let C=(0,c.useDependency)(t.ICommandService),w=(0,c.useDebounceFn)(e=>{if(!h)return;let{unitId:t,subUnitId:n,row:r,col:a}=h;if(!C.syncExecuteCommand(i.SheetUpdateNoteCommand.id,{unitId:t,sheetId:n,row:r,col:a,note:e})){let i=o.getNote(t,n,{noteId:e.id,row:r,col:a});i?x(i):p.hidePopup(!0)}}),T=(0,l.useCallback)(e=>{if(!y||e===y.note)return;let t={...y,note:e};x(t),w(t)},[y]),E=(0,l.useCallback)((e,t)=>{if(!y||(S(e),e===y.width&&t===y.height))return;let n={...y,width:e,height:t};x(n),w(n)},[S,y]);return(0,d.jsx)(u.Textarea,{ref:g,"data-u-comp":`note-textarea`,className:(0,u.clsx)(`univer-ml-px univer-min-h-1 univer-min-w-1 univer-bg-white !univer-text-sm univer-shadow dark:!univer-bg-gray-800`),value:y==null?void 0:y.note,placeholder:s.t(`sheets-note-ui.note.placeholder`),onResize:E,onValueChange:T,onWheel:e=>{document.activeElement!==g.current&&v.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type,e.nativeEvent))}})},W=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[h,U]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({AddNoteIcon:R,DeleteNoteIcon:B,HideNoteIcon:H}))}};W=p([f(0,(0,t.Inject)(c.ComponentManager)),f(1,(0,t.Inject)(c.IconManager))],W);let G=class extends t.Disposable{constructor(e,n,r,i){super(),this._sheetsNoteModel=e,this._univerInstanceService=n,this._cellPopupManagerService=r,this._sheetsNotePopupService=i,y(this,`_noteMatrix`,new t.ObjectMatrix),this._initNoteChangeListener()}_showPopup(e,t,n,r){return this._sheetsNotePopupService.hidePopup(!0),this._cellPopupManagerService.showPopup({unitId:e,subUnitId:t,row:n,col:r},{componentKey:h,direction:`horizontal`,extraProps:{location:{unitId:e,subUnitId:t,row:n,col:r}},priority:3})}dispose(){super.dispose(),this._noteMatrix.forValue((e,t,n)=>{n.dispose()})}_initSheet(e,n){var r;this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix;let i=(e,t,n,r,i)=>{let a=this._noteMatrix,o=a.getValue(n,r);if(i!=null&&i.show){if(!o){let i=this._showPopup(e,t,n,r);i&&a.setValue(n,r,i)}}else o&&(o.dispose(),a.realDeleteValue(n,r))};return(r=this._sheetsNoteModel.getSheetNotes(e,n))==null||r.forEach(t=>{i(e,n,t.row,t.col,t)}),this._sheetsNoteModel.change$.subscribe(t=>{if(!(t.unitId!==e||t.subUnitId!==n))switch(t.type){case`ref`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:i}=t;if(!i.show)return;let a=this._noteMatrix,{row:o,col:s}=r,{row:c,col:l}=i,u=a.getValue(o,s);u&&(u.dispose(),a.realDeleteValue(o,s));let d=this._showPopup(e,n,c,l);d&&a.setValue(c,l,d);break}case`update`:{let{unitId:e,subUnitId:n,oldNote:r,newNote:a}=t;i(e,n,a?a.row:r.row,a?a.col:r.col,a);break}default:break}})}_initNoteChangeListener(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>{var t;return(t=e==null?void 0:e.activeSheet$)==null?(0,a.of)(null):t})).subscribe(e=>{if(e){let t=this._initSheet(e.getUnitId(),e.getSheetId());return()=>{t.unsubscribe()}}else this._noteMatrix.forValue((e,t,n)=>{n.dispose()}),this._noteMatrix=new t.ObjectMatrix}))}};G=p([f(0,(0,t.Inject)(i.SheetsNoteModel)),f(1,(0,t.Inject)(t.IUniverInstanceService)),f(2,(0,t.Inject)(o.CellPopupManagerService)),f(3,(0,t.Inject)(b))],G);let K=class extends t.Disposable{constructor(e,t){super(),this._menuManagerService=e,this._commandService=t,this._initMenu(),this._initCommands()}_initMenu(){this._menuManagerService.mergeMenu(D)}_initCommands(){this._commandService.registerCommand(S)}};K=p([f(0,(0,t.Inject)(c.IMenuManagerService)),f(1,t.ICommandService)],K);let q=class extends t.Plugin{constructor(e=j,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},j,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(A,a)}onStarting(){this._injector.add([W]),this._injector.get(W),[[b],[m],[x],[K],[G]].forEach(e=>{this._injector.add(e)})}onReady(){(0,t.touchDependencies)(this._injector,[[K],[m]])}onRendered(){(0,t.touchDependencies)(this._injector,[[x],[G]])}};y(q,`pluginName`,`SHEET_NOTE_UI_PLUGIN`),y(q,`packageName`,O),y(q,`version`,k),y(q,`type`,t.UniverInstanceType.UNIVER_SHEET),q=p([(0,t.DependentOn)(i.UniverSheetsNotePlugin),f(1,(0,t.Inject)(t.Injector)),f(2,t.IConfigService)],q),Object.defineProperty(e,"SheetsCellContentController",{enumerable:!0,get:function(){return m}}),Object.defineProperty(e,"SheetsNotePopupController",{enumerable:!0,get:function(){return x}}),Object.defineProperty(e,"SheetsNotePopupService",{enumerable:!0,get:function(){return b}}),e.SheetsNoteUIMenuSchema=D,Object.defineProperty(e,"UniverSheetsNoteUIPlugin",{enumerable:!0,get:function(){return q}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-note-ui",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.3",
4
4
  "private": false,
5
5
  "description": "Cell note UI for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -56,23 +56,23 @@
56
56
  "rxjs": ">=7.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@univerjs/icons": "1.14.0",
60
- "@univerjs/core": "1.0.0-alpha.1",
61
- "@univerjs/design": "1.0.0-alpha.1",
62
- "@univerjs/engine-render": "1.0.0-alpha.1",
63
- "@univerjs/sheets-note": "1.0.0-alpha.1",
64
- "@univerjs/sheets-ui": "1.0.0-alpha.1",
65
- "@univerjs/sheets": "1.0.0-alpha.1",
66
- "@univerjs/ui": "1.0.0-alpha.1"
59
+ "@univerjs/icons": "1.20.0",
60
+ "@univerjs/core": "1.0.0-alpha.3",
61
+ "@univerjs/design": "1.0.0-alpha.3",
62
+ "@univerjs/sheets": "1.0.0-alpha.3",
63
+ "@univerjs/sheets-ui": "1.0.0-alpha.3",
64
+ "@univerjs/sheets-note": "1.0.0-alpha.3",
65
+ "@univerjs/ui": "1.0.0-alpha.3",
66
+ "@univerjs/engine-render": "1.0.0-alpha.3"
67
67
  },
68
68
  "devDependencies": {
69
- "postcss": "^8.5.15",
69
+ "postcss": "^8.5.16",
70
70
  "react": "18.3.1",
71
71
  "rxjs": "^7.8.2",
72
72
  "tailwindcss": "3.4.18",
73
73
  "typescript": "^6.0.3",
74
- "vitest": "^4.1.9",
75
- "@univerjs-infra/shared": "1.0.0-alpha.1"
74
+ "vitest": "^4.1.10",
75
+ "@univerjs-infra/shared": "1.0.0-alpha.3"
76
76
  },
77
77
  "scripts": {
78
78
  "test": "vitest run",