generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the file exchange function (#73)
* feat: add the service & command of the exchange plugin * feat: complete the basic import feature * feat: complete the export feature of excel and usheet * fix: remove unnecessary code * feat: add the filter feature & update univer version to 0.1.8 * feat: revert the import feature * feat: add the incremental update feature * feat: add wasm inject * chore: update readme * fix: remove unnecessary files & fix the vite config & make the plugin support the mobile device * fix: fix the exchange function bugs * feat: complete the base function of exchange * fix: enhance the import function, make it quickly as it can * fix: fix the mutation observer function * fix: optimize the file name of save function * chore: remove uncessary css style and ts file * fix: use univerInstanceService instead of mitt
- Loading branch information
1 parent
436c15f
commit 344c583
Showing
27 changed files
with
5,703 additions
and
4,396 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,3 @@ dist | |
|
||
.env | ||
|
||
.npmrc |
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,2 @@ | ||
@univerjs-pro:registry="https://verdaccio.univer.work/" | ||
@univerjs:registry="https://verdaccio.univer.work/" |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,42 @@ | ||
import { | ||
LocaleService, | ||
|
||
Plugin, | ||
UniverInstanceType, | ||
} from '@univerjs/core' | ||
|
||
import type { Dependency } from '@wendellhu/redi' | ||
import { Inject, Injector } from '@wendellhu/redi' | ||
import { ExchangeController } from './controllers/exchange.controller' | ||
import { ExchangeService, IExchangeService } from './services/exchange.service' | ||
import zhCN from './locale/zh-CN' | ||
import enUS from './locale/en-US' | ||
|
||
export class ExchangePlugin extends Plugin { | ||
static override type = UniverInstanceType.UNIVER_SHEET | ||
static override pluginName = 'exchange-client' | ||
constructor( | ||
@Inject(Injector) override readonly _injector: Injector, | ||
@Inject(LocaleService) private readonly _localeService: LocaleService, | ||
) { | ||
super() | ||
} | ||
|
||
initialize() { | ||
this._localeService.load({ | ||
zhCN, | ||
enUS, | ||
}) | ||
|
||
const dependencies: Dependency[] = [ | ||
[ExchangeController], | ||
[IExchangeService, { useClass: ExchangeService }], | ||
] as Dependency[] | ||
|
||
dependencies.forEach(dependency => this._injector.add(dependency)) | ||
} | ||
|
||
override onReady(): void { | ||
this.initialize() | ||
} | ||
} |
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,47 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { ICommand } from '@univerjs/core' | ||
import { CommandType } from '@univerjs/core' | ||
import type { IAccessor } from '@wendellhu/redi' | ||
import { getUploadXlsxFile } from '@/utils/file' | ||
import { IExchangeService } from '@/plugins/services/exchange.service' | ||
|
||
export const ExchangeClientUploadJsonOperation: ICommand = { | ||
id: 'exchange-client.operation.upload-json', | ||
type: CommandType.OPERATION, | ||
handler: async (accessor: IAccessor) => { | ||
const exchangeService = accessor.get(IExchangeService) | ||
|
||
const file = await getUploadXlsxFile() | ||
|
||
if (!file) | ||
return false | ||
|
||
exchangeService.uploadJson(file) | ||
return true | ||
}, | ||
} | ||
|
||
export const ExchangeClientDownloadJsonOperation: ICommand = { | ||
id: 'exchange-client.operation.download-json', | ||
type: CommandType.OPERATION, | ||
handler: async (accessor: IAccessor) => { | ||
const exchangeService = accessor.get(IExchangeService) | ||
exchangeService.downloadJson() | ||
return true | ||
}, | ||
} |
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,38 @@ | ||
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core' | ||
import type { IMenuItemFactory } from '@univerjs/ui' | ||
import { IMenuService } from '@univerjs/ui' | ||
import { Inject, Injector } from '@wendellhu/redi' | ||
import { ExchangeClientDownloadJsonOperation, ExchangeClientUploadJsonOperation } from '../commands/exchange.operation' | ||
import { ExchangeDownloadJsonMenuItemFactory, ExchangeMenuItemFactory, ExchangeUploadJsonMenuItemFactory } from './menu' | ||
|
||
@OnLifecycle(LifecycleStages.Steady, ExchangeController) | ||
export class ExchangeController extends Disposable { | ||
constructor( | ||
@Inject(Injector) private readonly _injector: Injector, | ||
@ICommandService private readonly _commandService: ICommandService, | ||
@IMenuService private readonly _menuService: IMenuService, | ||
) { | ||
super() | ||
this._initCommands() | ||
this._initMenus() | ||
} | ||
|
||
private _initCommands() { | ||
[ | ||
ExchangeClientUploadJsonOperation, | ||
ExchangeClientDownloadJsonOperation, | ||
].forEach((command) => { | ||
this.disposeWithMe(this._commandService.registerCommand(command)) | ||
}) | ||
} | ||
|
||
private _initMenus() { | ||
([ | ||
ExchangeMenuItemFactory, | ||
ExchangeUploadJsonMenuItemFactory, | ||
ExchangeDownloadJsonMenuItemFactory, | ||
] as IMenuItemFactory[]).forEach((factory) => { | ||
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory))) | ||
}) | ||
} | ||
} |
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,37 @@ | ||
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui' | ||
import { MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui' | ||
import type { IAccessor } from '@wendellhu/redi' | ||
import { ExchangeClientDownloadJsonOperation, ExchangeClientUploadJsonOperation } from '@/plugins/commands/exchange.operation' | ||
|
||
const EXCHANGE_OPERATION_ID = 'exchange-client.operation.exchange' | ||
|
||
export function ExchangeMenuItemFactory(): IMenuSelectorItem<string> { | ||
return { | ||
id: EXCHANGE_OPERATION_ID, | ||
group: MenuGroup.TOOLBAR_OTHERS, | ||
type: MenuItemType.SUBITEMS, | ||
icon: 'DirectExportSingle', | ||
tooltip: 'exchange.file', | ||
positions: [MenuPosition.TOOLBAR_START], | ||
} | ||
} | ||
|
||
export function ExchangeUploadJsonMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> { | ||
return { | ||
id: ExchangeClientUploadJsonOperation.id, | ||
type: MenuItemType.BUTTON, | ||
title: 'exchange.uploadJson', | ||
icon: 'FolderSingle', | ||
positions: [EXCHANGE_OPERATION_ID], | ||
} | ||
} | ||
|
||
export function ExchangeDownloadJsonMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> { | ||
return { | ||
id: ExchangeClientDownloadJsonOperation.id, | ||
type: MenuItemType.BUTTON, | ||
title: 'exchange.downloadJson', | ||
icon: 'ExportSingle', | ||
positions: [EXCHANGE_OPERATION_ID], | ||
} | ||
} |
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,9 @@ | ||
export default { | ||
exchange: { | ||
uploadJson: 'Open(File)', | ||
downloadJson: 'Save As', | ||
uploadError: 'Open Failed', | ||
uploading: 'Uploading, please wait...', | ||
file: 'File', | ||
}, | ||
} |
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,9 @@ | ||
export default { | ||
exchage: { | ||
uploadJson: '打开(文件)', | ||
downloadJson: '保存到本地', | ||
uploadError: '打开失败', | ||
uploading: '正在上传,请稍后...', | ||
file: '文件', | ||
}, | ||
} |
Oops, something went wrong.