@apollo-office/sheets-note-ui 1.0.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/LICENSE +176 -0
- package/MODIFICATIONS.md +26 -0
- package/NOTICE +14 -0
- package/README.md +42 -0
- package/lib/cjs/index.js +789 -0
- package/lib/cjs/locale/ar-SA.js +13 -0
- package/lib/cjs/locale/ca-ES.js +13 -0
- package/lib/cjs/locale/de-DE.js +13 -0
- package/lib/cjs/locale/en-US.js +28 -0
- package/lib/cjs/locale/es-ES.js +13 -0
- package/lib/cjs/locale/fa-IR.js +13 -0
- package/lib/cjs/locale/fr-FR.js +13 -0
- package/lib/cjs/locale/id-ID.js +13 -0
- package/lib/cjs/locale/it-IT.js +13 -0
- package/lib/cjs/locale/ja-JP.js +13 -0
- package/lib/cjs/locale/ko-KR.js +13 -0
- package/lib/cjs/locale/pl-PL.js +13 -0
- package/lib/cjs/locale/pt-BR.js +13 -0
- package/lib/cjs/locale/ru-RU.js +13 -0
- package/lib/cjs/locale/sk-SK.js +13 -0
- package/lib/cjs/locale/vi-VN.js +13 -0
- package/lib/cjs/locale/zh-CN.js +13 -0
- package/lib/cjs/locale/zh-HK.js +13 -0
- package/lib/cjs/locale/zh-TW.js +13 -0
- package/lib/es/index.js +764 -0
- package/lib/es/locale/ar-SA.js +12 -0
- package/lib/es/locale/ca-ES.js +12 -0
- package/lib/es/locale/de-DE.js +12 -0
- package/lib/es/locale/en-US.js +27 -0
- package/lib/es/locale/es-ES.js +12 -0
- package/lib/es/locale/fa-IR.js +12 -0
- package/lib/es/locale/fr-FR.js +12 -0
- package/lib/es/locale/id-ID.js +12 -0
- package/lib/es/locale/it-IT.js +12 -0
- package/lib/es/locale/ja-JP.js +12 -0
- package/lib/es/locale/ko-KR.js +12 -0
- package/lib/es/locale/pl-PL.js +12 -0
- package/lib/es/locale/pt-BR.js +12 -0
- package/lib/es/locale/ru-RU.js +12 -0
- package/lib/es/locale/sk-SK.js +12 -0
- package/lib/es/locale/vi-VN.js +12 -0
- package/lib/es/locale/zh-CN.js +12 -0
- package/lib/es/locale/zh-HK.js +12 -0
- package/lib/es/locale/zh-TW.js +12 -0
- package/lib/index.css +31 -0
- package/lib/index.js +764 -0
- package/lib/locale/ar-SA.js +12 -0
- package/lib/locale/ca-ES.js +12 -0
- package/lib/locale/de-DE.js +12 -0
- package/lib/locale/en-US.js +27 -0
- package/lib/locale/es-ES.js +12 -0
- package/lib/locale/fa-IR.js +12 -0
- package/lib/locale/fr-FR.js +12 -0
- package/lib/locale/id-ID.js +12 -0
- package/lib/locale/it-IT.js +12 -0
- package/lib/locale/ja-JP.js +12 -0
- package/lib/locale/ko-KR.js +12 -0
- package/lib/locale/pl-PL.js +12 -0
- package/lib/locale/pt-BR.js +12 -0
- package/lib/locale/ru-RU.js +12 -0
- package/lib/locale/sk-SK.js +12 -0
- package/lib/locale/vi-VN.js +12 -0
- package/lib/locale/zh-CN.js +12 -0
- package/lib/locale/zh-HK.js +12 -0
- package/lib/locale/zh-TW.js +12 -0
- package/lib/types/commands/operations/add-note-popup.operation.d.ts +20 -0
- package/lib/types/config/config.d.ts +26 -0
- package/lib/types/controllers/sheets-cell-content.controller.d.ts +28 -0
- package/lib/types/controllers/sheets-note-attachment.controller.d.ts +31 -0
- package/lib/types/controllers/sheets-note-popup.controller.d.ts +36 -0
- package/lib/types/controllers/sheets-note-ui.controller.d.ts +26 -0
- package/lib/types/index.d.ts +22 -0
- package/lib/types/locale/ar-SA.d.ts +18 -0
- package/lib/types/locale/ca-ES.d.ts +18 -0
- package/lib/types/locale/de-DE.d.ts +18 -0
- package/lib/types/locale/en-US.d.ts +28 -0
- package/lib/types/locale/es-ES.d.ts +18 -0
- package/lib/types/locale/fa-IR.d.ts +18 -0
- package/lib/types/locale/fr-FR.d.ts +18 -0
- package/lib/types/locale/id-ID.d.ts +18 -0
- package/lib/types/locale/it-IT.d.ts +18 -0
- package/lib/types/locale/ja-JP.d.ts +18 -0
- package/lib/types/locale/ko-KR.d.ts +18 -0
- package/lib/types/locale/pl-PL.d.ts +18 -0
- package/lib/types/locale/pt-BR.d.ts +18 -0
- package/lib/types/locale/ru-RU.d.ts +18 -0
- package/lib/types/locale/sk-SK.d.ts +18 -0
- package/lib/types/locale/vi-VN.d.ts +18 -0
- package/lib/types/locale/zh-CN.d.ts +18 -0
- package/lib/types/locale/zh-HK.d.ts +18 -0
- package/lib/types/locale/zh-TW.d.ts +18 -0
- package/lib/types/menu/note.menu.d.ts +21 -0
- package/lib/types/menu/schema.d.ts +17 -0
- package/lib/types/plugin.d.ts +30 -0
- package/lib/types/services/sheets-note-popup.service.d.ts +41 -0
- package/lib/types/views/Note.d.ts +27 -0
- package/lib/types/views/config.d.ts +16 -0
- package/lib/umd/index.js +1 -0
- package/lib/umd/locale/ar-SA.js +1 -0
- package/lib/umd/locale/ca-ES.js +1 -0
- package/lib/umd/locale/de-DE.js +1 -0
- package/lib/umd/locale/en-US.js +1 -0
- package/lib/umd/locale/es-ES.js +1 -0
- package/lib/umd/locale/fa-IR.js +1 -0
- package/lib/umd/locale/fr-FR.js +1 -0
- package/lib/umd/locale/id-ID.js +1 -0
- package/lib/umd/locale/it-IT.js +1 -0
- package/lib/umd/locale/ja-JP.js +1 -0
- package/lib/umd/locale/ko-KR.js +1 -0
- package/lib/umd/locale/pl-PL.js +1 -0
- package/lib/umd/locale/pt-BR.js +1 -0
- package/lib/umd/locale/ru-RU.js +1 -0
- package/lib/umd/locale/sk-SK.js +1 -0
- package/lib/umd/locale/vi-VN.js +1 -0
- package/lib/umd/locale/zh-CN.js +1 -0
- package/lib/umd/locale/zh-HK.js +1 -0
- package/lib/umd/locale/zh-TW.js +1 -0
- package/package.json +73 -0
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,789 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@apollo-office/core");
|
|
3
|
+
let _univerjs_engine_render = require("@apollo-office/engine-render");
|
|
4
|
+
let _univerjs_sheets = require("@apollo-office/sheets");
|
|
5
|
+
let _univerjs_sheets_note = require("@apollo-office/sheets-note");
|
|
6
|
+
let rxjs = require("rxjs");
|
|
7
|
+
let _univerjs_sheets_ui = require("@apollo-office/sheets-ui");
|
|
8
|
+
let rxjs_operators = require("rxjs/operators");
|
|
9
|
+
let _univerjs_ui = require("@apollo-office/ui");
|
|
10
|
+
let _univerjs_icons = require("@univerjs/icons");
|
|
11
|
+
let _univerjs_design = require("@apollo-office/design");
|
|
12
|
+
let react = require("react");
|
|
13
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
14
|
+
|
|
15
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
16
|
+
function __decorateParam(paramIndex, decorator) {
|
|
17
|
+
return function(target, key) {
|
|
18
|
+
decorator(target, key, paramIndex);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorate.js
|
|
24
|
+
function __decorate(decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/controllers/sheets-cell-content.controller.ts
|
|
33
|
+
let SheetsCellContentController = class SheetsCellContentController extends _univerjs_core.Disposable {
|
|
34
|
+
constructor(_sheetInterceptorService, _sheetsNoteModel, _renderManagerService, _univerInstanceService) {
|
|
35
|
+
super();
|
|
36
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
37
|
+
this._sheetsNoteModel = _sheetsNoteModel;
|
|
38
|
+
this._renderManagerService = _renderManagerService;
|
|
39
|
+
this._univerInstanceService = _univerInstanceService;
|
|
40
|
+
this._initViewModelIntercept();
|
|
41
|
+
this._initSkeletonChange();
|
|
42
|
+
}
|
|
43
|
+
_initViewModelIntercept() {
|
|
44
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
45
|
+
effect: _univerjs_core.InterceptorEffectEnum.Style,
|
|
46
|
+
handler: (cell, pos, next) => {
|
|
47
|
+
const { row, col, unitId, subUnitId } = pos;
|
|
48
|
+
if (this._sheetsNoteModel.getNote(unitId, subUnitId, {
|
|
49
|
+
row,
|
|
50
|
+
col
|
|
51
|
+
})) {
|
|
52
|
+
if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
|
|
53
|
+
cell.markers = {
|
|
54
|
+
...cell === null || cell === void 0 ? void 0 : cell.markers,
|
|
55
|
+
tr: {
|
|
56
|
+
color: "#FFBD37",
|
|
57
|
+
size: 6
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return next(cell);
|
|
61
|
+
}
|
|
62
|
+
return next(cell);
|
|
63
|
+
},
|
|
64
|
+
priority: 100
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
_initSkeletonChange() {
|
|
68
|
+
const markSkeletonDirty = () => {
|
|
69
|
+
var _currentRender$mainCo;
|
|
70
|
+
const workbook = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
71
|
+
if (!workbook) return;
|
|
72
|
+
const unitId = workbook.getUnitId();
|
|
73
|
+
const currentRender = this._renderManagerService.getRenderById(unitId);
|
|
74
|
+
currentRender === null || currentRender === void 0 || (_currentRender$mainCo = currentRender.mainComponent) === null || _currentRender$mainCo === void 0 || _currentRender$mainCo.makeForceDirty();
|
|
75
|
+
};
|
|
76
|
+
this.disposeWithMe(this._sheetsNoteModel.change$.pipe((0, rxjs.debounceTime)(16)).subscribe(() => {
|
|
77
|
+
markSkeletonDirty();
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
SheetsCellContentController = __decorate([
|
|
82
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
83
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_note.SheetsNoteModel)),
|
|
84
|
+
__decorateParam(2, _univerjs_engine_render.IRenderManagerService),
|
|
85
|
+
__decorateParam(3, _univerjs_core.IUniverInstanceService)
|
|
86
|
+
], SheetsCellContentController);
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/views/config.ts
|
|
90
|
+
/**
|
|
91
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
92
|
+
*
|
|
93
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
94
|
+
* you may not use this file except in compliance with the License.
|
|
95
|
+
* You may obtain a copy of the License at
|
|
96
|
+
*
|
|
97
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
98
|
+
*
|
|
99
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
100
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
101
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
102
|
+
* See the License for the specific language governing permissions and
|
|
103
|
+
* limitations under the License.
|
|
104
|
+
*/
|
|
105
|
+
const SHEET_NOTE_COMPONENT = "SHEET_NOTE_COMPONENT";
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
109
|
+
function _typeof(o) {
|
|
110
|
+
"@babel/helpers - typeof";
|
|
111
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
112
|
+
return typeof o;
|
|
113
|
+
} : function(o) {
|
|
114
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
115
|
+
}, _typeof(o);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
120
|
+
function toPrimitive(t, r) {
|
|
121
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
122
|
+
var e = t[Symbol.toPrimitive];
|
|
123
|
+
if (void 0 !== e) {
|
|
124
|
+
var i = e.call(t, r || "default");
|
|
125
|
+
if ("object" != _typeof(i)) return i;
|
|
126
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
127
|
+
}
|
|
128
|
+
return ("string" === r ? String : Number)(t);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
133
|
+
function toPropertyKey(t) {
|
|
134
|
+
var i = toPrimitive(t, "string");
|
|
135
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
140
|
+
function _defineProperty(e, r, t) {
|
|
141
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
142
|
+
value: t,
|
|
143
|
+
enumerable: !0,
|
|
144
|
+
configurable: !0,
|
|
145
|
+
writable: !0
|
|
146
|
+
}) : e[r] = t, e;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/services/sheets-note-popup.service.ts
|
|
151
|
+
let SheetsNotePopupService = class SheetsNotePopupService extends _univerjs_core.Disposable {
|
|
152
|
+
get activePopup() {
|
|
153
|
+
return this._activePopup;
|
|
154
|
+
}
|
|
155
|
+
constructor(_zenZoneService, _cellPopupManagerService) {
|
|
156
|
+
super();
|
|
157
|
+
this._zenZoneService = _zenZoneService;
|
|
158
|
+
this._cellPopupManagerService = _cellPopupManagerService;
|
|
159
|
+
_defineProperty(this, "_lastPopup", null);
|
|
160
|
+
_defineProperty(this, "_activePopup", void 0);
|
|
161
|
+
_defineProperty(this, "_activePopup$", new rxjs.BehaviorSubject(null));
|
|
162
|
+
_defineProperty(this, "activePopup$", this._activePopup$.asObservable());
|
|
163
|
+
this._initZenVisible();
|
|
164
|
+
this.disposeWithMe(() => {
|
|
165
|
+
this._activePopup$.complete();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
_initZenVisible() {
|
|
169
|
+
this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
|
|
170
|
+
if (visible) this.hidePopup();
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
dispose() {
|
|
174
|
+
super.dispose();
|
|
175
|
+
this.hidePopup();
|
|
176
|
+
}
|
|
177
|
+
showPopup(location, onHide) {
|
|
178
|
+
var _this$activePopup;
|
|
179
|
+
const { row, col, unitId, subUnitId } = location;
|
|
180
|
+
if (this._activePopup && row === this._activePopup.row && col === this._activePopup.col && unitId === this._activePopup.unitId && subUnitId === ((_this$activePopup = this.activePopup) === null || _this$activePopup === void 0 ? void 0 : _this$activePopup.subUnitId)) {
|
|
181
|
+
this._activePopup = location;
|
|
182
|
+
this._activePopup$.next(location);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (this._lastPopup) this._lastPopup.dispose();
|
|
186
|
+
if (this._zenZoneService.visible) return;
|
|
187
|
+
this._activePopup = location;
|
|
188
|
+
this._activePopup$.next(location);
|
|
189
|
+
const popupDisposable = this._cellPopupManagerService.showPopup({
|
|
190
|
+
unitId,
|
|
191
|
+
subUnitId,
|
|
192
|
+
row,
|
|
193
|
+
col
|
|
194
|
+
}, {
|
|
195
|
+
componentKey: SHEET_NOTE_COMPONENT,
|
|
196
|
+
onClickOutside: () => {
|
|
197
|
+
this.hidePopup();
|
|
198
|
+
},
|
|
199
|
+
direction: "horizontal",
|
|
200
|
+
extraProps: { location },
|
|
201
|
+
priority: 3
|
|
202
|
+
});
|
|
203
|
+
if (!popupDisposable) throw new Error("[SheetsNotePopupService]: cannot show popup!");
|
|
204
|
+
const disposableCollection = new _univerjs_core.DisposableCollection();
|
|
205
|
+
disposableCollection.add(popupDisposable);
|
|
206
|
+
disposableCollection.add({ dispose: () => {
|
|
207
|
+
onHide === null || onHide === void 0 || onHide();
|
|
208
|
+
} });
|
|
209
|
+
this._lastPopup = disposableCollection;
|
|
210
|
+
}
|
|
211
|
+
hidePopup(force) {
|
|
212
|
+
if (!this._activePopup) return;
|
|
213
|
+
if (!force && !this._activePopup.temp) return;
|
|
214
|
+
if (this._lastPopup) this._lastPopup.dispose();
|
|
215
|
+
this._lastPopup = null;
|
|
216
|
+
this._activePopup = null;
|
|
217
|
+
this._activePopup$.next(null);
|
|
218
|
+
}
|
|
219
|
+
persistPopup() {
|
|
220
|
+
if (!this._activePopup || !this._activePopup.temp) return;
|
|
221
|
+
this._activePopup = {
|
|
222
|
+
...this._activePopup,
|
|
223
|
+
temp: false
|
|
224
|
+
};
|
|
225
|
+
this._activePopup$.next(this._activePopup);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
SheetsNotePopupService = __decorate([__decorateParam(0, _univerjs_ui.IZenZoneService), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellPopupManagerService))], SheetsNotePopupService);
|
|
229
|
+
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/controllers/sheets-note-popup.controller.ts
|
|
232
|
+
let SheetsNotePopupController = class SheetsNotePopupController extends _univerjs_core.Disposable {
|
|
233
|
+
constructor(_sheetsNotePopupService, _sheetsNoteModel, _sheetSelectionService, _editorBridgeService, _renderManagerService, _hoverManagerService) {
|
|
234
|
+
super();
|
|
235
|
+
this._sheetsNotePopupService = _sheetsNotePopupService;
|
|
236
|
+
this._sheetsNoteModel = _sheetsNoteModel;
|
|
237
|
+
this._sheetSelectionService = _sheetSelectionService;
|
|
238
|
+
this._editorBridgeService = _editorBridgeService;
|
|
239
|
+
this._renderManagerService = _renderManagerService;
|
|
240
|
+
this._hoverManagerService = _hoverManagerService;
|
|
241
|
+
_defineProperty(this, "_isSwitchingSheet", false);
|
|
242
|
+
this._initSelectionUpdateListener();
|
|
243
|
+
this._initEditorBridge();
|
|
244
|
+
this._initHoverEvent();
|
|
245
|
+
this._initDeleteNoteListener();
|
|
246
|
+
}
|
|
247
|
+
_handleSelectionChange(selections, unitId, subUnitId) {
|
|
248
|
+
var _selections$, _render$with$getSkele, _range$rangeType;
|
|
249
|
+
const range = (_selections$ = selections[0]) === null || _selections$ === void 0 ? void 0 : _selections$.range;
|
|
250
|
+
const render = this._renderManagerService.getRenderById(unitId);
|
|
251
|
+
const skeleton = render === null || render === void 0 || (_render$with$getSkele = render.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _render$with$getSkele === void 0 ? void 0 : _render$with$getSkele.skeleton;
|
|
252
|
+
if (!skeleton) return;
|
|
253
|
+
if (!range) return;
|
|
254
|
+
const actualCell = skeleton.getCellWithCoordByIndex(range.startRow, range.startColumn);
|
|
255
|
+
if ((((_range$rangeType = range.rangeType) !== null && _range$rangeType !== void 0 ? _range$rangeType : _univerjs_core.RANGE_TYPE.NORMAL) !== _univerjs_core.RANGE_TYPE.NORMAL || range.endColumn - range.startColumn > 0 || range.endRow - range.startRow > 0) && !((actualCell.isMerged || actualCell.isMergedMainCell) && _univerjs_core.Rectangle.equals(actualCell.mergeInfo, range))) {
|
|
256
|
+
this._sheetsNotePopupService.hidePopup();
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const row = actualCell.actualRow;
|
|
260
|
+
const col = actualCell.actualColumn;
|
|
261
|
+
const note = this._sheetsNoteModel.getNote(unitId, subUnitId, {
|
|
262
|
+
row,
|
|
263
|
+
col
|
|
264
|
+
});
|
|
265
|
+
if (note === null || note === void 0 ? void 0 : note.show) return;
|
|
266
|
+
if (note) this._sheetsNotePopupService.showPopup({
|
|
267
|
+
unitId,
|
|
268
|
+
subUnitId,
|
|
269
|
+
noteId: note.id,
|
|
270
|
+
row,
|
|
271
|
+
col
|
|
272
|
+
});
|
|
273
|
+
else this._sheetsNotePopupService.hidePopup(true);
|
|
274
|
+
}
|
|
275
|
+
_initSelectionUpdateListener() {
|
|
276
|
+
this.disposeWithMe(this._sheetSelectionService.selectionMoveEnd$.subscribe((selections) => {
|
|
277
|
+
if (this._isSwitchingSheet) return;
|
|
278
|
+
const current = this._sheetSelectionService.currentSelectionParam;
|
|
279
|
+
if (!current) return;
|
|
280
|
+
this._handleSelectionChange(selections, current.unitId, current.sheetId);
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
_initEditorBridge() {
|
|
284
|
+
this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
|
|
285
|
+
if (visible.visible) this._sheetsNotePopupService.hidePopup(true);
|
|
286
|
+
}));
|
|
287
|
+
}
|
|
288
|
+
_initHoverEvent() {
|
|
289
|
+
this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs_operators.debounceTime)(100)).subscribe((cell) => {
|
|
290
|
+
var _render$with$getSkele2;
|
|
291
|
+
if (!(cell === null || cell === void 0 ? void 0 : cell.location)) return;
|
|
292
|
+
const { unitId, subUnitId, row, col } = cell.location;
|
|
293
|
+
const render = this._renderManagerService.getRenderById(unitId);
|
|
294
|
+
const skeleton = render === null || render === void 0 || (_render$with$getSkele2 = render.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _render$with$getSkele2 === void 0 ? void 0 : _render$with$getSkele2.skeleton;
|
|
295
|
+
let targetRow = row;
|
|
296
|
+
let targetCol = col;
|
|
297
|
+
let note = this._sheetsNoteModel.getNote(unitId, subUnitId, {
|
|
298
|
+
row: targetRow,
|
|
299
|
+
col: targetCol
|
|
300
|
+
});
|
|
301
|
+
if (!note && skeleton) {
|
|
302
|
+
const { startRow, endRow, startColumn, endColumn } = skeleton.getCellWithCoordByIndex(row, col).mergeInfo;
|
|
303
|
+
if (startRow !== endRow || startColumn !== endColumn) {
|
|
304
|
+
const sheetNotes = this._sheetsNoteModel.getSheetNotes(unitId, subUnitId);
|
|
305
|
+
if (sheetNotes) {
|
|
306
|
+
for (const [_id, _note] of sheetNotes) if (_note.row >= startRow && _note.row <= endRow && _note.col >= startColumn && _note.col <= endColumn) {
|
|
307
|
+
note = _note;
|
|
308
|
+
targetRow = _note.row;
|
|
309
|
+
targetCol = _note.col;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (note === null || note === void 0 ? void 0 : note.show) return;
|
|
316
|
+
if (note) this._sheetsNotePopupService.showPopup({
|
|
317
|
+
unitId,
|
|
318
|
+
subUnitId,
|
|
319
|
+
noteId: note.id,
|
|
320
|
+
row: targetRow,
|
|
321
|
+
col: targetCol,
|
|
322
|
+
temp: true
|
|
323
|
+
});
|
|
324
|
+
else this._sheetsNotePopupService.hidePopup();
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
327
|
+
_initDeleteNoteListener() {
|
|
328
|
+
this.disposeWithMe(this._sheetsNoteModel.change$.subscribe((change) => {
|
|
329
|
+
if (!this._sheetsNotePopupService.activePopup) return;
|
|
330
|
+
const { unitId, subUnitId, noteId, row, col } = this._sheetsNotePopupService.activePopup;
|
|
331
|
+
const { oldNote, newNote } = change;
|
|
332
|
+
if (newNote === null && change.unitId === unitId && change.subUnitId === subUnitId && ((oldNote === null || oldNote === void 0 ? void 0 : oldNote.id) && oldNote.id === noteId || (oldNote === null || oldNote === void 0 ? void 0 : oldNote.row) === row && oldNote.col === col)) this._sheetsNotePopupService.hidePopup(true);
|
|
333
|
+
}));
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
SheetsNotePopupController = __decorate([
|
|
337
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(SheetsNotePopupService)),
|
|
338
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_note.SheetsNoteModel)),
|
|
339
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
|
|
340
|
+
__decorateParam(3, _univerjs_sheets_ui.IEditorBridgeService),
|
|
341
|
+
__decorateParam(4, _univerjs_engine_render.IRenderManagerService),
|
|
342
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService))
|
|
343
|
+
], SheetsNotePopupController);
|
|
344
|
+
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region package.json
|
|
347
|
+
var name = "@apollo-office/sheets-note-ui";
|
|
348
|
+
var version = "0.25.1";
|
|
349
|
+
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/config/config.ts
|
|
352
|
+
const SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY = "sheets-note-ui.config";
|
|
353
|
+
const configSymbol = Symbol(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY);
|
|
354
|
+
const defaultPluginConfig = {};
|
|
355
|
+
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/controllers/sheets-note-attachment.controller.ts
|
|
358
|
+
let SheetsNoteAttachmentController = class SheetsNoteAttachmentController extends _univerjs_core.Disposable {
|
|
359
|
+
constructor(_sheetsNoteModel, _univerInstanceService, _cellPopupManagerService, _sheetsNotePopupService) {
|
|
360
|
+
super();
|
|
361
|
+
this._sheetsNoteModel = _sheetsNoteModel;
|
|
362
|
+
this._univerInstanceService = _univerInstanceService;
|
|
363
|
+
this._cellPopupManagerService = _cellPopupManagerService;
|
|
364
|
+
this._sheetsNotePopupService = _sheetsNotePopupService;
|
|
365
|
+
_defineProperty(this, "_noteMatrix", new _univerjs_core.ObjectMatrix());
|
|
366
|
+
this._initNoteChangeListener();
|
|
367
|
+
}
|
|
368
|
+
_showPopup(unitId, sheetId, row, col) {
|
|
369
|
+
this._sheetsNotePopupService.hidePopup(true);
|
|
370
|
+
return this._cellPopupManagerService.showPopup({
|
|
371
|
+
unitId,
|
|
372
|
+
subUnitId: sheetId,
|
|
373
|
+
row,
|
|
374
|
+
col
|
|
375
|
+
}, {
|
|
376
|
+
componentKey: SHEET_NOTE_COMPONENT,
|
|
377
|
+
direction: "horizontal",
|
|
378
|
+
extraProps: { location: {
|
|
379
|
+
unitId,
|
|
380
|
+
subUnitId: sheetId,
|
|
381
|
+
row,
|
|
382
|
+
col
|
|
383
|
+
} },
|
|
384
|
+
priority: 3
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
dispose() {
|
|
388
|
+
super.dispose();
|
|
389
|
+
this._noteMatrix.forValue((_, __, disposable) => {
|
|
390
|
+
disposable.dispose();
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
_initSheet(targetUnitId, targetSheetId) {
|
|
394
|
+
var _this$_sheetsNoteMode;
|
|
395
|
+
this._noteMatrix.forValue((_, __, disposable) => {
|
|
396
|
+
disposable.dispose();
|
|
397
|
+
});
|
|
398
|
+
this._noteMatrix = new _univerjs_core.ObjectMatrix();
|
|
399
|
+
const handleNote = (unitId, sheetId, row, col, note) => {
|
|
400
|
+
const matrix = this._noteMatrix;
|
|
401
|
+
const disposable = matrix.getValue(row, col);
|
|
402
|
+
if (note === null || note === void 0 ? void 0 : note.show) {
|
|
403
|
+
if (!disposable) {
|
|
404
|
+
const newDisposable = this._showPopup(unitId, sheetId, row, col);
|
|
405
|
+
if (newDisposable) matrix.setValue(row, col, newDisposable);
|
|
406
|
+
}
|
|
407
|
+
} else if (disposable) {
|
|
408
|
+
disposable.dispose();
|
|
409
|
+
matrix.realDeleteValue(row, col);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
(_this$_sheetsNoteMode = this._sheetsNoteModel.getSheetNotes(targetUnitId, targetSheetId)) === null || _this$_sheetsNoteMode === void 0 || _this$_sheetsNoteMode.forEach((note) => {
|
|
413
|
+
handleNote(targetUnitId, targetSheetId, note.row, note.col, note);
|
|
414
|
+
});
|
|
415
|
+
return this._sheetsNoteModel.change$.subscribe((change) => {
|
|
416
|
+
if (change.unitId !== targetUnitId || change.subUnitId !== targetSheetId) return;
|
|
417
|
+
switch (change.type) {
|
|
418
|
+
case "ref": {
|
|
419
|
+
const { unitId, subUnitId, oldNote, newNote } = change;
|
|
420
|
+
if (!newNote.show) return;
|
|
421
|
+
const matrix = this._noteMatrix;
|
|
422
|
+
const { row: oldRow, col: oldCol } = oldNote;
|
|
423
|
+
const { row: newRow, col: newCol } = newNote;
|
|
424
|
+
const disposable = matrix.getValue(oldRow, oldCol);
|
|
425
|
+
if (disposable) {
|
|
426
|
+
disposable.dispose();
|
|
427
|
+
matrix.realDeleteValue(oldRow, oldCol);
|
|
428
|
+
}
|
|
429
|
+
const newDisposable = this._showPopup(unitId, subUnitId, newRow, newCol);
|
|
430
|
+
if (newDisposable) matrix.setValue(newRow, newCol, newDisposable);
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
case "update": {
|
|
434
|
+
const { unitId, subUnitId, oldNote, newNote } = change;
|
|
435
|
+
handleNote(unitId, subUnitId, newNote ? newNote.row : oldNote.row, newNote ? newNote.col : oldNote.col, newNote);
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
default: break;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
_initNoteChangeListener() {
|
|
443
|
+
this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => {
|
|
444
|
+
var _workbook$activeSheet;
|
|
445
|
+
return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
|
|
446
|
+
})).subscribe((sheet) => {
|
|
447
|
+
if (sheet) {
|
|
448
|
+
const disposable = this._initSheet(sheet.getUnitId(), sheet.getSheetId());
|
|
449
|
+
return () => {
|
|
450
|
+
disposable.unsubscribe();
|
|
451
|
+
};
|
|
452
|
+
} else {
|
|
453
|
+
this._noteMatrix.forValue((_, __, disposable) => {
|
|
454
|
+
disposable.dispose();
|
|
455
|
+
});
|
|
456
|
+
this._noteMatrix = new _univerjs_core.ObjectMatrix();
|
|
457
|
+
}
|
|
458
|
+
}));
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
SheetsNoteAttachmentController = __decorate([
|
|
462
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_note.SheetsNoteModel)),
|
|
463
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
|
|
464
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellPopupManagerService)),
|
|
465
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(SheetsNotePopupService))
|
|
466
|
+
], SheetsNoteAttachmentController);
|
|
467
|
+
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/commands/operations/add-note-popup.operation.ts
|
|
470
|
+
const AddNotePopupOperation = {
|
|
471
|
+
id: "sheet.operation.add-note-popup",
|
|
472
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
473
|
+
handler: async (accessor, params) => {
|
|
474
|
+
var _params$trigger;
|
|
475
|
+
const selectionService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
476
|
+
const notePopupService = accessor.get(SheetsNotePopupService);
|
|
477
|
+
const workbook = accessor.get(_univerjs_core.IUniverInstanceService).getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
478
|
+
if (!workbook) return false;
|
|
479
|
+
const worksheet = workbook.getActiveSheet();
|
|
480
|
+
const lastSelection = selectionService.getCurrentLastSelection();
|
|
481
|
+
if (!(lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.primary)) return false;
|
|
482
|
+
const { primary } = lastSelection;
|
|
483
|
+
notePopupService.showPopup({
|
|
484
|
+
unitId: workbook.getUnitId(),
|
|
485
|
+
subUnitId: worksheet.getSheetId(),
|
|
486
|
+
row: primary.actualRow,
|
|
487
|
+
col: primary.actualColumn,
|
|
488
|
+
temp: false,
|
|
489
|
+
trigger: (_params$trigger = params === null || params === void 0 ? void 0 : params.trigger) !== null && _params$trigger !== void 0 ? _params$trigger : "add-note"
|
|
490
|
+
});
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/menu/note.menu.ts
|
|
497
|
+
function getHasNote$(accessor) {
|
|
498
|
+
const sheetsSelectionsService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
499
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
500
|
+
return sheetsSelectionsService.selectionMoveEnd$.pipe((0, rxjs.map)(() => {
|
|
501
|
+
const selection = sheetsSelectionsService.getCurrentLastSelection();
|
|
502
|
+
if (!(selection === null || selection === void 0 ? void 0 : selection.primary)) return false;
|
|
503
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
|
|
504
|
+
if (!target) return false;
|
|
505
|
+
const { actualColumn, actualRow } = selection.primary;
|
|
506
|
+
const noteModel = accessor.get(_univerjs_sheets_note.SheetsNoteModel);
|
|
507
|
+
return Boolean(noteModel.getNote(target.unitId, target.subUnitId, {
|
|
508
|
+
row: actualRow,
|
|
509
|
+
col: actualColumn
|
|
510
|
+
}));
|
|
511
|
+
}));
|
|
512
|
+
}
|
|
513
|
+
function sheetNoteContextMenuFactory(accessor) {
|
|
514
|
+
return {
|
|
515
|
+
id: AddNotePopupOperation.id,
|
|
516
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
517
|
+
title: "sheets-note-ui.rightClick.addNote",
|
|
518
|
+
icon: "AddNoteIcon",
|
|
519
|
+
hidden$: (0, rxjs.combineLatest)([(0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET), getHasNote$(accessor)]).pipe((0, rxjs.map)(([hidden, hasNote]) => hidden || hasNote)),
|
|
520
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
521
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
522
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
|
|
523
|
+
}),
|
|
524
|
+
commandId: AddNotePopupOperation.id
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function sheetDeleteNoteMenuFactory(accessor) {
|
|
528
|
+
return {
|
|
529
|
+
id: _univerjs_sheets_note.SheetDeleteNoteCommand.id,
|
|
530
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
531
|
+
title: "sheets-note-ui.rightClick.deleteNote",
|
|
532
|
+
icon: "DeleteNoteIcon",
|
|
533
|
+
hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote)),
|
|
534
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
535
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
536
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission]
|
|
537
|
+
})
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function sheetNoteToggleMenuFactory(accessor) {
|
|
541
|
+
return {
|
|
542
|
+
id: _univerjs_sheets_note.SheetToggleNotePopupCommand.id,
|
|
543
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
544
|
+
title: "sheets-note-ui.rightClick.toggleNote",
|
|
545
|
+
icon: "HideNoteIcon",
|
|
546
|
+
hidden$: getHasNote$(accessor).pipe((0, rxjs.map)((hasNote) => !hasNote))
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/menu/schema.ts
|
|
552
|
+
const menuSchema = { [_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
|
|
553
|
+
order: 0,
|
|
554
|
+
[AddNotePopupOperation.id]: {
|
|
555
|
+
order: 0,
|
|
556
|
+
menuItemFactory: sheetNoteContextMenuFactory
|
|
557
|
+
},
|
|
558
|
+
[_univerjs_sheets_note.SheetDeleteNoteCommand.id]: {
|
|
559
|
+
order: 0,
|
|
560
|
+
menuItemFactory: sheetDeleteNoteMenuFactory
|
|
561
|
+
},
|
|
562
|
+
[_univerjs_sheets_note.SheetToggleNotePopupCommand.id]: {
|
|
563
|
+
order: 0,
|
|
564
|
+
menuItemFactory: sheetNoteToggleMenuFactory
|
|
565
|
+
}
|
|
566
|
+
} } };
|
|
567
|
+
|
|
568
|
+
//#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
|
|
676
|
+
/**
|
|
677
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
678
|
+
*
|
|
679
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
680
|
+
* you may not use this file except in compliance with the License.
|
|
681
|
+
* You may obtain a copy of the License at
|
|
682
|
+
*
|
|
683
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
684
|
+
*
|
|
685
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
686
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
687
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
688
|
+
* See the License for the specific language governing permissions and
|
|
689
|
+
* limitations under the License.
|
|
690
|
+
*/
|
|
691
|
+
let SheetsNoteUIController = class SheetsNoteUIController extends _univerjs_core.Disposable {
|
|
692
|
+
constructor(_componentManager, _menuManagerService, _commandService) {
|
|
693
|
+
super();
|
|
694
|
+
this._componentManager = _componentManager;
|
|
695
|
+
this._menuManagerService = _menuManagerService;
|
|
696
|
+
this._commandService = _commandService;
|
|
697
|
+
this._initComponents();
|
|
698
|
+
this._initMenu();
|
|
699
|
+
this._initCommands();
|
|
700
|
+
}
|
|
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
|
+
_initMenu() {
|
|
712
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
713
|
+
}
|
|
714
|
+
_initCommands() {
|
|
715
|
+
this._commandService.registerCommand(AddNotePopupOperation);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
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);
|
|
723
|
+
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region src/plugin.ts
|
|
726
|
+
let UniverSheetsNoteUIPlugin = class UniverSheetsNoteUIPlugin extends _univerjs_core.Plugin {
|
|
727
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
728
|
+
super();
|
|
729
|
+
this._config = _config;
|
|
730
|
+
this._injector = _injector;
|
|
731
|
+
this._configService = _configService;
|
|
732
|
+
const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
733
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
734
|
+
this._configService.setConfig(SHEETS_NOTE_UI_PLUGIN_CONFIG_KEY, rest);
|
|
735
|
+
}
|
|
736
|
+
onStarting() {
|
|
737
|
+
[
|
|
738
|
+
[SheetsNotePopupService],
|
|
739
|
+
[SheetsCellContentController],
|
|
740
|
+
[SheetsNotePopupController],
|
|
741
|
+
[SheetsNoteUIController],
|
|
742
|
+
[SheetsNoteAttachmentController]
|
|
743
|
+
].forEach((dependency) => {
|
|
744
|
+
this._injector.add(dependency);
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
onReady() {
|
|
748
|
+
(0, _univerjs_core.touchDependencies)(this._injector, [[SheetsNoteUIController], [SheetsCellContentController]]);
|
|
749
|
+
}
|
|
750
|
+
onRendered() {
|
|
751
|
+
(0, _univerjs_core.touchDependencies)(this._injector, [[SheetsNotePopupController], [SheetsNoteAttachmentController]]);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
_defineProperty(UniverSheetsNoteUIPlugin, "pluginName", "SHEET_NOTE_UI_PLUGIN");
|
|
755
|
+
_defineProperty(UniverSheetsNoteUIPlugin, "packageName", name);
|
|
756
|
+
_defineProperty(UniverSheetsNoteUIPlugin, "version", version);
|
|
757
|
+
_defineProperty(UniverSheetsNoteUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
758
|
+
UniverSheetsNoteUIPlugin = __decorate([
|
|
759
|
+
(0, _univerjs_core.DependentOn)(_univerjs_sheets_note.UniverSheetsNotePlugin),
|
|
760
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
761
|
+
__decorateParam(2, _univerjs_core.IConfigService)
|
|
762
|
+
], UniverSheetsNoteUIPlugin);
|
|
763
|
+
|
|
764
|
+
//#endregion
|
|
765
|
+
Object.defineProperty(exports, 'SheetsCellContentController', {
|
|
766
|
+
enumerable: true,
|
|
767
|
+
get: function () {
|
|
768
|
+
return SheetsCellContentController;
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
exports.SheetsNote = SheetsNote;
|
|
772
|
+
Object.defineProperty(exports, 'SheetsNotePopupController', {
|
|
773
|
+
enumerable: true,
|
|
774
|
+
get: function () {
|
|
775
|
+
return SheetsNotePopupController;
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
Object.defineProperty(exports, 'SheetsNotePopupService', {
|
|
779
|
+
enumerable: true,
|
|
780
|
+
get: function () {
|
|
781
|
+
return SheetsNotePopupService;
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
Object.defineProperty(exports, 'UniverSheetsNoteUIPlugin', {
|
|
785
|
+
enumerable: true,
|
|
786
|
+
get: function () {
|
|
787
|
+
return UniverSheetsNoteUIPlugin;
|
|
788
|
+
}
|
|
789
|
+
});
|