From 8b6cf5586f6f0194135a3c31a095a5c4c547d48f Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Fri, 10 Apr 2026 00:49:01 +1000 Subject: [PATCH] refactor(google-maps)!: OverlayView class extraction and reactive position rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Internal restructure of with one behaviour-visible side effect (DOM structure change). Highlights: - Reactive position. Position updates from `draw()` write to a `overlayPosition` shallowRef that the template binds via `:style` on the anchor element. Vue's patcher updates the moved DOM node, so imperative `el.style.left/top/visibility/...` writes are gone. The `data-state` attribute is also a reactive template binding now, removing the imperative `setDataState` helper that previously propagated state to both the wrapper and its first child. - Anchor + content split. The overlay renders a two-element structure: the anchor div (positioned, moved into a Google Maps pane) wraps the content div (carries `data-state` + forwarded `class`/attrs + the slot). This is the DOM-level breaking change; consumers that target `[data-state]` on the slot's first child should move that class to the OverlayView component itself. - Class factory. The `CustomOverlay extends mapsApi.OverlayView` declaration is lifted out of `useGoogleMapsResource`'s `create()` callback into a `makeOverlayClass(mapsApi, map)` factory at script setup top level, so the `create()` callback is just wiring. - Playground demo update. `overlay-animated.vue` moves the `.overlay-popup` class from a slot child div onto the `` itself and uses `:deep()` in scoped styles to reach the now-internal content element. Tests: Five new mount-based tests in google-maps-overlay-view.nuxt.test.ts covering the anchor → content → slot DOM hierarchy, the projected pixel position landing on the anchor's inline style, the reactive visibility transition when the controlled `open` prop flips to false, the anchor staying in the DOM during the close path (so CSS animations targeting `[data-state="closed"]` can run), and data-state exposure on the content div for CSS targeting. All v1 protected behaviours remain green: - skip-if-equal setCenter watcher - map.setOptions exclusion of zoom/center - defineModel('open', { default: undefined }) - data-state="open"/"closed" toggling - InfoWindow group close 100/100 google-maps-* tests pass; lint and typecheck clean. --- .../docs/4.migration-guide/1.v0-to-v1.md | 25 +++ .../ScriptGoogleMapsOverlayView.vue | 200 ++++++++++-------- .../google-maps/overlay-animated.vue | 55 ++--- .../google-maps-overlay-view.nuxt.test.ts | 106 ++++++++++ 4 files changed, 269 insertions(+), 117 deletions(-) diff --git a/docs/content/docs/4.migration-guide/1.v0-to-v1.md b/docs/content/docs/4.migration-guide/1.v0-to-v1.md index a4d0f404..5e49c411 100644 --- a/docs/content/docs/4.migration-guide/1.v0-to-v1.md +++ b/docs/content/docs/4.migration-guide/1.v0-to-v1.md @@ -414,6 +414,31 @@ The same rename applies to ``{lang="html"}: its exp }) ``` +#### ``{lang="html"} DOM Structure + +The overlay view now renders an extra wrapper element. The structure is `anchor div → content div → slot`, where the anchor handles positioning (Google Maps reparents it into a pane on mount) and the content div carries `data-state` plus any forwarded `class`/attrs. + +CSS that targets `[data-state="open"]` on the slot's root element should move to a class on the ``{lang="html"} itself, since the data-state attribute now lives on the internal content div rather than propagating into the slot's first child. + +```diff + + + +``` + ### Google Maps Static Placeholder ([#673](https://github.com/nuxt/scripts/pull/673)) v1 extracts the built-in static map placeholder into a standalone [``{lang="html"}](/scripts/google-maps/api/static-map) component. This removes the following props from ``{lang="html"}: diff --git a/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue b/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue index e1e79147..113f8420 100644 --- a/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue +++ b/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue @@ -90,7 +90,7 @@ export interface ScriptGoogleMapsOverlayViewExpose {