diff --git a/docs/docs/api/canvas.md b/docs/docs/api/canvas.md index 344223bcb..b6af6680e 100644 --- a/docs/docs/api/canvas.md +++ b/docs/docs/api/canvas.md @@ -1,5 +1,5 @@ --- -title: cavas - 画布 API +title: canvas - 画布 API sidebar_position: 12 --- @@ -17,30 +17,25 @@ sidebar_position: 12 获取拖拽操作对象的实例 -```typescript -/** - * 获取拖拽操作对象的实例 - * get dragon instance, you can use this to obtain draging related abilities and lifecycle hooks - * @since v1.1.0 - */ -get dragon(): IPublicModelDragon | null; -``` -关联模型 [IPublicModelDragon](./model/dragon) +`@type {IPublicModelDragon | null}` + + +相关类型:[IPublicModelDragon](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/dragon.ts) ### activeTracker 获取活动追踪器实例 -```typescript -/** - * 获取活动追踪器实例 - * 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 - * focusing node/node[] changed. - * @since v1.1.0 - */ -get activeTracker(): IPublicModelActiveTracker | null; -``` +`@type {IPublicModelActiveTracker | null}` + +相关类型:[IPublicModelActiveTracker](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/active-tracker.ts) + +### isInLiveEditing + +是否处于 LiveEditing 状态 + +`@type {boolean}` + ## 方法 @@ -83,4 +78,4 @@ createScroller(scrollable: IPublicModelScrollable): IPublicModelScroller; * @since v1.1.0 */ createScrollTarget(shell: HTMLDivElement): IPublicModelScrollTarget; -``` \ No newline at end of file +``` diff --git a/packages/designer/tests/designer/builtin-hotkey.test.ts b/packages/designer/tests/designer/builtin-hotkey.test.ts index 6df390ee4..9cb068ac1 100644 --- a/packages/designer/tests/designer/builtin-hotkey.test.ts +++ b/packages/designer/tests/designer/builtin-hotkey.test.ts @@ -7,11 +7,11 @@ import { import { Designer } from '../../src/designer/designer'; import formSchema from '../fixtures/schema/form'; 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 { ILowCodePluginContextPrivate, LowCodePluginManager } from '@alilc/lowcode-designer'; 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'; const editor = new Editor(); @@ -19,12 +19,6 @@ const workspace = new Workspace(); 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 // hotkey 模块底层用的 keyCode,所以还不能用 key / code 测试 describe('快捷键测试', () => { @@ -40,6 +34,7 @@ describe('快捷键测试', () => { context.hotkey = hotkey; context.logger = logger; context.project = project; + context.canvas = new Canvas(editor); } }; pluginManager = new LowCodePluginManager(contextApiAssembler).toProxy(); diff --git a/packages/engine/src/inner-plugins/builtin-hotkey.ts b/packages/engine/src/inner-plugins/builtin-hotkey.ts index 6b926721b..3ee79831b 100644 --- a/packages/engine/src/inner-plugins/builtin-hotkey.ts +++ b/packages/engine/src/inner-plugins/builtin-hotkey.ts @@ -1,5 +1,4 @@ /* eslint-disable max-len */ -import { Editor, globalContext } from '@alilc/lowcode-editor-core'; import { isFormEvent } from '@alilc/lowcode-utils'; import { focusing, @@ -12,23 +11,9 @@ import { IPublicModelNode, } from '@alilc/lowcode-types'; import symbols from '../modules/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 */ function getNextForSelect(next: IPublicModelNode | null, head?: any, parent?: IPublicModelNode | null): any { if (next) { @@ -95,12 +80,12 @@ function getPrevForSelect(prev: IPublicModelNode | null, head?: any, parent?: IP export const builtinHotkey = (ctx: IPublicModelPluginContext) => { return { init() { - const { hotkey, project, logger } = ctx; + const { hotkey, project, logger, canvas } = ctx; // hotkey binding hotkey.bind(['backspace', 'del'], (e: KeyboardEvent, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } // TODO: use focus-tracker @@ -124,7 +109,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { hotkey.bind('escape', (e: KeyboardEvent, action) => { logger.info(`action ${action} is triggered`); // const currentFocus = focusing.current; - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const sel = focusing.focusDesigner?.currentDocument?.selection; @@ -140,7 +125,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { // command + c copy command + x cut hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const doc = project.currentDocument; @@ -179,10 +164,9 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { // command + v paste hotkey.bind(['command+v', 'ctrl+v'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } - if (isInLiveEditing()) return; // TODO const designer = focusing.focusDesigner; const doc = project?.currentDocument; @@ -212,7 +196,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { // command + z undo hotkey.bind(['command+z', 'ctrl+z'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const history = project.currentDocument?.history; @@ -230,7 +214,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { // command + shift + z redo hotkey.bind(['command+y', 'ctrl+y', 'command+shift+z'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const history = project.currentDocument?.history; @@ -247,7 +231,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { // sibling selection hotkey.bind(['left', 'right'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const doc = project.currentDocument; @@ -266,7 +250,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { hotkey.bind(['up', 'down'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const doc = project.currentDocument; @@ -291,7 +275,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { hotkey.bind(['option+left', 'option+right'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const doc = project.currentDocument; @@ -325,7 +309,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { hotkey.bind(['option+up'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const doc = project.currentDocument; @@ -367,7 +351,7 @@ export const builtinHotkey = (ctx: IPublicModelPluginContext) => { hotkey.bind(['option+down'], (e, action) => { logger.info(`action ${action} is triggered`); - if (isInLiveEditing()) { + if (canvas.isInLiveEditing) { return; } const doc = project.getCurrentDocument(); diff --git a/packages/shell/src/api/canvas.ts b/packages/shell/src/api/canvas.ts index 3c3129957..5489a8b75 100644 --- a/packages/shell/src/api/canvas.ts +++ b/packages/shell/src/api/canvas.ts @@ -36,6 +36,10 @@ export class Canvas implements IPublicApiCanvas { return activeTracker; } + get isInLiveEditing(): boolean { + return Boolean(this[editorSymbol].get('designer')?.project?.simulator?.liveEditing?.editing); + } + constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) { this[editorSymbol] = editor; } diff --git a/packages/types/src/shell/api/canvas.ts b/packages/types/src/shell/api/canvas.ts index 147d554ec..f7983e094 100644 --- a/packages/types/src/shell/api/canvas.ts +++ b/packages/types/src/shell/api/canvas.ts @@ -1,9 +1,11 @@ import { IPublicModelDragon, IPublicModelDropLocation, IPublicModelScrollTarget, IPublicModelScrollable, IPublicModelScroller, IPublicModelActiveTracker } from '../model'; import { IPublicTypeLocationData } from '../type'; +/** + * @since v1.1.0 + */ export interface IPublicApiCanvas { - /** * 创一个滚动控制器 Scroller,赋予一个视图滚动的基本能力, * a Scroller is a controller that gives a view (IPublicModelScrollable) the ability scrolling @@ -45,4 +47,11 @@ export interface IPublicApiCanvas { * @since v1.1.0 */ get activeTracker(): IPublicModelActiveTracker | null; + + /** + * 是否处于 LiveEditing 状态 + * check if canvas is in liveEditing state + * @since v1.1.0 + */ + get isInLiveEditing(): boolean; }