Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor(*): refactor command system (#58)

Wenzhao Huae05f4948621
diff --git a/.eslintrc.js b/.eslintrc.js
index 3361b89935..e7425e002e 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -84,13 +84,6 @@ module.exports = {
accessibility: 'no-public',
},
],
- '@typescript-eslint/consistent-type-assertions': [
- 'error',
- {
- assertionStyle: 'as',
- objectLiteralTypeAssertions: 'allow-as-parameter',
- },
- ],
'spaced-comment': 'off',
eqeqeq: [
'error',
@@ -108,7 +101,9 @@ module.exports = {
'grouped-accessor-pairs': 'off',
'@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
+ '@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/no-unsafe-return': 'error',
+ '@typescript-eslint/no-redeclare': 'off', // dependency interface and dependency token share the same name
},
// https://www.npmjs.com/package/eslint-import-resolver-typescript
settings: {
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
new file mode 100644
index 0000000000..400d2bf5ef
--- /dev/null
+++ b/.github/CODEOWNERS
@@ -0,0 +1,2 @@
+
+docs/graphs.tldr @wzhudev
diff --git a/docs/graphs.tldr b/docs/graphs.tldr
new file mode 100644
index 0000000000..ebdc025365
--- /dev/null
+++ b/docs/graphs.tldr
@@ -0,0 +1,701 @@
+{
+ "tldrawFileFormatVersion": 1,
+ "schema": {
+ "schemaVersion": 1,
+ "storeVersion": 4,
+ "recordVersions": {
+ "asset": {
+ "version": 1,
+ "subTypeKey": "type",
+ "subTypeVersions": {
+ "image": 2,
+ "video": 2,
+ "bookmark": 0
+ }
+ },
+ "camera": {
+ "version": 1
+ },
+ "document": {
+ "version": 2
+ },
+ "instance": {
+ "version": 17
+ },
+ "instance_page_state": {
+ "version": 3
+ },
+ "page": {
+ "version": 1
+ },
+ "shape": {
+ "version": 3,
+ "subTypeKey": "type",
+ "subTypeVersions": {
+ "group": 0,
+ "embed": 4,
+ "bookmark": 1,
+ "image": 2,
+ "text": 1,
+ "draw": 1,
+ "geo": 7,
+ "line": 0,
+ "note": 4,
+ "frame": 0,
+ "arrow": 1,
+ "highlight": 0,
+ "video": 1
+ }
+ },
+ "instance_presence": {
+ "version": 4
+ },
+ "pointer": {
+ "version": 1
+ }
+ }
+ },
+ "records": [
+ {
+ "gridSize": 10,
+ "name": "",
+ "meta": {},
+ "id": "document:document",
+ "typeName": "document"
+ },
+ {
+ "id": "pointer:pointer",
+ "typeName": "pointer",
+ "x": 380.68473598340495,
+ "y": -181.8336219765346,
+ "lastActivityTimestamp": 1692931222942,
+ "meta": {}
+ },
+ {
+ "meta": {},
+ "id": "page:rA3Bannhl7kKSPnxwH2KA",
+ "name": "command system architecture",
+ "index": "a1",
+ "typeName": "page"
+ },
+ {
+ "x": 66.07625614128683,
+ "y": 287.1086716671836,
+ "z": 0.7599141509320603,
+ "meta": {},
+ "id": "camera:page:rA3Bannhl7kKSPnxwH2KA",
+ "typeName": "camera"
+ },
+ {
+ "editingId": null,
+ "croppingId": null,
+ "selectedIds": [],
+ "hoveredId": null,
+ "erasingIds": [],
+ "hintingIds": [],
+ "focusLayerId": null,
+ "meta": {},
+ "id": "instance_page_state:page:rA3Bannhl7kKSPnxwH2KA",
+ "pageId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "typeName": "instance_page_state"
+ },
+ {
+ "followingUserId": null,
+ "opacityForNextShape": 1,
+ "stylesForNextShape": {
+ "tldraw:geo": "rectangle",
+ "tldraw:dash": "dotted",
+ "tldraw:color": "light-blue",
+ "tldraw:fill": "none"
+ },
+ "brush": null,
+ "scribble": null,
+ "cursor": {
+ "type": "default",
+ "color": "black",
+ "rotation": 0
+ },
+ "isFocusMode": false,
+ "exportBackground": true,
+ "isDebugMode": false,
+ "isToolLocked": false,
+ "screenBounds": {
+ "x": 0,
+ "y": 0,
+ "w": 672,
+ "h": 738
+ },
+ "zoomBrush": null,
+ "isGridMode": false,
+ "isPenMode": false,
+ "chatMessage": "",
+ "isChatting": false,
+ "highlightedUserIds": [],
+ "meta": {},
+ "id": "instance:instance",
+ "currentPageId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "typeName": "instance"
+ },
+ {
+ "x": 439.53247946758506,
+ "y": 94.65373260827283,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:RyMexxxwgYQpcKl9XUjc6",
+ "type": "geo",
+ "props": {
+ "w": 287.5,
+ "h": 61.6953125,
+ "geo": "rectangle",
+ "color": "black",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "solid",
+ "size": "m",
+ "font": "draw",
+ "text": "ICommandService",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a1",
+ "typeName": "shape"
+ },
+ {
+ "x": 47.5,
+ "y": 43,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:_Iol5bXeZW3J-TeKm5A0u",
+ "type": "geo",
+ "props": {
+ "w": 222,
+ "h": 61.6953125,
+ "geo": "rectangle",
+ "color": "black",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "draw",
+ "size": "m",
+ "font": "draw",
+ "text": "Univer",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "shape:EXTAV2ZFeDoY7JD9ykdXo",
+ "index": "a1",
+ "typeName": "shape"
+ },
+ {
+ "x": 0,
+ "y": 0,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:-NlsVAEiZ8MB1C8baEWDY",
+ "type": "geo",
+ "props": {
+ "w": 61.6953125,
+ "h": 61.6953125,
+ "geo": "ellipse",
+ "color": "orange",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "solid",
+ "size": "m",
+ "font": "draw",
+ "text": "DI",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "shape:EXTAV2ZFeDoY7JD9ykdXo",
+ "index": "a2",
+ "typeName": "shape"
+ },
+ {
+ "x": 47.5,
+ "y": 42.99999999999997,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:rc-hRnk8B3Z3SeAPEn81e",
+ "type": "geo",
+ "props": {
+ "w": 222,
+ "h": 61.6953125,
+ "geo": "rectangle",
+ "color": "black",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "draw",
+ "size": "m",
+ "font": "draw",
+ "text": "UniverSheet",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "shape:W0amEPzL3oqhERqpVU03u",
+ "index": "a1",
+ "typeName": "shape"
+ },
+ {
+ "x": 0,
+ "y": -2.842170943040401e-14,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:pNaLnvf0SwFtoE9xWzZMH",
+ "type": "geo",
+ "props": {
+ "w": 61.6953125,
+ "h": 61.6953125,
+ "geo": "ellipse",
+ "color": "orange",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "solid",
+ "size": "m",
+ "font": "draw",
+ "text": "DI",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "shape:W0amEPzL3oqhERqpVU03u",
+ "index": "a2",
+ "typeName": "shape"
+ },
+ {
+ "x": 265.5,
+ "y": 183,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:Rr4Pd1wv_JyRTOnSpxASa",
+ "type": "arrow",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a6",
+ "props": {
+ "dash": "dotted",
+ "size": "m",
+ "fill": "none",
+ "color": "orange",
+ "labelColor": "black",
+ "bend": 0,
+ "start": {
+ "type": "binding",
+ "boundShapeId": "shape:RyMexxxwgYQpcKl9XUjc6",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "end": {
+ "type": "binding",
+ "boundShapeId": "shape:pNaLnvf0SwFtoE9xWzZMH",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "arrowheadStart": "none",
+ "arrowheadEnd": "arrow",
+ "text": "",
+ "font": "draw"
+ },
+ "typeName": "shape"
+ },
+ {
+ "x": 322.5,
+ "y": 203,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:mq_B38XWG2ZIbvk5DBdim",
+ "type": "arrow",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a9",
+ "props": {
+ "dash": "dotted",
+ "size": "m",
+ "fill": "none",
+ "color": "orange",
+ "labelColor": "black",
+ "bend": 0,
+ "start": {
+ "type": "binding",
+ "boundShapeId": "shape:rUT6E9SRsBYNLkWFII3jO",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "end": {
+ "type": "binding",
+ "boundShapeId": "shape:-NlsVAEiZ8MB1C8baEWDY",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "arrowheadStart": "none",
+ "arrowheadEnd": "arrow",
+ "text": "",
+ "font": "draw"
+ },
+ "typeName": "shape"
+ },
+ {
+ "x": 522,
+ "y": 265,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:QakBNC0Rk6xsBUTBxHSSK",
+ "type": "arrow",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a7",
+ "props": {
+ "dash": "solid",
+ "size": "m",
+ "fill": "none",
+ "color": "orange",
+ "labelColor": "black",
+ "bend": 0,
+ "start": {
+ "type": "binding",
+ "boundShapeId": "shape:pNaLnvf0SwFtoE9xWzZMH",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "end": {
+ "type": "binding",
+ "boundShapeId": "shape:-NlsVAEiZ8MB1C8baEWDY",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "arrowheadStart": "none",
+ "arrowheadEnd": "arrow",
+ "text": "",
+ "font": "draw"
+ },
+ "typeName": "shape"
+ },
+ {
+ "x": 321.9866165385808,
+ "y": 290.89139227450494,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:rUT6E9SRsBYNLkWFII3jO",
+ "type": "geo",
+ "props": {
+ "w": 287.5,
+ "h": 61.6953125,
+ "geo": "rectangle",
+ "color": "black",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "solid",
+ "size": "m",
+ "font": "draw",
+ "text": "ICommandService",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a8",
+ "typeName": "shape"
+ },
+ {
+ "x": 293,
+ "y": 167,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:PtpUjdnpGE51HEsWDSPkw",
+ "type": "arrow",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a8V",
+ "props": {
+ "dash": "dotted",
+ "size": "m",
+ "fill": "none",
+ "color": "orange",
+ "labelColor": "black",
+ "bend": 0,
+ "start": {
+ "type": "binding",
+ "boundShapeId": "shape:RyMexxxwgYQpcKl9XUjc6",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "end": {
+ "type": "binding",
+ "boundShapeId": "shape:rUT6E9SRsBYNLkWFII3jO",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "arrowheadStart": "none",
+ "arrowheadEnd": "arrow",
+ "text": "",
+ "font": "draw"
+ },
+ "typeName": "shape"
+ },
+ {
+ "x": 143.8158741794448,
+ "y": -6.155882805263957,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:mjNPq0t9Puk0Zvy_3YM4_",
+ "type": "geo",
+ "props": {
+ "w": 228.31526401659505,
+ "h": 61.6953125,
+ "geo": "rectangle",
+ "color": "light-blue",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "draw",
+ "size": "m",
+ "font": "draw",
+ "text": "SheetCommands",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "aA",
+ "typeName": "shape"
+ },
+ {
+ "x": 547.1509083067438,
+ "y": 47.79758016119371,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:gu_dxmGcATVyn-jDvvLl0",
+ "type": "arrow",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "aB",
+ "props": {
+ "dash": "draw",
+ "size": "m",
+ "fill": "none",
+ "color": "light-blue",
+ "labelColor": "black",
+ "bend": 0,
+ "start": {
+ "type": "binding",
+ "boundShapeId": "shape:mjNPq0t9Puk0Zvy_3YM4_",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "end": {
+ "type": "binding",
+ "boundShapeId": "shape:RyMexxxwgYQpcKl9XUjc6",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "arrowheadStart": "none",
+ "arrowheadEnd": "arrow",
+ "text": "",
+ "font": "draw"
+ },
+ "typeName": "shape"
+ },
+ {
+ "x": 52.35817476069343,
+ "y": 158.99435139694162,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:fx8UKMzZfi4EulsqtVvLq",
+ "type": "geo",
+ "props": {
+ "w": 248.73907181699673,
+ "h": 61.6953125,
+ "geo": "rectangle",
+ "color": "light-blue",
+ "labelColor": "black",
+ "fill": "none",
+ "dash": "draw",
+ "size": "m",
+ "font": "draw",
+ "text": "CommonCommands",
+ "align": "middle",
+ "verticalAlign": "middle",
+ "growY": 0,
+ "url": ""
+ },
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "aC",
+ "typeName": "shape"
+ },
+ {
+ "x": 56.30598912409266,
+ "y": 251.11001987625963,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:yPWMtHT-IFjuDHl3EEl-J",
+ "type": "arrow",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "aD",
+ "props": {
+ "dash": "draw",
+ "size": "m",
+ "fill": "none",
+ "color": "light-blue",
+ "labelColor": "black",
+ "bend": 0,
+ "start": {
+ "type": "binding",
+ "boundShapeId": "shape:fx8UKMzZfi4EulsqtVvLq",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "end": {
+ "type": "binding",
+ "boundShapeId": "shape:rUT6E9SRsBYNLkWFII3jO",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "arrowheadStart": "none",
+ "arrowheadEnd": "arrow",
+ "text": "",
+ "font": "draw"
+ },
+ "typeName": "shape"
+ },
+ {
+ "x": 31.96113388313006,
+ "y": 43.84976579779436,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:s2nQFQX6LGG-DG8QWd3Bs",
+ "type": "arrow",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "aAV",
+ "props": {
+ "dash": "dotted",
+ "size": "m",
+ "fill": "none",
+ "color": "light-blue",
+ "labelColor": "black",
+ "bend": 0,
+ "start": {
+ "type": "binding",
+ "boundShapeId": "shape:mjNPq0t9Puk0Zvy_3YM4_",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "end": {
+ "type": "binding",
+ "boundShapeId": "shape:rUT6E9SRsBYNLkWFII3jO",
+ "normalizedAnchor": {
+ "x": 0.5,
+ "y": 0.5
+ },
+ "isExact": false
+ },
+ "arrowheadStart": "none",
+ "arrowheadEnd": "arrow",
+ "text": "",
+ "font": "draw"
+ },
+ "typeName": "shape"
+ },
+ {
+ "x": 675.4950894431682,
+ "y": 221.78843315206828,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:W0amEPzL3oqhERqpVU03u",
+ "type": "group",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a5",
+ "props": {},
+ "typeName": "shape"
+ },
+ {
+ "x": 592,
+ "y": 397,
+ "rotation": 0,
+ "isLocked": false,
+ "opacity": 1,
+ "meta": {},
+ "id": "shape:EXTAV2ZFeDoY7JD9ykdXo",
+ "type": "group",
+ "parentId": "page:rA3Bannhl7kKSPnxwH2KA",
+ "index": "a3",
+ "props": {},
+ "typeName": "shape"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/examples/univer-sheet-ts/local/index.html b/examples/univer-sheet-ts/local/index.html
index 58ff590d12..c804d874ee 100644
--- a/examples/univer-sheet-ts/local/index.html
+++ b/examples/univer-sheet-ts/local/index.html
@@ -24,7 +24,7 @@
</script>
</head>
-<body>
+<body style="overflow: hidden;">
<div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>
<!-- <div id="universheet" style="height: 225px;width: 400px;"></div> -->
<div id="universheet" style="height: 100%;"></div>
diff --git a/examples/univer-sheet-ts/public/index.html b/examples/univer-sheet-ts/public/index.html
index 58ff590d12..c804d874ee 100644
--- a/examples/univer-sheet-ts/public/index.html
+++ b/examples/univer-sheet-ts/public/index.html
@@ -24,7 +24,7 @@
</script>
</head>
-<body>
+<body style="overflow: hidden;">
<div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>
<!-- <div id="universheet" style="height: 225px;width: 400px;"></div> -->
<div id="universheet" style="height: 100%;"></div>
diff --git a/examples/univer-sheet-ts/src/Types/index.d.ts b/examples/univer-sheet-ts/src/Types/index.d.ts
deleted file mode 100644
index 6aabf2941f..0000000000
--- a/examples/univer-sheet-ts/src/Types/index.d.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-/// <reference types="vite/client" />
-
-declare module 'univer-sheet-ts' {}
-
-// use css module
-declare module '*.less' {
- const resource: { [key: string]: string };
- export = resource;
-}
diff --git a/examples/univer-sheet-ts/src/Types/preact.d.ts b/examples/univer-sheet-ts/src/Types/preact.d.ts
deleted file mode 100644
index 0d092b3751..0000000000
--- a/examples/univer-sheet-ts/src/Types/preact.d.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-/// <reference types="enzyme-adapter-preact-pure" />
-import JSX = preact.JSX;
-
-declare module 'enzyme';
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsx
index c10180c022..0f6ca96924 100644
--- a/examples/univer-sheet-ts/src/main.tsx
+++ b/examples/univer-sheet-ts/src/main.tsx
@@ -10,8 +10,6 @@ import { ImportXlsxPlugin } from '@univerjs/sheets-plugin-import-xlsx';
import { OperationPlugin } from '@univerjs/sheets-plugin-operation';
import { ImagePlugin } from '@univerjs/sheets-plugin-image';
-// TODO: @huwenzhao: change the following to new API
-
// univer
const univer = new Univer({
locale: LocaleType.EN,
@@ -42,7 +40,6 @@ univer.registerPlugin(FormulaPlugin, DEFAULT_FORMULA_DATA_DEMO);
univer.registerPlugin(ImportXlsxPlugin);
univer.registerPlugin(ImagePlugin);
univer.registerPlugin(OperationPlugin);
-// universheet.installPlugin(new OverGridImagePlugin());
// use for console test
declare global {
diff --git a/packages/base-docs/package.json b/packages/base-docs/package.json
index 09ef0ee674..b935fe423f 100644
--- a/packages/base-docs/package.json
+++ b/packages/base-docs/package.json
@@ -58,7 +58,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1"
}
diff --git a/packages/base-formula-engine/package.json b/packages/base-formula-engine/package.json
index b3f5e665d6..1d3aff7808 100644
--- a/packages/base-formula-engine/package.json
+++ b/packages/base-formula-engine/package.json
@@ -55,7 +55,7 @@
},
"dependencies": {
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"preact": "^10.12.1"
}
}
\ No newline at end of file
diff --git a/packages/base-render/package.json b/packages/base-render/package.json
index d7b5c8a2f6..9585731e79 100644
--- a/packages/base-render/package.json
+++ b/packages/base-render/package.json
@@ -63,6 +63,6 @@
},
"dependencies": {
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0"
+ "@wendellhu/redi": "^0.12.6"
}
}
\ No newline at end of file
diff --git a/packages/base-render/src/RenderEngine.ts b/packages/base-render/src/RenderEngine.ts
index 042b61d5ff..0b2fec41fa 100644
--- a/packages/base-render/src/RenderEngine.ts
+++ b/packages/base-render/src/RenderEngine.ts
@@ -1,5 +1,6 @@
import { Injector, Optional, createIdentifier } from '@wendellhu/redi';
-import { Plugin, PluginType, PLUGIN_NAMES, Univer } from '@univerjs/core';
+import { Plugin, PluginType, PLUGIN_NAMES } from '@univerjs/core';
+
import { Engine } from './Engine';
export const IRenderingEngine = createIdentifier<Engine>('univer.render-engine');
@@ -17,11 +18,7 @@ export class RenderEngine extends Plugin {
this._injector?.add([IRenderingEngine, { useFactory: () => this._engine }]);
}
- installTo(univerInstance: Univer) {
- univerInstance.install(this);
- }
-
getEngine(): Engine {
return this._engine;
}
-}
\ No newline at end of file
+}
diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.json
index 1180266b73..17f437568e 100644
--- a/packages/base-sheets/package.json
+++ b/packages/base-sheets/package.json
@@ -66,6 +66,6 @@
"dependencies": {
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0"
+ "@wendellhu/redi": "^0.12.6"
}
}
\ No newline at end of file
diff --git a/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts b/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts
new file mode 100644
index 0000000000..321990843e
--- /dev/null
+++ b/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts
@@ -0,0 +1,69 @@
+import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';
+import { IAccessor } from '@wendellhu/redi';
+
+import { ISelectionManager } from '../../Services/tokens';
+import { SelectionController } from '../../Controller/Selection/SelectionController';
+import { SelectionModel } from '../../Model/SelectionModel';
+import { ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../Mutations/set-range-values.mutation';
+
+/**
+ * The command to clear content in current selected ranges.
+ */
+export const ClearSelectionContentCommand: ICommand = {
+ id: 'sheet.command.clear-selection',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor) => {
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+ const undoRedoService = accessor.get(IUndoRedoService);
+
+ // TODO: this is to verbose to get a serializable range
+ // a range should have worksheet id as well
+ const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const worksheet = workbook.getActiveSheet();
+ const controls = selectionManager.getCurrentControls();
+ const selections = controls?.map((control: SelectionController) => {
+ const model: SelectionModel = control.model;
+ return {
+ startRow: model.startRow,
+ startColumn: model.startColumn,
+ endRow: model.endRow,
+ endColumn: model.endColumn,
+ };
+ });
+
+ if (!selections) {
+ return false;
+ }
+
+ // prepare do mutations
+
+ const range = selections[0];
+ const clearMutationParams: ISetRangeValuesMutationParams = {
+ rangeData: range,
+ worksheetId: worksheet.getSheetId(),
+ };
+ const undoClearMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, clearMutationParams);
+
+ // execute do mutations and add undo mutations to undo stack if completed
+ const result = commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);
+ if (result) {
+ undoRedoService.pushUndoRedo({
+ // 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面
+ // 通过勾子可以 hook 外部 controller 的代码来增加新的 action
+ URI: 'sheet', // TODO: this URI is fake
+ undo() {
+ return commandService.executeCommand(SetRangeValuesMutation.id, undoClearMutationParams);
+ },
+ redo() {
+ return commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);
+ },
+ });
+
+ return true;
+ }
+
+ return false;
+ },
+};
diff --git a/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts b/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts
new file mode 100644
index 0000000000..0d4cf95280
--- /dev/null
+++ b/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts
@@ -0,0 +1,31 @@
+import { CommandType, ICommand } from '@univerjs/core';
+import { IAccessor } from '@wendellhu/redi';
+
+export interface InsertRowCommandParams {
+ worksheetId: string;
+ workbookId: string;
+ fromIndex?: number;
+ count?: number;
+}
+
+/**
+ * The command to insert a row into a worksheet.
+ */
+export const InsertRowCommand: ICommand = {
+ type: CommandType.COMMAND,
+ id: 'sheet.command.insert-row',
+
+ handler: async (accessor: IAccessor, params: InsertRowCommandParams) => {
+ // all subsequent mutations should succeed inorder to make the whole process succeed
+ return Promise.all([]).then(() => true);
+ },
+};
+
+export const InsertColCommand: ICommand = {
+ type: CommandType.COMMAND,
+ id: 'sheet.command.insert-col',
+
+ handler: async (accessor, params) => {
+ return true;
+ },
+};
\ No newline at end of file
diff --git a/packages/base-sheets/src/Commands/Commands/set-style.command.ts b/packages/base-sheets/src/Commands/Commands/set-style.command.ts
new file mode 100644
index 0000000000..77f341c51f
--- /dev/null
+++ b/packages/base-sheets/src/Commands/Commands/set-style.command.ts
@@ -0,0 +1,43 @@
+import { IAccessor } from '@wendellhu/redi';
+import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';
+
+import { ISelectionManager } from '../../Services/tokens';
+import { SelectionController } from '../../Controller/Selection/SelectionController';
+import { SelectionModel } from '../../Model/SelectionModel';
+
+export interface ISetFontFamilyParams {
+ fontFamily: string;
+}
+
+/**
+ * Set new font family for currently selected cells
+ */
+export const SetFontFamilyCommand: ICommand<ISetFontFamilyParams> = {
+ id: 'sheet.command.set-font-family',
+ type: CommandType.COMMAND,
+ handler: async (accessor: IAccessor) => {
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.gett(ISelectionManager);
+ const undoRedoService = accessor.get(IUndoRedoService);
+
+ const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const worksheet = workbook.getActiveSheet();
+ const controls = selectionManager.getCurrentControls();
+ const selections = controls?.map((control: SelectionController) => {
+ const model: SelectionModel = control.model;
+ return {
+ startRow: model.startRow,
+ startColumn: model.startColumn,
+ endRow: model.endRow,
+ endColumn: model.endColumn,
+ };
+ });
+
+ const
+
+ // FIXME: 为什么之前有些 command 支持的多 selection 有的不支持?
+
+ return true;
+ },
+};
diff --git a/packages/base-sheets/src/Commands/Mutations/insert-row-col.mutation.ts b/packages/base-sheets/src/Commands/Mutations/insert-row-col.mutation.ts
new file mode 100644
index 0000000000..65a2b10074
--- /dev/null
+++ b/packages/base-sheets/src/Commands/Mutations/insert-row-col.mutation.ts
@@ -0,0 +1,23 @@
+import { CommandType, IMutation } from '@univerjs/core';
+
+export interface IInsertRowParams {}
+
+export const InsertRowMutation: IMutation<IInsertRowParams> = {
+ id: 'sheet.mutation.insert-row',
+ type: CommandType.MUTATION,
+ handler: async (accessor, params) => {
+ // TODO: copy code from
+ // packages/core/src/Sheets/Apply/InsertRow.ts
+ return true;
+ },
+};
+
+export interface IInsertColParams {}
+
+export const IInsertColMutation: IMutation<IInsertColParams> = {
+ id: 'sheet.mutation.insert-col',
+ type: CommandType.MUTATION,
+ handler: async (accessor, params) => {
+ return true;
+ },
+};
\ No newline at end of file
diff --git a/packages/base-sheets/src/Commands/Mutations/set-range-styles.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-range-styles.mutation.ts
new file mode 100644
index 0000000000..5d1a610da3
--- /dev/null
+++ b/packages/base-sheets/src/Commands/Mutations/set-range-styles.mutation.ts
@@ -0,0 +1,13 @@
+import { CommandType, IMutation } from '@univerjs/core';
+
+export interface ISetRangeStyleMutation {
+
+}
+
+export const SetRangeStyleMutation: IMutation<> = {
+ id: 'sheet.mutation.set-range-style',
+ type: CommandType.MUTATION,
+ handler: async (accessor, params) => {
+ return true;
+ }
+};
\ No newline at end of file
diff --git a/packages/base-sheets/src/Commands/Mutations/set-range-values.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-range-values.mutation.ts
new file mode 100644
index 0000000000..04b13a0c7f
--- /dev/null
+++ b/packages/base-sheets/src/Commands/Mutations/set-range-values.mutation.ts
@@ -0,0 +1,110 @@
+import {
+ IMutation,
+ CommandType,
+ ICurrentUniverService,
+ ICellData,
+ ObjectMatrix,
+ Tools,
+ ObjectMatrixPrimitiveType,
+ ICopyToOptionsData,
+ IRangeData,
+ createRowColIter,
+} from '@univerjs/core';
+import { IAccessor } from '@wendellhu/redi';
+
+/** Params of `SetRangeValuesMutation` */
+export interface ISetRangeValuesMutationParams {
+ rangeData: IRangeData;
+ worksheetId: string;
+
+ cellValue?: ObjectMatrixPrimitiveType<ICellData>;
+ workbookId?: string;
+ options?: ICopyToOptionsData;
+}
+
+/**
+ * Generate undo mutation of a `SetRangeValuesMutation`
+ *
+ * @param {IAccessor} accessor - injector accessor
+ * @param {ISetRangeValuesMutationParams} params - do mutation params
+ * @returns {ISetRangeValuesMutationParams} undo mutation params
+ */
+export const SetRangeValuesUndoMutationFactory = (accessor: IAccessor, params: ISetRangeValuesMutationParams): ISetRangeValuesMutationParams => {
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(params.worksheetId);
+ const cellMatrix = worksheet?.getCellMatrix();
+ const { startRow, endRow, startColumn, endColumn } = params.rangeData;
+
+ const undoData = new ObjectMatrix<ICellData>();
+ for (let r = startRow; r <= endRow; r++) {
+ for (let c = startColumn; c <= endColumn; c++) {
+ const value = cellMatrix?.getValue(r, c);
+ undoData.setValue(r, c, Tools.deepClone(value as ICellData));
+ }
+ }
+
+ return {
+ ...Tools.deepClone(params),
+ options: {},
+ cellValue: undoData.getData(),
+ } as ISetRangeValuesMutationParams;
+};
+
+export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, boolean> = {
+ id: 'sheet.mutation.set-range-values',
+ type: CommandType.MUTATION,
+ handler: async (accessor, params) => {
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const worksheet = workbook.getSheetBySheetId(params.worksheetId);
+ if (!worksheet) {
+ return false;
+ }
+
+ const cellMatrix = worksheet.getCellMatrix();
+ const { cellValue, rangeData } = params;
+ const { startRow, startColumn, endColumn, endRow } = rangeData;
+
+ // clear selection content
+ createRowColIter(startRow, endRow, startColumn, endColumn).forEach((r, c) => {
+ if (cellMatrix.getValue(r, c)) {
+ cellMatrix.setValue(r, c, { v: null });
+ }
+ });
+
+ const newValues = new ObjectMatrix(cellValue);
+ newValues.forValue((row, col, newVal) => {
+ const oldVal = cellMatrix.getValue(row, col) || {};
+
+ // clear all
+ if (!newVal) {
+ cellMatrix?.setValue(row, col, {
+ v: null,
+ });
+ } else {
+ // TODO: @wzhudev: add config to change value or format only
+ if (newVal.p != null) {
+ oldVal.p = newVal.p;
+ }
+
+ if (newVal.v != null) {
+ oldVal.v = newVal.v;
+ }
+
+ if (newVal.m != null) {
+ oldVal.m = newVal.m;
+ } else {
+ oldVal.m = String(oldVal.v);
+ }
+
+ if (newVal.t != null) {
+ oldVal.t = newVal.t;
+ }
+
+ cellMatrix.setValue(row, col, oldVal);
+ }
+ });
+
+ return true;
+ },
+};
\ No newline at end of file
diff --git a/packages/base-sheets/src/Commands/Operations/scroll.operation.ts b/packages/base-sheets/src/Commands/Operations/scroll.operation.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
new file mode 100644
index 0000000000..149354aaaf
--- /dev/null
+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
@@ -0,0 +1,28 @@
+import { IDisposable } from '@wendellhu/redi';
+import { Disposable, ICommandService } from '@univerjs/core';
+
+import { ClearSelectionContentCommand } from '../Commands/Commands/clear-selection-content.command';
+import { SetRangeValuesMutation } from '../Commands/Mutations/set-range-values.mutation';
+
+/**
+ * The controller to provide the most basic sheet CRUD methods to other modules of sheet modules.
+ */
+export class BasicWorksheetController extends Disposable implements IDisposable {
+ constructor(@ICommandService private readonly _commandService: ICommandService) {
+ super();
+
+ this.disposeWithMe(_commandService.registerCommand(ClearSelectionContentCommand));
+ this.disposeWithMe(_commandService.registerCommand(SetRangeValuesMutation));
+ }
+
+ onInitialize() {}
+
+ // TODO: @Dushusir: add other basic mutation methods here.
+
+ /**
+ * Clear contents in the current selected ranges.
+ */
+ async clearSelectionContent(): Promise<boolean> {
+ return this._commandService.executeCommand(ClearSelectionContentCommand.id);
+ }
+}
\ No newline at end of file
diff --git a/packages/base-sheets/src/Controller/EditTooltipsController.ts b/packages/base-sheets/src/Controller/EditTooltipsController.ts
index b87e70063a..af93e70020 100644
--- a/packages/base-sheets/src/Controller/EditTooltipsController.ts
+++ b/packages/base-sheets/src/Controller/EditTooltipsController.ts
@@ -63,15 +63,15 @@ export class EditTooltipsController {
const sheet = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(sheetId);
const editTooltips = this.createIfEditTooltips(key, sheetId);
if (sheet) {
- let merges = sheet.getMerges().getByRowColumn(row, column);
- let rowTitle = sheet.getConfig().rowTitle;
- let columnTitle = sheet.getConfig().columnTitle;
+ const merges = sheet.getMerges().getByRowColumn(row, column);
+ const rowTitle = sheet.getConfig().rowTitle;
+ const columnTitle = sheet.getConfig().columnTitle;
let left = rowTitle.width ?? 0;
let top = columnTitle.height ?? 0;
let height = 0;
let width = 0;
if (merges) {
- let merge = merges[0];
+ const merge = merges[0];
for (let i = merge.startColumn; i <= merge.endColumn; i++) {
width += sheet.getColumnWidth(i);
}
diff --git a/packages/base-sheets/src/Controller/RightMenuController.ts b/packages/base-sheets/src/Controller/RightMenuController.ts
index 986715193d..34f68c9cd3 100644
--- a/packages/base-sheets/src/Controller/RightMenuController.ts
+++ b/packages/base-sheets/src/Controller/RightMenuController.ts
@@ -1,17 +1,19 @@
import { Inject, SkipSelf } from '@wendellhu/redi';
-import { ICurrentUniverService, ObserverManager, UIObserver } from '@univerjs/core';
+import { ICommandService, ICurrentUniverService, ObserverManager, UIObserver } from '@univerjs/core';
import { SelectionController } from './Selection/SelectionController';
import { SelectionModel } from '../Model/SelectionModel';
import { ISelectionManager } from '../Services/tokens';
import { SelectionManager } from './Selection';
import { HideColumnController } from './HideColumnController';
+import { ClearSelectionContentCommand } from '../Commands/Commands/clear-selection-content.command';
export class RightMenuController {
constructor(
@SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,
@ISelectionManager private readonly _selectionManager: SelectionManager,
@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
- @Inject(HideColumnController) private readonly _hideColumnController: HideColumnController
+ @Inject(HideColumnController) private readonly _hideColumnController: HideColumnController,
+ @ICommandService private readonly _commandService: ICommandService,
) {}
listenEventManager() {
@@ -92,11 +94,9 @@ export class RightMenuController {
};
clearContent = () => {
- const selections = this._getSelections();
- if (selections?.length === 1) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();
- sheet.getRange(selections[0]).clear();
- }
+ // TODO: @wzhudev: should not call a command directly. Instead, it should invoke a method on XXXController and the controller would trigger a command.
+ // Only command should be resonsible for triggering commands.
+ this._commandService.executeCommand(ClearSelectionContentCommand.id);
};
deleteCellLeft = () => {
@@ -144,4 +144,4 @@ export class RightMenuController {
});
return selections;
}
-}
+}
\ No newline at end of file
diff --git a/packages/base-sheets/src/Controller/Selection/selection.operation.ts b/packages/base-sheets/src/Controller/Selection/selection.operation.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-sheets/src/Controller/SheetContainerController.ts b/packages/base-sheets/src/Controller/SheetContainerController.ts
index f9d6ac8f2a..72627851cb 100644
--- a/packages/base-sheets/src/Controller/SheetContainerController.ts
+++ b/packages/base-sheets/src/Controller/SheetContainerController.ts
@@ -1,21 +1,29 @@
-import { CommandManager, ICurrentUniverService, ISheetActionData, SheetActionBase } from '@univerjs/core';
+import { CommandManager, Disposable, ICommandService, ICurrentUniverService, ISheetActionData, SheetActionBase } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';
import { ISelectionManager } from '../Services/tokens';
import { SelectionManager } from './Selection';
import { CanvasView } from '../View';
-// All skins' less file
-export class SheetContainerController {
+export class SheetContainerController extends Disposable {
constructor(
@ISelectionManager private readonly _selectionManager: SelectionManager,
@Inject(CanvasView) private readonly canvasView: CanvasView,
- @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService
+ @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
+ @ICommandService private readonly _commandService: ICommandService
) {
+ super();
+
this._initialize();
}
private _initialize() {
+ this.disposeWithMe(
+ this._commandService.onCommandExecuted(() => {
+ this.canvasView.getSheetView().getSpreadsheet().makeDirty(true);
+ })
+ );
+
// Monitor all command changes and automatically trigger the refresh of the canvas
CommandManager.getCommandObservers().add(({ actions }) => {
if (!actions || actions.length === 0) return;
diff --git a/packages/base-sheets/src/Controller/ToolbarController.ts b/packages/base-sheets/src/Controller/ToolbarController.ts
index a5f550fcd4..73cfb5f740 100644
--- a/packages/base-sheets/src/Controller/ToolbarController.ts
+++ b/packages/base-sheets/src/Controller/ToolbarController.ts
@@ -1,4 +1,16 @@
-import { BorderType, HorizontalAlign, UIObserver, VerticalAlign, WrapStrategy, ObserverManager, ICurrentUniverService, CommandManager } from '@univerjs/core';
+import {
+ BorderType,
+ HorizontalAlign,
+ UIObserver,
+ VerticalAlign,
+ WrapStrategy,
+ ObserverManager,
+ ICurrentUniverService,
+ CommandManager,
+ ICommandService,
+ UndoCommand,
+ RedoCommand,
+} from '@univerjs/core';
import { Inject, SkipSelf } from '@wendellhu/redi';
import { SelectionController } from './Selection/SelectionController';
@@ -17,7 +29,7 @@ export interface BorderInfo {
export class ToolbarController {
constructor(
@SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,
- @Inject(CommandManager) private readonly _commandManager: CommandManager,
+ @ICommandService private readonly _commandService: ICommandService,
@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
@ISelectionManager private readonly _selectionManager: SelectionManager,
@Inject(CellEditorController) private readonly _cellEditorController: CellEditorController
@@ -126,47 +138,47 @@ export class ToolbarController {
// });
}
- setRedo() {
- this._commandManager.redo();
+ private setRedo() {
+ this._commandService.executeCommand(RedoCommand.id);
}
- setUndo() {
- this._commandManager.undo();
+ private setUndo() {
+ this._commandService.executeCommand(UndoCommand.id);
}
- setFontColor(value: string) {
+ private setFontColor(value: string) {
this._selectionManager.getActiveRangeList()?.setFontColor(value);
}
- setBackground(value: string) {
+ private setBackground(value: string) {
this._selectionManager.getActiveRangeList()?.setBackground(value);
}
- setFontSize(value: number) {
+ private setFontSize(value: number) {
this._selectionManager.getActiveRangeList()?.setFontSize(value);
}
- setFontFamily(value: string) {
+ private setFontFamily(value: string) {
this._selectionManager.getActiveRangeList()?.setFontFamily(value);
}
- setFontWeight(value: boolean) {
+ private setFontWeight(value: boolean) {
this._selectionManager.getActiveRangeList()?.setFontWeight(value);
}
- setFontStyle(value: boolean) {
+ private setFontStyle(value: boolean) {
this._selectionManager.getActiveRangeList()?.setFontStyle(value);
}
- setStrikeThrough(value: boolean) {
+ private setStrikeThrough(value: boolean) {
this._selectionManager.getActiveRangeList()?.setStrikeThrough(value);
}
- setUnderline(value: boolean) {
+ private setUnderline(value: boolean) {
this._selectionManager.getActiveRangeList()?.setUnderline(value);
}
- setMerge(value: string) {
+ private setMerge(value: string) {
const currentRange = this._selectionManager.getActiveRange();
switch (value) {
@@ -191,19 +203,19 @@ export class ToolbarController {
}
}
- setHorizontalAlignment(value: HorizontalAlign) {
+ private setHorizontalAlignment(value: HorizontalAlign) {
this._selectionManager.getActiveRangeList()?.setHorizontalAlignment(value);
}
- setVerticalAlignment(value: VerticalAlign) {
+ private setVerticalAlignment(value: VerticalAlign) {
this._selectionManager.getActiveRangeList()?.setVerticalAlignment(value);
}
- setWrapStrategy(value: WrapStrategy) {
+ private setWrapStrategy(value: WrapStrategy) {
this._selectionManager.getActiveRangeList()?.setWrapStrategy(value);
}
- setTextRotation(value: number | string) {
+ private setTextRotation(value: number | string) {
if (value === 'v') {
this._selectionManager.getActiveRangeList()?.setVerticalText(1);
} else {
@@ -211,7 +223,7 @@ export class ToolbarController {
}
}
- setBorder(info: BorderInfo) {
+ private setBorder(info: BorderInfo) {
const controls = this._selectionManager.getCurrentControls();
if (controls && controls.length > 0) {
@@ -228,4 +240,4 @@ export class ToolbarController {
});
}
}
-}
+}
\ No newline at end of file
diff --git a/packages/base-sheets/src/Desktop/Controllers/workbench.controller.ts b/packages/base-sheets/src/Desktop/Controllers/workbench.controller.ts
new file mode 100644
index 0000000000..af65e9d183
--- /dev/null
+++ b/packages/base-sheets/src/Desktop/Controllers/workbench.controller.ts
@@ -0,0 +1,3 @@
+export class WorkbenchController {
+
+}
diff --git a/packages/base-sheets/src/Desktop/desktop.plugin.ts b/packages/base-sheets/src/Desktop/desktop.plugin.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-sheets/src/Desktop/index.ts b/packages/base-sheets/src/Desktop/index.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-sheets/src/Model/workbook.model.ts b/packages/base-sheets/src/Model/workbook.model.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-sheets/src/Model/worksheet.model.ts b/packages/base-sheets/src/Model/worksheet.model.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.ts
index 5401f66cbd..2fe7b601c7 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/SheetPlugin.ts
@@ -25,6 +25,7 @@ import { ColumnTitleController } from './Controller/Selection/ColumnTitleControl
import { RowTitleController } from './Controller/Selection/RowTitleController';
import { ColumnRulerManager } from './Basics/Register/ColumnRegister';
import { HideColumnRulerFactory } from './Basics/Register/HideColumnRuler';
+import { BasicWorksheetController } from './Controller/BasicWorksheet.controller';
/**
* The main sheet base, construct the sheet container and layout, mount the rendering engine
@@ -120,6 +121,8 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
this._rightMenuController = this._injector.get(RightMenuController);
this._countBarController = this._injector.get(CountBarController);
this._hideColumnController = this._injector.get(HideColumnController);
+
+ this._injector.get(BasicWorksheetController);
}
initCanvasView() {
@@ -193,6 +196,8 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
[HideColumnController],
[ColumnRulerManager],
+
+ [BasicWorksheetController],
];
dependencies.forEach((d) => {
diff --git a/packages/base-sheets/src/Types/index.d.ts b/packages/base-sheets/src/Types/index.d.ts
deleted file mode 100644
index fc52974669..0000000000
--- a/packages/base-sheets/src/Types/index.d.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-/// <reference types="vite/client" />
-
-export * from '../index';
-declare module '@univerjs/base-sheets' {}
-
-// use css module
-declare module '*.less' {
- const resource: { [key: string]: string };
- export = resource;
-}
diff --git a/packages/base-sheets/src/Types/preact.d.ts b/packages/base-sheets/src/Types/preact.d.ts
deleted file mode 100644
index 0d9c32b84c..0000000000
--- a/packages/base-sheets/src/Types/preact.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-import JSX = preact.JSX;
diff --git a/packages/base-slides/package.json b/packages/base-slides/package.json
index ffd6deeb22..2e52ec3a55 100644
--- a/packages/base-slides/package.json
+++ b/packages/base-slides/package.json
@@ -58,7 +58,7 @@
"@univerjs/core": "workspace:^0.0.1",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1",
- "@wendellhu/redi": "^0.10.0"
+ "@wendellhu/redi": "^0.12.6"
}
}
\ No newline at end of file
diff --git a/packages/base-ui/package.json b/packages/base-ui/package.json
index 01de2c48cd..15fe5b8e5f 100644
--- a/packages/base-ui/package.json
+++ b/packages/base-ui/package.json
@@ -67,7 +67,7 @@
"dependencies": {
"@univerjs/base-render": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"preact": "^10.12.1",
"react-colorful": "^5.3.0"
}
diff --git a/packages/base-ui/src/Services/Clipboard/clipboard.service.ts b/packages/base-ui/src/Services/Clipboard/clipboard.service.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-ui/src/Services/ContextMenu/contextMenu.service.ts b/packages/base-ui/src/Services/ContextMenu/contextMenu.service.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-ui/src/Services/Menu/menu.service.ts b/packages/base-ui/src/Services/Menu/menu.service.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/base-ui/src/Services/Toolbar/toolbar.service.ts b/packages/base-ui/src/Services/Toolbar/toolbar.service.ts
new file mode 100644
index 0000000000..66f8efeb69
--- /dev/null
+++ b/packages/base-ui/src/Services/Toolbar/toolbar.service.ts
@@ -0,0 +1,11 @@
+import { createIdentifier } from '@wendellhu/redi';
+
+export interface IToolbarItem {}
+
+export interface IToolbarService {}
+
+export const IToolbarService = createIdentifier<IToolbarService>('univer.toolbar-service');
+
+export class DesktopToolbarService implements IToolbarService {
+
+}
diff --git a/packages/core/package.json b/packages/core/package.json
index a6d0bdda1c..390023c858 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -56,7 +56,7 @@
"url": "https://github.com/dream-num/univer.git"
},
"dependencies": {
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"dayjs": "^1.11.5",
"es6-proxy-polyfill": "^2.1.1",
"nanoid": "4.0.0",
@@ -76,4 +76,4 @@
"vite": "^3.0.9",
"vite-plugin-external": "1.2.3"
}
-}
\ No newline at end of file
+}
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index 29b22b01d3..1ae71992fc 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -11,6 +11,8 @@ import { UniverObserverImpl } from './UniverObserverImpl';
import { ObserverManager } from '../Observer';
import { CurrentUniverService, ICurrentUniverService } from '../Service/Current.service';
import { UniverSlide } from './UniverSlide';
+import { CommandService, ICommandService } from '../Service/Command/Command.service';
+import { IUndoRedoService, LocalUndoRedoService } from '../Service/UndoRedo/undoRedo.service';
/**
* Univer.
@@ -130,7 +132,15 @@ export class Univer {
}
private initializeDependencies(): Injector {
- return new Injector([[ObserverManager], [ICurrentUniverService, { useClass: CurrentUniverService }], [CommandManager], [LocaleService], [UndoManager]]);
+ return new Injector([
+ [ObserverManager],
+ [ICurrentUniverService, { useClass: CurrentUniverService }],
+ [CommandManager],
+ [LocaleService],
+ [UndoManager],
+ [ICommandService, { useClass: CommandService }],
+ [IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],
+ ]);
}
private registerUniverPlugin<T extends Plugin>(plugin: PluginCtor<T>, options?: any): void {
diff --git a/packages/core/src/Basics/UniverSheet.ts b/packages/core/src/Basics/UniverSheet.ts
index 27564b0e3f..b1168e92b3 100644
--- a/packages/core/src/Basics/UniverSheet.ts
+++ b/packages/core/src/Basics/UniverSheet.ts
@@ -7,6 +7,7 @@ import { Plugin, PluginCtor, PluginStore } from '../Plugin';
import { GenName, Logger } from '../Shared';
import { VersionCode, VersionEnv } from './Version';
import { WorkBookObserverImpl } from './WorkBookObserverImpl';
+import { CommandService, ICommandService } from '../Service/Command/Command.service';
/**
* Externally provided UniverSheet root instance
@@ -63,7 +64,16 @@ export class UniverSheet implements Disposable {
}
private _initializeDependencies(parentInjector?: Injector): Injector {
- const dependencies: Dependency[] = [[ObserverManager], [GenName]];
+ const dependencies: Dependency[] = [
+ [ObserverManager],
+ [GenName],
+ [
+ ICommandService,
+ {
+ useClass: CommandService,
+ },
+ ],
+ ];
return parentInjector ? parentInjector.createChild(dependencies) : new Injector(dependencies);
}
diff --git a/packages/core/src/Command/ActionBase.ts b/packages/core/src/Command/ActionBase.ts
index b951e8ae0e..316046eda7 100644
--- a/packages/core/src/Command/ActionBase.ts
+++ b/packages/core/src/Command/ActionBase.ts
@@ -1,96 +1,89 @@
-import { ActionObservers, CommonParameter } from './index';
-
-/**
- * Format of action data param
- */
-export interface IActionData {
- actionName: string;
- memberId?: string;
- operation?: ActionOperationType;
-}
-
-/**
- * Action Operation Type
- */
-export enum ActionOperationType {
- /**
- * send obs
- */
- OBSERVER_ACTION = 0x00000001,
-
- /**
- * send server
- */
- SERVER_ACTION = 0x00000002,
-
- /**
- * push to UNDO/REDO stack
- */
- UNDO_ACTION = 0x00000004,
-
- /**
- * action extension
- */
- EXTENSION_ACTION = 0x00000008,
-
- /**
- * default obs
- */
- DEFAULT_ACTION = ActionOperationType.OBSERVER_ACTION |
- ActionOperationType.SERVER_ACTION |
- ActionOperationType.UNDO_ACTION |
- ActionOperationType.EXTENSION_ACTION,
-}
-
-/**
- * Basics class for action
- *
- * @beta
- */
-export abstract class ActionBase<
- D extends IActionData,
- O extends IActionData = D,
- R = void
-> {
- protected _observers: ActionObservers;
-
- protected _doActionData: D;
-
- protected _oldActionData: O;
-
- protected _operation: ActionOperationType;
-
- protected constructor(actionData: D, observers: ActionObservers) {
- this._doActionData = actionData;
- this._observers = observers;
- this._operation = ActionOperationType.OBSERVER_ACTION;
- }
-
- getDoActionData() {
- return this._doActionData;
- }
-
- getOldActionData() {
- return this._oldActionData;
- }
-
- hasOperation(operation: ActionOperationType): boolean {
- return (this._operation & operation) === operation;
- }
-
- addOperation(operation: ActionOperationType) {
- this._operation |= operation;
- }
-
- removeOperation(operation: ActionOperationType) {
- this._operation &= ~operation;
- }
-
- abstract redo(commonParameter?: CommonParameter): void;
-
- abstract undo(commonParameter?: CommonParameter): void;
-
- abstract do(commonParameter?: CommonParameter): R;
-
- abstract validate(): boolean;
-}
+import { ActionObservers, CommonParameter } from './index';
+
+/**
+ * Format of action data param
+ */
+export interface IActionData {
+ actionName: string;
+ memberId?: string;
+ operation?: ActionOperationType;
+}
+
+/**
+ * Action Operation Type
+ */
+export enum ActionOperationType {
+ /**
+ * send obs
+ */
+ OBSERVER_ACTION = 0x00000001,
+
+ /**
+ * send server
+ */
+ SERVER_ACTION = 0x00000002,
+
+ /**
+ * push to UNDO/REDO stack
+ */
+ UNDO_ACTION = 0x00000004,
+
+ /**
+ * action extension
+ */
+ EXTENSION_ACTION = 0x00000008,
+
+ /**
+ * default obs
+ */
+ DEFAULT_ACTION = ActionOperationType.OBSERVER_ACTION | ActionOperationType.SERVER_ACTION | ActionOperationType.UNDO_ACTION | ActionOperationType.EXTENSION_ACTION,
+}
+
+/**
+ * Basics class for action
+ *
+ * @beta
+ */
+export abstract class ActionBase<D extends IActionData, O extends IActionData = D, R = void> {
+ protected _observers: ActionObservers;
+
+ protected _doActionData: D;
+
+ protected _oldActionData: O;
+
+ protected _operation: ActionOperationType;
+
+ protected constructor(actionData: D, observers: ActionObservers) {
+ this._doActionData = actionData;
+ this._observers = observers;
+ this._operation = ActionOperationType.OBSERVER_ACTION;
+ }
+
+ getDoActionData() {
+ return this._doActionData;
+ }
+
+ getOldActionData() {
+ return this._oldActionData;
+ }
+
+ hasOperation(operation: ActionOperationType): boolean {
+ return (this._operation & operation) === operation;
+ }
+
+ addOperation(operation: ActionOperationType) {
+ this._operation |= operation;
+ }
+
+ removeOperation(operation: ActionOperationType) {
+ this._operation &= ~operation;
+ }
+
+ abstract redo(commonParameter?: CommonParameter): void;
+
+ abstract undo(commonParameter?: CommonParameter): void;
+
+ abstract do(commonParameter?: CommonParameter): R;
+
+ abstract validate(): boolean;
+}
diff --git a/packages/core/src/Command/SheetActionBase.ts b/packages/core/src/Command/SheetActionBase.ts
index e86c6ec6bf..7e5f4ef930 100644
--- a/packages/core/src/Command/SheetActionBase.ts
+++ b/packages/core/src/Command/SheetActionBase.ts
@@ -2,6 +2,7 @@ import { Injector } from '@wendellhu/redi';
import { Workbook, Worksheet } from '../Sheets/Domain';
import { ActionBase, IActionData, ActionObservers, CommandUnit } from './index';
+// TODO: @wzhudev: rename this interface to ISheetMutationData
/**
* Format of action data param
*/
@@ -9,6 +10,9 @@ export interface ISheetActionData extends IActionData {
sheetId: string;
rangeRef?: string;
injector?: Injector;
+ actionName: string;
+ memberId?: string;
+ operation?: ActionOperationType;
}
/**
diff --git a/packages/core/src/Command/UndoManager.ts b/packages/core/src/Command/UndoManager.ts
index 5dbf079540..955fdb447f 100644
--- a/packages/core/src/Command/UndoManager.ts
+++ b/packages/core/src/Command/UndoManager.ts
@@ -15,6 +15,8 @@ export class UndoManager {
push(command: Command): void {
this._redoStack.push(command);
+
+ this._undoStack.length = 0;
}
undo(): Command | undefined {
@@ -32,4 +34,4 @@ export class UndoManager {
return command;
}
}
-}
+}
\ No newline at end of file
diff --git a/packages/core/src/Service/Command/Command.service.ts b/packages/core/src/Service/Command/Command.service.ts
new file mode 100644
index 0000000000..f6b52bcdde
--- /dev/null
+++ b/packages/core/src/Service/Command/Command.service.ts
@@ -0,0 +1,239 @@
+import { createIdentifier, IAccessor, IDisposable, Inject, Injector, Optional, SkipSelf } from '@wendellhu/redi';
+import { ActionType, CommandManager, IActionData } from '../../Command';
+import { toDisposable } from '../../Shared/Lifecycle';
+
+export const enum CommandType {
+ /** Command could generate some operations or mutations. */
+ COMMAND = 0,
+ /** An operation that do not require conflict resolve. */
+ OPERATION = 1,
+ /** An operation that need to be resolved before applicated on peer client. */
+ MUTATION = 2,
+}
+
+export interface ICommand<P extends object = object, R = boolean> {
+ /**
+ * ${businessName}.${type}.${name}
+ */
+ readonly id: string;
+
+ readonly type: CommandType;
+
+ handler(accessor: IAccessor, params: P): Promise<R>;
+}
+
+/**
+ * Mutation would change the model of Univer applications.
+ */
+export interface IMutation<P extends object = object, R = boolean> extends ICommand<P, R> {
+ type: CommandType.MUTATION;
+}
+
+/**
+ * Operation would change the state of Univer applications. State should only be in memory and does not
+ * require data confliction.
+ */
+export interface IOperation<P extends object = object> extends ICommand<P> {
+ type: CommandType.OPERATION;
+}
+
+/**
+ * The command info, only a command id and responsible params
+ */
+export interface ICommandInfo<T extends object = object> {
+ // TODO: change object to serializable interface type
+ id: string;
+
+ /**
+ * Args should be serializable.
+ */
+ params?: T;
+}
+
+export interface IExecutionOptions {
+ silent?: boolean;
+}
+
+export type CommandListener = (commandInfo: Readonly<ICommandInfo>) => void;
+
+export interface ICommandService {
+ registerCommand<P extends object>(command: ICommand<P>): IDisposable;
+ executeCommand(id: string, params?: object, options?: IExecutionOptions): Promise<boolean> | boolean;
+
+ /**
+ * Register a hook that will be triggered when the
+ *
+ * @param id the command that will be fired.
+ * @param callback the callback function that would be called
+ */
+ onCommandWillExecute<P extends object = object>(id: string, callback: (params?: P) => ICommandInfo[][]): IDisposable;
+
+ /**
+ * The method that would be trigger when a command is executing. Gather all interceptors and middlewares.
+ * Should return a series of mutations or operations that would be executed as well.
+ *
+ * @param id ID of the command that would be fired
+ * @param params Command parameters
+ *
+ * @returns redo and undo mutations / operations
+ */
+ triggerCommandWillFire<P extends object = object>(id: string, params: P): ICommandInfo[][];
+
+ /**
+ * Register a callback function that will be executed when a command is executed.
+ */
+ onCommandExecuted(listener: CommandListener): IDisposable;
+}
+
+export const ICommandService = createIdentifier<ICommandService>('anywhere.command-service');
+
+/**
+ * The registry of commands.
+ */
+class CommandRegistry {
+ private readonly commands = new Map<string, ICommand>();
+
+ private readonly commandInjector = new Map<string, Injector>();
+
+ registerCommand(command: ICommand, injector: Injector): IDisposable {
+ if (this.commands.has(command.id) || this.commandInjector.has(command.id)) {
+ throw new Error();
+ }
+
+ this.commands.set(command.id, command);
+ this.commandInjector.set(command.id, injector);
+
+ return toDisposable(() => {
+ this.commands.delete(command.id);
+ this.commandInjector.delete(command.id);
+ });
+ }
+
+ getCommand(id: string): [ICommand, Injector] | null {
+ if (!this.commands.has(id) || !this.commandInjector.has(id)) {
+ return null;
+ }
+
+ return [this.commands.get(id)!, this.commandInjector.get(id)!];
+ }
+}
+
+export class CommandService implements ICommandService {
+ private readonly _commandRegistry: CommandRegistry;
+
+ private readonly _commandWillExecuteRegistry: Map<string, Set<(params?: object) => ICommandInfo[][]>> = new Map();
+
+ private readonly _commandExecutedListeners: CommandListener[] = [];
+
+ constructor(@SkipSelf() @Optional(ICommandService) private readonly _parentCommandService: CommandService, @Inject(Injector) private readonly _injector: Injector) {
+ this._commandRegistry = new CommandRegistry();
+ }
+
+ registerCommand(command: ICommand): IDisposable {
+ return this._registerCommand(command, this._injector);
+ }
+
+ onCommandWillExecute<P extends object = object>(id: string, callback: (params?: P) => ICommandInfo[][]): IDisposable {
+ if (this._parentCommandService) {
+ return this._parentCommandService.onCommandWillExecute(id, callback);
+ }
+
+ const set = !this._commandWillExecuteRegistry.has(id)
+ ? (() => {
+ const newSet = new Set<(params?: P) => ICommandInfo[][]>();
+ this._commandWillExecuteRegistry.set(id, newSet as Set<(params?: object) => ICommandInfo[][]>);
+ return newSet;
+ })()
+ : this._commandWillExecuteRegistry.get(id)!;
+
+ set.add(callback);
+
+ return toDisposable(() => {
+ set.delete(callback);
+ if (set.size === 0) {
+ this._commandWillExecuteRegistry.delete(id);
+ }
+ });
+ }
+
+ triggerCommandWillFire<P extends object = object>(id: string, params: P): ICommandInfo[][] {
+ if (this._parentCommandService) {
+ return this._parentCommandService.triggerCommandWillFire(id, params);
+ }
+
+ if (!this._commandWillExecuteRegistry.has(id)) {
+ return [];
+ }
+
+ // TODO: @wzhudev: it may be better to wrapp all undo & redos.
+ return Array.from(this._commandWillExecuteRegistry.get(id)!)
+ .map((interceptor) => interceptor(params))
+ .flat();
+ }
+
+ onCommandExecuted(listener: (commandInfo: ICommandInfo) => void): IDisposable {
+ if (this._parentCommandService) {
+ return this._parentCommandService.onCommandExecuted(listener);
+ }
+
+ if (this._commandExecutedListeners.indexOf(listener) === -1) {
+ this._commandExecutedListeners.push(listener);
+ return toDisposable(() => {
+ const index = this._commandExecutedListeners.indexOf(listener);
+ this._commandExecutedListeners.splice(index, 1);
+ });
+ }
+
+ throw new Error('Could not add a listener twice.');
+ }
+
+ async executeCommand(id: string, params?: object): Promise<boolean> {
+ if (this._parentCommandService) {
+ return this._parentCommandService.executeCommand(id, params);
+ }
+
+ const item = this._commandRegistry.getCommand(id);
+ if (item) {
+ const command = item[0];
+ const injector = item[1];
+
+ await this._execute(command, injector, params);
+
+ const commandInfo: ICommandInfo = {
+ id: command.id,
+ params,
+ };
+
+ // emit command execution info
+ this._commandExecutedListeners.forEach((l) => l(commandInfo));
+
+ return true;
+ }
+
+ throw new Error(`Command "${id}" is not registered.`);
+ }
+
+ private _registerCommand<P extends object>(command: ICommand<P>, injector: Injector): IDisposable {
+ if (this._parentCommandService) {
+ return this._parentCommandService._registerCommand(command, injector);
+ }
+
+ return this._commandRegistry.registerCommand(command, injector);
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ private async _execute(command: ICommand<any>, injector: Injector, params?: object): Promise<boolean> {
+ const result = await injector.invoke(command.handler, params);
+
+ // MOTE: remove from old command manager
+ if (command.type === CommandType.MUTATION) {
+ CommandManager.getActionObservers().notifyObservers({
+ type: ActionType.REDO,
+ data: result as unknown as IActionData,
+ action: null as any,
+ });
+ }
+
+ return result;
+ }
+}
diff --git a/packages/core/src/Service/UndoRedo/undoRedo.service.ts b/packages/core/src/Service/UndoRedo/undoRedo.service.ts
new file mode 100644
index 0000000000..27b64b3455
--- /dev/null
+++ b/packages/core/src/Service/UndoRedo/undoRedo.service.ts
@@ -0,0 +1,138 @@
+import { createIdentifier, IAccessor, IDisposable } from '@wendellhu/redi';
+import { Disposable } from '../../Shared/Lifecycle';
+
+import { CommandService, CommandType, ICommand, ICommandService } from '../Command/Command.service';
+
+// TODO:: an undo redo element may be mergable to another undo redo element
+
+interface IUndoRedoItem {
+ /** */
+ URI: string;
+
+ undo(): Promise<boolean> | boolean;
+ redo(): Promise<boolean> | boolean;
+}
+
+export interface IUndoRedoService {
+ pushUndoRedo(item: IUndoRedoItem): void;
+
+ pitchTopUndoElement(): IUndoRedoItem | null;
+ pitchTopRedoElement(): IUndoRedoItem | null;
+
+ popUndoToRedo(): void;
+ popRedoToUndo(): void;
+}
+
+export const IUndoRedoService = createIdentifier<IUndoRedoService>('univer.undo-redo.service');
+
+/**
+ * This UndoRedoService is local.
+ */
+export class LocalUndoRedoService extends Disposable implements IUndoRedoService {
+ private readonly _undoStack: IUndoRedoItem[] = [];
+
+ private readonly _redoStack: IUndoRedoItem[] = [];
+
+ constructor(@ICommandService private readonly _commandService: CommandService) {
+ super();
+
+ this.disposeWithMe(this._commandService.registerCommand(UndoCommand));
+ this.disposeWithMe(this._commandService.registerCommand(RedoCommand));
+ }
+
+ pushUndoRedo(item: IUndoRedoItem): void {
+ // redo stack should be cleared when push an undo
+ this._redoStack.length = 0;
+
+ // TODO: undo element maybe mergeable
+ // TODO: undo redo stack should have a maximum capacity, maybe we should get the config from IConfigService?
+ this._undoStack.push(item);
+ if (this._undoStack.length > 20) {
+ this._undoStack.splice(0, 1);
+ }
+ }
+
+ pitchTopUndoElement(): IUndoRedoItem | null {
+ if (this._undoStack.length) {
+ return this._undoStack[this._undoStack.length - 1];
+ }
+
+ return null;
+ }
+
+ pitchTopRedoElement(): IUndoRedoItem | null {
+ if (this._redoStack.length) {
+ return this._redoStack[this._redoStack.length - 1];
+ }
+
+ return null;
+ }
+
+ popUndoToRedo(): void {
+ const element = this._undoStack.pop();
+ if (element) {
+ this._redoStack.push(element);
+ }
+ }
+
+ popRedoToUndo(): void {
+ const element = this._redoStack.pop();
+ if (element) {
+ this._undoStack.push(element);
+ }
+ }
+}
+
+abstract class MultiImplementationCommand implements IDisposable {
+ dispose(): void {}
+
+ addCommandHandler(id: string, priority: number = 10) {}
+
+ async dispatchToHandlers(accessor: IAccessor): Promise<boolean> {
+ return false;
+ }
+}
+
+export const UndoCommand = new (class extends MultiImplementationCommand implements ICommand {
+ readonly type = CommandType.COMMAND;
+
+ readonly id = 'univer.command.undo';
+
+ async handler(accessor: IAccessor) {
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const element = undoRedoService.pitchTopUndoElement();
+ if (!element) {
+ return false;
+ }
+
+ const result = await element.undo();
+ if (result) {
+ undoRedoService.popUndoToRedo();
+ return true;
+ }
+
+ return false;
+ }
+})();
+
+export const RedoCommand = new (class extends MultiImplementationCommand implements ICommand {
+ readonly type = CommandType.COMMAND;
+
+ readonly id = 'univer.command.redo';
+
+ async handler(accessor: IAccessor) {
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const element = undoRedoService.pitchTopRedoElement();
+ if (!element) {
+ return false;
+ }
+
+ const result = await element.redo();
+ if (result) {
+ undoRedoService.popRedoToUndo();
+ return true;
+ }
+
+ return false;
+ }
+})();
diff --git a/packages/core/src/Shared/Lifecycle.ts b/packages/core/src/Shared/Lifecycle.ts
new file mode 100644
index 0000000000..7481e3117d
--- /dev/null
+++ b/packages/core/src/Shared/Lifecycle.ts
@@ -0,0 +1,35 @@
+import { IDisposable } from '@wendellhu/redi';
+
+export function toDisposable(callback: () => void): IDisposable {
+ return {
+ dispose: callback,
+ };
+}
+
+export class DisposableCollection implements IDisposable {
+ private readonly _disposables = new Set<IDisposable>();
+
+ add(disposable: IDisposable): IDisposable {
+ this._disposables.add(disposable);
+ return {
+ dispose: () => {
+ disposable.dispose();
+ this._disposables.delete(disposable);
+ },
+ };
+ }
+
+ dispose(): void {}
+}
+
+export class Disposable implements IDisposable {
+ private readonly _collection = new DisposableCollection();
+
+ disposeWithMe(disposable: IDisposable): IDisposable {
+ return this._collection.add(disposable);
+ }
+
+ dispose(): void {
+ this._collection.dispose();
+ }
+}
diff --git a/packages/core/src/Shared/ObjectArray.ts b/packages/core/src/Shared/ObjectArray.ts
index f4bcc4419a..c7bc92cd53 100644
--- a/packages/core/src/Shared/ObjectArray.ts
+++ b/packages/core/src/Shared/ObjectArray.ts
@@ -29,15 +29,15 @@ export type ObjectArrayType<T> = ObjectArray<T> | ObjectArrayPrimitiveType<T>;
const define = <T>(value?: T): value is T => value !== undefined && value !== null;
const likeArr = (value: object): number => {
- let keys: string[] = Object.keys(value);
- let regexp = /^\d+$/;
+ const keys: string[] = Object.keys(value);
+ const regexp = /^\d+$/;
let maxKey = 0;
for (let i = 0; i < keys.length; i++) {
- let key = keys[i];
+ const key = keys[i];
if (!regexp.test(key)) {
return -1;
}
- let seq = parseInt(key) + 1;
+ const seq = parseInt(key) + 1;
if (seq > maxKey) {
maxKey = seq;
}
@@ -78,9 +78,7 @@ export class ObjectArray<T> {
this._length = length;
return;
}
- throw new Error(
- `create object array error ${JSON.stringify(argument[0])}`
- );
+ throw new Error(`create object array error ${JSON.stringify(argument[0])}`);
}
case 2: {
if (likeArr(argument[0]) > -1) {
@@ -88,9 +86,7 @@ export class ObjectArray<T> {
this._length = argument[1];
return;
}
- throw new Error(
- `create object array error ${JSON.stringify(argument[0])}`
- );
+ throw new Error(`create object array error ${JSON.stringify(argument[0])}`);
}
}
}
diff --git a/packages/core/src/Shared/ObjectMatrix.ts b/packages/core/src/Shared/ObjectMatrix.ts
index 1c674dea99..c40379dcb0 100644
--- a/packages/core/src/Shared/ObjectMatrix.ts
+++ b/packages/core/src/Shared/ObjectMatrix.ts
@@ -1,9 +1,5 @@
import { IRangeData } from '../Types/Interfaces/IRangeData';
-import {
- ObjectArray,
- ObjectArrayPrimitiveType,
- PredicateFunction,
-} from './ObjectArray';
+import { ObjectArray, ObjectArrayPrimitiveType, PredicateFunction } from './ObjectArray';
import { Nullable } from './Types';
/**
@@ -50,9 +46,7 @@ export class ObjectMatrix<T> {
return this;
}
- forValue(
- callback: (row: number, col: number, value: T) => Nullable<boolean>
- ): ObjectMatrix<T> {
+ forValue(callback: (row: number, col: number, value: T) => Nullable<boolean>): ObjectMatrix<T> {
const keys = this._option.getKeys();
for (let i = 0; i < keys.length; i++) {
const rowNumber = +keys[i];
@@ -180,12 +174,7 @@ export class ObjectMatrix<T> {
});
}
- getFragments(
- startRow: number,
- endRow: number,
- startColumn: number,
- endColumn: number
- ): ObjectMatrix<T> {
+ getFragments(startRow: number, endRow: number, startColumn: number, endColumn: number): ObjectMatrix<T> {
const objectMatrix = new ObjectMatrix<T>();
for (let r = startRow; r <= endRow; r++) {
const row = new ObjectArray<T>();
@@ -230,9 +219,7 @@ export class ObjectMatrix<T> {
}
toArray(): T[][] {
- return this._option
- .toArray()
- .map((item) => new ObjectArray(item).toArray()) as T[][];
+ return this._option.toArray().map((item) => new ObjectArray(item).toArray()) as T[][];
}
toJSON(): ObjectMatrixPrimitiveType<T> {
@@ -264,11 +251,7 @@ export class ObjectMatrix<T> {
startColumn = columnIndex;
}
const value = this.getValue(rowIndex, columnIndex) as T;
- objectMatrix.setValue(
- rowIndex - startRow,
- columnIndex - startColumn,
- value
- );
+ objectMatrix.setValue(rowIndex - startRow, columnIndex - startColumn, value);
});
});
@@ -316,4 +299,4 @@ export class ObjectMatrix<T> {
this._matrix = matrix;
this._option = new ObjectArray<ObjectArrayPrimitiveType<T>>(matrix);
}
-}
+}
\ No newline at end of file
diff --git a/packages/core/src/Shared/RowColIter.ts b/packages/core/src/Shared/RowColIter.ts
new file mode 100644
index 0000000000..eeaa404025
--- /dev/null
+++ b/packages/core/src/Shared/RowColIter.ts
@@ -0,0 +1,15 @@
+export interface IRowColIter {
+ forEach(cb: (row: number, col: number) => void): void;
+}
+
+export function createRowColIter(rowStart: number, rowEnd: number, colStart: number, colEnd: number): IRowColIter {
+ return {
+ forEach(cb) {
+ for (let r = rowStart; r <= rowEnd; r++) {
+ for (let c = colStart; c <= colEnd; c++) {
+ cb(r, c);
+ }
+ }
+ },
+ };
+}
diff --git a/packages/core/src/Shared/index.ts b/packages/core/src/Shared/index.ts
index 5ca44d33d5..95b6dfa5f3 100644
--- a/packages/core/src/Shared/index.ts
+++ b/packages/core/src/Shared/index.ts
@@ -1,30 +1,30 @@
-// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)
-export * from './ArraySearch';
-export * from './Common';
-export * from './DateTime';
-export * from './ExcelDateTime';
-export * from './Generate';
-export * from './GroupModel';
-export * from './IOHttp';
-export * from './IOSocket';
-export * from './KeyboardUtil';
-export * from './Locale';
-export * from './Logger';
-export * from './Random';
-export * from './GenName';
-export * from './LRU/index';
-export * from './Migrate/index';
-export * from './ObjectArray';
-export * from './ObjectMatrix';
-export * from './Rectangle';
-export * from './Reference';
-export * from './Sequence';
-export * from './Serialize/index';
-export * from './SortRules';
-export * from './Tools';
-export * from './Tuples';
-export * from './Types';
-export * from './TypeStore';
-export * from './HashAlgorithm';
-export * from './Compare';
-// @endindex
+// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)
+export * from './ArraySearch';
+export * from './Common';
+export * from './DateTime';
+export * from './ExcelDateTime';
+export * from './Generate';
+export * from './GroupModel';
+export * from './IOHttp';
+export * from './IOSocket';
+export * from './KeyboardUtil';
+export * from './Locale';
+export * from './Logger';
+export * from './Random';
+export * from './GenName';
+export * from './LRU/index';
+export * from './Migrate/index';
+export * from './ObjectArray';
+export * from './ObjectMatrix';
+export * from './Rectangle';
+export * from './Reference';
+export * from './Sequence';
+export * from './Serialize/index';
+export * from './SortRules';
+export * from './Tools';
+export * from './Tuples';
+export * from './Types';
+export * from './TypeStore';
+export * from './HashAlgorithm';
+export * from './Compare';
+// @endindex
diff --git a/packages/core/src/Sheets/Action/ClearRangeAction.ts b/packages/core/src/Sheets/Action/ClearRangeAction.ts
index 0bb63e1307..ffcd7dd80b 100644
--- a/packages/core/src/Sheets/Action/ClearRangeAction.ts
+++ b/packages/core/src/Sheets/Action/ClearRangeAction.ts
@@ -8,6 +8,7 @@ import { CommandManager, CommandUnit } from '../../Command';
/**
* @internal
+ * @deprecated
*/
export interface IClearRangeActionData extends ISheetActionData {
options: IOptionData;
@@ -17,20 +18,13 @@ export interface IClearRangeActionData extends ISheetActionData {
/**
* Clearly specify a range of styles, content, comments, validation, filtering
*
+ * @deprecated
* @internal
*/
-export class ClearRangeAction extends SheetActionBase<
- IClearRangeActionData,
- ISetRangeDataActionData,
- ObjectMatrixPrimitiveType<ICellData>
-> {
+export class ClearRangeAction extends SheetActionBase<IClearRangeActionData, ISetRangeDataActionData, ObjectMatrixPrimitiveType<ICellData>> {
static NAME = 'ClearRangeAction';
- constructor(
- actionData: IClearRangeActionData,
- commandUnit: CommandUnit,
- observers: ActionObservers
- ) {
+ constructor(actionData: IClearRangeActionData, commandUnit: CommandUnit, observers: ActionObservers) {
super(actionData, commandUnit, observers);
this._doActionData = {
@@ -45,6 +39,8 @@ export class ClearRangeAction extends SheetActionBase<
do(): ObjectMatrixPrimitiveType<ICellData> {
const result = ClearRangeApply(this._commandUnit, this._doActionData);
+
+ // action 不应该跟 undo redo 耦合在一起,因为 action 可能被发送到协同端去
this._observers.notifyObservers({
type: ActionType.REDO,
data: this._doActionData,
diff --git a/packages/core/src/Sheets/Action/InsertRowAction.ts b/packages/core/src/Sheets/Action/InsertRowAction.ts
index 41cf4b0349..913df5fd3f 100644
--- a/packages/core/src/Sheets/Action/InsertRowAction.ts
+++ b/packages/core/src/Sheets/Action/InsertRowAction.ts
@@ -1,11 +1,4 @@
-import {
- SheetActionBase,
- ISheetActionData,
- ActionObservers,
- ActionType,
- CommandUnit,
- CommandManager,
-} from '../../Command';
+import { SheetActionBase, ISheetActionData, ActionObservers, ActionType, CommandUnit, CommandManager } from '../../Command';
import { InsertRowApply, RemoveRowApply } from '../Apply';
import { IRemoveRowActionData } from './RemoveRowAction';
@@ -22,17 +15,10 @@ export interface IInsertRowActionData extends ISheetActionData {
*
* @internal
*/
-export class InsertRowAction extends SheetActionBase<
- IInsertRowActionData,
- IRemoveRowActionData
-> {
+export class InsertRowAction extends SheetActionBase<IInsertRowActionData, IRemoveRowActionData> {
static NAME = 'InsertRowAction';
- constructor(
- actionData: IInsertRowActionData,
- commandUnit: CommandUnit,
- observers: ActionObservers
- ) {
+ constructor(actionData: IInsertRowActionData, commandUnit: CommandUnit, observers: ActionObservers) {
super(actionData, commandUnit, observers);
this._doActionData = {
...actionData,
@@ -71,4 +57,4 @@ export class InsertRowAction extends SheetActionBase<
}
}
-CommandManager.register(InsertRowAction.NAME, InsertRowAction);
+CommandManager.register(InsertRowAction.NAME, InsertRowAction);
\ No newline at end of file
diff --git a/packages/core/src/Sheets/Action/InsertRowDataAction.ts b/packages/core/src/Sheets/Action/InsertRowDataAction.ts
index 981578722f..3e1aac5fa6 100644
--- a/packages/core/src/Sheets/Action/InsertRowDataAction.ts
+++ b/packages/core/src/Sheets/Action/InsertRowDataAction.ts
@@ -20,17 +20,10 @@ export interface IInsertRowDataActionData extends ISheetActionData {
*
* @internal
*/
-export class InsertRowDataAction extends SheetActionBase<
- IInsertRowDataActionData,
- IRemoveRowDataActionData
-> {
+export class InsertRowDataAction extends SheetActionBase<IInsertRowDataActionData, IRemoveRowDataActionData> {
static NAME = 'InsertRowDataAction';
- constructor(
- actionData: IInsertRowDataActionData,
- commandUnit: CommandUnit,
- observers: ActionObservers
- ) {
+ constructor(actionData: IInsertRowDataActionData, commandUnit: CommandUnit, observers: ActionObservers) {
super(actionData, commandUnit, observers);
this._doActionData = {
...actionData,
@@ -70,4 +63,4 @@ export class InsertRowDataAction extends SheetActionBase<
}
}
-CommandManager.register(InsertRowDataAction.NAME, InsertRowDataAction);
+CommandManager.register(InsertRowDataAction.NAME, InsertRowDataAction);
\ No newline at end of file
diff --git a/packages/core/src/Sheets/Action/SetRangeDataAction.ts b/packages/core/src/Sheets/Action/SetRangeDataAction.ts
index 6f838654f6..843645bddd 100644
--- a/packages/core/src/Sheets/Action/SetRangeDataAction.ts
+++ b/packages/core/src/Sheets/Action/SetRangeDataAction.ts
@@ -1,13 +1,6 @@
import { SetRangeDataApply } from '../Apply';
import { ObjectMatrixPrimitiveType } from '../../Shared';
-import {
- SheetActionBase,
- ISheetActionData,
- ActionObservers,
- ActionType,
- CommandUnit,
- CommandManager,
-} from '../../Command';
+import { SheetActionBase, ISheetActionData, ActionObservers, ActionType, CommandUnit, CommandManager, ActionOperationType } from '../../Command';
import { ICopyToOptionsData, ICellData } from '../../Types/Interfaces';
/**
@@ -29,6 +22,9 @@ export interface ISetRangeDataActionData extends ISheetActionData {
cellValue: ObjectMatrixPrimitiveType<ICellData>;
options?: ICopyToOptionsData;
type?: SetRangeDataType;
+ actionName: string;
+ memberId?: string;
+ operation?: ActionOperationType;
}
/**
@@ -36,18 +32,10 @@ export interface ISetRangeDataActionData extends ISheetActionData {
*
* @internal
*/
-export class SetRangeDataAction extends SheetActionBase<
- ISetRangeDataActionData,
- ISetRangeDataActionData,
- ObjectMatrixPrimitiveType<ICellData>
-> {
+export class SetRangeDataAction extends SheetActionBase<ISetRangeDataActionData, ISetRangeDataActionData, ObjectMatrixPrimitiveType<ICellData>> {
static NAME = 'SetRangeDataAction';
- constructor(
- actionData: ISetRangeDataActionData,
- commandUnit: CommandUnit,
- observers: ActionObservers
- ) {
+ constructor(actionData: ISetRangeDataActionData, commandUnit: CommandUnit, observers: ActionObservers) {
super(actionData, commandUnit, observers);
this._doActionData = {
@@ -111,4 +99,4 @@ export class SetRangeDataAction extends SheetActionBase<
}
}
-CommandManager.register(SetRangeDataAction.NAME, SetRangeDataAction);
+CommandManager.register(SetRangeDataAction.NAME, SetRangeDataAction);
\ No newline at end of file
diff --git a/packages/core/src/Sheets/Action/SetRangeStyleAction.ts b/packages/core/src/Sheets/Action/SetRangeStyleAction.ts
index c8278f9626..6fe4ad4706 100644
--- a/packages/core/src/Sheets/Action/SetRangeStyleAction.ts
+++ b/packages/core/src/Sheets/Action/SetRangeStyleAction.ts
@@ -16,11 +16,7 @@ export interface ISetRangeStyleActionData extends ISheetActionData {
export class SetRangeStyleAction extends SheetActionBase<ISetRangeStyleActionData> {
static NAME = 'SetRangeStyleAction';
- constructor(
- actionData: ISetRangeStyleActionData,
- commandUnit: CommandUnit,
- observers: ActionObservers
- ) {
+ constructor(actionData: ISetRangeStyleActionData, commandUnit: CommandUnit, observers: ActionObservers) {
super(actionData, commandUnit, observers);
// store previous data
@@ -86,4 +82,4 @@ export class SetRangeStyleAction extends SheetActionBase<ISetRangeStyleActionDat
}
}
-CommandManager.register(SetRangeStyleAction.NAME, SetRangeStyleAction);
+CommandManager.register(SetRangeStyleAction.NAME, SetRangeStyleAction);
\ No newline at end of file
diff --git a/packages/core/src/Sheets/Apply/InsertDataRow.ts b/packages/core/src/Sheets/Apply/InsertDataRow.ts
index a2fede0c9a..ed24874738 100644
--- a/packages/core/src/Sheets/Apply/InsertDataRow.ts
+++ b/packages/core/src/Sheets/Apply/InsertDataRow.ts
@@ -11,22 +11,15 @@ import { IInsertRowDataActionData } from '../Action';
*
* @internal
*/
-export function InsertDataRow(
- rowIndex: number,
- rowData: ObjectMatrixPrimitiveType<ICellData>,
- primitiveData: ObjectMatrixPrimitiveType<ICellData>
-) {
+export function InsertDataRow(rowIndex: number, rowData: ObjectMatrixPrimitiveType<ICellData>, primitiveData: ObjectMatrixPrimitiveType<ICellData>) {
const wrapper = new ObjectMatrix(primitiveData);
wrapper.insertRows(rowIndex, new ObjectMatrix(rowData));
}
-export function InsertDataRowApply(
- unit: CommandUnit,
- data: IInsertRowDataActionData
-) {
+export function InsertDataRowApply(unit: CommandUnit, data: IInsertRowDataActionData) {
const worksheet = unit.WorkBookUnit!.getSheetBySheetId(data.sheetId);
const primitiveData = worksheet!.getCellMatrix().toJSON();
const wrapper = new ObjectMatrix(primitiveData);
wrapper.insertRows(data.rowIndex, new ObjectMatrix(data.rowData));
-}
+}
\ No newline at end of file
diff --git a/packages/core/src/Sheets/Apply/SetRangeData.ts b/packages/core/src/Sheets/Apply/SetRangeData.ts
index 7176f9af2d..d3b41c3753 100644
--- a/packages/core/src/Sheets/Apply/SetRangeData.ts
+++ b/packages/core/src/Sheets/Apply/SetRangeData.ts
@@ -1,10 +1,11 @@
-import { ICellData, IStyleData } from '../../Types/Interfaces';
-import { Nullable, Tools } from '../../Shared';
import { ObjectMatrix } from '../../Shared/ObjectMatrix';
-import { mergeStyle, transformStyle } from './SetRangeStyle';
import { CommandUnit } from '../../Command';
import { ISetRangeDataActionData } from '../Action';
+// eslint-disable-next-line max-lines-per-function
+/**
+ * @deprecated
+ */
export function SetRangeDataApply(unit: CommandUnit, data: ISetRangeDataActionData) {
const workbook = unit.WorkBookUnit;
const worksheet = workbook!.getSheetBySheetId(data.sheetId)!;
@@ -13,90 +14,44 @@ export function SetRangeDataApply(unit: CommandUnit, data: ISetRangeDataActionDa
const addMatrix = data.cellValue;
const styles = workbook!.getStyles();
+ // FIXME: result should be removed out of the applying process
+
const target = new ObjectMatrix(addMatrix);
- const result = new ObjectMatrix<ICellData>();
+ // FIXME: 不应该写两个循环体,而应该在循环体内判断 options
+ // 另外和 clearRangeValues 的代码重复了
if (options) {
target.forValue((r, c, value) => {
- const cell = cellMatrix.getValue(r, c);
- const newCell: ICellData = {};
-
- if (options.contentsOnly) {
- newCell.m = cell?.m;
- newCell.v = cell?.v;
- }
-
- if (options.formatOnly) {
- // newCell.f = cell?.f;
- newCell.v = cell?.v;
- newCell.m = cell?.m;
- }
-
- result.setValue(r, c, newCell || {});
-
cellMatrix.setValue(r, c, value || {});
});
-
- return result.getData();
}
- target.forValue((r, c, value) => {
- const cell = cellMatrix.getValue(r, c) || {};
+
+ target.forValue((row, col, value) => {
+ const newVal = cellMatrix.getValue(row, col) || {};
// set null, clear cell
if (!value) {
- cellMatrix.setValue(r, c, value);
- result.setValue(r, c, cell);
+ cellMatrix.setValue(row, col, null);
} else {
- // update style
-
- // use null to clear style
- const old = styles.getStyleByCell(cell);
-
- // store old data
- const oldCellStyle = transformStyle(
- old,
- value?.s as Nullable<IStyleData>
- );
- const oldCellData = Tools.deepClone(cell);
- oldCellData.s = oldCellStyle;
-
- result.setValue(r, c, oldCellData);
-
- if (old == null) {
- // clear
- delete cell.s;
- }
-
- // set style
- const merge = mergeStyle(old, value?.s as Nullable<IStyleData>);
-
- // then remove null
- merge && Tools.removeNull(merge);
-
- if (Tools.isEmptyObject(merge)) {
- delete cell.s;
- } else {
- cell.s = styles.setValue(merge);
- }
-
- // update other value TODO: move
if (value.p != null) {
- cell.p = value.p;
+ newVal.p = value.p;
}
+
if (value.v != null) {
- cell.v = value.v;
+ newVal.v = value.v;
}
+
if (value.m != null) {
- cell.m = value.m;
+ newVal.m = value.m;
} else {
- cell.m = String(cell.v);
+ newVal.m = String(newVal.v);
}
+
if (value.t != null) {
- cell.t = value.t;
+ newVal.t = value.t;
}
- cellMatrix.setValue(r, c, cell);
+ cellMatrix.setValue(row, col, newVal);
}
});
- return result.getData();
-}
+}
\ No newline at end of file
diff --git a/packages/core/src/Sheets/Apply/SetRangeStyle.ts b/packages/core/src/Sheets/Apply/SetRangeStyle.ts
index 2183a7e4c2..72b7b3f419 100644
--- a/packages/core/src/Sheets/Apply/SetRangeStyle.ts
+++ b/packages/core/src/Sheets/Apply/SetRangeStyle.ts
@@ -2,13 +2,7 @@ import { ITextStyle } from '../../Types/Interfaces/IDocumentData';
import { Styles } from '../Domain';
import { IRangeData, ICellData, IDocumentData } from '../../Types/Interfaces';
import { IBorderData, IStyleData } from '../../Types/Interfaces/IStyleData';
-import {
- IKeyValue,
- Nullable,
- ObjectMatrix,
- ObjectMatrixPrimitiveType,
- Tools,
-} from '../../Shared';
+import { IKeyValue, Nullable, ObjectMatrix, ObjectMatrixPrimitiveType, Tools } from '../../Shared';
/**
* Set the style. The style sent by the user will be merged into the original style object. If you want to delete a style, you need to explicitly set it to null
@@ -40,10 +34,7 @@ export function SetRangeStyle(
}
// set style
- const merge = mergeStyle(
- old,
- value[r - startRow][c - startColumn] as Nullable<IStyleData>
- );
+ const merge = mergeStyle(old, value[r - startRow][c - startColumn] as Nullable<IStyleData>);
// then remove null
merge && Tools.removeNull(merge);
@@ -57,23 +48,13 @@ export function SetRangeStyle(
// When the rich text sets the cell style, you need to modify the style of all rich text
// TODO redo/undo use setRangeData to undo rich text setting
if (cell.p) {
- mergeRichTextStyle(
- cell.p,
- value[r - startRow][c - startColumn] as Nullable<IStyleData>
- );
+ mergeRichTextStyle(cell.p, value[r - startRow][c - startColumn] as Nullable<IStyleData>);
}
cellMatrix.setValue(r, c, cell);
// store old data
- result.setValue(
- r - startRow,
- c - startColumn,
- transformStyle(
- old,
- value[r - startRow][c - startColumn] as Nullable<IStyleData>
- )
- );
+ result.setValue(r - startRow, c - startColumn, transformStyle(old, value[r - startRow][c - startColumn] as Nullable<IStyleData>));
}
// result.push(rowResult);
@@ -85,10 +66,7 @@ export function SetRangeStyle(
* Convert old style data for storage
* @param style
*/
-export function transformStyle(
- oldStyle: Nullable<IStyleData>,
- newStyle: Nullable<IStyleData>
-): Nullable<IStyleData> {
+export function transformStyle(oldStyle: Nullable<IStyleData>, newStyle: Nullable<IStyleData>): Nullable<IStyleData> {
const backupStyle = transformNormalKey(oldStyle, newStyle);
return backupStyle;
}
@@ -97,10 +75,7 @@ export function transformStyle(
*
* @param style
*/
-export function transformNormalKey(
- oldStyle: Nullable<IStyleData>,
- newStyle: Nullable<IStyleData>
-): Nullable<IStyleData> {
+export function transformNormalKey(oldStyle: Nullable<IStyleData>, newStyle: Nullable<IStyleData>): Nullable<IStyleData> {
// If there is no newly set style, directly store the historical style
if (!newStyle || !Object.keys(newStyle).length) {
return oldStyle;
@@ -125,10 +100,7 @@ export function transformNormalKey(
* @param style
*/
-export function transformBorders(
- oldBorders: IBorderData,
- newBorders: Nullable<IBorderData>
-): IBorderData {
+export function transformBorders(oldBorders: IBorderData, newBorders: Nullable<IBorderData>): IBorderData {
// If there is no newly set border, directly store the historical border
if (!newBorders || !Object.keys(newBorders).length) {
return oldBorders;
@@ -151,11 +123,7 @@ export function transformBorders(
* @param oldStyle
* @param newStyle
*/
-export function mergeStyle(
- oldStyle: Nullable<IStyleData>,
- newStyle: Nullable<IStyleData>,
- isRichText: boolean = false
-): Nullable<IStyleData> {
+export function mergeStyle(oldStyle: Nullable<IStyleData>, newStyle: Nullable<IStyleData>, isRichText: boolean = false): Nullable<IStyleData> {
// clear style
if (newStyle === null) return newStyle;
// don't operate
@@ -189,10 +157,7 @@ export function mergeStyle(
* @param p
* @param newStyle
*/
-export function mergeRichTextStyle(
- p: IDocumentData,
- newStyle: Nullable<IStyleData>
-) {
+export function mergeRichTextStyle(p: IDocumentData, newStyle: Nullable<IStyleData>) {
// p.body?.blockElements.forEach((blockElement) => {
// if (blockElement.blockType === 0) {
// const paragraph = blockElement.paragraph;
@@ -244,4 +209,4 @@ export function mergeRichTextStyle(
textRun.ts = merge as ITextStyle;
}
});
-}
+}
\ No newline at end of file
diff --git a/packages/core/src/Sheets/Domain/Worksheet.ts b/packages/core/src/Sheets/Domain/Worksheet.ts
index 3a551b26f5..27298bb8ad 100644
--- a/packages/core/src/Sheets/Domain/Worksheet.ts
+++ b/packages/core/src/Sheets/Domain/Worksheet.ts
@@ -125,6 +125,7 @@ export class Worksheet {
* Returns WorkSheet Cell Data Matrix
* @returns
*/
+ // TODO: change its name to getWorksheetMatrix?
getCellMatrix(): ObjectMatrix<ICellData> {
return this._cellData;
}
@@ -497,6 +498,7 @@ export class Worksheet {
const { _sheetId } = this;
// TODO: @wzhudev: the two parameters are pretty same, so really not necessary
+ // TODO: @wzhudev: is `insertRowData` really necessary? could it replaced by `setRangeData`?
const insertRowData: IInsertRowDataActionData = {
actionName: InsertRowDataAction.NAME,
sheetId: _sheetId,
@@ -520,6 +522,8 @@ export class Worksheet {
return this;
}
+ // TODO: @wzhudev: the following method would completely be unnecessary
+
/**
* Inserts a number of rows after the given row position.
* @param afterPosition row index
@@ -1553,7 +1557,7 @@ export class Worksheet {
}
/**
- * Unhides the row in the given range.
+ * Unhide the row in the given range.
* @param row row range
* @return WorkSheet Instance
*/
@@ -1972,4 +1976,4 @@ export class Worksheet {
// this._selection = new Selection(this);
this._merges = new Merges(this, this._config.mergeData, this._commandManager, this._currentUniverService);
}
-}
\ No newline at end of file
+}
diff --git a/packages/core/src/Types/Interfaces/ICellData.ts b/packages/core/src/Types/Interfaces/ICellData.ts
index 83b4bb668e..0003698b71 100644
--- a/packages/core/src/Types/Interfaces/ICellData.ts
+++ b/packages/core/src/Types/Interfaces/ICellData.ts
@@ -68,14 +68,9 @@ export interface IFormatData {
/**
* Cell data type
*/
-export type ICellDataType =
- | Nullable<ICellData>
- | Nullable<IStyleData>
- | string
- | number
- | boolean;
+export type ICellDataType = Nullable<ICellData> | Nullable<IStyleData> | string | number | boolean;
/**
* Cell data matrix type
*/
-export type ICellDataMatrix = ICellDataType[][];
+export type ICellDataMatrix = ICellDataType[][];
\ No newline at end of file
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 6aff260366..6e71493a21 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -25,8 +25,12 @@ export * from './Observer';
export * from './Plugin';
export * from './Server';
export * from './Shared';
+export { IRowColIter, createRowColIter } from './Shared/RowColIter';
+export { DisposableCollection, Disposable, toDisposable } from './Shared/Lifecycle';
export * from './Sheets';
export * from './Slides/Domain';
export { ICurrentUniverService } from './Service/Current.service';
export { LocaleService } from './Service/Locale.service';
+export { ICommandService, ICommand, CommandType, IMutation } from './Service/Command/Command.service';
+export { IUndoRedoService, LocalUndoRedoService, UndoCommand, RedoCommand } from './Service/UndoRedo/undoRedo.service';
diff --git a/packages/sheets-plugin-find/package.json b/packages/sheets-plugin-find/package.json
index c33e660fc2..934f3f6db7 100644
--- a/packages/sheets-plugin-find/package.json
+++ b/packages/sheets-plugin-find/package.json
@@ -1,69 +1,69 @@
-{
- "name": "@univerjs/sheets-plugin-find",
- "version": "0.0.1",
- "description": "UniverSheet normal plugin find",
- "keywords": [],
- "author": "DreamNum <[email protected]>",
- "license": "MIT",
- "main": "./src/index.ts",
- "module": "./src/index.ts",
- "types": "./src/Types/index.d.ts",
- "publishConfig": {
- "main": "./lib/univer-sheets-plugin-find.cjs.js",
- "module": "./lib/univer-sheets-plugin-find.js",
- "types": "./lib/index.d.ts",
- "exports": {
- ".": {
- "require": "./lib/univer-sheets-plugin-find.cjs.js",
- "default": "./lib/univer-sheets-plugin-find.js"
- },
- "./*": "./lib/*"
- },
- "access": "public"
- },
- "exports": {
- ".": "./src/index.ts",
- "./*": "./src/*"
- },
- "directories": {
- "lib": "lib"
- },
- "files": [
- "lib"
- ],
- "private": false,
- "scripts": {
- "test": "jest",
- "dev": "vite",
- "build": "tsc && vite build",
- "watch": "vite build",
- "link": "pnpm link ./",
- "serve": "vite preview"
- },
- "devDependencies": {
- "@preact/preset-vite": "2.0.0",
- "@testing-library/preact": "^2.0.1",
- "@types/jest": "^27.5.2",
- "@types/node": "^18.14.0",
- "debug": "^4.3.3",
- "identity-obj-proxy": "^3.0.0",
- "jest-dev-server": "^6.1.1",
- "jest-environment-jsdom": "^29.0.3",
- "less": "^4.1.1",
- "ts-jest": "29.0.1",
- "ts-node": "^10.9.1",
- "typescript": "^4.4.1-rc",
- "vite": "^2.4.4",
- "vite-plugin-external": "1.2.3"
- },
- "dependencies": {
- "@univerjs/base-render": "workspace:^0.0.1",
- "@univerjs/base-sheets": "workspace:^0.0.1",
- "@univerjs/base-ui": "workspace:^0.0.1",
- "@univerjs/common-plugin-data": "workspace:^0.0.1",
- "@univerjs/core": "workspace:^0.0.1",
- "@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "preact": "^10.12.1",
- "@wendellhu/redi": "^0.10.0"
- }
-}
+{
+ "name": "@univerjs/sheets-plugin-find",
+ "version": "0.0.1",
+ "description": "UniverSheet normal plugin find",
+ "keywords": [],
+ "author": "DreamNum <[email protected]>",
+ "license": "MIT",
+ "main": "./src/index.ts",
+ "module": "./src/index.ts",
+ "types": "./src/Types/index.d.ts",
+ "publishConfig": {
+ "main": "./lib/univer-sheets-plugin-find.cjs.js",
+ "module": "./lib/univer-sheets-plugin-find.js",
+ "types": "./lib/index.d.ts",
+ "exports": {
+ ".": {
+ "require": "./lib/univer-sheets-plugin-find.cjs.js",
+ "default": "./lib/univer-sheets-plugin-find.js"
+ },
+ "./*": "./lib/*"
+ },
+ "access": "public"
+ },
+ "exports": {
+ ".": "./src/index.ts",
+ "./*": "./src/*"
+ },
+ "directories": {
+ "lib": "lib"
+ },
+ "files": [
+ "lib"
+ ],
+ "private": false,
+ "scripts": {
+ "test": "jest",
+ "dev": "vite",
+ "build": "tsc && vite build",
+ "watch": "vite build",
+ "link": "pnpm link ./",
+ "serve": "vite preview"
+ },
+ "devDependencies": {
+ "@preact/preset-vite": "2.0.0",
+ "@testing-library/preact": "^2.0.1",
+ "@types/jest": "^27.5.2",
+ "@types/node": "^18.14.0",
+ "debug": "^4.3.3",
+ "identity-obj-proxy": "^3.0.0",
+ "jest-dev-server": "^6.1.1",
+ "jest-environment-jsdom": "^29.0.3",
+ "less": "^4.1.1",
+ "ts-jest": "29.0.1",
+ "ts-node": "^10.9.1",
+ "typescript": "^4.4.1-rc",
+ "vite": "^2.4.4",
+ "vite-plugin-external": "1.2.3"
+ },
+ "dependencies": {
+ "@univerjs/base-render": "workspace:^0.0.1",
+ "@univerjs/base-sheets": "workspace:^0.0.1",
+ "@univerjs/base-ui": "workspace:^0.0.1",
+ "@univerjs/common-plugin-data": "workspace:^0.0.1",
+ "@univerjs/core": "workspace:^0.0.1",
+ "@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
+ "preact": "^10.12.1",
+ "@wendellhu/redi": "^0.12.6"
+ }
+}
diff --git a/packages/sheets-plugin-formula/package.json b/packages/sheets-plugin-formula/package.json
index 8722defd54..5811c53c7d 100644
--- a/packages/sheets-plugin-formula/package.json
+++ b/packages/sheets-plugin-formula/package.json
@@ -63,7 +63,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"preact": "^10.12.1"
}
}
diff --git a/packages/sheets-plugin-import-xlsx/package.json b/packages/sheets-plugin-import-xlsx/package.json
index 5922646ff7..e1010c3a05 100644
--- a/packages/sheets-plugin-import-xlsx/package.json
+++ b/packages/sheets-plugin-import-xlsx/package.json
@@ -59,7 +59,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"luckyexcel": "^1.0.1",
"preact": "^10.12.1"
}
diff --git a/packages/sheets-plugin-numfmt/package.json b/packages/sheets-plugin-numfmt/package.json
index cc9ced91d5..df5586c138 100644
--- a/packages/sheets-plugin-numfmt/package.json
+++ b/packages/sheets-plugin-numfmt/package.json
@@ -64,7 +64,7 @@
"@univerjs/common-plugin-data": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"preact": "^10.12.1"
}
}
\ No newline at end of file
diff --git a/packages/sheets-plugin-operation/package.json b/packages/sheets-plugin-operation/package.json
index c452121580..4a39056589 100644
--- a/packages/sheets-plugin-operation/package.json
+++ b/packages/sheets-plugin-operation/package.json
@@ -60,6 +60,6 @@
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/ui-plugin-sheets": "workspace:^0.0.1",
"preact": "^10.12.1",
- "@wendellhu/redi": "^0.10.0"
+ "@wendellhu/redi": "^0.12.6"
}
}
diff --git a/packages/ui-plugin-docs/package.json b/packages/ui-plugin-docs/package.json
index e36f7e8211..11216a7942 100644
--- a/packages/ui-plugin-docs/package.json
+++ b/packages/ui-plugin-docs/package.json
@@ -58,7 +58,7 @@
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
"@univerjs/base-docs": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1"
}
diff --git a/packages/ui-plugin-sheets/package.json b/packages/ui-plugin-sheets/package.json
index 75fcfa8865..0059500fa5 100644
--- a/packages/ui-plugin-sheets/package.json
+++ b/packages/ui-plugin-sheets/package.json
@@ -62,7 +62,7 @@
"@univerjs/base-sheets": "workspace:^0.0.1",
"@univerjs/base-ui": "workspace:^0.0.1",
"@univerjs/core": "workspace:^0.0.1",
- "@wendellhu/redi": "^0.10.0",
+ "@wendellhu/redi": "^0.12.6",
"css-vars-ponyfill": "^2.4.6",
"preact": "^10.12.1"
}
diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
index 7e57f76f1b..a2a90a837e 100644
--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
@@ -89,11 +89,9 @@ export class ToolbarUIController {
@Inject(ObserverManager) private readonly _observerManager: ObserverManager,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager
) {
- // TODO@huwenzhao: 看到这个真的是要哭了
-
this._config = Tools.deepMerge({}, DefaultToolbarConfig, config);
- // TODO@huwenzhao: toolbar config
+ // TODO: @wzhudev: toolbar configurations should be moved to command system
this._toolList = [
{
toolbarType: 1,
@@ -768,4 +766,4 @@ export class ToolbarUIController {
}
});
}
-}
+}
\ No newline at end of file
diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
index 91f62d28c6..a4974b77d5 100644
--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
@@ -166,5 +166,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {
this._registerManager = this._injector.get(RegisterManager);
this._appUIController = this._injector.createInstance(AppUIController, this._config);
+ this._injector.add([AppUIController, { useValue: this._appUIController }]);
}
-}
+}
\ No newline at end of file
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar-zh.md b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar-zh.md
index 3d310b457f..42531d12a6 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar-zh.md
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar-zh.md
@@ -21,7 +21,7 @@ cover: ''
| forwardRef | preact refs 引用 | `RefObject<HTMLDivElement>` | - |
| func | 回调挂载 | `object` | `{ addButton: Function; }` |
-`IShowToolbarConfig`包含以下配置,默认都为 `true`,可以指定想隐藏的工具栏按钮为`false`
+
```json
{
@@ -89,4 +89,4 @@ const SheetContainer = () => {
></Toolbar>
);
};
-```
+```
\ No newline at end of file
diff --git a/packages/ui-plugin-slides/package.json b/packages/ui-plugin-slides/package.json
index 870bb77791..58d897add9 100644
--- a/packages/ui-plugin-slides/package.json
+++ b/packages/ui-plugin-slides/package.json
@@ -1,65 +1,65 @@
-{
- "name": "@univerjs/ui-plugin-slides",
- "version": "0.0.1",
- "description": "Univer normal ui-plugin-slides",
- "keywords": [],
- "author": "DreamNum <[email protected]>",
- "license": "MIT",
- "main": "./src/index.ts",
- "module": "./src/index.ts",
- "types": "./src/Types/index.d.ts",
- "publishConfig": {
- "main": "./lib/univer-ui-plugin-slides.cjs.js",
- "module": "./lib/univer-ui-plugin-slides.js",
- "types": "./lib/index.d.ts",
- "exports": {
- ".": {
- "require": "./lib/univer-ui-plugin-slides.cjs.js",
- "default": "./lib/univer-ui-plugin-slides.js"
- },
- "./*": "./lib/*"
- },
- "access": "public"
- },
- "exports": {
- ".": "./src/index.ts",
- "./*": "./src/*"
- },
- "directories": {
- "lib": "lib"
- },
- "files": [
- "lib"
- ],
- "private": true,
- "scripts": {
- "test": "jest",
- "dev": "vite",
- "build": "tsc && vite build",
- "watch": "vite build",
- "link": "pnpm link ./",
- "serve": "vite preview"
- },
- "devDependencies": {
- "@preact/preset-vite": "2.0.0",
- "@testing-library/preact": "^2.0.1",
- "@types/jest": "^27.0.1",
- "@types/node": "^16.4.6",
- "@vitejs/plugin-legacy": "^1.5.1",
- "less": "^4.1.1",
- "prettier": "^2.3.2",
- "ts-jest": "29.0.1",
- "ts-node": "^10.2.1",
- "typescript": "^4.4.1-rc",
- "vite": "^2.4.4"
- },
- "dependencies": {
- "@univerjs/base-render": "workspace:^0.0.1",
- "@univerjs/base-slides": "workspace:^0.0.1",
- "@univerjs/base-ui": "workspace:^0.0.1",
- "@univerjs/core": "workspace:^0.0.1",
- "css-vars-ponyfill": "^2.4.6",
- "preact": "^10.12.1",
- "@wendellhu/redi": "^0.10.0"
- }
+{
+ "name": "@univerjs/ui-plugin-slides",
+ "version": "0.0.1",
+ "description": "Univer normal ui-plugin-slides",
+ "keywords": [],
+ "author": "DreamNum <[email protected]>",
+ "license": "MIT",
+ "main": "./src/index.ts",
+ "module": "./src/index.ts",
+ "types": "./src/Types/index.d.ts",
+ "publishConfig": {
+ "main": "./lib/univer-ui-plugin-slides.cjs.js",
+ "module": "./lib/univer-ui-plugin-slides.js",
+ "types": "./lib/index.d.ts",
+ "exports": {
+ ".": {
+ "require": "./lib/univer-ui-plugin-slides.cjs.js",
+ "default": "./lib/univer-ui-plugin-slides.js"
+ },
+ "./*": "./lib/*"
+ },
+ "access": "public"
+ },
+ "exports": {
+ ".": "./src/index.ts",
+ "./*": "./src/*"
+ },
+ "directories": {
+ "lib": "lib"
+ },
+ "files": [
+ "lib"
+ ],
+ "private": true,
+ "scripts": {
+ "test": "jest",
+ "dev": "vite",
+ "build": "tsc && vite build",
+ "watch": "vite build",
+ "link": "pnpm link ./",
+ "serve": "vite preview"
+ },
+ "devDependencies": {
+ "@preact/preset-vite": "2.0.0",
+ "@testing-library/preact": "^2.0.1",
+ "@types/jest": "^27.0.1",
+ "@types/node": "^16.4.6",
+ "@vitejs/plugin-legacy": "^1.5.1",
+ "less": "^4.1.1",
+ "prettier": "^2.3.2",
+ "ts-jest": "29.0.1",
+ "ts-node": "^10.2.1",
+ "typescript": "^4.4.1-rc",
+ "vite": "^2.4.4"
+ },
+ "dependencies": {
+ "@univerjs/base-render": "workspace:^0.0.1",
+ "@univerjs/base-slides": "workspace:^0.0.1",
+ "@univerjs/base-ui": "workspace:^0.0.1",
+ "@univerjs/core": "workspace:^0.0.1",
+ "css-vars-ponyfill": "^2.4.6",
+ "preact": "^10.12.1",
+ "@wendellhu/redi": "^0.12.6"
+ }
}
\ No newline at end of file