Loading...
Loading...
Compare original and translation side by side
npm install @syncfusion/ej2-angular-blockeditor
npm install @syncfusion/ej2-angular-buttons
npm install @syncfusion/ej2-basenpm install @syncfusion/ej2-angular-blockeditor
npm install @syncfusion/ej2-angular-buttons
npm install @syncfusion/ej2-baseimport { Component } from '@angular/core';
import { BlockEditorModule } from '@syncfusion/ej2-angular-blockeditor';
@Component({
selector: 'app-editor',
template: `<ejs-blockeditor [height]="'500px'" />`,
standalone: true,
imports: [BlockEditorModule]
})
export class EditorComponent {}import { Component } from '@angular/core';
import { BlockEditorModule } from '@syncfusion/ej2-angular-blockeditor';
@Component({
selector: 'app-editor',
template: `<ejs-blockeditor [height]="'500px'" />`,
standalone: true,
imports: [BlockEditorModule]
})
export class EditorComponent {}
@import '../node_modules/@syncfusion/ej2-base/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-angular-blockeditor/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-base/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-angular-blockeditor/styles/material3.css';
// app.config.ts
import { importProvidersFrom } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
export const appConfig = {
providers: [
importProvidersFrom(BrowserModule)
]
};
// OR in app.module.ts
@NgModule({
imports: [BlockEditorModule]
})
export class AppModule {}// app.config.ts
import { importProvidersFrom } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
export const appConfig = {
providers: [
importProvidersFrom(BrowserModule)
]
};
// OR in app.module.ts
@NgModule({
imports: [BlockEditorModule]
})
export class AppModule {}@Component({
selector: 'app-autosave-editor',
template: `
<div>
<span>Status: {{ saveStatus }}</span>
<ejs-blockeditor #editor (blockChanged)="onContentChange()"></ejs-blockeditor>
</div>
`,
standalone: true,
imports: [BlockEditorModule]
})
export class AutosaveEditorComponent {
@ViewChild('editor') editor!: BlockEditorComponent;
public saveStatus = 'Saved';
private saveTimeout: any;
public onContentChange(): void {
this.saveStatus = 'Unsaved';
clearTimeout(this.saveTimeout);
this.saveTimeout = setTimeout(() => {
const content = this.editor.getDataAsJson();
this.saveToServer(content);
}, 1000);
}
private saveToServer(content: any): void {
// Save to backend
this.saveStatus = 'Saved';
}
}@Component({
selector: 'app-autosave-editor',
template: `
<div>
<span>状态: {{ saveStatus }}</span>
<ejs-blockeditor #editor (blockChanged)="onContentChange()"></ejs-blockeditor>
</div>
`,
standalone: true,
imports: [BlockEditorModule]
})
export class AutosaveEditorComponent {
@ViewChild('editor') editor!: BlockEditorComponent;
public saveStatus = '已保存';
private saveTimeout: any;
public onContentChange(): void {
this.saveStatus = '未保存';
clearTimeout(this.saveTimeout);
this.saveTimeout = setTimeout(() => {
const content = this.editor.getDataAsJson();
this.saveToServer(content);
}, 1000);
}
private saveToServer(content: any): void {
// 保存到后端
this.saveStatus = '已保存';
}
}@Component({
selector: 'app-document-exporter',
template: `
<div>
<button (click)="exportJson()">Export JSON</button>
<button (click)="exportHtml()">Export HTML</button>
<button (click)="exportMarkdown()">Export Markdown</button>
<ejs-blockeditor #editor></ejs-blockeditor>
</div>
`,
standalone: true,
imports: [BlockEditorModule]
})
export class DocumentExporterComponent {
@ViewChild('editor') editor!: BlockEditorComponent;
public exportJson(): void {
const data = this.editor.getDataAsJson();
this.downloadFile(JSON.stringify(data, null, 2), 'document.json', 'application/json');
}
public exportHtml(): void {
const html = this.editor.getDataAsHtml();
this.downloadFile(html, 'document.html', 'text/html');
}
public exportMarkdown(): void {
// Convert to markdown format
const data = this.editor.getDataAsJson();
const markdown = this.convertToMarkdown(data);
this.downloadFile(markdown, 'document.md', 'text/markdown');
}
private downloadFile(content: string, filename: string, type: string): void {
const blob = new Blob([content], { type });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
link.click();
}
private convertToMarkdown(blocks: any[]): string {
// Implementation details in Data Export and Import reference
return '';
}
}@Component({
selector: 'app-document-exporter',
template: `
<div>
<button (click)="exportJson()">导出JSON</button>
<button (click)="exportHtml()">导出HTML</button>
<button (click)="exportMarkdown()">导出Markdown</button>
<ejs-blockeditor #editor></ejs-blockeditor>
</div>
`,
standalone: true,
imports: [BlockEditorModule]
})
export class DocumentExporterComponent {
@ViewChild('editor') editor!: BlockEditorComponent;
public exportJson(): void {
const data = this.editor.getDataAsJson();
this.downloadFile(JSON.stringify(data, null, 2), 'document.json', 'application/json');
}
public exportHtml(): void {
const html = this.editor.getDataAsHtml();
this.downloadFile(html, 'document.html', 'text/html');
}
public exportMarkdown(): void {
// 转换为Markdown格式
const data = this.editor.getDataAsJson();
const markdown = this.convertToMarkdown(data);
this.downloadFile(markdown, 'document.md', 'text/markdown');
}
private downloadFile(content: string, filename: string, type: string): void {
const blob = new Blob([content], { type });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
link.click();
}
private convertToMarkdown(blocks: any[]): string {
// 实现细节请参考数据导出与导入文档
return '';
}
}
@import '../node_modules/@syncfusion/ej2-base/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-angular-blockeditor/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-base/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material3.css';
@import '../node_modules/@syncfusion/ej2-angular-blockeditor/styles/material3.css';
getDataAsJson()const content = this.blockEditor.getDataAsJson();getDataAsJson()const content = this.blockEditor.getDataAsJson();@Component({
standalone: true,
imports: [BlockEditorModule]
})@Component({
standalone: true,
imports: [BlockEditorModule]
})