mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
refactor: add isInLiveEditing api to canvas for refactoring of hotkey plugin as a standalone one
This commit is contained in:
parent
4fd3af10c5
commit
f25babe728
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: cavas - 画布 API
|
title: canvas - 画布 API
|
||||||
sidebar_position: 12
|
sidebar_position: 12
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -17,30 +17,25 @@ sidebar_position: 12
|
|||||||
|
|
||||||
获取拖拽操作对象的实例
|
获取拖拽操作对象的实例
|
||||||
|
|
||||||
```typescript
|
`@type {IPublicModelDragon | null}`
|
||||||
/**
|
|
||||||
* 获取拖拽操作对象的实例
|
|
||||||
* get dragon instance, you can use this to obtain draging related abilities and lifecycle hooks
|
相关类型:[IPublicModelDragon](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/dragon.ts)
|
||||||
* @since v1.1.0
|
|
||||||
*/
|
|
||||||
get dragon(): IPublicModelDragon | null;
|
|
||||||
```
|
|
||||||
关联模型 [IPublicModelDragon](./model/dragon)
|
|
||||||
|
|
||||||
### activeTracker
|
### activeTracker
|
||||||
|
|
||||||
获取活动追踪器实例
|
获取活动追踪器实例
|
||||||
|
|
||||||
```typescript
|
`@type {IPublicModelActiveTracker | null}`
|
||||||
/**
|
|
||||||
* 获取活动追踪器实例
|
相关类型:[IPublicModelActiveTracker](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/active-tracker.ts)
|
||||||
* get activeTracker instance, which is a singleton running in engine.
|
|
||||||
* it tracks document`s current focusing node/node[], and notify it`s subscribers that when
|
### isInLiveEditing
|
||||||
* focusing node/node[] changed.
|
|
||||||
* @since v1.1.0
|
是否处于 LiveEditing 状态
|
||||||
*/
|
|
||||||
get activeTracker(): IPublicModelActiveTracker | null;
|
`@type {boolean}`
|
||||||
```
|
|
||||||
|
|
||||||
## 方法
|
## 方法
|
||||||
|
|
||||||
@ -83,4 +78,4 @@ createScroller(scrollable: IPublicModelScrollable): IPublicModelScroller;
|
|||||||
* @since v1.1.0
|
* @since v1.1.0
|
||||||
*/
|
*/
|
||||||
createScrollTarget(shell: HTMLDivElement): IPublicModelScrollTarget;
|
createScrollTarget(shell: HTMLDivElement): IPublicModelScrollTarget;
|
||||||
```
|
```
|
||||||
|
|||||||
@ -7,11 +7,11 @@ import {
|
|||||||
import { Designer } from '../../src/designer/designer';
|
import { Designer } from '../../src/designer/designer';
|
||||||
import formSchema from '../fixtures/schema/form';
|
import formSchema from '../fixtures/schema/form';
|
||||||
import { fireEvent } from '@testing-library/react';
|
import { fireEvent } from '@testing-library/react';
|
||||||
import { isInLiveEditing, builtinHotkey } from '../../../engine/src/inner-plugins/builtin-hotkey';
|
import { builtinHotkey } from '../../../engine/src/inner-plugins/builtin-hotkey';
|
||||||
import { shellModelFactory } from '../../../engine/src/modules/shell-model-factory';
|
import { shellModelFactory } from '../../../engine/src/modules/shell-model-factory';
|
||||||
import { ILowCodePluginContextPrivate, LowCodePluginManager } from '@alilc/lowcode-designer';
|
import { ILowCodePluginContextPrivate, LowCodePluginManager } from '@alilc/lowcode-designer';
|
||||||
import { IPublicApiPlugins } from '@alilc/lowcode-types';
|
import { IPublicApiPlugins } from '@alilc/lowcode-types';
|
||||||
import { Logger, Project } from '@alilc/lowcode-shell';
|
import { Logger, Project, Canvas } from '@alilc/lowcode-shell';
|
||||||
import { Workspace } from '@alilc/lowcode-workspace';
|
import { Workspace } from '@alilc/lowcode-workspace';
|
||||||
|
|
||||||
const editor = new Editor();
|
const editor = new Editor();
|
||||||
@ -19,12 +19,6 @@ const workspace = new Workspace();
|
|||||||
|
|
||||||
let designer: Designer;
|
let designer: Designer;
|
||||||
|
|
||||||
describe('error scenarios', () => {
|
|
||||||
it('edtior not registered', () => {
|
|
||||||
expect(isInLiveEditing()).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// keyCode 对应表:https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
|
// keyCode 对应表:https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
|
||||||
// hotkey 模块底层用的 keyCode,所以还不能用 key / code 测试
|
// hotkey 模块底层用的 keyCode,所以还不能用 key / code 测试
|
||||||
describe('快捷键测试', () => {
|
describe('快捷键测试', () => {
|
||||||
@ -40,6 +34,7 @@ describe('快捷键测试', () => {
|
|||||||
context.hotkey = hotkey;
|
context.hotkey = hotkey;
|
||||||
context.logger = logger;
|
context.logger = logger;
|
||||||
context.project = project;
|
context.project = project;
|
||||||
|
context.canvas = new Canvas(editor);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
pluginManager = new LowCodePluginManager(contextApiAssembler).toProxy();
|
pluginManager = new LowCodePluginManager(contextApiAssembler).toProxy();
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
import { Editor, globalContext } from '@alilc/lowcode-editor-core';
|
|
||||||
import { isFormEvent } from '@alilc/lowcode-utils';
|
import { isFormEvent } from '@alilc/lowcode-utils';
|
||||||
import {
|
import {
|
||||||
focusing,
|
focusing,
|
||||||
@ -12,23 +11,9 @@ import {
|
|||||||
IPublicModelNode,
|
IPublicModelNode,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import symbols from '../modules/symbols';
|
import symbols from '../modules/symbols';
|
||||||
|
|
||||||
const { nodeSymbol, documentSymbol } = symbols;
|
const { nodeSymbol, documentSymbol } = symbols;
|
||||||
|
|
||||||
export function isInLiveEditing() {
|
|
||||||
const workspace = globalContext.has('workspace') && globalContext.get('workspace');
|
|
||||||
if (workspace?.isActive) {
|
|
||||||
return Boolean(
|
|
||||||
workspace.window.editor.get('designer')?.project?.simulator?.liveEditing?.editing,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalContext.has(Editor)) {
|
|
||||||
return Boolean(
|
|
||||||
globalContext.get(Editor).get('designer')?.project?.simulator?.liveEditing?.editing,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
function getNextForSelect(next: IPublicModelNode | null, head?: any, parent?: IPublicModelNode | null): any {
|
function getNextForSelect(next: IPublicModelNode | null, head?: any, parent?: IPublicModelNode | null): any {
|
||||||
if (next) {
|
if (next) {
|
||||||
@ -95,12 +80,12 @@ function getPrevForSelect(prev: IPublicModelNode | null, head?: any, parent?: IP
|
|||||||
export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
||||||
return {
|
return {
|
||||||
init() {
|
init() {
|
||||||
const { hotkey, project, logger } = ctx;
|
const { hotkey, project, logger, canvas } = ctx;
|
||||||
// hotkey binding
|
// hotkey binding
|
||||||
hotkey.bind(['backspace', 'del'], (e: KeyboardEvent, action) => {
|
hotkey.bind(['backspace', 'del'], (e: KeyboardEvent, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
|
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: use focus-tracker
|
// TODO: use focus-tracker
|
||||||
@ -124,7 +109,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
hotkey.bind('escape', (e: KeyboardEvent, action) => {
|
hotkey.bind('escape', (e: KeyboardEvent, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
// const currentFocus = focusing.current;
|
// const currentFocus = focusing.current;
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const sel = focusing.focusDesigner?.currentDocument?.selection;
|
const sel = focusing.focusDesigner?.currentDocument?.selection;
|
||||||
@ -140,7 +125,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
// command + c copy command + x cut
|
// command + c copy command + x cut
|
||||||
hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => {
|
hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const doc = project.currentDocument;
|
const doc = project.currentDocument;
|
||||||
@ -179,10 +164,9 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
// command + v paste
|
// command + v paste
|
||||||
hotkey.bind(['command+v', 'ctrl+v'], (e, action) => {
|
hotkey.bind(['command+v', 'ctrl+v'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isInLiveEditing()) return;
|
|
||||||
// TODO
|
// TODO
|
||||||
const designer = focusing.focusDesigner;
|
const designer = focusing.focusDesigner;
|
||||||
const doc = project?.currentDocument;
|
const doc = project?.currentDocument;
|
||||||
@ -212,7 +196,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
// command + z undo
|
// command + z undo
|
||||||
hotkey.bind(['command+z', 'ctrl+z'], (e, action) => {
|
hotkey.bind(['command+z', 'ctrl+z'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const history = project.currentDocument?.history;
|
const history = project.currentDocument?.history;
|
||||||
@ -230,7 +214,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
// command + shift + z redo
|
// command + shift + z redo
|
||||||
hotkey.bind(['command+y', 'ctrl+y', 'command+shift+z'], (e, action) => {
|
hotkey.bind(['command+y', 'ctrl+y', 'command+shift+z'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const history = project.currentDocument?.history;
|
const history = project.currentDocument?.history;
|
||||||
@ -247,7 +231,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
// sibling selection
|
// sibling selection
|
||||||
hotkey.bind(['left', 'right'], (e, action) => {
|
hotkey.bind(['left', 'right'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const doc = project.currentDocument;
|
const doc = project.currentDocument;
|
||||||
@ -266,7 +250,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
|
|
||||||
hotkey.bind(['up', 'down'], (e, action) => {
|
hotkey.bind(['up', 'down'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const doc = project.currentDocument;
|
const doc = project.currentDocument;
|
||||||
@ -291,7 +275,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
|
|
||||||
hotkey.bind(['option+left', 'option+right'], (e, action) => {
|
hotkey.bind(['option+left', 'option+right'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const doc = project.currentDocument;
|
const doc = project.currentDocument;
|
||||||
@ -325,7 +309,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
|
|
||||||
hotkey.bind(['option+up'], (e, action) => {
|
hotkey.bind(['option+up'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const doc = project.currentDocument;
|
const doc = project.currentDocument;
|
||||||
@ -367,7 +351,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => {
|
|||||||
|
|
||||||
hotkey.bind(['option+down'], (e, action) => {
|
hotkey.bind(['option+down'], (e, action) => {
|
||||||
logger.info(`action ${action} is triggered`);
|
logger.info(`action ${action} is triggered`);
|
||||||
if (isInLiveEditing()) {
|
if (canvas.isInLiveEditing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const doc = project.getCurrentDocument();
|
const doc = project.getCurrentDocument();
|
||||||
|
|||||||
@ -36,6 +36,10 @@ export class Canvas implements IPublicApiCanvas {
|
|||||||
return activeTracker;
|
return activeTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isInLiveEditing(): boolean {
|
||||||
|
return Boolean(this[editorSymbol].get('designer')?.project?.simulator?.liveEditing?.editing);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) {
|
constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) {
|
||||||
this[editorSymbol] = editor;
|
this[editorSymbol] = editor;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
import { IPublicModelDragon, IPublicModelDropLocation, IPublicModelScrollTarget, IPublicModelScrollable, IPublicModelScroller, IPublicModelActiveTracker } from '../model';
|
import { IPublicModelDragon, IPublicModelDropLocation, IPublicModelScrollTarget, IPublicModelScrollable, IPublicModelScroller, IPublicModelActiveTracker } from '../model';
|
||||||
import { IPublicTypeLocationData } from '../type';
|
import { IPublicTypeLocationData } from '../type';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
export interface IPublicApiCanvas {
|
export interface IPublicApiCanvas {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创一个滚动控制器 Scroller,赋予一个视图滚动的基本能力,
|
* 创一个滚动控制器 Scroller,赋予一个视图滚动的基本能力,
|
||||||
* a Scroller is a controller that gives a view (IPublicModelScrollable) the ability scrolling
|
* a Scroller is a controller that gives a view (IPublicModelScrollable) the ability scrolling
|
||||||
@ -45,4 +47,11 @@ export interface IPublicApiCanvas {
|
|||||||
* @since v1.1.0
|
* @since v1.1.0
|
||||||
*/
|
*/
|
||||||
get activeTracker(): IPublicModelActiveTracker | null;
|
get activeTracker(): IPublicModelActiveTracker | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否处于 LiveEditing 状态
|
||||||
|
* check if canvas is in liveEditing state
|
||||||
|
* @since v1.1.0
|
||||||
|
*/
|
||||||
|
get isInLiveEditing(): boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user