diff --git a/packages/vstory/demo/src/demos/API.tsx b/packages/vstory/demo/src/demos/API.tsx index 7bc8d253..9a25e5fd 100644 --- a/packages/vstory/demo/src/demos/API.tsx +++ b/packages/vstory/demo/src/demos/API.tsx @@ -126,7 +126,6 @@ export const API = () => { } }); - debugger; text.setConfig({ options: { graphic: { text: '这是普通文本' } } }); console.log(text); @@ -136,16 +135,32 @@ export const API = () => { // 添加character // 更新character story.play(); + let selectedCharacter: any = null; const edit = new Edit(story); edit.emitter.on('startEdit', msg => { + selectedCharacter = msg.actionInfo.character; if (msg.type === 'commonEdit' && msg.actionInfo.character) { msg.updateCharacter({ options: { graphic: { fill: 'green' } } }); story.play(); } }); + edit.emitter.on('endEdit', msg => { + selectedCharacter = null; + }); edit.emitter.on('resize', msg => { console.log('resize', msg); }); + // 删除character + document.addEventListener('keydown', e => { + if (e.key === 'Backspace') { + debugger; + const sc = selectedCharacter; + edit.stopEdit(); + sc && story.removeCharacter(sc.id); + story.play(false); + console.log('Backspace'); + } + }); // 导出DSL console.log(story.toDSL()); // story读取DSL diff --git a/packages/vstory/src/story/character-tree/character-tree.ts b/packages/vstory/src/story/character-tree/character-tree.ts index adf45927..edf9e2f4 100644 --- a/packages/vstory/src/story/character-tree/character-tree.ts +++ b/packages/vstory/src/story/character-tree/character-tree.ts @@ -19,7 +19,10 @@ export class CharacterTree implements ICharacterTree { } removeCharacter(cId: string) { - this._characters[cId] = null; + const c = this._characters[cId]; + // TODO 先直接release掉,后续如果需要复用再说 + c && c.release(); + delete this._characters[cId]; } addCharacter(spec: ICharacterConfig) { diff --git a/packages/vstory/src/story/character/chart/character.ts b/packages/vstory/src/story/character/chart/character.ts index e67bc707..76540c93 100644 --- a/packages/vstory/src/story/character/chart/character.ts +++ b/packages/vstory/src/story/character/chart/character.ts @@ -1,10 +1,8 @@ import { CommonSpecRuntime } from './runtime/common-spec'; import { ComponentSpecRuntime } from './runtime/component-spec'; import type { IChartCharacterRuntimeConstructor } from './runtime/interface'; -import { cloneDeep, merge } from '@visactor/vutils'; -import { VChart } from '@visactor/vchart'; -import type { ICharacterConfig, IChartCharacterConfig } from '../dsl-interface'; -import { VChartGraphic } from './graphic/vrender/vchart-graphic'; +import { cloneDeep } from '@visactor/vutils'; +import type { IChartCharacterConfig } from '../dsl-interface'; import { CharacterVisactor } from '../visactor/character'; import { SpecProcess } from './spec-process/spec-process'; import { ChartDataTempTransform } from './spec-process/data-temp-transform'; @@ -17,7 +15,7 @@ import { getLayoutFromWidget } from '../../utils/layout'; import { getChartModelWithEvent } from '../../utils/vchart-pick'; import { mergeChartOption } from '../../utils/chart'; import { Chart } from './graphic/chart'; -import { StoryChartType, StoryComponentType } from '../../../constants/character'; +import { StoryChartType } from '../../../constants/character'; export class CharacterChart extends CharacterVisactor { static type = 'CharacterChart'; diff --git a/packages/vstory/src/story/character/dsl-interface.ts b/packages/vstory/src/story/character/dsl-interface.ts index cee69d1d..e974db81 100644 --- a/packages/vstory/src/story/character/dsl-interface.ts +++ b/packages/vstory/src/story/character/dsl-interface.ts @@ -28,6 +28,7 @@ export interface ICharacterConfigBase { type: string; // 类型 position: IWidgetData; // 定位描述 zIndex: number; + extra?: any; // 带着的额外信息 } export type IEditorTextGraphicAttribute = { diff --git a/packages/vstory/src/story/story.ts b/packages/vstory/src/story/story.ts index 5f304f09..bf076c04 100644 --- a/packages/vstory/src/story/story.ts +++ b/packages/vstory/src/story/story.ts @@ -92,7 +92,7 @@ export class Story implements IStory { // this._player.addAct(spec, this._characters); // } - play(loop: boolean = true) { + play(loop: boolean = false) { // player 开始播放 this._dsl && this.load(this._dsl); this._player.play();