From b56162cbbe6e60484a481b676cb3d312047fb3bb Mon Sep 17 00:00:00 2001 From: Gary Date: Mon, 16 Dec 2019 15:24:54 +1100 Subject: [PATCH] Add some docblocks. --- packages/embed-block/src/index.js | 2 +- packages/embed-block/src/settings.js | 7 +++++++ packages/embed-block/src/util.js | 12 ++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/embed-block/src/index.js b/packages/embed-block/src/index.js index f01d200a95ace..331819713ba5f 100644 --- a/packages/embed-block/src/index.js +++ b/packages/embed-block/src/index.js @@ -2,5 +2,5 @@ * Internal dependencies */ export * from './icons'; -export * from './settings'; +export { getEmbedBlockSettings } from './settings'; export { isFromWordPress } from './util'; diff --git a/packages/embed-block/src/settings.js b/packages/embed-block/src/settings.js index 17d97cee43da6..7599b51a3dfd9 100644 --- a/packages/embed-block/src/settings.js +++ b/packages/embed-block/src/settings.js @@ -37,6 +37,13 @@ const embedAttributes = { }, }; +/** + * Generate the settings object for an embed block to register with. + * + * @param {Object} settings The settings object to pass to `registerBlockType())`. The `save` and `edit` + * attributes will be overriden, if passed. + * @return {Object} The settings object configured as an embed block. + */ export function getEmbedBlockSettings( { title, description, icon, category = 'embed', transforms, keywords = [], supports = {}, responsive = true } ) { const blockDescription = description || __( 'Add a block that displays content pulled from other sites, like Twitter, Instagram or YouTube.' ); const edit = getEmbedEditComponent( title, icon, responsive ); diff --git a/packages/embed-block/src/util.js b/packages/embed-block/src/util.js index 2f2ee9bf9dbe5..cfdb79be53411 100644 --- a/packages/embed-block/src/util.js +++ b/packages/embed-block/src/util.js @@ -16,6 +16,12 @@ import memoize from 'memize'; import { renderToString } from '@wordpress/element'; import { createBlock } from '@wordpress/blocks'; +/** + * Given a photo object, generate the HTML to show a preview of the photo. + * + * @param {Object} photo The photo data. + * @return {string} The preview HTML, rendered as a string. + */ export const getPhotoHtml = ( photo ) => { // 100% width for the preview so it fits nicely into the document, some "thumbnails" are // actually the full size photo. If thumbnails not found, use full image. @@ -24,6 +30,12 @@ export const getPhotoHtml = ( photo ) => { return renderToString( photoPreview ); }; +/** + * Determines if the HTML passed is an embed generated by WordPress. + * + * @param {string} html The HTML to check. + * @return {boolean} Whether it was generated by WordPress or not. + */ export const isFromWordPress = ( html ) => { return includes( html, 'class="wp-embedded-content"' ); };