-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: only override slash menu with slash-menu-controller
- Loading branch information
Showing
9 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../src/app/pages/examples/ui-components/replacing-slash-menu/custom-slash-menu.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component } from '@angular/core'; | ||
import { getDefaultSlashMenuItems } from '@blocknote/core'; | ||
import { NgxBlocknoteService } from '@dytab/ngx-blocknote'; | ||
import { HlmButtonDirective } from '@dytab/ui'; | ||
|
||
@Component({ | ||
selector: 'bna-custom-slash-menu', | ||
standalone: true, | ||
imports: [CommonModule, HlmButtonDirective], | ||
template: ` | ||
<div | ||
class="h-full flex flex-col overflow-auto border border-border bg-background shadow-lg shadow-border rounded p-1 min-w-[250px]" | ||
> | ||
@for (item of customSlashItems; track item.key) { | ||
<button | ||
hlmBtn | ||
size="icon" | ||
variant="ghost" | ||
(mousedown)="addItem($event,item)" | ||
class="w-full" | ||
> | ||
{{ item.title }} | ||
</button> | ||
} | ||
</div> | ||
`, | ||
styles: ``, | ||
}) | ||
export class CustomSlashMenuComponent { | ||
customSlashItems = getDefaultSlashMenuItems( | ||
this.ngxBlockNoteService.editor(), | ||
); | ||
constructor(public ngxBlockNoteService: NgxBlocknoteService) {} | ||
|
||
addItem($event: Event,item: { title: string; onItemClick: () => void }){ | ||
$event.preventDefault(); | ||
this.ngxBlockNoteService.editor().suggestionMenus.clearQuery(); | ||
item.onItemClick(); | ||
this.ngxBlockNoteService.editor().suggestionMenus.closeMenu(); | ||
this.ngxBlockNoteService.editor().focus() | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...src/app/pages/examples/ui-components/replacing-slash-menu/replacing-slash-menu.example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component } from '@angular/core'; | ||
import { PartialBlock } from '@blocknote/core'; | ||
import { | ||
BnaEditorComponent, | ||
BnaSlashMenuControllerComponent, | ||
} from '@dytab/ngx-blocknote'; | ||
import { CustomSlashMenuComponent } from './custom-slash-menu.component'; | ||
|
||
@Component({ | ||
selector: 'bna-replacing-slash-menu-example', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
BnaEditorComponent, | ||
CustomSlashMenuComponent, | ||
BnaSlashMenuControllerComponent, | ||
], | ||
template: `<bna-editor [initialContent]="initialContent"> | ||
<bna-slash-menu-controller> | ||
<bna-custom-slash-menu /> | ||
</bna-slash-menu-controller> | ||
</bna-editor> `, | ||
}) | ||
export class ReplacingSlashMenuExample { | ||
initialContent: PartialBlock[] = [ | ||
{ | ||
type: 'paragraph', | ||
content: 'Welcome to this demo!', | ||
}, | ||
{ | ||
type: 'paragraph', | ||
content: "Press the '/' key to open the Slash Menu", | ||
}, | ||
{ | ||
type: 'paragraph', | ||
content: "It's been replaced with a custom component", | ||
}, | ||
{ | ||
type: 'paragraph', | ||
}, | ||
]; | ||
} | ||
|
||
export const formattingToolbarButtonsExampleCode = `import { CommonModule } from '@angular/common'; | ||
import { Component } from '@angular/core'; | ||
import { PartialBlock } from '@blocknote/core'; | ||
import { HlmButtonDirective } from '@dytab/ui'; | ||
import { CustomSlashMenuComponent } from './custom-slash-menu.component'; | ||
import { | ||
BnaBasicTextStyleButtonComponent, | ||
BnaEditorComponent, | ||
BnaFormattingToolbarComponent, | ||
BnaFormattingToolbarControllerComponent, | ||
BnaSuggestionsMenuControllerComponent, | ||
} from '@dytab/ngx-blocknote'; | ||
@Component({ | ||
selector: 'bna-replacing-slash-menu-example', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
BnaEditorComponent, | ||
CustomSlashMenuComponent, | ||
BnaSuggestionsMenuControllerComponent, | ||
], | ||
template: \`<bna-editor [initialContent]="initialContent"> | ||
<bna-suggestions-menu-controller triggerCharacter="/"> | ||
<bna-custom-slash-menu /> | ||
</bna-suggestions-menu-controller> | ||
</bna-editor> \`, | ||
}) | ||
export class ReplacingSlashMenuExample { | ||
initialContent: PartialBlock[] = [ | ||
{ | ||
type: 'paragraph', | ||
content: 'Welcome to this demo!', | ||
}, | ||
{ | ||
type: 'paragraph', | ||
content: "Press the '/' key to open the Slash Menu", | ||
}, | ||
{ | ||
type: 'paragraph', | ||
content: "It's been replaced with a custom component", | ||
}, | ||
{ | ||
type: 'paragraph', | ||
}, | ||
]; | ||
}`; |
56 changes: 56 additions & 0 deletions
56
...cs/src/app/pages/examples/ui-components/replacing-slash-menu/replacing-slash-menu.page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component } from '@angular/core'; | ||
import { | ||
hlmP, | ||
HlmTabsComponent, | ||
HlmTabsContentDirective, | ||
HlmTabsListComponent, | ||
HlmTabsTriggerDirective, | ||
} from '@dytab/ui'; | ||
import { Highlight } from 'ngx-highlightjs'; | ||
import { CodeComponent } from '../../../../shared/code/code.component'; | ||
import { DemoBoxComponent } from '../../../../shared/layout/demo-box.component'; | ||
import { TabsComponent } from '../../../../shared/layout/example-tabs.component'; | ||
import { SectionIntroComponent } from '../../../../shared/layout/section-intro.component'; | ||
import { | ||
ReplacingSlashMenuExample, | ||
formattingToolbarButtonsExampleCode, | ||
} from './replacing-slash-menu.example'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
SectionIntroComponent, | ||
DemoBoxComponent, | ||
HlmTabsComponent, | ||
HlmTabsListComponent, | ||
HlmTabsContentDirective, | ||
HlmTabsTriggerDirective, | ||
TabsComponent, | ||
CodeComponent, | ||
ReplacingSlashMenuExample, | ||
Highlight, | ||
], | ||
template: ` | ||
<bna-section-intro name="Replacing Slash Menu"> | ||
<p class="${hlmP} mb-8"> | ||
In this example, we replace the default Slash Menu component with a basic custom one. | ||
</p> | ||
<p> | ||
<strong>Try it out</strong>: Press the "/" key to see the new Slash Menu! | ||
</p> | ||
</bna-section-intro> | ||
<hlm-tabs tab="preview"> | ||
<bna-example-tabs firstTab="Preview" secondTab="Code"> | ||
<bna-demo-box firstTab> | ||
<bna-replacing-slash-menu-example /> | ||
</bna-demo-box> | ||
<bna-code [code]="exampleCode" secondTab /> | ||
</bna-example-tabs> | ||
</hlm-tabs> | ||
`, | ||
}) | ||
export class ReplacingSlashMenuPage { | ||
exampleCode = formattingToolbarButtonsExampleCode; | ||
} |
13 changes: 13 additions & 0 deletions
13
.../ngx-blocknote/src/lib/components/suggestions-menu/bna-slash-menu-controller.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component } from '@angular/core'; | ||
import { BnaSuggestionsMenuControllerComponent } from './bna-suggestions-menu-controller.component'; | ||
|
||
@Component({ | ||
imports: [CommonModule, BnaSuggestionsMenuControllerComponent], | ||
selector: 'bna-slash-menu-controller', | ||
standalone: true, | ||
template: `<bna-suggestions-menu-controller triggerCharacter="/" | ||
><ng-content></ng-content | ||
></bna-suggestions-menu-controller>`, | ||
}) | ||
export class BnaSlashMenuControllerComponent {} |
1 change: 1 addition & 0 deletions
1
libs/ngx-blocknote/src/lib/components/suggestions-menu/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './bna-suggestions-menu-controller.component'; | ||
export * from './bna-suggestions-menu.component'; | ||
export * from './bna-slash-menu-controller.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters