diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-on/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-on/view.js
index 3fc1e63784fbc..69378b53e14c0 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-on/view.js
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-on/view.js
@@ -1,29 +1,30 @@
-( ( { wp } ) => {
- const { store, getContext } = wp.interactivity;
+/**
+ * WordPress dependencies
+ */
+import { store, getContext } from '@wordpress/interactivity';
- const { state } = store( 'directive-on', {
- state: {
- counter: 0,
- text: ''
+const { state } = store( 'directive-on', {
+ state: {
+ counter: 0,
+ text: '',
+ },
+ actions: {
+ clickHandler: ( event ) => {
+ state.counter += 1;
+ event.target.dispatchEvent(
+ new CustomEvent( 'customevent', { bubbles: true } )
+ );
},
- actions: {
- clickHandler: ( event ) => {
- state.counter += 1;
- event.target.dispatchEvent(
- new CustomEvent( 'customevent', { bubbles: true } )
- );
- },
- inputHandler: ( event ) => {
- state.text = event.target.value;
- },
- selectHandler: ( event ) => {
- const context = getContext();
- context.option = event.target.value;
- },
- customEventHandler: () => {
- const context = getContext();
- context.customEvents += 1;
- },
+ inputHandler: ( event ) => {
+ state.text = event.target.value;
},
- } );
-} )( window );
+ selectHandler: ( event ) => {
+ const context = getContext();
+ context.option = event.target.value;
+ },
+ customEventHandler: () => {
+ const context = getContext();
+ context.customEvents += 1;
+ },
+ },
+} );
diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/render.php b/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/render.php
index 0502189e86679..f082d44dd8fdf 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/render.php
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/render.php
@@ -5,7 +5,9 @@
* @package gutenberg-test-interactive-blocks
*/
+gutenberg_enqueue_module( 'directive-priorities-view' );
?>
+
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 e3c14741e1bb5..4d47084e34362 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/view.js
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-priorities/view.js
@@ -1,126 +1,117 @@
-( ( { wp } ) => {
- /**
- * WordPress dependencies
- */
- const {
- store,
- getContext,
- directive,
- deepSignal,
- useEffect,
- createElement: h
- } = wp.interactivity;
+/**
+ * WordPress dependencies
+ */
+import {
+ store,
+ getContext,
+ directive,
+ deepSignal,
+ useEffect,
+ createElement as h,
+} from '@wordpress/interactivity';
- /**
- * Namespace used in custom directives and store.
- */
- const namespace = 'directive-priorities';
+/**
+ * Namespace used in custom directives and store.
+ */
+const namespace = 'directive-priorities';
- /**
- * Util to check that render calls happen in order.
- *
- * @param {string} n Name passed from the directive being executed.
- */
- const executionProof = ( n ) => {
- const el = document.querySelector( '[data-testid="execution order"]' );
- if ( ! el.textContent ) el.textContent = n;
- else el.textContent += `, ${ n }`;
- };
+/**
+ * Util to check that render calls happen in order.
+ *
+ * @param {string} n Name passed from the directive being executed.
+ */
+const executionProof = ( n ) => {
+ const el = document.querySelector( '[data-testid="execution order"]' );
+ if ( ! el.textContent ) el.textContent = n;
+ else el.textContent += `, ${ n }`;
+};
- /**
- * Simple context directive, just for testing purposes. It provides a deep
- * signal with these two properties:
- * - attribute: 'from context'
- * - text: 'from context'
- */
- directive(
- 'test-context',
- ( { context: { Provider }, props: { children } } ) => {
- executionProof( 'context' );
- const value = deepSignal(
- {
- [namespace]: {
- attribute: 'from context',
- text: 'from context',
- }
- }
- );
- return h( Provider, { value }, children );
- },
- { priority: 8 }
- );
+/**
+ * Simple context directive, just for testing purposes. It provides a deep
+ * signal with these two properties:
+ * - attribute: 'from context'
+ * - text: 'from context'
+ */
+directive(
+ 'test-context',
+ ( { context: { Provider }, props: { children } } ) => {
+ executionProof( 'context' );
+ const value = deepSignal( {
+ [ namespace ]: {
+ attribute: 'from context',
+ text: 'from context',
+ },
+ } );
+ return h( Provider, { value }, children );
+ },
+ { priority: 8 }
+);
- /**
- * Simple attribute directive, for testing purposes. It reads the value of
- * `attribute` from context and populates `data-attribute` with it.
- */
- directive( 'test-attribute', ( { evaluate, element } ) => {
- executionProof( 'attribute' );
- const attributeValue = evaluate(
- { namespace, value: 'context.attribute' }
- );
- useEffect( () => {
- element.ref.current.setAttribute(
- 'data-attribute',
- attributeValue,
- );
- }, [] );
- element.props[ 'data-attribute' ] = attributeValue;
+/**
+ * Simple attribute directive, for testing purposes. It reads the value of
+ * `attribute` from context and populates `data-attribute` with it.
+ */
+directive( 'test-attribute', ( { evaluate, element } ) => {
+ executionProof( 'attribute' );
+ const attributeValue = evaluate( {
+ namespace,
+ value: 'context.attribute',
} );
+ useEffect( () => {
+ element.ref.current.setAttribute( 'data-attribute', attributeValue );
+ }, [] );
+ element.props[ 'data-attribute' ] = attributeValue;
+} );
- /**
- * Simple text directive, for testing purposes. It reads the value of
- * `text` from context and populates `children` with it.
- */
- directive(
- 'test-text',
- ( { evaluate, element } ) => {
- executionProof( 'text' );
- const textValue = evaluate(
- { namespace, value: 'context.text' }
- );
- element.props.children =
- h( 'p', { 'data-testid': 'text' }, textValue );
- },
- { priority: 12 }
- );
+/**
+ * Simple text directive, for testing purposes. It reads the value of
+ * `text` from context and populates `children` with it.
+ */
+directive(
+ 'test-text',
+ ( { evaluate, element } ) => {
+ executionProof( 'text' );
+ const textValue = evaluate( { namespace, value: 'context.text' } );
+ element.props.children = h( 'p', { 'data-testid': 'text' }, textValue );
+ },
+ { priority: 12 }
+);
- /**
- * Children directive, for testing purposes. It adds a wrapper around
- * `children`, including two buttons to modify `text` and `attribute` values
- * from the received context.
- */
- directive(
- 'test-children',
- ( { evaluate, element } ) => {
- executionProof( 'children' );
- const updateAttribute = () => {
- evaluate( { namespace, value: 'actions.updateAttribute' } );
- };
- const updateText = () => {
- evaluate( { namespace, value: 'actions.updateText' } );
- };
- element.props.children = h(
- 'div',
- {},
- element.props.children,
- h( 'button', { onClick: updateAttribute }, 'Update attribute' ),
- h( 'button', { onClick: updateText }, 'Update text' )
- );
- },
- { priority: 14 }
- );
+/**
+ * Children directive, for testing purposes. It adds a wrapper around
+ * `children`, including two buttons to modify `text` and `attribute` values
+ * from the received context.
+ */
+directive(
+ 'test-children',
+ ( { evaluate, element } ) => {
+ executionProof( 'children' );
+ const updateAttribute = () => {
+ evaluate( { namespace, value: 'actions.updateAttribute' } );
+ };
+ const updateText = () => {
+ evaluate( { namespace, value: 'actions.updateText' } );
+ };
+ element.props.children = h(
+ 'div',
+ {},
+ element.props.children,
+ h( 'button', { onClick: updateAttribute }, 'Update attribute' ),
+ h( 'button', { onClick: updateText }, 'Update text' )
+ );
+ },
+ { priority: 14 }
+);
- store( 'directive-priorities', {
- actions: {
- updateText() {
- const context = getContext();
- context.text = 'updated';
- },
- updateAttribute() {
- const context = getContext();
- context.attribute = 'updated';
- },
+store( 'directive-priorities', {
+ actions: {
+ updateText() {
+ const context = getContext();
+ context.text = 'updated';
},
- } );
-} )( window );
+ updateAttribute() {
+ const context = getContext();
+ context.attribute = 'updated';
+ },
+ },
+} );
diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-slots/render.php b/packages/e2e-tests/plugins/interactive-blocks/directive-slots/render.php
index 8419069baa640..c9a989ccaf027 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-slots/render.php
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-slots/render.php
@@ -5,7 +5,9 @@
* @package gutenberg-test-interactive-blocks
*/
+gutenberg_enqueue_module( 'directive-slots-view' );
?>
+
{
- const { store, getContext } = wp.interactivity;
+/**
+ * WordPress dependencies
+ */
+import { store, getContext } from '@wordpress/interactivity';
- const { state } = store( 'directive-slots', {
- state: {
- slot: ''
+const { state } = store( 'directive-slots', {
+ state: {
+ slot: '',
+ },
+ actions: {
+ changeSlot( event ) {
+ state.slot = event.target.dataset.slot;
},
- actions: {
- changeSlot( event ) {
- state.slot = event.target.dataset.slot;
- },
- updateSlotText() {
- const context = getContext();
- const n = context.text[1];
- context.text = `[${n} updated]`;
- },
+ updateSlotText() {
+ const context = getContext();
+ const n = context.text[ 1 ];
+ context.text = `[${ n } updated]`;
},
- } );
-} )( window );
+ },
+} );
diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-style/render.php b/packages/e2e-tests/plugins/interactive-blocks/directive-style/render.php
index a62f055617a32..b31f13cf1335c 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-style/render.php
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-style/render.php
@@ -5,6 +5,7 @@
* @package gutenberg-test-interactive-blocks
*/
+gutenberg_enqueue_module( 'directive-style-view' );
?>
diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-style/view.js b/packages/e2e-tests/plugins/interactive-blocks/directive-style/view.js
index 4a3024302dc77..ccf366844276c 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-style/view.js
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-style/view.js
@@ -1,23 +1,24 @@
-( ( { wp } ) => {
- const { store, getContext } = wp.interactivity;
+/**
+ * WordPress dependencies
+ */
+import { store, getContext } from '@wordpress/interactivity';
- const { state } = store( 'directive-style', {
- state: {
- falseValue: false,
- color: "red",
- border: "2px solid yellow"
+const { state } = store( 'directive-style', {
+ state: {
+ falseValue: false,
+ color: 'red',
+ border: '2px solid yellow',
+ },
+ actions: {
+ toggleColor() {
+ state.color = state.color === 'red' ? 'blue' : 'red';
},
- actions: {
- toggleColor() {
- state.color = state.color === "red" ? "blue" : "red";
- },
- switchColorToFalse() {
- state.color = false;
- },
- toggleContext() {
- const context = getContext();
- context.color = context.color === "red" ? "blue" : "red";
- },
+ switchColorToFalse() {
+ state.color = false;
},
- } );
-} )( window );
+ toggleContext() {
+ const context = getContext();
+ context.color = context.color === 'red' ? 'blue' : 'red';
+ },
+ },
+} );
diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-text/render.php b/packages/e2e-tests/plugins/interactive-blocks/directive-text/render.php
index 1746cbe940a7e..98803669c6b0b 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-text/render.php
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-text/render.php
@@ -5,7 +5,9 @@
* @package gutenberg-test-interactive-blocks
*/
+gutenberg_enqueue_module( 'directive-text-view' );
?>
+
{
- const { store, getContext } = wp.interactivity;
+/**
+ * WordPress dependencies
+ */
+import { store, getContext } from '@wordpress/interactivity';
- const { state } = store( 'directive-context', {
- state: {
- text: 'Text 1',
+const { state } = store( 'directive-context', {
+ state: {
+ text: 'Text 1',
+ },
+ actions: {
+ toggleStateText() {
+ state.text = state.text === 'Text 1' ? 'Text 2' : 'Text 1';
},
- actions: {
- toggleStateText() {
- state.text = state.text === 'Text 1' ? 'Text 2' : 'Text 1';
- },
- toggleContextText() {
- const context = getContext();
- context.text = context.text === 'Text 1' ? 'Text 2' : 'Text 1';
- },
+ toggleContextText() {
+ const context = getContext();
+ context.text = context.text === 'Text 1' ? 'Text 2' : 'Text 1';
},
- } );
-} )( window );
+ },
+} );
diff --git a/packages/e2e-tests/plugins/interactive-blocks/directive-watch/render.php b/packages/e2e-tests/plugins/interactive-blocks/directive-watch/render.php
index 9434bd777fd24..4fc7dd96ee883 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/directive-watch/render.php
+++ b/packages/e2e-tests/plugins/interactive-blocks/directive-watch/render.php
@@ -5,7 +5,9 @@
* @package gutenberg-test-interactive-blocks
*/
+gutenberg_enqueue_module( 'directive-watch-view' );
?>
+
{
- const { store, directive } = wp.interactivity;
+/**
+ * WordPress dependencies
+ */
+import { store, directive } from '@wordpress/interactivity';
- // Fake `data-wp-show-mock` directive to test when things are removed from the
- // DOM. Replace with `data-wp-show` when it's ready.
- directive(
- 'show-mock',
- ( {
- directives: {
- "show-mock": showMock,
- },
- element,
- evaluate,
- } ) => {
- const entry = showMock.find(
- ( { suffix } ) => suffix === 'default'
- );
- if ( ! evaluate( entry ) ) return null;
- return element;
- }
- );
+// Fake `data-wp-show-mock` directive to test when things are removed from the
+// DOM. Replace with `data-wp-show` when it's ready.
+directive(
+ 'show-mock',
+ ( { directives: { 'show-mock': showMock }, element, evaluate } ) => {
+ const entry = showMock.find( ( { suffix } ) => suffix === 'default' );
+ if ( ! evaluate( entry ) ) return null;
+ return element;
+ }
+);
- const { state } = store( 'directive-watch', {
- state: {
- isOpen: true,
- isElementInTheDOM: false,
- counter: 0,
- get elementInTheDOM() {
- return state.isElementInTheDOM
- ? 'element is in the DOM'
- : 'element is not in the DOM';
- }
+const { state } = store( 'directive-watch', {
+ state: {
+ isOpen: true,
+ isElementInTheDOM: false,
+ counter: 0,
+ get elementInTheDOM() {
+ return state.isElementInTheDOM
+ ? 'element is in the DOM'
+ : 'element is not in the DOM';
+ },
+ },
+ actions: {
+ toggle() {
+ state.isOpen = ! state.isOpen;
},
- actions: {
- toggle() {
- state.isOpen = ! state.isOpen;
- },
- increment() {
- state.counter = state.counter + 1;
- },
+ increment() {
+ state.counter = state.counter + 1;
},
- callbacks: {
- elementAddedToTheDOM: () => {
- state.isElementInTheDOM = true;
+ },
+ callbacks: {
+ elementAddedToTheDOM: () => {
+ state.isElementInTheDOM = true;
- return () => {
- state.isElementInTheDOM = false;
- };
- },
- changeFocus: () => {
- if ( state.isOpen ) {
- document.querySelector( "[data-testid='input']" ).focus();
- }
- },
- infiniteLoop: () => {
- state.counter = state.counter + 1;
+ return () => {
+ state.isElementInTheDOM = false;
+ };
+ },
+ changeFocus: () => {
+ if ( state.isOpen ) {
+ document.querySelector( "[data-testid='input']" ).focus();
}
},
- } );
-
-} )( window );
+ infiniteLoop: () => {
+ state.counter = state.counter + 1;
+ },
+ },
+} );
diff --git a/packages/e2e-tests/plugins/interactive-blocks/negation-operator/render.php b/packages/e2e-tests/plugins/interactive-blocks/negation-operator/render.php
index 29b7dcbd32dfd..8d686e6c3ff46 100644
--- a/packages/e2e-tests/plugins/interactive-blocks/negation-operator/render.php
+++ b/packages/e2e-tests/plugins/interactive-blocks/negation-operator/render.php
@@ -5,7 +5,9 @@
* @package gutenberg-test-interactive-blocks
*/
+gutenberg_enqueue_module( 'negation-operator-view' );
?>
+