Skip to content

Commit

Permalink
Revert "Add privateApis to RichText package and export useAnchorWithU…
Browse files Browse the repository at this point in the history
…pdate hook"

This reverts commit cbcbf41.

# Conflicts:
#	packages/rich-text/README.md
#	packages/rich-text/src/private-apis.js
  • Loading branch information
getdave committed Jan 12, 2024
1 parent dbf7429 commit 57a3ebb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 62 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/private-apis/src/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const CORE_MODULES_USING_PRIVATE_APIS = [
'@wordpress/format-library',
'@wordpress/patterns',
'@wordpress/reusable-blocks',
'@wordpress/rich-text',
'@wordpress/router',
'@wordpress/dataviews',
];
Expand Down
4 changes: 0 additions & 4 deletions packages/rich-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,6 @@ _Returns_

- `RichTextValue`: A new combined value.

### privateApis

Private @wordpress/rich-text APIs.

### registerFormatType

Registers a new format provided a unique name and an object defining its behavior.
Expand Down
1 change: 0 additions & 1 deletion packages/rich-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@wordpress/escape-html": "file:../escape-html",
"@wordpress/i18n": "file:../i18n",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/private-apis": "file:../private-apis",
"memize": "^2.1.0",
"rememo": "^4.0.2"
},
Expand Down
55 changes: 26 additions & 29 deletions packages/rich-text/src/component/use-anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ function createVirtualAnchorElement( range, editableContentElement ) {
};
}

/**
* Get the anchor: a format element if there is a matching one based on the
* tagName and className or a range otherwise.
*
* @param {HTMLElement} editableContentElement The editable wrapper.
* @param {string} tagName The tag name of the format
* element.
* @param {string} className The class name of the format
* element.
*
* @return {HTMLElement|VirtualAnchorElement|undefined} The anchor.
*/
function getAnchor( editableContentElement, tagName, className ) {
if ( ! editableContentElement ) return;

Expand All @@ -112,7 +124,19 @@ function getAnchor( editableContentElement, tagName, className ) {
return createVirtualAnchorElement( range, editableContentElement );
}

function useAnchorBase( { editableContentElement, settings = {} } ) {
/**
* This hook, to be used in a format type's Edit component, returns the active
* element that is formatted, or a virtual element for the selection range if
* no format is active. The returned value is meant to be used for positioning
* UI, e.g. by passing it to the `Popover` component via the `anchor` prop.
*
* @param {Object} $1 Named parameters.
* @param {HTMLElement|null} $1.editableContentElement The element containing
* the editable content.
* @param {WPFormat=} $1.settings The format type's settings.
* @return {Element|VirtualAnchorElement|undefined|null} The active element or selection range.
*/
export function useAnchor( { editableContentElement, settings = {} } ) {
const { tagName, className } = settings;
const [ anchor, setAnchor ] = useState( () =>
getAnchor( editableContentElement, tagName, className )
Expand Down Expand Up @@ -150,33 +174,6 @@ function useAnchorBase( { editableContentElement, settings = {} } ) {
};
}, [ editableContentElement, tagName, className, callback ] );

return {
anchor,
update: callback,
};
}

/**
* This hook, to be used in a format type's Edit component, returns the active
* element that is formatted, or a virtual element for the selection range if
* no format is active. The returned value is meant to be used for positioning
* UI, e.g. by passing it to the `Popover` component via the `anchor` prop.
*
* @param {Object} $1 Named parameters.
* @param {HTMLElement|null} $1.editableContentElement The element containing
* the editable content.
* @param {WPFormat=} $1.settings The format type's settings.
* @return {Element|VirtualAnchorElement|undefined|null} The active element or selection range.
*/
export function useAnchor( { editableContentElement, settings = {} } ) {
const { anchor } = useAnchorBase( { editableContentElement, settings } );

anchor.update = callback;
return anchor;
}

export function useAnchorWithUpdate( {
editableContentElement,
settings = {},
} ) {
return useAnchorBase( { editableContentElement, settings } );
}
2 changes: 0 additions & 2 deletions packages/rich-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@ export {
* documentation for more information.
*/
export type { RichTextValue } from './types';

export { privateApis } from './private-apis';
10 changes: 0 additions & 10 deletions packages/rich-text/src/lock-unlock.js

This file was deleted.

13 changes: 0 additions & 13 deletions packages/rich-text/src/private-apis.js

This file was deleted.

0 comments on commit 57a3ebb

Please sign in to comment.