Skip to content

Commit 0941002

Browse files
committed
feat: default excel id
1 parent dac4a4a commit 0941002

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
git clone https://github.com/nusr/excel.git
1616
cd excel
1717

18-
npm i -g pnpm jscpd
18+
npm i -g pnpm
1919
pnpm i
2020
npm run start
2121
```
@@ -29,7 +29,6 @@ npm run test
2929
## E2E Test
3030

3131
```bash
32-
pnpm exec playwright install --with-deps
3332
npm run e2e
3433
```
3534

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@
2929
"@testing-library/jest-dom": "6.6.3",
3030
"@testing-library/react": "16.0.1",
3131
"@types/jest": "29.5.14",
32-
"@types/node": "22.9.1",
32+
"@types/node": "22.10.1",
3333
"@types/pixelmatch": "5.2.6",
3434
"@types/pngjs": "6.0.5",
3535
"@types/react": "18.3.12",
3636
"@types/react-dom": "18.3.1",
37-
"@vitejs/plugin-react": "4.3.3",
37+
"@vitejs/plugin-react": "4.3.4",
3838
"canvas": "2.11.2",
3939
"husky": "9.1.7",
4040
"jest": "29.7.0",
4141
"jest-environment-jsdom": "29.7.0",
42-
"nx": "20.1.3",
42+
"nx": "20.1.4",
4343
"pixelmatch": "6.0.0",
4444
"pngjs": "7.0.0",
4545
"ts-jest": "29.2.5",
46-
"typescript": "5.6.3",
47-
"vite": "5.4.11",
46+
"typescript": "5.7.2",
47+
"vite": "6.0.1",
4848
"vite-plugin-dts": "4.3.0"
4949
},
5050
"engines": {

packages/demo/src/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ import {
77
initCollaboration,
88
initDoc,
99
wrap,
10+
getDocId,
1011
} from '@excel/react';
1112
import '@excel/react/style';
12-
import { copyOrCut, paste, getDocId, type WorkerMethod } from '@excel/shared';
13+
import { copyOrCut, paste, type WorkerMethod } from '@excel/shared';
1314
import './sentry';
1415
import Worker from './worker?worker';
1516

16-
console.log(import.meta.env);
17-
1817
const workerInstance = wrap<WorkerMethod>(new Worker());
1918

2019
async function initView() {
21-
const docId = getDocId();
20+
const docId = getDocId(import.meta.env.VITE_DEFAULT_EXCEL_ID);
2221
location.hash = `#${docId}`;
2322
const doc = initDoc({ guid: docId });
2423
const { isServer, provider } = await initCollaboration(doc);

packages/react/src/containers/MenuBar/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ import { Theme } from './Theme';
66
import { $ } from '../../i18n';
77
import { I18N } from './I18N';
88
import { FPS } from './FPS';
9-
import { saveAs, isInIframe, getDocId } from '@excel/shared';
9+
import { saveAs, isInIframe, DEFAULT_EXCEL_ID } from '@excel/shared';
1010
import { useExcel } from '../store';
1111

12+
export function getDocId(defaultExcelId: string = '') {
13+
const docId =
14+
(window?.top?.location?.hash || '').slice(1) ||
15+
window.location.hash.slice(1) ||
16+
defaultExcelId ||
17+
DEFAULT_EXCEL_ID;
18+
return docId;
19+
}
20+
1221
export const MenuBarContainer = memo(() => {
1322
const { controller } = useExcel();
1423
const handleExportXLSX = useCallback(() => {

packages/react/src/containers/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export const App = memo(() => {
2020
App.displayName = 'App';
2121

2222
export { StateContext, useExcel } from './store';
23+
export { getDocId } from './MenuBar'

packages/react/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { App } from './containers';
22
import { initController } from './controller';
33
import './global.css';
4-
import { StateContext, useExcel } from './containers';
4+
import { StateContext, useExcel, getDocId } from './containers';
55
import { initCollaboration } from './collaboration';
66
import * as Y from 'yjs';
77
import workerMethod from './canvas/worker';
@@ -14,6 +14,7 @@ export function initDoc(...params: ConstructorParameters<typeof Y.Doc>) {
1414
}
1515

1616
export {
17+
getDocId,
1718
initCollaboration,
1819
StateContext,
1920
useExcel,

packages/shared/src/util/util.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
SPLITTER,
44
FORMULA_PREFIX,
55
MERGE_CELL_LINE_BREAK,
6-
DEFAULT_EXCEL_ID as DEFAULT_DOC_ID,
76
} from './constant';
87
import type {
98
WorksheetType,
@@ -236,11 +235,3 @@ export function isMergeContent(isMergeCell: boolean, text: string) {
236235
export function isInIframe() {
237236
return window?.top !== window;
238237
}
239-
240-
export function getDocId() {
241-
const docId =
242-
(window?.top?.location?.hash || '').slice(1) ||
243-
window.location.hash.slice(1) ||
244-
DEFAULT_DOC_ID;
245-
return docId;
246-
}

0 commit comments

Comments
 (0)