|
| 1 | +import { CommonModule } from '@angular/common'; |
| 2 | +import { Component } from '@angular/core'; |
| 3 | +import { BnaEditorComponent } from '@dytab/block-note-angular'; |
| 4 | +import { HlmButtonDirective } from '@spartan-ng/ui-button-helm'; |
| 5 | +import { BlockNoteEditor } from '@blocknote/core'; |
| 6 | + |
| 7 | +@Component({ |
| 8 | + selector: 'bna-manipulating-blocks-example', |
| 9 | + standalone: true, |
| 10 | + imports: [CommonModule, BnaEditorComponent, HlmButtonDirective], |
| 11 | + template: ` |
| 12 | + <div class="flex gap-2"> |
| 13 | + <button hlmBtn size="sm" type="button" (click)="insertFirstBlock()">Insert First Block</button> |
| 14 | + <button hlmBtn size="sm" type="button" (click)="updateFirstBlock()">Update First Block</button> |
| 15 | + <button hlmBtn size="sm" type="button" (click)="removeFirstBlock()">Remove First Block</button> |
| 16 | + <button hlmBtn size="sm" type="button" (click)="replaceFirstBlock()">Replace First Block</button> |
| 17 | + </div> |
| 18 | + <bna-editor [initialContent]="initialContent" (onEditorReady)="editorReady($event)" /> |
| 19 | + `, |
| 20 | +}) |
| 21 | +export class ManipulatingBlocksExample{ |
| 22 | + initialContent = undefined; |
| 23 | + editor!: BlockNoteEditor; |
| 24 | + |
| 25 | + async editorReady(editor: BlockNoteEditor) { |
| 26 | + this.editor = editor; |
| 27 | + } |
| 28 | + |
| 29 | + insertFirstBlock(){ |
| 30 | + this.editor.insertBlocks( |
| 31 | + [ |
| 32 | + { |
| 33 | + content: |
| 34 | + "This block was inserted at " + |
| 35 | + new Date().toLocaleTimeString(), |
| 36 | + }, |
| 37 | + ], |
| 38 | + this.editor.document[0], |
| 39 | + "before" |
| 40 | + ) |
| 41 | + } |
| 42 | + |
| 43 | + updateFirstBlock(){ |
| 44 | + this.editor.updateBlock(this.editor.document[0], { |
| 45 | + content: |
| 46 | + "This block was updated at " + new Date().toLocaleTimeString(), |
| 47 | + }) |
| 48 | + } |
| 49 | + |
| 50 | + removeFirstBlock(){ |
| 51 | + this.editor.removeBlocks([this.editor.document[0]]) |
| 52 | + } |
| 53 | + |
| 54 | + replaceFirstBlock(){ |
| 55 | + this.editor.replaceBlocks( |
| 56 | + [this.editor.document[0]], |
| 57 | + [ |
| 58 | + { |
| 59 | + content: |
| 60 | + "This block was replaced at " + |
| 61 | + new Date().toLocaleTimeString(), |
| 62 | + }, |
| 63 | + ] |
| 64 | + ) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +export const manipulatingBlocksExampleCode = `import { CommonModule } from '@angular/common'; |
| 69 | +import { Component } from '@angular/core'; |
| 70 | +import { BnaEditorComponent } from '@dytab/block-note-angular'; |
| 71 | +import { HlmButtonDirective } from '@spartan-ng/ui-button-helm'; |
| 72 | +import { BlockNoteEditor } from '@blocknote/core'; |
| 73 | +
|
| 74 | +@Component({ |
| 75 | + selector: 'bna-manipulating-blocks-example', |
| 76 | + standalone: true, |
| 77 | + imports: [CommonModule, BnaEditorComponent, HlmButtonDirective], |
| 78 | + template: \` |
| 79 | + <div class="flex gap-2"> |
| 80 | + <button hlmBtn size="sm" type="button" (click)="insertFirstBlock()">Insert First Block</button> |
| 81 | + <button hlmBtn size="sm" type="button" (click)="updateFirstBlock()">Update First Block</button> |
| 82 | + <button hlmBtn size="sm" type="button" (click)="removeFirstBlock()">Remove First Block</button> |
| 83 | + <button hlmBtn size="sm" type="button" (click)="replaceFirstBlock()">Replace First Block</button> |
| 84 | + </div> |
| 85 | + <bna-editor [initialContent]="initialContent" (onEditorReady)="editorReady($event)" /> |
| 86 | + \`, |
| 87 | +}) |
| 88 | +export class ManipulatingBlocksExample{ |
| 89 | + initialContent = undefined; |
| 90 | + editor!: BlockNoteEditor; |
| 91 | +
|
| 92 | + async editorReady(editor: BlockNoteEditor) { |
| 93 | + this.editor = editor; |
| 94 | + } |
| 95 | +
|
| 96 | + insertFirstBlock(){ |
| 97 | + this.editor.insertBlocks( |
| 98 | + [ |
| 99 | + { |
| 100 | + content: |
| 101 | + "This block was inserted at " + |
| 102 | + new Date().toLocaleTimeString(), |
| 103 | + }, |
| 104 | + ], |
| 105 | + this.editor.document[0], |
| 106 | + "before" |
| 107 | + ) |
| 108 | + } |
| 109 | +
|
| 110 | + updateFirstBlock(){ |
| 111 | + this.editor.updateBlock(this.editor.document[0], { |
| 112 | + content: |
| 113 | + "This block was updated at " + new Date().toLocaleTimeString(), |
| 114 | + }) |
| 115 | + } |
| 116 | +
|
| 117 | + removeFirstBlock(){ |
| 118 | + this.editor.removeBlocks([this.editor.document[0]]) |
| 119 | + } |
| 120 | +
|
| 121 | + replaceFirstBlock(){ |
| 122 | + this.editor.replaceBlocks( |
| 123 | + [this.editor.document[0]], |
| 124 | + [ |
| 125 | + { |
| 126 | + content: |
| 127 | + "This block was replaced at " + |
| 128 | + new Date().toLocaleTimeString(), |
| 129 | + }, |
| 130 | + ] |
| 131 | + ) |
| 132 | + } |
| 133 | +}`; |
0 commit comments