-
-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
901 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
"name": "@univerjs/uniui", | ||
"version": "0.0.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", | ||
"rxjs": ">=7.0.0" | ||
}, | ||
"dependencies": { | ||
"@univerjs/icons": "^0.1.46", | ||
"rc-util": "^5.43.0" | ||
}, | ||
"devDependencies": { | ||
"@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", | ||
"rxjs": "^7.8.1", | ||
"typescript": "^5.4.5", | ||
"vite": "^5.2.11", | ||
"vitest": "^1.6.0" | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
packages-experimental/uniui/src/controllers/uniui-desktop.controller.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* 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 { IRenderManagerService } from '@univerjs/engine-render'; | ||
import type { IWorkbenchOptions } from '@univerjs/ui'; | ||
import { BuiltInUIPart, CanvasPopup, FloatDom, ILayoutService, IUIPartsService } from '@univerjs/ui'; | ||
import type { IDisposable } from '@wendellhu/redi'; | ||
import { Inject, Injector, Optional } 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( | ||
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService, | ||
@Inject(Injector) private readonly _injector: Injector, | ||
@Inject(LifecycleService) private readonly _lifecycleService: LifecycleService, | ||
@IUIPartsService private readonly _uiPartsService: IUIPartsService, | ||
@Optional(ILayoutService) private readonly _layoutService?: ILayoutService | ||
) { | ||
super(); | ||
this._initBuiltinComponents(); | ||
} | ||
|
||
bootstrapWorkbench(options: IWorkbenchOptions): void { | ||
this.disposeWithMe( | ||
bootstrap(this._injector, options, () => { | ||
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.CONTENT, () => 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.