From fc850220b27f980dcd3a68f92b32bf4c7b41e968 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+c4rl0sbr4v0@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:42:40 +0100 Subject: [PATCH] Interactivity API: Remove wp-data-navigation-link directive (#57853) * Remove wp-data-navigation-link directive * Update changelog * Remove not needed functions * Revert "Remove not needed functions" This reverts commit 3461c772474e42ca89785fa9b302dbd85ff43b0c. * Move breaking change changelog to correct position * Add function style to changelog --- packages/interactivity/CHANGELOG.md | 1 + packages/interactivity/src/directives.js | 51 +----------------------- 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/packages/interactivity/CHANGELOG.md b/packages/interactivity/CHANGELOG.md index db396cfa11de12..913134d6700085 100644 --- a/packages/interactivity/CHANGELOG.md +++ b/packages/interactivity/CHANGELOG.md @@ -9,6 +9,7 @@ ### Breaking Change - Remove `data-wp-slot` and `data-wp-fill`. ([#57854](https://github.com/WordPress/gutenberg/pull/57854)) +- Remove `wp-data-navigation-link` directive. ([#57853](https://github.com/WordPress/gutenberg/pull/57853)) ### Bug Fix diff --git a/packages/interactivity/src/directives.js b/packages/interactivity/src/directives.js index cddab32079823e..931fa07493f44d 100644 --- a/packages/interactivity/src/directives.js +++ b/packages/interactivity/src/directives.js @@ -1,13 +1,7 @@ /** * External dependencies */ -import { - useContext, - useMemo, - useEffect, - useRef, - useLayoutEffect, -} from 'preact/hooks'; +import { useContext, useMemo, useRef, useLayoutEffect } from 'preact/hooks'; import { deepSignal, peek } from 'deepsignal'; /** @@ -16,7 +10,6 @@ import { deepSignal, peek } from 'deepsignal'; import { createPortal } from './portals'; import { useWatch, useInit } from './utils'; import { directive } from './hooks'; -import { navigate } from './router'; const isObject = ( item ) => item && typeof item === 'object' && ! Array.isArray( item ); @@ -264,48 +257,6 @@ export default () => { ); } ); - // data-wp-navigation-link - directive( - 'navigation-link', - ( { - directives: { 'navigation-link': navigationLink }, - props: { href }, - element, - } ) => { - const { value: link } = navigationLink.find( - ( { suffix } ) => suffix === 'default' - ); - - useEffect( () => { - // Prefetch the page if it is in the directive options. - if ( link?.prefetch ) { - // prefetch( href ); - } - } ); - - // Don't do anything if it's falsy. - if ( link !== false ) { - element.props.onclick = async ( event ) => { - event.preventDefault(); - - // Fetch the page (or return it from cache). - await navigate( href ); - - // Update the scroll, depending on the option. True by default. - if ( link?.scroll === 'smooth' ) { - window.scrollTo( { - top: 0, - left: 0, - behavior: 'smooth', - } ); - } else if ( link?.scroll !== false ) { - window.scrollTo( 0, 0 ); - } - }; - } - } - ); - // data-wp-ignore directive( 'ignore',