2022-05-03 21:51:01 -05:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-05-20 14:30:29 -05:00
|
|
|
import { CanvasElementOptions, CanvasFrameOptions } from 'app/features/canvas';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-05-04 00:58:00 -05:00
|
|
|
import { FrameState } from './frame';
|
2021-10-28 11:58:31 -05:00
|
|
|
import { Scene } from './scene';
|
2021-10-13 15:12:16 -05:00
|
|
|
|
2022-05-04 00:58:00 -05:00
|
|
|
export class RootElement extends FrameState {
|
|
|
|
constructor(public options: CanvasFrameOptions, public scene: Scene, private changeCallback: () => void) {
|
2021-10-28 11:58:31 -05:00
|
|
|
super(options, scene);
|
2022-04-20 11:59:49 -05:00
|
|
|
|
|
|
|
this.sizeStyle = {
|
|
|
|
height: '100%',
|
|
|
|
width: '100%',
|
|
|
|
};
|
2021-10-13 15:12:16 -05:00
|
|
|
}
|
|
|
|
|
2021-10-28 11:58:31 -05:00
|
|
|
isRoot(): this is RootElement {
|
2021-10-13 15:12:16 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// root type can not change
|
|
|
|
onChange(options: CanvasElementOptions) {
|
|
|
|
this.revId++;
|
2022-05-04 00:58:00 -05:00
|
|
|
this.options = { ...options } as CanvasFrameOptions;
|
2021-10-13 15:12:16 -05:00
|
|
|
this.changeCallback();
|
|
|
|
}
|
|
|
|
|
2022-05-04 00:58:00 -05:00
|
|
|
getSaveModel(): CanvasFrameOptions {
|
2022-04-20 11:59:49 -05:00
|
|
|
const { placement, constraint, ...rest } = this.options;
|
2021-10-13 15:12:16 -05:00
|
|
|
|
|
|
|
return {
|
2022-04-20 11:59:49 -05:00
|
|
|
...rest, // everything except placement & constraint
|
2021-10-13 15:12:16 -05:00
|
|
|
elements: this.elements.map((v) => v.getSaveModel()),
|
2022-03-02 08:02:09 -06:00
|
|
|
};
|
2021-10-13 15:12:16 -05:00
|
|
|
}
|
2022-05-03 21:51:01 -05:00
|
|
|
|
|
|
|
setRootRef = (target: HTMLDivElement) => {
|
|
|
|
this.div = target;
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-05-20 14:30:29 -05:00
|
|
|
<div
|
|
|
|
onContextMenu={(event) => event.preventDefault()}
|
|
|
|
key={this.UID}
|
|
|
|
ref={this.setRootRef}
|
|
|
|
style={{ ...this.sizeStyle, ...this.dataStyle }}
|
|
|
|
>
|
2022-05-03 21:51:01 -05:00
|
|
|
{this.elements.map((v) => v.render())}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-10-13 15:12:16 -05:00
|
|
|
}
|