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

77 lines
1.7 KiB
TypeScript

import { Component } from "vue";
import { ZeroEditorField, ZeroSchema, ZeroEditorDisplay } from "zero/schemas";
import { ZeroEditorCanvas } from "./editor-canvas";
export class ZeroEditor extends ZeroEditorCanvas implements ZeroSchema
{
alias: string;
resourcePrefix?: string;
system: boolean = false;
display: ZeroEditorDisplay = 'tabs';
meta: ZeroEditorMeta = {};
onLabelCreate = (field: ZeroEditorField): string =>
{
return field.configuration.label || (this.resourcePrefix ? this.resourcePrefix + field.path : '@nolabel[' + field.path + ']');
};
onDescriptionCreate = (field: ZeroEditorField): string | null =>
{
return field.configuration.description || (this.resourcePrefix ? this.resourcePrefix + field.path + '_text' : '@nodesc[' + field.path + ']');
};
constructor(alias: string)
{
super();
this.alias = alias;
}
}
export interface ZeroEditorMeta
{
getUrl?: (model: any) => Promise<any>;
allowUrlPreview: boolean;
}
export class ZeroModuleEditor extends ZeroEditor
{
_preview: ZeroModuleEditorPreview | null = null;
constructor(alias: string)
{
super(alias);
}
preview(component: Component, buildProps?: (model: any) => any, options?: ZeroModuleEditorPreviewOptions): void
{
this._preview = {
component,
buildProps: buildProps || (_ => ({})),
options: options || {}
};
}
getPreview(): ZeroModuleEditorPreview | null
{
return this._preview;
}
}
export interface ZeroModuleEditorPreviewOptions
{
canEdit?: boolean;
hideLabel?: boolean;
}
export interface ZeroModuleEditorPreview
{
component: Component;
buildProps?: (model: any) => any;
options?: ZeroModuleEditorPreviewOptions;
}