diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-init/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-init/view.js index 333dbd6d7f501..9990e2743c879 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/directive-init/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/directive-init/view.js @@ -1,7 +1,11 @@ /** * WordPress dependencies */ -import { store, directive, getContext } from '@wordpress/interactivity'; +import { store, getContext, privateApis } from '@wordpress/interactivity'; + +const { directive } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); // Mock `data-wp-show` directive to test when things are removed from the // DOM. Replace with `data-wp-show` when it's ready. diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-on-document/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-on-document/view.js index b7f2a52b42baa..c2a41832737ab 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/directive-on-document/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/directive-on-document/view.js @@ -1,7 +1,11 @@ /** * WordPress dependencies */ -import { store, directive } from '@wordpress/interactivity'; +import { store, privateApis } from '@wordpress/interactivity'; + +const { directive } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); // Mock `data-wp-show` directive to test when things are removed from the // DOM. Replace with `data-wp-show` when it's ready. diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-on-window/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-on-window/view.js index 1743311dee6cb..b99f63b02517a 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/directive-on-window/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/directive-on-window/view.js @@ -1,7 +1,11 @@ /** * WordPress dependencies */ -import { store, directive } from '@wordpress/interactivity'; +import { store, privateApis } from '@wordpress/interactivity'; + +const { directive } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); // Mock `data-wp-show` directive to test when things are removed from the // DOM. Replace with `data-wp-show` when it's ready. diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/view.js index 4d47084e34362..c4a7ae2f6e875 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/view.js @@ -4,12 +4,14 @@ import { store, getContext, - directive, - deepSignal, useEffect, - createElement as h, + privateApis } from '@wordpress/interactivity'; +const { directive, deepSignal, h } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); + /** * Namespace used in custom directives and store. */ diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-run/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-run/view.js index 5151fb4c6db10..ae1095f08ac8f 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/directive-run/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/directive-run/view.js @@ -3,13 +3,16 @@ */ import { store, - directive, useInit, useWatch, - cloneElement, getElement, + privateApis } from '@wordpress/interactivity'; +const { directive, cloneElement } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); + // Custom directive to show hide the content elements in which it is placed. directive( 'show-children', diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-text/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-text/view.js index 12b8ca9488ea1..239f13e8f61b6 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/directive-text/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/directive-text/view.js @@ -1,12 +1,17 @@ /** * WordPress dependencies */ -import { store, getContext, createElement } from '@wordpress/interactivity'; +import { store, getContext, privateApis } from '@wordpress/interactivity'; + +const { h } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); + const { state } = store( 'directive-context', { state: { text: 'Text 1', - component: () => (createElement( 'div', {}, state.text )), + component: () => ( h( 'div', {}, state.text ) ), number: 1, boolean: true }, diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-watch/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-watch/view.js index d1acd45970dd6..c333269cd6377 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/directive-watch/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/directive-watch/view.js @@ -1,7 +1,11 @@ /** * WordPress dependencies */ -import { store, directive } from '@wordpress/interactivity'; +import { store, privateApis } from '@wordpress/interactivity'; + +const { directive } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); // Fake `data-wp-show-mock` directive to test when things are removed from the // DOM. Replace with `data-wp-show` when it's ready. diff --git a/packages/e2e-tests/plugins/interactive-blocks/tovdom-islands/view.js b/packages/e2e-tests/plugins/interactive-blocks/tovdom-islands/view.js index ba6106801fbc7..2993a273486c2 100644 --- a/packages/e2e-tests/plugins/interactive-blocks/tovdom-islands/view.js +++ b/packages/e2e-tests/plugins/interactive-blocks/tovdom-islands/view.js @@ -1,7 +1,11 @@ /** * WordPress dependencies */ -import { store, directive, createElement as h } from '@wordpress/interactivity'; +import { store, privateApis } from '@wordpress/interactivity'; + +const { directive, h } = privateApis( + 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' +); // Fake `data-wp-show-mock` directive to test when things are removed from the // DOM. Replace with `data-wp-show` when it's ready. diff --git a/packages/interactivity-router/src/index.js b/packages/interactivity-router/src/index.js index 46f184b4ec030..7693cc6e54657 100644 --- a/packages/interactivity-router/src/index.js +++ b/packages/interactivity-router/src/index.js @@ -1,9 +1,9 @@ /** * WordPress dependencies */ -import { render, store, privateApis } from '@wordpress/interactivity'; +import { store, privateApis } from '@wordpress/interactivity'; -const { directivePrefix, getRegionRootFragment, initialVdom, toVdom } = +const { directivePrefix, getRegionRootFragment, initialVdom, toVdom, render } = privateApis( 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.' ); diff --git a/packages/interactivity/src/index.ts b/packages/interactivity/src/index.ts index 477b90db1efc1..367e612a8dfce 100644 --- a/packages/interactivity/src/index.ts +++ b/packages/interactivity/src/index.ts @@ -1,3 +1,9 @@ +/** + * External dependencies + */ +import { h, cloneElement, render } from 'preact'; +import { deepSignal } from 'deepsignal'; + /** * Internal dependencies */ @@ -5,9 +11,10 @@ import registerDirectives from './directives'; import { init, getRegionRootFragment, initialVdom } from './init'; import { directivePrefix } from './constants'; import { toVdom } from './vdom'; +import { directive, getNamespace } from './hooks'; export { store } from './store'; -export { directive, getContext, getElement, getNamespace } from './hooks'; +export { getContext, getElement } from './hooks'; export { withScope, useWatch, @@ -18,20 +25,24 @@ export { useMemo, } from './utils'; -export { h as createElement, cloneElement, render } from 'preact'; -export { useContext, useState, useRef } from 'preact/hooks'; -export { deepSignal } from 'deepsignal'; +export { useState, useRef } from 'preact/hooks'; const requiredConsent = 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'; -export const privateApis = ( lock ) => { +export const privateApis = ( lock ): any => { if ( lock === requiredConsent ) { return { directivePrefix, getRegionRootFragment, initialVdom, toVdom, + directive, + getNamespace, + h, + cloneElement, + render, + deepSignal, }; }