@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
43 lines (40 loc) • 1.3 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getFootnotesOrder;
var _getRichTextValuesCached = _interopRequireDefault(require("./get-rich-text-values-cached"));
/**
* Internal dependencies
*/
const cache = new WeakMap();
function getBlockFootnotesOrder(block) {
if (!cache.has(block)) {
const order = [];
for (const value of (0, _getRichTextValuesCached.default)(block)) {
if (!value) {
continue;
}
// replacements is a sparse array, use forEach to skip empty slots.
value.replacements.forEach(({
type,
attributes
}) => {
if (type === 'core/footnote') {
order.push(attributes['data-fn']);
}
});
}
cache.set(block, order);
}
return cache.get(block);
}
function getFootnotesOrder(blocks) {
// We can only separate getting order from blocks at the root level. For
// deeper inner blocks, this will not work since it's possible to have both
// inner blocks and block attributes, so order needs to be computed from the
// Edit functions as a whole.
return blocks.flatMap(getBlockFootnotesOrder);
}
//# sourceMappingURL=get-footnotes-order.js.map
;