Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sheets-ui): cell-editor & formula-editor #4209

Open
wants to merge 98 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
9e0d7dc
fix: SelectionMoveType default to be ONLY_SET
lumixraku Nov 27, 2024
a03a347
fix: move range should add SelectionMoveType.move_end
lumixraku Nov 27, 2024
cb285cf
fix: playwright prompt undefined
lumixraku Nov 27, 2024
98a78e0
feat: update
weird94 Nov 27, 2024
0a9b30d
fix: rename
lumixraku Nov 27, 2024
c96e249
fix: add a comma after selection would change sheetId !!!
lumixraku Nov 28, 2024
19aba7a
feat: update
weird94 Nov 28, 2024
a09e679
feat: update
weird94 Nov 28, 2024
c0d1029
feat: update
weird94 Nov 28, 2024
5625f1a
Merge remote-tracking branch 'origin/dev' into refactor/cell-editor-1125
weird94 Nov 28, 2024
35b697d
Merge remote-tracking branch 'origin/fix/selection-expand-with-shift'…
weird94 Nov 28, 2024
2f3d44f
feat: update
weird94 Nov 28, 2024
dcc3def
feat: update
weird94 Nov 28, 2024
8ea49fa
feat: update
weird94 Nov 29, 2024
f96a3b1
feat: update
weird94 Nov 29, 2024
1e9ce8c
feat: update
weird94 Nov 29, 2024
c9b9e21
feat: update
weird94 Nov 29, 2024
ee807ea
feat: update
weird94 Nov 29, 2024
50ff8d9
feat: update
weird94 Nov 29, 2024
0b8b591
feat: update
weird94 Nov 30, 2024
c64296e
feat: update
weird94 Nov 30, 2024
af86125
feat: update
weird94 Nov 30, 2024
d78902c
feat: update
weird94 Nov 30, 2024
0b7cfdc
feat: update
weird94 Nov 30, 2024
dfd394a
feat: update
weird94 Nov 30, 2024
60f1311
feat: update
weird94 Nov 30, 2024
a4bcc4d
feat: update
weird94 Nov 30, 2024
9e7c359
feat: update
weird94 Dec 2, 2024
0cf2959
feat: update
weird94 Dec 2, 2024
1a92b30
feat: update
weird94 Dec 2, 2024
5c65608
feat: update
weird94 Dec 2, 2024
5834818
feat: update
weird94 Dec 2, 2024
32f3d27
feat: update
weird94 Dec 2, 2024
fa2f8f3
feat: update
weird94 Dec 2, 2024
e58e8e5
Merge remote-tracking branch 'origin/dev' into refactor/cell-editor-1125
weird94 Dec 2, 2024
84cc13f
chore(snapshots): update snapshots
actions-user Dec 2, 2024
6e1f1d6
feat: update
weird94 Dec 2, 2024
b12bc92
Merge branch 'refactor/cell-editor-1125' of github.com:dream-num/univ…
weird94 Dec 2, 2024
88efb89
feat: update
weird94 Dec 2, 2024
e27eb81
feat: update
weird94 Dec 2, 2024
fbfa9d0
feat: update
weird94 Dec 2, 2024
b700251
feat: update
weird94 Dec 3, 2024
a84f0f7
Merge branch dev into refactor/cell-editor-1125
weird94 Dec 3, 2024
9093fcd
chore(snapshots): update snapshots
actions-user Dec 3, 2024
cc4a146
Merge remote-tracking branch 'origin/dev' into refactor/cell-editor-1125
weird94 Dec 3, 2024
47967ae
feat: update
weird94 Dec 3, 2024
06687cb
feat: update
weird94 Dec 3, 2024
3f92f36
feat: update
weird94 Dec 3, 2024
eeebad6
feat: update
weird94 Dec 3, 2024
3cf1c55
feat: update
weird94 Dec 3, 2024
a4c136f
feat: update
weird94 Dec 4, 2024
5b5716a
feat: update
weird94 Dec 4, 2024
bd7dbb7
Merge branch 'dev' into refactor/cell-editor-1125
weird94 Dec 11, 2024
3583755
Merge branch 'dev' into refactor/cell-editor-1125
weird94 Dec 11, 2024
2f94d88
fix: https://github.com/dream-num/univer-pro/issues/3752
weird94 Dec 11, 2024
ce24c06
feat: update
weird94 Dec 11, 2024
9ef9f63
feat: update
weird94 Dec 11, 2024
a41e54d
feat: update
weird94 Dec 12, 2024
daca1a0
feat: update
weird94 Dec 12, 2024
b492bda
feat: update
weird94 Dec 12, 2024
7de9031
feat: update
weird94 Dec 12, 2024
116793e
feat: update
weird94 Dec 12, 2024
5256dab
feat: update
weird94 Dec 12, 2024
0919cc8
feat: update
weird94 Dec 13, 2024
3394c4c
Merge branch 'dev' into refactor/cell-editor-1125
weird94 Dec 19, 2024
7fc8073
refactor: editor-service
weird94 Dec 19, 2024
2ddedd3
feat: update
weird94 Dec 19, 2024
d7c1c70
feat: update
weird94 Dec 19, 2024
8ed0086
feat: update
weird94 Dec 19, 2024
ac37858
feat: update
weird94 Dec 19, 2024
cc7e6d4
feat: update
weird94 Dec 20, 2024
7042677
feat: update
weird94 Dec 20, 2024
6d95992
feat: update
weird94 Dec 20, 2024
d3ea7aa
feat: update
weird94 Dec 20, 2024
bed4897
feat: update
weird94 Dec 20, 2024
7493892
feat: update
weird94 Dec 20, 2024
f5e4a5e
feat: cursor
weird94 Dec 20, 2024
3e154a0
feat: update
weird94 Dec 20, 2024
cfc9c82
feat: update
weird94 Dec 23, 2024
47aba48
feat: update
weird94 Dec 23, 2024
7c6cfba
feat: update
weird94 Dec 23, 2024
dcaa122
feat: update
weird94 Dec 23, 2024
0debcba
feat: update
weird94 Dec 23, 2024
7ad2f0c
feat: update
weird94 Dec 23, 2024
62f1295
feat: update
weird94 Dec 23, 2024
c419a3d
feat: update
weird94 Dec 24, 2024
e6290b9
Merge branch 'dev' into refactor/cell-editor-1125
weird94 Dec 24, 2024
295497c
feat: disable undo redo shortcut on cell editor
weird94 Dec 24, 2024
a000ea0
feat: update
weird94 Dec 25, 2024
1157972
feat: update
weird94 Dec 25, 2024
45f897b
feat: update
weird94 Dec 25, 2024
cca97df
feat: update
weird94 Dec 25, 2024
70ffcf8
feat: update
weird94 Dec 25, 2024
c57b00a
feat: update
weird94 Dec 25, 2024
8a9dbdc
feat: update
weird94 Dec 25, 2024
38b1d78
fix: no need to resize
Jocs Dec 25, 2024
d0ce17c
feat: update
weird94 Dec 25, 2024
1cd5d3a
feat: update
weird94 Dec 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import type { IAccessor, ICommand, Workbook } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IEditorService } from '@univerjs/docs-ui';
import { ISidebarService } from '@univerjs/ui';
import type { IAccessor, ICommand, Workbook } from '@univerjs/core';
import { TEST_EDITOR_CONTAINER_COMPONENT } from '../../views/test-editor/component-name';

export interface IUIComponentCommandParams {
Expand All @@ -34,25 +34,17 @@ export const SidebarOperation: ICommand = {
const unit = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
switch (params.value) {
case 'open':
editorService.setOperationSheetUnitId(unit.getUnitId());
editorService.setOperationSheetSubUnitId(unit.getActiveSheet()?.getSheetId());
sidebarService.open({
header: { title: 'Sidebar title' },
children: { label: TEST_EDITOR_CONTAINER_COMPONENT },
footer: { title: 'Sidebar Footer' },
onClose: () => {
editorService.setOperationSheetUnitId(null);
editorService.setOperationSheetSubUnitId(null);
editorService.closeRangePrompt();
},
});
break;

case 'close':
default:
editorService.setOperationSheetUnitId(null);
editorService.setOperationSheetSubUnitId(null);
editorService.closeRangePrompt();
sidebarService.close();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import { ImageDemo } from '../components/Image';

// @ts-ignore
import VueI18nIcon from '../components/VueI18nIcon.vue';
import { TEST_EDITOR_CONTAINER_COMPONENT } from '../views/test-editor/component-name';
import { TestEditorContainer } from '../views/test-editor/TestTextEditor';
// import { TEST_EDITOR_CONTAINER_COMPONENT } from '../views/test-editor/component-name';
// import { TestEditorContainer } from '../views/test-editor/TestTextEditor';
import { RecordController } from './local-save/record.controller';
import { menuSchema } from './menu.schema';

Expand Down Expand Up @@ -81,7 +81,7 @@ export class DebuggerController extends Disposable {

private _initCustomComponents(): void {
const componentManager = this._componentManager;
this.disposeWithMe(componentManager.register(TEST_EDITOR_CONTAINER_COMPONENT, TestEditorContainer));
// this.disposeWithMe(componentManager.register(TEST_EDITOR_CONTAINER_COMPONENT, TestEditorContainer));
this.disposeWithMe(componentManager.register('VueI18nIcon', VueI18nIcon, {
framework: 'vue3',
}));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { IDocumentData, Nullable } from '@univerjs/core';
import type { IUniFormulaPopupInfo } from '../../services/formula-popup.service';
import { BooleanNumber, createInternalEditorID, DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentFlavor, HorizontalAlign, ICommandService, LocaleService, useDependency, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { TextEditor } from '@univerjs/docs-ui';
// import { TextEditor } from '@univerjs/docs-ui';
import { CheckMarkSingle, CloseSingle } from '@univerjs/icons';
import { useObservable } from '@univerjs/ui';
import clsx from 'clsx';
Expand Down Expand Up @@ -123,7 +123,7 @@ function DocFormula(props: { popupInfo: IUniFormulaPopupInfo }) {

return (
<div className={styles.docUiFormulaPopup} onMouseEnter={() => onHovered(true)} onMouseLeave={() => onHovered(false)}>
<TextEditor
{/* <TextEditor
id={UNI_FORMULA_EDITOR_ID}
className={clsx(styles.docUiFormulaPopupEditor, focused && styles.docUiFormulaPopupEditorActivated)}
placeholder={localeService.t('uni-formula.popup.placeholder')}
Expand All @@ -138,7 +138,7 @@ function DocFormula(props: { popupInfo: IUniFormulaPopupInfo }) {
setFocused(true);
}}
onBlur={() => setFocused(false)}
/>
/> */}
<div className={clsx(styles.formulaIcon, { [styles.formulaIconDisable]: !formulaString })}>
<span
className={clsx(styles.iconContainer, styles.iconContainerError)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { Nullable, Workbook } from '@univerjs/core';
import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DocumentFlavor, HorizontalAlign, IPermissionService, IUniverInstanceService, Rectangle, ThemeService, UniverInstanceType, useDependency, useObservable, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { TextEditor } from '@univerjs/docs-ui';
// import { TextEditor } from '@univerjs/docs-ui';
import { DeviceInputEventType } from '@univerjs/engine-render';
import { CheckMarkSingle, CloseSingle, FxSingle } from '@univerjs/icons';
import { RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel, WorksheetSetCellValuePermission } from '@univerjs/sheets';
Expand Down Expand Up @@ -206,7 +206,7 @@ export function FormulaBar() {

return (
<div className={styles.uniFormulaBox}>
<TextEditor
{/* <TextEditor
id={DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY}
isSheetEditor
resizeCallBack={resizeCallBack}
Expand All @@ -215,7 +215,7 @@ export function FormulaBar() {
className={clsx(styles.uniFormulaInput, styles.formulaContent)}
snapshot={INITIAL_SNAPSHOT}
isSingle
/>
/> */}
<div className={clsx(styles.formulaIcon, { [styles.formulaIconDisable]: disable })}>
<span
className={clsx(styles.iconContainer, styles.iconContainerError)}
Expand Down
17 changes: 10 additions & 7 deletions packages/core/src/docs/data-model/document-data-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
* limitations under the License.
*/

import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../../common/unit';
import { Tools } from '../../shared/tools';
import { getEmptySnapshot } from './empty-snapshot';
import { JSONX } from './json-x/json-x';
import { PRESET_LIST_TYPE } from './preset-list-type';
import { getBodySlice, SliceBodyType } from './text-x/utils';
import type { Nullable } from '../../shared';
import type {
IDocumentBody,
Expand All @@ -32,6 +25,13 @@ import type {
} from '../../types/interfaces/i-document-data';
import type { IPaddingData } from '../../types/interfaces/i-style-data';
import type { JSONXActions } from './json-x/json-x';
import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../../common/unit';
import { Tools } from '../../shared/tools';
import { getEmptySnapshot } from './empty-snapshot';
import { JSONX } from './json-x/json-x';
import { PRESET_LIST_TYPE } from './preset-list-type';
import { getBodySlice, SliceBodyType } from './text-x/utils';

export const DEFAULT_DOC = {
id: 'default_doc',
Expand Down Expand Up @@ -228,6 +228,7 @@ export class DocumentDataModel extends DocumentDataModelSimple {
headerModelMap: Map<string, DocumentDataModel> = new Map();

footerModelMap: Map<string, DocumentDataModel> = new Map();
change$ = new BehaviorSubject<number>(0);

constructor(snapshot: Partial<IDocumentData>) {
super(Tools.isEmptyObject(snapshot) ? getEmptySnapshot() : snapshot);
Expand Down Expand Up @@ -281,6 +282,7 @@ export class DocumentDataModel extends DocumentDataModelSimple {

this.snapshot = { ...DEFAULT_DOC, ...snapshot };
this._initializeHeaderFooterModel();
this.change$.next(this.change$.value + 1);
}

getSelfOrHeaderFooterModel(segmentId?: string) {
Expand Down Expand Up @@ -315,6 +317,7 @@ export class DocumentDataModel extends DocumentDataModelSimple {
this._initializeHeaderFooterModel();
}

this.change$.next(this.change$.value + 1);
return this.snapshot;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { addDrawing } from './drawings';
import { changeParagraphBulletNestLevel, setParagraphBullet, switchParagraphBullet, toggleChecklistParagraph } from './paragraph';
import { fromPlainText, getPlainText, isEmptyDocument } from './parse';
import { isSegmentIntersects, makeSelection, normalizeSelection } from './selection';
import { addCustomRangeTextX, deleteCustomRangeTextX, deleteSelectionTextX, replaceSelectionTextX } from './text-x-utils';
import { addCustomRangeTextX, deleteCustomRangeTextX, deleteSelectionTextX, replaceSelectionTextRuns, replaceSelectionTextX } from './text-x-utils';

export class BuildTextUtils {
static customRange = {
Expand All @@ -41,6 +41,7 @@ export class BuildTextUtils {
makeSelection,
normalizeSelection,
delete: deleteSelectionTextX,
replaceTextRuns: replaceSelectionTextRuns,
};

static range = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

import type { IAccessor } from '@wendellhu/redi';
import type { ITextRange, ITextRangeParam } from '../../../../sheets/typedef';
import type { CustomRangeType, IDocumentBody } from '../../../../types/interfaces';
import type { CustomRangeType, IDocumentBody, ITextRun } from '../../../../types/interfaces';
import type { DocumentDataModel } from '../../document-data-model';
import type { TextXAction } from '../action-types';
import type { TextXSelection } from '../text-x';
import { type Nullable, UpdateDocsAttributeType } from '../../../../shared';
import { textDiff } from '../../../../shared/text-diff';
import { TextXActionType } from '../action-types';
import { TextX } from '../text-x';
import { getBodySlice } from '../utils';
import { getBodySlice, getTextRunSlice } from '../utils';
import { excludePointsFromRange, getIntersectingCustomRanges, getSelectionForAddCustomRange } from './custom-range';

export interface IDeleteCustomRangeParam {
Expand Down Expand Up @@ -301,3 +301,73 @@ export const replaceSelectionTextX = (params: IReplaceSelectionTextXParams) => {
textX.push(...actions);
return textX;
};

function isTextRunsEqual(textRuns: ITextRun[] | undefined, oldTextRuns: ITextRun[] | undefined) {
if (textRuns?.length === oldTextRuns?.length && textRuns?.every((textRun, index) => JSON.stringify(textRun) === JSON.stringify(oldTextRuns?.[index]))) {
return true;
}

return false;
}

export const replaceSelectionTextRuns = (params: IReplaceSelectionTextXParams) => {
const { selection, body: insertBody, doc } = params;
const segmentId = selection.segmentId;
const body = doc.getSelfOrHeaderFooterModel(segmentId)?.getBody();
if (!body) return false;

const oldBody = selection.collapsed ? null : getBodySlice(body, selection.startOffset, selection.endOffset);
const diffs = textDiff(oldBody ? oldBody.dataStream : '', insertBody.dataStream);
let cursor = 0;
const actions = diffs.map(([type, text]) => {
switch (type) {
// retain
case 0: {
const textRunsSlice = getTextRunSlice(insertBody, cursor, cursor + text.length, false);
const oldTextRunsSlice = getTextRunSlice(oldBody!, cursor, cursor + text.length, false);
const action: TextXAction = {
t: TextXActionType.RETAIN,
body: isTextRunsEqual(textRunsSlice, oldTextRunsSlice)
? undefined
: {
textRuns: textRunsSlice,
dataStream: '',
},
len: text.length,
};
cursor += text.length;
return action;
}
// insert
case 1: {
const action: TextXAction = {
t: TextXActionType.INSERT,
body: getBodySlice(insertBody, cursor, cursor + text.length),
len: text.length,
};
cursor += text.length;
return action;
}
// delete
default: {
const action: TextXAction = {
t: TextXActionType.DELETE,
len: text.length,
};
return action;
}
}
});

if (actions.every((action) => action.t === TextXActionType.RETAIN && !action.body)) {
return false;
}

const textX = new TextX();
textX.push({
t: TextXActionType.RETAIN,
len: selection.startOffset,
});
textX.push(...actions);
return textX;
};
Loading