Skip to content

Commit 7d33bf9

Browse files
committed
fix: scroll page
1 parent e966ac3 commit 7d33bf9

File tree

15 files changed

+102
-83
lines changed

15 files changed

+102
-83
lines changed

packages/demo/src/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ async function initView() {
2020
const docId = getDocId(import.meta.env.VITE_DEFAULT_EXCEL_ID);
2121
location.hash = `#${docId}`;
2222
const doc = initDoc({ guid: docId });
23-
const { isServer, provider } = await initCollaboration(doc);
23+
const { isServer, provider, isInit } = await initCollaboration(doc);
2424
const controller = initController({
2525
copyOrCut,
2626
paste,
2727
worker: workerInstance,
2828
doc,
2929
});
30+
if (isInit) {
31+
controller.setCurrentSheetId(controller.getCurrentSheetId());
32+
}
3033

3134
createRoot(document.getElementById('root')!).render(
3235
<StrictMode>
@@ -42,9 +45,7 @@ async function initView() {
4245
</StateContext.Provider>
4346
</StrictMode>,
4447
);
45-
document.body.append(`<!-- ${process.env.COMMIT_LOG} --> `);
46-
setTimeout(() => {
47-
document.getElementById('loading')?.remove();
48-
}, 0);
48+
document.head.append(`<!-- ${process.env.COMMIT_LOG} --> `);
49+
document.getElementById('loading')?.remove();
4950
}
5051
initView();

packages/formula/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"build": "vite build",
22-
"dev": "vite",
22+
"dev": "vite --port 5000",
2323
"type-check": "tsc"
2424
},
2525
"files": [

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"scripts": {
2727
"build": "vite build",
2828
"type-check": "tsc",
29-
"dev": "vite --force --host"
29+
"dev": "vite --force --host --port 4000"
3030
},
3131
"peerDependencies": {
3232
"react": "18.3.1",

packages/react/src/canvas/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {
99
scrollBar,
1010
scrollToView,
1111
scrollSheetToView,
12+
computeScrollPosition,
1213
} from './shortcut';
1314

1415
let instance: MainCanvas;

packages/react/src/canvas/offScreenWorker.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,22 +280,30 @@ export default class OffScreenWorker implements WorkerMainView {
280280
const pointList: Point[] = [];
281281
let y = 0;
282282
let x = 0;
283+
const xTemp: Point[] = [];
284+
const yTemp: Point[] = [];
283285
for (let i = rowIndex; i < rowCount && y <= height; i++) {
284286
while (i < rowCount && this.getRowHeight(i) === 0) {
285287
i++;
286288
}
287-
pointList.push([0, y], [width, y]);
289+
yTemp.push([0, y]);
288290
const h = this.getRowHeight(i);
289291
y += h;
290292
}
291293
for (let i = colIndex; i < colCount && x <= width; i++) {
292294
while (i < colCount && this.getColWidth(i) === 0) {
293295
i++;
294296
}
295-
pointList.push([x, 0], [x, y]);
297+
xTemp.push([x, 0]);
296298
const w = this.getColWidth(i);
297299
x += w;
298300
}
301+
for (const item of xTemp) {
302+
pointList.push(item, [item[0], y]);
303+
}
304+
for (const item of yTemp) {
305+
pointList.push(item, [x, item[1]]);
306+
}
299307
pointList.push([0, y], [x, y]);
300308
pointList.push([x, 0], [x, y]);
301309
drawLines(this.ctx, pointList);

packages/react/src/canvas/shortcut.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import {
1111
SHEET_ITEM_TEST_ID_PREFIX,
1212
sheetViewSizeSet,
1313
headerSizeSet,
14-
computeScrollPosition,
1514
canvasSizeSet,
1615
FORMULA_EDITOR_ROLE,
1716
MERGE_CELL_LINE_BREAK,
1817
LINE_BREAK,
1918
isMergeContent,
2019
} from '@excel/shared';
2120
import { coreStore } from '../containers/store';
22-
export const BOTTOM_BUFF = 200;
2321

2422
export function handleTabClick(controller: IController) {
2523
controller.transaction(() => {
@@ -129,6 +127,24 @@ export function scrollToView(controller: IController, range: IRange) {
129127
});
130128
}
131129

130+
export function computeScrollPosition() {
131+
const contentSize = 30;
132+
const BOTTOM_BUFF = 200;
133+
const canvasRect = canvasSizeSet.get();
134+
const viewSize = sheetViewSizeSet.get();
135+
const maxHeight = viewSize.height - canvasRect.height + BOTTOM_BUFF;
136+
const maxWidth = viewSize.width - canvasRect.width + BOTTOM_BUFF;
137+
const maxScrollHeight = canvasRect.height - contentSize;
138+
const maxScrollWidth = canvasRect.width - contentSize;
139+
140+
return {
141+
maxHeight,
142+
maxWidth,
143+
maxScrollHeight,
144+
maxScrollWidth,
145+
};
146+
}
147+
132148
export function scrollBar(
133149
controller: IController,
134150
scrollX: number,

packages/react/src/collaboration/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { initProvider, ResultData } from './provider';
1+
import { initProvider } from './provider';
22
import * as Y from 'yjs';
3-
import { collaborationLog } from '@excel/shared';
3+
import { collaborationLog, CollaborationProvider } from '@excel/shared';
44
import { SYNC_FLAG } from '@excel/shared';
55
import { DEFAULT_UPDATE } from './provider/util';
66

@@ -11,7 +11,13 @@ function shouldSkip(isServer: boolean, tran: Y.Transaction) {
1111
return false;
1212
}
1313

14-
export async function initCollaboration(doc: Y.Doc): Promise<ResultData> {
14+
export async function initCollaboration(
15+
doc: Y.Doc,
16+
): Promise<{
17+
provider: CollaborationProvider;
18+
isServer: boolean;
19+
isInit: boolean;
20+
}> {
1521
const { provider, isServer } = initProvider(doc);
1622

1723
doc.on('update', (update: Uint8Array, _b, _c, tran) => {
@@ -24,11 +30,13 @@ export async function initCollaboration(doc: Y.Doc): Promise<ResultData> {
2430
provider.subscribe();
2531

2632
const result = await provider.retrieveHistory();
33+
let isInit = false;
2734
if (result.length > 0) {
2835
Y.applyUpdate(doc, Y.mergeUpdates(result), SYNC_FLAG.SKIP_UPDATE);
2936
} else {
37+
isInit = true;
3038
Y.applyUpdate(doc, DEFAULT_UPDATE, SYNC_FLAG.SKIP_UNDO_REDO);
3139
}
3240

33-
return { isServer, provider };
41+
return { isServer, provider, isInit };
3442
}

packages/react/src/collaboration/provider/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import { LocalProvider } from './local';
55
import { CollaborationProvider } from '@excel/shared';
66
import { type Doc } from 'yjs';
77

8-
export type ResultData = {
9-
provider: CollaborationProvider;
10-
isServer: boolean;
11-
};
12-
13-
export function initProvider(doc: Doc): ResultData {
8+
export function initProvider(doc: Doc) {
149
const url = import.meta.env.VITE_SUPABASE_URL;
1510
const key = import.meta.env.VITE_SUPABASE_ANON_KEY;
1611
let isServer = false;

packages/react/src/containers/canvas/BottomBar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { Button } from '../../components';
33
import styles from './index.module.css';
44
import { scrollBar } from '../../canvas';
55
import { $ } from '../../i18n';
6-
import { classnames, sheetViewSizeSet, MAX_ADD_ROW_THRESHOLD } from '@excel/shared';
6+
import {
7+
classnames,
8+
sheetViewSizeSet,
9+
MAX_ADD_ROW_THRESHOLD,
10+
} from '@excel/shared';
711
import { scrollStore, useExcel } from '../store';
812

913
const defaultData = 10;

packages/react/src/containers/canvas/ScrollBar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import React, {
88
useMemo,
99
} from 'react';
1010
import { type IController, ScrollStatus } from '@excel/shared';
11-
import { computeScrollRowAndCol } from '../../canvas';
11+
import { computeScrollRowAndCol, computeScrollPosition } from '../../canvas';
1212
import styles from './index.module.css';
1313
import { scrollStore, useExcel } from '../store';
14-
import { computeScrollPosition } from '@excel/shared';
1514

1615
interface State {
1716
prevPageY: number;

0 commit comments

Comments
 (0)