From 700e5b06dd9d7f461a85d9ceaa419f7f76485b0c Mon Sep 17 00:00:00 2001 From: "wuyue.xht" Date: Tue, 26 May 2020 23:07:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20ve=E4=BA=8B=E4=BB=B6=E5=9F=8B?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/designer/src/document/history.ts | 12 +++++++++++- packages/editor-core/src/hotkey.ts | 13 +++++++++++++ packages/editor-preset-vision/src/bus.ts | 18 ++++++++++++++++-- packages/editor-preset-vision/src/panes.ts | 2 ++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/packages/designer/src/document/history.ts b/packages/designer/src/document/history.ts index 8a37f1032..44c9010c6 100644 --- a/packages/designer/src/document/history.ts +++ b/packages/designer/src/document/history.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import { autorun, Reaction, untracked } from '@ali/lowcode-editor-core'; +import { autorun, Reaction, untracked, globalContext, Editor } from '@ali/lowcode-editor-core'; import { NodeSchema } from '@ali/lowcode-types'; // TODO: cache to localStorage @@ -114,6 +114,11 @@ export class History { } const cursor = this.session.cursor - 1; this.go(cursor); + const editor = globalContext.get(Editor); + if (!editor) { + return; + } + editor.emit('history.back', cursor); } forward() { @@ -122,6 +127,11 @@ export class History { } const cursor = this.session.cursor + 1; this.go(cursor); + const editor = globalContext.get(Editor); + if (!editor) { + return; + } + editor.emit('history.forward', cursor); } savePoint() { diff --git a/packages/editor-core/src/hotkey.ts b/packages/editor-core/src/hotkey.ts index 293d5179c..5bb6707a9 100644 --- a/packages/editor-core/src/hotkey.ts +++ b/packages/editor-core/src/hotkey.ts @@ -1,3 +1,6 @@ +import { globalContext } from './di'; +import { Editor } from './editor'; + interface KeyMap { [key: number]: string; } @@ -329,6 +332,16 @@ function fireCallback(callback: HotkeyCallback, e: KeyboardEvent, combo?: string e.preventDefault(); e.stopPropagation(); } + const editor = globalContext.get(Editor); + if (!editor) { + return; + } + editor.emit('hotkey.callback.call', { + callback, + e, + combo, + sequence, + }); } export class Hotkey { diff --git a/packages/editor-preset-vision/src/bus.ts b/packages/editor-preset-vision/src/bus.ts index c8554d99f..dd6b8386a 100644 --- a/packages/editor-preset-vision/src/bus.ts +++ b/packages/editor-preset-vision/src/bus.ts @@ -1,5 +1,6 @@ import logger from '@ali/vu-logger'; import { EventEmitter } from 'events'; +import { editor } from './editor'; /** * Bus class as an EventEmitter @@ -19,7 +20,6 @@ export class Bus { // alias to unsub off(event: string, func: (...args: any[]) => any) { this.unsub(event, func); - } // alias to pub @@ -62,4 +62,18 @@ export class Bus { } } -export default new Bus(); +const bus = new Bus(); + +editor.on('hotkey.callback.call', (data) => { + bus.emit('ve.hotkey.callback.call', data); +}); + +editor.on('history.back', (data) => { + bus.emit('ve.history.back', data); +}); + +editor.on('history.forward', (data) => { + bus.emit('ve.history.forward', data); +}); + +export default bus; diff --git a/packages/editor-preset-vision/src/panes.ts b/packages/editor-preset-vision/src/panes.ts index 77c5947c6..75e4ec38d 100644 --- a/packages/editor-preset-vision/src/panes.ts +++ b/packages/editor-preset-vision/src/panes.ts @@ -2,6 +2,7 @@ import { skeleton, editor } from './editor'; import { ReactElement } from 'react'; import { IWidgetBaseConfig, Skeleton } from '@ali/lowcode-editor-skeleton'; import { uniqueId } from '@ali/lowcode-utils'; +import bus from './bus'; export interface IContentItemConfig { title: string; @@ -175,6 +176,7 @@ const dockPane = Object.assign(skeleton.leftArea, { console.warn(`Could not find pane with name ${name}`); } pane?.active(); + bus.emit('ve.dock_pane.active_doc', pane); }, /** From 46784089638433b9bee69c30e8611ef87aba7a9c Mon Sep 17 00:00:00 2001 From: "shuaige.zsg" Date: Wed, 27 May 2020 15:29:12 +0800 Subject: [PATCH 2/2] feat: add URL link for setter titles --- .../editor-core/src/widgets/title/index.tsx | 19 +++++++++++++++++-- .../src/components/field/fields.tsx | 13 +++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/editor-core/src/widgets/title/index.tsx b/packages/editor-core/src/widgets/title/index.tsx index 76e341c80..1006935ed 100644 --- a/packages/editor-core/src/widgets/title/index.tsx +++ b/packages/editor-core/src/widgets/title/index.tsx @@ -7,8 +7,23 @@ import { Tip } from '../tip'; import './title.less'; export class Title extends Component<{ title: TitleContent; className?: string; onClick?: () => void }> { + constructor(props: any) { + super(props); + this.handleClick = this.handleClick.bind(this); + } + handleClick(e: React.MouseEvent) { + const { title, onClick } = this.props as any; + const url = title && (title.docUrl || title.url); + if (url) { + window.open(url); + // 防止触发行操作(如折叠面板) + e.stopPropagation(); + } + // TODO: 操作交互冲突,目前 mixedSetter 仅有 2 个 setter 注册时用到了 onClick + onClick && onClick(e); + } render() { - let { title, className, onClick } = this.props; + let { title, className } = this.props; if (title == null) { return null; } @@ -40,7 +55,7 @@ export class Title extends Component<{ title: TitleContent; className?: string; 'has-tip': !!tip, 'only-icon': !title.label })} - onClick={onClick} + onClick={this.handleClick} > {icon ? {icon} : null} {title.label ? intl(title.label) : null} diff --git a/packages/editor-skeleton/src/components/field/fields.tsx b/packages/editor-skeleton/src/components/field/fields.tsx index 51b7a2232..dcd1c78bb 100644 --- a/packages/editor-skeleton/src/components/field/fields.tsx +++ b/packages/editor-skeleton/src/components/field/fields.tsx @@ -28,6 +28,11 @@ export class Field extends Component { display: this.props.defaultDisplay || 'inline', }; + constructor(props: any) { + super(props); + this.handleClear = this.handleClear.bind(this); + } + private toggleExpand = () => { const { onExpandChange } = this.props; const collapsed = !this.state.collapsed; @@ -68,6 +73,10 @@ export class Field extends Component { }); this.dispose = () => observer.disconnect(); } + private handleClear(e: React.MouseEvent) { + e.stopPropagation(); + this.props.onClear && this.props.onClear(); + } componentDidMount() { const { defaultDisplay } = this.props; if (!defaultDisplay || defaultDisplay === 'inline') { @@ -118,7 +127,7 @@ export class Field extends Component { >
- {createValueState(valueState, onClear)} + {createValueState(valueState, this.handleClear)} <InlineTip position="top">{tipContent}</InlineTip> </div> @@ -143,7 +152,7 @@ export class Field extends Component<FieldProps> { * * TODO: turn number to enum */ -function createValueState(valueState?: number, onClear?: () => void) { +function createValueState(valueState?: number, onClear?: (e: React.MouseEvent) => void) { let tip: any = null; let className = 'lc-valuestate'; let icon: any = null;