@wordpress/core-data 7.16.0 → 7.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/actions.js +0 -1
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +0 -1
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +0 -1
- package/build/batch/default-processor.js.map +1 -1
- package/build/dynamic-entities.js.map +1 -1
- package/build/entities.js +0 -1
- package/build/entities.js.map +1 -1
- package/build/entity-types/index.js.map +1 -1
- package/build/entity-types/term.js +6 -0
- package/build/entity-types/term.js.map +1 -0
- package/build/fetch/__experimental-fetch-link-suggestions.js +0 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/index.js +0 -1
- package/build/fetch/index.js.map +1 -1
- package/build/footnotes/get-footnotes-order.js +0 -1
- package/build/footnotes/get-footnotes-order.js.map +1 -1
- package/build/footnotes/index.js +0 -1
- package/build/footnotes/index.js.map +1 -1
- package/build/index.js +0 -1
- package/build/index.js.map +1 -1
- package/build/locks/reducer.js +0 -1
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/utils.js +0 -1
- package/build/locks/utils.js.map +1 -1
- package/build/private-selectors.js +0 -1
- package/build/private-selectors.js.map +1 -1
- package/build/queried-data/get-query-parts.js +0 -1
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/reducer.js +0 -1
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +0 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +0 -1
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +0 -1
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +0 -1
- package/build/selectors.js.map +1 -1
- package/build/utils/get-nested-value.js +0 -1
- package/build/utils/get-nested-value.js.map +1 -1
- package/build/utils/set-nested-value.js +0 -1
- package/build/utils/set-nested-value.js.map +1 -1
- package/build/utils/user-permissions.js +0 -1
- package/build/utils/user-permissions.js.map +1 -1
- package/build-module/actions.js +0 -1
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +0 -1
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +0 -1
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/dynamic-entities.js.map +1 -1
- package/build-module/entities.js +0 -1
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-types/index.js.map +1 -1
- package/build-module/entity-types/term.js +2 -0
- package/build-module/entity-types/term.js.map +1 -0
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +0 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/index.js +0 -1
- package/build-module/fetch/index.js.map +1 -1
- package/build-module/footnotes/get-footnotes-order.js +0 -1
- package/build-module/footnotes/get-footnotes-order.js.map +1 -1
- package/build-module/footnotes/index.js +0 -1
- package/build-module/footnotes/index.js.map +1 -1
- package/build-module/index.js +0 -1
- package/build-module/index.js.map +1 -1
- package/build-module/locks/reducer.js +0 -1
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/utils.js +0 -1
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/private-selectors.js +0 -1
- package/build-module/private-selectors.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +0 -1
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/reducer.js +0 -1
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +0 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +0 -1
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +0 -1
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +0 -1
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/get-nested-value.js +0 -1
- package/build-module/utils/get-nested-value.js.map +1 -1
- package/build-module/utils/set-nested-value.js +0 -1
- package/build-module/utils/set-nested-value.js.map +1 -1
- package/build-module/utils/user-permissions.js +0 -1
- package/build-module/utils/user-permissions.js.map +1 -1
- package/build-types/dynamic-entities.d.ts +1 -0
- package/build-types/dynamic-entities.d.ts.map +1 -1
- package/build-types/entity-types/index.d.ts +3 -2
- package/build-types/entity-types/index.d.ts.map +1 -1
- package/build-types/entity-types/term.d.ts +49 -0
- package/build-types/entity-types/term.d.ts.map +1 -0
- package/build-types/index.d.ts +10 -0
- package/build-types/index.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/dynamic-entities.ts +1 -0
- package/src/entity-types/index.ts +3 -0
- package/src/entity-types/term.ts +57 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_apiFetch","_interopRequireDefault","require","_url","_htmlEntities","_i18n","fetchLinkSuggestions","search","searchOptions","editorSettings","searchOptionsToUse","isInitialSuggestions","initialSuggestionsSearchOptions","type","subtype","page","perPage","disablePostFormats","queries","push","apiFetch","path","addQueryArgs","per_page","then","results","map","result","id","url","title","decodeEntities","__","kind","catch","source_url","rendered","responses","Promise","all","flat","filter","sortResults","slice","searchTokens","tokenize","scores","titleTokens","exactMatchingTokens","titleToken","some","searchToken","subMatchingTokens","includes","exactMatchScore","length","subMatchScore","sort","a","b","text","toLowerCase","match"],"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\n\nexport type SearchOptions = {\n\t/**\n\t * Displays initial search suggestions, when true.\n\t */\n\tisInitialSuggestions?: boolean;\n\t/**\n\t * Search options for initial suggestions.\n\t */\n\tinitialSuggestionsSearchOptions?: Omit<\n\t\tSearchOptions,\n\t\t'isInitialSuggestions' | 'initialSuggestionsSearchOptions'\n\t>;\n\t/**\n\t * Filters by search type.\n\t */\n\ttype?: 'attachment' | 'post' | 'term' | 'post-format';\n\t/**\n\t * Slug of the post-type or taxonomy.\n\t */\n\tsubtype?: string;\n\t/**\n\t * Which page of results to return.\n\t */\n\tpage?: number;\n\t/**\n\t * Search results per page.\n\t */\n\tperPage?: number;\n};\n\nexport type EditorSettings = {\n\t/**\n\t * Disables post formats, when true.\n\t */\n\tdisablePostFormats?: boolean;\n};\n\ntype SearchAPIResult = {\n\tid: number;\n\ttitle: string;\n\turl: string;\n\ttype: string;\n\tsubtype: string;\n};\n\ntype MediaAPIResult = {\n\tid: number;\n\ttitle: { rendered: string };\n\tsource_url: string;\n\ttype: string;\n};\n\nexport type SearchResult = {\n\t/**\n\t * Post or term id.\n\t */\n\tid: number;\n\t/**\n\t * Link url.\n\t */\n\turl: string;\n\t/**\n\t * Title of the link.\n\t */\n\ttitle: string;\n\t/**\n\t * The taxonomy or post type slug or type URL.\n\t */\n\ttype: string;\n\t/**\n\t * Link kind of post-type or taxonomy\n\t */\n\tkind?: string;\n};\n\n/**\n * Fetches link suggestions from the WordPress API.\n *\n * WordPress does not support searching multiple tables at once, e.g. posts and terms, so we\n * perform multiple queries at the same time and then merge the results together.\n *\n * @param search\n * @param searchOptions\n * @param editorSettings\n *\n * @example\n * ```js\n * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchLinkSuggestions = (\n * search,\n * searchOptions\n * ) => fetchLinkSuggestions( search, searchOptions, settings );\n * ```\n */\nexport default async function fetchLinkSuggestions(\n\tsearch: string,\n\tsearchOptions: SearchOptions = {},\n\teditorSettings: EditorSettings = {}\n): Promise< SearchResult[] > {\n\tconst searchOptionsToUse =\n\t\tsearchOptions.isInitialSuggestions &&\n\t\tsearchOptions.initialSuggestionsSearchOptions\n\t\t\t? {\n\t\t\t\t\t...searchOptions,\n\t\t\t\t\t...searchOptions.initialSuggestionsSearchOptions,\n\t\t\t }\n\t\t\t: searchOptions;\n\n\tconst {\n\t\ttype,\n\t\tsubtype,\n\t\tpage,\n\t\tperPage = searchOptions.isInitialSuggestions ? 3 : 20,\n\t} = searchOptionsToUse;\n\n\tconst { disablePostFormats = false } = editorSettings;\n\n\tconst queries: Promise< SearchResult[] >[] = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'post-type',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'term' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'term',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'taxonomy',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post-format',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'taxonomy',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< MediaAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.source_url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title.rendered || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.type,\n\t\t\t\t\t\t\tkind: 'media',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tconst responses = await Promise.all( queries );\n\n\tlet results = responses.flat();\n\tresults = results.filter( ( result ) => !! result.id );\n\tresults = sortResults( results, search );\n\tresults = results.slice( 0, perPage );\n\treturn results;\n}\n\n/**\n * Sort search results by relevance to the given query.\n *\n * Sorting is necessary as we're querying multiple endpoints and merging the results. For example\n * a taxonomy title might be more relevant than a post title, but by default taxonomy results will\n * be ordered after all the (potentially irrelevant) post results.\n *\n * We sort by scoring each result, where the score is the number of tokens in the title that are\n * also in the search query, divided by the total number of tokens in the title. This gives us a\n * score between 0 and 1, where 1 is a perfect match.\n *\n * @param results\n * @param search\n */\nexport function sortResults( results: SearchResult[], search: string ) {\n\tconst searchTokens = tokenize( search );\n\n\tconst scores = {};\n\tfor ( const result of results ) {\n\t\tif ( result.title ) {\n\t\t\tconst titleTokens = tokenize( result.title );\n\t\t\tconst exactMatchingTokens = titleTokens.filter( ( titleToken ) =>\n\t\t\t\tsearchTokens.some(\n\t\t\t\t\t( searchToken ) => titleToken === searchToken\n\t\t\t\t)\n\t\t\t);\n\t\t\tconst subMatchingTokens = titleTokens.filter( ( titleToken ) =>\n\t\t\t\tsearchTokens.some(\n\t\t\t\t\t( searchToken ) =>\n\t\t\t\t\t\ttitleToken !== searchToken &&\n\t\t\t\t\t\ttitleToken.includes( searchToken )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// The score is a combination of exact matches and sub-matches.\n\t\t\t// More weight is given to exact matches, as they are more relevant (e.g. \"cat\" vs \"caterpillar\").\n\t\t\t// Diving by the total number of tokens in the title normalizes the score and skews\n\t\t\t// the results towards shorter titles.\n\t\t\tconst exactMatchScore =\n\t\t\t\t( exactMatchingTokens.length / titleTokens.length ) * 10;\n\n\t\t\tconst subMatchScore = subMatchingTokens.length / titleTokens.length;\n\n\t\t\tscores[ result.id ] = exactMatchScore + subMatchScore;\n\t\t} else {\n\t\t\tscores[ result.id ] = 0;\n\t\t}\n\t}\n\n\treturn results.sort( ( a, b ) => scores[ b.id ] - scores[ a.id ] );\n}\n\n/**\n * Turns text into an array of tokens, with whitespace and punctuation removed.\n *\n * For example, `\"I'm having a ball.\"` becomes `[ \"im\", \"having\", \"a\", \"ball\" ]`.\n *\n * @param text\n */\nexport function tokenize( text: string ): string[] {\n\t// \\p{L} matches any kind of letter from any language.\n\t// \\p{N} matches any kind of numeric character.\n\treturn text.toLowerCase().match( /[\\p{L}\\p{N}]+/gu ) || [];\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AANA;AACA;AACA;;AAiFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,eAAeI,oBAAoBA,CACjDC,MAAc,EACdC,aAA4B,GAAG,CAAC,CAAC,EACjCC,cAA8B,GAAG,CAAC,CAAC,EACP;EAC5B,MAAMC,kBAAkB,GACvBF,aAAa,CAACG,oBAAoB,IAClCH,aAAa,CAACI,+BAA+B,GAC1C;IACA,GAAGJ,aAAa;IAChB,GAAGA,aAAa,CAACI;EACjB,CAAC,GACDJ,aAAa;EAEjB,MAAM;IACLK,IAAI;IACJC,OAAO;IACPC,IAAI;IACJC,OAAO,GAAGR,aAAa,CAACG,oBAAoB,GAAG,CAAC,GAAG;EACpD,CAAC,GAAGD,kBAAkB;EAEtB,MAAM;IAAEO,kBAA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IAC/B,IAAKE,MAAM,CAACG,KAAK,EAAG;MACnB,MAAMiB,WAAW,GAAGF,QAAQ,CAAElB,MAAM,CAACG,KAAM,CAAC;MAC5C,MAAMkB,mBAAmB,GAAGD,WAAW,CAACN,MAAM,CAAIQ,UAAU,IAC3DL,YAAY,CAACM,IAAI,CACdC,WAAW,IAAMF,UAAU,KAAKE,WACnC,CACD,CAAC;MACD,MAAMC,iBAAiB,GAAGL,WAAW,CAACN,MAAM,CAAIQ,UAAU,IACzDL,YAAY,CAACM,IAAI,CACdC,WAAW,IACZF,UAAU,KAAKE,WAAW,IAC1BF,UAAU,CAACI,QAAQ,CAAEF,WAAY,CACnC,CACD,CAAC;;MAED;MACA;MACA;MACA;MACA,MAAMG,eAAe,GAClBN,mBAAmB,CAACO,MAAM,GAAGR,WAAW,CAACQ,MAAM,GAAK,EAAE;MAEzD,MAAMC,aAAa,GAAGJ,iBAAiB,CAACG,MAAM,GAAGR,WAAW,CAACQ,MAAM;MAEnET,MAAM,CAAEnB,MAAM,CAACC,EAAE,CAAE,GAAG0B,eAAe,GAAGE,aAAa;IACtD,CAAC,MAAM;MACNV,MAAM,CAAEnB,MAAM,CAACC,EAAE,CAAE,GAAG,CAAC;IACxB;EACD;EAEA,OAAOH,OAAO,CAACgC,IAAI,CAAE,CAAEC,CAAC,EAAEC,CAAC,KAAMb,MAAM,CAAEa,CAAC,CAAC/B,EAAE,CAAE,GAAGkB,MAAM,CAAEY,CAAC,CAAC9B,EAAE,CAAG,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASiB,QAAQA,CAAEe,IAAY,EAAa;EAClD;EACA;EACA,OAAOA,IAAI,CAACC,WAAW,CAAC,CAAC,CAACC,KAAK,CAAE,iBAAkB,CAAC,IAAI,EAAE;AAC3D","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_apiFetch","_interopRequireDefault","require","_url","_htmlEntities","_i18n","fetchLinkSuggestions","search","searchOptions","editorSettings","searchOptionsToUse","isInitialSuggestions","initialSuggestionsSearchOptions","type","subtype","page","perPage","disablePostFormats","queries","push","apiFetch","path","addQueryArgs","per_page","then","results","map","result","id","url","title","decodeEntities","__","kind","catch","source_url","rendered","responses","Promise","all","flat","filter","sortResults","slice","searchTokens","tokenize","scores","titleTokens","exactMatchingTokens","titleToken","some","searchToken","subMatchingTokens","includes","exactMatchScore","length","subMatchScore","sort","a","b","text","toLowerCase","match"],"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\n\nexport type SearchOptions = {\n\t/**\n\t * Displays initial search suggestions, when true.\n\t */\n\tisInitialSuggestions?: boolean;\n\t/**\n\t * Search options for initial suggestions.\n\t */\n\tinitialSuggestionsSearchOptions?: Omit<\n\t\tSearchOptions,\n\t\t'isInitialSuggestions' | 'initialSuggestionsSearchOptions'\n\t>;\n\t/**\n\t * Filters by search type.\n\t */\n\ttype?: 'attachment' | 'post' | 'term' | 'post-format';\n\t/**\n\t * Slug of the post-type or taxonomy.\n\t */\n\tsubtype?: string;\n\t/**\n\t * Which page of results to return.\n\t */\n\tpage?: number;\n\t/**\n\t * Search results per page.\n\t */\n\tperPage?: number;\n};\n\nexport type EditorSettings = {\n\t/**\n\t * Disables post formats, when true.\n\t */\n\tdisablePostFormats?: boolean;\n};\n\ntype SearchAPIResult = {\n\tid: number;\n\ttitle: string;\n\turl: string;\n\ttype: string;\n\tsubtype: string;\n};\n\ntype MediaAPIResult = {\n\tid: number;\n\ttitle: { rendered: string };\n\tsource_url: string;\n\ttype: string;\n};\n\nexport type SearchResult = {\n\t/**\n\t * Post or term id.\n\t */\n\tid: number;\n\t/**\n\t * Link url.\n\t */\n\turl: string;\n\t/**\n\t * Title of the link.\n\t */\n\ttitle: string;\n\t/**\n\t * The taxonomy or post type slug or type URL.\n\t */\n\ttype: string;\n\t/**\n\t * Link kind of post-type or taxonomy\n\t */\n\tkind?: string;\n};\n\n/**\n * Fetches link suggestions from the WordPress API.\n *\n * WordPress does not support searching multiple tables at once, e.g. posts and terms, so we\n * perform multiple queries at the same time and then merge the results together.\n *\n * @param search\n * @param searchOptions\n * @param editorSettings\n *\n * @example\n * ```js\n * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchLinkSuggestions = (\n * search,\n * searchOptions\n * ) => fetchLinkSuggestions( search, searchOptions, settings );\n * ```\n */\nexport default async function fetchLinkSuggestions(\n\tsearch: string,\n\tsearchOptions: SearchOptions = {},\n\teditorSettings: EditorSettings = {}\n): Promise< SearchResult[] > {\n\tconst searchOptionsToUse =\n\t\tsearchOptions.isInitialSuggestions &&\n\t\tsearchOptions.initialSuggestionsSearchOptions\n\t\t\t? {\n\t\t\t\t\t...searchOptions,\n\t\t\t\t\t...searchOptions.initialSuggestionsSearchOptions,\n\t\t\t }\n\t\t\t: searchOptions;\n\n\tconst {\n\t\ttype,\n\t\tsubtype,\n\t\tpage,\n\t\tperPage = searchOptions.isInitialSuggestions ? 3 : 20,\n\t} = searchOptionsToUse;\n\n\tconst { disablePostFormats = false } = editorSettings;\n\n\tconst queries: Promise< SearchResult[] >[] = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'post-type',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'term' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'term',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'taxonomy',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch< SearchAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post-format',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\t\t\tkind: 'taxonomy',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch< MediaAPIResult[] >( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tid: result.id,\n\t\t\t\t\t\t\turl: result.source_url,\n\t\t\t\t\t\t\ttitle:\n\t\t\t\t\t\t\t\tdecodeEntities( result.title.rendered || '' ) ||\n\t\t\t\t\t\t\t\t__( '(no title)' ),\n\t\t\t\t\t\t\ttype: result.type,\n\t\t\t\t\t\t\tkind: 'media',\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tconst responses = await Promise.all( queries );\n\n\tlet results = responses.flat();\n\tresults = results.filter( ( result ) => !! result.id );\n\tresults = sortResults( results, search );\n\tresults = results.slice( 0, perPage );\n\treturn results;\n}\n\n/**\n * Sort search results by relevance to the given query.\n *\n * Sorting is necessary as we're querying multiple endpoints and merging the results. For example\n * a taxonomy title might be more relevant than a post title, but by default taxonomy results will\n * be ordered after all the (potentially irrelevant) post results.\n *\n * We sort by scoring each result, where the score is the number of tokens in the title that are\n * also in the search query, divided by the total number of tokens in the title. This gives us a\n * score between 0 and 1, where 1 is a perfect match.\n *\n * @param results\n * @param search\n */\nexport function sortResults( results: SearchResult[], search: string ) {\n\tconst searchTokens = tokenize( search );\n\n\tconst scores = {};\n\tfor ( const result of results ) {\n\t\tif ( result.title ) {\n\t\t\tconst titleTokens = tokenize( result.title );\n\t\t\tconst exactMatchingTokens = titleTokens.filter( ( titleToken ) =>\n\t\t\t\tsearchTokens.some(\n\t\t\t\t\t( searchToken ) => titleToken === searchToken\n\t\t\t\t)\n\t\t\t);\n\t\t\tconst subMatchingTokens = titleTokens.filter( ( titleToken ) =>\n\t\t\t\tsearchTokens.some(\n\t\t\t\t\t( searchToken ) =>\n\t\t\t\t\t\ttitleToken !== searchToken &&\n\t\t\t\t\t\ttitleToken.includes( searchToken )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// The score is a combination of exact matches and sub-matches.\n\t\t\t// More weight is given to exact matches, as they are more relevant (e.g. \"cat\" vs \"caterpillar\").\n\t\t\t// Diving by the total number of tokens in the title normalizes the score and skews\n\t\t\t// the results towards shorter titles.\n\t\t\tconst exactMatchScore =\n\t\t\t\t( exactMatchingTokens.length / titleTokens.length ) * 10;\n\n\t\t\tconst subMatchScore = subMatchingTokens.length / titleTokens.length;\n\n\t\t\tscores[ result.id ] = exactMatchScore + subMatchScore;\n\t\t} else {\n\t\t\tscores[ result.id ] = 0;\n\t\t}\n\t}\n\n\treturn results.sort( ( a, b ) => scores[ b.id ] - scores[ a.id ] );\n}\n\n/**\n * Turns text into an array of tokens, with whitespace and punctuation removed.\n *\n * For example, `\"I'm having a ball.\"` becomes `[ \"im\", \"having\", \"a\", \"ball\" ]`.\n *\n * @param text\n */\nexport function tokenize( text: string ): string[] {\n\t// \\p{L} matches any kind of letter from any language.\n\t// \\p{N} matches any kind of numeric character.\n\treturn text.toLowerCase().match( /[\\p{L}\\p{N}]+/gu ) || [];\n}\n"],"mappings":";;;;;;;;;AAGA,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AAa,GAAGJ,iBAAiB,CAACG,MAAM,GAAGR,WAAW,CAACQ,MAAM;MAEnET,MAAM,CAAEnB,MAAM,CAACC,EAAE,CAAE,GAAG0B,eAAe,GAAGE,aAAa;IACtD,CAAC,MAAM;MACNV,MAAM,CAAEnB,MAAM,CAACC,EAAE,CAAE,GAAG,CAAC;IACxB;EACD;EAEA,OAAOH,OAAO,CAACgC,IAAI,CAAE,CAAEC,CAAC,EAAEC,CAAC,KAAMb,MAAM,CAAEa,CAAC,CAAC/B,EAAE,CAAE,GAAGkB,MAAM,CAAEY,CAAC,CAAC9B,EAAE,CAAG,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASiB,QAAQA,CAAEe,IAAY,EAAa;EAClD;EACA;EACA,OAAOA,IAAI,CAACC,WAAW,CAAC,CAAC,CAACC,KAAK,CAAE,iBAAkB,CAAC,IAAI,EAAE;AAC3D","ignoreList":[]}
|
package/build/fetch/index.js
CHANGED
package/build/fetch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_changeCase","require","_apiFetch","_interopRequireDefault","_experimentalFetchLinkSuggestions","_experimentalFetchUrlData","fetchBlockPatterns","restPatterns","apiFetch","path","map","pattern","Object","fromEntries","entries","key","value","camelCase"],"sources":["@wordpress/core-data/src/fetch/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\nexport { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';\nexport { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';\n\nexport async function fetchBlockPatterns() {\n\tconst restPatterns = await apiFetch( {\n\t\tpath: '/wp/v2/block-patterns/patterns',\n\t} );\n\tif ( ! restPatterns ) {\n\t\treturn [];\n\t}\n\treturn restPatterns.map( ( pattern ) =>\n\t\tObject.fromEntries(\n\t\t\tObject.entries( pattern ).map( ( [ key, value ] ) => [\n\t\t\t\tcamelCase( key ),\n\t\t\t\tvalue,\n\t\t\t] )\n\t\t)\n\t);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_changeCase","require","_apiFetch","_interopRequireDefault","_experimentalFetchLinkSuggestions","_experimentalFetchUrlData","fetchBlockPatterns","restPatterns","apiFetch","path","map","pattern","Object","fromEntries","entries","key","value","camelCase"],"sources":["@wordpress/core-data/src/fetch/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\nexport { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';\nexport { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';\n\nexport async function fetchBlockPatterns() {\n\tconst restPatterns = await apiFetch( {\n\t\tpath: '/wp/v2/block-patterns/patterns',\n\t} );\n\tif ( ! restPatterns ) {\n\t\treturn [];\n\t}\n\treturn restPatterns.map( ( pattern ) =>\n\t\tObject.fromEntries(\n\t\t\tObject.entries( pattern ).map( ( [ key, value ] ) => [\n\t\t\t\tcamelCase( key ),\n\t\t\t\tvalue,\n\t\t\t] )\n\t\t)\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,iCAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,yBAAA,GAAAF,sBAAA,CAAAF,OAAA;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMO,eAAeK,kBAAkBA,CAAA,EAAG;EAC1C,MAAMC,YAAY,GAAG,MAAM,IAAAC,iBAAQ,EAAE;IACpCC,IAAI,EAAE;EACP,CAAE,CAAC;EACH,IAAK,CAAEF,YAAY,EAAG;IACrB,OAAO,EAAE;EACV;EACA,OAAOA,YAAY,CAACG,GAAG,CAAIC,OAAO,IACjCC,MAAM,CAACC,WAAW,CACjBD,MAAM,CAACE,OAAO,CAAEH,OAAQ,CAAC,CAACD,GAAG,CAAE,CAAE,CAAEK,GAAG,EAAEC,KAAK,CAAE,KAAM,CACpD,IAAAC,qBAAS,EAAEF,GAAI,CAAC,EAChBC,KAAK,CACJ,CACH,CACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_getRichTextValuesCached","_interopRequireDefault","require","cache","WeakMap","getBlockFootnotesOrder","block","has","order","value","getRichTextValuesCached","replacements","forEach","type","attributes","push","set","get","getFootnotesOrder","blocks","flatMap"],"sources":["@wordpress/core-data/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":"
|
|
1
|
+
{"version":3,"names":["_getRichTextValuesCached","_interopRequireDefault","require","cache","WeakMap","getBlockFootnotesOrder","block","has","order","value","getRichTextValuesCached","replacements","forEach","type","attributes","push","set","get","getFootnotesOrder","blocks","flatMap"],"sources":["@wordpress/core-data/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":";;;;;;;AAGA,IAAAA,wBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAMC,KAAK,GAAG,IAAIC,OAAO,CAAC,CAAC;AAE3B,SAASC,sBAAsBA,CAAEC,KAAK,EAAG;EACxC,IAAK,CAAEH,KAAK,CAACI,GAAG,CAAED,KAAM,CAAC,EAAG;IAC3B,MAAME,KAAK,GAAG,EAAE;IAChB,KAAM,MAAMC,KAAK,IAAI,IAAAC,gCAAuB,EAAEJ,KAAM,CAAC,EAAG;MACvD,IAAK,CAAEG,KAAK,EAAG;QACd;MACD;;MAEA;MACAA,KAAK,CAACE,YAAY,CAACC,OAAO,CAAE,CAAE;QAAEC,IAAI;QAAEC;MAAW,CAAC,KAAM;QACvD,IAAKD,IAAI,KAAK,eAAe,EAAG;UAC/BL,KAAK,CAACO,IAAI,CAAED,UAAU,CAAE,SAAS,CAAG,CAAC;QACtC;MACD,CAAE,CAAC;IACJ;IACAX,KAAK,CAACa,GAAG,CAAEV,KAAK,EAAEE,KAAM,CAAC;EAC1B;EAEA,OAAOL,KAAK,CAACc,GAAG,CAAEX,KAAM,CAAC;AAC1B;AAEe,SAASY,iBAAiBA,CAAEC,MAAM,EAAG;EACnD;EACA;EACA;EACA;EACA,OAAOA,MAAM,CAACC,OAAO,CAAEf,sBAAuB,CAAC;AAChD","ignoreList":[]}
|
package/build/footnotes/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_richText","require","_getFootnotesOrder","_interopRequireDefault","oldFootnotes","updateFootnotesFromMeta","blocks","meta","output","footnotes","undefined","newOrder","getFootnotesOrder","JSON","parse","currentOrder","map","fn","id","join","newFootnotes","fnId","find","content","updateAttributes","attributes","Array","isArray","key","value","RichTextData","richTextValue","fromHTMLString","hasFootnotes","replacements","forEach","replacement","type","index","indexOf","countValue","create","html","innerHTML","text","String","formats","from","length","toHTMLString","updateBlocksAttributes","__blocks","block","innerBlocks","newBlocks","reduce","acc","includes","stringify"],"sources":["@wordpress/core-data/src/footnotes/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RichTextData, create, toHTMLString } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport getFootnotesOrder from './get-footnotes-order';\n\nlet oldFootnotes = {};\n\nexport function updateFootnotesFromMeta( blocks, meta ) {\n\tconst output = { blocks };\n\tif ( ! meta ) {\n\t\treturn output;\n\t}\n\n\t// If meta.footnotes is empty, it means the meta is not registered.\n\tif ( meta.footnotes === undefined ) {\n\t\treturn output;\n\t}\n\n\tconst newOrder = getFootnotesOrder( blocks );\n\n\tconst footnotes = meta.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst currentOrder = footnotes.map( ( fn ) => fn.id );\n\n\tif ( currentOrder.join( '' ) === newOrder.join( '' ) ) {\n\t\treturn output;\n\t}\n\n\tconst newFootnotes = newOrder.map(\n\t\t( fnId ) =>\n\t\t\tfootnotes.find( ( fn ) => fn.id === fnId ) ||\n\t\t\toldFootnotes[ fnId ] || {\n\t\t\t\tid: fnId,\n\t\t\t\tcontent: '',\n\t\t\t}\n\t);\n\n\tfunction updateAttributes( attributes ) {\n\t\t// Only attempt to update attributes, if attributes is an object.\n\t\tif (\n\t\t\t! attributes ||\n\t\t\tArray.isArray( attributes ) ||\n\t\t\ttypeof attributes !== 'object'\n\t\t) {\n\t\t\treturn attributes;\n\t\t}\n\n\t\tattributes = { ...attributes };\n\n\t\tfor ( const key in attributes ) {\n\t\t\tconst value = attributes[ key ];\n\n\t\t\tif ( Array.isArray( value ) ) {\n\t\t\t\tattributes[ key ] = value.map( updateAttributes );\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// To do, remove support for string values?\n\t\t\tif (\n\t\t\t\ttypeof value !== 'string' &&\n\t\t\t\t! ( value instanceof RichTextData )\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst richTextValue =\n\t\t\t\ttypeof value === 'string'\n\t\t\t\t\t? RichTextData.fromHTMLString( value )\n\t\t\t\t\t: new RichTextData( value );\n\n\t\t\tlet hasFootnotes = false;\n\n\t\t\trichTextValue.replacements.forEach( ( replacement ) => {\n\t\t\t\tif ( replacement.type === 'core/footnote' ) {\n\t\t\t\t\tconst id = replacement.attributes[ 'data-fn' ];\n\t\t\t\t\tconst index = newOrder.indexOf( id );\n\t\t\t\t\t// The innerHTML contains the count wrapped in a link.\n\t\t\t\t\tconst countValue = create( {\n\t\t\t\t\t\thtml: replacement.innerHTML,\n\t\t\t\t\t} );\n\t\t\t\t\tcountValue.text = String( index + 1 );\n\t\t\t\t\tcountValue.formats = Array.from(\n\t\t\t\t\t\t{ length: countValue.text.length },\n\t\t\t\t\t\t() => countValue.formats[ 0 ]\n\t\t\t\t\t);\n\t\t\t\t\tcountValue.replacements = Array.from(\n\t\t\t\t\t\t{ length: countValue.text.length },\n\t\t\t\t\t\t() => countValue.replacements[ 0 ]\n\t\t\t\t\t);\n\t\t\t\t\treplacement.innerHTML = toHTMLString( {\n\t\t\t\t\t\tvalue: countValue,\n\t\t\t\t\t} );\n\t\t\t\t\thasFootnotes = true;\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\tif ( hasFootnotes ) {\n\t\t\t\tattributes[ key ] =\n\t\t\t\t\ttypeof value === 'string'\n\t\t\t\t\t\t? richTextValue.toHTMLString()\n\t\t\t\t\t\t: richTextValue;\n\t\t\t}\n\t\t}\n\n\t\treturn attributes;\n\t}\n\n\tfunction updateBlocksAttributes( __blocks ) {\n\t\treturn __blocks.map( ( block ) => {\n\t\t\treturn {\n\t\t\t\t...block,\n\t\t\t\tattributes: updateAttributes( block.attributes ),\n\t\t\t\tinnerBlocks: updateBlocksAttributes( block.innerBlocks ),\n\t\t\t};\n\t\t} );\n\t}\n\n\t// We need to go through all block attributes deeply and update the\n\t// footnote anchor numbering (textContent) to match the new order.\n\tconst newBlocks = updateBlocksAttributes( blocks );\n\n\toldFootnotes = {\n\t\t...oldFootnotes,\n\t\t...footnotes.reduce( ( acc, fn ) => {\n\t\t\tif ( ! newOrder.includes( fn.id ) ) {\n\t\t\t\tacc[ fn.id ] = fn;\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, {} ),\n\t};\n\n\treturn {\n\t\tmeta: {\n\t\t\t...meta,\n\t\t\tfootnotes: JSON.stringify( newFootnotes ),\n\t\t},\n\t\tblocks: newBlocks,\n\t};\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_richText","require","_getFootnotesOrder","_interopRequireDefault","oldFootnotes","updateFootnotesFromMeta","blocks","meta","output","footnotes","undefined","newOrder","getFootnotesOrder","JSON","parse","currentOrder","map","fn","id","join","newFootnotes","fnId","find","content","updateAttributes","attributes","Array","isArray","key","value","RichTextData","richTextValue","fromHTMLString","hasFootnotes","replacements","forEach","replacement","type","index","indexOf","countValue","create","html","innerHTML","text","String","formats","from","length","toHTMLString","updateBlocksAttributes","__blocks","block","innerBlocks","newBlocks","reduce","acc","includes","stringify"],"sources":["@wordpress/core-data/src/footnotes/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RichTextData, create, toHTMLString } from '@wordpress/rich-text';\n\n/**\n * Internal dependencies\n */\nimport getFootnotesOrder from './get-footnotes-order';\n\nlet oldFootnotes = {};\n\nexport function updateFootnotesFromMeta( blocks, meta ) {\n\tconst output = { blocks };\n\tif ( ! meta ) {\n\t\treturn output;\n\t}\n\n\t// If meta.footnotes is empty, it means the meta is not registered.\n\tif ( meta.footnotes === undefined ) {\n\t\treturn output;\n\t}\n\n\tconst newOrder = getFootnotesOrder( blocks );\n\n\tconst footnotes = meta.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst currentOrder = footnotes.map( ( fn ) => fn.id );\n\n\tif ( currentOrder.join( '' ) === newOrder.join( '' ) ) {\n\t\treturn output;\n\t}\n\n\tconst newFootnotes = newOrder.map(\n\t\t( fnId ) =>\n\t\t\tfootnotes.find( ( fn ) => fn.id === fnId ) ||\n\t\t\toldFootnotes[ fnId ] || {\n\t\t\t\tid: fnId,\n\t\t\t\tcontent: '',\n\t\t\t}\n\t);\n\n\tfunction updateAttributes( attributes ) {\n\t\t// Only attempt to update attributes, if attributes is an object.\n\t\tif (\n\t\t\t! attributes ||\n\t\t\tArray.isArray( attributes ) ||\n\t\t\ttypeof attributes !== 'object'\n\t\t) {\n\t\t\treturn attributes;\n\t\t}\n\n\t\tattributes = { ...attributes };\n\n\t\tfor ( const key in attributes ) {\n\t\t\tconst value = attributes[ key ];\n\n\t\t\tif ( Array.isArray( value ) ) {\n\t\t\t\tattributes[ key ] = value.map( updateAttributes );\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// To do, remove support for string values?\n\t\t\tif (\n\t\t\t\ttypeof value !== 'string' &&\n\t\t\t\t! ( value instanceof RichTextData )\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst richTextValue =\n\t\t\t\ttypeof value === 'string'\n\t\t\t\t\t? RichTextData.fromHTMLString( value )\n\t\t\t\t\t: new RichTextData( value );\n\n\t\t\tlet hasFootnotes = false;\n\n\t\t\trichTextValue.replacements.forEach( ( replacement ) => {\n\t\t\t\tif ( replacement.type === 'core/footnote' ) {\n\t\t\t\t\tconst id = replacement.attributes[ 'data-fn' ];\n\t\t\t\t\tconst index = newOrder.indexOf( id );\n\t\t\t\t\t// The innerHTML contains the count wrapped in a link.\n\t\t\t\t\tconst countValue = create( {\n\t\t\t\t\t\thtml: replacement.innerHTML,\n\t\t\t\t\t} );\n\t\t\t\t\tcountValue.text = String( index + 1 );\n\t\t\t\t\tcountValue.formats = Array.from(\n\t\t\t\t\t\t{ length: countValue.text.length },\n\t\t\t\t\t\t() => countValue.formats[ 0 ]\n\t\t\t\t\t);\n\t\t\t\t\tcountValue.replacements = Array.from(\n\t\t\t\t\t\t{ length: countValue.text.length },\n\t\t\t\t\t\t() => countValue.replacements[ 0 ]\n\t\t\t\t\t);\n\t\t\t\t\treplacement.innerHTML = toHTMLString( {\n\t\t\t\t\t\tvalue: countValue,\n\t\t\t\t\t} );\n\t\t\t\t\thasFootnotes = true;\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\tif ( hasFootnotes ) {\n\t\t\t\tattributes[ key ] =\n\t\t\t\t\ttypeof value === 'string'\n\t\t\t\t\t\t? richTextValue.toHTMLString()\n\t\t\t\t\t\t: richTextValue;\n\t\t\t}\n\t\t}\n\n\t\treturn attributes;\n\t}\n\n\tfunction updateBlocksAttributes( __blocks ) {\n\t\treturn __blocks.map( ( block ) => {\n\t\t\treturn {\n\t\t\t\t...block,\n\t\t\t\tattributes: updateAttributes( block.attributes ),\n\t\t\t\tinnerBlocks: updateBlocksAttributes( block.innerBlocks ),\n\t\t\t};\n\t\t} );\n\t}\n\n\t// We need to go through all block attributes deeply and update the\n\t// footnote anchor numbering (textContent) to match the new order.\n\tconst newBlocks = updateBlocksAttributes( blocks );\n\n\toldFootnotes = {\n\t\t...oldFootnotes,\n\t\t...footnotes.reduce( ( acc, fn ) => {\n\t\t\tif ( ! newOrder.includes( fn.id ) ) {\n\t\t\t\tacc[ fn.id ] = fn;\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, {} ),\n\t};\n\n\treturn {\n\t\tmeta: {\n\t\t\t...meta,\n\t\t\tfootnotes: JSON.stringify( newFootnotes ),\n\t\t},\n\t\tblocks: newBlocks,\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AAKA,IAAAC,kBAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,IAAIG,YAAY,GAAG,CAAC,CAAC;AAEd,SAASC,uBAAuBA,CAAEC,MAAM,EAAEC,IAAI,EAAG;EACvD,MAAMC,MAAM,GAAG;IAAEF;EAAO,CAAC;EACzB,IAAK,CAAEC,IAAI,EAAG;IACb,OAAOC,MAAM;EACd;;EAEA;EACA,IAAKD,IAAI,CAACE,SAAS,KAAKC,SAAS,EAAG;IACnC,OAAOF,MAAM;EACd;EAEA,MAAMG,QAAQ,GAAG,IAAAC,0BAAiB,EAAEN,MAAO,CAAC;EAE5C,MAAMG,SAAS,GAAGF,IAAI,CAACE,SAAS,GAAGI,IAAI,CAACC,KAAK,CAAEP,IAAI,CAACE,SAAU,CAAC,GAAG,EAAE;EACpE,MAAMM,YAAY,GAAGN,SAAS,CAACO,GAAG,CAAIC,EAAE,IAAMA,EAAE,CAACC,EAAG,CAAC;EAErD,IAAKH,YAAY,CAACI,IAAI,CAAE,EAAG,CAAC,KAAKR,QAAQ,CAACQ,IAAI,CAAE,EAAG,CAAC,EAAG;IACtD,OAAOX,MAAM;EACd;EAEA,MAAMY,YAAY,GAAGT,QAAQ,CAACK,GAAG,CAC9BK,IAAI,IACLZ,SAAS,CAACa,IAAI,CAAIL,EAAE,IAAMA,EAAE,CAACC,EAAE,KAAKG,IAAK,CAAC,IAC1CjB,YAAY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ACC,EAAE,CAAE,GAAGD,EAAE;MAClB;MACA,OAAOuC,GAAG;IACX,CAAC,EAAE,CAAC,CAAE;EACP,CAAC;EAED,OAAO;IACNjD,IAAI,EAAE;MACL,GAAGA,IAAI;MACPE,SAAS,EAAEI,IAAI,CAAC6C,SAAS,CAAEtC,YAAa;IACzC,CAAC;IACDd,MAAM,EAAEgD;EACT,CAAC;AACF","ignoreList":[]}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_reducer","_interopRequireDefault","selectors","_interopRequireWildcard","privateSelectors","actions","privateActions","resolvers","_actions2","_entities","_name","_lockUnlock","_dynamicEntities","_entityProvider","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_entityTypes","_fetch","_hooks","_privateApis","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","entitiesConfig","rootEntitiesConfig","additionalEntityConfigLoaders","filter","config","name","entitySelectors","reduce","result","entity","kind","plural","getMethodName","state","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","record","options","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","dynamicActions","createLocksActions","dynamicSelectors","store","createReduxStore","STORE_NAME","unlock","registerPrivateSelectors","registerPrivateActions","register"],"sources":["@wordpress/core-data/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\n\tif ( plural ) {\n\t\tresult[ getMethodName( kind, plural, 'get' ) ] = ( state, query ) =>\n\t\t\tselectors.getEntityRecords( state, kind, name, query );\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\n\tif ( plural ) {\n\t\tconst pluralMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\t\tresolvers.getEntityRecords( kind, name, ...args );\n\t\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( record, options ) =>\n\t\tactions.saveEntityRecord( kind, name, record, options );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query, options ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query, options );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nunlock( store ).registerPrivateActions( privateActions );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\nexport * from './private-apis';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAD,uBAAA,CAAAJ,OAAA;AACA,IAAAM,OAAA,GAAAF,uBAAA,CAAAJ,OAAA;AACA,IAAAO,cAAA,GAAAH,uBAAA,CAAAJ,OAAA;AACA,IAAAQ,SAAA,GAAAJ,uBAAA,CAAAJ,OAAA;AACA,IAAAS,SAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,SAAA,GAAAV,OAAA;AAKA,IAAAW,KAAA,GAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AACA,IAAAa,gBAAA,GAAAb,OAAA;AAyEA,IAAAc,eAAA,GAAAV,uBAAA,CAAAJ,OAAA;AACAe,MAAA,CAAAC,IAAA,CAAAF,eAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAA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]}
|
|
1
|
+
{"version":3,"names":["_data","require","_reducer","_interopRequireDefault","selectors","_interopRequireWildcard","privateSelectors","actions","privateActions","resolvers","_actions2","_entities","_name","_lockUnlock","_dynamicEntities","_entityProvider","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_entityTypes","_fetch","_hooks","_privateApis","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","entitiesConfig","rootEntitiesConfig","additionalEntityConfigLoaders","filter","config","name","entitySelectors","reduce","result","entity","kind","plural","getMethodName","state","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","record","options","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","dynamicActions","createLocksActions","dynamicSelectors","store","createReduxStore","STORE_NAME","unlock","registerPrivateSelectors","registerPrivateActions","register"],"sources":["@wordpress/core-data/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\n\tif ( plural ) {\n\t\tresult[ getMethodName( kind, plural, 'get' ) ] = ( state, query ) =>\n\t\t\tselectors.getEntityRecords( state, kind, name, query );\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\n\tif ( plural ) {\n\t\tconst pluralMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\t\tresolvers.getEntityRecords( kind, name, ...args );\n\t\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( record, options ) =>\n\t\tactions.saveEntityRecord( kind, name, record, options );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query, options ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query, options );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nunlock( store ).registerPrivateActions( privateActions );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\nexport * from './private-apis';\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAD,uBAAA,CAAAJ,OAAA;AACA,IAAAM,OAAA,GAAAF,uBAAA,CAAAJ,OAAA;AACA,IAAAO,cAAA,GAAAH,uBAAA,CAAAJ,OAAA;AACA,IAAAQ,SAAA,GAAAJ,uBAAA,CAAAJ,OAAA;AACA,IAAAS,SAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,SAAA,GAAAV,OAAA;AAKA,IAAAW,KAAA,GAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AACA,IAAAa,gBAAA,GAAAb,OAAA;AAyEA,IAAAc,eAAA,GAAAV,uBAAA,CAAAJ,OAAA;AACAe,MAAA,CAAAC,IAAA,CAAAF,eAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,eAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,eAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,YAAA,GAAA3B,OAAA;AAAAe,MAAA,CAAAC,IAAA,CAAAW,YAAA,EAAAV,OAAA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C,GAAG,EAAE0C,KAAK,EAAEU,OAAO,KACtEhE,OAAO,CAACkE,kBAAkB,CAAEhB,IAAI,EAAEL,IAAI,EAAEjC,GAAG,EAAE0C,KAAK,EAAEU,OAAQ,CAAC;EAC9D,OAAOhB,MAAM;AACd,CAAC,EAAE,CAAC,CAAE,CAAC;AAEP,MAAMmB,WAAW,GAAGA,CAAA,MAAQ;EAC3BC,OAAO,EAAPA,gBAAO;EACPpE,OAAO,EAAE;IACR,GAAGqE,+BAAc;IACjB,GAAGrE,OAAO;IACV,GAAG8D,aAAa;IAChB,GAAG,IAAAQ,iBAAkB,EAAC;EACvB,CAAC;EACDzE,SAAS,EAAE;IACV,GAAG0E,iCAAgB;IACnB,GAAG1E,SAAS;IACZ,GAAGiD;EACJ,CAAC;EACD5C,SAAS,EAAE;IAAE,GAAGA,SAAS;IAAE,GAAGuD;EAAgB;AAC/C,CAAC,CAAE;;AAEH;AACA;AACA;AACA;AACA;AACO,MAAMe,KAAK,GAAAvD,OAAA,CAAAuD,KAAA,GAAG,IAAAC,sBAAgB,EAAEC,gBAAU,EAAEP,WAAW,CAAC,CAAE,CAAC;AAClE,IAAAQ,kBAAM,EAAEH,KAAM,CAAC,CAACI,wBAAwB,CAAE7E,gBAAiB,CAAC;AAC5D,IAAA4E,kBAAM,EAAEH,KAAM,CAAC,CAACK,sBAAsB,CAAE5E,cAAe,CAAC;AACxD,IAAA6E,cAAQ,EAAEN,KAAM,CAAC,CAAC,CAAC","ignoreList":[]}
|
package/build/locks/reducer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_utils","require","DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","deepCopyLocksTreePath","node","getNode","filter","r","l"],"sources":["@wordpress/core-data/src/locks/reducer.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { getNode, deepCopyLocksTreePath } from './utils';\n\nconst DEFAULT_STATE = {\n\trequests: [],\n\ttree: {\n\t\tlocks: [],\n\t\tchildren: {},\n\t},\n};\n\n/**\n * Reducer returning locks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport default function locks( state = DEFAULT_STATE, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ENQUEUE_LOCK_REQUEST': {\n\t\t\tconst { request } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\trequests: [ request, ...state.requests ],\n\t\t\t};\n\t\t}\n\t\tcase 'GRANT_LOCK_REQUEST': {\n\t\t\tconst { lock, request } = action;\n\t\t\tconst { store, path } = request;\n\t\t\tconst storePath = [ store, ...path ];\n\n\t\t\tconst newTree = deepCopyLocksTreePath( state.tree, storePath );\n\t\t\tconst node = getNode( newTree, storePath );\n\t\t\tnode.locks = [ ...node.locks, lock ];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\trequests: state.requests.filter( ( r ) => r !== request ),\n\t\t\t\ttree: newTree,\n\t\t\t};\n\t\t}\n\t\tcase 'RELEASE_LOCK': {\n\t\t\tconst { lock } = action;\n\t\t\tconst storePath = [ lock.store, ...lock.path ];\n\n\t\t\tconst newTree = deepCopyLocksTreePath( state.tree, storePath );\n\t\t\tconst node = getNode( newTree, storePath );\n\t\t\tnode.locks = node.locks.filter( ( l ) => l !== lock );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\ttree: newTree,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_utils","require","DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","deepCopyLocksTreePath","node","getNode","filter","r","l"],"sources":["@wordpress/core-data/src/locks/reducer.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { getNode, deepCopyLocksTreePath } from './utils';\n\nconst DEFAULT_STATE = {\n\trequests: [],\n\ttree: {\n\t\tlocks: [],\n\t\tchildren: {},\n\t},\n};\n\n/**\n * Reducer returning locks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport default function locks( state = DEFAULT_STATE, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ENQUEUE_LOCK_REQUEST': {\n\t\t\tconst { request } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\trequests: [ request, ...state.requests ],\n\t\t\t};\n\t\t}\n\t\tcase 'GRANT_LOCK_REQUEST': {\n\t\t\tconst { lock, request } = action;\n\t\t\tconst { store, path } = request;\n\t\t\tconst storePath = [ store, ...path ];\n\n\t\t\tconst newTree = deepCopyLocksTreePath( state.tree, storePath );\n\t\t\tconst node = getNode( newTree, storePath );\n\t\t\tnode.locks = [ ...node.locks, lock ];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\trequests: state.requests.filter( ( r ) => r !== request ),\n\t\t\t\ttree: newTree,\n\t\t\t};\n\t\t}\n\t\tcase 'RELEASE_LOCK': {\n\t\t\tconst { lock } = action;\n\t\t\tconst storePath = [ lock.store, ...lock.path ];\n\n\t\t\tconst newTree = deepCopyLocksTreePath( state.tree, storePath );\n\t\t\tconst node = getNode( newTree, storePath );\n\t\t\tnode.locks = node.locks.filter( ( l ) => l !== lock );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\ttree: newTree,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAMC,aAAa,GAAG;EACrBC,QAAQ,EAAE,EAAE;EACZC,IAAI,EAAE;IACLC,KAAK,EAAE,EAAE;IACTC,QAAQ,EAAE,CAAC;EACZ;AACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASD,KAAKA,CAAEE,KAAK,GAAGL,aAAa,EAAEM,MAAM,EAAG;EAC9D,QAASA,MAAM,CAACC,IAAI;IACnB,KAAK,sBAAsB;MAAE;Q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AK;UACRH,IAAI,EAAEW;QACP,CAAC;MACF;EACD;EAEA,OAAOR,KAAK;AACb","ignoreList":[]}
|
package/build/locks/utils.js
CHANGED
package/build/locks/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["deepCopyLocksTreePath","tree","path","newTree","currentNode","branchName","children","locks","getNode","nextNode","iteratePath","iterateDescendants","node","stack","Object","values","length","childNode","pop","push","hasConflictingLock","exclusive","filter","lock"],"sources":["@wordpress/core-data/src/locks/utils.js"],"sourcesContent":["export function deepCopyLocksTreePath( tree, path ) {\n\tconst newTree = { ...tree };\n\tlet currentNode = newTree;\n\tfor ( const branchName of path ) {\n\t\tcurrentNode.children = {\n\t\t\t...currentNode.children,\n\t\t\t[ branchName ]: {\n\t\t\t\tlocks: [],\n\t\t\t\tchildren: {},\n\t\t\t\t...currentNode.children[ branchName ],\n\t\t\t},\n\t\t};\n\t\tcurrentNode = currentNode.children[ branchName ];\n\t}\n\treturn newTree;\n}\n\nexport function getNode( tree, path ) {\n\tlet currentNode = tree;\n\tfor ( const branchName of path ) {\n\t\tconst nextNode = currentNode.children[ branchName ];\n\t\tif ( ! nextNode ) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrentNode = nextNode;\n\t}\n\treturn currentNode;\n}\n\nexport function* iteratePath( tree, path ) {\n\tlet currentNode = tree;\n\tyield currentNode;\n\tfor ( const branchName of path ) {\n\t\tconst nextNode = currentNode.children[ branchName ];\n\t\tif ( ! nextNode ) {\n\t\t\tbreak;\n\t\t}\n\t\tyield nextNode;\n\t\tcurrentNode = nextNode;\n\t}\n}\n\nexport function* iterateDescendants( node ) {\n\tconst stack = Object.values( node.children );\n\twhile ( stack.length ) {\n\t\tconst childNode = stack.pop();\n\t\tyield childNode;\n\t\tstack.push( ...Object.values( childNode.children ) );\n\t}\n}\n\nexport function hasConflictingLock( { exclusive }, locks ) {\n\tif ( exclusive && locks.length ) {\n\t\treturn true;\n\t}\n\n\tif ( ! exclusive && locks.filter( ( lock ) => lock.exclusive ).length ) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["deepCopyLocksTreePath","tree","path","newTree","currentNode","branchName","children","locks","getNode","nextNode","iteratePath","iterateDescendants","node","stack","Object","values","length","childNode","pop","push","hasConflictingLock","exclusive","filter","lock"],"sources":["@wordpress/core-data/src/locks/utils.js"],"sourcesContent":["export function deepCopyLocksTreePath( tree, path ) {\n\tconst newTree = { ...tree };\n\tlet currentNode = newTree;\n\tfor ( const branchName of path ) {\n\t\tcurrentNode.children = {\n\t\t\t...currentNode.children,\n\t\t\t[ branchName ]: {\n\t\t\t\tlocks: [],\n\t\t\t\tchildren: {},\n\t\t\t\t...currentNode.children[ branchName ],\n\t\t\t},\n\t\t};\n\t\tcurrentNode = currentNode.children[ branchName ];\n\t}\n\treturn newTree;\n}\n\nexport function getNode( tree, path ) {\n\tlet currentNode = tree;\n\tfor ( const branchName of path ) {\n\t\tconst nextNode = currentNode.children[ branchName ];\n\t\tif ( ! nextNode ) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrentNode = nextNode;\n\t}\n\treturn currentNode;\n}\n\nexport function* iteratePath( tree, path ) {\n\tlet currentNode = tree;\n\tyield currentNode;\n\tfor ( const branchName of path ) {\n\t\tconst nextNode = currentNode.children[ branchName ];\n\t\tif ( ! nextNode ) {\n\t\t\tbreak;\n\t\t}\n\t\tyield nextNode;\n\t\tcurrentNode = nextNode;\n\t}\n}\n\nexport function* iterateDescendants( node ) {\n\tconst stack = Object.values( node.children );\n\twhile ( stack.length ) {\n\t\tconst childNode = stack.pop();\n\t\tyield childNode;\n\t\tstack.push( ...Object.values( childNode.children ) );\n\t}\n}\n\nexport function hasConflictingLock( { exclusive }, locks ) {\n\tif ( exclusive && locks.length ) {\n\t\treturn true;\n\t}\n\n\tif ( ! exclusive && locks.filter( ( lock ) => lock.exclusive ).length ) {\n\t\treturn true;\n\t}\n\n\treturn false;\n}\n"],"mapp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C,OAAQO,KAAK,CAACG,MAAM,EAAG;IACtB,MAAMC,SAAS,GAAGJ,KAAK,CAACK,GAAG,CAAC,CAAC;IAC7B,MAAMD,SAAS;IACfJ,KAAK,CAACM,IAAI,CAAE,GAAGL,MAAM,CAACC,MAAM,CAAEE,SAAS,CAACX,QAAS,CAAE,CAAC;EACrD;AACD;AAEO,SAASc,kBAAkBA,CAAE;EAAEC;AAAU,CAAC,EAAEd,KAAK,EAAG;EAC1D,IAAKc,SAAS,IAAId,KAAK,CAACS,MAAM,EAAG;IAChC,OAAO,IAAI;EACZ;EAEA,IAAK,CAAEK,SAAS,IAAId,KAAK,CAACe,MAAM,CAAIC,IAAI,IAAMA,IAAI,CAACF,SAAU,CAAC,CAACL,MAAM,EAAG;IACvE,OAAO,IAAI;EACZ;EAEA,OAAO,KAAK;AACb","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_selectors","_name","_lockUnlock","getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId","getBlockPatternsForPostType","exports","createRegistrySelector","select","createSelector","postType","STORE_NAME","getBlockPatterns","filter","postTypes","Array","isArray","includes","getEntityRecordsPermissions","kind","name","ids","normalizedIds","map","id","delete","canUser","update","userPermissions","getEntityRecordPermissions","getRegisteredPostMeta","_state$registeredPost","registeredPostMeta","normalizePageId","value","Number","toString","getHomePage","canReadSiteData","siteData","getEntityRecord","homepageId","show_on_front","page_on_front","postId","frontPageTemplateId","getDefaultTemplateId","slug","getPostsPageId","page_for_posts","getTemplateId","homepage","unlock","templates","getEntityRecords","per_page","find","editedEntity","getEditedEntityRecord","postsPageId","currentTemplateSlug","template","currentTemplate","slugToCheck"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcanUser,\n\tgetDefaultTemplateId,\n\tgetEntityRecord,\n\ttype State,\n} from './selectors';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t(\n\t\t\tstate: State,\n\t\t\tkind: string,\n\t\t\tname: string,\n\t\t\tids: string | string[]\n\t\t) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n\nfunction normalizePageId( value: number | string | undefined ): string | null {\n\tif ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {\n\t\treturn null;\n\t}\n\n\t// We also need to check if it's not zero (`'0'`).\n\tif ( Number( value ) === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn value.toString();\n}\n\ninterface SiteData {\n\tshow_on_front?: string;\n\tpage_on_front?: string | number;\n\tpage_for_posts?: string | number;\n}\n\nexport const getHomePage = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst canReadSiteData = select( STORE_NAME ).canUser( 'read', {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t} );\n\t\t\tif ( ! canReadSiteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'site'\n\t\t\t) as SiteData | undefined;\n\t\t\tif ( ! siteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page'\n\t\t\t\t\t? normalizePageId( siteData.page_on_front )\n\t\t\t\t\t: null;\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t\t}\n\t\t\tconst frontPageTemplateId = select(\n\t\t\t\tSTORE_NAME\n\t\t\t).getDefaultTemplateId( {\n\t\t\t\tslug: 'front-page',\n\t\t\t} );\n\t\t\treturn { postType: 'wp_template', postId: frontPageTemplateId };\n\t\t},\n\t\t( state ) => [\n\t\t\tcanUser( state, 'read', {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t} ) && getEntityRecord( state, 'root', 'site' ),\n\t\t\tgetDefaultTemplateId( state, {\n\t\t\t\tslug: 'front-page',\n\t\t\t} ),\n\t\t]\n\t)\n);\n\nexport const getPostsPageId = createRegistrySelector( ( select ) => () => {\n\tconst canReadSiteData = select( STORE_NAME ).canUser( 'read', {\n\t\tkind: 'root',\n\t\tname: 'site',\n\t} );\n\tif ( ! canReadSiteData ) {\n\t\treturn null;\n\t}\n\tconst siteData = select( STORE_NAME ).getEntityRecord( 'root', 'site' ) as\n\t\t| SiteData\n\t\t| undefined;\n\treturn siteData?.show_on_front === 'page'\n\t\t? normalizePageId( siteData.page_for_posts )\n\t\t: null;\n} );\n\nexport const getTemplateId = createRegistrySelector(\n\t( select ) => ( state, postType, postId ) => {\n\t\tconst homepage = unlock( select( STORE_NAME ) ).getHomePage();\n\n\t\tif ( ! homepage ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For the front page, we always use the front page template if existing.\n\t\tif (\n\t\t\tpostType === 'page' &&\n\t\t\tpostType === homepage?.postType &&\n\t\t\tpostId.toString() === homepage?.postId\n\t\t) {\n\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t// that case, we want to check if there is a front page\n\t\t\t// template, and instead of falling back to the home\n\t\t\t// template, we want to fall back to the page template.\n\t\t\tconst templates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tif ( ! templates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = templates.find( ( { slug } ) => slug === 'front-page' )\n\t\t\t\t?.id;\n\t\t\tif ( id ) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\t// If no front page template is found, continue with the\n\t\t\t// logic below (fetching the page template).\n\t\t}\n\n\t\tconst editedEntity = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tif ( ! editedEntity ) {\n\t\t\treturn;\n\t\t}\n\t\tconst postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();\n\t\t// Check if the current page is the posts page.\n\t\tif ( postType === 'page' && postsPageId === postId.toString() ) {\n\t\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\t\tslug: 'home',\n\t\t\t} );\n\t\t}\n\t\t// First see if the post/page has an assigned template and fetch it.\n\t\tconst currentTemplateSlug = editedEntity.template;\n\t\tif ( currentTemplateSlug ) {\n\t\t\tconst currentTemplate = select( STORE_NAME )\n\t\t\t\t.getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} )\n\t\t\t\t?.find( ( { slug } ) => slug === currentTemplateSlug );\n\t\t\tif ( currentTemplate ) {\n\t\t\t\treturn currentTemplate.id;\n\t\t\t}\n\t\t}\n\t\t// If no template is assigned, use the default template.\n\t\tlet slugToCheck;\n\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t// through template hierarchy.\n\t\tif ( editedEntity.slug ) {\n\t\t\tslugToCheck =\n\t\t\t\tpostType === 'page'\n\t\t\t\t\t? `${ postType }-${ editedEntity.slug }`\n\t\t\t\t\t: `single-${ postType }-${ editedEntity.slug }`;\n\t\t} else {\n\t\t\tslugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t}\n\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\tslug: slugToCheck,\n\t\t} );\n\t}\n);\n"],"mappings":";;;;;;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]}
|
|
1
|
+
{"version":3,"names":["_data","require","_selectors","_name","_lockUnlock","getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId","getBlockPatternsForPostType","exports","createRegistrySelector","select","createSelector","postType","STORE_NAME","getBlockPatterns","filter","postTypes","Array","isArray","includes","getEntityRecordsPermissions","kind","name","ids","normalizedIds","map","id","delete","canUser","update","userPermissions","getEntityRecordPermissions","getRegisteredPostMeta","_state$registeredPost","registeredPostMeta","normalizePageId","value","Number","toString","getHomePage","canReadSiteData","siteData","getEntityRecord","homepageId","show_on_front","page_on_front","postId","frontPageTemplateId","getDefaultTemplateId","slug","getPostsPageId","page_for_posts","getTemplateId","homepage","unlock","templates","getEntityRecords","per_page","find","editedEntity","getEditedEntityRecord","postsPageId","currentTemplateSlug","template","currentTemplate","slugToCheck"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport {\n\tcanUser,\n\tgetDefaultTemplateId,\n\tgetEntityRecord,\n\ttype State,\n} from './selectors';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t(\n\t\t\tstate: State,\n\t\t\tkind: string,\n\t\t\tname: string,\n\t\t\tids: string | string[]\n\t\t) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n\nfunction normalizePageId( value: number | string | undefined ): string | null {\n\tif ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {\n\t\treturn null;\n\t}\n\n\t// We also need to check if it's not zero (`'0'`).\n\tif ( Number( value ) === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn value.toString();\n}\n\ninterface SiteData {\n\tshow_on_front?: string;\n\tpage_on_front?: string | number;\n\tpage_for_posts?: string | number;\n}\n\nexport const getHomePage = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst canReadSiteData = select( STORE_NAME ).canUser( 'read', {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t} );\n\t\t\tif ( ! canReadSiteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'site'\n\t\t\t) as SiteData | undefined;\n\t\t\tif ( ! siteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page'\n\t\t\t\t\t? normalizePageId( siteData.page_on_front )\n\t\t\t\t\t: null;\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t\t}\n\t\t\tconst frontPageTemplateId = select(\n\t\t\t\tSTORE_NAME\n\t\t\t).getDefaultTemplateId( {\n\t\t\t\tslug: 'front-page',\n\t\t\t} );\n\t\t\treturn { postType: 'wp_template', postId: frontPageTemplateId };\n\t\t},\n\t\t( state ) => [\n\t\t\tcanUser( state, 'read', {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t} ) && getEntityRecord( state, 'root', 'site' ),\n\t\t\tgetDefaultTemplateId( state, {\n\t\t\t\tslug: 'front-page',\n\t\t\t} ),\n\t\t]\n\t)\n);\n\nexport const getPostsPageId = createRegistrySelector( ( select ) => () => {\n\tconst canReadSiteData = select( STORE_NAME ).canUser( 'read', {\n\t\tkind: 'root',\n\t\tname: 'site',\n\t} );\n\tif ( ! canReadSiteData ) {\n\t\treturn null;\n\t}\n\tconst siteData = select( STORE_NAME ).getEntityRecord( 'root', 'site' ) as\n\t\t| SiteData\n\t\t| undefined;\n\treturn siteData?.show_on_front === 'page'\n\t\t? normalizePageId( siteData.page_for_posts )\n\t\t: null;\n} );\n\nexport const getTemplateId = createRegistrySelector(\n\t( select ) => ( state, postType, postId ) => {\n\t\tconst homepage = unlock( select( STORE_NAME ) ).getHomePage();\n\n\t\tif ( ! homepage ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For the front page, we always use the front page template if existing.\n\t\tif (\n\t\t\tpostType === 'page' &&\n\t\t\tpostType === homepage?.postType &&\n\t\t\tpostId.toString() === homepage?.postId\n\t\t) {\n\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t// that case, we want to check if there is a front page\n\t\t\t// template, and instead of falling back to the home\n\t\t\t// template, we want to fall back to the page template.\n\t\t\tconst templates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tif ( ! templates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = templates.find( ( { slug } ) => slug === 'front-page' )\n\t\t\t\t?.id;\n\t\t\tif ( id ) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\t// If no front page template is found, continue with the\n\t\t\t// logic below (fetching the page template).\n\t\t}\n\n\t\tconst editedEntity = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tif ( ! editedEntity ) {\n\t\t\treturn;\n\t\t}\n\t\tconst postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();\n\t\t// Check if the current page is the posts page.\n\t\tif ( postType === 'page' && postsPageId === postId.toString() ) {\n\t\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\t\tslug: 'home',\n\t\t\t} );\n\t\t}\n\t\t// First see if the post/page has an assigned template and fetch it.\n\t\tconst currentTemplateSlug = editedEntity.template;\n\t\tif ( currentTemplateSlug ) {\n\t\t\tconst currentTemplate = select( STORE_NAME )\n\t\t\t\t.getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} )\n\t\t\t\t?.find( ( { slug } ) => slug === currentTemplateSlug );\n\t\t\tif ( currentTemplate ) {\n\t\t\t\treturn currentTemplate.id;\n\t\t\t}\n\t\t}\n\t\t// If no template is assigned, use the default template.\n\t\tlet slugToCheck;\n\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t// through template hierarchy.\n\t\tif ( editedEntity.slug ) {\n\t\t\tslugToCheck =\n\t\t\t\tpostType === 'page'\n\t\t\t\t\t? `${ postType }-${ editedEntity.slug }`\n\t\t\t\t\t: `single-${ postType }-${ editedEntity.slug }`;\n\t\t} else {\n\t\t\tslugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t}\n\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\tslug: slugToCheck,\n\t\t} );\n\t}\n);\n"],"mappings":";;;;;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,cAAcA,CAAEC,KAAY,EAAG;EAC9C,OAAOA,KAAK,CAACC,WAAW;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,uBAAuBA,CACtCF,KAAY,EACkB;EAC9B,OAAOA,KAAK,CAACG,oBAAoB;AAClC;AAEO,MAAMC,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,IAAAE,4BAAsB,EAC9DC,MAAW,IACZ,IAAAC,oBAAc,EACb,CAAER,KAAK,EAAES,QAAQ,KAChBF,MAAM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BAAgB,CAAE,UAAU,EAAE,aAAa,EAAE;MAC7CC,QAAQ,EAAE,CAAC;IACZ,CAAE,CAAC,EACDC,IAAI,CAAE,CAAE;MAAET;IAAK,CAAC,KAAMA,IAAI,KAAKa,mBAAoB,CAAC;IACvD,IAAKE,eAAe,EAAG;MACtB,OAAOA,eAAe,CAACtC,EAAE;IAC1B;EACD;EACA;EACA,IAAIuC,WAAW;EACf;EACA;EACA;EACA;EACA,IAAKN,YAAY,CAACV,IAAI,EAAG;IACxBgB,WAAW,GACVrD,QAAQ,KAAK,MAAM,GAChB,GAAIA,QAAQ,IAAM+C,YAAY,CAACV,IAAI,EAAG,GACtC,UAAWrC,QAAQ,IAAM+C,YAAY,CAACV,IAAI,EAAG;EAClD,CAAC,MAAM;IACNgB,WAAW,GAAGrD,QAAQ,KAAK,MAAM,GAAG,MAAM,GAAG,UAAWA,QAAQ,EAAG;EACpE;EACA,OAAOF,MAAM,CAAEG,gBAAW,CAAC,CAACmC,oBAAoB,CAAE;IACjDC,IAAI,EAAEgB;EACP,CAAE,CAAC;AACJ,CACD,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_url","require","_utils","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","_getNormalizedCommaSe","getNormalizedCommaSeparable","join","_getNormalizedCommaSe2","toString","map","addQueryArgs","slice","_default","exports","default","withWeakMapCache"],"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_url","require","_utils","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","_getNormalizedCommaSe","getNormalizedCommaSeparable","join","_getNormalizedCommaSe2","toString","map","addQueryArgs","slice","_default","exports","default","withWeakMapCache"],"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"],"mappings":";;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,aAAaA,CAAEC,KAAK,EAAG;EACtC;AACD;AACA;EACC,MAAMC,KAAK,GAAG;IACbC,SAAS,EAAE,EAAE;IACbC,IAAI,EAAE,CAAC;IACPC,OAAO,EAAE,EAAE;IACXC,MAAM,EAAE,IAAI;IACZC,OAAO,EAAE,IAAI;IACbC,OAAO,EAAE;EACV,CAAC;;EAED;EACA,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAAER,KAAM,CAAC,CAACU,IAAI,CAAC,CAAC;EAExC,KAAM,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,EAAG;IACvC,MAAME,GAAG,GAAGL,IAAI,CAAEG,CAAC,CAAE;IACrB,IAAIG,KAAK,GAAGd,KAAK,CAAEa,GAAG,CAAE;IAExB,QAASA,GAAG;MACX,KAAK,MAAM;QACVZ,KAAK,CAAEY,GAAG,CAAE,GAAGE,MAAM,CAAED,KAAM,CAAC;QAC9B;MAED,KAAK,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utils","_entities","_getQueryParts","_interopRequireDefault","getContextFromAction","action","query","queryParts","getQueryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","_itemIds$length","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","removeEntitiesById","entities","ids","Object","fromEntries","entries","filter","id","some","itemId","Number","isInteger","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","conservativeMapItem","map","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","compose","ifMatchingAction","replaceAction","onSubKey","Boolean","meta","queries","removedItems","queryGroup","contextQueries","queryItems","queryId","_default","exports","default","combineReducers"],"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds?.length ?? 0,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value?.[ key ];\n\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item?.[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `onSubKey` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `onSubKey` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tonSubKey( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tonSubKey( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate?.itemIds || [],\n\t\t\taction.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),\n\t\t\tpage,\n\t\t\tperPage\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,\n\titemIsComplete,\n\tqueries,\n} );\n"],"mappings":";;;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AAMA,IAAAG,SAAA,GAA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AAC;IACD+C,IAAI,EAAExD,MAAM,CAACwD;EACd,CAAC;AACF,CAAE,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,OAAO,GAAGA,CAAEvB,KAAK,GAAG,CAAC,CAAC,EAAElC,MAAM,KAAM;EACzC,QAASA,MAAM,CAACmC,IAAI;IACnB,KAAK,eAAe;MACnB,OAAOe,cAAc,CAAEhB,KAAK,EAAElC,MAAO,CAAC;IACvC,KAAK,cAAc;MAClB,MAAM0D,YAAY,GAAG1D,MAAM,CAACM,OAAO,CAACgC,MAAM,CAAE,CAAEU,MAAM,EAAElB,MAAM,KAAM;QACjEkB,MAAM,CAAElB,MAAM,CAAE,GAAG,IAAI;QACvB,OAAOkB,MAAM;MACd,CAAC,EAAE,CAAC,CAAE,CAAC;MAEP,OAAOxB,MAAM,CAACC,WAAW,CACxBD,MAAM,CAACE,OAAO,CAAEQ,KAAM,CAAC,CAACQ,GAAG,CAC1B,CAAE,CAAEiB,UAAU,EAAEC,cAAc,CAAE,KAAM,CACrCD,UAAU,EACVnC,MAAM,CAACC,WAAW,CACjBD,MAAM,CAACE,OAAO,CAAEkC,cAAe,CAAC,CAAClB,GAAG,CACnC,CAAE,CAAEzC,KAAK,EAAE4D,UAAU,CAAE,KAAM,CAC5B5D,KAAK,EACL;QACC,GAAG4D,UAAU;QACbvD,OAAO,EAAEuD,UAAU,CAACvD,OAAO,CAACqB,MAAM,CAC/BmC,OAAO,IACR,CAAEJ,YAAY,CAAEI,OAAO,CACzB;MACD,CAAC,CAEH,CACD,CAAC,CAEH,CACD,CAAC;IACF;MACC,OAAO5B,KAAK;EACd;AACD,CAAC;AAAC,IAAA6B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa,IAAAC,qBAAe,EAAE;EAC/BjC,KAAK;EACLW,cAAc;EACda;AACD,CAAE,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_data","require","_compose","_utils","_entities","_getQueryParts","_interopRequireDefault","getContextFromAction","action","query","queryParts","getQueryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","_itemIds$length","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","removeEntitiesById","entities","ids","Object","fromEntries","entries","filter","id","some","itemId","Number","isInteger","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","conservativeMapItem","map","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","compose","ifMatchingAction","replaceAction","onSubKey","Boolean","meta","queries","removedItems","queryGroup","contextQueries","queryItems","queryId","_default","exports","default","combineReducers"],"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds?.length ?? 0,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value?.[ key ];\n\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item?.[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `onSubKey` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `onSubKey` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tonSubKey( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tonSubKey( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate?.itemIds || [],\n\t\t\taction.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),\n\t\t\tpage,\n\t\t\tperPage\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,\n\titemIsComplete,\n\tqueries,\n} );\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,MAAA,GAAAF,OAAA;AAMA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAA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CAACwD;EACd,CAAC;AACF,CAAE,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,OAAO,GAAGA,CAAEvB,KAAK,GAAG,CAAC,CAAC,EAAElC,MAAM,KAAM;EACzC,QAASA,MAAM,CAACmC,IAAI;IACnB,KAAK,eAAe;MACnB,OAAOe,cAAc,CAAEhB,KAAK,EAAElC,MAAO,CAAC;IACvC,KAAK,cAAc;MAClB,MAAM0D,YAAY,GAAG1D,MAAM,CAACM,OAAO,CAACgC,MAAM,CAAE,CAAEU,MAAM,EAAElB,MAAM,KAAM;QACjEkB,MAAM,CAAElB,MAAM,CAAE,GAAG,IAAI;QACvB,OAAOkB,MAAM;MACd,CAAC,EAAE,CAAC,CAAE,CAAC;MAEP,OAAOxB,MAAM,CAACC,WAAW,CACxBD,MAAM,CAACE,OAAO,CAAEQ,KAAM,CAAC,CAACQ,GAAG,CAC1B,CAAE,CAAEiB,UAAU,EAAEC,cAAc,CAAE,KAAM,CACrCD,UAAU,EACVnC,MAAM,CAACC,WAAW,CACjBD,MAAM,CAACE,OAAO,CAAEkC,cAAe,CAAC,CAAClB,GAAG,CACnC,CAAE,CAAEzC,KAAK,EAAE4D,UAAU,CAAE,KAAM,CAC5B5D,KAAK,EACL;QACC,GAAG4D,UAAU;QACbvD,OAAO,EAAEuD,UAAU,CAACvD,OAAO,CAACqB,MAAM,CAC/BmC,OAAO,IACR,CAAEJ,YAAY,CAAEI,OAAO,CACzB;MACD,CAAC,CAEH,CACD,CAAC,CAEH,CACD,CAAC;IACF;MACC,OAAO5B,KAAK;EACd;AACD,CAAC;AAAC,IAAA6B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa,IAAAC,qBAAe,EAAE;EAC/BjC,KAAK;EACLW,cAAc;EACda;AACD,CAAE,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_equivalentKeyMap","_interopRequireDefault","require","_data","_getQueryParts","_utils","queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","getQueryParts","itemIds","queries","startOffset","endOffset","length","Math","min","items","i","itemId","Array","isArray","includes","undefined","hasOwnProperty","item","filteredItem","f","field","split","value","forEach","fieldName","setNestedValue","itemIsComplete","push","getQueriedItems","exports","createSelector","queriedItemsCache","get","queriedItems","EquivalentKeyMap","set","getQueriedTotalItems","_state$queries$contex","meta","totalItems","getQueriedTotalPages","_state$queries$contex2","totalPages"],"sources":["@wordpress/core-data/src/queried-data/selectors.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\nimport { setNestedValue } from '../utils';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nfunction getQueriedItemsUncached( state, query ) {\n\tconst { stableKey, page, perPage, include, fields, context } =\n\t\tgetQueryParts( query );\n\tlet itemIds;\n\n\tif ( state.queries?.[ context ]?.[ stableKey ] ) {\n\t\titemIds = state.queries[ context ][ stableKey ].itemIds;\n\t}\n\n\tif ( ! itemIds ) {\n\t\treturn null;\n\t}\n\n\tconst startOffset = perPage === -1 ? 0 : ( page - 1 ) * perPage;\n\tconst endOffset =\n\t\tperPage === -1\n\t\t\t? itemIds.length\n\t\t\t: Math.min( startOffset + perPage, itemIds.length );\n\n\tconst items = [];\n\tfor ( let i = startOffset; i < endOffset; i++ ) {\n\t\tconst itemId = itemIds[ i ];\n\t\tif ( Array.isArray( include ) && ! include.includes( itemId ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( itemId === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Having a target item ID doesn't guarantee that this object has been queried.\n\t\tif ( ! state.items[ context ]?.hasOwnProperty( itemId ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst item = state.items[ context ][ itemId ];\n\n\t\tlet filteredItem;\n\t\tif ( Array.isArray( fields ) ) {\n\t\t\tfilteredItem = {};\n\n\t\t\tfor ( let f = 0; f < fields.length; f++ ) {\n\t\t\t\tconst field = fields[ f ].split( '.' );\n\t\t\t\tlet value = item;\n\t\t\t\tfield.forEach( ( fieldName ) => {\n\t\t\t\t\tvalue = value?.[ fieldName ];\n\t\t\t\t} );\n\n\t\t\t\tsetNestedValue( filteredItem, field, value );\n\t\t\t}\n\t\t} else {\n\t\t\t// If expecting a complete item, validate that completeness, or\n\t\t\t// otherwise abort.\n\t\t\tif ( ! state.itemIsComplete[ context ]?.[ itemId ] ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfilteredItem = item;\n\t\t}\n\n\t\titems.push( filteredItem );\n\t}\n\n\treturn items;\n}\n\n/**\n * Returns items for a given query, or null if the items are not known. Caches\n * result both per state (by reference) and per query (by deep equality).\n * The caching approach is intended to be durable to query objects which are\n * deeply but not referentially equal, since otherwise:\n *\n * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nexport const getQueriedItems = createSelector( ( state, query = {} ) => {\n\tlet queriedItemsCache = queriedItemsCacheByState.get( state );\n\tif ( queriedItemsCache ) {\n\t\tconst queriedItems = queriedItemsCache.get( query );\n\t\tif ( queriedItems !== undefined ) {\n\t\t\treturn queriedItems;\n\t\t}\n\t} else {\n\t\tqueriedItemsCache = new EquivalentKeyMap();\n\t\tqueriedItemsCacheByState.set( state, queriedItemsCache );\n\t}\n\n\tconst items = getQueriedItemsUncached( state, query );\n\tqueriedItemsCache.set( query, items );\n\treturn items;\n} );\n\nexport function getQueriedTotalItems( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalItems ?? null;\n}\n\nexport function getQueriedTotalPages( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalPages ?? null;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_equivalentKeyMap","_interopRequireDefault","require","_data","_getQueryParts","_utils","queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","getQueryParts","itemIds","queries","startOffset","endOffset","length","Math","min","items","i","itemId","Array","isArray","includes","undefined","hasOwnProperty","item","filteredItem","f","field","split","value","forEach","fieldName","setNestedValue","itemIsComplete","push","getQueriedItems","exports","createSelector","queriedItemsCache","get","queriedItems","EquivalentKeyMap","set","getQueriedTotalItems","_state$queries$contex","meta","totalItems","getQueriedTotalPages","_state$queries$contex2","totalPages"],"sources":["@wordpress/core-data/src/queried-data/selectors.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\nimport { setNestedValue } from '../utils';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nfunction getQueriedItemsUncached( state, query ) {\n\tconst { stableKey, page, perPage, include, fields, context } =\n\t\tgetQueryParts( query );\n\tlet itemIds;\n\n\tif ( state.queries?.[ context ]?.[ stableKey ] ) {\n\t\titemIds = state.queries[ context ][ stableKey ].itemIds;\n\t}\n\n\tif ( ! itemIds ) {\n\t\treturn null;\n\t}\n\n\tconst startOffset = perPage === -1 ? 0 : ( page - 1 ) * perPage;\n\tconst endOffset =\n\t\tperPage === -1\n\t\t\t? itemIds.length\n\t\t\t: Math.min( startOffset + perPage, itemIds.length );\n\n\tconst items = [];\n\tfor ( let i = startOffset; i < endOffset; i++ ) {\n\t\tconst itemId = itemIds[ i ];\n\t\tif ( Array.isArray( include ) && ! include.includes( itemId ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( itemId === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Having a target item ID doesn't guarantee that this object has been queried.\n\t\tif ( ! state.items[ context ]?.hasOwnProperty( itemId ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst item = state.items[ context ][ itemId ];\n\n\t\tlet filteredItem;\n\t\tif ( Array.isArray( fields ) ) {\n\t\t\tfilteredItem = {};\n\n\t\t\tfor ( let f = 0; f < fields.length; f++ ) {\n\t\t\t\tconst field = fields[ f ].split( '.' );\n\t\t\t\tlet value = item;\n\t\t\t\tfield.forEach( ( fieldName ) => {\n\t\t\t\t\tvalue = value?.[ fieldName ];\n\t\t\t\t} );\n\n\t\t\t\tsetNestedValue( filteredItem, field, value );\n\t\t\t}\n\t\t} else {\n\t\t\t// If expecting a complete item, validate that completeness, or\n\t\t\t// otherwise abort.\n\t\t\tif ( ! state.itemIsComplete[ context ]?.[ itemId ] ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfilteredItem = item;\n\t\t}\n\n\t\titems.push( filteredItem );\n\t}\n\n\treturn items;\n}\n\n/**\n * Returns items for a given query, or null if the items are not known. Caches\n * result both per state (by reference) and per query (by deep equality).\n * The caching approach is intended to be durable to query objects which are\n * deeply but not referentially equal, since otherwise:\n *\n * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nexport const getQueriedItems = createSelector( ( state, query = {} ) => {\n\tlet queriedItemsCache = queriedItemsCacheByState.get( state );\n\tif ( queriedItemsCache ) {\n\t\tconst queriedItems = queriedItemsCache.get( query );\n\t\tif ( queriedItems !== undefined ) {\n\t\t\treturn queriedItems;\n\t\t}\n\t} else {\n\t\tqueriedItemsCache = new EquivalentKeyMap();\n\t\tqueriedItemsCacheByState.set( state, queriedItemsCache );\n\t}\n\n\tconst items = getQueriedItemsUncached( state, query );\n\tqueriedItemsCache.set( query, items );\n\treturn items;\n} );\n\nexport function getQueriedTotalItems( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalItems ?? null;\n}\n\nexport function getQueriedTotalPages( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalPages ?? null;\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,wBAAwB,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAuBA,CAAEC,KAAK,EAAEC,KAAK,EAAG;EAChD,MAAM;IAAEC,SAAS;IAAEC,IAAI;IAAEC,OAAO;IAAEC,OAAO;IAAEC,MAAM;IAAEC;EAAQ,CAAC,GAC3D,IAAAC,sBAAa,EAAEP,KAAM,CAAC;EACvB,IAAIQ,OAAO;EAEX,IAAKT,KAAK,CAACU,OAAO,GAAIH,OAAO,CAAE,GAAIL,SAAS,CAAE,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