-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use /state instead of deprecated /stores
- Loading branch information
1 parent
ad84dee
commit 950c5b4
Showing
26 changed files
with
242 additions
and
235 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
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
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,88 @@ | ||
/* eslint-disable @typescript-eslint/prefer-readonly */ | ||
import {page} from '$app/state'; | ||
|
||
export type Frameworks = 'angular' | 'react' | 'svelte'; | ||
export type ApiFrameworks = 'typescript' | Frameworks; | ||
export type PackageType = 'headless' | 'bootstrap'; | ||
|
||
const baseCanonicalURL = 'https://www.agnosui.dev/latest/'; | ||
const tabRegExp = /^\/docs\/\[framework\]\/(components|daisyUI)\/[^/]*\/([^/]*)/; | ||
|
||
export const routing = new (class Routing { | ||
// Return how deep the current route is compared to base | ||
#routeLevel = $derived( | ||
page.route.id ? page.route.id.split('/').length - 2 + Object.values(page.params).reduce((pV, cur) => pV + cur.split('/').length - 1, 0) : 0, | ||
); | ||
|
||
// Return the url relative path to root, ex './', '../' or '../..' | ||
#relativePathToRoot = $derived(this.#routeLevel ? '../'.repeat(this.#routeLevel) : './'); | ||
|
||
#pathToRoot = $derived(new URL(this.#relativePathToRoot, page.url.href).href); | ||
|
||
#canonicalURL = $derived(page.url.href.replace(new URL(this.#relativePathToRoot, page.url.href).href, baseCanonicalURL)); | ||
|
||
/** | ||
* Current selected framework | ||
*/ | ||
#previousFwk: Frameworks = 'angular'; | ||
#selectedFramework = $derived.by(() => { | ||
if (page.params.framework && page.params.framework !== 'typescript') { | ||
this.#previousFwk = page.params.framework as Frameworks; | ||
} | ||
return this.#previousFwk; | ||
}); | ||
|
||
/** | ||
* Current non-typescript selected framework | ||
*/ | ||
#previousApiFwk: ApiFrameworks = 'angular'; | ||
#selectedApiFramework = $derived.by(() => { | ||
if (page.params.framework) { | ||
this.#previousApiFwk = page.params.framework as Frameworks; | ||
} | ||
return this.#previousApiFwk; | ||
}); | ||
|
||
/** | ||
* Current package type | ||
*/ | ||
#selectedPackageType = $derived.by(() => { | ||
if (page.params.type) { | ||
return page.params.type as PackageType; | ||
} | ||
if (page.url.pathname.match(/\/daisyUI\//)) { | ||
return 'headless'; | ||
} | ||
if (page.url.pathname.match(/\/docs\/[^/]*\/components\//)) { | ||
return 'bootstrap'; | ||
} | ||
return undefined; | ||
}); | ||
|
||
/** | ||
* Current selected tab | ||
*/ | ||
#selectedTabName = $derived(tabRegExp.exec(page.route.id || '')?.[2]); | ||
|
||
get routeLevel() { | ||
return this.#routeLevel; | ||
} | ||
get pathToRoot() { | ||
return this.#pathToRoot; | ||
} | ||
get canonicalURL() { | ||
return this.#canonicalURL; | ||
} | ||
get selectedFramework() { | ||
return this.#selectedFramework; | ||
} | ||
get selectedApiFramework() { | ||
return this.#selectedApiFramework; | ||
} | ||
get selectedPackageType() { | ||
return this.#selectedPackageType; | ||
} | ||
get selectedTabName() { | ||
return this.#selectedTabName; | ||
} | ||
})(); |
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
Oops, something went wrong.