Browse Source

Add support for target spot

pull/5337/head
Artur Arseniev 3 years ago
parent
commit
0884f2695a
  1. 2
      src/canvas/config/config.ts
  2. 2
      src/canvas/index.ts
  3. 14
      src/canvas/model/CanvasSpot.ts
  4. 21
      src/utils/Sorter.ts

2
src/canvas/config/config.ts

@ -92,8 +92,10 @@ const config: CanvasConfig = {
notTextable: ['button', 'a', 'input[type=checkbox]', 'input[type=radio]'], notTextable: ['button', 'a', 'input[type=checkbox]', 'input[type=radio]'],
allowExternalDrop: true, allowExternalDrop: true,
customSpots: { customSpots: {
// select: true,
hover: true, hover: true,
spacing: true, spacing: true,
target: true,
}, },
}; };

2
src/canvas/index.ts

@ -724,7 +724,7 @@ export default class CanvasModule extends Module<CanvasConfig> {
['model', 'droppable'].forEach(i => (this[i] = {})); ['model', 'droppable'].forEach(i => (this[i] = {}));
} }
setSpot<T extends CanvasSpotProps>(props: Omit<T, 'id'>, opts: AddOptions = {}) { setSpot<T extends CanvasSpotProps>(props: Omit<T, 'id'> & { id?: string }, opts: AddOptions = {}) {
const spotProps = props as T; const spotProps = props as T;
const spots = this.getSpots<T>(spotProps); const spots = this.getSpots<T>(spotProps);

14
src/canvas/model/CanvasSpot.ts

@ -9,8 +9,8 @@ export enum CanvasSpotBuiltInTypes {
Select = 'select', Select = 'select',
Hover = 'hover', Hover = 'hover',
Spacing = 'spacing', Spacing = 'spacing',
Resize = 'resize',
Target = 'target', Target = 'target',
Resize = 'resize',
} }
export type CanvasSpotBuiltInType = `${CanvasSpotBuiltInTypes}`; export type CanvasSpotBuiltInType = `${CanvasSpotBuiltInTypes}`;
@ -78,14 +78,14 @@ export default class CanvasSpot<T extends CanvasSpotProps = CanvasSpotProps> ext
return this.componentView?.el; return this.componentView?.el;
} }
get style() { getStyle(opts: { boxRect?: BoxRect } = {}): Partial<CSSStyleDeclaration> {
const { width, height, x, y } = this.boxRect; const { width, height, x, y } = opts.boxRect || this.boxRect;
return { return {
width, width: `${width}px`,
height, height: `${height}px`,
top: 0, top: '0',
left: 0, left: '0',
position: 'absolute', position: 'absolute',
translate: `${x}px ${y}px`, translate: `${x}px ${y}px`,
}; };

21
src/utils/Sorter.ts

@ -1,13 +1,12 @@
import { bindAll, each, isArray, isFunction, isString, result } from 'underscore'; import { bindAll, each, isArray, isFunction, isString, result } from 'underscore';
import { BlockProperties } from '../block_manager/model/Block'; import { BlockProperties } from '../block_manager/model/Block';
import CanvasModule from '../canvas'; import CanvasModule from '../canvas';
import { CanvasSpotBuiltInTypes } from '../canvas/model/CanvasSpot';
import { $, Collection, Model, View } from '../common'; import { $, Collection, Model, View } from '../common';
import EditorModel from '../editor/model/Editor'; import EditorModel from '../editor/model/Editor';
import { getPointerEvent, isTextNode, off, on } from './dom'; import { getPointerEvent, isTextNode, off, on } from './dom';
import { getElement, getModel, matches } from './mixins'; import { getElement, getModel, matches } from './mixins';
const noop = () => {};
type DropContent = BlockProperties['content']; type DropContent = BlockProperties['content'];
interface Dim { interface Dim {
@ -56,6 +55,15 @@ export interface SorterOptions {
scale?: number; scale?: number;
} }
const noop = () => {};
const targetSpotType = CanvasSpotBuiltInTypes.Target;
const spotTarget = {
id: 'sorter-target',
type: targetSpotType,
};
export default class Sorter extends View { export default class Sorter extends View {
opt!: SorterOptions; opt!: SorterOptions;
elT!: number; elT!: number;
@ -396,7 +404,7 @@ export default class Sorter extends View {
if (src) { if (src) {
srcModel = this.getSourceModel(src); srcModel = this.getSourceModel(src);
srcModel && srcModel.set && srcModel.set('status', 'freezed'); srcModel?.set && srcModel.set('status', 'freezed');
this.srcModel = srcModel; this.srcModel = srcModel;
} }
@ -488,8 +496,10 @@ export default class Sorter extends View {
targetModel.set('status', ''); targetModel.set('status', '');
} }
if (model && model.set) { if (model?.set) {
model.set('status', 'selected-parent'); const cv = this.em!.Canvas;
cv.setSpot({ ...spotTarget, component: model as any });
!cv.hasCustomSpot(targetSpotType) && model.set('status', 'selected-parent');
this.targetModel = model; this.targetModel = model;
} }
} }
@ -1208,6 +1218,7 @@ export default class Sorter extends View {
this.disableTextable(); this.disableTextable();
this.selectTargetModel(); this.selectTargetModel();
this.toggleSortCursor(); this.toggleSortCursor();
this.em?.Canvas.removeSpot(spotTarget);
delete this.toMove; delete this.toMove;
delete this.eventMove; delete this.eventMove;

Loading…
Cancel
Save