@wordpress/core-data
Version:
Access to and manipulation of core WordPress entities.
8 lines (7 loc) • 1.74 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/footnotes/get-footnotes-order.js"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport getRichTextValuesCached from './get-rich-text-values-cached';\n\nconst cache = new WeakMap();\n\nfunction getBlockFootnotesOrder( block ) {\n\tif ( ! cache.has( block ) ) {\n\t\tconst order = [];\n\t\tfor ( const value of getRichTextValuesCached( block ) ) {\n\t\t\tif ( ! value ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// replacements is a sparse array, use forEach to skip empty slots.\n\t\t\tvalue.replacements.forEach( ( { type, attributes } ) => {\n\t\t\t\tif ( type === 'core/footnote' ) {\n\t\t\t\t\torder.push( attributes[ 'data-fn' ] );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t\tcache.set( block, order );\n\t}\n\n\treturn cache.get( block );\n}\n\nexport default function getFootnotesOrder( blocks ) {\n\t// We can only separate getting order from blocks at the root level. For\n\t// deeper inner blocks, this will not work since it's possible to have both\n\t// inner blocks and block attributes, so order needs to be computed from the\n\t// Edit functions as a whole.\n\treturn blocks.flatMap( getBlockFootnotesOrder );\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yCAAoC;AAEpC,IAAM,QAAQ,oBAAI,QAAQ;AAE1B,SAAS,uBAAwB,OAAQ;AACxC,MAAK,CAAE,MAAM,IAAK,KAAM,GAAI;AAC3B,UAAM,QAAQ,CAAC;AACf,eAAY,aAAS,mCAAAA,SAAyB,KAAM,GAAI;AACvD,UAAK,CAAE,OAAQ;AACd;AAAA,MACD;AAGA,YAAM,aAAa,QAAS,CAAE,EAAE,MAAM,WAAW,MAAO;AACvD,YAAK,SAAS,iBAAkB;AAC/B,gBAAM,KAAM,WAAY,SAAU,CAAE;AAAA,QACrC;AAAA,MACD,CAAE;AAAA,IACH;AACA,UAAM,IAAK,OAAO,KAAM;AAAA,EACzB;AAEA,SAAO,MAAM,IAAK,KAAM;AACzB;AAEe,SAAR,kBAAoC,QAAS;AAKnD,SAAO,OAAO,QAAS,sBAAuB;AAC/C;",
"names": ["getRichTextValuesCached"]
}