mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-19 12:14:27 +08:00
feat(stage): 新增禁用标尺配置
This commit is contained in:
parent
bbf93cb2b5
commit
95d6263f42
@ -8,19 +8,23 @@ import type { RuleOptions } from './types';
|
|||||||
const guidesClass = 'tmagic-stage-guides';
|
const guidesClass = 'tmagic-stage-guides';
|
||||||
|
|
||||||
export default class Rule extends EventEmitter {
|
export default class Rule extends EventEmitter {
|
||||||
public hGuides: Guides;
|
public hGuides?: Guides;
|
||||||
public vGuides: Guides;
|
public vGuides?: Guides;
|
||||||
public horizontalGuidelines: number[] = [];
|
public horizontalGuidelines: number[] = [];
|
||||||
public verticalGuidelines: number[] = [];
|
public verticalGuidelines: number[] = [];
|
||||||
|
|
||||||
private container: HTMLDivElement;
|
private container?: HTMLDivElement;
|
||||||
private containerResizeObserver: ResizeObserver;
|
private containerResizeObserver?: ResizeObserver;
|
||||||
private isShowGuides = true;
|
private isShowGuides = true;
|
||||||
private guidesOptions?: Partial<GuidesOptions>;
|
private guidesOptions?: Partial<GuidesOptions>;
|
||||||
|
|
||||||
constructor(container: HTMLDivElement, options?: RuleOptions) {
|
constructor(container: HTMLDivElement, options?: RuleOptions) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
if (options?.disabledRule) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.guidesOptions = options?.guidesOptions || {};
|
this.guidesOptions = options?.guidesOptions || {};
|
||||||
|
|
||||||
this.container = container;
|
this.container = container;
|
||||||
@ -28,8 +32,8 @@ export default class Rule extends EventEmitter {
|
|||||||
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
||||||
|
|
||||||
this.containerResizeObserver = new ResizeObserver(() => {
|
this.containerResizeObserver = new ResizeObserver(() => {
|
||||||
this.vGuides.resize();
|
this.vGuides?.resize();
|
||||||
this.hGuides.resize();
|
this.hGuides?.resize();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.containerResizeObserver.observe(this.container);
|
this.containerResizeObserver.observe(this.container);
|
||||||
@ -42,11 +46,11 @@ export default class Rule extends EventEmitter {
|
|||||||
public showGuides(isShowGuides = true) {
|
public showGuides(isShowGuides = true) {
|
||||||
this.isShowGuides = isShowGuides;
|
this.isShowGuides = isShowGuides;
|
||||||
|
|
||||||
this.hGuides.setState({
|
this.hGuides?.setState({
|
||||||
showGuides: isShowGuides,
|
showGuides: isShowGuides,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.vGuides.setState({
|
this.vGuides?.setState({
|
||||||
showGuides: isShowGuides,
|
showGuides: isShowGuides,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -55,11 +59,11 @@ export default class Rule extends EventEmitter {
|
|||||||
this.horizontalGuidelines = hLines;
|
this.horizontalGuidelines = hLines;
|
||||||
this.verticalGuidelines = vLines;
|
this.verticalGuidelines = vLines;
|
||||||
|
|
||||||
this.hGuides.setState({
|
this.hGuides?.setState({
|
||||||
defaultGuides: hLines,
|
defaultGuides: hLines,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.vGuides.setState({
|
this.vGuides?.setState({
|
||||||
defaultGuides: vLines,
|
defaultGuides: vLines,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,13 +97,13 @@ export default class Rule extends EventEmitter {
|
|||||||
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
||||||
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
||||||
} else {
|
} else {
|
||||||
this.hGuides.setState({
|
this.hGuides?.setState({
|
||||||
rulerStyle: {
|
rulerStyle: {
|
||||||
visibility: 'hidden',
|
visibility: 'hidden',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.vGuides.setState({
|
this.vGuides?.setState({
|
||||||
rulerStyle: {
|
rulerStyle: {
|
||||||
visibility: 'hidden',
|
visibility: 'hidden',
|
||||||
},
|
},
|
||||||
@ -108,28 +112,32 @@ export default class Rule extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public scrollRule(scrollTop: number) {
|
public scrollRule(scrollTop: number) {
|
||||||
this.hGuides.scrollGuides(scrollTop);
|
this.hGuides?.scrollGuides(scrollTop);
|
||||||
this.hGuides.scroll(0);
|
this.hGuides?.scroll(0);
|
||||||
|
|
||||||
this.vGuides.scrollGuides(0);
|
this.vGuides?.scrollGuides(0);
|
||||||
this.vGuides.scroll(scrollTop);
|
this.vGuides?.scroll(scrollTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy(): void {
|
public destroy(): void {
|
||||||
this.destroyGuides();
|
this.destroyGuides();
|
||||||
this.hGuides.off('changeGuides', this.hGuidesChangeGuidesHandler);
|
this.hGuides?.off('changeGuides', this.hGuidesChangeGuidesHandler);
|
||||||
this.vGuides.off('changeGuides', this.vGuidesChangeGuidesHandler);
|
this.vGuides?.off('changeGuides', this.vGuidesChangeGuidesHandler);
|
||||||
this.containerResizeObserver.disconnect();
|
this.containerResizeObserver?.disconnect();
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroyGuides(): void {
|
public destroyGuides(): void {
|
||||||
this.hGuides.destroy();
|
this.hGuides?.destroy();
|
||||||
this.vGuides.destroy();
|
this.vGuides?.destroy();
|
||||||
|
|
||||||
this.container.querySelectorAll(`.${guidesClass}`).forEach((el) => {
|
this.container?.querySelectorAll(`.${guidesClass}`).forEach((el) => {
|
||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.hGuides = undefined;
|
||||||
|
this.vGuides = undefined;
|
||||||
|
this.container = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getGuidesStyle = (type: GuidesType) => ({
|
private getGuidesStyle = (type: GuidesType) => ({
|
||||||
@ -141,7 +149,11 @@ export default class Rule extends EventEmitter {
|
|||||||
height: type === GuidesType.HORIZONTAL ? '30px' : '100%',
|
height: type === GuidesType.HORIZONTAL ? '30px' : '100%',
|
||||||
});
|
});
|
||||||
|
|
||||||
private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides => {
|
private createGuides = (type: GuidesType, defaultGuides: number[] = []): Guides | undefined => {
|
||||||
|
if (!this.container) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const guides = new Guides(this.container, {
|
const guides = new Guides(this.container, {
|
||||||
type,
|
type,
|
||||||
defaultGuides,
|
defaultGuides,
|
||||||
|
@ -74,6 +74,7 @@ export default class StageCore extends EventEmitter {
|
|||||||
});
|
});
|
||||||
this.mask = new StageMask({
|
this.mask = new StageMask({
|
||||||
guidesOptions: config.guidesOptions,
|
guidesOptions: config.guidesOptions,
|
||||||
|
disabledRule: config.disabledRule,
|
||||||
});
|
});
|
||||||
this.actionManager = new ActionManager(this.getActionManagerConfig(config));
|
this.actionManager = new ActionManager(this.getActionManagerConfig(config));
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ export interface StageCoreConfig {
|
|||||||
renderType?: RenderType;
|
renderType?: RenderType;
|
||||||
guidesOptions?: Partial<GuidesOptions>;
|
guidesOptions?: Partial<GuidesOptions>;
|
||||||
disabledMultiSelect?: boolean;
|
disabledMultiSelect?: boolean;
|
||||||
|
disabledRule?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActionManagerConfig {
|
export interface ActionManagerConfig {
|
||||||
@ -240,6 +241,7 @@ export interface TargetShadowConfig {
|
|||||||
|
|
||||||
export interface RuleOptions {
|
export interface RuleOptions {
|
||||||
guidesOptions?: Partial<GuidesOptions>;
|
guidesOptions?: Partial<GuidesOptions>;
|
||||||
|
disabledRule?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CoreEvents {
|
export interface CoreEvents {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user