Edit File by line
/home/barbar84/www/wp-inclu.../js/dist
File: blocks.js
// - Transformed: `true`
[5000] Fix | Delete
//
[5001] Fix | Delete
// <input disabled="disabled">
[5002] Fix | Delete
// - Value: `'disabled'`
[5003] Fix | Delete
// - Transformed: `true`
[5004] Fix | Delete
function (value) {
[5005] Fix | Delete
return value !== undefined;
[5006] Fix | Delete
}]);
[5007] Fix | Delete
};
[5008] Fix | Delete
/**
[5009] Fix | Delete
* Returns true if value is of the given JSON schema type, or false otherwise.
[5010] Fix | Delete
*
[5011] Fix | Delete
* @see http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.25
[5012] Fix | Delete
*
[5013] Fix | Delete
* @param {*} value Value to test.
[5014] Fix | Delete
* @param {string} type Type to test.
[5015] Fix | Delete
*
[5016] Fix | Delete
* @return {boolean} Whether value is of type.
[5017] Fix | Delete
*/
[5018] Fix | Delete
[5019] Fix | Delete
function isOfType(value, type) {
[5020] Fix | Delete
switch (type) {
[5021] Fix | Delete
case 'string':
[5022] Fix | Delete
return typeof value === 'string';
[5023] Fix | Delete
[5024] Fix | Delete
case 'boolean':
[5025] Fix | Delete
return typeof value === 'boolean';
[5026] Fix | Delete
[5027] Fix | Delete
case 'object':
[5028] Fix | Delete
return !!value && value.constructor === Object;
[5029] Fix | Delete
[5030] Fix | Delete
case 'null':
[5031] Fix | Delete
return value === null;
[5032] Fix | Delete
[5033] Fix | Delete
case 'array':
[5034] Fix | Delete
return Array.isArray(value);
[5035] Fix | Delete
[5036] Fix | Delete
case 'integer':
[5037] Fix | Delete
case 'number':
[5038] Fix | Delete
return typeof value === 'number';
[5039] Fix | Delete
}
[5040] Fix | Delete
[5041] Fix | Delete
return true;
[5042] Fix | Delete
}
[5043] Fix | Delete
/**
[5044] Fix | Delete
* Returns true if value is of an array of given JSON schema types, or false
[5045] Fix | Delete
* otherwise.
[5046] Fix | Delete
*
[5047] Fix | Delete
* @see http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.25
[5048] Fix | Delete
*
[5049] Fix | Delete
* @param {*} value Value to test.
[5050] Fix | Delete
* @param {string[]} types Types to test.
[5051] Fix | Delete
*
[5052] Fix | Delete
* @return {boolean} Whether value is of types.
[5053] Fix | Delete
*/
[5054] Fix | Delete
[5055] Fix | Delete
function isOfTypes(value, types) {
[5056] Fix | Delete
return types.some(function (type) {
[5057] Fix | Delete
return isOfType(value, type);
[5058] Fix | Delete
});
[5059] Fix | Delete
}
[5060] Fix | Delete
/**
[5061] Fix | Delete
* Returns true if value is valid per the given block attribute schema type
[5062] Fix | Delete
* definition, or false otherwise.
[5063] Fix | Delete
*
[5064] Fix | Delete
* @see https://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1.1
[5065] Fix | Delete
*
[5066] Fix | Delete
* @param {*} value Value to test.
[5067] Fix | Delete
* @param {?(Array<string>|string)} type Block attribute schema type.
[5068] Fix | Delete
*
[5069] Fix | Delete
* @return {boolean} Whether value is valid.
[5070] Fix | Delete
*/
[5071] Fix | Delete
[5072] Fix | Delete
function isValidByType(value, type) {
[5073] Fix | Delete
return type === undefined || isOfTypes(value, Object(external_lodash_["castArray"])(type));
[5074] Fix | Delete
}
[5075] Fix | Delete
/**
[5076] Fix | Delete
* Returns true if value is valid per the given block attribute schema enum
[5077] Fix | Delete
* definition, or false otherwise.
[5078] Fix | Delete
*
[5079] Fix | Delete
* @see https://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1.2
[5080] Fix | Delete
*
[5081] Fix | Delete
* @param {*} value Value to test.
[5082] Fix | Delete
* @param {?Array} enumSet Block attribute schema enum.
[5083] Fix | Delete
*
[5084] Fix | Delete
* @return {boolean} Whether value is valid.
[5085] Fix | Delete
*/
[5086] Fix | Delete
[5087] Fix | Delete
function isValidByEnum(value, enumSet) {
[5088] Fix | Delete
return !Array.isArray(enumSet) || enumSet.includes(value);
[5089] Fix | Delete
}
[5090] Fix | Delete
/**
[5091] Fix | Delete
* Returns true if the given attribute schema describes a value which may be
[5092] Fix | Delete
* an ambiguous string.
[5093] Fix | Delete
*
[5094] Fix | Delete
* Some sources are ambiguously serialized as strings, for which value casting
[5095] Fix | Delete
* is enabled. This is only possible when a singular type is assigned to the
[5096] Fix | Delete
* attribute schema, since the string ambiguity makes it impossible to know the
[5097] Fix | Delete
* correct type of multiple to which to cast.
[5098] Fix | Delete
*
[5099] Fix | Delete
* @param {Object} attributeSchema Attribute's schema.
[5100] Fix | Delete
*
[5101] Fix | Delete
* @return {boolean} Whether attribute schema defines an ambiguous string
[5102] Fix | Delete
* source.
[5103] Fix | Delete
*/
[5104] Fix | Delete
[5105] Fix | Delete
function isAmbiguousStringSource(attributeSchema) {
[5106] Fix | Delete
var source = attributeSchema.source,
[5107] Fix | Delete
type = attributeSchema.type;
[5108] Fix | Delete
var isStringSource = STRING_SOURCES.has(source);
[5109] Fix | Delete
var isSingleType = typeof type === 'string';
[5110] Fix | Delete
return isStringSource && isSingleType;
[5111] Fix | Delete
}
[5112] Fix | Delete
/**
[5113] Fix | Delete
* Returns an hpq matcher given a source object.
[5114] Fix | Delete
*
[5115] Fix | Delete
* @param {Object} sourceConfig Attribute Source object.
[5116] Fix | Delete
*
[5117] Fix | Delete
* @return {Function} A hpq Matcher.
[5118] Fix | Delete
*/
[5119] Fix | Delete
[5120] Fix | Delete
function matcherFromSource(sourceConfig) {
[5121] Fix | Delete
switch (sourceConfig.source) {
[5122] Fix | Delete
case 'attribute':
[5123] Fix | Delete
var matcher = attr(sourceConfig.selector, sourceConfig.attribute);
[5124] Fix | Delete
[5125] Fix | Delete
if (sourceConfig.type === 'boolean') {
[5126] Fix | Delete
matcher = parser_toBooleanAttributeMatcher(matcher);
[5127] Fix | Delete
}
[5128] Fix | Delete
[5129] Fix | Delete
return matcher;
[5130] Fix | Delete
[5131] Fix | Delete
case 'html':
[5132] Fix | Delete
return matchers_html(sourceConfig.selector, sourceConfig.multiline);
[5133] Fix | Delete
[5134] Fix | Delete
case 'text':
[5135] Fix | Delete
return es_text(sourceConfig.selector);
[5136] Fix | Delete
[5137] Fix | Delete
case 'children':
[5138] Fix | Delete
return children_matcher(sourceConfig.selector);
[5139] Fix | Delete
[5140] Fix | Delete
case 'node':
[5141] Fix | Delete
return node_matcher(sourceConfig.selector);
[5142] Fix | Delete
[5143] Fix | Delete
case 'query':
[5144] Fix | Delete
var subMatchers = Object(external_lodash_["mapValues"])(sourceConfig.query, matcherFromSource);
[5145] Fix | Delete
return query(sourceConfig.selector, subMatchers);
[5146] Fix | Delete
[5147] Fix | Delete
case 'tag':
[5148] Fix | Delete
return Object(external_lodash_["flow"])([prop(sourceConfig.selector, 'nodeName'), function (nodeName) {
[5149] Fix | Delete
return nodeName ? nodeName.toLowerCase() : undefined;
[5150] Fix | Delete
}]);
[5151] Fix | Delete
[5152] Fix | Delete
default:
[5153] Fix | Delete
// eslint-disable-next-line no-console
[5154] Fix | Delete
console.error("Unknown source type \"".concat(sourceConfig.source, "\""));
[5155] Fix | Delete
}
[5156] Fix | Delete
}
[5157] Fix | Delete
/**
[5158] Fix | Delete
* Given a block's raw content and an attribute's schema returns the attribute's
[5159] Fix | Delete
* value depending on its source.
[5160] Fix | Delete
*
[5161] Fix | Delete
* @param {string} innerHTML Block's raw content.
[5162] Fix | Delete
* @param {Object} attributeSchema Attribute's schema.
[5163] Fix | Delete
*
[5164] Fix | Delete
* @return {*} Attribute value.
[5165] Fix | Delete
*/
[5166] Fix | Delete
[5167] Fix | Delete
function parseWithAttributeSchema(innerHTML, attributeSchema) {
[5168] Fix | Delete
return es_parse(innerHTML, matcherFromSource(attributeSchema));
[5169] Fix | Delete
}
[5170] Fix | Delete
/**
[5171] Fix | Delete
* Given an attribute key, an attribute's schema, a block's raw content and the
[5172] Fix | Delete
* commentAttributes returns the attribute value depending on its source
[5173] Fix | Delete
* definition of the given attribute key.
[5174] Fix | Delete
*
[5175] Fix | Delete
* @param {string} attributeKey Attribute key.
[5176] Fix | Delete
* @param {Object} attributeSchema Attribute's schema.
[5177] Fix | Delete
* @param {string} innerHTML Block's raw content.
[5178] Fix | Delete
* @param {Object} commentAttributes Block's comment attributes.
[5179] Fix | Delete
*
[5180] Fix | Delete
* @return {*} Attribute value.
[5181] Fix | Delete
*/
[5182] Fix | Delete
[5183] Fix | Delete
function getBlockAttribute(attributeKey, attributeSchema, innerHTML, commentAttributes) {
[5184] Fix | Delete
var type = attributeSchema.type,
[5185] Fix | Delete
enumSet = attributeSchema.enum;
[5186] Fix | Delete
var value;
[5187] Fix | Delete
[5188] Fix | Delete
switch (attributeSchema.source) {
[5189] Fix | Delete
// An undefined source means that it's an attribute serialized to the
[5190] Fix | Delete
// block's "comment".
[5191] Fix | Delete
case undefined:
[5192] Fix | Delete
value = commentAttributes ? commentAttributes[attributeKey] : undefined;
[5193] Fix | Delete
break;
[5194] Fix | Delete
[5195] Fix | Delete
case 'attribute':
[5196] Fix | Delete
case 'property':
[5197] Fix | Delete
case 'html':
[5198] Fix | Delete
case 'text':
[5199] Fix | Delete
case 'children':
[5200] Fix | Delete
case 'node':
[5201] Fix | Delete
case 'query':
[5202] Fix | Delete
case 'tag':
[5203] Fix | Delete
value = parseWithAttributeSchema(innerHTML, attributeSchema);
[5204] Fix | Delete
break;
[5205] Fix | Delete
}
[5206] Fix | Delete
[5207] Fix | Delete
if (!isValidByType(value, type) || !isValidByEnum(value, enumSet)) {
[5208] Fix | Delete
// Reject the value if it is not valid. Reverting to the undefined
[5209] Fix | Delete
// value ensures the default is respected, if applicable.
[5210] Fix | Delete
value = undefined;
[5211] Fix | Delete
}
[5212] Fix | Delete
[5213] Fix | Delete
if (value === undefined) {
[5214] Fix | Delete
return attributeSchema.default;
[5215] Fix | Delete
}
[5216] Fix | Delete
[5217] Fix | Delete
return value;
[5218] Fix | Delete
}
[5219] Fix | Delete
/**
[5220] Fix | Delete
* Returns the block attributes of a registered block node given its type.
[5221] Fix | Delete
*
[5222] Fix | Delete
* @param {string|Object} blockTypeOrName Block type or name.
[5223] Fix | Delete
* @param {string} innerHTML Raw block content.
[5224] Fix | Delete
* @param {?Object} attributes Known block attributes (from delimiters).
[5225] Fix | Delete
*
[5226] Fix | Delete
* @return {Object} All block attributes.
[5227] Fix | Delete
*/
[5228] Fix | Delete
[5229] Fix | Delete
function getBlockAttributes(blockTypeOrName, innerHTML) {
[5230] Fix | Delete
var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
[5231] Fix | Delete
var blockType = normalizeBlockType(blockTypeOrName);
[5232] Fix | Delete
var blockAttributes = Object(external_lodash_["mapValues"])(blockType.attributes, function (attributeSchema, attributeKey) {
[5233] Fix | Delete
return getBlockAttribute(attributeKey, attributeSchema, innerHTML, attributes);
[5234] Fix | Delete
});
[5235] Fix | Delete
return Object(external_wp_hooks_["applyFilters"])('blocks.getBlockAttributes', blockAttributes, blockType, innerHTML, attributes);
[5236] Fix | Delete
}
[5237] Fix | Delete
/**
[5238] Fix | Delete
* Given a block object, returns a new copy of the block with any applicable
[5239] Fix | Delete
* deprecated migrations applied, or the original block if it was both valid
[5240] Fix | Delete
* and no eligible migrations exist.
[5241] Fix | Delete
*
[5242] Fix | Delete
* @param {WPBlock} block Original block object.
[5243] Fix | Delete
* @param {Object} parsedAttributes Attributes as parsed from the initial
[5244] Fix | Delete
* block markup.
[5245] Fix | Delete
*
[5246] Fix | Delete
* @return {WPBlock} Migrated block object.
[5247] Fix | Delete
*/
[5248] Fix | Delete
[5249] Fix | Delete
function getMigratedBlock(block, parsedAttributes) {
[5250] Fix | Delete
var blockType = registration_getBlockType(block.name);
[5251] Fix | Delete
var deprecatedDefinitions = blockType.deprecated; // Bail early if there are no registered deprecations to be handled.
[5252] Fix | Delete
[5253] Fix | Delete
if (!deprecatedDefinitions || !deprecatedDefinitions.length) {
[5254] Fix | Delete
return block;
[5255] Fix | Delete
}
[5256] Fix | Delete
[5257] Fix | Delete
var _block = block,
[5258] Fix | Delete
originalContent = _block.originalContent,
[5259] Fix | Delete
innerBlocks = _block.innerBlocks; // By design, blocks lack any sort of version tracking. Instead, to process
[5260] Fix | Delete
// outdated content the system operates a queue out of all the defined
[5261] Fix | Delete
// attribute shapes and tries each definition until the input produces a
[5262] Fix | Delete
// valid result. This mechanism seeks to avoid polluting the user-space with
[5263] Fix | Delete
// machine-specific code. An invalid block is thus a block that could not be
[5264] Fix | Delete
// matched successfully with any of the registered deprecation definitions.
[5265] Fix | Delete
[5266] Fix | Delete
for (var i = 0; i < deprecatedDefinitions.length; i++) {
[5267] Fix | Delete
// A block can opt into a migration even if the block is valid by
[5268] Fix | Delete
// defining `isEligible` on its deprecation. If the block is both valid
[5269] Fix | Delete
// and does not opt to migrate, skip.
[5270] Fix | Delete
var _deprecatedDefinition = deprecatedDefinitions[i].isEligible,
[5271] Fix | Delete
isEligible = _deprecatedDefinition === void 0 ? external_lodash_["stubFalse"] : _deprecatedDefinition;
[5272] Fix | Delete
[5273] Fix | Delete
if (block.isValid && !isEligible(parsedAttributes, innerBlocks)) {
[5274] Fix | Delete
continue;
[5275] Fix | Delete
} // Block type properties which could impact either serialization or
[5276] Fix | Delete
// parsing are not considered in the deprecated block type by default,
[5277] Fix | Delete
// and must be explicitly provided.
[5278] Fix | Delete
[5279] Fix | Delete
[5280] Fix | Delete
var deprecatedBlockType = Object.assign(Object(external_lodash_["omit"])(blockType, DEPRECATED_ENTRY_KEYS), deprecatedDefinitions[i]);
[5281] Fix | Delete
var migratedAttributes = getBlockAttributes(deprecatedBlockType, originalContent, parsedAttributes); // Ignore the deprecation if it produces a block which is not valid.
[5282] Fix | Delete
[5283] Fix | Delete
var _getBlockContentValid = getBlockContentValidationResult(deprecatedBlockType, migratedAttributes, originalContent),
[5284] Fix | Delete
isValid = _getBlockContentValid.isValid,
[5285] Fix | Delete
validationIssues = _getBlockContentValid.validationIssues; // An invalid block does not imply incorrect HTML but the fact block
[5286] Fix | Delete
// source information could be lost on reserialization.
[5287] Fix | Delete
[5288] Fix | Delete
[5289] Fix | Delete
if (!isValid) {
[5290] Fix | Delete
block = parser_objectSpread(parser_objectSpread({}, block), {}, {
[5291] Fix | Delete
validationIssues: [].concat(Object(toConsumableArray["a" /* default */])(Object(external_lodash_["get"])(block, 'validationIssues', [])), Object(toConsumableArray["a" /* default */])(validationIssues))
[5292] Fix | Delete
});
[5293] Fix | Delete
continue;
[5294] Fix | Delete
}
[5295] Fix | Delete
[5296] Fix | Delete
var migratedInnerBlocks = innerBlocks; // A block may provide custom behavior to assign new attributes and/or
[5297] Fix | Delete
// inner blocks.
[5298] Fix | Delete
[5299] Fix | Delete
var migrate = deprecatedBlockType.migrate;
[5300] Fix | Delete
[5301] Fix | Delete
if (migrate) {
[5302] Fix | Delete
var _castArray = Object(external_lodash_["castArray"])(migrate(migratedAttributes, innerBlocks));
[5303] Fix | Delete
[5304] Fix | Delete
var _castArray2 = Object(slicedToArray["a" /* default */])(_castArray, 2);
[5305] Fix | Delete
[5306] Fix | Delete
var _castArray2$ = _castArray2[0];
[5307] Fix | Delete
migratedAttributes = _castArray2$ === void 0 ? parsedAttributes : _castArray2$;
[5308] Fix | Delete
var _castArray2$2 = _castArray2[1];
[5309] Fix | Delete
migratedInnerBlocks = _castArray2$2 === void 0 ? innerBlocks : _castArray2$2;
[5310] Fix | Delete
}
[5311] Fix | Delete
[5312] Fix | Delete
block = parser_objectSpread(parser_objectSpread({}, block), {}, {
[5313] Fix | Delete
attributes: migratedAttributes,
[5314] Fix | Delete
innerBlocks: migratedInnerBlocks,
[5315] Fix | Delete
isValid: true
[5316] Fix | Delete
});
[5317] Fix | Delete
}
[5318] Fix | Delete
[5319] Fix | Delete
return block;
[5320] Fix | Delete
}
[5321] Fix | Delete
/**
[5322] Fix | Delete
* Convert legacy blocks to their canonical form. This function is used
[5323] Fix | Delete
* both in the parser level for previous content and to convert such blocks
[5324] Fix | Delete
* used in Custom Post Types templates.
[5325] Fix | Delete
*
[5326] Fix | Delete
* @param {string} name The block's name
[5327] Fix | Delete
* @param {Object} attributes The block's attributes
[5328] Fix | Delete
*
[5329] Fix | Delete
* @return {Object} The block's name and attributes, changed accordingly if a match was found
[5330] Fix | Delete
*/
[5331] Fix | Delete
[5332] Fix | Delete
function convertLegacyBlocks(name, attributes) {
[5333] Fix | Delete
var newAttributes = parser_objectSpread({}, attributes); // Convert 'core/cover-image' block in existing content to 'core/cover'.
[5334] Fix | Delete
[5335] Fix | Delete
[5336] Fix | Delete
if ('core/cover-image' === name) {
[5337] Fix | Delete
name = 'core/cover';
[5338] Fix | Delete
} // Convert 'core/text' blocks in existing content to 'core/paragraph'.
[5339] Fix | Delete
[5340] Fix | Delete
[5341] Fix | Delete
if ('core/text' === name || 'core/cover-text' === name) {
[5342] Fix | Delete
name = 'core/paragraph';
[5343] Fix | Delete
} // Convert derivative blocks such as 'core/social-link-wordpress' to the
[5344] Fix | Delete
// canonical form 'core/social-link'.
[5345] Fix | Delete
[5346] Fix | Delete
[5347] Fix | Delete
if (name && name.indexOf('core/social-link-') === 0) {
[5348] Fix | Delete
// Capture `social-link-wordpress` into `{"service":"wordpress"}`
[5349] Fix | Delete
newAttributes.service = name.substring(17);
[5350] Fix | Delete
name = 'core/social-link';
[5351] Fix | Delete
} // Convert derivative blocks such as 'core-embed/instagram' to the
[5352] Fix | Delete
// canonical form 'core/embed'.
[5353] Fix | Delete
[5354] Fix | Delete
[5355] Fix | Delete
if (name && name.indexOf('core-embed/') === 0) {
[5356] Fix | Delete
// Capture `core-embed/instagram` into `{"providerNameSlug":"instagram"}`
[5357] Fix | Delete
var providerSlug = name.substring(11);
[5358] Fix | Delete
var deprecated = {
[5359] Fix | Delete
speaker: 'speaker-deck',
[5360] Fix | Delete
polldaddy: 'crowdsignal'
[5361] Fix | Delete
};
[5362] Fix | Delete
newAttributes.providerNameSlug = providerSlug in deprecated ? deprecated[providerSlug] : providerSlug; // this is needed as the `responsive` attribute was passed
[5363] Fix | Delete
// in a different way before the refactoring to block variations
[5364] Fix | Delete
[5365] Fix | Delete
if (!['amazon-kindle', 'wordpress'].includes(providerSlug)) {
[5366] Fix | Delete
newAttributes.responsive = true;
[5367] Fix | Delete
}
[5368] Fix | Delete
[5369] Fix | Delete
name = 'core/embed';
[5370] Fix | Delete
}
[5371] Fix | Delete
[5372] Fix | Delete
return {
[5373] Fix | Delete
name: name,
[5374] Fix | Delete
attributes: newAttributes
[5375] Fix | Delete
};
[5376] Fix | Delete
}
[5377] Fix | Delete
/**
[5378] Fix | Delete
* Creates a block with fallback to the unknown type handler.
[5379] Fix | Delete
*
[5380] Fix | Delete
* @param {Object} blockNode Parsed block node.
[5381] Fix | Delete
*
[5382] Fix | Delete
* @return {?Object} An initialized block object (if possible).
[5383] Fix | Delete
*/
[5384] Fix | Delete
[5385] Fix | Delete
function createBlockWithFallback(blockNode) {
[5386] Fix | Delete
var originalName = blockNode.blockName; // The fundamental structure of a blocktype includes its attributes, inner
[5387] Fix | Delete
// blocks, and inner HTML. It is important to distinguish inner blocks from
[5388] Fix | Delete
// the HTML content of the block as only the latter is relevant for block
[5389] Fix | Delete
// validation and edit operations.
[5390] Fix | Delete
[5391] Fix | Delete
var attributes = blockNode.attrs,
[5392] Fix | Delete
_blockNode$innerBlock = blockNode.innerBlocks,
[5393] Fix | Delete
innerBlocks = _blockNode$innerBlock === void 0 ? [] : _blockNode$innerBlock,
[5394] Fix | Delete
innerHTML = blockNode.innerHTML;
[5395] Fix | Delete
var innerContent = blockNode.innerContent; // Blocks that don't have a registered handler are considered freeform.
[5396] Fix | Delete
[5397] Fix | Delete
var freeformContentFallbackBlock = getFreeformContentHandlerName();
[5398] Fix | Delete
var unregisteredFallbackBlock = getUnregisteredTypeHandlerName() || freeformContentFallbackBlock;
[5399] Fix | Delete
attributes = attributes || {}; // Trim content to avoid creation of intermediary freeform segments.
[5400] Fix | Delete
[5401] Fix | Delete
innerHTML = innerHTML.trim(); // Use type from block content if available. Otherwise, default to the
[5402] Fix | Delete
// freeform content fallback.
[5403] Fix | Delete
[5404] Fix | Delete
var name = originalName || freeformContentFallbackBlock;
[5405] Fix | Delete
[5406] Fix | Delete
var _convertLegacyBlocks = convertLegacyBlocks(name, attributes);
[5407] Fix | Delete
[5408] Fix | Delete
name = _convertLegacyBlocks.name;
[5409] Fix | Delete
attributes = _convertLegacyBlocks.attributes;
[5410] Fix | Delete
[5411] Fix | Delete
// Fallback content may be upgraded from classic content expecting implicit
[5412] Fix | Delete
// automatic paragraphs, so preserve them. Assumes wpautop is idempotent,
[5413] Fix | Delete
// meaning there are no negative consequences to repeated autop calls.
[5414] Fix | Delete
if (name === freeformContentFallbackBlock) {
[5415] Fix | Delete
innerHTML = Object(external_wp_autop_["autop"])(innerHTML).trim();
[5416] Fix | Delete
} // Try finding the type for known block name, else fall back again.
[5417] Fix | Delete
[5418] Fix | Delete
[5419] Fix | Delete
var blockType = registration_getBlockType(name);
[5420] Fix | Delete
[5421] Fix | Delete
if (!blockType) {
[5422] Fix | Delete
// Since the constituents of the block node are extracted at the start
[5423] Fix | Delete
// of the present function, construct a new object rather than reuse
[5424] Fix | Delete
// `blockNode`.
[5425] Fix | Delete
var reconstitutedBlockNode = {
[5426] Fix | Delete
attrs: attributes,
[5427] Fix | Delete
blockName: originalName,
[5428] Fix | Delete
innerBlocks: innerBlocks,
[5429] Fix | Delete
innerContent: innerContent
[5430] Fix | Delete
}; // Preserve undelimited content for use by the unregistered type
[5431] Fix | Delete
// handler. A block node's `innerHTML` isn't enough, as that field only
[5432] Fix | Delete
// carries the block's own HTML and not its nested blocks.
[5433] Fix | Delete
[5434] Fix | Delete
var originalUndelimitedContent = serializeBlockNode(reconstitutedBlockNode, {
[5435] Fix | Delete
isCommentDelimited: false
[5436] Fix | Delete
}); // Preserve full block content for use by the unregistered type
[5437] Fix | Delete
// handler, block boundaries included.
[5438] Fix | Delete
[5439] Fix | Delete
var originalContent = serializeBlockNode(reconstitutedBlockNode, {
[5440] Fix | Delete
isCommentDelimited: true
[5441] Fix | Delete
}); // If detected as a block which is not registered, preserve comment
[5442] Fix | Delete
// delimiters in content of unregistered type handler.
[5443] Fix | Delete
[5444] Fix | Delete
if (name) {
[5445] Fix | Delete
innerHTML = originalContent;
[5446] Fix | Delete
}
[5447] Fix | Delete
[5448] Fix | Delete
name = unregisteredFallbackBlock;
[5449] Fix | Delete
attributes = {
[5450] Fix | Delete
originalName: originalName,
[5451] Fix | Delete
originalContent: originalContent,
[5452] Fix | Delete
originalUndelimitedContent: originalUndelimitedContent
[5453] Fix | Delete
};
[5454] Fix | Delete
blockType = registration_getBlockType(name);
[5455] Fix | Delete
} // Coerce inner blocks from parsed form to canonical form.
[5456] Fix | Delete
[5457] Fix | Delete
[5458] Fix | Delete
innerBlocks = innerBlocks.map(createBlockWithFallback); // Remove `undefined` innerBlocks.
[5459] Fix | Delete
//
[5460] Fix | Delete
// This is a temporary fix to prevent unrecoverable TypeErrors when handling unexpectedly
[5461] Fix | Delete
// empty freeform block nodes. See https://github.com/WordPress/gutenberg/pull/17164.
[5462] Fix | Delete
[5463] Fix | Delete
innerBlocks = innerBlocks.filter(function (innerBlock) {
[5464] Fix | Delete
return innerBlock;
[5465] Fix | Delete
});
[5466] Fix | Delete
var isFallbackBlock = name === freeformContentFallbackBlock || name === unregisteredFallbackBlock; // Include in set only if type was determined.
[5467] Fix | Delete
[5468] Fix | Delete
if (!blockType || !innerHTML && isFallbackBlock) {
[5469] Fix | Delete
return;
[5470] Fix | Delete
}
[5471] Fix | Delete
[5472] Fix | Delete
var block = createBlock(name, getBlockAttributes(blockType, innerHTML, attributes), innerBlocks); // Block validation assumes an idempotent operation from source block to serialized block
[5473] Fix | Delete
// provided there are no changes in attributes. The validation procedure thus compares the
[5474] Fix | Delete
// provided source value with the serialized output before there are any modifications to
[5475] Fix | Delete
// the block. When both match, the block is marked as valid.
[5476] Fix | Delete
[5477] Fix | Delete
if (!isFallbackBlock) {
[5478] Fix | Delete
var _getBlockContentValid2 = getBlockContentValidationResult(blockType, block.attributes, innerHTML),
[5479] Fix | Delete
isValid = _getBlockContentValid2.isValid,
[5480] Fix | Delete
validationIssues = _getBlockContentValid2.validationIssues;
[5481] Fix | Delete
[5482] Fix | Delete
block.isValid = isValid;
[5483] Fix | Delete
block.validationIssues = validationIssues;
[5484] Fix | Delete
} // Preserve original content for future use in case the block is parsed
[5485] Fix | Delete
// as invalid, or future serialization attempt results in an error.
[5486] Fix | Delete
[5487] Fix | Delete
[5488] Fix | Delete
block.originalContent = block.originalContent || innerHTML; // Ensure all necessary migrations are applied to the block.
[5489] Fix | Delete
[5490] Fix | Delete
block = getMigratedBlock(block, attributes);
[5491] Fix | Delete
[5492] Fix | Delete
if (block.validationIssues && block.validationIssues.length > 0) {
[5493] Fix | Delete
if (block.isValid) {
[5494] Fix | Delete
// eslint-disable-next-line no-console
[5495] Fix | Delete
console.info('Block successfully updated for `%s` (%o).\n\nNew content generated by `save` function:\n\n%s\n\nContent retrieved from post body:\n\n%s', blockType.name, blockType, getSaveContent(blockType, block.attributes), block.originalContent);
[5496] Fix | Delete
} else {
[5497] Fix | Delete
block.validationIssues.forEach(function (_ref) {
[5498] Fix | Delete
var log = _ref.log,
[5499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function