-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
9879d8f
commit b462265
Showing
3 changed files
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface RouteDetail { | ||
route: string | RegExp; | ||
location: string; | ||
querystring: string; | ||
userData?: {}; | ||
component?: {}; | ||
name?: string; | ||
} |
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,13 @@ | ||
interface ActiveOptions { | ||
path: string | RegExp; | ||
className: string; | ||
} | ||
|
||
/** | ||
* Svelte Action for automatically adding the "active" class to elements (links, or any other DOM element) when the current location matches a certain path. | ||
* | ||
* @param node - The target node (automatically set by Svelte) | ||
* @param opts - Can be an object of type ActiveOptions, or a string (or regular expressions) representing ActiveOptions.path. | ||
* @returns Destroy function | ||
*/ | ||
export declare function active(node: HTMLElement,opt?: ActiveOptions | string | RegExp): {destroy: () => void}; |
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,34 @@ | ||
import { SvelteComponent } from 'svelte' | ||
import { RouteDetail } from './Router' | ||
|
||
interface WrappedComponent { | ||
component: SvelteComponent; | ||
conditions?: RoutePrecondition[]; | ||
props?: {}; | ||
userData?: {}; | ||
_sveltesparouter: boolean; | ||
} | ||
|
||
type RoutePrecondition = (detail: any) => boolean | ||
|
||
interface WarpOptions { | ||
component?: SvelteComponent; | ||
asyncComponent?: () => Promise<SvelteComponent>; | ||
loadingComponent?: SvelteComponent; | ||
loadingParams?: SvelteComponent; | ||
userData?: {}; | ||
props?: {}; | ||
conditions?: ((detail: RouteDetail) => boolean)[] | ((detail: RouteDetail) => boolean); | ||
} | ||
/** | ||
* Wraps a component to enable multiple capabilities: | ||
* 1. Using dynamically-imported component, with (e.g. `{asyncComponent: () => import('Foo.svelte')}`), which also allows bundlers to do code-splitting. | ||
* 2. Adding route pre-conditions (e.g. `{conditions: [...]}`) | ||
* 3. Adding static props that are passed to the component | ||
* 4. Adding custom userData, which is passed to route events (e.g. route loaded events) or to route pre-conditions (e.g. `{userData: {foo: 'bar}}`) | ||
* | ||
* @param args - Arguments object | ||
* @returns Wrapped component | ||
*/ | ||
export declare function warp(args:WarpOptions):WrappedComponent; | ||
export default warp; |