|
| 1 | +import { CommonModule } from '@angular/common'; |
| 2 | +import { Component } from '@angular/core'; |
| 3 | +import { |
| 4 | + BlockNoteEditor, |
| 5 | + BlockNoteSchema, |
| 6 | + defaultBlockSpecs, |
| 7 | + defaultInlineContentSpecs, |
| 8 | + defaultStyleSpecs, |
| 9 | + PartialBlock, |
| 10 | +} from '@blocknote/core'; |
| 11 | +import { |
| 12 | + BlockNoteEditorOptionsType, |
| 13 | + BnaEditorComponent, |
| 14 | + BnaSuggestionsMenuComponent, |
| 15 | + BnaSuggestionsMenuControllerDirective, |
| 16 | + HlmButtonDirective, |
| 17 | +} from '@dytab/block-note-angular'; |
| 18 | +import { Mention } from './mentions'; |
| 19 | + |
| 20 | +const getMentionMenuItems = (editor: typeof schema.BlockNoteEditor) => { |
| 21 | + const users = ['Steve', 'Bob', 'Joe', 'Mike']; |
| 22 | + |
| 23 | + return users.map((user) => ({ |
| 24 | + title: user, |
| 25 | + onItemClick: () => { |
| 26 | + editor.insertInlineContent([ |
| 27 | + { |
| 28 | + type: 'mention', |
| 29 | + props: { |
| 30 | + user, |
| 31 | + }, |
| 32 | + }, |
| 33 | + ' ', // add a space after the mention |
| 34 | + ]); |
| 35 | + }, |
| 36 | + })); |
| 37 | +}; |
| 38 | +const schema = BlockNoteSchema.create({ |
| 39 | + blockSpecs: { |
| 40 | + ...defaultBlockSpecs, |
| 41 | + }, |
| 42 | + inlineContentSpecs: { ...defaultInlineContentSpecs, mention: Mention }, |
| 43 | + styleSpecs: { ...defaultStyleSpecs }, |
| 44 | +}); |
| 45 | +@Component({ |
| 46 | + selector: 'bna-mentions-menu-example', |
| 47 | + standalone: true, |
| 48 | + imports: [ |
| 49 | + CommonModule, |
| 50 | + BnaEditorComponent, |
| 51 | + HlmButtonDirective, |
| 52 | + BnaSuggestionsMenuControllerDirective, |
| 53 | + BnaSuggestionsMenuComponent, |
| 54 | + ], |
| 55 | + template: `<bna-editor |
| 56 | + [initialContent]="initialContent" |
| 57 | + [options]="options" |
| 58 | + (onEditorReady)="onEditorReady($event)" |
| 59 | + ><bna-suggestions-menu-controller triggerCharacter="@"> |
| 60 | + <div |
| 61 | + class="bg-background shadow-2xl shadow-neutral-500 rounded p-1 flex flex-col" |
| 62 | + > |
| 63 | + @for(item of items;track item.title){ |
| 64 | + <button |
| 65 | + hlmBtn |
| 66 | + variant="ghost" |
| 67 | + size="sm" |
| 68 | + (mousedown)="item.onItemClick()" |
| 69 | + > |
| 70 | + {{ item.title }} |
| 71 | + </button> |
| 72 | + } |
| 73 | + </div> |
| 74 | + </bna-suggestions-menu-controller></bna-editor |
| 75 | + >`, |
| 76 | +}) |
| 77 | +export class MentionsMenuExample { |
| 78 | + items: { title: string; onItemClick: () => void }[] = []; |
| 79 | + initialContent: PartialBlock< |
| 80 | + typeof schema.blockSchema, |
| 81 | + typeof schema.inlineContentSchema |
| 82 | + >[] = [ |
| 83 | + { |
| 84 | + type: 'paragraph', |
| 85 | + content: 'Welcome to this demo!', |
| 86 | + }, |
| 87 | + { |
| 88 | + type: 'paragraph', |
| 89 | + content: [ |
| 90 | + { |
| 91 | + type: 'mention', |
| 92 | + props: { |
| 93 | + user: 'Steve', |
| 94 | + }, |
| 95 | + }, |
| 96 | + { |
| 97 | + type: 'text', |
| 98 | + text: ' <- This is an example mention', |
| 99 | + styles: {}, |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | + { |
| 104 | + type: 'paragraph', |
| 105 | + content: "Press the '@' key to open the mentions menu and add another", |
| 106 | + }, |
| 107 | + { |
| 108 | + type: 'paragraph', |
| 109 | + }, |
| 110 | + ]; |
| 111 | + options: BlockNoteEditorOptionsType = { schema }; |
| 112 | + |
| 113 | + onEditorReady($event: BlockNoteEditor<any, any, any>) { |
| 114 | + this.items = getMentionMenuItems($event); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +export const mentionsMenuExampleCode = `import { CommonModule } from '@angular/common'; |
| 119 | +import { Component } from '@angular/core'; |
| 120 | +import { |
| 121 | + BlockNoteEditor, |
| 122 | + BlockNoteSchema, |
| 123 | + defaultBlockSpecs, |
| 124 | + defaultInlineContentSpecs, |
| 125 | + defaultStyleSpecs, |
| 126 | + PartialBlock, |
| 127 | +} from '@blocknote/core'; |
| 128 | +import { |
| 129 | + BlockNoteEditorOptionsType, |
| 130 | + BnaEditorComponent, |
| 131 | + BnaSuggestionsMenuComponent, |
| 132 | + BnaSuggestionsMenuControllerDirective, |
| 133 | + HlmButtonDirective, |
| 134 | +} from '@dytab/block-note-angular'; |
| 135 | +import { Mention } from './mentions'; |
| 136 | +
|
| 137 | +const getMentionMenuItems = (editor: typeof schema.BlockNoteEditor) => { |
| 138 | + const users = ['Steve', 'Bob', 'Joe', 'Mike']; |
| 139 | +
|
| 140 | + return users.map((user) => ({ |
| 141 | + title: user, |
| 142 | + onItemClick: () => { |
| 143 | + editor.insertInlineContent([ |
| 144 | + { |
| 145 | + type: 'mention', |
| 146 | + props: { |
| 147 | + user, |
| 148 | + }, |
| 149 | + }, |
| 150 | + ' ', // add a space after the mention |
| 151 | + ]); |
| 152 | + }, |
| 153 | + })); |
| 154 | +}; |
| 155 | +const schema = BlockNoteSchema.create({ |
| 156 | + blockSpecs: { |
| 157 | + ...defaultBlockSpecs, |
| 158 | + }, |
| 159 | + inlineContentSpecs: { ...defaultInlineContentSpecs, mention: Mention }, |
| 160 | + styleSpecs: { ...defaultStyleSpecs }, |
| 161 | +}); |
| 162 | +@Component({ |
| 163 | + selector: 'bna-mentions-menu-example', |
| 164 | + standalone: true, |
| 165 | + imports: [ |
| 166 | + CommonModule, |
| 167 | + BnaEditorComponent, |
| 168 | + HlmButtonDirective, |
| 169 | + BnaSuggestionsMenuControllerDirective, |
| 170 | + BnaSuggestionsMenuComponent, |
| 171 | + ], |
| 172 | + template: \`<bna-editor |
| 173 | + [initialContent]="initialContent" |
| 174 | + [options]="options" |
| 175 | + (onEditorReady)="onEditorReady($event)" |
| 176 | + ><bna-suggestions-menu-controller triggerCharacter="@"> |
| 177 | + <div |
| 178 | + class="bg-background shadow-2xl shadow-neutral-500 rounded p-1 flex flex-col" |
| 179 | + > |
| 180 | + @for(item of items;track item.title){ |
| 181 | + <button |
| 182 | + hlmBtn |
| 183 | + variant="ghost" |
| 184 | + size="sm" |
| 185 | + (mousedown)="item.onItemClick()" |
| 186 | + > |
| 187 | + {{ item.title }} |
| 188 | + </button> |
| 189 | + } |
| 190 | + </div> |
| 191 | + </bna-suggestions-menu-controller></bna-editor |
| 192 | + >\`, |
| 193 | +}) |
| 194 | +export class MentionsMenuExample { |
| 195 | + items: { title: string; onItemClick: () => void }[] = []; |
| 196 | + initialContent: PartialBlock< |
| 197 | + typeof schema.blockSchema, |
| 198 | + typeof schema.inlineContentSchema |
| 199 | + >[] = [ |
| 200 | + { |
| 201 | + type: 'paragraph', |
| 202 | + content: 'Welcome to this demo!', |
| 203 | + }, |
| 204 | + { |
| 205 | + type: 'paragraph', |
| 206 | + content: [ |
| 207 | + { |
| 208 | + type: 'mention', |
| 209 | + props: { |
| 210 | + user: 'Steve', |
| 211 | + }, |
| 212 | + }, |
| 213 | + { |
| 214 | + type: 'text', |
| 215 | + text: ' <- This is an example mention', |
| 216 | + styles: {}, |
| 217 | + }, |
| 218 | + ], |
| 219 | + }, |
| 220 | + { |
| 221 | + type: 'paragraph', |
| 222 | + content: "Press the '@' key to open the mentions menu and add another", |
| 223 | + }, |
| 224 | + { |
| 225 | + type: 'paragraph', |
| 226 | + }, |
| 227 | + ]; |
| 228 | + options: BlockNoteEditorOptionsType = { schema }; |
| 229 | +
|
| 230 | + onEditorReady($event: BlockNoteEditor<any, any, any>) { |
| 231 | + this.items = getMentionMenuItems($event); |
| 232 | + } |
| 233 | +}`; |
0 commit comments