Przeglądaj źródła

remove MonthView

Adam Shaw 7 lat temu
rodzic
commit
20cd18d1e9

+ 0 - 10
src/View.ts

@@ -432,16 +432,6 @@ export default abstract class View extends DateComponent<ViewProps> {
      // subclasses must implement
   }
 
-
-  /* Date Utils
-  ------------------------------------------------------------------------------------------------------------------*/
-
-
-  // For DateComponent::getDayClasses
-  isDateInOtherMonth(date: DateMarker, dateProfile) {
-    return false
-  }
-
 }
 
 EmitterMixin.mixInto(View)

+ 16 - 3
src/basic/AbstractBasicView.ts

@@ -219,10 +219,23 @@ export default abstract class BasicView extends View {
 
   // Sets the height of just the DayGrid component in this view
   setGridHeight(height, isAuto) {
-    if (isAuto) {
-      undistributeHeight(this.dayGrid.rowEls) // let the rows be their natural height with no expanding
+
+    if (this.opt('monthMode')) {
+
+      // if auto, make the height of each row the height that it would be if there were 6 weeks
+      if (isAuto) {
+        height *= this.dayGrid.rowCnt / 6
+      }
+
+      distributeHeight(this.dayGrid.rowEls, height, !isAuto) // if auto, don't compensate for height-hogging rows
+
     } else {
-      distributeHeight(this.dayGrid.rowEls, height, true) // true = compensate for height-hogging rows
+
+      if (isAuto) {
+        undistributeHeight(this.dayGrid.rowEls) // let the rows be their natural height with no expanding
+      } else {
+        distributeHeight(this.dayGrid.rowEls, height, true) // true = compensate for height-hogging rows
+      }
     }
   }
 

+ 12 - 1
src/basic/BasicViewDateProfileGenerator.ts

@@ -1,5 +1,5 @@
 import DateProfileGenerator from '../DateProfileGenerator'
-import { addWeeks } from '../datelib/marker'
+import { addWeeks, diffWeeks } from '../datelib/marker'
 import { DateRange } from '../datelib/date-range'
 
 
@@ -24,6 +24,17 @@ export default class BasicViewDateProfileGenerator extends DateProfileGenerator
       }
     }
 
+    // ensure 6 weeks
+    if (
+      this.options.monthMode &&
+      this.options.fixedWeekCount
+    ) {
+      let rowCnt = Math.ceil( // could be partial weeks due to hiddenDays
+        diffWeeks(start, end)
+      )
+      end = addWeeks(end, 6 - rowCnt)
+    }
+
     return { start, end }
   }
 

+ 0 - 32
src/basic/MonthView.ts

@@ -1,32 +0,0 @@
-import { distributeHeight } from '../util/misc'
-import BasicView from './BasicView'
-import MonthViewDateProfileGenerator from './MonthViewDateProfileGenerator'
-import { DateMarker } from '../datelib/marker'
-
-
-/* A month view with day cells running in rows (one-per-week) and columns
-----------------------------------------------------------------------------------------------------------------------*/
-
-export default class MonthView extends BasicView {
-
-  // Overrides the default BasicView behavior to have special multi-week auto-height logic
-  setGridHeight(height, isAuto) {
-
-    // if auto, make the height of each row the height that it would be if there were 6 weeks
-    if (isAuto) {
-      height *= this.dayTable.rowCnt / 6
-    }
-
-    distributeHeight(this.dayGrid.rowEls, height, !isAuto) // if auto, don't compensate for height-hogging rows
-  }
-
-
-  isDateInOtherMonth(date: DateMarker, dateProfile) {
-    let { dateEnv } = this
-
-    return dateEnv.getMonth(date) !== dateEnv.getMonth(dateProfile.currentRange.start)
-  }
-
-}
-
-MonthView.prototype.dateProfileGeneratorClass = MonthViewDateProfileGenerator

+ 0 - 25
src/basic/MonthViewDateProfileGenerator.ts

@@ -1,25 +0,0 @@
-import BasicViewDateProfileGenerator from './BasicViewDateProfileGenerator'
-import { addWeeks, diffWeeks } from '../datelib/marker'
-
-
-export default class MonthViewDateProfileGenerator extends BasicViewDateProfileGenerator {
-
-  // Computes the date range that will be rendered.
-  buildRenderRange(currentRange, currentRangeUnit, isRangeAllDay) {
-    let renderRange = super.buildRenderRange(currentRange, currentRangeUnit, isRangeAllDay)
-    let start = renderRange.start
-    let end = renderRange.end
-    let rowCnt
-
-    // ensure 6 weeks
-    if (this.options.fixedWeekCount) {
-      rowCnt = Math.ceil( // could be partial weeks due to hiddenDays
-        diffWeeks(start, end)
-      )
-      end = addWeeks(end, 6 - rowCnt)
-    }
-
-    return { start, end }
-  }
-
-}

+ 2 - 2
src/basic/config.ts

@@ -1,6 +1,5 @@
 import { defineView } from '../ViewRegistry'
 import BasicView from './BasicView'
-import MonthView from './MonthView'
 
 defineView('basic', BasicView)
 
@@ -15,7 +14,8 @@ defineView('basicWeek', {
 })
 
 defineView('month', {
-  'class': MonthView,
+  type: 'basic',
+  monthMode: true,
   duration: { months: 1 }, // important for prev/next
   fixedWeekCount: true
 })

+ 5 - 2
src/component/date-rendering.ts

@@ -60,7 +60,7 @@ export function getAllDayHtml(component: Component<any>) {
 
 // Computes HTML classNames for a single-day element
 export function getDayClasses(date: DateMarker, dateProfile: DateProfile, context: ComponentContext, noThemeHighlight?) {
-  let { calendar, view, theme } = context
+  let { calendar, view, theme, dateEnv } = context
   let classes = []
   let todayStart: DateMarker
   let todayEnd: DateMarker
@@ -70,7 +70,10 @@ export function getDayClasses(date: DateMarker, dateProfile: DateProfile, contex
   } else {
     classes.push('fc-' + DAY_IDS[date.getUTCDay()])
 
-    if (view.isDateInOtherMonth(date, dateProfile)) {
+    if (
+      view.opt('monthMode') &&
+      dateEnv.getMonth(date) !== dateEnv.getMonth(dateProfile.currentRange.start)
+    ) {
       classes.push('fc-other-month')
     }
 

+ 0 - 1
src/exports.ts

@@ -101,7 +101,6 @@ export { buildDayRanges, sliceSegs as sliceTimeGridSegs } from './agenda/SimpleT
 export { sliceSegs as sliceDayGridSegs } from './basic/SimpleDayGrid'
 export { default as DayGrid, DayGridSeg } from './basic/DayGrid'
 export { default as BasicView } from './basic/BasicView'
-export { default as MonthView } from './basic/MonthView'
 export { default as ListView } from './list/ListView'
 export { default as DateProfileGenerator, DateProfile } from './DateProfileGenerator'
 export { ViewSpec } from './structs/view-spec'