Skip to content

Commit a8560c4

Browse files
committed
fix: Indexing taking a long time for sheet file
1 parent f83409d commit a8560c4

File tree

7 files changed

+74
-87
lines changed

7 files changed

+74
-87
lines changed

src/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const VIEW_TYPE_EXCEL_PRO = 'excel-pro-view'
22
export const FRONTMATTER_KEY = 'excel-pro-plugin'
3-
export const FRONTMATTER = ['---', '', `${FRONTMATTER_KEY}: parsed`, '', '---', '', ''].join('\n')
3+
export const FRONTMATTER = ['---', '', `${FRONTMATTER_KEY}: parsed`, '', '---', '', '', '```', ''].join('\n')

src/lang/locale.ts

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
1-
import { LocaleType } from '@univerjs/core'
2-
// import { enUS as UniverDesignEnUS } from '@univerjs/design'
3-
// import { enUS as UniverDocsUIEnUS } from '@univerjs/docs-ui'
4-
// import { enUS as UniverSheetsEnUS } from '@univerjs/sheets'
5-
// import { enUS as UniverSheetsUIEnUS } from '@univerjs/sheets-ui'
6-
// import { enUS as UniverFindReplaceEnUS } from '@univerjs/find-replace'
7-
// import { enUS as UniverSheetsFormulaEnUS } from '@univerjs/sheets-formula'
8-
// import { enUS as UniverSheetsDataValidationEnUS } from '@univerjs/sheets-data-validation'
9-
// import { enUS as UniverUiEnUS } from '@univerjs/ui'
1+
import { LocaleType, Tools } from '@univerjs/core'
2+
import { enUS as UniverDesignEnUS, ruRU as UniverDesignRuRu } from '@univerjs/design'
3+
import { enUS as UniverDocsUIEnUS, ruRU as UniverDocsUIRuRu } from '@univerjs/docs-ui'
4+
import { enUS as UniverSheetsEnUS, ruRU as UniverSheetsRuRu } from '@univerjs/sheets'
5+
import { enUS as UniverSheetsUIEnUS, ruRU as UniverSheetsUIRuRu } from '@univerjs/sheets-ui'
6+
import { enUS as UniverFindReplaceEnUS, ruRU as UniverFindReplaceRuRu } from '@univerjs/find-replace'
7+
import { enUS as UniverSheetsFormulaEnUS, ruRU as UniverSheetsFormulaRuRu } from '@univerjs/sheets-formula'
8+
import { enUS as UniverSheetsDataValidationEnUS, ruRU as UniverSheetsDataValidationRuRu } from '@univerjs/sheets-data-validation'
9+
import { enUS as UniverUiEnUS, ruRU as UniverUiRuRu } from '@univerjs/ui'
1010

11-
// import { ruRU as UniverDesignRuRu } from '@univerjs/design'
12-
// import { ruRU as UniverDocsUIRuRu } from '@univerjs/docs-ui'
13-
// import { ruRU as UniverSheetsRuRu } from '@univerjs/sheets'
14-
// import { ruRU as UniverSheetsUIRuRu } from '@univerjs/sheets-ui'
15-
// import { ruRU as UniverFindReplaceRuRu } from '@univerjs/find-replace'
16-
// import { ruRU as UniverSheetsFormulaRuRu } from '@univerjs/sheets-formula'
17-
// import { ruRU as UniverSheetsDataValidationRuRu } from '@univerjs/sheets-data-validation'
18-
// import { ruRU as UniverUiRuRu } from '@univerjs/ui'
19-
import { enUS, ruRU } from 'univer:locales'
20-
21-
// export const locales = {
22-
// [LocaleType.EN_US]: Tools.deepMerge(
23-
// UniverSheetsEnUS,
24-
// UniverDocsUIEnUS,
25-
// UniverFindReplaceEnUS,
26-
// UniverSheetsUIEnUS,
27-
// UniverSheetsFormulaEnUS,
28-
// UniverSheetsDataValidationEnUS,
29-
// UniverUiEnUS,
30-
// UniverDesignEnUS,
31-
// ),
32-
// [LocaleType.RU_RU]: ruRU,
33-
// }
3411
export const locales = {
35-
[LocaleType.EN_US]: enUS,
36-
[LocaleType.RU_RU]: ruRU,
12+
[LocaleType.EN_US]: Tools.deepMerge(
13+
UniverSheetsEnUS,
14+
UniverDocsUIEnUS,
15+
UniverFindReplaceEnUS,
16+
UniverSheetsUIEnUS,
17+
UniverSheetsFormulaEnUS,
18+
UniverSheetsDataValidationEnUS,
19+
UniverUiEnUS,
20+
UniverDesignEnUS,
21+
),
22+
[LocaleType.RU_RU]: Tools.deepMerge(
23+
UniverDesignRuRu,
24+
UniverDocsUIRuRu,
25+
UniverSheetsRuRu,
26+
UniverSheetsUIRuRu,
27+
UniverFindReplaceRuRu,
28+
UniverSheetsFormulaRuRu,
29+
UniverSheetsDataValidationRuRu,
30+
UniverUiRuRu,
31+
),
3732
}

src/style/univer.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,18 @@ button.univer-button-default {
126126
color: rgb(var(--text-color));
127127
background-color: rgb(var(--bg-color-secondary));
128128
box-shadow: none;
129+
}
130+
131+
.univer-input-number-input {
132+
width: 100%;
133+
height: 100%;
134+
padding: 0;
135+
line-height: 34px;
136+
color: rgb(var(--text-color));
137+
text-align: center;
138+
border: 0;
139+
border-radius: var(--border-radius-base);
140+
outline: 0;
141+
transition: all .15s;
142+
background: rgb(var(--bg-color-secondary));
129143
}

src/utils/data.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ export function extractYAML(str: string): string | null {
3636
export function getExcelData(str: string): IWorkbookData | null {
3737
const markdown = splitYAML(str)?.rest
3838
if (markdown) {
39-
const data: IWorkbookData = JSON.parse(markdown)
40-
if (data)
41-
return data
39+
const json = markdown.replaceAll('```', '')
40+
if (json) {
41+
// console.log("getExcelData-----", json)
42+
const data: IWorkbookData = JSON.parse(json)
43+
if (data)
44+
return data
45+
}
4246
}
4347
return null
4448
}

src/views/excelProView.ts

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1-
import type {
2-
WorkspaceLeaf,
3-
} from 'obsidian'
4-
import {
5-
Notice,
6-
TextFileView,
7-
moment,
8-
} from 'obsidian'
1+
import type { WorkspaceLeaf } from 'obsidian'
2+
import { Notice, TextFileView, moment } from 'obsidian'
93
import { FUniver } from '@univerjs/facade'
10-
import type {
11-
IWorkbookData,
12-
Univer,
13-
Workbook,
14-
} from '@univerjs/core'
15-
import {
16-
LocaleType,
17-
UniverInstanceType,
18-
} from '@univerjs/core'
4+
import type { IWorkbookData, Univer, Workbook } from '@univerjs/core'
5+
import { LocaleType, UniverInstanceType } from '@univerjs/core'
196
import type ExcelProPlugin from '../main'
207

218
import {
229
extractYAML,
10+
getExcelData,
2311
rangeToRangeString,
2412
renderToHtml,
25-
splitYAML,
2613
} from '../utils/data'
2714
import { randomString } from '../utils/uuid'
2815
import { FRONTMATTER, VIEW_TYPE_EXCEL_PRO } from '../common/constants'
@@ -94,12 +81,12 @@ export class ExcelProView extends TextFileView {
9481
dispose() {
9582
// 释放工作簿
9683
if (this.workbook !== null && this.workbook !== undefined)
97-
this.workbook.dispose()
84+
this.workbook.dispose()
9885

9986
// 释放 univer
10087
if (this.univer !== null && this.univer !== undefined) {
101-
this.univer.dispose()
102-
this.univer = null
88+
this.univer.dispose()
89+
this.univer = null
10390
}
10491
}
10592

@@ -134,24 +121,14 @@ export class ExcelProView extends TextFileView {
134121
this.univer = createUniver(id, locale, true)
135122
this.univerAPI = FUniver.newAPI(this.univer)
136123

137-
const markdown = splitYAML(this.data)?.rest
138-
// const data = markdownToJSON(markdown);
139-
if (markdown) {
140-
const data = JSON.parse(markdown)
141-
if (data) {
142-
// workbookData 的内容都包含在 workbook 字段中
143-
const workbookData: IWorkbookData = data
144-
this.workbook = this.univer.createUnit(
145-
UniverInstanceType.UNIVER_SHEET,
146-
workbookData,
147-
)
148-
}
149-
else {
150-
this.workbook = this.univer.createUnit(
151-
UniverInstanceType.UNIVER_SHEET,
152-
{},
153-
)
154-
}
124+
const data = getExcelData(this.data)
125+
if (data) {
126+
// workbookData 的内容都包含在 workbook 字段中
127+
const workbookData: IWorkbookData = data
128+
this.workbook = this.univer.createUnit(
129+
UniverInstanceType.UNIVER_SHEET,
130+
workbookData,
131+
)
155132
}
156133
else {
157134
this.workbook = this.univer.createUnit(
@@ -181,9 +158,7 @@ export class ExcelProView extends TextFileView {
181158
if (!activeWorkbook)
182159
throw new Error('activeWorkbook is not defined')
183160

184-
const activeWorkbookData = JSON.stringify(
185-
activeWorkbook.getSnapshot(),
186-
)
161+
const activeWorkbookData = JSON.stringify(activeWorkbook.getSnapshot())
187162

188163
if (this.lastWorkbookData === null) {
189164
// 第一次加载不处理
@@ -216,7 +191,7 @@ export class ExcelProView extends TextFileView {
216191
}
217192
else {
218193
// 添加 --- 分隔符
219-
header = ['---', '', `${header}`, '', '---', '', ''].join('\n')
194+
header = ['---', '', `${header}`, '', '---', '', '', '```', ''].join('\n')
220195
}
221196

222197
return header
@@ -225,7 +200,7 @@ export class ExcelProView extends TextFileView {
225200
saveDataToFile(data: string) {
226201
const yaml = this.headerData()
227202

228-
this.data = yaml + data
203+
this.data = `${yaml + data}\n\`\`\``
229204

230205
this.save(false)
231206
.then(() => {
@@ -244,8 +219,8 @@ export class ExcelProView extends TextFileView {
244219
this.data = data
245220

246221
this.app.workspace.onLayoutReady(async () => {
247-
// console.log("setViewData", data);
248-
this.setupUniver()
222+
// console.log("setViewData", data);
223+
this.setupUniver()
249224
})
250225
}
251226

styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { copyFile, rename, writeFile } from 'node:fs/promises'
22
import { join, resolve } from 'node:path'
33
import process from 'node:process'
44
import { defineConfig } from 'vite'
5-
import { univerPlugin } from '@univerjs/vite-plugin'
65
import builtins from 'builtin-modules'
76
import dotenv from 'dotenv'
87
import pkg from './package.json'
@@ -45,7 +44,7 @@ export default defineConfig((_) => {
4544
return {
4645
plugins: [
4746
generate(dev),
48-
univerPlugin(),
47+
// univerPlugin()
4948
],
5049
resolve: {
5150
alias: {

0 commit comments

Comments
 (0)