Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
chore(base-sheets): cell editor controller
Dushusir77a37df80975
diff --git a/packages/base-sheets/src/Basics/RegisterAction.ts b/packages/base-sheets/src/Basics/RegisterAction.tsindex 2a3320c527..639cbee21a 100644--- a/packages/base-sheets/src/Basics/RegisterAction.ts+++ b/packages/base-sheets/src/Basics/RegisterAction.ts@@ -1,5 +1,4 @@import { CommandManager } from '@univerjs/core';import { SetSelectionValueAction } from '../Model/Action/SetSelectionValueAction';-import { ACTION_NAMES } from './Enum';-CommandManager.register(ACTION_NAMES.SET_SELECTION_VALUE_ACTION, SetSelectionValueAction);+CommandManager.register(SetSelectionValueAction.NAME, SetSelectionValueAction);diff --git a/packages/base-sheets/src/Controller/CellEditorController.ts b/packages/base-sheets/src/Controller/CellEditorController.tsindex 6ac8d742aa..c2adf73cc0 100644--- a/packages/base-sheets/src/Controller/CellEditorController.ts+++ b/packages/base-sheets/src/Controller/CellEditorController.ts@@ -1,5 +1,4 @@-import { handleJsonToDom } from '@univerjs/base-ui';-import { Direction, IDocumentData, IRangeData, IStyleData, Nullable, ICellData } from '@univerjs/core';+import { Direction, IDocumentData, IRangeData, IStyleData, Nullable, ICellData, handleJsonToDom } from '@univerjs/core';import { SheetPlugin } from '../SheetPlugin';/**@@ -8,9 +7,6 @@ import { SheetPlugin } from '../SheetPlugin';export class CellEditorController {private _plugin: SheetPlugin;- // Is it in editing state- isEditMode: boolean;-// current edit cellcurrentEditRangeData: IRangeData;diff --git a/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts b/packages/base-sheets/src/Model/Action/SetSelectionValueAction.tsindex 00498b1350..99342ed9ae 100644--- a/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts+++ b/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts@@ -1,4 +1,4 @@-import { SheetActionBase, ActionObservers, ActionType, ISheetActionData, ICellInfo, ISelection, Nullable, Workbook } from '@univerjs/core';+import { SheetActionBase, ActionObservers, ActionType, ISheetActionData, ICellInfo, ISelection, Nullable, CommandUnit } from '@univerjs/core';import { ACTION_NAMES } from '../../Basics';import { SetSelectionValue } from '../Apply/SetSelectionValue';@@ -12,8 +12,10 @@ export interface ISetSelectionValueActionData extends ISheetActionData {}export class SetSelectionValueAction extends SheetActionBase<ISetSelectionValueActionData, ISetSelectionValueActionData, ISelectionModelValue[]> {- constructor(actionData: ISetSelectionValueActionData, workbook: Workbook, observers: ActionObservers) {- super(actionData, workbook, observers);+ static NAME = 'SetSelectionValueAction';++ constructor(actionData: ISetSelectionValueActionData, commandUnit: CommandUnit, observers: ActionObservers) {+ super(actionData, commandUnit, observers);this._doActionData = {...actionData,diff --git a/packages/base-sheets/src/SheetPlugin.tsx b/packages/base-sheets/src/SheetPlugin.tsxindex ccc6e78949..3d8c1ca03a 100644--- a/packages/base-sheets/src/SheetPlugin.tsx+++ b/packages/base-sheets/src/SheetPlugin.tsx@@ -64,6 +64,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {zh,});+ this.initController();this.initCanvasView();this.registerExtension();@@ -73,9 +74,15 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {return this._config;}+ initController() {+ this._cellEditorController = new CellEditorController(this);+ }+initCanvasView() {const engine = this.getContext().getUniver().getGlobalContext().getPluginManager().getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;+ this._canvasEngine = engine;+if (this._canvasView == null) {this._canvasView = new CanvasView(engine, this);}diff --git a/packages/base-ui/src/Helpers/Cell.ts b/packages/base-ui/src/Helpers/Cell.tsindex f4679591bc..5a2ac1ec09 100644--- a/packages/base-ui/src/Helpers/Cell.ts+++ b/packages/base-ui/src/Helpers/Cell.ts@@ -1,21 +1,4 @@-import {- BaselineOffset,- BlockType,- BorderStyleTypes,- getColorStyle,- HorizontalAlign,- ICellData,- IDocumentData,- IElementsOrder,- IRangeData,- IStyleData,- ITextDecoration,- ParagraphElementType,- TextDirection,- Tools,- VerticalAlign,- WrapStrategy,-} from '@univerjs/core';+import { BlockType, ICellData, IDocumentData, IElementsOrder, IRangeData, IStyleData, ITextDecoration, Tools } from '@univerjs/core';import { nanoid } from 'nanoid';import { pxToPt } from '@univerjs/base-render';import { textTrim } from '../Utils';@@ -146,40 +129,6 @@ export function handleDomToJson($dom: HTMLElement): IDocumentData | string {return p;}-/**- * Convert rich text json to DOM- * @param p- */-export function handleJsonToDom(p: IDocumentData): string {- let span = '';- // let span = `<span id="${p.documentId}">`;- if (p.body?.blockElements) {- for (let k in p.body.blockElements) {- const section = p.body.blockElements[k];- if (section.blockType !== BlockType.PARAGRAPH && section.blockType !== BlockType.SECTION_BREAK) {- continue;- }- if (section.blockType === BlockType.PARAGRAPH) {- for (let i in section.paragraph) {- const element = section.paragraph[i];- for (let j in element) {- const item = element[j];- if (item.et === ParagraphElementType.TEXT_RUN) {- let style = `display:inline-block;${handleStyleToString(item.tr.ts)}`;- span += `<span id='${item.eId}' ${style.length ? `style="${style}"` : ''} >${item.tr.ct}</span>`;- }- }- }- }- // else if (section.blockType === BlockType.SECTION_BREAK) {- // span += '<br/>';- // }- }- }-- // span += '</span>';- return span;-}/*** A single span parses out the ITextStyle style sheet* @param $dom@@ -417,291 +366,6 @@ export function splitSpanText(text: string) {return arr1;}-/**- * transform style object to string- * @param style- * @returns- */-export function handleStyleToString(style: IStyleData, isCell: boolean = false) {- let str = '';- const styleMap = new Map([- [- 'ff',- () => {- if (style.ff) {- str += `font-family: ${style.ff}; `;- }- },- ],- [- 'fs',- () => {- if (style.fs) {- let fs = style.fs;-- // subscript / superscript, Font size for superscripts and subscripts is halved- if (style.va) {- fs /= 2;- }- str += `font-size: ${fs}pt; `;- }-- // const fs = isCss ? `${style.fs}px` : `${pxToPt(style.fs || 14)}pt`;- // str += `font-size: ${fs}; `;- },- ],- [- 'it',- () => {- if (style.it) {- str += `font-style: italic; `;- } else {- str += `font-style: normal; `;- }- },- ],- [- 'bl',- () => {- if (style.bl) {- str += `font-weight: bold; `;- } else {- str += `font-weight: normal; `;- }- },- ],- [- 'ul',- () => {- if (style.ul?.s) {- // If there are existing lines, add new lines- if (str.indexOf('text-decoration-line') > -1) {- str = str.replace(/(?<=text-decoration-line:.*)\b(?=;)/g, ' underline');- } else {- str += `text-decoration-line: underline; `;- }- if (style.ul.cl && str.indexOf('text-decoration-color') === -1) {- str += `text-decoration-color: ${getColorStyle(style.ul.cl)}; `;- }- if (style.ul.t && str.indexOf('text-decoration-style') === -1) {- str += `text-decoration-style: ${style.ul.t} `;- }- }- },- ],- [- 'st',- () => {- if (style.st?.s) {- if (str.indexOf('text-decoration-line') > -1) {- str = str.replace(/(?<=text-decoration-line:.*)\b(?=;)/g, ' line-through');- } else {- str += `text-decoration-line: line-through; `;- }- if (style.st.cl && str.indexOf('text-decoration-color') === -1) {- str += `text-decoration-color: ${getColorStyle(style.st.cl)}; `;- }- if (style.st.t && str.indexOf('text-decoration-style') === -1) {- str += `text-decoration-style: ${style.st.t} `;- }- }- },- ],- [- 'ol',- () => {- if (style.ol?.s) {- if (str.indexOf('text-decoration-line') > -1) {- str = str.replace(/(?<=text-decoration-line:.*)\b(?=;)/g, ' overline');- } else {- str += `text-decoration-line: overline; `;- }- if (style.ol.cl && str.indexOf('text-decoration-color') === -1) {- str += `text-decoration-color: ${getColorStyle(style.ol.cl)}; `;- }- if (style.ol.t && str.indexOf('text-decoration-style') === -1) {- str += `text-decoration-style: ${style.ol.t} `;- }- }- },- ],- [- 'bg',- () => {- str += `background: ${getColorStyle(style.bg)}; `;- },- ],- [- 'bd',- () => {- if (style.bd?.b) {- str += `border-bottom: ${getBorderStyle(style.bd?.b.s)} ${getColorStyle(style.bd.b.cl) ?? ''}; `;- }- if (style.bd?.t) {- str += `border-top: ${getBorderStyle(style.bd?.t.s)} ${getColorStyle(style.bd.t.cl) ?? ''}; `;- }- if (style.bd?.r) {- str += `border-right: ${getBorderStyle(style.bd?.r.s)} ${getColorStyle(style.bd.r.cl) ?? ''}; `;- }- if (style.bd?.l) {- str += `border-left: ${getBorderStyle(style.bd?.l.s)} ${getColorStyle(style.bd.l.cl) ?? ''}; `;- }- },- ],- [- 'cl',- () => {- str += `color: ${getColorStyle(style.cl)}; `;- },- ],- [- 'va',- () => {- if (style.va === BaselineOffset.NORMAL) {- str += `vertical-align: baseline; `;- } else if (style.va === BaselineOffset.SUBSCRIPT) {- str += `vertical-align: sub; `;- } else {- str += `vertical-align: super; `;- }- },- ],- [- 'td',- () => {- if (style.td === TextDirection.UNSPECIFIED) {- str += `direction: inherit; `;- } else if (style.td === TextDirection.LEFT_TO_RIGHT) {- str += `direction: ltr; `;- } else {- str += `direction: rtl; `;- }- },- ],- [- 'tr',- () => {- str += `data-rotate: (${style.tr?.a}deg${style.tr?.v ? ` ,${style.tr?.v}` : ''});`;- },- ],- [- 'ht',- () => {- if (style.ht === HorizontalAlign.UNSPECIFIED) {- str += `text-align: inherit; `;- } else if (style.ht === HorizontalAlign.LEFT) {- str += `text-align: left; `;- } else if (style.ht === HorizontalAlign.RIGHT) {- str += `text-align: right; `;- } else if (style.ht === HorizontalAlign.CENTER) {- str += `text-align: center; `;- } else {- str += `text-align: justify; `;- }- },- ],- [- 'vt',- () => {- if (style.vt === VerticalAlign.UNSPECIFIED) {- str += `vertical-align: inherit; `;- } else if (style.vt === VerticalAlign.BOTTOM) {- str += `vertical-align: bottom; `;- } else if (style.vt === VerticalAlign.TOP) {- str += `vertical-align: top; `;- } else {- str += `vertical-align: middle; `;- }- },- ],- [- 'tb',- () => {- if (style.tb === WrapStrategy.CLIP) {- str += `text-overflow: clip; `;- } else if (style.tb === WrapStrategy.OVERFLOW) {- str += `text-break: overflow; `;- } else if (style.tb === WrapStrategy.WRAP) {- str += `word-wrap: break-word; word-break: normal; `;- }- },- ],- [- 'pd',- () => {- // let b = '';- // let t = '';- // let l = '';- // let r = '';-- // if (isCss) {- // b = `${pxToPt(style.pd?.b || 0)}pt`;- // t = `${pxToPt(style.pd?.t || 0)}pt`;- // l = `${pxToPt(style.pd?.l || 0)}pt`;- // r = `${pxToPt(style.pd?.r || 0)}pt`;- // } else {- let b = `${style.pd?.b}pt`;- let t = `${style.pd?.t}pt`;- let l = `${style.pd?.l}pt`;- let r = `${style.pd?.r}pt`;- // }- if (style.pd?.b) {- str += `padding-bottom: ${b}; `;- }- if (style.pd?.t) {- str += `padding-top: ${t}; `;- }- if (style.pd?.l) {- str += `padding-left: ${l}; `;- }- if (style.pd?.r) {- str += `padding-right: ${r}; `;- }- },- ],- ]);- const cellSkip = ['bd', 'tr', 'tb'];- for (let k in style) {- if (isCell && cellSkip.includes(k)) continue; // Cell styles to skip when entering edit mode- styleMap.get(k)?.();- }- return str;-}--function getBorderStyle(type: BorderStyleTypes) {- let str = '';- if (type === BorderStyleTypes.NONE) {- str = 'none';- } else if (type === BorderStyleTypes.THIN) {- str = '0.5pt solid';- } else if (type === BorderStyleTypes.HAIR) {- str = '0.5pt double';- } else if (type === BorderStyleTypes.DOTTED) {- str = '0.5pt dotted';- } else if (type === BorderStyleTypes.DASHED) {- str = '0.5pt dashed';- } else if (type === BorderStyleTypes.DASH_DOT) {- str = '0.5pt dashed';- } else if (type === BorderStyleTypes.DASH_DOT_DOT) {- str = '0.5pt dotted';- } else if (type === BorderStyleTypes.DOUBLE) {- str = '0.5pt double';- } else if (type === BorderStyleTypes.MEDIUM) {- str = '1pt solid';- } else if (type === BorderStyleTypes.MEDIUM_DASHED) {- str = '1pt dashed';- } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT) {- str = '1pt dashed';- } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT_DOT) {- str = '1pt dotted';- } else if (type === BorderStyleTypes.SLANT_DASH_DOT) {- str = '0.5pt dashed';- } else if (type === BorderStyleTypes.THICK) {- str = '1.5pt solid';- }- return str;-}-// 将table数据转为sheet数据export function handelTableToJson(table: string) {let data: any[] = [];diff --git a/packages/core/src/Shared/Common.ts b/packages/core/src/Shared/Common.tsindex 81b2d1c8b2..2b13b21ace 100644--- a/packages/core/src/Shared/Common.ts+++ b/packages/core/src/Shared/Common.ts@@ -1,7 +1,24 @@import { Tools } from './Tools';import { Nullable } from '.';-import { ICellInfo, ISelection, ICellData, IColorStyle } from '../Interfaces';+import {+ ICellInfo,+ ISelection,+ ICellData,+ IColorStyle,+ BlockType,+ IDocumentData,+ IStyleData,+ ParagraphElementType,+} from '../Interfaces';import { ColorBuilder } from '../Sheets/Domain';+import {+ BaselineOffset,+ TextDirection,+ HorizontalAlign,+ VerticalAlign,+ WrapStrategy,+ BorderStyleTypes,+} from '../Enum';export function makeCellToSelection(cellInfo: Nullable<ICellInfo>@@ -95,3 +112,355 @@ export function isFormulaString(value: any): boolean {// return style as IStyleData;// }++/**+ * Convert rich text json to DOM+ * @param p+ */+export function handleJsonToDom(p: IDocumentData): string {+ let span = '';+ // let span = `<span id="${p.documentId}">`;+ if (p.body?.blockElements) {+ for (let k in p.body.blockElements) {+ const section = p.body.blockElements[k];+ if (+ section.blockType !== BlockType.PARAGRAPH &&+ section.blockType !== BlockType.SECTION_BREAK+ ) {+ continue;+ }+ if (section.blockType === BlockType.PARAGRAPH) {+ for (let i in section.paragraph) {+ const element = section.paragraph[i];+ for (let j in element) {+ const item = element[j];+ if (item.et === ParagraphElementType.TEXT_RUN) {+ let style = `display:inline-block;${handleStyleToString(+ item.tr.ts+ )}`;+ span += `<span id='${item.eId}' ${+ style.length ? `style="${style}"` : ''+ } >${item.tr.ct}</span>`;+ }+ }+ }+ }+ // else if (section.blockType === BlockType.SECTION_BREAK) {+ // span += '<br/>';+ // }+ }+ }++ // span += '</span>';+ return span;+}++/**+ * transform style object to string+ * @param style+ * @returns+ */+export function handleStyleToString(style: IStyleData, isCell: boolean = false) {+ let str = '';+ const styleMap = new Map([+ [+ 'ff',+ () => {+ if (style.ff) {+ str += `font-family: ${style.ff}; `;+ }+ },+ ],+ [+ 'fs',+ () => {+ if (style.fs) {+ let fs = style.fs;++ // subscript / superscript, Font size for superscripts and subscripts is halved+ if (style.va) {+ fs /= 2;+ }+ str += `font-size: ${fs}pt; `;+ }++ // const fs = isCss ? `${style.fs}px` : `${pxToPt(style.fs || 14)}pt`;+ // str += `font-size: ${fs}; `;+ },+ ],+ [+ 'it',+ () => {+ if (style.it) {+ str += `font-style: italic; `;+ } else {+ str += `font-style: normal; `;+ }+ },+ ],+ [+ 'bl',+ () => {+ if (style.bl) {+ str += `font-weight: bold; `;+ } else {+ str += `font-weight: normal; `;+ }+ },+ ],+ [+ 'ul',+ () => {+ if (style.ul?.s) {+ // If there are existing lines, add new lines+ if (str.indexOf('text-decoration-line') > -1) {+ str = str.replace(+ /(?<=text-decoration-line:.*)\b(?=;)/g,+ ' underline'+ );+ } else {+ str += `text-decoration-line: underline; `;+ }+ if (style.ul.cl && str.indexOf('text-decoration-color') === -1) {+ str += `text-decoration-color: ${getColorStyle(+ style.ul.cl+ )}; `;+ }+ if (style.ul.t && str.indexOf('text-decoration-style') === -1) {+ str += `text-decoration-style: ${style.ul.t} `;+ }+ }+ },+ ],+ [+ 'st',+ () => {+ if (style.st?.s) {+ if (str.indexOf('text-decoration-line') > -1) {+ str = str.replace(+ /(?<=text-decoration-line:.*)\b(?=;)/g,+ ' line-through'+ );+ } else {+ str += `text-decoration-line: line-through; `;+ }+ if (style.st.cl && str.indexOf('text-decoration-color') === -1) {+ str += `text-decoration-color: ${getColorStyle(+ style.st.cl+ )}; `;+ }+ if (style.st.t && str.indexOf('text-decoration-style') === -1) {+ str += `text-decoration-style: ${style.st.t} `;+ }+ }+ },+ ],+ [+ 'ol',+ () => {+ if (style.ol?.s) {+ if (str.indexOf('text-decoration-line') > -1) {+ str = str.replace(+ /(?<=text-decoration-line:.*)\b(?=;)/g,+ ' overline'+ );+ } else {+ str += `text-decoration-line: overline; `;+ }+ if (style.ol.cl && str.indexOf('text-decoration-color') === -1) {+ str += `text-decoration-color: ${getColorStyle(+ style.ol.cl+ )}; `;+ }+ if (style.ol.t && str.indexOf('text-decoration-style') === -1) {+ str += `text-decoration-style: ${style.ol.t} `;+ }+ }+ },+ ],+ [+ 'bg',+ () => {+ str += `background: ${getColorStyle(style.bg)}; `;+ },+ ],+ [+ 'bd',+ () => {+ if (style.bd?.b) {+ str += `border-bottom: ${getBorderStyle(style.bd?.b.s)} ${+ getColorStyle(style.bd.b.cl) ?? ''+ }; `;+ }+ if (style.bd?.t) {+ str += `border-top: ${getBorderStyle(style.bd?.t.s)} ${+ getColorStyle(style.bd.t.cl) ?? ''+ }; `;+ }+ if (style.bd?.r) {+ str += `border-right: ${getBorderStyle(style.bd?.r.s)} ${+ getColorStyle(style.bd.r.cl) ?? ''+ }; `;+ }+ if (style.bd?.l) {+ str += `border-left: ${getBorderStyle(style.bd?.l.s)} ${+ getColorStyle(style.bd.l.cl) ?? ''+ }; `;+ }+ },+ ],+ [+ 'cl',+ () => {+ str += `color: ${getColorStyle(style.cl)}; `;+ },+ ],+ [+ 'va',+ () => {+ if (style.va === BaselineOffset.NORMAL) {+ str += `vertical-align: baseline; `;+ } else if (style.va === BaselineOffset.SUBSCRIPT) {+ str += `vertical-align: sub; `;+ } else {+ str += `vertical-align: super; `;+ }+ },+ ],+ [+ 'td',+ () => {+ if (style.td === TextDirection.UNSPECIFIED) {+ str += `direction: inherit; `;+ } else if (style.td === TextDirection.LEFT_TO_RIGHT) {+ str += `direction: ltr; `;+ } else {+ str += `direction: rtl; `;+ }+ },+ ],+ [+ 'tr',+ () => {+ str += `data-rotate: (${style.tr?.a}deg${+ style.tr?.v ? ` ,${style.tr?.v}` : ''+ });`;+ },+ ],+ [+ 'ht',+ () => {+ if (style.ht === HorizontalAlign.UNSPECIFIED) {+ str += `text-align: inherit; `;+ } else if (style.ht === HorizontalAlign.LEFT) {+ str += `text-align: left; `;+ } else if (style.ht === HorizontalAlign.RIGHT) {+ str += `text-align: right; `;+ } else if (style.ht === HorizontalAlign.CENTER) {+ str += `text-align: center; `;+ } else {+ str += `text-align: justify; `;+ }+ },+ ],+ [+ 'vt',+ () => {+ if (style.vt === VerticalAlign.UNSPECIFIED) {+ str += `vertical-align: inherit; `;+ } else if (style.vt === VerticalAlign.BOTTOM) {+ str += `vertical-align: bottom; `;+ } else if (style.vt === VerticalAlign.TOP) {+ str += `vertical-align: top; `;+ } else {+ str += `vertical-align: middle; `;+ }+ },+ ],+ [+ 'tb',+ () => {+ if (style.tb === WrapStrategy.CLIP) {+ str += `text-overflow: clip; `;+ } else if (style.tb === WrapStrategy.OVERFLOW) {+ str += `text-break: overflow; `;+ } else if (style.tb === WrapStrategy.WRAP) {+ str += `word-wrap: break-word; word-break: normal; `;+ }+ },+ ],+ [+ 'pd',+ () => {+ // let b = '';+ // let t = '';+ // let l = '';+ // let r = '';++ // if (isCss) {+ // b = `${pxToPt(style.pd?.b || 0)}pt`;+ // t = `${pxToPt(style.pd?.t || 0)}pt`;+ // l = `${pxToPt(style.pd?.l || 0)}pt`;+ // r = `${pxToPt(style.pd?.r || 0)}pt`;+ // } else {+ let b = `${style.pd?.b}pt`;+ let t = `${style.pd?.t}pt`;+ let l = `${style.pd?.l}pt`;+ let r = `${style.pd?.r}pt`;+ // }+ if (style.pd?.b) {+ str += `padding-bottom: ${b}; `;+ }+ if (style.pd?.t) {+ str += `padding-top: ${t}; `;+ }+ if (style.pd?.l) {+ str += `padding-left: ${l}; `;+ }+ if (style.pd?.r) {+ str += `padding-right: ${r}; `;+ }+ },+ ],+ ]);+ const cellSkip = ['bd', 'tr', 'tb'];+ for (let k in style) {+ if (isCell && cellSkip.includes(k)) continue; // Cell styles to skip when entering edit mode+ styleMap.get(k)?.();+ }+ return str;+}++function getBorderStyle(type: BorderStyleTypes) {+ let str = '';+ if (type === BorderStyleTypes.NONE) {+ str = 'none';+ } else if (type === BorderStyleTypes.THIN) {+ str = '0.5pt solid';+ } else if (type === BorderStyleTypes.HAIR) {+ str = '0.5pt double';+ } else if (type === BorderStyleTypes.DOTTED) {+ str = '0.5pt dotted';+ } else if (type === BorderStyleTypes.DASHED) {+ str = '0.5pt dashed';+ } else if (type === BorderStyleTypes.DASH_DOT) {+ str = '0.5pt dashed';+ } else if (type === BorderStyleTypes.DASH_DOT_DOT) {+ str = '0.5pt dotted';+ } else if (type === BorderStyleTypes.DOUBLE) {+ str = '0.5pt double';+ } else if (type === BorderStyleTypes.MEDIUM) {+ str = '1pt solid';+ } else if (type === BorderStyleTypes.MEDIUM_DASHED) {+ str = '1pt dashed';+ } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT) {+ str = '1pt dashed';+ } else if (type === BorderStyleTypes.MEDIUM_DASH_DOT_DOT) {+ str = '1pt dotted';+ } else if (type === BorderStyleTypes.SLANT_DASH_DOT) {+ str = '0.5pt dashed';+ } else if (type === BorderStyleTypes.THICK) {+ str = '1.5pt solid';+ }+ return str;+}diff --git a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.tsindex f86875ad77..4a63d7cb73 100644--- a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts@@ -1,15 +1,22 @@-import { getRefElement, CellEditExtensionManager, KeyboardManager, $$, setLastCaretPosition, handleStringToStyle } from '@univerjs/base-ui';-import { isKeyPrintable, Tools } from '@univerjs/core';+import { IPointerEvent, IMouseEvent } from '@univerjs/base-render';+import { CANVAS_VIEW_KEY, SheetPlugin } from '@univerjs/base-sheets';+import { getRefElement, CellEditExtensionManager, KeyboardManager, $$, setLastCaretPosition, handleStringToStyle, handleDomToJson } from '@univerjs/base-ui';+import { Direction, handleStyleToString, ICellData, isKeyPrintable, PLUGIN_NAMES, Tools } from '@univerjs/core';import { SheetUIPlugin } from '../SheetUIPlugin';import { RichText } from '../View/RichText';export class CellEditorUIController {private _plugin: SheetUIPlugin;+ private _sheetPlugin: SheetPlugin;+private _cellEditExtensionManager: CellEditExtensionManager;private _keyboardManager: KeyboardManager;+ // Is it in editing state+ isEditMode: boolean;+richTextEle: HTMLElement;richTextEditEle: HTMLElement;@@ -18,6 +25,7 @@ export class CellEditorUIController {constructor(plugin: SheetUIPlugin) {this._plugin = plugin;+ this._sheetPlugin = plugin.getContext().getUniver().getAllUniverSheetsInstance()[0].context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;this._initialize();}@@ -26,23 +34,18 @@ export class CellEditorUIController {// this._initRegisterComponent();// If other plugins are loaded asynchronously, they may be initialized after the rendering layer is loaded, and they will not receive obs listeners.- // this._plugin.context- // .getObserverManager()- // .getObserver('onSheetRenderDidMountObservable', 'core')- // ?.add((e) => {- // const main = this._plugin.getMainComponent();-- // main.onDblclickObserver.add((evt: IPointerEvent | IMouseEvent) => {- // // Prevent left + right double click- // if (evt.button !== 2) {- // this.enterEditMode();- // }- // });- // main.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {- // this.exitEditMode();- // evt.preventDefault();- // });- // });+ const main = this._sheetPlugin.getMainComponent();++ main.onDblclickObserver.add((evt: IPointerEvent | IMouseEvent) => {+ // Prevent left + right double click+ if (evt.button !== 2) {+ this.enterEditMode();+ }+ });+ main.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {+ this.exitEditMode();+ evt.preventDefault();+ });this._cellEditExtensionManager = new CellEditExtensionManager();@@ -102,10 +105,10 @@ export class CellEditorUIController {if (this.isEditMode) {this.exitEditMode();- const currentCell = this._plugin.getSelectionManager().getCurrentCellModel();+ const currentCell = this._sheetPlugin.getSelectionManager().getCurrentCellModel();if (!currentCell?.isMerged) {// move to cell below- this._plugin.getSelectionManager().move(Direction.BOTTOM);+ this._sheetPlugin.getSelectionManager().move(Direction.BOTTOM);}} else {this.enterEditMode();@@ -120,31 +123,31 @@ export class CellEditorUIController {case 'ArrowUp':if (!this.isEditMode) {- this._plugin.getSelectionManager().move(Direction.TOP);+ this._sheetPlugin.getSelectionManager().move(Direction.TOP);}break;case 'ArrowDown':if (!this.isEditMode) {- this._plugin.getSelectionManager().move(Direction.BOTTOM);+ this._sheetPlugin.getSelectionManager().move(Direction.BOTTOM);}break;case 'ArrowLeft':if (!this.isEditMode) {- this._plugin.getSelectionManager().move(Direction.LEFT);+ this._sheetPlugin.getSelectionManager().move(Direction.LEFT);}break;case 'ArrowRight':if (!this.isEditMode) {- this._plugin.getSelectionManager().move(Direction.RIGHT);+ this._sheetPlugin.getSelectionManager().move(Direction.RIGHT);}break;case 'Tab':if (!this.isEditMode) {- this._plugin.getSelectionManager().move(Direction.RIGHT);+ this._sheetPlugin.getSelectionManager().move(Direction.RIGHT);}evt.preventDefault();break;@@ -199,7 +202,7 @@ export class CellEditorUIController {this.isEditMode = true;- const currentCell = this._plugin.getSelectionManager().getCurrentCellModel();+ const currentCell = this._sheetPlugin.getSelectionManager().getCurrentCellModel();if (!currentCell) {return false;@@ -223,8 +226,8 @@ export class CellEditorUIController {endY = currentCell.endY;}- const scrollX = this._plugin.getMainScene()?.getViewport(CANVAS_VIEW_KEY.VIEW_TOP)?.actualScrollX || 0;- const scrollY = this._plugin.getMainScene()?.getViewport(CANVAS_VIEW_KEY.VIEW_LEFT)?.actualScrollY || 0;+ const scrollX = this._sheetPlugin.getMainScene()?.getViewport(CANVAS_VIEW_KEY.VIEW_TOP)?.actualScrollX || 0;+ const scrollY = this._sheetPlugin.getMainScene()?.getViewport(CANVAS_VIEW_KEY.VIEW_LEFT)?.actualScrollY || 0;this.richTextEle.style.left = `${startX - scrollX}px`;this.richTextEle.style.top = `${startY - scrollY}px`;@@ -233,7 +236,7 @@ export class CellEditorUIController {this.richTextEle.style.minHeight = `${endY - startY}px`;this.richTextEle.style.borderWidth = '2px';- const univerContainerContentRef = this._plugin.getSheetContainerUIController().getContentRef();+ const univerContainerContentRef = this._plugin.getSheetContainerController().getContentRef();const sheetContentRect = getRefElement(univerContainerContentRef).getBoundingClientRect();this.richTextEle.style.maxWidth = `${sheetContentRect.width - startX + scrollX}px`;@@ -242,7 +245,7 @@ export class CellEditorUIController {this.richTextEle.style.transform = '';// this._plugin.showMainByName('cellEditor', true).then(() => {- let cellValue = this.getSelectionValue();+ let cellValue = this._sheetPlugin.getCellEditorController().getSelectionValue();// Intercept, the formula needs to modify the value of the edit stateconst cell = this._cellEditExtensionManager.handle({@@ -260,7 +263,7 @@ export class CellEditorUIController {}this.richText.setValue(cellValue);- const style = this.getSelectionStyle();+ const style = this._sheetPlugin.getCellEditorController().getSelectionStyle();this.richTextEditEle.style.cssText = '';@@ -270,7 +273,7 @@ export class CellEditorUIController {}// });- this.setCurrentEditRangeData();+ this._sheetPlugin.getCellEditorController().setCurrentEditRangeData();}exitEditMode() {@@ -302,7 +305,7 @@ export class CellEditorUIController {if (Tools.isPlainObject(style)) {cell.s = style;}- this.setCurrentEditRangeValue(cell);+ this._sheetPlugin.getCellEditorController().setCurrentEditRangeValue(cell);this.hideEditContainer();}diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsxindex 2ce5733f43..a1803944e6 100644--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx@@ -13,8 +13,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {private _config: ISheetUIPluginConfig;- private _canvasEngine: Engine;-constructor(config?: ISheetUIPluginConfig) {super(SHEET_UI_PLUGIN_NAME);this._config = Tools.deepMerge({}, DefaultSheetUiConfig, config);@@ -52,7 +50,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {initRender() {const engine = this.getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;let container = getRefElement(this.getSheetContainerController().getContentRef());- this._canvasEngine = engine;// mount canvas to DOM containerengine.setContainer(container);