Adam Shaw vor 7 Jahren
Ursprung
Commit
c235218f5d
3 geänderte Dateien mit 27 neuen und 13 gelöschten Zeilen
  1. 6 10
      src/common/browser-context.ts
  2. 18 0
      src/structs/date-span.ts
  3. 3 3
      src/validation.ts

+ 6 - 10
src/common/browser-context.ts

@@ -6,7 +6,7 @@ import EventClicking from '../interactions/EventClicking'
 import EventHovering from '../interactions/EventHovering'
 import EventDragging from '../interactions/EventDragging'
 import EventResizing from '../interactions/EventResizing'
-import { DateSpan } from '../structs/date-span'
+import { DateSpan, buildDateSpanApi } from '../structs/date-span'
 import Calendar from '../Calendar'
 
 export class BrowserContext {
@@ -119,15 +119,11 @@ export class BrowserContext {
 
     this.dateSelectedCalendar = calendar // in case publicTrigger wants to unselect
 
-    calendar.publiclyTrigger('select', [
-      {
-        start: calendar.dateEnv.toDate(selection.range.start),
-        end: calendar.dateEnv.toDate(selection.range.end),
-        isAllDay: selection.isAllDay,
-        jsEvent: pev ? pev.origEvent : null,
-        view: calendar.view
-      }
-    ])
+    let arg = buildDateSpanApi(selection, calendar.dateEnv)
+    arg.jsEvent = pev ? pev.origEvent : null
+    arg.view = calendar.view
+
+    calendar.publiclyTrigger('select', [ arg ])
   }
 
   unselectEvent() {

+ 18 - 0
src/structs/date-span.ts

@@ -2,6 +2,7 @@ import { DateRange, rangesEqual, OpenDateRange } from '../datelib/date-range'
 import { DateInput, DateEnv } from '../datelib/env'
 import { refineProps } from '../util/misc'
 import { Duration } from '../datelib/duration'
+import { assignTo } from '../util/object'
 
 /*
 A data-structure for a date-range that will be visually displayed.
@@ -32,6 +33,13 @@ export interface DateSpan extends OpenDateSpan {
   range: DateRange
 }
 
+export interface DateSpanApi {
+  start: Date
+  end: Date
+  isAllDay: boolean
+  [otherProp: string]: any
+}
+
 const STANDARD_PROPS = {
   start: null,
   end: null,
@@ -121,3 +129,13 @@ export function isSpanPropsMatching(subjectSpan: DateSpan, matchSpan: DateSpan):
 
   return true
 }
+
+export function buildDateSpanApi(span: DateSpan, dateEnv: DateEnv): DateSpanApi {
+  let props = assignTo({}, span)
+  delete props.range
+
+  props.start = dateEnv.toDate(span.range.start)
+  props.end = dateEnv.toDate(span.range.end)
+
+  return props
+}

+ 3 - 3
src/validation.ts

@@ -1,6 +1,6 @@
 import { EventStore, expandRecurring, eventTupleToStore, mapEventInstances, filterEventStoreDefs, isEventDefsRelated } from './structs/event-store'
 import Calendar from './Calendar'
-import { DateSpan, parseOpenDateSpan, OpenDateSpanInput, OpenDateSpan, isSpanPropsEqual, isSpanPropsMatching } from './structs/date-span'
+import { DateSpan, parseOpenDateSpan, OpenDateSpanInput, OpenDateSpan, isSpanPropsEqual, isSpanPropsMatching, buildDateSpanApi, DateSpanApi } from './structs/date-span'
 import { EventInstance, EventDef, EventTuple, parseEvent } from './structs/event'
 import { EventSourceHash } from './structs/event-source'
 import { rangeContainsRange, rangesIntersect } from './datelib/date-range'
@@ -10,7 +10,7 @@ import EventApi from './api/EventApi'
 export type ConstraintInput = 'businessHours' | string | OpenDateSpanInput | { [timeOrRecurringProp: string]: any }
 export type Constraint = 'businessHours' | string | OpenDateSpan | EventTuple
 export type Overlap = boolean | ((stillEvent: EventApi, movingEvent: EventApi | null) => boolean)
-export type Allow = (span: DateSpan, movingEvent: EventApi | null) => boolean
+export type Allow = (span: DateSpanApi, movingEvent: EventApi | null) => boolean
 
 interface ValidationEntity {
   dateSpan: DateSpan
@@ -186,7 +186,7 @@ function isDateSpanAllowed(dateSpan: DateSpan, moving: EventTuple | null, allow:
   if (typeof allow === 'function') {
     return Boolean(
       allow(
-        dateSpan,
+        buildDateSpanApi(dateSpan, calendar.dateEnv),
         moving ? new EventApi(calendar, moving.def, moving.instance) : null
       )
     )