Files
mixtape/zero.Backoffice.UI/app/editor/editor-canvas.ts
T

82 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-12-21 00:53:17 +01:00
import { ZeroEditorField } from "zero/schemas";
import { ZeroEditorFieldImpl, ZeroEditorFieldConfiguration, createFieldProxy } from "./editor-field";
export class ZeroEditorCanvasBase
{
fields: ZeroEditorField[] = [];
2021-12-21 13:58:48 +01:00
sort: number = 0;
2022-01-03 01:08:55 +01:00
isFake: boolean = false;
2021-12-21 00:53:17 +01:00
field(path: string, config?: ZeroEditorFieldConfiguration): ZeroEditorField
{
const field = new ZeroEditorFieldImpl(path, config);
2021-12-21 13:58:48 +01:00
if (!config || typeof config.sort === 'undefined')
{
field.configuration.sort = (this.fields.length + 1) * 10;
}
2021-12-21 00:53:17 +01:00
const proxy = createFieldProxy(field) as ZeroEditorField;
this.fields.push(proxy);
return proxy;
}
2022-01-14 11:51:38 +01:00
getField(path: string): ZeroEditorField | undefined
{
return this.fields.find(x => x.path == path);
}
2021-12-21 00:53:17 +01:00
}
2021-12-29 13:08:48 +01:00
interface OnFieldsetCreate
{
(set: ZeroEditorCanvasBase): void;
}
2021-12-21 00:53:17 +01:00
export class ZeroEditorCanvasBaseWithFieldset extends ZeroEditorCanvasBase
{
2021-12-21 13:58:48 +01:00
fieldsets: ZeroEditorCanvasBase[] = [];
2021-12-29 13:08:48 +01:00
fieldset(onCreate: OnFieldsetCreate): void
2021-12-21 00:53:17 +01:00
{
2021-12-21 13:58:48 +01:00
const fieldset = new ZeroEditorCanvasBase();
fieldset.sort = (this.fieldsets.length + 1) * 10;
this.fieldsets.push(fieldset);
2021-12-29 13:08:48 +01:00
onCreate(fieldset);
2021-12-21 00:53:17 +01:00
}
}
export class ZeroEditorCanvas extends ZeroEditorCanvasBaseWithFieldset
{
2021-12-21 13:58:48 +01:00
tabs: ZeroEditorTab[] = [];
2021-12-21 00:53:17 +01:00
tab(alias: string, name: string): ZeroEditorTab
{
2021-12-21 13:58:48 +01:00
const tab = new ZeroEditorTab(alias, name);
tab.sort = (this.tabs.length + 1) * 10;
this.tabs.push(tab);
return tab;
2021-12-21 00:53:17 +01:00
}
2022-01-14 11:51:38 +01:00
getTab(alias: string): ZeroEditorTab | undefined
{
return this.tabs.find(x => x.alias == alias);
}
2021-12-21 00:53:17 +01:00
}
export class ZeroEditorTab extends ZeroEditorCanvasBaseWithFieldset
{
alias: string;
name: string;
constructor(alias: string, name: string)
{
super();
this.alias = alias;
this.name = name;
}
}