-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for custom plugins
- Loading branch information
Showing
30 changed files
with
312 additions
and
213 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { NgModule, ModuleWithProviders, InjectionToken } from '@angular/core'; | ||
|
||
import { NgxEditorComponent } from './ngx-editor.component'; | ||
|
||
import { NgxEditorServiceConfig, provideMyServiceOptions } from './ngx-editor.service'; | ||
import { NgxEditorConfig } from './types'; | ||
|
||
const NGX_EDITOR_CONFIG_TOKEN = new InjectionToken<NgxEditorConfig>('NgxEditorConfig'); | ||
|
||
@NgModule({ | ||
declarations: [NgxEditorComponent], | ||
exports: [NgxEditorComponent], | ||
}) | ||
|
||
export class NgxEditorModule { } | ||
export class NgxEditorModule { | ||
static forRoot(config: NgxEditorConfig): ModuleWithProviders { | ||
|
||
return { | ||
ngModule: NgxEditorModule, | ||
providers: [ | ||
{ | ||
provide: NGX_EDITOR_CONFIG_TOKEN, | ||
useValue: config | ||
}, | ||
{ | ||
provide: NgxEditorServiceConfig, | ||
useFactory: provideMyServiceOptions, | ||
deps: [NGX_EDITOR_CONFIG_TOKEN] | ||
} | ||
] | ||
}; | ||
} | ||
} |
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,31 @@ | ||
import { Injectable, Optional } from '@angular/core'; | ||
|
||
import { NgxEditorConfig } from './types'; | ||
|
||
import menu from './prosemirror/plugins/menu'; | ||
import placeholder from './prosemirror/plugins/placeholder'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class NgxEditorServiceConfig { | ||
public plugins = [ | ||
menu(), | ||
placeholder() | ||
]; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class NgxEditorService { | ||
config: NgxEditorServiceConfig; | ||
|
||
constructor(@Optional() config?: NgxEditorServiceConfig) { | ||
this.config = config; | ||
} | ||
} | ||
|
||
export function provideMyServiceOptions(config?: NgxEditorConfig): NgxEditorConfig { | ||
return (config); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
export * from './toggleBlockType'; | ||
export * from './toggleList'; |
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
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,2 @@ | ||
export * from './isMarkActive'; | ||
export * from './isNodeActive'; |
2 changes: 1 addition & 1 deletion
2
src/lib/pm-tools/helpers/isMarkActive.ts → src/lib/prosemirror/helpers/isMarkActive.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as placeholder } from './placeholder'; | ||
export { default as menu } from './menu'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { EditorView } from 'prosemirror-view'; | ||
import { Plugin, PluginKey } from 'prosemirror-state'; | ||
|
||
import { Toolbar, MenuLabels, MenuOptions } from '../../../types'; | ||
import MenuBarView from './MenuBarView'; | ||
|
||
const DEFAULT_TOOLBAR: Toolbar = [ | ||
['bold', 'italic'], | ||
['code'], | ||
['ordered_list', 'bullet_list'], | ||
[{ heading: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] }] | ||
]; | ||
|
||
const DEFAULT_LABELS: MenuLabels = { | ||
bold: 'Bold', | ||
italics: 'Italics', | ||
code: 'Code', | ||
ordered_list: 'Ordered List', | ||
bullet_list: 'Bullet List', | ||
heading: 'Heading' | ||
}; | ||
|
||
const DEFAULT_OPTIONS: MenuOptions = { | ||
toolbar: DEFAULT_TOOLBAR, | ||
labels: DEFAULT_LABELS | ||
}; | ||
|
||
function menuPlugin(options: MenuOptions): Plugin { | ||
return new Plugin({ | ||
key: new PluginKey('menu'), | ||
view(editorView: EditorView): MenuBarView { | ||
return new MenuBarView(editorView, options); | ||
}, | ||
}); | ||
} | ||
|
||
const menu = (options: MenuOptions = DEFAULT_OPTIONS) => { | ||
return menuPlugin(options); | ||
}; | ||
|
||
export default menu; |
Oops, something went wrong.