@univerjs/sheets-note-ui 0.25.0 → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -6,13 +6,13 @@ 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_ui = require("@univerjs/ui");
10
9
  let _univerjs_icons = require("@univerjs/icons");
10
+ let _univerjs_ui = require("@univerjs/ui");
11
11
  let _univerjs_design = require("@univerjs/design");
12
12
  let react = require("react");
13
13
  let react_jsx_runtime = require("react/jsx-runtime");
14
14
 
15
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
15
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
16
16
  function __decorateParam(paramIndex, decorator) {
17
17
  return function(target, key) {
18
18
  decorator(target, key, paramIndex);
@@ -20,7 +20,7 @@ function __decorateParam(paramIndex, decorator) {
20
20
  }
21
21
 
22
22
  //#endregion
23
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
23
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
24
24
  function __decorate(decorators, target, key, desc) {
25
25
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
26
26
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -105,7 +105,7 @@ SheetsCellContentController = __decorate([
105
105
  const SHEET_NOTE_COMPONENT = "SHEET_NOTE_COMPONENT";
106
106
 
107
107
  //#endregion
108
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
108
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
109
109
  function _typeof(o) {
110
110
  "@babel/helpers - typeof";
111
111
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -116,7 +116,7 @@ function _typeof(o) {
116
116
  }
117
117
 
118
118
  //#endregion
119
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
119
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
120
120
  function toPrimitive(t, r) {
121
121
  if ("object" != _typeof(t) || !t) return t;
122
122
  var e = t[Symbol.toPrimitive];
@@ -129,14 +129,14 @@ function toPrimitive(t, r) {
129
129
  }
130
130
 
131
131
  //#endregion
132
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
132
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
133
133
  function toPropertyKey(t) {
134
134
  var i = toPrimitive(t, "string");
135
135
  return "symbol" == _typeof(i) ? i : i + "";
136
136
  }
137
137
 
138
138
  //#endregion
139
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
139
+ //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
140
140
  function _defineProperty(e, r, t) {
141
141
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
142
142
  value: t,
@@ -152,24 +152,17 @@ let SheetsNotePopupService = class SheetsNotePopupService extends _univerjs_core
152
152
  get activePopup() {
153
153
  return this._activePopup;
154
154
  }
155
- constructor(_zenZoneService, _cellPopupManagerService) {
155
+ constructor(_cellPopupManagerService) {
156
156
  super();
157
- this._zenZoneService = _zenZoneService;
158
157
  this._cellPopupManagerService = _cellPopupManagerService;
159
158
  _defineProperty(this, "_lastPopup", null);
160
159
  _defineProperty(this, "_activePopup", void 0);
161
160
  _defineProperty(this, "_activePopup$", new rxjs.BehaviorSubject(null));
162
161
  _defineProperty(this, "activePopup$", this._activePopup$.asObservable());
163
- this._initZenVisible();
164
162
  this.disposeWithMe(() => {
165
163
  this._activePopup$.complete();
166
164
  });
167
165
  }
168
- _initZenVisible() {
169
- this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
170
- if (visible) this.hidePopup();
171
- }));
172
- }
173
166
  dispose() {
174
167
  super.dispose();
175
168
  this.hidePopup();
@@ -183,7 +176,6 @@ let SheetsNotePopupService = class SheetsNotePopupService extends _univerjs_core
183
176
  return;
184
177
  }
185
178
  if (this._lastPopup) this._lastPopup.dispose();
186
- if (this._zenZoneService.visible) return;
187
179
  this._activePopup = location;
188
180
  this._activePopup$.next(location);
189
181
  const popupDisposable = this._cellPopupManagerService.showPopup({
@@ -225,7 +217,7 @@ let SheetsNotePopupService = class SheetsNotePopupService extends _univerjs_core
225
217
  this._activePopup$.next(this._activePopup);
226
218
  }
227
219
  };
228
- SheetsNotePopupService = __decorate([__decorateParam(0, _univerjs_ui.IZenZoneService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellPopupManagerService))], SheetsNotePopupService);
220
+ SheetsNotePopupService = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellPopupManagerService))], SheetsNotePopupService);
229
221
 
230
222
  //#endregion
231
223
  //#region src/controllers/sheets-note-popup.controller.ts
@@ -345,7 +337,7 @@ SheetsNotePopupController = __decorate([
345
337
  //#endregion
346
338
  //#region package.json
347
339
  var name = "@univerjs/sheets-note-ui";
348
- var version = "0.25.0";
340
+ var version = "1.0.0-alpha.0";
349
341
 
350
342
  //#endregion
351
343
  //#region src/config/config.ts
@@ -353,6 +345,152 @@ const SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY = "sheets-note-ui.config";
353
345
  const configSymbol = Symbol(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY);
354
346
  const defaultPluginConfig = {};
355
347
 
348
+ //#endregion
349
+ //#region src/views/Note.tsx
350
+ const SheetsNote = (props) => {
351
+ var _popup$extraProps;
352
+ const { popup } = props;
353
+ const noteModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets_note.SheetsNoteModel);
354
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
355
+ const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
356
+ const notePopupService = (0, _univerjs_ui.useDependency)(SheetsNotePopupService);
357
+ const config = (0, _univerjs_ui.useConfigValue)(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY);
358
+ const activePopup = (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.location;
359
+ if (!activePopup) {
360
+ console.error("Popup extraProps or location is undefined.");
361
+ return null;
362
+ }
363
+ const textareaRef = (0, react.useRef)(null);
364
+ const currentRender = renderManagerService.getRenderById(activePopup.unitId);
365
+ const [note, setNote] = (0, react.useState)(null);
366
+ (0, react.useEffect)(() => {
367
+ var _ref, _note$width, _config$defaultNoteSi, _ref2, _note$height, _config$defaultNoteSi2;
368
+ const { unitId, subUnitId, row, col } = activePopup;
369
+ const note = noteModel.getNote(unitId, subUnitId, {
370
+ row,
371
+ col
372
+ });
373
+ const width = (_ref = (_note$width = note === null || note === void 0 ? void 0 : note.width) !== null && _note$width !== void 0 ? _note$width : config === null || config === void 0 || (_config$defaultNoteSi = config.defaultNoteSize) === null || _config$defaultNoteSi === void 0 ? void 0 : _config$defaultNoteSi.width) !== null && _ref !== void 0 ? _ref : 160;
374
+ const height = (_ref2 = (_note$height = note === null || note === void 0 ? void 0 : note.height) !== null && _note$height !== void 0 ? _note$height : config === null || config === void 0 || (_config$defaultNoteSi2 = config.defaultNoteSize) === null || _config$defaultNoteSi2 === void 0 ? void 0 : _config$defaultNoteSi2.height) !== null && _ref2 !== void 0 ? _ref2 : 72;
375
+ if (!note) {
376
+ const initNote = {
377
+ id: (0, _univerjs_core.generateRandomId)(6),
378
+ width,
379
+ height,
380
+ note: ""
381
+ };
382
+ setNote(initNote);
383
+ updateNote(initNote);
384
+ } else setNote(note);
385
+ if (textareaRef.current) {
386
+ textareaRef.current.style.width = `${width}px`;
387
+ textareaRef.current.style.height = `${height}px`;
388
+ }
389
+ }, [activePopup, textareaRef]);
390
+ (0, react.useEffect)(() => {
391
+ if (!activePopup || activePopup.temp || !activePopup.trigger) return;
392
+ if (!textareaRef.current) return;
393
+ const focusId = requestAnimationFrame(() => {
394
+ var _textareaRef$current;
395
+ (_textareaRef$current = textareaRef.current) === null || _textareaRef$current === void 0 || _textareaRef$current.focus();
396
+ });
397
+ return () => cancelAnimationFrame(focusId);
398
+ }, [activePopup]);
399
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
400
+ const updateNote = (0, _univerjs_ui.useDebounceFn)((newNote) => {
401
+ if (!activePopup) return;
402
+ const { unitId, subUnitId, row, col } = activePopup;
403
+ if (!commandService.syncExecuteCommand(_univerjs_sheets_note.SheetUpdateNoteCommand.id, {
404
+ unitId,
405
+ sheetId: subUnitId,
406
+ row,
407
+ col,
408
+ note: newNote
409
+ })) {
410
+ const oldNote = noteModel.getNote(unitId, subUnitId, {
411
+ noteId: newNote.id,
412
+ row,
413
+ col
414
+ });
415
+ if (oldNote) setNote(oldNote);
416
+ else notePopupService.hidePopup(true);
417
+ }
418
+ });
419
+ const handleNoteChange = (0, react.useCallback)((value) => {
420
+ if (!note) return;
421
+ if (value === note.note) return;
422
+ const newNote = {
423
+ ...note,
424
+ note: value
425
+ };
426
+ setNote(newNote);
427
+ updateNote(newNote);
428
+ }, [note]);
429
+ const handleResize = (0, react.useCallback)((width, height) => {
430
+ if (!note) return;
431
+ if (width === note.width && height === note.height) return;
432
+ const newNote = {
433
+ ...note,
434
+ width,
435
+ height
436
+ };
437
+ setNote(newNote);
438
+ updateNote(newNote);
439
+ }, [note]);
440
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Textarea, {
441
+ ref: textareaRef,
442
+ "data-u-comp": "note-textarea",
443
+ className: (0, _univerjs_design.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"),
444
+ value: note === null || note === void 0 ? void 0 : note.note,
445
+ placeholder: localeService.t("sheets-note-ui.note.placeholder"),
446
+ onResize: handleResize,
447
+ onValueChange: handleNoteChange,
448
+ onWheel: (e) => {
449
+ if (document.activeElement !== textareaRef.current) currentRender.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type, e.nativeEvent));
450
+ }
451
+ });
452
+ };
453
+
454
+ //#endregion
455
+ //#region src/controllers/components.controller.ts
456
+ /**
457
+ * Copyright 2023-present DreamNum Co., Ltd.
458
+ *
459
+ * Licensed under the Apache License, Version 2.0 (the "License");
460
+ * you may not use this file except in compliance with the License.
461
+ * You may obtain a copy of the License at
462
+ *
463
+ * http://www.apache.org/licenses/LICENSE-2.0
464
+ *
465
+ * Unless required by applicable law or agreed to in writing, software
466
+ * distributed under the License is distributed on an "AS IS" BASIS,
467
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
468
+ * See the License for the specific language governing permissions and
469
+ * limitations under the License.
470
+ */
471
+ let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
472
+ constructor(_componentManager, _iconManager) {
473
+ super();
474
+ this._componentManager = _componentManager;
475
+ this._iconManager = _iconManager;
476
+ this._registerComponents();
477
+ this._registerIcons();
478
+ }
479
+ _registerComponents() {
480
+ [[SHEET_NOTE_COMPONENT, SheetsNote]].forEach(([key, comp]) => {
481
+ this.disposeWithMe(this._componentManager.register(key, comp));
482
+ });
483
+ }
484
+ _registerIcons() {
485
+ this.disposeWithMe(this._iconManager.register({
486
+ AddNoteIcon: _univerjs_icons.AddNoteIcon,
487
+ DeleteNoteIcon: _univerjs_icons.DeleteNoteIcon,
488
+ HideNoteIcon: _univerjs_icons.HideNoteIcon
489
+ }));
490
+ }
491
+ };
492
+ ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
493
+
356
494
  //#endregion
357
495
  //#region src/controllers/sheets-note-attachment.controller.ts
358
496
  let SheetsNoteAttachmentController = class SheetsNoteAttachmentController extends _univerjs_core.Disposable {
@@ -566,113 +704,7 @@ const menuSchema = { [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_
566
704
  } } };
567
705
 
568
706
  //#endregion
569
- //#region src/views/Note.tsx
570
- const SheetsNote = (props) => {
571
- var _popup$extraProps;
572
- const { popup } = props;
573
- const noteModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets_note.SheetsNoteModel);
574
- const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
575
- const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
576
- const notePopupService = (0, _univerjs_ui.useDependency)(SheetsNotePopupService);
577
- const config = (0, _univerjs_ui.useConfigValue)(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY);
578
- const activePopup = (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.location;
579
- if (!activePopup) {
580
- console.error("Popup extraProps or location is undefined.");
581
- return null;
582
- }
583
- const textareaRef = (0, react.useRef)(null);
584
- const currentRender = renderManagerService.getRenderById(activePopup.unitId);
585
- const [note, setNote] = (0, react.useState)(null);
586
- (0, react.useEffect)(() => {
587
- var _ref, _note$width, _config$defaultNoteSi, _ref2, _note$height, _config$defaultNoteSi2;
588
- const { unitId, subUnitId, row, col } = activePopup;
589
- const note = noteModel.getNote(unitId, subUnitId, {
590
- row,
591
- col
592
- });
593
- const width = (_ref = (_note$width = note === null || note === void 0 ? void 0 : note.width) !== null && _note$width !== void 0 ? _note$width : config === null || config === void 0 || (_config$defaultNoteSi = config.defaultNoteSize) === null || _config$defaultNoteSi === void 0 ? void 0 : _config$defaultNoteSi.width) !== null && _ref !== void 0 ? _ref : 160;
594
- const height = (_ref2 = (_note$height = note === null || note === void 0 ? void 0 : note.height) !== null && _note$height !== void 0 ? _note$height : config === null || config === void 0 || (_config$defaultNoteSi2 = config.defaultNoteSize) === null || _config$defaultNoteSi2 === void 0 ? void 0 : _config$defaultNoteSi2.height) !== null && _ref2 !== void 0 ? _ref2 : 72;
595
- if (!note) {
596
- const initNote = {
597
- id: (0, _univerjs_core.generateRandomId)(6),
598
- width,
599
- height,
600
- note: ""
601
- };
602
- setNote(initNote);
603
- updateNote(initNote);
604
- } else setNote(note);
605
- if (textareaRef.current) {
606
- textareaRef.current.style.width = `${width}px`;
607
- textareaRef.current.style.height = `${height}px`;
608
- }
609
- }, [activePopup, textareaRef]);
610
- (0, react.useEffect)(() => {
611
- if (!activePopup || activePopup.temp || !activePopup.trigger) return;
612
- if (!textareaRef.current) return;
613
- const focusId = requestAnimationFrame(() => {
614
- var _textareaRef$current;
615
- (_textareaRef$current = textareaRef.current) === null || _textareaRef$current === void 0 || _textareaRef$current.focus();
616
- });
617
- return () => cancelAnimationFrame(focusId);
618
- }, [activePopup]);
619
- const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
620
- const updateNote = (0, _univerjs_ui.useDebounceFn)((newNote) => {
621
- if (!activePopup) return;
622
- const { unitId, subUnitId, row, col } = activePopup;
623
- if (!commandService.syncExecuteCommand(_univerjs_sheets_note.SheetUpdateNoteCommand.id, {
624
- unitId,
625
- sheetId: subUnitId,
626
- row,
627
- col,
628
- note: newNote
629
- })) {
630
- const oldNote = noteModel.getNote(unitId, subUnitId, {
631
- noteId: newNote.id,
632
- row,
633
- col
634
- });
635
- if (oldNote) setNote(oldNote);
636
- else notePopupService.hidePopup(true);
637
- }
638
- });
639
- const handleNoteChange = (0, react.useCallback)((value) => {
640
- if (!note) return;
641
- if (value === note.note) return;
642
- const newNote = {
643
- ...note,
644
- note: value
645
- };
646
- setNote(newNote);
647
- updateNote(newNote);
648
- }, [note]);
649
- const handleResize = (0, react.useCallback)((width, height) => {
650
- if (!note) return;
651
- if (width === note.width && height === note.height) return;
652
- const newNote = {
653
- ...note,
654
- width,
655
- height
656
- };
657
- setNote(newNote);
658
- updateNote(newNote);
659
- }, [note]);
660
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Textarea, {
661
- ref: textareaRef,
662
- "data-u-comp": "note-textarea",
663
- className: (0, _univerjs_design.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"),
664
- value: note === null || note === void 0 ? void 0 : note.note,
665
- placeholder: localeService.t("sheets-note-ui.note.placeholder"),
666
- onResize: handleResize,
667
- onValueChange: handleNoteChange,
668
- onWheel: (e) => {
669
- if (document.activeElement !== textareaRef.current) currentRender.engine.getCanvasElement().dispatchEvent(new WheelEvent(e.type, e.nativeEvent));
670
- }
671
- });
672
- };
673
-
674
- //#endregion
675
- //#region src/controllers/sheets-note-ui.controller.ts
707
+ //#region src/controllers/ui.controller.ts
676
708
  /**
677
709
  * Copyright 2023-present DreamNum Co., Ltd.
678
710
  *
@@ -689,25 +721,13 @@ const SheetsNote = (props) => {
689
721
  * limitations under the License.
690
722
  */
691
723
  let SheetsNoteUIController = class SheetsNoteUIController extends _univerjs_core.Disposable {
692
- constructor(_componentManager, _menuManagerService, _commandService) {
724
+ constructor(_menuManagerService, _commandService) {
693
725
  super();
694
- this._componentManager = _componentManager;
695
726
  this._menuManagerService = _menuManagerService;
696
727
  this._commandService = _commandService;
697
- this._initComponents();
698
728
  this._initMenu();
699
729
  this._initCommands();
700
730
  }
701
- _initComponents() {
702
- [
703
- [SHEET_NOTE_COMPONENT, SheetsNote],
704
- ["AddNoteIcon", _univerjs_icons.AddNoteIcon],
705
- ["DeleteNoteIcon", _univerjs_icons.DeleteNoteIcon],
706
- ["HideNoteIcon", _univerjs_icons.HideNoteIcon]
707
- ].forEach(([key, comp]) => {
708
- this.disposeWithMe(this._componentManager.register(key, comp));
709
- });
710
- }
711
731
  _initMenu() {
712
732
  this._menuManagerService.mergeMenu(menuSchema);
713
733
  }
@@ -715,11 +735,7 @@ let SheetsNoteUIController = class SheetsNoteUIController extends _univerjs_core
715
735
  this._commandService.registerCommand(AddNotePopupOperation);
716
736
  }
717
737
  };
718
- SheetsNoteUIController = __decorate([
719
- __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
720
- __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IMenuManagerService)),
721
- __decorateParam(2, _univerjs_core.ICommandService)
722
- ], SheetsNoteUIController);
738
+ SheetsNoteUIController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.IMenuManagerService)), __decorateParam(1, _univerjs_core.ICommandService)], SheetsNoteUIController);
723
739
 
724
740
  //#endregion
725
741
  //#region src/plugin.ts
@@ -734,6 +750,8 @@ let UniverSheetsNoteUIPlugin = class UniverSheetsNoteUIPlugin extends _univerjs_
734
750
  this._configService.setConfig(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY, rest);
735
751
  }
736
752
  onStarting() {
753
+ this._injector.add([ComponentsController]);
754
+ this._injector.get(ComponentsController);
737
755
  [
738
756
  [SheetsNotePopupService],
739
757
  [SheetsCellContentController],
@@ -768,7 +786,6 @@ Object.defineProperty(exports, 'SheetsCellContentController', {
768
786
  return SheetsCellContentController;
769
787
  }
770
788
  });
771
- exports.SheetsNote = SheetsNote;
772
789
  Object.defineProperty(exports, 'SheetsNotePopupController', {
773
790
  enumerable: true,
774
791
  get: function () {