Skip to content

Commit

Permalink
Update interactivity exports (#58864)
Browse files Browse the repository at this point in the history
Co-authored-by: DAreRodz <[email protected]>
Co-authored-by: luisherranz <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2024
1 parent 6af41df commit b283c47
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/interactivity-router/src/index.js
Original file line number Diff line number Diff line change
@@ -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.'
);
Expand Down
21 changes: 16 additions & 5 deletions packages/interactivity/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/**
* External dependencies
*/
import { h, cloneElement, render } from 'preact';
import { deepSignal } from 'deepsignal';

/**
* Internal dependencies
*/
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,
Expand All @@ -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,
};
}

Expand Down

0 comments on commit b283c47

Please sign in to comment.