UNPKG

@gechiui/block-editor

Version:
77 lines (68 loc) 2.03 kB
import { createElement } from "@gechiui/element"; /** * GeChiUI dependencies */ import { regexp } from '@gechiui/shortcode'; import deprecated from '@gechiui/deprecated'; import { renderToString } from '@gechiui/element'; import { createBlock } from '@gechiui/blocks'; export function addActiveFormats(value, activeFormats) { if (activeFormats !== null && activeFormats !== void 0 && 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} The multiline tag. */ export function getMultilineTag(multiline) { if (multiline !== true && multiline !== 'p' && multiline !== 'li') { return; } return multiline === true ? 'p' : multiline; } export function getAllowedFormats(_ref) { let { allowedFormats, formattingControls, disableFormats } = _ref; if (disableFormats) { return getAllowedFormats.EMPTY_ARRAY; } if (!allowedFormats && !formattingControls) { return; } if (allowedFormats) { return allowedFormats; } deprecated('gc.blockEditor.RichText formattingControls prop', { since: '5.4', alternative: 'allowedFormats' }); return formattingControls.map(name => `core/${name}`); } getAllowedFormats.EMPTY_ARRAY = []; export const isShortcode = text => regexp('.*').test(text); /** * 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. */ export function createLinkInParagraph(url, onReplace) { const link = createElement("a", { href: url }, url); onReplace(createBlock('core/paragraph', { content: renderToString(link) })); } //# sourceMappingURL=utils.js.map