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(slides): support partial slides function #2890

Merged
merged 9 commits into from
Jul 30, 2024
Merged
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
35 changes: 34 additions & 1 deletion packages/core/src/slides/slide-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,33 @@
* limitations under the License.
*/

import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../common/unit';
import type { Nullable } from '../shared';
import { Tools } from '../shared';
import { DEFAULT_SLIDE } from '../types/const';
import type { ISlideData, ISlidePage } from '../types/interfaces';
import { PageType } from '../types/interfaces';

export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNIVER_SLIDE> {
override type: UniverInstanceType.UNIVER_SLIDE = UniverInstanceType.UNIVER_SLIDE;
private readonly _activePage$ = new BehaviorSubject<Nullable<ISlidePage>>(null);
private get _activePage(): Nullable<ISlidePage> {
const activePage = this._activePage$.getValue();

if (!activePage) {
const activePageId = this.getPageOrder()?.[0];
if (!activePageId) {
return null;
}

return this.getPages()?.[activePageId];
}

return activePage;
}

readonly activePage$ = this._activePage$.asObservable();

private _snapshot: ISlideData;

Expand Down Expand Up @@ -75,7 +94,7 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
return {
id: 'cover_1',
pageType: PageType.SLIDE,
zIndex: 1,
zIndex: 10,
title: 'cover',
description: 'this is first page, cover',
pageBackgroundFill: {
Expand All @@ -84,4 +103,18 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
pageElements: {},
};
}

setActivePage(page: Nullable<ISlidePage>) {
this._activePage$.next(page);
}

getActivePage() {
return this._activePage;
}

updatePage(pageId: string, page: ISlidePage) {
if (!this._snapshot.body) return;

this._snapshot.body.pages[pageId] = page;
}
}
11 changes: 11 additions & 0 deletions packages/engine-render/src/base-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,21 @@ export const BASE_OBJECT_ARRAY = [
'strokeWidth',
];

export enum ObjectType {
UNKNOWN,
RICH_TEXT,
SHAPE,
IMAGE,
RECT,
CIRCLE,
}

export abstract class BaseObject extends Disposable {
groupKey?: string;
isInGroup: boolean = false;

objectType: ObjectType = ObjectType.UNKNOWN;

onTransformChange$ = new EventSubject<ITransformChangeState>();

onPointerDown$ = new EventSubject<IPointerEvent | IMouseEvent>();
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-render/src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class Layer extends Disposable {
* insert o to _objects[]
* if o is a group, insert all its children and group itself to _objects[]
* @param o
* @returns
* @returns this
*/
addObject(o: BaseObject) {
if (o.classType === RENDER_CLASS_TYPE.GROUP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import type { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType, UniverInstanceType } from '@univerjs/core';
import { createIdentifier, Disposable, Inject, Injector, IUniverInstanceService, remove, toDisposable } from '@univerjs/core';
import type { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType } from '@univerjs/core';
import { createIdentifier, Disposable, Inject, Injector, IUniverInstanceService, remove, toDisposable, UniverInstanceType } from '@univerjs/core';
import type { Observable } from 'rxjs';
import { BehaviorSubject, Subject } from 'rxjs';

Expand Down Expand Up @@ -148,9 +148,17 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
dependencies.push(ctor);

for (const [renderUnitId, render] of this._renderMap) {
const renderType = this._univerInstanceService.getUnitType(renderUnitId);
if (renderType === type) {
(render as RenderUnit).addRenderDependencies([ctor]);
if (type === UniverInstanceType.UNIVER_SLIDE) {
// const renderType = this._univerInstanceService.getUnitType(renderUnitId);
// renderUnitId slide_test cover_1 rect_1....
if (this._univerInstanceService.getUnit(renderUnitId)) {
(render as RenderUnit).addRenderDependencies([ctor]);
}
} else {
const renderType = this._univerInstanceService.getUnitType(renderUnitId);
if (renderType === type) {
(render as RenderUnit).addRenderDependencies([ctor]);
}
}
}

Expand Down Expand Up @@ -217,7 +225,7 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
height,
});

const unit = this._univerInstanceService.getUnit(unitId)!;
const unit = this._univerInstanceService.getUnit(unitId);
let renderUnit: IRender;

if (unit) {
Expand Down
4 changes: 4 additions & 0 deletions packages/engine-render/src/scene.transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,10 @@ export class Transformer extends Disposable implements ITransformerConfig {
return currentScene.getEngine()?.activeScene as Nullable<Scene>;
}

activeAnObject(applyObject: BaseObject) {
this._updateActiveObjectList(applyObject, {} as IPointerEvent);
}

private _updateActiveObjectList(applyObject: BaseObject, evt: IPointerEvent | IMouseEvent) {
const { isCropper } = this._getConfig(applyObject);

Expand Down
3 changes: 3 additions & 0 deletions packages/engine-render/src/shape/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { IKeyValue } from '@univerjs/core';

import { TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '../basics/interfaces';
import type { UniverRenderingContext } from '../context';
import { ObjectType } from '../base-object';
import type { IShapeProps } from './shape';
import { Shape } from './shape';

Expand All @@ -30,6 +31,8 @@ export const CIRCLE_OBJECT_ARRAY = ['radius'];
export class Circle extends Shape<ICircleProps> {
private _radius: number;

override objectType = ObjectType.CIRCLE;

constructor(key?: string, props?: ICircleProps) {
super(key, props);
this._radius = props?.radius || 10;
Expand Down
3 changes: 3 additions & 0 deletions packages/engine-render/src/shape/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { IObjectFullState, ITransformChangeState, IViewportInfo } from '../
import { RENDER_CLASS_TYPE, Vector2 } from '../basics';
import { offsetRotationAxis } from '../basics/offset-rotation-axis';
import type { Scene } from '../scene';
import { ObjectType } from '../base-object';
import type { IShapeProps } from './shape';
import { Shape } from './shape';

Expand Down Expand Up @@ -51,6 +52,8 @@ export class Image extends Shape<IImageProps> {

private _transformCalculateSrcRect: boolean = true;

override objectType = ObjectType.IMAGE;

constructor(id: string, config: IImageProps) {
super(id, config);
this._props = {
Expand Down
3 changes: 3 additions & 0 deletions packages/engine-render/src/shape/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { type IKeyValue, Rectangle } from '@univerjs/core';

import type { UniverRenderingContext } from '../context';
import type { IViewportInfo } from '../basics/vector2';
import { ObjectType } from '../base-object';
import type { IShapeProps } from './shape';
import { Shape } from './shape';

Expand All @@ -30,6 +31,8 @@ export const RECT_OBJECT_ARRAY = ['radius'];
export class Rect<T extends IRectProps = IRectProps> extends Shape<T> {
private _radius: number = 0;

override objectType = ObjectType.RECT;

constructor(key?: string, props?: T) {
super(key, props);
if (props?.radius) {
Expand Down
4 changes: 3 additions & 1 deletion packages/engine-render/src/shape/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type {
} from '@univerjs/core';
import { BooleanNumber, DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentDataModel } from '@univerjs/core';

import { BaseObject } from '../base-object';
import { BaseObject, ObjectType } from '../base-object';
import { TRANSFORM_CHANGE_OBSERVABLE_TYPE } from '../basics/interfaces';
import type { IViewportInfo } from '../basics/vector2';
import { DocumentSkeleton } from '../components/docs/layout/doc-skeleton';
Expand Down Expand Up @@ -77,6 +77,8 @@ export class RichText extends BaseObject {

private _cl?: Nullable<IColorStyle>;

override objectType = ObjectType.RICH_TEXT;

constructor(
private _localeService: LocaleService,
key?: string,
Expand Down
4 changes: 3 additions & 1 deletion packages/engine-render/src/shape/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { IKeyValue, IOffset, IScale, ISize, Nullable } from '@univerjs/core';

import { BASE_OBJECT_ARRAY, BaseObject } from '../base-object';
import { BASE_OBJECT_ARRAY, BaseObject, ObjectType } from '../base-object';
import { SHAPE_TYPE } from '../basics/const';
import type { IObjectFullState } from '../basics/interfaces';
import type { IViewportInfo, Vector2 } from '../basics/vector2';
Expand Down Expand Up @@ -133,6 +133,8 @@ export abstract class Shape<T extends IShapeProps> extends BaseObject {

private _type: SHAPE_TYPE = SHAPE_TYPE.RECT;

override objectType = ObjectType.SHAPE;

constructor(key?: string, props?: T) {
super(key);

Expand Down
1 change: 0 additions & 1 deletion packages/sheets-numfmt/src/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const locale: typeof zhCN = {
subtractDecimal: 'Decreasing decimal places',
customFormat: 'Custom Format',
customFormatDes: 'Generate custom number formats based on existing formats.',

},
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/sheets-numfmt/src/locale/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const locale: typeof zhCN = {
subtractDecimal: 'Уменьшить количество десятичных знаков',
customFormat: 'Custom Format',
customFormatDes: 'Generate custom number formats based on existing formats.',

},
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/sheets-numfmt/src/locale/vi-VN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const locale: typeof zhCN = {
subtractDecimal: 'Giảm chữ số thập phân',
customFormat: 'Custom Format',
customFormatDes: 'Generate custom number formats based on existing formats.',

},
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/sheets-numfmt/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const locale = {
subtractDecimal: '减少小数位',
customFormat: '自定义格式',
customFormatDes: '根据现有格式生成自定义数字格式。',

},
},
};
Expand Down
11 changes: 5 additions & 6 deletions packages/sheets-numfmt/src/locale/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ const locale: typeof zhCN = {
currencyDes: '貨幣格式用來表示一般貨幣數值。會計格式可以對一列數值進行小數點對齊',
accountingDes: '會計數字格式可對一列數值進行貨幣符號和小數點對齊',
dateType: '日期類型',
dateDes: '日期格式將日期和時間系列數值品顯示為日期值。 ',
dateDes: '日期格式將日期和時間系列數值品顯示為日期值。',
negType: '負數型別',
generalDes: '常規格式不包含任何特定的數字格式。 ',
thousandthPercentileDes: '千分位符號格式用於一般數字的表示。貨幣和會計格式則提供貨幣值計算的專用格式。 ',
generalDes: '常規格式不包含任何特定的數字格式。',
thousandthPercentileDes: '千分位符號格式用於一般數字的表示。貨幣和會計格式則提供貨幣值計算的專用格式。',
addDecimal: '增加小數位',
subtractDecimal: '減少小數位',
customFormat: '自定义格式',
customFormatDes: '根据现有格式生成自定义数字格式。',

customFormat: 'Custom Format',
customFormatDes: 'Generate custom number formats based on existing formats.',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class SheetRenderController extends RxDisposable implements IRenderModule

private _addNewRender() {
const { scene, engine, unit: workbook } = this._context;

scene.addLayer(new Layer(scene, [], 0), new Layer(scene, [], 2));

this._addComponent(workbook);
Expand Down
10 changes: 8 additions & 2 deletions packages/slides-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@univerjs/slides-ui",
"version": "0.2.5",
"private": false,
"private": true,
"description": "Univer normal ui-plugin-slides",
"author": "DreamNum <developer@univer.ai>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -67,16 +67,22 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/slides": "workspace:*",
"@univerjs/ui": "workspace:*",
"clsx": ">=2.0.0",
"react": "^16.9.0 || ^17.0.0 || ^18.0.0"
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.65"
},
"devDependencies": {
"@types/react": "^18.3.3",
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/slides": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import type { IAccessor, IOperation } from '@univerjs/core';
import { CommandType } from '@univerjs/core';
import type { IAccessor, IOperation, SlideDataModel } from '@univerjs/core';
import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { CanvasView } from '@univerjs/slides';

export interface IActiveSlidePageOperationParams {
Expand All @@ -26,6 +26,18 @@ export const ActivateSlidePageOperation: IOperation<IActiveSlidePageOperationPar
type: CommandType.OPERATION,
handler: (accessor: IAccessor, params: IActiveSlidePageOperationParams) => {
const canvasView = accessor.get(CanvasView);
const univerInstanceService = accessor.get(IUniverInstanceService);
const model = univerInstanceService.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
const id = model?.getActivePage()?.id;

if (!id) return false;

const page = canvasView.getRenderUnitByPageId(id);
const transformer = page.scene?.getTransformer();

if (!transformer) return false;
transformer.clearControls();

canvasView.activePage(params.id);
return true;
},
Expand Down
Loading
Loading