@univerjs/sheets-ui
Version:
Spreadsheet UI layer for Univer Sheets.
1,238 lines (1,230 loc) • 54.3 kB
JavaScript
import { CanceledError, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DisposableCollection, ICommandService, ILogService, IPermissionService, IUniverInstanceService, InterceptorEffectEnum, LifecycleService, LifecycleStages, RichTextValue, UniverInstanceType, awaitTime, generateRandomId, toDisposable } from "@univerjs/core";
import { FEnum, FEventName, FUniver } from "@univerjs/core/facade";
import { RichTextEditingMutation } from "@univerjs/docs";
import { DeviceInputEventType, IRenderManagerService, SHEET_VIEWPORT_KEY } from "@univerjs/engine-render";
import { COMMAND_LISTENER_SKELETON_CHANGE, INTERCEPTOR_POINT, InterceptCellContentPriority, SetWorksheetRowIsAutoHeightCommand, SheetInterceptorService, SheetsSelectionsService, getSkeletonChangedEffectedRange } from "@univerjs/sheets";
import { CellAlertManagerService, DragManagerService, HoverManagerService, IEditorBridgeService, IMarkSelectionService, ISheetCellDropdownManagerService, ISheetClipboardService, ISheetSelectionRenderService, SHEET_VIEW_KEY, SetCellEditVisibleOperation, SetColumnHeaderHeightCommand, SetRowHeaderWidthCommand, SetWorksheetColAutoWidthCommand, SetZoomRatioCommand, SheetCanvasPopManagerService, SheetPasteShortKeyCommand, SheetPermissionRenderManagerService, SheetScrollManagerService, SheetSkeletonManagerService, SheetsScrollRenderController } from "@univerjs/sheets-ui";
import { FRange, FSheetHooks, FWorkbook, FWorkbookPermission, FWorksheet } from "@univerjs/sheets/facade";
import { ComponentManager, CopyCommand, CutCommand, HTML_CLIPBOARD_MIME_TYPE, IClipboardInterfaceService, IDialogService, ISidebarService, KeyCode, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, PasteCommand, supportClipboardAPI } from "@univerjs/ui";
import { combineLatest, filter } from "rxjs";
//#region src/facade/f-univer.ts
var FUniverSheetsUIMixin = class extends FUniver {
_initSheetUIEvent(injector) {
const commandService = injector.get(ICommandService);
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetEditStart, () => commandService.beforeCommandExecuted((commandInfo) => {
if (commandInfo.id !== SetCellEditVisibleOperation.id) return;
const target = this.getActiveSheet();
if (!target) return;
const { workbook, worksheet } = target;
const editorBridgeService = injector.get(IEditorBridgeService);
const { visible, keycode, eventType } = commandInfo.params;
const loc = editorBridgeService.getEditLocation();
if (!visible) return;
const eventParams = {
row: loc.row,
column: loc.column,
eventType,
keycode,
workbook,
worksheet,
isZenEditor: false
};
this.fireEvent(this.Event.BeforeSheetEditStart, eventParams);
if (eventParams.cancel) throw new CanceledError();
})));
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetEditEnd, () => commandService.beforeCommandExecuted((commandInfo) => {
if (commandInfo.id !== SetCellEditVisibleOperation.id) return;
const target = this.getActiveSheet();
if (!target) return;
const { workbook, worksheet } = target;
const editorBridgeService = injector.get(IEditorBridgeService);
const univerInstanceService = injector.get(IUniverInstanceService);
const { visible, keycode, eventType } = commandInfo.params;
const loc = editorBridgeService.getEditLocation();
if (visible) return;
const eventParams = {
row: loc.row,
column: loc.column,
eventType,
keycode,
workbook,
worksheet,
isZenEditor: false,
value: RichTextValue.create(univerInstanceService.getUnit(DOCS_NORMAL_EDITOR_UNIT_ID_KEY).getSnapshot()),
isConfirm: keycode !== KeyCode.ESC
};
this.fireEvent(this.Event.BeforeSheetEditEnd, eventParams);
if (eventParams.cancel) throw new CanceledError();
})));
this.disposeWithMe(this.registerEventHandler(this.Event.SheetEditStarted, () => commandService.onCommandExecuted((commandInfo) => {
if (commandInfo.id !== SetCellEditVisibleOperation.id) return;
const target = this.getCommandSheetTarget(commandInfo);
if (!target) return;
const { workbook, worksheet } = target;
const editorBridgeService = injector.get(IEditorBridgeService);
const { visible, keycode, eventType } = commandInfo.params;
const loc = editorBridgeService.getEditLocation();
if (!visible) return;
const eventParams = {
row: loc.row,
column: loc.column,
eventType,
keycode,
workbook,
worksheet,
isZenEditor: false
};
this.fireEvent(this.Event.SheetEditStarted, eventParams);
})));
this.disposeWithMe(this.registerEventHandler(this.Event.SheetEditEnded, () => commandService.onCommandExecuted((commandInfo) => {
if (commandInfo.id !== SetCellEditVisibleOperation.id) return;
const target = this.getCommandSheetTarget(commandInfo);
if (!target) return;
const { workbook, worksheet } = target;
const editorBridgeService = injector.get(IEditorBridgeService);
const { visible, keycode, eventType } = commandInfo.params;
const loc = editorBridgeService.getEditLocation();
if (visible) return;
const eventParams = {
row: loc.row,
column: loc.column,
eventType,
keycode,
workbook,
worksheet,
isZenEditor: false,
isConfirm: keycode !== KeyCode.ESC
};
this.fireEvent(this.Event.SheetEditEnded, eventParams);
})));
this.disposeWithMe(this.registerEventHandler(this.Event.SheetEditChanging, () => commandService.onCommandExecuted((commandInfo) => {
if (commandInfo.id !== RichTextEditingMutation.id) return;
const target = this.getActiveSheet();
if (!target) return;
const { workbook, worksheet } = target;
const editorBridgeService = injector.get(IEditorBridgeService);
const univerInstanceService = injector.get(IUniverInstanceService);
const params = commandInfo.params;
if (!editorBridgeService.isVisible().visible) return;
const { unitId } = params;
if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
const { row, column } = editorBridgeService.getEditLocation();
const eventParams = {
workbook,
worksheet,
row,
column,
value: RichTextValue.create(univerInstanceService.getUnit(DOCS_NORMAL_EDITOR_UNIT_ID_KEY).getSnapshot()),
isZenEditor: false
};
this.fireEvent(this.Event.SheetEditChanging, eventParams);
}
})));
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetZoomChange, () => commandService.beforeCommandExecuted((commandInfo) => {
if (commandInfo.id !== SetZoomRatioCommand.id) return;
const target = this.getCommandSheetTarget(commandInfo);
if (!target) return;
const { workbook, worksheet } = target;
const eventParams = {
zoom: commandInfo.params.zoomRatio,
workbook,
worksheet
};
this.fireEvent(this.Event.BeforeSheetZoomChange, eventParams);
if (eventParams.cancel) throw new CanceledError();
})));
this.disposeWithMe(this.registerEventHandler(this.Event.SheetZoomChanged, () => commandService.onCommandExecuted((commandInfo) => {
if (commandInfo.id !== SetZoomRatioCommand.id) return;
const target = this.getCommandSheetTarget(commandInfo);
if (!target) return;
const { workbook, worksheet } = target;
const eventParams = {
zoom: worksheet.getZoom(),
workbook,
worksheet
};
this.fireEvent(this.Event.SheetZoomChanged, eventParams);
})));
}
_initObserverListener(injector) {
const renderManagerService = injector.get(IRenderManagerService);
const lifeCycleService = injector.get(LifecycleService);
const lifecycle$Disposable = new DisposableCollection();
this.disposeWithMe(lifeCycleService.lifecycle$.subscribe((lifecycle) => {
if (lifecycle !== LifecycleStages.Rendered) return;
const hoverManagerService = injector.get(HoverManagerService);
const dragManagerService = injector.get(DragManagerService);
if (!hoverManagerService) return;
lifecycle$Disposable.dispose();
lifecycle$Disposable.add(this.registerEventHandler(this.Event.CellClicked, () => {
var _hoverManagerService$;
return (_hoverManagerService$ = hoverManagerService.currentClickedCell$) === null || _hoverManagerService$ === void 0 ? void 0 : _hoverManagerService$.pipe(filter((cell) => !!cell)).subscribe((cell) => {
const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
...cell,
row: cell.location.row,
column: cell.location.col
};
this.fireEvent(this.Event.CellClicked, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.CellHover, () => {
var _hoverManagerService$2;
return (_hoverManagerService$2 = hoverManagerService.currentRichText$) === null || _hoverManagerService$2 === void 0 ? void 0 : _hoverManagerService$2.pipe(filter((cell) => !!cell)).subscribe((cell) => {
const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
...cell,
row: cell.row,
column: cell.col
};
this.fireEvent(this.Event.CellHover, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.CellPointerDown, () => {
var _hoverManagerService$3;
return (_hoverManagerService$3 = hoverManagerService.currentPointerDownCell$) === null || _hoverManagerService$3 === void 0 ? void 0 : _hoverManagerService$3.pipe(filter((cell) => !!cell)).subscribe((cell) => {
const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
...cell,
row: cell.row,
column: cell.col
};
this.fireEvent(this.Event.CellPointerDown, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.CellPointerUp, () => {
var _hoverManagerService$4;
return (_hoverManagerService$4 = hoverManagerService.currentPointerUpCell$) === null || _hoverManagerService$4 === void 0 ? void 0 : _hoverManagerService$4.pipe(filter((cell) => !!cell)).subscribe((cell) => {
const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
...cell,
row: cell.row,
column: cell.col
};
this.fireEvent(this.Event.CellPointerUp, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.CellPointerMove, () => {
var _hoverManagerService$5;
return (_hoverManagerService$5 = hoverManagerService.currentCellPosWithEvent$) === null || _hoverManagerService$5 === void 0 ? void 0 : _hoverManagerService$5.pipe(filter((cell) => !!cell)).subscribe((cell) => {
const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
...cell,
row: cell.row,
column: cell.col
};
this.fireEvent(this.Event.CellPointerMove, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.DragOver, () => {
var _dragManagerService$c;
return (_dragManagerService$c = dragManagerService.currentCell$) === null || _dragManagerService$c === void 0 ? void 0 : _dragManagerService$c.pipe(filter((cell) => !!cell)).subscribe((cell) => {
const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
...cell,
row: cell.location.row,
column: cell.location.col
};
this.fireEvent(this.Event.DragOver, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.Drop, () => {
var _dragManagerService$e;
return (_dragManagerService$e = dragManagerService.endCell$) === null || _dragManagerService$e === void 0 ? void 0 : _dragManagerService$e.pipe(filter((cell) => !!cell)).subscribe((cell) => {
const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
...cell,
row: cell.location.row,
column: cell.location.col
};
this.fireEvent(this.Event.Drop, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.RowHeaderClick, () => {
var _hoverManagerService$6;
return (_hoverManagerService$6 = hoverManagerService.currentRowHeaderClick$) === null || _hoverManagerService$6 === void 0 ? void 0 : _hoverManagerService$6.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
row: header.index
};
this.fireEvent(this.Event.RowHeaderClick, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.RowHeaderPointerDown, () => {
var _hoverManagerService$7;
return (_hoverManagerService$7 = hoverManagerService.currentRowHeaderPointerDown$) === null || _hoverManagerService$7 === void 0 ? void 0 : _hoverManagerService$7.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
row: header.index
};
this.fireEvent(this.Event.RowHeaderPointerDown, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.RowHeaderPointerUp, () => {
var _hoverManagerService$8;
return (_hoverManagerService$8 = hoverManagerService.currentRowHeaderPointerUp$) === null || _hoverManagerService$8 === void 0 ? void 0 : _hoverManagerService$8.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
row: header.index
};
this.fireEvent(this.Event.RowHeaderPointerUp, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.RowHeaderHover, () => {
var _hoverManagerService$9;
return (_hoverManagerService$9 = hoverManagerService.currentHoveredRowHeader$) === null || _hoverManagerService$9 === void 0 ? void 0 : _hoverManagerService$9.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
row: header.index
};
this.fireEvent(this.Event.RowHeaderHover, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.ColumnHeaderClick, () => {
var _hoverManagerService$10;
return (_hoverManagerService$10 = hoverManagerService.currentColHeaderClick$) === null || _hoverManagerService$10 === void 0 ? void 0 : _hoverManagerService$10.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
column: header.index
};
this.fireEvent(this.Event.ColumnHeaderClick, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.ColumnHeaderPointerDown, () => {
var _hoverManagerService$11;
return (_hoverManagerService$11 = hoverManagerService.currentColHeaderPointerDown$) === null || _hoverManagerService$11 === void 0 ? void 0 : _hoverManagerService$11.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
column: header.index
};
this.fireEvent(this.Event.ColumnHeaderPointerDown, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.ColumnHeaderPointerUp, () => {
var _hoverManagerService$12;
return (_hoverManagerService$12 = hoverManagerService.currentColHeaderPointerUp$) === null || _hoverManagerService$12 === void 0 ? void 0 : _hoverManagerService$12.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
column: header.index
};
this.fireEvent(this.Event.ColumnHeaderPointerUp, eventParams);
});
}));
lifecycle$Disposable.add(this.registerEventHandler(this.Event.ColumnHeaderHover, () => {
var _hoverManagerService$13;
return (_hoverManagerService$13 = hoverManagerService.currentHoveredColHeader$) === null || _hoverManagerService$13 === void 0 ? void 0 : _hoverManagerService$13.pipe(filter((header) => !!header)).subscribe((header) => {
const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);
if (!baseParams) return;
const eventParams = {
...baseParams,
column: header.index
};
this.fireEvent(this.Event.ColumnHeaderHover, eventParams);
});
}));
this.disposeWithMe(lifecycle$Disposable);
}));
let sheetRenderUnit;
const combined$ = combineLatest([renderManagerService.created$, lifeCycleService.lifecycle$]);
const combined$Disposable = new DisposableCollection();
this.disposeWithMe(combined$.subscribe(([created, lifecycle]) => {
if (created.type === UniverInstanceType.UNIVER_SHEET) sheetRenderUnit = created;
if (lifecycle <= LifecycleStages.Rendered) return;
if (!sheetRenderUnit) return;
const workbook = this.getWorkbook(sheetRenderUnit.unitId);
if (!workbook) return;
combined$Disposable.dispose();
const scrollManagerService = sheetRenderUnit.with(SheetScrollManagerService);
const selectionService = sheetRenderUnit.with(SheetsSelectionsService);
combined$Disposable.add(this.registerEventHandler(this.Event.Scroll, () => scrollManagerService.validViewportScrollInfo$.subscribe((params) => {
if (!params) return;
const eventParams = {
workbook,
worksheet: workbook.getActiveSheet(),
...params
};
this.fireEvent(this.Event.Scroll, eventParams);
})));
combined$Disposable.add(this.registerEventHandler(this.Event.SelectionMoveStart, () => selectionService.selectionMoveStart$.subscribe((selections) => {
var _selections$map;
const eventParams = {
workbook,
worksheet: workbook.getActiveSheet(),
selections: (_selections$map = selections === null || selections === void 0 ? void 0 : selections.map((s) => s.range)) !== null && _selections$map !== void 0 ? _selections$map : []
};
this.fireEvent(this.Event.SelectionMoveStart, eventParams);
})));
combined$Disposable.add(this.registerEventHandler(this.Event.SelectionMoving, () => selectionService.selectionMoving$.subscribe((selections) => {
var _selections$map2;
const eventParams = {
workbook,
worksheet: workbook.getActiveSheet(),
selections: (_selections$map2 = selections === null || selections === void 0 ? void 0 : selections.map((s) => s.range)) !== null && _selections$map2 !== void 0 ? _selections$map2 : []
};
this.fireEvent(this.Event.SelectionMoving, eventParams);
})));
combined$Disposable.add(this.registerEventHandler(this.Event.SelectionMoveEnd, () => selectionService.selectionMoveEnd$.subscribe((selections) => {
var _selections$map3;
const eventParams = {
workbook,
worksheet: workbook.getActiveSheet(),
selections: (_selections$map3 = selections === null || selections === void 0 ? void 0 : selections.map((s) => s.range)) !== null && _selections$map3 !== void 0 ? _selections$map3 : []
};
this.fireEvent(this.Event.SelectionMoveEnd, eventParams);
})));
combined$Disposable.add(this.registerEventHandler(this.Event.SelectionChanged, () => selectionService.selectionChanged$.subscribe((selections) => {
var _selections$map4;
const eventParams = {
workbook,
worksheet: workbook.getActiveSheet(),
selections: (_selections$map4 = selections === null || selections === void 0 ? void 0 : selections.map((s) => s.range)) !== null && _selections$map4 !== void 0 ? _selections$map4 : []
};
this.fireEvent(this.Event.SelectionChanged, eventParams);
})));
sheetRenderUnit = null;
this.disposeWithMe(combined$Disposable);
}));
}
/**
* @ignore
*/
_initialize(injector) {
this._initSheetUIEvent(injector);
this._initObserverListener(injector);
const commandService = injector.get(ICommandService);
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeClipboardChange, () => commandService.beforeCommandExecuted((commandInfo) => {
switch (commandInfo.id) {
case CopyCommand.id:
case CutCommand.id:
this._beforeClipboardChange();
break;
}
})));
this.disposeWithMe(this.registerEventHandler(this.Event.ClipboardChanged, () => commandService.onCommandExecuted((commandInfo) => {
switch (commandInfo.id) {
case CopyCommand.id:
case CutCommand.id:
this._clipboardChanged();
break;
}
})));
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeClipboardPaste, () => commandService.beforeCommandExecuted((commandInfo) => {
switch (commandInfo.id) {
case SheetPasteShortKeyCommand.id:
this._beforeClipboardPaste(commandInfo.params);
break;
case PasteCommand.id:
this._beforeClipboardPasteAsync();
break;
}
})));
this.disposeWithMe(this.registerEventHandler(this.Event.ClipboardPasted, () => commandService.onCommandExecuted((commandInfo) => {
switch (commandInfo.id) {
case SheetPasteShortKeyCommand.id:
this._clipboardPaste(commandInfo.params);
break;
case PasteCommand.id:
this._clipboardPasteAsync();
break;
}
})));
this.disposeWithMe(this.registerEventHandler(this.Event.SheetSkeletonChanged, () => commandService.onCommandExecuted((commandInfo) => {
if (COMMAND_LISTENER_SKELETON_CHANGE.indexOf(commandInfo.id) > -1) {
const sheet = this.getActiveSheet();
if (!sheet) return;
const ranges = getSkeletonChangedEffectedRange(commandInfo, sheet.worksheet.getMaxColumns()).map((range) => {
var _this$getWorkbook;
return (_this$getWorkbook = this.getWorkbook(range.unitId)) === null || _this$getWorkbook === void 0 || (_this$getWorkbook = _this$getWorkbook.getSheetBySheetId(range.subUnitId)) === null || _this$getWorkbook === void 0 ? void 0 : _this$getWorkbook.getRange(range.range);
}).filter(Boolean);
if (!ranges.length) return;
const eventParams = {
workbook: sheet.workbook,
worksheet: sheet.worksheet,
payload: commandInfo,
skeleton: sheet.worksheet.getSkeleton(),
effectedRanges: ranges
};
this.fireEvent(this.Event.SheetSkeletonChanged, eventParams);
}
})));
}
_generateClipboardCopyParam() {
const workbook = this.getActiveWorkbook();
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
const range = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveRange();
if (!workbook || !worksheet || !range) return;
const content = this._injector.get(ISheetClipboardService).generateCopyContent(workbook.getId(), worksheet.getSheetId(), range.getRange());
if (!content) return;
const { html, plain } = content;
return {
workbook,
worksheet,
text: plain,
html,
fromSheet: worksheet,
fromRange: range
};
}
_beforeClipboardChange() {
const eventParams = this._generateClipboardCopyParam();
if (!eventParams) return;
this.fireEvent(this.Event.BeforeClipboardChange, eventParams);
if (eventParams.cancel) throw new CanceledError();
}
_clipboardChanged() {
const eventParams = this._generateClipboardCopyParam();
if (!eventParams) return;
this.fireEvent(this.Event.ClipboardChanged, eventParams);
}
_generateClipboardPasteParam(params) {
if (!params) return;
const { htmlContent, textContent } = params;
const workbook = this.getActiveWorkbook();
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
if (!workbook || !worksheet) return;
return {
workbook,
worksheet,
text: textContent,
html: htmlContent
};
}
async _generateClipboardPasteParamAsync() {
const workbook = this.getActiveWorkbook();
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getActiveSheet();
if (!workbook || !worksheet) return;
const item = (await this._injector.get(IClipboardInterfaceService).read())[0];
let eventParams;
if (item) {
const types = item.types;
eventParams = {
workbook,
worksheet,
text: types.indexOf(PLAIN_TEXT_CLIPBOARD_MIME_TYPE) !== -1 ? await item.getType(PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then((blob) => blob && blob.text()) : "",
html: types.indexOf(HTML_CLIPBOARD_MIME_TYPE) !== -1 ? await item.getType(HTML_CLIPBOARD_MIME_TYPE).then((blob) => blob && blob.text()) : ""
};
}
return eventParams;
}
_beforeClipboardPaste(params) {
const eventParams = this._generateClipboardPasteParam(params);
if (!eventParams) return;
this.fireEvent(this.Event.BeforeClipboardPaste, eventParams);
if (eventParams.cancel) throw new CanceledError();
}
_clipboardPaste(params) {
const eventParams = this._generateClipboardPasteParam(params);
if (!eventParams) return;
this.fireEvent(this.Event.ClipboardPasted, eventParams);
if (eventParams.cancel) throw new CanceledError();
}
async _beforeClipboardPasteAsync() {
if (!supportClipboardAPI()) {
this._injector.get(ILogService).warn("[Facade]: The navigator object only supports the browser environment");
return;
}
const eventParams = await this._generateClipboardPasteParamAsync();
if (!eventParams) return;
this.fireEvent(this.Event.BeforeClipboardPaste, eventParams);
if (eventParams.cancel) throw new CanceledError();
}
async _clipboardPasteAsync() {
if (!supportClipboardAPI()) {
this._injector.get(ILogService).warn("[Facade]: The navigator object only supports the browser environment");
return;
}
const eventParams = await this._generateClipboardPasteParamAsync();
if (!eventParams) return;
this.fireEvent(this.Event.ClipboardPasted, eventParams);
if (eventParams.cancel) throw new CanceledError();
}
customizeColumnHeader(cfg) {
var _cfg$headerStyle;
const wb = this.getActiveWorkbook();
if (!wb) {
console.error("WorkBook not exist");
return;
}
const unitId = wb === null || wb === void 0 ? void 0 : wb.getId();
const renderManagerService = this._injector.get(IRenderManagerService);
const activeSheet = wb.getActiveSheet();
const subUnitId = activeSheet.getSheetId();
const render = renderManagerService.getRenderById(unitId);
if (render && ((_cfg$headerStyle = cfg.headerStyle) === null || _cfg$headerStyle === void 0 ? void 0 : _cfg$headerStyle.size)) {
var _cfg$headerStyle2;
render.with(SheetSkeletonManagerService).setColumnHeaderSize(render, subUnitId, (_cfg$headerStyle2 = cfg.headerStyle) === null || _cfg$headerStyle2 === void 0 ? void 0 : _cfg$headerStyle2.size);
activeSheet === null || activeSheet === void 0 || activeSheet.refreshCanvas();
}
this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.COLUMN).setCustomHeader(cfg);
activeSheet === null || activeSheet === void 0 || activeSheet.refreshCanvas();
}
customizeRowHeader(cfg) {
const wb = this.getActiveWorkbook();
if (!wb) {
console.error("WorkBook not exist");
return;
}
const unitId = wb === null || wb === void 0 ? void 0 : wb.getId();
this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.ROW).setCustomHeader(cfg);
}
registerSheetRowHeaderExtension(unitId, ...extensions) {
const sheetComponent = this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.ROW);
const registerDisposable = sheetComponent.register(...extensions);
return toDisposable(() => {
registerDisposable.dispose();
sheetComponent.makeDirty(true);
});
}
registerSheetColumnHeaderExtension(unitId, ...extensions) {
const sheetComponent = this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.COLUMN);
const registerDisposable = sheetComponent.register(...extensions);
return toDisposable(() => {
registerDisposable.dispose();
sheetComponent.makeDirty(true);
});
}
registerSheetMainExtension(unitId, ...extensions) {
const sheetComponent = this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.MAIN);
const registerDisposable = sheetComponent.register(...extensions);
return toDisposable(() => {
registerDisposable.dispose();
sheetComponent.makeDirty(true);
});
}
/**
* Get sheet render component from render by unitId and view key.
* @private
* @param {string} unitId The unit id of the spreadsheet.
* @param {SHEET_VIEW_KEY} viewKey The view key of the spreadsheet.
* @returns {Nullable<RenderComponentType>} The render component.
*/
_getSheetRenderComponent(unitId, viewKey) {
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (!render) throw new Error(`Render Unit with unitId ${unitId} not found`);
const { components } = render;
const renderComponent = components.get(viewKey);
if (!renderComponent) throw new Error("Render component not found");
return renderComponent;
}
/**
* Get sheet hooks.
* @returns {FSheetHooks} FSheetHooks instance
*/
getSheetHooks() {
return this._injector.createInstance(FSheetHooks);
}
pasteIntoSheet(htmlContent, textContent, files) {
return this._commandService.executeCommand(SheetPasteShortKeyCommand.id, {
htmlContent,
textContent,
files
});
}
setProtectedRangeShadowStrategy(strategy) {
this._injector.get(SheetPermissionRenderManagerService).setProtectedRangeShadowStrategy(strategy);
}
getProtectedRangeShadowStrategy() {
return this._injector.get(SheetPermissionRenderManagerService).getProtectedRangeShadowStrategy();
}
getProtectedRangeShadowStrategy$() {
return this._injector.get(SheetPermissionRenderManagerService).getProtectedRangeShadowStrategy$();
}
setPermissionDialogVisible(visible) {
this._injector.get(IPermissionService).setShowComponents(visible);
}
};
FUniver.extend(FUniverSheetsUIMixin);
//#endregion
//#region src/facade/f-workbook.ts
var FWorkbookSheetsUIMixin = class extends FWorkbook {
openSiderbar(params) {
this._logDeprecation("openSiderbar");
return this._injector.get(ISidebarService).open(params);
}
openDialog(dialog) {
this._logDeprecation("openDialog");
const disposable = this._injector.get(IDialogService).open({
...dialog,
onClose: () => {
disposable.dispose();
}
});
return disposable;
}
customizeColumnHeader(cfg) {
const unitId = this._workbook.getUnitId();
this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.COLUMN).setCustomHeader(cfg);
}
customizeRowHeader(cfg) {
const unitId = this._workbook.getUnitId();
this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.ROW).setCustomHeader(cfg);
}
/**
* Get sheet render component from render by unitId and view key.
* @private
* @param {string} unitId The unit id of the spreadsheet.
* @param {SHEET_VIEW_KEY} viewKey The view key of the spreadsheet.
* @returns {Nullable<RenderComponentType>} The render component.
*/
_getSheetRenderComponent(unitId, viewKey) {
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (!render) throw new Error(`Render Unit with unitId ${unitId} not found`);
const { components } = render;
const renderComponent = components.get(viewKey);
if (!renderComponent) throw new Error("Render component not found");
return renderComponent;
}
_logDeprecation(name) {
this._injector.get(ILogService).warn("[FWorkbook]", `${name} is deprecated. Please use the function of the same name on "FUniver".`);
}
onCellClick(callback) {
return toDisposable(this._injector.get(HoverManagerService).currentClickedCell$.pipe(filter((cell) => !!cell)).subscribe((cell) => {
callback(cell);
}));
}
onCellHover(callback) {
return toDisposable(this._injector.get(HoverManagerService).currentRichText$.pipe(filter((cell) => !!cell)).subscribe(callback));
}
onCellPointerDown(callback) {
return toDisposable(this._injector.get(HoverManagerService).currentPointerDownCell$.subscribe(callback));
}
onCellPointerUp(callback) {
return toDisposable(this._injector.get(HoverManagerService).currentPointerUpCell$.subscribe(callback));
}
onCellPointerMove(callback) {
return toDisposable(this._injector.get(HoverManagerService).currentCellPosWithEvent$.pipe(filter((cell) => !!cell)).subscribe((cell) => {
callback(cell, cell.event);
}));
}
onDragOver(callback) {
return toDisposable(this._injector.get(DragManagerService).currentCell$.pipe(filter((cell) => !!cell)).subscribe((cell) => {
callback(cell);
}));
}
onDrop(callback) {
return toDisposable(this._injector.get(DragManagerService).endCell$.pipe(filter((cell) => !!cell)).subscribe((cell) => {
callback(cell);
}));
}
startEditing() {
const commandService = this._injector.get(ICommandService);
if (this._injector.get(IEditorBridgeService).isVisible().visible) return true;
return commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {
eventType: DeviceInputEventType.Dblclick,
unitId: this._workbook.getUnitId(),
visible: true
});
}
async endEditing(save) {
const commandService = this._injector.get(ICommandService);
if (this._injector.get(IEditorBridgeService).isVisible().visible) commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {
eventType: DeviceInputEventType.Keyboard,
keycode: save ? KeyCode.ENTER : KeyCode.ESC,
visible: false,
unitId: this._workbook.getUnitId()
});
await awaitTime(0);
return true;
}
endEditingAsync(save = true) {
return this.endEditing(save);
}
abortEditingAsync() {
return this.endEditingAsync(false);
}
isCellEditing() {
return this._injector.get(IEditorBridgeService).isVisible().visible;
}
/**
* Get scroll state of specified sheet.
* @param {string} sheetId - sheet id
* @returns {IScrollState} scroll state
* @example
* ``` ts
* univerAPI.getActiveWorkbook().getScrollStateBySheetId($sheetId)
* ```
*/
getScrollStateBySheetId(sheetId) {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (!render) return null;
return render.with(SheetScrollManagerService).getScrollStateByParam({
unitId,
sheetId
});
}
disableSelection() {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (render) render.with(ISheetSelectionRenderService).disableSelection();
return this;
}
enableSelection() {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (render) render.with(ISheetSelectionRenderService).enableSelection();
return this;
}
transparentSelection() {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (render) render.with(ISheetSelectionRenderService).transparentSelection();
return this;
}
showSelection() {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (render) render.with(ISheetSelectionRenderService).showSelection();
return this;
}
};
FWorkbook.extend(FWorkbookSheetsUIMixin);
//#endregion
//#region src/facade/f-worksheet.ts
var FWorksheetUIMixin = class extends FWorksheet {
refreshCanvas() {
const renderManagerService = this._injector.get(IRenderManagerService);
const unitId = this._fWorkbook.id;
const render = renderManagerService.getRenderById(unitId);
if (!render) throw new Error(`Render Unit with unitId ${unitId} not found`);
render.with(SheetSkeletonManagerService).reCalculate();
render.components.forEach((component) => {
var _component$makeDirty;
(_component$makeDirty = component.makeDirty) === null || _component$makeDirty === void 0 || _component$makeDirty.call(component);
});
return this;
}
highlightRanges(ranges, style, primary) {
const markSelectionService = this._injector.get(IMarkSelectionService);
const ids = [];
for (const range of ranges) {
const iRange = range.getRange();
const id = markSelectionService.addShapeWithNoFresh({
range: iRange,
style,
primary
});
if (id) ids.push(id);
}
markSelectionService.refreshShapes();
if (ids.length === 0) throw new Error("Failed to highlight current range");
return toDisposable(() => {
ids.forEach((id) => {
markSelectionService.removeShape(id);
});
});
}
zoom(zoomRatio) {
const commandService = this._injector.get(ICommandService);
const _zoomRatio = Math.min(Math.max(zoomRatio, .1), 4);
commandService.executeCommand(SetZoomRatioCommand.id, {
unitId: this._workbook.getUnitId(),
subUnitId: this._worksheet.getSheetId(),
zoomRatio: _zoomRatio
});
return this;
}
getZoom() {
return this._worksheet.getZoomRatio();
}
getVisibleRange() {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (!render) return null;
const sk = render.with(SheetSkeletonManagerService).getCurrentSkeleton();
if (!sk) return null;
return sk.getVisibleRangeByViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN);
}
getVisibleRangesOfAllViewports() {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (!render) return null;
const sk = render.with(SheetSkeletonManagerService).getCurrentSkeleton();
if (!sk) return null;
return sk.getVisibleRanges();
}
scrollToCell(row, column, duration) {
const unitId = this._workbook.getUnitId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (render) (render === null || render === void 0 ? void 0 : render.with(SheetsScrollRenderController)).scrollToCell(row, column, duration);
return this;
}
getScrollState() {
const emptyScrollState = {
offsetX: 0,
offsetY: 0,
sheetViewStartColumn: 0,
sheetViewStartRow: 0
};
const unitId = this._workbook.getUnitId();
const sheetId = this._worksheet.getSheetId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (!render) return emptyScrollState;
return render.with(SheetScrollManagerService).getScrollStateByParam({
unitId,
sheetId
}) || emptyScrollState;
}
onScroll(callback) {
var _renderManagerService;
const unitId = this._workbook.getUnitId();
const scrollManagerService = (_renderManagerService = this._injector.get(IRenderManagerService).getRenderById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(SheetScrollManagerService);
if (scrollManagerService) return toDisposable(scrollManagerService.validViewportScrollInfo$.subscribe((params) => {
callback(params);
}));
return toDisposable(() => {});
}
getSkeleton() {
var _this$_injector$get$g;
const service = (_this$_injector$get$g = this._injector.get(IRenderManagerService).getRenderById(this._workbook.getUnitId())) === null || _this$_injector$get$g === void 0 ? void 0 : _this$_injector$get$g.with(SheetSkeletonManagerService);
return service === null || service === void 0 ? void 0 : service.getSkeleton(this._worksheet.getSheetId());
}
autoResizeColumn(columnPosition) {
return this.autoResizeColumns(columnPosition, 1);
}
autoResizeColumns(startColumn, numColumns) {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
const ranges = [{
startColumn,
endColumn: startColumn + numColumns - 1,
startRow: 0,
endRow: this._worksheet.getRowCount() - 1
}];
this._commandService.syncExecuteCommand(SetWorksheetColAutoWidthCommand.id, {
unitId,
subUnitId,
ranges
});
return this;
}
setColumnAutoWidth(columnPosition, numColumn) {
return this.autoResizeColumns(columnPosition, numColumn);
}
autoResizeRows(startRow, numRows) {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
const ranges = [{
startRow,
endRow: startRow + numRows - 1,
startColumn: 0,
endColumn: this._worksheet.getColumnCount() - 1
}];
this._commandService.syncExecuteCommand(SetWorksheetRowIsAutoHeightCommand.id, {
unitId,
subUnitId,
ranges
});
return this;
}
customizeColumnHeader(cfg) {
var _cfg$headerStyle;
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (render && ((_cfg$headerStyle = cfg.headerStyle) === null || _cfg$headerStyle === void 0 ? void 0 : _cfg$headerStyle.size)) {
var _cfg$headerStyle2;
render.with(SheetSkeletonManagerService).setColumnHeaderSize(render, subUnitId, (_cfg$headerStyle2 = cfg.headerStyle) === null || _cfg$headerStyle2 === void 0 ? void 0 : _cfg$headerStyle2.size);
}
this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.COLUMN).setCustomHeader(cfg, subUnitId);
}
customizeRowHeader(cfg) {
var _cfg$headerStyle3;
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (render && ((_cfg$headerStyle3 = cfg.headerStyle) === null || _cfg$headerStyle3 === void 0 ? void 0 : _cfg$headerStyle3.size)) {
var _cfg$headerStyle4;
render.with(SheetSkeletonManagerService).setRowHeaderSize(render, subUnitId, (_cfg$headerStyle4 = cfg.headerStyle) === null || _cfg$headerStyle4 === void 0 ? void 0 : _cfg$headerStyle4.size);
}
this._getSheetRenderComponent(unitId, SHEET_VIEW_KEY.ROW).setCustomHeader(cfg, subUnitId);
}
setColumnHeaderHeight(height) {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
this._commandService.executeCommand(SetColumnHeaderHeightCommand.id, {
unitId,
subUnitId,
size: height
});
return this;
}
setRowHeaderWidth(width) {
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
this._commandService.executeCommand(SetRowHeaderWidthCommand.id, {
unitId,
subUnitId,
size: width
});
return this;
}
/**
* Get sheet render component from render by unitId and view key.
* @private
* @param {string} unitId The unit id of the spreadsheet.
* @param {SHEET_VIEW_KEY} viewKey The view key of the spreadsheet.
* @returns {Nullable<RenderComponentType>} The render component.
*/
_getSheetRenderComponent(unitId, viewKey) {
const render = this._injector.get(IRenderManagerService).getRenderById(unitId);
if (!render) throw new Error(`Render Unit with unitId ${unitId} not found`);
const { components } = render;
const renderComponent = components.get(viewKey);
if (!renderComponent) throw new Error("Render component not found");
return renderComponent;
}
};
FWorksheet.extend(FWorksheetUIMixin);
//#endregion
//#region src/facade/f-workbook-permission.ts
/**
* Copyright 2023-present DreamNum Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var FWorkbookPermissionSheetsUIMixin = class extends FWorkbookPermission {
setPermissionDialogVisible(visible) {
this._permissionService.setShowComponents(visible);
}
};
FWorkbookPermission.extend(FWorkbookPermissionSheetsUIMixin);
//#endregion
//#region src/facade/f-sheet-hooks.ts
var FSheetHooksUIMixin = class extends FSheetHooks {
onCellPointerMove(callback) {
return toDisposable(this._injector.get(HoverManagerService).currentPosition$.subscribe(callback));
}
onCellPointerOver(callback) {
return toDisposable(this._injector.get(HoverManagerService).currentCell$.subscribe(callback));
}
onCellDragOver(callback) {
return toDisposable(this._injector.get(DragManagerService).currentCell$.subscribe(callback));
}
onCellDrop(callback) {
return toDisposable(this._injector.get(DragManagerService).endCell$.subscribe(callback));
}
onCellRender(customRender, effect = InterceptorEffectEnum.Style, priority = InterceptCellContentPriority.DATA_VALIDATION) {
return this._injector.get(SheetInterceptorService).intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
effect,
handler: (cell, pos, next) => {
if (!cell) return next(cell);
if (!cell.customRender && customRender) cell.customRender = [...customRender];
return next(cell);
},
priority
});
}
onBeforeCellEdit(callback) {
return this._injector.get(ICommandService).beforeCommandExecuted((command) => {
const params = command.params;
if (command.id === SetCellEditVisibleOperation.id && params.visible) callback(params);
});
}
onAfterCellEdit(callback) {
return this._injector.get(ICommandService).onCommandExecuted((command) => {
const params = command.params;
if (command.id === SetCellEditVisibleOperation.id && !params.visible) callback(params);
});
}
};
FSheetHooks.extend(FSheetHooksUIMixin);
//#endregion
//#region src/facade/f-event.ts
var FSheetsUIEventNameMixin = class extends FEventName {
get BeforeClipboardChange() {
return "BeforeClipboardChange";
}
get ClipboardChanged() {
return "ClipboardChanged";
}
get BeforeClipboardPaste() {
return "BeforeClipboardPaste";
}
get ClipboardPasted() {
return "ClipboardPasted";
}
get BeforeSheetEditStart() {
return "BeforeSheetEditStart";
}
get SheetEditStarted() {
return "SheetEditStarted";
}
get SheetEditChanging() {
return "SheetEditChanging";
}
get BeforeSheetEditEnd() {
return "BeforeSheetEditEnd";
}
get SheetEditEnded() {
return "SheetEditEnded";
}
get CellClicked() {
return "CellClicked";
}
get CellHover() {
return "CellHover";
}
get CellPointerDown() {
return "CellPointerDown";
}
get CellPointerUp() {
return "CellPointerUp";
}
get CellPointerMove() {
return "CellPointerMove";
}
get DragOver() {
return "DragOver";
}
get Drop() {
return "Drop";
}
get Scroll() {
return "Scroll";
}
get SelectionMoveStart() {
return "SelectionMoveStart";
}
get SelectionChanged() {
return "SelectionChanged";
}
get SelectionMoving() {
return "SelectionMoving";
}
get SelectionMoveEnd() {
return "SelectionMoveEnd";
}
get RowHeaderClick() {
return "RowHeaderClick";
}
get RowHeaderPointerDown() {
return "RowHeaderPointerDown";
}
get RowHeaderPointerUp() {
return "RowHeaderPointerUp";
}
get RowHeaderHover() {
return "RowHeaderHover";
}
get ColumnHeaderClick() {
return "ColumnHeaderClick";
}
get ColumnHeaderPointerDown() {
return "ColumnHeaderPointerDown";
}
get ColumnHeaderPointerUp() {
return "ColumnHeaderPointerUp";
}
get ColumnHeaderHover() {
return "ColumnHeaderHover";
}
get SheetSkeletonChanged() {
return "SheetSkeletonChanged";
}
get BeforeSheetZoomChange() {
return "BeforeSheetZoomChange";
}
get SheetZoomChanged() {
return "SheetZoomChanged";
}
};
FEventName.extend(FSheetsUIEventNameMixin);
//#endregion
//#region src/facade/f-enum.ts
/**
* Copyright 2023-present DreamNum Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var FSheetsUIEnumMixin = class extends FEnum {
get SHEET_VIEWPORT_KEY() {
return SHEET_VIEWPORT_KEY;
}
};
FEnum.extend(FSheetsUIEnumMixin);
//#endregion
//#region src/facade/f-range.ts
var FRangeSheetsUIMixin = class extends FRange {
getCell() {
var _render$with$getSkele;
const renderManagerService = this._injector.get(IRenderManagerService);
const logService = this._injector.get(ILogService);
const unitId = this._workbook.getUnitId();
const subUnitId = this._worksheet.getSheetId();
const render = renderManagerService.getRenderById(unitId);
const skeleton = render === null || render === void 0 || (_render$with$getSkele = render.with(SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _render$with$getSkele === void 0 ? void 0 : _render$with$getSkele.skeleton;
if (!skeleton) {
logService.error("[Facade]: `FRange.getCell` can only be called in current worksheet");
throw new Error("`FRange.getCell` can only be called in current worksheet");
}
return skeleton.getCellWithCoordByIndex(this._range.startRow, this._range.startColumn);
}
getCellRect() {
const { startX: x, startY: y, endX: x2, endY: y2 } = this.getCell();
const data = {
x,
y,
width: x2 - x,
height: y2 - y,
top: y,
left: x,
bottom: y2,
right: x2
};
return {
...data,
toJSON: () => JSON.stringify(data)
};
}
generateHTML() {
var _copyContent$html;
const copyContent = this._injector.get(ISheetClipboardService).generateCopyContent(this._workbook.getUnitId(), this._