-
-
Notifications
You must be signed in to change notification settings - Fork 665
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
17 changed files
with
262 additions
and
48 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
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
70 changes: 70 additions & 0 deletions
70
packages/slides-ui/src/commands/operations/insert-text.operation.ts
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,70 @@ | ||
/** | ||
* 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, SlideDataModel } from '@univerjs/core'; | ||
import { CommandType, IUniverInstanceService, PageElementType, Tools, UniverInstanceType } from '@univerjs/core'; | ||
import { CanvasView } from '@univerjs/slides'; | ||
|
||
export interface ISlideAddTextParam { | ||
text: string; | ||
}; | ||
|
||
export const SlideAddTextOperation: ICommand<ISlideAddTextParam> = { | ||
id: 'slide.operation.add-text', | ||
type: CommandType.OPERATION, | ||
handler: async (accessor, params) => { | ||
const elementId = Tools.generateRandomId(6); | ||
const defaultWidth = 220; | ||
const defaultheight = 40; | ||
|
||
const textContent = params?.text || 'A New Text'; | ||
const elmentData = { | ||
id: elementId, | ||
zIndex: 2, | ||
left: 230, | ||
top: 142, | ||
width: defaultWidth, | ||
height: defaultheight, | ||
title: 'text', | ||
description: '', | ||
type: PageElementType.TEXT, | ||
richText: { | ||
text: textContent, | ||
fs: 30, | ||
cl: { | ||
rgb: 'rgb(51, 51, 51)', | ||
}, | ||
bl: 1, | ||
}, | ||
}; | ||
|
||
const univerInstanceService = accessor.get(IUniverInstanceService); | ||
const slideData = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE); | ||
if (!slideData) return false; | ||
|
||
const activePage = slideData.getActivePage()!; | ||
activePage.pageElements[elementId] = elmentData; | ||
slideData.updatePage(activePage.id, activePage); | ||
|
||
const canvasview = accessor.get(CanvasView); | ||
const sceneObject = canvasview.createObjectToPage(elmentData, activePage.id); | ||
if (sceneObject) { | ||
canvasview.setObjectActiveByPage(sceneObject, activePage.id); | ||
} | ||
|
||
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
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
28 changes: 28 additions & 0 deletions
28
packages/slides-ui/src/controllers/slide.render-controller.ts
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,28 @@ | ||
/** | ||
* 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 { RxDisposable } from '@univerjs/core'; | ||
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render'; | ||
|
||
export class SlideRenderController extends RxDisposable implements IRenderModule { | ||
constructor(private readonly _context: IRenderContext<any>) { | ||
super(); | ||
} | ||
|
||
override dispose() { | ||
//... | ||
} | ||
} |
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,36 @@ | ||
/** | ||
* 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 { IAccessor } from '@univerjs/core'; | ||
import { UniverInstanceType } from '@univerjs/core'; | ||
import type { IMenuButtonItem } from '@univerjs/ui'; | ||
import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui'; | ||
import { SlideAddTextOperation } from '../commands/operations/insert-text.operation'; | ||
|
||
export const TEXT_ICON_ID = 'text-single'; | ||
|
||
export function AddTextMenuItemFactory(_accessor: IAccessor): IMenuButtonItem { | ||
return { | ||
id: SlideAddTextOperation.id, | ||
group: MenuGroup.TOOLBAR_FORMULAS_INSERT, | ||
type: MenuItemType.BUTTON, | ||
icon: TEXT_ICON_ID, | ||
title: 'addText', | ||
tooltip: 'addText', | ||
positions: [MenuPosition.TOOLBAR_START], | ||
hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SLIDE), | ||
}; | ||
} |
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
Oops, something went wrong.