From e43ebbd0ca65cf95bb420f397181292649aeb702 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Thu, 9 Dec 2021 00:01:30 +0100 Subject: [PATCH] ++ --- zero.Backoffice.UI/app/editor/editor.d.ts | 24 ++++ .../app/editor/editorFieldProxy.ts | 15 +++ zero.Backoffice.UI/app/editor/fields/text.vue | 32 +++++ .../app/editor/tests/_testcmp.vue | 55 ++++++++ zero.Backoffice.UI/app/editor/tests/types.ts | 120 ++++++++++++++++++ zero.Backoffice.UI/app/editor/types.ts | 81 ------------ .../app/modules/countries/plugin.ts | 12 +- 7 files changed, 256 insertions(+), 83 deletions(-) create mode 100644 zero.Backoffice.UI/app/editor/editor.d.ts create mode 100644 zero.Backoffice.UI/app/editor/editorFieldProxy.ts create mode 100644 zero.Backoffice.UI/app/editor/fields/text.vue create mode 100644 zero.Backoffice.UI/app/editor/tests/_testcmp.vue create mode 100644 zero.Backoffice.UI/app/editor/tests/types.ts delete mode 100644 zero.Backoffice.UI/app/editor/types.ts diff --git a/zero.Backoffice.UI/app/editor/editor.d.ts b/zero.Backoffice.UI/app/editor/editor.d.ts new file mode 100644 index 00000000..0216e1ca --- /dev/null +++ b/zero.Backoffice.UI/app/editor/editor.d.ts @@ -0,0 +1,24 @@ + + +declare module 'zero/editor' +{ + export interface FieldSupportsMaxLength + { + maxLength?: number; + } + + export interface FieldSupportsPlaceholder + { + placeholder?: string; + } + + export type TextFieldOptions = FieldSupportsMaxLength | FieldSupportsPlaceholder; + export type NumberFieldOptions = FieldSupportsMaxLength | FieldSupportsPlaceholder; + + + export interface EditorField + { + text(options?: TextFieldOptions): void; + number(options?: NumberFieldOptions): void; + } +} \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/editorFieldProxy.ts b/zero.Backoffice.UI/app/editor/editorFieldProxy.ts new file mode 100644 index 00000000..5de736a3 --- /dev/null +++ b/zero.Backoffice.UI/app/editor/editorFieldProxy.ts @@ -0,0 +1,15 @@ +import { EditorField } from "zero/editor"; + +export const fieldTypes: Record = {}; + +export const proxy = new Proxy(fieldTypes, { + + get(target, handler) + { + console.info({ target, handler }); + return target[handler]; + } + +}) as EditorField; + +//var field = editor.field('name').text("hallo"); \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/fields/text.vue b/zero.Backoffice.UI/app/editor/fields/text.vue new file mode 100644 index 00000000..ae163cbc --- /dev/null +++ b/zero.Backoffice.UI/app/editor/fields/text.vue @@ -0,0 +1,32 @@ + + + + \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/tests/_testcmp.vue b/zero.Backoffice.UI/app/editor/tests/_testcmp.vue new file mode 100644 index 00000000..347681d7 --- /dev/null +++ b/zero.Backoffice.UI/app/editor/tests/_testcmp.vue @@ -0,0 +1,55 @@ + + + + +// @ts-ignore + + + \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/tests/types.ts b/zero.Backoffice.UI/app/editor/tests/types.ts new file mode 100644 index 00000000..2b5438ec --- /dev/null +++ b/zero.Backoffice.UI/app/editor/tests/types.ts @@ -0,0 +1,120 @@ + +import { Component, ComponentPropsOptions } from 'vue'; +import { proxy, fieldTypes } from '../editorFieldProxy'; +import TestCmp from './_testcmp.vue'; + +export interface ZeroEditor +{ + +} + + +export interface ZeroFieldType +{ + component: Promise; + options: any; +} + + + + +//const testField = { +// component: () => import('./_testcmp.vue'), +// options: { +// maxLength: { +// type: Number, +// default: null +// }, +// placeholder: { +// type: [String, Function], +// default: null +// } +// } + +//} as ZeroFieldType; + + +export class ZeroEditorCanvasBase +{ + field(path: string, component: Component): ZeroEditorField + { + return new ZeroEditorField(path, component); + } +} + + +export class ZeroEditorCanvasBaseWithFieldset extends ZeroEditorCanvasBase +{ + fieldset(): ZeroEditorCanvasBase + { + return new ZeroEditorCanvasBase(); + } +} + + +export class ZeroEditorCanvas extends ZeroEditorCanvasBaseWithFieldset +{ + tab(alias: string, name: string): ZeroEditorTab + { + return new ZeroEditorTab(alias, name); + } +} + + +export class ZeroEditorTab extends ZeroEditorCanvasBaseWithFieldset +{ + alias: string; + name: string; + + constructor(alias: string, name: string) + { + super(); + this.alias = alias; + this.name = name; + } +} + + +export declare type BooleanExpression = (model: TModel, value: TField) => boolean; + + +export class ZeroEditorField +{ + path: string; + component: Component; + + constructor(path: string, component: Component) + { + this.path = path; + this.component = component; + } + + when(condition: BooleanExpression): ZeroEditorField + { + return this; + } + + required(required: boolean | BooleanExpression): ZeroEditorField + { + return this; + } + + configure(opts: ComponentPropsOptions) + { + + } +} + + +export function test() +{ + fieldTypes.text = (maxLength?: number, placeholder?: string | Function) => console.log(`text() called with maxLength: ${maxLength}, placeholder: ${placeholder}`); + + proxy.text(17, 'Enter your text...'); + + //var editor = new ZeroEditorCanvas(); + + //editor.field('hi', TestCmp) + + //console.info(TestCmp.); +} \ No newline at end of file diff --git a/zero.Backoffice.UI/app/editor/types.ts b/zero.Backoffice.UI/app/editor/types.ts deleted file mode 100644 index 38d48173..00000000 --- a/zero.Backoffice.UI/app/editor/types.ts +++ /dev/null @@ -1,81 +0,0 @@ - -export interface ZeroEditor -{ - -} - - -export class ZeroFieldComponent // TODO this needs to extend a vue component -{ - -} - -export class ConfigurableZeroFieldComponent extends ZeroFieldComponent -{ - -} - - -export class ZeroEditorCanvasBase -{ - field(path: string, component: ZeroFieldComponent | ConfigurableZeroFieldComponent): ZeroEditorField - { - return new ZeroEditorField(); - } -} - - -export class ZeroEditorCanvasBaseWithFieldset extends ZeroEditorCanvasBase -{ - fieldset(): ZeroEditorCanvasBase - { - return new ZeroEditorCanvasBase(); - } -} - - -export class ZeroEditorCanvas extends ZeroEditorCanvasBaseWithFieldset -{ - tab(alias: string, name: string): ZeroEditorTab - { - return new ZeroEditorTab(alias, name); - } -} - - -export class ZeroEditorTab extends ZeroEditorCanvasBaseWithFieldset -{ - alias: string; - name: string; - - constructor(alias: string, name: string) - { - super(); - this.alias = alias; - this.name = name; - } -} - - -export declare type BooleanExpression = (model: TModel, value: TField) => boolean; - - -export class ZeroEditorField -{ - when(condition: BooleanExpression): ZeroEditorField - { - return this; - } - - required(required: boolean | BooleanExpression): ZeroEditorField - { - return this; - } -} - - -//var editor = new ZeroEditorCanvas(); - -//editor.field('hi', null); -//editor.fieldset(); -//editor.tab('hi', 'ho'). \ No newline at end of file diff --git a/zero.Backoffice.UI/app/modules/countries/plugin.ts b/zero.Backoffice.UI/app/modules/countries/plugin.ts index d31df350..782e7d71 100644 --- a/zero.Backoffice.UI/app/modules/countries/plugin.ts +++ b/zero.Backoffice.UI/app/modules/countries/plugin.ts @@ -1,5 +1,8 @@ import { ZeroPlugin, ZeroPluginOptions } from '../../core'; import { defineAsyncComponent } from 'vue'; +import { test } from '../../editor/tests/types'; +import { proxy, fieldTypes } from '../../editor/editorFieldProxy'; +import { TextFieldOptions } from 'zero/editor'; const Picker = () => import('./ui-countrypicker.vue'); const Page = () => import('./_page.vue'); @@ -12,7 +15,12 @@ export default { app.vue.component('ui-countrypicker', defineAsyncComponent(Picker)); app.route({ path: '/countries', component: Page }); - app.editor('country', null); - app.editorField('') + //app.editor('country', null); + //app.editorField('') + test(); + + fieldTypes.number = (maxLength?: number, placeholder?: string | Function) => console.log(`number() called with maxLength: ${maxLength}, placeholder: ${placeholder}`); + + proxy.number({ maxLength: 17, placeholder: 'Enter your number...' }); } } as ZeroPlugin; \ No newline at end of file