|
1 | 1 | import { CommonModule } from '@angular/common';
|
2 |
| -import { Component } from '@angular/core'; |
| 2 | +import { Component, inject, Input } from '@angular/core'; |
3 | 3 | import {
|
| 4 | + Block, |
4 | 5 | BlockNoteEditor,
|
5 |
| - BlockNoteSchema, |
| 6 | + BlockNoteSchema, BlockSchemaFromSpecs, |
| 7 | + DefaultBlockSchema, |
6 | 8 | defaultBlockSpecs,
|
| 9 | + DefaultInlineContentSchema, |
7 | 10 | defaultInlineContentSpecs,
|
8 |
| - defaultStyleSpecs, |
9 |
| - insertOrUpdateBlock, |
10 |
| - PartialBlock, |
| 11 | + DefaultStyleSchema, |
| 12 | + defaultStyleSpecs, InlineContentSchema, |
| 13 | + PartialBlock, StyleSchema, TiptapBlockImplementation |
11 | 14 | } from '@blocknote/core';
|
12 | 15 | import {
|
| 16 | + BlockNoteAngularService, |
13 | 17 | BlockNoteEditorOptionsType,
|
| 18 | + BnaAddBlockButtonComponent, |
| 19 | + BnaDeleteBlockItemComponent, |
| 20 | + BnaDragHandleMenuComponent, |
14 | 21 | BnaEditorComponent,
|
| 22 | + BnaSideMenuComponent, |
| 23 | + BnaSideMenuControllerDirective, |
15 | 24 | HlmButtonDirective,
|
| 25 | + HlmCheckboxComponent, |
| 26 | + HlmDialogComponent, |
| 27 | + HlmDialogContentComponent, |
| 28 | + HlmDialogFooterComponent, |
| 29 | + HlmDialogHeaderComponent, HlmInputDirective |
16 | 30 | } from '@dytab/block-note-angular';
|
17 | 31 | import { apiContentBlock } from './api-content-block';
|
| 32 | +import { |
| 33 | + ResetBlockButtonComponent |
| 34 | +} from '../../ui-components/adding-side-menu-drag-handle-items/reset-block-button.component'; |
| 35 | +import { |
| 36 | + BrnDialogContentDirective, |
| 37 | + BrnDialogDescriptionDirective, |
| 38 | + BrnDialogRef, |
| 39 | + BrnDialogTitleDirective, |
| 40 | + BrnDialogTriggerDirective |
| 41 | +} from '@spartan-ng/ui-dialog-brain'; |
| 42 | +import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms'; |
18 | 43 |
|
19 | 44 | const schema = BlockNoteSchema.create({
|
20 | 45 | blockSpecs: {
|
21 | 46 | ...defaultBlockSpecs,
|
22 |
| - apiContent: apiContentBlock, |
| 47 | + apiContent: apiContentBlock |
23 | 48 | },
|
24 | 49 | inlineContentSpecs: { ...defaultInlineContentSpecs },
|
25 |
| - styleSpecs: { ...defaultStyleSpecs }, |
| 50 | + styleSpecs: { ...defaultStyleSpecs } |
26 | 51 | });
|
| 52 | + |
27 | 53 | @Component({
|
28 | 54 | selector: 'bna-api-content-block-example',
|
29 | 55 | standalone: true,
|
30 |
| - imports: [CommonModule, BnaEditorComponent, HlmButtonDirective], |
31 |
| - template: `<bna-editor |
32 |
| - [initialContent]="initialContent" |
33 |
| - [options]="options" |
34 |
| - />`, |
35 |
| -}) |
36 |
| -export class ApiContentBlockExample { |
37 |
| - initialContent: PartialBlock<typeof schema.blockSchema>[] = [ |
38 |
| - { |
39 |
| - type: 'apiContent', |
40 |
| - props: {}, |
41 |
| - }, |
42 |
| - ]; |
43 |
| - options: BlockNoteEditorOptionsType< |
44 |
| - typeof schema.blockSchema, |
45 |
| - typeof schema.inlineContentSchema, |
46 |
| - typeof schema.styleSchema |
47 |
| - > = { |
48 |
| - schema, |
49 |
| - }; |
50 |
| -} |
| 56 | + imports: [ |
| 57 | + CommonModule, |
| 58 | + BnaEditorComponent, |
| 59 | + HlmButtonDirective, |
| 60 | + BnaAddBlockButtonComponent, |
| 61 | + BnaDeleteBlockItemComponent, |
| 62 | + BnaDragHandleMenuComponent, |
| 63 | + BnaSideMenuComponent, |
| 64 | + BnaSideMenuControllerDirective, |
| 65 | + ResetBlockButtonComponent, |
| 66 | + HlmDialogComponent, |
| 67 | + HlmDialogContentComponent, |
| 68 | + BrnDialogContentDirective, |
| 69 | + HlmDialogHeaderComponent, |
| 70 | + BrnDialogTitleDirective, |
| 71 | + BrnDialogDescriptionDirective, |
| 72 | + BrnDialogTriggerDirective, |
| 73 | + HlmDialogFooterComponent, |
| 74 | + HlmCheckboxComponent, |
| 75 | + ReactiveFormsModule, |
| 76 | + HlmInputDirective |
| 77 | + ], |
| 78 | + providers: [BlockNoteAngularService], |
| 79 | + template: ` |
| 80 | + <bna-editor |
| 81 | + [initialContent]="initialContent" |
| 82 | + [options]="options" |
| 83 | + (onEditorReady)="onEditorReady($event)" |
| 84 | + > |
| 85 | + <bna-side-menu-controller> |
| 86 | + <bna-side-menu> |
| 87 | + <bna-add-block-btn /> |
| 88 | + <bna-drag-handle-menu-btn> |
| 89 | + <hlm-dialog> |
| 90 | + <button |
| 91 | + hlmBtn |
| 92 | + brnDialogTrigger |
| 93 | + variant="ghost" |
| 94 | + size="sm" |
| 95 | + class="justify-start w-full" |
| 96 | + > |
| 97 | + Configure Block |
| 98 | + </button> |
| 99 | + <hlm-dialog-content *brnDialogContent="let ctx"> |
| 100 | + <form [formGroup]="formGroup" (ngSubmit)="updateBlockConfiguration(); ctx.close()"> |
51 | 101 |
|
52 |
| -export const apiContentBlockExampleCode = `import { CommonModule } from '@angular/common'; |
53 |
| -import { Component } from '@angular/core'; |
54 |
| -import { |
55 |
| - BlockNoteEditor, |
56 |
| - BlockNoteSchema, |
57 |
| - defaultBlockSpecs, |
58 |
| - defaultInlineContentSpecs, |
59 |
| - defaultStyleSpecs, |
60 |
| - insertOrUpdateBlock, |
61 |
| - PartialBlock, |
62 |
| -} from '@blocknote/core'; |
63 |
| -import { |
64 |
| - BlockNoteEditorOptionsType, |
65 |
| - BnaEditorComponent, |
66 |
| -} from '@dytab/block-note-angular'; |
67 |
| -import { HlmButtonDirective } from '@dytab/block-note-angular'; |
68 |
| -import { apiContentBlock } from './api-content-block'; |
| 102 | + <hlm-dialog-header> |
| 103 | + <h3 brnDialogTitle hlm>Configure Block</h3> |
| 104 | + <p brnDialogDescription hlm>Toggle which content which should |
| 105 | + be rendered</p> |
69 | 106 |
|
70 |
| -const schema = BlockNoteSchema.create({ |
71 |
| - blockSpecs: { |
72 |
| - ...defaultBlockSpecs, |
73 |
| - alert: apiContentBlock, |
74 |
| - }, |
75 |
| - inlineContentSpecs: { ...defaultInlineContentSpecs }, |
76 |
| - styleSpecs: { ...defaultStyleSpecs }, |
77 |
| -}); |
78 |
| -@Component({ |
79 |
| - selector: 'bna-alert-block-example', |
80 |
| - standalone: true, |
81 |
| - imports: [CommonModule, BnaEditorComponent, HlmButtonDirective], |
82 |
| - template: \`<bna-editor |
83 |
| - [initialContent]="initialContent" |
84 |
| - [options]="options" |
85 |
| - />\`, |
| 107 | + <label class="flex items-center" hlmLabel> |
| 108 | + Name: |
| 109 | + <input hlmInput [size]="'sm'" formControlName="name" class="mr-2" /> |
| 110 | + </label> |
| 111 | + <label class="flex items-center" hlmLabel> |
| 112 | + <hlm-checkbox formControlName="age" class="mr-2" /> |
| 113 | + Age |
| 114 | + </label> |
| 115 | + <label class="flex items-center" hlmLabel> |
| 116 | + <hlm-checkbox formControlName="address" class="mr-2" /> |
| 117 | + Address |
| 118 | + </label> |
| 119 | + </hlm-dialog-header> |
| 120 | + <hlm-dialog-footer> |
| 121 | + <button hlmBtn type="submit" >Save changes |
| 122 | + </button> |
| 123 | + </hlm-dialog-footer> |
| 124 | + </form> |
| 125 | + </hlm-dialog-content> |
| 126 | + </hlm-dialog> |
| 127 | + </bna-drag-handle-menu-btn> |
| 128 | + </bna-side-menu |
| 129 | + > |
| 130 | + </bna-side-menu-controller> |
| 131 | + </bna-editor> |
| 132 | + ` |
86 | 133 | })
|
87 |
| -export class AlertBlockExample { |
| 134 | + |
| 135 | +export class ApiContentBlockExample{ |
| 136 | + @Input() block?: Block<any, any, any>; |
| 137 | + @Input() editor?: BlockNoteEditor<typeof schema.blockSchema>; |
| 138 | + |
| 139 | + formGroup = new FormGroup({ |
| 140 | + name: new FormControl(this.block?.props.name), |
| 141 | + age: new FormControl(this.block?.props.age), |
| 142 | + address: new FormControl(this.block?.props.address) |
| 143 | + }); |
| 144 | + |
88 | 145 | initialContent: PartialBlock<typeof schema.blockSchema>[] = [
|
89 | 146 | {
|
90 |
| - type: 'alert', |
| 147 | + type: 'apiContent', |
91 | 148 | props: {
|
92 |
| - type: 'warning', |
93 |
| - }, |
| 149 | + name: 'Max Mustermann', |
| 150 | + age: true |
| 151 | + } |
94 | 152 | },
|
| 153 | + { |
| 154 | + type: 'apiContent', |
| 155 | + } |
95 | 156 | ];
|
96 | 157 | options: BlockNoteEditorOptionsType<
|
97 | 158 | typeof schema.blockSchema,
|
98 | 159 | typeof schema.inlineContentSchema,
|
99 | 160 | typeof schema.styleSchema
|
100 | 161 | > = {
|
101 |
| - schema, |
102 |
| - inputSlashMenuItems: [ |
103 |
| - ( |
104 |
| - editor: BlockNoteEditor< |
105 |
| - typeof schema.blockSchema, |
106 |
| - typeof schema.inlineContentSchema, |
107 |
| - typeof schema.styleSchema |
108 |
| - > |
109 |
| - ) => ({ |
110 |
| - title: 'Alert', |
111 |
| - onItemClick: () => { |
112 |
| - insertOrUpdateBlock(editor, { |
113 |
| - type: 'alert' as never, |
114 |
| - }); |
115 |
| - }, |
116 |
| - badge: 'BAFD', |
117 |
| - subtext: 'SUBTEXT', |
118 |
| - aliases: [ |
119 |
| - 'alert', |
120 |
| - 'notification', |
121 |
| - 'emphasize', |
122 |
| - 'warning', |
123 |
| - 'error', |
124 |
| - 'info', |
125 |
| - 'success', |
126 |
| - ], |
127 |
| - group: 'Other', |
128 |
| - }), |
129 |
| - ], |
| 162 | + schema |
130 | 163 | };
|
131 |
| -}`; |
| 164 | + |
| 165 | + updateBlockConfiguration(){ |
| 166 | + if(!this.block || !this.editor) return |
| 167 | + |
| 168 | + const formValues = this.formGroup.value; |
| 169 | + this.editor.updateBlock(this.block, { |
| 170 | + props: { ...formValues } |
| 171 | + }) |
| 172 | + } |
| 173 | + |
| 174 | + onEditorReady(editor: BlockNoteEditor<typeof schema.blockSchema>){ |
| 175 | + this.editor = editor; |
| 176 | + this.editor.sideMenu.onUpdate((state) => { |
| 177 | + this.block = state.block; |
| 178 | + this.formGroup.patchValue(this.block?.props); |
| 179 | + }); |
| 180 | + } |
| 181 | +} |
| 182 | + |
| 183 | +export const apiContentBlockExampleCode = ``; |
0 commit comments