UNPKG

@gechiui/block-editor

Version:
99 lines (78 loc) 2.47 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.addActiveFormats = addActiveFormats; exports.createLinkInParagraph = createLinkInParagraph; exports.getAllowedFormats = getAllowedFormats; exports.getMultilineTag = getMultilineTag; exports.isShortcode = void 0; var _element = require("@gechiui/element"); var _shortcode = require("@gechiui/shortcode"); var _deprecated = _interopRequireDefault(require("@gechiui/deprecated")); var _blocks = require("@gechiui/blocks"); /** * GeChiUI dependencies */ 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. */ function getMultilineTag(multiline) { if (multiline !== true && multiline !== 'p' && multiline !== 'li') { return; } return multiline === true ? 'p' : multiline; } function getAllowedFormats(_ref) { let { allowedFormats, formattingControls, disableFormats } = _ref; if (disableFormats) { return getAllowedFormats.EMPTY_ARRAY; } if (!allowedFormats && !formattingControls) { return; } if (allowedFormats) { return allowedFormats; } (0, _deprecated.default)('gc.blockEditor.RichText formattingControls prop', { since: '5.4', alternative: 'allowedFormats' }); return formattingControls.map(name => `core/${name}`); } getAllowedFormats.EMPTY_ARRAY = []; const isShortcode = text => (0, _shortcode.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. */ exports.isShortcode = isShortcode; function createLinkInParagraph(url, onReplace) { const link = (0, _element.createElement)("a", { href: url }, url); onReplace((0, _blocks.createBlock)('core/paragraph', { content: (0, _element.renderToString)(link) })); } //# sourceMappingURL=utils.js.map