From 6195e8b5200f6d6e8f3dde4344b6c6512ef09740 Mon Sep 17 00:00:00 2001
From: Dushusir <1414556676@qq.com>
Date: Tue, 5 Mar 2024 12:22:06 +0800
Subject: [PATCH 1/6] feat(example): add doc uniscript demo
---
examples/esbuild.config.mjs | 8 +-
.../{uniscript => docs-uniscript}/index.html | 2 +-
examples/public/sheets-multi/index.html | 2 +-
examples/public/sheets-uniscript/index.html | 31 ++++++++
examples/public/sheets/index.html | 2 +-
examples/src/docs-uniscript/main.ts | 74 +++++++++++++++++++
examples/src/main.tsx | 11 ++-
.../change-font-style.js | 0
.../china-id-validation.js | 0
.../{uniscript => sheets-uniscript}/data.csv | 0
.../draw-univer-logo.js | 0
.../{uniscript => sheets-uniscript}/main.ts | 0
packages/uniscript/src/controllers/menu.ts | 9 +--
13 files changed, 126 insertions(+), 13 deletions(-)
rename examples/public/{uniscript => docs-uniscript}/index.html (94%)
create mode 100644 examples/public/sheets-uniscript/index.html
create mode 100644 examples/src/docs-uniscript/main.ts
rename examples/src/{uniscript => sheets-uniscript}/change-font-style.js (100%)
rename examples/src/{uniscript => sheets-uniscript}/china-id-validation.js (100%)
rename examples/src/{uniscript => sheets-uniscript}/data.csv (100%)
rename examples/src/{uniscript => sheets-uniscript}/draw-univer-logo.js (100%)
rename examples/src/{uniscript => sheets-uniscript}/main.ts (100%)
diff --git a/examples/esbuild.config.mjs b/examples/esbuild.config.mjs
index 519a500fb67..55bb9e667f2 100644
--- a/examples/esbuild.config.mjs
+++ b/examples/esbuild.config.mjs
@@ -72,14 +72,18 @@ const ctx = await esbuild[args.watch ? 'context' : 'build']({
// sheets-multi
'./src/sheets-multi/main.tsx',
+ // sheets-uniscript
+ './src/sheets-uniscript/main.ts',
+
// docs
'./src/docs/main.ts',
+ // docs-uniscript
+ './src/docs-uniscript/main.ts',
+
// slides
'./src/slides/main.ts',
- // uniscript
- './src/uniscript/main.ts',
],
outdir: './local',
diff --git a/examples/public/uniscript/index.html b/examples/public/docs-uniscript/index.html
similarity index 94%
rename from examples/public/uniscript/index.html
rename to examples/public/docs-uniscript/index.html
index 746774a132a..ceca80978c2 100644
--- a/examples/public/uniscript/index.html
+++ b/examples/public/docs-uniscript/index.html
@@ -3,7 +3,7 @@
- Uniscript
+ Univer Docs Uniscript
diff --git a/examples/public/sheets-multi/index.html b/examples/public/sheets-multi/index.html
index 9091cac93b6..f25beb52d47 100644
--- a/examples/public/sheets-multi/index.html
+++ b/examples/public/sheets-multi/index.html
@@ -3,7 +3,7 @@
- Univer Sheet
+ Univer Sheets Multi Instance
diff --git a/examples/public/sheets-uniscript/index.html b/examples/public/sheets-uniscript/index.html
new file mode 100644
index 00000000000..d46fc634343
--- /dev/null
+++ b/examples/public/sheets-uniscript/index.html
@@ -0,0 +1,31 @@
+
+
+
+
+
+ Univer Sheets Uniscript
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/public/sheets/index.html b/examples/public/sheets/index.html
index 4005a1fceea..c228b9f521f 100644
--- a/examples/public/sheets/index.html
+++ b/examples/public/sheets/index.html
@@ -3,7 +3,7 @@
- Univer Sheet
+ Univer Sheets
diff --git a/examples/src/docs-uniscript/main.ts b/examples/src/docs-uniscript/main.ts
new file mode 100644
index 00000000000..8e4cfbf64c4
--- /dev/null
+++ b/examples/src/docs-uniscript/main.ts
@@ -0,0 +1,74 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { LocaleType, LogLevel, Univer } from '@univerjs/core';
+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 { UniverUIPlugin } from '@univerjs/ui';
+import { UniverUniscriptPlugin } from '@univerjs/uniscript';
+
+import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
+import { UniverSheetsPlugin } from '@univerjs/sheets';
+import { DEFAULT_DOCUMENT_DATA_CN } from '../data';
+
+// univer
+const univer = new Univer({
+ theme: defaultTheme,
+ locale: LocaleType.ZH_CN,
+ logLevel: LogLevel.VERBOSE,
+});
+
+// core plugins
+
+univer.registerPlugin(UniverRenderEnginePlugin);
+univer.registerPlugin(UniverFormulaEnginePlugin);
+univer.registerPlugin(UniverUIPlugin, {
+ container: 'app',
+ header: true,
+ toolbar: true,
+});
+
+univer.registerPlugin(UniverDocsPlugin, {
+ standalone: true,
+});
+univer.registerPlugin(UniverDocsUIPlugin);
+
+univer.registerPlugin(UniverSheetsPlugin);
+univer.registerPlugin(UniverSheetsUIPlugin);
+
+univer.registerPlugin(UniverUniscriptPlugin, {
+ getWorkerUrl(moduleID: string, label: string) {
+ if (label === 'typescript' || label === 'javascript') {
+ return './vs/language/typescript/ts.worker.js';
+ }
+
+ return './vs/editor/editor.worker.js';
+ },
+});
+
+// create univer doc instance
+univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);
+
+declare global {
+ interface Window {
+ univer?: Univer;
+ }
+}
+
+window.univer = univer;
diff --git a/examples/src/main.tsx b/examples/src/main.tsx
index a4cf2bdb226..53a48b4ea28 100644
--- a/examples/src/main.tsx
+++ b/examples/src/main.tsx
@@ -51,12 +51,17 @@ function Examples() {
{' '}
- Univer Multi Instance
+ Univer Sheets Multi Instance
→
{' '}
-
- Uniscript
+
+ Univer Sheets Uniscript
+ →
+ {' '}
+
+
+ Univer Docs Uniscript
→
{' '}
diff --git a/examples/src/uniscript/change-font-style.js b/examples/src/sheets-uniscript/change-font-style.js
similarity index 100%
rename from examples/src/uniscript/change-font-style.js
rename to examples/src/sheets-uniscript/change-font-style.js
diff --git a/examples/src/uniscript/china-id-validation.js b/examples/src/sheets-uniscript/china-id-validation.js
similarity index 100%
rename from examples/src/uniscript/china-id-validation.js
rename to examples/src/sheets-uniscript/china-id-validation.js
diff --git a/examples/src/uniscript/data.csv b/examples/src/sheets-uniscript/data.csv
similarity index 100%
rename from examples/src/uniscript/data.csv
rename to examples/src/sheets-uniscript/data.csv
diff --git a/examples/src/uniscript/draw-univer-logo.js b/examples/src/sheets-uniscript/draw-univer-logo.js
similarity index 100%
rename from examples/src/uniscript/draw-univer-logo.js
rename to examples/src/sheets-uniscript/draw-univer-logo.js
diff --git a/examples/src/uniscript/main.ts b/examples/src/sheets-uniscript/main.ts
similarity index 100%
rename from examples/src/uniscript/main.ts
rename to examples/src/sheets-uniscript/main.ts
diff --git a/packages/uniscript/src/controllers/menu.ts b/packages/uniscript/src/controllers/menu.ts
index 6f468b694f5..b7f00a3a67f 100644
--- a/packages/uniscript/src/controllers/menu.ts
+++ b/packages/uniscript/src/controllers/menu.ts
@@ -14,10 +14,8 @@
* limitations under the License.
*/
-import { UniverInstanceType } from '@univerjs/core';
-import { getCurrentSheetDisabled$ } from '@univerjs/sheets';
import type { IMenuButtonItem } from '@univerjs/ui';
-import { getMenuHiddenObservable, MenuItemType, MenuPosition } from '@univerjs/ui';
+import { MenuItemType, MenuPosition } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
import { ToggleScriptPanelOperation } from '../commands/operations/panel.operation';
@@ -30,7 +28,8 @@ export function UniscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
icon: 'CodeSingle',
type: MenuItemType.BUTTON,
positions: [MenuPosition.TOOLBAR_START],
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
- disabled$: getCurrentSheetDisabled$(accessor),
+ // FIXME@wendellhu: hidden$ and disabled$ are not correctly in doc
+ // hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
+ // disabled$: getCurrentSheetDisabled$(accessor),
};
}
From 33c68902462beb2cdb162b6fbeb92e793a4c65d7 Mon Sep 17 00:00:00 2001
From: Dushusir <1414556676@qq.com>
Date: Tue, 5 Mar 2024 12:26:31 +0800
Subject: [PATCH 2/6] feat(example): use univer api in doc uniscript
---
examples/package.json | 1 +
examples/src/docs-uniscript/main.ts | 3 +
pnpm-lock.yaml | 107 +++++++++++++++++++++++++++-
3 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/examples/package.json b/examples/package.json
index 41c6ce00aa2..76c5086f9ba 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -16,6 +16,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
+ "@univerjs/facade": "workspace:*",
"@univerjs/find-replace": "workspace:*",
"@univerjs/icons": "^0.1.30",
"@univerjs/rpc": "workspace:*",
diff --git a/examples/src/docs-uniscript/main.ts b/examples/src/docs-uniscript/main.ts
index 8e4cfbf64c4..fd9e6424b21 100644
--- a/examples/src/docs-uniscript/main.ts
+++ b/examples/src/docs-uniscript/main.ts
@@ -25,6 +25,7 @@ import { UniverUniscriptPlugin } from '@univerjs/uniscript';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import { UniverSheetsPlugin } from '@univerjs/sheets';
+import { FUniver } from '@univerjs/facade';
import { DEFAULT_DOCUMENT_DATA_CN } from '../data';
// univer
@@ -65,6 +66,8 @@ univer.registerPlugin(UniverUniscriptPlugin, {
// create univer doc instance
univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);
+const univerAPI = FUniver.newAPI(univer);
+
declare global {
interface Window {
univer?: Univer;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3e83e4c6b69..6f85911962a 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -198,6 +198,9 @@ importers:
'@univerjs/engine-render':
specifier: workspace:*
version: link:../packages/engine-render
+ '@univerjs/facade':
+ specifier: workspace:*
+ version: link:../packages/facade
'@univerjs/find-replace':
specifier: workspace:*
version: link:../packages/find-replace
@@ -4142,7 +4145,7 @@ packages:
resolution: {integrity: sha512-5HGgegON/aBu/tDM3IFyEAZfaMmG98Y0OI48kkkc9EipfQRMIrYFizbCjV7388H98wM81TqTEqvzxYpFkPSphg==}
engines: {node: '>=18'}
dependencies:
- '@storybook/core-common': 8.0.0-rc.1
+ '@storybook/core-common': 8.0.0-rc.2
'@swc/core': 1.4.2
swc-loader: 0.2.6(@swc/core@1.4.2)(webpack@5.90.3)
transitivePeerDependencies:
@@ -4291,6 +4294,17 @@ packages:
telejson: 7.2.0
tiny-invariant: 1.3.1
+ /@storybook/channels@8.0.0-rc.2:
+ resolution: {integrity: sha512-Gb7lVLKPHpdCGNMvAF4Zrr5QNrjlRgDXTC1AxjfJtJcZw4BsCfmLiPbQVltCrIFHgtPbxXB20gCCtYcE4M6k7Q==}
+ dependencies:
+ '@storybook/client-logger': 8.0.0-rc.2
+ '@storybook/core-events': 8.0.0-rc.2
+ '@storybook/global': 5.0.0
+ qs: 6.11.2
+ telejson: 7.2.0
+ tiny-invariant: 1.3.3
+ dev: false
+
/@storybook/cli@8.0.0-rc.1(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-B7XebUK63lhScJO+U9XNA3y98MYR4K98zkijYkH3xe5eKjd17aa4hr1VszmKJbsgs8dzP0ZZpcp5MlKrCKZR+w==}
hasBin: true
@@ -4352,6 +4366,12 @@ packages:
dependencies:
'@storybook/global': 5.0.0
+ /@storybook/client-logger@8.0.0-rc.2:
+ resolution: {integrity: sha512-T5HhSJUDnOKhpgPiogCEGvW9KATVWfKDBlDbh0/MBmVBR0tqGpFVLefGAM7wmRoVg3MVIeQRRtzMv02PYFxJDg==}
+ dependencies:
+ '@storybook/global': 5.0.0
+ dev: false
+
/@storybook/codemod@8.0.0-rc.1:
resolution: {integrity: sha512-5GDCci06/lddHZo9Bxq488p0BuQpu6IFQ1J1/QRgbrNMJcPFv+D7B9nwtgQ+cdi3XNzc7RuMJLjMyyCf2entGw==}
dependencies:
@@ -4430,6 +4450,42 @@ packages:
- encoding
- supports-color
+ /@storybook/core-common@8.0.0-rc.2:
+ resolution: {integrity: sha512-31B/kUzpH/TP3yVmv3g5UlnuJ0rR7dBPIB5qaKsDx/ygpG9sm4xhXFHGZWU8Nqshu2MREuPQYI2UPELF+luUug==}
+ dependencies:
+ '@storybook/core-events': 8.0.0-rc.2
+ '@storybook/csf-tools': 8.0.0-rc.2
+ '@storybook/node-logger': 8.0.0-rc.2
+ '@storybook/types': 8.0.0-rc.2
+ '@yarnpkg/fslib': 2.10.3
+ '@yarnpkg/libzip': 2.3.0
+ chalk: 4.1.2
+ cross-spawn: 7.0.3
+ esbuild: 0.18.20
+ esbuild-register: 3.5.0(esbuild@0.18.20)
+ execa: 5.1.1
+ file-system-cache: 2.3.0
+ find-cache-dir: 3.3.2
+ find-up: 5.0.0
+ fs-extra: 11.2.0
+ glob: 10.3.10
+ handlebars: 4.7.8
+ lazy-universal-dotenv: 4.0.0
+ node-fetch: 2.7.0
+ picomatch: 2.3.1
+ pkg-dir: 5.0.0
+ pretty-hrtime: 1.0.3
+ resolve-from: 5.0.0
+ semver: 7.6.0
+ tempy: 1.0.1
+ tiny-invariant: 1.3.1
+ ts-dedent: 2.2.0
+ util: 0.12.5
+ transitivePeerDependencies:
+ - encoding
+ - supports-color
+ dev: false
+
/@storybook/core-events@7.6.17:
resolution: {integrity: sha512-AriWMCm/k1cxlv10f+jZ1wavThTRpLaN3kY019kHWbYT9XgaSuLU67G7GPr3cGnJ6HuA6uhbzu8qtqVCd6OfXA==}
dependencies:
@@ -4441,6 +4497,12 @@ packages:
dependencies:
ts-dedent: 2.2.0
+ /@storybook/core-events@8.0.0-rc.2:
+ resolution: {integrity: sha512-SQ/vcAbRJCuywQDiBsKZDXRbqbTEcQQlDOdzoDtV9jjfPhcIShB4BMhUmoTkR5OJAImHmTYm5gOXvYMXo97IEQ==}
+ dependencies:
+ ts-dedent: 2.2.0
+ dev: false
+
/@storybook/core-server@8.0.0-rc.1(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-q5wgVPJS7i+lN0lpDvxrzICkw1ewGYgbpWlvp9bShObHctH2oPjjAAEB1DdyFLCPDmkokyygpM/iBBWW3oP3Pw==}
dependencies:
@@ -4533,6 +4595,22 @@ packages:
transitivePeerDependencies:
- supports-color
+ /@storybook/csf-tools@8.0.0-rc.2:
+ resolution: {integrity: sha512-IwYQEwXvm3P1DzDPzxhcqQ+xcoLj6DGfgQaHLeIrmmUtpVEA8am5mAgqfKUqd55RuaBYFh78qfTLMEL3dJBSBw==}
+ dependencies:
+ '@babel/generator': 7.23.6
+ '@babel/parser': 7.23.9
+ '@babel/traverse': 7.23.9
+ '@babel/types': 7.23.9
+ '@storybook/csf': 0.1.2
+ '@storybook/types': 8.0.0-rc.2
+ fs-extra: 11.2.0
+ recast: 0.23.5
+ ts-dedent: 2.2.0
+ transitivePeerDependencies:
+ - supports-color
+ dev: false
+
/@storybook/csf@0.1.2:
resolution: {integrity: sha512-ePrvE/pS1vsKR9Xr+o+YwdqNgHUyXvg+1Xjx0h9LrVx7Zq4zNe06pd63F5EvzTbCbJsHj7GHr9tkiaqm7U8WRA==}
dependencies:
@@ -4603,6 +4681,10 @@ packages:
/@storybook/node-logger@8.0.0-rc.1:
resolution: {integrity: sha512-WFIK9NRclmSepPsTmVOcxzVGv/yyjAckiL3Z/iV2idwP4Qj/TT/FGFGAPs7oGSiQfgP80FMifDFN6tcZ0awpYQ==}
+ /@storybook/node-logger@8.0.0-rc.2:
+ resolution: {integrity: sha512-jL2bF9BkD9kNELlt5zW1fTB6OI3Ue47ob8j6AtgeB32FW1idheycRzzGCNgZTVBhcKsdSIIg5D49cTadpjJHbQ==}
+ dev: false
+
/@storybook/preset-react-webpack@8.0.0-rc.1(@swc/core@1.4.2)(esbuild@0.18.20)(react-dom@18.2.0)(react@18.2.0)(typescript@5.3.3):
resolution: {integrity: sha512-LbxngVsSAAKjMd4AtYROiLyaJ8tk22EuOIEPQ5r+dpcv92nTWLc7NHe83LrWAvxKizb0G1+T5QLLK7ZOjSKvKA==}
engines: {node: '>=18.0.0'}
@@ -4815,6 +4897,14 @@ packages:
'@types/express': 4.17.21
file-system-cache: 2.3.0
+ /@storybook/types@8.0.0-rc.2:
+ resolution: {integrity: sha512-xzj7l/54hPMLLxT3CyBJhCNSpfPNpyxsStNEb9zTSZXTu4xxRTPy09oJ1psSpJeMcG71bTAo6ElPxMVvBENP4w==}
+ dependencies:
+ '@storybook/channels': 8.0.0-rc.2
+ '@types/express': 4.17.21
+ file-system-cache: 2.3.0
+ dev: false
+
/@stylistic/eslint-plugin-js@1.6.2(eslint@8.57.0):
resolution: {integrity: sha512-ndT6X2KgWGxv8101pdMOxL8pihlYIHcOv3ICd70cgaJ9exwkPn8hJj4YQwslxoAlre1TFHnXd/G1/hYXgDrjIA==}
engines: {node: ^16.0.0 || >=18.0.0}
@@ -12052,6 +12142,17 @@ packages:
source-map: 0.6.1
tslib: 2.6.2
+ /recast@0.23.5:
+ resolution: {integrity: sha512-M67zIddJiwXdfPQRYKJ0qZO1SLdH1I0hYeb0wzxA+pNOvAZiQHulWzuk+fYsEWRQ8VfZrgjyucqsCOtCyM01/A==}
+ engines: {node: '>= 4'}
+ dependencies:
+ ast-types: 0.16.1
+ esprima: 4.0.1
+ source-map: 0.6.1
+ tiny-invariant: 1.3.3
+ tslib: 2.6.2
+ dev: false
+
/rechoir@0.6.2:
resolution: {integrity: sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==}
engines: {node: '>= 0.10'}
@@ -13105,6 +13206,10 @@ packages:
/tiny-invariant@1.3.1:
resolution: {integrity: sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw==}
+ /tiny-invariant@1.3.3:
+ resolution: {integrity: sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==}
+ dev: false
+
/tinybench@2.6.0:
resolution: {integrity: sha512-N8hW3PG/3aOoZAN5V/NSAEDz0ZixDSSt5b/a05iqtpgfLWMSVuCo7w0k2vVvEjdrIoeGqZzweX2WlyioNIHchA==}
From 641152b5707427efe496c041b1a68dc729028eab Mon Sep 17 00:00:00 2001
From: Dushusir <1414556676@qq.com>
Date: Tue, 5 Mar 2024 14:16:52 +0800
Subject: [PATCH 3/6] feat(facade): add appendText api
---
examples/src/docs-uniscript/main.ts | 3 -
packages/facade/package.json | 2 +
packages/facade/src/apis/docs/f-document.ts | 102 ++++++++++++++++++
packages/facade/src/apis/facade.ts | 66 ++++++++++--
.../__tests__/create-test-bed.ts | 0
.../__tests__/f-range.spec.ts | 0
.../{sheet => sheets}/__tests__/utils.spec.ts | 0
.../src/apis/{sheet => sheets}/f-range.ts | 0
.../src/apis/{sheet => sheets}/f-selection.ts | 0
.../src/apis/{sheet => sheets}/f-workbook.ts | 0
.../src/apis/{sheet => sheets}/f-worksheet.ts | 0
.../src/apis/{sheet => sheets}/utils.ts | 0
packages/facade/src/index.ts | 10 +-
packages/uniscript/src/controllers/menu.ts | 2 +-
pnpm-lock.yaml | 5 +-
15 files changed, 174 insertions(+), 16 deletions(-)
create mode 100644 packages/facade/src/apis/docs/f-document.ts
rename packages/facade/src/apis/{sheet => sheets}/__tests__/create-test-bed.ts (100%)
rename packages/facade/src/apis/{sheet => sheets}/__tests__/f-range.spec.ts (100%)
rename packages/facade/src/apis/{sheet => sheets}/__tests__/utils.spec.ts (100%)
rename packages/facade/src/apis/{sheet => sheets}/f-range.ts (100%)
rename packages/facade/src/apis/{sheet => sheets}/f-selection.ts (100%)
rename packages/facade/src/apis/{sheet => sheets}/f-workbook.ts (100%)
rename packages/facade/src/apis/{sheet => sheets}/f-worksheet.ts (100%)
rename packages/facade/src/apis/{sheet => sheets}/utils.ts (100%)
diff --git a/examples/src/docs-uniscript/main.ts b/examples/src/docs-uniscript/main.ts
index fd9e6424b21..8e4cfbf64c4 100644
--- a/examples/src/docs-uniscript/main.ts
+++ b/examples/src/docs-uniscript/main.ts
@@ -25,7 +25,6 @@ import { UniverUniscriptPlugin } from '@univerjs/uniscript';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import { UniverSheetsPlugin } from '@univerjs/sheets';
-import { FUniver } from '@univerjs/facade';
import { DEFAULT_DOCUMENT_DATA_CN } from '../data';
// univer
@@ -66,8 +65,6 @@ univer.registerPlugin(UniverUniscriptPlugin, {
// create univer doc instance
univer.createUniverDoc(DEFAULT_DOCUMENT_DATA_CN);
-const univerAPI = FUniver.newAPI(univer);
-
declare global {
interface Window {
univer?: Univer;
diff --git a/packages/facade/package.json b/packages/facade/package.json
index fd38d2a70a9..38b77cf1662 100644
--- a/packages/facade/package.json
+++ b/packages/facade/package.json
@@ -62,6 +62,7 @@
},
"peerDependencies": {
"@univerjs/core": "workspace:*",
+ "@univerjs/docs": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
@@ -72,6 +73,7 @@
"dependencies": {},
"devDependencies": {
"@univerjs/core": "workspace:*",
+ "@univerjs/docs": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/shared": "workspace:*",
diff --git a/packages/facade/src/apis/docs/f-document.ts b/packages/facade/src/apis/docs/f-document.ts
new file mode 100644
index 00000000000..d0b23d1b59e
--- /dev/null
+++ b/packages/facade/src/apis/docs/f-document.ts
@@ -0,0 +1,102 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { DocumentDataModel, IDocumentData } from '@univerjs/core';
+import {
+ ICommandService,
+ IUniverInstanceService,
+ RedoCommand,
+ UndoCommand,
+} from '@univerjs/core';
+import { InsertCommand } from '@univerjs/docs';
+
+export class FDocument {
+ readonly id: string;
+
+ constructor(
+ private readonly _documentDataModel: DocumentDataModel,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @ICommandService private readonly _commandService: ICommandService
+ ) {
+ this.id = this._documentDataModel.getUnitId();
+ }
+
+ getId(): string {
+ return this._documentDataModel.getUnitId();
+ }
+
+ getName(): string {
+ return this.getSnapshot().title || '';
+ }
+
+ getSnapshot(): IDocumentData {
+ return this._documentDataModel.getSnapshot();
+ }
+
+ undo(): Promise {
+ this._univerInstanceService.focusUniverInstance(this.id);
+ return this._commandService.executeCommand(UndoCommand.id);
+ }
+
+ redo(): Promise {
+ this._univerInstanceService.focusUniverInstance(this.id);
+ return this._commandService.executeCommand(RedoCommand.id);
+ }
+
+ /**
+ * Adds the specified text to the end of this text region.
+ * @param text
+ */
+ appendText(text: string): void {
+ const unitId = this.id;
+
+ const { body } = this.getSnapshot();
+
+ if (!body) {
+ throw new Error('The document body is empty');
+ }
+
+ const lastPosition = body.dataStream.length - 2;
+
+ const activeRange = {
+ startOffset: lastPosition,
+ endOffset: lastPosition,
+ collapsed: true,
+ segmentId: '',
+ };
+
+ const { startOffset, segmentId } = activeRange;
+
+ const len = text.length;
+
+ const textRanges = [
+ {
+ startOffset: startOffset + len,
+ endOffset: startOffset + len,
+ },
+ ];
+
+ this._commandService.executeCommand(InsertCommand.id, {
+ unitId,
+ body: {
+ dataStream: text,
+ },
+ range: activeRange,
+ textRanges,
+ segmentId,
+ });
+ }
+}
diff --git a/packages/facade/src/apis/facade.ts b/packages/facade/src/apis/facade.ts
index 4ed893a9397..8f3ea17ff22 100644
--- a/packages/facade/src/apis/facade.ts
+++ b/packages/facade/src/apis/facade.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { CommandListener, IExecutionOptions, IWorkbookData } from '@univerjs/core';
+import type { CommandListener, IDocumentData, IExecutionOptions, IWorkbookData } from '@univerjs/core';
import {
BorderStyleTypes,
ICommandService,
@@ -25,11 +25,12 @@ import {
} from '@univerjs/core';
import { ISocketService, WebSocketService } from '@univerjs/network';
import type { IRegisterFunctionParams, IUnregisterFunctionParams } from '@univerjs/sheets-formula';
-import { IRegisterFunctionService } from '@univerjs/sheets-formula';
+import { IRegisterFunctionService, RegisterFunctionService } from '@univerjs/sheets-formula';
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector, Quantity } from '@wendellhu/redi';
-import { FWorkbook } from './sheet/f-workbook';
+import { FWorkbook } from './sheets/f-workbook';
+import { FDocument } from './docs/f-document';
export class FUniver {
/**
@@ -53,7 +54,7 @@ export class FUniver {
@Inject(Injector) private readonly _injector: Injector,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@ICommandService private readonly _commandService: ICommandService,
- @IRegisterFunctionService private readonly _registerFunctionService: IRegisterFunctionService,
+ // @IRegisterFunctionService private readonly _registerFunctionService: IRegisterFunctionService,
@ISocketService private readonly _ws: ISocketService
) {}
@@ -67,6 +68,16 @@ export class FUniver {
return this._injector.createInstance(FWorkbook, workbook);
}
+ /**
+ * Create a new document and get the API handler of that document.
+ * @param data the snapshot of the document.
+ * @returns Document API instance.
+ */
+ createUniverDoc(data: Partial): FDocument {
+ const document = this._univerInstanceService.createDoc(data);
+ return this._injector.createInstance(FDocument, document);
+ }
+
/**
* Get the spreadsheet API handler by the spreadsheet id.
* @param id the spreadsheet id.
@@ -81,6 +92,20 @@ export class FUniver {
return this._injector.createInstance(FWorkbook, workbook);
}
+ /**
+ * Get the document API handler by the document id.
+ * @param id the document id.
+ * @returns Document API instance.
+ */
+ getUniverDoc(id: string): FDocument | null {
+ const document = this._univerInstanceService.getUniverDocInstance(id);
+ if (!document) {
+ return null;
+ }
+
+ return this._injector.createInstance(FDocument, document);
+ }
+
/**
* Get the currently focused Univer spreadsheet.
* @returns the currently focused Univer spreadsheet.
@@ -94,20 +119,49 @@ export class FUniver {
return this._injector.createInstance(FWorkbook, workbook);
}
+ /**
+ * Get the currently focused Univer document.
+ * @returns the currently focused Univer document.
+ */
+ getActiveDocument(): FDocument | null {
+ const document = this._univerInstanceService.getCurrentUniverDocInstance();
+ if (!document) {
+ return null;
+ }
+
+ return this._injector.createInstance(FDocument, document);
+ }
+
/**
* Register a function to the spreadsheet.
* @param config
*/
registerFunction(config: IRegisterFunctionParams) {
- this._registerFunctionService.registerFunctions(config);
+ let registerFunctionService = this._injector.get(IRegisterFunctionService);
+
+ if (!registerFunctionService) {
+ this._injector.add([IRegisterFunctionService, { useClass: RegisterFunctionService }]);
+ registerFunctionService = this._injector.get(IRegisterFunctionService);
+ }
+
+ registerFunctionService.registerFunctions(config);
}
/**
* Unregister a function from the spreadsheet.
+ *
+ * TODO@Dushusir: remove unregister,use IDisposable
* @param config
*/
unregisterFunction(config: IUnregisterFunctionParams) {
- this._registerFunctionService.unregisterFunctions(config);
+ let registerFunctionService = this._injector.get(IRegisterFunctionService);
+
+ if (!registerFunctionService) {
+ this._injector.add([IRegisterFunctionService, { useClass: RegisterFunctionService }]);
+ registerFunctionService = this._injector.get(IRegisterFunctionService);
+ }
+
+ registerFunctionService.unregisterFunctions(config);
}
// #region
diff --git a/packages/facade/src/apis/sheet/__tests__/create-test-bed.ts b/packages/facade/src/apis/sheets/__tests__/create-test-bed.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/__tests__/create-test-bed.ts
rename to packages/facade/src/apis/sheets/__tests__/create-test-bed.ts
diff --git a/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts b/packages/facade/src/apis/sheets/__tests__/f-range.spec.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/__tests__/f-range.spec.ts
rename to packages/facade/src/apis/sheets/__tests__/f-range.spec.ts
diff --git a/packages/facade/src/apis/sheet/__tests__/utils.spec.ts b/packages/facade/src/apis/sheets/__tests__/utils.spec.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/__tests__/utils.spec.ts
rename to packages/facade/src/apis/sheets/__tests__/utils.spec.ts
diff --git a/packages/facade/src/apis/sheet/f-range.ts b/packages/facade/src/apis/sheets/f-range.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/f-range.ts
rename to packages/facade/src/apis/sheets/f-range.ts
diff --git a/packages/facade/src/apis/sheet/f-selection.ts b/packages/facade/src/apis/sheets/f-selection.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/f-selection.ts
rename to packages/facade/src/apis/sheets/f-selection.ts
diff --git a/packages/facade/src/apis/sheet/f-workbook.ts b/packages/facade/src/apis/sheets/f-workbook.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/f-workbook.ts
rename to packages/facade/src/apis/sheets/f-workbook.ts
diff --git a/packages/facade/src/apis/sheet/f-worksheet.ts b/packages/facade/src/apis/sheets/f-worksheet.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/f-worksheet.ts
rename to packages/facade/src/apis/sheets/f-worksheet.ts
diff --git a/packages/facade/src/apis/sheet/utils.ts b/packages/facade/src/apis/sheets/utils.ts
similarity index 100%
rename from packages/facade/src/apis/sheet/utils.ts
rename to packages/facade/src/apis/sheets/utils.ts
diff --git a/packages/facade/src/index.ts b/packages/facade/src/index.ts
index b365b6aa011..dd8dc6bfec9 100644
--- a/packages/facade/src/index.ts
+++ b/packages/facade/src/index.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-export type { FontLine, FontStyle, FontWeight } from './apis/sheet/f-range';
+export type { FontLine, FontStyle, FontWeight } from './apis/sheets/f-range';
export { FUniver } from './apis/facade';
-export { FRange } from './apis/sheet/f-range';
-export { FSelection } from './apis/sheet/f-selection';
-export { FWorkbook } from './apis/sheet/f-workbook';
-export { FWorksheet } from './apis/sheet/f-worksheet';
+export { FRange } from './apis/sheets/f-range';
+export { FSelection } from './apis/sheets/f-selection';
+export { FWorkbook } from './apis/sheets/f-workbook';
+export { FWorksheet } from './apis/sheets/f-worksheet';
diff --git a/packages/uniscript/src/controllers/menu.ts b/packages/uniscript/src/controllers/menu.ts
index b7f00a3a67f..b8458f7d855 100644
--- a/packages/uniscript/src/controllers/menu.ts
+++ b/packages/uniscript/src/controllers/menu.ts
@@ -28,7 +28,7 @@ export function UniscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
icon: 'CodeSingle',
type: MenuItemType.BUTTON,
positions: [MenuPosition.TOOLBAR_START],
- // FIXME@wendellhu: hidden$ and disabled$ are not correctly in doc
+ // FIXME hidden$ and disabled$ are not correctly in doc
// hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
// disabled$: getCurrentSheetDisabled$(accessor),
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6f85911962a..943e33b385f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -576,6 +576,9 @@ importers:
'@univerjs/core':
specifier: workspace:*
version: link:../core
+ '@univerjs/docs':
+ specifier: workspace:*
+ version: link:../docs
'@univerjs/engine-formula':
specifier: workspace:*
version: link:../engine-formula
@@ -4478,7 +4481,7 @@ packages:
resolve-from: 5.0.0
semver: 7.6.0
tempy: 1.0.1
- tiny-invariant: 1.3.1
+ tiny-invariant: 1.3.3
ts-dedent: 2.2.0
util: 0.12.5
transitivePeerDependencies:
From 4f40ac12736fa24d78351db7b0a99804e5d30242 Mon Sep 17 00:00:00 2001
From: Dushusir <1414556676@qq.com>
Date: Tue, 5 Mar 2024 15:02:59 +0800
Subject: [PATCH 4/6] test(facade): document appendText test
---
packages/facade/package.json | 2 +
.../apis/docs/__tests__/create-test-bed.ts | 120 ++++++++++++++++++
.../apis/docs/__tests__/f-document.spec.ts | 49 +++++++
.../mock-text-selection-render-manager.ts | 32 +++++
packages/facade/src/apis/docs/f-document.ts | 4 +-
pnpm-lock.yaml | 3 +
6 files changed, 208 insertions(+), 2 deletions(-)
create mode 100644 packages/facade/src/apis/docs/__tests__/create-test-bed.ts
create mode 100644 packages/facade/src/apis/docs/__tests__/f-document.spec.ts
create mode 100644 packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts
diff --git a/packages/facade/package.json b/packages/facade/package.json
index 38b77cf1662..427f5d85487 100644
--- a/packages/facade/package.json
+++ b/packages/facade/package.json
@@ -63,6 +63,7 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/docs": "workspace:*",
+ "@univerjs/engine-render": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
@@ -75,6 +76,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/docs": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
+ "@univerjs/engine-render": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
diff --git a/packages/facade/src/apis/docs/__tests__/create-test-bed.ts b/packages/facade/src/apis/docs/__tests__/create-test-bed.ts
new file mode 100644
index 00000000000..d877bd44d7e
--- /dev/null
+++ b/packages/facade/src/apis/docs/__tests__/create-test-bed.ts
@@ -0,0 +1,120 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { DocumentDataModel, IDocumentData } from '@univerjs/core';
+import {
+ ILogService,
+ IUniverInstanceService,
+ LocaleService,
+ LogLevel,
+ Plugin,
+ PluginType,
+ Univer,
+} from '@univerjs/core';
+import {
+ enUS,
+ zhCN,
+} from '@univerjs/sheets-formula';
+import type { Dependency } from '@wendellhu/redi';
+import { Inject, Injector } from '@wendellhu/redi';
+
+import { DocStateChangeManagerService, DocViewModelManagerService, IMEInputManagerService, TextSelectionManagerService } from '@univerjs/docs';
+
+import { ITextSelectionRenderManager, TextSelectionRenderManager } from '@univerjs/engine-render';
+import { FUniver } from '../../facade';
+
+function getTestDocumentDataDemo(): IDocumentData {
+ return {
+ id: 'test',
+ body: {
+ dataStream: 'Hello,\r\n',
+ },
+ documentStyle: {
+ pageSize: {
+ width: 594.3,
+ height: 840.51,
+ },
+ marginTop: 72,
+ marginBottom: 72,
+ marginRight: 90,
+ marginLeft: 90,
+ },
+ };
+}
+
+export interface ITestBed {
+ univer: Univer;
+ get: Injector['get'];
+ doc: DocumentDataModel;
+ univerAPI: FUniver;
+}
+
+export function createTestBed(documentConfig?: IDocumentData, dependencies?: Dependency[]): ITestBed {
+ const univer = new Univer();
+ const injector = univer.__getInjector();
+
+ class TestSpyPlugin extends Plugin {
+ static override type = PluginType.Univer;
+
+ constructor(
+ _config: undefined,
+ @Inject(Injector) override readonly _injector: Injector
+ ) {
+ super('test-plugin');
+
+ this._injector = _injector;
+ }
+
+ override onStarting(injector: Injector): void {
+ injector.add([TextSelectionManagerService]);
+ injector.add([DocViewModelManagerService]);
+ injector.add([DocStateChangeManagerService]);
+ injector.add([IMEInputManagerService]);
+ injector.add([ITextSelectionRenderManager, { useClass: TextSelectionRenderManager }]);
+ // injector.add([
+ // IDescriptionService,
+ // {
+ // useFactory: () => this._injector.createInstance(DescriptionService, undefined),
+ // },
+ // ]);
+ // injector.add([IFunctionService, { useClass: FunctionService }]);
+ // injector.add([IFormulaCustomFunctionService, { useClass: FormulaCustomFunctionService }]);
+ // injector.add([ISocketService, { useClass: WebSocketService }]);
+
+ dependencies?.forEach((d) => injector.add(d));
+ }
+ }
+
+ injector.get(LocaleService).load({ zhCN, enUS });
+
+ univer.registerPlugin(TestSpyPlugin);
+ const doc = univer.createUniverDoc(documentConfig || getTestDocumentDataDemo());
+
+ const univerInstanceService = injector.get(IUniverInstanceService);
+ univerInstanceService.focusUniverInstance('test');
+ const logService = injector.get(ILogService);
+
+ logService.setLogLevel(LogLevel.SILENT); // change this to `LogLevel.VERBOSE` to debug tests via logs
+
+ const univerAPI = FUniver.newAPI(injector);
+
+ return {
+ univer,
+ get: injector.get.bind(injector),
+ doc,
+ univerAPI,
+ };
+}
diff --git a/packages/facade/src/apis/docs/__tests__/f-document.spec.ts b/packages/facade/src/apis/docs/__tests__/f-document.spec.ts
new file mode 100644
index 00000000000..5faa498f356
--- /dev/null
+++ b/packages/facade/src/apis/docs/__tests__/f-document.spec.ts
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { ICommandService } from '@univerjs/core';
+import type { Injector } from '@wendellhu/redi';
+import { beforeEach, describe, expect, it } from 'vitest';
+
+import { InsertCommand, RichTextEditingMutation } from '@univerjs/docs';
+import type { FUniver } from '../../facade';
+import { createTestBed } from './create-test-bed';
+
+describe('Test FDocument', () => {
+ let get: Injector['get'];
+ let commandService: ICommandService;
+ let univerAPI: FUniver;
+
+ beforeEach(() => {
+ const testBed = createTestBed();
+ get = testBed.get;
+ univerAPI = testBed.univerAPI;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(InsertCommand);
+ commandService.registerCommand(RichTextEditingMutation as any);
+ });
+
+ it('Document appendText', async () => {
+ const activeDoc = univerAPI.getActiveDocument();
+
+ expect(await activeDoc?.appendText('Univer')).toBeTruthy();
+
+ const dataStream = activeDoc?.getSnapshot().body?.dataStream;
+
+ expect(dataStream?.substring(0, dataStream.length - 2)).toEqual('Hello,Univer');
+ });
+});
diff --git a/packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts b/packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts
new file mode 100644
index 00000000000..506084e39cf
--- /dev/null
+++ b/packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { Nullable } from '@univerjs/core';
+import type { ITextSelectionInnerParam } from '@univerjs/engine-render';
+import { createIdentifier } from '@wendellhu/redi';
+import { BehaviorSubject } from 'rxjs';
+
+export class TextSelectionRenderManager {
+ private readonly _textSelectionInner$ = new BehaviorSubject>(null);
+
+ readonly textSelectionInner$ = this._textSelectionInner$.asObservable();
+ removeAllTextRanges() {}
+ addTextRanges() {}
+}
+
+export const ITextSelectionRenderManager = createIdentifier(
+ 'mock.univer.doc.text-selection-render-manager'
+);
diff --git a/packages/facade/src/apis/docs/f-document.ts b/packages/facade/src/apis/docs/f-document.ts
index d0b23d1b59e..a77b1e6bbc8 100644
--- a/packages/facade/src/apis/docs/f-document.ts
+++ b/packages/facade/src/apis/docs/f-document.ts
@@ -60,7 +60,7 @@ export class FDocument {
* Adds the specified text to the end of this text region.
* @param text
*/
- appendText(text: string): void {
+ appendText(text: string): Promise {
const unitId = this.id;
const { body } = this.getSnapshot();
@@ -89,7 +89,7 @@ export class FDocument {
},
];
- this._commandService.executeCommand(InsertCommand.id, {
+ return this._commandService.executeCommand(InsertCommand.id, {
unitId,
body: {
dataStream: text,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 943e33b385f..284e0acdf02 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -582,6 +582,9 @@ importers:
'@univerjs/engine-formula':
specifier: workspace:*
version: link:../engine-formula
+ '@univerjs/engine-render':
+ specifier: workspace:*
+ version: link:../engine-render
'@univerjs/network':
specifier: workspace:*
version: link:../network
From c8d38a508d5921a396fd4f5062db55ad0b820509 Mon Sep 17 00:00:00 2001
From: Dushusir <1414556676@qq.com>
Date: Tue, 5 Mar 2024 15:04:32 +0800
Subject: [PATCH 5/6] fix(facade): remove unused comment
---
.../facade/src/apis/docs/__tests__/create-test-bed.ts | 9 ---------
packages/facade/src/apis/facade.ts | 1 -
2 files changed, 10 deletions(-)
diff --git a/packages/facade/src/apis/docs/__tests__/create-test-bed.ts b/packages/facade/src/apis/docs/__tests__/create-test-bed.ts
index d877bd44d7e..b28e572d1db 100644
--- a/packages/facade/src/apis/docs/__tests__/create-test-bed.ts
+++ b/packages/facade/src/apis/docs/__tests__/create-test-bed.ts
@@ -84,15 +84,6 @@ export function createTestBed(documentConfig?: IDocumentData, dependencies?: Dep
injector.add([DocStateChangeManagerService]);
injector.add([IMEInputManagerService]);
injector.add([ITextSelectionRenderManager, { useClass: TextSelectionRenderManager }]);
- // injector.add([
- // IDescriptionService,
- // {
- // useFactory: () => this._injector.createInstance(DescriptionService, undefined),
- // },
- // ]);
- // injector.add([IFunctionService, { useClass: FunctionService }]);
- // injector.add([IFormulaCustomFunctionService, { useClass: FormulaCustomFunctionService }]);
- // injector.add([ISocketService, { useClass: WebSocketService }]);
dependencies?.forEach((d) => injector.add(d));
}
diff --git a/packages/facade/src/apis/facade.ts b/packages/facade/src/apis/facade.ts
index 8f3ea17ff22..ac81c74a594 100644
--- a/packages/facade/src/apis/facade.ts
+++ b/packages/facade/src/apis/facade.ts
@@ -54,7 +54,6 @@ export class FUniver {
@Inject(Injector) private readonly _injector: Injector,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@ICommandService private readonly _commandService: ICommandService,
- // @IRegisterFunctionService private readonly _registerFunctionService: IRegisterFunctionService,
@ISocketService private readonly _ws: ISocketService
) {}
From e714affb3dac6f0c1d819ff7567cf6a603194d09 Mon Sep 17 00:00:00 2001
From: Dushusir <1414556676@qq.com>
Date: Tue, 5 Mar 2024 15:06:01 +0800
Subject: [PATCH 6/6] fix(facade): remove unused mock file
---
.../mock-text-selection-render-manager.ts | 32 -------------------
1 file changed, 32 deletions(-)
delete mode 100644 packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts
diff --git a/packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts b/packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts
deleted file mode 100644
index 506084e39cf..00000000000
--- a/packages/facade/src/apis/docs/__tests__/mock-text-selection-render-manager.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { Nullable } from '@univerjs/core';
-import type { ITextSelectionInnerParam } from '@univerjs/engine-render';
-import { createIdentifier } from '@wendellhu/redi';
-import { BehaviorSubject } from 'rxjs';
-
-export class TextSelectionRenderManager {
- private readonly _textSelectionInner$ = new BehaviorSubject>(null);
-
- readonly textSelectionInner$ = this._textSelectionInner$.asObservable();
- removeAllTextRanges() {}
- addTextRanges() {}
-}
-
-export const ITextSelectionRenderManager = createIdentifier(
- 'mock.univer.doc.text-selection-render-manager'
-);