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/upgrade vrender 0.22.0 vstory.5 #224

Merged
merged 3 commits into from
Jan 18, 2025
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
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
* PNPM documentation: https://pnpm.io/package_json#pnpmoverrides
*/
"globalOverrides": {
// "@visactor/vrender": "0.21.5-vstory.2",
// "@visactor/vrender-core": "0.21.5-vstory.2",
// "@visactor/vrender-kits": "0.21.5-vstory.2",
// "@visactor/vrender-components": "0.21.5-vstory.2",
// "@visactor/vrender": "0.22.0-vstory.5",
// "@visactor/vrender-core": "0.22.0-vstory.5",
// "@visactor/vrender-kits": "0.22.0-vstory.5",
// "@visactor/vrender-components": "0.22.0-vstory.5",
// "@visactor/vscale": "0.18.5"
// "example2": "npm:@company/example2@^1.0.0"
},
Expand Down
352 changes: 169 additions & 183 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/assets/examples/en/character/vgraphic.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const characterList = [

const story = new VStory.Story(null, {
dom: CONTAINER_ID,
width: 400,
width: 500,
height: 400,
scaleX: 'auto',
scaleY: 'auto',
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/examples/zh/character/vgraphic.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const characterList = [

const story = new VStory.Story(null, {
dom: CONTAINER_ID,
width: 400,
width: 500,
height: 400,
scaleX: 'auto',
scaleY: 'auto',
Expand Down
10 changes: 5 additions & 5 deletions packages/vstory-animate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"test-watch": "DEBUG_MODE=1 jest --watch"
},
"dependencies": {
"@visactor/vchart": "1.13.3-vstory.3",
"@visactor/vchart": "1.13.5-vstory.1",
"@visactor/vtable": "1.14.4-alpha.0",
"@visactor/vrender": "0.21.5-vstory.2",
"@visactor/vrender-core": "0.21.5-vstory.2",
"@visactor/vrender-kits": "0.21.5-vstory.2",
"@visactor/vrender-components": "0.21.5-vstory.2",
"@visactor/vrender": "0.22.0-vstory.5",
"@visactor/vrender-core": "0.22.0-vstory.5",
"@visactor/vrender-kits": "0.22.0-vstory.5",
"@visactor/vrender-components": "0.22.0-vstory.5",
"@visactor/vutils": "~0.18.17",
"@visactor/vchart-extension": "0.0.3-vstory.2",
"@visactor/vdataset": "~0.18.17",
Expand Down
10 changes: 5 additions & 5 deletions packages/vstory-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"test-watch": "DEBUG_MODE=1 jest --watch"
},
"dependencies": {
"@visactor/vchart": "1.13.3-vstory.3",
"@visactor/vchart": "1.13.5-vstory.1",
"@visactor/vtable": "1.14.4-alpha.0",
"@visactor/vrender": "0.21.5-vstory.2",
"@visactor/vrender-core": "0.21.5-vstory.2",
"@visactor/vrender-kits": "0.21.5-vstory.2",
"@visactor/vrender-components": "0.21.5-vstory.2",
"@visactor/vrender": "0.22.0-vstory.5",
"@visactor/vrender-core": "0.22.0-vstory.5",
"@visactor/vrender-kits": "0.22.0-vstory.5",
"@visactor/vrender-components": "0.22.0-vstory.5",
"@visactor/vutils": "~0.18.17",
"@visactor/vchart-extension": "0.0.3-vstory.2",
"@visactor/vdataset": "~0.18.17",
Expand Down
19 changes: 14 additions & 5 deletions packages/vstory-core/src/character/character-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import type { ICharacterRuntimeConfig, ILayoutLine } from './../interface/charac
import type { IGraphic } from '@visactor/vrender-core';
import { Generator } from '@visactor/vrender-core';
import type { ICharacter } from '../interface/character';
import type { ICharacterConfig, ICharacterInitOption } from '../interface/dsl/dsl';
import type { ICharacterConfig, ICharacterInitOption, IUpdateConfigParams } from '../interface/dsl/dsl';
import { cloneDeep, isArray } from '@visactor/vutils';
import type { ICharacterPickInfo, IStoryEvent } from '../interface/event';
import type { IStory } from '../interface/story';
import type { IStoryCanvas } from '../interface/canvas';
import type { IConfigProcess } from './config-transform/interface';
import type { IUpdateConfigParams } from './chart/interface/runtime';
import { getLayoutLine } from '../utils/layout';
import { foreachAllConstructor } from '../utils/type';
import { ThemeManager } from '../theme/theme-manager';
import { RuntimeStore } from '../store';
import { Events } from '../constants/events';

export abstract class CharacterBase<T> implements ICharacter {
readonly id: string;
Expand Down Expand Up @@ -56,8 +56,16 @@ export abstract class CharacterBase<T> implements ICharacter {
this._canvas = option.canvas;
}

setConfig(config: Partial<IUpdateConfigParams>, forceMergeOption: boolean = true) {
if (forceMergeOption === false) {
setConfig(
config: Partial<IUpdateConfigParams>,
params: {
forceMergeOption?: boolean;
mode?: number;
} = {}
) {
const { forceMergeOption = true } = params;
this.story.emit(Events.BEFORE_SET_CONFIG, { config, character: this, params });
if (!forceMergeOption) {
const { options, ...rest } = config;
this.configProcess.updateConfig(rest, config, this._config);
this._config.options = options;
Expand All @@ -68,6 +76,7 @@ export abstract class CharacterBase<T> implements ICharacter {
this.applyConfigToAttribute(diffConfig, this._config);
}
this._setAttributes(this._attribute);
this.story.emit(Events.AFTER_SET_CONFIG, { config, character: this, params });
}

init(): void {
Expand Down Expand Up @@ -102,7 +111,7 @@ export abstract class CharacterBase<T> implements ICharacter {
this.init();
}

protected diffConfig(config: IUpdateConfigParams): IUpdateConfigParams {
diffConfig(config: IUpdateConfigParams): IUpdateConfigParams {
return config;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vstory-core/src/character/chart/character-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { CharacterBase } from '../character-base';
import type { IChartGraphicAttribute } from './graphic/vchart-graphic';
import { VChartGraphic } from './graphic/vchart-graphic';
import { getChartModelWithEvent } from './utils/vchart-pick';
import type { ICharacterConfig, ICharacterInitOption } from '../../interface/dsl/dsl';
import type { ICharacterConfig, ICharacterInitOption, IUpdateConfigParams } from '../../interface/dsl/dsl';
import type { IChartCharacterConfig } from '../../interface/dsl/chart';
import { getLayoutFromWidget } from '../../utils/layout';
import type { IChartCharacterRuntime, IUpdateConfigParams } from './interface/runtime';
import type { IChartCharacterRuntime } from './interface/runtime';
import { ChartConfigProcess } from './chart-config-process';
import type { ICharacterChart } from './interface/character-chart';
import { mergeChartOption } from '../../utils/chart';
Expand Down
2 changes: 0 additions & 2 deletions packages/vstory-core/src/character/chart/interface/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ export interface IChartCharacterRuntime {
export interface IChartCharacterRuntimeConstructor {
new (): IChartCharacterRuntime;
}

export type IUpdateConfigParams = Omit<Partial<ICharacterConfig>, 'id' | 'type'>;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IGraphic } from '@visactor/vrender-core';
import { CharacterBase } from '../character-base';
import type { IComponentCharacterConfig } from '../../interface/dsl/component';
import type { IComponentCharacterRuntime, IUpdateConfigParams } from './interface/runtime';
import type { ICharacterInitOption } from '../../interface/dsl/dsl';
import type { IComponentCharacterRuntime } from './interface/runtime';
import type { ICharacterInitOption, IUpdateConfigParams } from '../../interface/dsl/dsl';
import { ComponentConfigProcess } from './component-config-process';
import type { ICharacterComponent } from './interface/character-component';
import type { IStoryEvent, ICharacterPickInfo } from '../../interface/event';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ export interface IComponentCharacterRuntime {
export interface IComponentCharacterRuntimeConstructor {
new (): IComponentCharacterRuntime;
}

export type IUpdateConfigParams = Omit<Partial<ICharacterConfig>, 'id' | 'type'>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cloneDeep, isValid, merge } from '@visactor/vutils';
import type { ICharacter } from '../../interface/character';
import { deepMergeWithDeletedAttr } from '../../utils/merge';
import type { IConfigProcess } from './interface';
import type { IUpdateConfigParams } from '../chart/interface/runtime';
import type { IUpdateConfigParams } from '../../interface/dsl/dsl';

export class ConfigProcessBase implements IConfigProcess {
protected _character: ICharacter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ICharacter } from '../../interface/character';
import type { IUpdateConfigParams } from '../chart/interface/runtime';
import type { IUpdateConfigParams } from '../../interface/dsl/dsl';

export interface IConfigProcess {
checkEnable: (diffConfig: IUpdateConfigParams, config: IUpdateConfigParams) => boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/vstory-core/src/character/table/character-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type { ICharacterPickInfo, IStoryEvent } from '../../interface/event';
import { CharacterBase } from '../character-base';
import type { ITableGraphicAttribute } from './graphic/vtable-graphic';
import { VTableGraphic } from './graphic/vtable-graphic';
import type { ICharacterConfig, ICharacterInitOption } from '../../interface/dsl/dsl';
import type { ICharacterConfig, ICharacterInitOption, IUpdateConfigParams } from '../../interface/dsl/dsl';
import type { ITableCharacterConfig } from '../../interface/dsl/table';
import { getLayoutFromWidget } from '../../utils/layout';
import type { ITableCharacterRuntime, IUpdateConfigParams } from './interface/runtime';
import type { ITableCharacterRuntime } from './interface/runtime';
import { TableConfigProcess } from './table-config-process';
import type { ICharacterTable, IVTable } from './interface/character-table';
import { isArray } from '@visactor/vutils';
Expand Down
2 changes: 0 additions & 2 deletions packages/vstory-core/src/character/table/interface/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ export interface ITableCharacterRuntime {
export interface ITableCharacterRuntimeConstructor {
new (): ITableCharacterRuntime;
}

export type IUpdateConfigParams = Omit<Partial<ICharacterConfig>, 'id' | 'type'>;
4 changes: 4 additions & 0 deletions packages/vstory-core/src/constants/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const Events = {
BEFORE_SET_CONFIG: 'beforeSetConfig',
AFTER_SET_CONFIG: 'afterSetConfig'
};
70 changes: 70 additions & 0 deletions packages/vstory-core/src/core/plugin-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { IPlugin, IPluginService } from '../interface/plugin-service';
import type { IStory } from '../interface/story';

export class DefaultPluginService implements IPluginService {
declare onStartupFinishedPlugin: IPlugin[];
declare onRegisterPlugin: IPlugin[];
declare story: IStory;
declare actived: boolean;

constructor() {
this.onStartupFinishedPlugin = [];
this.onRegisterPlugin = [];
this.actived = false;
}

active(story: IStory, params: { pluginList?: IPlugin[] }) {
this.story = story;
this.actived = true;

// 启动插件
const { pluginList } = params;
pluginList &&
pluginList.forEach(p => {
this.register(p);
});
}

findPluginsByName(name: string): IPlugin[] {
const arr: IPlugin[] = [];
this.onStartupFinishedPlugin.forEach(plugin => {
if (plugin.name === name) {
arr.push(plugin);
}
});
this.onRegisterPlugin.forEach(plugin => {
if (plugin.name === name) {
arr.push(plugin);
}
});
return arr;
}

register(plugin: IPlugin) {
if (plugin.activeEvent === 'onStartupFinished') {
this.onStartupFinishedPlugin.push(plugin);
} else if (plugin.activeEvent === 'onRegister') {
this.onRegisterPlugin.push(plugin);
plugin.activate(this);
}
}
unRegister(plugin: IPlugin) {
if (plugin.activeEvent === 'onStartupFinished') {
this.onStartupFinishedPlugin.splice(this.onStartupFinishedPlugin.indexOf(plugin), 1);
} else if (plugin.activeEvent === 'onRegister') {
this.onRegisterPlugin.splice(this.onStartupFinishedPlugin.indexOf(plugin), 1);
}
plugin.deactivate(this);
}

release(...params: any): void {
this.onStartupFinishedPlugin.forEach(plugin => {
plugin.deactivate(this);
});
this.onStartupFinishedPlugin = [];
this.onRegisterPlugin.forEach(plugin => {
plugin.deactivate(this);
});
this.onRegisterPlugin = [];
}
}
12 changes: 10 additions & 2 deletions packages/vstory-core/src/core/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import type { ICharacterConfig, IStoryDSL } from '../interface/dsl/dsl';
import { StoryCanvas } from './canvas';
import type { IStoryCanvas } from '../interface/canvas';
import type { IAABBBoundsLike } from '@visactor/vutils';
import { isString } from '@visactor/vutils';
import { EventEmitter, isString } from '@visactor/vutils';
import type { ICharacter } from '../interface/character';
import type { IPlayer } from '../interface/player';
import type { ICharacterTree } from '../interface/character-tree';
import { CharacterTree } from './character-tree';
import type { IPluginService } from '../interface/plugin-service';
import { DefaultPluginService } from './plugin-service';

type NodeCanvas = any;

Expand All @@ -27,13 +29,14 @@ export interface IStoryInitOption {
theme?: string;
}

export class Story implements IStory {
export class Story extends EventEmitter implements IStory {
readonly id: string;
protected _canvas: IStoryCanvas;
protected _dsl: IStoryDSL | null;
protected _player: IPlayer;
protected _characterTree: ICharacterTree;
protected _theme: string;
pluginService: IPluginService;

get canvas(): IStoryCanvas {
return this._canvas;
Expand All @@ -48,6 +51,7 @@ export class Story implements IStory {
}

constructor(dsl: IStoryDSL | null, option: IStoryInitOption) {
super();
this.id = `test-mvp_${Generator.GenAutoIncrementId()}`;
const {
dom,
Expand Down Expand Up @@ -80,6 +84,10 @@ export class Story implements IStory {
this._characterTree = new CharacterTree(this);
this._dsl = dsl;
this._theme = theme;
this.pluginService = new DefaultPluginService();
this.pluginService.active(this, {
pluginList: []
});
}

init(player: IPlayer) {
Expand Down
3 changes: 3 additions & 0 deletions packages/vstory-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ export * from './module/graphic';
export * from './module/character';

export * from './constants/character';
export * from './constants/events';

export * from './interface/action-processor';
export * from './interface/dsl/dsl';
export * from './interface/character';
export * from './interface/story';
export * from './interface/event';
export * from './interface/plugin-service';
export * from './interface/releaseable';
export * from './core/processorRegistry';
export * from './tools/global-ticker';
export * from './character/component/character-component';
Expand Down
9 changes: 7 additions & 2 deletions packages/vstory-core/src/interface/character.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IGraphic } from '@visactor/vrender-core';
import { IGroup } from '@visactor/vrender-core';
import type { ICharacterConfig } from './dsl/dsl';
import type { ICharacterConfig, IUpdateConfigParams } from './dsl/dsl';
import type { ICharacterPickInfo, IStoryEvent } from './event';
import type { IReleaseable } from './releaseable';
import type { IStory } from './story';
Expand All @@ -17,6 +17,10 @@ export interface ILayoutLine {
bounds: IAABBBounds;
}

export enum SetConfigMode {
default = 0,
animate = 1
}
export interface ICharacter extends IReleaseable {
id: string;
type: string;
Expand Down Expand Up @@ -47,7 +51,8 @@ export interface ICharacter extends IReleaseable {
checkEvent: (event: IStoryEvent) => false | (ICharacterPickInfo & any);

toDSL: () => ICharacterConfig;
setConfig: (config: Partial<ICharacterConfig>) => void;
setConfig: (config: Partial<ICharacterConfig>, params?: { forceMergeOption?: boolean; mode?: SetConfigMode }) => void;
diffConfig: (config: IUpdateConfigParams) => IUpdateConfigParams;

getAttribute: () => any;

Expand Down
2 changes: 2 additions & 0 deletions packages/vstory-core/src/interface/dsl/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export type ICharacterConfig =
| ITableCharacterConfig
| IPivotChartCharacterConfig;

export type IUpdateConfigParams = Omit<Partial<ICharacterConfig>, 'id' | 'type'>;

export interface ICharacterInitOption {
story: IStory;
canvas: IStoryCanvas;
Expand Down
18 changes: 18 additions & 0 deletions packages/vstory-core/src/interface/plugin-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Releaseable } from '@visactor/vrender-core';
import type { IStory } from './story';

export interface IPluginService extends Releaseable {
register: (plugin: IPlugin) => void;
unRegister: (plugin: IPlugin) => void;
active: (story: IStory, params: { pluginList?: IPlugin[] }) => void;
actived: boolean;
story: IStory;
findPluginsByName: (name: string) => IPlugin[];
}

export interface IPlugin {
name: string;
activeEvent: 'onStartupFinished' | 'onRegister';
activate: (context: IPluginService) => void;
deactivate: (context: IPluginService) => void;
}
Loading
Loading