Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactivity API: Limit the exported APIs #58864

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading