Skip to content

Commit

Permalink
feat: add individual month / week / day modules
Browse files Browse the repository at this point in the history
now you can just import what you need to help reduce bundle size
Closes #361
  • Loading branch information
Matt Lewis committed Oct 22, 2017
1 parent d3137e6 commit e87ae23
Show file tree
Hide file tree
Showing 41 changed files with 258 additions and 155 deletions.
60 changes: 60 additions & 0 deletions src/calendar.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { DraggableHelper } from 'angular-draggable-droppable';
import {
CalendarCommonModule,
CalendarModuleConfig,
CalendarEventTitleFormatter,
CalendarDateFormatter,
CalendarUtils
} from './common/calendar-common.module';
import { CalendarMonthModule } from './month/calendar-month.module';
import { CalendarWeekModule } from './week/calendar-week.module';
import { CalendarDayModule } from './day/calendar-day.module';

export * from './common/calendar-common.module';
export * from './month/calendar-month.module';
export * from './week/calendar-week.module';
export * from './day/calendar-day.module';

/**
* The main module of this library. Example usage:
*
* ```typescript
* import { CalenderModule } from 'angular-calendar';
*
* @NgModule({
* imports: [
* CalenderModule.forRoot()
* ]
* })
* class MyModule {}
* ```
*
*/
@NgModule({
imports: [
CalendarCommonModule,
CalendarMonthModule,
CalendarWeekModule,
CalendarDayModule
],
exports: [
CalendarCommonModule,
CalendarMonthModule,
CalendarWeekModule,
CalendarDayModule
]
})
export class CalendarModule {
static forRoot(config: CalendarModuleConfig = {}): ModuleWithProviders {
return {
ngModule: CalendarModule,
providers: [
DraggableHelper,
config.eventTitleFormatter || CalendarEventTitleFormatter,
config.dateFormatter || CalendarDateFormatter,
config.utils || CalendarUtils
]
};
}
}
80 changes: 80 additions & 0 deletions src/common/calendar-common.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { ModuleWithProviders, NgModule, Provider } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DraggableHelper } from 'angular-draggable-droppable';
import { CalendarEventActionsComponent } from './calendar-event-actions.component';
import { CalendarEventTitleComponent } from './calendar-event-title.component';
import {
CalendarTooltipDirective,
CalendarTooltipWindowComponent
} from './calendar-tooltip.directive';
import { CalendarPreviousViewDirective } from './calendar-previous-view.directive';
import { CalendarNextViewDirective } from './calendar-next-view.directive';
import { CalendarTodayDirective } from './calendar-today.directive';
import { CalendarDatePipe } from './calendar-date.pipe';
import { CalendarEventTitlePipe } from './calendar-event-title.pipe';
import { ClickDirective } from './click.directive';
import { CalendarEventTitleFormatter } from './calendar-event-title-formatter.provider';
import { CalendarDateFormatter } from './calendar-date-formatter.provider';
import { CalendarUtils } from './calendar-utils.provider';

export interface CalendarModuleConfig {
eventTitleFormatter?: Provider;
dateFormatter?: Provider;
utils?: Provider;
}

export * from './calendar-event-title-formatter.provider';
export * from './calendar-moment-date-formatter.provider';
export * from './calendar-native-date-formatter.provider';
export * from './calendar-date-formatter.provider';
export * from './calendar-utils.provider';
export * from './calendar-date-formatter.interface';
export * from './calendar-event-times-changed-event.interface';

export {
CalendarEvent,
EventAction as CalendarEventAction,
DAYS_OF_WEEK
} from 'calendar-utils';

@NgModule({
declarations: [
CalendarEventActionsComponent,
CalendarEventTitleComponent,
CalendarTooltipWindowComponent,
CalendarTooltipDirective,
CalendarPreviousViewDirective,
CalendarNextViewDirective,
CalendarTodayDirective,
CalendarDatePipe,
CalendarEventTitlePipe,
ClickDirective
],
imports: [CommonModule],
exports: [
CalendarEventActionsComponent,
CalendarEventTitleComponent,
CalendarTooltipWindowComponent,
CalendarTooltipDirective,
CalendarPreviousViewDirective,
CalendarNextViewDirective,
CalendarTodayDirective,
CalendarDatePipe,
CalendarEventTitlePipe,
ClickDirective
],
entryComponents: [CalendarTooltipWindowComponent]
})
export class CalendarCommonModule {
static forRoot(config: CalendarModuleConfig = {}): ModuleWithProviders {
return {
ngModule: CalendarCommonModule,
providers: [
DraggableHelper,
config.eventTitleFormatter || CalendarEventTitleFormatter,
config.dateFormatter || CalendarDateFormatter,
config.utils || CalendarUtils
]
};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Pipe, PipeTransform, LOCALE_ID, Inject } from '@angular/core';
import { CalendarDateFormatter } from '../providers/calendar-date-formatter.provider';
import { CalendarDateFormatter } from './calendar-date-formatter.provider';

/**
* This pipe is primarily for rendering the current view title. Example usage:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Pipe, PipeTransform } from '@angular/core';
import { CalendarEvent } from 'calendar-utils';
import { CalendarEventTitleFormatter } from '../providers/calendar-event-title-formatter.provider';
import { CalendarEventTitleFormatter } from './calendar-event-title-formatter.provider';

@Pipe({
name: 'calendarEventTitle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InjectionToken, Inject } from '@angular/core';
import {
CalendarDateFormatterInterface,
DateFormatterParams
} from '../interfaces/calendar-date-formatter.interface';
} from './calendar-date-formatter.interface';

export const MOMENT: InjectionToken<string> = new InjectionToken('Moment');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CalendarDateFormatterInterface,
DateFormatterParams
} from './../interfaces/calendar-date-formatter.interface';
} from './calendar-date-formatter.interface';
import getISOWeek from 'date-fns/get_iso_week';

/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './calendar-common.module';
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { Subject } from 'rxjs/Subject';
import { Subscription } from 'rxjs/Subscription';
import { ResizeEvent } from 'angular-resizable-element';
import addMinutes from 'date-fns/add_minutes';
import { CalendarDragHelper } from '../../providers/calendar-drag-helper.provider';
import { CalendarResizeHelper } from '../../providers/calendar-resize-helper.provider';
import { CalendarEventTimesChangedEvent } from '../../interfaces/calendar-event-times-changed-event.interface';
import { CalendarUtils } from '../../providers/calendar-utils.provider';
import { validateEvents } from '../../providers/util';
import { CalendarDragHelper } from '../common/calendar-drag-helper.provider';
import { CalendarResizeHelper } from '../common/calendar-resize-helper.provider';
import { CalendarEventTimesChangedEvent } from '../common/calendar-event-times-changed-event.interface';
import { CalendarUtils } from '../common/calendar-utils.provider';
import { validateEvents } from '../common/util';

/**
* @hidden
Expand Down
33 changes: 33 additions & 0 deletions src/day/calendar-day.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ResizableModule } from 'angular-resizable-element';
import { DragAndDropModule } from 'angular-draggable-droppable';
import { CalendarDayViewComponent } from './calendar-day-view.component';
import { CalendarAllDayEventComponent } from './calendar-all-day-event.component';
import { CalendarDayViewHourSegmentComponent } from './calendar-day-view-hour-segment.component';
import { CalendarDayViewEventComponent } from './calendar-day-view-event.component';
import { CalendarCommonModule } from '../common/calendar-common.module';

export { CalendarDayViewComponent } from './calendar-day-view.component';

@NgModule({
imports: [
CommonModule,
ResizableModule,
DragAndDropModule,
CalendarCommonModule
],
declarations: [
CalendarDayViewComponent,
CalendarAllDayEventComponent,
CalendarDayViewHourSegmentComponent,
CalendarDayViewEventComponent
],
exports: [
CalendarDayViewComponent,
CalendarAllDayEventComponent,
CalendarDayViewHourSegmentComponent,
CalendarDayViewEventComponent
]
})
export class CalendarDayModule {}
1 change: 1 addition & 0 deletions src/day/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './calendar-day.module';
21 changes: 1 addition & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
export * from './providers/calendar-event-title-formatter.provider';
export * from './providers/calendar-moment-date-formatter.provider';
export * from './providers/calendar-native-date-formatter.provider';
export * from './providers/calendar-date-formatter.provider';
export * from './providers/calendar-utils.provider';
export * from './interfaces/calendar-date-formatter.interface';
export * from './interfaces/calendar-event-times-changed-event.interface';
export * from './modules/calendar';
export * from './components/day/calendar-day-view.component';
export * from './components/month/calendar-month-view.component';
export * from './components/week/calendar-week-view.component';
export {
CalendarEvent,
EventAction as CalendarEventAction,
MonthViewDay as CalendarMonthViewDay,
WeekViewEvent as CalendarWeekViewEvent,
WeekViewEventRow as CalendarWeekViewEventRow,
GetWeekViewArgs as CalendarGetWeekViewArgs,
DAYS_OF_WEEK
} from 'calendar-utils';
export * from './calendar.module';
118 changes: 0 additions & 118 deletions src/modules/calendar.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import getMonth from 'date-fns/get_month';
import getYear from 'date-fns/get_year';
import differenceInSeconds from 'date-fns/difference_in_seconds';
import addSeconds from 'date-fns/add_seconds';
import { CalendarEventTimesChangedEvent } from '../../interfaces/calendar-event-times-changed-event.interface';
import { CalendarUtils } from '../../providers/calendar-utils.provider';
import { validateEvents } from '../../providers/util';
import { CalendarEventTimesChangedEvent } from '../common/calendar-event-times-changed-event.interface';
import { CalendarUtils } from '../common/calendar-utils.provider';
import { validateEvents } from '../common/util';

/**
* Shows all events on a given month. Example usage:
Expand Down
Loading

0 comments on commit e87ae23

Please sign in to comment.