-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33216a4
commit 3604216
Showing
16 changed files
with
369 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
eslint: { ignoreDuringBuilds: true }, | ||
reactStrictMode: false, | ||
}; | ||
|
||
module.exports = nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { endFlow, startFlow } from "./public-methods"; | ||
import { FlowsContext } from "./flows-context"; | ||
import { locationMatch } from "./form"; | ||
|
||
let prevPathname: string | null = null; | ||
export const handleDocumentChange = (): void => { | ||
const pathname = window.location.pathname + window.location.search; | ||
const locationChanged = prevPathname !== pathname; | ||
if (locationChanged) { | ||
FlowsContext.getInstance().onLocationChange?.(pathname, FlowsContext.getInstance()); | ||
|
||
FlowsContext.getInstance().instances.forEach((state) => { | ||
const step = state.currentStep; | ||
if (!step) return; | ||
if ("element" in step) { | ||
const el = document.querySelector(step.element); | ||
if (!el) endFlow(state.flowId, { variant: "cancel" }); | ||
} | ||
if (step.wait) { | ||
if (Array.isArray(step.wait)) { | ||
const matchingWait = step.wait.find((wait) => { | ||
if (wait.location) return locationMatch({ location: wait.location, pathname }); | ||
return false; | ||
}); | ||
if (matchingWait) state.nextStep(matchingWait.action).render(); | ||
} else if ( | ||
step.wait.location && | ||
locationMatch({ location: step.wait.location, pathname }) | ||
) { | ||
state.nextStep().render(); | ||
} | ||
} | ||
}); | ||
|
||
Object.values(FlowsContext.getInstance().flowsById ?? {}).forEach((flow) => { | ||
if (!flow.location) return; | ||
if (locationMatch({ location: flow.location, pathname })) startFlow(flow.id); | ||
}); | ||
} | ||
prevPathname = pathname; | ||
|
||
FlowsContext.getInstance().instances.forEach((state) => { | ||
if (state.waitingForElement) state.render(); | ||
|
||
const step = state.currentStep; | ||
if (step && "element" in step) { | ||
const el = document.querySelector(step.element); | ||
const targetChanged = state.flowElement?.target && el !== state.flowElement.target; | ||
if (targetChanged) state.render(); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- any is correct here | ||
export function ready(fn: (...args: any[]) => any): void { | ||
if (document.readyState !== "loading") { | ||
fn(); | ||
return; | ||
} | ||
document.addEventListener("DOMContentLoaded", fn); | ||
} |
Oops, something went wrong.