Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unimode #2551

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@univerjs/thread-comment-ui": "workspace:*",
"@univerjs/ui": "workspace:*",
"@univerjs/uniscript": "workspace:*",
"@univerjs/uniui": "workspace:*",
"@wendellhu/redi": "0.15.5",
"clsx": "^2.1.1",
"monaco-editor": "0.50.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { IWorkbookData } from '@univerjs/core';
import { BooleanNumber, BorderStyleTypes, LocaleType } from '@univerjs/core';

export const DEFAULT_WORKBOOK_DATA_DEMO1: IWorkbookData = {
id: 'workbook-01',
id: 'workbook-001',
locale: LocaleType.ZH_CN,
name: 'universheet',
sheetOrder: ['sheet-0003'],
Expand Down
24 changes: 12 additions & 12 deletions examples/src/uni/lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

import type { Plugin, PluginCtor } from '@univerjs/core';
import { UniverSheetsFilterUIPlugin } from '@univerjs/sheets-filter-ui';
import { UniverUniscriptPlugin } from '@univerjs/uniscript';
// import { UniverUniscriptPlugin } from '@univerjs/uniscript';

export default function getLazyPlugins(): Array<[PluginCtor<Plugin>] | [PluginCtor<Plugin>, unknown]> {
return [
[
UniverUniscriptPlugin,
{
getWorkerUrl(moduleID: string, label: string) {
if (label === 'typescript' || label === 'javascript') {
return './vs/language/typescript/ts.worker.js';
}
// [
// UniverUniscriptPlugin,
// {
// getWorkerUrl(moduleID: string, label: string) {
// if (label === 'typescript' || label === 'javascript') {
// return './vs/language/typescript/ts.worker.js';
// }

return './vs/editor/editor.worker.js';
},
},
],
// return './vs/editor/editor.worker.js';
// },
// },
// ],
[UniverSheetsFilterUIPlugin],
];
}
9 changes: 5 additions & 4 deletions examples/src/uni/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import { UniverSheetsPlugin } from '@univerjs/sheets';
import { UniverSheetsFormulaPlugin } from '@univerjs/sheets-formula';
import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
import { UniverUIPlugin } from '@univerjs/ui';
import { UniverUniUIPlugin } from '@univerjs/uniui';
import { UniverDebuggerPlugin } from '@univerjs/debugger';
import { FUniver } from '@univerjs/facade';
import { UniverDrawingPlugin } from '@univerjs/drawing';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '../data/sheets/demo/default-workbook-data-demo';
import { enUS } from '../locales';
import { DEFAULT_WORKBOOK_DATA_DEMO1 } from '../data';

/* eslint-disable-next-line node/prefer-global/process */
const IS_E2E: boolean = !!process.env.IS_E2E;
Expand All @@ -52,7 +52,7 @@ univer.registerPlugin(UniverDocsPlugin, {
});
univer.registerPlugin(UniverFormulaEnginePlugin);
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, {
univer.registerPlugin(UniverUniUIPlugin, {
container: 'app',
});

Expand All @@ -64,12 +64,13 @@ univer.registerPlugin(UniverSheetsPlugin);
univer.registerPlugin(UniverSheetsUIPlugin);

univer.registerPlugin(UniverSheetsNumfmtPlugin);
univer.registerPlugin(UniverSheetsZenEditorPlugin);
univer.registerPlugin(UniverSheetsFormulaPlugin);

// create univer sheet instance
if (!IS_E2E) {
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO);
univer.createUnit(UniverInstanceType.UNIVER_SHEET, DEFAULT_WORKBOOK_DATA_DEMO1);
// univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_CN);
}

// debugger plugin
Expand Down
3 changes: 3 additions & 0 deletions packages-experimental/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Experimental Packages

Experimental packages in development. These packages are not meant to be published to npm or used in production.
16 changes: 16 additions & 0 deletions packages-experimental/uniui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @univerjs/uniui

[![npm version](https://img.shields.io/npm/v/@univerjs/uniui)](https://npmjs.org/packages/@univerjs/uniui)
[![license](https://img.shields.io/npm/l/@univerjs/uniui)](https://img.shields.io/npm/l/@univerjs/uniui)

## Introduction

> TODO: Introduction
## Usage

### Installation

```shell
npm i @univerjs/uniui
```
95 changes: 95 additions & 0 deletions packages-experimental/uniui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"name": "@univerjs/uniui",
"version": "0.2.1",
"private": true,
"description": "",
"author": "DreamNum <[email protected]>",
"license": "Apache-2.0",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/univer"
},
"homepage": "https://univer.ai",
"repository": {
"type": "git",
"url": "https://github.com/dream-num/univer"
},
"bugs": {
"url": "https://github.com/dream-num/univer/issues"
},
"keywords": [],
"sideEffects": [
"**/*.css"
],
"exports": {
".": "./src/index.ts",
"./*": "./src/*"
},
"main": "./lib/cjs/index.js",
"module": "./lib/es/index.js",
"types": "./lib/types/index.d.ts",
"publishConfig": {
"access": "public",
"main": "./lib/cjs/index.js",
"module": "./lib/es/index.js",
"exports": {
".": {
"import": "./lib/es/index.js",
"require": "./lib/cjs/index.js",
"types": "./lib/types/index.d.ts"
},
"./*": {
"import": "./lib/es/*",
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
"./lib/*": "./lib/*"
}
},
"directories": {
"lib": "lib"
},
"files": [
"lib"
],
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
"coverage": "vitest run --coverage",
"lint:types": "tsc --noEmit",
"build": "tsc && vite build"
},
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/ui": "workspace:*",
"@wendellhu/redi": ">=0.12.13",
"clsx": ">=2.0.0",
"react": ">=16.9.0",
"react-dom": "18.3.1",
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.46",
"rc-util": "^5.43.0"
},
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/ui": "workspace:*",
"@wendellhu/redi": "^0.15.2",
"clsx": "^2.1.1",
"less": "^4.2.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"rxjs": "^7.8.1",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Disposable, LifecycleService, LifecycleStages, toDisposable } from '@univerjs/core';
import type { IUniverUIConfig, IWorkbenchOptions } from '@univerjs/ui';
import { BuiltInUIPart, CanvasPopup, FloatDom, IUIPartsService } from '@univerjs/ui';
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { connectInjector } from '@wendellhu/redi/react-bindings';
import React from 'react';
import { delay, filter, take } from 'rxjs';
import { render as createRoot, unmount } from 'rc-util/lib/React/render';

import { UniWorkbench } from '../views/workbench/UniWorkbench';

const STEADY_TIMEOUT = 3000;

export class UniverUniUIController extends Disposable {
constructor(
private readonly _config: IUniverUIConfig,
@Inject(Injector) private readonly _injector: Injector,
@Inject(LifecycleService) private readonly _lifecycleService: LifecycleService,
@IUIPartsService private readonly _uiPartsService: IUIPartsService
) {
super();

this._initBuiltinComponents();

Promise.resolve().then(() => this._bootstrapWorkbench());
}

private _bootstrapWorkbench(): void {
this.disposeWithMe(
bootstrap(this._injector, this._config, () => {
this._lifecycleService.lifecycle$.pipe(
filter((lifecycle) => lifecycle === LifecycleStages.Ready),
delay(300),
take(1)
).subscribe(() => {
this._lifecycleService.stage = LifecycleStages.Rendered;
setTimeout(() => this._lifecycleService.stage = LifecycleStages.Steady, STEADY_TIMEOUT);
});
})
);
}

private _initBuiltinComponents() {
this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FLOATING, () => connectInjector(CanvasPopup, this._injector)));
this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(FloatDom, this._injector)));
}
}

function bootstrap(
injector: Injector,
options: IWorkbenchOptions,
callback: () => void
): IDisposable {
let mountContainer: HTMLElement;

const container = options.container;
if (typeof container === 'string') {
const containerElement = document.getElementById(container);
if (!containerElement) {
mountContainer = createContainer(container);
} else {
mountContainer = containerElement;
}
} else if (container instanceof HTMLElement) {
mountContainer = container;
} else {
mountContainer = createContainer('univer');
}

const ConnectedApp = connectInjector(UniWorkbench, injector);
function render() {
createRoot(
<ConnectedApp
{...options}
mountContainer={mountContainer}
onRendered={callback}
/>,
mountContainer
);
}

render();

return toDisposable(() => {
unmount(mountContainer);
});
}

function createContainer(id: string): HTMLElement {
const element = document.createElement('div');
element.id = id;
// FIXME: the element is not append to the DOM tree. So it won't be rendered.
return element;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,4 @@
* limitations under the License.
*/

import React from 'react';

import styles from './index.module.less';

/**
* Doc standalone background
*/
export const DocBackground = () => {
return (
<div className={styles.docsUiCanvasBackground}></div>
);
};
export { UniverUniUIPlugin } from './plugin';
Loading
Loading