@univerjs/sheets-zen-editor 0.20.1 → 0.21.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/facade.js +160 -1
- package/lib/cjs/index.js +526 -1
- package/lib/cjs/locale/ca-ES.js +12 -1
- package/lib/cjs/locale/en-US.js +27 -1
- package/lib/cjs/locale/es-ES.js +12 -1
- package/lib/cjs/locale/fa-IR.js +12 -1
- package/lib/cjs/locale/fr-FR.js +12 -1
- package/lib/cjs/locale/ja-JP.js +12 -1
- package/lib/cjs/locale/ko-KR.js +12 -1
- package/lib/cjs/locale/ru-RU.js +12 -1
- package/lib/cjs/locale/sk-SK.js +12 -1
- package/lib/cjs/locale/vi-VN.js +12 -1
- package/lib/cjs/locale/zh-CN.js +12 -1
- package/lib/cjs/locale/zh-TW.js +12 -1
- package/lib/es/facade.js +161 -1
- package/lib/es/index.js +517 -1
- package/lib/es/locale/ca-ES.js +11 -1
- package/lib/es/locale/en-US.js +26 -1
- package/lib/es/locale/es-ES.js +11 -1
- package/lib/es/locale/fa-IR.js +11 -1
- package/lib/es/locale/fr-FR.js +11 -1
- package/lib/es/locale/ja-JP.js +11 -1
- package/lib/es/locale/ko-KR.js +11 -1
- package/lib/es/locale/ru-RU.js +11 -1
- package/lib/es/locale/sk-SK.js +11 -1
- package/lib/es/locale/vi-VN.js +11 -1
- package/lib/es/locale/zh-CN.js +11 -1
- package/lib/es/locale/zh-TW.js +11 -1
- package/lib/facade.js +161 -1
- package/lib/index.js +517 -1
- package/lib/locale/ca-ES.js +11 -1
- package/lib/locale/en-US.js +26 -1
- package/lib/locale/es-ES.js +11 -1
- package/lib/locale/fa-IR.js +11 -1
- package/lib/locale/fr-FR.js +11 -1
- package/lib/locale/ja-JP.js +11 -1
- package/lib/locale/ko-KR.js +11 -1
- package/lib/locale/ru-RU.js +11 -1
- package/lib/locale/sk-SK.js +11 -1
- package/lib/locale/vi-VN.js +11 -1
- package/lib/locale/zh-CN.js +11 -1
- package/lib/locale/zh-TW.js +11 -1
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
package/lib/es/index.js
CHANGED
|
@@ -1 +1,517 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CommandType, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_ZEN_EDITOR_UNIT_ID_KEY, Disposable, DocumentDataModel, DocumentFlavor, EDITOR_ACTIVATED, FOCUSING_DOC, FOCUSING_EDITOR_STANDALONE, FOCUSING_UNIVER_EDITOR, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, Plugin, RxDisposable, Tools, UniverInstanceType, createIdentifier, delayAnimationFrame, merge } from "@univerjs/core";
|
|
2
|
+
import { DocBackScrollRenderController, IEditorService, VIEWPORT_KEY } from "@univerjs/docs-ui";
|
|
3
|
+
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
4
|
+
import { EditingRenderController, IEditorBridgeService, getCurrentExclusiveRangeInterest$, getCurrentRangeDisable$, getEditorObject } from "@univerjs/sheets-ui";
|
|
5
|
+
import { ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IShortcutService, ISidebarService, IZenZoneService, KeyCode, MenuItemType, MetaKeys, useDependency } from "@univerjs/ui";
|
|
6
|
+
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from "@univerjs/sheets";
|
|
7
|
+
import { BehaviorSubject, map, switchMap, takeUntil } from "rxjs";
|
|
8
|
+
import { clsx } from "@univerjs/design";
|
|
9
|
+
import { CheckMarkIcon, CloseIcon } from "@univerjs/icons";
|
|
10
|
+
import { useEffect, useRef } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
|
|
13
|
+
//#region src/commands/commands/zen-editor.command.ts
|
|
14
|
+
const OpenZenEditorCommand = {
|
|
15
|
+
id: "zen-editor.command.open-zen-editor",
|
|
16
|
+
type: CommandType.COMMAND,
|
|
17
|
+
handler: async (accessor) => {
|
|
18
|
+
var _editCellState$docume;
|
|
19
|
+
const zenZoneService = accessor.get(IZenZoneService);
|
|
20
|
+
const editorService = accessor.get(IEditorService);
|
|
21
|
+
const editorBridgeService = accessor.get(IEditorBridgeService);
|
|
22
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
23
|
+
const sideBarService = accessor.get(ISidebarService);
|
|
24
|
+
if (sideBarService.visible) {
|
|
25
|
+
sideBarService.close();
|
|
26
|
+
await delayAnimationFrame();
|
|
27
|
+
}
|
|
28
|
+
zenZoneService.open();
|
|
29
|
+
const editor = editorService.getEditor(DOCS_ZEN_EDITOR_UNIT_ID_KEY);
|
|
30
|
+
if (editor == null) return false;
|
|
31
|
+
const editCellState = editorBridgeService.getLatestEditCellState();
|
|
32
|
+
if (editCellState == null) return false;
|
|
33
|
+
const snapshot = (_editCellState$docume = editCellState.documentLayoutObject.documentModel) === null || _editCellState$docume === void 0 ? void 0 : _editCellState$docume.getSnapshot();
|
|
34
|
+
if (snapshot == null) return false;
|
|
35
|
+
univerInstanceService.focusUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY);
|
|
36
|
+
const { body, drawings, drawingsOrder, tableSource, settings } = Tools.deepClone(snapshot);
|
|
37
|
+
const newSnapshot = {
|
|
38
|
+
...editor.getDocumentData(),
|
|
39
|
+
body,
|
|
40
|
+
drawings,
|
|
41
|
+
drawingsOrder,
|
|
42
|
+
tableSource,
|
|
43
|
+
settings
|
|
44
|
+
};
|
|
45
|
+
const textRanges = [{
|
|
46
|
+
startOffset: 0,
|
|
47
|
+
endOffset: 0,
|
|
48
|
+
collapsed: true
|
|
49
|
+
}];
|
|
50
|
+
editor.focus();
|
|
51
|
+
editor.setDocumentData(newSnapshot, textRanges);
|
|
52
|
+
editor.clearUndoRedoHistory();
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const CancelZenEditCommand = {
|
|
57
|
+
id: "zen-editor.command.cancel-zen-edit",
|
|
58
|
+
type: CommandType.COMMAND,
|
|
59
|
+
handler: async (accessor) => {
|
|
60
|
+
const zenZoneEditorService = accessor.get(IZenZoneService);
|
|
61
|
+
const editorBridgeService = accessor.get(IEditorBridgeService);
|
|
62
|
+
const univerInstanceManager = accessor.get(IUniverInstanceService);
|
|
63
|
+
const sideBarService = accessor.get(ISidebarService);
|
|
64
|
+
if (sideBarService.visible) {
|
|
65
|
+
sideBarService.close();
|
|
66
|
+
await delayAnimationFrame();
|
|
67
|
+
}
|
|
68
|
+
zenZoneEditorService.close();
|
|
69
|
+
const currentSheetInstance = univerInstanceManager.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
70
|
+
if (currentSheetInstance) {
|
|
71
|
+
univerInstanceManager.focusUnit(currentSheetInstance.getUnitId());
|
|
72
|
+
editorBridgeService.refreshEditCellState();
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const ConfirmZenEditCommand = {
|
|
79
|
+
id: "zen-editor.command.confirm-zen-edit",
|
|
80
|
+
type: CommandType.COMMAND,
|
|
81
|
+
handler: async (accessor) => {
|
|
82
|
+
const zenZoneEditorService = accessor.get(IZenZoneService);
|
|
83
|
+
const editorBridgeService = accessor.get(IEditorBridgeService);
|
|
84
|
+
const univerInstanceManager = accessor.get(IUniverInstanceService);
|
|
85
|
+
const editorService = accessor.get(IEditorService);
|
|
86
|
+
const sideBarService = accessor.get(ISidebarService);
|
|
87
|
+
if (sideBarService.visible) {
|
|
88
|
+
sideBarService.close();
|
|
89
|
+
await delayAnimationFrame();
|
|
90
|
+
}
|
|
91
|
+
zenZoneEditorService.close();
|
|
92
|
+
const editor = editorService.getEditor(DOCS_ZEN_EDITOR_UNIT_ID_KEY);
|
|
93
|
+
if (editor == null) return false;
|
|
94
|
+
const renderManagerService = accessor.get(IRenderManagerService);
|
|
95
|
+
const currentSheetInstance = univerInstanceManager.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
96
|
+
if (currentSheetInstance) {
|
|
97
|
+
var _renderManagerService;
|
|
98
|
+
const currentSheetId = currentSheetInstance.getUnitId();
|
|
99
|
+
const editingRenderController = (_renderManagerService = renderManagerService.getRenderById(currentSheetId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(EditingRenderController);
|
|
100
|
+
if (editingRenderController) {
|
|
101
|
+
const snapshot = Tools.deepClone(editor.getDocumentData());
|
|
102
|
+
snapshot.documentStyle.documentFlavor = DocumentFlavor.UNSPECIFIED;
|
|
103
|
+
editingRenderController.submitCellData(new DocumentDataModel(snapshot));
|
|
104
|
+
}
|
|
105
|
+
univerInstanceManager.focusUnit(currentSheetInstance.getUnitId());
|
|
106
|
+
editorBridgeService.refreshEditCellState();
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region package.json
|
|
115
|
+
var name = "@univerjs/sheets-zen-editor";
|
|
116
|
+
var version = "0.21.0";
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/config/config.ts
|
|
120
|
+
const SHEETS_ZEN_EDITOR_PLUGIN_CONFIG_KEY = "sheets-zen-editor.config";
|
|
121
|
+
const configSymbol = Symbol(SHEETS_ZEN_EDITOR_PLUGIN_CONFIG_KEY);
|
|
122
|
+
const defaultPluginConfig = {};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/menu/menu.ts
|
|
126
|
+
function ZenEditorMenuItemFactory(accessor) {
|
|
127
|
+
const editorBridgeService = accessor.get(IEditorBridgeService);
|
|
128
|
+
return {
|
|
129
|
+
id: OpenZenEditorCommand.id,
|
|
130
|
+
type: MenuItemType.BUTTON,
|
|
131
|
+
title: "rightClick.zenEditor",
|
|
132
|
+
icon: "AmplifyIcon",
|
|
133
|
+
hidden$: getCurrentExclusiveRangeInterest$(accessor),
|
|
134
|
+
disabled$: editorBridgeService.currentEditCell$.pipe(switchMap((cell) => getCurrentRangeDisable$(accessor, {
|
|
135
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
136
|
+
worksheetTypes: [
|
|
137
|
+
WorksheetEditPermission,
|
|
138
|
+
WorksheetSetCellValuePermission,
|
|
139
|
+
WorksheetSetCellStylePermission
|
|
140
|
+
],
|
|
141
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
142
|
+
}).pipe(map((disabled) => {
|
|
143
|
+
var _cell$documentLayoutO, _cell$documentLayoutO2;
|
|
144
|
+
return disabled || ((_cell$documentLayoutO = cell === null || cell === void 0 || (_cell$documentLayoutO2 = cell.documentLayoutObject.documentModel) === null || _cell$documentLayoutO2 === void 0 || (_cell$documentLayoutO2 = _cell$documentLayoutO2.getBody()) === null || _cell$documentLayoutO2 === void 0 || (_cell$documentLayoutO2 = _cell$documentLayoutO2.customBlocks) === null || _cell$documentLayoutO2 === void 0 ? void 0 : _cell$documentLayoutO2.length) !== null && _cell$documentLayoutO !== void 0 ? _cell$documentLayoutO : 0) > 0;
|
|
145
|
+
}))))
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/menu/schema.ts
|
|
151
|
+
const menuSchema = { [ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.OTHERS]: { [OpenZenEditorCommand.id]: {
|
|
152
|
+
order: 2,
|
|
153
|
+
menuItemFactory: ZenEditorMenuItemFactory
|
|
154
|
+
} } } };
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
158
|
+
function _typeof(o) {
|
|
159
|
+
"@babel/helpers - typeof";
|
|
160
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
161
|
+
return typeof o;
|
|
162
|
+
} : function(o) {
|
|
163
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
164
|
+
}, _typeof(o);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
169
|
+
function toPrimitive(t, r) {
|
|
170
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
171
|
+
var e = t[Symbol.toPrimitive];
|
|
172
|
+
if (void 0 !== e) {
|
|
173
|
+
var i = e.call(t, r || "default");
|
|
174
|
+
if ("object" != _typeof(i)) return i;
|
|
175
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
176
|
+
}
|
|
177
|
+
return ("string" === r ? String : Number)(t);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
182
|
+
function toPropertyKey(t) {
|
|
183
|
+
var i = toPrimitive(t, "string");
|
|
184
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
189
|
+
function _defineProperty(e, r, t) {
|
|
190
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
191
|
+
value: t,
|
|
192
|
+
enumerable: !0,
|
|
193
|
+
configurable: !0,
|
|
194
|
+
writable: !0
|
|
195
|
+
}) : e[r] = t, e;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/services/zen-editor.service.ts
|
|
200
|
+
var ZenEditorManagerService = class {
|
|
201
|
+
constructor() {
|
|
202
|
+
_defineProperty(this, "_position", null);
|
|
203
|
+
_defineProperty(this, "_position$", new BehaviorSubject(null));
|
|
204
|
+
_defineProperty(this, "position$", this._position$.asObservable());
|
|
205
|
+
}
|
|
206
|
+
dispose() {
|
|
207
|
+
this._position$.complete();
|
|
208
|
+
this._position = null;
|
|
209
|
+
}
|
|
210
|
+
setPosition(param) {
|
|
211
|
+
this._position = param;
|
|
212
|
+
this._refresh(param);
|
|
213
|
+
}
|
|
214
|
+
getPosition() {
|
|
215
|
+
return this._position;
|
|
216
|
+
}
|
|
217
|
+
_refresh(param) {
|
|
218
|
+
this._position$.next(param);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const IZenEditorManagerService = createIdentifier("univer.sheet-zen-editor-manager.service");
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/views/zen-editor/ZenEditor.tsx
|
|
225
|
+
const COMPONENT_PREFIX = "ZEN_EDITOR_PLUGIN_";
|
|
226
|
+
const ZEN_EDITOR_COMPONENT = `${COMPONENT_PREFIX}ZEN_EDITOR_COMPONENT`;
|
|
227
|
+
const INITIAL_SNAPSHOT = {
|
|
228
|
+
id: DOCS_ZEN_EDITOR_UNIT_ID_KEY,
|
|
229
|
+
body: {
|
|
230
|
+
dataStream: `${DEFAULT_EMPTY_DOCUMENT_VALUE}`,
|
|
231
|
+
textRuns: [],
|
|
232
|
+
tables: [],
|
|
233
|
+
customBlocks: [],
|
|
234
|
+
paragraphs: [{ startIndex: 0 }],
|
|
235
|
+
sectionBreaks: [{ startIndex: 1 }]
|
|
236
|
+
},
|
|
237
|
+
tableSource: {},
|
|
238
|
+
documentStyle: {
|
|
239
|
+
pageSize: {
|
|
240
|
+
width: 595,
|
|
241
|
+
height: Number.POSITIVE_INFINITY
|
|
242
|
+
},
|
|
243
|
+
documentFlavor: DocumentFlavor.MODERN,
|
|
244
|
+
marginTop: 0,
|
|
245
|
+
marginBottom: 0,
|
|
246
|
+
marginRight: 0,
|
|
247
|
+
marginLeft: 0,
|
|
248
|
+
renderConfig: {
|
|
249
|
+
vertexAngle: 0,
|
|
250
|
+
centerAngle: 0
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
drawings: {},
|
|
254
|
+
drawingsOrder: []
|
|
255
|
+
};
|
|
256
|
+
function ZenEditor() {
|
|
257
|
+
const editorRef = useRef(null);
|
|
258
|
+
const zenEditorService = useDependency(IZenEditorManagerService);
|
|
259
|
+
const editorService = useDependency(IEditorService);
|
|
260
|
+
const commandService = useDependency(ICommandService);
|
|
261
|
+
useEffect(() => {
|
|
262
|
+
const editorDom = editorRef.current;
|
|
263
|
+
if (!editorDom) return;
|
|
264
|
+
const registerSubscription = editorService.register({
|
|
265
|
+
editorUnitId: DOCS_ZEN_EDITOR_UNIT_ID_KEY,
|
|
266
|
+
initialSnapshot: INITIAL_SNAPSHOT,
|
|
267
|
+
scrollBar: true,
|
|
268
|
+
backScrollOffset: 100
|
|
269
|
+
}, editorDom);
|
|
270
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
271
|
+
zenEditorService.setPosition(editorDom.getBoundingClientRect());
|
|
272
|
+
});
|
|
273
|
+
resizeObserver.observe(editorDom);
|
|
274
|
+
return () => {
|
|
275
|
+
registerSubscription.dispose();
|
|
276
|
+
resizeObserver.unobserve(editorDom);
|
|
277
|
+
};
|
|
278
|
+
}, []);
|
|
279
|
+
function handleCloseBtnClick() {
|
|
280
|
+
const editor = editorService.getEditor(DOCS_ZEN_EDITOR_UNIT_ID_KEY);
|
|
281
|
+
editor === null || editor === void 0 || editor.blur();
|
|
282
|
+
commandService.executeCommand(CancelZenEditCommand.id);
|
|
283
|
+
}
|
|
284
|
+
function handleConfirmBtnClick() {
|
|
285
|
+
const editor = editorService.getEditor(DOCS_ZEN_EDITOR_UNIT_ID_KEY);
|
|
286
|
+
editor === null || editor === void 0 || editor.blur();
|
|
287
|
+
commandService.executeCommand(ConfirmZenEditCommand.id);
|
|
288
|
+
}
|
|
289
|
+
const containerClassName = "univer-flex univer-w-7 univer-cursor-pointer univer-items-center univer-justify-center univer-transition-colors";
|
|
290
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
291
|
+
className: "univer-absolute univer-inset-0 univer-size-full univer-bg-white dark:!univer-bg-gray-800",
|
|
292
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
293
|
+
className: "univer-absolute univer-right-6 univer-top-2 univer-z-10 univer-flex univer-items-center univer-justify-center",
|
|
294
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
295
|
+
className: clsx(containerClassName, "univer-text-red-500 hover:univer-text-red-600"),
|
|
296
|
+
onClick: handleCloseBtnClick,
|
|
297
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { className: "univer-size-5" })
|
|
298
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
299
|
+
className: clsx(containerClassName, "univer-text-green-500 hover:univer-text-green-600"),
|
|
300
|
+
onClick: handleConfirmBtnClick,
|
|
301
|
+
children: /* @__PURE__ */ jsx(CheckMarkIcon, { className: "univer-size-5" })
|
|
302
|
+
})]
|
|
303
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
304
|
+
ref: editorRef,
|
|
305
|
+
className: "univer-absolute univer-inset-0 univer-size-full"
|
|
306
|
+
})]
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/controllers/shortcuts/zen-editor.shortcut.ts
|
|
312
|
+
const ZenEditorConfirmShortcut = {
|
|
313
|
+
id: ConfirmZenEditCommand.id,
|
|
314
|
+
description: "shortcut.sheet.zen-edit-confirm",
|
|
315
|
+
group: "4_sheet-edit",
|
|
316
|
+
preconditions: (contextService) => whenZenEditorActivated(contextService),
|
|
317
|
+
binding: KeyCode.ENTER | MetaKeys.ALT
|
|
318
|
+
};
|
|
319
|
+
const ZenEditorCancelShortcut = {
|
|
320
|
+
id: CancelZenEditCommand.id,
|
|
321
|
+
description: "shortcut.sheet.zen-edit-cancel",
|
|
322
|
+
group: "4_sheet-edit",
|
|
323
|
+
preconditions: (contextService) => whenZenEditorActivated(contextService),
|
|
324
|
+
binding: KeyCode.ESC
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Requires the currently focused unit to be Doc and the zen editor is activated.
|
|
328
|
+
* @param contextService
|
|
329
|
+
* @returns
|
|
330
|
+
*/
|
|
331
|
+
function whenZenEditorActivated(contextService) {
|
|
332
|
+
return contextService.getContextValue(FOCUSING_DOC) && contextService.getContextValue(FOCUSING_UNIVER_EDITOR) && contextService.getContextValue(EDITOR_ACTIVATED) && !contextService.getContextValue(FOCUSING_EDITOR_STANDALONE);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
337
|
+
function __decorateParam(paramIndex, decorator) {
|
|
338
|
+
return function(target, key) {
|
|
339
|
+
decorator(target, key, paramIndex);
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
345
|
+
function __decorate(decorators, target, key, desc) {
|
|
346
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
347
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
348
|
+
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;
|
|
349
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/controllers/zen-editor-ui.controller.ts
|
|
354
|
+
/**
|
|
355
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
356
|
+
*
|
|
357
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
358
|
+
* you may not use this file except in compliance with the License.
|
|
359
|
+
* You may obtain a copy of the License at
|
|
360
|
+
*
|
|
361
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
362
|
+
*
|
|
363
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
364
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
365
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
366
|
+
* See the License for the specific language governing permissions and
|
|
367
|
+
* limitations under the License.
|
|
368
|
+
*/
|
|
369
|
+
let ZenEditorUIController = class ZenEditorUIController extends Disposable {
|
|
370
|
+
constructor(_zenZoneService, _commandService, _menuManagerService, _shortcutService) {
|
|
371
|
+
super();
|
|
372
|
+
this._zenZoneService = _zenZoneService;
|
|
373
|
+
this._commandService = _commandService;
|
|
374
|
+
this._menuManagerService = _menuManagerService;
|
|
375
|
+
this._shortcutService = _shortcutService;
|
|
376
|
+
this._initialize();
|
|
377
|
+
}
|
|
378
|
+
_initialize() {
|
|
379
|
+
this._initCustomComponents();
|
|
380
|
+
this._initCommands();
|
|
381
|
+
this._initMenus();
|
|
382
|
+
this._initShortcuts();
|
|
383
|
+
}
|
|
384
|
+
_initCustomComponents() {
|
|
385
|
+
this.disposeWithMe(this._zenZoneService.set(ZEN_EDITOR_COMPONENT, ZenEditor));
|
|
386
|
+
}
|
|
387
|
+
_initCommands() {
|
|
388
|
+
[
|
|
389
|
+
OpenZenEditorCommand,
|
|
390
|
+
CancelZenEditCommand,
|
|
391
|
+
ConfirmZenEditCommand
|
|
392
|
+
].forEach((c) => {
|
|
393
|
+
this.disposeWithMe(this._commandService.registerCommand(c));
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
_initMenus() {
|
|
397
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
398
|
+
}
|
|
399
|
+
_initShortcuts() {
|
|
400
|
+
[ZenEditorConfirmShortcut, ZenEditorCancelShortcut].forEach((item) => {
|
|
401
|
+
this.disposeWithMe(this._shortcutService.registerShortcut(item));
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
ZenEditorUIController = __decorate([
|
|
406
|
+
__decorateParam(0, IZenZoneService),
|
|
407
|
+
__decorateParam(1, ICommandService),
|
|
408
|
+
__decorateParam(2, IMenuManagerService),
|
|
409
|
+
__decorateParam(3, IShortcutService)
|
|
410
|
+
], ZenEditorUIController);
|
|
411
|
+
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/controllers/zen-editor.controller.ts
|
|
414
|
+
let ZenEditorController = class ZenEditorController extends RxDisposable {
|
|
415
|
+
constructor(_zenEditorManagerService, _renderManagerService) {
|
|
416
|
+
super();
|
|
417
|
+
this._zenEditorManagerService = _zenEditorManagerService;
|
|
418
|
+
this._renderManagerService = _renderManagerService;
|
|
419
|
+
this._initialize();
|
|
420
|
+
}
|
|
421
|
+
_initialize() {
|
|
422
|
+
this._syncZenEditorSize();
|
|
423
|
+
}
|
|
424
|
+
_syncZenEditorSize() {
|
|
425
|
+
this._zenEditorManagerService.position$.pipe(takeUntil(this.dispose$)).subscribe((position) => {
|
|
426
|
+
if (position == null) return;
|
|
427
|
+
const { width, height } = position;
|
|
428
|
+
const editorObject = getEditorObject(DOCS_ZEN_EDITOR_UNIT_ID_KEY, this._renderManagerService);
|
|
429
|
+
if (editorObject == null) return;
|
|
430
|
+
requestIdleCallback(() => {
|
|
431
|
+
editorObject.engine.resizeBySize(width, height);
|
|
432
|
+
this._calculatePagePosition(editorObject);
|
|
433
|
+
this._scrollToTop();
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
_calculatePagePosition(currentRender) {
|
|
438
|
+
const { document: docsComponent, scene, docBackground } = currentRender;
|
|
439
|
+
const parent = scene === null || scene === void 0 ? void 0 : scene.getParent();
|
|
440
|
+
const { width: docsWidth, height: docsHeight, pageMarginLeft, pageMarginTop } = docsComponent;
|
|
441
|
+
if (parent == null || docsWidth === Number.POSITIVE_INFINITY || docsHeight === Number.POSITIVE_INFINITY) return;
|
|
442
|
+
const { width: engineWidth, height: engineHeight } = parent;
|
|
443
|
+
let docsLeft = 0;
|
|
444
|
+
const docsTop = pageMarginTop;
|
|
445
|
+
let sceneWidth = 0;
|
|
446
|
+
let sceneHeight = 0;
|
|
447
|
+
let scrollToX = Number.POSITIVE_INFINITY;
|
|
448
|
+
const { scaleX, scaleY } = scene.getAncestorScale();
|
|
449
|
+
if (engineWidth > (docsWidth + pageMarginLeft * 2) * scaleX) {
|
|
450
|
+
docsLeft = engineWidth / 2 - docsWidth * scaleX / 2;
|
|
451
|
+
docsLeft /= scaleX;
|
|
452
|
+
sceneWidth = (engineWidth - pageMarginLeft * 2) / scaleX;
|
|
453
|
+
scrollToX = 0;
|
|
454
|
+
} else {
|
|
455
|
+
docsLeft = pageMarginLeft;
|
|
456
|
+
sceneWidth = docsWidth + pageMarginLeft * 2;
|
|
457
|
+
scrollToX = (sceneWidth - engineWidth / scaleX) / 2;
|
|
458
|
+
}
|
|
459
|
+
if (engineHeight > docsHeight) sceneHeight = (engineHeight - pageMarginTop * 2) / scaleY;
|
|
460
|
+
else sceneHeight = docsHeight + pageMarginTop * 2;
|
|
461
|
+
scene.resize(sceneWidth, sceneHeight);
|
|
462
|
+
docsComponent.translate(docsLeft, docsTop);
|
|
463
|
+
docBackground.translate(docsLeft, docsTop);
|
|
464
|
+
const viewport = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
|
|
465
|
+
if (scrollToX !== Number.POSITIVE_INFINITY && viewport != null) {
|
|
466
|
+
const actualX = viewport.transScroll2ViewportScrollValue(scrollToX, 0).x;
|
|
467
|
+
viewport.scrollToBarPos({ x: actualX });
|
|
468
|
+
}
|
|
469
|
+
return this;
|
|
470
|
+
}
|
|
471
|
+
_scrollToTop() {
|
|
472
|
+
var _this$_renderManagerS;
|
|
473
|
+
const backScrollController = (_this$_renderManagerS = this._renderManagerService.getRenderById(DOCS_ZEN_EDITOR_UNIT_ID_KEY)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.with(DocBackScrollRenderController);
|
|
474
|
+
const textRange = {
|
|
475
|
+
startOffset: 0,
|
|
476
|
+
endOffset: 0
|
|
477
|
+
};
|
|
478
|
+
if (backScrollController) backScrollController.scrollToRange(textRange);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
ZenEditorController = __decorate([__decorateParam(0, IZenEditorManagerService), __decorateParam(1, IRenderManagerService)], ZenEditorController);
|
|
482
|
+
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/plugin.ts
|
|
485
|
+
let UniverSheetsZenEditorPlugin = class UniverSheetsZenEditorPlugin extends Plugin {
|
|
486
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
487
|
+
super();
|
|
488
|
+
this._config = _config;
|
|
489
|
+
this._injector = _injector;
|
|
490
|
+
this._configService = _configService;
|
|
491
|
+
const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
492
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
493
|
+
this._configService.setConfig(SHEETS_ZEN_EDITOR_PLUGIN_CONFIG_KEY, rest);
|
|
494
|
+
this._initializeDependencies(this._injector);
|
|
495
|
+
}
|
|
496
|
+
_initializeDependencies(injector) {
|
|
497
|
+
[
|
|
498
|
+
[ZenEditorUIController],
|
|
499
|
+
[ZenEditorController],
|
|
500
|
+
[IZenEditorManagerService, { useClass: ZenEditorManagerService }]
|
|
501
|
+
].forEach((dependency) => injector.add(dependency));
|
|
502
|
+
}
|
|
503
|
+
onReady() {
|
|
504
|
+
this._injector.get(ZenEditorUIController);
|
|
505
|
+
}
|
|
506
|
+
onSteady() {
|
|
507
|
+
this._injector.get(ZenEditorController);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
_defineProperty(UniverSheetsZenEditorPlugin, "pluginName", "SHEET_ZEN_EDITOR_PLUGIN");
|
|
511
|
+
_defineProperty(UniverSheetsZenEditorPlugin, "packageName", name);
|
|
512
|
+
_defineProperty(UniverSheetsZenEditorPlugin, "version", version);
|
|
513
|
+
_defineProperty(UniverSheetsZenEditorPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
514
|
+
UniverSheetsZenEditorPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverSheetsZenEditorPlugin);
|
|
515
|
+
|
|
516
|
+
//#endregion
|
|
517
|
+
export { CancelZenEditCommand, ConfirmZenEditCommand, OpenZenEditorCommand, UniverSheetsZenEditorPlugin };
|
package/lib/es/locale/ca-ES.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/ca-ES.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "Editor a pantalla completa" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "Cancel·la edició Zen",
|
|
6
|
+
"zen-edit-confirm": "Confirma edició Zen"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|
package/lib/es/locale/en-US.js
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/en-US.ts
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
const locale = {
|
|
18
|
+
rightClick: { zenEditor: "Full Screen Editor" },
|
|
19
|
+
shortcut: { sheet: {
|
|
20
|
+
"zen-edit-cancel": "Cancel Zen Edit",
|
|
21
|
+
"zen-edit-confirm": "Confirm Zen Edit"
|
|
22
|
+
} }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { locale as default };
|
package/lib/es/locale/es-ES.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/es-ES.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "Editor a pantalla completa" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "Cancelar edición Zen",
|
|
6
|
+
"zen-edit-confirm": "Confirmar edición Zen"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|
package/lib/es/locale/fa-IR.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/fa-IR.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "ویرایشگر تمام صفحه" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "لغو ویرایش Zen",
|
|
6
|
+
"zen-edit-confirm": "تایید ویرایش Zen"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|
package/lib/es/locale/fr-FR.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/fr-FR.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "Éditeur plein écran" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "Annuler l'édition plein écran",
|
|
6
|
+
"zen-edit-confirm": "Confirmer l'édition plein écran"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|
package/lib/es/locale/ja-JP.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/ja-JP.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "禅モード" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "禅モードをキャンセル",
|
|
6
|
+
"zen-edit-confirm": "禅モードに移行"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|
package/lib/es/locale/ko-KR.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/ko-KR.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "젠 에디터" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "젠 편집 취소",
|
|
6
|
+
"zen-edit-confirm": "젠 편집 확인"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|
package/lib/es/locale/ru-RU.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/ru-RU.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "Редактор на весь экран" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "Отменить Zen редактирование",
|
|
6
|
+
"zen-edit-confirm": "Подтвердить Zen редактирование"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|
package/lib/es/locale/sk-SK.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/locale/sk-SK.ts
|
|
2
|
+
const locale = {
|
|
3
|
+
rightClick: { zenEditor: "Editor na celú obrazovku" },
|
|
4
|
+
shortcut: { sheet: {
|
|
5
|
+
"zen-edit-cancel": "Zrušiť zen úpravu",
|
|
6
|
+
"zen-edit-confirm": "Potvrdiť zen úpravu"
|
|
7
|
+
} }
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { locale as default };
|