Skip to content

Commit

Permalink
feat(workspace): add multi foces-tracker in workspace mode
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Jul 10, 2023
1 parent eb3b570 commit 7b61817
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/designer/src/builtin-simulator/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
reaction,
computed,
getPublicPath,
focusTracker,
engineConfig,
globalLocale,
IReactionPublic,
Expand Down Expand Up @@ -519,7 +518,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
// bind hotkey & clipboard
const hotkey = this.designer.editor.get('innerHotkey');
hotkey.mount(this._contentWindow);
focusTracker.mount(this._contentWindow);
const innerSkeleton = this.designer.editor.get('skeleton');
innerSkeleton.focusTracker.mount(this._contentWindow);
clipboard.injectCopyPaster(this._contentDocument);

// TODO: dispose the bindings
Expand Down
5 changes: 5 additions & 0 deletions packages/designer/tests/builtin-simulator/host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { fireEvent } from '@testing-library/react';
import { shellModelFactory } from '../../../engine/src/modules/shell-model-factory';
import { Setters, Workspace } from '@alilc/lowcode-shell';
import { ILowCodePluginContextApiAssembler, ILowCodePluginContextPrivate, LowCodePluginManager } from '@alilc/lowcode-designer';
import {
Skeleton as InnerSkeleton,
} from '@alilc/lowcode-editor-skeleton';

describe('Host 测试', () => {
let editor: Editor;
Expand All @@ -45,6 +48,8 @@ describe('Host 测试', () => {
const innerPlugins = new LowCodePluginManager(pluginContextApiAssembler);
const innerWorkspace = new InnerWorkspace(() => {}, {});
const workspace = new Workspace(innerWorkspace);
const innerSkeleton = new InnerSkeleton(editor);
editor.set('skeleton' as any, innerSkeleton);
editor.set('innerHotkey', new InnerHotkey())
editor.set('setters', new Setters(new InnerSetters()));
editor.set('innerPlugins' as any, innerPlugins);
Expand Down
12 changes: 4 additions & 8 deletions packages/editor-core/src/utils/focus-tracker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export class FocusTracker {
private actives: Focusable[] = [];

private modals: Array<{ checkDown: (e: MouseEvent) => boolean; checkOpen: () => boolean }> = [];

mount(win: Window) {
const checkDown = (e: MouseEvent) => {
if (this.checkModalDown(e)) {
Expand All @@ -16,14 +20,10 @@ export class FocusTracker {
};
}

private actives: Focusable[] = [];

get first() {
return this.actives[0];
}

private modals: Array<{ checkDown: (e: MouseEvent) => boolean; checkOpen: () => boolean }> = [];

addModal(checkDown: (e: MouseEvent) => boolean, checkOpen: () => boolean) {
this.modals.push({
checkDown,
Expand Down Expand Up @@ -154,7 +154,3 @@ export class Focusable {
}
}
}

export const focusTracker = new FocusTracker();

focusTracker.mount(window);
4 changes: 2 additions & 2 deletions packages/editor-skeleton/src/layouts/left-float-pane.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Fragment } from 'react';
import classNames from 'classnames';
import { observer, Focusable, focusTracker } from '@alilc/lowcode-editor-core';
import { observer, Focusable } from '@alilc/lowcode-editor-core';
import { Area } from '../area';
import { Panel } from '../widget/panel';
import { PanelConfig } from '../types';
Expand Down Expand Up @@ -31,7 +31,7 @@ export default class LeftFloatPane extends Component<{ area: Area<PanelConfig, P
area.skeleton.editor.removeListener('designer.drag', triggerClose);
};

this.focusing = focusTracker.create({
this.focusing = area.skeleton.focusTracker.create({
range: (e) => {
const target = e.target as HTMLElement;
if (!target) {
Expand Down
7 changes: 6 additions & 1 deletion packages/editor-skeleton/src/skeleton.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, makeObservable, obx, engineConfig, IEditor } from '@alilc/lowcode-editor-core';
import { action, makeObservable, obx, engineConfig, IEditor, FocusTracker } from '@alilc/lowcode-editor-core';
import {
DockConfig,
PanelConfig,
Expand Down Expand Up @@ -83,6 +83,8 @@ export interface ISkeleton extends Omit<IPublicApiSkeleton,

readonly widgets: IWidget[];

readonly focusTracker: FocusTracker;

getPanel(name: string): Panel | undefined;

getWidget(name: string): IWidget | undefined;
Expand Down Expand Up @@ -133,6 +135,8 @@ export class Skeleton {

readonly widgets: IWidget[] = [];

readonly focusTracker = new FocusTracker();

constructor(readonly editor: IEditor, readonly viewName: string = 'global') {
makeObservable(this);
this.leftArea = new Area(
Expand Down Expand Up @@ -245,6 +249,7 @@ export class Skeleton {

this.setupPlugins();
this.setupEvents();
this.focusTracker.mount(window);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/workspace/src/layouts/left-float-pane.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Fragment } from 'react';
import classNames from 'classnames';
import { observer, Focusable, focusTracker } from '@alilc/lowcode-editor-core';
import { observer, Focusable } from '@alilc/lowcode-editor-core';
import { Area, Panel } from '@alilc/lowcode-editor-skeleton';

@observer
Expand Down Expand Up @@ -29,7 +29,7 @@ export default class LeftFloatPane extends Component<{ area: Area<any, Panel> }>
area.skeleton.editor.removeListener('designer.drag', triggerClose);
};

this.focusing = focusTracker.create({
this.focusing = area.skeleton.focusTracker.create({
range: (e) => {
const target = e.target as HTMLElement;
if (!target) {
Expand Down

0 comments on commit 7b61817

Please sign in to comment.