Adam Shaw 7 роки тому
батько
коміт
a3342bc4d9
3 змінених файлів з 21 додано та 17 видалено
  1. 1 1
      src/component/DateComponent.ts
  2. 17 13
      src/interactions/DateSelecting.ts
  3. 3 3
      src/validation.ts

+ 1 - 1
src/component/DateComponent.ts

@@ -44,7 +44,7 @@ export default class DateComponent<PropsType> extends Component<PropsType> {
   useEventCenter: boolean // for dragging geometry
   fgSegSelector: string // lets eventRender produce elements without fc-event class
   bgSegSelector: string
-  // IN SCHEDULER: allowEventResizeAcrossResources
+  // IN SCHEDULER: allowAcrossResources
 
   // if defined, holds the unit identified (ex: "year" or "month") that determines the level of granularity
   // of the date areas. if not defined, assumes to be day and time granularity.

+ 17 - 13
src/interactions/DateSelecting.ts

@@ -57,9 +57,9 @@ export default class DateSelecting {
     let isInvalid = false
 
     if (hit) {
-      dragSelection = joinSpansIntoSelection(
-        this.hitDragging.initialHit!.dateSpan,
-        hit.dateSpan,
+      dragSelection = joinHitsIntoSelection(
+        this.hitDragging.initialHit!,
+        hit,
         calendar.pluginSystem.hooks.dateSelectionTransformers
       )
 
@@ -108,7 +108,9 @@ function getComponentTouchDelay(component: DateComponent<any>): number {
   return delay
 }
 
-function joinSpansIntoSelection(dateSpan0: DateSpan, dateSpan1: DateSpan, dateSelectionTransformers: dateSelectionJoinTransformer[]): DateSpan {
+function joinHitsIntoSelection(hit0: Hit, hit1: Hit, dateSelectionTransformers: dateSelectionJoinTransformer[]): DateSpan {
+  let dateSpan0 = hit0.dateSpan
+  let dateSpan1 = hit1.dateSpan
   let ms = [
     dateSpan0.range.start,
     dateSpan0.range.end,
@@ -118,20 +120,22 @@ function joinSpansIntoSelection(dateSpan0: DateSpan, dateSpan1: DateSpan, dateSe
 
   ms.sort(compareNumbers)
 
-  let finalDateSpan: DateSpan = {
-    range: { start: ms[0], end: ms[3] },
-    allDay: dateSpan0.allDay
-  }
+  let props = {} as DateSpan
 
   for (let transformer of dateSelectionTransformers) {
-    if (
-      !transformer(finalDateSpan, dateSpan0, dateSpan1)
-    ) {
+    let res = transformer(hit0, hit1)
+
+    if (res === false) {
       return null
+    } else if (res) {
+      Object.assign(props, res)
     }
   }
 
-  return finalDateSpan
+  props.range = { start: ms[0], end: ms[3] }
+  props.allDay = dateSpan0.allDay
+
+  return props
 }
 
-export type dateSelectionJoinTransformer = (finalDateSpan: DateSpan, dateSpan0: DateSpan, dateSpan1: DateSpan) => boolean
+export type dateSelectionJoinTransformer = (hit0: Hit, hit1: Hit) => any

+ 3 - 3
src/validation.ts

@@ -1,6 +1,6 @@
 import { EventStore, expandRecurring, filterEventStoreDefs, parseEvents, createEmptyEventStore } from './structs/event-store'
 import Calendar from './Calendar'
-import { DateSpan, buildDateSpanApi, DateSpanApi } from './structs/date-span'
+import { DateSpan, DateSpanApi } from './structs/date-span'
 import { rangeContainsRange, rangesIntersect, DateRange, OpenDateRange } from './datelib/date-range'
 import EventApi from './api/EventApi'
 import { compileEventUis } from './component/event-rendering'
@@ -137,7 +137,7 @@ function isInteractionPropsValid(state: SplittableProps, calendar: Calendar, dat
       )
 
       if (!subjectAllow(
-        buildDateSpanApi(subjectDateSpan, calendar.dateEnv),
+        calendar.buildDateSpanApi(subjectDateSpan),
         new EventApi(calendar, origDef, origInstance)
       )) {
         return false
@@ -200,7 +200,7 @@ function isDateSelectionPropsValid(state: SplittableProps, calendar: Calendar, d
     let fullDateSpan = Object.assign({}, dateSpanMeta, selection)
 
     if (!selectionAllow(
-      buildDateSpanApi(fullDateSpan, calendar.dateEnv),
+      calendar.buildDateSpanApi(fullDateSpan),
       null
     )) {
       return false