From 4899665181bd624b5ccbc3dbb22f77d980428213 Mon Sep 17 00:00:00 2001 From: tjtanjin Date: Sat, 14 Sep 2024 22:14:31 +0800 Subject: [PATCH] feat: Add support for transition attribute to accept number --- src/services/BlockService/TransitionProcessor.tsx | 7 ++++++- src/types/Block.ts | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/services/BlockService/TransitionProcessor.tsx b/src/services/BlockService/TransitionProcessor.tsx index 09c0099e..8d9dedeb 100644 --- a/src/services/BlockService/TransitionProcessor.tsx +++ b/src/services/BlockService/TransitionProcessor.tsx @@ -33,6 +33,11 @@ export const processTransition = async (flow: Flow, path: keyof Flow, params: Pa transitionDetails = transitionAttr; } + // if number provided, transform to object with default values + if (typeof transitionDetails === "number") { + transitionDetails = {duration: transitionDetails}; + } + // cannot transition if details are not present if (!transitionDetails || transitionDetails instanceof Promise) { return; @@ -44,7 +49,7 @@ export const processTransition = async (flow: Flow, path: keyof Flow, params: Pa } // defaults interruptable to false if not found - if (!transitionDetails.interruptable) { + if (transitionDetails.interruptable == null) { transitionDetails.interruptable = false; } diff --git a/src/types/Block.ts b/src/types/Block.ts index 46225163..614a2a3f 100644 --- a/src/types/Block.ts +++ b/src/types/Block.ts @@ -21,9 +21,9 @@ export type Block = { ((params: Params) => Promise); chatDisabled?: boolean | ((params: Params) => boolean) | ((params: Params) => Promise); isSensitive?: boolean | ((params: Params) => boolean) | ((params: Params) => Promise); - transition?: {duration: number, interruptable?: boolean} | void | - ((params: Params) => {duration: number, interruptable?: boolean} | void) | - ((params: Params) => Promise<{duration: number, interruptable?: boolean} | void>); + transition?: number | {duration: number, interruptable?: boolean} | void | + ((params: Params) => number | {duration: number, interruptable?: boolean} | void) | + ((params: Params) => Promise); // post-processing attributes (runs after user input) function?: ((params: Params) => void) | ((params: Params) => Promise);