From 62b0d20b974dc932769221d210b751627fb4bbc6 Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:09:49 +0200 Subject: [PATCH] Extends virtual module astro:transitions/client to export swapFunctions (#11708) * extend virtual module astro:transitions/client to exports swapFunctions * use virtual module in e2e tests * Update .changeset/new-monkeys-sit.md * Update .changeset/new-monkeys-sit.md Co-authored-by: Sarah Rainsberger * Update new-monkeys-sit.md * Update swap-functions.ts restoreFocus() bindings are now returned by saveFocus() and do not make sense anymore as a member of the swapFunctions object * take over suggestion Co-authored-by: Sarah Rainsberger * Update .changeset/new-monkeys-sit.md Co-authored-by: Sarah Rainsberger --------- Co-authored-by: Emanuele Stoppa Co-authored-by: Sarah Rainsberger --- .changeset/new-monkeys-sit.md | 32 +++++++++++++++++++ packages/astro/client.d.ts | 2 ++ .../src/pages/keep-style-one.astro | 12 +++---- .../src/pages/keep-theme-one.astro | 12 +++---- .../src/pages/replace-main-one.astro | 14 ++++---- packages/astro/e2e/view-transitions.test.js | 2 +- .../astro/src/transitions/swap-functions.ts | 8 +++++ .../transitions/vite-plugin-transitions.ts | 1 + .../transitions-swap-functions.ts | 1 + 9 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 .changeset/new-monkeys-sit.md create mode 100644 packages/astro/src/virtual-modules/transitions-swap-functions.ts diff --git a/.changeset/new-monkeys-sit.md b/.changeset/new-monkeys-sit.md new file mode 100644 index 000000000000..b147b593f4a1 --- /dev/null +++ b/.changeset/new-monkeys-sit.md @@ -0,0 +1,32 @@ +--- +'astro': minor +--- + +Adds a new object `swapFunctions` to expose the necessary utility functions on `astro:transitions/client` that allow you to build custom swap functions to be used with view transitions. + +The example below uses these functions to replace Astro's built-in default `swap` function with one that only swaps the `
` part of the page: + +```astro + diff --git a/packages/astro/e2e/fixtures/view-transitions/src/pages/keep-theme-one.astro b/packages/astro/e2e/fixtures/view-transitions/src/pages/keep-theme-one.astro index a4c942d587f2..18ae0221fc65 100644 --- a/packages/astro/e2e/fixtures/view-transitions/src/pages/keep-theme-one.astro +++ b/packages/astro/e2e/fixtures/view-transitions/src/pages/keep-theme-one.astro @@ -6,18 +6,18 @@ import Layout from '../components/Layout.astro'; go to next page