Skip to content

Commit

Permalink
fix: export InjectionToken editor configuration (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoviccarretti committed May 11, 2022
1 parent 8a423e7 commit c996665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion projects/ngx-editor/src/lib/Locals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const defaults: Record<string, string> = {
export const defaults: Record<string, string> = {
// menu
bold: 'Bold',
italic: 'Italic',
Expand Down
11 changes: 6 additions & 5 deletions projects/ngx-editor/src/lib/editor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgModule, ModuleWithProviders, InjectionToken } from '@angular/core';
import { CommonModule } from '@angular/common';

import { NgxEditorConfig } from './types';
import { defaults } from './Locals';

import { NgxEditorComponent } from './editor.component';
import { NgxEditorServiceConfig } from './editor-config.service';
Expand All @@ -12,7 +13,7 @@ import { MenuComponent } from './modules/menu/menu.component';
import { ImageViewComponent } from './components/image-view/image-view.component';
import { FloatingMenuComponent } from './modules/menu/floating-menu/floating-menu.component';

const NGX_EDITOR_CONFIG_TOKEN = new InjectionToken<NgxEditorConfig>('NgxEditorConfig');
export const NGX_EDITOR_CONFIG_TOKEN = new InjectionToken<NgxEditorConfig>('NgxEditorConfig');

@NgModule({
imports: [
Expand All @@ -32,13 +33,13 @@ const NGX_EDITOR_CONFIG_TOKEN = new InjectionToken<NgxEditorConfig>('NgxEditorCo
})

export class NgxEditorModule {
static forRoot(config: NgxEditorConfig): ModuleWithProviders<NgxEditorModule> {
static forRoot(config?: NgxEditorConfig): ModuleWithProviders<NgxEditorModule> {
return {
ngModule: NgxEditorModule,
providers: [
{
provide: NGX_EDITOR_CONFIG_TOKEN,
useValue: config,
useValue: config ?? { locals: defaults },
},
{
provide: NgxEditorServiceConfig,
Expand All @@ -49,13 +50,13 @@ export class NgxEditorModule {
};
}

static forChild(config: NgxEditorConfig): ModuleWithProviders<NgxEditorModule> {
static forChild(config?: NgxEditorConfig): ModuleWithProviders<NgxEditorModule> {
return {
ngModule: NgxEditorModule,
providers: [
{
provide: NGX_EDITOR_CONFIG_TOKEN,
useValue: config,
useValue: config ?? { locals: defaults },
},
{
provide: NgxEditorServiceConfig,
Expand Down

0 comments on commit c996665

Please sign in to comment.