2
0
Эх сурвалжийг харах

simple plugin for isPropsValid

Adam Shaw 7 жил өмнө
parent
commit
651675d556

+ 1 - 1
src/exports.ts

@@ -161,4 +161,4 @@ export { default as DayTable, DayTableSeg, DayTableCell } from './common/DayTabl
 export { default as Slicer, SlicedProps } from './common/slicing-utils'
 
 export { EventMutation } from './structs/event-mutation'
-export { ConstraintInput, AllowFunc } from './validation'
+export { ConstraintInput, AllowFunc, isPropsValid } from './validation'

+ 9 - 3
src/plugin-system.ts

@@ -9,6 +9,7 @@ import { assignTo } from './util/object'
 import { ViewSpecTransformer, ViewSpec } from './structs/view-spec'
 import { ViewProps } from './View'
 import { CalendarComponentProps } from './CalendarComponent'
+import { isPropsValidTester } from './validation'
 
 // TODO: easier way to add new hooks? need to update a million things
 
@@ -24,6 +25,7 @@ export interface PluginDefInput {
   viewConfigs?: ViewConfigInputHash
   viewSpecTransformers?: ViewSpecTransformer[]
   viewPropsTransformers?: ViewPropsTransformerClass[]
+  isPropsValid?: isPropsValidTester
 }
 
 export interface PluginHooks {
@@ -37,6 +39,7 @@ export interface PluginHooks {
   viewConfigs: ViewConfigInputHash // TODO: parse before gets to this step?
   viewSpecTransformers: ViewSpecTransformer[]
   viewPropsTransformers: ViewPropsTransformerClass[]
+  isPropsValid: isPropsValidTester | null
 }
 
 export interface PluginDef extends PluginHooks {
@@ -66,7 +69,8 @@ export function createPlugin(input: PluginDefInput): PluginDef {
     dateSelectionApiTransformers: input.dateSelectionApiTransformers || [],
     viewConfigs: input.viewConfigs || {},
     viewSpecTransformers: input.viewSpecTransformers || [],
-    viewPropsTransformers: input.viewPropsTransformers || []
+    viewPropsTransformers: input.viewPropsTransformers || [],
+    isPropsValid: input.isPropsValid || null
   }
 }
 
@@ -86,7 +90,8 @@ export class PluginSystem {
       dateSelectionApiTransformers: [],
       viewConfigs: {},
       viewSpecTransformers: [],
-      viewPropsTransformers: []
+      viewPropsTransformers: [],
+      isPropsValid: null
     }
     this.addedHash = {}
   }
@@ -116,6 +121,7 @@ function combineHooks(hooks0: PluginHooks, hooks1: PluginHooks): PluginHooks {
     dateSelectionApiTransformers: hooks0.dateSelectionApiTransformers.concat(hooks1.dateSelectionApiTransformers),
     viewConfigs: assignTo({}, hooks0.viewConfigs, hooks1.viewConfigs),
     viewSpecTransformers: hooks0.viewSpecTransformers.concat(hooks1.viewSpecTransformers),
-    viewPropsTransformers: hooks0.viewPropsTransformers.concat(hooks1.viewPropsTransformers)
+    viewPropsTransformers: hooks0.viewPropsTransformers.concat(hooks1.viewPropsTransformers),
+    isPropsValid: hooks1.isPropsValid || hooks0.isPropsValid
   }
 }

+ 3 - 4
src/validation.ts

@@ -14,6 +14,7 @@ export type ConstraintInput = 'businessHours' | string | EventInput | EventInput
 export type Constraint = 'businessHours' | string | EventStore | false // false means won't pass at all
 export type OverlapFunc = ((stillEvent: EventApi, movingEvent: EventApi | null) => boolean)
 export type AllowFunc = (span: DateSpanApi, movingEvent: EventApi | null) => boolean
+export type isPropsValidTester = (props: SplittableProps, calendar: Calendar) => boolean
 
 
 // high-level segmenting-aware tester functions
@@ -40,12 +41,10 @@ function isNewPropsValid(newProps, calendar: Calendar) {
     eventResize: null
   }, newProps)
 
-  // TODO: hooks
-
-  return isPropsValid(props, calendar)
+  return (calendar.pluginSystem.hooks.isPropsValid || isPropsValid)(props, calendar)
 }
 
-export function isPropsValid(state: SplittableProps, calendar: Calendar, dateSpanMeta = {}) {
+export function isPropsValid(state: SplittableProps, calendar: Calendar, dateSpanMeta = {}): boolean {
 
   if (state.dateSelection && !isDateSelectionPropsValid(state, calendar, dateSpanMeta)) {
     return false