diff --git a/libs/composer/package.json b/libs/composer/package.json index fa55e297..2a31f874 100644 --- a/libs/composer/package.json +++ b/libs/composer/package.json @@ -18,6 +18,7 @@ "author": "Orchestrator ", "license": "MIT", "peerDependencies": { + "@angular/cdk": "^7.0.0", "@angular/common": "^7.0.0", "@angular/core": "^7.0.0", "@orchestrator/core": "^0.0.0", diff --git a/libs/composer/src/lib/composer-canvas/composer-canvas.component.html b/libs/composer/src/lib/composer-canvas/composer-canvas.component.html index dbcbaa57..5a8578a9 100644 --- a/libs/composer/src/lib/composer-canvas/composer-canvas.component.html +++ b/libs/composer/src/lib/composer-canvas/composer-canvas.component.html @@ -1 +1 @@ -

composer-canvas works!

+ diff --git a/libs/composer/src/lib/composer-canvas/composer-canvas.component.ts b/libs/composer/src/lib/composer-canvas/composer-canvas.component.ts index c57fde68..5d17d1d9 100644 --- a/libs/composer/src/lib/composer-canvas/composer-canvas.component.ts +++ b/libs/composer/src/lib/composer-canvas/composer-canvas.component.ts @@ -1,4 +1,7 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { OrchestratorConfigItem } from '@orchestrator/core'; + +import { ComposerDroppableComponent } from '../composer-droppable'; @Component({ selector: 'orc-composer-canvas', @@ -6,8 +9,6 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; styleUrls: ['./composer-canvas.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class ComposerCanvasComponent implements OnInit { - constructor() {} - - ngOnInit() {} +export class ComposerCanvasComponent { + initialConfig: OrchestratorConfigItem = ComposerDroppableComponent.getWrapperConfig(); } diff --git a/libs/composer/src/lib/composer-canvas/composer-canvas.module.ts b/libs/composer/src/lib/composer-canvas/composer-canvas.module.ts index e3812121..bf8dcf60 100644 --- a/libs/composer/src/lib/composer-canvas/composer-canvas.module.ts +++ b/libs/composer/src/lib/composer-canvas/composer-canvas.module.ts @@ -1,10 +1,12 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; +import { OrchestratorCoreModule } from '@orchestrator/core'; +import { ComposerDroppableModule } from '../composer-droppable'; import { ComposerCanvasComponent } from './composer-canvas.component'; @NgModule({ - imports: [CommonModule], + imports: [CommonModule, OrchestratorCoreModule, ComposerDroppableModule], exports: [ComposerCanvasComponent], declarations: [ComposerCanvasComponent], }) diff --git a/libs/composer/src/lib/composer-components/composer-components.component.css b/libs/composer/src/lib/composer-components/composer-components.component.css index f3ea1e68..2beeb344 100644 --- a/libs/composer/src/lib/composer-components/composer-components.component.css +++ b/libs/composer/src/lib/composer-components/composer-components.component.css @@ -1,3 +1,7 @@ +nz-list-item { + background: white; +} + nz-list-item-meta::ng-deep .ant-list-item-meta-title { word-break: break-all; } diff --git a/libs/composer/src/lib/composer-components/composer-components.component.html b/libs/composer/src/lib/composer-components/composer-components.component.html index 9f8a5b03..855c4c9d 100644 --- a/libs/composer/src/lib/composer-components/composer-components.component.html +++ b/libs/composer/src/lib/composer-components/composer-components.component.html @@ -1,7 +1,12 @@

Component List

- + - + this.cfr.resolveComponentFactory(comp)); + .map(comp => this.cfr.resolveComponentFactory(comp)) + .filter(({ selector }) => !selector.startsWith('orc-composer')); } } diff --git a/libs/composer/src/lib/composer-components/composer-components.module.ts b/libs/composer/src/lib/composer-components/composer-components.module.ts index dc79017b..f047be54 100644 --- a/libs/composer/src/lib/composer-components/composer-components.module.ts +++ b/libs/composer/src/lib/composer-components/composer-components.module.ts @@ -1,3 +1,4 @@ +import { DragDropModule } from '@angular/cdk/drag-drop'; import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { NzListModule } from 'ng-zorro-antd/list'; @@ -5,7 +6,7 @@ import { NzListModule } from 'ng-zorro-antd/list'; import { ComposerComponentsComponent } from './composer-components.component'; @NgModule({ - imports: [CommonModule, NzListModule], + imports: [CommonModule, DragDropModule, NzListModule], exports: [ComposerComponentsComponent], declarations: [ComposerComponentsComponent], }) diff --git a/libs/composer/src/lib/composer-droppable/composer-droppable-config.ts b/libs/composer/src/lib/composer-droppable/composer-droppable-config.ts new file mode 100644 index 00000000..334ca968 --- /dev/null +++ b/libs/composer/src/lib/composer-droppable/composer-droppable-config.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@angular/core'; +import { + Option, + OptionRequired, + OrchestratorConfigItem, + OrchestratorDynamicComponentType, +} from '@orchestrator/core'; + +@Injectable({ providedIn: 'root' }) +export class ComposerDroppableConfig + implements OrchestratorConfigItem { + @OptionRequired() + component: string | OrchestratorDynamicComponentType; + + @Option() + config?: C; + + @Option() + id?: string; + + @Option() + classes?: string | string[] | { [name: string]: boolean }; + + @Option() + attributes?: { [attr: string]: string }; + + @Option() + handlers?: { [event: string]: string | Function }; +} diff --git a/libs/composer/src/lib/composer-droppable/composer-droppable.component.css b/libs/composer/src/lib/composer-droppable/composer-droppable.component.css index e69de29b..f4388ce0 100644 --- a/libs/composer/src/lib/composer-droppable/composer-droppable.component.css +++ b/libs/composer/src/lib/composer-droppable/composer-droppable.component.css @@ -0,0 +1,10 @@ +.drop-list { + padding: 10px; + background: lightcyan; + border: 1px dashed lightblue; + text-align: center; +} + +.drop-list.cdk-drop-list-dragging .drop-list-hint { + display: none; +} diff --git a/libs/composer/src/lib/composer-droppable/composer-droppable.component.html b/libs/composer/src/lib/composer-droppable/composer-droppable.component.html index 1e485e7f..353788f6 100644 --- a/libs/composer/src/lib/composer-droppable/composer-droppable.component.html +++ b/libs/composer/src/lib/composer-droppable/composer-droppable.component.html @@ -1 +1,9 @@ -

composer-droppable works!

+ +
+ Drop component here! +
diff --git a/libs/composer/src/lib/composer-droppable/composer-droppable.component.ts b/libs/composer/src/lib/composer-droppable/composer-droppable.component.ts index 794161eb..bf74fe13 100644 --- a/libs/composer/src/lib/composer-droppable/composer-droppable.component.ts +++ b/libs/composer/src/lib/composer-droppable/composer-droppable.component.ts @@ -1,4 +1,19 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; +import { CdkDragDrop } from '@angular/cdk/drag-drop'; +import { + ChangeDetectionStrategy, + Component, + EventEmitter, + Input, + Output, +} from '@angular/core'; +import { + DynamicComponent, + OrchestratorConfigItem, + OrchestratorDynamicComponent, + OrchestratorDynamicComponentType, +} from '@orchestrator/core'; + +import { ComposerDroppableConfig } from './composer-droppable-config'; /** * @internal @@ -9,8 +24,54 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; styleUrls: ['./composer-droppable.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class ComposerDroppableComponent implements OnInit { - constructor() {} +@DynamicComponent({ config: ComposerDroppableConfig }) +export class ComposerDroppableComponent + implements OrchestratorDynamicComponent { + + @Input() config: ComposerDroppableConfig; + + @Output() componentDrop = new EventEmitter(); + static getWrapperConfig() { + return { + component: ComposerDroppableComponent, + handlers: { + componentDrop( + updateConfig, + getInjector, + injectFlags, + getComponent, + $config: OrchestratorConfigItem, + ) { + updateConfig($config); + const getParentDroppableInjector = getInjector().get( + 'getInjector', + injectFlags.SkipSelf, + ); + const parentUpdateConfig = getParentDroppableInjector().get( + 'updateConfig', + ); + const parentGetConfig = getParentDroppableInjector().get('getConfig'); + const parentConfigItems = parentGetConfig().items || []; + parentUpdateConfig({ + items: [ + ...parentConfigItems, + getComponent().constructor.getWrapperConfig(), + ], + }); + }, + }, + }; + } + + static wrapComponent(comp) { + return { + component: comp, + items: [ComposerDroppableComponent.getWrapperConfig()], + }; + } - ngOnInit() {} + drop(e: CdkDragDrop) { + const compType = e.item.data as OrchestratorDynamicComponentType; + this.componentDrop.emit(ComposerDroppableComponent.wrapComponent(compType)); + } } diff --git a/libs/composer/src/lib/composer-droppable/composer-droppable.module.ts b/libs/composer/src/lib/composer-droppable/composer-droppable.module.ts index 9cccddf7..d57984ce 100644 --- a/libs/composer/src/lib/composer-droppable/composer-droppable.module.ts +++ b/libs/composer/src/lib/composer-droppable/composer-droppable.module.ts @@ -1,5 +1,7 @@ +import { DragDropModule } from '@angular/cdk/drag-drop'; import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; +import { OrchestratorCoreModule } from '@orchestrator/core'; import { ComposerDroppableComponent } from './composer-droppable.component'; @@ -7,7 +9,11 @@ import { ComposerDroppableComponent } from './composer-droppable.component'; * @internal */ @NgModule({ - imports: [CommonModule], + imports: [ + CommonModule, + DragDropModule, + OrchestratorCoreModule.withComponents([ComposerDroppableComponent]), + ], exports: [ComposerDroppableComponent], declarations: [ComposerDroppableComponent], }) diff --git a/libs/composer/src/lib/composer.component.css b/libs/composer/src/lib/composer.component.css index e69de29b..896f95b8 100644 --- a/libs/composer/src/lib/composer.component.css +++ b/libs/composer/src/lib/composer.component.css @@ -0,0 +1,10 @@ +nz-sider { + height: 100vh; + position: fixed; + left: 0; +} + +nz-content { + margin: 24px 16px 0; + overflow: initial; +} diff --git a/libs/composer/src/lib/composer.component.html b/libs/composer/src/lib/composer.component.html index 7394e576..f60f5de6 100644 --- a/libs/composer/src/lib/composer.component.html +++ b/libs/composer/src/lib/composer.component.html @@ -1,12 +1,9 @@ - - + + - - + + diff --git a/libs/composer/src/lib/composer.component.ts b/libs/composer/src/lib/composer.component.ts index 83038288..860b2052 100644 --- a/libs/composer/src/lib/composer.component.ts +++ b/libs/composer/src/lib/composer.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component } from '@angular/core'; @Component({ selector: 'orc-composer', @@ -6,8 +6,6 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; styleUrls: ['./composer.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class ComposerComponent implements OnInit { - constructor() {} - - ngOnInit() {} +export class ComposerComponent { + sideWidth = 250; } diff --git a/libs/composer/src/lib/composer.module.ts b/libs/composer/src/lib/composer.module.ts index dd8a24d8..0c3f2444 100644 --- a/libs/composer/src/lib/composer.module.ts +++ b/libs/composer/src/lib/composer.module.ts @@ -1,12 +1,14 @@ +import { DragDropModule } from '@angular/cdk/drag-drop'; import { CommonModule } from '@angular/common'; import { ModuleWithProviders, NgModule } from '@angular/core'; import { ComponentRegistry, + ErrorStrategy, OrchestratorCoreModule, OrchestratorDynamicComponentType, + SuppressErrorStrategy, } from '@orchestrator/core'; import { NzLayoutModule } from 'ng-zorro-antd/layout'; -import { NzMenuModule } from 'ng-zorro-antd/menu'; import { ComposerCanvasModule } from './composer-canvas'; import { ComposerComponentsModule } from './composer-components'; @@ -21,6 +23,7 @@ import { ComposerComponent } from './composer.component'; @NgModule({ imports: [ CommonModule, + DragDropModule, NzLayoutModule, OrchestratorCoreModule, ComposerCanvasModule, @@ -42,11 +45,13 @@ import { ComposerComponent } from './composer.component'; ComposerComponent, ], declarations: [ComposerComponent], + providers: [], }) export class ComposerModule { static forRoot(): ModuleWithProviders { return { ngModule: ComposerModule, + providers: [{ provide: ErrorStrategy, useClass: SuppressErrorStrategy }], }; }