Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add @univerjs-pro/engine-formula
Browse files Browse the repository at this point in the history
hexf00 committed Nov 13, 2024
1 parent d429ee4 commit 164bbf7
Showing 7 changed files with 93 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UNIVER_ENDPOINT=http://127.0.0.1:8000
UNIVER_CLIENT_LICENSE=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -22,3 +22,4 @@ dist-ssr
*.njsproj
*.sln
*.sw?
.env
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -15,10 +15,13 @@
"@univerjs-pro/collaboration-client": "0.5.0-alpha.0",
"@univerjs-pro/edit-history-loader": "0.5.0-alpha.0",
"@univerjs-pro/edit-history-viewer": "0.5.0-alpha.0",
"@univerjs-pro/engine-formula": "0.5.0-alpha.0",
"@univerjs-pro/engine-pivot": "0.5.0-alpha.0",
"@univerjs-pro/exchange-client": "0.5.0-alpha.0",
"@univerjs-pro/license": "0.5.0-alpha.0",
"@univerjs-pro/print": "0.5.0-alpha.0",
"@univerjs-pro/sheets-chart": "0.5.0-alpha.0",
"@univerjs-pro/sheets-chart-ui": "0.5.0-alpha.0",
"@univerjs-pro/sheets-exchange-client": "0.5.0-alpha.0",
"@univerjs-pro/sheets-pivot": "0.5.0-alpha.0",
"@univerjs-pro/sheets-pivot-ui": "0.5.0-alpha.0",
10 changes: 10 additions & 0 deletions src/locale.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,12 @@ import SheetsFindReplaceEnUS from '@univerjs/sheets-find-replace/locale/en-US'
import UniverSheetsFormulaUIPluginEnUs from '@univerjs/sheets-formula-ui/locale/en-US'
import UniverSheetsChartEnUs from '@univerjs-pro/sheets-chart/locale/en-US'
import UniverSheetsChartUiEnUs from '@univerjs-pro/sheets-chart-ui/locale/en-US'
import UniverSheetsDataValidationUiEnUs from '@univerjs/sheets-data-validation-ui/locale/en-US'
import UniverSheetsCrosshairHighlightEnUs from '@univerjs/sheets-crosshair-highlight/locale/en-US'
import UniverSheetsDrawingUiEnUs from '@univerjs/sheets-drawing-ui/locale/en-US'
// eslint-disable-next-line ts/ban-ts-comment
// @ts-ignore
import UniverSheetsFormulaEnUs from '@univerjs/sheets-formula/locale/en-US'

export const locales = {
[LocaleType.EN_US]: Tools.deepMerge(
@@ -45,5 +51,9 @@ export const locales = {
SheetsFindReplaceEnUS,
UniverSheetsChartEnUs,
UniverSheetsChartUiEnUs,
UniverSheetsDataValidationUiEnUs,
UniverSheetsCrosshairHighlightEnUs,
UniverSheetsDrawingUiEnUs,
UniverSheetsFormulaEnUs,
),
}
27 changes: 22 additions & 5 deletions src/setup-univer.ts
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ import { IAuthzIoService, IConfigService, IUndoRedoService, LocaleType, LogLevel
import { defaultTheme } from '@univerjs/design'
import { UniverDocsPlugin } from '@univerjs/docs'
import { UniverDocsUIPlugin } from '@univerjs/docs-ui'
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'
import { UniverRenderEnginePlugin } from '@univerjs/engine-render'
import { UniverSheetsPlugin } from '@univerjs/sheets'
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula'
@@ -64,8 +63,11 @@ import { UniverSheetsDataValidationUIPlugin } from '@univerjs/sheets-data-valida

import { UniverSheetsChartPlugin } from '@univerjs-pro/sheets-chart'
import { UniverSheetsChartUIPlugin } from '@univerjs-pro/sheets-chart-ui'
import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc'

import { HTTPService } from '@univerjs/network'
import workerURL from './worker.ts?worker&url'

import { locales } from './locale'

@@ -99,14 +101,27 @@ export function setupUniver() {
header: true,
footer: true,
})
univer.registerPlugin(UniverSheetsPlugin)

// basic use
// univer.registerPlugin(UniverFormulaEnginePlugin)
// univer.registerPlugin(UniverSheetsPlugin)
// univer.registerPlugin(UniverSheetsFormulaPlugin)

// advanced use: worker and pro formula engine
univer.registerPlugin(UniverRPCMainThreadPlugin, {
workerURL: new Worker(new URL(workerURL, import.meta.url), {
type: 'module',
}),
})
univer.registerPlugin(UniverProFormulaEnginePlugin, { notExecuteFormula: true })
univer.registerPlugin(UniverSheetsPlugin, { notExecuteFormula: true })
univer.registerPlugin(UniverSheetsFormulaPlugin, { notExecuteFormula: true })

univer.registerPlugin(UniverSheetsUIPlugin)
univer.registerPlugin(UniverDocsUIPlugin)

univer.registerPlugin(UniverSheetsNumfmtPlugin)
univer.registerPlugin(UniverSheetsNumfmtUIPlugin)
univer.registerPlugin(UniverFormulaEnginePlugin)
univer.registerPlugin(UniverSheetsFormulaPlugin)
univer.registerPlugin(UniverSheetsFormulaUIPlugin)
univer.registerPlugin(UniverSheetsConditionalFormattingUIPlugin)

@@ -189,7 +204,9 @@ export function setupUniver() {
univer.registerPlugin(UniverSheetsExchangeClientPlugin)

// pivot table
univer.registerPlugin(UniverSheetsPivotTablePlugin)
univer.registerPlugin(UniverSheetsPivotTablePlugin, {
notExecuteFormula: true,
})
univer.registerPlugin(UniverSheetsPivotTableUIPlugin)
univer.registerPlugin(UniverSheetsThreadCommentPlugin)
univer.registerPlugin(UniverSheetsThreadCommentUIPlugin)
31 changes: 31 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { LogLevel, Univer } from '@univerjs/core'
import { UniverProFormulaEnginePlugin } from '@univerjs-pro/engine-formula'
import { UniverRPCWorkerThreadPlugin } from '@univerjs/rpc'
import { UniverSheetsPlugin } from '@univerjs/sheets'
import { UniverRemoteSheetsFormulaPlugin } from '@univerjs/sheets-formula'
import { UniverLicensePlugin } from '@univerjs-pro/license'
import { UniverSheetsPivotTablePlugin } from '@univerjs-pro/sheets-pivot'

// Univer web worker is also a univer application.
const univer = new Univer({
logLevel: LogLevel.VERBOSE,
locales: {},
})

univer.registerPlugin(UniverLicensePlugin, {
// if you want to use the no-limit business feature, you can get 30-day trial license from https://univer.ai/pro/license
// eslint-disable-next-line node/prefer-global/process
license: process.env.UNIVER_CLIENT_LICENSE || 'your license.txt',
})
univer.registerPlugin(UniverSheetsPlugin, { onlyRegisterFormulaRelatedMutations: true })
univer.registerPlugin(UniverProFormulaEnginePlugin)
univer.registerPlugin(UniverRPCWorkerThreadPlugin)
univer.registerPlugin(UniverRemoteSheetsFormulaPlugin)

univer.registerPlugin(UniverSheetsPivotTablePlugin, {
notExecuteFormula: true,
})

// eslint-disable-next-line ts/ban-ts-comment
// @ts-expect-error
globalThis.univer = univer
44 changes: 24 additions & 20 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { defineConfig } from 'vite'
import process from 'node:process'
import { defineConfig, loadEnv } from 'vite'

export default defineConfig({
server: {
cors: true,
proxy: {
'/universer-api': {
target: 'http://127.0.0.1:8000',
changeOrigin: true,
ws: true,
export default ({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return defineConfig({
server: {
cors: true,
proxy: {
'/universer-api': {
target: env.UNIVER_ENDPOINT,
changeOrigin: true,
ws: true,
},
},
},
},
define: {
'process.env.UNIVER_CLIENT_LICENSE': '"%%UNIVER_CLIENT_LICENSE_PLACEHOLDER%%"',
},
base: './',
build: {
rollupOptions: {
output: {
entryFileNames: 'main.js',
define: {
'process.env.UNIVER_CLIENT_LICENSE': `"${env.UNIVER_CLIENT_LICENSE}"` || '"%%UNIVER_CLIENT_LICENSE_PLACEHOLDER%%"',
},
base: './',
build: {
rollupOptions: {
output: {
entryFileNames: 'main.js',
},
},
},
},
})
})
}

0 comments on commit 164bbf7

Please sign in to comment.