Browse Source

Update CanvasSpot

canvas-spot
Artur Arseniev 3 years ago
parent
commit
09abaebf0a
  1. 4
      src/canvas/index.ts
  2. 60
      src/canvas/model/CanvasSpot.ts
  3. 6
      src/canvas/view/CanvasView.ts

4
src/canvas/index.ts

@ -276,6 +276,10 @@ export default class CanvasModule extends Module<CanvasConfig> {
return this.getCanvasView().fixedOffsetEl; return this.getCanvasView().fixedOffsetEl;
} }
getSpotsEl() {
return this.canvasView?.spotsEl;
}
render(): HTMLElement { render(): HTMLElement {
this.canvasView?.remove(); this.canvasView?.remove();
this.canvasView = new CanvasView(this.canvas); this.canvasView = new CanvasView(this.canvas);

60
src/canvas/model/CanvasSpot.ts

@ -2,6 +2,7 @@ import CanvasModule from '..';
import { ModuleModel } from '../../abstract'; import { ModuleModel } from '../../abstract';
import { BoxRect, LiteralUnion } from '../../common'; import { BoxRect, LiteralUnion } from '../../common';
import Component from '../../dom_components/model/Component'; import Component from '../../dom_components/model/Component';
import ComponentView from '../../dom_components/view/ComponentView';
import Frame from './Frame'; import Frame from './Frame';
export enum CanvasSpotBuiltInTypes { export enum CanvasSpotBuiltInTypes {
@ -22,6 +23,7 @@ export interface CanvasSpotProps<T = CanvasSpotType> {
type: T; type: T;
boxRect?: BoxRect; boxRect?: BoxRect;
component?: Component; component?: Component;
componentView?: ComponentView;
frame?: Frame; frame?: Frame;
} }
@ -34,17 +36,59 @@ export default class CanvasSpot extends ModuleModel<CanvasModule, CanvasSpotProp
} }
get boxRect() { get boxRect() {
return ( const { el, em } = this;
this.get('boxRect') || { const cvView = em.Canvas.getCanvasView();
x: 0, const boxRect = this.get('boxRect');
y: 0,
width: 0, if (boxRect) {
height: 0, return boxRect;
} } else if (el && cvView) {
); return cvView.getElBoxRect(el);
}
return {
x: 0,
y: 0,
width: 0,
height: 0,
};
} }
get type() { get type() {
return this.get('type') || ''; return this.get('type') || '';
} }
get component() {
return this.get('component');
}
get componentView() {
return this.get('componentView');
}
get el() {
const { component, componentView } = this;
return componentView?.el || component?.getEl();
}
get style() {
const { em, component } = this;
const cmpView = this.get('componentView');
const el = cmpView?.el || component?.getEl();
if (el) {
const { width, height, x, y } = this.boxRect;
return {
width,
height,
top: 0,
left: 0,
position: 'absolute',
translate: `${x}px ${y}px`,
};
}
return {};
}
} }

6
src/canvas/view/CanvasView.ts

@ -45,7 +45,9 @@ export default class CanvasView extends ModuleView<Canvas> {
template() { template() {
const { pfx } = this; const { pfx } = this;
return ` return `
<div class="${pfx}canvas__frames" data-frames></div> <div class="${pfx}canvas__frames" data-frames>
<div class="${pfx}canvas__spots" data-spots style="z-index: 1; position: absolute; pointer-events: none"></div>
</div>
<div id="${pfx}tools" class="${pfx}canvas__tools" data-tools></div> <div id="${pfx}tools" class="${pfx}canvas__tools" data-tools></div>
`; `;
} }
@ -64,6 +66,7 @@ export default class CanvasView extends ModuleView<Canvas> {
toolsEl?: HTMLElement; toolsEl?: HTMLElement;
framesArea?: HTMLElement; framesArea?: HTMLElement;
toolsWrapper?: HTMLElement; toolsWrapper?: HTMLElement;
spotsEl?: HTMLElement;
ready = false; ready = false;
frames!: FramesView; frames!: FramesView;
@ -571,6 +574,7 @@ export default class CanvasView extends ModuleView<Canvas> {
this.offsetEl = el.querySelector(`.${ppfx}offset-v`)!; this.offsetEl = el.querySelector(`.${ppfx}offset-v`)!;
this.fixedOffsetEl = el.querySelector(`.${ppfx}offset-fixed-v`)!; this.fixedOffsetEl = el.querySelector(`.${ppfx}offset-fixed-v`)!;
this.toolsGlobEl = el.querySelector(`.${ppfx}tools-gl`)!; this.toolsGlobEl = el.querySelector(`.${ppfx}tools-gl`)!;
this.spotsEl = el.querySelector('[data-spots]')!;
this.el.className = getUiClass(em, this.className); this.el.className = getUiClass(em, this.className);
this.ready = true; this.ready = true;
this._renderFrames(); this._renderFrames();

Loading…
Cancel
Save