UNPKG

@wordpress/block-editor

Version:
66 lines (62 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addActiveFormats = addActiveFormats; exports.createLinkInParagraph = createLinkInParagraph; exports.getAllowedFormats = getAllowedFormats; exports.getMultilineTag = getMultilineTag; var _element = require("@wordpress/element"); var _blocks = require("@wordpress/blocks"); var _jsxRuntime = require("react/jsx-runtime"); /** * WordPress dependencies */ function addActiveFormats(value, activeFormats) { if (activeFormats?.length) { let index = value.formats.length; while (index--) { value.formats[index] = [...activeFormats, ...(value.formats[index] || [])]; } } } /** * Get the multiline tag based on the multiline prop. * * @param {?(string|boolean)} multiline The multiline prop. * * @return {string | undefined} The multiline tag. */ function getMultilineTag(multiline) { if (multiline !== true && multiline !== 'p' && multiline !== 'li') { return; } return multiline === true ? 'p' : multiline; } function getAllowedFormats({ allowedFormats, disableFormats }) { if (disableFormats) { return getAllowedFormats.EMPTY_ARRAY; } return allowedFormats; } getAllowedFormats.EMPTY_ARRAY = []; /** * Creates a link from pasted URL. * Creates a paragraph block containing a link to the URL, and calls `onReplace`. * * @param {string} url The URL that could not be embedded. * @param {Function} onReplace Function to call with the created fallback block. */ function createLinkInParagraph(url, onReplace) { const link = /*#__PURE__*/(0, _jsxRuntime.jsx)("a", { href: url, children: url }); onReplace((0, _blocks.createBlock)('core/paragraph', { content: (0, _element.renderToString)(link) })); } //# sourceMappingURL=utils.js.map