This commit is contained in:
Chris Chen
2024-04-08 16:48:41 -07:00
parent 0ee2e7e545
commit cd9021d9c0
19 changed files with 438 additions and 39 deletions
@@ -8,6 +8,7 @@ export class MD2Clone {
let cloneObj = null;
switch (type) {
case "TreasureItem":
//let copy = structuredClone(obj);
return new TreasureItem(obj['type'], 1);
break;
case "MobInfo":
@@ -83,7 +83,7 @@ export class HeroDashboardComponent extends MD2Base implements OnInit {
}
public get allowAttack(): boolean {
return this.hero.uiBossFight || (!!this.md2Service.mobs && this.md2Service.mobs.length > 0) || (!!this.md2Service.roamingMonsters && this.md2Service.roamingMonsters.length > 0);
return this.hero.uiBossFight || this.md2Service.mobs?.length > 0 || this.md2Service.roamingMonsters?.length > 0;
}
ngOnInit(): void {
@@ -11,6 +11,9 @@
</nb-accordion-item>
</nb-accordion>
</div> -->
<div class="col-12">
<md2-html-editor></md2-html-editor>
</div>
<div class="col-12 col-md-5">
<nb-card>
@@ -0,0 +1 @@
<editor [init]="htmlEditorSetting"></editor>
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MD2HtmlEditorComponent } from './md2-html-editor.component';
describe('MD2HtmlEditorComponent', () => {
let component: MD2HtmlEditorComponent;
let fixture: ComponentFixture<MD2HtmlEditorComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MD2HtmlEditorComponent]
})
.compileComponents();
fixture = TestBed.createComponent(MD2HtmlEditorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,109 @@
import { Component, ElementRef, EventEmitter, Input, Output, Renderer2 } from '@angular/core';
import { ControlValueAccessor, Validator, AbstractControl, ValidationErrors } from '@angular/forms';
import { Editor, RawEditorOptions } from 'tinymce';
import { MsgBoxService } from '../../../services/msg-box.service';
import { DropDownOption } from '../../../entity/dropDownOption';
import { MD2Icon } from '../massive-darkness2.model';
import { first } from 'rxjs/operators';
@Component({
selector: 'md2-html-editor',
templateUrl: './md2-html-editor.component.html',
styleUrl: './md2-html-editor.component.scss'
})
export class MD2HtmlEditorComponent implements ControlValueAccessor, Validator {
private _lastBlurValue: string;
readonly: boolean = false;
isRequired: boolean = false;
@Input() id? = '';
@Input() name = '';
@Input() data: string;
@Output() focus = new EventEmitter();
@Output() blur = new EventEmitter<string>();
@Input('readonly')
public set input_readonly(value) {
this.readonly = typeof value !== 'undefined' && value !== false;
}
@Input('isRequired')
public set input_isRequired(value) {
this.isRequired = typeof value !== 'undefined' && value !== false;
}
constructor(
private msgBoxService: MsgBoxService,
private elementRef: ElementRef,
private renderer: Renderer2) {
this.htmlEditorSetting.base_url = '/tinymce';
this.htmlEditorSetting.suffix = '.min';
this.htmlEditorSetting['parentComponent'] = this;
this.htmlEditorSetting.plugins = 'lists link image table code';
this.htmlEditorSetting.toolbar2 = 'customInsertButton'
this.htmlEditorSetting.setup = this.htmlEditorSetup;
}
htmlEditorSetting: RawEditorOptions = {};
htmlEditorSetup(editor: Editor) {
let component = this.htmlEditorSetting['parentComponent'] as MD2HtmlEditorComponent;
editor.ui.registry.addButton('customInsertButton', {
icon: 'code-sample',
text: 'MD2 Icon',
onAction: (_) => component.showInsertMD2Icon(editor)
});
}
showInsertMD2Icon(editor: Editor) {
var iconKeys = Object.keys(MD2Icon);
iconKeys = iconKeys.slice(iconKeys.length / 2, iconKeys.length - 1);
this.msgBoxService.showInputbox('Insert MD2 Icon', '', { inputType: 'dropdown', dropDownOptions: iconKeys.map(k => new DropDownOption(k, k)) })
.pipe(first()).subscribe(result => {
editor.insertContent(`&nbsp;<strong>${result}</strong>&nbsp;`);
this.writeValue(editor.getContent());
});
}
validate(control: AbstractControl): ValidationErrors {
// if (this.required && (this.value == null || this.value == 0)) {
// return { 'currency': '' };
// }
return null;
}
registerOnValidatorChange?(fn: () => void): void {
}
onChange = (value: number) => { };
onTouched = () => { };
writeValue(obj: string): void {
this.data = obj;
}
registerOnChange(fn: any): void {
this.onChange = fn;
}
registerOnTouched(fn: any): void {
this.onTouched = fn;
}
setDisabledState?(isDisabled: boolean): void {
this.readonly = isDisabled;
}
ngOnInit() {
}
ngAfterViewInit() {
this.renderer.removeAttribute(this.elementRef.nativeElement, 'id')
}
onBlur() {
if (this._lastBlurValue != this.data) {
this._lastBlurValue = this.data;
this.blur.emit(this.data);
}
}
}