diff --git a/composer.json b/composer.json index a77c864bf5a..6c40d67301c 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "paypal/paypal-checkout-sdk": "*", "sentry/sentry-laravel": "*", "symfony/yaml": "*", - "tightenco/ziggy": ">=0.8.1", + "tightenco/ziggy": "^1.8", "xsolla/xsolla-sdk-php": "dev-php81" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 6efcaae73f1..f87cac34e7c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c748b63fdc90f32f3850b615cb80eb80", + "content-hash": "0f9e7b546f1c77a54bd518d7918c1e4d", "packages": [ { "name": "anhskohbo/no-captcha", @@ -10779,16 +10779,16 @@ }, { "name": "tightenco/ziggy", - "version": "v1.6.0", + "version": "v1.8.1", "source": { "type": "git", "url": "https://github.com/tighten/ziggy.git", - "reference": "3beb080be60b1eadad043f3773a160df13fa215f" + "reference": "22dafc51f3f5ae5ed51f7cb6b566e6b9537f6937" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tighten/ziggy/zipball/3beb080be60b1eadad043f3773a160df13fa215f", - "reference": "3beb080be60b1eadad043f3773a160df13fa215f", + "url": "https://api.github.com/repos/tighten/ziggy/zipball/22dafc51f3f5ae5ed51f7cb6b566e6b9537f6937", + "reference": "22dafc51f3f5ae5ed51f7cb6b566e6b9537f6937", "shasum": "" }, "require": { @@ -10840,9 +10840,9 @@ ], "support": { "issues": "https://github.com/tighten/ziggy/issues", - "source": "https://github.com/tighten/ziggy/tree/v1.6.0" + "source": "https://github.com/tighten/ziggy/tree/v1.8.1" }, - "time": "2023-05-12T20:08:56+00:00" + "time": "2023-10-12T18:31:26+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", diff --git a/package.json b/package.json index 3f8c495efd1..4a583dc71b9 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,8 @@ "webpack-cli": "^5.1.4", "webpack-manifest-plugin": "^5.0.0", "webpack-sentry-plugin": "^2.0.2", - "yargs": "^12.0.5" + "yargs": "^12.0.5", + "ziggy-js": "^1.8.1" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^6.6.0", diff --git a/resources/js/beatmap-discussions/post.tsx b/resources/js/beatmap-discussions/post.tsx index 16e3ea1fd19..0ea3e1168fe 100644 --- a/resources/js/beatmap-discussions/post.tsx +++ b/resources/js/beatmap-discussions/post.tsx @@ -173,8 +173,8 @@ export default class Post extends React.Component { private deleteHref(op: 'destroy' | 'restore') { const [controller, key] = this.props.type === 'reply' - ? ['beatmapsets.discussions.posts', 'post'] - : ['beatmapsets.discussions', 'discussion']; + ? ['beatmapsets.discussions.posts', 'post'] as const + : ['beatmapsets.discussions', 'discussion'] as const; return route(`${controller}.${op}`, { [key]: this.deleteModel.id }); } diff --git a/resources/js/components/quick-search-button.tsx b/resources/js/components/quick-search-button.tsx index f66216d1189..89f069cb85d 100644 --- a/resources/js/components/quick-search-button.tsx +++ b/resources/js/components/quick-search-button.tsx @@ -20,7 +20,7 @@ interface State { @observer export default class QuickSearchButton extends React.Component { formRef = React.createRef(); - searchPath = route('search', null, false); + searchPath = route('search', undefined, false); state: State = { open: false }; private get isSearchPage() { @@ -36,7 +36,7 @@ interface State { render() { let className = 'nav2__menu-link-main nav2__menu-link-main--search'; - if (this.state.open || currentUrl().pathname === route('search', null, false)) { + if (this.state.open || currentUrl().pathname === route('search', undefined, false)) { className += ' u-section--bg-normal'; } diff --git a/resources/js/laroute.ts b/resources/js/laroute.ts index 7f7f150aa9d..2a7de45e4cb 100644 --- a/resources/js/laroute.ts +++ b/resources/js/laroute.ts @@ -3,13 +3,16 @@ import { currentUrl } from 'utils/turbolinks'; import { Ziggy } from 'ziggy'; -import ziggyRoute from 'ziggy-route'; +import ziggyRoute, { RouteList } from 'ziggy-js'; // ensure correct url const siteUrl = currentUrl(); Ziggy.port = +siteUrl.port || null; // either port number or null if empty (converted to 0) Ziggy.url = siteUrl.origin; -export function route(name: string, params?: Partial> | null, absolute?: boolean) { - return ziggyRoute(name, params ?? {}, absolute, Ziggy).toString(); +type RouteName = keyof RouteList; +type Params = Parameters>[1]; + +export function route(name: T, params?: Params, absolute?: boolean) { + return ziggyRoute(name, params, absolute, Ziggy); } diff --git a/resources/js/profile-page/cover.tsx b/resources/js/profile-page/cover.tsx index b608920468b..961428140e3 100644 --- a/resources/js/profile-page/cover.tsx +++ b/resources/js/profile-page/cover.tsx @@ -18,7 +18,7 @@ import { trans } from 'utils/lang'; interface Props { coverUrl: string | null; - currentMode: GameMode | null; + currentMode: GameMode; editor?: JSX.Element; isUpdatingCover?: boolean; modifiers?: Modifiers; diff --git a/resources/js/utils/offset-paginator.ts b/resources/js/utils/offset-paginator.ts index 94add2f40eb..ba340c1eca7 100644 --- a/resources/js/utils/offset-paginator.ts +++ b/resources/js/utils/offset-paginator.ts @@ -4,6 +4,7 @@ import KudosuHistoryJson from 'interfaces/kudosu-history-json'; import { route } from 'laroute'; import { action } from 'mobx'; +import { RouteList } from 'ziggy-js'; type RouteParams = Partial>; @@ -17,7 +18,7 @@ export interface OffsetPaginatorJson { pagination: OffsetPaginationJson; } -export const apiShowMore = action((json: OffsetPaginatorJson, routeName: string, baseRouteParams: RouteParams): JQuery.jqXHR => { +export const apiShowMore = action((json: OffsetPaginatorJson, routeName: keyof RouteList, baseRouteParams: RouteParams): JQuery.jqXHR => { json.pagination.loading = true; let limit = baseRouteParams.limit; diff --git a/resources/js/ziggy.d.ts b/resources/js/ziggy.d.ts index 7d9d01f2f49..02b3a20b336 100644 --- a/resources/js/ziggy.d.ts +++ b/resources/js/ziggy.d.ts @@ -2,14 +2,7 @@ // See the LICENCE file in the repository root for full licence text. declare module 'ziggy' { - interface ZiggyClass { - port: number | null; - url: string; - } + import route, { RouteList } from 'ziggy-js'; - export const Ziggy: ZiggyClass; -} - -declare module 'ziggy-route' { - export default function route(name: string, params: any, absolute?: boolean, ziggy?: import('ziggy').ZiggyClass): string; + export const Ziggy: NonNullable>[3]>; } diff --git a/tests/karma/tsconfig.json b/tests/karma/tsconfig.json index a12fa1ee6f1..7a9bc984700 100644 --- a/tests/karma/tsconfig.json +++ b/tests/karma/tsconfig.json @@ -15,6 +15,7 @@ }, "include": [ "../../resources/js", + "../../resources/builds/ziggy.d.ts", ".", ] } diff --git a/tsconfig.json b/tsconfig.json index cd4828c3fe9..30a6635ec83 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,7 @@ "useDefineForClassFields": true }, "include": [ - "resources/js" + "resources/js", + "resources/builds/ziggy.d.ts" ] } diff --git a/webpack.config.js b/webpack.config.js index 29e5143e004..fa24df0300a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -218,7 +218,6 @@ const resolve = { alias: { '@fonts': path.resolve(__dirname, 'resources/fonts'), '@images': path.resolve(__dirname, 'public/images'), - 'ziggy-route': resolvePath('vendor/tightenco/ziggy/dist/index.es.js'), }, extensions: ['*', '.js', '.coffee', '.ts', '.tsx'], modules: [ @@ -294,7 +293,7 @@ const watches = [ { callback: () => spawnSync( 'php', - ['artisan', 'ziggy:generate', 'resources/builds/ziggy.js'], + ['artisan', 'ziggy:generate', 'resources/builds/ziggy.js', '--types'], { stdio: 'inherit' }, ), path: resolvePath('routes/web.php'), diff --git a/yarn.lock b/yarn.lock index 42db78bcc0a..ef0043891bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6483,6 +6483,11 @@ qs@~6.5.2: resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.3.tgz#3aeeffc91967ef6e35c0e488ef46fb296ab76aad" integrity sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA== +qs@~6.9.7: + version "6.9.7" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.7.tgz#4610846871485e1e048f44ae3b94033f0e675afe" + integrity sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw== + "qtip2@https://github.com/notbakaneko/qTip2.git#cd5f038667d2b23a44f4274c46de01834d704ce6": version "3.0.3-jquery3" resolved "https://github.com/notbakaneko/qTip2.git#cd5f038667d2b23a44f4274c46de01834d704ce6" @@ -8245,6 +8250,13 @@ yargs@^16.1.1: y18n "^5.0.5" yargs-parser "^20.2.2" +ziggy-js@^1.8.1: + version "1.8.1" + resolved "https://registry.yarnpkg.com/ziggy-js/-/ziggy-js-1.8.1.tgz#582f4c19424cec0f8b80de2d033d70f953314a94" + integrity sha512-fnf30uG0yvUQBPL4T8YPgmkBHUdjYaOFgUb1K1gj0+rclnLTNr9/K/cxC3xkCZyYCZz8oTnXkdf3oJXRPSzavw== + dependencies: + qs "~6.9.7" + zwitch@^1.0.0: version "1.0.5" resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920"