@wordpress/block-library
Version:
Block library for the WordPress editor.
332 lines (331 loc) • 12.3 kB
JavaScript
import { registerBlockType, setDefaultBlockName, setFreeformContentHandlerName, setGroupingBlockName, setUnregisteredTypeHandlerName, store } from "@wordpress/blocks";
import { useDisabled } from "@wordpress/compose";
import { select } from "@wordpress/data";
import { useBlockProps } from "@wordpress/block-editor";
import { useServerSideRender } from "@wordpress/server-side-render";
import { __, sprintf } from "@wordpress/i18n";
import HtmlRenderer from "./utils/html-renderer.mjs";
import * as accordion from "./accordion/index.mjs";
import * as accordionItem from "./accordion-item/index.mjs";
import * as accordionHeading from "./accordion-heading/index.mjs";
import * as accordionPanel from "./accordion-panel/index.mjs";
import * as archives from "./archives/index.mjs";
import * as avatar from "./avatar/index.mjs";
import * as audio from "./audio/index.mjs";
import * as breadcrumbs from "./breadcrumbs/index.mjs";
import * as button from "./button/index.mjs";
import * as buttons from "./buttons/index.mjs";
import * as calendar from "./calendar/index.mjs";
import * as categories from "./categories/index.mjs";
import * as classic from "./freeform/index.mjs";
import * as code from "./code/index.mjs";
import * as column from "./column/index.mjs";
import * as columns from "./columns/index.mjs";
import * as comments from "./comments/index.mjs";
import * as commentAuthorAvatar from "./comment-author-avatar/index.mjs";
import * as commentAuthorName from "./comment-author-name/index.mjs";
import * as commentContent from "./comment-content/index.mjs";
import * as commentDate from "./comment-date/index.mjs";
import * as commentEditLink from "./comment-edit-link/index.mjs";
import * as commentReplyLink from "./comment-reply-link/index.mjs";
import * as commentTemplate from "./comment-template/index.mjs";
import * as commentsPaginationPrevious from "./comments-pagination-previous/index.mjs";
import * as commentsPagination from "./comments-pagination/index.mjs";
import * as commentsPaginationNext from "./comments-pagination-next/index.mjs";
import * as commentsPaginationNumbers from "./comments-pagination-numbers/index.mjs";
import * as commentsTitle from "./comments-title/index.mjs";
import * as cover from "./cover/index.mjs";
import * as details from "./details/index.mjs";
import * as embed from "./embed/index.mjs";
import * as file from "./file/index.mjs";
import * as gallery from "./gallery/index.mjs";
import * as group from "./group/index.mjs";
import * as heading from "./heading/index.mjs";
import * as homeLink from "./home-link/index.mjs";
import * as html from "./html/index.mjs";
import * as icon from "./icon/index.mjs";
import * as image from "./image/index.mjs";
import * as latestComments from "./latest-comments/index.mjs";
import * as latestPosts from "./latest-posts/index.mjs";
import * as list from "./list/index.mjs";
import * as math from "./math/index.mjs";
import * as listItem from "./list-item/index.mjs";
import * as logInOut from "./loginout/index.mjs";
import * as mediaText from "./media-text/index.mjs";
import * as missing from "./missing/index.mjs";
import * as more from "./more/index.mjs";
import * as navigation from "./navigation/index.mjs";
import * as navigationLink from "./navigation-link/index.mjs";
import * as navigationSubmenu from "./navigation-submenu/index.mjs";
import * as nextpage from "./nextpage/index.mjs";
import * as navigationOverlayClose from "./navigation-overlay-close/index.mjs";
import * as pattern from "./pattern/index.mjs";
import * as pageList from "./page-list/index.mjs";
import * as pageListItem from "./page-list-item/index.mjs";
import * as paragraph from "./paragraph/index.mjs";
import * as playlist from "./playlist/index.mjs";
import * as playlistTrack from "./playlist-track/index.mjs";
import * as postAuthor from "./post-author/index.mjs";
import * as postAuthorName from "./post-author-name/index.mjs";
import * as postAuthorBiography from "./post-author-biography/index.mjs";
import * as postComment from "./post-comment/index.mjs";
import * as postCommentsCount from "./post-comments-count/index.mjs";
import * as postCommentsForm from "./post-comments-form/index.mjs";
import * as postCommentsLink from "./post-comments-link/index.mjs";
import * as postContent from "./post-content/index.mjs";
import * as postDate from "./post-date/index.mjs";
import * as postExcerpt from "./post-excerpt/index.mjs";
import * as postFeaturedImage from "./post-featured-image/index.mjs";
import * as postNavigationLink from "./post-navigation-link/index.mjs";
import * as postTemplate from "./post-template/index.mjs";
import * as postTerms from "./post-terms/index.mjs";
import * as postTimeToRead from "./post-time-to-read/index.mjs";
import * as postTitle from "./post-title/index.mjs";
import * as preformatted from "./preformatted/index.mjs";
import * as pullquote from "./pullquote/index.mjs";
import * as query from "./query/index.mjs";
import * as queryNoResults from "./query-no-results/index.mjs";
import * as queryPagination from "./query-pagination/index.mjs";
import * as queryPaginationNext from "./query-pagination-next/index.mjs";
import * as queryPaginationNumbers from "./query-pagination-numbers/index.mjs";
import * as queryPaginationPrevious from "./query-pagination-previous/index.mjs";
import * as queryTitle from "./query-title/index.mjs";
import * as queryTotal from "./query-total/index.mjs";
import * as quote from "./quote/index.mjs";
import * as reusableBlock from "./block/index.mjs";
import * as readMore from "./read-more/index.mjs";
import * as rss from "./rss/index.mjs";
import * as search from "./search/index.mjs";
import * as separator from "./separator/index.mjs";
import * as shortcode from "./shortcode/index.mjs";
import * as siteLogo from "./site-logo/index.mjs";
import * as siteTagline from "./site-tagline/index.mjs";
import * as siteTitle from "./site-title/index.mjs";
import * as socialLink from "./social-link/index.mjs";
import * as socialLinks from "./social-links/index.mjs";
import * as spacer from "./spacer/index.mjs";
import * as tabPanel from "./tab-panel/index.mjs";
import * as tabPanels from "./tab-panels/index.mjs";
import * as table from "./table/index.mjs";
import * as tableOfContents from "./table-of-contents/index.mjs";
import * as tabList from "./tab-list/index.mjs";
import * as tabs from "./tabs/index.mjs";
import * as tagCloud from "./tag-cloud/index.mjs";
import * as templatePart from "./template-part/index.mjs";
import * as termCount from "./term-count/index.mjs";
import * as termDescription from "./term-description/index.mjs";
import * as termName from "./term-name/index.mjs";
import * as termsQuery from "./terms-query/index.mjs";
import * as termTemplate from "./term-template/index.mjs";
import * as textColumns from "./text-columns/index.mjs";
import * as verse from "./verse/index.mjs";
import * as video from "./video/index.mjs";
import * as footnotes from "./footnotes/index.mjs";
import isBlockMetadataExperimental from "./utils/is-block-metadata-experimental.mjs";
import { unlock } from "./lock-unlock.mjs";
import { jsx } from "react/jsx-runtime";
import { privateApis } from "./private-apis.mjs";
// packages/block-library/src/index.jsx
/**
* Function to get all the block-library blocks in an array
*/
const getAllBlocks = () => {
const blocks = [
paragraph,
image,
heading,
gallery,
list,
listItem,
quote,
accordion,
accordionItem,
accordionHeading,
accordionPanel,
archives,
audio,
button,
buttons,
calendar,
categories,
code,
column,
columns,
commentAuthorAvatar,
cover,
details,
embed,
file,
group,
html,
math,
latestComments,
latestPosts,
mediaText,
missing,
more,
nextpage,
pageList,
pageListItem,
pattern,
playlist,
playlistTrack,
preformatted,
pullquote,
reusableBlock,
rss,
search,
separator,
shortcode,
socialLink,
socialLinks,
spacer,
table,
tabs,
tabList,
tabPanels,
tabPanel,
tagCloud,
textColumns,
verse,
video,
footnotes,
navigation,
navigationLink,
navigationSubmenu,
siteLogo,
siteTitle,
siteTagline,
query,
templatePart,
avatar,
postTitle,
postExcerpt,
postFeaturedImage,
postContent,
postAuthor,
postAuthorName,
postComment,
postCommentsCount,
postCommentsLink,
postDate,
postTerms,
postNavigationLink,
postTemplate,
postTimeToRead,
queryPagination,
queryPaginationNext,
queryPaginationNumbers,
queryPaginationPrevious,
queryNoResults,
queryTotal,
readMore,
comments,
commentAuthorName,
commentContent,
commentDate,
commentEditLink,
commentReplyLink,
commentTemplate,
commentsTitle,
commentsPagination,
commentsPaginationNext,
commentsPaginationNumbers,
commentsPaginationPrevious,
postCommentsForm,
tableOfContents,
homeLink,
icon,
logInOut,
navigationOverlayClose,
termCount,
termDescription,
termName,
termsQuery,
termTemplate,
queryTitle,
postAuthorBiography,
breadcrumbs
];
if (window?.__experimentalEnableBlockExperiments) {}
blocks.push(classic);
return blocks.filter(Boolean);
};
/**
* Function to get all the core blocks in an array.
*
* @example
* ```js
* import { __experimentalGetCoreBlocks } from '@wordpress/block-library';
*
* const coreBlocks = __experimentalGetCoreBlocks();
* ```
*/
const __experimentalGetCoreBlocks = () => getAllBlocks().filter(({ metadata }) => !isBlockMetadataExperimental(metadata));
/**
* Function to register core blocks provided by the block editor.
*
* @param {Array} blocks An optional array of the core blocks being registered.
*
* @example
* ```js
* import { registerCoreBlocks } from '@wordpress/block-library';
*
* registerCoreBlocks();
* ```
*/
const registerCoreBlocks = (blocks = __experimentalGetCoreBlocks()) => {
blocks.forEach(({ init }) => init());
if (window.__unstableAutoRegisterBlocks) window.__unstableAutoRegisterBlocks.forEach((blockName) => {
const bootstrappedBlockType = unlock(select(store)).getBootstrappedBlockType(blockName);
registerBlockType(blockName, {
...bootstrappedBlockType,
title: bootstrappedBlockType?.title || blockName,
...(bootstrappedBlockType?.apiVersion ?? 0) < 3 && { apiVersion: 3 },
usesContext: Array.from(/* @__PURE__ */ new Set([...bootstrappedBlockType?.usesContext ?? [], "postId"])),
edit: function Edit({ attributes, context }) {
const disabledRef = useDisabled();
const blockProps = useBlockProps({ ref: disabledRef });
const { content, status, error } = useServerSideRender({
block: blockName,
attributes,
urlQueryArgs: { post_id: context?.postId }
});
if (status === "loading") return /* @__PURE__ */ jsx("div", {
...blockProps,
children: __("Loading…")
});
if (status === "error") return /* @__PURE__ */ jsx("div", {
...blockProps,
children: sprintf(__("Error loading block: %s"), error)
});
return /* @__PURE__ */ jsx(HtmlRenderer, {
wrapperProps: blockProps,
html: content
});
},
save: () => null
});
});
setDefaultBlockName(paragraph.name);
if (window.wp && window.wp.oldEditor && blocks.some(({ name }) => name === classic.name)) setFreeformContentHandlerName(classic.name);
setUnregisteredTypeHandlerName(missing.name);
setGroupingBlockName(group.name);
};
/**
* Function to register experimental core blocks depending on editor settings.
*
* @param {boolean} enableFSEBlocks Whether to enable the full site editing blocks.
* @example
* ```js
* import { __experimentalRegisterExperimentalCoreBlocks } from '@wordpress/block-library';
*
* __experimentalRegisterExperimentalCoreBlocks( settings );
* ```
*/
const __experimentalRegisterExperimentalCoreBlocks = globalThis.IS_GUTENBERG_PLUGIN ? ({ enableFSEBlocks } = {}) => {
const enabledExperiments = [enableFSEBlocks ? "fse" : null];
getAllBlocks().filter(({ metadata }) => isBlockMetadataExperimental(metadata)).filter(({ metadata: { __experimental } }) => __experimental === true || enabledExperiments.includes(__experimental)).forEach(({ init }) => init());
} : void 0;
export { __experimentalGetCoreBlocks, __experimentalRegisterExperimentalCoreBlocks, privateApis, registerCoreBlocks };
//# sourceMappingURL=index.mjs.map